Merge remote-tracking branch 'bennibu/rails3' into rails3

Conflicts:
	app/controllers/articles_controller.rb
	app/views/articles/_form.html.haml
	app/views/articles/sync.html.haml
	app/views/finance/balancing/_edit_note.html.haml
	app/views/finance/group_order_articles/_form.html.haml
	app/views/finance/order_articles/_edit.html.haml
	app/views/finance/order_articles/_new.html.haml
	app/views/group_orders/show.html.haml
	app/views/invites/_modal_form.html.haml
This commit is contained in:
wvengen 2013-04-12 15:45:24 +02:00
commit f6ba21832d
15 changed files with 71 additions and 33 deletions

View file

@ -74,12 +74,12 @@ class ArticlesController < ApplicationController
end
# Updates all article of specific supplier
# deletes all articles from params[outlisted_articles]
def update_all
invalid_articles = false
begin
Article.transaction do
unless params[:articles].blank?
invalid_articles = false
# Update other article attributes...
@articles = Article.find(params[:articles].keys)
@articles.each do |article|
@ -88,25 +88,18 @@ class ArticlesController < ApplicationController
end
end
raise I18n.t('articles.update_all.error_invalid') if invalid_articles
end
# delete articles
if params[:outlisted_articles]
params[:outlisted_articles].keys.each {|id| Article.find(id).mark_as_deleted }
raise ActiveRecord::Rollback if invalid_articles # Rollback all changes
end
end
end
if invalid_articles
# An error has occurred, transaction has been rolled back.
flash.now.alert = I18n.t('articles.update_all.error_invalid')
render :edit_all
else
# Successfully done.
redirect_to supplier_articles_path(@supplier), notice: I18n.t('articles.update_all.notice')
rescue => e
# An error has occurred, transaction has been rolled back.
if params[:sync]
flash[:error] = I18n.t('articles.update_all.error_update', :article => current_article.name, :msg => e.message)
redirect_to(supplier_articles_path(@supplier))
else
flash.now.alert = e.message
render :edit_all
end
end
end
@ -232,4 +225,33 @@ class ArticlesController < ApplicationController
redirect_to supplier_articles_path(@supplier), :notice => I18n.t('articles.sync.notice')
end
end
# Updates, deletes articles when sync form is submitted
def update_synchronized
begin
Article.transaction do
# delete articles
if params[:outlisted_articles]
Article.find(params[:outlisted_articles].keys).each(&:mark_as_deleted)
end
# Update articles
params[:articles].each do |id, attrs|
Article.find(id).update_attributes! attrs
end
end
# Successfully done.
redirect_to supplier_articles_path(@supplier), notice: I18n.t('articles.update_synchronized.notice')
rescue ActiveRecord::RecordInvalid => invalid
# An error has occurred, transaction has been rolled back.
redirect_to supplier_articles_path(@supplier),
alert: I18n.t('articles.update_synchronized.error_update', :article => invalid.record.name, :msg => invalid.record.errors.full_messages)
rescue => error
redirect_to supplier_articles_path(@supplier),
alert: I18n.t('errors.general_msg', :msg => error.message)
end
end
end