From 1e3341151642a2960eac5c93f8eb5fd5c6e6cd69 Mon Sep 17 00:00:00 2001 From: benni Date: Thu, 19 May 2011 19:49:37 +0200 Subject: [PATCH] refactored some js stuff. Fixed forms in article modul. --- app/controllers/articles_controller.rb | 19 ++-- app/controllers/home_controller.rb | 3 +- app/helpers/articles_helper.rb | 4 +- app/views/articles/_article.html.haml | 20 ++++ app/views/articles/_article_row.rhtml | 25 ----- app/views/articles/_articles.html.haml | 18 ++- app/views/articles/_edit.haml | 7 -- app/views/articles/_new_article_row.haml | 2 - app/views/articles/create.js.erb | 2 +- app/views/articles/destroy.js.erb | 4 +- app/views/articles/edit_all.rhtml | 102 +++++++++-------- app/views/articles/index.haml | 21 ++-- app/views/articles/parse_upload.html.haml | 4 +- app/views/articles/update.js.erb | 2 +- app/views/articles/upload.html.haml | 10 +- .../foodcoop/ordergroups/index.html.haml | 20 +--- app/views/foodcoop/users/index.html.haml | 16 +-- app/views/home/index.html.haml | 2 +- app/views/pages/show.html.haml | 4 +- app/views/shared/_workgroup_members.haml | 2 +- config/locales/de.yml | 1 + config/routes.rb | 3 - lib/foodcoop.rb | 35 ------ public/javascripts/application.js | 105 ++++++++++-------- public/stylesheets/main.css | 2 +- 25 files changed, 184 insertions(+), 249 deletions(-) create mode 100644 app/views/articles/_article.html.haml delete mode 100644 app/views/articles/_article_row.rhtml delete mode 100644 app/views/articles/_edit.haml delete mode 100644 app/views/articles/_new_article_row.haml delete mode 100644 lib/foodcoop.rb diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index aeed1c88..e98f279f 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -76,7 +76,7 @@ class ArticlesController < ApplicationController # Renders a form for editing all articles from a supplier def edit_all - @articles = @supplier.articles.without_deleted + @articles = @supplier.articles end # Updates all article of specific supplier @@ -130,14 +130,14 @@ class ArticlesController < ApplicationController articles.each {|a| a.update_attribute(:availability, true) } flash[:notice] = 'Alle gewählten Artikel wurden auf "verfügbar" gesetzt' else - flash[:error] = 'Keine Aktion ausgewählt!' + flash[:alert] = 'Keine Aktion ausgewählt!' end # action succeded - redirect_to supplier_articles_path(@supplier, :per_page => params[:per_page]) + redirect_to supplier_articles_url(@supplier, :per_page => params[:per_page]) - rescue => e - flash[:error] = 'Ein Fehler ist aufgetreten: ' + e - redirect_to supplier_articles_path(@supplier, :per_page => params[:per_page]) + rescue => error + redirect_to supplier_articles_url(@supplier, :per_page => params[:per_page]), + :alert => "Ein Fehler ist aufgetreten: #{error}" end # lets start with parsing articles from uploaded file, yeah @@ -174,10 +174,9 @@ class ArticlesController < ApplicationController end @articles << article end - flash.now[:notice] = @articles.size.to_s + " articles are parsed successfully." - rescue => e - flash[:error] = "An error has occurred: " + e.message - redirect_to upload_supplier_articles_path(@supplier) + flash.now[:notice] = "#{@articles.size} articles are parsed successfully." + rescue => error + redirect_to upload_supplier_articles_path(@supplier), :alert => "An error has occurred: #{error.message}" end end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 266e9a6f..f857992b 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,6 +1,5 @@ class HomeController < ApplicationController - helper :messages - + def index # unaccepted tasks @unaccepted_tasks = @current_user.unaccepted_tasks diff --git a/app/helpers/articles_helper.rb b/app/helpers/articles_helper.rb index f6b2458f..8df06524 100644 --- a/app/helpers/articles_helper.rb +++ b/app/helpers/articles_helper.rb @@ -6,9 +6,9 @@ module ArticlesHelper end def row_classes(article) - classes = " click-me" + classes = " " classes += " unavailable" if !article.availability - classes += " just_updated" if @article.recently_updated && @article.availability + classes += " just_updated" if article.recently_updated && article.availability classes end end \ No newline at end of file diff --git a/app/views/articles/_article.html.haml b/app/views/articles/_article.html.haml new file mode 100644 index 00000000..2f4fa38c --- /dev/null +++ b/app/views/articles/_article.html.haml @@ -0,0 +1,20 @@ +%tr{ :class => cycle('even','odd') + row_classes(article)}[article] + %td= check_box_tag 'selected_articles[]', article.id.to_s, false, {:id => "checkbox_#{article.id}", 'data-ignore-onchange' => true} + %td{'data-check-this' => "#checkbox_#{article.id}", :class => 'click-me'}= article.name + %td= article.origin + %td= truncate(article.article_category.name, :length => 11) if article.article_category + %td= article.unit + %td= truncate(article.note, :length => 11) + %td= article.unit_quantity + %td{:class => "currency"} + %acronym{:title => "zuletzt geändert: #{format_date(article.updated_at)} | Brutto: #{number_to_currency(article.gross_price)}"} + = number_to_currency(article.price) + %td= number_to_percentage(article.tax) if article.tax != 0 + %td= number_to_currency(article.deposit) if article.deposit != 0 + %td + = link_to icon(:edit), edit_supplier_article_path(@supplier, article), + :remote => true + = link_to icon(:delete), [@supplier, article], + :method => :delete, :confirm => 'Bist du sicher?', :remote => true + + \ No newline at end of file diff --git a/app/views/articles/_article_row.rhtml b/app/views/articles/_article_row.rhtml deleted file mode 100644 index fc26c2b5..00000000 --- a/app/views/articles/_article_row.rhtml +++ /dev/null @@ -1,25 +0,0 @@ - - <%= check_box_tag 'selected_articles[]', @article.id.to_s, false, - {:id => "checkbox_#{@article.id.to_s}", :onclick => "checkRow('#{@article.id.to_s}')"} %> - -<%= @article.name -%> -<%= @article.origin -%> -<%= truncate(@article.article_category.name, :length => 11) if @article.article_category -%> -<%= @article.unit -%> -<%= truncate(@article.note, :length => 11) -%> -<%= @article.unit_quantity -%> - - - <%= number_to_currency(@article.price) -%> - - -<%= number_to_percentage(@article.tax) if @article.tax != 0 -%> -<%= number_to_currency(@article.deposit) if @article.deposit != 0 -%> - - <%= link_to icon(:edit, :onclick => "checkRow('#{@article.id.to_s}')"), edit_supplier_article_path(@supplier, @article), - :remote => true %> - <%= link_to icon(:delete, :onclick => "checkRow('#{@article.id.to_s}')"), [@supplier, @article], - :method => :delete, :confirm => 'Bist du sicher?', :remote => true %> - - \ No newline at end of file diff --git a/app/views/articles/_articles.html.haml b/app/views/articles/_articles.html.haml index 33d7a17f..2a79e1f3 100644 --- a/app/views/articles/_articles.html.haml +++ b/app/views/articles/_articles.html.haml @@ -25,7 +25,7 @@ %th[sort_td_class_helper "note"] = sort_link_helper "Notiz", "note" %th{:style => "width: 4em;"} Gebgr. - %th{:style => "width: 4em;"} Preis + %th{:style => "width: 5em;"} Preis %th{:style => "width: 3.5em;"} MwSt %th{:style => "width: 4em;"} Pfand %th{:style => "width: 3em;"} @@ -33,19 +33,17 @@ %tbody#listbody - if @total > 0 - - for @article in @articles - %tr{ :class => cycle('even','odd') + row_classes(@article), :id => @article.id, :onclick => "checkRow('#{@article.id.to_s}')"} - = render :partial => 'article_row' + - for article in @articles + = render(article) %tfoot %tr %td{:colspan => '11'} - = check_box_tag :checkall, 1, false, :onclick => 'checkUncheckAll(this)' - %select{:name => "selected_action"} + = check_box_tag :checkall, 1, false, 'data-check-all' => '#articlesInListForm', 'data-ignore-onchange' => true + %select{:name => "selected_action", 'data-submit-onchange' => true} %option{:value => '', :selected => 'selected'} Aktion wählen ... - %option{:value => "destroy", :onclick => "if (confirm('Willst Du wirklich alle gewählten Artikel löschen?')) { this.up('form').submit(); }; return false;"} Artikel löschen - %option{:value => "setNotAvailable", :onclick => "this.up('form').submit()"} Artikel sind nicht mehr verfügbar - %option{:value => "setAvailable", :onclick => "this.up('form').submit()"} Artikel sind verfügbar - + %option{:value => "destroy", 'data-confirm' => 'Willst Du wirklich alle gewählten Artikel löschen?'} Artikel löschen + %option{:value => "setNotAvailable"} Artikel sind nicht mehr verfügbar + %option{:value => "setAvailable"} Artikel sind verfügbar = hidden_field_tag 'supplier_id', @supplier.id %p= pagination_links_remote @articles, :params => {:sort => params[:sort]} diff --git a/app/views/articles/_edit.haml b/app/views/articles/_edit.haml deleted file mode 100644 index 10e473dc..00000000 --- a/app/views/articles/_edit.haml +++ /dev/null @@ -1,7 +0,0 @@ -%h2 - Bearbeiten von - = @article.name -zuletzt aktualisiert am: -= format_time(@article.updated_at) - -= render :partial => "form" diff --git a/app/views/articles/_new_article_row.haml b/app/views/articles/_new_article_row.haml deleted file mode 100644 index c236606a..00000000 --- a/app/views/articles/_new_article_row.haml +++ /dev/null @@ -1,2 +0,0 @@ -%tr{:class => row_classes(@article), :id => @article.id, :onclick => "checkRow('#{@article.id.to_s}')"} - = render :partial => 'article_row' \ No newline at end of file diff --git a/app/views/articles/create.js.erb b/app/views/articles/create.js.erb index a06276fd..001d42eb 100644 --- a/app/views/articles/create.js.erb +++ b/app/views/articles/create.js.erb @@ -1,2 +1,2 @@ -$('#listbody').prepend('<%= escape_javascript(render("new_article_row")) %>'); +$('#listbody').prepend('<%= escape_javascript(render(@article)) %>'); $.fancybox.close(); \ No newline at end of file diff --git a/app/views/articles/destroy.js.erb b/app/views/articles/destroy.js.erb index d59480f9..17ec0157 100644 --- a/app/views/articles/destroy.js.erb +++ b/app/views/articles/destroy.js.erb @@ -1,5 +1,5 @@ <% if @order %> -$('#<%= @article.id %>').after('<%= escape_javascript(render("destroy_active_article")) %>'); +$('#article_<%= @article.id %>').after('<%= escape_javascript(render("destroy_active_article")) %>'); <% else %> -$('#<%= @article.id %>').remove(); +$('#article_<%= @article.id %>').remove(); <% end %> \ No newline at end of file diff --git a/app/views/articles/edit_all.rhtml b/app/views/articles/edit_all.rhtml index 4183db2e..40147f63 100644 --- a/app/views/articles/edit_all.rhtml +++ b/app/views/articles/edit_all.rhtml @@ -1,64 +1,62 @@ -

