Implemented fancy box for ajax forms. Refactored articles modul.
This commit is contained in:
parent
0decbb36e1
commit
9388e918a7
36 changed files with 490 additions and 157 deletions
|
|
@ -25,68 +25,35 @@ class ArticlesController < ApplicationController
|
|||
sort = "article_categories.name, articles.name"
|
||||
end
|
||||
|
||||
# if somebody uses the search field:
|
||||
conditions = ["articles.name LIKE ?", "%#{params[:query]}%"] unless params[:query].nil?
|
||||
@articles = @supplier.articles.includes(:article_category).order(sort)
|
||||
@articles = @articles.where(:name.matches => "%#{params[:query]}%") unless params[:query].nil?
|
||||
|
||||
@total = @supplier.articles.count(:conditions => conditions)
|
||||
@articles = @supplier.articles.paginate(
|
||||
:order => sort,
|
||||
:conditions => conditions,
|
||||
:page => params[:page],
|
||||
:per_page => @per_page,
|
||||
:include => :article_category
|
||||
)
|
||||
@total = @articles.size
|
||||
@articles = @articles.paginate(:page => params[:page], :per_page => @per_page)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # list.haml
|
||||
format.js do
|
||||
render :update do |page|
|
||||
page.replace_html 'table', :partial => "articles"
|
||||
end
|
||||
end
|
||||
format.html
|
||||
format.js { render :layout => false }
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@article = @supplier.articles.build(:tax => 7.0)
|
||||
|
||||
render :update do |page|
|
||||
page["edit_article"].replace_html :partial => 'new'
|
||||
page["edit_article"].show
|
||||
end
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def create
|
||||
@article = Article.new(params[:article])
|
||||
if @article.valid? and @article.save
|
||||
render :update do |page|
|
||||
page.Element.hide('edit_article')
|
||||
page.insert_html :top, 'listbody', :partial => 'new_article_row'
|
||||
page[@article.id.to_s].visual_effect(:highlight,
|
||||
:duration => 2)
|
||||
# highlights article
|
||||
if !@article.availability
|
||||
page[@article.id.to_s].addClassName 'unavailable'
|
||||
else
|
||||
page[@article.id.to_s].addClassName 'just_updated'
|
||||
end
|
||||
end
|
||||
render :layout => false
|
||||
else
|
||||
render :update do |page|
|
||||
page.replace_html 'edit_article', :partial => "new"
|
||||
end
|
||||
end
|
||||
render :action => 'new', :layout => false
|
||||
end
|
||||
end
|
||||
|
||||
# edit an article and its price
|
||||
def edit
|
||||
@article = Article.find(params[:id])
|
||||
|
||||
render :update do |page|
|
||||
page["edit_article"].replace_html :partial => 'edit'
|
||||
page["edit_article"].show
|
||||
end
|
||||
#render :partial => "quick_edit", :layout => false
|
||||
render :action => 'new', :layout => false
|
||||
end
|
||||
|
||||
# Updates one Article and highlights the line if succeded
|
||||
|
|
@ -94,46 +61,17 @@ class ArticlesController < ApplicationController
|
|||
@article = Article.find(params[:id])
|
||||
|
||||
if @article.update_attributes(params[:article])
|
||||
render :update do |page|
|
||||
page["edit_article"].hide
|
||||
page[@article.id.to_s].replace_html :partial => 'article_row'
|
||||
|
||||
# hilights an updated article if the article ist available
|
||||
page[@article.id.to_s].addClassName 'just_updated' if @article.availability
|
||||
|
||||
# highlights an available article and de-highlights in other case
|
||||
if !@article.availability
|
||||
page[@article.id.to_s].addClassName 'unavailable'
|
||||
# remove updated-class
|
||||
page[@article.id.to_s].removeClassName 'just_updated'
|
||||
else
|
||||
page[@article.id.to_s].removeClassName 'unavailable'
|
||||
end
|
||||
|
||||
page[@article.id.to_s].visual_effect(:highlight, :delay => 0.5, :duration => 2)
|
||||
end
|
||||
render :layout => false
|
||||
else
|
||||
render :update do |page|
|
||||
page["edit_article"].replace_html :partial => "edit"
|
||||
end
|
||||
render :action => 'new', :layout => false
|
||||
end
|
||||
end
|
||||
|
||||
# Deletes article from database. send error msg, if article is used in a current order
|
||||
def destroy
|
||||
@article = Article.find(params[:id])
|
||||
|
||||
@order = @article.in_open_order # If article is in an active Order, the Order will be returned
|
||||
if @order
|
||||
render :update do |page|
|
||||
page.insert_html :after, @article.id.to_s, :partial => 'destroyActiveArticle'
|
||||
end
|
||||
else
|
||||
@article.destroy
|
||||
render :update do |page|
|
||||
page[@article.id.to_s].remove
|
||||
end
|
||||
end
|
||||
@article.destroy unless @order = @article.in_open_order # If article is in an active Order, the Order will be returned
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
# Renders a form for editing all articles from a supplier
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
<%= check_box_tag 'selected_articles[]', @article.id.to_s, false,
|
||||
{:id => "checkbox_#{@article.id.to_s}", :onclick => "checkRow('#{@article.id.to_s}')"} %>
|
||||
</td>
|
||||
<td><%=h @article.name -%></td>
|
||||
<td><%= @article.name -%></td>
|
||||
<td><%= @article.origin -%></td>
|
||||
<td><%=h truncate(@article.article_category.name, :length => 11) if @article.article_category -%></td>
|
||||
<td><%=h @article.unit -%></td>
|
||||
<td><%=h truncate(@article.note, :length => 11) -%></td>
|
||||
<td><%= truncate(@article.article_category.name, :length => 11) if @article.article_category -%></td>
|
||||
<td><%= @article.unit -%></td>
|
||||
<td><%= truncate(@article.note, :length => 11) -%></td>
|
||||
<td><%= @article.unit_quantity -%></td>
|
||||
<td class="currency">
|
||||
<acronym title="zuletzt geändert: <%= format_date(@article.updated_at) -%>
|
||||
|
|
@ -17,11 +17,9 @@
|
|||
<td><%= number_to_percentage(@article.tax) if @article.tax != 0 -%></td>
|
||||
<td><%= number_to_currency(@article.deposit) if @article.deposit != 0 -%></td>
|
||||
<td>
|
||||
<%= remote_link_to icon(:edit, :onclick => "checkRow('#{@article.id.to_s}')"),
|
||||
:url => edit_supplier_article_path(@supplier, @article) %>
|
||||
<%= remote_link_to icon(:delete, :onclick => "checkRow('#{@article.id.to_s}')"),
|
||||
:url => [@supplier, @article],
|
||||
:method => :delete,
|
||||
:confirm => 'Bist du sicher?' %>
|
||||
<%= 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 %>
|
||||
</td>
|
||||
|
||||
|
|
@ -4,6 +4,4 @@
|
|||
wird in laufenden Bestellungen verwendet und kann nicht gelöscht werden.
|
||||
Bitte zuerst den Artikel aus den Bestellungen
|
||||
= link_to "entfernen", :controller => 'orders', :action => 'edit', :id => @order
|
||||
oder
|
||||
= link_to_function 'abbrechen', "Element.remove('edit_#{@article.id.to_s}')"
|
||||
|
||||
|
|
@ -1,45 +1,18 @@
|
|||
- remote_form_for [@supplier, @article], :before => "Element.show('loader')", |
|
||||
:success => "Element.hide('loader')" do |form| |
|
||||
= simple_form_for [@supplier, @article], :remote => true do |f|
|
||||
= f.input :availability
|
||||
= f.input :name
|
||||
= f.input :origin
|
||||
= f.input :manufacturer
|
||||
= f.input :unit
|
||||
= f.input :note
|
||||
= f.association :article_category
|
||||
|
||||
= form.error_messages
|
||||
%p
|
||||
%b Verfügbar?
|
||||
= form.check_box :availability
|
||||
%table{ :style => "width: 20em"}
|
||||
%tr
|
||||
%th Name
|
||||
%th Herkunft
|
||||
%th Hersteller
|
||||
%th Einheit
|
||||
%th Notiz
|
||||
%th kategorie
|
||||
%tbody
|
||||
%tr
|
||||
%td= form.text_field :name, :size => 15
|
||||
%td= form.text_field :origin, :size => 5
|
||||
%td= form.text_field :manufacturer, :size => 8
|
||||
%td= form.text_field :unit, :size => 5
|
||||
%td= form.text_field :note, :size => 15
|
||||
%td= form.select :article_category_id, ArticleCategory.find(:all, :order => 'name').collect {|a| [ a.name, a.id ] }
|
||||
%br/
|
||||
%table{ :style=>"width:35em"}
|
||||
%tr
|
||||
%th Nettopreis
|
||||
%th Gebindegröße
|
||||
%th Bestellnummer
|
||||
%th MwSt
|
||||
%th Pfand
|
||||
%tbody
|
||||
%tr
|
||||
%td= form.text_field :price, :size => 5
|
||||
%td= form.text_field :unit_quantity, :size => 5
|
||||
%td= form.text_field :order_number, :size => 10
|
||||
%td= form.text_field :tax, :size => 5
|
||||
%td= form.text_field :deposit, :size => 5
|
||||
|
||||
= form.hidden_field :shared_updated_on
|
||||
= form.hidden_field :supplier_id
|
||||
= f.input :price
|
||||
= f.input :unit_quantity
|
||||
= f.input :order_number
|
||||
= f.input :tax
|
||||
= f.input :deposit
|
||||
= f.submit
|
||||
|
||||
= submit_tag "Speichern"
|
||||
|
|
||||
= link_to_function "Abbrechen", "Element.hide('edit_article')"
|
||||
= f.hidden_field :shared_updated_on
|
||||
= f.hidden_field :supplier_id
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
%h3 Neuer Artikel
|
||||
= render :partial => 'form'
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
%tr{:class => cycle('even','odd'), :id => @article.id, :onclick => "checkRow('#{@article.id.to_s}')"}
|
||||
%tr{:class => row_classes(@article), :id => @article.id, :onclick => "checkRow('#{@article.id.to_s}')"}
|
||||
= render :partial => 'article_row'
|
||||
2
app/views/articles/create.js.erb
Normal file
2
app/views/articles/create.js.erb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$('#listbody').prepend('<%= escape_javascript(render("new_article_row")) %>');
|
||||
$.fancybox.close();
|
||||
5
app/views/articles/destroy.js.erb
Normal file
5
app/views/articles/destroy.js.erb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<% if @order %>
|
||||
$('#<%= @article.id %>').after('<%= escape_javascript(render("destroy_active_article")) %>');
|
||||
<% else %>
|
||||
$('#<%= @article.id %>').remove();
|
||||
<% end %>
|
||||
|
|
@ -7,19 +7,19 @@
|
|||
%li
|
||||
Zugriff auf externe Datenbank
|
||||
%ul
|
||||
%li= link_to_function "Suchen/Importieren", "Element.toggle('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;" |
|
||||
= 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;"
|
||||
|
||||
- unless @supplier.shared_supplier.nil?
|
||||
#import.single_column{:style => "display:none; clear:both"}
|
||||
|
|
@ -27,9 +27,7 @@
|
|||
%h2 Artikel importieren
|
||||
.column_content
|
||||
#search{:style => "padding-bottom:3em"}
|
||||
- form_remote_tag :url => shared_supplier_articles_path(@supplier), |
|
||||
:before => "Element.show('loader')", :success => "Element.hide('loader')", |
|
||||
:method => :get do |
|
||||
= form_tag shared_supplier_articles_path(@supplier), :method => :get, :remote => true do
|
||||
= text_field_tag :import_query, params['import_query'], :size => 10
|
||||
= submit_tag "Suchen"
|
||||
- if @supplier.shared_supplier.lists
|
||||
|
|
@ -42,30 +40,29 @@
|
|||
= check_box_tag "regional", "1", false
|
||||
#search_results
|
||||
// "import_search_results" will be rendered
|
||||
= link_to_function "Schließen", "Element.hide('import')"
|
||||
= link_to "Schließen", "#import", 'data-toggle_this' => '#import'
|
||||
|
||||
.single_column{:style => 'width:100%; clear:both'}
|
||||
.box_title
|
||||
.column_content
|
||||
#links
|
||||
%b= remote_link_to "Neuer Artikel", :url => new_supplier_article_path(@supplier)
|
||||
%b= link_to "Neuer Artikel", new_supplier_article_path(@supplier), :remote => true
|
||||
|
|
||||
= link_to "Alle bearbeiten", edit_all_supplier_articles_path(@supplier)
|
||||
|
|
||||
= link_to "Artikel hochladen", upload_supplier_articles_path(@supplier)
|
||||
|
|
||||
= link_to_if @current_user.role_orders?, "Bestellung anlegen", {:controller => 'orders', :action => 'new', :supplier_id => @supplier }
|
||||
- if current_user.role_orders?
|
||||
|
|
||||
= link_to "Bestellung anlegen", new_order_path(:supplier_id => @supplier)
|
||||
|
||||
#article_filter
|
||||
#article_search_form{:style=>"display:inline;"}
|
||||
- form_remote_tag :url => supplier_articles_path(@supplier), |
|
||||
:before => "Element.show('loader')", :success => "Element.hide('loader')", |
|
||||
:method => :get do |
|
||||
= form_tag supplier_articles_path(@supplier), :method => :get, :remote => true do
|
||||
%label{:for => 'article_name'} Suche im Artikelnamen:
|
||||
= text_field_tag("query", params['query'], :size => 10 )
|
||||
= submit_tag "Suchen"
|
||||
|
||||
%form{ :action => url_for(update_selected_supplier_articles_path(@supplier)), :method => "post", :id => "articlesInListForm" }
|
||||
#table= render :partial => 'articles'
|
||||
|
||||
= form_tag update_selected_supplier_articles_path(@supplier), :id => "articlesInListForm" do
|
||||
#table= render 'articles'
|
||||
|
||||
#edit_article{:style => "display:none"}
|
||||
|
|
|
|||
1
app/views/articles/index.js.erb
Normal file
1
app/views/articles/index.js.erb
Normal file
|
|
@ -0,0 +1 @@
|
|||
$('#table').html('<%= escape_javascript(render("articles")) %>');
|
||||
1
app/views/articles/new.js.erb
Normal file
1
app/views/articles/new.js.erb
Normal file
|
|
@ -0,0 +1 @@
|
|||
$.fancybox('<%= escape_javascript(render("form")) %>');
|
||||
2
app/views/articles/update.js.erb
Normal file
2
app/views/articles/update.js.erb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$('#<%= @article.id %>').html('<%= escape_javascript(render("article_row")) %>');
|
||||
$.fancybox.close();
|
||||
|
|
@ -3,13 +3,14 @@
|
|||
%head
|
||||
%meta{"http-equiv" => "content-type", :content => "text/html;charset=UTF-8"}
|
||||
%title= "FoodSoft - " + (yield(:title) or controller.controller_name)
|
||||
= stylesheet_link_tag 'main', 'rails_messages', 'nav', 'simple_form', 'token-input', :cache => "all_cached"
|
||||
= stylesheet_link_tag 'main', 'rails_messages', 'nav', 'simple_form', 'token-input', 'jquery.fancybox-1.3.4',
|
||||
:cache => "all_cached"
|
||||
= stylesheet_link_tag "print", :media => "print"
|
||||
<!--[if lte IE 7]>
|
||||
= stylesheet_link_tag 'ie_hacks'
|
||||
<![endif]-->
|
||||
= javascript_include_tag 'jquery.min', 'jquery-ui.min', 'jquery_ujs', 'jquery.tokeninput', 'jquery.observe_field',
|
||||
'application', 'ordering', :cache => "all_cached"
|
||||
'application', 'ordering', 'jquery.fancybox-1.3.4.pack', :cache => 'all_cached'
|
||||
= csrf_meta_tag
|
||||
= yield(:head)
|
||||
%body
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue