refactored some js stuff. Fixed forms in article modul.

This commit is contained in:
benni 2011-05-19 19:49:37 +02:00
parent 9388e918a7
commit 1e33411516
25 changed files with 184 additions and 249 deletions

View file

@ -76,7 +76,7 @@ class ArticlesController < ApplicationController
# Renders a form for editing all articles from a supplier # Renders a form for editing all articles from a supplier
def edit_all def edit_all
@articles = @supplier.articles.without_deleted @articles = @supplier.articles
end end
# Updates all article of specific supplier # Updates all article of specific supplier
@ -130,14 +130,14 @@ class ArticlesController < ApplicationController
articles.each {|a| a.update_attribute(:availability, true) } articles.each {|a| a.update_attribute(:availability, true) }
flash[:notice] = 'Alle gewählten Artikel wurden auf "verfügbar" gesetzt' flash[:notice] = 'Alle gewählten Artikel wurden auf "verfügbar" gesetzt'
else else
flash[:error] = 'Keine Aktion ausgewählt!' flash[:alert] = 'Keine Aktion ausgewählt!'
end end
# action succeded # 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 rescue => error
flash[:error] = 'Ein Fehler ist aufgetreten: ' + e redirect_to supplier_articles_url(@supplier, :per_page => params[:per_page]),
redirect_to supplier_articles_path(@supplier, :per_page => params[:per_page]) :alert => "Ein Fehler ist aufgetreten: #{error}"
end end
# lets start with parsing articles from uploaded file, yeah # lets start with parsing articles from uploaded file, yeah
@ -174,10 +174,9 @@ class ArticlesController < ApplicationController
end end
@articles << article @articles << article
end end
flash.now[:notice] = @articles.size.to_s + " articles are parsed successfully." flash.now[:notice] = "#{@articles.size} articles are parsed successfully."
rescue => e rescue => error
flash[:error] = "An error has occurred: " + e.message redirect_to upload_supplier_articles_path(@supplier), :alert => "An error has occurred: #{error.message}"
redirect_to upload_supplier_articles_path(@supplier)
end end
end end

View file

@ -1,5 +1,4 @@
class HomeController < ApplicationController class HomeController < ApplicationController
helper :messages
def index def index
# unaccepted tasks # unaccepted tasks

View file

@ -6,9 +6,9 @@ module ArticlesHelper
end end
def row_classes(article) def row_classes(article)
classes = " click-me" classes = " "
classes += " unavailable" if !article.availability classes += " unavailable" if !article.availability
classes += " just_updated" if @article.recently_updated && @article.availability classes += " just_updated" if article.recently_updated && article.availability
classes classes
end end
end end

View file

@ -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

View file

@ -1,25 +0,0 @@
<td>
<%= check_box_tag 'selected_articles[]', @article.id.to_s, false,
{:id => "checkbox_#{@article.id.to_s}", :onclick => "checkRow('#{@article.id.to_s}')"} %>
</td>
<td><%= @article.name -%></td>
<td><%= @article.origin -%></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) -%>
| Brutto: <%= number_to_currency(@article.gross_price) -%>">
<%= number_to_currency(@article.price) -%>
</acronym>
</td>
<td><%= number_to_percentage(@article.tax) if @article.tax != 0 -%></td>
<td><%= number_to_currency(@article.deposit) if @article.deposit != 0 -%></td>
<td>
<%= 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>

View file