Alle Artikel von <%= @supplier.name %> bearbeiten

+<% title "Alle Artikel von #{@supplier.name} bearbeiten" %>
- <% form_tag do -%> - <%= select_tag :switch_supplier, - options_for_select( Supplier.all.collect {|s| [s.name, url_for(edit_all_supplier_articles_path(s))] }, - url_for(edit_all_supplier_articles_path(@supplier)) ), - :onchange => "redirectTo(this)", - :style => "font-size: 0.9em;margin-left:1em;" %> - <% end %> -
+ <%= select_tag :switch_supplier, + options_for_select( Supplier.all.collect {|s| [s.name, edit_all_supplier_articles_url(s)] }, + edit_all_supplier_articles_url(@supplier)), + 'data-redirect-to' => true, + :style => "font-size: 0.9em;margin-left:1em;" %> +

- - Pflichtfelder sind: Name, Einheit, (netto) Preis und Bestellnummer. - -

- <% form_tag(update_all_supplier_articles_path(@supplier)) do %> - - - - - - - - - - - - - - - - <% for article in @articles %> - <% fields_for 'articles[]', article do |form| %> - > - - - - - - - - - - - <% end %> - <% end %> - - -
verf.NameEinheitPreisGebGrBest.Nr.NotizKategorieMwSt.Pfand
- <%= form.check_box 'availability' -%> - <%= form.text_field 'name', :size => 0 -%> - <%= form.text_field 'unit', :size => 5 -%><%= form.text_field 'price', :size => 4 -%><%= form.text_field 'unit_quantity', :size => 4 -%><%= form.text_field 'order_number', :size => 6 -%><%= form.text_field 'note', :size => 15 -%><%= form.select 'article_category_id', ArticleCategory.find(:all).collect {|a| [ a.name, a.id ] }, { :include_blank => true } -%><%= form.text_field 'tax', :size => 4 -%><%= form.text_field 'deposit', :size => 4 -%>

- Achtung, alle Artikel werden aktualisiert!
- <%= submit_tag 'Alle Artikel aktualisieren'%> | <%= link_to 'Abbrechen', supplier_articles_path(@supplier) %> + + Pflichtfelder sind: Name, Einheit, (netto) Preis und Bestellnummer. + +

+ <%= form_tag(update_all_supplier_articles_path(@supplier)) do %> + + + + + + + + + + + + + + + + <% for article in @articles %> + <%= fields_for 'articles[]', article do |form| %> + > + + + + + + + + + + + <% end %> + <% end %> + + +
verf.NameEinheitPreisGebGrBest.Nr.NotizKategorieMwSt.Pfand
+ <%= form.check_box 'availability' -%> + <%= form.text_field 'name', :size => 0 -%> + <%= form.text_field 'unit', :size => 5 -%><%= form.text_field 'price', :size => 4 -%><%= form.text_field 'unit_quantity', :size => 4 -%><%= form.text_field 'order_number', :size => 6 -%><%= form.text_field 'note', :size => 15 -%><%= form.select 'article_category_id', ArticleCategory.find(:all).collect {|a| [ a.name, a.id ] }, { :include_blank => true } -%><%= form.text_field 'tax', :size => 4 -%><%= form.text_field 'deposit', :size => 4 -%>

