From 8ca237d75a3271844d65b22e25a3f9c877fd572f Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Mon, 18 Mar 2013 22:17:57 +0100 Subject: [PATCH] =?UTF-8?q?am=C3=A9lioration=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/stylesheets/admin/sheets.css.scss | 17 ++++++++++ app/controllers/sheets_controller.rb | 14 +++----- app/models/sheet_year.rb | 34 ++++++++++++++----- app/views/sheet_years/_form.html.haml | 4 +++ app/views/sheets/_sheet.html.haml | 2 +- app/views/sheets/edit.html.haml | 1 + app/views/sheets/show.html.haml | 7 +++- app/views/sheets/update.js.erb | 3 ++ ...20130318194848_add_plume_to_sheet_years.rb | 5 +++ .../20130318194918_add_plume_to_sheets.rb | 5 +++ db/schema.rb | 4 ++- 11 files changed, 76 insertions(+), 20 deletions(-) create mode 100644 app/views/sheets/update.js.erb create mode 100644 db/migrate/20130318194848_add_plume_to_sheet_years.rb create mode 100644 db/migrate/20130318194918_add_plume_to_sheets.rb diff --git a/app/assets/stylesheets/admin/sheets.css.scss b/app/assets/stylesheets/admin/sheets.css.scss index 8ddc88a..4204871 100644 --- a/app/assets/stylesheets/admin/sheets.css.scss +++ b/app/assets/stylesheets/admin/sheets.css.scss @@ -82,4 +82,21 @@ padding:10px; width :33%; vertical-align :top;} +} + +#sheets{ +tr{ + +&:hover{ +background:#f2f2f2; + +} + +} + +} + +.field{ +border:1px solid black; + } \ No newline at end of file diff --git a/app/controllers/sheets_controller.rb b/app/controllers/sheets_controller.rb index 7d0a711..54d6968 100644 --- a/app/controllers/sheets_controller.rb +++ b/app/controllers/sheets_controller.rb @@ -186,18 +186,14 @@ require 'iconv' def update @sheet = Sheet.find(params[:id]) - respond_to do |format| + if @sheet.update_attributes(params[:sheet]) - flash[:notice] = 'Sheet was successfully updated.' - format.html { redirect_to(@sheet) } - format.js { render :action => "show", :layout => false } - format.xml { head :ok } + @sheet = Sheet.find(params[:id]) + else - format.html { render :action => "edit" } - format.js { render :action => "edit", :layout => false } - format.xml { render :xml => @sheet.errors, :status => :unprocessable_entity } + end - end + end diff --git a/app/models/sheet_year.rb b/app/models/sheet_year.rb index f32f5a3..285942f 100644 --- a/app/models/sheet_year.rb +++ b/app/models/sheet_year.rb @@ -4,20 +4,28 @@ class SheetYear < ActiveRecord::Base validates_presence_of :year - attr_accessible :year, :join_type, :benefactor, :gift_year, :paid_at, :amount, :payment_type, :bank, :check_number, :sheet_id + attr_accessible :year, :join_type, :benefactor, :gift_year, :paid_at, :amount, :payment_type, :bank, :check_number, :sheet_id, :plume JOIN_TYPE = {1 => "Individuel", 2 => "Familial", 3 =>"Association"} PAYMENT_TYPE = {1 => "Chèque", 2 => "Liquide"} - def after_save + after_save do sy = self.sheet.sheet_years.find(:first, :order => "year DESC") if sy self.sheet.last_year = sy.year self.sheet.first_year = self.sheet.sheet_years.find(:first, :order => "year ASC").year - self.sheet.save + + if sy.plume + self.sheet.plume = true + else + self.sheet.plume = false + end + + self.sheet.save + end @@ -26,16 +34,26 @@ class SheetYear < ActiveRecord::Base end - def after_destroy + after_destroy do sy = self.sheet.sheet_years.find(:first, :order => "year DESC") if sy - self.sheet.last_year = sy.year - self.sheet.first_year = self.sheet.sheet_years.find(:first, :order => "year ASC").year - self.sheet.save - + self.sheet.last_year = sy.year + self.sheet.first_year = self.sheet.sheet_years.find(:first, :order => "year ASC").year + + if sy.plume + self.sheet.plume = true + else + self.sheet.plume = false + end + + + else + self.sheet.plume = false end + + self.sheet.save end diff --git a/app/views/sheet_years/_form.html.haml b/app/views/sheet_years/_form.html.haml index 102526c..572b225 100644 --- a/app/views/sheet_years/_form.html.haml +++ b/app/views/sheet_years/_form.html.haml @@ -1,5 +1,8 @@ .field + = form.label :plume, "Option plume papier : " + = form.check_box :plume + %br = form.label :year, "Année :" = form.text_field :year @@ -14,6 +17,7 @@ = form.check_box :gift_year, :onchange => "payment_form("+form.object.id.to_s+",$(this));" %br + .payment_form{:style => ("display:none;" if form.object.gift_year)} diff --git a/app/views/sheets/_sheet.html.haml b/app/views/sheets/_sheet.html.haml index 2a2b8c6..0d75db3 100644 --- a/app/views/sheets/_sheet.html.haml +++ b/app/views/sheets/_sheet.html.haml @@ -1,4 +1,4 @@ -%tr +%tr#sheet_line{:id => sheet.id} -if sheet.corporate and sheet.corporate != "" %td{:colspan => 2}=sheet.corporate -else diff --git a/app/views/sheets/edit.html.haml b/app/views/sheets/edit.html.haml index d68a861..aa5ff96 100644 --- a/app/views/sheets/edit.html.haml +++ b/app/views/sheets/edit.html.haml @@ -1,6 +1,7 @@ #sheet_show .links{:style => "float:right;"} =link_to "Retour", @sheet, :class => "lien", :remote => true, :confirm => "Attention, les changements éventuellements apportés ne seront pas sauvegardés." + = link_to 'Fermer', "#", :onclick => "$('#sheet_show').remove();return false;" %h1 Modifier une fiche = semantic_form_for [@sheet], :remote => true do |form| diff --git a/app/views/sheets/show.html.haml b/app/views/sheets/show.html.haml index bcfa223..dd08846 100644 --- a/app/views/sheets/show.html.haml +++ b/app/views/sheets/show.html.haml @@ -1,7 +1,7 @@ #sheet_show .links{:style => "float:right;"} = link_to 'Modifier', edit_sheet_path(@sheet), :method => :get, :remote => true - = link_to 'Retour', "#", :onclick => "$('#sheet_show').remove();return false;" + = link_to 'Fermer', "#", :onclick => "$('#sheet_show').remove();return false;" %h1 Fiche n° @@ -11,6 +11,11 @@ ="/" =@sheet.last_year + -if @sheet.plume + %p{:style => "background:red;"} Souhaite recevoir la plume par courrier. + + + %h2 Cette adhésion regroupe : = link_to 'Ajouter', :url => new_person_path(:sheet_id => @sheet), :update => "new_sheet_people", :method => :get, :remote => true #if has_permission?('adherent.edit') #new_sheet_people diff --git a/app/views/sheets/update.js.erb b/app/views/sheets/update.js.erb new file mode 100644 index 0000000..6e04659 --- /dev/null +++ b/app/views/sheets/update.js.erb @@ -0,0 +1,3 @@ +$('#sheet_show').remove(); + +$('#sheet_line_<%= @sheet.id %>').replaceWith("<%= escape_javascript(render(@sheet)) %>"); diff --git a/db/migrate/20130318194848_add_plume_to_sheet_years.rb b/db/migrate/20130318194848_add_plume_to_sheet_years.rb new file mode 100644 index 0000000..abf3862 --- /dev/null +++ b/db/migrate/20130318194848_add_plume_to_sheet_years.rb @@ -0,0 +1,5 @@ +class AddPlumeToSheetYears < ActiveRecord::Migration + def change + add_column :sheet_years, :plume, :boolean + end +end diff --git a/db/migrate/20130318194918_add_plume_to_sheets.rb b/db/migrate/20130318194918_add_plume_to_sheets.rb new file mode 100644 index 0000000..af2c97a --- /dev/null +++ b/db/migrate/20130318194918_add_plume_to_sheets.rb @@ -0,0 +1,5 @@ +class AddPlumeToSheets < ActiveRecord::Migration + def change + add_column :sheets, :plume, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 17b7e9b..a9f6eed 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130115105842) do +ActiveRecord::Schema.define(:version => 20130318194918) do create_table "admins", :force => true do |t| t.string "email", :default => "", :null => false @@ -215,6 +215,7 @@ ActiveRecord::Schema.define(:version => 20130115105842) do t.integer "sheet_id" t.datetime "created_at" t.datetime "updated_at" + t.boolean "plume" end create_table "sheets", :force => true do |t| @@ -234,6 +235,7 @@ ActiveRecord::Schema.define(:version => 20130115105842) do t.integer "last_year" t.datetime "created_at" t.datetime "updated_at" + t.boolean "plume" end create_table "survey_item_answers", :force => true do |t|