@ -25,7 +25,7 @@
%th[sort_td_class_helper "note"] %th[sort_td_class_helper "note"]
= sort_link_helper "Notiz", "note" = sort_link_helper "Notiz", "note"
%th{:style => "width: 4em;"} Gebgr. %th{:style => "width: 4em;"} Gebgr.
%th{:style => "width: 4em;"} Preis %th{:style => "width: 5em;"} Preis
%th{:style => "width: 3.5em;"} MwSt %th{:style => "width: 3.5em;"} MwSt
%th{:style => "width: 4em;"} Pfand %th{:style => "width: 4em;"} Pfand
%th{:style => "width: 3em;"} %th{:style => "width: 3em;"}
@ -33,19 +33,17 @@
%tbody#listbody %tbody#listbody
- if @total > 0 - if @total > 0
- for @article in @articles - for article in @articles
%tr{ :class => cycle('even','odd') + row_classes(@article), :id => @article.id, :onclick => "checkRow('#{@article.id.to_s}')"} = render(article)
= render :partial => 'article_row'
%tfoot %tfoot
%tr %tr
%td{:colspan => '11'} %td{:colspan => '11'}
= check_box_tag :checkall, 1, false, :onclick => 'checkUncheckAll(this)' = check_box_tag :checkall, 1, false, 'data-check-all' => '#articlesInListForm', 'data-ignore-onchange' => true
%select{:name => "selected_action"} %select{:name => "selected_action", 'data-submit-onchange' => true}
%option{:value => '', :selected => 'selected'} Aktion wählen ... %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 => "destroy", 'data-confirm' => 'Willst Du wirklich alle gewählten Artikel löschen?'} Artikel löschen
%option{:value => "setNotAvailable", :onclick => "this.up('form').submit()"} Artikel sind nicht mehr verfügbar %option{:value => "setNotAvailable"} Artikel sind nicht mehr verfügbar
%option{:value => "setAvailable", :onclick => "this.up('form').submit()"} Artikel sind verfügbar %option{:value => "setAvailable"} Artikel sind verfügbar
= hidden_field_tag 'supplier_id', @supplier.id = hidden_field_tag 'supplier_id', @supplier.id
%p= pagination_links_remote @articles, :params => {:sort => params[:sort]} %p= pagination_links_remote @articles, :params => {:sort => params[:sort]}

View file

@ -1,7 +0,0 @@
%h2
Bearbeiten von
= @article.name
zuletzt aktualisiert am:
= format_time(@article.updated_at)
= render :partial => "form"

View file

@ -1,2 +0,0 @@
%tr{:class => row_classes(@article), :id => @article.id, :onclick => "checkRow('#{@article.id.to_s}')"}
= render :partial => 'article_row'

View file

@ -1,2 +1,2 @@
$('#listbody').prepend('<%= escape_javascript(render("new_article_row")) %>'); $('#listbody').prepend('<%= escape_javascript(render(@article)) %>');
$.fancybox.close(); $.fancybox.close();

View file

@ -1,5 +1,5 @@
<% if @order %> <% if @order %>
$('#<%= @article.id %>').after('<%= escape_javascript(render("destroy_active_article")) %>'); $('#article_<%= @article.id %>').after('<%= escape_javascript(render("destroy_active_article")) %>');
<% else %> <% else %>
$('#<%= @article.id %>').remove(); $('#article_<%= @article.id %>').remove();
<% end %> <% end %>

View file

