refactored some js stuff. Fixed forms in article modul.
This commit is contained in:
parent
9388e918a7
commit
1e33411516
25 changed files with 184 additions and 249 deletions
|
@ -76,7 +76,7 @@ class ArticlesController < ApplicationController
|
|||
|
||||
# Renders a form for editing all articles from a supplier
|
||||
def edit_all
|
||||
@articles = @supplier.articles.without_deleted
|
||||
@articles = @supplier.articles
|
||||
end
|
||||
|
||||
# Updates all article of specific supplier
|
||||
|
@ -130,14 +130,14 @@ class ArticlesController < ApplicationController
|
|||
articles.each {|a| a.update_attribute(:availability, true) }
|
||||
flash[:notice] = 'Alle gewählten Artikel wurden auf "verfügbar" gesetzt'
|
||||
else
|
||||
flash[:error] = 'Keine Aktion ausgewählt!'
|
||||
flash[:alert] = 'Keine Aktion ausgewählt!'
|
||||
end
|
||||
# action succeded
|
||||
redirect_to supplier_articles_path(@supplier, :per_page => params[:per_page])
|
||||
redirect_to supplier_articles_url(@supplier, :per_page => params[:per_page])
|
||||
|
||||
rescue => e
|
||||
flash[:error] = 'Ein Fehler ist aufgetreten: ' + e
|
||||
redirect_to supplier_articles_path(@supplier, :per_page => params[:per_page])
|
||||
rescue => error
|
||||
redirect_to supplier_articles_url(@supplier, :per_page => params[:per_page]),
|
||||
:alert => "Ein Fehler ist aufgetreten: #{error}"
|
||||
end
|
||||
|
||||
# lets start with parsing articles from uploaded file, yeah
|
||||
|
@ -174,10 +174,9 @@ class ArticlesController < ApplicationController
|
|||
end
|
||||
@articles << article
|
||||
end
|
||||
flash.now[:notice] = @articles.size.to_s + " articles are parsed successfully."
|
||||
rescue => e
|
||||
flash[:error] = "An error has occurred: " + e.message
|
||||
redirect_to upload_supplier_articles_path(@supplier)
|
||||
flash.now[:notice] = "#{@articles.size} articles are parsed successfully."
|
||||
rescue => error
|
||||
redirect_to upload_supplier_articles_path(@supplier), :alert => "An error has occurred: #{error.message}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
class HomeController < ApplicationController
|
||||
helper :messages
|
||||
|
||||
def index
|
||||
# unaccepted tasks
|
||||
|
|
|
@ -6,9 +6,9 @@ module ArticlesHelper
|
|||
end
|
||||
|
||||
def row_classes(article)
|
||||
classes = " click-me"
|
||||
classes = " "
|
||||
classes += " unavailable" if !article.availability
|
||||
classes += " just_updated" if @article.recently_updated && @article.availability
|
||||
classes += " just_updated" if article.recently_updated && article.availability
|
||||
classes
|
||||
end
|
||||
end
|
20
app/views/articles/_article.html.haml
Normal file
20
app/views/articles/_article.html.haml
Normal 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
|
||||
|
||||
|
|
@ -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>
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
%th[sort_td_class_helper "note"]
|
||||
= sort_link_helper "Notiz", "note"
|
||||
%th{:style => "width: 4em;"} Gebgr.
|
||||
%th{:style => "width: 4em;"} Preis
|
||||
%th{:style => "width: 5em;"} Preis
|
||||
%th{:style => "width: 3.5em;"} MwSt
|
||||
%th{:style => "width: 4em;"} Pfand
|
||||
%th{:style => "width: 3em;"}
|
||||
|
@ -33,19 +33,17 @@
|
|||
%tbody#listbody
|
||||
|
||||
- if @total > 0
|
||||
- for @article in @articles
|
||||
%tr{ :class => cycle('even','odd') + row_classes(@article), :id => @article.id, :onclick => "checkRow('#{@article.id.to_s}')"}
|
||||
= render :partial => 'article_row'
|
||||
- for article in @articles
|
||||
= render(article)
|
||||
%tfoot
|
||||
%tr
|
||||
%td{:colspan => '11'}
|
||||
= check_box_tag :checkall, 1, false, :onclick => 'checkUncheckAll(this)'
|
||||
%select{:name => "selected_action"}
|
||||
= check_box_tag :checkall, 1, false, 'data-check-all' => '#articlesInListForm', 'data-ignore-onchange' => true
|
||||
%select{:name => "selected_action", 'data-submit-onchange' => true}
|
||||
%option{:value => '', :selected => 'selected'} Aktion wählen ...
|
||||
%option{:value => "destroy", :onclick => "if (confirm('Willst Du wirklich alle gewählten Artikel löschen?')) { this.up('form').submit(); }; return false;"} Artikel löschen
|
||||
%option{:value => "setNotAvailable", :onclick => "this.up('form').submit()"} Artikel sind nicht mehr verfügbar
|
||||
%option{:value => "setAvailable", :onclick => "this.up('form').submit()"} Artikel sind verfügbar
|
||||
|
||||
%option{:value => "destroy", 'data-confirm' => 'Willst Du wirklich alle gewählten Artikel löschen?'} Artikel löschen
|
||||
%option{:value => "setNotAvailable"} Artikel sind nicht mehr verfügbar
|
||||
%option{:value => "setAvailable"} Artikel sind verfügbar
|
||||
= hidden_field_tag 'supplier_id', @supplier.id
|
||||
|
||||
%p= pagination_links_remote @articles, :params => {:sort => params[:sort]}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
%h2
|
||||
Bearbeiten von
|
||||
= @article.name
|
||||
zuletzt aktualisiert am:
|
||||
= format_time(@article.updated_at)
|
||||
|
||||
= render :partial => "form"
|
|
@ -1,2 +0,0 @@
|
|||
%tr{:class => row_classes(@article), :id => @article.id, :onclick => "checkRow('#{@article.id.to_s}')"}
|
||||
= render :partial => 'article_row'
|
|
@ -1,2 +1,2 @@
|
|||
$('#listbody').prepend('<%= escape_javascript(render("new_article_row")) %>');
|
||||
$('#listbody').prepend('<%= escape_javascript(render(@article)) %>');
|
||||
$.fancybox.close();
|
|
@ -1,5 +1,5 @@
|
|||
<% if @order %>
|
||||
$('#<%= @article.id %>').after('<%= escape_javascript(render("destroy_active_article")) %>');
|
||||
$('#article_<%= @article.id %>').after('<%= escape_javascript(render("destroy_active_article")) %>');
|
||||
<% else %>
|
||||
$('#<%= @article.id %>').remove();
|
||||
$('#article_<%= @article.id %>').remove();
|
||||
<% end %>
|
|
@ -1,14 +1,12 @@
|
|||
<h1>Alle Artikel von <%= @supplier.name %> bearbeiten</h1>
|
||||
<% title "Alle Artikel von #{@supplier.name} bearbeiten" %>
|
||||
|
||||
<div class="single_column" style="width:100%">
|
||||
<div id="change_supplier">
|
||||
<% form_tag do -%>
|
||||
<%= select_tag :switch_supplier,
|
||||
options_for_select( Supplier.all.collect {|s| [s.name, url_for(edit_all_supplier_articles_path(s))] },
|
||||
url_for(edit_all_supplier_articles_path(@supplier)) ),
|
||||
:onchange => "redirectTo(this)",
|
||||
options_for_select( Supplier.all.collect {|s| [s.name, edit_all_supplier_articles_url(s)] },
|
||||
edit_all_supplier_articles_url(@supplier)),
|
||||
'data-redirect-to' => true,
|
||||
:style => "font-size: 0.9em;margin-left:1em;" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="box_title">
|
||||
<h2></h2>
|
||||
|
@ -20,7 +18,7 @@
|
|||
Pflichtfelder sind: Name, Einheit, (netto) Preis und Bestellnummer.
|
||||
</i>
|
||||
</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">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -37,7 +35,7 @@
|
|||
</tr>
|
||||
<tbody>
|
||||
<% 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 %>>
|
||||
<td colspan="2">
|
||||
<%= form.check_box 'availability' -%>
|
||||
|
|
|
@ -7,19 +7,17 @@
|
|||
%li
|
||||
Zugriff auf externe Datenbank
|
||||
%ul
|
||||
%li= link_to "Suchen/Importieren", "#import", 'data-toggle_this' => '#import'
|
||||
%li= link_to "Suchen/Importieren", "#import", 'data-toggle-this' => '#import'
|
||||
%li= link_to "Synchronisieren", sync_supplier_articles_path(@supplier), :method => :post
|
||||
|
||||
|
||||
#change_supplier{:style => "padding:0 0 0.5em 0.7em;"}
|
||||
%span{:style => "float:left"}
|
||||
Lieferantin wechseln:
|
||||
= form_tag do
|
||||
= select_tag :switch_supplier,
|
||||
options_for_select( Supplier.all(:order => 'name').collect {|s| [s.name, url_for(supplier_articles_path(s))] },
|
||||
url_for(supplier_articles_path(@supplier)) ),
|
||||
:onchange => "redirectTo(this)",
|
||||
:style => "font-size: 0.9em;margin-left:1em;"
|
||||
options_for_select(Supplier.order(:name).map {|s| [s.name, supplier_articles_url(s)] }, supplier_articles_url(@supplier)),
|
||||
:style => "font-size: 0.9em;margin-left:1em;",
|
||||
'data-redirect-to' => true
|
||||
|
||||
- unless @supplier.shared_supplier.nil?
|
||||
#import.single_column{:style => "display:none; clear:both"}
|
||||
|
@ -40,7 +38,7 @@
|
|||
= check_box_tag "regional", "1", false
|
||||
#search_results
|
||||
// "import_search_results" will be rendered
|
||||
= link_to "Schließen", "#import", 'data-toggle_this' => '#import'
|
||||
= link_to "Schließen", "#import", 'data-toggle-this' => '#import'
|
||||
|
||||
.single_column{:style => 'width:100%; clear:both'}
|
||||
.box_title
|
||||
|
@ -57,12 +55,13 @@
|
|||
|
||||
#article_filter
|
||||
#article_search_form{:style=>"display:inline;"}
|
||||
= form_tag supplier_articles_path(@supplier), :method => :get, :remote => true do
|
||||
= form_tag supplier_articles_path(@supplier), :method => :get, :remote => true, 'data-submit-onchange' => true do
|
||||
%label{:for => 'article_name'} Suche im Artikelnamen:
|
||||
= text_field_tag("query", params['query'], :size => 10 )
|
||||
= text_field_tag :query, params[:query], :size => 10
|
||||
= submit_tag "Suchen"
|
||||
|
||||
= form_tag update_selected_supplier_articles_path(@supplier), :id => "articlesInListForm" do
|
||||
= form_tag update_selected_supplier_articles_path(@supplier), :id => "articlesInListForm",
|
||||
'data-submit-onchange' => true do
|
||||
#table= render 'articles'
|
||||
|
||||
#edit_article{:style => "display:none"}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
%br/
|
||||
Achtung, momentan gibt es keine Überprüfung auf doppelte Artikel.
|
||||
|
||||
- form_tag(create_from_upload_supplier_articles_path(@supplier)) do
|
||||
= form_tag(create_from_upload_supplier_articles_path(@supplier)) do
|
||||
%table
|
||||
%tr
|
||||
%th Nummer
|
||||
|
@ -20,7 +20,7 @@
|
|||
%th Gebindegröße
|
||||
%th Kategorie
|
||||
- for article in @articles
|
||||
- fields_for "articles[]", article do |form|
|
||||
= fields_for "articles[]", article do |form|
|
||||
%tr{:class => cycle('even', 'odd')}
|
||||
%td= form.text_field 'order_number', :size => 6
|
||||
%td= form.text_field 'name', :size => 0
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
$('#<%= @article.id %>').html('<%= escape_javascript(render("article_row")) %>');
|
||||
$('#article_<%= @article.id %>').replaceWith('<%= escape_javascript(render(@article)) %>');
|
||||
$.fancybox.close();
|
|
@ -12,12 +12,12 @@
|
|||
%i
|
||||
Korrekte Reihenfolge der Spalten:
|
||||
%br/
|
||||
= ["Status (x=ausgelistet)", "Bestellnummer", "Name", "Notiz", "Hersteller", "Herkunft", |
|
||||
"Einheit", "Preis(netto)", "MwSt", "Pfand", "Gebindegröße", |
|
||||
"Staffelmenge", "Staffelpreis", "Kategorie"].join(" | ") |
|
||||
= ["Status (x=ausgelistet)", "Bestellnummer", "Name", "Notiz", "Hersteller", "Herkunft",
|
||||
"Einheit", "Preis(netto)", "MwSt", "Pfand", "Gebindegröße",
|
||||
"Staffelmenge", "Staffelpreis", "Kategorie"].join(" | ")
|
||||
|
||||
#uploadArticles.uploadForm
|
||||
- form_for :articles, :url => parse_upload_supplier_articles_path(@supplier), |
|
||||
:html => { :multipart => true } do |form| |
|
||||
= form_for :articles, :url => parse_upload_supplier_articles_path(@supplier),
|
||||
:html => { :multipart => true } do |form|
|
||||
%p= form.file_field "file"
|
||||
%p= submit_tag "Datei hochladen"
|
||||
|
|
|
@ -5,23 +5,13 @@
|
|||
%h2 Übersicht
|
||||
.column_content
|
||||
#filter{:style => "margin-right:2em;"}
|
||||
= form_tag foodcoop_ordergroups_path, :method => :get, :style=>"display:inline;", :id => 'ordergroup_search', :remote => true do
|
||||
= form_tag foodcoop_ordergroups_path, :method => :get, :style=>"display:inline;", :id => 'ordergroup_search',
|
||||
:remote => true, 'data-submit-onchange' => true do
|
||||
%label{:for => 'article_name'} Suche nach Name:
|
||||
= text_field_tag(:query, params[:query], :size => 10 )
|
||||
= text_field_tag :query, params[:query], :size => 10
|
||||
%label{:for => 'only_active'} Nur aktive:
|
||||
= check_box_tag('only_active')
|
||||
= check_box_tag 'only_active', 1, params[:only_active]
|
||||
%small (mindestens einmal in den letzten 3 Monaten bestellt)
|
||||
|
||||
#ordergroups
|
||||
= render :partial => "ordergroups"
|
||||
|
||||
- content_for :head do
|
||||
:javascript
|
||||
$(function() {
|
||||
$('#query').observe_field(1, function() {
|
||||
$('#ordergroup_search').submit();
|
||||
});
|
||||
$('#only_active').click(function() {
|
||||
$('#ordergroup_search').submit();
|
||||
});
|
||||
});
|
|
@ -1,14 +1,3 @@
|
|||
- content_for :head do
|
||||
:javascript
|
||||
$(function() {
|
||||
$('#query').observe_field(1, function() {
|
||||
$('#user_search').submit();
|
||||
});
|
||||
$('#sort_by_ordergroups').click(function() {
|
||||
$('#user_search').submit();
|
||||
});
|
||||
});
|
||||
|
||||
%h1 Mitglieder der Foodcoop
|
||||
%p
|
||||
%i
|
||||
|
@ -24,9 +13,10 @@
|
|||
.column_content
|
||||
- unless params[:sort_by_ordergroups]
|
||||
#user_filter{:style => "float:left; margin-right:2em;"}
|
||||
= form_tag foodcoop_users_path, :method => :get, :style=>"display:inline;", :id => 'user_search', :remote => true do
|
||||
= form_tag foodcoop_users_path, :method => :get, :style=>"display:inline;", :id => 'user_search',
|
||||
:remote => true, 'data-submit-onchange' => true do
|
||||
%label{:for => 'article_name'} Suche nach Name:
|
||||
= text_field_tag(:query, params[:query], :size => 10 )
|
||||
= text_field_tag :query, params[:query], :size => 10
|
||||
|
||||
Nach Bestellgruppen sortieren:
|
||||
= check_box_tag :sort_by_ordergroups, 1, params[:sort_by_ordergroups]
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
.box_title
|
||||
%h2 Neuste Nachrichten
|
||||
.column_content
|
||||
= render :partial => 'messages/messages', :locals => {:messages => Message.public.order(:create_at.desc).limit(5), :subject_length => 70}
|
||||
= render :partial => 'messages/messages', :locals => {:messages => Message.public.order(:created_at.desc).limit(5), :subject_length => 70}
|
||||
%br/
|
||||
= link_to "Alle Nachrichten einsehen", messages_path
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
#sidebar
|
||||
#sidebar-links
|
||||
= link_to "Bearbeiten", edit_page_path(@page)
|
||||
= link_to "Versionen (#{@page.versions.count})", "#versions", 'data-toggle_this' => '#versions'
|
||||
= link_to "Versionen (#{@page.versions.count})", "#versions", 'data-toggle-this' => '#versions'
|
||||
- unless @page.children.empty?
|
||||
= link_to "Unterseiten", "#subpages", 'data-toggle_this' => '#subpages'
|
||||
= link_to "Unterseiten", "#subpages", 'data-toggle-this' => '#subpages'
|
||||
#versions{:style => "display:none"}
|
||||
.box_title
|
||||
%h2 Versionen
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
- for workgroup in Workgroup.all
|
||||
%h4= link_to workgroup.name, "#", 'data-toggle_this' => "#workgroup_#{workgroup.id}"
|
||||
%h4= link_to workgroup.name, "#", 'data-toggle-this' => "#workgroup_#{workgroup.id}"
|
||||
%ul{:style => "display:none"}[workgroup]
|
||||
- for user in workgroup.users.order("nick")
|
||||
%li= "#{user.nick} (#{user.ordergroup.try(:name)})"
|
||||
|
|
|
@ -168,6 +168,7 @@ de:
|
|||
unit_quantity: Gebindegröße
|
||||
tax: MwSt
|
||||
deposit: Pfand
|
||||
article_category: Kategorie
|
||||
stock_article:
|
||||
price: Nettopreis
|
||||
user:
|
||||
|
|
|
@ -2,9 +2,6 @@ Foodsoft::Application.routes.draw do
|
|||
|
||||
get "sessions/new"
|
||||
|
||||
# Use routing filter to select foodcoop config and datbase
|
||||
# filter :foodcoop
|
||||
|
||||
root :to => redirect("/#{Foodsoft.env}")
|
||||
|
||||
scope '/:foodcoop', :defaults => { :foodcoop => Foodsoft.env } do
|
||||
|
|
|
@ -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
|
|
@ -1,58 +1,71 @@
|
|||
// Load following statements, when DOM is ready
|
||||
$(function() {
|
||||
$('a[data-toggle_this]').click(function() {
|
||||
$($(this).data('toggle_this')).toggle();
|
||||
|
||||
// Show/Hide a specific DOM element
|
||||
$('a[data-toggle-this]').click(function() {
|
||||
$($(this).data('toggle-this')).toggle();
|
||||
return false;
|
||||
});
|
||||
|
||||
// Check/Uncheck a single checkbox
|
||||
$('[data-check-this]').live('click', function() {
|
||||
var checkbox = $($(this).data('check-this'));
|
||||
checkbox.attr('checked', !checkbox.is(':checked'));
|
||||
highlightRow(checkbox);
|
||||
return false;
|
||||
});
|
||||
|
||||
// Check/Uncheck all checkboxes for s specific form
|
||||
$('input[data-check-all]').live('click', function() {
|
||||
var status = $(this).is(':checked')
|
||||
$($(this).data('check-all')).find('input[type="checkbox"]').each(function() {
|
||||
$(this).attr('checked', status);
|
||||
highlightRow($(this));
|
||||
});
|
||||
});
|
||||
|
||||
// Submit form when changing a select menu.
|
||||
$('form[data-submit-onchange] select').live('change', function() {
|
||||
var confirmMessage = $(this).children(':selected').data('confirm');
|
||||
if (confirmMessage && confirm(confirmMessage)) {
|
||||
$(this).parents('form').submit();
|
||||
} else {
|
||||
$(this).parents('form').submit();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// Submit form when changing text of an input field
|
||||
// Use jquery observe_field plugin
|
||||
$('form[data-submit-onchange] input[type=text]').each(function() {
|
||||
$(this).observe_field(1, function() {
|
||||
$(this).parents('form').submit();
|
||||
});
|
||||
});
|
||||
|
||||
// Submit form when clicking on checkbox
|
||||
$('form[data-submit-onchange] input[type=checkbox]:not(input[data-ignore-onchange])').click(function() {
|
||||
$(this).parents('form').submit();
|
||||
});
|
||||
|
||||
$('[data-redirect-to]').bind('change', function() {
|
||||
var newLocation = $(this).children(':selected').val();
|
||||
if (newLocation != "") {
|
||||
document.location.href = newLocation;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Place your application-specific JavaScript functions and classes here
|
||||
// This file is automatically included by javascript_include_tag :defaults
|
||||
|
||||
// for checkboxes. just insert box in same form-element like:
|
||||
// <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
|
||||
function highlightRow(row_id,status) {
|
||||
if(status) {
|
||||
$(row_id).addClassName("selected");
|
||||
function highlightRow(checkbox) {
|
||||
var row = checkbox.parents('tr');
|
||||
if (checkbox.is(':checked')) {
|
||||
row.addClass('selected');
|
||||
} else {
|
||||
$(row_id).removeClassName("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);
|
||||
}
|
||||
row.removeClass('selected');
|
||||
}
|
||||
|
||||
// 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,
|
||||
|
|
|
@ -246,7 +246,7 @@ table {
|
|||
color: #008000; }
|
||||
table tr.selected, table tr.active {
|
||||
background-color: #ffffc2; }
|
||||
table tr.click-me {
|
||||
table tr.click-me, table td.click-me {
|
||||
cursor: pointer; }
|
||||
table tr.ignored {
|
||||
color: grey; }
|
||||
|
|
Loading…
Reference in a new issue