diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/line_footnotes_controller.rb | 33 | ||||
| -rw-r--r-- | app/controllers/referential_lines_controller.rb | 4 | ||||
| -rw-r--r-- | app/policies/line_policy.rb | 1 | ||||
| -rw-r--r-- | app/views/line_footnotes/_form.html.slim | 15 | ||||
| -rw-r--r-- | app/views/line_footnotes/edit.html.slim | 3 | ||||
| -rw-r--r-- | app/views/referential_lines/_form.html.slim | 10 | ||||
| -rw-r--r-- | app/views/referential_lines/show.html.slim | 3 |
7 files changed, 59 insertions, 10 deletions
diff --git a/app/controllers/line_footnotes_controller.rb b/app/controllers/line_footnotes_controller.rb new file mode 100644 index 000000000..6e3c08653 --- /dev/null +++ b/app/controllers/line_footnotes_controller.rb @@ -0,0 +1,33 @@ +class LineFootnotesController < ChouetteController + before_action :set_line + before_action :check_policy, :only => [:edit, :update] + + def show + end + + def edit + end + + def update + if @line.update(line_params) + redirect_to referential_line_path(@referential, @line) , notice: t('notice.footnotes.updated') + else + render :edit + end + end + + private + def check_policy + authorize @line, :update_footnote? + end + + def set_line + @referential = Referential.find params[:referential_id] + @line = @referential.lines.find params[:line_id] + end + + def line_params + params.require(:line).permit( + { footnotes_attributes: [ :code, :label, :_destroy, :id ] } ) + end +end diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb index fb53e4959..c1f3e01a8 100644 --- a/app/controllers/referential_lines_controller.rb +++ b/app/controllers/referential_lines_controller.rb @@ -1,4 +1,5 @@ class ReferentialLinesController < ChouetteController + before_action :check_policy, :only => [:edit, :update, :destroy] defaults :resource_class => Chouette::Line, :collection_name => 'lines', :instance_name => 'line' respond_to :html @@ -79,6 +80,9 @@ class ReferentialLinesController < ChouetteController end private + def check_policy + authorize resource + end def line_params params.require(:line).permit( diff --git a/app/policies/line_policy.rb b/app/policies/line_policy.rb index 92310f042..8ef2dcaed 100644 --- a/app/policies/line_policy.rb +++ b/app/policies/line_policy.rb @@ -12,4 +12,5 @@ class LinePolicy < ApplicationPolicy def new? ; create? end def edit? ; true end def destroy? ; create? end + def update_footnote?; true end end diff --git a/app/views/line_footnotes/_form.html.slim b/app/views/line_footnotes/_form.html.slim new file mode 100644 index 000000000..9eb4e1a70 --- /dev/null +++ b/app/views/line_footnotes/_form.html.slim @@ -0,0 +1,15 @@ += semantic_form_for [@referential, @line], url: referential_line_footnotes_path do |form| + = form.inputs do + .footnotes_block + h3 = t("footnotes.index.title") + + #footnotes + = form.semantic_fields_for :footnotes do |f| + = render "footnotes/footnote_fields", f: f + + .add_footnote + = link_to_add_association t("footnotes.actions.add_footnote"), form, :footnotes , :partial => "footnotes/footnote_fields", :"data-association-insertion-method" => "append", :"data-association-insertion-node" => "div#footnotes", class: 'add' + + = form.actions do + = form.action :submit, as: :button + = form.action :cancel, as: :link diff --git a/app/views/line_footnotes/edit.html.slim b/app/views/line_footnotes/edit.html.slim new file mode 100644 index 000000000..f09d99e6d --- /dev/null +++ b/app/views/line_footnotes/edit.html.slim @@ -0,0 +1,3 @@ += title_tag t('lines.edit.title', line: @line.name) + += render 'form' diff --git a/app/views/referential_lines/_form.html.slim b/app/views/referential_lines/_form.html.slim index a4c98d43d..5e450d0cc 100644 --- a/app/views/referential_lines/_form.html.slim +++ b/app/views/referential_lines/_form.html.slim @@ -17,16 +17,6 @@ / = form.input :objectid, :required => !@line.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.line.objectid") } / = form.input :group_of_line_tokens, :label => t('.group_of_lines'), as: :text, :input_html => { :"data-pre" => ( @line.group_of_lines.map { |group_of_line| { :id => group_of_line.id, :name => group_of_line.name } } ).to_json } - .footnotes_block - h3 = t("footnotes.index.title") - - #footnotes - = form.semantic_fields_for :footnotes do |f| - = render "footnotes/footnote_fields", f: f - - .add_footnote - = link_to_add_association t("footnotes.actions.add_footnote"), form, :footnotes , :partial => "footnotes/footnote_fields", :"data-association-insertion-method" => "append", :"data-association-insertion-node" => "div#footnotes", class: 'add' - = form.actions do = form.action :submit, as: :button = form.action :cancel, as: :link diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim index e32978b20..1b27a22f8 100644 --- a/app/views/referential_lines/show.html.slim +++ b/app/views/referential_lines/show.html.slim @@ -134,6 +134,9 @@ p.after_map - if policy(@line).update? li = link_to t('lines.actions.edit'), edit_referential_line_path(@referential, @line), class: 'edit' + - if policy(@line).update_footnote? + li + = link_to t('lines.actions.edit_footnotes'), edit_referential_line_footnotes_path(@referential, @line), class: 'edit' - if policy(@line).destroy? li = link_to t('lines.actions.destroy'), referential_line_path(@referential, @line), method: :delete, :data => {:confirm => t('lines.actions.destroy_confirm')}, class: 'remove' |