@ -1,64 +1,62 @@
<h1>Alle Artikel von <%= @supplier.name %> bearbeiten</h1> <% title "Alle Artikel von #{@supplier.name} bearbeiten" %>
<div class="single_column" style="width:100%"> <div class="single_column" style="width:100%">
<div id="change_supplier"> <div id="change_supplier">
<% form_tag do -%> <%= select_tag :switch_supplier,
<%= select_tag :switch_supplier, options_for_select( Supplier.all.collect {|s| [s.name, edit_all_supplier_articles_url(s)] },
options_for_select( Supplier.all.collect {|s| [s.name, url_for(edit_all_supplier_articles_path(s))] }, edit_all_supplier_articles_url(@supplier)),
url_for(edit_all_supplier_articles_path(@supplier)) ), 'data-redirect-to' => true,
:onchange => "redirectTo(this)", :style => "font-size: 0.9em;margin-left:1em;" %>
:style => "font-size: 0.9em;margin-left:1em;" %> </div>
<% end %>
</div>
<div class="box_title"> <div class="box_title">
<h2></h2> <h2></h2>
</div> </div>
<div class="box column_content"> <div class="box column_content">
<div id="links"><%= link_to 'zurück zur Liste', supplier_articles_path(@supplier) -%></div> <div id="links"><%= link_to 'zurück zur Liste', supplier_articles_path(@supplier) -%></div>
<p> <p>
<i> <i>
Pflichtfelder sind: Name, Einheit, (netto) Preis und Bestellnummer. Pflichtfelder sind: Name, Einheit, (netto) Preis und Bestellnummer.
</i> </i>
</p> </p>
<% form_tag(update_all_supplier_articles_path(@supplier)) do %> <%= form_tag(update_all_supplier_articles_path(@supplier)) do %>
<table id="articles_table" class="list"> <table id="articles_table" class="list">
<thead> <thead>
<tr> <tr>
<th><acronym title="verfügbar">verf.</acronym></th> <th><acronym title="verfügbar">verf.</acronym></th>
<th>Name</th> <th>Name</th>
<th>Einheit</th> <th>Einheit</th>
<th><acronym title="Netto!">Preis</acronym></th> <th><acronym title="Netto!">Preis</acronym></th>
<th><acronym title="Gebindegröße">GebGr</acronym></th> <th><acronym title="Gebindegröße">GebGr</acronym></th>
<th>Best.Nr.</th> <th>Best.Nr.</th>
<th>Notiz</th> <th>Notiz</th>
<th>Kategorie</th> <th>Kategorie</th>
<th>MwSt.</th> <th>MwSt.</th>
<th>Pfand</th> <th>Pfand</th>
</tr> </tr>
<tbody> <tbody>
<% for article in @articles %> <% for article in @articles %>
<% fields_for 'articles[]', article do |form| %> <%= fields_for 'articles[]', article do |form| %>
<tr class="<%= cycle('even', 'odd') %>"<%= ' style="background-color: yellow"' if @failedArticle == article %>> <tr class="<%= cycle('even', 'odd') %>"<%= ' style="background-color: yellow"' if @failedArticle == article %>>
<td colspan="2"> <td colspan="2">
<%= form.check_box 'availability' -%> <%= form.check_box 'availability' -%>
<%= form.text_field 'name', :size => 0 -%> <%= form.text_field 'name', :size => 0 -%>
</td> </td>
<td><%= form.text_field 'unit', :size => 5 -%></td> <td><%= form.text_field 'unit', :size => 5 -%></td>
<td><%= form.text_field 'price', :size => 4 -%></td> <td><%= form.text_field 'price', :size => 4 -%></td>
<td><%= form.text_field 'unit_quantity', :size => 4 -%></td> <td><%= form.text_field 'unit_quantity', :size => 4 -%></td>
<td><%= form.text_field 'order_number', :size => 6 -%></td> <td><%= form.text_field 'order_number', :size => 6 -%></td>
<td><%= form.text_field 'note', :size => 15 -%></td> <td><%= form.text_field 'note', :size => 15 -%></td>
<td><%= form.select 'article_category_id', ArticleCategory.find(:all).collect {|a| [ a.name, a.id ] }, { :include_blank => true } -%></td> <td><%= form.select 'article_category_id', ArticleCategory.find(:all).collect {|a| [ a.name, a.id ] }, { :include_blank => true } -%></td>
<td><%= form.text_field 'tax', :size => 4 -%></td> <td><%= form.text_field 'tax', :size => 4 -%></td>
<td><%= form.text_field 'deposit', :size => 4 -%></td> <td><%= form.text_field 'deposit', :size => 4 -%></td>
</tr> </tr>
<% end %> <% end %>
<% end %> <% end %>
<!--[eoform:article]--> <!--[eoform:article]-->
</tbody> </tbody>
</table><br /> </table><br />
<i>Achtung, alle Artikel werden aktualisiert!</i><br /> <i>Achtung, alle Artikel werden aktualisiert!</i><br />
<%= submit_tag 'Alle Artikel aktualisieren'%> | <%= link_to 'Abbrechen', supplier_articles_path(@supplier) %> <%= submit_tag 'Alle Artikel aktualisieren'%> | <%= link_to 'Abbrechen', supplier_articles_path(@supplier) %>
<% end %> <% end %>
</div> </div>
</div> </div>

View file

