From afb2c26ab31e013f9ba587fc2b593918f9926d03 Mon Sep 17 00:00:00 2001 From: benni Date: Fri, 10 Jun 2011 13:53:51 +0200 Subject: [PATCH] Fixed orders form. --- app/helpers/orders_helper.rb | 7 +- app/models/order.rb | 4 +- app/views/orders/_form.html.haml | 130 ++++++++++++++---------------- app/views/orders/edit.html.haml | 8 +- app/views/orders/index.haml | 14 ++-- app/views/orders/new.html.haml | 6 +- public/javascripts/application.js | 2 +- 7 files changed, 77 insertions(+), 94 deletions(-) diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index ffb2e4c2..de115ce7 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -12,8 +12,9 @@ module OrdersHelper end def options_for_suppliers_to_select - suppliers = Supplier.without_deleted.collect {|s| [ s.name, url_for(:action => "new", :supplier_id => s)] } - stockit = [["Lager", url_for(:action => 'new', :supplier_id => 0)]] - options_for_select(stockit + suppliers) + options = [["Lieferantin/Lager auswählen"]] + options += Supplier.all.map {|s| [ s.name, url_for(:action => "new", :supplier_id => s)] } + options += [["Lager", url_for(:action => 'new', :supplier_id => 0)]] + options_for_select(options) end end diff --git a/app/models/order.rb b/app/models/order.rb index 93cabc57..79a2596b 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -37,12 +37,12 @@ class Order < ActiveRecord::Base def articles_for_ordering if stockit? - StockArticle.available.without_deleted(:include => :article_category, + StockArticle.available.all(:include => :article_category, :order => 'article_categories.name, articles.name').reject{ |a| a.quantity_available <= 0 }.group_by { |a| a.article_category.name } else - supplier.articles.available.without_deleted.group_by { |a| a.article_category.name } + supplier.articles.available.all.group_by { |a| a.article_category.name } end end diff --git a/app/views/orders/_form.html.haml b/app/views/orders/_form.html.haml index c5ba0856..3a153815 100644 --- a/app/views/orders/_form.html.haml +++ b/app/views/orders/_form.html.haml @@ -1,73 +1,63 @@ -= form.error_messages += simple_form_for @order do |f| + .single_column + .box_title + %h2 Bestellung für #{@order.supplier.name} + .column_content + = f.hidden_field :supplier_id + = f.input :note + = f.input :starts + = f.input :ends -.single_column - .box_title - %h2 Bestellung - .column_content - = form.hidden_field :supplier_id - %p - Lieferantin: - = @order.name - %p - Notiz - %br/ - = form.text_area :note, :cols => 50, :rows => 5 - %p - Start - %br/ - = form.datetime_select :starts, :start_year => Time.now.year - 1 - %p - Ende - %br/ - = form.datetime_select :ends, :start_year => Time.now.year - 1, :include_blank => true + .box_title + %h2 Artikel + .column_content + - if (@template_orders && !@template_orders.empty?) + %p + %label{:for => 'template'} Benutze Artikelauswahl von + %select{:name => "template_id", :onchange => "useTemplate(this[this.selectedIndex].value)"} + %option{:value => "-1", :selected => "selected"} Bestellung auswählen... + - i = -1 + - for order in @template_orders + %option{:value => (i += 1)}= "#{h(order.name)} bis #{order.ends.strftime('%d. %b')}" + %table.list + %tr + %th= check_box_tag 'checkall', "1", false, { 'data-check-all' => 'form.order' } + %th Name + %th Notiz + - if @order.stockit? + %th Verfügbar + - else + %th Herkunft + %th Hersteller + %th Gebinde + %th Preis (netto/FC) + - for category_name, articles in @order.articles_for_ordering + %tr{:style => "background-color:#EFEFEF"} + %td + %td{:colspan => "6", :style => "text-align:left"} + %b=h category_name + - for article in articles + / check if the article is selected + - included = @order.order_articles.detect { |order_article| order_article.article_id == article.id } + - included_class = included ? ' selected' : '' + %tr{:class => cycle('even', 'odd') + ' click-me' + included_class, :id => article.id.to_s, :onclick => "checkRow('#{article.id}')"} + %td= check_box_tag "order[article_ids][]", article.id, included, { :id => "checkbox_#{article.id}", :onclick => "checkRow('#{article.id}')" } + %td=h article.name + %td=h truncate article.note, :length => 25 + - if @order.stockit? + %td= "#{article.quantity_available} * #{article.unit}" + - else + %td=h truncate article.origin, :length => 15 + %td=h truncate article.manufacturer, :length => 15 + %td= "#{article.unit_quantity} x #{article.unit}" + %td= "#{number_to_currency(article.price)} / #{number_to_currency(article.fc_price)}" + %tr + %td{:colspan => "6"} + = check_box_tag 'checkall', "1", false, { 'data-check-all' => 'form.order' } + Alle auswählen - .box_title - %h2 Artikel - .column_content - - if (@template_orders && !@template_orders.empty?) - %p - %label{:for => 'template'} Benutze Artikelauswahl von - %select{:name => "template_id", :onchange => "useTemplate(this[this.selectedIndex].value)"} - %option{:value => "-1", :selected => "selected"} Bestellung auswählen... - - i = -1 - - for order in @template_orders - %option{:value => (i += 1)}= "#{h(order.name)} bis #{order.ends.strftime('%d. %b')}" - %table.list - %tr - %th= check_box_tag 'checkall', "1", false, { :onclick => "checkUncheckAll(this)" } - %th Name - %th Notiz - - if @order.stockit? - %th Verfügbar - - else - %th Herkunft - %th Hersteller - %th Gebinde - %th Preis (netto/FC) - - for category_name, articles in @order.articles_for_ordering - %tr{:style => "background-color:#EFEFEF"} - %td - %td{:colspan => "6", :style => "text-align:left"} - %b=h category_name - - for article in articles - / check if the article is selected - - included = @order.order_articles.detect { |order_article| order_article.article_id == article.id } - - included_class = included ? ' selected' : '' - %tr{:class => cycle('even', 'odd') + ' click-me' + included_class, :id => article.id.to_s, :onclick => "checkRow('#{article.id}')"} - %td= check_box_tag "order[article_ids][]", article.id, included, { :id => "checkbox_#{article.id}", :onclick => "checkRow('#{article.id}')" } - %td=h article.name - %td=h truncate article.note, :length => 25 - - if @order.stockit? - %td= "#{article.quantity_available} * #{article.unit}" - - else - %td=h truncate article.origin, :length => 15 - %td=h truncate article.manufacturer, :length => 15 - %td= "#{article.unit_quantity} x #{article.unit}" - %td= "#{number_to_currency(article.price)} / #{number_to_currency(article.fc_price)}" - %tr - %td{:colspan => "6"} - = check_box_tag 'checkall', "1", false, { :onclick => "checkUncheckAll(this)" } - Alle auswählen + - if (@template_orders && !@template_orders.empty?) + = render :partial => 'template_orders_script' -- if (@template_orders && !@template_orders.empty?) - = render :partial => 'template_orders_script' \ No newline at end of file + = f.submit + = link_to "oder abbrechen", orders_path \ No newline at end of file diff --git a/app/views/orders/edit.html.haml b/app/views/orders/edit.html.haml index 7f3095bc..11472287 100644 --- a/app/views/orders/edit.html.haml +++ b/app/views/orders/edit.html.haml @@ -1,7 +1,3 @@ -- title _("Edit order") +- title "Bestellung bearbeiten" -- form_for @order do |form| - = render :partial => 'form', :locals => { :form => form } - = submit_tag "Speichern" - | - = link_to "Abbrechen", :action => 'show', :id => @order \ No newline at end of file += render :partial => 'form' diff --git a/app/views/orders/index.haml b/app/views/orders/index.haml index c2ba250f..e24cc2a6 100644 --- a/app/views/orders/index.haml +++ b/app/views/orders/index.haml @@ -1,12 +1,12 @@ - title "Bestellungen verwalten" -- if @current_user.role_orders? - %p - - form_tag do - Neue Bestellung anlegen für - %select{:onchange => "redirectTo(this)", :style => "font-size: 0.9em;margin-left:1em;"} - %option{:selected => 'selected'} Lieferantin auswählen... - = options_for_suppliers_to_select +%p + - form_tag do + Neue Bestellung anlegen für + = select_tag :switch_supplier, + options_for_suppliers_to_select, + :style => "font-size: 0.9em;margin-left:1em;", + 'data-redirect-to' => true %br/ .left_column{:style => "width:55em"} .box_title diff --git a/app/views/orders/new.html.haml b/app/views/orders/new.html.haml index ee3cb48a..bc67fe2b 100644 --- a/app/views/orders/new.html.haml +++ b/app/views/orders/new.html.haml @@ -1,7 +1,3 @@ - title "Neue Bestellung anlegen" -- form_for @order do |form| - = render :partial => 'form', :locals => { :form => form } - = submit_tag "Bestellung online stellen" - | - = link_to "Abbrechen", orders_path \ No newline at end of file += render :partial => 'form', :locals => { :f => f } diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 561be4d9..ced3fbc6 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -21,7 +21,7 @@ $(function() { return false; }); - // Check/Uncheck all checkboxes for s specific form + // Check/Uncheck all checkboxes for a specific form $('input[data-check-all]').live('click', function() { var status = $(this).is(':checked') $($(this).data('check-all')).find('input[type="checkbox"]').each(function() {