diff options
| author | Xinhui | 2016-11-28 12:05:45 +0100 | 
|---|---|---|
| committer | Xinhui | 2016-11-28 12:05:50 +0100 | 
| commit | 61653806b8d977eef4d565040cc7ea86cb9fa9c9 (patch) | |
| tree | 8207d82f01e077a2e3c1b83164a463680fcdfd97 | |
| parent | 9fb08c0de8278d4a72103e760350d76adb7a406f (diff) | |
| download | chouette-core-61653806b8d977eef4d565040cc7ea86cb9fa9c9.tar.bz2 | |
LineFootnotesController
Refs #2036
| -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 | ||||
| -rw-r--r-- | config/locales/footnotes.en.yml | 7 | ||||
| -rw-r--r-- | config/locales/footnotes.fr.yml | 5 | ||||
| -rw-r--r-- | config/locales/lines.en.yml | 1 | ||||
| -rw-r--r-- | config/locales/lines.fr.yml | 1 | ||||
| -rw-r--r-- | config/routes.rb | 1 | 
12 files changed, 71 insertions, 13 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' diff --git a/config/locales/footnotes.en.yml b/config/locales/footnotes.en.yml index 98be688c5..98b6bb2a6 100644 --- a/config/locales/footnotes.en.yml +++ b/config/locales/footnotes.en.yml @@ -1,9 +1,12 @@  en: +  notice: +    footnotes: +      updated: 'Footnotes has been updated'    footnotes:      actions: -      add_footnote: "add footnote"  +      add_footnote: "add footnote"      index: -      title: "Footnotes"      +      title: "Footnotes"    activerecord:      models:        footnote: "footnote" diff --git a/config/locales/footnotes.fr.yml b/config/locales/footnotes.fr.yml index f1a9b2cf5..a3cf2312d 100644 --- a/config/locales/footnotes.fr.yml +++ b/config/locales/footnotes.fr.yml @@ -1,9 +1,12 @@  fr: +  notice: +    footnotes: +      updated: 'Note en bas de page mise à jour'    footnotes:      actions:        add_footnote: "ajouter une note en bas de page"      index: -      title: "Notes en bas de page"    +      title: "Notes en bas de page"    activerecord:      models:        footnote: "note en bas de page" diff --git a/config/locales/lines.en.yml b/config/locales/lines.en.yml index 33e979a00..e7c8f9d97 100644 --- a/config/locales/lines.en.yml +++ b/config/locales/lines.en.yml @@ -3,6 +3,7 @@ en:      actions:        new: "Add a new line"        edit: "Edit this line" +      edit_footnotes: "Edit line footnotes"        destroy: "Remove this line"        destroy_confirm: "Are you sure you want destroy this line?"        destroy_selection_confirm: "Are you sure you want destroy those lines?" diff --git a/config/locales/lines.fr.yml b/config/locales/lines.fr.yml index 58331b363..e4cfdb513 100644 --- a/config/locales/lines.fr.yml +++ b/config/locales/lines.fr.yml @@ -3,6 +3,7 @@ fr:      actions:        new: "Ajouter une ligne"        edit: "Modifier cette ligne" +      edit_footnotes: "Modifier notes en bas de page"        destroy: "Supprimer cette ligne"        destroy_confirm: "Etes vous sûr de supprimer cette ligne ?"        destroy_selection_confirm: "Etes vous sûr de supprimer cette sélection de lignes ?" diff --git a/config/routes.rb b/config/routes.rb index 74e4b47b5..04d1875c9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -89,6 +89,7 @@ ChouetteIhm::Application.routes.draw do      match 'lines' => 'lines#destroy_all', :via => :delete      resources :lines, controller: "referential_lines" do +      resource :footnotes, controller: "line_footnotes"        delete :index, on: :collection, action: :delete_all        collection do          get 'name_filter' | 