@ -7,19 +7,17 @@
%li %li
Zugriff auf externe Datenbank Zugriff auf externe Datenbank
%ul %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 %li= link_to "Synchronisieren", sync_supplier_articles_path(@supplier), :method => :post
#change_supplier{:style => "padding:0 0 0.5em 0.7em;"} #change_supplier{:style => "padding:0 0 0.5em 0.7em;"}
%span{:style => "float:left"} %span{:style => "float:left"}
Lieferantin wechseln: Lieferantin wechseln:
= form_tag do = select_tag :switch_supplier,
= select_tag :switch_supplier, options_for_select(Supplier.order(:name).map {|s| [s.name, supplier_articles_url(s)] }, supplier_articles_url(@supplier)),
options_for_select( Supplier.all(:order => 'name').collect {|s| [s.name, url_for(supplier_articles_path(s))] }, :style => "font-size: 0.9em;margin-left:1em;",
url_for(supplier_articles_path(@supplier)) ), 'data-redirect-to' => true
:onchange => "redirectTo(this)",
:style => "font-size: 0.9em;margin-left:1em;"
- unless @supplier.shared_supplier.nil? - unless @supplier.shared_supplier.nil?
#import.single_column{:style => "display:none; clear:both"} #import.single_column{:style => "display:none; clear:both"}
@ -40,7 +38,7 @@
= check_box_tag "regional", "1", false = check_box_tag "regional", "1", false
#search_results #search_results
// "import_search_results" will be rendered // "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'} .single_column{:style => 'width:100%; clear:both'}
.box_title .box_title
@ -57,12 +55,13 @@
#article_filter #article_filter
#article_search_form{:style=>"display:inline;"} #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: %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" = 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' #table= render 'articles'
#edit_article{:style => "display:none"} #edit_article{:style => "display:none"}

View file

@ -5,7 +5,7 @@
%br/ %br/
Achtung, momentan gibt es keine Überprüfung auf doppelte Artikel. 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 %table
%tr %tr
%th Nummer %th Nummer
@ -20,7 +20,7 @@
%th Gebindegröße %th Gebindegröße
%th Kategorie %th Kategorie
- for article in @articles - for article in @articles
- fields_for "articles[]", article do |form| = fields_for "articles[]", article do |form|
%tr{:class => cycle('even', 'odd')} %tr{:class => cycle('even', 'odd')}
%td= form.text_field 'order_number', :size => 6 %td= form.text_field 'order_number', :size => 6
%td= form.text_field 'name', :size => 0 %td= form.text_field 'name', :size => 0

View file

@ -1,2 +1,2 @@
$('#<%= @article.id %>').html('<%= escape_javascript(render("article_row")) %>'); $('#article_<%= @article.id %>').replaceWith('<%= escape_javascript(render(@article)) %>');
$.fancybox.close(); $.fancybox.close();

View file

@ -12,12 +12,12 @@
%i %i
Korrekte Reihenfolge der Spalten: Korrekte Reihenfolge der Spalten:
%br/ %br/
= ["Status (x=ausgelistet)", "Bestellnummer", "Name", "Notiz", "Hersteller", "Herkunft", | = ["Status (x=ausgelistet)", "Bestellnummer", "Name", "Notiz", "Hersteller", "Herkunft",
"Einheit", "Preis(netto)", "MwSt", "Pfand", "Gebindegröße", | "Einheit", "Preis(netto)", "MwSt", "Pfand", "Gebindegröße",
"Staffelmenge", "Staffelpreis", "Kategorie"].join(" | ") | "Staffelmenge", "Staffelpreis", "Kategorie"].join(" | ")
#uploadArticles.uploadForm #uploadArticles.uploadForm
- form_for :articles, :url => parse_upload_supplier_articles_path(@supplier), | = form_for :articles, :url => parse_upload_supplier_articles_path(@supplier),
:html => { :multipart => true } do |form| | :html => { :multipart => true } do |form|
%p= form.file_field "file" %p= form.file_field "file"
%p= submit_tag "Datei hochladen" %p= submit_tag "Datei hochladen"

View file

@ -5,23 +5,13 @@
%h2 Übersicht %h2 Übersicht
.column_content .column_content
#filter{:style => "margin-right:2em;"} #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: %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: %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) %small (mindestens einmal in den letzten 3 Monaten bestellt)
#ordergroups #ordergroups
= render :partial => "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();
});
});

View file

@ -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 %h1 Mitglieder der Foodcoop
%p %p
%i %i
@ -24,9 +13,10 @@
.column_content .column_content
- unless params[:sort_by_ordergroups] - unless params[:sort_by_ordergroups]
#user_filter{:style => "float:left; margin-right:2em;"} #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: %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: Nach Bestellgruppen sortieren:
= check_box_tag :sort_by_ordergroups, 1, params[:sort_by_ordergroups] = check_box_tag :sort_by_ordergroups, 1, params[:sort_by_ordergroups]

