From a4474213bebb81dccdab09b9954e7ff6710df31d Mon Sep 17 00:00:00 2001 From: Julius Date: Sat, 12 Jan 2013 16:04:00 +0100 Subject: [PATCH 01/14] tell git to ignore secret_token.rb --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c554eb26..2bd55feb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ log/*.log tmp/**/* config/*.yml +config/initializers/secret_token.rb db/*.sqlite3 nbproject/ config/environments/development.rb From ecb7ce7cd3fadcd3fec221f810f7351adea7f36a Mon Sep 17 00:00:00 2001 From: Julius Date: Sat, 12 Jan 2013 16:11:07 +0100 Subject: [PATCH 02/14] Remove secret_token.rb from git's tracked files --- config/initializers/secret_token.rb | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 config/initializers/secret_token.rb diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb deleted file mode 100644 index fcbd6c1e..00000000 --- a/config/initializers/secret_token.rb +++ /dev/null @@ -1,7 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -Foodsoft::Application.config.secret_token = '2be5574568ff4d270b108399078a8e485b363af84d441d02d2a6fd3fc51a8c015065790b7e414134e6d97ffc40da898a5a12f66f9de6b992b7ea96e7a34839b8' From 099e2b9b06bca02b205d15dd00c1872620c5b39f Mon Sep 17 00:00:00 2001 From: Julius Date: Sat, 12 Jan 2013 16:14:06 +0100 Subject: [PATCH 03/14] Add stock_article_selection (deleting multiple stock articles at once) --- app/controllers/stockit_controller.rb | 1 + .../stockit_selections_controller.rb | 56 +++++++++++++++ app/helpers/application_helper.rb | 2 +- .../stock_article_selections_helper.rb | 2 + app/helpers/stockit_helper.rb | 11 +++ app/models/stock_article_selection.rb | 24 +++++++ app/views/stockit/index.html.haml | 72 ++++++++++--------- .../stockit_selections/_overview.html.haml | 19 +++++ app/views/stockit_selections/index.html.haml | 7 ++ app/views/stockit_selections/show.html.haml | 18 +++++ config/routes.rb | 8 +++ ...2121840_create_stock_article_selections.rb | 18 +++++ db/schema.rb | 13 +++- 13 files changed, 217 insertions(+), 34 deletions(-) create mode 100644 app/controllers/stockit_selections_controller.rb create mode 100644 app/helpers/stock_article_selections_helper.rb create mode 100644 app/models/stock_article_selection.rb create mode 100644 app/views/stockit_selections/_overview.html.haml create mode 100644 app/views/stockit_selections/index.html.haml create mode 100644 app/views/stockit_selections/show.html.haml create mode 100644 db/migrate/20130112121840_create_stock_article_selections.rb diff --git a/app/controllers/stockit_controller.rb b/app/controllers/stockit_controller.rb index cdd9b633..2c130fce 100644 --- a/app/controllers/stockit_controller.rb +++ b/app/controllers/stockit_controller.rb @@ -3,6 +3,7 @@ class StockitController < ApplicationController def index @stock_articles = StockArticle.includes(:supplier, :article_category). order('suppliers.name, article_categories.name, articles.name') + @stock_article_selection = StockArticleSelection.new end def new diff --git a/app/controllers/stockit_selections_controller.rb b/app/controllers/stockit_selections_controller.rb new file mode 100644 index 00000000..ae498c40 --- /dev/null +++ b/app/controllers/stockit_selections_controller.rb @@ -0,0 +1,56 @@ +# encoding: utf-8 +class StockitSelectionsController < ApplicationController + + def index + @stock_article_selections = StockArticleSelection.all + end + + def show + @stock_article_selection = StockArticleSelection.find(params[:id]) + end + + def create + @stock_article_selection = StockArticleSelection.new(params[:stock_article_selection]) + @stock_article_selection.created_by = current_user + + if @stock_article_selection.save + redirect_to(@stock_article_selection, :notice => 'Löschvorschlag für gewählte Artikel wurde erstellt.') + else + @stock_articles = StockArticle.includes(:supplier, :article_category). + order('suppliers.name, article_categories.name, articles.name') + render 'stockit/index' + end + end + + def destroy # destroy (open or finished) selection without deleting articles + stock_article_selection = StockArticleSelection.find(params[:id]) + stock_article_selection.destroy + + redirect_to stock_article_selections_path, :notice => 'Löschvorschlag wurde verworfen.' + end + + def articles # destroy articles, finish selection + stock_article_selection = StockArticleSelection.find(params[:id]) + + destroyed_articles_count = 0 + failed_articles_count = 0 + stock_article_selection.stock_articles.each do |article| + begin + article.destroy # article.delete would save some effort, but validations are important + destroyed_articles_count += 1 + rescue => error # recover if article.destroy fails and continue with next article + failed_articles_count += 1 + end + end + + if destroyed_articles_count>0 # note that 1 successful article.destroy is enough to destroy selection + stock_article_selection.destroy + flash[:notice] = "#{destroyed_articles_count} gewählte Artikel sind nun gelöscht." + flash[:error] = "#{failed_articles_count} Artikel konnten nicht gelöscht werden." unless 0==failed_articles_count + else + flash[:error] = "Löschvorgang fehlgeschlagen. Es wurden keine Artikel gelöscht." + end + + redirect_to stock_articles_path + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 19269cdb..b5dfbaf5 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -142,7 +142,7 @@ module ApplicationHelper # offers a link for writing message to user # checks for nil (useful for relations) def link_to_user_message_if_valid(user) - user.nil? ? '??' : ( link_to user.nick, user_message_path(user), :title => 'Nachricht schreiben' ) + user.nil? ? '??' : ( link_to user.nick, new_message_path(:message => {:mail_to => user.id}), :title => 'Nachricht schreiben' ) end def bootstrap_flash diff --git a/app/helpers/stock_article_selections_helper.rb b/app/helpers/stock_article_selections_helper.rb new file mode 100644 index 00000000..9d7090f5 --- /dev/null +++ b/app/helpers/stock_article_selections_helper.rb @@ -0,0 +1,2 @@ +module StockArticleSelectionsHelper +end diff --git a/app/helpers/stockit_helper.rb b/app/helpers/stockit_helper.rb index 2888603c..c2665a96 100644 --- a/app/helpers/stockit_helper.rb +++ b/app/helpers/stockit_helper.rb @@ -1,7 +1,18 @@ +# encoding: utf-8 module StockitHelper def stock_article_classes(article) class_names = [] class_names << "unavailable" if article.quantity_available <= 0 class_names.join(" ") end + + def stock_article_delete_checkbox(article) + if article.quantity_available <= 0 + check_box_tag "stock_article_selection[stock_article_ids][]", article.id, false, + { :id => "checkbox_#{article.id}", :title => 'Zum löschen markieren' } + else + check_box_tag 'checkall', '1', false, + { :disabled => true, :title => 'Verfügbare Artikel können nicht gelöscht werden.', :class => 'unavailable' } + end + end end diff --git a/app/models/stock_article_selection.rb b/app/models/stock_article_selection.rb new file mode 100644 index 00000000..20aafd7a --- /dev/null +++ b/app/models/stock_article_selection.rb @@ -0,0 +1,24 @@ +# encoding: utf-8 +class StockArticleSelection < ActiveRecord::Base + + # Associations + has_and_belongs_to_many :stock_articles + belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id' + belongs_to :finished_by, :class_name => 'User', :foreign_key => 'finished_by_user_id' + + # Validations + validate :include_stock_articles + + def all_articles + all_articles = stock_article_ids + end + + protected + + def include_stock_articles + errors.add(:stock_articles, "Es muss mindestens ein Lagerartikel ausgewählt sein.") if stock_articles.empty? + end + + private + +end diff --git a/app/views/stockit/index.html.haml b/app/views/stockit/index.html.haml index 40e3410f..f19e767d 100644 --- a/app/views/stockit/index.html.haml +++ b/app/views/stockit/index.html.haml @@ -2,7 +2,7 @@ - content_for :javascript do :javascript $(function() { - $('tr.unavailable').hide(); + $('tr.unavailable,input.unavailable').hide(); }) .well.well-small @@ -12,7 +12,7 @@ Ansichtsoptionen %span.caret %ul.dropdown-menu - %li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable', tabindex: -1 + %li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable,input.unavailable', tabindex: -1 .btn-group = link_to "Neuen Lagerartikel anlegen", new_stock_article_path, class: 'btn btn-primary' @@ -20,6 +20,7 @@ class: 'btn' = link_to "Inventur anlegen", new_stock_taking_path, class: 'btn' = link_to "Inventurübersicht", stock_takings_path, class: 'btn' + = link_to 'Löschvorschläge', stock_article_selections_path, class: 'btn' .btn-group = link_to '#', data: {toggle: 'dropdown'}, class: 'btn dropdown-toggle' do @@ -29,36 +30,43 @@ - Supplier.all.each do |supplier| %li= link_to supplier.name, new_supplier_delivery_path(supplier), tabindex: -1 - -%table.table.table-hover#articles - %thead - %tr - %th Artikel - %th im Lager - %th davon bestellt - %th verfügbar - %th Einheit - %th Preis - %th MwSt - %th Lieferantin - %th Kategorie - %th - %tbody - - for article in @stock_articles - %tr{:class => stock_article_classes(article)} - %td=h article.name - %td= article.quantity - %td= article.quantity - article.quantity_available - %th= article.quantity_available - %td= article.unit - %td= article.price - %td= number_to_percentage article.tax - %td= link_to article.supplier.name, article.supplier - %td= article.article_category.name - %td - = link_to "Bearbeiten", edit_stock_article_path(article), class: 'btn btn-mini' - = link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?", - class: 'btn btn-mini btn-danger' += form_for @stock_article_selection do |form| + - if @stock_article_selection.errors.has_key?(:stock_articles) + .alert.alert-error + = @stock_article_selection.errors.get(:stock_articles).join(" ") + %table.table.table-hover#articles + %thead + %tr + %th= check_box_tag 'checkall', '1', false, + { 'data-check-all' => 'table#articles tr.unavailable', :title => 'Alle löschbaren Artikel', :class => 'unavailable' } + %th Artikel + %th im Lager + %th davon bestellt + %th verfügbar + %th Einheit + %th Preis + %th MwSt + %th Lieferantin + %th Kategorie + %th + %tbody + - for article in @stock_articles + %tr{:class => stock_article_classes(article)} + %td= stock_article_delete_checkbox(article) + %td=h article.name + %td= article.quantity + %td= article.quantity - article.quantity_available + %th= article.quantity_available + %td= article.unit + %td= article.price + %td= number_to_percentage article.tax + %td= link_to article.supplier.name, article.supplier + %td= article.article_category.name + %td + = link_to "Bearbeiten", edit_stock_article_path(article), class: 'btn btn-mini' + = link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?", + class: 'btn btn-mini btn-danger' + %p= submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' } %p Aktueller Lagerwert: = number_to_currency StockArticle.stock_value diff --git a/app/views/stockit_selections/_overview.html.haml b/app/views/stockit_selections/_overview.html.haml new file mode 100644 index 00000000..15f9b7f9 --- /dev/null +++ b/app/views/stockit_selections/_overview.html.haml @@ -0,0 +1,19 @@ + +%table.table.table-hover + %tr + %th Artikel + %th Erstellt am + %th Erstellt von + %th Optionen + + - stock_article_selections.each do |stock_article_selection| + %tr + %td=h truncate stock_article_selection.stock_articles.map{ |article| article.name}.join(', ') + %td=h stock_article_selection.created_at + %td=h link_to_user_message_if_valid stock_article_selection.created_by + %td + = link_to 'Anzeigen', stock_article_selection, class: 'btn btn-small' + = link_to "Artikel löschen", articles_stock_article_selection_path(stock_article_selection), :method => :delete, + :confirm => 'Diesen Löschvorschlag wirklich ausführen und markierte Artikel löschen?', class: 'btn btn-small btn-danger' + = link_to "Verwerfen", stock_article_selection, :method => :delete, + :confirm => 'Diesen Löschvorschlag wirklich verwerfen?', class: 'btn btn-small' diff --git a/app/views/stockit_selections/index.html.haml b/app/views/stockit_selections/index.html.haml new file mode 100644 index 00000000..99cac93f --- /dev/null +++ b/app/views/stockit_selections/index.html.haml @@ -0,0 +1,7 @@ +- title "Löschvorschläge für Lagerartikel" +- if @stock_article_selections.empty? + %p Es gibt keine ausstehenden Löschvorschläge. + %ul + %li= link_to "Löschvorschlag erstellen", stock_articles_path +- else + = render :partial => 'overview', :locals => {:stock_article_selections => @stock_article_selections} diff --git a/app/views/stockit_selections/show.html.haml b/app/views/stockit_selections/show.html.haml new file mode 100644 index 00000000..63ea5dfa --- /dev/null +++ b/app/views/stockit_selections/show.html.haml @@ -0,0 +1,18 @@ +- title "Löschvorschlag für #{@stock_article_selection.stock_articles.count} Lagerartikel" + +%dl + %dt Löschvorschlag vom: + %dd=h @stock_article_selection.created_at + %dt Erstellt durch: + %dd=h link_to_user_message_if_valid(@stock_article_selection.created_by) + %dt Zu löschende Artikel + - for article in @stock_article_selection.stock_articles + %dd=h article.name + + +%p + = link_to 'Artikel löschen', articles_stock_article_selection_path(@stock_article_selection), :method => :delete, + :confirm => 'Diesen Löschvorschlag wirklich ausführen und markierte Artikel löschen?', class: 'btn btn-danger' + = link_to 'Verwerfen', @stock_article_selection, :method => :delete, + :confirm => 'Diesen Löschvorschlag wirklich verwerfen?', class: 'btn' + = link_to 'Alle Löschvorschläge zeigen', stock_article_selections_path, class: 'btn' diff --git a/config/routes.rb b/config/routes.rb index aa8e0e29..9c27bbe7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -89,6 +89,14 @@ Foodsoft::Application.routes.draw do post :add_stock_article end end + + resources :stock_article_selections, :controller => 'stockit_selections', + :only => [ :create, :show, :index, :destroy ], :path => "/stock_articles/selections" do + member do + delete 'articles' + end + end + resources :stock_articles, :to => 'stockit' do collection do diff --git a/db/migrate/20130112121840_create_stock_article_selections.rb b/db/migrate/20130112121840_create_stock_article_selections.rb new file mode 100644 index 00000000..2ead9008 --- /dev/null +++ b/db/migrate/20130112121840_create_stock_article_selections.rb @@ -0,0 +1,18 @@ +class CreateStockArticleSelections < ActiveRecord::Migration + def up + create_table :stock_article_selections do |t| + t.integer :created_by_user_id + t.timestamps + end + + create_table :stock_article_selections_stock_articles, :id => false do |t| + t.integer :stock_article_id + t.integer :stock_article_selection_id + end + end + + def down + drop_table :stock_article_selections + drop_table :stock_article_selections_stock_articles + end +end diff --git a/db/schema.rb b/db/schema.rb index 188ea83b..bec2b950 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 => 20121230142516) do +ActiveRecord::Schema.define(:version => 20130112121840) do create_table "article_categories", :force => true do |t| t.string "name", :default => "", :null => false @@ -268,6 +268,17 @@ ActiveRecord::Schema.define(:version => 20121230142516) do add_index "pages", ["permalink"], :name => "index_pages_on_permalink" add_index "pages", ["title"], :name => "index_pages_on_title" + create_table "stock_article_selections", :force => true do |t| + t.integer "created_by_user_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "stock_article_selections_stock_articles", :id => false, :force => true do |t| + t.integer "stock_article_id" + t.integer "stock_article_selection_id" + end + create_table "stock_changes", :force => true do |t| t.integer "delivery_id" t.integer "order_id" From ce0300df431986775a1a71dfe9410a0fced8c85f Mon Sep 17 00:00:00 2001 From: Julius Date: Sat, 12 Jan 2013 16:24:13 +0100 Subject: [PATCH 04/14] Fix order.created_by --- app/controllers/orders_controller.rb | 3 ++- app/models/order.rb | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 31baa680..a123179a 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -60,6 +60,7 @@ class OrdersController < ApplicationController # order_articles will be saved in Order.article_ids=() def create @order = Order.new(params[:order]) + @order.created_by = current_user if @order.save flash[:notice] = "Die Bestellung wurde erstellt." redirect_to @order @@ -125,4 +126,4 @@ class OrdersController < ApplicationController :type => 'text/plain; charset=utf-8; header=present', :disposition => "attachment; filename=#{order.name}" end -end \ No newline at end of file +end diff --git a/app/models/order.rb b/app/models/order.rb index c6c4341b..5956b224 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -19,9 +19,6 @@ class Order < ActiveRecord::Base validate :starts_before_ends, :include_articles # Callbacks - before_create do |order| - order.created_by = User.current_user - end after_update :update_price_of_group_orders after_save :save_order_articles From 396a47b6afa5478c96dd8990a80a5437b784c0da Mon Sep 17 00:00:00 2001 From: Julius Date: Mon, 28 Jan 2013 20:46:35 +0100 Subject: [PATCH 05/14] Improve stock_article_selections --- app/controllers/stockit_controller.rb | 3 +- .../stockit_selections_controller.rb | 29 +++++++++++-------- .../stock_article_selections_helper.rb | 16 ++++++++++ app/models/stock_article.rb | 5 ++++ app/models/stock_article_selection.rb | 12 ++++++++ app/views/stockit/index.html.haml | 7 +++-- .../stockit_selections/_overview.html.haml | 13 +++++++-- app/views/stockit_selections/index.html.haml | 28 ++++++++++++++---- app/views/stockit_selections/show.html.haml | 17 +++++++---- config/routes.rb | 4 +++ 10 files changed, 104 insertions(+), 30 deletions(-) diff --git a/app/controllers/stockit_controller.rb b/app/controllers/stockit_controller.rb index 2c130fce..d555b4c3 100644 --- a/app/controllers/stockit_controller.rb +++ b/app/controllers/stockit_controller.rb @@ -1,8 +1,7 @@ class StockitController < ApplicationController def index - @stock_articles = StockArticle.includes(:supplier, :article_category). - order('suppliers.name, article_categories.name, articles.name') + @stock_articles = StockArticle.elements_for_index @stock_article_selection = StockArticleSelection.new end diff --git a/app/controllers/stockit_selections_controller.rb b/app/controllers/stockit_selections_controller.rb index ae498c40..6e89b5dc 100644 --- a/app/controllers/stockit_selections_controller.rb +++ b/app/controllers/stockit_selections_controller.rb @@ -2,7 +2,7 @@ class StockitSelectionsController < ApplicationController def index - @stock_article_selections = StockArticleSelection.all + @stock_article_selections = StockArticleSelection.find(:all, :order => 'created_at DESC') end def show @@ -14,43 +14,48 @@ class StockitSelectionsController < ApplicationController @stock_article_selection.created_by = current_user if @stock_article_selection.save - redirect_to(@stock_article_selection, :notice => 'Löschvorschlag für gewählte Artikel wurde erstellt.') + redirect_to(@stock_article_selection, :notice => 'Löschvorschlag für gewählte Artikel erstellt.') else - @stock_articles = StockArticle.includes(:supplier, :article_category). - order('suppliers.name, article_categories.name, articles.name') + @stock_articles = StockArticle.elements_for_index render 'stockit/index' end end - def destroy # destroy (open or finished) selection without deleting articles + def destroy # destroy selection without deleting articles stock_article_selection = StockArticleSelection.find(params[:id]) stock_article_selection.destroy - redirect_to stock_article_selections_path, :notice => 'Löschvorschlag wurde verworfen.' + redirect_to stock_article_selections_path, :notice => 'Löschvorschlag verworfen.' end - def articles # destroy articles, finish selection + def articles # destroy articles stock_article_selection = StockArticleSelection.find(params[:id]) destroyed_articles_count = 0 failed_articles_count = 0 stock_article_selection.stock_articles.each do |article| begin - article.destroy # article.delete would save some effort, but validations are important + article.destroy destroyed_articles_count += 1 rescue => error # recover if article.destroy fails and continue with next article failed_articles_count += 1 end end - if destroyed_articles_count>0 # note that 1 successful article.destroy is enough to destroy selection - stock_article_selection.destroy - flash[:notice] = "#{destroyed_articles_count} gewählte Artikel sind nun gelöscht." + if destroyed_articles_count > 0 + flash[:notice] = "#{destroyed_articles_count} gewählte Artikel gelöscht." flash[:error] = "#{failed_articles_count} Artikel konnten nicht gelöscht werden." unless 0==failed_articles_count else - flash[:error] = "Löschvorgang fehlgeschlagen. Es wurden keine Artikel gelöscht." + flash[:error] = 'Löschvorgang fehlgeschlagen. Keine Artikel gelöscht.' end redirect_to stock_articles_path end + + def finished # delete all finished selections + finished_selections = StockArticleSelection.all.select { |sel| sel.deletable_count + sel.nondeletable_count <= 0 } + finished_selections.each { |sel| sel.destroy } + + redirect_to stock_article_selections_path, :notice => 'Alle erledigten Löschvorschläge entfernt.' + end end diff --git a/app/helpers/stock_article_selections_helper.rb b/app/helpers/stock_article_selections_helper.rb index 9d7090f5..5d9d7737 100644 --- a/app/helpers/stock_article_selections_helper.rb +++ b/app/helpers/stock_article_selections_helper.rb @@ -1,2 +1,18 @@ +# encoding: utf-8 module StockArticleSelectionsHelper + def article_deletion_classes(article) + className = "label label-success" # usual deletable case, maybe modified below + className = "label label-important" if article.quantity_available > 0 + className = "label" if article.deleted? + + className + end + + def article_deletion_title(article) + myTitle = "Löschbar" # usual deletable case, maybe modified below + myTitle = "Nicht löschbar, da im Lager vorhanden" if article.quantity_available > 0 + myTitle = "Bereits gelöscht" if article.deleted? + + myTitle + end end diff --git a/app/models/stock_article.rb b/app/models/stock_article.rb index 6050c8c4..478e6c78 100644 --- a/app/models/stock_article.rb +++ b/app/models/stock_article.rb @@ -22,6 +22,11 @@ class StockArticle < Article def self.stock_value available.collect { |a| a.quantity * a.gross_price }.sum end + + def self.elements_for_index + StockArticle.includes(:supplier, :article_category). + order('suppliers.name, article_categories.name, articles.name') + end protected diff --git a/app/models/stock_article_selection.rb b/app/models/stock_article_selection.rb index 20aafd7a..a66c61f2 100644 --- a/app/models/stock_article_selection.rb +++ b/app/models/stock_article_selection.rb @@ -13,6 +13,18 @@ class StockArticleSelection < ActiveRecord::Base all_articles = stock_article_ids end + def deletable_count + stock_articles.select { |a| a.quantity_available<=0 }.length + end + + def nondeletable_count + stock_articles.select { |a| a.quantity_available>0 }.length + end + + def deleted_count + stock_articles.only_deleted.count + end + protected def include_stock_articles diff --git a/app/views/stockit/index.html.haml b/app/views/stockit/index.html.haml index fb9e3c30..89063bd7 100644 --- a/app/views/stockit/index.html.haml +++ b/app/views/stockit/index.html.haml @@ -2,7 +2,7 @@ - content_for :javascript do :javascript $(function() { - $('tr.unavailable,input.unavailable').hide(); + $('tr.unavailable,input.unavailable,div.unavailable').hide(); }) .well.well-small @@ -12,7 +12,7 @@ Ansichtsoptionen %span.caret %ul.dropdown-menu - %li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable,input.unavailable', tabindex: -1 + %li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable,input.unavailable,div.unavailable', tabindex: -1 .btn-group = link_to_if @current_user.role_orders?, "Lagerbestellung online stellen", new_order_path(supplier_id: 0), @@ -66,7 +66,8 @@ = link_to "Bearbeiten", edit_stock_article_path(article), class: 'btn btn-mini' = link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?", class: 'btn btn-mini btn-danger' - %p= submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' } + .form-actions.unavailable + = submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' } %p Aktueller Lagerwert: = number_to_currency StockArticle.stock_value diff --git a/app/views/stockit_selections/_overview.html.haml b/app/views/stockit_selections/_overview.html.haml index 15f9b7f9..5663fb4c 100644 --- a/app/views/stockit_selections/_overview.html.haml +++ b/app/views/stockit_selections/_overview.html.haml @@ -2,15 +2,22 @@ %table.table.table-hover %tr %th Artikel + %th Zusammenfassung %th Erstellt am %th Erstellt von %th Optionen - stock_article_selections.each do |stock_article_selection| %tr - %td=h truncate stock_article_selection.stock_articles.map{ |article| article.name}.join(', ') - %td=h stock_article_selection.created_at - %td=h link_to_user_message_if_valid stock_article_selection.created_by + %td + - for article in stock_article_selection.stock_articles.with_deleted + %span{:class => article_deletion_classes(article), :title => article_deletion_title(article)}= article.name + %td + %span{:class => 'label label-success'}= "#{stock_article_selection.deletable_count} Löschbar" + %span{:class => 'label'}= "#{stock_article_selection.deleted_count} Gelöscht" + %span{:class => 'label label-important'}= "#{stock_article_selection.nondeletable_count} Nicht löschbar" + %td= format_date(stock_article_selection.created_at) + %td= link_to_user_message_if_valid stock_article_selection.created_by %td = link_to 'Anzeigen', stock_article_selection, class: 'btn btn-small' = link_to "Artikel löschen", articles_stock_article_selection_path(stock_article_selection), :method => :delete, diff --git a/app/views/stockit_selections/index.html.haml b/app/views/stockit_selections/index.html.haml index 99cac93f..f189f2ca 100644 --- a/app/views/stockit_selections/index.html.haml +++ b/app/views/stockit_selections/index.html.haml @@ -1,7 +1,25 @@ - title "Löschvorschläge für Lagerartikel" -- if @stock_article_selections.empty? - %p Es gibt keine ausstehenden Löschvorschläge. - %ul - %li= link_to "Löschvorschlag erstellen", stock_articles_path + +.well.well-small + .btn-toolbar + .btn-group + = link_to "Lager anzeigen", stock_articles_path, class: 'btn' + = link_to "Aufräumen", finished_stock_article_selections_path, :method => 'delete', + :confirm => 'Wirklich alle erledigten Löschvorschläge entfernen?', class: 'btn' + +.well + %h2 Ausstehende Löschvorschläge + - open_selections = @stock_article_selections.select { |sel| sel.deletable_count + sel.nondeletable_count > 0 } + - if open_selections.length == 0 + %p Es gibt keine ausstehenden Löschvorschläge. + %ul + %li= link_to "Löschvorschlag erstellen", stock_articles_path + - else + = render :partial => 'overview', :locals => {:stock_article_selections => open_selections} + +%h2 Erledigte Löschvorschläge +- finished_selections = @stock_article_selections.select { |sel| sel.deletable_count + sel.nondeletable_count <= 0 } +- if finished_selections.length == 0 + %p Es gibt keine erledigten Löschvorschläge. - else - = render :partial => 'overview', :locals => {:stock_article_selections => @stock_article_selections} + = render :partial => 'overview', :locals => {:stock_article_selections => finished_selections} diff --git a/app/views/stockit_selections/show.html.haml b/app/views/stockit_selections/show.html.haml index 63ea5dfa..9434421b 100644 --- a/app/views/stockit_selections/show.html.haml +++ b/app/views/stockit_selections/show.html.haml @@ -1,13 +1,20 @@ - title "Löschvorschlag für #{@stock_article_selection.stock_articles.count} Lagerartikel" +.well.well-small + .btn-toolbar + .btn-group + = link_to "Lager anzeigen", stock_articles_path, class: 'btn' + = link_to 'Alle Löschvorschläge anzeigen', stock_article_selections_path, class: 'btn' + %dl %dt Löschvorschlag vom: - %dd=h @stock_article_selection.created_at + %dd= format_time(@stock_article_selection.created_at) %dt Erstellt durch: - %dd=h link_to_user_message_if_valid(@stock_article_selection.created_by) + %dd= link_to_user_message_if_valid(@stock_article_selection.created_by) %dt Zu löschende Artikel - - for article in @stock_article_selection.stock_articles - %dd=h article.name + - for article in @stock_article_selection.stock_articles.with_deleted + %dd + %span{:class => article_deletion_classes(article), :title => article_deletion_title(article)}= article.name %p @@ -15,4 +22,4 @@ :confirm => 'Diesen Löschvorschlag wirklich ausführen und markierte Artikel löschen?', class: 'btn btn-danger' = link_to 'Verwerfen', @stock_article_selection, :method => :delete, :confirm => 'Diesen Löschvorschlag wirklich verwerfen?', class: 'btn' - = link_to 'Alle Löschvorschläge zeigen', stock_article_selections_path, class: 'btn' + = link_to 'Alle Löschvorschläge anzeigen', stock_article_selections_path, class: 'btn' diff --git a/config/routes.rb b/config/routes.rb index 9c27bbe7..6e108cce 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -95,6 +95,10 @@ Foodsoft::Application.routes.draw do member do delete 'articles' end + + collection do + delete 'finished' + end end From 8c7a4f0331a50768b90bdea3e7a2f7bdf8f79e06 Mon Sep 17 00:00:00 2001 From: Julius Date: Tue, 29 Jan 2013 17:52:44 +0100 Subject: [PATCH 06/14] Fix empty dd in horizontal dl --- app/assets/stylesheets/bootstrap_and_overrides.css.less | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index 3f956cd1..b6d9f746 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -37,6 +37,11 @@ body { // Custom styles +// Fix empty dd tags in horizontal dl, see https://github.com/twitter/bootstrap/issues/4062 +.dl-horizontal { + dd { .clearfix(); } +} + @mainRedColor: #ED0606; .logo { @@ -194,4 +199,4 @@ tr.unavailable { input, select { border-color: red; } -} \ No newline at end of file +} From 2c9fdcd79ed2de5c8782251d7e6b638d965e4c9f Mon Sep 17 00:00:00 2001 From: Julius Date: Wed, 30 Jan 2013 19:46:18 +0100 Subject: [PATCH 07/14] Show customer number in fax pdf --- app/documents/order_fax.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/documents/order_fax.rb b/app/documents/order_fax.rb index 3630546c..5dd4bfee 100644 --- a/app/documents/order_fax.rb +++ b/app/documents/order_fax.rb @@ -19,6 +19,10 @@ class OrderFax < OrderPdf text contact[:street], align: :right move_down 5 text "#{contact[:zip_code]} #{contact[:city]}", align: :right + move_down 5 + if @order.supplier.customer_number != '' + text "Kundennummer: #{@order.supplier.customer_number}", align: :right + end move_down 10 text contact[:phone], size: 9, align: :right move_down 5 @@ -34,6 +38,7 @@ class OrderFax < OrderPdf text "Fax: " + @order.supplier.fax end + move_down 5 text Date.today.strftime('%d.%m.%Y'), align: :right move_down 10 @@ -66,4 +71,4 @@ class OrderFax < OrderPdf #align: {0 => :left} end -end \ No newline at end of file +end From a511da9ae37185b0ac1b342675100b007a43aef6 Mon Sep 17 00:00:00 2001 From: Julius Date: Wed, 30 Jan 2013 21:21:49 +0100 Subject: [PATCH 08/14] Prevent stock_articles from appearing in supplier article index --- app/controllers/articles_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 4044d454..35bd36db 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -20,7 +20,7 @@ class ArticlesController < ApplicationController sort = "article_categories.name, articles.name" end - @articles = Article.where(supplier_id: @supplier).includes(:article_category).order(sort) + @articles = Article.where(supplier_id: @supplier, :type => nil).includes(:article_category).order(sort) @articles = @articles.where('articles.name LIKE ?', "%#{params[:query]}%") unless params[:query].nil? @articles = @articles.page(params[:page]).per(@per_page) @@ -231,4 +231,4 @@ class ArticlesController < ApplicationController redirect_to supplier_articles_path(@supplier), :notice => "Der Katalog ist aktuell." end end -end \ No newline at end of file +end From 82178161fab7511322ad7b90dd262b9b791d10fc Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 24 Feb 2013 23:26:16 +0100 Subject: [PATCH 09/14] Show usefull error message for uniqueness_of_name with acts_as_paranoid. Fixed #88 --- app/models/group.rb | 2 +- app/models/ordergroup.rb | 12 +++++++++++- app/models/supplier.rb | 18 ++++++++++++++---- app/models/workgroup.rb | 1 + config/locales/de.yml | 1 + 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/models/group.rb b/app/models/group.rb index c1976830..68cb015c 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -4,7 +4,7 @@ class Group < ActiveRecord::Base has_many :memberships, :dependent => :destroy has_many :users, :through => :memberships - validates :name, :presence => true, :length => {:in => 1..25}, :uniqueness => true + validates :name, :presence => true, :length => {:in => 1..25} attr_reader :user_tokens diff --git a/app/models/ordergroup.rb b/app/models/ordergroup.rb index 3d863834..dbfe3171 100644 --- a/app/models/ordergroup.rb +++ b/app/models/ordergroup.rb @@ -16,7 +16,7 @@ class Ordergroup < Group has_many :orders, :through => :group_orders validates_numericality_of :account_balance, :message => 'ist keine gültige Zahl' - validate :uniqueness_of_members + validate :uniqueness_of_name, :uniqueness_of_members after_create :update_stats! @@ -106,6 +106,16 @@ class Ordergroup < Group errors.add :user_tokens, "#{user.nick} ist schon in einer anderen Bestellgruppe" if user.groups.where(:type => 'Ordergroup').size > 1 end end + + # Make sure, the name is uniq, add usefull message if uniq group is already deleted + def uniqueness_of_name + id = new_record? ? '' : self.id + group = Ordergroup.with_deleted.where('groups.id != ? AND groups.name = ?', id, name).first + if group.present? + message = group.deleted? ? :taken_with_deleted : :taken + errors.add :name, message + end + end end diff --git a/app/models/supplier.rb b/app/models/supplier.rb index 05dbeb6c..384c5973 100644 --- a/app/models/supplier.rb +++ b/app/models/supplier.rb @@ -12,15 +12,13 @@ class Supplier < ActiveRecord::Base attr_accessible :name, :address, :phone, :phone2, :fax, :email, :url, :contact_person, :customer_number, :delivery_days, :order_howto, :note, :shared_supplier_id, :min_order_quantity - validates :name, :presence => true, :length => { :in => 4..30 }, :uniqueness => true + validates :name, :presence => true, :length => { :in => 4..30 } validates :phone, :presence => true, :length => { :in => 8..20 } validates :address, :presence => true, :length => { :in => 8..50 } validates_length_of :order_howto, :note, maximum: 250 -# validates_length_of :name, :in => 4..30 -# validates_uniqueness_of :name - validates_length_of :phone, :in => 8..20 validates_length_of :address, :in => 8..50 + validate :uniqueness_of_name # sync all articles with the external database # returns an array with articles(and prices), which should be updated (to use in a form) @@ -66,5 +64,17 @@ class Supplier < ActiveRecord::Base end return [updated_articles, outlisted_articles] end + + protected + + # Make sure, the name is uniq, add usefull message if uniq group is already deleted + def uniqueness_of_name + id = new_record? ? '' : self.id + supplier = Supplier.with_deleted.where('suppliers.id != ? AND suppliers.name = ?', id, name).first + if supplier.present? + message = supplier.deleted? ? :taken_with_deleted : :taken + errors.add :name, message + end + end end diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb index 5b201932..20448839 100644 --- a/app/models/workgroup.rb +++ b/app/models/workgroup.rb @@ -5,6 +5,7 @@ class Workgroup < Group # returns all non-finished tasks has_many :open_tasks, :class_name => 'Task', :conditions => ['done = ?', false], :order => 'due_date ASC' + validates_uniqueness_of :name validates_presence_of :task_name, :weekday, :task_required_users, :next_weekly_tasks_number, :if => :weekly_task validates_numericality_of :next_weekly_tasks_number, :greater_than => 0, :less_than => 21, :only_integer => true, diff --git a/config/locales/de.yml b/config/locales/de.yml index 213c3c97..6f6d108a 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -143,6 +143,7 @@ de: odd: muss ungerade sein record_invalid: ! 'Gültigkeitsprüfung ist fehlgeschlagen: %{errors}' taken: ist bereits vergeben + taken_with_deleted: ist bereits vergeben (eine gelöschte Gruppe) too_long: ist zu lang (nicht mehr als %{count} Zeichen) too_short: ist zu kurz (nicht weniger als %{count} Zeichen) wrong_length: hat die falsche Länge (muss genau %{count} Zeichen haben) From 6685012a3e1ea8cdb8291dab669893e99cce9d4a Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 24 Feb 2013 23:54:59 +0100 Subject: [PATCH 10/14] Fixed bad syntax (from already dropped meta_where gem). Thanks to wvengen, closed #91 --- app/models/workgroup.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb index 20448839..5a5855e7 100644 --- a/app/models/workgroup.rb +++ b/app/models/workgroup.rb @@ -62,7 +62,7 @@ class Workgroup < Group # add validation check on update # Return an error if this is the last group with admin role and role_admin should set to false def last_admin_on_earth - if !role_admin && Workgroup.where(:role_admin => true, :id.ne => id).empty? + if !role_admin && !Workgroup.where('role_admin = ? AND id != ?', true, id).exists? errors.add(:role_admin, "Der letzten Gruppe mit Admin-Rechten darf die Admin-Rolle nicht entzogen werden") end end From ccf0d010b4f9c3aa7a63930fc7bf6db4ed863354 Mon Sep 17 00:00:00 2001 From: Julius Date: Mon, 25 Feb 2013 10:02:21 +0100 Subject: [PATCH 11/14] Apply AJAX for deleting a StockArticle --- app/controllers/stockit_controller.rb | 7 ++++--- app/views/stockit/_destroy_fail.js.haml | 7 +++++++ app/views/stockit/destroy.js.haml | 1 + app/views/stockit/index.html.haml | 3 +-- 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 app/views/stockit/_destroy_fail.js.haml create mode 100644 app/views/stockit/destroy.js.haml diff --git a/app/controllers/stockit_controller.rb b/app/controllers/stockit_controller.rb index d555b4c3..36254f10 100644 --- a/app/controllers/stockit_controller.rb +++ b/app/controllers/stockit_controller.rb @@ -33,10 +33,11 @@ class StockitController < ApplicationController def destroy StockArticle.find(params[:id]).destroy - redirect_to stock_articles_path + render :layout => false, + :locals => { :destroyed_article_id => params[:id] } rescue => error - flash[:error] = "Ein Fehler ist aufgetreten: " + error.message - redirect_to stock_articles_path + render :partial => "destroy_fail", :layout => false, + :locals => { :fail_msg => "Ein Fehler ist aufgetreten: " + error.message } end #TODO: Fix this!! diff --git a/app/views/stockit/_destroy_fail.js.haml b/app/views/stockit/_destroy_fail.js.haml new file mode 100644 index 00000000..60b03d87 --- /dev/null +++ b/app/views/stockit/_destroy_fail.js.haml @@ -0,0 +1,7 @@ +-# please polish the following line if you know how +var errorDiv = $(''); + +-# next line, createTextNode called by .text(textString) helps escaping for html, but what about ' signs? +errorDiv.text('#{fail_msg}'); + +$('div.container-fluid').prepend(errorDiv); diff --git a/app/views/stockit/destroy.js.haml b/app/views/stockit/destroy.js.haml new file mode 100644 index 00000000..39602dfb --- /dev/null +++ b/app/views/stockit/destroy.js.haml @@ -0,0 +1 @@ +console.log('#{destroyed_article_id}'); diff --git a/app/views/stockit/index.html.haml b/app/views/stockit/index.html.haml index 89063bd7..b84b4f4f 100644 --- a/app/views/stockit/index.html.haml +++ b/app/views/stockit/index.html.haml @@ -64,8 +64,7 @@ %td= article.article_category.name %td = link_to "Bearbeiten", edit_stock_article_path(article), class: 'btn btn-mini' - = link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?", - class: 'btn btn-mini btn-danger' + = link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?", class: 'btn btn-mini btn-danger', :remote => true .form-actions.unavailable = submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' } %p From 8f15cfb446749308f7eae77af8b6e7a937e4ad94 Mon Sep 17 00:00:00 2001 From: Julius Date: Mon, 25 Feb 2013 10:13:44 +0100 Subject: [PATCH 12/14] Revert 396a47b6afa5478c96dd8990a80a5437b784c0da --- app/controllers/stockit_controller.rb | 3 +- .../stockit_selections_controller.rb | 29 ++++++++----------- .../stock_article_selections_helper.rb | 16 ---------- app/models/stock_article.rb | 5 ---- app/models/stock_article_selection.rb | 12 -------- app/views/stockit/index.html.haml | 7 ++--- .../stockit_selections/_overview.html.haml | 13 ++------- app/views/stockit_selections/index.html.haml | 28 ++++-------------- app/views/stockit_selections/show.html.haml | 17 ++++------- config/routes.rb | 4 --- 10 files changed, 30 insertions(+), 104 deletions(-) diff --git a/app/controllers/stockit_controller.rb b/app/controllers/stockit_controller.rb index 36254f10..53bf0e25 100644 --- a/app/controllers/stockit_controller.rb +++ b/app/controllers/stockit_controller.rb @@ -1,7 +1,8 @@ class StockitController < ApplicationController def index - @stock_articles = StockArticle.elements_for_index + @stock_articles = StockArticle.includes(:supplier, :article_category). + order('suppliers.name, article_categories.name, articles.name') @stock_article_selection = StockArticleSelection.new end diff --git a/app/controllers/stockit_selections_controller.rb b/app/controllers/stockit_selections_controller.rb index 6e89b5dc..ae498c40 100644 --- a/app/controllers/stockit_selections_controller.rb +++ b/app/controllers/stockit_selections_controller.rb @@ -2,7 +2,7 @@ class StockitSelectionsController < ApplicationController def index - @stock_article_selections = StockArticleSelection.find(:all, :order => 'created_at DESC') + @stock_article_selections = StockArticleSelection.all end def show @@ -14,48 +14,43 @@ class StockitSelectionsController < ApplicationController @stock_article_selection.created_by = current_user if @stock_article_selection.save - redirect_to(@stock_article_selection, :notice => 'Löschvorschlag für gewählte Artikel erstellt.') + redirect_to(@stock_article_selection, :notice => 'Löschvorschlag für gewählte Artikel wurde erstellt.') else - @stock_articles = StockArticle.elements_for_index + @stock_articles = StockArticle.includes(:supplier, :article_category). + order('suppliers.name, article_categories.name, articles.name') render 'stockit/index' end end - def destroy # destroy selection without deleting articles + def destroy # destroy (open or finished) selection without deleting articles stock_article_selection = StockArticleSelection.find(params[:id]) stock_article_selection.destroy - redirect_to stock_article_selections_path, :notice => 'Löschvorschlag verworfen.' + redirect_to stock_article_selections_path, :notice => 'Löschvorschlag wurde verworfen.' end - def articles # destroy articles + def articles # destroy articles, finish selection stock_article_selection = StockArticleSelection.find(params[:id]) destroyed_articles_count = 0 failed_articles_count = 0 stock_article_selection.stock_articles.each do |article| begin - article.destroy + article.destroy # article.delete would save some effort, but validations are important destroyed_articles_count += 1 rescue => error # recover if article.destroy fails and continue with next article failed_articles_count += 1 end end - if destroyed_articles_count > 0 - flash[:notice] = "#{destroyed_articles_count} gewählte Artikel gelöscht." + if destroyed_articles_count>0 # note that 1 successful article.destroy is enough to destroy selection + stock_article_selection.destroy + flash[:notice] = "#{destroyed_articles_count} gewählte Artikel sind nun gelöscht." flash[:error] = "#{failed_articles_count} Artikel konnten nicht gelöscht werden." unless 0==failed_articles_count else - flash[:error] = 'Löschvorgang fehlgeschlagen. Keine Artikel gelöscht.' + flash[:error] = "Löschvorgang fehlgeschlagen. Es wurden keine Artikel gelöscht." end redirect_to stock_articles_path end - - def finished # delete all finished selections - finished_selections = StockArticleSelection.all.select { |sel| sel.deletable_count + sel.nondeletable_count <= 0 } - finished_selections.each { |sel| sel.destroy } - - redirect_to stock_article_selections_path, :notice => 'Alle erledigten Löschvorschläge entfernt.' - end end diff --git a/app/helpers/stock_article_selections_helper.rb b/app/helpers/stock_article_selections_helper.rb index 5d9d7737..9d7090f5 100644 --- a/app/helpers/stock_article_selections_helper.rb +++ b/app/helpers/stock_article_selections_helper.rb @@ -1,18 +1,2 @@ -# encoding: utf-8 module StockArticleSelectionsHelper - def article_deletion_classes(article) - className = "label label-success" # usual deletable case, maybe modified below - className = "label label-important" if article.quantity_available > 0 - className = "label" if article.deleted? - - className - end - - def article_deletion_title(article) - myTitle = "Löschbar" # usual deletable case, maybe modified below - myTitle = "Nicht löschbar, da im Lager vorhanden" if article.quantity_available > 0 - myTitle = "Bereits gelöscht" if article.deleted? - - myTitle - end end diff --git a/app/models/stock_article.rb b/app/models/stock_article.rb index 478e6c78..6050c8c4 100644 --- a/app/models/stock_article.rb +++ b/app/models/stock_article.rb @@ -22,11 +22,6 @@ class StockArticle < Article def self.stock_value available.collect { |a| a.quantity * a.gross_price }.sum end - - def self.elements_for_index - StockArticle.includes(:supplier, :article_category). - order('suppliers.name, article_categories.name, articles.name') - end protected diff --git a/app/models/stock_article_selection.rb b/app/models/stock_article_selection.rb index a66c61f2..20aafd7a 100644 --- a/app/models/stock_article_selection.rb +++ b/app/models/stock_article_selection.rb @@ -13,18 +13,6 @@ class StockArticleSelection < ActiveRecord::Base all_articles = stock_article_ids end - def deletable_count - stock_articles.select { |a| a.quantity_available<=0 }.length - end - - def nondeletable_count - stock_articles.select { |a| a.quantity_available>0 }.length - end - - def deleted_count - stock_articles.only_deleted.count - end - protected def include_stock_articles diff --git a/app/views/stockit/index.html.haml b/app/views/stockit/index.html.haml index b84b4f4f..5cd138d6 100644 --- a/app/views/stockit/index.html.haml +++ b/app/views/stockit/index.html.haml @@ -2,7 +2,7 @@ - content_for :javascript do :javascript $(function() { - $('tr.unavailable,input.unavailable,div.unavailable').hide(); + $('tr.unavailable,input.unavailable').hide(); }) .well.well-small @@ -12,7 +12,7 @@ Ansichtsoptionen %span.caret %ul.dropdown-menu - %li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable,input.unavailable,div.unavailable', tabindex: -1 + %li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable,input.unavailable', tabindex: -1 .btn-group = link_to_if @current_user.role_orders?, "Lagerbestellung online stellen", new_order_path(supplier_id: 0), @@ -65,8 +65,7 @@ %td = link_to "Bearbeiten", edit_stock_article_path(article), class: 'btn btn-mini' = link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?", class: 'btn btn-mini btn-danger', :remote => true - .form-actions.unavailable - = submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' } + %p= submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' } %p Aktueller Lagerwert: = number_to_currency StockArticle.stock_value diff --git a/app/views/stockit_selections/_overview.html.haml b/app/views/stockit_selections/_overview.html.haml index 5663fb4c..15f9b7f9 100644 --- a/app/views/stockit_selections/_overview.html.haml +++ b/app/views/stockit_selections/_overview.html.haml @@ -2,22 +2,15 @@ %table.table.table-hover %tr %th Artikel - %th Zusammenfassung %th Erstellt am %th Erstellt von %th Optionen - stock_article_selections.each do |stock_article_selection| %tr - %td - - for article in stock_article_selection.stock_articles.with_deleted - %span{:class => article_deletion_classes(article), :title => article_deletion_title(article)}= article.name - %td - %span{:class => 'label label-success'}= "#{stock_article_selection.deletable_count} Löschbar" - %span{:class => 'label'}= "#{stock_article_selection.deleted_count} Gelöscht" - %span{:class => 'label label-important'}= "#{stock_article_selection.nondeletable_count} Nicht löschbar" - %td= format_date(stock_article_selection.created_at) - %td= link_to_user_message_if_valid stock_article_selection.created_by + %td=h truncate stock_article_selection.stock_articles.map{ |article| article.name}.join(', ') + %td=h stock_article_selection.created_at + %td=h link_to_user_message_if_valid stock_article_selection.created_by %td = link_to 'Anzeigen', stock_article_selection, class: 'btn btn-small' = link_to "Artikel löschen", articles_stock_article_selection_path(stock_article_selection), :method => :delete, diff --git a/app/views/stockit_selections/index.html.haml b/app/views/stockit_selections/index.html.haml index f189f2ca..99cac93f 100644 --- a/app/views/stockit_selections/index.html.haml +++ b/app/views/stockit_selections/index.html.haml @@ -1,25 +1,7 @@ - title "Löschvorschläge für Lagerartikel" - -.well.well-small - .btn-toolbar - .btn-group - = link_to "Lager anzeigen", stock_articles_path, class: 'btn' - = link_to "Aufräumen", finished_stock_article_selections_path, :method => 'delete', - :confirm => 'Wirklich alle erledigten Löschvorschläge entfernen?', class: 'btn' - -.well - %h2 Ausstehende Löschvorschläge - - open_selections = @stock_article_selections.select { |sel| sel.deletable_count + sel.nondeletable_count > 0 } - - if open_selections.length == 0 - %p Es gibt keine ausstehenden Löschvorschläge. - %ul - %li= link_to "Löschvorschlag erstellen", stock_articles_path - - else - = render :partial => 'overview', :locals => {:stock_article_selections => open_selections} - -%h2 Erledigte Löschvorschläge -- finished_selections = @stock_article_selections.select { |sel| sel.deletable_count + sel.nondeletable_count <= 0 } -- if finished_selections.length == 0 - %p Es gibt keine erledigten Löschvorschläge. +- if @stock_article_selections.empty? + %p Es gibt keine ausstehenden Löschvorschläge. + %ul + %li= link_to "Löschvorschlag erstellen", stock_articles_path - else - = render :partial => 'overview', :locals => {:stock_article_selections => finished_selections} + = render :partial => 'overview', :locals => {:stock_article_selections => @stock_article_selections} diff --git a/app/views/stockit_selections/show.html.haml b/app/views/stockit_selections/show.html.haml index 9434421b..63ea5dfa 100644 --- a/app/views/stockit_selections/show.html.haml +++ b/app/views/stockit_selections/show.html.haml @@ -1,20 +1,13 @@ - title "Löschvorschlag für #{@stock_article_selection.stock_articles.count} Lagerartikel" -.well.well-small - .btn-toolbar - .btn-group - = link_to "Lager anzeigen", stock_articles_path, class: 'btn' - = link_to 'Alle Löschvorschläge anzeigen', stock_article_selections_path, class: 'btn' - %dl %dt Löschvorschlag vom: - %dd= format_time(@stock_article_selection.created_at) + %dd=h @stock_article_selection.created_at %dt Erstellt durch: - %dd= link_to_user_message_if_valid(@stock_article_selection.created_by) + %dd=h link_to_user_message_if_valid(@stock_article_selection.created_by) %dt Zu löschende Artikel - - for article in @stock_article_selection.stock_articles.with_deleted - %dd - %span{:class => article_deletion_classes(article), :title => article_deletion_title(article)}= article.name + - for article in @stock_article_selection.stock_articles + %dd=h article.name %p @@ -22,4 +15,4 @@ :confirm => 'Diesen Löschvorschlag wirklich ausführen und markierte Artikel löschen?', class: 'btn btn-danger' = link_to 'Verwerfen', @stock_article_selection, :method => :delete, :confirm => 'Diesen Löschvorschlag wirklich verwerfen?', class: 'btn' - = link_to 'Alle Löschvorschläge anzeigen', stock_article_selections_path, class: 'btn' + = link_to 'Alle Löschvorschläge zeigen', stock_article_selections_path, class: 'btn' diff --git a/config/routes.rb b/config/routes.rb index 6e108cce..9c27bbe7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -95,10 +95,6 @@ Foodsoft::Application.routes.draw do member do delete 'articles' end - - collection do - delete 'finished' - end end From 5dc3fc30adf5fb4b70c45a0663eb475e5652ec8d Mon Sep 17 00:00:00 2001 From: Julius Date: Mon, 25 Feb 2013 10:29:47 +0100 Subject: [PATCH 13/14] Revert 099e2b9b06bca02b205d15dd00c1872620c5b39f --- app/controllers/stockit_controller.rb | 1 - .../stockit_selections_controller.rb | 56 --------------- .../stock_article_selections_helper.rb | 2 - app/helpers/stockit_helper.rb | 11 --- app/models/stock_article_selection.rb | 24 ------- app/views/stockit/index.html.haml | 71 +++++++++---------- .../stockit_selections/_overview.html.haml | 19 ----- app/views/stockit_selections/index.html.haml | 7 -- app/views/stockit_selections/show.html.haml | 18 ----- config/routes.rb | 8 --- ...2121840_create_stock_article_selections.rb | 18 ----- db/schema.rb | 13 +--- 12 files changed, 33 insertions(+), 215 deletions(-) delete mode 100644 app/controllers/stockit_selections_controller.rb delete mode 100644 app/helpers/stock_article_selections_helper.rb delete mode 100644 app/models/stock_article_selection.rb delete mode 100644 app/views/stockit_selections/_overview.html.haml delete mode 100644 app/views/stockit_selections/index.html.haml delete mode 100644 app/views/stockit_selections/show.html.haml delete mode 100644 db/migrate/20130112121840_create_stock_article_selections.rb diff --git a/app/controllers/stockit_controller.rb b/app/controllers/stockit_controller.rb index 53bf0e25..f70bec27 100644 --- a/app/controllers/stockit_controller.rb +++ b/app/controllers/stockit_controller.rb @@ -3,7 +3,6 @@ class StockitController < ApplicationController def index @stock_articles = StockArticle.includes(:supplier, :article_category). order('suppliers.name, article_categories.name, articles.name') - @stock_article_selection = StockArticleSelection.new end def new diff --git a/app/controllers/stockit_selections_controller.rb b/app/controllers/stockit_selections_controller.rb deleted file mode 100644 index ae498c40..00000000 --- a/app/controllers/stockit_selections_controller.rb +++ /dev/null @@ -1,56 +0,0 @@ -# encoding: utf-8 -class StockitSelectionsController < ApplicationController - - def index - @stock_article_selections = StockArticleSelection.all - end - - def show - @stock_article_selection = StockArticleSelection.find(params[:id]) - end - - def create - @stock_article_selection = StockArticleSelection.new(params[:stock_article_selection]) - @stock_article_selection.created_by = current_user - - if @stock_article_selection.save - redirect_to(@stock_article_selection, :notice => 'Löschvorschlag für gewählte Artikel wurde erstellt.') - else - @stock_articles = StockArticle.includes(:supplier, :article_category). - order('suppliers.name, article_categories.name, articles.name') - render 'stockit/index' - end - end - - def destroy # destroy (open or finished) selection without deleting articles - stock_article_selection = StockArticleSelection.find(params[:id]) - stock_article_selection.destroy - - redirect_to stock_article_selections_path, :notice => 'Löschvorschlag wurde verworfen.' - end - - def articles # destroy articles, finish selection - stock_article_selection = StockArticleSelection.find(params[:id]) - - destroyed_articles_count = 0 - failed_articles_count = 0 - stock_article_selection.stock_articles.each do |article| - begin - article.destroy # article.delete would save some effort, but validations are important - destroyed_articles_count += 1 - rescue => error # recover if article.destroy fails and continue with next article - failed_articles_count += 1 - end - end - - if destroyed_articles_count>0 # note that 1 successful article.destroy is enough to destroy selection - stock_article_selection.destroy - flash[:notice] = "#{destroyed_articles_count} gewählte Artikel sind nun gelöscht." - flash[:error] = "#{failed_articles_count} Artikel konnten nicht gelöscht werden." unless 0==failed_articles_count - else - flash[:error] = "Löschvorgang fehlgeschlagen. Es wurden keine Artikel gelöscht." - end - - redirect_to stock_articles_path - end -end diff --git a/app/helpers/stock_article_selections_helper.rb b/app/helpers/stock_article_selections_helper.rb deleted file mode 100644 index 9d7090f5..00000000 --- a/app/helpers/stock_article_selections_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module StockArticleSelectionsHelper -end diff --git a/app/helpers/stockit_helper.rb b/app/helpers/stockit_helper.rb index c2665a96..2888603c 100644 --- a/app/helpers/stockit_helper.rb +++ b/app/helpers/stockit_helper.rb @@ -1,18 +1,7 @@ -# encoding: utf-8 module StockitHelper def stock_article_classes(article) class_names = [] class_names << "unavailable" if article.quantity_available <= 0 class_names.join(" ") end - - def stock_article_delete_checkbox(article) - if article.quantity_available <= 0 - check_box_tag "stock_article_selection[stock_article_ids][]", article.id, false, - { :id => "checkbox_#{article.id}", :title => 'Zum löschen markieren' } - else - check_box_tag 'checkall', '1', false, - { :disabled => true, :title => 'Verfügbare Artikel können nicht gelöscht werden.', :class => 'unavailable' } - end - end end diff --git a/app/models/stock_article_selection.rb b/app/models/stock_article_selection.rb deleted file mode 100644 index 20aafd7a..00000000 --- a/app/models/stock_article_selection.rb +++ /dev/null @@ -1,24 +0,0 @@ -# encoding: utf-8 -class StockArticleSelection < ActiveRecord::Base - - # Associations - has_and_belongs_to_many :stock_articles - belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id' - belongs_to :finished_by, :class_name => 'User', :foreign_key => 'finished_by_user_id' - - # Validations - validate :include_stock_articles - - def all_articles - all_articles = stock_article_ids - end - - protected - - def include_stock_articles - errors.add(:stock_articles, "Es muss mindestens ein Lagerartikel ausgewählt sein.") if stock_articles.empty? - end - - private - -end diff --git a/app/views/stockit/index.html.haml b/app/views/stockit/index.html.haml index 5cd138d6..6ceb0e91 100644 --- a/app/views/stockit/index.html.haml +++ b/app/views/stockit/index.html.haml @@ -2,7 +2,7 @@ - content_for :javascript do :javascript $(function() { - $('tr.unavailable,input.unavailable').hide(); + $('tr.unavailable').hide(); }) .well.well-small @@ -12,7 +12,7 @@ Ansichtsoptionen %span.caret %ul.dropdown-menu - %li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable,input.unavailable', tabindex: -1 + %li= link_to "Nicht verfügbare Artikel zeigen/verstecken", "#", 'data-toggle-this' => 'tr.unavailable', tabindex: -1 .btn-group = link_to_if @current_user.role_orders?, "Lagerbestellung online stellen", new_order_path(supplier_id: 0), @@ -20,7 +20,6 @@ = link_to "Neuen Lagerartikel anlegen", new_stock_article_path, class: 'btn' = link_to "Inventur anlegen", new_stock_taking_path, class: 'btn' = link_to "Inventurübersicht", stock_takings_path, class: 'btn' - = link_to 'Löschvorschläge', stock_article_selections_path, class: 'btn' .btn-group = link_to '#', data: {toggle: 'dropdown'}, class: 'btn dropdown-toggle' do @@ -30,42 +29,36 @@ - Supplier.all.each do |supplier| %li= link_to supplier.name, new_supplier_delivery_path(supplier), tabindex: -1 -= form_for @stock_article_selection do |form| - - if @stock_article_selection.errors.has_key?(:stock_articles) - .alert.alert-error - = @stock_article_selection.errors.get(:stock_articles).join(" ") - %table.table.table-hover#articles - %thead - %tr - %th= check_box_tag 'checkall', '1', false, - { 'data-check-all' => 'table#articles tr.unavailable', :title => 'Alle löschbaren Artikel', :class => 'unavailable' } - %th Artikel - %th im Lager - %th davon bestellt - %th verfügbar - %th Einheit - %th Preis - %th MwSt - %th Lieferantin - %th Kategorie - %th - %tbody - - for article in @stock_articles - %tr{:class => stock_article_classes(article)} - %td= stock_article_delete_checkbox(article) - %td=h article.name - %td= article.quantity - %td= article.quantity - article.quantity_available - %th= article.quantity_available - %td= article.unit - %td= article.price - %td= number_to_percentage article.tax - %td= link_to article.supplier.name, article.supplier - %td= article.article_category.name - %td - = link_to "Bearbeiten", edit_stock_article_path(article), class: 'btn btn-mini' - = link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?", class: 'btn btn-mini btn-danger', :remote => true - %p= submit_tag "Artikel zum Löschen vormerken", { :class => 'unavailable btn' } +%table.table.table-hover#articles + %thead + %tr + %th Artikel + %th im Lager + %th davon bestellt + %th verfügbar + %th Einheit + %th Preis + %th MwSt + %th Lieferantin + %th Kategorie + %th + %tbody + - for article in @stock_articles + %tr{:class => stock_article_classes(article)} + %td=h article.name + %td= article.quantity + %td= article.quantity - article.quantity_available + %th= article.quantity_available + %td= article.unit + %td= article.price + %td= number_to_percentage article.tax + %td= link_to article.supplier.name, article.supplier + %td= article.article_category.name + %td + = link_to "Bearbeiten", edit_stock_article_path(article), class: 'btn btn-mini' + = link_to "Löschen", article, :method => :delete, :confirm => "Bist Du sicher?", + class: 'btn btn-mini btn-danger', :remote => true + %p Aktueller Lagerwert: = number_to_currency StockArticle.stock_value diff --git a/app/views/stockit_selections/_overview.html.haml b/app/views/stockit_selections/_overview.html.haml deleted file mode 100644 index 15f9b7f9..00000000 --- a/app/views/stockit_selections/_overview.html.haml +++ /dev/null @@ -1,19 +0,0 @@ - -%table.table.table-hover - %tr - %th Artikel - %th Erstellt am - %th Erstellt von - %th Optionen - - - stock_article_selections.each do |stock_article_selection| - %tr - %td=h truncate stock_article_selection.stock_articles.map{ |article| article.name}.join(', ') - %td=h stock_article_selection.created_at - %td=h link_to_user_message_if_valid stock_article_selection.created_by - %td - = link_to 'Anzeigen', stock_article_selection, class: 'btn btn-small' - = link_to "Artikel löschen", articles_stock_article_selection_path(stock_article_selection), :method => :delete, - :confirm => 'Diesen Löschvorschlag wirklich ausführen und markierte Artikel löschen?', class: 'btn btn-small btn-danger' - = link_to "Verwerfen", stock_article_selection, :method => :delete, - :confirm => 'Diesen Löschvorschlag wirklich verwerfen?', class: 'btn btn-small' diff --git a/app/views/stockit_selections/index.html.haml b/app/views/stockit_selections/index.html.haml deleted file mode 100644 index 99cac93f..00000000 --- a/app/views/stockit_selections/index.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -- title "Löschvorschläge für Lagerartikel" -- if @stock_article_selections.empty? - %p Es gibt keine ausstehenden Löschvorschläge. - %ul - %li= link_to "Löschvorschlag erstellen", stock_articles_path -- else - = render :partial => 'overview', :locals => {:stock_article_selections => @stock_article_selections} diff --git a/app/views/stockit_selections/show.html.haml b/app/views/stockit_selections/show.html.haml deleted file mode 100644 index 63ea5dfa..00000000 --- a/app/views/stockit_selections/show.html.haml +++ /dev/null @@ -1,18 +0,0 @@ -- title "Löschvorschlag für #{@stock_article_selection.stock_articles.count} Lagerartikel" - -%dl - %dt Löschvorschlag vom: - %dd=h @stock_article_selection.created_at - %dt Erstellt durch: - %dd=h link_to_user_message_if_valid(@stock_article_selection.created_by) - %dt Zu löschende Artikel - - for article in @stock_article_selection.stock_articles - %dd=h article.name - - -%p - = link_to 'Artikel löschen', articles_stock_article_selection_path(@stock_article_selection), :method => :delete, - :confirm => 'Diesen Löschvorschlag wirklich ausführen und markierte Artikel löschen?', class: 'btn btn-danger' - = link_to 'Verwerfen', @stock_article_selection, :method => :delete, - :confirm => 'Diesen Löschvorschlag wirklich verwerfen?', class: 'btn' - = link_to 'Alle Löschvorschläge zeigen', stock_article_selections_path, class: 'btn' diff --git a/config/routes.rb b/config/routes.rb index 9c27bbe7..aa8e0e29 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -89,14 +89,6 @@ Foodsoft::Application.routes.draw do post :add_stock_article end end - - resources :stock_article_selections, :controller => 'stockit_selections', - :only => [ :create, :show, :index, :destroy ], :path => "/stock_articles/selections" do - member do - delete 'articles' - end - end - resources :stock_articles, :to => 'stockit' do collection do diff --git a/db/migrate/20130112121840_create_stock_article_selections.rb b/db/migrate/20130112121840_create_stock_article_selections.rb deleted file mode 100644 index 2ead9008..00000000 --- a/db/migrate/20130112121840_create_stock_article_selections.rb +++ /dev/null @@ -1,18 +0,0 @@ -class CreateStockArticleSelections < ActiveRecord::Migration - def up - create_table :stock_article_selections do |t| - t.integer :created_by_user_id - t.timestamps - end - - create_table :stock_article_selections_stock_articles, :id => false do |t| - t.integer :stock_article_id - t.integer :stock_article_selection_id - end - end - - def down - drop_table :stock_article_selections - drop_table :stock_article_selections_stock_articles - end -end diff --git a/db/schema.rb b/db/schema.rb index bec2b950..188ea83b 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 => 20130112121840) do +ActiveRecord::Schema.define(:version => 20121230142516) do create_table "article_categories", :force => true do |t| t.string "name", :default => "", :null => false @@ -268,17 +268,6 @@ ActiveRecord::Schema.define(:version => 20130112121840) do add_index "pages", ["permalink"], :name => "index_pages_on_permalink" add_index "pages", ["title"], :name => "index_pages_on_title" - create_table "stock_article_selections", :force => true do |t| - t.integer "created_by_user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false - end - - create_table "stock_article_selections_stock_articles", :id => false, :force => true do |t| - t.integer "stock_article_id" - t.integer "stock_article_selection_id" - end - create_table "stock_changes", :force => true do |t| t.integer "delivery_id" t.integer "order_id" From 0e1bd5c75e0ed1d0f71adf94f63649b266a9c9b7 Mon Sep 17 00:00:00 2001 From: Julius Date: Mon, 25 Feb 2013 11:12:28 +0100 Subject: [PATCH 14/14] Improve (AJAX) deletion of StockArticles --- app/controllers/stockit_controller.rb | 6 +++--- app/views/stockit/_destroy_fail.js.haml | 8 +++----- app/views/stockit/destroy.js.haml | 15 ++++++++++++++- app/views/stockit/index.html.haml | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/controllers/stockit_controller.rb b/app/controllers/stockit_controller.rb index f70bec27..2a232a31 100644 --- a/app/controllers/stockit_controller.rb +++ b/app/controllers/stockit_controller.rb @@ -32,9 +32,9 @@ class StockitController < ApplicationController end def destroy - StockArticle.find(params[:id]).destroy - render :layout => false, - :locals => { :destroyed_article_id => params[:id] } + @article = StockArticle.find(params[:id]) + @article.destroy + render :layout => false rescue => error render :partial => "destroy_fail", :layout => false, :locals => { :fail_msg => "Ein Fehler ist aufgetreten: " + error.message } diff --git a/app/views/stockit/_destroy_fail.js.haml b/app/views/stockit/_destroy_fail.js.haml index 60b03d87..a9601900 100644 --- a/app/views/stockit/_destroy_fail.js.haml +++ b/app/views/stockit/_destroy_fail.js.haml @@ -1,7 +1,5 @@ --# please polish the following line if you know how -var errorDiv = $(''); - --# next line, createTextNode called by .text(textString) helps escaping for html, but what about ' signs? -errorDiv.text('#{fail_msg}'); +-# please polish the following line if you know how, same in view destroy +var errorDiv = $(''); +errorDiv.append(document.createTextNode('#{j(fail_msg)}')); $('div.container-fluid').prepend(errorDiv); diff --git a/app/views/stockit/destroy.js.haml b/app/views/stockit/destroy.js.haml index 39602dfb..66d6d70d 100644 --- a/app/views/stockit/destroy.js.haml +++ b/app/views/stockit/destroy.js.haml @@ -1 +1,14 @@ -console.log('#{destroyed_article_id}'); +-# please polish the following line if you know how, same in partial _destroy_fail +var successDiv = $(''); + +successDiv.append(document.createTextNode('Artikel #{j(@article.name)} gelöscht.')); +$('div.container-fluid').prepend(successDiv); + +-# WARNING: If you try to use the escape j(...) here, an error occurs: +-# Ein Fehler ist aufgetreten: undefined method `gsub' for 50:Fixnum +-# However, it should work without without escaping. +-# Note that article names which are purely numeric, e.g. 12345, are escaped correctly (see above). + +$('#stockArticle-#{@article.id}').remove(); + +-# WARNING: Do not use a simple .fadeOut() above, because it conflicts with the show/hide function of unavailable articles. diff --git a/app/views/stockit/index.html.haml b/app/views/stockit/index.html.haml index 6ceb0e91..c69c1689 100644 --- a/app/views/stockit/index.html.haml +++ b/app/views/stockit/index.html.haml @@ -44,7 +44,7 @@ %th %tbody - for article in @stock_articles - %tr{:class => stock_article_classes(article)} + %tr{:class => stock_article_classes(article), :id => "stockArticle-#{article.id}"} %td=h article.name %td= article.quantity %td= article.quantity - article.quantity_available