+ Achtung, alle Artikel werden aktualisiert!
+ <%= submit_tag 'Alle Artikel aktualisieren'%> | <%= link_to 'Abbrechen', supplier_articles_path(@supplier) %> <% end %>
\ No newline at end of file diff --git a/app/views/articles/index.haml b/app/views/articles/index.haml index d8d26897..d174bcbd 100644 --- a/app/views/articles/index.haml +++ b/app/views/articles/index.haml @@ -7,19 +7,17 @@ %li Zugriff auf externe Datenbank %ul - %li= link_to "Suchen/Importieren", "#import", 'data-toggle_this' => '#import' + %li= link_to "Suchen/Importieren", "#import", 'data-toggle-this' => '#import' %li= link_to "Synchronisieren", sync_supplier_articles_path(@supplier), :method => :post #change_supplier{:style => "padding:0 0 0.5em 0.7em;"} %span{:style => "float:left"} Lieferantin wechseln: - = form_tag do - = select_tag :switch_supplier, - options_for_select( Supplier.all(:order => 'name').collect {|s| [s.name, url_for(supplier_articles_path(s))] }, - url_for(supplier_articles_path(@supplier)) ), - :onchange => "redirectTo(this)", - :style => "font-size: 0.9em;margin-left:1em;" + = select_tag :switch_supplier, + options_for_select(Supplier.order(:name).map {|s| [s.name, supplier_articles_url(s)] }, supplier_articles_url(@supplier)), + :style => "font-size: 0.9em;margin-left:1em;", + 'data-redirect-to' => true - unless @supplier.shared_supplier.nil? #import.single_column{:style => "display:none; clear:both"} @@ -40,7 +38,7 @@ = check_box_tag "regional", "1", false #search_results // "import_search_results" will be rendered - = link_to "Schließen", "#import", 'data-toggle_this' => '#import' + = link_to "Schließen", "#import", 'data-toggle-this' => '#import' .single_column{:style => 'width:100%; clear:both'} .box_title @@ -57,12 +55,13 @@ #article_filter #article_search_form{:style=>"display:inline;"} - = form_tag supplier_articles_path(@supplier), :method => :get, :remote => true do + = form_tag supplier_articles_path(@supplier), :method => :get, :remote => true, 'data-submit-onchange' => true do %label{:for => 'article_name'} Suche im Artikelnamen: - = text_field_tag("query", params['query'], :size => 10 ) + = text_field_tag :query, params[:query], :size => 10 = submit_tag "Suchen" - = form_tag update_selected_supplier_articles_path(@supplier), :id => "articlesInListForm" do + = form_tag update_selected_supplier_articles_path(@supplier), :id => "articlesInListForm", + 'data-submit-onchange' => true do #table= render 'articles' #edit_article{:style => "display:none"} diff --git a/app/views/articles/parse_upload.html.haml b/app/views/articles/parse_upload.html.haml index 67d411d9..78052fb9 100644 --- a/app/views/articles/parse_upload.html.haml +++ b/app/views/articles/parse_upload.html.haml @@ -5,7 +5,7 @@ %br/ Achtung, momentan gibt es keine Überprüfung auf doppelte Artikel. -- form_tag(create_from_upload_supplier_articles_path(@supplier)) do += form_tag(create_from_upload_supplier_articles_path(@supplier)) do %table %tr %th Nummer @@ -20,7 +20,7 @@ %th Gebindegröße %th Kategorie - for article in @articles - - fields_for "articles[]", article do |form| + = fields_for "articles[]", article do |form| %tr{:class => cycle('even', 'odd')} %td= form.text_field 'order_number', :size => 6 %td= form.text_field 'name', :size => 0 diff --git a/app/views/articles/update.js.erb b/app/views/articles/update.js.erb index 1f2a3df0..d0bbc47e 100644 --- a/app/views/articles/update.js.erb +++ b/app/views/articles/update.js.erb @@ -1,2 +1,2 @@ -$('#<%= @article.id %>').html('<%= escape_javascript(render("article_row")) %>'); +$('#article_<%= @article.id %>').replaceWith('<%= escape_javascript(render(@article)) %>'); $.fancybox.close(); \ No newline at end of file diff --git a/app/views/articles/upload.html.haml b/app/views/articles/upload.html.haml index 6c64fcb0..dcb3bfe2 100644 --- a/app/views/articles/upload.html.haml +++ b/app/views/articles/upload.html.haml @@ -12,12 +12,12 @@ %i Korrekte Reihenfolge der Spalten: %br/ - = ["Status (x=ausgelistet)", "Bestellnummer", "Name", "Notiz", "Hersteller", "Herkunft", | - "Einheit", "Preis(netto)", "MwSt", "Pfand", "Gebindegröße", | - "Staffelmenge", "Staffelpreis", "Kategorie"].join(" | ") | + = ["Status (x=ausgelistet)", "Bestellnummer", "Name", "Notiz", "Hersteller", "Herkunft", + "Einheit", "Preis(netto)", "MwSt", "Pfand", "Gebindegröße", + "Staffelmenge", "Staffelpreis", "Kategorie"].join(" | ") #uploadArticles.uploadForm - - form_for :articles, :url => parse_upload_supplier_articles_path(@supplier), | - :html => { :multipart => true } do |form| | + = form_for :articles, :url => parse_upload_supplier_articles_path(@supplier), + :html => { :multipart => true } do |form| %p= form.file_field "file" %p= submit_tag "Datei hochladen" diff --git a/app/views/foodcoop/ordergroups/index.html.haml b/app/views/foodcoop/ordergroups/index.html.haml index b60da1f5..14a5888a 100644 --- a/app/views/foodcoop/ordergroups/index.html.haml +++ b/app/views/foodcoop/ordergroups/index.html.haml @@ -5,23 +5,13 @@ %h2 Übersicht .column_content #filter{:style => "margin-right:2em;"} - = form_tag foodcoop_ordergroups_path, :method => :get, :style=>"display:inline;", :id => 'ordergroup_search', :remote => true do + = form_tag foodcoop_ordergroups_path, :method => :get, :style=>"display:inline;", :id => 'ordergroup_search', + :remote => true, 'data-submit-onchange' => true do %label{:for => 'article_name'} Suche nach Name: - = text_field_tag(:query, params[:query], :size => 10 ) + = text_field_tag :query, params[:query], :size => 10 %label{:for => 'only_active'} Nur aktive: - = check_box_tag('only_active') + = check_box_tag 'only_active', 1, params[:only_active] %small (mindestens einmal in den letzten 3 Monaten bestellt) #ordergroups - = render :partial => "ordergroups" - -- content_for :head do - :javascript - $(function() { - $('#query').observe_field(1, function() { - $('#ordergroup_search').submit(); - }); - $('#only_active').click(function() { - $('#ordergroup_search').submit(); - }); - }); \ No newline at end of file + = render :partial => "ordergroups" \ No newline at end of file diff --git a/app/views/foodcoop/users/index.html.haml b/app/views/foodcoop/users/index.html.haml index 8932d255..00951486 100644 --- a/app/views/foodcoop/users/index.html.haml +++ b/app/views/foodcoop/users/index.html.haml @@ -1,14 +1,3 @@ -- content_for :head do - :javascript - $(function() { - $('#query').observe_field(1, function() { - $('#user_search').submit(); - }); - $('#sort_by_ordergroups').click(function() { - $('#user_search').submit(); - }); - }); - %h1 Mitglieder der Foodcoop %p %i @@ -24,9 +13,10 @@ .column_content - unless params[:sort_by_ordergroups] #user_filter{:style => "float:left; margin-right:2em;"} - = form_tag foodcoop_users_path, :method => :get, :style=>"display:inline;", :id => 'user_search', :remote => true do + = form_tag foodcoop_users_path, :method => :get, :style=>"display:inline;", :id => 'user_search', + :remote => true, 'data-submit-onchange' => true do %label{:for => 'article_name'} Suche nach Name: - = text_field_tag(:query, params[:query], :size => 10 ) + = text_field_tag :query, params[:query], :size => 10 Nach Bestellgruppen sortieren: = check_box_tag :sort_by_ordergroups, 1, params[:sort_by_ordergroups] diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index d2fef72c..edbd6ba3 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -42,7 +42,7 @@ .box_title %h2 Neuste Nachrichten .column_content - = render :partial => 'messages/messages', :locals => {:messages => Message.public.order(:create_at.desc).limit(5), :subject_length => 70} + = render :partial => 'messages/messages', :locals => {:messages => Message.public.order(:created_at.desc).limit(5), :subject_length => 70} %br/ = link_to "Alle Nachrichten einsehen", messages_path diff --git a/app/views/pages/show.html.haml b/app/views/pages/show.html.haml index 58f9de77..470de1f4 100644 --- a/app/views/pages/show.html.haml +++ b/app/views/pages/show.html.haml @@ -16,9 +16,9 @@ #sidebar #sidebar-links = link_to "Bearbeiten", edit_page_path(@page) - = link_to "Versionen (#{@page.versions.count})", "#versions", 'data-toggle_this' => '#versions' + = link_to "Versionen (#{@page.versions.count})", "#versions", 'data-toggle-this' => '#versions' - unless @page.children.empty? - = link_to "Unterseiten", "#subpages", 'data-toggle_this' => '#subpages' + = link_to "Unterseiten", "#subpages", 'data-toggle-this' => '#subpages' #versions{:style => "display:none"} .box_title %h2 Versionen diff --git a/app/views/shared/_workgroup_members.haml b/app/views/shared/_workgroup_members.haml index a09d6fbe..f1470f5a 100644 --- a/app/views/shared/_workgroup_members.haml +++ b/app/views/shared/_workgroup_members.haml @@ -1,5 +1,5 @@ - for workgroup in Workgroup.all - %h4= link_to workgroup.name, "#", 'data-toggle_this' => "#workgroup_#{workgroup.id}" + %h4= link_to workgroup.name, "#", 'data-toggle-this' => "#workgroup_#{workgroup.id}" %ul{:style => "display:none"}[workgroup] - for user in workgroup.users.order("nick") %li= "#{user.nick} (#{user.ordergroup.try(:name)})" diff --git a/config/locales/de.yml b/config/locales/de.yml index 5d293998..042f7409 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -168,6 +168,7 @@ de: unit_quantity: Gebindegröße tax: MwSt deposit: Pfand + article_category: Kategorie stock_article: price: Nettopreis user: diff --git a/config/routes.rb b/config/routes.rb index 5e711ada..cad8ccac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,9 +2,6 @@ Foodsoft::Application.routes.draw do get "sessions/new" - # Use routing filter to select foodcoop config and datbase -# filter :foodcoop - root :to => redirect("/#{Foodsoft.env}") scope '/:foodcoop', :defaults => { :foodcoop => Foodsoft.env } do diff --git a/lib/foodcoop.rb b/lib/foodcoop.rb deleted file mode 100644 index f4d61c32..00000000 --- a/lib/foodcoop.rb +++ /dev/null @@ -1,35 +0,0 @@ -module RoutingFilter - class Foodcoop < Filter - def around_recognize(path, env, &block) - token = extract_token!(path) # remove the token from the beginning of the path - yield.tap do |params| # invoke the given block (calls more filters and finally routing) - params[:foodcoop] = token if token # set recognized token to the resulting params hash - end - end - - def around_generate(*args, &block) - token = args.extract_options!.delete(:foodcoop) # extract the passed :token option - token = Foodsoft.env if token.nil? # default to Foodsoft.env - - yield.tap do |result| - if token - url = result.is_a?(Array) ? result.first : result - prepend_token!(url, token) - end - end - end - - protected - - def extract_token!(path) - foodcoop = nil - path.sub! %r(^/([a-zA-Z0-9]*)(?=/|$)) do foodcoop = $1; '' end - foodcoop - end - - def prepend_token!(url, token) - url.sub!(%r(^(http.?://[^/]*)?(.*))) { "#{$1}/#{token}#{$2}" } - end - - end -end \ No newline at end of file diff --git a/public/javascripts/application.js b/public/javascripts/application.js index fcf9a074..e4059468 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -1,58 +1,71 @@ // Load following statements, when DOM is ready $(function() { - $('a[data-toggle_this]').click(function() { - $($(this).data('toggle_this')).toggle(); + + // Show/Hide a specific DOM element + $('a[data-toggle-this]').click(function() { + $($(this).data('toggle-this')).toggle(); return false; }); + + // Check/Uncheck a single checkbox + $('[data-check-this]').live('click', function() { + var checkbox = $($(this).data('check-this')); + checkbox.attr('checked', !checkbox.is(':checked')); + highlightRow(checkbox); + return false; + }); + + // Check/Uncheck all checkboxes for s specific form + $('input[data-check-all]').live('click', function() { + var status = $(this).is(':checked') + $($(this).data('check-all')).find('input[type="checkbox"]').each(function() { + $(this).attr('checked', status); + highlightRow($(this)); + }); + }); + + // Submit form when changing a select menu. + $('form[data-submit-onchange] select').live('change', function() { + var confirmMessage = $(this).children(':selected').data('confirm'); + if (confirmMessage && confirm(confirmMessage)) { + $(this).parents('form').submit(); + } else { + $(this).parents('form').submit(); + } + return false; + }); + + // Submit form when changing text of an input field + // Use jquery observe_field plugin + $('form[data-submit-onchange] input[type=text]').each(function() { + $(this).observe_field(1, function() { + $(this).parents('form').submit(); + }); + }); + + // Submit form when clicking on checkbox + $('form[data-submit-onchange] input[type=checkbox]:not(input[data-ignore-onchange])').click(function() { + $(this).parents('form').submit(); + }); + + $('[data-redirect-to]').bind('change', function() { + var newLocation = $(this).children(':selected').val(); + if (newLocation != "") { + document.location.href = newLocation; + } + }); }); -// Place your application-specific JavaScript functions and classes here -// This file is automatically included by javascript_include_tag :defaults - -// for checkboxes. just insert box in same form-element like: -// -// credit to Shawn Olson & http://www.shawnolson.net -function checkUncheckAll(theElement) { - var theForm = theElement.form, z = 0; - for(z=0; z