View file

@ -42,7 +42,7 @@
.box_title .box_title
%h2 Neuste Nachrichten %h2 Neuste Nachrichten
.column_content .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/ %br/
= link_to "Alle Nachrichten einsehen", messages_path = link_to "Alle Nachrichten einsehen", messages_path

View file

@ -16,9 +16,9 @@
#sidebar #sidebar
#sidebar-links #sidebar-links
= link_to "Bearbeiten", edit_page_path(@page) = 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? - unless @page.children.empty?
= link_to "Unterseiten", "#subpages", 'data-toggle_this' => '#subpages' = link_to "Unterseiten", "#subpages", 'data-toggle-this' => '#subpages'
#versions{:style => "display:none"} #versions{:style => "display:none"}
.box_title .box_title
%h2 Versionen %h2 Versionen

View file

@ -1,5 +1,5 @@
- for workgroup in Workgroup.all - 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] %ul{:style => "display:none"}[workgroup]
- for user in workgroup.users.order("nick") - for user in workgroup.users.order("nick")
%li= "#{user.nick} (#{user.ordergroup.try(:name)})" %li= "#{user.nick} (#{user.ordergroup.try(:name)})"

View file

@ -168,6 +168,7 @@ de:
unit_quantity: Gebindegröße unit_quantity: Gebindegröße
tax: MwSt tax: MwSt
deposit: Pfand deposit: Pfand
article_category: Kategorie
stock_article: stock_article:
price: Nettopreis price: Nettopreis
user: user:

View file

@ -2,9 +2,6 @@ Foodsoft::Application.routes.draw do
get "sessions/new" get "sessions/new"
# Use routing filter to select foodcoop config and datbase
# filter :foodcoop
root :to => redirect("/#{Foodsoft.env}") root :to => redirect("/#{Foodsoft.env}")
scope '/:foodcoop', :defaults => { :foodcoop => Foodsoft.env } do scope '/:foodcoop', :defaults => { :foodcoop => Foodsoft.env } do

View file

@ -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

View file

@ -1,58 +1,71 @@
// Load following statements, when DOM is ready // Load following statements, when DOM is ready
$(function() { $(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; 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:
// <input type="checkbox" name="checkall" onclick="checkUncheckAll(this);"/>
// credit to Shawn Olson & http://www.shawnolson.net
function checkUncheckAll(theElement) {
var theForm = theElement.form, z = 0;
for(z=0; z<theForm.length;z++){
if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
theForm[z].checked = theElement.checked;
// remove "checkbox_" in form-id before call highligh-function
highlightRow(theForm[z].id.substring(9), theElement.checked);
}
}
}
// gives the row an yellow background // gives the row an yellow background
function highlightRow(row_id,status) { function highlightRow(checkbox) {
if(status) { var row = checkbox.parents('tr');
$(row_id).addClassName("selected"); if (checkbox.is(':checked')) {
} else { row.addClass('selected');
$(row_id).removeClassName("selected"); } else {
} row.removeClass('selected');
} }
// check or uncheck a given checkbox and adds or removes class "selected"
// used prototype to get the element
function checkRow(id) {
var checkbox = "checkbox_" + id
if($(checkbox).checked) {
$(checkbox).checked = false;
highlightRow(id,false);
} else {
$(checkbox).checked = true;
highlightRow(id,true);
}
}
// redirect to another "item"
// this function is used with an select menu
// for an example see app/views/articles/list.haml
function redirectTo(newLoc) {
nextPage = newLoc.options[newLoc.selectedIndex].value
if (nextPage != "") {
document.location.href = nextPage
}
} }
// Use with auto_complete to set a unique id, // Use with auto_complete to set a unique id,

View file

@ -246,7 +246,7 @@ table {
color: #008000; } color: #008000; }
table tr.selected, table tr.active { table tr.selected, table tr.active {
background-color: #ffffc2; } background-color: #ffffc2; }
table tr.click-me { table tr.click-me, table td.click-me {
cursor: pointer; } cursor: pointer; }
table tr.ignored { table tr.ignored {
color: grey; } color: grey; }