From c49edb79a249399e98a619be51595b06d7c218e4 Mon Sep 17 00:00:00 2001 From: benni Date: Sat, 12 May 2012 10:55:20 +0200 Subject: [PATCH] Fixed edit_not in balancing. --- app/controllers/finance/balancing_controller.rb | 16 ++++++---------- app/helpers/application_helper.rb | 2 +- app/views/finance/balancing/_edit_note.html.haml | 11 +++-------- app/views/finance/balancing/edit_note.js.erb | 1 + app/views/finance/balancing/new.html.haml | 8 +++----- app/views/finance/balancing/update_note.js.erb | 2 ++ config/routes.rb | 8 ++++++++ 7 files changed, 24 insertions(+), 24 deletions(-) create mode 100644 app/views/finance/balancing/edit_note.js.erb create mode 100644 app/views/finance/balancing/update_note.js.erb diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 4d9e72c2..a49bc622 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -1,8 +1,7 @@ # encoding: utf-8 class Finance::BalancingController < ApplicationController before_filter :authenticate_finance - verify :method => :post, :only => [:close, :close_direct] - + def index @financial_transactions = FinancialTransaction.find(:all, :order => "created_on DESC", :limit => 8) @orders = Order.finished_not_closed @@ -55,18 +54,15 @@ class Finance::BalancingController < ApplicationController def edit_note @order = Order.find(params[:id]) - render :partial => 'edit_note' + render :layout => false end def update_note @order = Order.find(params[:id]) - render :update do |page| - if @order.update_attributes(params[:order]) - page["note"].replace_html simple_format(@order.note) - page["edit_box"].hide - else - page["results"].replace_html :partial => "edit_note" - end + if @order.update_attributes(params[:order]) + render :layout => false + else + render :action => :edit_note, :layout => false end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f7e96760..ba82cb0f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -112,7 +112,7 @@ module ApplicationHelper :success => "Element.hide('loader')", :method => :get } - link_to_remote(text, remote_options.merge(options)) + link_to(text, options[:url], remote_options.merge(options)) end def format_roles(record) diff --git a/app/views/finance/balancing/_edit_note.html.haml b/app/views/finance/balancing/_edit_note.html.haml index 2344603a..4322556b 100644 --- a/app/views/finance/balancing/_edit_note.html.haml +++ b/app/views/finance/balancing/_edit_note.html.haml @@ -1,9 +1,4 @@ %h2 Notiz bearbeiten -- remote_form_for 'order', @order, :url => {:action => 'update_note', :id => @order}, | - :before => "Element.show('loader')", :success => "Element.hide('loader')" do |form| | - = form.error_messages - = form.text_area "note", :size => "60x20" - %p - = submit_tag "Speichern" - | - = link_to_function 'Abbrechen', "Element.hide('edit_box')" \ No newline at end of file += simple_form_for @order, url: update_note_finance_order_path(@order), remote: true, method: :put do |f| + = f.input :note, inner_html: {size: "60x20"} + = f.submit \ No newline at end of file diff --git a/app/views/finance/balancing/edit_note.js.erb b/app/views/finance/balancing/edit_note.js.erb new file mode 100644 index 00000000..1a4766fe --- /dev/null +++ b/app/views/finance/balancing/edit_note.js.erb @@ -0,0 +1 @@ +$.fancybox('<%= escape_javascript(render("edit_note")) %>'); \ No newline at end of file diff --git a/app/views/finance/balancing/new.html.haml b/app/views/finance/balancing/new.html.haml index 49d7870c..3df59ce2 100644 --- a/app/views/finance/balancing/new.html.haml +++ b/app/views/finance/balancing/new.html.haml @@ -35,14 +35,12 @@ = simple_format @order.note - else %p Hier kannst Du deine Abrechnung kommentieren - = remote_link_to "Notiz bearbeiten", | - :update => 'edit_box', :url => {:action => 'edit_note', :id => @order}, | - :success => "Element.hide('loader'); Element.show('edit_box')" | + = link_to "Notiz bearbeiten", edit_note_finance_order_path(@order), remote: true .box_title %h2 Kommentare .column_content #comments - = render :partial => 'shared/comments' + = render :partial => 'shared/comments', locals: {comments: @order.comments} .left_column{:style => 'width: 69%'} .box_title @@ -53,6 +51,6 @@ %li= remote_link_to 'Bestellung bearbeiten', :update => 'results', :url => {:action => 'new', :id => @order, :view => 'editResults'} .column_content #results - = render :partial => 'edit_results_by_articles' + /= render :partial => 'edit_results_by_articles' %p= link_to_top #edit_box{:style => 'display:none'} \ No newline at end of file diff --git a/app/views/finance/balancing/update_note.js.erb b/app/views/finance/balancing/update_note.js.erb new file mode 100644 index 00000000..f91361ac --- /dev/null +++ b/app/views/finance/balancing/update_note.js.erb @@ -0,0 +1,2 @@ +$.fancybox.close(); +$('#note').html('<%= escape_javascript(simple_format(@order.note)) %>'); diff --git a/config/routes.rb b/config/routes.rb index 548a29cf..83f08d5d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -119,6 +119,14 @@ Foodsoft::Application.routes.draw do namespace :finance do root :to => 'balancing#index' + + resources :order, controller: 'balancing', path: 'balancing' do + member do + get :edit_note + put :update_note + end + end + match 'balancing/list' => 'balancing#list', :as => 'balancing' resources :invoices