From 384a9444aa1f08c2fe19ac20dc8738ed2df0cca1 Mon Sep 17 00:00:00 2001 From: KieranP Date: Sun, 28 Jun 2009 17:13:01 -0700 Subject: [PATCH 0001/2024] bugfix: When using form_ui = :select with an array of options, you would get 'Symbol as array index' errors when using the create action. --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index dbdc09d420..2ea78cfa6f 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -60,7 +60,7 @@ def active_scaffold_input_options(column, scope = nil) end def javascript_for_update_column(column, scope, options) - if column.options[:update_column] + if column.options.is_a?(Hash) && column.options[:update_column] url_params = {:action => 'render_field', :id => params[:id]} url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope From 7bb10303ff74926ac4feff75c8b7e040bb0c2ee6 Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 30 Jun 2009 11:07:17 +0200 Subject: [PATCH 0002/2024] Use build_#{singular_association} or plural_association.build to create new associated records It fixes creating associated records which have validates_presence_of :parent --- lib/active_scaffold/attribute_params.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index cd7eaf2e19..0615c5229d 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -65,7 +65,7 @@ def update_record_from_params(parent_record, columns, attributes) elsif column.singular_association? hash = value - record = find_or_create_for_params(hash, column, parent_record.send("#{column.name}")) + record = find_or_create_for_params(hash, column, parent_record) if record record_columns = active_scaffold_config_for(column.association.klass).subform.columns update_record_from_params(record, record_columns, hash) @@ -76,7 +76,7 @@ def update_record_from_params(parent_record, columns, attributes) elsif column.plural_association? collection = value.collect do |key_value_pair| hash = key_value_pair[1] - record = find_or_create_for_params(hash, column, parent_record.send("#{column.name}")) + record = find_or_create_for_params(hash, column, parent_record) if record record_columns = active_scaffold_config_for(column.association.klass).subform.columns update_record_from_params(record, record_columns, hash) @@ -139,7 +139,8 @@ def update_record_from_params(parent_record, columns, attributes) # Attempts to create or find an instance of klass (which must be an ActiveRecord object) from the # request parameters given. If params[:id] exists it will attempt to find an existing object # otherwise it will build a new one. - def find_or_create_for_params(params, parent_column, current) + def find_or_create_for_params(params, parent_column, parent_record) + current = parent_record.send(parent_column.name) klass = parent_column.association.klass return nil if parent_column.show_blank_record and attributes_hash_is_empty?(params, klass) @@ -155,7 +156,13 @@ def find_or_create_for_params(params, parent_column, current) return klass.find(params[:id]) end else - return klass.new if klass.authorized_for?(:action => :create) + if klass.authorized_for?(:action => :create) + if parent_column.singular_association? + return parent_record.send("build_#{parent_column.name}") + else + return parent_record.send(parent_column.name).build + end + end end end @@ -182,4 +189,4 @@ def attributes_hash_is_empty?(hash, klass) end end end -end \ No newline at end of file +end From e941a33f215895b73ab4dd8665434fafd6acb069 Mon Sep 17 00:00:00 2001 From: Sergio Date: Wed, 1 Jul 2009 09:22:50 +0200 Subject: [PATCH 0003/2024] Fix close button for nested scaffolds --- frontends/default/stylesheets/stylesheet.css | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 7c522b7b3d..3ef0f39e02 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -290,6 +290,10 @@ background-color: #1F7F00; background: transparent; } +.active-scaffold .active-scaffold .active-scaffold-header { +margin-right: 15px; +} + .active-scaffold .active-scaffold .active-scaffold-header h2 { font-size: 12px; font-weight: bold; @@ -300,6 +304,11 @@ font-weight: bold; color: #444; } +.active-scaffold .active-scaffold .active-scaffold-header div.actions { +top: 0px; +right: 0px; +} + .active-scaffold .active-scaffold .active-scaffold-header div.actions a { font: bold 11px verdana, sans-serif; padding: 0 2px 1px 17px; From 61dc7d4fbfc2c0a546f0cdb75b33fbb145b5ca2d Mon Sep 17 00:00:00 2001 From: Sergio Date: Wed, 1 Jul 2009 12:56:55 +0200 Subject: [PATCH 0004/2024] Fix guessing foreign_key for belongs_to associations in constraints --- lib/active_scaffold/constraints.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 361248a1af..def47ccdd8 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -91,8 +91,10 @@ def condition_from_association_constraint(association, value) # please see the relevant tests for concrete examples. field = if [:has_one, :has_many].include?(association.macro) association.klass.primary_key + elsif [:has_and_belongs_to_many].include?(association.macro) + association.association_foreign_key else - association.options[:association_foreign_key] || association.options[:foreign_key] || association.association_foreign_key + association.options[:foreign_key] || association.name.to_s.foreign_key end table = case association.macro @@ -102,9 +104,6 @@ def condition_from_association_constraint(association, value) when :belongs_to active_scaffold_config.model.table_name - when :has_many - association.table_name - else association.table_name end From a55e3a36309fbced63a04f9b06b828fbde8a06a9 Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 2 Jul 2009 09:53:28 +0200 Subject: [PATCH 0005/2024] Simplify i18n in column description --- lib/active_scaffold/data_structures/column.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index f436950a76..0b902acade 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -29,7 +29,11 @@ def label # a textual description of the column and its contents. this will be displayed with any associated form input widget, so you may want to consider adding a content example. attr_writer :description def description - @description.is_a?(Symbol) ? as_(@description, {:scope => [:activerecord, :attributes, active_record_class.to_s.underscore.to_sym]}) : as_(@description) if @description + if @description + @description + else + I18n.t name, :scope => [:activerecord, :description, active_record_class.to_s.underscore.to_sym], :default => '' + end end # this will be /joined/ to the :name for the td's class attribute. useful if you want to style columns on different ActiveScaffolds the same way, but the columns have different names. From 0e4c368da3a23c31f6710e9ac391ed96f8299f46 Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 2 Jul 2009 10:43:42 +0200 Subject: [PATCH 0006/2024] Return to main without id --- lib/active_scaffold/actions/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 982c8882e6..fb99ea47b6 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -82,7 +82,7 @@ def return_to_main params[:parent_column] = nil params[:parent_id] = nil end - redirect_to params_for(:action => "index") + redirect_to params_for(:action => "index", :id => nil) end # Override this method on your controller to define conditions to be used when querying a recordset (e.g. for List). The return of this method should be any format compatible with the :conditions clause of ActiveRecord::Base's find. From 4293d29116388414d5ef549150c0ba5cf67feb87 Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 2 Jul 2009 11:21:06 +0200 Subject: [PATCH 0007/2024] Set successful message only when destory is successful. Add warning when destroy raise an exception, so you can raise a exception in before_destroy to avoid destroying and show a message --- lib/active_scaffold/actions/delete.rb | 9 +++++++-- lib/active_scaffold/locale/en.rb | 1 + lib/active_scaffold/locale/es.yml | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 3426b05c4c..a2ccbbdb43 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -19,7 +19,7 @@ def destroy protected def destroy_respond_to_html - flash[:info] = as_(:deleted_model, :model => @record.to_label) + flash[:info] = as_(:deleted_model, :model => @record.to_label) if self.successful? return_to_main end @@ -47,7 +47,12 @@ def destroy_find_record # May be overridden to customize the behavior def do_destroy destroy_find_record - self.successful = @record.destroy + begin + self.successful = @record.destroy + rescue + flash[:warning] = as_(:cant_destroy_record, :record => @record.to_label) + self.successful = false + end end # The default security delegates to ActiveRecordPermissions. diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 43ccb165b6..6b4ef37cee 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -59,6 +59,7 @@ :between => 'Between', # error_messages + :cant_destroy_record => "{{record}} can't be destroyed", :internal_error => 'Request Failed (code 500, Internal Error)', :version_inconsistency => 'Version inconsistency - this record has been modified since you started editing it.' } diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index d074fa3b60..d3412b76e8 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -60,5 +60,6 @@ es: between: 'entre' # error_messages + cant_destroy_record: "No se pudo borrar {{record}}" internal_error: 'Petición fallida (código 500, error interno)' version_inconsistency: 'Inconsistencia de versiones - este registro se ha modificado después de que empezó a editarlo.' From 5a68f85d25de68e4d7e8add898dafbb8da5842bd Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 3 Jul 2009 17:51:44 +0200 Subject: [PATCH 0008/2024] Fix tiny_mce bridge --- lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb b/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb index 5ef1813080..098697b922 100644 --- a/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb +++ b/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb @@ -1,7 +1,7 @@ module ActiveScaffold module Helpers module ViewHelpers - def active_scaffold_includes_with_tiny_mce(frontend = :default) + def active_scaffold_includes_with_tiny_mce(*args) tiny_mce_js = javascript_tag(%| var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; ActiveScaffold.ActionLink.Abstract.prototype.close = function() { @@ -11,7 +11,7 @@ def active_scaffold_includes_with_tiny_mce(frontend = :default) action_link_close.apply(this); }; |) if using_tiny_mce? - active_scaffold_includes_without_tiny_mce(frontend) + (include_tiny_mce_if_needed || '') + (tiny_mce_js || '') + active_scaffold_includes_without_tiny_mce(*args) + (include_tiny_mce_if_needed || '') + (tiny_mce_js || '') end alias_method_chain :active_scaffold_includes, :tiny_mce end From 39ee51f829bc44ad8475ec669c9d4a59cc22af56 Mon Sep 17 00:00:00 2001 From: Sergio Cambra Date: Wed, 8 Jul 2009 00:57:37 +0200 Subject: [PATCH 0009/2024] Lookup form override partials in active_scaffold paths, so you can add a view path to some controllers with some form override partials to share, or put some form override partials to share in app/views/active_scaffold_overrides --- lib/active_scaffold.rb | 5 +++++ lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- lib/extensions/action_view_rendering.rb | 6 ++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index c7b501dced..d23c659c47 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -128,6 +128,11 @@ def add_active_scaffold_path(path) @active_scaffold_custom_paths << path end + def add_active_scaffold_override_path(path) + @active_scaffold_paths = nil # Force active_scaffold_paths to rebuild + @active_scaffold_overrides.unshift path + end + def active_scaffold_paths @active_scaffold_paths ||= ActionView::PathSet.new(@active_scaffold_overrides + @active_scaffold_custom_paths + @active_scaffold_frontends) unless @active_scaffold_overrides.nil? || @active_scaffold_custom_paths.nil? || @active_scaffold_frontends.nil? end diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 2ea78cfa6f..2ca5f43e57 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -200,7 +200,7 @@ def override_subform_partial(column, subform_partial) def override_form_field_partial?(column) path, partial_name = partial_pieces(override_form_field_partial(column)) - template_exists?(File.join(path, "_#{partial_name}")) + template_exists?(File.join(path, "_#{partial_name}"), true) end # the naming convention for overriding form fields with partials diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index e13806d7f3..105eb3098a 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -74,9 +74,11 @@ def partial_pieces(partial_path) # This is the template finder logic, keep it updated with however we find stuff in rails # currently this very similar to the logic in ActionBase::Base.render for options file # TODO: Work with rails core team to find a better way to check for this. - def template_exists?(template_name) + def template_exists?(template_name, lookup_overrides = false) begin - self.view_paths.find_template_without_active_scaffold(template_name, @template_format) + method = 'find_template' + method << '_without_active_scaffold' unless lookup_overrides + self.view_paths.send(method, template_name, @template_format) return true rescue ActionView::MissingTemplate => e return false From 1ff7026f12129a529a3305ea03962de436b184fb Mon Sep 17 00:00:00 2001 From: Sergio Cambra Date: Thu, 9 Jul 2009 01:08:59 +0200 Subject: [PATCH 0010/2024] authorized_for? as class method lookup for class methods to do security checks instead of create a new instance add :action to authorized_for? options in addition to crud_type and column --- .../default/views/_form_association.html.erb | 2 +- .../views/_form_association_footer.html.erb | 2 +- .../views/_horizontal_subform_record.html.erb | 8 +- .../default/views/_list_actions.html.erb | 2 +- frontends/default/views/_list_record.html.erb | 2 +- .../default/views/_update_actions.html.erb | 2 +- .../views/_vertical_subform_record.html.erb | 8 +- lib/active_record_permissions.rb | 100 ++++++------- lib/active_scaffold/actions/core.rb | 4 +- lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/actions/delete.rb | 2 +- lib/active_scaffold/actions/field_search.rb | 2 +- lib/active_scaffold/actions/list.rb | 2 +- lib/active_scaffold/actions/live_search.rb | 2 +- lib/active_scaffold/actions/search.rb | 2 +- lib/active_scaffold/actions/show.rb | 2 +- lib/active_scaffold/actions/update.rb | 4 +- lib/active_scaffold/attribute_params.rb | 8 +- .../data_structures/action_columns.rb | 2 +- .../data_structures/action_link.rb | 4 +- lib/active_scaffold/finder.rb | 4 +- .../helpers/list_column_helpers.rb | 6 +- test/misc/active_record_permissions.rb | 132 +++++++++--------- 23 files changed, 155 insertions(+), 149 deletions(-) diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index f073e3ca0a..b5b5ed4e6b 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -6,7 +6,7 @@ associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless if column.show_blank_record show_blank_record = (column.plural_association? or (column.singular_association? and associated.empty?)) show_blank_record = false if column.through_association? - show_blank_record = false unless column.association.klass.authorized_for?(:action => :create) + show_blank_record = false unless column.association.klass.authorized_for?(:crud_type => :create) else show_blank_record = false end diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index 3140d2feea..dfb4b8cf53 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -8,7 +8,7 @@ end show_add_existing = (!column.through_association? and options_for_association_count(column.association) > 0) show_add_new = !column.through_association? and (column.plural_association? or (column.singular_association? and not associated.empty?)) -show_add_new = false unless @record.class.authorized_for?(:action => :create) +show_add_new = false unless @record.class.authorized_for?(:crud_type => :create) edit_associated_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :associated_id => '--ID--', :escape => false, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :escape => false, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]); diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index ea4eff341b..dc02f96bbe 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -1,9 +1,9 @@ <% record_column = column -%> -<% readonly = (@record.readonly? or not @record.authorized_for?(:action => :update)) -%> -<% action = @record.new_record? ? :create : (readonly ? :read : nil) -%> +<% readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) -%> +<% crud_type = @record.new_record? ? :create : (readonly ? :read : nil) -%> <% show_actions = false -%> -<% active_scaffold_config_for(@record.class).subform.columns.each :for => @record.class, :action => action, :flatten => true do |column| %> +<% active_scaffold_config_for(@record.class).subform.columns.each :for => @record.class, :crud_type => crud_type, :flatten => true do |column| %> <% next unless in_subform?(column, parent_record) show_actions = true @@ -20,7 +20,7 @@ <% end -%> <% if show_actions -%> - <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:action => :destroy) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> + <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:crud_type => :destroy) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> <% unless @record.new_record? %> " value="<%= @record.id -%>" /> <% end -%> diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 90d0279135..333713117d 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -6,7 +6,7 @@ <% active_scaffold_config.action_links.each :record do |link| -%> <% next if controller.respond_to? link.security_method and !controller.send(link.security_method) -%> - <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options) : "#{link.label}" -%> + <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options) : "#{link.label}" -%> <% end -%> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 736b4a39bf..f7b0c5f061 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -11,7 +11,7 @@ url_options = params_for(:action => :list, :id => record.id) <% column_value = get_column_value(record, column) -%> - <%= record.authorized_for?(:action => :read, :column => column.name) ? render_list_column(column_value, column, record) : '' %> + <%= record.authorized_for?(:crud_type => :read, :column => column.name) ? render_list_column(column_value, column, record) : '' %> <% end -%> <% if active_scaffold_config.action_links.any? {|link| link.type == :record } -%> diff --git a/frontends/default/views/_update_actions.html.erb b/frontends/default/views/_update_actions.html.erb index 392f05b003..4e7ccf3248 100644 --- a/frontends/default/views/_update_actions.html.erb +++ b/frontends/default/views/_update_actions.html.erb @@ -3,7 +3,7 @@ <% active_scaffold_config.action_links.each :record do |link| -%> <% next unless link.action == 'nested' -%> <% next if controller.respond_to? link.security_method and !controller.send(link.security_method) -%> - <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options) : "#{link.label}" -%> + <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options) : "#{link.label}" -%> <% end -%> diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index 4fa47b626d..3523ab4b6e 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -1,11 +1,11 @@ <% record_column = column - readonly = (@record.readonly? or not @record.authorized_for?(:action => :update)) - action = @record.new_record? ? :create : (readonly ? :read : nil) + readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) + crud_type = @record.new_record? ? :create : (readonly ? :read : nil) show_actions = false -%>
    -<% active_scaffold_config_for(@record.class).subform.columns.each :for => @record, :action => action, :flatten => true do |column| %> +<% active_scaffold_config_for(@record.class).subform.columns.each :for => @record, :crud_type => crud_type, :flatten => true do |column| %> <% next unless in_subform?(column, parent_record) show_actions = true @@ -22,7 +22,7 @@ <% end -%> <% if show_actions -%>
  1. - <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:action => :destroy) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> + <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:crud_type => :destroy) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> <% unless @record.new_record? %> " value="<%= @record.id -%>" /> <% end -%> diff --git a/lib/active_record_permissions.rb b/lib/active_record_permissions.rb index fa8e6e767b..f446dc2de6 100644 --- a/lib/active_record_permissions.rb +++ b/lib/active_record_permissions.rb @@ -62,38 +62,8 @@ def current_user module Permissions def self.included(base) - base.extend ClassMethods - end - - # A generic authorization query. This is what will be called programatically, since - # the actual permission methods can't be guaranteed to exist. And because we want to - # intelligently combine multiple applicable methods. - # - # options[:action] should be a CRUD verb (:create, :read, :update, :destroy) - # options[:column] should be the name of a model attribute - def authorized_for?(options = {}) - raise ArgumentError, "unknown action #{options[:action]}" if options[:action] and ![:create, :read, :update, :destroy].include?(options[:action]) - - # column_authorized_for_action? has priority over other methods, - # you can disable an action and enable that action for a column - # (for example, disable update and enable inplace_edit in a column) - method = column_and_action_security_method(options[:column], options[:action]) - return send(method) if method and respond_to?(method) - - # collect the possibly-related methods that actually exist - methods = [ - column_security_method(options[:column]), - action_security_method(options[:action]), - ].compact.select {|m| respond_to?(m)} - - # if any method returns false, then return false - return false if methods.any? {|m| !send(m)} - - # if any method actually exists then it must've returned true, so return true - return true unless methods.empty? - - # if no method exists, return the default permission - return ActiveRecordPermissions.default_permission + base.extend SecurityMethods + base.include SecurityMethods end # Because any class-level queries get delegated to the instance level via a new record, @@ -103,26 +73,62 @@ def existing_record_check? !new_record? end - module ClassMethods - # Class level just delegates to instance level - def authorized_for?(*args) - @authorized_for_delegatee ||= self.new - @authorized_for_delegatee.authorized_for?(*args) + module SecurityMethods + # A generic authorization query. This is what will be called programatically, since + # the actual permission methods can't be guaranteed to exist. And because we want to + # intelligently combine multiple applicable methods. + # + # options[:crud_type] should be a CRUD verb (:create, :read, :update, :destroy) + # options[:column] should be the name of a model attribute + # options[:action] is the name of a method + def authorized_for?(options = {}) + raise ArgumentError, "unknown action #{options[:crud_type]}" if options[:crud_type] and ![:create, :read, :update, :destroy].include?(options[:crud_type]) + + # column_authorized_for_crud_type? has the highest priority over other methods, + # you can disable a crud verb and enable that verb for a column + # (for example, disable update and enable inplace_edit in a column) + method = column_and_crud_type_security_method(options[:column], options[:crud_type]) + return send(method) if method and respond_to?(method) + + # authorized_for_action? has higher priority than other methods, + # you can disable a crud verb and enable an action with that crud verb + # (for example, disable update and enable an action with update as crud type) + method = action_security_method(options[:action]) + return send(method) if method and respond_to?(method) + + # collect other possibly-related methods that actually exist + methods = [ + column_security_method(options[:column]), + crud_type_security_method(options[:crud_type]), + ].compact.select {|m| respond_to?(m)} + + # if any method returns false, then return false + return false if methods.any? {|m| !send(m)} + + # if any method actually exists then it must've returned true, so return true + return true unless methods.empty? + + # if no method exists, return the default permission + return ActiveRecordPermissions.default_permission end - end - private + private - def column_security_method(column) - "#{column}_authorized?" if column - end + def column_security_method(column) + "#{column}_authorized?" if column + end - def action_security_method(action) - "authorized_for_#{action}?" if action - end + def crud_type_security_method(crud_type) + "authorized_for_#{crud_type}?" if crud_type + end - def column_and_action_security_method(column, action) - "#{column}_authorized_for_#{action}?" if column and action + def action_security_method(action) + "authorized_for_#{action}?" if action + end + + def column_and_crud_type_security_method(column, crud_type) + "#{column}_authorized_for_#{crud_type}?" if column and crud_type + end end end end diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index fb99ea47b6..4cfee8955f 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -19,8 +19,8 @@ def render_field protected - def authorized_for?(*args) - active_scaffold_config.model.authorized_for?(*args) + def authorized_for?(options = {}) + active_scaffold_config.model.authorized_for?(options) end def clear_flashes diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index c4bc5b9b90..ec7a0738cd 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -123,7 +123,7 @@ def after_create_save(record); end # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def create_authorized? - authorized_for?(:action => :create) + authorized_for?(:crud_type => :create) end private def create_authorized_filter diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index a2ccbbdb43..79e0f57442 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -58,7 +58,7 @@ def do_destroy # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def delete_authorized? - authorized_for?(:action => :destroy) + authorized_for?(:crud_type => :destroy) end private def delete_authorized_filter diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index 61f18065f5..d879876d45 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -44,7 +44,7 @@ def do_search # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def search_authorized? - authorized_for?(:action => :read) + authorized_for?(:crud_type => :read) end private def search_authorized_filter diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index cc05f6bab2..71d8449b74 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -80,7 +80,7 @@ def do_list # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def list_authorized? - authorized_for?(:action => :read) + authorized_for?(:crud_type => :read) end private def list_authorized_filter diff --git a/lib/active_scaffold/actions/live_search.rb b/lib/active_scaffold/actions/live_search.rb index 5228366baa..c7c477a3ff 100644 --- a/lib/active_scaffold/actions/live_search.rb +++ b/lib/active_scaffold/actions/live_search.rb @@ -43,7 +43,7 @@ def do_search # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def search_authorized? - authorized_for?(:action => :read) + authorized_for?(:crud_type => :read) end private def search_authorized_filter diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index 858e244378..ca1346bf2c 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -36,7 +36,7 @@ def do_search # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def search_authorized? - authorized_for?(:action => :read) + authorized_for?(:crud_type => :read) end private def search_authorized_filter diff --git a/lib/active_scaffold/actions/show.rb b/lib/active_scaffold/actions/show.rb index 37a41495cb..a004dce397 100644 --- a/lib/active_scaffold/actions/show.rb +++ b/lib/active_scaffold/actions/show.rb @@ -40,7 +40,7 @@ def do_show # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def show_authorized? - authorized_for?(:action => :read) + authorized_for?(:crud_type => :read) end private def show_authorized_filter diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 13cb6e3cd3..221e3d7f3c 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -93,7 +93,7 @@ def do_update def do_update_column @record = active_scaffold_config.model.find(params[:id]) - if @record.authorized_for?(:action => :update, :column => params[:column]) + if @record.authorized_for?(:crud_type => :update, :column => params[:column]) params[:value] ||= @record.column_for_attribute(params[:column]).default unless @record.column_for_attribute(params[:column]).null @record.send("#{params[:column]}=", params[:value]) @record.save @@ -109,7 +109,7 @@ def after_update_save(record); end # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def update_authorized? - authorized_for?(:action => :update) + authorized_for?(:crud_type => :update) end private def update_authorized_filter diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 0615c5229d..eadaa9ddd4 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -35,8 +35,8 @@ module AttributeParams # This is a secure way to apply params to a record, because it's based on a loop over the columns # set. The columns set will not yield unauthorized columns, and it will not yield unregistered columns. def update_record_from_params(parent_record, columns, attributes) - action = parent_record.new_record? ? :create : :update - return parent_record unless parent_record.authorized_for?(:action => action) + crud_type = parent_record.new_record? ? :create : :update + return parent_record unless parent_record.authorized_for?(:crud_type => crud_type) multi_parameter_attributes = {} attributes.each do |k, v| @@ -46,7 +46,7 @@ def update_record_from_params(parent_record, columns, attributes) multi_parameter_attributes[column_name] << [k, v] end - columns.each :for => parent_record, :action => action, :flatten => true do |column| + columns.each :for => parent_record, :crud_type => crud_type, :flatten => true do |column| if multi_parameter_attributes.has_key? column.name parent_record.send(:assign_multiparameter_attributes, multi_parameter_attributes[column.name]) elsif attributes.has_key? column.name @@ -156,7 +156,7 @@ def find_or_create_for_params(params, parent_column, parent_record) return klass.find(params[:id]) end else - if klass.authorized_for?(:action => :create) + if klass.authorized_for?(:crud_type => :create) if parent_column.singular_association? return parent_record.send("build_#{parent_column.name}") else diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index 6487c67234..65d3fde3e6 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -65,7 +65,7 @@ def each(options = {}, &proc) # skip if this matches the field_name of a constrained column next if item.field_name and constraint_columns.include?(item.field_name.to_sym) # skip this field if it's not authorized - next unless options[:for].authorized_for?(:action => options[:action] || self.action.crud_type, :column => item.name) + next unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.crud_type, :column => item.name) end if item.is_a? ActiveScaffold::DataStructures::ActionColumns and options.has_key?(:flatten) and options[:flatten] item.each(options, &proc) diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 4e39ad1e2f..62c4430e31 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -62,11 +62,11 @@ def dhtml_confirm? # note that this is only the UI part of the security. to prevent URL hax0rz, you also need security on requests (e.g. don't execute update method unless authorized). attr_writer :security_method def security_method - @security_method || "#{self.label.underscore.downcase.gsub(/ /, '_')}_authorized?" + @security_method || "#{self.action}_authorized?" end # the crud type of the (eventual?) action. different than :method, because this crud action may not be imminent. - # this is used to determine record-level authorization (e.g. record.authorized_for?(:action => link.crud_type). + # this is used to determine record-level authorization (e.g. record.authorized_for?(:crud_type => link.crud_type). # options are :create, :read, :update, and :destroy attr_accessor :crud_type diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 19857bf717..cfa558d7f5 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -130,10 +130,10 @@ def all_conditions # returns a single record (the given id) but only if it's allowed for the specified action. # accomplishes this by checking model.#{action}_authorized? # TODO: this should reside on the model, not the controller - def find_if_allowed(id, action, klass = nil) + def find_if_allowed(id, crud_type, klass = nil) klass ||= active_scaffold_config.model record = klass.find(id) - raise ActiveScaffold::RecordNotAllowed unless record.authorized_for?(:action => action.to_sym) + raise ActiveScaffold::RecordNotAllowed unless record.authorized_for?(:crud_type => crud_type.to_sym) return record end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index e60eafe055..a49a801dd7 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -78,10 +78,10 @@ def render_list_column(text, column, record) # check authorization if column.association - authorized = (associated ? associated : column.association.klass).authorized_for?(:action => link.crud_type) - authorized = authorized and record.authorized_for?(:action => :update, :column => column.name) if link.crud_type == :create + authorized = (associated ? associated : column.association.klass).authorized_for?(:crud_type => link.crud_type) + authorized = authorized and record.authorized_for?(:crud_type => :update, :column => column.name) if link.crud_type == :create else - authorized = record.authorized_for?(:action => link.crud_type) + authorized = record.authorized_for?(:crud_type => link.crud_type) end return "#{text}" unless authorized diff --git a/test/misc/active_record_permissions.rb b/test/misc/active_record_permissions.rb index d5403ac671..ebe1ba6733 100644 --- a/test/misc/active_record_permissions.rb +++ b/test/misc/active_record_permissions.rb @@ -65,39 +65,39 @@ def test_method_combinations_with_default_true fail(@model.authorized_for?(:column => :a2), '_f_') pass(@model.authorized_for?(:column => :a1), '_t_') - pass(@model.authorized_for?(:action => :create), 'a__') - fail(@model.authorized_for?(:action => :update), 'f__') - pass(@model.authorized_for?(:action => :read), 't__') - - pass(@model.authorized_for?(:action => :create, :column => :c3), 'aaa') - fail(@model.authorized_for?(:action => :create, :column => :b3), 'aaf') - pass(@model.authorized_for?(:action => :create, :column => :a3), 'aat') - fail(@model.authorized_for?(:action => :create, :column => :c2), 'afa') - fail(@model.authorized_for?(:action => :create, :column => :b2), 'aff') - fail(@model.authorized_for?(:action => :create, :column => :a2), 'aft') - pass(@model.authorized_for?(:action => :create, :column => :c1), 'ata') - fail(@model.authorized_for?(:action => :create, :column => :b1), 'atf') - pass(@model.authorized_for?(:action => :create, :column => :a1), 'att') - - fail(@model.authorized_for?(:action => :update, :column => :c3), 'faa') - fail(@model.authorized_for?(:action => :update, :column => :b3), 'faf') - fail(@model.authorized_for?(:action => :update, :column => :a3), 'fat') - fail(@model.authorized_for?(:action => :update, :column => :c2), 'ffa') - fail(@model.authorized_for?(:action => :update, :column => :b2), 'fff') - fail(@model.authorized_for?(:action => :update, :column => :a2), 'fft') - fail(@model.authorized_for?(:action => :update, :column => :c1), 'fta') - fail(@model.authorized_for?(:action => :update, :column => :b1), 'ftf') - fail(@model.authorized_for?(:action => :update, :column => :a1), 'ftt') - - pass(@model.authorized_for?(:action => :read, :column => :c3), 'taa') - fail(@model.authorized_for?(:action => :read, :column => :b3), 'taf') - pass(@model.authorized_for?(:action => :read, :column => :a3), 'tat') - fail(@model.authorized_for?(:action => :read, :column => :c2), 'tfa') - fail(@model.authorized_for?(:action => :read, :column => :b2), 'tff') - fail(@model.authorized_for?(:action => :read, :column => :a2), 'tft') - pass(@model.authorized_for?(:action => :read, :column => :c1), 'tta') - fail(@model.authorized_for?(:action => :read, :column => :b1), 'ttf') - pass(@model.authorized_for?(:action => :read, :column => :a1), 'ttt') + pass(@model.authorized_for?(:crud_type => :create), 'a__') + fail(@model.authorized_for?(:crud_type => :update), 'f__') + pass(@model.authorized_for?(:crud_type => :read), 't__') + + pass(@model.authorized_for?(:crud_type => :create, :column => :c3), 'aaa') + fail(@model.authorized_for?(:crud_type => :create, :column => :b3), 'aaf') + pass(@model.authorized_for?(:crud_type => :create, :column => :a3), 'aat') + fail(@model.authorized_for?(:crud_type => :create, :column => :c2), 'afa') + fail(@model.authorized_for?(:crud_type => :create, :column => :b2), 'aff') + fail(@model.authorized_for?(:crud_type => :create, :column => :a2), 'aft') + pass(@model.authorized_for?(:crud_type => :create, :column => :c1), 'ata') + fail(@model.authorized_for?(:crud_type => :create, :column => :b1), 'atf') + pass(@model.authorized_for?(:crud_type => :create, :column => :a1), 'att') + + fail(@model.authorized_for?(:crud_type => :update, :column => :c3), 'faa') + fail(@model.authorized_for?(:crud_type => :update, :column => :b3), 'faf') + fail(@model.authorized_for?(:crud_type => :update, :column => :a3), 'fat') + fail(@model.authorized_for?(:crud_type => :update, :column => :c2), 'ffa') + fail(@model.authorized_for?(:crud_type => :update, :column => :b2), 'fff') + fail(@model.authorized_for?(:crud_type => :update, :column => :a2), 'fft') + fail(@model.authorized_for?(:crud_type => :update, :column => :c1), 'fta') + fail(@model.authorized_for?(:crud_type => :update, :column => :b1), 'ftf') + fail(@model.authorized_for?(:crud_type => :update, :column => :a1), 'ftt') + + pass(@model.authorized_for?(:crud_type => :read, :column => :c3), 'taa') + fail(@model.authorized_for?(:crud_type => :read, :column => :b3), 'taf') + pass(@model.authorized_for?(:crud_type => :read, :column => :a3), 'tat') + fail(@model.authorized_for?(:crud_type => :read, :column => :c2), 'tfa') + fail(@model.authorized_for?(:crud_type => :read, :column => :b2), 'tff') + fail(@model.authorized_for?(:crud_type => :read, :column => :a2), 'tft') + pass(@model.authorized_for?(:crud_type => :read, :column => :c1), 'tta') + fail(@model.authorized_for?(:crud_type => :read, :column => :b1), 'ttf') + pass(@model.authorized_for?(:crud_type => :read, :column => :a1), 'ttt') end def test_method_combinations_with_default_false @@ -107,39 +107,39 @@ def test_method_combinations_with_default_false fail(@model.authorized_for?(:column => :a2), '_f_') pass(@model.authorized_for?(:column => :a1), '_t_') - fail(@model.authorized_for?(:action => :create), 'a__') - fail(@model.authorized_for?(:action => :update), 'f__') - pass(@model.authorized_for?(:action => :read), 't__') - - fail(@model.authorized_for?(:action => :create, :column => :c3), 'aaa') - fail(@model.authorized_for?(:action => :create, :column => :b3), 'aaf') - pass(@model.authorized_for?(:action => :create, :column => :a3), 'aat') - fail(@model.authorized_for?(:action => :create, :column => :c2), 'afa') - fail(@model.authorized_for?(:action => :create, :column => :b2), 'aff') - fail(@model.authorized_for?(:action => :create, :column => :a2), 'aft') - pass(@model.authorized_for?(:action => :create, :column => :c1), 'ata') - fail(@model.authorized_for?(:action => :create, :column => :b1), 'atf') - pass(@model.authorized_for?(:action => :create, :column => :a1), 'att') - - fail(@model.authorized_for?(:action => :update, :column => :c3), 'faa') - fail(@model.authorized_for?(:action => :update, :column => :b3), 'faf') - fail(@model.authorized_for?(:action => :update, :column => :a3), 'fat') - fail(@model.authorized_for?(:action => :update, :column => :c2), 'ffa') - fail(@model.authorized_for?(:action => :update, :column => :b2), 'fff') - fail(@model.authorized_for?(:action => :update, :column => :a2), 'fft') - fail(@model.authorized_for?(:action => :update, :column => :c1), 'fta') - fail(@model.authorized_for?(:action => :update, :column => :b1), 'ftf') - fail(@model.authorized_for?(:action => :update, :column => :a1), 'ftt') - - pass(@model.authorized_for?(:action => :read, :column => :c3), 'taa') - fail(@model.authorized_for?(:action => :read, :column => :b3), 'taf') - pass(@model.authorized_for?(:action => :read, :column => :a3), 'tat') - fail(@model.authorized_for?(:action => :read, :column => :c2), 'tfa') - fail(@model.authorized_for?(:action => :read, :column => :b2), 'tff') - fail(@model.authorized_for?(:action => :read, :column => :a2), 'tft') - pass(@model.authorized_for?(:action => :read, :column => :c1), 'tta') - fail(@model.authorized_for?(:action => :read, :column => :b1), 'ttf') - pass(@model.authorized_for?(:action => :read, :column => :a1), 'ttt') + fail(@model.authorized_for?(:crud_type => :create), 'a__') + fail(@model.authorized_for?(:crud_type => :update), 'f__') + pass(@model.authorized_for?(:crud_type => :read), 't__') + + fail(@model.authorized_for?(:crud_type => :create, :column => :c3), 'aaa') + fail(@model.authorized_for?(:crud_type => :create, :column => :b3), 'aaf') + pass(@model.authorized_for?(:crud_type => :create, :column => :a3), 'aat') + fail(@model.authorized_for?(:crud_type => :create, :column => :c2), 'afa') + fail(@model.authorized_for?(:crud_type => :create, :column => :b2), 'aff') + fail(@model.authorized_for?(:crud_type => :create, :column => :a2), 'aft') + pass(@model.authorized_for?(:crud_type => :create, :column => :c1), 'ata') + fail(@model.authorized_for?(:crud_type => :create, :column => :b1), 'atf') + pass(@model.authorized_for?(:crud_type => :create, :column => :a1), 'att') + + fail(@model.authorized_for?(:crud_type => :update, :column => :c3), 'faa') + fail(@model.authorized_for?(:crud_type => :update, :column => :b3), 'faf') + fail(@model.authorized_for?(:crud_type => :update, :column => :a3), 'fat') + fail(@model.authorized_for?(:crud_type => :update, :column => :c2), 'ffa') + fail(@model.authorized_for?(:crud_type => :update, :column => :b2), 'fff') + fail(@model.authorized_for?(:crud_type => :update, :column => :a2), 'fft') + fail(@model.authorized_for?(:crud_type => :update, :column => :c1), 'fta') + fail(@model.authorized_for?(:crud_type => :update, :column => :b1), 'ftf') + fail(@model.authorized_for?(:crud_type => :update, :column => :a1), 'ftt') + + pass(@model.authorized_for?(:crud_type => :read, :column => :c3), 'taa') + fail(@model.authorized_for?(:crud_type => :read, :column => :b3), 'taf') + pass(@model.authorized_for?(:crud_type => :read, :column => :a3), 'tat') + fail(@model.authorized_for?(:crud_type => :read, :column => :c2), 'tfa') + fail(@model.authorized_for?(:crud_type => :read, :column => :b2), 'tff') + fail(@model.authorized_for?(:crud_type => :read, :column => :a2), 'tft') + pass(@model.authorized_for?(:crud_type => :read, :column => :c1), 'tta') + fail(@model.authorized_for?(:crud_type => :read, :column => :b1), 'ttf') + pass(@model.authorized_for?(:crud_type => :read, :column => :a1), 'ttt') end private From 85e2fa81f6a4a5afafe0c8c6022a640522f60a96 Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 13 Jul 2009 10:25:29 +0200 Subject: [PATCH 0011/2024] Fix title in column headings without sorting --- frontends/default/views/_list_column_headings.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index aeae7b13fa..96a3b96287 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -12,7 +12,7 @@ default_sorting_stages = ['ASC', 'DESC'] :sort => column.name, :sort_direction => column_sort_direction) column_header_id = active_scaffold_column_header_id(column) -%> - "> + " title="<%= h column.description %>"> <% if column.sortable? -%> <% href = url_for(sort_params) -%> <%= link_to_remote column.label, @@ -22,7 +22,7 @@ default_sorting_stages = ['ASC', 'DESC'] :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :update => active_scaffold_content_id, :method => :get }, - { :href => href, :title => column.description } %> + { :href => href } %> <% else -%>

    <%= column.label %>

    <% end -%> From 031e7b7984900be8bd13ed8f0604cdc8436194ca Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 13 Jul 2009 11:23:18 +0200 Subject: [PATCH 0012/2024] Validate HTML --- frontends/default/views/_list_actions.html.erb | 2 +- frontends/default/views/_list_record.html.erb | 11 ++++++----- frontends/default/views/list.html.erb | 8 ++++++-- lib/active_scaffold/helpers/id_helpers.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 90d0279135..73d0a36fb7 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -10,4 +10,4 @@ <% end -%> - \ No newline at end of file + diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 736b4a39bf..81c563d0e1 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -14,15 +14,12 @@ url_options = params_for(:action => :list, :id => record.id) <%= record.authorized_for?(:action => :read, :column => column.name) ? render_list_column(column_value, column, record) : '' %> <% end -%> - <% if active_scaffold_config.action_links.any? {|link| link.type == :record } -%> - <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options} %> - - <% end -%> - + <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options} if active_scaffold_config.action_links.any? {|link| link.type == :record } %> <% target_id = element_row_id(:action => :list, :id => record.id) -%> + + + diff --git a/frontends/default/views/list.html.erb b/frontends/default/views/list.html.erb index 18414d11a7..409f010746 100644 --- a/frontends/default/views/list.html.erb +++ b/frontends/default/views/list.html.erb @@ -12,6 +12,8 @@ + <% else %> + <% end %> <% if params[:nested].nil? && active_scaffold_config.list.always_show_create %> @@ -30,10 +32,11 @@ diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index d2ac02dded..3c4c6a1b54 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -3,7 +3,7 @@ module Helpers # A bunch of helper methods to produce the common view ids module IdHelpers def controller_id - @controller_id ||= (params[:eid] || params[:parent_controller] || params[:controller]).gsub("/", "__") + @controller_id ||= 'as_' + (params[:eid] || params[:parent_controller] || params[:controller]).gsub("/", "__") end def active_scaffold_id diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 67ed240aa9..52c86c5573 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -155,7 +155,7 @@ def render_action_link(link, url_options) html_options[:position] = link.position if link.position and link.inline? html_options[:class] += ' action' if link.inline? html_options[:popup] = true if link.popup? - html_options[:id] = action_link_id(url_options[:action],url_options[:id] || url_options[:parent_id]) + html_options[:id] = action_link_id("#{url_options[:parent_controller] + '_' if url_options[:parent_controller]}" + url_options[:action],url_options[:id] || url_options[:parent_id]) if link.dhtml_confirm? html_options[:class] += ' action' if !link.inline? From 081ec6367c27cea80aa667aa484ab50d3af0e883 Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 13 Jul 2009 18:05:33 +0200 Subject: [PATCH 0013/2024] Fix delete without AJAX --- frontends/default/javascripts/active_scaffold.js | 1 + frontends/default/views/destroy.js.rjs | 2 +- lib/active_scaffold/config/delete.rb | 2 +- lib/extensions/resources.rb | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index bb26303c4c..b383be1ea4 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -314,6 +314,7 @@ ActiveScaffold.Actions.Record.prototype = Object.extend(new ActiveScaffold.Actio instantiate_link: function(link) { var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); l.refresh_url = this.options.refresh_url; + if (link.hasClassName('delete')) l.url = l.url.replace(/\/delete(\?.*)?/, '$1'); if (l.position) l.url = l.url.append_params({adapter: '_list_inline_adapter'}); l.set = this; return l; diff --git a/frontends/default/views/destroy.js.rjs b/frontends/default/views/destroy.js.rjs index 2baa860a98..ca287de40a 100644 --- a/frontends/default/views/destroy.js.rjs +++ b/frontends/default/views/destroy.js.rjs @@ -1,5 +1,5 @@ if controller.send(:successful?) - page << "$('#{action_link_id((respond_to?(:nested_habtm?) and nested_habtm? and active_scaffold_config.nested.shallow_delete) ? 'destroy_existing' : 'destroy', params[:id])}').action_link.close_previous_adapter();" + page << "$('#{action_link_id((respond_to?(:nested_habtm?) and nested_habtm? and active_scaffold_config.nested.shallow_delete) ? 'destroy_existing' : 'delete', params[:id])}').action_link.close_previous_adapter();" page.remove element_row_id(:action => 'list', :id => params[:id]) page << "ActiveScaffold.reload_if_empty('#{active_scaffold_tbody_id}','#{url_for(params_for(:action => 'update_table', :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" page << "ActiveScaffold.stripe('#{active_scaffold_tbody_id}');" diff --git a/lib/active_scaffold/config/delete.rb b/lib/active_scaffold/config/delete.rb index 0b897e4636..465795e580 100644 --- a/lib/active_scaffold/config/delete.rb +++ b/lib/active_scaffold/config/delete.rb @@ -14,7 +14,7 @@ def initialize(core_config) # the ActionLink for this action cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('destroy', :label => :delete, :type => :record, :confirm => 'are_you_sure', :method => :delete, :position => false, :security_method => :delete_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('delete', :label => :delete, :type => :record, :confirm => 'are_you_sure', :method => :delete, :position => false, :security_method => :delete_authorized?) # instance-level configuration # ---------------------------- diff --git a/lib/extensions/resources.rb b/lib/extensions/resources.rb index d21c5b565e..9359f36906 100644 --- a/lib/extensions/resources.rb +++ b/lib/extensions/resources.rb @@ -3,7 +3,7 @@ module Resources class Resource ACTIVE_SCAFFOLD_ROUTING = { :collection => {:show_search => :get, :update_table => :get, :edit_associated => :get, :list => :get, :new_existing => :get, :add_existing => :post, :render_field => :get}, - :member => {:row => :get, :nested => :get, :edit_associated => :get, :add_association => :get, :update_column => :post, :destroy_existing => :delete, :render_field => :get} + :member => {:row => :get, :nested => :get, :edit_associated => :get, :add_association => :get, :update_column => :post, :destroy_existing => :delete, :render_field => :get, :delete => :get} } # by overwriting the attr_reader :options, we can parse out a special :active_scaffold flag just-in-time. From 94c7ca0d4fab8a4f7b8de375c0d4edd3423ba906 Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 17 Jul 2009 10:49:08 +0200 Subject: [PATCH 0014/2024] Fix checking permissions for empty plural associations, it fixes an exception in through associations --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index e60eafe055..bc61c591f3 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -78,7 +78,7 @@ def render_list_column(text, column, record) # check authorization if column.association - authorized = (associated ? associated : column.association.klass).authorized_for?(:action => link.crud_type) + authorized = (associated.blank? ? column.association.klass : associated).authorized_for?(:action => link.crud_type) authorized = authorized and record.authorized_for?(:action => :update, :column => column.name) if link.crud_type == :create else authorized = record.authorized_for?(:action => link.crud_type) From ba2451498becf8e7c79c82bf95038c6f9c5d0fc6 Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 20 Jul 2009 10:53:46 +0200 Subject: [PATCH 0015/2024] Fix checking permissions for non-empty through associations --- lib/active_scaffold/helpers/list_column_helpers.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index bc61c591f3..561da01d3d 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -78,7 +78,14 @@ def render_list_column(text, column, record) # check authorization if column.association - authorized = (associated.blank? ? column.association.klass : associated).authorized_for?(:action => link.crud_type) + associated_for_authorized = if associated.blank? + column.association.klass + elsif associated.is_a? Array + associated.first + else + associated + end + authorized = associated_for_authorized.authorized_for?(:action => link.crud_type) authorized = authorized and record.authorized_for?(:action => :update, :column => column.name) if link.crud_type == :create else authorized = record.authorized_for?(:action => link.crud_type) From 228afdb0bda851a7d26b73e70a08cffb50f7312e Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 23 Jul 2009 12:02:42 +0200 Subject: [PATCH 0016/2024] Add russian translation by Antiarchitect --- lib/active_scaffold/locale/ru.yml | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 lib/active_scaffold/locale/ru.yml diff --git a/lib/active_scaffold/locale/ru.yml b/lib/active_scaffold/locale/ru.yml new file mode 100644 index 0000000000..f04e36c1d0 --- /dev/null +++ b/lib/active_scaffold/locale/ru.yml @@ -0,0 +1,61 @@ +ru: + active_scaffold: + add: 'Добавить запись' + add_existing: 'Добавить существующую запись' + add_existing_model: 'Добавить существующую запись {{model}}' + are_you_sure: 'Вы уверены?' + cancel: 'Отмена' + click_to_edit: 'Нажмите для редактирования' + close: 'Закрыть' + create: 'Создать запись' + create_model: 'Создать запись {{model}}' + create_another: 'Создать другую запись' + created_model: 'Создана запись {{model}}' + create_new: 'Создать новую запись' + customize: 'Настроить' + delete: 'Удалить' + deleted_model: 'Удалена запись {{model}}' + delimiter: 'Разделитель' + download: 'Загрузить' + edit: 'Изменить' + export: 'Экспорт' + nested_for_model: '{{parent_model}} / {{nested_model}}' + filtered: '(Найденное)' + found: 'Найдено' + hide: 'Скрыть' + live_search: 'Поиск' + loading: 'Загрузка...' + next: 'Следующее' + no_entries: 'Нет записей' + omit_header: 'Omit Header' + options: 'Настройки' + pdf: 'PDF' + previous: 'Предыдущее' + print: 'Распечатать' + refresh: 'Обновить' + remove: 'Удалить' + remove_file: 'Удалить или заменить файл' + replace_with_new: 'Заменить новым' + revisions_for_model: 'Редакции {{model}}' + reset: 'Сбросить' + saving: 'Сохранение...' + search: 'Поиск' + search_terms: 'Ключевые слова' + _select_: '- выбрать -' + show: 'Показать' + show_model: 'Показать запись {{model}}' + _to_ : ' to ' + update: 'Обновить запись' + update_model: 'Обновить запись {{model}}' + udated_model: 'Обновлена запись {{model}}' + '=': '=' + '>=': '>=' + '<=': '<=' + '>': '>' + '<': '<' + '!=': '!=' + between: 'Между' + + # error_messages + internal_error: 'Внутренняя ошибка сервера.' + version_inconsistency: 'Эта запись была обновлена с того момента, как вы начали ее редактировать.' From ab2ad2ea3f8e67edf4f2766be68cf20f1457f178 Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 23 Jul 2009 12:25:31 +0200 Subject: [PATCH 0017/2024] Mark required fields in subforms --- frontends/default/stylesheets/stylesheet.css | 2 +- frontends/default/views/_horizontal_subform_header.html.erb | 4 ++-- frontends/default/views/_vertical_subform_record.html.erb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 3ef0f39e02..55ebdd09e1 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -741,7 +741,7 @@ padding: 0 5px 0 1px; background: none; } -.active-scaffold .horizontal-sub-form label { +.active-scaffold .horizontal-sub-form td label { display: none; } diff --git a/frontends/default/views/_horizontal_subform_header.html.erb b/frontends/default/views/_horizontal_subform_header.html.erb index e1760b5067..240d0d3bbe 100644 --- a/frontends/default/views/_horizontal_subform_header.html.erb +++ b/frontends/default/views/_horizontal_subform_header.html.erb @@ -4,7 +4,7 @@ active_scaffold_config_for(@record.class).subform.columns.each :for => @record, :flatten => true do |column| next unless in_subform?(column, parent_record) and column_renders_as(column) != :hidden -%> - <%= column.label %> + > <% end -%> - \ No newline at end of file + diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index 4fa47b626d..1aabfa4545 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -12,7 +12,7 @@ column = column.clone column.form_ui ||= :select if column.association -%> -
  2. +
  3. <% unless readonly -%> <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%> <% else -%> From 8be51aa50541784dfc7a3ebfae8bf0d38240560d Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 23 Jul 2009 17:55:30 +0200 Subject: [PATCH 0018/2024] Fix issue #35 --- lib/active_scaffold.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index d23c659c47..4f842d3597 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -134,7 +134,13 @@ def add_active_scaffold_override_path(path) end def active_scaffold_paths - @active_scaffold_paths ||= ActionView::PathSet.new(@active_scaffold_overrides + @active_scaffold_custom_paths + @active_scaffold_frontends) unless @active_scaffold_overrides.nil? || @active_scaffold_custom_paths.nil? || @active_scaffold_frontends.nil? + return @active_scaffold_paths unless @active_scaffold_paths.nil? + + @active_scaffold_paths = ActionView::PathSet.new + @active_scaffold_paths.concat @active_scaffold_overrides unless @active_scaffold_overrides.nil? + @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil? + @active_scaffold_paths.concat @active_scaffold_frontends) unless @active_scaffold_frontends.nil? + @active_scaffold_paths end def active_scaffold_config From db24e068cab7780f934876faf046dd7cf093b84f Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 24 Jul 2009 09:18:56 +0200 Subject: [PATCH 0019/2024] Fix a typo --- lib/active_scaffold.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 4f842d3597..4824e2804c 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -139,7 +139,7 @@ def active_scaffold_paths @active_scaffold_paths = ActionView::PathSet.new @active_scaffold_paths.concat @active_scaffold_overrides unless @active_scaffold_overrides.nil? @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil? - @active_scaffold_paths.concat @active_scaffold_frontends) unless @active_scaffold_frontends.nil? + @active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil? @active_scaffold_paths end From 8a808f9ddb2f9f42c378ec0e36393ee008bcbb3b Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 24 Jul 2009 14:36:40 +0200 Subject: [PATCH 0020/2024] Use a different cache or concat string for ie stylesheets --- lib/active_scaffold/helpers/view_helpers.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 52c86c5573..5e2808071a 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -105,6 +105,8 @@ def active_scaffold_includes(*args) js = javascript_include_tag(*active_scaffold_javascripts(frontend).push(options)) css = stylesheet_link_tag(*active_scaffold_stylesheets(frontend).push(options)) + options[:cache] += '_ie' if options[:cache].is_a? String + options[:concat] += '_ie' if options[:concat].is_a? String ie_css = stylesheet_link_tag(*active_scaffold_ie_stylesheets(frontend).push(options)) js + "\n" + css + "\n\n" From e445041c00420d031f48c4d093245d3b50a917c4 Mon Sep 17 00:00:00 2001 From: Leo Wong Date: Mon, 27 Jul 2009 03:33:58 +0800 Subject: [PATCH 0021/2024] make loading indicator look a little bit nicer --- frontends/default/stylesheets/stylesheet.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 55ebdd09e1..e4cc6fa31f 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -500,7 +500,7 @@ background-color: transparent; ============================== */ .active-scaffold .loading-indicator { -vertical-align: bottom; +vertical-align: text-bottom; width: 16px; margin: 0; } From e00f36a53273144ac054637b5e88fa45bf37b7da Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 27 Jul 2009 12:16:35 +0200 Subject: [PATCH 0022/2024] Optimize associations rendering when eager loading is disabled --- .../helpers/list_column_helpers.rb | 15 ++++++++++----- lib/active_scaffold/helpers/view_helpers.rb | 3 +-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 561da01d3d..97dfcd02f2 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -32,14 +32,19 @@ def get_column_value(record, column) if column.associated_limit.nil? firsts = value.collect { |v| v.to_label } else - firsts = value.first(column.associated_limit + 1).collect { |v| v.to_label } + firsts = if value.loaded? # we are using eager loading, use first in order not to query the database + value.first(column.associated_limit + 1) + else + value.find(:all, :limit => column.associated_limit + 1) + end + firsts.collect! { |v| v.to_label } firsts[column.associated_limit] = '…' if firsts.length > column.associated_limit end if column.associated_limit == 0 - formatted_value = value.length if column.associated_number? + formatted_value = value.size if column.associated_number? else formatted_value = clean_column_value(format_value(firsts.join(', '))) - formatted_value << " (#{value.length})" if column.associated_number? and column.associated_limit and firsts.length > column.associated_limit + formatted_value << " (#{value.size})" if column.associated_number? and column.associated_limit and firsts.length > column.associated_limit end formatted_value end @@ -78,9 +83,9 @@ def render_list_column(text, column, record) # check authorization if column.association - associated_for_authorized = if associated.blank? + associated_for_authorized = if associated.nil? || associated.empty? column.association.klass - elsif associated.is_a? Array + elsif column.plural_association? associated.first else associated diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 5e2808071a..4d56b7dbeb 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -185,8 +185,7 @@ def column_class(column, column_value) def column_empty?(column_value) empty = column_value.nil? empty ||= column_value.empty? if column_value.respond_to? :empty? - empty ||= (column_value == ' ') - empty ||= (column_value == active_scaffold_config.list.empty_field_text) + empty ||= [' ', active_scaffold_config.list.empty_field_text].include? column_value if String === column_value return empty end From 4709692a38f8620160254af00fd1f906f0030b5c Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 28 Jul 2009 12:13:12 +0200 Subject: [PATCH 0023/2024] Fix links for singular associations --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 97dfcd02f2..90661d6360 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -83,7 +83,7 @@ def render_list_column(text, column, record) # check authorization if column.association - associated_for_authorized = if associated.nil? || associated.empty? + associated_for_authorized = if associated.nil? || (associated.respond_to?(:empty?) && associated.empty?) column.association.klass elsif column.plural_association? associated.first From 2bb78e58cb83170129b83cf510b279ac5b56eea4 Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 30 Jul 2009 15:15:34 +0200 Subject: [PATCH 0024/2024] Fix including security methods --- lib/active_record_permissions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_record_permissions.rb b/lib/active_record_permissions.rb index f446dc2de6..222a715424 100644 --- a/lib/active_record_permissions.rb +++ b/lib/active_record_permissions.rb @@ -63,7 +63,7 @@ def current_user module Permissions def self.included(base) base.extend SecurityMethods - base.include SecurityMethods + base.send :include, SecurityMethods end # Because any class-level queries get delegated to the instance level via a new record, From 9501edbf3dc986207e58ea55f2327890d7c06522 Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 30 Jul 2009 17:11:14 +0200 Subject: [PATCH 0025/2024] Fix dhtml history requests Enable dhtml history in page number links --- frontends/default/javascripts/dhtml_history.js | 2 +- lib/active_scaffold/helpers/pagination_helpers.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/dhtml_history.js b/frontends/default/javascripts/dhtml_history.js index 1eb5e4d0bb..161417e2e3 100755 --- a/frontends/default/javascripts/dhtml_history.js +++ b/frontends/default/javascripts/dhtml_history.js @@ -858,7 +858,7 @@ var handleHistoryChange = function(pageId, pageData) { var info = pageId.split(':'); var id = info[0]; pageData += '&_method=get'; - new Ajax.Updater(id+'-content', pageData, {asynchronous:true, evalScripts:true, onLoading:function(request){Element.show(id+'-pagination-loading-indicator');}}); + new Ajax.Updater(id+'-content', pageData, {asynchronous:true, evalScripts:true, method: 'get', onLoading:function(request){Element.show(id+'-pagination-loading-indicator');}}); } window.onload = function() { diff --git a/lib/active_scaffold/helpers/pagination_helpers.rb b/lib/active_scaffold/helpers/pagination_helpers.rb index c67b28ea18..61920309eb 100644 --- a/lib/active_scaffold/helpers/pagination_helpers.rb +++ b/lib/active_scaffold/helpers/pagination_helpers.rb @@ -2,8 +2,10 @@ module ActiveScaffold module Helpers module PaginationHelpers def pagination_ajax_link(page_number, params) + url = url_for params.merge(:page => page_number) page_link = link_to_remote(page_number, - { :url => params.merge(:page => page_number), + { :url => url, + :before => "addActiveScaffoldPageToHistory('#{url}', '#{controller_id}');", :after => "$('#{loading_indicator_id(:action => :pagination)}').style.visibility = 'visible';", :complete => "$('#{loading_indicator_id(:action => :pagination)}').style.visibility = 'hidden';", :update => active_scaffold_content_id, From cd5add332e098ef263a25ce43fa37f1ef78505f1 Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 30 Jul 2009 17:38:29 +0200 Subject: [PATCH 0026/2024] Fix security for delete action link --- lib/active_scaffold/config/delete.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/delete.rb b/lib/active_scaffold/config/delete.rb index 465795e580..a715b8319a 100644 --- a/lib/active_scaffold/config/delete.rb +++ b/lib/active_scaffold/config/delete.rb @@ -14,7 +14,7 @@ def initialize(core_config) # the ActionLink for this action cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('delete', :label => :delete, :type => :record, :confirm => 'are_you_sure', :method => :delete, :position => false, :security_method => :delete_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('delete', :label => :delete, :type => :record, :confirm => 'are_you_sure', :crud_type => :destroy, :method => :delete, :position => false, :security_method => :delete_authorized?) # instance-level configuration # ---------------------------- From 3294b9e2be4bf322a82c608435e0d341049fed14 Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 31 Jul 2009 12:40:16 +0200 Subject: [PATCH 0027/2024] clone actions_for_association_links because deleting a value in a column will delete it in all columns of all controllers --- lib/active_scaffold/data_structures/column.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 0b902acade..9de97a34f4 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -233,7 +233,7 @@ def initialize(name, active_record_class) #:nodoc: @associated_limit = self.class.associated_limit @associated_number = self.class.associated_number @show_blank_record = self.class.show_blank_record - @actions_for_association_links = self.class.actions_for_association_links if @association + @actions_for_association_links = self.class.actions_for_association_links.clone if @association # default all the configurable variables self.css_class = '' From 05a9fd51a755c76396803a9ce00de835852f3a7e Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 3 Aug 2009 09:57:01 +0200 Subject: [PATCH 0028/2024] Try to fix changing delete to destroy for non RESTful routes --- frontends/default/javascripts/active_scaffold.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index b383be1ea4..c99efa1644 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -314,7 +314,10 @@ ActiveScaffold.Actions.Record.prototype = Object.extend(new ActiveScaffold.Actio instantiate_link: function(link) { var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); l.refresh_url = this.options.refresh_url; - if (link.hasClassName('delete')) l.url = l.url.replace(/\/delete(\?.*)?/, '$1'); + if (link.hasClassName('delete')) { + l.url = l.url.replace(/\/delete(\?.*)?$/, '$1'); + l.url = l.url.replace(/\/delete\/(.*)/, '/destroy/$1'); + } if (l.position) l.url = l.url.append_params({adapter: '_list_inline_adapter'}); l.set = this; return l; From edd1fb8ef9a802f718be8260362a2fb3fa93b160 Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 4 Aug 2009 11:20:39 +0200 Subject: [PATCH 0029/2024] Enable setting options for select method in column.options --- .../helpers/form_column_helpers.rb | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 2ca5f43e57..110b2e7b5c 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -77,7 +77,7 @@ def javascript_for_update_column(column, scope, options) ## Form input methods ## - def active_scaffold_input_singular_association(column, options) + def active_scaffold_input_singular_association(column, html_options) associated = @record.send(column.association.name) select_options = options_for_association(column.association) @@ -85,8 +85,18 @@ def active_scaffold_input_singular_association(column, options) selected = associated.nil? ? nil : associated.id method = column.association.macro == :belongs_to ? column.association.primary_key_name : column.name - options[:name] += '[id]' - select(:record, method, select_options.uniq, {:selected => selected, :include_blank => as_(:_select_)}, options.merge(column.options)) + html_options[:name] += '[id]' + options = {:selected => selected, :include_blank => as_(:_select_)} + + # For backwards compatibility, to add method options is needed to set a html_options hash + # in other case all column.options will be added as html options + if column.options[:html_options] + html_options.update(column.options[:html_options]) + options.update(column.options) + else + html_options.update(column.options) + end + select(:record, method, select_options.uniq, options, html_options) end def active_scaffold_input_plural_association(column, options) @@ -114,13 +124,21 @@ def active_scaffold_input_plural_association(column, options) html end - def active_scaffold_input_select(column, options) + def active_scaffold_input_select(column, html_options) if column.singular_association? - active_scaffold_input_singular_association(column, options) + active_scaffold_input_singular_association(column, html_options) elsif column.plural_association? - active_scaffold_input_plural_association(column, options) + active_scaffold_input_plural_association(column, html_options) else - select(:record, column.name, column.options, { :selected => @record.send(column.name) }, options) + options = { :selected => @record.send(column.name) } + if column.options.is_a? Hash + options_for_select = column.options[:options] + html_options.update(column.options[:html_options] || {}) + options.update(column.options) + else + options_for_select = column.options + end + select(:record, column.name, options_for_select, options, html_options) end end From 4e6ad0df45ad0c5d86498e046ac8ee8bd035dab8 Mon Sep 17 00:00:00 2001 From: Dan Tennant Date: Tue, 4 Aug 2009 16:44:43 -0400 Subject: [PATCH 0030/2024] changing this function to use Element.update instead of Element.replace, so that multiple actions will work correctly. Fixes issue 695 --- frontends/default/views/edit_associated.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/edit_associated.js.rjs b/frontends/default/views/edit_associated.js.rjs index 33e4a11d1b..da2fe2fe31 100644 --- a/frontends/default/views/edit_associated.js.rjs +++ b/frontends/default/views/edit_associated.js.rjs @@ -4,7 +4,7 @@ if @column.singular_association? page << %| associated = #{associated_form.to_json}; if (current = $$('##{sub_form_list_id(:association => @column.name)} .association-record')[0]) { - Element.replace(current, associated) + Element.update(current, associated) } else { new Insertion.Top('#{sub_form_list_id(:association => @column.name)}', associated) } From 65a8bce3fdba837d302d210e10c720473c517685 Mon Sep 17 00:00:00 2001 From: Kenny Ortmann Date: Wed, 5 Aug 2009 11:10:12 -0500 Subject: [PATCH 0031/2024] adding in try statement for when page.items returns nil --- lib/active_scaffold/actions/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index cc05f6bab2..43d1d68fed 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -70,7 +70,7 @@ def do_list end page = find_page(options); - if page.items.empty? + if page.items.try(:empty?) page = page.pager.first active_scaffold_config.list.user.page = 1 end From 9e4bd651e3bdf2f49d76b2d96fce55deecfb24da Mon Sep 17 00:00:00 2001 From: Kenny Ortmann Date: Wed, 5 Aug 2009 11:10:12 -0500 Subject: [PATCH 0032/2024] adding in try statement for when page.items returns nil --- lib/active_scaffold/actions/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 71d8449b74..a27ed7e904 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -70,7 +70,7 @@ def do_list end page = find_page(options); - if page.items.empty? + if page.items.try(:empty?) page = page.pager.first active_scaffold_config.list.user.page = 1 end From d72a173c282755e8c1689ba1b048a9c02b2bc75f Mon Sep 17 00:00:00 2001 From: Kenny Ortmann Date: Wed, 5 Aug 2009 11:28:24 -0500 Subject: [PATCH 0033/2024] actually fix issue where page.items is nil --- lib/active_scaffold/actions/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 43d1d68fed..4f6b0d8432 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -70,7 +70,7 @@ def do_list end page = find_page(options); - if page.items.try(:empty?) + if page.items.blank? page = page.pager.first active_scaffold_config.list.user.page = 1 end From 60546f6b3fae5e92a6654b3079ede1f365d6eaa4 Mon Sep 17 00:00:00 2001 From: Kenny Ortmann Date: Wed, 5 Aug 2009 11:28:24 -0500 Subject: [PATCH 0034/2024] actually fix issue where page.items is nil --- lib/active_scaffold/actions/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index a27ed7e904..6d72926bba 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -70,7 +70,7 @@ def do_list end page = find_page(options); - if page.items.try(:empty?) + if page.items.blank? page = page.pager.first active_scaffold_config.list.user.page = 1 end From 808f361e279b194e93603e78fb6e18e647a21c8b Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 6 Aug 2009 11:43:25 +0200 Subject: [PATCH 0035/2024] Fix colors for visited links --- frontends/default/stylesheets/stylesheet.css | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index e4cc6fa31f..fbc43f43e3 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -153,7 +153,7 @@ display: block; background-color: #555; } -.active-scaffold th a { +.active-scaffold th a, .active-scaffold th a:visited { color: #fff; padding: 2px 15px 2px 5px; } @@ -314,7 +314,8 @@ font: bold 11px verdana, sans-serif; padding: 0 2px 1px 17px; } -.blue-theme .active-scaffold .active-scaffold-header div.actions a { +.blue-theme .active-scaffold .active-scaffold-header div.actions a, +.blue-theme .active-scaffold .active-scaffold-header div.actions a:visited { color: #06c; } @@ -377,7 +378,8 @@ margin: 0 -2px; font: bold 12px arial, sans-serif; } -.blue-theme .active-scaffold-footer a { +.blue-theme .active-scaffold-footer a, +.blue-theme .active-scaffold-footer a:visited { color: #fff; } From dc2a060a80c3a96db73eac54091fe7a4c62a33d5 Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 6 Aug 2009 11:43:25 +0200 Subject: [PATCH 0036/2024] Fix colors for visited links --- frontends/default/stylesheets/stylesheet.css | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index e4cc6fa31f..fbc43f43e3 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -153,7 +153,7 @@ display: block; background-color: #555; } -.active-scaffold th a { +.active-scaffold th a, .active-scaffold th a:visited { color: #fff; padding: 2px 15px 2px 5px; } @@ -314,7 +314,8 @@ font: bold 11px verdana, sans-serif; padding: 0 2px 1px 17px; } -.blue-theme .active-scaffold .active-scaffold-header div.actions a { +.blue-theme .active-scaffold .active-scaffold-header div.actions a, +.blue-theme .active-scaffold .active-scaffold-header div.actions a:visited { color: #06c; } @@ -377,7 +378,8 @@ margin: 0 -2px; font: bold 12px arial, sans-serif; } -.blue-theme .active-scaffold-footer a { +.blue-theme .active-scaffold-footer a, +.blue-theme .active-scaffold-footer a:visited { color: #fff; } From d309321681681bfe64c698d3ff19cd408f987596 Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 6 Aug 2009 13:56:58 +0200 Subject: [PATCH 0037/2024] Add class names to show views --- frontends/default/views/_show_columns.html.erb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/frontends/default/views/_show_columns.html.erb b/frontends/default/views/_show_columns.html.erb index e5248d4594..f603221779 100644 --- a/frontends/default/views/_show_columns.html.erb +++ b/frontends/default/views/_show_columns.html.erb @@ -1,11 +1,12 @@
    <% columns.each :for => @record do |column| %> - <% if column.is_a? ActiveScaffold::DataStructures::ActionColumns -%> -
    <%= column.label -%>
    -
    <%= render :partial => 'show_columns', :locals => {:columns => column} %>
    - <% else -%> -
    <%= column.label -%>
    -
    <%= show_column_value(@record, column) -%>  
    - <% end -%> +
    <%= column.label -%>
    +
    +<% if column.is_a? ActiveScaffold::DataStructures::ActionColumns -%> + <%= render :partial => 'show_columns', :locals => {:columns => column} %> +<% else -%> + <%= show_column_value(@record, column) -%>   +<% end -%> +
    <% end -%>
    From 4c6c0beeda4462ac6c2a5fe217cec7659f3f631b Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 6 Aug 2009 16:59:28 +0200 Subject: [PATCH 0038/2024] Pluralize model for label in nested scaffold --- frontends/default/views/_nested.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_nested.html.erb b/frontends/default/views/_nested.html.erb index 20a92a87cc..7c2d228ae1 100644 --- a/frontends/default/views/_nested.html.erb +++ b/frontends/default/views/_nested.html.erb @@ -25,7 +25,7 @@ end # generate the customized label - @label = as_(:nested_for_model, :nested_model => active_scaffold_config_for(association.klass).label, :parent_model => format_value(@record.to_label)) + @label = as_(:nested_for_model, :nested_model => active_scaffold_config_for(association.klass).list.label, :parent_model => format_value(@record.to_label)) begin controller = active_scaffold_controller_for(association.klass) From 1f45f4228157ffdb1d1eee749b3d71efeb1600c9 Mon Sep 17 00:00:00 2001 From: Patrick Feisthammel Date: Mon, 10 Aug 2009 09:42:14 +0200 Subject: [PATCH 0039/2024] German locale --- lib/active_scaffold/locale/de.rb | 67 ++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 lib/active_scaffold/locale/de.rb diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb new file mode 100644 index 0000000000..1c48894499 --- /dev/null +++ b/lib/active_scaffold/locale/de.rb @@ -0,0 +1,67 @@ +{ + :'de' => { + :active_scaffold => { + :add => 'Hinzufügen', + :add_existing => 'Existierenden Eintrag hinzufügen', + :add_existing_model => 'Existierende {{model}} hinzufügen', + :are_you_sure => 'Sind Sie sicher?', + :cancel => 'Abbrechen', + :click_to_edit => 'Zum Editieren anklicken', + :close => 'Schliessen', + :create => 'Anlegen', + :create_model => 'Lege {{model}} an', + :create_another => 'Weitere anlegen', + :created_model => '{{model}} anlegen', + :create_new => 'Neu anlegen', + :customize => 'Anpassen', + :delete => 'Löschen', + :deleted_model => '{{model}} gelöscht', + :delimiter => 'Trennzeichen', + :download => 'Download', + :edit => 'Bearbeiten', + :export => 'Exportieren', + :nested_for_model => '{{nested_model}} für {{parent_model}}', + :filtered => '(Gefiltert)', + :found => 'Gefunden', + :hide => 'Verstecken', + :live_search => 'Live-Suche', + :loading => 'Lade…', + :next => 'Vorwärts', + :no_entries => 'Keine Einträge', + :no_options => 'Keine Optionen', + :omit_header => 'Lasse Header weg', + :options => 'Optionen', + :pdf => 'PDF', + :previous => 'Zurück', + :print => 'Drucken', + :refresh => 'Neu laden', + :remove => 'Entfernen', + :remove_file => 'Entferne oder Ersetze Datei', + :replace_with_new => 'Mit Neuer ersetzen', + :revisions_for_model => 'Revisionen für {{model}}', + :reset => 'Zurücksetzen', + :saving => 'Speichern…', + :search => 'Suche', + :search_terms => 'Suchbegriffe', + :_select_ => '- Auswählen -', + :show => 'Anzeigen', + :show_model => 'Zeige {{model}} an', + :_to_ => ' zu ', + :update => 'Speichern', + :update_model => 'Editiere {{model}}', + :udated_model => '{{model}} aktualisiert', + :'=' => '=', + :'>=' => '>=', + :'<=' => '<=', + :'>' => '>', + :'<' => '<', + :'!=' => '!=', + :between => 'Zwischen', + + # error_messages + :cant_destroy_record => "{{record}} kann nicht gelöscht werden", + :internal_error => 'Fehler bei der Verarbeitung (code 500, Interner Fehler)', + :version_inconsistency => 'Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben.' + } + } +} From 6c8ada14f1538039b429bd7dc26556eb912c84ef Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 10 Aug 2009 10:20:14 +0200 Subject: [PATCH 0040/2024] Add support for multiple chaining fields --- frontends/default/views/render_field.js.rjs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/render_field.js.rjs b/frontends/default/views/render_field.js.rjs index c67d81814b..780026cce0 100644 --- a/frontends/default/views/render_field.js.rjs +++ b/frontends/default/views/render_field.js.rjs @@ -1,2 +1,7 @@ -field_id = active_scaffold_input_options(@update_column, params[:scope])[:id] -page[field_id].up('li').replace_html :partial => form_partial_for_column(@update_column), :locals => { :column => @update_column, :scope => params[:scope] } +column = @update_column +while column + field_id = active_scaffold_input_options(column, params[:scope])[:id] + page[field_id].up('li').replace_html :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } + column = Hash === column.options ? column.options[:update_column] : nil + column = active_scaffold_config.columns[column] if column +end From 0edf791f816b043403bcc2d4c7c8cd348dfc3085 Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 10 Aug 2009 10:49:35 +0200 Subject: [PATCH 0041/2024] Fix css for fields with errors (github issue #44) --- frontends/default/stylesheets/stylesheet.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index fbc43f43e3..a8804a6518 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -644,7 +644,8 @@ border: solid 1px #1F7F00; padding: 2px; } -.active-scaffold .fieldWithErrors input.text-input, +.active-scaffold .fieldWithErrors input, +.active-scaffold .fieldWithErrors textarea, .active-scaffold .fieldWithErrors select { border: solid 1px #f00; } From 4551c902d3a2ef86d6201d40d1fff28fcdeca81e Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 10 Aug 2009 11:34:49 +0200 Subject: [PATCH 0042/2024] Fix marking with fieldWithErrors the select tags for belongs_to associations --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 110b2e7b5c..9336b9733a 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -84,7 +84,7 @@ def active_scaffold_input_singular_association(column, html_options) select_options.unshift([ associated.to_label, associated.id ]) unless associated.nil? or select_options.find {|label, id| id == associated.id} selected = associated.nil? ? nil : associated.id - method = column.association.macro == :belongs_to ? column.association.primary_key_name : column.name + method = column.name html_options[:name] += '[id]' options = {:selected => selected, :include_blank => as_(:_select_)} From 23668e99edb49590cb2b8a0822eaff9ee371071b Mon Sep 17 00:00:00 2001 From: Sergio Date: Thu, 13 Aug 2009 10:38:40 +0200 Subject: [PATCH 0043/2024] Use alias_method_chain to override Resource.options (fix #45) --- lib/extensions/resources.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/extensions/resources.rb b/lib/extensions/resources.rb index 9359f36906..5e90a0b845 100644 --- a/lib/extensions/resources.rb +++ b/lib/extensions/resources.rb @@ -7,7 +7,7 @@ class Resource } # by overwriting the attr_reader :options, we can parse out a special :active_scaffold flag just-in-time. - def options + def options_with_active_scaffold if @options.delete :active_scaffold logger.info "ActiveScaffold: extending RESTful routes for #{@plural}" @options[:collection] ||= {} @@ -15,8 +15,9 @@ def options @options[:member] ||= {} @options[:member].merge! ACTIVE_SCAFFOLD_ROUTING[:member] end - @options + options_without_active_scaffold end + alias_method_chain :options, :active_scaffold def logger ActionController::Base::logger From 12a3b098c4de8fd54a2f704daa3371553f35d049 Mon Sep 17 00:00:00 2001 From: Sergio Date: Fri, 14 Aug 2009 09:54:40 +0200 Subject: [PATCH 0044/2024] remove not used JS variable --- frontends/default/views/_list_record.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 81c563d0e1..e35f1e7469 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -20,7 +20,7 @@ url_options = params_for(:action => :list, :id => record.id) <% target_id = element_row_id(:action => :list, :id => record.id) -%> + +

    blank.html - Needed for Internet Explorer's hidden IFrame

    + + diff --git a/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT b/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT new file mode 100644 index 0000000000..c5e44a354f --- /dev/null +++ b/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT @@ -0,0 +1,2 @@ +Any changes made to files in sub-folders will be lost. +See http://activescaffold.com/tutorials/faq#custom-css. diff --git a/test/mock_app/public/images/active_scaffold/default/add.gif b/test/mock_app/public/images/active_scaffold/default/add.gif new file mode 100644 index 0000000000000000000000000000000000000000..51e6a2d53a13122a3e85de3bb56c22fee79de313 GIT binary patch literal 986 zcmZ?wbhEHb6krfw_|CxKz`$VLYU0>q>eOfM)NSR`ZROr$@7`zU(QD`4>)=1bA!v$s z$W))Oxh}D@Lz3qQC(I2?nje<3Ff46hWcsS0lvN>FE5kEaM`f>!%-s^62SO3~+arp% zMHO$0F5D4Sv@^P3Z(P~#_>$FWWoy#QHz(I_$gJL(T(dj1W^Y=>p4^%pnKe7I>UQMh zA4sY=kX(HztMX`8?SYKi<9Usnb6d9-v~Mfx-c{PMx4d&lMbF-g{*e?YgsW+kJ%pE(LbT%SCWpL0!C z30bC5csPmaplay`7s)1eegO&NYbFvIF1`{f_90jHC@{55RT5yiR1tjC{p|7zixWSJ z92RsMyHq)>J*n6#&cu}KFj45RE9*KLJBy146BJlY^qo2$%sS{ilaa-JjX>~}!)&~= t#}YgOJ~(n3`v=U)a60DH&@3pz@o*DsI|DN>tCd4Qg5$IE%*;#-)&TDaA-Mnm literal 0 HcmV?d00001 diff --git a/test/mock_app/public/images/active_scaffold/default/arrow_down.gif b/test/mock_app/public/images/active_scaffold/default/arrow_down.gif new file mode 100644 index 0000000000000000000000000000000000000000..bcda8697b6ac9701b40499855afe5fc32a7f899e GIT binary patch literal 853 zcmZ?wbhEHb6kuRy_|CvkRaI42SJ&9sxN6m^U%!6+{rmSn7%+^2(GVB`A)xq^g^>Z6 z6?8y;1?33_4kHGB76FG12?rV2h16sM4m2EYXXD}tSTRBINQbaySk8-pMQ*)fwskC? P3XeT{8T{lpI2fz}7^o(6 literal 0 HcmV?d00001 diff --git a/test/mock_app/public/images/active_scaffold/default/arrow_up.gif b/test/mock_app/public/images/active_scaffold/default/arrow_up.gif new file mode 100644 index 0000000000000000000000000000000000000000..b5e3399e44967d6a029de64dd19ea9a653cc1c31 GIT binary patch literal 851 zcmZ?wbhEHb6kuRy_|CvkRaI42SJ&9sxN6m^U%!6+{rmSn7%+^2(GVB`A)xq^g^>Z6 z6?8y;1?33_4g&^$4jGPw1qYj%*aajS1Rgdpv2hvX%n(@A*dZ(%wWlLc`FOt&KbwHV Nrj(NmY|Kmy)&Qp2Bz6D* literal 0 HcmV?d00001 diff --git a/test/mock_app/public/images/active_scaffold/default/close.gif b/test/mock_app/public/images/active_scaffold/default/close.gif new file mode 100644 index 0000000000000000000000000000000000000000..aa1b988cc99c95e9badcbd6ff2210ef7f990b310 GIT binary patch literal 960 zcmZ?wbhEHb6krf!_|Cu}R?IJ6%qLmSC0)rbSIZ<{&mdMHB9yKzoS`j}p(T;6Cz+!s zm9H;XsIOFPrdesNU1g)x$gJ7QZPhPt*x+Q_;p;J7KWx5z&g!DPbtSc1vs-o+Pd_tt z!O6+X&(7X+bMux*>$g4Lu=CmG{jatkzPtO_hrK61?LYtR$ocO_u0B71IyScpDC?d0pv1z&$YPXrN5bJChX6a9h=k{+Ck@Oj&eLKdAEbCq zWDQy|L7=gvYoeaxA(guEoyT++I zn$b9r%cFfhHe2K68PkBu*@^<$y+7xQ$wJ~;c5aBx$R=xq*41Wo zhwQus_VOgm0hughj}MhOvs#{>Vg09Y8WxjWUJY5YW zJ?&8eG!59Cz=|E%Ns@013KLWOLV)CObIIj_5{>{#k%TEAMs_GbdDV`x-iYsGH z#=Z{USAQA>NY(}X7=3{K8#o^IfD8vYgMn2$K}oI2VBRB#S&XxIHb|UVXSGe;amR7P zS2p)o76|ciA8|Qvq4aIax{H@ZnNanE3}Rqa1nNI*(8rR=r7=;>sb^kJkjQcgmhyRT z7B%Zv2=Mjp6aeYsgxksmwpAUdi^Z^yHIpx6qMGv@nUmU^jBC}J3SKO~=O-c|#O#_} zlpXt!wvdlubV z6`o{w!*|FkOH{$acy{5e#3#>^yGRm*%-h>*l%@ z5-iIjM2hF$SyUjT+!)}Z!6w}7$Q0o{&k5PNj6jb<0%#ITQY71o%t={F9B&Kvd{pF1 z3*_4q@n<(nzsvhN)Nl+6Z8W$ NR4SG~(qLh*1_1j1mLdQE literal 0 HcmV?d00001 diff --git a/test/mock_app/public/images/active_scaffold/default/indicator.gif b/test/mock_app/public/images/active_scaffold/default/indicator.gif new file mode 100644 index 0000000000000000000000000000000000000000..9cb298eb4ac260aecbb06f8e701dc7f411286a85 GIT binary patch literal 725 zcmZ?wbhEHb6krfwSi}GVhRJ(_s`n};Un}m}J7wvyoqJCK1r`5u`?-b$J39ur8tEA@ zGlGPEvao{G>wpN5b_Qk#j$Hx=Cs>M47szcge6aWCvC?bDdr~9|c^pH!6B*WVpDy|v z_9N#ogXH3X4vzLCNj&W;Z0WWg##K)wxr`rdnuK8}KhRKnj$I0efQE`I<~9i+8R`=l za@qjd(8CEG0*Xf-D@DdgaUE3_mh@$sGF4NB5#6DDKr?MQb~zjYni;N{%cO{8W=~>> zw*bh@P0@Qq?QR=1tT~#@!!{vGu)szrcbnQIkJX0D8(0t~G6B8L2le`@(BJD#SM)Gm z65O=r=&fUnVTHPnJm#Ih7TB+_#z5h;d=2*+yUPLV2KU+Lz znjW2k>~(~p_8hCyfQFuk(Ox%2HTRnI1=|D-s|m*f`5ouzJlG{{Eu8U2>#zf7lk58L z3`~{I4hjqgY!gqZe)gDXl-#ANjpB7Cpfe#}&tf~XZspgcmd~D1W^-qn^CWPJup0C& zYg(jzbD!qzT`xsg)EuYmmOb&DnYEIMvEhfY(&ST*cvtOdoU|6n>kJGC6RnuP9dq3p zQ7sgFTVqbNyJxaMk4EOKm7mt8{}vIvy-PuXBQtQp?z<0 zz$iC3Twp04%8|>Id;^h=x)nmWpYQr$vHvQ^g$+9dT0*%PSmu>gNuvOO$0ks zMIj=HnnBRUR?tKXG11rxCU4&7dG4NbuvR2_mEvc)n?Cow;~Wve|KR^>9@p5l)|QB+ z$jmun3q#x>;ss-PW_mnr2MHVzLAl1RW&0?VkixF*4t!St0YVb2wnKdU(kmOHiL;aW zK8Xte%(k>MVGG$E4no6dcNnb>BhVHHGD&1pv4YZ68kE2V03t5#PCEFm7=ad$6)+3B zTCmn*?A?=u(o~ET7~-7g0)ZB=6|lumi4}B}MLgy~Ysy6)Q5%Al7|05&1z3Jpu>cF8 z3?VXs*3<}%h3`5Wld)N2zJnk%Agw<~3k)sPTLFd=F5;d8-bj-09SkQuynfflNcZLN z!^_37fdZvzrq=9~mp*($%mcDRKC&qvaaZuX+C=AT6O*~tHl>0mcP<_q>-z%$xO(@! zYluq5a8VQI$S@4?r*v;gPo!QQ%pX3A#>xx4t=w-L6COWx?aj&`f+!YePsFtj=hOQR zP3=E2j@9L7s8;T^&s?u(Hdpu?CubjMrGn{t_37>9$|AD)QE08weJlKn8|OyjL~7oP zC8mPT`jzuH*Dh^I0048RGafUIT)4H~*m8m>egI0iH=(LB%b@@O002ovPDHLkV1lw0 B3'; + element.parentNode.replaceChild(tempDiv.getElementsByTagName(tn).item(0), element); + } + else throw e; + } + } else { + var range = element.ownerDocument.createRange(); + /* patch to fix
    replaces in Firefox. see http://dev.rubyonrails.org/ticket/8010 */ + range.selectNodeContents(element.parentNode); + element.parentNode.replaceChild(range.createContextualFragment(html.stripScripts()), element); + } + setTimeout(function() {html.evalScripts()}, 10); + return element; +}; + +/* + * URL modification support. Incomplete functionality. + */ +Object.extend(String.prototype, { + append_params: function(params) { + url = this; + if (url.indexOf('?') == -1) url += '?'; + else if (url.lastIndexOf('&') != url.length) url += '&'; + + url += $H(params).collect(function(item) { + return item.key + '=' + item.value; + }).join('&'); + + return url; + } +}); + +/* + * Prototype's implementation was throwing an error instead of false + */ +Element.Methods.Simulated = { + hasAttribute: function(element, attribute) { + var t = Element._attributeTranslations; + attribute = (t.names && t.names[attribute]) || attribute; + // Return false if we get an error here + try { + return $(element).getAttributeNode(attribute).specified; + } catch (e) { + return false; + } + } +}; + +/** + * A set of links. As a set, they can be controlled such that only one is "open" at a time, etc. + */ +ActiveScaffold.Actions = new Object(); +ActiveScaffold.Actions.Abstract = function(){} +ActiveScaffold.Actions.Abstract.prototype = { + initialize: function(links, target, loading_indicator, options) { + this.target = $(target); + this.loading_indicator = $(loading_indicator); + this.options = options; + this.links = links.collect(function(link) { + return this.instantiate_link(link); + }.bind(this)); + }, + + instantiate_link: function(link) { + throw 'unimplemented' + } +} + +/** + * A DataStructures::ActionLink, represented in JavaScript. + * Concerned with AJAX-enabling a link and adapting the result for insertion into the table. + */ +ActiveScaffold.ActionLink = new Object(); +ActiveScaffold.ActionLink.Abstract = function(){} +ActiveScaffold.ActionLink.Abstract.prototype = { + initialize: function(a, target, loading_indicator) { + this.tag = $(a); + this.url = this.tag.href; + this.method = 'get'; + if(this.url.match('_method=delete')){ + this.method = 'delete'; + } else if(this.url.match('_method=post')){ + this.method = 'post'; + } + this.target = target; + this.loading_indicator = loading_indicator; + this.hide_target = false; + this.position = this.tag.getAttribute('position'); + this.page_link = this.tag.getAttribute('page_link'); + + this.onclick = this.tag.onclick; + this.tag.onclick = null; + this.tag.observe('click', function(event) { + this.open(); + Event.stop(event); + }.bind(this)); + + this.tag.action_link = this; + }, + + open: function() { + if (this.is_disabled()) return; + + if (this.tag.hasAttribute( "dhtml_confirm")) { + if (this.onclick) this.onclick(); + return; + } else { + if (this.onclick && !this.onclick()) return;//e.g. confirmation messages + this.open_action(); + } + }, + + open_action: function() { + if (this.position) this.disable(); + + if (this.page_link) { + window.location = this.url; + } else { + if (this.loading_indicator) this.loading_indicator.style.visibility = 'visible'; + new Ajax.Request(this.url, { + asynchronous: true, + evalScripts: true, + method: this.method, + onSuccess: function(request) { + if (this.position) { + this.insert(request.responseText); + if (this.hide_target) this.target.hide(); + } else { + request.evalResponse(); + } + }.bind(this), + + onFailure: function(request) { + ActiveScaffold.report_500_response(this.scaffold_id()); + if (this.position) this.enable() + }.bind(this), + + onComplete: function(request) { + if (this.loading_indicator) this.loading_indicator.style.visibility = 'hidden'; + }.bind(this) + }); + } + }, + + insert: function(content) { + throw 'unimplemented' + }, + + close: function() { + this.enable(); + this.adapter.remove(); + if (this.hide_target) this.target.show(); + }, + + register_cancel_hooks: function() { + // anything in the insert with a class of cancel gets the closer method, and a reference to this object for good measure + var self = this; + this.adapter.select('.cancel').each(function(elem) { + elem.observe('click', this.close_handler.bind(this)); + elem.link = self; + }.bind(this)) + }, + + reload: function() { + this.close(); + this.open(); + }, + + get_new_adapter_id: function() { + var id = 'adapter_'; + var i = 0; + while ($(id + i)) i++; + return id + i; + }, + + enable: function() { + return this.tag.removeClassName('disabled'); + }, + + disable: function() { + return this.tag.addClassName('disabled'); + }, + + is_disabled: function() { + return this.tag.hasClassName('disabled'); + }, + + scaffold_id: function() { + return this.tag.up('div.active-scaffold').id; + } +} + +/** + * Concrete classes for record actions + */ +ActiveScaffold.Actions.Record = Class.create(); +ActiveScaffold.Actions.Record.prototype = Object.extend(new ActiveScaffold.Actions.Abstract(), { + instantiate_link: function(link) { + var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); + l.refresh_url = this.options.refresh_url; + if (link.hasClassName('delete')) { + l.url = l.url.replace(/\/delete(\?.*)?$/, '$1'); + l.url = l.url.replace(/\/delete\/(.*)/, '/destroy/$1'); + } + if (l.position) l.url = l.url.append_params({adapter: '_list_inline_adapter'}); + l.set = this; + return l; + } +}); + +ActiveScaffold.ActionLink.Record = Class.create(); +ActiveScaffold.ActionLink.Record.prototype = Object.extend(new ActiveScaffold.ActionLink.Abstract(), { + close_previous_adapter: function() { + this.set.links.each(function(item) { + if (item.url != this.url && item.is_disabled() && item.adapter) item.close(); + }.bind(this)); + }, + + insert: function(content) { + this.close_previous_adapter(); + + if (this.position == 'replace') { + this.position = 'after'; + this.hide_target = true; + } + + if (this.position == 'after') { + new Insertion.After(this.target, content); + this.adapter = this.target.next(); + } + else if (this.position == 'before') { + new Insertion.Before(this.target, content); + this.adapter = this.target.previous(); + } + else { + return false; + } + + this.adapter.down('a.inline-adapter-close').observe('click', this.close_handler.bind(this)); + this.register_cancel_hooks(); + + new Effect.Highlight(this.adapter.down('td')); + }, + + close_handler: function(event) { + this.close_with_refresh(); + if (event) Event.stop(event); + }, + + /* it might simplify things to just override the close function. then the Record and Table links could share more code ... wouldn't need custom close_handler functions, for instance */ + close_with_refresh: function() { + new Ajax.Request(this.refresh_url, { + asynchronous: true, + evalScripts: true, + method: this.method, + onSuccess: function(request) { + Element.replace(this.target, request.responseText); + var new_target = $(this.target.id); + if (this.target.hasClassName('even-record')) new_target.addClassName('even-record'); + this.target = new_target; + this.close(); + }.bind(this), + + onFailure: function(request) { + ActiveScaffold.report_500_response(this.scaffold_id()); + } + }); + }, + + enable: function() { + this.set.links.each(function(item) { + if (item.url != this.url) return; + item.tag.removeClassName('disabled'); + }.bind(this)); + }, + + disable: function() { + this.set.links.each(function(item) { + if (item.url != this.url) return; + item.tag.addClassName('disabled'); + }.bind(this)); + } +}); + +/** + * Concrete classes for table actions + */ +ActiveScaffold.Actions.Table = Class.create(); +ActiveScaffold.Actions.Table.prototype = Object.extend(new ActiveScaffold.Actions.Abstract(), { + instantiate_link: function(link) { + var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator); + if (l.position) l.url = l.url.append_params({adapter: '_list_inline_adapter'}); + return l; + } +}); + +ActiveScaffold.ActionLink.Table = Class.create(); +ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.ActionLink.Abstract(), { + insert: function(content) { + if (this.position == 'top') { + new Insertion.Top(this.target, content); + this.adapter = this.target.immediateDescendants().first(); + } + else { + throw 'Unknown position "' + this.position + '"' + } + + this.adapter.down('a.inline-adapter-close').observe('click', this.close_handler.bind(this)); + this.register_cancel_hooks(); + + new Effect.Highlight(this.adapter.down('td')); + }, + + close_handler: function(event) { + this.close(); + if (event) Event.stop(event); + } +}); diff --git a/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js b/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js new file mode 100755 index 0000000000..161417e2e3 --- /dev/null +++ b/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js @@ -0,0 +1,867 @@ +/* +Copyright (c) 2007 Brian Dillard and Brad Neuberg: +Brian Dillard | Project Lead | bdillard@pathf.com | http://blogs.pathf.com/agileajax/ +Brad Neuberg | Original Project Creator | http://codinginparadise.org + +SVN r113 from http://code.google.com/p/reallysimplehistory ++ Changes by Ed Wildgoose - MailASail ++ Changed EncodeURIComponent -> EncodeURI ++ Changed DecodeURIComponent -> DecodeURI ++ Changed 'blank.html?' -> '/blank.html?' + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +/* + dhtmlHistory: An object that provides history, history data, and bookmarking for DHTML and Ajax applications. + + dependencies: + * the historyStorage object included in this file. + +*/ +window.dhtmlHistory = { + + /*Public: User-agent booleans*/ + isIE: false, + isOpera: false, + isSafari: false, + isKonquerer: false, + isGecko: false, + isSupported: false, + + /*Public: Create the DHTML history infrastructure*/ + create: function(options) { + + /* + options - object to store initialization parameters + options.blankURL - string to override the default location of blank.html. Must end in "?" + options.debugMode - boolean that causes hidden form fields to be shown for development purposes. + options.toJSON - function to override default JSON stringifier + options.fromJSON - function to override default JSON parser + options.baseTitle - pattern for title changes; example: "Armchair DJ [@@@]" - @@@ will be replaced + */ + + var that = this; + + /*Set up the historyStorage object; pass in options bundle*/ + window.historyStorage.setup(options); + + /*Set up our base title if one is passed in*/ + if (options && options.baseTitle) { + if (options.baseTitle.indexOf("@@@") < 0 && historyStorage.debugMode) { + throw new Error("Programmer error: options.baseTitle must contain the replacement parameter" + + " '@@@' to be useful."); + } + this.baseTitle = options.baseTitle; + } + + /*set user-agent flags*/ + var UA = navigator.userAgent.toLowerCase(); + var platform = navigator.platform.toLowerCase(); + var vendor = navigator.vendor || ""; + if (vendor === "KDE") { + this.isKonqueror = true; + this.isSupported = false; + } else if (typeof window.opera !== "undefined") { + this.isOpera = true; + this.isSupported = true; + } else if (typeof document.all !== "undefined") { + this.isIE = true; + this.isSupported = true; + } else if (vendor.indexOf("Apple Computer, Inc.") > -1) { + this.isSafari = true; + this.isSupported = (platform.indexOf("mac") > -1); + } else if (UA.indexOf("gecko") != -1) { + this.isGecko = true; + this.isSupported = true; + } + + /*Create Safari/Opera-specific code*/ + if (this.isSafari) { + this.createSafari(); + } else if (this.isOpera) { + this.createOpera(); + } + + /*Get our initial location*/ + var initialHash = this.getCurrentLocation(); + + /*Save it as our current location*/ + this.currentLocation = initialHash; + + /*Now that we have a hash, create IE-specific code*/ + if (this.isIE) { + /*Optionally override the URL of IE's blank HTML file*/ + if (options && options.blankURL) { + var u = options.blankURL; + /*assign the value, adding the trailing ? if it's not passed in*/ + this.blankURL = (u.indexOf("?") != u.length - 1 + ? u + "?" + : u + ); + } + this.createIE(initialHash); + } + + /*Add an unload listener for the page; this is needed for FF 1.5+ because this browser caches all dynamic updates to the + page, which can break some of our logic related to testing whether this is the first instance a page has loaded or whether + it is being pulled from the cache*/ + + var unloadHandler = function() { + that.firstLoad = null; + }; + + this.addEventListener(window,'unload',unloadHandler); + + /*Determine if this is our first page load; for IE, we do this in this.iframeLoaded(), which is fired on pageload. We do it + there because we have no historyStorage at this point, which only exists after the page is finished loading in IE*/ + if (this.isIE) { + /*The iframe will get loaded on page load, and we want to ignore this fact*/ + this.ignoreLocationChange = true; + } else { + if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) { + /*This is our first page load, so ignore the location change and add our special history entry*/ + this.ignoreLocationChange = true; + this.firstLoad = true; + historyStorage.put(this.PAGELOADEDSTRING, true); + } else { + /*This isn't our first page load, so indicate that we want to pay attention to this location change*/ + this.ignoreLocationChange = false; + this.firstLoad = false; + /*For browsers other than IE, fire a history change event; on IE, the event will be thrown automatically when its + hidden iframe reloads on page load. Unfortunately, we don't have any listeners yet; indicate that we want to fire + an event when a listener is added.*/ + this.fireOnNewListener = true; + } + } + + /*Other browsers can use a location handler that checks at regular intervals as their primary mechanism; we use it for IE as + well to handle an important edge case; see checkLocation() for details*/ + var locationHandler = function() { + that.checkLocation(); + }; + setInterval(locationHandler, 100); + }, + + /*Public: Initialize our DHTML history. You must call this after the page is finished loading. Optionally, you can pass your listener in + here so you don't need to make a separate call to addListener*/ + initialize: function(listener) { + + /*save original document title to plug in when we hit a null-key history point*/ + this.originalTitle = document.title; + + /*IE needs to be explicitly initialized. IE doesn't autofill form data until the page is finished loading, so we have to wait*/ + if (this.isIE) { + /*If this is the first time this page has loaded*/ + if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) { + /*For IE, we do this in initialize(); for other browsers, we do it in create()*/ + this.fireOnNewListener = false; + this.firstLoad = true; + historyStorage.put(this.PAGELOADEDSTRING, true); + } + /*Else if this is a fake onload event*/ + else { + this.fireOnNewListener = true; + this.firstLoad = false; + } + } + /*optional convenience to save a separate call to addListener*/ + if (listener) { + this.addListener(listener); + } + }, + + /*Public: Adds a history change listener. Only one listener is supported at this time.*/ + addListener: function(listener) { + this.listener = listener; + /*If the page was just loaded and we should not ignore it, fire an event to our new listener now*/ + if (this.fireOnNewListener) { + this.fireHistoryEvent(this.currentLocation); + this.fireOnNewListener = false; + } + }, + + /*Public: Change the current HTML title*/ + changeTitle: function(historyData) { + var winTitle = (historyData && historyData.newTitle + /*Plug the new title into the pattern*/ + ? this.baseTitle.replace('@@@', historyData.newTitle) + /*Otherwise, if there is no new title, use the original document title. This is useful when some + history changes have title changes and some don't; we can automatically return to the original + title rather than leaving a misleading title in the title bar. The same goes for our "virgin" + (hashless) page state.*/ + : this.originalTitle + ); + /*No need to do anything if the title isn't changing*/ + if (document.title == winTitle) { + return; + } + + + /*Now change the DOM*/ + document.title = winTitle; + /*Change it in the iframe, too, for IE*/ + if (this.isIE) { + this.iframe.contentWindow.document.title = winTitle; + } + + /*If non-IE, reload the hash so the new title "sticks" in the browser history object*/ + if (!this.isIE && !this.isOpera) { + var hash = decodeURI(document.location.hash); + if (hash != "") { + var encodedHash = encodeURI(this.removeHash(hash)); + document.location.hash = encodedHash; + } else { + //document.location.hash = "#"; + } + } + }, + + /*Public: Add a history point. Parameters available: + * newLocation (required): + This will be the #hash value in the URL. Users can bookmark it. It will persist across sessions, so + your application should be able to restore itself to a specific state based on just this value. It + should be either a simple keyword for a viewstate or else a pseudo-querystring. + * historyData (optional): + This is for complex data that is relevant only to the current browsing session. It will be available + to your application until the browser is closed. If the user comes back to a bookmarked history point + during a later session, this data will no longer be available. Don't rely on it for application + re-initialization from a bookmark. + * historyData.newTitle (optional): + This will swap out the html attribute with a new value. If you have set a baseTitle using the + options bundle, the value will be plugged into the baseTitle by swapping out the @@@ replacement param. + */ + add: function(newLocation, historyData) { + + var that = this; + + /*Escape the location and remove any leading hash symbols*/ + var encodedLocation = encodeURI(this.removeHash(newLocation)); + + if (this.isSafari) { + + /*Store the history data into history storage - pass in unencoded newLocation since + historyStorage does its own encoding*/ + historyStorage.put(newLocation, historyData); + + /*Save this as our current location*/ + this.currentLocation = encodedLocation; + + /*Change the browser location*/ + window.location.hash = encodedLocation; + + /*Save this to the Safari form field*/ + this.putSafariState(encodedLocation); + + this.changeTitle(historyData); + + } else { + + /*Most browsers require that we wait a certain amount of time before changing the location, such + as 200 MS; rather than forcing external callers to use window.setTimeout to account for this, + we internally handle it by putting requests in a queue.*/ + var addImpl = function() { + + /*Indicate that the current wait time is now less*/ + if (that.currentWaitTime > 0) { + that.currentWaitTime = that.currentWaitTime - that.waitTime; + } + + /*IE has a strange bug; if the encodedLocation is the same as _any_ preexisting id in the + document, then the history action gets recorded twice; throw a programmer exception if + there is an element with this ID*/ + if (document.getElementById(encodedLocation) && that.debugMode) { + var e = "Exception: History locations can not have the same value as _any_ IDs that might be in the document," + + " due to a bug in IE; please ask the developer to choose a history location that does not match any HTML" + + " IDs in this document. The following ID is already taken and cannot be a location: " + newLocation; + throw new Error(e); + } + + /*Store the history data into history storage - pass in unencoded newLocation since + historyStorage does its own encoding*/ + historyStorage.put(newLocation, historyData); + + /*Indicate to the browser to ignore this upcomming location change since we're making it programmatically*/ + that.ignoreLocationChange = true; + + /*Indicate to IE that this is an atomic location change block*/ + that.ieAtomicLocationChange = true; + + /*Save this as our current location*/ + that.currentLocation = encodedLocation; + + /*Change the browser location*/ + window.location.hash = encodedLocation; + + /*Change the hidden iframe's location if on IE*/ + if (that.isIE) { + that.iframe.src = that.blankURL + encodedLocation; + } + + /*End of atomic location change block for IE*/ + that.ieAtomicLocationChange = false; + + that.changeTitle(historyData); + + }; + + /*Now queue up this add request*/ + window.setTimeout(addImpl, this.currentWaitTime); + + /*Indicate that the next request will have to wait for awhile*/ + this.currentWaitTime = this.currentWaitTime + this.waitTime; + } + }, + + /*Public*/ + isFirstLoad: function() { + return this.firstLoad; + }, + + /*Public*/ + getVersion: function() { + return this.VERSIONNUMBER; + }, + + /*- - - - - - - - - - - -*/ + + /*Private: Constant for our own internal history event called when the page is loaded*/ + PAGELOADEDSTRING: "DhtmlHistory_pageLoaded", + + VERSIONNUMBER: "0.8", + + /* + Private: Pattern for title changes. Example: "Armchair DJ [@@@]" where @@@ will be relaced by values passed to add(); + Default is just the title itself, hence "@@@" + */ + baseTitle: "@@@", + + /*Private: Placeholder variable for the original document title; will be set in ititialize()*/ + originalTitle: null, + + /*Private: URL for the blank html file we use for IE; can be overridden via the options bundle. Otherwise it must be served + in same directory as this library*/ + blankURL: "/blank.html?", + + /*Private: Our history change listener.*/ + listener: null, + + /*Private: MS to wait between add requests - will be reset for certain browsers*/ + waitTime: 200, + + /*Private: MS before an add request can execute*/ + currentWaitTime: 0, + + /*Private: Our current hash location, without the "#" symbol.*/ + currentLocation: null, + + /*Private: Hidden iframe used to IE to detect history changes*/ + iframe: null, + + /*Private: Flags and DOM references used only by Safari*/ + safariHistoryStartPoint: null, + safariStack: null, + safariLength: null, + + /*Private: Flag used to keep checkLocation() from doing anything when it discovers location changes we've made ourselves + programmatically with the add() method. Basically, add() sets this to true. When checkLocation() discovers it's true, + it refrains from firing our listener, then resets the flag to false for next cycle. That way, our listener only gets fired on + history change events triggered by the user via back/forward buttons and manual hash changes. This flag also helps us set up + IE's special iframe-based method of handling history changes.*/ + ignoreLocationChange: null, + + /*Private: A flag that indicates that we should fire a history change event when we are ready, i.e. after we are initialized and + we have a history change listener. This is needed due to an edge case in browsers other than IE; if you leave a page entirely + then return, we must fire this as a history change event. Unfortunately, we have lost all references to listeners from earlier, + because JavaScript clears out.*/ + fireOnNewListener: null, + + /*Private: A variable that indicates whether this is the first time this page has been loaded. If you go to a web page, leave it + for another one, and then return, the page's onload listener fires again. We need a way to differentiate between the first page + load and subsequent ones. This variable works hand in hand with the pageLoaded variable we store into historyStorage.*/ + firstLoad: null, + + /*Private: A variable to handle an important edge case in IE. In IE, if a user manually types an address into their browser's + location bar, we must intercept this by calling checkLocation() at regular intervals. However, if we are programmatically + changing the location bar ourselves using the add() method, we need to ignore these changes in checkLocation(). Unfortunately, + these changes take several lines of code to complete, so for the duration of those lines of code, we set this variable to true. + That signals to checkLocation() to ignore the change-in-progress. Once we're done with our chunk of location-change code in + add(), we set this back to false. We'll do the same thing when capturing user-entered address changes in checkLocation itself.*/ + ieAtomicLocationChange: null, + + /*Private: Generic utility function for attaching events*/ + addEventListener: function(o,e,l) { + if (o.addEventListener) { + o.addEventListener(e,l,false); + } else if (o.attachEvent) { + o.attachEvent('on'+e,function() { + l(window.event); + }); + } + }, + + + /*Private: Create IE-specific DOM nodes and overrides*/ + createIE: function(initialHash) { + /*write out a hidden iframe for IE and set the amount of time to wait between add() requests*/ + this.waitTime = 400;/*IE needs longer between history updates*/ + var styles = (historyStorage.debugMode + ? 'width: 800px;height:80px;border:1px solid black;' + : historyStorage.hideStyles + ); + var iframeID = "rshHistoryFrame"; + var iframeHTML = '<iframe frameborder="0" id="' + iframeID + '" style="' + styles + '" src="' + this.blankURL + initialHash + '"></iframe>'; + document.write(iframeHTML); + this.iframe = document.getElementById(iframeID); + }, + + /*Private: Create Opera-specific DOM nodes and overrides*/ + createOpera: function() { + this.waitTime = 400;/*Opera needs longer between history updates*/ + var imgHTML = '<img src="javascript:location.href=\'javascript:dhtmlHistory.checkLocation();\';" style="' + historyStorage.hideStyles + '" />'; + document.write(imgHTML); + }, + + /*Private: Create Safari-specific DOM nodes and overrides*/ + createSafari: function() { + var formID = "rshSafariForm"; + var stackID = "rshSafariStack"; + var lengthID = "rshSafariLength"; + var formStyles = historyStorage.debugMode ? historyStorage.showStyles : historyStorage.hideStyles; + var stackStyles = (historyStorage.debugMode + ? 'width: 800px;height:80px;border:1px solid black;' + : historyStorage.hideStyles + ); + var lengthStyles = (historyStorage.debugMode + ? 'width:800px;height:20px;border:1px solid black;margin:0;padding:0;' + : historyStorage.hideStyles + ); + var safariHTML = '<form id="' + formID + '" style="' + formStyles + '">' + + '<textarea style="' + stackStyles + '" id="' + stackID + '">[]</textarea>' + + '<input type="text" style="' + lengthStyles + '" id="' + lengthID + '" value=""/>' + + '</form>'; + document.write(safariHTML); + this.safariStack = document.getElementById(stackID); + this.safariLength = document.getElementById(lengthID); + if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) { + this.safariHistoryStartPoint = history.length; + this.safariLength.value = this.safariHistoryStartPoint; + } else { + this.safariHistoryStartPoint = this.safariLength.value; + } + }, + + /*TODO: make this public again?*/ + /*Private: Get browser's current hash location; for Safari, read value from a hidden form field*/ + getCurrentLocation: function() { + var r = (this.isSafari + ? this.getSafariState() + : this.getCurrentHash() + ); + return r; + }, + + /*TODO: make this public again?*/ + /*Private: Manually parse the current url for a hash; tip of the hat to YUI*/ + getCurrentHash: function() { + var r = window.location.href; + var i = r.indexOf("#"); + return (i >= 0 + ? r.substr(i+1) + : "" + ); + }, + + /*Private: Safari method to read the history stack from a hidden form field*/ + getSafariStack: function() { + var r = this.safariStack.value; + return historyStorage.fromJSON(r); + }, + /*Private: Safari method to read from the history stack*/ + getSafariState: function() { + var stack = this.getSafariStack(); + var state = stack[history.length - this.safariHistoryStartPoint - 1]; + return state; + }, + /*Private: Safari method to write the history stack to a hidden form field*/ + putSafariState: function(newLocation) { + var stack = this.getSafariStack(); + stack[history.length - this.safariHistoryStartPoint] = newLocation; + this.safariStack.value = historyStorage.toJSON(stack); + }, + + /*Private: Notify the listener of new history changes.*/ + fireHistoryEvent: function(newHash) { + var decodedHash = decodeURI(newHash) + /*extract the value from our history storage for this hash*/ + var historyData = historyStorage.get(decodedHash); + this.changeTitle(historyData); + /*call our listener*/ + this.listener.call(null, decodedHash, historyData); + }, + + /*Private: See if the browser has changed location. This is the primary history mechanism for Firefox. For IE, we use this to + handle an important edge case: if a user manually types in a new hash value into their IE location bar and press enter, we want to + to intercept this and notify any history listener.*/ + checkLocation: function() { + + /*Ignore any location changes that we made ourselves for browsers other than IE*/ + if (!this.isIE && this.ignoreLocationChange) { + this.ignoreLocationChange = false; + return; + } + + /*If we are dealing with IE and we are in the middle of making a location change from an iframe, ignore it*/ + if (!this.isIE && this.ieAtomicLocationChange) { + return; + } + + /*Get hash location*/ + var hash = this.getCurrentLocation(); + + /*Do nothing if there's been no change*/ + if (hash == this.currentLocation) { + return; + } + + /*In IE, users manually entering locations into the browser; we do this by comparing the browser's location against the + iframe's location; if they differ, we are dealing with a manual event and need to place it inside our history, otherwise + we can return*/ + this.ieAtomicLocationChange = true; + + if (this.isIE && this.getIframeHash() != hash) { + this.iframe.src = this.blankURL + hash; + } + else if (this.isIE) { + /*the iframe is unchanged*/ + return; + } + + /*Save this new location*/ + this.currentLocation = hash; + + this.ieAtomicLocationChange = false; + + /*Notify listeners of the change*/ + this.fireHistoryEvent(hash); + }, + + /*Private: Get the current location of IE's hidden iframe.*/ + getIframeHash: function() { + var doc = this.iframe.contentWindow.document; + var hash = String(doc.location.search); + if (hash.length == 1 && hash.charAt(0) == "?") { + hash = ""; + } + else if (hash.length >= 2 && hash.charAt(0) == "?") { + hash = hash.substring(1); + } + return hash; + }, + + /*Private: Remove any leading hash that might be on a location.*/ + removeHash: function(hashValue) { + var r; + if (hashValue === null || hashValue === undefined) { + r = null; + } + else if (hashValue === "") { + r = ""; + } + else if (hashValue.length == 1 && hashValue.charAt(0) == "#") { + r = ""; + } + else if (hashValue.length > 1 && hashValue.charAt(0) == "#") { + r = hashValue.substring(1); + } + else { + r = hashValue; + } + return r; + }, + + /*Private: For IE, tell when the hidden iframe has finished loading.*/ + iframeLoaded: function(newLocation) { + /*ignore any location changes that we made ourselves*/ + if (this.ignoreLocationChange) { + this.ignoreLocationChange = false; + return; + } + + /*Get the new location*/ + var hash = String(newLocation.search); + if (hash.length == 1 && hash.charAt(0) == "?") { + hash = ""; + } + else if (hash.length >= 2 && hash.charAt(0) == "?") { + hash = hash.substring(1); + } + /*Keep the browser location bar in sync with the iframe hash*/ + window.location.hash = hash; + + /*Notify listeners of the change*/ + this.fireHistoryEvent(hash); + } + + +}; + +/* + historyStorage: An object that uses a hidden form to store history state across page loads. The mechanism for doing so relies on + the fact that browsers save the text in form data for the life of the browser session, which means the text is still there when + the user navigates back to the page. This object can be used independently of the dhtmlHistory object for caching of Ajax + session information. + + dependencies: + * json2007.js (included in a separate file) or alternate JSON methods passed in through an options bundle. +*/ +window.historyStorage = { + + /*Public: Set up our historyStorage object for use by dhtmlHistory or other objects*/ + setup: function(options) { + + /* + options - object to store initialization parameters - passed in from dhtmlHistory or directly into historyStorage + options.debugMode - boolean that causes hidden form fields to be shown for development purposes. + options.toJSON - function to override default JSON stringifier + options.fromJSON - function to override default JSON parser + */ + + /*process init parameters*/ + if (typeof options !== "undefined") { + if (options.debugMode) { + this.debugMode = options.debugMode; + } + if (options.toJSON) { + this.toJSON = options.toJSON; + } + if (options.fromJSON) { + this.fromJSON = options.fromJSON; + } + } + + /*write a hidden form and textarea into the page; we'll stow our history stack here*/ + var formID = "rshStorageForm"; + var textareaID = "rshStorageField"; + var formStyles = this.debugMode ? historyStorage.showStyles : historyStorage.hideStyles; + var textareaStyles = (historyStorage.debugMode + ? 'width: 800px;height:80px;border:1px solid black;' + : historyStorage.hideStyles + ); + var textareaHTML = '<form id="' + formID + '" style="' + formStyles + '">' + + '<textarea id="' + textareaID + '" style="' + textareaStyles + '"></textarea>' + + '</form>'; + document.write(textareaHTML); + this.storageField = document.getElementById(textareaID); + if (typeof window.opera !== "undefined") { + this.storageField.focus();/*Opera needs to focus this element before persisting values in it*/ + } + }, + + /*Public*/ + put: function(key, value) { + + var encodedKey = encodeURI(key); + + this.assertValidKey(encodedKey); + /*if we already have a value for this, remove the value before adding the new one*/ + if (this.hasKey(key)) { + this.remove(key); + } + /*store this new key*/ + this.storageHash[encodedKey] = value; + /*save and serialize the hashtable into the form*/ + this.saveHashTable(); + }, + + /*Public*/ + get: function(key) { + + var encodedKey = encodeURI(key); + + this.assertValidKey(encodedKey); + /*make sure the hash table has been loaded from the form*/ + this.loadHashTable(); + var value = this.storageHash[encodedKey]; + if (value === undefined) { + value = null; + } + return value; + }, + + /*Public*/ + remove: function(key) { + + var encodedKey = encodeURI(key); + + this.assertValidKey(encodedKey); + /*make sure the hash table has been loaded from the form*/ + this.loadHashTable(); + /*delete the value*/ + delete this.storageHash[encodedKey]; + /*serialize and save the hash table into the form*/ + this.saveHashTable(); + }, + + /*Public: Clears out all saved data.*/ + reset: function() { + this.storageField.value = ""; + this.storageHash = {}; + }, + + /*Public*/ + hasKey: function(key) { + + var encodedKey = encodeURI(key); + + this.assertValidKey(encodedKey); + /*make sure the hash table has been loaded from the form*/ + this.loadHashTable(); + return (typeof this.storageHash[encodedKey] !== "undefined"); + }, + + /*Public*/ + isValidKey: function(key) { + return (typeof key === "string"); + //TODO - should we ban hash signs and other special characters? + }, + + /*- - - - - - - - - - - -*/ + + /*Private - CSS strings utilized by both objects to hide or show behind-the-scenes DOM elements*/ + showStyles: 'border:0;margin:0;padding:0;', + hideStyles: 'left:-1000px;top:-1000px;width:1px;height:1px;border:0;position:absolute;', + + /*Private - debug mode flag*/ + debugMode: false, + + /*Private: Our hash of key name/values.*/ + storageHash: {}, + + /*Private: If true, we have loaded our hash table out of the storage form.*/ + hashLoaded: false, + + /*Private: DOM reference to our history field*/ + storageField: null, + + /*Private: Assert that a key is valid; throw an exception if it not.*/ + assertValidKey: function(key) { + var isValid = this.isValidKey(key); + if (!isValid && this.debugMode) { + throw new Error("Please provide a valid key for window.historyStorage. Invalid key = " + key + "."); + } + }, + + /*Private: Load the hash table up from the form.*/ + loadHashTable: function() { + if (!this.hashLoaded) { + var serializedHashTable = this.storageField.value; + if (serializedHashTable !== "" && serializedHashTable !== null) { + this.storageHash = this.fromJSON(serializedHashTable); + this.hashLoaded = true; + } + } + }, + /*Private: Save the hash table into the form.*/ + saveHashTable: function() { + this.loadHashTable(); + var serializedHashTable = this.toJSON(this.storageHash); + this.storageField.value = serializedHashTable; + }, + /*Private: Bridges for our JSON implementations - both rely on 2007 JSON.org library - can be overridden by options bundle*/ + toJSON: function(o) { + return o.toJSONString(); + }, + fromJSON: function(s) { + return s.parseJSON(); + } +}; + + +/*******************************************************************/ +/** QueryString Object from http://adamv.com/dev/javascript/querystring */ +/* Client-side access to querystring name=value pairs + Version 1.3 + 28 May 2008 + + License (Simplified BSD): + http://adamv.com/dev/javascript/qslicense.txt +*/ +function Querystring(qs) { // optionally pass a querystring to parse + this.params = {}; + + if (qs == null) qs = location.search.substring(1, location.search.length); + if (qs.length == 0) return; + +// Turn <plus> back to <space> +// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1 + qs = qs.replace(/\+/g, ' '); + var args = qs.split('&'); // parse out name/value pairs separated via & + +// split out each name=value pair + for (var i = 0; i < args.length; i++) { + var pair = args[i].split('='); + var name = decodeURI(pair[0]); + + var value = (pair.length==2) + ? decodeURI(pair[1]) + : name; + + this.params[name] = value; + } +} + +Querystring.prototype.get = function(key, default_) { + var value = this.params[key]; + return (value != null) ? value : default_; +} + +Querystring.prototype.contains = function(key) { + var value = this.params[key]; + return (value != null); +} + +/*******************************************************************/ +/* Added by Ed Wildgoose - MailASail */ +/* Initialise the library and add our history callback */ +/*******************************************************************/ +window.dhtmlHistory.create({ + toJSON: function(o) { + return Object.toJSON(o); + } + , fromJSON: function(s) { + return s.evalJSON(); + } + + // Enable this to assist with debugging +// , debugMode: true + + // dhtmlHistory has been modified not to need the next line + // But left in for robustness when updating dhtmlHistory + , blankURL: '/blank.html?' +}); + +/** Our callback to receive history + change events. */ +var handleHistoryChange = function(pageId, pageData) { + if (!pageData) return; + var info = pageId.split(':'); + var id = info[0]; + pageData += '&_method=get'; + new Ajax.Updater(id+'-content', pageData, {asynchronous:true, evalScripts:true, method: 'get', onLoading:function(request){Element.show(id+'-pagination-loading-indicator');}}); +} + +window.onload = function() { + dhtmlHistory.initialize(handleHistoryChange); +}; + diff --git a/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js b/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js new file mode 100644 index 0000000000..cab9997e9c --- /dev/null +++ b/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js @@ -0,0 +1,114 @@ + +// TODO Change to dropping the name property off the input element when in example mode +TextFieldWithExample = Class.create(); +TextFieldWithExample.prototype = { + initialize: function(inputElementId, defaultText, options) { + this.setOptions(options); + + this.input = $(inputElementId); + this.name = this.input.name; + this.defaultText = defaultText; + this.createHiddenInput(); + + this.checkAndShowExample(); + + Event.observe(this.input, "blur", this.onBlur.bindAsEventListener(this)); + Event.observe(this.input, "focus", this.onFocus.bindAsEventListener(this)); + Event.observe(this.input, "select", this.onFocus.bindAsEventListener(this)); + Event.observe(this.input, "keydown", this.onKeyPress.bindAsEventListener(this)); + Event.observe(this.input, "click", this.onClick.bindAsEventListener(this)); + }, + createHiddenInput: function() { + this.hiddenInput = document.createElement("input"); + this.hiddenInput.type = "hidden"; + this.hiddenInput.value = ""; + this.input.parentNode.appendChild(this.hiddenInput); + }, + setOptions: function(options) { + this.options = { exampleClassName: 'example' }; + Object.extend(this.options, options || {}); + }, + onKeyPress: function(event) { + if (!event) var event = window.event; + var code = (event.which) ? event.which : event.keyCode + if (this.isAlphanumeric(code)) { + this.removeExample(); + } + }, + onBlur: function(event) { + this.checkAndShowExample(); + }, + onFocus: function(event) { + if (this.exampleShown()) { + this.removeExample(); + } + }, + onClick: function(event) { + this.removeExample(); + }, + isAlphanumeric: function(keyCode) { + return keyCode >= 40 && keyCode <= 90; + }, + checkAndShowExample: function() { + if (this.input.value == '') { + this.input.value = this.defaultText; + this.input.name = null; + this.hiddenInput.name = this.name; + Element.addClassName(this.input, this.options.exampleClassName); + } + }, + removeExample: function() { + if (this.exampleShown()) { + this.input.value = ''; + this.input.name = this.name; + this.hiddenInput.name = null; + Element.removeClassName(this.input, this.options.exampleClassName); + } + }, + exampleShown: function() { + return Element.hasClassName(this.input, this.options.exampleClassName); + } +} + +Form.disable = function(form) { + var elements = this.getElements(form); + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + try { element.blur(); } catch (e) {} + element.disabled = 'disabled'; + Element.addClassName(element, 'disabled'); + } + } +Form.enable = function(form) { + var elements = this.getElements(form); + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + element.disabled = ''; + Element.removeClassName(element, 'disabled'); + } + } + +DraggableLists = Class.create({ + initialize: function(list) { + list = $(list).addClassName('draggable-list'); + var list_selected = list.cloneNode(false).addClassName('selected'); + list_selected.id += '_seleted'; + list.select('input[type=checkbox]').each(function(item) { + var li = item.up('li'); + li.down('label').htmlFor = null; + new Draggable(li, {revert: 'failure', ghosting: true}); + if (item.checked) list_selected.insert(li.remove()); + }); + list.insert({after: list_selected}); + Droppables.add(list, {hoverclass: 'hover', containment: list_selected.id, onDrop: this.drop_to_list}); + Droppables.add(list_selected, {hoverclass: 'hover', containment: list.id, onDrop: this.drop_to_list}); + list.undoPositioned(); // undo positioned to fix dragging from elements with overflow auto + list_selected.undoPositioned(); + }, + + drop_to_list: function(draggable, droppable, event) { + droppable.insert(draggable.remove()); + draggable.setStyle({left: '0px', top: '0px'}); + draggable.down('input').checked = droppable.hasClassName('selected'); + } +}); diff --git a/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js b/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js new file mode 100644 index 0000000000..e6541f1633 --- /dev/null +++ b/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js @@ -0,0 +1,370 @@ +/** + * + * Copyright 2005 Sabre Airline Solutions + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this + * file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + **/ + + +//-------------------- rico.js +var Rico = { + Version: '1.1.0', + prototypeVersion: parseFloat(Prototype.Version.split(".")[0] + "." + Prototype.Version.split(".")[1]) +} + +//-------------------- ricoColor.js +Rico.Color = Class.create(); + +Rico.Color.prototype = { + + initialize: function(red, green, blue) { + this.rgb = { r: red, g : green, b : blue }; + }, + + blend: function(other) { + this.rgb.r = Math.floor((this.rgb.r + other.rgb.r)/2); + this.rgb.g = Math.floor((this.rgb.g + other.rgb.g)/2); + this.rgb.b = Math.floor((this.rgb.b + other.rgb.b)/2); + }, + + asRGB: function() { + return "rgb(" + this.rgb.r + "," + this.rgb.g + "," + this.rgb.b + ")"; + }, + + asHex: function() { + return "#" + this.rgb.r.toColorPart() + this.rgb.g.toColorPart() + this.rgb.b.toColorPart(); + }, + + asHSB: function() { + return Rico.Color.RGBtoHSB(this.rgb.r, this.rgb.g, this.rgb.b); + }, + + toString: function() { + return this.asHex(); + } + +}; + +Rico.Color.createFromHex = function(hexCode) { + if(hexCode.length==4) { + var shortHexCode = hexCode; + var hexCode = '#'; + for(var i=1;i<4;i++) hexCode += (shortHexCode.charAt(i) + shortHexCode.charAt(i)); + } + if ( hexCode.indexOf('#') == 0 ) + hexCode = hexCode.substring(1); + var red = hexCode.substring(0,2); + var green = hexCode.substring(2,4); + var blue = hexCode.substring(4,6); + return new Rico.Color( parseInt(red,16), parseInt(green,16), parseInt(blue,16) ); +} + +/** + * Factory method for creating a color from the background of + * an HTML element. + */ +Rico.Color.createColorFromBackground = function(elem) { + + //var actualColor = RicoUtil.getElementsComputedStyle($(elem), "backgroundColor", "background-color"); // Changed to prototype style + var actualColor = $(elem).getStyle('backgroundColor'); + + if ( actualColor == "transparent" && elem.parentNode ) + return Rico.Color.createColorFromBackground(elem.parentNode); + + if ( actualColor == null ) + return new Rico.Color(255,255,255); + + if ( actualColor.indexOf("rgb(") == 0 ) { + var colors = actualColor.substring(4, actualColor.length - 1 ); + var colorArray = colors.split(","); + return new Rico.Color( parseInt( colorArray[0] ), + parseInt( colorArray[1] ), + parseInt( colorArray[2] ) ); + + } + else if ( actualColor.indexOf("#") == 0 ) { + return Rico.Color.createFromHex(actualColor); + } + else + return new Rico.Color(255,255,255); +} + +/* next two functions changed to mootools color.js functions */ +Rico.Color.HSBtoRGB = function(hue, saturation, brightness) { + + var br = Math.round(brightness / 100 * 255); + if (this[1] == 0){ + return [br, br, br]; + } else { + var hue = this[0] % 360; + var f = hue % 60; + var p = Math.round((brightness * (100 - saturation)) / 10000 * 255); + var q = Math.round((brightness * (6000 - saturation * f)) / 600000 * 255); + var t = Math.round((brightness * (6000 - saturation * (60 - f))) / 600000 * 255); + switch(Math.floor(hue / 60)){ + case 0: return { r : br, g : t, b : p }; + case 1: return { r : q, g : br, b : p }; + case 2: return { r : p, g : br, b : t }; + case 3: return { r : p, g : q, b : br }; + case 4: return { r : t, g : p, b : br }; + case 5: return { r : br, g : p, b : q }; + } + } + return false; + } + +Rico.Color.RGBtoHSB = function(red, green, blue) { + var hue, saturation, brightness; + var max = Math.max(red, green, blue), min = Math.min(red, green, blue); + var delta = max - min; + brightness = max / 255; + saturation = (max != 0) ? delta / max : 0; + if (saturation == 0){ + hue = 0; + } else { + var rr = (max - red) / delta; + var gr = (max - green) / delta; + var br = (max - blue) / delta; + if (red == max) hue = br - gr; + else if (green == max) hue = 2 + rr - br; + else hue = 4 + gr - rr; + hue /= 6; + if (hue < 0) hue++; + } + return { h : Math.round(hue * 360), s : Math.round(saturation * 100), b : Math.round(brightness * 100)}; +} + + +//-------------------- ricoCorner.js +Rico.Corner = { + + round: function(e, options) { + var e = $(e); + this._setOptions(options); + + var color = this.options.color; + if ( this.options.color == "fromElement" ) + color = this._background(e); + + var bgColor = this.options.bgColor; + if ( this.options.bgColor == "fromParent" ) + bgColor = this._background(e.offsetParent); + + this._roundCornersImpl(e, color, bgColor); + }, + + _roundCornersImpl: function(e, color, bgColor) { + if(this.options.border) + this._renderBorder(e,bgColor); + if(this._isTopRounded()) + this._roundTopCorners(e,color,bgColor); + if(this._isBottomRounded()) + this._roundBottomCorners(e,color,bgColor); + }, + + _renderBorder: function(el,bgColor) { + var borderValue = "1px solid " + this._borderColor(bgColor); + var borderL = "border-left: " + borderValue; + var borderR = "border-right: " + borderValue; + var style = "style='" + borderL + ";" + borderR + "'"; + el.innerHTML = "<div " + style + ">" + el.innerHTML + "</div>" + }, + + _roundTopCorners: function(el, color, bgColor) { + var corner = this._createCorner(bgColor); + for(var i=0 ; i < this.options.numSlices ; i++ ) + corner.appendChild(this._createCornerSlice(color,bgColor,i,"top")); + el.style.paddingTop = 0; + el.insertBefore(corner,el.firstChild); + }, + + _roundBottomCorners: function(el, color, bgColor) { + var corner = this._createCorner(bgColor); + for(var i=(this.options.numSlices-1) ; i >= 0 ; i-- ) + corner.appendChild(this._createCornerSlice(color,bgColor,i,"bottom")); + el.style.paddingBottom = 0; + el.appendChild(corner); + }, + + _createCorner: function(bgColor) { + var corner = document.createElement("div"); + corner.style.backgroundColor = (this._isTransparent() ? "transparent" : bgColor); + return corner; + }, + + _createCornerSlice: function(color,bgColor, n, position) { + var slice = document.createElement("span"); + + var inStyle = slice.style; + inStyle.backgroundColor = color; + inStyle.display = "block"; + inStyle.height = "1px"; + inStyle.overflow = "hidden"; + inStyle.fontSize = "1px"; + + var borderColor = this._borderColor(color,bgColor); + if ( this.options.border && n == 0 ) { + inStyle.borderTopStyle = "solid"; + inStyle.borderTopWidth = "1px"; + inStyle.borderLeftWidth = "0px"; + inStyle.borderRightWidth = "0px"; + inStyle.borderBottomWidth = "0px"; + inStyle.height = "0px"; // assumes css compliant box model + inStyle.borderColor = borderColor; + } + else if(borderColor) { + inStyle.borderColor = borderColor; + inStyle.borderStyle = "solid"; + inStyle.borderWidth = "0px 1px"; + } + + if ( !this.options.compact && (n == (this.options.numSlices-1)) ) + inStyle.height = "2px"; + + this._setMargin(slice, n, position); + this._setBorder(slice, n, position); + return slice; + }, + + _setOptions: function(options) { + this.options = { + corners : "all", + color : "fromElement", + bgColor : "fromParent", + blend : true, + border : false, + compact : false + } + Object.extend(this.options, options || {}); + + this.options.numSlices = this.options.compact ? 2 : 4; + if ( this._isTransparent() ) + this.options.blend = false; + }, + + _whichSideTop: function() { + if ( this._hasString(this.options.corners, "all", "top") ) + return ""; + + if ( this.options.corners.indexOf("tl") >= 0 && this.options.corners.indexOf("tr") >= 0 ) + return ""; + + if (this.options.corners.indexOf("tl") >= 0) + return "left"; + else if (this.options.corners.indexOf("tr") >= 0) + return "right"; + return ""; + }, + + _whichSideBottom: function() { + if ( this._hasString(this.options.corners, "all", "bottom") ) + return ""; + + if ( this.options.corners.indexOf("bl")>=0 && this.options.corners.indexOf("br")>=0 ) + return ""; + + if(this.options.corners.indexOf("bl") >=0) + return "left"; + else if(this.options.corners.indexOf("br")>=0) + return "right"; + return ""; + }, + + _borderColor : function(color,bgColor) { + if ( color == "transparent" ) + return bgColor; + else if ( this.options.border ) + return this.options.border; + else if ( this.options.blend ) + return this._blend( bgColor, color ); + else + return ""; + }, + + + _setMargin: function(el, n, corners) { + var marginSize = this._marginSize(n); + var whichSide = corners == "top" ? this._whichSideTop() : this._whichSideBottom(); + + if ( whichSide == "left" ) { + el.style.marginLeft = marginSize + "px"; el.style.marginRight = "0px"; + } + else if ( whichSide == "right" ) { + el.style.marginRight = marginSize + "px"; el.style.marginLeft = "0px"; + } + else { + el.style.marginLeft = marginSize + "px"; el.style.marginRight = marginSize + "px"; + } + }, + + _setBorder: function(el,n,corners) { + var borderSize = this._borderSize(n); + var whichSide = corners == "top" ? this._whichSideTop() : this._whichSideBottom(); + if ( whichSide == "left" ) { + el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = "0px"; + } + else if ( whichSide == "right" ) { + el.style.borderRightWidth = borderSize + "px"; el.style.borderLeftWidth = "0px"; + } + else { + el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = borderSize + "px"; + } + if (this.options.border != false) + el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = borderSize + "px"; + }, + + _marginSize: function(n) { + if ( this._isTransparent() ) + return 0; + + var marginSizes = [ 5, 3, 2, 1 ]; + var blendedMarginSizes = [ 3, 2, 1, 0 ]; + var compactMarginSizes = [ 2, 1 ]; + var smBlendedMarginSizes = [ 1, 0 ]; + + if ( this.options.compact && this.options.blend ) + return smBlendedMarginSizes[n]; + else if ( this.options.compact ) + return compactMarginSizes[n]; + else if ( this.options.blend ) + return blendedMarginSizes[n]; + else + return marginSizes[n]; + }, + + _borderSize: function(n) { + var transparentBorderSizes = [ 5, 3, 2, 1 ]; + var blendedBorderSizes = [ 2, 1, 1, 1 ]; + var compactBorderSizes = [ 1, 0 ]; + var actualBorderSizes = [ 0, 2, 0, 0 ]; + + if ( this.options.compact && (this.options.blend || this._isTransparent()) ) + return 1; + else if ( this.options.compact ) + return compactBorderSizes[n]; + else if ( this.options.blend ) + return blendedBorderSizes[n]; + else if ( this.options.border ) + return actualBorderSizes[n]; + else if ( this._isTransparent() ) + return transparentBorderSizes[n]; + return 0; + }, + + _hasString: function(str) { for(var i=1 ; i<arguments.length ; i++) if (str.indexOf(arguments[i]) >= 0) return true; return false; }, + _blend: function(c1, c2) { var cc1 = Rico.Color.createFromHex(c1); cc1.blend(Rico.Color.createFromHex(c2)); return cc1; }, + _background: function(el) { try { return Rico.Color.createColorFromBackground(el).asHex(); } catch(err) { return "#ffffff"; } }, + _isTransparent: function() { return this.options.color == "transparent"; }, + _isTopRounded: function() { return this._hasString(this.options.corners, "all", "top", "tl", "tr"); }, + _isBottomRounded: function() { return this._hasString(this.options.corners, "all", "bottom", "bl", "br"); }, + _hasSingleTextChild: function(el) { return el.childNodes.length == 1 && el.childNodes[0].nodeType == 3; } +} + diff --git a/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT b/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT new file mode 100644 index 0000000000..c5e44a354f --- /dev/null +++ b/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT @@ -0,0 +1,2 @@ +Any changes made to files in sub-folders will be lost. +See http://activescaffold.com/tutorials/faq#custom-css. diff --git a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css new file mode 100644 index 0000000000..d8759cfc9a --- /dev/null +++ b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css @@ -0,0 +1,35 @@ +/* IE hacks + ==================================== */ + +* html .active-scaffold-header, +.active-scaffold li.form-element, +.active-scaffold li.sub-section { +zoom: 1; +} + +* html .active-scaffold td .messages-container { +border-top: solid 1px #DAFFCD; +} + +.active-scaffold-header div.actions a.show_search { +background-image: none; +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/active_scaffold/default/magnifier.png', sizingMethod='crop'); +} + +.active-scaffold .sub-form .association-record a.destroy { +background-image: none; +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/active_scaffold/default/cross.png', sizingMethod='crop'); +} + +.active-scaffold-header div.actions a.disabled { +filter: alpha(opacity=50); +} + +.active-scaffold .show-view dd, +.active-scaffold li.form-element dd { +float: none; +} + +.active-scaffold li.form-element dt { +padding: 4px 0; +} \ No newline at end of file diff --git a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css new file mode 100644 index 0000000000..a8804a6518 --- /dev/null +++ b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css @@ -0,0 +1,822 @@ +/* + ActiveScaffold + (c) 2007 Richard White <rrwhite@gmail.com> + + ActiveScaffold is freely distributable under the terms of an MIT-style license. + + For details, see the ActiveScaffold web site: http://www.activescaffold.com/ +*/ + +.active-scaffold form, +.active-scaffold table, +.active-scaffold p, +.active-scaffold div, +.active-scaffold fieldset { +margin: 0; +padding: 0; +} + +.active-scaffold { +margin: 5px 0; +} + +.active-scaffold table { +width: 100%; +border-collapse: separate; +} + +.active-scaffold a, +.active-scaffold a:visited { +color: #06c; +text-decoration: none; +} + +.active-scaffold a.disabled { +color: #999; +} + +.active-scaffold a:hover { +background-color: #ff8; +} + +.active-scaffold .clear-fix { +clear: both; +} + +noscript.active-scaffold { +border-left: solid 5px #f66; +background-color: #fbb; +font-size: 11px; +font-weight: bold; +padding: 5px 20px 5px 5px; +color: #333; +} + +/* Header + ======================== */ + +.active-scaffold-header { +position: relative; +} + +.blue-theme .active-scaffold-header { +background-color: #005CB8; +} + +.active-scaffold-header h2 { +padding: 2px 0px; +margin: 0; +color: #555; +font: bold 160% arial, sans-serif; +} + +.blue-theme .active-scaffold-header h2 { +color: #fff; +padding: 2px 5px 4px 5px; +} + +.active-scaffold-header div.actions a { +float: right; +font: bold 14px arial; +letter-spacing: -1px; +text-decoration: none; +padding: 1px 2px; +white-space: nowrap; +margin-left: 5px; +background-position: 1px 50%; +background-repeat: no-repeat; +} + +.view .active-scaffold-header div.actions a { +float: left; +} + +.blue-theme .active-scaffold-header div.actions a { +color: #fff; +} + +.active-scaffold-header div.actions a.disabled { +color: #666; +opacity: 0.5; +} + +.blue-theme .active-scaffold-header div.actions a.disabled { +color: #fff; +opacity: 0.5; +} + +.active-scaffold-header div.actions a.new, +.active-scaffold-header div.actions a.new_existing, +.active-scaffold-header div.actions a.show_search { +padding-left: 19px; +background-position: 1px 50%; +background-repeat: no-repeat; +} + +.active-scaffold-header div.actions a.new, +.active-scaffold-header div.actions a.new_existing { +background-image: url(../../../images/active_scaffold/default/add.gif); +} + +.active-scaffold-header div.actions a.show_search { +background-image: url(../../../images/active_scaffold/default/magnifier.png); +} + +.blue-theme .active-scaffold-header div.actions a:hover { +background-color: #378CDF; +} + +.active-scaffold-header div.actions a.disabled:hover { +background-color: transparent; +cursor: default; +} + +.active-scaffold-header div.actions { +position: absolute; +right: 5px; +top: 5px; +text-align: right; +} + +/* Table :: Column Headers + ============================= */ + +.active-scaffold th { +background-color: #555; +text-align: left; +} + +.active-scaffold th a, +.active-scaffold th p { +font: bold 11px arial, sans-serif; +display: block; +background-color: #555; +} + +.active-scaffold th a, .active-scaffold th a:visited { +color: #fff; +padding: 2px 15px 2px 5px; +} + +.active-scaffold th p { +color: #eee; +padding: 2px 5px; +} + +.active-scaffold th a:hover { +background-color: #000; +color: #ff8; +} + +.active-scaffold th.sorted { +background-color: #333; +} + +.active-scaffold th.asc a, +.active-scaffold th.asc a:hover { +background: #333 url(../../../images/active_scaffold/default/arrow_up.gif) right 50% no-repeat; +} + +.active-scaffold th.desc a, +.active-scaffold th.desc a:hover { +background: #333 url(../../../images/active_scaffold/default/arrow_down.gif) right 50% no-repeat; +} + +.active-scaffold th.loading a, +.active-scaffold th.loading a:hover { +background: #333 url(../../../images/active_scaffold/default/indicator-small.gif) right 50% no-repeat; +} + +/* Table :: Record Rows + ============================= */ + +.active-scaffold tr.record td { +padding: 5px 4px; +color: #333; +font-family: Verdana, sans-serif; +font-size: 11px; +background-color: #E6F2FF; +border-bottom: solid 1px #C5DBF7; +border-left: solid 1px #C5DBF7; +} + +.active-scaffold tr.even-record td { +background-color: #fff; +border-left: solid 1px #ddd; +} + +.active-scaffold tr.record td.sorted { +background-color: #B9DCFF; +border-bottom: solid 1px #AFD0F5; +} + +.active-scaffold tr.even-record td.sorted { +background-color: #E6F2FF; +border-bottom: solid 1px #AFD0F5; +} + +.active-scaffold tbody.records td.empty { +color: #999; +text-align: center; +} + +.active-scaffold td.numeric, +.active-scaffold-calculations td { +text-align: right; +} + +/* Table :: Actions (Edit, Delete) + ============================= */ + +.active-scaffold tr.record td.actions { +border-right: solid 1px #ccc; +padding: 0; +min-width: 1%; +} + +.active-scaffold tr.record td.actions table { +float: right; +width: auto; +margin-right: 5px; +} + +.active-scaffold tr.record td.actions table td { +border: none; +text-align: right; +padding: 0 2px; +} + +.active-scaffold tr.record td.actions a { +font: bold 11px verdana, sans-serif; +letter-spacing: -1px; +padding: 2px; +margin: 0 2px; +line-height: 16px; +white-space: nowrap; +} + +/* Table :: Inline Adapter + ============================= */ + +.active-scaffold .view { +background-color: #DAFFCD; +padding: 4px; +border: solid 1px #7FcF00; +} + +.active-scaffold tbody.records td.inline-adapter-cell .view { +border-top: none; +} + +.active-scaffold .before-header td.inline-adapter-cell .view { +border-bottom: none; +} + +.active-scaffold a.inline-adapter-close { +float: right; +text-indent: -4000px; +width: 16px; +height: 17px; +background: url(../../../images/active_scaffold/default/close.gif) 0 0 no-repeat; +} + +/* Nested + ======================== */ + +.blue-theme .active-scaffold .active-scaffold-header, +.blue-theme .active-scaffold .active-scaffold-footer { +background-color: #1F7F00; + +background: transparent; +} + +.active-scaffold .active-scaffold .active-scaffold-header { +margin-right: 15px; +} + +.active-scaffold .active-scaffold .active-scaffold-header h2 { +font-size: 12px; +font-weight: bold; +} + +.blue-theme .active-scaffold .active-scaffold-header h2, +.active-scaffold .active-scaffold .active-scaffold-footer { +color: #444; +} + +.active-scaffold .active-scaffold .active-scaffold-header div.actions { +top: 0px; +right: 0px; +} + +.active-scaffold .active-scaffold .active-scaffold-header div.actions a { +font: bold 11px verdana, sans-serif; +padding: 0 2px 1px 17px; +} + +.blue-theme .active-scaffold .active-scaffold-header div.actions a, +.blue-theme .active-scaffold .active-scaffold-header div.actions a:visited { +color: #06c; +} + +.blue-theme .active-scaffold .active-scaffold-header div.actions a:hover { +background-color: #ff8; +} + +.active-scaffold .active-scaffold td { +background-color: #ECFFE7; +border-bottom: solid 1px #CDF7C5; +border-left: solid 1px #CDF7C5; +} + +.active-scaffold .active-scaffold td.inline-adapter-cell { +background-color: #FFFFBB; +padding: 4px; +border: solid 1px #DDDF37; +border-top: none; +} + +.active-scaffold .active-scaffold .active-scaffold-footer { +font-size: 11px; +} + +/* Footer + ========================== */ + +.active-scaffold-calculations td { +background-color: #eee; +border-top: 2px solid #005CB8; +font: bold 12px arial, sans-serif; +} + +.active-scaffold .active-scaffold-footer { +padding: 3px 0px 2px 0px; +border-bottom: none; +font: bold 12px arial, sans-serif; +} + +.blue-theme .active-scaffold-footer { +background-color: #005CB8; +color: #ccc; +} + +.active-scaffold-footer .active-scaffold-pagination { +float: right; +white-space: nowrap; +margin-right: 5px; +} + +.blue-theme .active-scaffold-footer .active-scaffold-records { +margin-left: 5px; +} + +.active-scaffold-footer a { +text-decoration: none; +letter-spacing: 0; +padding: 0 2px; +margin: 0 -2px; +font: bold 12px arial, sans-serif; +} + +.blue-theme .active-scaffold-footer a, +.blue-theme .active-scaffold-footer a:visited { +color: #fff; +} + +.blue-theme .active-scaffold-footer a:hover { +background-color: #378CDF; +} + +.active-scaffold-footer .next { +margin-left: 0; +padding-left: 5px; +border-left: solid 1px #ccc; +} + +.active-scaffold-footer .previous { +margin-right: 0; +padding-right: 5px; +border-right: solid 1px #ccc; +} + +/* Messages + ========================= */ + +.active-scaffold .messages-container, +.active-scaffold .active-scaffold .messages-container{ +padding: 0; +margin: 0 7px; +border: none; +} + +.active-scaffold .empty-message, .active-scaffold .filtered-message { +background-color: #e8e8e8; +padding: 4px; +text-align: center; +color: #666; +} + +.active-scaffold .message { +font-size: 11px; +font-weight: bold; +padding: 5px 20px 5px 5px; +color: #333; +position: relative; +margin: 2px 7px; +line-height: 12px; +} + +.active-scaffold .message a { +position: absolute; +right: 10px; +top: 4px; +padding: 0; +font: bold 11px verdana, sans-serif; +letter-spacing: -1px; +} + +.active-scaffold .messages-container .message { +margin: 0; +} + +.active-scaffold .error-message { +border-left: solid 5px #f66; +background-color: #fbb; +} + +.active-scaffold .warning-message { +border-left: solid 5px #ff6; +background-color: #ffb; +} + +.active-scaffold .info-message { +border-left: solid 5px #66f; +background-color: #bbf; +} + +/* Error Styling + ========================== */ + +.active-scaffold .errorExplanation { +background-color: #fcc; +margin: 2px 0; +border: solid 1px #f66; +} + +.active-scaffold fieldset { +clear: both; +} + +.active-scaffold .errorExplanation h2 { +padding: 2px 5px; +color: #333; +font-size: 11px; +margin: 0; +letter-spacing: 0; +font-family: Verdana; +background-color: #f66; +} + +.active-scaffold .errorExplanation ul { +margin: 0; +padding: 0 2px 4px 25px; +list-style: disc; +} + +.active-scaffold .errorExplanation p { +font-size: 11px; +padding: 2px 5px; +font-family: Verdana; +margin: 0; +} + +.active-scaffold .errorExplanation ul li { +font: bold 11px verdana; +letter-spacing: -1px; +margin: 0; +padding: 0; +background-color: transparent; +} + +/* Loading Indicators + ============================== */ + +.active-scaffold .loading-indicator { +vertical-align: text-bottom; +width: 16px; +margin: 0; +} + +.active-scaffold .active-scaffold-header .loading-indicator { +margin-bottom: 3px; +} + +/* Show + ============================= */ + +.active-scaffold .show-view dl { +margin-left: 5px; +} + +.active-scaffold .show-view dt { +width: 12em; +float: left; +clear: left; +font: normal 11px verdana, sans-serif; +color: #555; +line-height: 16px; +} + +.active-scaffold .show-view dd { +float: left; +font: bold 14px arial; +padding-left: 5px; +margin-bottom: 5px; +} + +/* Form + ============================== */ + +.active-scaffold .submit { +font-weight: bold; +font-size: 14px; +font-family: Arial, sans-serif; +letter-spacing: 0; +margin: 0; +margin-top: 5px; +} + +.active-scaffold form p { +clear: both; +} + +.active-scaffold fieldset { +border: none; +} + +.active-scaffold h4, +.active-scaffold h5 { +padding: 2px; +margin: 0; +text-transform: none; +color: #1F7F00; +letter-spacing: -1px; +font: bold 16px arial; +} + +.active-scaffold h5 { +padding: 0; +margin: 5px 0 2px 0; +font-size: 14px; +letter-spacing: 0; +} + +.active-scaffold ol { +clear: both; +float: none; +padding: 2px; +margin-left: 5px; +list-style: none; +} + +.active-scaffold p.form-footer { +clear: both; +} + +.active-scaffold a.cancel, +.active-scaffold p.form-footer a { +font: bold 14px arial, sans-serif; +letter-spacing: 0; +} + +/* Form :: Fields + ============================== */ + +.active-scaffold li.form-element { +clear: both; +padding-top: 2px; +} + +.active-scaffold label { +font: normal 11px verdana, sans-serif; +color: #555; +} + +.active-scaffold li.form-element dt { +float: left; +width: 12em; +padding: 6px 0; +} + +.active-scaffold li.form-element dd { +float: left; +} + +.active-scaffold .form dd { +margin: 0; +} + + +.active-scaffold .description { +color: #999; +font-size: 10px; +margin-left: 5px; +} + +.active-scaffold .required label { +font-weight: bold; +} + +.active-scaffold label.example { +font-size: 11px; +font-family: arial; +color: #888; +} + +.active-scaffold input.text-input, +.active-scaffold select { +font: bold 16px arial; +letter-spacing: -1px; +border: solid 1px #1F7F00; +} + +.active-scaffold input.text-input { +padding: 2px; +} + +.active-scaffold .fieldWithErrors input, +.active-scaffold .fieldWithErrors textarea, +.active-scaffold .fieldWithErrors select { +border: solid 1px #f00; +} + +.active-scaffold select { +padding: 1px; +} + +.active-scaffold input.example { +color: #aaa; +} + +.active-scaffold select:focus, +.active-scaffold input.text-input:focus { +background-color: #ffc; +} + +.active-scaffold textarea { +font-family: Arial, sans-serif; +font-size: 12px; +padding: 1px; +border: solid 1px #1F7F00; +} + +.active-scaffold .checkbox-list { +padding-left: 0px; +} + +.active-scaffold .checkbox-list li { +padding-right: 5px; +display: inline; +} + +.active-scaffold .checkbox-list li label { +padding: 0 0 0 2px; +} + +.active-scaffold .draggable-list { +float: left; +width: 300px; +margin-right: 15px; +min-height: 30px; +max-height: 100px; +overflow: auto; +background-color: #FFFF88; +} + +.active-scaffold .draggable-list.hover { +opacity: 0.5; +} + +.active-scaffold .draggable-list.selected { +background-color: #7FCF00; +} + +.active-scaffold .draggable-list li { +display: block; +} + +.active-scaffold .draggable-list input { +display: none; +} + +/* Form :: Sub-Sections + ============================== */ + +.active-scaffold li.sub-section { +clear: left; +padding: 5px 0; +} + +/* Form :: Association Sub-Forms + ============================== */ + +.active-scaffold .sub-form { +float: left; +clear: left; +padding: 5px 0; +padding-left: 5px; +} + +.active-scaffold .sub-form h5 { +margin-left: -5px; +} + +.active-scaffold .sub-form table, +.active-scaffold .sub-form table td { +width: auto; +background: none; +} + +.active-scaffold .sub-form table th { +font: normal 10px verdana, sans-serif; +color: #555; +padding: 0 5px 0 1px; +background: none; +} + +.active-scaffold .horizontal-sub-form td label { +display: none; +} + +.active-scaffold .sub-form .checkbox-list { +padding: 0 2px 2px 2px; +background-color: #fff; +border: solid 1px #1F7F00; +} + +.active-scaffold .sub-form .checkbox-list label { +display: block; +} + +.active-scaffold .sub-form table td { +border: none; +background-color: transparent; +padding: 1px; +vertical-align: top; +color: #999; +} + +.active-scaffold .sub-form .actions { +vertical-align: middle; +background-color: transparent; +clear: left; +} + +.active-scaffold .sub-form .association-record a.destroy { +font-weight: bold; +display: block; +height: 16px; +padding: 0; +width: 16px; +text-indent: -4000px; +background: url(../../../images/active_scaffold/default/cross.png) 0 0 no-repeat; +} + +.active-scaffold .sub-form .locked a.destroy { +display: none; +} + +.active-scaffold .sub-form .association-record a { +font: bold 12px arial; +} + +.active-scaffold .sub-form input.text-input, +.active-scaffold .sub-form select { +letter-spacing: 0; +font: bold 12px arial; +} + +.active-scaffold .sub-form .footer-wrapper { +margin-top: 3px; +margin-right: 10px; +} + +.active-scaffold .sub-form .footer { +color: #999; +padding: 3px 5px; +} + +.active-scaffold .sub-form .footer select, +.active-scaffold .sub-form .footer input { +font-weight: bold; +font-size: 12px; +padding: 0; +} + +.active-scaffold a.visibility-toggle { +font-size: 100%; +} + +.active-scaffold-found { + float:left; +} diff --git a/test/mock_app/vendor/plugins/active_scaffold b/test/mock_app/vendor/plugins/active_scaffold new file mode 120000 index 0000000000..c866b86874 --- /dev/null +++ b/test/mock_app/vendor/plugins/active_scaffold @@ -0,0 +1 @@ +../../../.. \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index 444b311846..d2869337da 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,23 @@ require 'test/unit' -require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb')) +ENV['RAILS_ENV'] = 'test' +ENV['RAILS_ROOT'] ||= File.join(File.dirname(__FILE__), 'mock_app') + +require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb')) + +def load_schema + stdout = $stdout + $stdout = StringIO.new # suppress output while building the schema + load File.join(ENV['RAILS_ROOT'], 'db', 'schema.rb') + $stdout = stdout +end + +def silence_stderr(&block) + stderr = $stderr + $stderr = StringIO.new + yield + $stderr = stderr +end for file in %w[model_stub const_mocker] require File.join(File.dirname(__FILE__), file) From e8ce9fc9dc3aa4326e83b0d629a850676124df3f Mon Sep 17 00:00:00 2001 From: Adam Salter <adam@codebright.net> Date: Tue, 8 Sep 2009 16:01:14 +1000 Subject: [PATCH 0053/2024] - update test filenames for autotest --- test/extensions/{array.rb => array_test.rb} | 0 ...ve_record_permissions.rb => active_record_permissions_test.rb} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename test/extensions/{array.rb => array_test.rb} (100%) rename test/misc/{active_record_permissions.rb => active_record_permissions_test.rb} (100%) diff --git a/test/extensions/array.rb b/test/extensions/array_test.rb similarity index 100% rename from test/extensions/array.rb rename to test/extensions/array_test.rb diff --git a/test/misc/active_record_permissions.rb b/test/misc/active_record_permissions_test.rb similarity index 100% rename from test/misc/active_record_permissions.rb rename to test/misc/active_record_permissions_test.rb From 92036c9d9e1f71d4f442626322ad18cb97c31cbe Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Tue, 8 Sep 2009 09:27:42 +0200 Subject: [PATCH 0054/2024] fix lang test --- test/misc/lang_test.rb | 2 +- test/test_helper.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/misc/lang_test.rb b/test/misc/lang_test.rb index 049ea40e96..07810318be 100644 --- a/test/misc/lang_test.rb +++ b/test/misc/lang_test.rb @@ -9,4 +9,4 @@ def test_localization assert_equal "Dutch", as_(:dutch) assert_equal "Create Test", as_(:create_model, :model => 'Test') end -end \ No newline at end of file +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 444b311846..30dda35d94 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,7 @@ require 'test/unit' require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb')) +I18n.locale = :en for file in %w[model_stub const_mocker] require File.join(File.dirname(__FILE__), file) @@ -10,4 +11,4 @@ def quote_column_name(name) name end -end \ No newline at end of file +end From ac0d78c62d6f28c89c4a91d4fe94481f49c119fd Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Tue, 8 Sep 2009 09:34:53 +0200 Subject: [PATCH 0055/2024] fix finder test --- test/misc/finder_test.rb | 6 +++--- test/model_stub.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index 3be14961ba..a6f5afd3ef 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -30,9 +30,9 @@ def test_create_conditions_for_columns '(LOWER(model_stubs.a) LIKE ? OR LOWER(model_stubs.b) LIKE ?)', '%foo%', '%foo%' ] - assert_equal expected_conditions, ActiveScaffold::Finder.create_conditions_for_columns('foo', columns) + assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns('foo', columns) - assert_equal nil, ActiveScaffold::Finder.create_conditions_for_columns('foo', []) + assert_equal nil, ClassWithFinder.create_conditions_for_columns('foo', []) end def test_build_order_clause @@ -67,4 +67,4 @@ def test_method_sorting collection = [3, 1, 2] assert_equal collection.sort, @klass.send(:sort_collection_by_column, collection, column, 'asc') end -end \ No newline at end of file +end diff --git a/test/model_stub.rb b/test/model_stub.rb index 129b602fd4..32550a6d9e 100644 --- a/test/model_stub.rb +++ b/test/model_stub.rb @@ -22,7 +22,7 @@ def other_models end def self.columns - @columns ||= self.stubbed_columns.map{|c| ActiveRecord::ConnectionAdapters::Column.new(c.to_s, '') } + @columns ||= self.stubbed_columns.map{|c| ActiveRecord::ConnectionAdapters::Column.new(c.to_s, '', 'varchar(255)') } end def self.columns_hash From f7b7feaa75fde3aee5aa77b690ef7c282b6660bf Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Tue, 8 Sep 2009 10:00:46 +0200 Subject: [PATCH 0056/2024] Fix constraint tests --- test/misc/constraints_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/misc/constraints_test.rb b/test/misc/constraints_test.rb index 275c1b66e9..8c98a73912 100644 --- a/test/misc/constraints_test.rb +++ b/test/misc/constraints_test.rb @@ -7,6 +7,7 @@ def self.columns; [ActiveRecord::ConnectionAdapters::Column.new('foo', '')] end def self.table_name to_s.split('::').last.underscore.pluralize end + self.store_full_sti_class = false end ## @@ -56,7 +57,7 @@ class OtherUser < ModelStub class OtherService < ModelStub set_table_name 'services' has_many :other_subscriptions, :class_name => 'ModelStubs::OtherSubscription', :foreign_key => 'service_id' - has_many :other_users, :through => :subscriptions # :class_name and :foreign_key are ignored for :through + has_many :other_users, :through => :other_subscriptions # :class_name and :foreign_key are ignored for :through end class OtherSubscription < ModelStub @@ -174,4 +175,4 @@ def assert_constraint_condition(constraint, condition, message = nil) def config_for(klass) ActiveScaffold::Config::Core.new("model_stubs/#{klass.to_s.underscore.downcase}") end -end \ No newline at end of file +end From 03d0b40992fed09e5b5408cd68d8f7cac77e8619 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Tue, 8 Sep 2009 10:09:17 +0200 Subject: [PATCH 0057/2024] Fix permissions test --- test/misc/active_record_permissions_test.rb | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/misc/active_record_permissions_test.rb b/test/misc/active_record_permissions_test.rb index d5403ac671..0d4aa65cfa 100644 --- a/test/misc/active_record_permissions_test.rb +++ b/test/misc/active_record_permissions_test.rb @@ -74,27 +74,27 @@ def test_method_combinations_with_default_true pass(@model.authorized_for?(:action => :create, :column => :a3), 'aat') fail(@model.authorized_for?(:action => :create, :column => :c2), 'afa') fail(@model.authorized_for?(:action => :create, :column => :b2), 'aff') - fail(@model.authorized_for?(:action => :create, :column => :a2), 'aft') + pass(@model.authorized_for?(:action => :create, :column => :a2), 'aft') pass(@model.authorized_for?(:action => :create, :column => :c1), 'ata') fail(@model.authorized_for?(:action => :create, :column => :b1), 'atf') pass(@model.authorized_for?(:action => :create, :column => :a1), 'att') fail(@model.authorized_for?(:action => :update, :column => :c3), 'faa') fail(@model.authorized_for?(:action => :update, :column => :b3), 'faf') - fail(@model.authorized_for?(:action => :update, :column => :a3), 'fat') + pass(@model.authorized_for?(:action => :update, :column => :a3), 'fat') fail(@model.authorized_for?(:action => :update, :column => :c2), 'ffa') fail(@model.authorized_for?(:action => :update, :column => :b2), 'fff') - fail(@model.authorized_for?(:action => :update, :column => :a2), 'fft') + pass(@model.authorized_for?(:action => :update, :column => :a2), 'fft') fail(@model.authorized_for?(:action => :update, :column => :c1), 'fta') fail(@model.authorized_for?(:action => :update, :column => :b1), 'ftf') - fail(@model.authorized_for?(:action => :update, :column => :a1), 'ftt') + pass(@model.authorized_for?(:action => :update, :column => :a1), 'ftt') pass(@model.authorized_for?(:action => :read, :column => :c3), 'taa') fail(@model.authorized_for?(:action => :read, :column => :b3), 'taf') pass(@model.authorized_for?(:action => :read, :column => :a3), 'tat') fail(@model.authorized_for?(:action => :read, :column => :c2), 'tfa') fail(@model.authorized_for?(:action => :read, :column => :b2), 'tff') - fail(@model.authorized_for?(:action => :read, :column => :a2), 'tft') + pass(@model.authorized_for?(:action => :read, :column => :a2), 'tft') pass(@model.authorized_for?(:action => :read, :column => :c1), 'tta') fail(@model.authorized_for?(:action => :read, :column => :b1), 'ttf') pass(@model.authorized_for?(:action => :read, :column => :a1), 'ttt') @@ -116,27 +116,27 @@ def test_method_combinations_with_default_false pass(@model.authorized_for?(:action => :create, :column => :a3), 'aat') fail(@model.authorized_for?(:action => :create, :column => :c2), 'afa') fail(@model.authorized_for?(:action => :create, :column => :b2), 'aff') - fail(@model.authorized_for?(:action => :create, :column => :a2), 'aft') + pass(@model.authorized_for?(:action => :create, :column => :a2), 'aft') pass(@model.authorized_for?(:action => :create, :column => :c1), 'ata') fail(@model.authorized_for?(:action => :create, :column => :b1), 'atf') pass(@model.authorized_for?(:action => :create, :column => :a1), 'att') fail(@model.authorized_for?(:action => :update, :column => :c3), 'faa') fail(@model.authorized_for?(:action => :update, :column => :b3), 'faf') - fail(@model.authorized_for?(:action => :update, :column => :a3), 'fat') + pass(@model.authorized_for?(:action => :update, :column => :a3), 'fat') fail(@model.authorized_for?(:action => :update, :column => :c2), 'ffa') fail(@model.authorized_for?(:action => :update, :column => :b2), 'fff') - fail(@model.authorized_for?(:action => :update, :column => :a2), 'fft') + pass(@model.authorized_for?(:action => :update, :column => :a2), 'fft') fail(@model.authorized_for?(:action => :update, :column => :c1), 'fta') fail(@model.authorized_for?(:action => :update, :column => :b1), 'ftf') - fail(@model.authorized_for?(:action => :update, :column => :a1), 'ftt') + pass(@model.authorized_for?(:action => :update, :column => :a1), 'ftt') pass(@model.authorized_for?(:action => :read, :column => :c3), 'taa') fail(@model.authorized_for?(:action => :read, :column => :b3), 'taf') pass(@model.authorized_for?(:action => :read, :column => :a3), 'tat') fail(@model.authorized_for?(:action => :read, :column => :c2), 'tfa') fail(@model.authorized_for?(:action => :read, :column => :b2), 'tff') - fail(@model.authorized_for?(:action => :read, :column => :a2), 'tft') + pass(@model.authorized_for?(:action => :read, :column => :a2), 'tft') pass(@model.authorized_for?(:action => :read, :column => :c1), 'tta') fail(@model.authorized_for?(:action => :read, :column => :b1), 'ttf') pass(@model.authorized_for?(:action => :read, :column => :a1), 'ttt') @@ -151,4 +151,4 @@ def pass(value, message = nil) def fail(value, message = nil) assert !value, "#{message} should fail" end -end \ No newline at end of file +end From d67ffaf59d934250eddda6eeefee1d83deea0ee5 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Tue, 8 Sep 2009 10:36:23 +0200 Subject: [PATCH 0058/2024] fix action link test --- test/data_structures/action_link_test.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/data_structures/action_link_test.rb b/test/data_structures/action_link_test.rb index 066d1af302..c92be6158e 100644 --- a/test/data_structures/action_link_test.rb +++ b/test/data_structures/action_link_test.rb @@ -21,10 +21,7 @@ def test_simple_attributes @link.confirm = true assert @link.confirm - @link.label = 'Hello World' - assert_equal 'hello_world_authorized?', @link.security_method - @link.label = 'HelloWorld' - assert_equal 'hello_world_authorized?', @link.security_method + assert_equal 'bar_authorized?', @link.security_method @link.security_method = 'blueberry_pie' assert_equal 'blueberry_pie', @link.security_method @@ -75,4 +72,4 @@ def test_presentation_style assert !@link.popup? assert !@link.page? end -end \ No newline at end of file +end From 8ef7938c631e030429ee06c39e6ffc67f443f557 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Tue, 8 Sep 2009 12:11:55 +0200 Subject: [PATCH 0059/2024] Try to fix config block for ruby 1.9 --- lib/active_scaffold/configurable.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/configurable.rb b/lib/active_scaffold/configurable.rb index 6f470b3fc4..aee4101195 100644 --- a/lib/active_scaffold/configurable.rb +++ b/lib/active_scaffold/configurable.rb @@ -8,7 +8,7 @@ module Configurable def configure(&configuration_block) return unless configuration_block @configuration_binding = configuration_block.binding - ret = instance_eval &configuration_block + ret = instance_exec self, &configuration_block @configuration_binding = nil return ret end @@ -26,4 +26,4 @@ def method_missing(name, *args) end end end -end \ No newline at end of file +end From cc7e0133b136dc27087f4a00428653fad451c483 Mon Sep 17 00:00:00 2001 From: Adam Salter <adam@codebright.net> Date: Wed, 9 Sep 2009 11:22:43 +1000 Subject: [PATCH 0060/2024] fix configurable test ruby1.9 --- test/misc/configurable_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/misc/configurable_test.rb b/test/misc/configurable_test.rb index f21e57acd3..e68e73fca0 100644 --- a/test/misc/configurable_test.rb +++ b/test/misc/configurable_test.rb @@ -39,7 +39,7 @@ def test_instance_configuration # variables assert_equal configurable_class, configurable_class.configure {configurable_class} # constants - assert_equal HELLO, configurable_class.configure {HELLO} + assert_equal ConfigurableTest::HELLO, configurable_class.configure {ConfigurableTest::HELLO} ## ## test extra "localized" block behavior @@ -74,7 +74,7 @@ def test_class_configuration # variables assert_equal ConfigurableClass, ConfigurableClass.configure {ConfigurableClass} # constants - assert_equal HELLO, ConfigurableClass.configure {HELLO} + assert_equal ConfigurableTest::HELLO, ConfigurableClass.configure {ConfigurableTest::HELLO} ## ## test extra "localized" block behavior From 2ca66c19ce0dcb8fc544644ab9b50c325bd29559 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 9 Sep 2009 17:33:48 +0200 Subject: [PATCH 0061/2024] Enable other plugins or bridges to override on_submit --- lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb b/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb index cb3103ef89..49faf316e5 100644 --- a/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb +++ b/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb @@ -1,7 +1,7 @@ module ActiveScaffold - module Helpers + module TinyMceBridge module ViewHelpers - def active_scaffold_includes_with_tiny_mce(*args) + def active_scaffold_includes(*args) tiny_mce_js = javascript_tag(%| var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; ActiveScaffold.ActionLink.Abstract.prototype.close = function() { @@ -11,9 +11,8 @@ def active_scaffold_includes_with_tiny_mce(*args) action_link_close.apply(this); }; |) if using_tiny_mce? - active_scaffold_includes_without_tiny_mce(*args) + (include_tiny_mce_if_needed || '') + (tiny_mce_js || '') + super(*args) + (include_tiny_mce_if_needed || '') + (tiny_mce_js || '') end - alias_method_chain :active_scaffold_includes, :tiny_mce end module FormColumnHelpers @@ -26,12 +25,21 @@ def active_scaffold_input_text_editor(column, options) end def onsubmit - 'tinyMCE.triggerSave();this.select("textarea.mceEditor").each(function(elem) { tinyMCE.execCommand("mceRemoveControl", false, elem.id); });' if using_tiny_mce? + submit_js = 'tinyMCE.triggerSave();this.select("textarea.mceEditor").each(function(elem) { tinyMCE.execCommand("mceRemoveControl", false, elem.id); });' if using_tiny_mce? + [super, submit_js].compact.join ';' end end module SearchColumnHelpers - alias_method :active_scaffold_search_text_editor, :active_scaffold_search_text + def self.included(base) + base.class_eval { alias_method :active_scaffold_search_text_editor, :active_scaffold_search_text } + end end end end + +ActionView::Base.class_eval do + include ActiveScaffold::TinyMceBridge::FormColumnHelpers + include ActiveScaffold::TinyMceBridge::SearchColumnHelpers + include ActiveScaffold::TinyMceBridge::ViewHelpers +end From 1159b2c341fc2aff4b76de8119146a7cab405f52 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 10 Sep 2009 13:06:46 +0200 Subject: [PATCH 0062/2024] Add associations to class attribute in links to nested scaffolds --- lib/active_scaffold.rb | 4 ++-- lib/active_scaffold/config/nested.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 4824e2804c..9b347eb7f5 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -102,7 +102,7 @@ def links_for_associations next unless column.link.nil? and column.autolink if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. - column.set_link('nested', :parameters => {:associations => column.name.to_sym}) #unless column.through_association? + column.set_link('nested', :parameters => {:associations => column.name.to_sym}, :html_options => {:class => column.name}) #unless column.through_association? elsif column.polymorphic_association? # note: we can't create inline forms on singular polymorphic associations column.clear_link @@ -118,7 +118,7 @@ def links_for_associations column.actions_for_association_links.delete :new unless actions.include? :create column.actions_for_association_links.delete :edit unless actions.include? :update column.actions_for_association_links.delete :show unless actions.include? :show - column.set_link(:none, :controller => controller.controller_path, :crud_type => nil) + column.set_link(:none, :controller => controller.controller_path, :crud_type => nil, :html_options => {:class => column.name}) end end end diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index b731156f71..4c1ea49b99 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -18,7 +18,7 @@ def initialize(core_config) # Add a nested ActionLink def add_link(label, models, options = {}) - @core.action_links.add('nested', options.merge(:label => label, :type => :record, :security_method => :nested_authorized?, :position => :after, :parameters => {:associations => models.join(' ')})) + @core.action_links.add('nested', options.merge(:label => label, :type => :record, :security_method => :nested_authorized?, :position => :after, :parameters => {:associations => models.join(' ')}, :html_options => {:class => models.join(' ')})) end # the label for this Nested action. used for the header. From a2c8414f25e8ec1959a7b9ef3b642893da401d48 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 10 Sep 2009 14:50:36 +0200 Subject: [PATCH 0063/2024] Allow to set html_options in add_link call --- lib/active_scaffold/config/nested.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index 4c1ea49b99..7c1c246bdc 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -18,7 +18,10 @@ def initialize(core_config) # Add a nested ActionLink def add_link(label, models, options = {}) - @core.action_links.add('nested', options.merge(:label => label, :type => :record, :security_method => :nested_authorized?, :position => :after, :parameters => {:associations => models.join(' ')}, :html_options => {:class => models.join(' ')})) + options.merge! :label => label, :type => :record, :security_method => :nested_authorized?, :position => :after, :parameters => {:associations => models.join(' ')} + options[:html_options] ||= {} + options[:html_options][:class] = [options[:html_options][:class], models.join(' ')].compact.join(' ') + @core.action_links.add('nested', options) end # the label for this Nested action. used for the header. From 5391f9b7cd40860a5c232334b451d9dc55551cb9 Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Thu, 10 Sep 2009 16:07:31 +0200 Subject: [PATCH 0064/2024] use models default_scope order clause to build default list sorting --- lib/active_scaffold/config/list.rb | 2 +- .../data_structures/sorting.rb | 36 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 2d32409a5a..414f972c71 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -11,7 +11,7 @@ def initialize(core_config) # originates here @sorting = ActiveScaffold::DataStructures::Sorting.new(@core.columns) - @sorting.add @core.model.primary_key, 'ASC' if @core.model.default_scoping.empty? + @sorting.set_default_sorting(@core.model) # inherit from global scope @empty_field_text = self.class.empty_field_text diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index e5af042f55..8ad2ba81e7 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -7,7 +7,15 @@ def initialize(columns) @columns = columns @clauses = [] end - + + def set_default_sorting(model) + if model.default_scoping.last.nil? || model.default_scoping.last[:find].nil? || model.default_scoping.last[:find][:order].nil? + add model.primary_key, 'ASC' + else + set_default_sorting_by_default_scope(model.default_scoping.last[:find][:order]) + end + end + # add a clause to the sorting, assuming the column is sortable def add(column_name, direction = nil) direction ||= 'ASC' @@ -85,5 +93,31 @@ def get_column(name_or_column) def mixed_sorting? sorts_by_method? and sorts_by_sql? end + + def set_default_sorting_by_default_scope(default_scope_order) + default_scope_order.split(',').each do |criterion| + order_parts = criterion.strip.split(' ') + unless order_parts.empty? + add(extract_column_name_in_order_criterion(order_parts), extract_direction_in_order_criterion(order_parts)) + end + end + end + + def extract_column_name_in_order_criterion(criterion_parts) + column_name = criterion_parts.first.split('.').last + if column_name.starts_with?('"') || column_name.starts_with?('`') + column_name[1, (column_name.length - 2)] + else + column_name + end + end + + def extract_direction_in_order_criterion(criterion_parts) + if criterion_parts.last.to_s.upcase == 'DESC' + 'DESC' + else + 'ASC' + end + end end end \ No newline at end of file From 7b0418ed8d88a728b2203783d3463319a217067b Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 11 Sep 2009 10:01:29 +0200 Subject: [PATCH 0065/2024] Rename internal methods and clear sorting before set from default scope --- lib/active_scaffold/data_structures/sorting.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 8ad2ba81e7..78c81cec6e 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -10,9 +10,9 @@ def initialize(columns) def set_default_sorting(model) if model.default_scoping.last.nil? || model.default_scoping.last[:find].nil? || model.default_scoping.last[:find][:order].nil? - add model.primary_key, 'ASC' + set model.primary_key, 'ASC' else - set_default_sorting_by_default_scope(model.default_scoping.last[:find][:order]) + set_sorting_from_order_clause(model.default_scoping.last[:find][:order]) end end @@ -94,12 +94,11 @@ def mixed_sorting? sorts_by_method? and sorts_by_sql? end - def set_default_sorting_by_default_scope(default_scope_order) - default_scope_order.split(',').each do |criterion| + def set_sorting_from_order_clause(order_clause) + clear + order_clause.split(',').each do |criterion| order_parts = criterion.strip.split(' ') - unless order_parts.empty? - add(extract_column_name_in_order_criterion(order_parts), extract_direction_in_order_criterion(order_parts)) - end + add(extract_column_name_in_order_criterion(order_parts), extract_direction_in_order_criterion(order_parts)) unless order_parts.empty? end end @@ -120,4 +119,4 @@ def extract_direction_in_order_criterion(criterion_parts) end end end -end \ No newline at end of file +end From a94286de0968805b425b9da909673354547f6b90 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Mon, 14 Sep 2009 10:22:51 +0200 Subject: [PATCH 0066/2024] Fix always show search with field search --- lib/active_scaffold/actions/list.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 4f6b0d8432..faea0be3db 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -26,9 +26,8 @@ def row def list do_list - if active_scaffold_config.list.always_show_create - do_new - end + do_new if active_scaffold_config.list.always_show_create + @record ||= active_scaffold_config.model.new if active_scaffold_config.list.always_show_search respond_to_action(:list) end From 4b76d00445d158689b650f8f33c19c61433bafa6 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Mon, 14 Sep 2009 10:20:11 +0200 Subject: [PATCH 0067/2024] Add div for error messages when is not loaded by XHR too --- frontends/default/views/_create_form.html.erb | 10 ++++++---- frontends/default/views/_update_form.html.erb | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index 781f35721d..bd9e0480cb 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -29,11 +29,13 @@ end -%> <h4><%= active_scaffold_config.create.label -%></h4> - <% if request.xhr? -%> - <div id="<%= element_messages_id(:action => :create) %>" class="messages-container"><%= error_messages_for :record, :object_name => @record.class.human_name.downcase %></div> - <% else -%> + <div id="<%= element_messages_id(:action => :create) %>" class="messages-container"> +<% if request.xhr? -%> + <%= error_messages_for :record, :object_name => @record.class.human_name.downcase %> +<% else -%> <%= render :partial => 'form_messages' %> - <% end -%> +<% end -%> + </div> <%= render :partial => 'form', :locals => { :columns => active_scaffold_config.create.columns } %> diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index a0b3b6467b..2674c439ae 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -33,11 +33,13 @@ end <h4><%= @record.to_label.nil? ? active_scaffold_config.update.label : as_(:update_model, :model => clean_column_value(@record.to_label)) %></h4> - <% if request.xhr? -%> - <div id="<%= element_messages_id(:action => :update) %>" class="messages-container"><%= error_messages_for :record, :object_name => @record.class.human_name.downcase %></div> - <% else -%> + <div id="<%= element_messages_id(:action => :update) %>" class="messages-container"> +<% if request.xhr? -%> + <%= error_messages_for :record, :object_name => @record.class.human_name.downcase %> +<% else -%> <%= render :partial => 'form_messages' %> - <% end -%> +<% end -%> + </div> <%= render :partial => 'form', :locals => { :columns => active_scaffold_config.update.columns } %> From 4313eb1c6145526d90cb09cf82e293b48c4abfb3 Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Mon, 14 Sep 2009 17:25:38 +0200 Subject: [PATCH 0068/2024] do not add primary key default sorting in case table has not primary key, eg. hbtm tables --- lib/active_scaffold/data_structures/sorting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 78c81cec6e..483ecb2947 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -10,7 +10,7 @@ def initialize(columns) def set_default_sorting(model) if model.default_scoping.last.nil? || model.default_scoping.last[:find].nil? || model.default_scoping.last[:find][:order].nil? - set model.primary_key, 'ASC' + set(model.primary_key, 'ASC') if model.column_names.include?(model.primary_key) else set_sorting_from_order_clause(model.default_scoping.last[:find][:order]) end From 15a3c001efe6de2819b03970a329ae06c646b0a6 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 16 Sep 2009 12:51:30 +0200 Subject: [PATCH 0069/2024] delete blank.html on uninstall --- uninstall.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uninstall.rb b/uninstall.rb index 7690558f2a..8f1e37b4d9 100644 --- a/uninstall.rb +++ b/uninstall.rb @@ -9,4 +9,5 @@ [ :stylesheets, :javascripts, :images].each do |asset_type| path = File.join(directory, "../../../public/#{asset_type}/active_scaffold") FileUtils.rm_r(path) -end \ No newline at end of file +end +FileUtils.rm(File.join(directory, "../../../public/blank.html") From bde80647b7cfa431a8fad6d62ce067e0958ae059 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 17 Sep 2009 16:59:21 +0200 Subject: [PATCH 0070/2024] Remove id from cancel links --- frontends/default/views/_create_form.html.erb | 2 +- frontends/default/views/_show.html.erb | 2 +- frontends/default/views/_update_form.html.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index bd9e0480cb..5f6c16f840 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -41,7 +41,7 @@ end -%> <p class="form-footer"> <%= submit_tag as_(:create), :class => "submit" %> - <%= link_to as_(:cancel), params_for(:controller => params[:parent_controller] ? params[:parent_controller] : params[:controller], :action => 'list', :eid => params[:parent_controller] ? params[:parent_controller] : params[:eid]), :class => 'cancel' %> + <%= link_to as_(:cancel), params_for(:controller => params[:parent_controller] ? params[:parent_controller] : params[:controller], :action => 'list', :eid => params[:parent_controller] ? params[:parent_controller] : params[:eid], :id => nil), :class => 'cancel' %> <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> </p> diff --git a/frontends/default/views/_show.html.erb b/frontends/default/views/_show.html.erb index 1c8146ad8c..4bdb2f8475 100644 --- a/frontends/default/views/_show.html.erb +++ b/frontends/default/views/_show.html.erb @@ -3,6 +3,6 @@ <%= render :partial => 'show_columns', :locals => {:columns => active_scaffold_config.show.columns} -%> <p class="form-footer"> - <%= link_to as_(:close), params_for(:controller => params[:parent_controller] ? params[:parent_controller] : params[:controller], :action => 'list'), :class => 'cancel' %> + <%= link_to as_(:close), params_for(:controller => params[:parent_controller] ? params[:parent_controller] : params[:controller], :action => 'list', :id => nil), :class => 'cancel' %> <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> </p> \ No newline at end of file diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index 2674c439ae..c8c45a4230 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -45,7 +45,7 @@ end <p class="form-footer"> <%= submit_tag as_(:update), :class => "submit" %> - <%= link_to as_(:cancel), params_for(:controller => params[:parent_controller] ? params[:parent_controller] : params[:controller], :action => 'list'), :class => 'cancel' %> + <%= link_to as_(:cancel), params_for(:controller => params[:parent_controller] ? params[:parent_controller] : params[:controller], :action => 'list', :id => nil), :class => 'cancel' %> <%= loading_indicator_tag(:action => :update, :id => params[:id]) %> </p> From cf1b42b03d194a58fb848bd4284ba087133de266 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 18 Sep 2009 09:23:49 +0200 Subject: [PATCH 0071/2024] Fix issue 495 --- lib/active_scaffold/actions/nested.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 844e4daf82..fd6e7359a1 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -84,10 +84,9 @@ module ChildMethods def self.included(base) super - # This .verify method call is clashing with other non .add_existing actions. How do we do this correctly? Can we make it action specific. - # base.verify :method => :post, - # :only => :add_existing, - # :redirect_to => { :action => :index } + base.verify :method => :post, + :only => :add_existing, + :redirect_to => { :action => :index } end def new_existing From 4dcef6d830b3201711ae5b3d2c193a19a31924fd Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 18 Sep 2009 10:05:51 +0200 Subject: [PATCH 0072/2024] Validate some HTML --- lib/active_scaffold/helpers/id_helpers.rb | 6 +++++- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index 3c4c6a1b54..2d8de32dbc 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -2,8 +2,12 @@ module ActiveScaffold module Helpers # A bunch of helper methods to produce the common view ids module IdHelpers + def id_from_controller(controller) + controller.gsub("/", "__") + end + def controller_id - @controller_id ||= 'as_' + (params[:eid] || params[:parent_controller] || params[:controller]).gsub("/", "__") + @controller_id ||= 'as_' + id_from_controller(params[:eid] || params[:parent_controller] || params[:controller]) end def active_scaffold_id diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 4d56b7dbeb..89c88ddf51 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -157,7 +157,7 @@ def render_action_link(link, url_options) html_options[:position] = link.position if link.position and link.inline? html_options[:class] += ' action' if link.inline? html_options[:popup] = true if link.popup? - html_options[:id] = action_link_id("#{url_options[:parent_controller] + '_' if url_options[:parent_controller]}" + url_options[:action],url_options[:id] || url_options[:parent_id]) + html_options[:id] = action_link_id("#{id_from_controller(url_options[:controller]) + '_' if url_options[:controller]}" + url_options[:action],url_options[:id] || url_options[:parent_id]) if link.dhtml_confirm? html_options[:class] += ' action' if !link.inline? From ab72688b511625b3883c89b82294a8e4686c36e4 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Mon, 21 Sep 2009 11:26:13 +0200 Subject: [PATCH 0073/2024] Fix issue #701 and really validate HTML for nested action links. --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 89c88ddf51..66d7c9110d 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -157,7 +157,7 @@ def render_action_link(link, url_options) html_options[:position] = link.position if link.position and link.inline? html_options[:class] += ' action' if link.inline? html_options[:popup] = true if link.popup? - html_options[:id] = action_link_id("#{id_from_controller(url_options[:controller]) + '_' if url_options[:controller]}" + url_options[:action],url_options[:id] || url_options[:parent_id]) + html_options[:id] = action_link_id("#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}" + "#{url_options[:associations].to_s + '-' if url_options[:associations]}" + url_options[:action],url_options[:id] || url_options[:parent_id]) if link.dhtml_confirm? html_options[:class] += ' action' if !link.inline? From a20fde41f8390bdadd699396b46e4e2290262c25 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 23 Sep 2009 10:01:38 +0200 Subject: [PATCH 0074/2024] Fix activescaffold config inheritance --- lib/active_scaffold.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 9b347eb7f5..18728ccc24 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -136,15 +136,19 @@ def add_active_scaffold_override_path(path) def active_scaffold_paths return @active_scaffold_paths unless @active_scaffold_paths.nil? - @active_scaffold_paths = ActionView::PathSet.new - @active_scaffold_paths.concat @active_scaffold_overrides unless @active_scaffold_overrides.nil? - @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil? - @active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil? - @active_scaffold_paths + if @active_scaffold_config + @active_scaffold_paths = ActionView::PathSet.new + @active_scaffold_paths.concat @active_scaffold_overrides unless @active_scaffold_overrides.nil? + @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil? + @active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil? + @active_scaffold_paths + elsif uses_active_scaffold? # superclass is using active_scaffold + self.superclass.active_scaffold_paths + end end def active_scaffold_config - @active_scaffold_config || self.superclass.instance_variable_get('@active_scaffold_config') + @active_scaffold_config || self.superclass.active_scaffold_config end def active_scaffold_config_for(klass) From 6e2a139728e3aa26f58655da800d3783d8ca7bf9 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 23 Sep 2009 10:50:32 +0200 Subject: [PATCH 0075/2024] Don't share configuration with children, configure using the same block --- lib/active_scaffold.rb | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 18728ccc24..724016304f 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -55,6 +55,7 @@ def active_scaffold(model_id = nil, &block) # run the configuration @active_scaffold_config = ActiveScaffold::Config::Core.new(model_id) + @active_scaffold_config_block = block self.active_scaffold_config.configure &block if block_given? self.active_scaffold_config._load_action_columns self.links_for_associations @@ -136,19 +137,23 @@ def add_active_scaffold_override_path(path) def active_scaffold_paths return @active_scaffold_paths unless @active_scaffold_paths.nil? - if @active_scaffold_config - @active_scaffold_paths = ActionView::PathSet.new - @active_scaffold_paths.concat @active_scaffold_overrides unless @active_scaffold_overrides.nil? - @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil? - @active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil? - @active_scaffold_paths - elsif uses_active_scaffold? # superclass is using active_scaffold - self.superclass.active_scaffold_paths - end + @active_scaffold_paths = ActionView::PathSet.new + @active_scaffold_paths.concat @active_scaffold_overrides unless @active_scaffold_overrides.nil? + @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil? + @active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil? + @active_scaffold_paths end def active_scaffold_config - @active_scaffold_config || self.superclass.active_scaffold_config + if @active_scaffold_config.nil? + config = self.superclass.active_scaffold_config if self.superclass.respond_to? :active_scaffold_config + self.active_scaffold config.model, &active_scaffold_config_block unless config.nil? + end + @active_scaffold_config + end + + def active_scaffold_config_block + @active_scaffold_config_block || self.superclass.instance_variable_get(:@active_scaffold_config_block) end def active_scaffold_config_for(klass) From dde75827a065d3303b9ada70b9c825c3ad5ccf74 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 23 Sep 2009 11:32:20 +0200 Subject: [PATCH 0076/2024] Little improvement for STI support, thanks to vhochstein --- lib/active_scaffold/actions/create.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index c4bc5b9b90..1e9384e6e9 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -89,7 +89,7 @@ def constraints_for_nested_create # A simple method to find and prepare an example new record for the form # May be overridden to customize the behavior (add default values, for instance) def do_new - @record = active_scaffold_config.model.new + @record = new_model apply_constraints_to_record(@record) params[:eid] = @old_eid if @remove_eid @record @@ -100,7 +100,7 @@ def do_new def do_create begin active_scaffold_config.model.transaction do - @record = update_record_from_params(active_scaffold_config.model.new, active_scaffold_config.create.columns, params[:record]) + @record = update_record_from_params(new_model, active_scaffold_config.create.columns, params[:record]) apply_constraints_to_record(@record, :allow_autosave => true) params[:eid] = @old_eid if @remove_eid before_create_save(@record) @@ -114,6 +114,16 @@ def do_create end end + def new_model + model = active_scaffold_config.model + if model.columns_hash[model.inheritance_column] + params = self.params # in new action inheritance_column must be in params + params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key + model = params[model.inheritance_column].camelize.constantize if params[model.inheritance_column] + end + model.new + end + # override this method if you want to inject data in the record (or its associated objects) before the save def before_create_save(record); end From 2b2fb34faed10868ccfdadb89d25ffdf2065b49c Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 23 Sep 2009 13:14:46 +0200 Subject: [PATCH 0077/2024] Improve STI support, thanks to vhochstein --- lib/active_scaffold.rb | 2 + lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/config/core.rb | 50 +++++++++++++++++++ lib/active_scaffold/data_structures/column.rb | 2 +- .../helpers/controller_helpers.rb | 2 +- .../helpers/form_column_helpers.rb | 2 +- 6 files changed, 56 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 724016304f..4ce56bbd95 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -57,6 +57,7 @@ def active_scaffold(model_id = nil, &block) @active_scaffold_config = ActiveScaffold::Config::Core.new(model_id) @active_scaffold_config_block = block self.active_scaffold_config.configure &block if block_given? + self.active_scaffold_config._configure_sti unless self.active_scaffold_config.sti_children.nil? self.active_scaffold_config._load_action_columns self.links_for_associations @@ -94,6 +95,7 @@ def active_scaffold(model_id = nil, &block) end end end + self.active_scaffold_config._add_sti_create_links if self.active_scaffold_config.add_sti_create_links? end # Create the automatic column links. Note that this has to happen when configuration is *done*, because otherwise the Nested module could be disabled. Actually, it could still be disabled later, couldn't it? diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 1e9384e6e9..c6852c869c 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -119,7 +119,7 @@ def new_model if model.columns_hash[model.inheritance_column] params = self.params # in new action inheritance_column must be in params params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key - model = params[model.inheritance_column].camelize.constantize if params[model.inheritance_column] + model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column] end model.new end diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index 9d681fcc19..a70921f8ac 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -54,6 +54,9 @@ def self.ignore_columns=(val) end @@ignore_columns = ActiveScaffold::DataStructures::Set.new + # lets you specify whether add a create link for each sti child + cattr_accessor :sti_create_links + # instance-level configuration # ---------------------------- @@ -77,6 +80,12 @@ def columns=(val) # lets you override the global ActiveScaffold theme for a specific controller attr_accessor :theme + # lets you specify whether add a create link for each sti child for a specific controller + attr_accessor :sti_create_links + def add_sti_create_links? + self.sti_create_links and not self.sti_children.nil? + end + # action links are used by actions to tie together. they appear as links for each record, or general links for the ActiveScaffold. attr_reader :action_links @@ -86,6 +95,10 @@ def label(options={}) as_(@label, options) || model.human_name(options.merge(options[:count].to_i == 1 ? {} : {:default => model.name.pluralize})) end + # STI children models, use an array of model names if you don't need specific configuration + # FIXME: use a hash with model names as keys with specific configuration + attr_accessor :sti_children + ## ## internal usage only below this point ## ------------------------------------ @@ -110,6 +123,7 @@ def initialize(model_id) # inherit the global frontend @frontend = self.class.frontend @theme = self.class.theme + @sti_create_links = self.class.sti_create_links # inherit from the global set of action links @action_links = self.class.action_links.clone @@ -127,6 +141,34 @@ def _load_action_columns end end + # To be called after your finished configuration + def _configure_sti + column = self.model.inheritance_column + if sti_create_links + self.columns[column].form_ui ||= :hidden + else + self.columns[column].form_ui ||= :select + self.columns[column].options ||= {} + self.columns[column].options[:options] = self.sti_children_models.collect do |model_name| + [model_name.to_s.camelize.constantize.human_name, model_name.to_s.camelize] + end + end + end + + # To be called after include action modules + def _add_sti_create_links + new_action_link = @action_links['new'] + unless new_action_link.nil? + @action_links.delete('new') + self.sti_children_models.each do |child| + new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone + new_sti_link.label = as_(:create_model, :model => child.to_s.camelize.constantize.human_name) + new_sti_link.parameters = {model.inheritance_column => child} + @action_links.add(new_sti_link) + end + end + end + # configuration routing. # we want to route calls named like an activated action to that action's global or local Config class. # --------------------------- @@ -163,6 +205,14 @@ def model @model ||= @model_id.to_s.camelize.constantize end + def sti_children_models + if self.sti_children.is_a? Hash + self.sti_children.keys + else + self.sti_children + end + end + # warning - this won't work as a per-request dynamic attribute in rails 2.0. You'll need to interact with Controller#generic_view_paths def inherited_view_paths @inherited_view_paths||=[] diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 9de97a34f4..395549e454 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -102,7 +102,7 @@ def ui_type=(val) # a place to store dev's column specific options attr_accessor :options def options - @options || {} + @options ||= {} end # associate an action_link with this column diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index c9e8123306..cefac09f60 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -12,7 +12,7 @@ def params_for(options = {}) # :sort, :sort_direction, and :page are arguments that stored in the session. they need not propagate. # and wow. no we don't want to propagate :record. # :commit is a special rails variable for form buttons - blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method] + blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token] unless @params_for @params_for = params.clone.delete_if { |key, value| blacklist.include? key.to_sym if key } @params_for[:controller] = '/' + @params_for[:controller] unless @params_for[:controller].first(1) == '/' # for namespaced controllers diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 8711428a84..9b96fcfd4c 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -272,7 +272,7 @@ def subform_partial_for_column(column) def column_renders_as(column) if column.is_a? ActiveScaffold::DataStructures::ActionColumns return :subsection - elsif column.active_record_class.locking_column.to_s == column.name.to_s + elsif column.active_record_class.locking_column.to_s == column.name.to_s or column.form_ui == :hidden return :hidden elsif column.association.nil? or column.form_ui or !active_scaffold_config_for(column.association.klass).actions.include?(:subform) return :field From 7c43b1743bd7cf65651e2714ef85d2e41aaa3151 Mon Sep 17 00:00:00 2001 From: Kouhei Sutou <kou@clear-code.com> Date: Thu, 24 Sep 2009 13:30:53 +0900 Subject: [PATCH 0078/2024] add Japanese translation. --- lib/active_scaffold/locale/ja.yml | 63 +++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 lib/active_scaffold/locale/ja.yml diff --git a/lib/active_scaffold/locale/ja.yml b/lib/active_scaffold/locale/ja.yml new file mode 100644 index 0000000000..d932c0cba3 --- /dev/null +++ b/lib/active_scaffold/locale/ja.yml @@ -0,0 +1,63 @@ +ja: + active_scaffold: + add: '追加' + add_existing: '既存のものを追加' + add_existing_model: '既存の{{model}}を追加' + are_you_sure: '本当によいですか?' + cancel: 'キャンセル' + click_to_edit: 'クリックして編集' + close: '閉じる' + create: '作成' + create_model: '{{model}}を作成' + create_another: '別のものを作成' + created_model: '{{model}}を作成しました' + create_new: '新規作成' + customize: 'カスタマイズ' + delete: '削除' + deleted_model: '%sを削除しました' + delimiter: 'Delimiter' # needed? + download: 'ダウンロード' + edit: '編集' + export: 'Export' # needed? + nested_for_model: '{{parent_model}}の{{nested_model}}' + filtered: '(フィルタ中)' + found: '個ありました' + hide: '隠す' + live_search: 'その場で検索' + loading: '読み込み中…' + next: '次' + no_entries: '見つかりませんでした' + no_options: 'オプション無し' + omit_header: 'Omit Header' # needed? + options: 'オプション' + pdf: 'PDF' + previous: '前' + print: '印刷' + refresh: 'Refresh' # needed? + remove: '削除' + remove_file: 'ファイルを削除または置換' + replace_with_new: '新しいもので置換' + revisions_for_model: 'Revisions for {{model}}' # neede? + reset: 'リセット' + saving: '保存中…' + search: '検索' + search_terms: '検索単語' + _select_: '- 選択してください -' + show: '表示' + show_model: '{{model}}を表示' + _to_ : ' to ' # needed? + update: '更新' + update_model: '{{model}}を更新' + udated_model: '{{model}}を更新しました' + '=': '=' + '>=': '>=' + '<=': '<=' + '>': '>' + '<': '<' + '!=': '!=' + between: 'Between' # needed? + + # error_messages + cant_destroy_record: "{{record}}を削除で来ません" + internal_error: 'リクエストが失敗しました(コード500: 内部エラー)' + version_inconsistency: 'バージョンが一致しません - あなたが編集している間にこのレコードが変更されました。' From 767085ff224298b75f17e76232928fc6cd5d1827 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 24 Sep 2009 10:09:23 +0200 Subject: [PATCH 0079/2024] Fix create label when sti_create_links is enabled --- frontends/default/views/_create_form.html.erb | 2 +- lib/active_scaffold/config/create.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index 5f6c16f840..2afc73d1c9 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -27,7 +27,7 @@ else :class => 'create' end -%> - <h4><%= active_scaffold_config.create.label -%></h4> + <h4><%= active_scaffold_config.create.label(@record.class.human_name(:count => 1)) -%></h4> <div id="<%= element_messages_id(:action => :create) %>" class="messages-container"> <% if request.xhr? -%> diff --git a/lib/active_scaffold/config/create.rb b/lib/active_scaffold/config/create.rb index c087842e49..73d333c3c0 100644 --- a/lib/active_scaffold/config/create.rb +++ b/lib/active_scaffold/config/create.rb @@ -29,8 +29,9 @@ def self.link=(val) # instance-level configuration # ---------------------------- # the label= method already exists in the Form base class - def label - @label ? as_(@label) : as_(:create_model, :model => @core.label(:count => 1)) + def label(model = nil) + model ||= @core.label(:count => 1) + @label ? as_(@label) : as_(:create_model, :model => model) end # whether the form stays open after a create or not From 1e6d5dd4d1d48c065d89eb4849c29fea2b179bd1 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 25 Sep 2009 11:39:23 +0200 Subject: [PATCH 0080/2024] Cache associated records when eager loading is disabled to reduce sql queries --- .../helpers/list_column_helpers.rb | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 90661d6360..6826eb2dc1 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -21,6 +21,17 @@ def get_column_value(record, column) else value = record.send(column.name) + associated_size = value.size if column.associated_number? # get count before cache association + # we are not using eager loading, cache firsts records in order not to query the database in a future + unless column.association.nil? or value.loaded? + # load at least one record, is needed for column_empty? and checking permissions + if column.associated_limit.nil? + Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries" + else + record.send(column.name).target = value.find(:all, :limit => [column.associated_limit, 1].max) + end + end + if column.association.nil? or column_empty?(value) formatted_value = clean_column_value(format_value(value, column.options)) else @@ -32,19 +43,15 @@ def get_column_value(record, column) if column.associated_limit.nil? firsts = value.collect { |v| v.to_label } else - firsts = if value.loaded? # we are using eager loading, use first in order not to query the database - value.first(column.associated_limit + 1) - else - value.find(:all, :limit => column.associated_limit + 1) - end + firsts = value.first(column.associated_limit) firsts.collect! { |v| v.to_label } - firsts[column.associated_limit] = '…' if firsts.length > column.associated_limit + firsts[column.associated_limit] = '…' if associated_size > column.associated_limit end if column.associated_limit == 0 - formatted_value = value.size if column.associated_number? + formatted_value = associated_size if column.associated_number? else formatted_value = clean_column_value(format_value(firsts.join(', '))) - formatted_value << " (#{value.size})" if column.associated_number? and column.associated_limit and firsts.length > column.associated_limit + formatted_value << " (#{associated_size})" if column.associated_number? and column.associated_limit and associated_size > column.associated_limit end formatted_value end From 385b8c6e0c2e943f17d882aa851df82db5722d37 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 25 Sep 2009 11:41:33 +0200 Subject: [PATCH 0081/2024] cleanup sti support --- lib/active_scaffold/config/core.rb | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index a70921f8ac..efabc59b69 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -95,8 +95,7 @@ def label(options={}) as_(@label, options) || model.human_name(options.merge(options[:count].to_i == 1 ? {} : {:default => model.name.pluralize})) end - # STI children models, use an array of model names if you don't need specific configuration - # FIXME: use a hash with model names as keys with specific configuration + # STI children models, use an array of model names attr_accessor :sti_children ## @@ -149,7 +148,7 @@ def _configure_sti else self.columns[column].form_ui ||= :select self.columns[column].options ||= {} - self.columns[column].options[:options] = self.sti_children_models.collect do |model_name| + self.columns[column].options[:options] = self.sti_children.collect do |model_name| [model_name.to_s.camelize.constantize.human_name, model_name.to_s.camelize] end end @@ -160,7 +159,7 @@ def _add_sti_create_links new_action_link = @action_links['new'] unless new_action_link.nil? @action_links.delete('new') - self.sti_children_models.each do |child| + self.sti_children.each do |child| new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone new_sti_link.label = as_(:create_model, :model => child.to_s.camelize.constantize.human_name) new_sti_link.parameters = {model.inheritance_column => child} @@ -205,14 +204,6 @@ def model @model ||= @model_id.to_s.camelize.constantize end - def sti_children_models - if self.sti_children.is_a? Hash - self.sti_children.keys - else - self.sti_children - end - end - # warning - this won't work as a per-request dynamic attribute in rails 2.0. You'll need to interact with Controller#generic_view_paths def inherited_view_paths @inherited_view_paths||=[] From 5d60328228249869fa59626c679d25127fca1a72 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 25 Sep 2009 12:07:07 +0200 Subject: [PATCH 0082/2024] Improve inheritance support Now active_scaffold method doesn't miss parent's configuration, so you can inherit from a controller which uses active_scaffold, and add a new active_scaffold block, parent's block will be executed first and then own block will be run --- lib/active_scaffold.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 4ce56bbd95..e260bd303f 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -56,6 +56,7 @@ def active_scaffold(model_id = nil, &block) # run the configuration @active_scaffold_config = ActiveScaffold::Config::Core.new(model_id) @active_scaffold_config_block = block + self.active_scaffold_superclasses_blocks.each {|superblock| self.active_scaffold_config.configure &superblock} self.active_scaffold_config.configure &block if block_given? self.active_scaffold_config._configure_sti unless self.active_scaffold_config.sti_children.nil? self.active_scaffold_config._load_action_columns @@ -148,14 +149,24 @@ def active_scaffold_paths def active_scaffold_config if @active_scaffold_config.nil? - config = self.superclass.active_scaffold_config if self.superclass.respond_to? :active_scaffold_config - self.active_scaffold config.model, &active_scaffold_config_block unless config.nil? + self.superclass.active_scaffold_config if self.superclass.respond_to? :active_scaffold_config + else + @active_scaffold_config end - @active_scaffold_config end def active_scaffold_config_block - @active_scaffold_config_block || self.superclass.instance_variable_get(:@active_scaffold_config_block) + @active_scaffold_config_block + end + + def active_scaffold_superclasses_blocks + blocks = [] + klass = self.superclass + while klass.respond_to? :active_scaffold_superclasses_blocks + blocks << klass.active_scaffold_config_block + klass = klass.superclass + end + blocks.compact.reverse end def active_scaffold_config_for(klass) From dbdd190e16b888e6ae4c7bff765ae13626a2e1ec Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 25 Sep 2009 13:35:21 +0200 Subject: [PATCH 0083/2024] Fix last commit, it was broken for singular associations --- .../helpers/list_column_helpers.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 6826eb2dc1..683e88cca9 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -21,14 +21,16 @@ def get_column_value(record, column) else value = record.send(column.name) - associated_size = value.size if column.associated_number? # get count before cache association - # we are not using eager loading, cache firsts records in order not to query the database in a future - unless column.association.nil? or value.loaded? - # load at least one record, is needed for column_empty? and checking permissions - if column.associated_limit.nil? - Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries" - else - record.send(column.name).target = value.find(:all, :limit => [column.associated_limit, 1].max) + if value && column.association + associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association + # we are not using eager loading, cache firsts records in order not to query the database in a future + unless value.loaded? + # load at least one record, is needed for column_empty? and checking permissions + if column.associated_limit.nil? + Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries" + else + record.send(column.name).target = value.find(:all, :limit => [column.associated_limit, 1].max) + end end end From 6d2b074698e00a9ef8302a20b6979a2d7bafb865 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 25 Sep 2009 13:39:08 +0200 Subject: [PATCH 0084/2024] Fix default sorting when default_scope use a symbol for order --- lib/active_scaffold/data_structures/sorting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 483ecb2947..892eebd56a 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -12,7 +12,7 @@ def set_default_sorting(model) if model.default_scoping.last.nil? || model.default_scoping.last[:find].nil? || model.default_scoping.last[:find][:order].nil? set(model.primary_key, 'ASC') if model.column_names.include?(model.primary_key) else - set_sorting_from_order_clause(model.default_scoping.last[:find][:order]) + set_sorting_from_order_clause(model.default_scoping.last[:find][:order].to_s) end end From 309a6447dd972befd3efe6e07a66a8bc196d4457 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 25 Sep 2009 14:05:00 +0200 Subject: [PATCH 0085/2024] Move build_order_clause to sorting class --- .../data_structures/sorting.rb | 16 +++++++++++++ lib/active_scaffold/finder.rb | 24 +------------------ test/misc/finder_test.rb | 5 ++-- test/mock_app/config/environment.rb | 4 ++-- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 892eebd56a..558725aa53 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -73,6 +73,22 @@ def first @clauses.first end + # builds an order-by clause + def clause + return nil if sorts_by_method? + + # unless the sorting is by method, create the sql string + order = [] + each do |sort_column, sort_direction| + sql = sort_column.sort[:sql] + next if sql.nil? or sql.empty? + + order << "#{sql} #{sort_direction}" + end + + order.join(', ') unless order.empty? + end + protected # retrieves the sorting clause for the given column diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 19857bf717..788b1741a1 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -154,7 +154,7 @@ def find_page(options = {}) klass = active_scaffold_config.model # create a general-use options array that's compatible with Rails finders - finder_options = { :order => build_order_clause(options[:sorting]), + finder_options = { :order => options[:sorting].try(:clause), :conditions => all_conditions, :joins => joins_for_finder, :include => options[:count_includes]} @@ -192,32 +192,10 @@ def joins_for_finder end + active_scaffold_habtm_joins end - # TODO: this should reside on the model, not the controller def merge_conditions(*conditions) active_scaffold_config.model.merge_conditions(*conditions) end - # accepts a DataStructure::Sorting object and builds an order-by clause - # TODO: this should reside on the model, not the controller - def build_order_clause(sorting) - return nil if sorting.nil? or sorting.sorts_by_method? - - # unless the sorting is by method, create the sql string - order = [] - sorting.each do |clause| - sort_column, sort_direction = clause - sql = sort_column.sort[:sql] - next if sql.nil? or sql.empty? - - order << "#{sql} #{sort_direction}" - end - - order = order.join(', ') - order = nil if order.empty? - - order - end - # TODO: this should reside on the column, not the controller def sort_collection_by_column(collection, column, order) sorter = column.sort[:method] diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index a6f5afd3ef..835c9d642c 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -39,13 +39,12 @@ def test_build_order_clause columns = ActiveScaffold::DataStructures::Columns.new(ModelStub, :a, :b, :c, :d) sorting = ActiveScaffold::DataStructures::Sorting.new(columns) - assert @klass.send(:build_order_clause, nil).nil? - assert @klass.send(:build_order_clause, sorting).nil? + assert sorting.clause.nil? sorting << [:a, 'desc'] sorting << [:b, 'asc'] - assert_equal 'model_stubs.a DESC, model_stubs.b ASC', @klass.send(:build_order_clause, sorting) + assert_equal 'model_stubs.a DESC, model_stubs.b ASC', sorting.clause end def test_method_sorting diff --git a/test/mock_app/config/environment.rb b/test/mock_app/config/environment.rb index 685505d628..fb79f2bb7a 100644 --- a/test/mock_app/config/environment.rb +++ b/test/mock_app/config/environment.rb @@ -1,7 +1,7 @@ # Be sure to restart your server when you modify this file # Specifies gem version of Rails to use when vendor/rails is not present -RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION +#RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') @@ -38,4 +38,4 @@ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] # config.i18n.default_locale = :de -end \ No newline at end of file +end From 7c5a3e9ec9ae8432a2190cd2ef741cb78d605f35 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Mon, 28 Sep 2009 11:07:37 +0200 Subject: [PATCH 0086/2024] Add a method to set columns to load from an association with eager loading disabled --- lib/active_scaffold/data_structures/column.rb | 3 +++ lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 395549e454..8bea80b024 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -142,6 +142,9 @@ def includes=(value) @includes = value.is_a?(Array) ? value : [value] # automatically convert to an array end + # a collection of columns to load when eager loading is disabled, if it's nil all columns will be loaded + attr_accessor :select_columns + # describes how to search on a column # search = true default, uses intelligent search sql # search = "CONCAT(a, b)" define your own sql for searching. this should be the "left-side" of a WHERE condition. the operator and value will be supplied by ActiveScaffold. diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 683e88cca9..73a0157331 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -29,7 +29,7 @@ def get_column_value(record, column) if column.associated_limit.nil? Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries" else - record.send(column.name).target = value.find(:all, :limit => [column.associated_limit, 1].max) + record.send(column.name).target = value.find(:all, :limit => [column.associated_limit, 1].max, :select => column.select_columns) end end end From db9eb96b422aa1990e804b99c0dbde301c5a1c6e Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Mon, 28 Sep 2009 11:48:04 +0200 Subject: [PATCH 0087/2024] Set links for association columns before configuration block, in order to allow config association links in the configuration block --- lib/active_scaffold.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index e260bd303f..1452576ddb 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -56,11 +56,11 @@ def active_scaffold(model_id = nil, &block) # run the configuration @active_scaffold_config = ActiveScaffold::Config::Core.new(model_id) @active_scaffold_config_block = block + self.links_for_associations self.active_scaffold_superclasses_blocks.each {|superblock| self.active_scaffold_config.configure &superblock} self.active_scaffold_config.configure &block if block_given? self.active_scaffold_config._configure_sti unless self.active_scaffold_config.sti_children.nil? self.active_scaffold_config._load_action_columns - self.links_for_associations # defines the attribute read methods on the model, so record.send() doesn't find protected/private methods instead klass = self.active_scaffold_config.model @@ -102,7 +102,7 @@ def active_scaffold(model_id = nil, &block) # Create the automatic column links. Note that this has to happen when configuration is *done*, because otherwise the Nested module could be disabled. Actually, it could still be disabled later, couldn't it? def links_for_associations return unless active_scaffold_config.actions.include? :list and active_scaffold_config.actions.include? :nested - active_scaffold_config.list.columns.each do |column| + active_scaffold_config.columns.each do |column| next unless column.link.nil? and column.autolink if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. From 2d0f074e7b451a895d12cc6611f6f68584256a0b Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Tue, 29 Sep 2009 10:29:48 +0200 Subject: [PATCH 0088/2024] Fix show associations in list with associated_number disabled --- lib/active_scaffold/helpers/list_column_helpers.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 73a0157331..f5b7b3aac3 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -29,7 +29,7 @@ def get_column_value(record, column) if column.associated_limit.nil? Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries" else - record.send(column.name).target = value.find(:all, :limit => [column.associated_limit, 1].max, :select => column.select_columns) + record.send(column.name).target = value.find(:all, :limit => column.associated_limit + 1, :select => column.select_columns) end end end @@ -47,13 +47,13 @@ def get_column_value(record, column) else firsts = value.first(column.associated_limit) firsts.collect! { |v| v.to_label } - firsts[column.associated_limit] = '…' if associated_size > column.associated_limit + firsts[column.associated_limit] = '…' if value.size > column.associated_limit end if column.associated_limit == 0 formatted_value = associated_size if column.associated_number? else formatted_value = clean_column_value(format_value(firsts.join(', '))) - formatted_value << " (#{associated_size})" if column.associated_number? and column.associated_limit and associated_size > column.associated_limit + formatted_value << " (#{associated_size})" if column.associated_number? and column.associated_limit and value.size > column.associated_limit end formatted_value end From e16a35f1e930e95d35fad81a89bc24b1fb66c8a6 Mon Sep 17 00:00:00 2001 From: Manuel Morales <manuelmorales@gmail.com> Date: Tue, 29 Sep 2009 12:22:54 +0200 Subject: [PATCH 0089/2024] fixes 'undefined method / for #<ActiveSupport::OrderedHash...' error when custom_finder_options contains a :group key --- lib/active_scaffold/finder.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 788b1741a1..4466efb4be 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -164,6 +164,10 @@ def find_page(options = {}) # NOTE: we must use :include in the count query, because some conditions may reference other tables count = klass.count(finder_options.reject{|k,v| [:select, :order].include? k}) + # Converts count to an integer if ActiveRecord returned an OrderedHash + # that happens when finder_options contains a :group key + count = count.length if count.is_a? ActiveSupport::OrderedHash + finder_options.merge! :include => full_includes # we build the paginator differently for method- and sql-based sorting From 8170ebbf31c5fde85f2faea2e148690d279daccd Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 30 Sep 2009 13:14:49 +0200 Subject: [PATCH 0090/2024] Move sorting test to data_structures/sorting --- test/data_structures/sorting_test.rb | 11 ++++++++++- test/misc/finder_test.rb | 12 ------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/test/data_structures/sorting_test.rb b/test/data_structures/sorting_test.rb index 7ac2740984..835a74f349 100644 --- a/test/data_structures/sorting_test.rb +++ b/test/data_structures/sorting_test.rb @@ -93,4 +93,13 @@ def test_sorts_by_method @sorting.add :b assert !@sorting.sorts_by_method? end -end \ No newline at end of file + + def test_build_order_clause + assert @sorting.clause.nil? + + @sorting << [:a, 'desc'] + @sorting << [:b, 'asc'] + + assert_equal 'model_stubs.a DESC, model_stubs.b ASC', @sorting.clause + end +end diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index 835c9d642c..b5b001a9b2 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -35,18 +35,6 @@ def test_create_conditions_for_columns assert_equal nil, ClassWithFinder.create_conditions_for_columns('foo', []) end - def test_build_order_clause - columns = ActiveScaffold::DataStructures::Columns.new(ModelStub, :a, :b, :c, :d) - sorting = ActiveScaffold::DataStructures::Sorting.new(columns) - - assert sorting.clause.nil? - - sorting << [:a, 'desc'] - sorting << [:b, 'asc'] - - assert_equal 'model_stubs.a DESC, model_stubs.b ASC', sorting.clause - end - def test_method_sorting column = ActiveScaffold::DataStructures::Column.new('a', ModelStub) column.sort_by :method => proc{self} From 6b775991b7654673c044fa922e63e9d6fed8c064 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 30 Sep 2009 14:48:21 +0200 Subject: [PATCH 0091/2024] Test for issue #705 --- test/misc/finder_test.rb | 18 ++++++++++++++++++ test/test_helper.rb | 2 ++ 2 files changed, 20 insertions(+) diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index b5b001a9b2..db8736ef20 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -3,11 +3,20 @@ class ClassWithFinder include ActiveScaffold::Finder + def conditions_for_collection; end + def conditions_from_params; end + def conditions_from_constraints; end + def joins_for_collection; end + def custom_finder_options + {} + end end +ClassWithFinder.any_instance.stubs(:active_scaffold_session_storage).returns({}) class FinderTest < Test::Unit::TestCase def setup @klass = ClassWithFinder.new + @klass.stubs(:active_scaffold_config).returns(mock { stubs(:model).returns(ModelStub) }) end def test_create_conditions_for_columns @@ -54,4 +63,13 @@ def test_method_sorting collection = [3, 1, 2] assert_equal collection.sort, @klass.send(:sort_collection_by_column, collection, column, 'asc') end + + def test_count_with_group + @klass.expects(:custom_finder_options).returns({:group => :a}) + ModelStub.expects(:count).returns(ActiveSupport::OrderedHash['foo', 5]) + page = @klass.send :find_page + + #assert_instance_of Integer, page.pager.count + assert_nothing_raised { page.pager.number_of_pages } + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index d593b350c4..55c98436d4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,6 @@ require 'test/unit' +require 'rubygems' +require 'mocha' ENV['RAILS_ENV'] = 'test' ENV['RAILS_ROOT'] ||= File.join(File.dirname(__FILE__), 'mock_app') From 8bb3b2eb570cf0d276f9dae89515705b8ca1c699 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 30 Sep 2009 17:51:43 +0200 Subject: [PATCH 0092/2024] Fix constraints for associations with primary key option, issue #706 --- lib/active_scaffold/constraints.rb | 4 ++++ test/misc/constraints_test.rb | 15 +++++++++++++++ test/misc/finder_test.rb | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index def47ccdd8..86fd3cf90a 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -108,6 +108,10 @@ def condition_from_association_constraint(association, value) association.table_name end + if association.options[:primary_key] + value = association.klass.find(value).send(association.options[:primary_key]) + end + condition = constraint_condition_for("#{table}.#{field}", value) if association.options[:polymorphic] condition = merge_conditions( diff --git a/test/misc/constraints_test.rb b/test/misc/constraints_test.rb index 8c98a73912..73283847e0 100644 --- a/test/misc/constraints_test.rb +++ b/test/misc/constraints_test.rb @@ -70,6 +70,14 @@ class OtherRole < ModelStub set_table_name 'roles' has_and_belongs_to_many :other_users, :class_name => 'ModelStubs::OtherUser', :foreign_key => 'role_id', :association_foreign_key => 'user_id', :join_table => 'roles_users' end + + class PrimaryKeyUser < ModelStub + has_many :locations, :class_name => 'PrimaryKeyLocation', :foreign_key => :username, :primary_key => :name + end + + class PrimaryKeyLocation < ModelStub + belongs_to :user, :class_name => 'PrimaryKeyUser', :foreign_key => :username, :primary_key => :name + end end class ConstraintsTestObject @@ -165,6 +173,13 @@ def test_constraint_conditions_for_normal_attributes assert_constraint_condition({'foo' => 'bar'}, ['users.foo = ?', 'bar'], 'normal column-based constraint') end + def test_constraint_conditions_for_associations_with_primary_key_option + @test_object.active_scaffold_config = config_for('primary_key_location') + #user = ModelStubs::PrimaryKeyUser.new(:id => 1, :name => 'User Name') + ModelStubs::PrimaryKeyUser.expects(:find).with(1).returns(stub(:id => 1, :name => 'User Name')) + assert_constraint_condition({'user' => 1}, ['primary_key_locations.username = ?', 'User Name'], 'association with primary-key constraint') + end + protected def assert_constraint_condition(constraint, condition, message = nil) diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index db8736ef20..d61bf3c9cb 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -11,12 +11,12 @@ def custom_finder_options {} end end -ClassWithFinder.any_instance.stubs(:active_scaffold_session_storage).returns({}) class FinderTest < Test::Unit::TestCase def setup @klass = ClassWithFinder.new @klass.stubs(:active_scaffold_config).returns(mock { stubs(:model).returns(ModelStub) }) + @klass.stubs(:active_scaffold_session_storage).returns({}) end def test_create_conditions_for_columns From 6a34dcb5818d6f6d82138bb12ab24b4ab8df5284 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 1 Oct 2009 10:08:10 +0200 Subject: [PATCH 0093/2024] Use select UI for associations in field search by default --- lib/active_scaffold/data_structures/column.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 8bea80b024..67a8c8c65a 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -237,6 +237,7 @@ def initialize(name, active_record_class) #:nodoc: @associated_number = self.class.associated_number @show_blank_record = self.class.show_blank_record @actions_for_association_links = self.class.actions_for_association_links.clone if @association + @search_ui = :select if @association # default all the configurable variables self.css_class = '' @@ -292,8 +293,7 @@ def initialize_search_sql if association.nil? self.search_sql = self.field.to_s else - # with associations we really don't know what to sort by without developer intervention. we could sort on the primary key ('id'), but that's hardly useful. previously ActiveScaffold would try and search using the same sql as from :sort, but we decided to just punt. - self.search_sql = nil + self.search_sql = "#{association.klass.table_name}.#{association.klass.primary_key}" end end end From 8b4bd836362d7c6d306579ca89abb232caa1a758 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 1 Oct 2009 10:09:48 +0200 Subject: [PATCH 0094/2024] Fix typo --- uninstall.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uninstall.rb b/uninstall.rb index 8f1e37b4d9..21b9cb79fa 100644 --- a/uninstall.rb +++ b/uninstall.rb @@ -10,4 +10,4 @@ path = File.join(directory, "../../../public/#{asset_type}/active_scaffold") FileUtils.rm_r(path) end -FileUtils.rm(File.join(directory, "../../../public/blank.html") +FileUtils.rm(File.join(directory, "../../../public/blank.html")) From 89ceb9fddf091a55a3df31c7a1c0a8be967f88bc Mon Sep 17 00:00:00 2001 From: "woody.peterson@gmail.com" <woody@CCiMacDev.local> Date: Thu, 1 Oct 2009 15:59:26 -0700 Subject: [PATCH 0095/2024] Nested country select does not honor form association name and id options, instead always using the defaults. Fixed. --- lib/active_scaffold/helpers/country_helpers.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/active_scaffold/helpers/country_helpers.rb b/lib/active_scaffold/helpers/country_helpers.rb index eaffc7ab65..e3001d94b9 100644 --- a/lib/active_scaffold/helpers/country_helpers.rb +++ b/lib/active_scaffold/helpers/country_helpers.rb @@ -301,6 +301,8 @@ class ActionView::Helpers::InstanceTag #:nodoc: def to_country_select_tag(priority_countries, options, html_options) html_options = html_options.stringify_keys + html_options['name'] = options[:name] + html_options['id'] = options[:id] add_default_name_and_id(html_options) value = value(object) content_tag("select", @@ -313,6 +315,8 @@ def to_country_select_tag(priority_countries, options, html_options) def to_usa_state_select_tag(priority_states, options, html_options) html_options = html_options.stringify_keys + html_options['name'] = options[:name] + html_options['id'] = options[:id] add_default_name_and_id(html_options) value = value(object) if method(:value).arity > 0 if html_options[:name.to_s].include?('search') From 00da9a987f9978df47f144d08020004fd9082c6a Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Tue, 6 Oct 2009 10:20:18 +0200 Subject: [PATCH 0096/2024] Don't set search_sql for polymorphic associations --- lib/active_scaffold/data_structures/column.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 67a8c8c65a..7ad08c8afb 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -237,7 +237,7 @@ def initialize(name, active_record_class) #:nodoc: @associated_number = self.class.associated_number @show_blank_record = self.class.show_blank_record @actions_for_association_links = self.class.actions_for_association_links.clone if @association - @search_ui = :select if @association + @search_ui = :select if @association and not polymorphic_association? # default all the configurable variables self.css_class = '' @@ -287,13 +287,13 @@ def initialize_sort end def initialize_search_sql - if self.virtual? - self.search_sql = nil - else + self.search_sql = unless self.virtual? if association.nil? - self.search_sql = self.field.to_s - else - self.search_sql = "#{association.klass.table_name}.#{association.klass.primary_key}" + self.field.to_s + elsif !self.polymorphic_association? + [association.klass.table_name, association.klass.primary_key].collect! do |str| + association.klass.connection.quote_column_name str + end.join('.') end end end From 678a1fdd3080d1571f0ba0604f39a4178a992456 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 7 Oct 2009 09:42:16 +0200 Subject: [PATCH 0097/2024] Cleanup last commit --- lib/active_scaffold/helpers/country_helpers.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/active_scaffold/helpers/country_helpers.rb b/lib/active_scaffold/helpers/country_helpers.rb index e3001d94b9..06a376a36a 100644 --- a/lib/active_scaffold/helpers/country_helpers.rb +++ b/lib/active_scaffold/helpers/country_helpers.rb @@ -301,8 +301,6 @@ class ActionView::Helpers::InstanceTag #:nodoc: def to_country_select_tag(priority_countries, options, html_options) html_options = html_options.stringify_keys - html_options['name'] = options[:name] - html_options['id'] = options[:id] add_default_name_and_id(html_options) value = value(object) content_tag("select", @@ -315,13 +313,11 @@ def to_country_select_tag(priority_countries, options, html_options) def to_usa_state_select_tag(priority_states, options, html_options) html_options = html_options.stringify_keys - html_options['name'] = options[:name] - html_options['id'] = options[:id] add_default_name_and_id(html_options) value = value(object) if method(:value).arity > 0 - if html_options[:name.to_s].include?('search') - html_options[:name.to_s] << '[]' - html_options[:multiple] = true + if html_options['name'].include?('search') + html_options['name'] << '[]' + html_options['multiple'] = true options[:include_blank] = true end content_tag("select", add_options(usa_state_options_for_select(value, priority_states), options, value), html_options) @@ -334,7 +330,8 @@ def active_scaffold_input_country(column, options) priority = ["United States"] select_options = {:prompt => as_(:_select_)} select_options.merge!(options) - country_select(:record, column.name, column.options[:priority] || priority, select_options, column.options) + options.delete(:prompt) + country_select(:record, column.name, column.options[:priority] || priority, select_options, column.options.merge(options)) end def active_scaffold_input_usa_state(column, options) @@ -343,8 +340,8 @@ def active_scaffold_input_usa_state(column, options) select_options.delete(:size) options.delete(:prompt) options.delete(:priority) - usa_state_select(:record, column.name, column.options[:priority], select_options, column.options.merge!(options)) + usa_state_select(:record, column.name, column.options[:priority], select_options, column.options.merge(options)) end end end -end \ No newline at end of file +end From 4cd2dc81c3e03c17e1b1722ebc698a13a6c1790a Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Thu, 8 Oct 2009 13:57:41 +0200 Subject: [PATCH 0098/2024] default_scope: added support for different table_names --- .../data_structures/sorting.rb | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 558725aa53..ff7b02d591 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -9,10 +9,11 @@ def initialize(columns) end def set_default_sorting(model) - if model.default_scoping.last.nil? || model.default_scoping.last[:find].nil? || model.default_scoping.last[:find][:order].nil? + last_scope = model.default_scoping.last + if last_scope.nil? || last_scope[:find].nil? || last_scope[:find][:order].nil? set(model.primary_key, 'ASC') if model.column_names.include?(model.primary_key) else - set_sorting_from_order_clause(model.default_scoping.last[:find][:order].to_s) + set_sorting_from_order_clause(model) end end @@ -40,6 +41,7 @@ def set(*args) # clears the sorting def clear + @default_sorting = false @clauses = [] end @@ -75,7 +77,7 @@ def first # builds an order-by clause def clause - return nil if sorts_by_method? + return nil if sorts_by_method? || default_sorting? # unless the sorting is by method, create the sql string order = [] @@ -109,21 +111,40 @@ def get_column(name_or_column) def mixed_sorting? sorts_by_method? and sorts_by_sql? end + + def default_sorting? + @default_sorting ||= false + end - def set_sorting_from_order_clause(order_clause) + def set_sorting_from_order_clause(model) clear + order_clause = model.default_scoping.last[:find][:order].to_s order_clause.split(',').each do |criterion| - order_parts = criterion.strip.split(' ') - add(extract_column_name_in_order_criterion(order_parts), extract_direction_in_order_criterion(order_parts)) unless order_parts.empty? + unless criterion.strip.split(' ').empty? + order_parts = extract_order_parts(criterion.strip.split(' ')) + add(order_parts[:column_name], order_parts[:direction]) unless different_table?(model, order_parts[:table_name]) + end end + @default_sorting = true + end + + def extract_order_parts(criterion_parts) + column_name_parts = criterion_parts.first.split('.') + order = {:direction => extract_direction_in_order_criterion(criterion_parts), + :column_name => remove_quotes(column_name_parts.last)} + order[:table_name] = remove_quotes(column_name_parts[-2]) if column_name_parts.length >= 2 + order + end + + def different_table?(model, order_table_name) + !order_table_name.nil? && model.table_name != order_table_name end - def extract_column_name_in_order_criterion(criterion_parts) - column_name = criterion_parts.first.split('.').last - if column_name.starts_with?('"') || column_name.starts_with?('`') - column_name[1, (column_name.length - 2)] + def remove_quotes(sql_name) + if sql_name.starts_with?('"') || sql_name.starts_with?('`') + sql_name[1, (sql_name.length - 2)] else - column_name + sql_name end end From 98299f59bdd156e104bcd5fa4c492ac06e8afb92 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 8 Oct 2009 14:53:18 +0200 Subject: [PATCH 0099/2024] cleanup last commit and add test --- .../data_structures/sorting.rb | 28 +++++++++---------- test/data_structures/sorting_test.rb | 11 ++++++++ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index ff7b02d591..f5c1f2622a 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -13,7 +13,8 @@ def set_default_sorting(model) if last_scope.nil? || last_scope[:find].nil? || last_scope[:find][:order].nil? set(model.primary_key, 'ASC') if model.column_names.include?(model.primary_key) else - set_sorting_from_order_clause(model) + set_sorting_from_order_clause(last_scope[:find][:order].to_s, model.table_name) + @default_sorting = true end end @@ -113,31 +114,30 @@ def mixed_sorting? end def default_sorting? - @default_sorting ||= false + @default_sorting end - def set_sorting_from_order_clause(model) + def set_sorting_from_order_clause(order_clause, model_table_name = nil) clear - order_clause = model.default_scoping.last[:find][:order].to_s order_clause.split(',').each do |criterion| - unless criterion.strip.split(' ').empty? - order_parts = extract_order_parts(criterion.strip.split(' ')) - add(order_parts[:column_name], order_parts[:direction]) unless different_table?(model, order_parts[:table_name]) + unless criterion.blank? + order_parts = extract_order_parts(criterion) + add(order_parts[:column_name], order_parts[:direction]) unless different_table?(model_table_name, order_parts[:table_name]) end end - @default_sorting = true end def extract_order_parts(criterion_parts) - column_name_parts = criterion_parts.first.split('.') - order = {:direction => extract_direction_in_order_criterion(criterion_parts), + column_name_part, direction_part = criterion_parts.strip.split(' ') + column_name_parts = column_name_part.split('.') + order = {:direction => extract_direction(direction_part), :column_name => remove_quotes(column_name_parts.last)} order[:table_name] = remove_quotes(column_name_parts[-2]) if column_name_parts.length >= 2 order end - def different_table?(model, order_table_name) - !order_table_name.nil? && model.table_name != order_table_name + def different_table?(model_table_name, order_table_name) + !order_table_name.nil? && model_table_name != order_table_name end def remove_quotes(sql_name) @@ -148,8 +148,8 @@ def remove_quotes(sql_name) end end - def extract_direction_in_order_criterion(criterion_parts) - if criterion_parts.last.to_s.upcase == 'DESC' + def extract_direction(direction_part) + if direction_part.upcase == 'DESC' 'DESC' else 'ASC' diff --git a/test/data_structures/sorting_test.rb b/test/data_structures/sorting_test.rb index 835a74f349..da2890d58d 100644 --- a/test/data_structures/sorting_test.rb +++ b/test/data_structures/sorting_test.rb @@ -102,4 +102,15 @@ def test_build_order_clause assert_equal 'model_stubs.a DESC, model_stubs.b ASC', @sorting.clause end + + ModelStubWithDefaultScope = ModelStub.clone + ModelStubWithDefaultScope.class_eval { default_scope :order => 'a DESC, players.last_name ASC' } + def test_set_default_sorting_with_default_scope + @sorting.set_default_sorting ModelStubWithDefaultScope + + assert @sorting.sorts_on?(:a) + assert_equal 'DESC', @sorting.direction_of(:a) + assert_equal 1, @sorting.instance_variable_get(:@clauses).size + assert_nil @sorting.clause + end end From 10d4be8c22ee5b950a0d81082c0439e9e3cee6d2 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 8 Oct 2009 15:17:53 +0200 Subject: [PATCH 0100/2024] Fix testing default search for association columns --- test/data_structures/association_column_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/data_structures/association_column_test.rb b/test/data_structures/association_column_test.rb index 95439e44e0..7570ab6287 100644 --- a/test/data_structures/association_column_test.rb +++ b/test/data_structures/association_column_test.rb @@ -18,8 +18,9 @@ def test_sorting end def test_searching - # right now, there's no intelligent searching on association columns - assert !@association_column.searchable? + # by default searching on association columns uses primary key + assert @association_column.searchable? + assert_equal 'model_stubs.id', @association_column.search_sql end def test_association From 3c871bc4b82bce00484e39f9e264c9ed9dbbb291 Mon Sep 17 00:00:00 2001 From: student <noreply@github.com> Date: Thu, 8 Oct 2009 22:42:39 -0700 Subject: [PATCH 0101/2024] I dug a bit, and found a much cleaner way to address the issue with undefined security methods. --- frontends/default/views/_list_actions.html.erb | 2 +- frontends/default/views/_list_header.html.erb | 2 +- frontends/default/views/_update_actions.html.erb | 2 +- lib/active_scaffold/data_structures/action_link.rb | 4 ++++ lib/active_scaffold/helpers/view_helpers.rb | 4 ++++ test/data_structures/action_link_test.rb | 3 +++ 6 files changed, 14 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 73d0a36fb7..f2925f73b2 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -4,7 +4,7 @@ <%= loading_indicator_tag(:action => :record, :id => record.id) %> </td> <% active_scaffold_config.action_links.each :record do |link| -%> - <% next if controller.respond_to? link.security_method and !controller.send(link.security_method) -%> + <% next if skip_action_link(controller, link) -%> <td> <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options) : "<a class='disabled'>#{link.label}</a>" -%> </td> diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index fc0e823929..97a13f9df0 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -2,7 +2,7 @@ <div class="actions"> <% new_params = params_for(:action => :table) %> <% active_scaffold_config.action_links.each :table do |link| -%> - <% next if controller.respond_to? link.security_method and !controller.send(link.security_method) -%> + <% next if skip_action_link(controller, link) -%> <% next if link.action == 'new' && params[:nested].nil? && active_scaffold_config.list.always_show_create %> <% next if link.action == 'show_search' && active_scaffold_config.list.always_show_search %> <%= render_action_link(link, new_params) -%> diff --git a/frontends/default/views/_update_actions.html.erb b/frontends/default/views/_update_actions.html.erb index 392f05b003..5cac1ef7a6 100644 --- a/frontends/default/views/_update_actions.html.erb +++ b/frontends/default/views/_update_actions.html.erb @@ -2,7 +2,7 @@ <div class="actions"> <% active_scaffold_config.action_links.each :record do |link| -%> <% next unless link.action == 'nested' -%> - <% next if controller.respond_to? link.security_method and !controller.send(link.security_method) -%> + <% next if skip_action_link(controller, link) -%> <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options) : "<a class='disabled'>#{link.label}</a>" -%> <% end -%> </div> diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 4e39ad1e2f..65929069fa 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -65,6 +65,10 @@ def security_method @security_method || "#{self.label.underscore.downcase.gsub(/ /, '_')}_authorized?" end + def security_method_set? + !!@security_method + end + # the crud type of the (eventual?) action. different than :method, because this crud action may not be imminent. # this is used to determine record-level authorization (e.g. record.authorized_for?(:action => link.crud_type). # options are :create, :read, :update, and :destroy diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 66d7c9110d..0ead421169 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -128,6 +128,10 @@ def link_to_visibility_toggle(options = {}) link_to_function link_text, "e = #{options[:of]}; e.toggle(); this.innerHTML = (e.style.display == 'none') ? '#{as_(:show)}' : '#{as_(:hide)}'", :class => 'visibility-toggle' end + def skip_action_link(controller, link) + (link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method) + end + def render_action_link(link, url_options) url_options = url_options.clone url_options[:action] = link.action diff --git a/test/data_structures/action_link_test.rb b/test/data_structures/action_link_test.rb index 066d1af302..2a5f5945aa 100644 --- a/test/data_structures/action_link_test.rb +++ b/test/data_structures/action_link_test.rb @@ -25,7 +25,10 @@ def test_simple_attributes assert_equal 'hello_world_authorized?', @link.security_method @link.label = 'HelloWorld' assert_equal 'hello_world_authorized?', @link.security_method + + assert_equal false, @link.security_method_set? @link.security_method = 'blueberry_pie' + assert_equal true, @link.security_method_set? assert_equal 'blueberry_pie', @link.security_method @link.type = :table From a54e8918b0d6909b2026b34e94fb5a10275e3375 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 9 Oct 2009 09:52:47 +0200 Subject: [PATCH 0102/2024] Cleanup last commit and fix nested action links --- frontends/default/views/_list_actions.html.erb | 2 +- frontends/default/views/_list_header.html.erb | 4 ++-- frontends/default/views/_update_actions.html.erb | 2 +- lib/active_scaffold/actions/nested.rb | 11 +++++++++++ lib/active_scaffold/helpers/view_helpers.rb | 2 +- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index f2925f73b2..e36fc3c150 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -4,7 +4,7 @@ <%= loading_indicator_tag(:action => :record, :id => record.id) %> </td> <% active_scaffold_config.action_links.each :record do |link| -%> - <% next if skip_action_link(controller, link) -%> + <% next if skip_action_link(link) -%> <td> <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options) : "<a class='disabled'>#{link.label}</a>" -%> </td> diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index 97a13f9df0..015f04fc7a 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -2,7 +2,7 @@ <div class="actions"> <% new_params = params_for(:action => :table) %> <% active_scaffold_config.action_links.each :table do |link| -%> - <% next if skip_action_link(controller, link) -%> + <% next if skip_action_link(link) -%> <% next if link.action == 'new' && params[:nested].nil? && active_scaffold_config.list.always_show_create %> <% next if link.action == 'show_search' && active_scaffold_config.list.always_show_search %> <%= render_action_link(link, new_params) -%> @@ -11,4 +11,4 @@ <%= loading_indicator_tag(:action => :table) %> </div> <% end %> -<h2><%= active_scaffold_config.list.user.label %></h2> \ No newline at end of file +<h2><%= active_scaffold_config.list.user.label %></h2> diff --git a/frontends/default/views/_update_actions.html.erb b/frontends/default/views/_update_actions.html.erb index 5cac1ef7a6..e565b26668 100644 --- a/frontends/default/views/_update_actions.html.erb +++ b/frontends/default/views/_update_actions.html.erb @@ -2,7 +2,7 @@ <div class="actions"> <% active_scaffold_config.action_links.each :record do |link| -%> <% next unless link.action == 'nested' -%> - <% next if skip_action_link(controller, link) -%> + <% next if skip_action_link(link) -%> <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options) : "<a class='disabled'>#{link.label}</a>" -%> <% end -%> </div> diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index fd6e7359a1..c52591dddd 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -29,6 +29,10 @@ def do_nested @record = find_if_allowed(params[:id], :read) end + def nested_authorized? + true + end + def include_habtm_actions if nested_habtm? # Production mode is ok with adding a link everytime the scaffold is nested - we ar not ok with that. @@ -161,6 +165,13 @@ def destroy_existing_respond_to_yaml render :text => successful? ? "" : response_object.to_yaml, :content_type => Mime::YAML, :status => response_status end + def add_existing_authorized? + true + end + def delete_existing_authorized? + true + end + def after_create_save(record) if params[:association_macro] == :has_and_belongs_to_many params[:associated_id] = record diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 0ead421169..cc7d5f94b8 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -128,7 +128,7 @@ def link_to_visibility_toggle(options = {}) link_to_function link_text, "e = #{options[:of]}; e.toggle(); this.innerHTML = (e.style.display == 'none') ? '#{as_(:show)}' : '#{as_(:hide)}'", :class => 'visibility-toggle' end - def skip_action_link(controller, link) + def skip_action_link(link) (link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method) end From 4f63ba9981ad5158b87c9e70d1fa2f2b71e6e70a Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Thu, 22 Oct 2009 17:24:06 +0200 Subject: [PATCH 0103/2024] Bugfix: in case of form_ui :select and in_place_edit show correct list value instead of <object xxxx> --- .../helpers/list_column_helpers.rb | 96 ++++++++++--------- 1 file changed, 53 insertions(+), 43 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index f5b7b3aac3..65381363ef 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -19,52 +19,13 @@ def get_column_value(record, column) elsif column.column and override_column_ui?(column.column.type) send(override_column_ui(column.column.type), column, record) else - value = record.send(column.name) - - if value && column.association - associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association - # we are not using eager loading, cache firsts records in order not to query the database in a future - unless value.loaded? - # load at least one record, is needed for column_empty? and checking permissions - if column.associated_limit.nil? - Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries" - else - record.send(column.name).target = value.find(:all, :limit => column.associated_limit + 1, :select => column.select_columns) - end - end - end - - if column.association.nil? or column_empty?(value) - formatted_value = clean_column_value(format_value(value, column.options)) - else - case column.association.macro - when :has_one, :belongs_to - formatted_value = clean_column_value(format_value(value.to_label)) - - when :has_many, :has_and_belongs_to_many - if column.associated_limit.nil? - firsts = value.collect { |v| v.to_label } - else - firsts = value.first(column.associated_limit) - firsts.collect! { |v| v.to_label } - firsts[column.associated_limit] = '…' if value.size > column.associated_limit - end - if column.associated_limit == 0 - formatted_value = associated_size if column.associated_number? - else - formatted_value = clean_column_value(format_value(firsts.join(', '))) - formatted_value << " (#{associated_size})" if column.associated_number? and column.associated_limit and value.size > column.associated_limit - end - formatted_value - end - end - - formatted_value + format_column_value(record, column) end value = ' ' if value.nil? or (value.respond_to?(:empty?) and value.empty?) # fix for IE 6 return value end + # TODO: move empty_field_text and   logic in here? # TODO: move active_scaffold_inplace_edit in here? @@ -182,14 +143,63 @@ def override_column_ui(list_ui) ## Formatting ## + def format_column_value(record, column) + value = record.send(column.name) + if column.association.nil? or column_empty?(value) + format_value(value, column.options) + else + cache_association(record, value, column) + format_association_value(value, column) + end + end + + def format_association_value(value, column) + case column.association.macro + when :has_one, :belongs_to + formatted_value = format_value(value.to_label) + when :has_many, :has_and_belongs_to_many + if column.associated_limit.nil? + firsts = value.collect { |v| v.to_label } + else + firsts = value.first(column.associated_limit) + firsts.collect! { |v| v.to_label } + firsts[column.associated_limit] = '…' if value.size > column.associated_limit + end + if column.associated_limit == 0 + formatted_value = associated_size if column.associated_number? + else + formatted_value = format_value(firsts.join(', ')) + formatted_value << " (#{associated_size})" if column.associated_number? and column.associated_limit and value.size > column.associated_limit + end + formatted_value + end + formatted_value + end + def format_value(column_value, options = {}) - if column_empty?(column_value) + value = if column_empty?(column_value) active_scaffold_config.list.empty_field_text elsif column_value.is_a?(Time) || column_value.is_a?(Date) l(column_value, :format => options[:format] || :default) else column_value.to_s end + clean_column_value(value) + end + + def cache_association(record, value, column) + if value && column.association + associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association + # we are not using eager loading, cache firsts records in order not to query the database in a future + unless value.loaded? + # load at least one record, is needed for column_empty? and checking permissions + if column.associated_limit.nil? + Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries" + else + record.send(column.name).target = value.find(:all, :limit => column.associated_limit + 1, :select => column.select_columns) + end + end + end end # ========== @@ -200,7 +210,7 @@ def format_inplace_edit_column(record,column) if column.list_ui == :checkbox active_scaffold_column_checkbox(column, record) else - clean_column_value(format_value(value)) + format_column_value(record, column) end end From 50d00cfc436403a5ef81c06ae3f7b7e78132f271 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 23 Oct 2009 10:47:55 +0200 Subject: [PATCH 0104/2024] Fix updated_model translations --- lib/active_scaffold/locale/de.rb | 2 +- lib/active_scaffold/locale/en.rb | 2 +- lib/active_scaffold/locale/es.yml | 2 +- lib/active_scaffold/locale/fr.rb | 2 +- lib/active_scaffold/locale/hu.yml | 2 +- lib/active_scaffold/locale/ja.yml | 2 +- lib/active_scaffold/locale/ru.yml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 1c48894499..1e67a39ac3 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -49,7 +49,7 @@ :_to_ => ' zu ', :update => 'Speichern', :update_model => 'Editiere {{model}}', - :udated_model => '{{model}} aktualisiert', + :updated_model => '{{model}} aktualisiert', :'=' => '=', :'>=' => '>=', :'<=' => '<=', diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 6b4ef37cee..643de22e95 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -49,7 +49,7 @@ :_to_ => ' to ', :update => 'Update', :update_model => 'Update {{model}}', - :udated_model => 'Updated {{model}}', + :updated_model => 'Updated {{model}}', :'=' => '=', :'>=' => '>=', :'<=' => '<=', diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index d3412b76e8..db8aa07d61 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -50,7 +50,7 @@ es: _to_ : ' a ' update: 'Actualizar' update_model: 'Actualizar {{model}}' - udated_model: '{{model}} actualizado' + updated_model: '{{model}} actualizado' '=': '=' '>=': '>=' '<=': '<=' diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 0021f8f27c..8efbfb7e2c 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -49,7 +49,7 @@ :_to_ => ' à ', :update => 'Mettre à jour', :update_model => 'Mettre à jour {{model}}', - :udated_model => '{{model}} mis à jour', + :updated_model => '{{model}} mis à jour', :'=' => '=', :'>=' => '>=', :'<=' => '<=', diff --git a/lib/active_scaffold/locale/hu.yml b/lib/active_scaffold/locale/hu.yml index 39f2b034e2..84cccc6dee 100644 --- a/lib/active_scaffold/locale/hu.yml +++ b/lib/active_scaffold/locale/hu.yml @@ -48,7 +48,7 @@ hu: _to_ : ' – ' update: 'Modosítás' update_model: '{{model}} modosítása' - udated_model: '{{model}} módosítva' + updated_model: '{{model}} módosítva' '=': '=' '>=': '>=' '<=': '<=' diff --git a/lib/active_scaffold/locale/ja.yml b/lib/active_scaffold/locale/ja.yml index d932c0cba3..430dc1e5ec 100644 --- a/lib/active_scaffold/locale/ja.yml +++ b/lib/active_scaffold/locale/ja.yml @@ -48,7 +48,7 @@ ja: _to_ : ' to ' # needed? update: '更新' update_model: '{{model}}を更新' - udated_model: '{{model}}を更新しました' + updated_model: '{{model}}を更新しました' '=': '=' '>=': '>=' '<=': '<=' diff --git a/lib/active_scaffold/locale/ru.yml b/lib/active_scaffold/locale/ru.yml index f04e36c1d0..4df3b70cf0 100644 --- a/lib/active_scaffold/locale/ru.yml +++ b/lib/active_scaffold/locale/ru.yml @@ -47,7 +47,7 @@ ru: _to_ : ' to ' update: 'Обновить запись' update_model: 'Обновить запись {{model}}' - udated_model: 'Обновлена запись {{model}}' + updated_model: 'Обновлена запись {{model}}' '=': '=' '>=': '>=' '<=': '<=' From 42107a533851591feaf1de9ab72a8276b2374a22 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 23 Oct 2009 14:27:15 +0200 Subject: [PATCH 0105/2024] Fix showing associated number --- .../helpers/list_column_helpers.rb | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 65381363ef..14e6abf982 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -145,18 +145,21 @@ def override_column_ui(list_ui) def format_column_value(record, column) value = record.send(column.name) + if value && column.association # cache association size before calling column_empty? + associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association + cache_association(value, column) + end if column.association.nil? or column_empty?(value) format_value(value, column.options) else - cache_association(record, value, column) - format_association_value(value, column) + format_association_value(value, column, associated_size) end end - def format_association_value(value, column) + def format_association_value(value, column, size) case column.association.macro when :has_one, :belongs_to - formatted_value = format_value(value.to_label) + format_value(value.to_label) when :has_many, :has_and_belongs_to_many if column.associated_limit.nil? firsts = value.collect { |v| v.to_label } @@ -166,14 +169,13 @@ def format_association_value(value, column) firsts[column.associated_limit] = '…' if value.size > column.associated_limit end if column.associated_limit == 0 - formatted_value = associated_size if column.associated_number? + size if column.associated_number? else - formatted_value = format_value(firsts.join(', ')) - formatted_value << " (#{associated_size})" if column.associated_number? and column.associated_limit and value.size > column.associated_limit + joined_associated = format_value(firsts.join(', ')) + joined_associated << " (#{size})" if column.associated_number? and column.associated_limit and value.size > column.associated_limit + joined_associated end - formatted_value end - formatted_value end def format_value(column_value, options = {}) @@ -187,17 +189,14 @@ def format_value(column_value, options = {}) clean_column_value(value) end - def cache_association(record, value, column) - if value && column.association - associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association - # we are not using eager loading, cache firsts records in order not to query the database in a future - unless value.loaded? - # load at least one record, is needed for column_empty? and checking permissions - if column.associated_limit.nil? - Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries" - else - record.send(column.name).target = value.find(:all, :limit => column.associated_limit + 1, :select => column.select_columns) - end + def cache_association(value, column) + # we are not using eager loading, cache firsts records in order not to query the database in a future + unless value.loaded? + # load at least one record, is needed for column_empty? and checking permissions + if column.associated_limit.nil? + Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries" + else + value.target = value.find(:all, :limit => column.associated_limit + 1, :select => column.select_columns) end end end From 692c1b29d6ef3d788ce1a93a45c211e639ec5c09 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Mon, 26 Oct 2009 16:35:54 +0100 Subject: [PATCH 0106/2024] Fix update column for subforms with default layout (horizontal) --- frontends/default/views/render_field.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/render_field.js.rjs b/frontends/default/views/render_field.js.rjs index 780026cce0..8453e7cefd 100644 --- a/frontends/default/views/render_field.js.rjs +++ b/frontends/default/views/render_field.js.rjs @@ -1,7 +1,7 @@ column = @update_column while column field_id = active_scaffold_input_options(column, params[:scope])[:id] - page[field_id].up('li').replace_html :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } + page[field_id].up('dl').replace :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } column = Hash === column.options ? column.options[:update_column] : nil column = active_scaffold_config.columns[column] if column end From 373ae82cc4b235120f3642e0be84fa2e14fdda79 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Mon, 26 Oct 2009 16:36:11 +0100 Subject: [PATCH 0107/2024] Fix update column for calendar date select --- lib/active_scaffold/helpers/form_column_helpers.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 9b96fcfd4c..beb0dbb329 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -6,6 +6,7 @@ module FormColumnHelpers # It does not do any rendering. It only decides which method is responsible for rendering. def active_scaffold_input_for(column, scope = nil) options = active_scaffold_input_options(column, scope) + options = javascript_for_update_column(column, scope, options) # first, check if the dev has created an override for this specific field if override_form_field?(column) send(override_form_field(column), @record, options[:name]) @@ -36,7 +37,7 @@ def active_scaffold_input_for(column, scope = nil) input(:record, column.name, options.merge(column.options)) end end - end.to_s + javascript_for_update_column(column, scope, options) + end end alias form_column active_scaffold_input_for @@ -67,10 +68,9 @@ def javascript_for_update_column(column, scope, options) parameters = "column=#{column.name}" parameters << "&eid=#{params[:eid]}" if params[:eid] parameters << "&scope=#{scope}" if scope - javascript_tag("$(#{options[:id].to_json}).observe('change', function(event) { new Ajax.Request(#{url_for(url_params).to_json}, {parameters: '#{parameters}&value=' + this.value, method: 'get'}); });") - else - '' + options[:onchange] = "new Ajax.Request(#{url_for(url_params).to_json}, {parameters: '#{parameters}&value=' + this.value, method: 'get'});#{options[:onchange]}" end + options end ## From 8cb194f47bab7768d0a81ac9c62342b5ba2f9ff7 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Mon, 26 Oct 2009 17:11:02 +0100 Subject: [PATCH 0108/2024] Add search_ui for search ranges in field_search with calendar date select --- .../calendar_date_select/lib/as_cds_bridge.rb | 59 +++++++++++++++---- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb index 0c3577bd6f..19eae5745d 100644 --- a/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb +++ b/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb @@ -21,7 +21,7 @@ def initialize_with_calendar_date_select(model_id) module ActiveScaffold - module Helpers + module CalendarDateSelectBridge # Helpers that assist with the rendering of a Form Column module FormColumnHelpers def active_scaffold_input_calendar_date_select(column, options) @@ -29,25 +29,58 @@ def active_scaffold_input_calendar_date_select(column, options) calendar_date_select("record", column.name, options.merge(column.options)) end end - end -end -module ActiveScaffold - module Helpers - module ViewHelpers + module SearchColumnHelpers + def active_scaffold_search_calendar_date_select(column, options) + options = column.options.merge(options) + helper = "select_#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}" + html = [] + html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[from]", :id => "#{options[:id]}_from")) + html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[to]", :id => "#{options[:id]}_to")) + html * ' - ' + end + end + module ViewHelpers # Provides stylesheets to include with +stylesheet_link_tag+ - def active_scaffold_stylesheets_with_calendar_date_select(frontend = :default) - active_scaffold_stylesheets_without_calendar_date_select.to_a << calendar_date_select_stylesheets + def active_scaffold_stylesheets(frontend = :default) + super + [calendar_date_select_stylesheets] end - alias_method_chain :active_scaffold_stylesheets, :calendar_date_select # Provides stylesheets to include with +stylesheet_link_tag+ - def active_scaffold_javascripts_with_calendar_date_select(frontend = :default) - active_scaffold_javascripts_without_calendar_date_select.to_a << calendar_date_select_javascripts + def active_scaffold_javascripts(frontend = :default) + super + [calendar_date_select_javascripts] + end + end + + module Finder + module ClassMethods + def condition_for_calendar_date_select_type(column, value, like_pattern) + conversion = column.column.type == :date ? 'to_date' : 'to_time' + from_value, to_value = ['from', 'to'].collect do |field| + Time.zone.parse(value[field]) rescue nil + end + + if from_value.nil? and to_value.nil? + nil + elsif !from_value + ["#{column.search_sql} <= ?", to_value.send(conversion).to_s(:db)] + elsif !to_value + ["#{column.search_sql} >= ?", from_value.send(conversion).to_s(:db)] + else + ["#{column.search_sql} BETWEEN ? AND ?", from_value.send(conversion).to_s(:db), to_value.send(conversion).to_s(:db)] + end + end end - alias_method_chain :active_scaffold_javascripts, :calendar_date_select - end end end + +ActionView::Base.class_eval do + include ActiveScaffold::CalendarDateSelectBridge::FormColumnHelpers + include ActiveScaffold::CalendarDateSelectBridge::SearchColumnHelpers + include ActiveScaffold::CalendarDateSelectBridge::ViewHelpers +end +ActiveScaffold::Finder::ClassMethods.module_eval do + include ActiveScaffold::CalendarDateSelectBridge::Finder::ClassMethods +end From 68ff14cadeecdcdf2871119dc44e60f70495f145 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Tue, 27 Oct 2009 13:36:58 +0100 Subject: [PATCH 0109/2024] Don't filter by page, sort and sort_direction columns, are used to sort and pagination (it fixes issue #709) --- lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/finder.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index fb99ea47b6..239562e5bd 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -102,7 +102,7 @@ def custom_finder_options # Builds search conditions by search params for column names. This allows urls like "contacts/list?company_id=5". def conditions_from_params conditions = nil - params.reject {|key, value| [:controller, :action, :id].include?(key.to_sym)}.each do |key, value| + params.reject {|key, value| [:controller, :action, :id, :page, :sort, :sort_direction].include?(key.to_sym)}.each do |key, value| next unless active_scaffold_config.model.column_names.include?(key) if value.is_a?(Array) conditions = merge_conditions(conditions, ["#{active_scaffold_config.model.table_name}.#{key.to_s} in (?)", value]) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 4466efb4be..c98a965bc2 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -147,15 +147,16 @@ def find_page(options = {}) options.assert_valid_keys :sorting, :per_page, :page, :count_includes full_includes = (active_scaffold_joins.blank? ? nil : active_scaffold_joins) + search_conditions = all_conditions options[:per_page] ||= 999999999 options[:page] ||= 1 - options[:count_includes] ||= full_includes + options[:count_includes] ||= full_includes unless search_conditions.nil? klass = active_scaffold_config.model # create a general-use options array that's compatible with Rails finders finder_options = { :order => options[:sorting].try(:clause), - :conditions => all_conditions, + :conditions => search_conditions, :joins => joins_for_finder, :include => options[:count_includes]} From e26b690015728c092456f3781b03304598f44523 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Tue, 27 Oct 2009 17:46:03 +0100 Subject: [PATCH 0110/2024] Create links for associations only if there is a reverse association, but don't try to guess it if it's not found. Fixes issue #704 --- lib/active_scaffold.rb | 2 +- lib/active_scaffold/data_structures/column.rb | 4 +++- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- lib/extensions/reverse_associations.rb | 6 +++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 1452576ddb..f7308992c8 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -103,7 +103,7 @@ def active_scaffold(model_id = nil, &block) def links_for_associations return unless active_scaffold_config.actions.include? :list and active_scaffold_config.actions.include? :nested active_scaffold_config.columns.each do |column| - next unless column.link.nil? and column.autolink + next unless column.link.nil? and column.autolink? if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. column.set_link('nested', :parameters => {:associations => column.name.to_sym}, :html_options => {:class => column.name}) #unless column.through_association? diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 7ad08c8afb..809b57c8be 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -109,7 +109,9 @@ def options attr_reader :link # set an action_link to nested list or inline form in this column - attr_reader :autolink + def autolink? + @autolink and self.association.reverse + end # this should not only delete any existing link but also prevent column links from being automatically added by later routines def clear_link diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 14e6abf982..a3cbbade1c 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -39,7 +39,7 @@ def render_list_column(text, column, record) url_options[:id] = associated.id if associated and link.controller and link.controller.to_s != params[:controller] # setup automatic link - if column.autolink # link to nested scaffold or inline form + if column.autolink? # link to nested scaffold or inline form link = action_link_to_inline_form(column, associated) if link.crud_type.nil? # automatic link to inline form (singular association) return text if link.crud_type.nil? if link.crud_type == :create diff --git a/lib/extensions/reverse_associations.rb b/lib/extensions/reverse_associations.rb index a82a4844b4..aad759e467 100644 --- a/lib/extensions/reverse_associations.rb +++ b/lib/extensions/reverse_associations.rb @@ -7,10 +7,10 @@ def reverse_for?(klass) attr_writer :reverse def reverse - unless @reverse + unless @reverse.nil? reverse_matches = reverse_matches_for(self.class_name.constantize) # grab first association, or make a wild guess - @reverse = reverse_matches.empty? ? self.active_record.to_s.pluralize.underscore : reverse_matches.first.name + @reverse = reverse_matches.empty? ? false : reverse_matches.first.name end @reverse end @@ -53,4 +53,4 @@ def reverse_matches_for(klass) end end -end \ No newline at end of file +end From ffc7f9371dbe3d65403618cc4496228eb88f4a04 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 28 Oct 2009 10:46:11 +0100 Subject: [PATCH 0111/2024] Fix last commit --- lib/extensions/reverse_associations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extensions/reverse_associations.rb b/lib/extensions/reverse_associations.rb index aad759e467..fd169f7312 100644 --- a/lib/extensions/reverse_associations.rb +++ b/lib/extensions/reverse_associations.rb @@ -7,7 +7,7 @@ def reverse_for?(klass) attr_writer :reverse def reverse - unless @reverse.nil? + if @reverse.nil? reverse_matches = reverse_matches_for(self.class_name.constantize) # grab first association, or make a wild guess @reverse = reverse_matches.empty? ? false : reverse_matches.first.name From c0d8eab02f2a781cce13e84c551b5edb98d44c9b Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 28 Oct 2009 11:20:22 +0100 Subject: [PATCH 0112/2024] Improve RESTful responses, fixes issue 570 --- lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/actions/create.rb | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 239562e5bd..cbf905566a 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -51,7 +51,7 @@ def accepts?(*types) end def response_status - successful? ? 200 : 500 + successful? ? 200 : 422 end # API response object that will be converted to XML/YAML/JSON using to_xxx diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index c6852c869c..27771b5b64 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -20,6 +20,14 @@ def create end protected + def response_status + successful? ? 201 : super + end + + def response_location + url_for(params_for(:action => "show", :id => @record.id)) if successful? + end + def new_respond_to_html if successful? render(:action => 'create') @@ -45,7 +53,7 @@ def create_respond_to_html if successful? flash[:info] = as_(:created_model, :model => @record.to_label) if active_scaffold_config.create.edit_after_create - redirect_to params.merge(:action => "edit", :id => @record.id) + redirect_to params_for(:action => "edit", :id => @record.id) else return_to_main end @@ -65,15 +73,15 @@ def create_respond_to_js end def create_respond_to_xml - render :xml => response_object.to_xml, :content_type => Mime::XML, :status => response_status + render :xml => response_object.to_xml, :content_type => Mime::XML, :status => response_status, :location => response_location end def create_respond_to_json - render :text => response_object.to_json, :content_type => Mime::JSON, :status => response_status + render :text => response_object.to_json, :content_type => Mime::JSON, :status => response_status, :location => response_location end def create_respond_to_yaml - render :text => response_object.to_yaml, :content_type => Mime::YAML, :status => response_status + render :text => response_object.to_yaml, :content_type => Mime::YAML, :status => response_status, :location => response_location end def constraints_for_nested_create From 1fd6e681b9c0a15f493fc1a7caa96049f473dfa4 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 28 Oct 2009 12:23:08 +0100 Subject: [PATCH 0113/2024] Keep example text in search input when is shown, fixes issue #241 --- frontends/default/javascripts/form_enhancements.js | 11 +++++++---- frontends/default/views/_live_search.html.erb | 4 +--- frontends/default/views/_search.html.erb | 5 ++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/frontends/default/javascripts/form_enhancements.js b/frontends/default/javascripts/form_enhancements.js index cab9997e9c..136c2c0e8f 100644 --- a/frontends/default/javascripts/form_enhancements.js +++ b/frontends/default/javascripts/form_enhancements.js @@ -10,7 +10,12 @@ TextFieldWithExample.prototype = { this.defaultText = defaultText; this.createHiddenInput(); + if (options.focus) this.input.focus(); this.checkAndShowExample(); + if (options.focus) { + this.input.selectionStart = 0; + this.input.selectionEnd = 0; + } Event.observe(this.input, "blur", this.onBlur.bindAsEventListener(this)); Event.observe(this.input, "focus", this.onFocus.bindAsEventListener(this)); @@ -39,9 +44,7 @@ TextFieldWithExample.prototype = { this.checkAndShowExample(); }, onFocus: function(event) { - if (this.exampleShown()) { - this.removeExample(); - } + this.removeExample(); }, onClick: function(event) { this.removeExample(); @@ -57,7 +60,7 @@ TextFieldWithExample.prototype = { Element.addClassName(this.input, this.options.exampleClassName); } }, - removeExample: function() { + removeExample: function() { if (this.exampleShown()) { this.input.value = ''; this.input.name = this.name; diff --git a/frontends/default/views/_live_search.html.erb b/frontends/default/views/_live_search.html.erb index 5b70cfae0c..128ea0f473 100644 --- a/frontends/default/views/_live_search.html.erb +++ b/frontends/default/views/_live_search.html.erb @@ -14,12 +14,10 @@ <script type="text/javascript"> //<![CDATA[ - new TextFieldWithExample('<%= search_input_id %>', '<%= as_(:live_search) %>'); + new TextFieldWithExample('<%= search_input_id %>', '<%= as_(:live_search) %>', {focus: true}); new Form.Element.Observer('<%= search_input_id %>', 1.5, function(element, value) { if (!$(element.id)) return false; // because the element may have been destroyed $(element).up('form').onsubmit(); }); - - Form.focusFirstElement('<%= search_form_id -%>'); //]]> </script> diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index 01b05c0e89..b1a71a10b0 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -15,7 +15,6 @@ <script type="text/javascript"> //<![CDATA[ - new TextFieldWithExample('<%= search_input_id %>', '<%= as_(:search_terms) %>'); - Form.focusFirstElement('<%= search_form_id -%>'); + new TextFieldWithExample('<%= search_input_id %>', '<%= as_(:search_terms) %>', {focus: true}); //]]> -</script> \ No newline at end of file +</script> From a5bded9a68f8dff3199f13de4575939f61376f83 Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Wed, 28 Oct 2009 12:33:44 +0100 Subject: [PATCH 0114/2024] add support for updating more than one column --- frontends/default/views/render_field.js.rjs | 14 ++++++++------ lib/active_scaffold/actions/core.rb | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/frontends/default/views/render_field.js.rjs b/frontends/default/views/render_field.js.rjs index 8453e7cefd..071ada8605 100644 --- a/frontends/default/views/render_field.js.rjs +++ b/frontends/default/views/render_field.js.rjs @@ -1,7 +1,9 @@ -column = @update_column -while column - field_id = active_scaffold_input_options(column, params[:scope])[:id] - page[field_id].up('dl').replace :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } - column = Hash === column.options ? column.options[:update_column] : nil - column = active_scaffold_config.columns[column] if column +@update_columns.each do |update_column| + column = update_column + while column + field_id = active_scaffold_input_options(column, params[:scope])[:id] + page[field_id].up('dl').replace :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } + column = Hash === column.options ? column.options[:update_column] : nil + column = active_scaffold_config.columns[column] if column + end end diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 239562e5bd..91c967d58a 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -14,7 +14,7 @@ def render_field params[:value] end @record.send "#{column.name}=", value - @update_column = active_scaffold_config.columns[column.options[:update_column]] + @update_columns = Array(column.options[:update_column]).collect {|column_name| active_scaffold_config.columns[column_name]} end protected From 57024eb4764ff811b12e7ac16fff90cc5d4d5326 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 28 Oct 2009 13:19:57 +0100 Subject: [PATCH 0115/2024] add action to class attribute in disabled action links --- frontends/default/views/_list_actions.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index e36fc3c150..d506284026 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -6,7 +6,7 @@ <% active_scaffold_config.action_links.each :record do |link| -%> <% next if skip_action_link(link) -%> <td> - <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options) : "<a class='disabled'>#{link.label}</a>" -%> + <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options) : "<a class='disabled #{link.action}'>#{link.label}</a>" -%> </td> <% end -%> </tr> From 68bd3718561d791fb37d0b6aab65a72713125688 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 28 Oct 2009 13:45:54 +0100 Subject: [PATCH 0116/2024] Fix set sorting from default_scope when direction is not set --- lib/active_scaffold/data_structures/sorting.rb | 2 +- test/data_structures/sorting_test.rb | 18 ++++++++++++++---- .../default/form_enhancements.js | 11 +++++++---- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index f5c1f2622a..7988ad28b8 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -149,7 +149,7 @@ def remove_quotes(sql_name) end def extract_direction(direction_part) - if direction_part.upcase == 'DESC' + if direction_part.to_s.upcase == 'DESC' 'DESC' else 'ASC' diff --git a/test/data_structures/sorting_test.rb b/test/data_structures/sorting_test.rb index da2890d58d..d6aaa87b57 100644 --- a/test/data_structures/sorting_test.rb +++ b/test/data_structures/sorting_test.rb @@ -103,10 +103,20 @@ def test_build_order_clause assert_equal 'model_stubs.a DESC, model_stubs.b ASC', @sorting.clause end - ModelStubWithDefaultScope = ModelStub.clone - ModelStubWithDefaultScope.class_eval { default_scope :order => 'a DESC, players.last_name ASC' } - def test_set_default_sorting_with_default_scope - @sorting.set_default_sorting ModelStubWithDefaultScope + def test_set_default_sorting_with_simple_default_scope + model_stub_with_default_scope = ModelStub.clone + model_stub_with_default_scope.class_eval { default_scope :order => 'a' } + @sorting.set_default_sorting model_stub_with_default_scope + + assert @sorting.sorts_on?(:a) + assert_equal 'ASC', @sorting.direction_of(:a) + assert_nil @sorting.clause + end + + def test_set_default_sorting_with_complex_default_scope + model_stub_with_default_scope = ModelStub.clone + model_stub_with_default_scope.class_eval { default_scope :order => 'a DESC, players.last_name ASC' } + @sorting.set_default_sorting model_stub_with_default_scope assert @sorting.sorts_on?(:a) assert_equal 'DESC', @sorting.direction_of(:a) diff --git a/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js b/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js index cab9997e9c..136c2c0e8f 100644 --- a/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +++ b/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js @@ -10,7 +10,12 @@ TextFieldWithExample.prototype = { this.defaultText = defaultText; this.createHiddenInput(); + if (options.focus) this.input.focus(); this.checkAndShowExample(); + if (options.focus) { + this.input.selectionStart = 0; + this.input.selectionEnd = 0; + } Event.observe(this.input, "blur", this.onBlur.bindAsEventListener(this)); Event.observe(this.input, "focus", this.onFocus.bindAsEventListener(this)); @@ -39,9 +44,7 @@ TextFieldWithExample.prototype = { this.checkAndShowExample(); }, onFocus: function(event) { - if (this.exampleShown()) { - this.removeExample(); - } + this.removeExample(); }, onClick: function(event) { this.removeExample(); @@ -57,7 +60,7 @@ TextFieldWithExample.prototype = { Element.addClassName(this.input, this.options.exampleClassName); } }, - removeExample: function() { + removeExample: function() { if (this.exampleShown()) { this.input.value = ''; this.input.name = this.name; From 963fe4f3f6fd89274a2aecd3e881c7938f3d10ec Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 28 Oct 2009 14:18:12 +0100 Subject: [PATCH 0117/2024] Fix links_for_associations for polymorphic associations --- lib/extensions/reverse_associations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extensions/reverse_associations.rb b/lib/extensions/reverse_associations.rb index fd169f7312..3b3c88aa33 100644 --- a/lib/extensions/reverse_associations.rb +++ b/lib/extensions/reverse_associations.rb @@ -7,7 +7,7 @@ def reverse_for?(klass) attr_writer :reverse def reverse - if @reverse.nil? + if @reverse.nil? and not self.options[:polymorphic] reverse_matches = reverse_matches_for(self.class_name.constantize) # grab first association, or make a wild guess @reverse = reverse_matches.empty? ? false : reverse_matches.first.name From ec484e0a6d92f02e40d587d3f1c833e40b9c1630 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 29 Oct 2009 10:23:58 +0100 Subject: [PATCH 0118/2024] Set url for return_to_main in a helper to use it for cancel links and return_to_main in controller --- .../default/views/_add_existing_form.html.erb | 2 +- frontends/default/views/_create_form.html.erb | 2 +- frontends/default/views/_show.html.erb | 2 +- frontends/default/views/_update_form.html.erb | 2 +- frontends/default/views/delete.html.erb | 2 +- lib/active_scaffold/actions/core.rb | 9 +-------- .../helpers/controller_helpers.rb | 18 +++++++++++++++++- 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/frontends/default/views/_add_existing_form.html.erb b/frontends/default/views/_add_existing_form.html.erb index 73687e897d..94c21135b6 100644 --- a/frontends/default/views/_add_existing_form.html.erb +++ b/frontends/default/views/_add_existing_form.html.erb @@ -30,7 +30,7 @@ <p class="form-footer"> <%= submit_tag as_(:add), :class => "submit" %> - <%= link_to as_(:cancel), params_for(:action => 'list'), :class => 'cancel' %> + <%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %> <%= loading_indicator_tag(:action => :add_existing, :id => params[:id]) %> </p> diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index 2afc73d1c9..f8ea9b0572 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -41,7 +41,7 @@ end -%> <p class="form-footer"> <%= submit_tag as_(:create), :class => "submit" %> - <%= link_to as_(:cancel), params_for(:controller => params[:parent_controller] ? params[:parent_controller] : params[:controller], :action => 'list', :eid => params[:parent_controller] ? params[:parent_controller] : params[:eid], :id => nil), :class => 'cancel' %> + <%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %> <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> </p> diff --git a/frontends/default/views/_show.html.erb b/frontends/default/views/_show.html.erb index 4bdb2f8475..14848254bf 100644 --- a/frontends/default/views/_show.html.erb +++ b/frontends/default/views/_show.html.erb @@ -3,6 +3,6 @@ <%= render :partial => 'show_columns', :locals => {:columns => active_scaffold_config.show.columns} -%> <p class="form-footer"> - <%= link_to as_(:close), params_for(:controller => params[:parent_controller] ? params[:parent_controller] : params[:controller], :action => 'list', :id => nil), :class => 'cancel' %> + <%= link_to as_(:close), main_path_to_return, :class => 'cancel' %> <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> </p> \ No newline at end of file diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index c8c45a4230..1163b08b35 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -45,7 +45,7 @@ end <p class="form-footer"> <%= submit_tag as_(:update), :class => "submit" %> - <%= link_to as_(:cancel), params_for(:controller => params[:parent_controller] ? params[:parent_controller] : params[:controller], :action => 'list', :id => nil), :class => 'cancel' %> + <%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %> <%= loading_indicator_tag(:action => :update, :id => params[:id]) %> </p> diff --git a/frontends/default/views/delete.html.erb b/frontends/default/views/delete.html.erb index bf85bd7f8a..bccc1b2840 100644 --- a/frontends/default/views/delete.html.erb +++ b/frontends/default/views/delete.html.erb @@ -5,7 +5,7 @@ <p class="form-footer"> <%= submit_tag as_(:delete), :class => 'submit' %> - <%= link_to as_(:cancel), params_for(:action => 'index'), :class => 'cancel' %> + <%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %> </p> </form> diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index ab7016cb2c..79b466c40a 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -75,14 +75,7 @@ def successful=(val) # Redirect to the main page (override if the ActiveScaffold is used as a component on another controllers page) for Javascript degradation def return_to_main - unless params[:parent_controller].nil? - params[:controller] = params[:parent_controller] - params[:eid] = nil - params[:parent_model] = nil - params[:parent_column] = nil - params[:parent_id] = nil - end - redirect_to params_for(:action => "index", :id => nil) + redirect_to main_path_to_return end # Override this method on your controller to define conditions to be used when querying a recordset (e.g. for List). The return of this method should be any format compatible with the :conditions clause of ActiveRecord::Base's find. diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index cefac09f60..a6d47b1b74 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Helpers module ControllerHelpers def self.included(controller) - controller.class_eval { helper_method :params_for } + controller.class_eval { helper_method :params_for, :main_path_to_return } end include ActiveScaffold::Helpers::IdHelpers @@ -20,6 +20,22 @@ def params_for(options = {}) end @params_for.merge(options) end + + # Parameters to generate url to the main page (override if the ActiveScaffold is used as a component on another controllers page) + def main_path_to_return + parameters = params.clone + if params[:parent_controller] + parameters[:controller] = params[:parent_controller] + parameters[:eid] = params[:parent_controller] + end + parameters[:nested] = nil + parameters[:parent_model] = nil + parameters[:parent_column] = nil + parameters[:parent_id] = nil + parameters[:action] = "index" + parameters[:id] = nil + params_for(parameters) + end end end end From 2d95e2f61c6729865c1d1d96d73ba50e676ee897 Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Thu, 29 Oct 2009 15:26:07 +0100 Subject: [PATCH 0119/2024] fixed nil exception in case of an unknown column in params added hook after_render_field --- lib/active_scaffold/actions/core.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 79b466c40a..885ab4c101 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -7,17 +7,25 @@ def self.included(base) end def render_field @record = active_scaffold_config.model.new + @update_columns = [] column = active_scaffold_config.columns[params[:column]] - value = if column.association - params[:value].blank? ? nil : column.association.klass.find(params[:value]) - else - params[:value] + unless column.nil? + value = if column.association + params[:value].blank? ? nil : column.association.klass.find(params[:value]) + else + params[:value] + end + @record.send "#{column.name}=", value + @update_columns << Array(column.options[:update_column]).collect {|column_name| active_scaffold_config.columns[column_name]} + @update_columns.flatten! + after_render_field(@record, column) end - @record.send "#{column.name}=", value - @update_columns = Array(column.options[:update_column]).collect {|column_name| active_scaffold_config.columns[column_name]} end protected + + # override this method if you want to do something after render_field + def after_render_field(record, column); end def authorized_for?(*args) active_scaffold_config.model.authorized_for?(*args) From 70cad8842f4c97cda7127970defe7c83f466596c Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Fri, 6 Nov 2009 17:08:37 +0100 Subject: [PATCH 0120/2024] show loading indicator in case of update column --- frontends/default/views/_form_attribute.html.erb | 3 +++ .../helpers/form_column_helpers.rb | 16 ++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/frontends/default/views/_form_attribute.html.erb b/frontends/default/views/_form_attribute.html.erb index 64264430bc..b25037301f 100644 --- a/frontends/default/views/_form_attribute.html.erb +++ b/frontends/default/views/_form_attribute.html.erb @@ -5,6 +5,9 @@ </dt> <dd> <%= active_scaffold_input_for column, scope %> + <% if column.options.is_a?(Hash) && column.options[:update_column] -%> + <%= loading_indicator_tag(:action => :render_field, :id => params[:id]) %> + <% end -%> <% if column.description -%> <span class="description"><%= column.description %></span> <% end -%> diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index beb0dbb329..4a34e0a782 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -62,13 +62,17 @@ def active_scaffold_input_options(column, scope = nil) def javascript_for_update_column(column, scope, options) if column.options.is_a?(Hash) && column.options[:update_column] - url_params = {:action => 'render_field', :id => params[:id]} + form_action = :create + form_action = :update if params[:action] == 'edit' + url_params = {:action => 'render_field', :id => params[:id], :column => column.name} + url_params[:eid] = params[:eid] if params[:eid] url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope - - parameters = "column=#{column.name}" - parameters << "&eid=#{params[:eid]}" if params[:eid] - parameters << "&scope=#{scope}" if scope - options[:onchange] = "new Ajax.Request(#{url_for(url_params).to_json}, {parameters: '#{parameters}&value=' + this.value, method: 'get'});#{options[:onchange]}" + url_params[:scope] = params[:scope] if scope + ajax_options = {:method => :get, + :url => url_for(url_params), :with => "'value=' + this.value", + :after => "$('#{loading_indicator_id(:action => :render_field, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => form_action)}');", + :complete => "$('#{loading_indicator_id(:action => :render_field, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => form_action)}');"} + options[:onchange] = "#{remote_function(ajax_options)};#{options[:onchange]}" end options end From 991081cbfe6be10bda2e7ab9a4c69c4fbaf29686 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 6 Nov 2009 17:28:30 +0100 Subject: [PATCH 0121/2024] Add deprecation warnings --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 4a34e0a782..3a3cfbbc24 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -98,6 +98,7 @@ def active_scaffold_input_singular_association(column, html_options) html_options.update(column.options[:html_options]) options.update(column.options) else + Rails.logger.warn "ActiveScaffold: Setting html options directly in a hash is deprecated for :select form_ui. Set the html options hash under html_options key, such as config.columns[:column_name].options = {:html_options => {...}, ...}" html_options.update(column.options) end select(:record, method, select_options.uniq, options, html_options) @@ -140,6 +141,7 @@ def active_scaffold_input_select(column, html_options) html_options.update(column.options[:html_options] || {}) options.update(column.options) else + Rails.logger.warn "ActiveScaffold: Setting the options array directly is deprecated for :select form_ui. Set the options array in a hash under options key, such as config.columns[:column_name].options = {:options => [...], ...}" options_for_select = column.options end select(:record, column.name, options_for_select, options, html_options) From 32a20b984d6837a70863c8a4f119be3ea52f551c Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Tue, 10 Nov 2009 11:57:29 +0100 Subject: [PATCH 0122/2024] Set css_class in li instead of dl --- frontends/default/views/_form.html.erb | 6 +++--- frontends/default/views/_form_attribute.html.erb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index fee5086dac..23261447e2 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -1,16 +1,16 @@ <ol class="form" <%= 'style="display: none;"' if columns.collapsed -%>> <% columns.each :for => @record do |column| -%> <% if is_subsection? column -%> - <li class="sub-section"> + <li class="sub-section <%= column.css_class unless column.css_class.nil? %>"> <h5><%= column.label %> (<%= link_to_visibility_toggle(:default_visible => !column.collapsed) -%>)</h5> <%= render :partial => 'form', :locals => { :columns => column } %> </li> <% elsif is_subform? column and !override_form_field?(column) -%> - <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form" id="<%= sub_form_id(:association => column.name) %>"> + <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? %>" id="<%= sub_form_id(:association => column.name) %>"> <%= render :partial => form_partial_for_column(column), :locals => { :column => column } -%> </li> <% else -%> - <li class="form-element <%= 'required' if column.required? %>"> + <li class="form-element <%= 'required' if column.required? %> <%= column.css_class unless column.css_class.nil? %>"> <%= render :partial => form_partial_for_column(column), :locals => { :column => column } -%> </li> <% end -%> diff --git a/frontends/default/views/_form_attribute.html.erb b/frontends/default/views/_form_attribute.html.erb index b25037301f..821d97843d 100644 --- a/frontends/default/views/_form_attribute.html.erb +++ b/frontends/default/views/_form_attribute.html.erb @@ -1,5 +1,5 @@ <% scope ||= nil %> -<dl class="<%= column.css_class unless column.css_class.nil? %>"> +<dl> <dt> <label for="<%= active_scaffold_input_options(column, scope)[:id] %>"><%= column.label %></label> </dt> From 829428114f9e2385a836b281ae0a033081e09bbd Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Wed, 11 Nov 2009 16:23:00 +0100 Subject: [PATCH 0123/2024] Enable inplace_edit for additional form_uis, such as calendar_date_select, boolean, belongs_to assoc, select --- .../default/javascripts/active_scaffold.js | 91 +++++++++++++++++++ .../views/_list_column_headings.html.erb | 1 + lib/active_scaffold/actions/update.rb | 6 +- .../helpers/list_column_helpers.rb | 70 +++++++++++++- 4 files changed, 163 insertions(+), 5 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index c99efa1644..bebb03bac1 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -432,3 +432,94 @@ ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.Act if (event) Event.stop(event); } }); + +ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { + initialize: function($super, element, url, options) { + $super(element, url, options); + }, + + createEditField: function() { + var text = (this.options.loadTextURL ? this.options.loadingText : this.getText()); + var fld; + var patternNodes = null; + if (this.options.inplacePatternSelector) { + patternNodes = this.getPatternNodes(this.options.inplacePatternSelector); + //var editNode = $('record_first_name_'); + if (!(patternNodes.editNode == null)) { + fld = patternNodes.editNode.cloneNode(true); + if (fld.id.length > 0) { + fld.id = fld.id + this.options.nodeIdSuffix; + } + } else { + alert('did not find any matching node for ' + this.options.editFieldSelector); + } + } else if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) { + fld = document.createElement('input'); + fld.type = 'text'; + var size = this.options.size || this.options.cols || 0; + if (0 < size) fld.size = size; + } else { + fld = document.createElement('textarea'); + fld.rows = (1 >= this.options.rows ? this.options.autoRows : this.options.rows); + fld.cols = this.options.cols || 40; + } + fld.name = this.options.paramName; + fld.className = 'editor_field'; + this.setValue(fld, text); + if (this.options.submitOnBlur) + fld.onblur = this._boundSubmitHandler; + this._controls.editor = fld; + if (this.options.loadTextURL) + this.loadExternalText(); + this._form.appendChild(this._controls.editor); + if (patternNodes != null) { + var patternNode; + for(var i=0; i < patternNodes.additionalNodes.length; i++) { + patternNode = patternNodes.additionalNodes[i].cloneNode(true); + if (patternNode.id.length > 0) { + patternNode.id = patternNode.id + this.options.nodeIdSuffix; + } + this._form.appendChild(patternNode); + } + } + }, + + getPatternNodes: function(inplacePatternSelector) { + var nodes = {editNode: null, additionalNodes: []}; + var selectedNodes = $$(inplacePatternSelector); + var firstNode = selectedNodes.first(); + + if (typeof(firstNode) !== 'undefined') { + // AS inplace_edit_control_container -> we have to select all child nodes + // Workaround for ie which does not support css > selector + if (firstNode.className.indexOf('as_inplace_pattern') !== -1) { + selectedNodes = firstNode.childElements(); + } + nodes.editNode = selectedNodes.first(); + selectedNodes.shift(); + nodes.additionalNodes = selectedNodes; + + } + return nodes; + }, + + setValue: function(editField, textValue) { + var function_name = 'setValueFor' + editField.nodeName.toLowerCase(); + if (typeof(this[function_name]) == 'function') { + this[function_name](editField, textValue); + } else { + editField.value = textValue; + } + }, + + setValueForselect: function(editField, textValue) { + var len = editField.options.length; + var i = 0; + while (i < len && editField.options[i].text != textValue) { + i++; + } + if (i < len) { + editField.value = editField.options[i].value + } + } +}); diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index 96a3b96287..306eed9360 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -26,6 +26,7 @@ default_sorting_stages = ['ASC', 'DESC'] <% else -%> <p><%= column.label %></p> <% end -%> + <%= inplace_edit_control(column) -%> </th> <% end -%> <th class="actions"> diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 13cb6e3cd3..8d6569d2f3 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -94,7 +94,11 @@ def do_update def do_update_column @record = active_scaffold_config.model.find(params[:id]) if @record.authorized_for?(:action => :update, :column => params[:column]) - params[:value] ||= @record.column_for_attribute(params[:column]).default unless @record.column_for_attribute(params[:column]).null + column = active_scaffold_config.columns[params[:column].to_sym] + params[:value] ||= @record.column_for_attribute(params[:column]).default unless @record.column_for_attribute(params[:column]).nil? || @record.column_for_attribute(params[:column]).null + if !column.nil? && column.association + params[:value] = params[:value].blank? ? nil : column.association.klass.find(params[:value]) + end @record.send("#{params[:column]}=", params[:value]) @record.save end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index a3cbbade1c..ef8ca6556e 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -14,7 +14,7 @@ def get_column_value(record, column) elsif column.list_ui and override_column_ui?(column.list_ui) send(override_column_ui(column.list_ui), column, record) - elsif column.inplace_edit and record.authorized_for?(:action => :update, :column => column.name) + elsif inplace_edit?(record, column) active_scaffold_inplace_edit(record, column) elsif column.column and override_column_ui?(column.column.type) send(override_column_ui(column.column.type), column, record) @@ -26,7 +26,6 @@ def get_column_value(record, column) return value end - # TODO: move empty_field_text and   logic in here? # TODO: move active_scaffold_inplace_edit in here? # TODO: we need to distinguish between the automatic links *we* create and the ones that the dev specified. some logic may not apply if the dev specified the link. @@ -183,6 +182,8 @@ def format_value(column_value, options = {}) active_scaffold_config.list.empty_field_text elsif column_value.is_a?(Time) || column_value.is_a?(Date) l(column_value, :format => options[:format] || :default) + elsif [FalseClass, TrueClass].include?(column_value.class) + as_(column_value.to_s.to_sym) else column_value.to_s end @@ -204,6 +205,11 @@ def cache_association(value, column) # ========== # = Inline Edit = # ========== + + def inplace_edit?(record, column) + column.inplace_edit and record.authorized_for?(:action => :update, :column => column.name) + end + def format_inplace_edit_column(record,column) value = record.send(column.name) if column.list_ui == :checkbox @@ -225,8 +231,64 @@ def active_scaffold_inplace_edit(record, column) :save_text => as_(:update), :saving_text => as_(:saving), :options => "{method: 'post'}", - :script => true}.merge(column.options) - content_tag(:span, formatted_column, tag_options) + in_place_editor(tag_options[:id], in_place_editor_options) + :script => true, + :inplace_pattern_selector => "##{active_scaffold_column_header_id(column)} .#{inplace_edit_control_css_class}", + :node_id_suffix => record.id.to_s}.merge(column.options) + content_tag(:span, formatted_column, tag_options) + active_scaffold_in_place_editor(tag_options[:id], in_place_editor_options) + end + + def inplace_edit_control(column) + @record = active_scaffold_config.model.new + edit_control = '' + if inplace_edit?(@record, column) + update_column_option = column.options.delete(:update_column) + orig_form_ui = column.form_ui + column.form_ui = :select if (column.association && column.form_ui.nil?) || column.form_ui == :record_select + edit_control = content_tag(:div, active_scaffold_input_for(column), {:style => "display:none;", :class => inplace_edit_control_css_class}) + column.options[:update_column] = update_column_option unless update_column_option.nil? + column.form_ui = orig_form_ui + end + @record = nil + edit_control + end + + def inplace_edit_control_css_class + "as_inplace_pattern" + end + + def active_scaffold_in_place_editor(field_id, options = {}) + function = "new ActiveScaffold.InPlaceEditor(" + function << "'#{field_id}', " + function << "'#{url_for(options[:url])}'" + + js_options = {} + + if protect_against_forgery? + options[:with] ||= "Form.serialize(form)" + options[:with] += " + '&authenticity_token=' + encodeURIComponent('#{form_authenticity_token}')" + end + + js_options['cancelText'] = %('#{options[:cancel_text]}') if options[:cancel_text] + js_options['okText'] = %('#{options[:save_text]}') if options[:save_text] + js_options['loadingText'] = %('#{options[:loading_text]}') if options[:loading_text] + js_options['savingText'] = %('#{options[:saving_text]}') if options[:saving_text] + js_options['rows'] = options[:rows] if options[:rows] + js_options['cols'] = options[:cols] if options[:cols] + js_options['size'] = options[:size] if options[:size] + js_options['externalControl'] = "'#{options[:external_control]}'" if options[:external_control] + js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url] + js_options['ajaxOptions'] = options[:options] if options[:options] + js_options['htmlResponse'] = !options[:script] if options[:script] + js_options['callback'] = "function(form) { return #{options[:with]} }" if options[:with] + js_options['clickToEditText'] = %('#{options[:click_to_edit_text]}') if options[:click_to_edit_text] + js_options['textBetweenControls'] = %('#{options[:text_between_controls]}') if options[:text_between_controls] + js_options['inplacePatternSelector'] = %('#{options[:inplace_pattern_selector]}') if options[:inplace_pattern_selector] + js_options['nodeIdSuffix'] = %('#{options[:node_id_suffix]}') if options[:node_id_suffix] + function << (', ' + options_for_javascript(js_options)) unless js_options.empty? + + function << ')' + + javascript_tag(function) end end From ed242d210425d6a08e26f06ba15bb010ddc15ec7 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 12 Nov 2009 10:42:58 +0100 Subject: [PATCH 0124/2024] clone column instead of modify it --- .../helpers/form_column_helpers.rb | 2 +- .../helpers/list_column_helpers.rb | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 3a3cfbbc24..ed71802fde 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -72,7 +72,7 @@ def javascript_for_update_column(column, scope, options) :url => url_for(url_params), :with => "'value=' + this.value", :after => "$('#{loading_indicator_id(:action => :render_field, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => form_action)}');", :complete => "$('#{loading_indicator_id(:action => :render_field, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => form_action)}');"} - options[:onchange] = "#{remote_function(ajax_options)};#{options[:onchange]}" + options[:onchange] = "#{remote_function(ajax_options)};#{options[:onchange]}" end options end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index ef8ca6556e..7e6aee86ab 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -238,18 +238,13 @@ def active_scaffold_inplace_edit(record, column) end def inplace_edit_control(column) - @record = active_scaffold_config.model.new - edit_control = '' - if inplace_edit?(@record, column) - update_column_option = column.options.delete(:update_column) - orig_form_ui = column.form_ui + if inplace_edit?(active_scaffold_config.model, column) + column = column.clone + column.options = column.options.clone + column.options.delete(:update_column) column.form_ui = :select if (column.association && column.form_ui.nil?) || column.form_ui == :record_select - edit_control = content_tag(:div, active_scaffold_input_for(column), {:style => "display:none;", :class => inplace_edit_control_css_class}) - column.options[:update_column] = update_column_option unless update_column_option.nil? - column.form_ui = orig_form_ui + content_tag(:div, active_scaffold_input_for(column), {:style => "display:none;", :class => inplace_edit_control_css_class}) end - @record = nil - edit_control end def inplace_edit_control_css_class From b84b487cc56e695dc5a79f6e38b2179e01a2973b Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 12 Nov 2009 10:58:31 +0100 Subject: [PATCH 0125/2024] Redirect to new if create is persistent --- lib/active_scaffold/actions/create.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 27771b5b64..d6ccbe4fd9 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -54,6 +54,8 @@ def create_respond_to_html flash[:info] = as_(:created_model, :model => @record.to_label) if active_scaffold_config.create.edit_after_create redirect_to params_for(:action => "edit", :id => @record.id) + elsif active_scaffold_config.create.persistent + redirect_to params_for(:action => "new") else return_to_main end From 5a12b18958fa7e99786bb9dbb8c9ef11f112a25f Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 12 Nov 2009 15:47:28 +0100 Subject: [PATCH 0126/2024] Clear column link when inplace_edit is enabled --- lib/active_scaffold/data_structures/column.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 809b57c8be..3dcd00c0b4 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -8,7 +8,11 @@ class Column attr_accessor :name # Whether to enable inplace editing for this column. Currently works for text columns, in the List. - attr_accessor :inplace_edit + attr_reader :inplace_edit + def inplace_edit=(value) + self.clear_link if value + @inplace_edit = value + end # Whether this column set is collapsed by default in contexts where collapsing is supported attr_accessor :collapsed From c59330023330550c6ca7e9382eadf2adda342c88 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 12 Nov 2009 16:46:41 +0100 Subject: [PATCH 0127/2024] Don't override code from Ajax.InPlaceEditor when inplacePatternSelector --- .../default/javascripts/active_scaffold.js | 60 +++++++------------ .../helpers/list_column_helpers.rb | 1 + 2 files changed, 24 insertions(+), 37 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index bebb03bac1..6cda680059 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -438,49 +438,36 @@ ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { $super(element, url, options); }, - createEditField: function() { - var text = (this.options.loadTextURL ? this.options.loadingText : this.getText()); - var fld; - var patternNodes = null; + createEditField: function($super) { if (this.options.inplacePatternSelector) { - patternNodes = this.getPatternNodes(this.options.inplacePatternSelector); - //var editNode = $('record_first_name_'); - if (!(patternNodes.editNode == null)) { - fld = patternNodes.editNode.cloneNode(true); - if (fld.id.length > 0) { - fld.id = fld.id + this.options.nodeIdSuffix; - } - } else { + var patternNodes = this.getPatternNodes(this.options.inplacePatternSelector); + if (patternNodes.editNode == null) { alert('did not find any matching node for ' + this.options.editFieldSelector); + return; } - } else if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) { - fld = document.createElement('input'); - fld.type = 'text'; - var size = this.options.size || this.options.cols || 0; - if (0 < size) fld.size = size; - } else { - fld = document.createElement('textarea'); - fld.rows = (1 >= this.options.rows ? this.options.autoRows : this.options.rows); - fld.cols = this.options.cols || 40; - } - fld.name = this.options.paramName; - fld.className = 'editor_field'; - this.setValue(fld, text); - if (this.options.submitOnBlur) - fld.onblur = this._boundSubmitHandler; - this._controls.editor = fld; - if (this.options.loadTextURL) - this.loadExternalText(); - this._form.appendChild(this._controls.editor); - if (patternNodes != null) { - var patternNode; - for(var i=0; i < patternNodes.additionalNodes.length; i++) { - patternNode = patternNodes.additionalNodes[i].cloneNode(true); + + var text = (this.options.loadTextURL ? this.options.loadingText : this.getText()); + var fld = patternNodes.editNode.cloneNode(true); + if (fld.id.length > 0) fld.id += this.options.nodeIdSuffix; + fld.name = this.options.paramName; + fld.className = 'editor_field'; + this.setValue(fld, text); + if (this.options.submitOnBlur) + fld.onblur = this._boundSubmitHandler; + this._controls.editor = fld; + if (this.options.loadTextURL) + this.loadExternalText(); + this._form.appendChild(this._controls.editor); + + $A(patternNodes.additionalNodes).each(function(node) { + var patternNode = node.cloneNode(true); if (patternNode.id.length > 0) { patternNode.id = patternNode.id + this.options.nodeIdSuffix; } this._form.appendChild(patternNode); - } + }.bind(this)); + } else { + $super(); } }, @@ -498,7 +485,6 @@ ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { nodes.editNode = selectedNodes.first(); selectedNodes.shift(); nodes.additionalNodes = selectedNodes; - } return nodes; }, diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 7e6aee86ab..336e056eff 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -239,6 +239,7 @@ def active_scaffold_inplace_edit(record, column) def inplace_edit_control(column) if inplace_edit?(active_scaffold_config.model, column) + @record = active_scaffold_config.model.new column = column.clone column.options = column.options.clone column.options.delete(:update_column) From b9d6d975c3a24a534606f4e333d828caa0589109 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 13 Nov 2009 09:16:28 +0100 Subject: [PATCH 0128/2024] Show calculation function next to the value (fix issue #712) --- frontends/default/views/_list_calculations.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_calculations.html.erb b/frontends/default/views/_list_calculations.html.erb index 0f07158f38..a3becfab68 100644 --- a/frontends/default/views/_list_calculations.html.erb +++ b/frontends/default/views/_list_calculations.html.erb @@ -10,7 +10,7 @@ calculation = self.method(override_formatter).call(calculation) if respond_to? override_formatter -%> - <%= calculation.to_s %> + <%= as_(column.calculate) %>: <%= calculation.to_s %> <% else -%>   <% end -%> From 1a6d8976f83aa359ce40997fcae9c303027a13b7 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 13 Nov 2009 11:34:16 +0100 Subject: [PATCH 0129/2024] Fix add_subgroup --- frontends/default/views/_form.html.erb | 2 +- frontends/default/views/_show_columns.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index 23261447e2..238adef474 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -1,7 +1,7 @@ <ol class="form" <%= 'style="display: none;"' if columns.collapsed -%>> <% columns.each :for => @record do |column| -%> <% if is_subsection? column -%> - <li class="sub-section <%= column.css_class unless column.css_class.nil? %>"> + <li class="sub-section"> <h5><%= column.label %> (<%= link_to_visibility_toggle(:default_visible => !column.collapsed) -%>)</h5> <%= render :partial => 'form', :locals => { :columns => column } %> </li> diff --git a/frontends/default/views/_show_columns.html.erb b/frontends/default/views/_show_columns.html.erb index f603221779..5cd3d0de23 100644 --- a/frontends/default/views/_show_columns.html.erb +++ b/frontends/default/views/_show_columns.html.erb @@ -1,7 +1,7 @@ <dl> <% columns.each :for => @record do |column| %> <dt><%= column.label -%></dt> - <dd class="<%=column.name%>-view <%= column.css_class %>"> + <dd<%= " class=\"#{column.name}-view #{column.css_class}\"" unless column.is_a? ActiveScaffold::DataStructures::ActionColumns %>> <% if column.is_a? ActiveScaffold::DataStructures::ActionColumns -%> <%= render :partial => 'show_columns', :locals => {:columns => column} %> <% else -%> From c52bb7dd38cc4bfbf0d28900ccdc23061d7eccb1 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 13 Nov 2009 11:35:01 +0100 Subject: [PATCH 0130/2024] Change inplace_edit to load the fields using AJAX call to render_field action in onFormCustomization callback. It enables to use record_select form_ui with in place editing --- .../default/javascripts/active_scaffold.js | 77 ------------------- .../views/_list_column_headings.html.erb | 1 - lib/active_scaffold/actions/core.rb | 8 +- .../helpers/form_column_helpers.rb | 16 ++-- .../helpers/list_column_helpers.rb | 69 ++++++++++------- 5 files changed, 53 insertions(+), 118 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 6cda680059..c99efa1644 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -432,80 +432,3 @@ ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.Act if (event) Event.stop(event); } }); - -ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { - initialize: function($super, element, url, options) { - $super(element, url, options); - }, - - createEditField: function($super) { - if (this.options.inplacePatternSelector) { - var patternNodes = this.getPatternNodes(this.options.inplacePatternSelector); - if (patternNodes.editNode == null) { - alert('did not find any matching node for ' + this.options.editFieldSelector); - return; - } - - var text = (this.options.loadTextURL ? this.options.loadingText : this.getText()); - var fld = patternNodes.editNode.cloneNode(true); - if (fld.id.length > 0) fld.id += this.options.nodeIdSuffix; - fld.name = this.options.paramName; - fld.className = 'editor_field'; - this.setValue(fld, text); - if (this.options.submitOnBlur) - fld.onblur = this._boundSubmitHandler; - this._controls.editor = fld; - if (this.options.loadTextURL) - this.loadExternalText(); - this._form.appendChild(this._controls.editor); - - $A(patternNodes.additionalNodes).each(function(node) { - var patternNode = node.cloneNode(true); - if (patternNode.id.length > 0) { - patternNode.id = patternNode.id + this.options.nodeIdSuffix; - } - this._form.appendChild(patternNode); - }.bind(this)); - } else { - $super(); - } - }, - - getPatternNodes: function(inplacePatternSelector) { - var nodes = {editNode: null, additionalNodes: []}; - var selectedNodes = $$(inplacePatternSelector); - var firstNode = selectedNodes.first(); - - if (typeof(firstNode) !== 'undefined') { - // AS inplace_edit_control_container -> we have to select all child nodes - // Workaround for ie which does not support css > selector - if (firstNode.className.indexOf('as_inplace_pattern') !== -1) { - selectedNodes = firstNode.childElements(); - } - nodes.editNode = selectedNodes.first(); - selectedNodes.shift(); - nodes.additionalNodes = selectedNodes; - } - return nodes; - }, - - setValue: function(editField, textValue) { - var function_name = 'setValueFor' + editField.nodeName.toLowerCase(); - if (typeof(this[function_name]) == 'function') { - this[function_name](editField, textValue); - } else { - editField.value = textValue; - } - }, - - setValueForselect: function(editField, textValue) { - var len = editField.options.length; - var i = 0; - while (i < len && editField.options[i].text != textValue) { - i++; - } - if (i < len) { - editField.value = editField.options[i].value - } - } -}); diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index 306eed9360..96a3b96287 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -26,7 +26,6 @@ default_sorting_stages = ['ASC', 'DESC'] <% else -%> <p><%= column.label %></p> <% end -%> - <%= inplace_edit_control(column) -%> </th> <% end -%> <th class="actions"> diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 885ab4c101..9fca336c5b 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -6,17 +6,19 @@ def self.included(base) end end def render_field - @record = active_scaffold_config.model.new + @record = active_scaffold_config.model.send(params[:in_place_editing] ? :find : :new, params[:id]) @update_columns = [] column = active_scaffold_config.columns[params[:column]] - unless column.nil? + if params[:in_place_editing] + render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>" + elsif !column.nil? value = if column.association params[:value].blank? ? nil : column.association.klass.find(params[:value]) else params[:value] end @record.send "#{column.name}=", value - @update_columns << Array(column.options[:update_column]).collect {|column_name| active_scaffold_config.columns[column_name]} + @update_columns << Array(params[:update_column]).collect {|column_name| active_scaffold_config.columns[column_name.to_sym]} @update_columns.flatten! after_render_field(@record, column) end diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index ed71802fde..d6faee4ccc 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -64,7 +64,7 @@ def javascript_for_update_column(column, scope, options) if column.options.is_a?(Hash) && column.options[:update_column] form_action = :create form_action = :update if params[:action] == 'edit' - url_params = {:action => 'render_field', :id => params[:id], :column => column.name} + url_params = {:action => 'render_field', :id => params[:id], :column => column.name, :update_column => column.options[:update_column]} url_params[:eid] = params[:eid] if params[:eid] url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope url_params[:scope] = params[:scope] if scope @@ -148,10 +148,7 @@ def active_scaffold_input_select(column, html_options) end end - # only works for singular associations - # requires RecordSelect plugin to be installed and configured. - # ... maybe this should be provided in a bridge? - def active_scaffold_input_record_select(column, options) + def active_scaffold_input_record_select_options(column, options) unless column.association raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)." end @@ -163,10 +160,13 @@ def active_scaffold_input_record_select(column, options) params.merge!({column.association.primary_key_name => ''}) end - record_select_options = {:controller => remote_controller, :id => options[:id]} - record_select_options.merge!(active_scaffold_input_text_options) - record_select_options.merge!(column.options) + active_scaffold_input_text_options({:controller => remote_controller, :id => options[:id]}.merge!(column.options)) + end + # requires RecordSelect plugin to be installed and configured. + # ... maybe this should be provided in a bridge? + def active_scaffold_input_record_select(column, options) + record_select_options = active_scaffold_input_record_select_options(column, options) if column.singular_association? record_select_field(options[:name], (@record.send(column.name) || column.association.klass.new), record_select_options) elsif column.plural_association? diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 336e056eff..51384881b3 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -223,37 +223,39 @@ def active_scaffold_inplace_edit(record, column) formatted_column = format_inplace_edit_column(record,column) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} tag_options = {:tag => "span", :id => element_cell_id(id_options), :class => "in_place_editor_field"} - in_place_editor_options = {:url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s}, - :with => params[:eid] ? "Form.serialize(form) + '&eid=#{params[:eid]}'" : nil, - :click_to_edit_text => as_(:click_to_edit), - :cancel_text => as_(:cancel), - :loading_text => as_(:loading), - :save_text => as_(:update), - :saving_text => as_(:saving), - :options => "{method: 'post'}", - :script => true, - :inplace_pattern_selector => "##{active_scaffold_column_header_id(column)} .#{inplace_edit_control_css_class}", - :node_id_suffix => record.id.to_s}.merge(column.options) - content_tag(:span, formatted_column, tag_options) + active_scaffold_in_place_editor(tag_options[:id], in_place_editor_options) - end - - def inplace_edit_control(column) - if inplace_edit?(active_scaffold_config.model, column) - @record = active_scaffold_config.model.new - column = column.clone - column.options = column.options.clone - column.options.delete(:update_column) - column.form_ui = :select if (column.association && column.form_ui.nil?) || column.form_ui == :record_select - content_tag(:div, active_scaffold_input_for(column), {:style => "display:none;", :class => inplace_edit_control_css_class}) + in_place_editor_options = { + :url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s}, + :with => params[:eid] ? "Form.serialize(form) + '&eid=#{params[:eid]}'" : nil, + :click_to_edit_text => as_(:click_to_edit), + :cancel_text => as_(:cancel), + :loading_text => as_(:loading), + :save_text => as_(:update), + :saving_text => as_(:saving), + :options => "{method: 'post'}", + :script => true + } + + if override_form_field?(column) or column.form_ui + ajax_options = { + :method => :get, + :url => {:action => 'render_field', :id => record.id, :column => column.name, :update_column => column.name, :in_place_editing => true}, + :complete => %| +element._form.insert({top: request.responseText}); +var fld = element._form.findFirstElement(); +element._controls.editor = fld; +fld.name = element.options.paramName; +fld.className = 'editor_field'; +if (element.options.submitOnBlur) fld.onblur = ipe._boundSubmitHandler; + |} + in_place_editor_options[:form_customization] = "element._controls.editor.remove(); #{remote_function(ajax_options)}" end - end - - def inplace_edit_control_css_class - "as_inplace_pattern" + + in_place_editor_options.merge!(column.options) + content_tag(:span, formatted_column, tag_options) + active_scaffold_in_place_editor(tag_options[:id], in_place_editor_options) end def active_scaffold_in_place_editor(field_id, options = {}) - function = "new ActiveScaffold.InPlaceEditor(" + function = "new Ajax.InPlaceEditor(" function << "'#{field_id}', " function << "'#{url_for(options[:url])}'" @@ -266,20 +268,29 @@ def active_scaffold_in_place_editor(field_id, options = {}) js_options['cancelText'] = %('#{options[:cancel_text]}') if options[:cancel_text] js_options['okText'] = %('#{options[:save_text]}') if options[:save_text] + js_options['okControl'] = %('#{options[:save_control_type]}') if options[:save_control_type] + js_options['cancelControl'] = %('#{options[:cancel_control_type]}') if options[:cancel_control_type] js_options['loadingText'] = %('#{options[:loading_text]}') if options[:loading_text] js_options['savingText'] = %('#{options[:saving_text]}') if options[:saving_text] js_options['rows'] = options[:rows] if options[:rows] js_options['cols'] = options[:cols] if options[:cols] js_options['size'] = options[:size] if options[:size] js_options['externalControl'] = "'#{options[:external_control]}'" if options[:external_control] + js_options['externalControlOnly'] = "true" if options[:external_control_only] + js_options['submitOnBlur'] = "'#{options[:submit_on_blur]}'" if options[:submit_on_blur] js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url] js_options['ajaxOptions'] = options[:options] if options[:options] js_options['htmlResponse'] = !options[:script] if options[:script] js_options['callback'] = "function(form) { return #{options[:with]} }" if options[:with] js_options['clickToEditText'] = %('#{options[:click_to_edit_text]}') if options[:click_to_edit_text] js_options['textBetweenControls'] = %('#{options[:text_between_controls]}') if options[:text_between_controls] - js_options['inplacePatternSelector'] = %('#{options[:inplace_pattern_selector]}') if options[:inplace_pattern_selector] - js_options['nodeIdSuffix'] = %('#{options[:node_id_suffix]}') if options[:node_id_suffix] + js_options['highlightcolor'] = %('#{options[:highlight_color]}') if options[:highlight_color] + js_options['highlightendcolor'] = %('#{options[:highlight_end_color]}') if options[:highlight_end_color] + js_options['onFailure'] = "function(element, transport) { #{options[:failure]} }" if options[:failure] + js_options['onComplete'] = "function(transport, element) { #{options[:complete]} }" if options[:complete] + js_options['onEnterEditMode'] = "function(element) { #{options[:enter_editing]} }" if options[:enter_editing] + js_options['onLeaveEditMode'] = "function(element) { #{options[:exit_editing]} }" if options[:exit_editing] + js_options['onFormCustomization'] = "function(element, form) { #{options[:form_customization]} }" if options[:form_customization] function << (', ' + options_for_javascript(js_options)) unless js_options.empty? function << ')' From b9bb28eadf3773e82d638fe4c5f1861218861239 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 13 Nov 2009 11:35:01 +0100 Subject: [PATCH 0131/2024] Change inplace_edit to load the fields using AJAX call to render_field action in onFormCustomization callback. It enables to use record_select form_ui with in place editing --- .../default/javascripts/active_scaffold.js | 77 ------------------- .../views/_list_column_headings.html.erb | 1 - lib/active_scaffold/actions/core.rb | 12 ++- .../helpers/form_column_helpers.rb | 16 ++-- .../helpers/list_column_helpers.rb | 69 ++++++++++------- 5 files changed, 57 insertions(+), 118 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 6cda680059..c99efa1644 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -432,80 +432,3 @@ ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.Act if (event) Event.stop(event); } }); - -ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { - initialize: function($super, element, url, options) { - $super(element, url, options); - }, - - createEditField: function($super) { - if (this.options.inplacePatternSelector) { - var patternNodes = this.getPatternNodes(this.options.inplacePatternSelector); - if (patternNodes.editNode == null) { - alert('did not find any matching node for ' + this.options.editFieldSelector); - return; - } - - var text = (this.options.loadTextURL ? this.options.loadingText : this.getText()); - var fld = patternNodes.editNode.cloneNode(true); - if (fld.id.length > 0) fld.id += this.options.nodeIdSuffix; - fld.name = this.options.paramName; - fld.className = 'editor_field'; - this.setValue(fld, text); - if (this.options.submitOnBlur) - fld.onblur = this._boundSubmitHandler; - this._controls.editor = fld; - if (this.options.loadTextURL) - this.loadExternalText(); - this._form.appendChild(this._controls.editor); - - $A(patternNodes.additionalNodes).each(function(node) { - var patternNode = node.cloneNode(true); - if (patternNode.id.length > 0) { - patternNode.id = patternNode.id + this.options.nodeIdSuffix; - } - this._form.appendChild(patternNode); - }.bind(this)); - } else { - $super(); - } - }, - - getPatternNodes: function(inplacePatternSelector) { - var nodes = {editNode: null, additionalNodes: []}; - var selectedNodes = $$(inplacePatternSelector); - var firstNode = selectedNodes.first(); - - if (typeof(firstNode) !== 'undefined') { - // AS inplace_edit_control_container -> we have to select all child nodes - // Workaround for ie which does not support css > selector - if (firstNode.className.indexOf('as_inplace_pattern') !== -1) { - selectedNodes = firstNode.childElements(); - } - nodes.editNode = selectedNodes.first(); - selectedNodes.shift(); - nodes.additionalNodes = selectedNodes; - } - return nodes; - }, - - setValue: function(editField, textValue) { - var function_name = 'setValueFor' + editField.nodeName.toLowerCase(); - if (typeof(this[function_name]) == 'function') { - this[function_name](editField, textValue); - } else { - editField.value = textValue; - } - }, - - setValueForselect: function(editField, textValue) { - var len = editField.options.length; - var i = 0; - while (i < len && editField.options[i].text != textValue) { - i++; - } - if (i < len) { - editField.value = editField.options[i].value - } - } -}); diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index 306eed9360..96a3b96287 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -26,7 +26,6 @@ default_sorting_stages = ['ASC', 'DESC'] <% else -%> <p><%= column.label %></p> <% end -%> - <%= inplace_edit_control(column) -%> </th> <% end -%> <th class="actions"> diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 885ab4c101..c7ab5fb923 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -6,17 +6,23 @@ def self.included(base) end end def render_field - @record = active_scaffold_config.model.new + @record = if params[:in_place_editing] + active_scaffold_config.model.find params[:id] + else + active_scaffold_config.model.new + end @update_columns = [] column = active_scaffold_config.columns[params[:column]] - unless column.nil? + if params[:in_place_editing] + render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>" + elsif !column.nil? value = if column.association params[:value].blank? ? nil : column.association.klass.find(params[:value]) else params[:value] end @record.send "#{column.name}=", value - @update_columns << Array(column.options[:update_column]).collect {|column_name| active_scaffold_config.columns[column_name]} + @update_columns << Array(params[:update_column]).collect {|column_name| active_scaffold_config.columns[column_name.to_sym]} @update_columns.flatten! after_render_field(@record, column) end diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index ed71802fde..d6faee4ccc 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -64,7 +64,7 @@ def javascript_for_update_column(column, scope, options) if column.options.is_a?(Hash) && column.options[:update_column] form_action = :create form_action = :update if params[:action] == 'edit' - url_params = {:action => 'render_field', :id => params[:id], :column => column.name} + url_params = {:action => 'render_field', :id => params[:id], :column => column.name, :update_column => column.options[:update_column]} url_params[:eid] = params[:eid] if params[:eid] url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope url_params[:scope] = params[:scope] if scope @@ -148,10 +148,7 @@ def active_scaffold_input_select(column, html_options) end end - # only works for singular associations - # requires RecordSelect plugin to be installed and configured. - # ... maybe this should be provided in a bridge? - def active_scaffold_input_record_select(column, options) + def active_scaffold_input_record_select_options(column, options) unless column.association raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)." end @@ -163,10 +160,13 @@ def active_scaffold_input_record_select(column, options) params.merge!({column.association.primary_key_name => ''}) end - record_select_options = {:controller => remote_controller, :id => options[:id]} - record_select_options.merge!(active_scaffold_input_text_options) - record_select_options.merge!(column.options) + active_scaffold_input_text_options({:controller => remote_controller, :id => options[:id]}.merge!(column.options)) + end + # requires RecordSelect plugin to be installed and configured. + # ... maybe this should be provided in a bridge? + def active_scaffold_input_record_select(column, options) + record_select_options = active_scaffold_input_record_select_options(column, options) if column.singular_association? record_select_field(options[:name], (@record.send(column.name) || column.association.klass.new), record_select_options) elsif column.plural_association? diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 336e056eff..51384881b3 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -223,37 +223,39 @@ def active_scaffold_inplace_edit(record, column) formatted_column = format_inplace_edit_column(record,column) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} tag_options = {:tag => "span", :id => element_cell_id(id_options), :class => "in_place_editor_field"} - in_place_editor_options = {:url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s}, - :with => params[:eid] ? "Form.serialize(form) + '&eid=#{params[:eid]}'" : nil, - :click_to_edit_text => as_(:click_to_edit), - :cancel_text => as_(:cancel), - :loading_text => as_(:loading), - :save_text => as_(:update), - :saving_text => as_(:saving), - :options => "{method: 'post'}", - :script => true, - :inplace_pattern_selector => "##{active_scaffold_column_header_id(column)} .#{inplace_edit_control_css_class}", - :node_id_suffix => record.id.to_s}.merge(column.options) - content_tag(:span, formatted_column, tag_options) + active_scaffold_in_place_editor(tag_options[:id], in_place_editor_options) - end - - def inplace_edit_control(column) - if inplace_edit?(active_scaffold_config.model, column) - @record = active_scaffold_config.model.new - column = column.clone - column.options = column.options.clone - column.options.delete(:update_column) - column.form_ui = :select if (column.association && column.form_ui.nil?) || column.form_ui == :record_select - content_tag(:div, active_scaffold_input_for(column), {:style => "display:none;", :class => inplace_edit_control_css_class}) + in_place_editor_options = { + :url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s}, + :with => params[:eid] ? "Form.serialize(form) + '&eid=#{params[:eid]}'" : nil, + :click_to_edit_text => as_(:click_to_edit), + :cancel_text => as_(:cancel), + :loading_text => as_(:loading), + :save_text => as_(:update), + :saving_text => as_(:saving), + :options => "{method: 'post'}", + :script => true + } + + if override_form_field?(column) or column.form_ui + ajax_options = { + :method => :get, + :url => {:action => 'render_field', :id => record.id, :column => column.name, :update_column => column.name, :in_place_editing => true}, + :complete => %| +element._form.insert({top: request.responseText}); +var fld = element._form.findFirstElement(); +element._controls.editor = fld; +fld.name = element.options.paramName; +fld.className = 'editor_field'; +if (element.options.submitOnBlur) fld.onblur = ipe._boundSubmitHandler; + |} + in_place_editor_options[:form_customization] = "element._controls.editor.remove(); #{remote_function(ajax_options)}" end - end - - def inplace_edit_control_css_class - "as_inplace_pattern" + + in_place_editor_options.merge!(column.options) + content_tag(:span, formatted_column, tag_options) + active_scaffold_in_place_editor(tag_options[:id], in_place_editor_options) end def active_scaffold_in_place_editor(field_id, options = {}) - function = "new ActiveScaffold.InPlaceEditor(" + function = "new Ajax.InPlaceEditor(" function << "'#{field_id}', " function << "'#{url_for(options[:url])}'" @@ -266,20 +268,29 @@ def active_scaffold_in_place_editor(field_id, options = {}) js_options['cancelText'] = %('#{options[:cancel_text]}') if options[:cancel_text] js_options['okText'] = %('#{options[:save_text]}') if options[:save_text] + js_options['okControl'] = %('#{options[:save_control_type]}') if options[:save_control_type] + js_options['cancelControl'] = %('#{options[:cancel_control_type]}') if options[:cancel_control_type] js_options['loadingText'] = %('#{options[:loading_text]}') if options[:loading_text] js_options['savingText'] = %('#{options[:saving_text]}') if options[:saving_text] js_options['rows'] = options[:rows] if options[:rows] js_options['cols'] = options[:cols] if options[:cols] js_options['size'] = options[:size] if options[:size] js_options['externalControl'] = "'#{options[:external_control]}'" if options[:external_control] + js_options['externalControlOnly'] = "true" if options[:external_control_only] + js_options['submitOnBlur'] = "'#{options[:submit_on_blur]}'" if options[:submit_on_blur] js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url] js_options['ajaxOptions'] = options[:options] if options[:options] js_options['htmlResponse'] = !options[:script] if options[:script] js_options['callback'] = "function(form) { return #{options[:with]} }" if options[:with] js_options['clickToEditText'] = %('#{options[:click_to_edit_text]}') if options[:click_to_edit_text] js_options['textBetweenControls'] = %('#{options[:text_between_controls]}') if options[:text_between_controls] - js_options['inplacePatternSelector'] = %('#{options[:inplace_pattern_selector]}') if options[:inplace_pattern_selector] - js_options['nodeIdSuffix'] = %('#{options[:node_id_suffix]}') if options[:node_id_suffix] + js_options['highlightcolor'] = %('#{options[:highlight_color]}') if options[:highlight_color] + js_options['highlightendcolor'] = %('#{options[:highlight_end_color]}') if options[:highlight_end_color] + js_options['onFailure'] = "function(element, transport) { #{options[:failure]} }" if options[:failure] + js_options['onComplete'] = "function(transport, element) { #{options[:complete]} }" if options[:complete] + js_options['onEnterEditMode'] = "function(element) { #{options[:enter_editing]} }" if options[:enter_editing] + js_options['onLeaveEditMode'] = "function(element) { #{options[:exit_editing]} }" if options[:exit_editing] + js_options['onFormCustomization'] = "function(element, form) { #{options[:form_customization]} }" if options[:form_customization] function << (', ' + options_for_javascript(js_options)) unless js_options.empty? function << ')' From d857b3b5c4ce90d79a70a7b103cc8ac0ff699640 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Wed, 18 Nov 2009 18:17:47 +0100 Subject: [PATCH 0132/2024] Restore inplace editing cloning some fields from the heading, and add support for get the fields by ajax setting inplace_edit to :ajax --- .../default/javascripts/active_scaffold.js | 83 +++++++++++++++++++ .../views/_list_column_headings.html.erb | 1 + .../helpers/form_column_helpers.rb | 16 ++-- .../helpers/list_column_helpers.rb | 47 +++++++---- 4 files changed, 125 insertions(+), 22 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index c99efa1644..ec9e7b3eb2 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -432,3 +432,86 @@ ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.Act if (event) Event.stop(event); } }); + +ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { + setFieldFromAjax: function(url, options) { + this._controls.editor.remove(); + new Ajax.Request(url, { + method: 'get', + onComplete: function(response) { + this._form.insert({top: response.responseText}); + var fld = this._form.findFirstElement(); + fld.name = this.options.paramName; + fld.className = 'editor_field'; + if (this.options.submitOnBlur) + fld.onblur = this._boundSubmitHandler; + this._controls.editor = fld; + }.bind(this) + }); + }, + + clonePatternField: function() { + var patternNodes = this.getPatternNodes(this.options.inplacePatternSelector); + if (patternNodes.editNode == null) { + alert('did not find any matching node for ' + this.options.editFieldSelector); + return; + } + + var fld = patternNodes.editNode.cloneNode(true); + if (fld.id.length > 0) fld.id += this.options.nodeIdSuffix; + fld.name = this.options.paramName; + fld.className = 'editor_field'; + this.setValue(fld, this._controls.editor.value); + if (this.options.submitOnBlur) + fld.onblur = this._boundSubmitHandler; + this._controls.editor.remove(); + this._controls.editor = fld; + this._form.appendChild(this._controls.editor); + + $A(patternNodes.additionalNodes).each(function(node) { + var patternNode = node.cloneNode(true); + if (patternNode.id.length > 0) { + patternNode.id = patternNode.id + this.options.nodeIdSuffix; + } + this._form.appendChild(patternNode); + }.bind(this)); + }, + + getPatternNodes: function(inplacePatternSelector) { + var nodes = {editNode: null, additionalNodes: []}; + var selectedNodes = $$(inplacePatternSelector); + var firstNode = selectedNodes.first(); + + if (typeof(firstNode) !== 'undefined') { + // AS inplace_edit_control_container -> we have to select all child nodes + // Workaround for ie which does not support css > selector + if (firstNode.className.indexOf('as_inplace_pattern') !== -1) { + selectedNodes = firstNode.childElements(); + } + nodes.editNode = selectedNodes.first(); + selectedNodes.shift(); + nodes.additionalNodes = selectedNodes; + } + return nodes; + }, + + setValue: function(editField, textValue) { + var function_name = 'setValueFor' + editField.nodeName.toLowerCase(); + if (typeof(this[function_name]) == 'function') { + this[function_name](editField, textValue); + } else { + editField.value = textValue; + } + }, + + setValueForselect: function(editField, textValue) { + var len = editField.options.length; + var i = 0; + while (i < len && editField.options[i].text != textValue) { + i++; + } + if (i < len) { + editField.value = editField.options[i].value + } + } +}); diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index 96a3b96287..306eed9360 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -26,6 +26,7 @@ default_sorting_stages = ['ASC', 'DESC'] <% else -%> <p><%= column.label %></p> <% end -%> + <%= inplace_edit_control(column) -%> </th> <% end -%> <th class="actions"> diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index d6faee4ccc..ee8e4fc3c0 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -95,7 +95,7 @@ def active_scaffold_input_singular_association(column, html_options) # For backwards compatibility, to add method options is needed to set a html_options hash # in other case all column.options will be added as html options if column.options[:html_options] - html_options.update(column.options[:html_options]) + html_options.update(column.options[:html_options] || {}) options.update(column.options) else Rails.logger.warn "ActiveScaffold: Setting html options directly in a hash is deprecated for :select form_ui. Set the html options hash under html_options key, such as config.columns[:column_name].options = {:html_options => {...}, ...}" @@ -148,7 +148,10 @@ def active_scaffold_input_select(column, html_options) end end - def active_scaffold_input_record_select_options(column, options) + # only works for singular associations + # requires RecordSelect plugin to be installed and configured. + # ... maybe this should be provided in a bridge? + def active_scaffold_input_record_select(column, options) unless column.association raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)." end @@ -160,13 +163,10 @@ def active_scaffold_input_record_select_options(column, options) params.merge!({column.association.primary_key_name => ''}) end - active_scaffold_input_text_options({:controller => remote_controller, :id => options[:id]}.merge!(column.options)) - end + record_select_options = {:controller => remote_controller, :id => options[:id]} + record_select_options.merge!(active_scaffold_input_text_options) + record_select_options.merge!(column.options) - # requires RecordSelect plugin to be installed and configured. - # ... maybe this should be provided in a bridge? - def active_scaffold_input_record_select(column, options) - record_select_options = active_scaffold_input_record_select_options(column, options) if column.singular_association? record_select_field(options[:name], (@record.send(column.name) || column.association.klass.new), record_select_options) elsif column.plural_association? diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 51384881b3..8b0d4f046a 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -210,6 +210,10 @@ def inplace_edit?(record, column) column.inplace_edit and record.authorized_for?(:action => :update, :column => column.name) end + def inplace_edit_cloning?(column) + column.inplace_edit != :ajax and (override_form_field?(column) or column.form_ui or (column.column and override_input?(column.column.type))) + end + def format_inplace_edit_column(record,column) value = record.send(column.name) if column.list_ui == :checkbox @@ -235,27 +239,40 @@ def active_scaffold_inplace_edit(record, column) :script => true } - if override_form_field?(column) or column.form_ui - ajax_options = { - :method => :get, - :url => {:action => 'render_field', :id => record.id, :column => column.name, :update_column => column.name, :in_place_editing => true}, - :complete => %| -element._form.insert({top: request.responseText}); -var fld = element._form.findFirstElement(); -element._controls.editor = fld; -fld.name = element.options.paramName; -fld.className = 'editor_field'; -if (element.options.submitOnBlur) fld.onblur = ipe._boundSubmitHandler; - |} - in_place_editor_options[:form_customization] = "element._controls.editor.remove(); #{remote_function(ajax_options)}" + if inplace_edit_cloning?(column) + in_place_editor_options.merge!( + :inplace_pattern_selector => "##{active_scaffold_column_header_id(column)} .#{inplace_edit_control_css_class}", + :node_id_suffix => record.id.to_s, + :form_customization => 'element.clonePatternField();' + ) + elsif column.inplace_edit == :ajax + url = url_for(:action => 'render_field', :id => record.id, :column => column.name, :update_column => column.name, :in_place_editing => true, :escape => false) + in_place_editor_options[:form_customization] = "element.setFieldFromAjax('#{escape_javascript(url)}');" + elsif column.column.try(:type) == :text + in_place_editor_options[:rows] = column.options[:rows] || 5 end in_place_editor_options.merge!(column.options) content_tag(:span, formatted_column, tag_options) + active_scaffold_in_place_editor(tag_options[:id], in_place_editor_options) end + def inplace_edit_control(column) + if inplace_edit?(active_scaffold_config.model, column) and inplace_edit_cloning?(column) + @record = active_scaffold_config.model.new + column = column.clone + column.options = column.options.clone + column.options.delete(:update_column) + column.form_ui = :select if (column.association && column.form_ui.nil?) + content_tag(:div, active_scaffold_input_for(column), {:style => "display:none;", :class => inplace_edit_control_css_class}) + end + end + + def inplace_edit_control_css_class + "as_inplace_pattern" + end + def active_scaffold_in_place_editor(field_id, options = {}) - function = "new Ajax.InPlaceEditor(" + function = "new ActiveScaffold.InPlaceEditor(" function << "'#{field_id}', " function << "'#{url_for(options[:url])}'" @@ -291,6 +308,8 @@ def active_scaffold_in_place_editor(field_id, options = {}) js_options['onEnterEditMode'] = "function(element) { #{options[:enter_editing]} }" if options[:enter_editing] js_options['onLeaveEditMode'] = "function(element) { #{options[:exit_editing]} }" if options[:exit_editing] js_options['onFormCustomization'] = "function(element, form) { #{options[:form_customization]} }" if options[:form_customization] + js_options['inplacePatternSelector'] = %('#{options[:inplace_pattern_selector]}') if options[:inplace_pattern_selector] + js_options['nodeIdSuffix'] = %('#{options[:node_id_suffix]}') if options[:node_id_suffix] function << (', ' + options_for_javascript(js_options)) unless js_options.empty? function << ')' From f3ac594e57c7fa3488d5bd6260c71fafb209c4a9 Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Tue, 24 Nov 2009 09:30:54 +0100 Subject: [PATCH 0133/2024] centralized get column value from params --- lib/active_scaffold/actions/core.rb | 6 +- lib/active_scaffold/actions/update.rb | 4 +- lib/active_scaffold/attribute_params.rb | 96 ++++++++++++------------- 3 files changed, 47 insertions(+), 59 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index c7ab5fb923..3663d2d25d 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -16,11 +16,7 @@ def render_field if params[:in_place_editing] render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>" elsif !column.nil? - value = if column.association - params[:value].blank? ? nil : column.association.klass.find(params[:value]) - else - params[:value] - end + value = column_value_from_param_value(@record, column, params[:value]) @record.send "#{column.name}=", value @update_columns << Array(params[:update_column]).collect {|column_name| active_scaffold_config.columns[column_name.to_sym]} @update_columns.flatten! diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 8d6569d2f3..a1f2326604 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -96,9 +96,7 @@ def do_update_column if @record.authorized_for?(:action => :update, :column => params[:column]) column = active_scaffold_config.columns[params[:column].to_sym] params[:value] ||= @record.column_for_attribute(params[:column]).default unless @record.column_for_attribute(params[:column]).nil? || @record.column_for_attribute(params[:column]).null - if !column.nil? && column.association - params[:value] = params[:value].blank? ? nil : column.association.klass.find(params[:value]) - end + params[:value] = column_value_from_param_value(@record, column, params[:value]) unless column.nil? @record.send("#{params[:column]}=", params[:value]) @record.save end diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 0615c5229d..b1e9ecb10f 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -50,57 +50,7 @@ def update_record_from_params(parent_record, columns, attributes) if multi_parameter_attributes.has_key? column.name parent_record.send(:assign_multiparameter_attributes, multi_parameter_attributes[column.name]) elsif attributes.has_key? column.name - value = attributes[column.name] - - # convert the value, possibly by instantiating associated objects - value = if value.is_a?(Hash) - # this is just for backwards compatibility. we should clean this up in 2.0. - if column.form_ui == :select - ids = if column.singular_association? - value[:id] - else - value.values.collect {|hash| hash[:id]} - end - (ids and not ids.empty?) ? column.association.klass.find(ids) : nil - - elsif column.singular_association? - hash = value - record = find_or_create_for_params(hash, column, parent_record) - if record - record_columns = active_scaffold_config_for(column.association.klass).subform.columns - update_record_from_params(record, record_columns, hash) - record.unsaved = true - end - record - - elsif column.plural_association? - collection = value.collect do |key_value_pair| - hash = key_value_pair[1] - record = find_or_create_for_params(hash, column, parent_record) - if record - record_columns = active_scaffold_config_for(column.association.klass).subform.columns - update_record_from_params(record, record_columns, hash) - record.unsaved = true - end - record - end - collection.compact - end - else - if column.singular_association? - # it's a single id - column.association.klass.find(value) if value and not value.empty? - elsif column.plural_association? - # it's an array of ids - column.association.klass.find(value) if value and not value.empty? - else - # convert empty strings into nil. this works better with 'null => true' columns (and validations), - # and 'null => false' columns should just convert back to an empty string. - # ... but we can at least check the ConnectionAdapter::Column object to see if nulls are allowed - value = nil if value.is_a? String and value.empty? and !column.column.nil? and column.column.null - value - end - end + value = column_value_from_param_value(parent_record, column, attributes[column.name]) # we avoid assigning a value that already exists because otherwise has_one associations will break (AR bug in has_one_association.rb#replace) parent_record.send("#{column.name}=", value) unless column.through_association? or parent_record.send(column.name) == value @@ -135,6 +85,50 @@ def update_record_from_params(parent_record, columns, attributes) parent_record end + + def manage_nested_record_from_params(parent_record, column, attributes) + record = find_or_create_for_params(attributes, column, parent_record) + if record + record_columns = active_scaffold_config_for(column.association.klass).subform.columns + update_record_from_params(record, record_columns, attributes) + record.unsaved = true + end + record + end + + def column_value_from_param_value(parent_record, column, value) + # convert the value, possibly by instantiating associated objects + if value.is_a?(Hash) + # this is just for backwards compatibility. we should clean this up in 2.0. + if column.form_ui == :select + ids = if column.singular_association? + value[:id] + else + value.values.collect {|hash| hash[:id]} + end + (ids and not ids.empty?) ? column.association.klass.find(ids) : nil + + elsif column.singular_association? + manage_nested_record_from_params(parent_record, column, value) + elsif column.plural_association? + value.collect {|key_value_pair| manage_nested_record_from_params(parent_record, column, key_value_pair[1])}.compact + end + else + if column.singular_association? + # it's a single id + column.association.klass.find(value) if value and not value.empty? + elsif column.plural_association? + # it's an array of ids + column.association.klass.find(value) if value and not value.empty? + else + # convert empty strings into nil. this works better with 'null => true' columns (and validations), + # and 'null => false' columns should just convert back to an empty string. + # ... but we can at least check the ConnectionAdapter::Column object to see if nulls are allowed + value = nil if value.is_a? String and value.empty? and !column.column.nil? and column.column.null + value + end + end + end # Attempts to create or find an instance of klass (which must be an ActiveRecord object) from the # request parameters given. If params[:id] exists it will attempt to find an existing object From ccce323d84ef298593fc41d278f824bc86b1cd99 Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Wed, 25 Nov 2009 17:33:07 +0100 Subject: [PATCH 0134/2024] added l18n support for number and currency --- lib/active_scaffold/attribute_params.rb | 2 ++ lib/active_scaffold/helpers/form_column_helpers.rb | 14 ++++++++++++++ lib/active_scaffold/helpers/list_column_helpers.rb | 9 ++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index b1e9ecb10f..9ba810b11f 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -120,6 +120,8 @@ def column_value_from_param_value(parent_record, column, value) elsif column.plural_association? # it's an array of ids column.association.klass.find(value) if value and not value.empty? + elsif [:l18n_number, :currency].include?(column.form_ui) + value.gsub(/[^0-9\-#{I18n.t(:'number.format.separator')}]/, '').gsub(I18n.t(:'number.format.separator'), '.') else # convert empty strings into nil. this works better with 'null => true' columns (and validations), # and 'null => false' columns should just convert back to an empty string. diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index ee8e4fc3c0..ec5f007dbe 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -186,6 +186,20 @@ def active_scaffold_input_password(column, options) def active_scaffold_input_textarea(column, options) text_area(:record, column.name, options.merge(:cols => column.options[:cols], :rows => column.options[:rows], :size => column.options[:size])) end + + def active_scaffold_input_l18n_number(column, options) + active_scaffold_input_number_helper(column, options, :number_with_precision) + end + + def active_scaffold_input_currency(column, options) + active_scaffold_input_number_helper(column, options, :number_to_currency) + end + + def active_scaffold_input_number_helper(column, options, helper) + options = active_scaffold_input_text_options(options).merge(column.options) + options.delete(:l18n_options) + text_field_tag(column.name, send(helper, @record.send(column.name), column.options[:l18n_options] || {}), options) + end def active_scaffold_input_virtual(column, options) options = active_scaffold_input_text_options(options) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 8b0d4f046a..4c3a59e2bc 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -149,7 +149,14 @@ def format_column_value(record, column) cache_association(value, column) end if column.association.nil? or column_empty?(value) - format_value(value, column.options) + case column.list_ui + when :currency + clean_column_value(number_to_currency(value, column.options[:l18n_options] || {})) + when :l18n_number + clean_column_value(number_with_precision(value, column.options[:l18n_options] || {})) + else + format_value(value, column.options) + end else format_association_value(value, column, associated_size) end From 6ecc5d1ab21c0a19d6680732dba4cb9f6188e35c Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 26 Nov 2009 11:56:16 +0100 Subject: [PATCH 0135/2024] improve error message --- lib/active_scaffold/attribute_params.rb | 2 +- .../default/active_scaffold.js | 83 +++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index b1e9ecb10f..b81876f202 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -76,7 +76,7 @@ def update_record_from_params(parent_record, columns, attributes) next unless [:has_one, :has_many].include?(a.macro) and not a.options[:through] next unless association_proxy = parent_record.send(a.name) - raise ActiveScaffold::ReverseAssociationRequired, "In order to support :has_one and :has_many where the parent record is new and the child record(s) validate the presence of the parent, ActiveScaffold requires the reverse association (the belongs_to)." unless a.reverse + raise ActiveScaffold::ReverseAssociationRequired, "Association #{a.name}: In order to support :has_one and :has_many where the parent record is new and the child record(s) validate the presence of the parent, ActiveScaffold requires the reverse association (the belongs_to)." unless a.reverse association_proxy = [association_proxy] if a.macro == :has_one association_proxy.each { |record| record.send("#{a.reverse}=", parent_record) } diff --git a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js index c99efa1644..ec9e7b3eb2 100644 --- a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +++ b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js @@ -432,3 +432,86 @@ ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.Act if (event) Event.stop(event); } }); + +ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { + setFieldFromAjax: function(url, options) { + this._controls.editor.remove(); + new Ajax.Request(url, { + method: 'get', + onComplete: function(response) { + this._form.insert({top: response.responseText}); + var fld = this._form.findFirstElement(); + fld.name = this.options.paramName; + fld.className = 'editor_field'; + if (this.options.submitOnBlur) + fld.onblur = this._boundSubmitHandler; + this._controls.editor = fld; + }.bind(this) + }); + }, + + clonePatternField: function() { + var patternNodes = this.getPatternNodes(this.options.inplacePatternSelector); + if (patternNodes.editNode == null) { + alert('did not find any matching node for ' + this.options.editFieldSelector); + return; + } + + var fld = patternNodes.editNode.cloneNode(true); + if (fld.id.length > 0) fld.id += this.options.nodeIdSuffix; + fld.name = this.options.paramName; + fld.className = 'editor_field'; + this.setValue(fld, this._controls.editor.value); + if (this.options.submitOnBlur) + fld.onblur = this._boundSubmitHandler; + this._controls.editor.remove(); + this._controls.editor = fld; + this._form.appendChild(this._controls.editor); + + $A(patternNodes.additionalNodes).each(function(node) { + var patternNode = node.cloneNode(true); + if (patternNode.id.length > 0) { + patternNode.id = patternNode.id + this.options.nodeIdSuffix; + } + this._form.appendChild(patternNode); + }.bind(this)); + }, + + getPatternNodes: function(inplacePatternSelector) { + var nodes = {editNode: null, additionalNodes: []}; + var selectedNodes = $$(inplacePatternSelector); + var firstNode = selectedNodes.first(); + + if (typeof(firstNode) !== 'undefined') { + // AS inplace_edit_control_container -> we have to select all child nodes + // Workaround for ie which does not support css > selector + if (firstNode.className.indexOf('as_inplace_pattern') !== -1) { + selectedNodes = firstNode.childElements(); + } + nodes.editNode = selectedNodes.first(); + selectedNodes.shift(); + nodes.additionalNodes = selectedNodes; + } + return nodes; + }, + + setValue: function(editField, textValue) { + var function_name = 'setValueFor' + editField.nodeName.toLowerCase(); + if (typeof(this[function_name]) == 'function') { + this[function_name](editField, textValue); + } else { + editField.value = textValue; + } + }, + + setValueForselect: function(editField, textValue) { + var len = editField.options.length; + var i = 0; + while (i < len && editField.options[i].text != textValue) { + i++; + } + if (i < len) { + editField.value = editField.options[i].value + } + } +}); From 98000f4fdf0d81882db16715c6755d267c815a88 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Thu, 26 Nov 2009 18:00:50 +0100 Subject: [PATCH 0136/2024] It should be i18n (or l10n), l18n doesn't exist. Add list_ui for currency and i18n_number --- lib/active_scaffold/attribute_params.rb | 2 +- .../helpers/form_column_helpers.rb | 6 +++--- .../helpers/list_column_helpers.rb | 17 +++++++++-------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index e2a134e8c8..b99d458e3e 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -120,7 +120,7 @@ def column_value_from_param_value(parent_record, column, value) elsif column.plural_association? # it's an array of ids column.association.klass.find(value) if value and not value.empty? - elsif [:l18n_number, :currency].include?(column.form_ui) + elsif [:i18n_number, :currency].include?(column.form_ui) value.gsub(/[^0-9\-#{I18n.t(:'number.format.separator')}]/, '').gsub(I18n.t(:'number.format.separator'), '.') else # convert empty strings into nil. this works better with 'null => true' columns (and validations), diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index ec5f007dbe..8ada215111 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -187,7 +187,7 @@ def active_scaffold_input_textarea(column, options) text_area(:record, column.name, options.merge(:cols => column.options[:cols], :rows => column.options[:rows], :size => column.options[:size])) end - def active_scaffold_input_l18n_number(column, options) + def active_scaffold_input_i18n_number(column, options) active_scaffold_input_number_helper(column, options, :number_with_precision) end @@ -197,8 +197,8 @@ def active_scaffold_input_currency(column, options) def active_scaffold_input_number_helper(column, options, helper) options = active_scaffold_input_text_options(options).merge(column.options) - options.delete(:l18n_options) - text_field_tag(column.name, send(helper, @record.send(column.name), column.options[:l18n_options] || {}), options) + options.delete(:i18n_options) + text_field_tag(column.name, send(helper, @record.send(column.name), column.options[:i18n_options] || {}), options) end def active_scaffold_input_virtual(column, options) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 4c3a59e2bc..c57fe81749 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -121,6 +121,14 @@ def active_scaffold_column_checkbox(column, record) end end + def active_scaffold_column_currency(column, record) + clean_column_value(number_to_currency(record.send(column.name), column.options[:i18n_options] || {})) + end + + def active_scaffold_column_i18n_number(column, record) + clean_column_value(number_with_precision(record.send(column.name), column.options[:i18n_options] || {})) + end + def column_override(column) "#{column.name.to_s.gsub('?', '')}_column" # parse out any question marks (see issue 227) end @@ -149,14 +157,7 @@ def format_column_value(record, column) cache_association(value, column) end if column.association.nil? or column_empty?(value) - case column.list_ui - when :currency - clean_column_value(number_to_currency(value, column.options[:l18n_options] || {})) - when :l18n_number - clean_column_value(number_with_precision(value, column.options[:l18n_options] || {})) - else - format_value(value, column.options) - end + format_value(value, column.options) else format_association_value(value, column, associated_size) end From 0b99113f5cf292ce47b4f17332cedb7d2a45e074 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 27 Nov 2009 10:01:32 +0100 Subject: [PATCH 0137/2024] Revert last change about list_ui, and simplify helpers --- .../helpers/form_column_helpers.rb | 11 ++------ .../helpers/list_column_helpers.rb | 26 ++++++++++++------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 8ada215111..73e0805812 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -188,18 +188,11 @@ def active_scaffold_input_textarea(column, options) end def active_scaffold_input_i18n_number(column, options) - active_scaffold_input_number_helper(column, options, :number_with_precision) - end - - def active_scaffold_input_currency(column, options) - active_scaffold_input_number_helper(column, options, :number_to_currency) - end - - def active_scaffold_input_number_helper(column, options, helper) options = active_scaffold_input_text_options(options).merge(column.options) options.delete(:i18n_options) - text_field_tag(column.name, send(helper, @record.send(column.name), column.options[:i18n_options] || {}), options) + text_field_tag(column.name, format_number_value(@record.send(column.name), column.form_ui, column.options), options) end + alias_method :active_scaffold_input_currency, :active_scaffold_input_i18n_number def active_scaffold_input_virtual(column, options) options = active_scaffold_input_text_options(options) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index c57fe81749..7fe12cdd1a 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -121,14 +121,6 @@ def active_scaffold_column_checkbox(column, record) end end - def active_scaffold_column_currency(column, record) - clean_column_value(number_to_currency(record.send(column.name), column.options[:i18n_options] || {})) - end - - def active_scaffold_column_i18n_number(column, record) - clean_column_value(number_with_precision(record.send(column.name), column.options[:i18n_options] || {})) - end - def column_override(column) "#{column.name.to_s.gsub('?', '')}_column" # parse out any question marks (see issue 227) end @@ -157,12 +149,28 @@ def format_column_value(record, column) cache_association(value, column) end if column.association.nil? or column_empty?(value) - format_value(value, column.options) + if value.is_a? Numeric + format_number_value(value, column.list_ui, column.options) + else + format_value(value, column.options) + end else format_association_value(value, column, associated_size) end end + def format_number_value(value, ui, options = {}) + value = case ui + when :currency + number_to_currency(value, options[:i18n_options] || {}) + when :i18n_number + send("number_with_#{value.is_a?(Integer) ? 'delimiter' : 'precision'}", value, options[:i18n_options] || {}) + else + value + end + clean_column_value(value) + end + def format_association_value(value, column, size) case column.association.macro when :has_one, :belongs_to From 30b1059c5b848734c09f6c605240b09222193d7a Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 27 Nov 2009 11:55:09 +0100 Subject: [PATCH 0138/2024] Update errors in associations when form is sent using AJAX --- frontends/default/views/_form_association.html.erb | 10 +--------- frontends/default/views/_horizontal_subform.html.erb | 2 +- frontends/default/views/_vertical_subform.html.erb | 2 +- frontends/default/views/form_messages_on_create.js.rjs | 2 -- frontends/default/views/form_messages_on_save.js.rjs | 10 ++++++++++ frontends/default/views/form_messages_on_update.js.rjs | 2 -- lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/actions/update.rb | 2 +- lib/active_scaffold/data_structures/column.rb | 9 ++++++++- 9 files changed, 23 insertions(+), 18 deletions(-) delete mode 100644 frontends/default/views/form_messages_on_create.js.rjs create mode 100644 frontends/default/views/form_messages_on_save.js.rjs delete mode 100644 frontends/default/views/form_messages_on_update.js.rjs diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index f073e3ca0a..c37fb32e22 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -3,15 +3,7 @@ parent_record = @record associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) -if column.show_blank_record - show_blank_record = (column.plural_association? or (column.singular_association? and associated.empty?)) - show_blank_record = false if column.through_association? - show_blank_record = false unless column.association.klass.authorized_for?(:action => :create) -else - show_blank_record = false -end - -associated << column.association.klass.new if show_blank_record +associated << column.association.klass.new if column.show_blank_record? associated -%> <h5><%= column.label -%> (<%= link_to_visibility_toggle(:default_visible => !column.collapsed) -%>)</h5> <div <%= 'style="display: none;"' if column.collapsed -%>> diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index 507ccbfcae..f04af620f1 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -7,7 +7,7 @@ <% @record = associated[index] -%> <% if @record.errors.count -%> <tr class="association-record-errors"> - <td colspan="<%= active_scaffold_config_for(@record.class).subform.columns.length + 1 %>"> + <td colspan="<%= active_scaffold_config_for(@record.class).subform.columns.length + 1 %>" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>"> <%= error_messages_for :record, :object_name => @record.class.human_name.downcase %> </td> </tr> diff --git a/frontends/default/views/_vertical_subform.html.erb b/frontends/default/views/_vertical_subform.html.erb index 7aa4a9b029..1d0c1d607e 100644 --- a/frontends/default/views/_vertical_subform.html.erb +++ b/frontends/default/views/_vertical_subform.html.erb @@ -2,7 +2,7 @@ <% associated.each_index do |index| %> <% @record = associated[index] -%> <% if @record.errors.count -%> - <div class="association-record-errors"> + <div class="association-record-errors" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>"> <%= error_messages_for :record, :object_name => @record.class.human_name.downcase %> </div> <% end %> diff --git a/frontends/default/views/form_messages_on_create.js.rjs b/frontends/default/views/form_messages_on_create.js.rjs deleted file mode 100644 index 9bab189da1..0000000000 --- a/frontends/default/views/form_messages_on_create.js.rjs +++ /dev/null @@ -1,2 +0,0 @@ -page.replace_html element_messages_id, :partial => 'form_messages' -page << "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'hidden';" diff --git a/frontends/default/views/form_messages_on_save.js.rjs b/frontends/default/views/form_messages_on_save.js.rjs new file mode 100644 index 0000000000..f577aadfc2 --- /dev/null +++ b/frontends/default/views/form_messages_on_save.js.rjs @@ -0,0 +1,10 @@ +page.replace_html element_messages_id, :partial => 'form_messages' +active_scaffold_config.send(action_name).columns.each(:for => @record, :flatten => true) do |column| + next unless is_subform? column + associated = Array(@record.send(column.name)).compact + associated << column.association.klass.new if column.show_blank_record? associated + associated.each_with_index do |record, index| + page.replace_html element_messages_id(:action => record.class.name.underscore, :id => "#{@record.id}-#{index}"), error_messages_for(:record, :object => record, :object_name => record.class.human_name.downcase) if record.errors.count + end +end +page << "$('#{loading_indicator_id(:action => action_name, :id => params[:id])}').style.visibility = 'hidden';" diff --git a/frontends/default/views/form_messages_on_update.js.rjs b/frontends/default/views/form_messages_on_update.js.rjs deleted file mode 100644 index 93832992fa..0000000000 --- a/frontends/default/views/form_messages_on_update.js.rjs +++ /dev/null @@ -1,2 +0,0 @@ -page.replace_html element_messages_id, :partial => 'form_messages' -page << "$('#{loading_indicator_id(:action => :update, :id => params[:id])}').style.visibility = 'hidden';" diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index d6ccbe4fd9..75caf2c7f4 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -46,7 +46,7 @@ def create_respond_to_html if successful? render :action => 'on_create.js' else - render :action => 'form_messages_on_create.js' + render :action => 'form_messages_on_save.js' end end else diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index a1f2326604..7c092d41f1 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -40,7 +40,7 @@ def update_respond_to_html if successful? render :action => 'on_update.js' else - render :action => 'form_messages_on_update.js' + render :action => 'form_messages_on_save.js' end end else # just a regular post diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 3dcd00c0b4..8c10fe6ea0 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -182,7 +182,14 @@ def associated_number? # whether a blank row must be shown in the subform cattr_accessor :show_blank_record @@show_blank_record = true - attr_accessor :show_blank_record + attr_writer :show_blank_record + def show_blank_record?(associated) + if @show_blank_record + return false if self.through_association? + return false unless self.association.klass.authorized_for?(:action => :create) + self.plural_association? or (self.singular_association? and associated.empty?) + end + end # methods for automatic links in singular association columns cattr_accessor :actions_for_association_links From 54d2b1ce3ead215646e4c1e882a8984bdc885a83 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 27 Nov 2009 16:44:02 +0100 Subject: [PATCH 0139/2024] Sometimes rails duplicates views from some plugins, and when one of those plugins have active_scaffold_overrides directory, it's duplicated and render :super is broken --- lib/active_scaffold.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index f7308992c8..f4e18c0af4 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -71,6 +71,7 @@ def active_scaffold(model_id = nil, &block) active_scaffold_overrides_dir = File.join(dir,"active_scaffold_overrides") @active_scaffold_overrides << active_scaffold_overrides_dir if File.exists?(active_scaffold_overrides_dir) end + @active_scaffold_overrides.uniq! # Fix rails duplicating some view_paths @active_scaffold_frontends = [] if active_scaffold_config.frontend.to_sym != :default active_scaffold_custom_frontend_path = File.join(Rails.root, 'vendor', 'plugins', ActiveScaffold::Config::Core.plugin_directory, 'frontends', active_scaffold_config.frontend.to_s , 'views') From 7aaf8145da2529884e063879890bdf1057863051 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 27 Nov 2009 17:04:04 +0100 Subject: [PATCH 0140/2024] Add radio form_ui (issue #708), fix setting id and name for boolean form_ui and don't use options[:options] in inplace_editor_options as ajaxOptions, because are used to set options for radio and select form_ui --- lib/active_scaffold/helpers/form_column_helpers.rb | 10 +++++++++- lib/active_scaffold/helpers/list_column_helpers.rb | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 73e0805812..df906dadf0 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -148,6 +148,14 @@ def active_scaffold_input_select(column, html_options) end end + def active_scaffold_input_radio(column, html_options) + html_options.update(column.options[:html_options] || {}) + column.options[:options].inject('') do |html, (text, value)| + value ||= text + html << content_tag(:label, radio_button(:record, column.name, value, html_options.merge(:id => html_options[:id] + '-' + value)) + text) + end + end + # only works for singular associations # requires RecordSelect plugin to be installed and configured. # ... maybe this should be provided in a bridge? @@ -209,7 +217,7 @@ def active_scaffold_input_boolean(column, options) select_options << [as_(:true), true] select_options << [as_(:false), false] - select_tag(options[:name], options_for_select(select_options, @record.send(column.name))) + select_tag(options[:name], options_for_select(select_options, @record.send(column.name)), options) end def onsubmit diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 7fe12cdd1a..88e788249c 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -251,7 +251,7 @@ def active_scaffold_inplace_edit(record, column) :loading_text => as_(:loading), :save_text => as_(:update), :saving_text => as_(:saving), - :options => "{method: 'post'}", + :ajax_options => "{method: 'post'}", :script => true } @@ -312,7 +312,7 @@ def active_scaffold_in_place_editor(field_id, options = {}) js_options['externalControlOnly'] = "true" if options[:external_control_only] js_options['submitOnBlur'] = "'#{options[:submit_on_blur]}'" if options[:submit_on_blur] js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url] - js_options['ajaxOptions'] = options[:options] if options[:options] + js_options['ajaxOptions'] = options[:ajax_options] if options[:ajax_options] js_options['htmlResponse'] = !options[:script] if options[:script] js_options['callback'] = "function(form) { return #{options[:with]} }" if options[:with] js_options['clickToEditText'] = %('#{options[:click_to_edit_text]}') if options[:click_to_edit_text] From 2de1dcc505fe4129637428474e2743bb8c715852 Mon Sep 17 00:00:00 2001 From: Sergio <sergio@entrecables.com> Date: Fri, 27 Nov 2009 17:33:46 +0100 Subject: [PATCH 0141/2024] Fix issue #717, show empty_field_text instead of blank when record is not authorized to read --- frontends/default/views/_list_record.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index e35f1e7469..354b9dd6cd 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -8,10 +8,11 @@ url_options = params_for(:action => :list, :id => record.id) <tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>"> <% active_scaffold_config.list.columns.each do |column| %> - <% column_value = get_column_value(record, column) -%> + <% authorized = record.authorized_for?(:action => :read, :column => column.name) -%> + <% column_value = authorized ? get_column_value(record, column) : active_scaffold_config.list.empty_field_text -%> <td class="<%= column_class(column, column_value) %>" > - <%= record.authorized_for?(:action => :read, :column => column.name) ? render_list_column(column_value, column, record) : '' %> + <%= authorized ? render_list_column(column_value, column, record) : column_value %> </td> <% end -%> <td class="actions"> From 78d1e0ec87a3e88e2176b668f064c2810ddd905e Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Tue, 1 Dec 2009 16:31:11 +0100 Subject: [PATCH 0142/2024] Bugfix: load ActiveScaffold Plugin in test mock_app --- test/mock_app/config/environment.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/mock_app/config/environment.rb b/test/mock_app/config/environment.rb index fb79f2bb7a..8602ac9f6d 100644 --- a/test/mock_app/config/environment.rb +++ b/test/mock_app/config/environment.rb @@ -23,6 +23,8 @@ # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named # config.plugins = [ :exception_notification, :ssl_requirement, :all ] + config.plugin_paths += %W(#{RAILS_ROOT}/../../..) + config.plugins = [:active_scaffold] # Skip frameworks you're not going to use. To use Rails without a database, # you must remove the Active Record framework. From 6852a783c28c576ba93be032c4ab391eba5c455e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 1 Dec 2009 17:12:29 +0100 Subject: [PATCH 0143/2024] set i18n_number as form_ui default for columns with number type --- lib/active_scaffold/data_structures/column.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 8c10fe6ea0..9a56237718 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -251,6 +251,7 @@ def initialize(name, active_record_class) #:nodoc: @show_blank_record = self.class.show_blank_record @actions_for_association_links = self.class.actions_for_association_links.clone if @association @search_ui = :select if @association and not polymorphic_association? + @form_ui = :i18n_number if @column.number? # default all the configurable variables self.css_class = '' From 3552197b2715b46099e7c13db2a6123e32e8d7fa Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 1 Dec 2009 17:36:05 +0100 Subject: [PATCH 0144/2024] Fix for virtual columns, were broken with last commit --- lib/active_scaffold/data_structures/column.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 9a56237718..370d8960cd 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -251,7 +251,7 @@ def initialize(name, active_record_class) #:nodoc: @show_blank_record = self.class.show_blank_record @actions_for_association_links = self.class.actions_for_association_links.clone if @association @search_ui = :select if @association and not polymorphic_association? - @form_ui = :i18n_number if @column.number? + @form_ui = :i18n_number if @column.try(:number?) # default all the configurable variables self.css_class = '' From 139aa991a6cd4622ec7da71f60061993e6e8e5fa Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 2 Dec 2009 17:20:44 +0100 Subject: [PATCH 0145/2024] Support native number format (using dot as decimal separator) apart from format for current locale --- lib/active_scaffold/attribute_params.rb | 10 +++++++++- test/data_structures/action_columns_test.rb | 8 -------- test/misc/constraints_test.rb | 4 ++-- test/test_helper.rb | 7 +++++++ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index b99d458e3e..34d0ee20dd 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -121,7 +121,15 @@ def column_value_from_param_value(parent_record, column, value) # it's an array of ids column.association.klass.find(value) if value and not value.empty? elsif [:i18n_number, :currency].include?(column.form_ui) - value.gsub(/[^0-9\-#{I18n.t(:'number.format.separator')}]/, '').gsub(I18n.t(:'number.format.separator'), '.') + native = '.' + delimiter = I18n.t('number.format.delimiter') + separator = I18n.t('number.format.separator') + + unless delimiter == native && !value.include?(separator) && value !~ /\.\d{3}$/ + value.gsub(/[^0-9\-#{I18n.t('number.format.separator')}]/, '').gsub(I18n.t('number.format.separator'), native) + else + value + end else # convert empty strings into nil. this works better with 'null => true' columns (and validations), # and 'null => false' columns should just convert back to an empty string. diff --git a/test/data_structures/action_columns_test.rb b/test/data_structures/action_columns_test.rb index 550742121a..b99760fb92 100644 --- a/test/data_structures/action_columns_test.rb +++ b/test/data_structures/action_columns_test.rb @@ -2,14 +2,6 @@ # require 'test/model_stub' require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/data_structures/set.rb') -ActiveScaffold::DataStructures::ActionColumns.class_eval do - #include Enumerable - include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration - def each - @set.each {|i| yield i} - end -end - class ActionColumnsTest < Test::Unit::TestCase def setup @columns = ActiveScaffold::DataStructures::ActionColumns.new([:a, :b]) diff --git a/test/misc/constraints_test.rb b/test/misc/constraints_test.rb index 73283847e0..93eafa2cf2 100644 --- a/test/misc/constraints_test.rb +++ b/test/misc/constraints_test.rb @@ -187,7 +187,7 @@ def assert_constraint_condition(constraint, condition, message = nil) assert_equal condition, @test_object.send(:conditions_from_constraints), message end - def config_for(klass) - ActiveScaffold::Config::Core.new("model_stubs/#{klass.to_s.underscore.downcase}") + def config_for(klass, namespace = nil) + super(klass, "model_stubs/") end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 55c98436d4..07ba5f1e4a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -30,3 +30,10 @@ def quote_column_name(name) name end end + +class Test::Unit::TestCase + protected + def config_for(klass, namespace = nil) + ActiveScaffold::Config::Core.new("#{namespace}#{klass.to_s.underscore.downcase}") + end +end \ No newline at end of file From 3a3bb59d195485a71f323bef7725136fec03402e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 2 Dec 2009 17:23:05 +0100 Subject: [PATCH 0146/2024] Add test convert number format --- test/misc/attribute_params_test.rb | 111 +++++++++++++++++++ test/mock_app/vendor/plugins/active_scaffold | 1 - 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 test/misc/attribute_params_test.rb delete mode 120000 test/mock_app/vendor/plugins/active_scaffold diff --git a/test/misc/attribute_params_test.rb b/test/misc/attribute_params_test.rb new file mode 100644 index 0000000000..e16c02c48f --- /dev/null +++ b/test/misc/attribute_params_test.rb @@ -0,0 +1,111 @@ +require File.join(File.dirname(__FILE__), '../test_helper.rb') + +class NumberModel < ActiveRecord::Base + abstract_class = true + def self.columns + @columns ||= [ActiveRecord::ConnectionAdapters::Column.new('number', '', 'double(10,2)')] + end +end + +class AttributeParamsTest < Test::Unit::TestCase + include ActiveScaffold::AttributeParams + + def setup + I18n.backend.store_translations :en, :number => {:format => { + :delimiter => ',', + :separator => '.' + }} + I18n.backend.store_translations :es, :number => {:format => { + :delimiter => '.', + :separator => ',' + }} + + @config = config_for('number_model') + @config.columns[:number].form_ui = :i18n_number + class << @config.list.columns + include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration + end + @config.list.columns.set_columns @config.columns + end + + def teardown + I18n.locale = :en + end + + def test_english_format_with_decimal_separator_using_english_language + I18n.locale = :en + assert_equal 0.1, convert_number('.1') + assert_equal 0.1, convert_number('.100') + assert_equal 0.1, convert_number('0.1') + assert_equal 0.345, convert_number('0.345') + assert_equal 0.345, convert_number('+0.345') + assert_equal -0.345, convert_number('-0.345') + assert_equal 9.345, convert_number('9.345') + assert_equal 9.1, convert_number('9.1') + assert_equal 90.1, convert_number('90.1') + end + + def test_english_format_with_thousand_delimiter_using_english_language + I18n.locale = :en + assert_equal 1000, convert_number('1,000') + assert_equal 1000, convert_number('+1,000') + assert_equal -1000, convert_number('-1,000') + assert_equal 1000000, convert_number('1,000,000') + end + + def test_english_format_with_separator_and_delimiter_using_english_language + I18n.locale = :en + assert_equal 1234.1, convert_number('1,234.1') + assert_equal 1234.1, convert_number('1,234.100') + assert_equal 1234.345, convert_number('+1,234.345') + assert_equal -1234.345, convert_number('-1,234.345') + assert_equal 1234000.1, convert_number('1,234,000.100') + end + + def test_english_format_with_decimal_separator_using_spanish_language + I18n.locale = :es + assert_equal 0.1, convert_number('.1') + assert_equal 0.1, convert_number('0.1') + assert_equal 0.12, convert_number('+0.12') + assert_equal -0.12, convert_number('-0.12') + assert_equal 9.1, convert_number('9.1') + assert_equal 90.1, convert_number('90.1') + end + + def test_spanish_format_with_decimal_separator_using_spanish_language + I18n.locale = :es + assert_equal 0.1, convert_number(',1') + assert_equal 0.1, convert_number(',100') + assert_equal 0.1, convert_number('0,1') + assert_equal 0.345, convert_number('0,345') + assert_equal 0.345, convert_number('+0,345') + assert_equal -0.345, convert_number('-0,345') + assert_equal 9.1, convert_number('9,1') + assert_equal 90.1, convert_number('90,1') + assert_equal 9.1, convert_number('9,100') + end + + def test_spanish_format_with_thousand_delimiter_using_spanish_language + I18n.locale = :es + assert_equal 1000, convert_number('1.000') + assert_equal 1000, convert_number('+1.000') + assert_equal -1000, convert_number('-1.000') + assert_equal 1000000, convert_number('1.000.000') + end + + def test_spanish_format_with_separator_and_decimal_using_spanish_language + I18n.locale = :es + assert_equal 1230.1, convert_number('1.230,1') + assert_equal 1230.1, convert_number('1.230,100') + assert_equal 1234.345, convert_number('+1.234,345') + assert_equal -1234.345, convert_number('-1.234,345') + assert_equal 1234000.1, convert_number('1.234.000,100') + end + + private + def convert_number(value) + record = NumberModel.new + update_record_from_params(record, @config.list.columns, HashWithIndifferentAccess.new({:number => value})) + record.number + end +end diff --git a/test/mock_app/vendor/plugins/active_scaffold b/test/mock_app/vendor/plugins/active_scaffold deleted file mode 120000 index c866b86874..0000000000 --- a/test/mock_app/vendor/plugins/active_scaffold +++ /dev/null @@ -1 +0,0 @@ -../../../.. \ No newline at end of file From 74fb82738be7ec955fe60a6cea696500aed512c7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 3 Dec 2009 09:20:20 +0100 Subject: [PATCH 0147/2024] Use config.label when sti_create_links is not set --- frontends/default/views/_create_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index f8ea9b0572..ab2f5d484f 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -27,7 +27,7 @@ else :class => 'create' end -%> - <h4><%= active_scaffold_config.create.label(@record.class.human_name(:count => 1)) -%></h4> + <h4><%= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.human_name(:count => 1) : nil) -%></h4> <div id="<%= element_messages_id(:action => :create) %>" class="messages-container"> <% if request.xhr? -%> From 1757d0821fcd8c387f8e20e3bbd79fe9491f8be2 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 3 Dec 2009 09:57:29 +0100 Subject: [PATCH 0148/2024] Move i18n_number and currency from form_ui to options[:format], add percentage and size too --- lib/active_scaffold/attribute_params.rb | 2 +- lib/active_scaffold/data_structures/column.rb | 2 +- lib/active_scaffold/helpers/form_column_helpers.rb | 8 +------- lib/active_scaffold/helpers/list_column_helpers.rb | 10 +++++++--- test/misc/attribute_params_test.rb | 1 - 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 34d0ee20dd..5739ae42c0 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -120,7 +120,7 @@ def column_value_from_param_value(parent_record, column, value) elsif column.plural_association? # it's an array of ids column.association.klass.find(value) if value and not value.empty? - elsif [:i18n_number, :currency].include?(column.form_ui) + elsif column.column && column.column.number? && [:i18n_number, :currency].include?(column.options[:format]) native = '.' delimiter = I18n.t('number.format.delimiter') separator = I18n.t('number.format.separator') diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 370d8960cd..083fb74158 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -251,7 +251,7 @@ def initialize(name, active_record_class) #:nodoc: @show_blank_record = self.class.show_blank_record @actions_for_association_links = self.class.actions_for_association_links.clone if @association @search_ui = :select if @association and not polymorphic_association? - @form_ui = :i18n_number if @column.try(:number?) + @options = {:format => :i18n_number} if @column.try(:number?) # default all the configurable variables self.css_class = '' diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index df906dadf0..3b5df5274f 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -34,6 +34,7 @@ def active_scaffold_input_for(column, scope = nil) options[:maxlength] = column.column.limit options[:size] ||= ActionView::Helpers::InstanceTag::DEFAULT_FIELD_OPTIONS["size"] end + options.update(:value => format_number_value(@record.send(column.name), column.options)) if column.column.number? input(:record, column.name, options.merge(column.options)) end end @@ -195,13 +196,6 @@ def active_scaffold_input_textarea(column, options) text_area(:record, column.name, options.merge(:cols => column.options[:cols], :rows => column.options[:rows], :size => column.options[:size])) end - def active_scaffold_input_i18n_number(column, options) - options = active_scaffold_input_text_options(options).merge(column.options) - options.delete(:i18n_options) - text_field_tag(column.name, format_number_value(@record.send(column.name), column.form_ui, column.options), options) - end - alias_method :active_scaffold_input_currency, :active_scaffold_input_i18n_number - def active_scaffold_input_virtual(column, options) options = active_scaffold_input_text_options(options) text_field :record, column.name, options.merge(column.options) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 88e788249c..01b9998cb6 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -150,7 +150,7 @@ def format_column_value(record, column) end if column.association.nil? or column_empty?(value) if value.is_a? Numeric - format_number_value(value, column.list_ui, column.options) + format_number_value(value, column.options) else format_value(value, column.options) end @@ -159,8 +159,12 @@ def format_column_value(record, column) end end - def format_number_value(value, ui, options = {}) - value = case ui + def format_number_value(value, options = {}) + value = case options[:format] + when :size + number_to_human_size(value, options[:i18n_options] || {}) + when :percentage + number_to_percentage(value, options[:i18n_options] || {}) when :currency number_to_currency(value, options[:i18n_options] || {}) when :i18n_number diff --git a/test/misc/attribute_params_test.rb b/test/misc/attribute_params_test.rb index e16c02c48f..a263169cd1 100644 --- a/test/misc/attribute_params_test.rb +++ b/test/misc/attribute_params_test.rb @@ -21,7 +21,6 @@ def setup }} @config = config_for('number_model') - @config.columns[:number].form_ui = :i18n_number class << @config.list.columns include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration end From 0024017b2c98208be0236071392ae5dfee71e45b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 3 Dec 2009 10:00:45 +0100 Subject: [PATCH 0149/2024] Fix issue #719 with loading indicator in search action --- frontends/default/views/_search.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index b1a71a10b0..a32203066a 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -2,8 +2,8 @@ <%= form_remote_tag :url => href, :method => :get, :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", - :after => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{search_form_id}');", - :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{search_form_id}');", + :after => "$('#{loading_indicator_id(:action => :search)}').style.visibility = 'visible'; Form.disable('#{search_form_id}');", + :complete => "$('#{loading_indicator_id(:action => :search)}').style.visibility = 'hidden'; Form.enable('#{search_form_id}');", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :update => active_scaffold_content_id, :html => { :href => href, :id => search_form_id, :class => 'search', :method => :get } %> From 87437c3327c0b24a3e7e9f3deb915dedf2bc3250 Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Tue, 29 Dec 2009 09:38:15 +0100 Subject: [PATCH 0150/2024] added basic support for named_scopes --- lib/active_scaffold/actions/core.rb | 6 ++- lib/active_scaffold/finder.rb | 29 +++++++++--- test/misc/finder_test.rb | 3 ++ test/misc/named_scope_test.rb | 69 +++++++++++++++++++++++++++++ test/model_stub.rb | 16 +++++++ 5 files changed, 116 insertions(+), 7 deletions(-) create mode 100644 test/misc/named_scope_test.rb diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 3663d2d25d..2f5427b6a4 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -101,7 +101,11 @@ def custom_finder_options {} end - + #Overide this method on your controller to provide model with named scopes + def named_scopes_for_collection + nil + end + # Builds search conditions by search params for column names. This allows urls like "contacts/list?company_id=5". def conditions_from_params conditions = nil diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index c98a965bc2..ca5e283d15 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -126,7 +126,26 @@ def all_conditions active_scaffold_session_storage[:conditions] # embedding conditions (weaker constraints) ) end - + + def model_with_named_scope(scope_definitions = named_scopes_for_collection) + case scope_definitions + when String + active_scaffold_config.model.instance_eval(scope_definitions) + when Symbol + active_scaffold_config.model.send(scope_definitions) + when Array + if scope_definitions.first.is_a?(Array) + scope_definitions.inject(active_scaffold_config.model) do |records, scope_definition| + records = model_with_named_scope(scope_definition) + end + else + active_scaffold_config.model.send(*scope_definitions) + end + else + active_scaffold_config.model + end + end + # returns a single record (the given id) but only if it's allowed for the specified action. # accomplishes this by checking model.#{action}_authorized? # TODO: this should reside on the model, not the controller @@ -152,8 +171,6 @@ def find_page(options = {}) options[:page] ||= 1 options[:count_includes] ||= full_includes unless search_conditions.nil? - klass = active_scaffold_config.model - # create a general-use options array that's compatible with Rails finders finder_options = { :order => options[:sorting].try(:clause), :conditions => search_conditions, @@ -163,7 +180,7 @@ def find_page(options = {}) finder_options.merge! custom_finder_options # NOTE: we must use :include in the count query, because some conditions may reference other tables - count = klass.count(finder_options.reject{|k,v| [:select, :order].include? k}) + count = model_with_named_scope.count(finder_options.reject{|k,v| [:select, :order].include? k}) # Converts count to an integer if ActiveRecord returned an OrderedHash # that happens when finder_options contains a :group key @@ -174,12 +191,12 @@ def find_page(options = {}) # we build the paginator differently for method- and sql-based sorting if options[:sorting] and options[:sorting].sorts_by_method? pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| - sorted_collection = sort_collection_by_column(klass.find(:all, finder_options), *options[:sorting].first) + sorted_collection = sort_collection_by_column(model_with_named_scope.all(finder_options), *options[:sorting].first) sorted_collection.slice(offset, per_page) end else pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| - klass.find(:all, finder_options.merge(:offset => offset, :limit => per_page)) + model_with_named_scope.all(finder_options.merge(:offset => offset, :limit => per_page)) end end diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index d61bf3c9cb..c15489f210 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -10,6 +10,9 @@ def joins_for_collection; end def custom_finder_options {} end + def named_scopes_for_collection + nil + end end class FinderTest < Test::Unit::TestCase diff --git a/test/misc/named_scope_test.rb b/test/misc/named_scope_test.rb new file mode 100644 index 0000000000..5b84ab81a5 --- /dev/null +++ b/test/misc/named_scope_test.rb @@ -0,0 +1,69 @@ +require File.join(File.dirname(__FILE__), '../test_helper.rb') + +class ClassWithFinder + include ActiveScaffold::Finder + def conditions_for_collection; end + def conditions_from_params; end + def conditions_from_constraints; end + def joins_for_collection; end + def custom_finder_options + {} + end + def named_scopes_for_collection + nil + end +end + +class NamedScopeTest < Test::Unit::TestCase + def setup + @klass = ClassWithFinder.new + @klass.stubs(:active_scaffold_config).returns(mock { stubs(:model).returns(ModelStub) }) + @klass.stubs(:active_scaffold_session_storage).returns({}) + ModelStub.nested_scope_calls.clear + end + + def test_named_scope_as_symbol + @klass.instance_eval do + def named_scopes_for_collection + :a_is_defined + end + end + model = @klass.send(:model_with_named_scope) + assert_equal 1, model.nested_scope_calls.length + end + + def test_named_scope_as_string + @klass.instance_eval do + def named_scopes_for_collection + "a_is_defined.b_like('hello')" + end + end + model = @klass.send(:model_with_named_scope) + assert_equal 2, model.nested_scope_calls.length + assert_equal :a_is_defined, model.nested_scope_calls.first + assert_equal :b_like, model.nested_scope_calls.last + end + + def test_named_scope_as_array + @klass.instance_eval do + def named_scopes_for_collection + [:b_like, 'hello'] + end + end + model = @klass.send(:model_with_named_scope) + assert_equal 1, model.nested_scope_calls.length + assert_equal :b_like, model.nested_scope_calls.first + end + + def test_named_scope_as_array_of_array + @klass.instance_eval do + def named_scopes_for_collection + [[:b_like, 'hello'], [:a_is_defined]] + end + end + model = @klass.send(:model_with_named_scope) + assert_equal 2, model.nested_scope_calls.length + assert_equal :b_like, model.nested_scope_calls.first + assert_equal :a_is_defined, model.nested_scope_calls.last + end +end diff --git a/test/model_stub.rb b/test/model_stub.rb index 32550a6d9e..270e2f10a2 100644 --- a/test/model_stub.rb +++ b/test/model_stub.rb @@ -6,6 +6,22 @@ class ModelStub < ActiveRecord::Base cattr_accessor :stubbed_columns self.stubbed_columns = [:a, :b, :c, :d, :id] attr_accessor *self.stubbed_columns + + @@nested_scope_calls = [] + cattr_accessor :nested_scope_calls + + named_scope :a_is_defined, :conditions => "a is not null" + named_scope :b_like, lambda {|pattern| {:conditions => ["b like ?", pattern]}} + + def self.a_is_defined + @@nested_scope_calls << :a_is_defined + self + end + + def self.b_like(pattern) + @@nested_scope_calls << :b_like + self + end def other_model=(val) @other_model = val From 7c5f070dd7253c3d868b0cd5c5d2a76c20e294ee Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Tue, 29 Dec 2009 10:50:32 +0100 Subject: [PATCH 0151/2024] Named Scopes: improved nested array detection Bugfix: concatenation of named_scopes calls in array format fixed --- lib/active_scaffold/finder.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index ca5e283d15..2e8d76b3e2 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -127,22 +127,20 @@ def all_conditions ) end - def model_with_named_scope(scope_definitions = named_scopes_for_collection) + def model_with_named_scope(model = active_scaffold_config.model, scope_definitions = named_scopes_for_collection) case scope_definitions when String - active_scaffold_config.model.instance_eval(scope_definitions) + model.instance_eval(scope_definitions) when Symbol - active_scaffold_config.model.send(scope_definitions) + model.send(scope_definitions) when Array - if scope_definitions.first.is_a?(Array) - scope_definitions.inject(active_scaffold_config.model) do |records, scope_definition| - records = model_with_named_scope(scope_definition) - end + if scope_definitions.any?{|element| element.is_a?(Array)} + scope_definitions.inject(model) {|records, scope_definition| records = model_with_named_scope(records, scope_definition)} else - active_scaffold_config.model.send(*scope_definitions) + model.send(*scope_definitions) end else - active_scaffold_config.model + model end end @@ -171,6 +169,8 @@ def find_page(options = {}) options[:page] ||= 1 options[:count_includes] ||= full_includes unless search_conditions.nil? + klass = model_with_named_scope + # create a general-use options array that's compatible with Rails finders finder_options = { :order => options[:sorting].try(:clause), :conditions => search_conditions, @@ -180,7 +180,7 @@ def find_page(options = {}) finder_options.merge! custom_finder_options # NOTE: we must use :include in the count query, because some conditions may reference other tables - count = model_with_named_scope.count(finder_options.reject{|k,v| [:select, :order].include? k}) + count = klass.count(finder_options.reject{|k,v| [:select, :order].include? k}) # Converts count to an integer if ActiveRecord returned an OrderedHash # that happens when finder_options contains a :group key @@ -191,12 +191,12 @@ def find_page(options = {}) # we build the paginator differently for method- and sql-based sorting if options[:sorting] and options[:sorting].sorts_by_method? pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| - sorted_collection = sort_collection_by_column(model_with_named_scope.all(finder_options), *options[:sorting].first) + sorted_collection = sort_collection_by_column(klass.all(finder_options), *options[:sorting].first) sorted_collection.slice(offset, per_page) end else pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| - model_with_named_scope.all(finder_options.merge(:offset => offset, :limit => per_page)) + klass.all(finder_options.merge(:offset => offset, :limit => per_page)) end end From dfacdbdcf940dd063bf2d4d13aba906615da7d9d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 5 Jan 2010 11:22:05 +0100 Subject: [PATCH 0152/2024] Fix icons set as background in IE --- frontends/default/stylesheets/stylesheet-ie.css | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet-ie.css b/frontends/default/stylesheets/stylesheet-ie.css index d8759cfc9a..7992a64468 100644 --- a/frontends/default/stylesheets/stylesheet-ie.css +++ b/frontends/default/stylesheets/stylesheet-ie.css @@ -11,14 +11,14 @@ zoom: 1; border-top: solid 1px #DAFFCD; } -.active-scaffold-header div.actions a.show_search { +* html .active-scaffold-header div.actions a.show_search { background-image: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/active_scaffold/default/magnifier.png', sizingMethod='crop'); +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../../images/active_scaffold/default/magnifier.png', sizingMethod='crop'); } -.active-scaffold .sub-form .association-record a.destroy { +* html .active-scaffold .sub-form .association-record a.destroy { background-image: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/active_scaffold/default/cross.png', sizingMethod='crop'); +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../../images/active_scaffold/default/cross.png', sizingMethod='crop'); } .active-scaffold-header div.actions a.disabled { @@ -32,4 +32,4 @@ float: none; .active-scaffold li.form-element dt { padding: 4px 0; -} \ No newline at end of file +} From 4d51968107980e31e761759d04094de9dc952e91 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 5 Jan 2010 12:16:38 +0100 Subject: [PATCH 0153/2024] Fix issue 608, quote table in order clause --- lib/active_scaffold/data_structures/column.rb | 2 +- test/data_structures/association_column_test.rb | 2 +- test/data_structures/column_test.rb | 6 +++--- test/data_structures/sorting_test.rb | 2 +- test/data_structures/standard_column_test.rb | 4 ++-- test/misc/constraints_test.rb | 2 +- test/misc/finder_test.rb | 4 ++-- .../active_scaffold/default/stylesheet-ie.css | 10 +++++----- test/test_helper.rb | 8 +------- 9 files changed, 17 insertions(+), 23 deletions(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 083fb74158..dbc41642aa 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -317,7 +317,7 @@ def initialize_search_sql # the table.field name for this column, if applicable def field - @field ||= [@table, field_name].join('.') + @field ||= [@active_record_class.connection.quote_column_name(@table), field_name].join('.') end end end diff --git a/test/data_structures/association_column_test.rb b/test/data_structures/association_column_test.rb index 7570ab6287..b4d9210075 100644 --- a/test/data_structures/association_column_test.rb +++ b/test/data_structures/association_column_test.rb @@ -20,7 +20,7 @@ def test_sorting def test_searching # by default searching on association columns uses primary key assert @association_column.searchable? - assert_equal 'model_stubs.id', @association_column.search_sql + assert_equal '`model_stubs`.`id`', @association_column.search_sql end def test_association diff --git a/test/data_structures/column_test.rb b/test/data_structures/column_test.rb index 8028a51511..3035ae4cca 100644 --- a/test/data_structures/column_test.rb +++ b/test/data_structures/column_test.rb @@ -41,7 +41,7 @@ def test_basic_properties end def test_field - assert_equal 'model_stubs.a', @column.send(:field) + assert_equal '`model_stubs`.`a`', @column.send(:field) end def test_table @@ -96,7 +96,7 @@ def test_sortable def test_custom_search @column.search_sql = true - assert_equal 'model_stubs.a', @column.search_sql + assert_equal '`model_stubs`.`a`', @column.search_sql @column.search_sql = 'foobar' assert_equal 'foobar', @column.search_sql assert @column.searchable? @@ -104,7 +104,7 @@ def test_custom_search def test_custom_sort @column.sort = true - hash = {:sql => 'model_stubs.a'} + hash = {:sql => '`model_stubs`.`a`'} assert_equal hash, @column.sort @column.sort_by :sql => 'foobar' hash = {:sql => 'foobar'} diff --git a/test/data_structures/sorting_test.rb b/test/data_structures/sorting_test.rb index d6aaa87b57..c8a390115a 100644 --- a/test/data_structures/sorting_test.rb +++ b/test/data_structures/sorting_test.rb @@ -100,7 +100,7 @@ def test_build_order_clause @sorting << [:a, 'desc'] @sorting << [:b, 'asc'] - assert_equal 'model_stubs.a DESC, model_stubs.b ASC', @sorting.clause + assert_equal '`model_stubs`.`a` DESC, `model_stubs`.`b` ASC', @sorting.clause end def test_set_default_sorting_with_simple_default_scope diff --git a/test/data_structures/standard_column_test.rb b/test/data_structures/standard_column_test.rb index 8ed10abe11..85ddbf541d 100644 --- a/test/data_structures/standard_column_test.rb +++ b/test/data_structures/standard_column_test.rb @@ -12,13 +12,13 @@ def test_virtuality end def test_sorting - hash = {:sql => 'model_stubs.a'} + hash = {:sql => '`model_stubs`.`a`'} assert @standard_column.sortable? assert_equal hash, @standard_column.sort # check default end def test_searching assert @standard_column.searchable? - assert_equal 'model_stubs.a', @standard_column.search_sql # check default + assert_equal '`model_stubs`.`a`', @standard_column.search_sql # check default end end diff --git a/test/misc/constraints_test.rb b/test/misc/constraints_test.rb index 93eafa2cf2..1059c3570e 100644 --- a/test/misc/constraints_test.rb +++ b/test/misc/constraints_test.rb @@ -170,7 +170,7 @@ def test_constraint_conditions_for_configured_associations def test_constraint_conditions_for_normal_attributes @test_object.active_scaffold_config = config_for('user') - assert_constraint_condition({'foo' => 'bar'}, ['users.foo = ?', 'bar'], 'normal column-based constraint') + assert_constraint_condition({'foo' => 'bar'}, ['`users`.`foo` = ?', 'bar'], 'normal column-based constraint') end def test_constraint_conditions_for_associations_with_primary_key_option diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index c15489f210..7d2ea5e07f 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -33,13 +33,13 @@ def test_create_conditions_for_columns ] expected_conditions = [ - '(LOWER(model_stubs.a) LIKE ? OR LOWER(model_stubs.b) LIKE ?) AND (LOWER(model_stubs.a) LIKE ? OR LOWER(model_stubs.b) LIKE ?)', + '(LOWER(`model_stubs`.`a`) LIKE ? OR LOWER(`model_stubs`.`b`) LIKE ?) AND (LOWER(`model_stubs`.`a`) LIKE ? OR LOWER(`model_stubs`.`b`) LIKE ?)', '%foo%', '%foo%', '%bar%', '%bar%' ] assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns(tokens, columns) expected_conditions = [ - '(LOWER(model_stubs.a) LIKE ? OR LOWER(model_stubs.b) LIKE ?)', + '(LOWER(`model_stubs`.`a`) LIKE ? OR LOWER(`model_stubs`.`b`) LIKE ?)', '%foo%', '%foo%' ] assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns('foo', columns) diff --git a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css index d8759cfc9a..7992a64468 100644 --- a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +++ b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css @@ -11,14 +11,14 @@ zoom: 1; border-top: solid 1px #DAFFCD; } -.active-scaffold-header div.actions a.show_search { +* html .active-scaffold-header div.actions a.show_search { background-image: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/active_scaffold/default/magnifier.png', sizingMethod='crop'); +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../../images/active_scaffold/default/magnifier.png', sizingMethod='crop'); } -.active-scaffold .sub-form .association-record a.destroy { +* html .active-scaffold .sub-form .association-record a.destroy { background-image: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/active_scaffold/default/cross.png', sizingMethod='crop'); +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../../images/active_scaffold/default/cross.png', sizingMethod='crop'); } .active-scaffold-header div.actions a.disabled { @@ -32,4 +32,4 @@ float: none; .active-scaffold li.form-element dt { padding: 4px 0; -} \ No newline at end of file +} diff --git a/test/test_helper.rb b/test/test_helper.rb index 07ba5f1e4a..1f1430ca84 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -25,15 +25,9 @@ def silence_stderr(&block) require File.join(File.dirname(__FILE__), file) end -ModelStub.connection.instance_eval do - def quote_column_name(name) - name - end -end - class Test::Unit::TestCase protected def config_for(klass, namespace = nil) ActiveScaffold::Config::Core.new("#{namespace}#{klass.to_s.underscore.downcase}") end -end \ No newline at end of file +end From a5106a5ee7dbec7c483b7268e2d7e2b89947cf21 Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Wed, 13 Jan 2010 16:43:29 +0100 Subject: [PATCH 0154/2024] Bugfix: set column object in action columns assignment, fixes exception in before_filters --- lib/active_scaffold/config/base.rb | 9 +++++++++ lib/active_scaffold/config/field_search.rb | 5 +---- lib/active_scaffold/config/form.rb | 5 +---- lib/active_scaffold/config/list.rb | 6 ++---- lib/active_scaffold/config/live_search.rb | 5 +---- lib/active_scaffold/config/search.rb | 5 +---- lib/active_scaffold/config/show.rb | 6 ++---- lib/active_scaffold/config/subform.rb | 6 +----- 8 files changed, 18 insertions(+), 29 deletions(-) diff --git a/lib/active_scaffold/config/base.rb b/lib/active_scaffold/config/base.rb index 22ada40dbe..a31fb8d005 100644 --- a/lib/active_scaffold/config/base.rb +++ b/lib/active_scaffold/config/base.rb @@ -41,5 +41,14 @@ def formats def formats=(val) @formats=val end + + private + + def columns=(val) + @columns = ActiveScaffold::DataStructures::ActionColumns.new(*val) + @columns.action = self + @columns.set_columns(@core.columns) if @columns.respond_to?(:set_columns) + @columns + end end end diff --git a/lib/active_scaffold/config/field_search.rb b/lib/active_scaffold/config/field_search.rb index c3268272a6..cbb9ff8d68 100644 --- a/lib/active_scaffold/config/field_search.rb +++ b/lib/active_scaffold/config/field_search.rb @@ -37,10 +37,7 @@ def columns @columns end - def columns=(val) - @columns = ActiveScaffold::DataStructures::ActionColumns.new(*val) - @columns.action = self - end + public :columns= attr_writer :full_text_search def full_text_search? diff --git a/lib/active_scaffold/config/form.rb b/lib/active_scaffold/config/form.rb index e1f84cb756..47fcde94cf 100644 --- a/lib/active_scaffold/config/form.rb +++ b/lib/active_scaffold/config/form.rb @@ -35,10 +35,7 @@ def columns @columns end - def columns=(val) - @columns = ActiveScaffold::DataStructures::ActionColumns.new(*val) - @columns.action = self - end + public :columns= # whether the form should be multipart attr_writer :multipart diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index fbab784e1c..ef39248c0f 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -35,10 +35,8 @@ def columns self.columns = @core.columns._inheritable unless @columns # lazy evaluation @columns end - def columns=(val) - @columns = ActiveScaffold::DataStructures::ActionColumns.new(*val) - @columns.action = self - end + + public :columns= # how many rows to show at once attr_accessor :per_page diff --git a/lib/active_scaffold/config/live_search.rb b/lib/active_scaffold/config/live_search.rb index 7f7638e396..60c48b5abc 100644 --- a/lib/active_scaffold/config/live_search.rb +++ b/lib/active_scaffold/config/live_search.rb @@ -36,10 +36,7 @@ def columns @columns end - def columns=(val) - @columns = ActiveScaffold::DataStructures::ActionColumns.new(*val) - @columns.action = self - end + public :columns= attr_writer :full_text_search def full_text_search? diff --git a/lib/active_scaffold/config/search.rb b/lib/active_scaffold/config/search.rb index c129e8ecfd..1761082ecb 100644 --- a/lib/active_scaffold/config/search.rb +++ b/lib/active_scaffold/config/search.rb @@ -36,10 +36,7 @@ def columns @columns end - def columns=(val) - @columns = ActiveScaffold::DataStructures::ActionColumns.new(*val) - @columns.action = self - end + public :columns= attr_writer :full_text_search def full_text_search? diff --git a/lib/active_scaffold/config/show.rb b/lib/active_scaffold/config/show.rb index f9dbd2edcb..1aac87d201 100644 --- a/lib/active_scaffold/config/show.rb +++ b/lib/active_scaffold/config/show.rb @@ -28,9 +28,7 @@ def columns self.columns = @core.columns._inheritable unless @columns # lazy evaluation @columns end - def columns=(val) - @columns = ActiveScaffold::DataStructures::ActionColumns.new(*val) - @columns.action = self - end + + public :columns= end end diff --git a/lib/active_scaffold/config/subform.rb b/lib/active_scaffold/config/subform.rb index e6becd2bbf..25c43e47b7 100644 --- a/lib/active_scaffold/config/subform.rb +++ b/lib/active_scaffold/config/subform.rb @@ -27,10 +27,6 @@ def columns @columns end - def columns=(val) - @columns = ActiveScaffold::DataStructures::ActionColumns.new(*val) - @columns.action = self - return @columns - end + public :columns= end end From 1acd1ab6677ffe88937f777a29be35652655dc3f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 15 Jan 2010 09:53:20 +0100 Subject: [PATCH 0155/2024] Fix test, change quoting from mysql to sqlite format --- test/data_structures/association_column_test.rb | 2 +- test/data_structures/column_test.rb | 6 +++--- test/data_structures/sorting_test.rb | 2 +- test/data_structures/standard_column_test.rb | 4 ++-- test/misc/constraints_test.rb | 2 +- test/misc/finder_test.rb | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/data_structures/association_column_test.rb b/test/data_structures/association_column_test.rb index b4d9210075..0abe073a47 100644 --- a/test/data_structures/association_column_test.rb +++ b/test/data_structures/association_column_test.rb @@ -20,7 +20,7 @@ def test_sorting def test_searching # by default searching on association columns uses primary key assert @association_column.searchable? - assert_equal '`model_stubs`.`id`', @association_column.search_sql + assert_equal '"model_stubs"."id"', @association_column.search_sql end def test_association diff --git a/test/data_structures/column_test.rb b/test/data_structures/column_test.rb index 3035ae4cca..0efa7f13ac 100644 --- a/test/data_structures/column_test.rb +++ b/test/data_structures/column_test.rb @@ -41,7 +41,7 @@ def test_basic_properties end def test_field - assert_equal '`model_stubs`.`a`', @column.send(:field) + assert_equal '"model_stubs"."a"', @column.send(:field) end def test_table @@ -96,7 +96,7 @@ def test_sortable def test_custom_search @column.search_sql = true - assert_equal '`model_stubs`.`a`', @column.search_sql + assert_equal '"model_stubs"."a"', @column.search_sql @column.search_sql = 'foobar' assert_equal 'foobar', @column.search_sql assert @column.searchable? @@ -104,7 +104,7 @@ def test_custom_search def test_custom_sort @column.sort = true - hash = {:sql => '`model_stubs`.`a`'} + hash = {:sql => '"model_stubs"."a"'} assert_equal hash, @column.sort @column.sort_by :sql => 'foobar' hash = {:sql => 'foobar'} diff --git a/test/data_structures/sorting_test.rb b/test/data_structures/sorting_test.rb index c8a390115a..9d622a44f0 100644 --- a/test/data_structures/sorting_test.rb +++ b/test/data_structures/sorting_test.rb @@ -100,7 +100,7 @@ def test_build_order_clause @sorting << [:a, 'desc'] @sorting << [:b, 'asc'] - assert_equal '`model_stubs`.`a` DESC, `model_stubs`.`b` ASC', @sorting.clause + assert_equal '"model_stubs"."a" DESC, "model_stubs"."b" ASC', @sorting.clause end def test_set_default_sorting_with_simple_default_scope diff --git a/test/data_structures/standard_column_test.rb b/test/data_structures/standard_column_test.rb index 85ddbf541d..22a919d3aa 100644 --- a/test/data_structures/standard_column_test.rb +++ b/test/data_structures/standard_column_test.rb @@ -12,13 +12,13 @@ def test_virtuality end def test_sorting - hash = {:sql => '`model_stubs`.`a`'} + hash = {:sql => '"model_stubs"."a"'} assert @standard_column.sortable? assert_equal hash, @standard_column.sort # check default end def test_searching assert @standard_column.searchable? - assert_equal '`model_stubs`.`a`', @standard_column.search_sql # check default + assert_equal '"model_stubs"."a"', @standard_column.search_sql # check default end end diff --git a/test/misc/constraints_test.rb b/test/misc/constraints_test.rb index 1059c3570e..9e00d7f668 100644 --- a/test/misc/constraints_test.rb +++ b/test/misc/constraints_test.rb @@ -170,7 +170,7 @@ def test_constraint_conditions_for_configured_associations def test_constraint_conditions_for_normal_attributes @test_object.active_scaffold_config = config_for('user') - assert_constraint_condition({'foo' => 'bar'}, ['`users`.`foo` = ?', 'bar'], 'normal column-based constraint') + assert_constraint_condition({'foo' => 'bar'}, ['"users"."foo" = ?', 'bar'], 'normal column-based constraint') end def test_constraint_conditions_for_associations_with_primary_key_option diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index 7d2ea5e07f..e262c2e3e3 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -33,13 +33,13 @@ def test_create_conditions_for_columns ] expected_conditions = [ - '(LOWER(`model_stubs`.`a`) LIKE ? OR LOWER(`model_stubs`.`b`) LIKE ?) AND (LOWER(`model_stubs`.`a`) LIKE ? OR LOWER(`model_stubs`.`b`) LIKE ?)', + '(LOWER("model_stubs"."a") LIKE ? OR LOWER("model_stubs"."b") LIKE ?) AND (LOWER("model_stubs"."a") LIKE ? OR LOWER("model_stubs"."b") LIKE ?)', '%foo%', '%foo%', '%bar%', '%bar%' ] assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns(tokens, columns) expected_conditions = [ - '(LOWER(`model_stubs`.`a`) LIKE ? OR LOWER(`model_stubs`.`b`) LIKE ?)', + '(LOWER("model_stubs"."a") LIKE ? OR LOWER("model_stubs"."b") LIKE ?)', '%foo%', '%foo%' ] assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns('foo', columns) From 4e4116264ee0b9d66e8aa00d847d2909c89241b8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Feb 2010 09:46:46 +0100 Subject: [PATCH 0156/2024] Rename active_scaffold_joins to active_scaffold_includes, because it's used in include option of find method --- lib/active_scaffold/actions/field_search.rb | 2 +- lib/active_scaffold/actions/list.rb | 2 +- lib/active_scaffold/actions/live_search.rb | 2 +- lib/active_scaffold/actions/search.rb | 2 +- lib/active_scaffold/constraints.rb | 6 +++--- lib/active_scaffold/finder.rb | 18 ++++++++++++++---- lib/active_scaffold/helpers/view_helpers.rb | 2 +- test/misc/constraints_test.rb | 6 +++--- 8 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index 61f18065f5..dc65b0eb1f 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -35,7 +35,7 @@ def do_search @filtered = !search_conditions.blank? includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact - self.active_scaffold_joins.concat includes_for_search_columns + self.active_scaffold_includes.concat includes_for_search_columns active_scaffold_config.list.user.page = nil end diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index faea0be3db..907d36d9f2 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -56,7 +56,7 @@ def update_table_respond_to_js # The actual algorithm to prepare for the list view def do_list includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact - self.active_scaffold_joins.concat includes_for_list_columns + self.active_scaffold_includes.concat includes_for_list_columns options = { :sorting => active_scaffold_config.list.user.sorting, :count_includes => active_scaffold_config.list.user.count_includes } diff --git a/lib/active_scaffold/actions/live_search.rb b/lib/active_scaffold/actions/live_search.rb index 5228366baa..608b3f566d 100644 --- a/lib/active_scaffold/actions/live_search.rb +++ b/lib/active_scaffold/actions/live_search.rb @@ -34,7 +34,7 @@ def do_search @filtered = !search_conditions.blank? includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact - self.active_scaffold_joins.concat includes_for_search_columns + self.active_scaffold_includes.concat includes_for_search_columns active_scaffold_config.list.user.page = nil end diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index 858e244378..5c58b442ad 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -27,7 +27,7 @@ def do_search @filtered = !search_conditions.blank? includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact - self.active_scaffold_joins.concat includes_for_search_columns + self.active_scaffold_includes.concat includes_for_search_columns active_scaffold_config.list.user.page = nil end diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 86fd3cf90a..0a24256ecb 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -51,7 +51,7 @@ def conditions_from_constraints field = far_association.klass.primary_key table = far_association.table_name - active_scaffold_joins.concat([{k => v.keys.first}]) # e.g. {:den => :park} + active_scaffold_includes.concat([{k => v.keys.first}]) # e.g. {:den => :park} constraint_condition_for("#{table}.#{field}", v.values.first) # association column constraint @@ -59,13 +59,13 @@ def conditions_from_constraints if column.association.macro == :has_and_belongs_to_many active_scaffold_habtm_joins.concat column.includes else - active_scaffold_joins.concat column.includes + active_scaffold_includes.concat column.includes end condition_from_association_constraint(column.association, v) # regular column constraints elsif column.searchable? - active_scaffold_joins.concat column.includes + active_scaffold_includes.concat column.includes constraint_condition_for(column.search_sql, v) end # unknown-to-activescaffold-but-real-database-column constraint diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 2e8d76b3e2..1d75b7bdef 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -107,9 +107,19 @@ def active_scaffold_conditions @active_scaffold_conditions ||= [] end - attr_writer :active_scaffold_joins - def active_scaffold_joins - @active_scaffold_joins ||= [] + attr_writer :active_scaffold_includes + def active_scaffold_includes + if respond_to? :active_scaffold_joins + ::ActiveSupport::Deprecation.warn("You have defined active_scaffold_joins, but it's deprecated because it's confusing, you should use active_scaffold_includes now", caller) + return active_scaffold_joins + end + @active_scaffold_includes ||= [] + end + + # Deprecated method + def active_scaffold_joins=(value) + ::ActiveSupport::Deprecation.warn("active_scaffold_joins is deprecated because it's confusing, you should use active_scaffold_includes now", caller) + self.active_scaffold_includes = value end attr_writer :active_scaffold_habtm_joins @@ -163,7 +173,7 @@ def find_if_allowed(id, action, klass = nil) def find_page(options = {}) options.assert_valid_keys :sorting, :per_page, :page, :count_includes - full_includes = (active_scaffold_joins.blank? ? nil : active_scaffold_joins) + full_includes = (active_scaffold_includes.blank? ? nil : active_scaffold_includes) search_conditions = all_conditions options[:per_page] ||= 999999999 options[:page] ||= 1 diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index cc7d5f94b8..c32b674ba4 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -195,7 +195,7 @@ def column_empty?(column_value) def column_calculation(column) calculation = active_scaffold_config.model.calculate(column.calculate, column.name, :conditions => controller.send(:all_conditions), - :joins => controller.send(:joins_for_collection), :include => controller.send(:active_scaffold_joins)) + :joins => controller.send(:joins_for_collection), :include => controller.send(:active_scaffold_includes)) end end end diff --git a/test/misc/constraints_test.rb b/test/misc/constraints_test.rb index 9e00d7f668..3737e04062 100644 --- a/test/misc/constraints_test.rb +++ b/test/misc/constraints_test.rb @@ -83,7 +83,7 @@ class PrimaryKeyLocation < ModelStub class ConstraintsTestObject # stub out what the mixin expects to find ... def self.before_filter(*args); end - attr_accessor :active_scaffold_joins + attr_accessor :active_scaffold_includes attr_accessor :active_scaffold_habtm_joins attr_accessor :active_scaffold_config attr_accessor :params @@ -98,7 +98,7 @@ def merge_conditions(old, new) attr_accessor :active_scaffold_constraints def initialize - @active_scaffold_joins = [] + @active_scaffold_includes = [] @active_scaffold_habtm_joins = [] @params = {} end @@ -119,7 +119,7 @@ def test_constraint_conditions_for_default_associations assert_constraint_condition({:address => 11}, ['addresses.id = ?', 11], 'find the user with address #11') # reverse of a has_many :through assert_constraint_condition({:subscription => {:service => 5}}, ['services.id = ?', 5], 'find all users subscribed to service #5') - assert(@test_object.active_scaffold_joins.include?({:subscription => :service}), 'multi-level association include') + assert(@test_object.active_scaffold_includes.include?({:subscription => :service}), 'multi-level association include') @test_object.active_scaffold_config = config_for('subscription') # belongs_to (vs has_one) From 70d85fd6819258e0d19cf95b892f67cf66c51cd7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Feb 2010 10:21:33 +0100 Subject: [PATCH 0157/2024] Improve delete confirmation message --- frontends/default/views/_list_actions.html.erb | 2 +- frontends/default/views/_update_actions.html.erb | 2 +- lib/active_scaffold/actions/nested.rb | 2 +- lib/active_scaffold/config/delete.rb | 2 +- lib/active_scaffold/data_structures/action_link.rb | 6 +++--- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 4 ++-- lib/active_scaffold/locale/de.rb | 2 +- lib/active_scaffold/locale/en.rb | 2 +- lib/active_scaffold/locale/es.yml | 2 +- lib/active_scaffold/locale/fr.rb | 2 +- lib/active_scaffold/locale/hu.yml | 2 +- lib/active_scaffold/locale/ja.yml | 2 +- lib/active_scaffold/locale/ru.yml | 2 +- 14 files changed, 17 insertions(+), 17 deletions(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index d506284026..236b9c683c 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -6,7 +6,7 @@ <% active_scaffold_config.action_links.each :record do |link| -%> <% next if skip_action_link(link) -%> <td> - <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options) : "<a class='disabled #{link.action}'>#{link.label}</a>" -%> + <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options, record) : "<a class='disabled #{link.action}'>#{link.label}</a>" -%> </td> <% end -%> </tr> diff --git a/frontends/default/views/_update_actions.html.erb b/frontends/default/views/_update_actions.html.erb index e565b26668..60457f7daa 100644 --- a/frontends/default/views/_update_actions.html.erb +++ b/frontends/default/views/_update_actions.html.erb @@ -3,7 +3,7 @@ <% active_scaffold_config.action_links.each :record do |link| -%> <% next unless link.action == 'nested' -%> <% next if skip_action_link(link) -%> - <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options) : "<a class='disabled'>#{link.label}</a>" -%> + <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options, record) : "<a class='disabled'>#{link.label}</a>" -%> <% end -%> </div> </div> diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index c52591dddd..2c4611f7f4 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -38,7 +38,7 @@ def include_habtm_actions # Production mode is ok with adding a link everytime the scaffold is nested - we ar not ok with that. active_scaffold_config.action_links.add('new_existing', :label => :add_existing, :type => :table, :security_method => :add_existing_authorized?) unless active_scaffold_config.action_links['new_existing'] if active_scaffold_config.nested.shallow_delete - active_scaffold_config.action_links.add('destroy_existing', :label => :remove, :type => :record, :confirm => 'are_you_sure', :method => :delete, :position => false, :security_method => :delete_existing_authorized?) unless active_scaffold_config.action_links['destroy_existing'] + active_scaffold_config.action_links.add('destroy_existing', :label => :remove, :type => :record, :confirm => :are_you_sure_to_delete, :method => :delete, :position => false, :security_method => :delete_existing_authorized?) unless active_scaffold_config.action_links['destroy_existing'] active_scaffold_config.action_links.delete("delete") if active_scaffold_config.action_links['delete'] end else diff --git a/lib/active_scaffold/config/delete.rb b/lib/active_scaffold/config/delete.rb index a715b8319a..904c763f17 100644 --- a/lib/active_scaffold/config/delete.rb +++ b/lib/active_scaffold/config/delete.rb @@ -14,7 +14,7 @@ def initialize(core_config) # the ActionLink for this action cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('delete', :label => :delete, :type => :record, :confirm => 'are_you_sure', :crud_type => :destroy, :method => :delete, :position => false, :security_method => :delete_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('delete', :label => :delete, :type => :record, :confirm => :are_you_sure_to_delete, :crud_type => :destroy, :method => :delete, :position => false, :security_method => :delete_authorized?) # instance-level configuration # ---------------------------- diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 65929069fa..1c3a08aad8 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -42,8 +42,8 @@ def label # if the action requires confirmation attr_writer :confirm - def confirm - @confirm.is_a?(String) ? as_(@confirm) : @confirm + def confirm(label = '') + @confirm.is_a?(String) ? @confirm : as_(@confirm, :label => label) end def confirm? @confirm ? true : false @@ -137,4 +137,4 @@ def position # html options for the link attr_accessor :html_options end -end \ No newline at end of file +end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 01b9998cb6..1e922c6697 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -66,7 +66,7 @@ def render_list_column(text, column, record) end return "<a class='disabled'>#{text}</a>" unless authorized - render_action_link(link, url_options) + render_action_link(link, url_options, record) else text end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index c32b674ba4..bbfcc6926d 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -132,7 +132,7 @@ def skip_action_link(link) (link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method) end - def render_action_link(link, url_options) + def render_action_link(link, url_options, record = nil) url_options = url_options.clone url_options[:action] = link.action url_options[:controller] = link.controller if link.controller @@ -157,7 +157,7 @@ def render_action_link(link, url_options) html_options[:method] = link.method end - html_options[:confirm] = link.confirm if link.confirm? + html_options[:confirm] = link.confirm(record.try(:to_label)) if link.confirm? html_options[:position] = link.position if link.position and link.inline? html_options[:class] += ' action' if link.inline? html_options[:popup] = true if link.popup? diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 1e67a39ac3..13de7d9eaa 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -4,7 +4,7 @@ :add => 'Hinzufügen', :add_existing => 'Existierenden Eintrag hinzufügen', :add_existing_model => 'Existierende {{model}} hinzufügen', - :are_you_sure => 'Sind Sie sicher?', + :are_you_sure_to_delete => 'Sind Sie sicher?', :cancel => 'Abbrechen', :click_to_edit => 'Zum Editieren anklicken', :close => 'Schliessen', diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 643de22e95..697fd91386 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -4,7 +4,7 @@ :add => 'Add', :add_existing => 'Add Existing', :add_existing_model => 'Add Existing {{model}}', - :are_you_sure => 'Are you sure?', + :are_you_sure_to_delete => 'Are you sure you want to delete {{label}}?', :cancel => 'Cancel', :click_to_edit => 'Click to edit', :close => 'Close', diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index db8aa07d61..d30be81dd1 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -3,7 +3,7 @@ es: add: 'Añadir' add_existing: 'Añadir Existente' add_existing_model: 'Añadir {{model}} Existente' - are_you_sure: '¿Estás seguro?' + are_you_sure_to_delete: '¿Estás seguro de que quieres borrar {{label}}?' cancel: 'Cancelar' click_to_edit: 'Pulsa para editar' close: 'Cerrar' diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 8efbfb7e2c..1e3621f363 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -4,7 +4,7 @@ :add => 'Ajouter', :add_existing => 'Ajouter un existant', :add_existing_model => 'Ajouter un {{model}} existant', - :are_you_sure => 'Etes vous sûr ?', + :are_you_sure_to_delete => 'Etes vous sûr ?', :cancel => 'Annuler', :click_to_edit => 'Cliquer pour éditer', :close => 'Fermer', diff --git a/lib/active_scaffold/locale/hu.yml b/lib/active_scaffold/locale/hu.yml index 84cccc6dee..d9a47cd792 100644 --- a/lib/active_scaffold/locale/hu.yml +++ b/lib/active_scaffold/locale/hu.yml @@ -3,7 +3,7 @@ hu: add: 'Hozzáadás' add_existing: 'Meglevő hozzáadása' add_existing_model: 'Meglevő {{model}} hozzáadása' - are_you_sure: 'Biztos vagy benne?' + are_you_sure_to_delete: 'Biztos vagy benne?' cancel: 'Mégse' click_to_edit: 'Kattints a szerkesztéshez' close: 'Bezárás' diff --git a/lib/active_scaffold/locale/ja.yml b/lib/active_scaffold/locale/ja.yml index 430dc1e5ec..5684d54ebd 100644 --- a/lib/active_scaffold/locale/ja.yml +++ b/lib/active_scaffold/locale/ja.yml @@ -3,7 +3,7 @@ ja: add: '追加' add_existing: '既存のものを追加' add_existing_model: '既存の{{model}}を追加' - are_you_sure: '本当によいですか?' + are_you_sure_to_delete: '本当によいですか?' cancel: 'キャンセル' click_to_edit: 'クリックして編集' close: '閉じる' diff --git a/lib/active_scaffold/locale/ru.yml b/lib/active_scaffold/locale/ru.yml index 4df3b70cf0..77cb85e74e 100644 --- a/lib/active_scaffold/locale/ru.yml +++ b/lib/active_scaffold/locale/ru.yml @@ -3,7 +3,7 @@ ru: add: 'Добавить запись' add_existing: 'Добавить существующую запись' add_existing_model: 'Добавить существующую запись {{model}}' - are_you_sure: 'Вы уверены?' + are_you_sure_to_delete: 'Вы уверены?' cancel: 'Отмена' click_to_edit: 'Нажмите для редактирования' close: 'Закрыть' From 47c6e203a9e02ecc840fcbdecf31e0c68ef9500f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Feb 2010 11:32:23 +0100 Subject: [PATCH 0158/2024] Fix bug #533, save serialized hash --- lib/active_scaffold/attribute_params.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 5739ae42c0..668d2280e0 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -112,6 +112,8 @@ def column_value_from_param_value(parent_record, column, value) manage_nested_record_from_params(parent_record, column, value) elsif column.plural_association? value.collect {|key_value_pair| manage_nested_record_from_params(parent_record, column, key_value_pair[1])}.compact + else + value end else if column.singular_association? From 354da4b65572227ce845c81fec2a158d5678a9c7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Feb 2010 12:02:44 +0100 Subject: [PATCH 0159/2024] Fix bug #103, use the same terms as routing for ActionLink#type --- .../default/views/_list_actions.html.erb | 2 +- frontends/default/views/_list_header.html.erb | 4 ++-- frontends/default/views/_list_record.html.erb | 2 +- .../default/views/_update_actions.html.erb | 2 +- frontends/default/views/update.html.erb | 4 ++-- lib/active_scaffold/actions/nested.rb | 4 ++-- lib/active_scaffold/config/create.rb | 2 +- lib/active_scaffold/config/delete.rb | 2 +- lib/active_scaffold/config/field_search.rb | 2 +- lib/active_scaffold/config/live_search.rb | 2 +- lib/active_scaffold/config/nested.rb | 2 +- lib/active_scaffold/config/search.rb | 2 +- lib/active_scaffold/config/show.rb | 2 +- lib/active_scaffold/config/update.rb | 2 +- .../data_structures/action_link.rb | 24 ++++++++++++++----- lib/active_scaffold/data_structures/column.rb | 2 +- test/config/create_test.rb | 2 +- test/config/show_test.rb | 2 +- test/data_structures/action_link_test.rb | 14 +++++------ test/data_structures/action_links_test.rb | 10 ++++---- 20 files changed, 50 insertions(+), 38 deletions(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 236b9c683c..ea71c46677 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -3,7 +3,7 @@ <td class="indicator-container"> <%= loading_indicator_tag(:action => :record, :id => record.id) %> </td> - <% active_scaffold_config.action_links.each :record do |link| -%> + <% active_scaffold_config.action_links.each :member do |link| -%> <% next if skip_action_link(link) -%> <td> <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options, record) : "<a class='disabled #{link.action}'>#{link.label}</a>" -%> diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index 015f04fc7a..8a09fb71f7 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -1,7 +1,7 @@ -<% if active_scaffold_config.action_links.any? { |link| link.type == :table } -%> +<% if active_scaffold_config.action_links.any? { |link| link.type == :collection } -%> <div class="actions"> <% new_params = params_for(:action => :table) %> - <% active_scaffold_config.action_links.each :table do |link| -%> + <% active_scaffold_config.action_links.each :collection do |link| -%> <% next if skip_action_link(link) -%> <% next if link.action == 'new' && params[:nested].nil? && active_scaffold_config.list.always_show_create %> <% next if link.action == 'show_search' && active_scaffold_config.list.always_show_search %> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 354b9dd6cd..18c94e4f62 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -16,7 +16,7 @@ url_options = params_for(:action => :list, :id => record.id) </td> <% end -%> <td class="actions"> - <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options} if active_scaffold_config.action_links.any? {|link| link.type == :record } %> + <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options} if active_scaffold_config.action_links.any? {|link| link.type == :member } %> <% target_id = element_row_id(:action => :list, :id => record.id) -%> <script type="text/javascript"> diff --git a/frontends/default/views/_update_actions.html.erb b/frontends/default/views/_update_actions.html.erb index 60457f7daa..ee15885253 100644 --- a/frontends/default/views/_update_actions.html.erb +++ b/frontends/default/views/_update_actions.html.erb @@ -1,6 +1,6 @@ <div class="active-scaffold-header"> <div class="actions"> - <% active_scaffold_config.action_links.each :record do |link| -%> + <% active_scaffold_config.action_links.each :member do |link| -%> <% next unless link.action == 'nested' -%> <% next if skip_action_link(link) -%> <%= record.authorized_for?(:action => link.crud_type) ? render_action_link(link, url_options, record) : "<a class='disabled'>#{link.label}</a>" -%> diff --git a/frontends/default/views/update.html.erb b/frontends/default/views/update.html.erb index 0749f23bbf..d31da15f9b 100644 --- a/frontends/default/views/update.html.erb +++ b/frontends/default/views/update.html.erb @@ -1,8 +1,8 @@ <div class="active-scaffold"> <div class="update-view <%= "#{params[:controller]}-view" %> view"> - <% if active_scaffold_config.update.nested_links and active_scaffold_config.action_links.any? {|link| link.type == :record } -%> + <% if active_scaffold_config.update.nested_links and active_scaffold_config.action_links.any? {|link| link.type == :member } -%> <%= render :partial => 'update_actions', :locals => {:record => @record, :url_options => params_for(:action => :list, :id => @record.id)} %> <% end -%> <%= render :partial => 'update_form' -%> </div> -</div> \ No newline at end of file +</div> diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 2c4611f7f4..3d1dae6798 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -36,9 +36,9 @@ def nested_authorized? def include_habtm_actions if nested_habtm? # Production mode is ok with adding a link everytime the scaffold is nested - we ar not ok with that. - active_scaffold_config.action_links.add('new_existing', :label => :add_existing, :type => :table, :security_method => :add_existing_authorized?) unless active_scaffold_config.action_links['new_existing'] + active_scaffold_config.action_links.add('new_existing', :label => :add_existing, :type => :collection, :security_method => :add_existing_authorized?) unless active_scaffold_config.action_links['new_existing'] if active_scaffold_config.nested.shallow_delete - active_scaffold_config.action_links.add('destroy_existing', :label => :remove, :type => :record, :confirm => :are_you_sure_to_delete, :method => :delete, :position => false, :security_method => :delete_existing_authorized?) unless active_scaffold_config.action_links['destroy_existing'] + active_scaffold_config.action_links.add('destroy_existing', :label => :remove, :type => :member, :confirm => :are_you_sure_to_delete, :method => :delete, :position => false, :security_method => :delete_existing_authorized?) unless active_scaffold_config.action_links['destroy_existing'] active_scaffold_config.action_links.delete("delete") if active_scaffold_config.action_links['delete'] end else diff --git a/lib/active_scaffold/config/create.rb b/lib/active_scaffold/config/create.rb index 73d333c3c0..76b6671937 100644 --- a/lib/active_scaffold/config/create.rb +++ b/lib/active_scaffold/config/create.rb @@ -16,7 +16,7 @@ def self.link def self.link=(val) @@link = val end - @@link = ActiveScaffold::DataStructures::ActionLink.new('new', :label => :create_new, :type => :table, :security_method => :create_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('new', :label => :create_new, :type => :collection, :security_method => :create_authorized?) # whether the form stays open after a create or not cattr_accessor :persistent diff --git a/lib/active_scaffold/config/delete.rb b/lib/active_scaffold/config/delete.rb index 904c763f17..185f753ed6 100644 --- a/lib/active_scaffold/config/delete.rb +++ b/lib/active_scaffold/config/delete.rb @@ -14,7 +14,7 @@ def initialize(core_config) # the ActionLink for this action cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('delete', :label => :delete, :type => :record, :confirm => :are_you_sure_to_delete, :crud_type => :destroy, :method => :delete, :position => false, :security_method => :delete_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('delete', :label => :delete, :type => :member, :confirm => :are_you_sure_to_delete, :crud_type => :destroy, :method => :delete, :position => false, :security_method => :delete_authorized?) # instance-level configuration # ---------------------------- diff --git a/lib/active_scaffold/config/field_search.rb b/lib/active_scaffold/config/field_search.rb index cbb9ff8d68..0b0f66ca2b 100644 --- a/lib/active_scaffold/config/field_search.rb +++ b/lib/active_scaffold/config/field_search.rb @@ -16,7 +16,7 @@ def initialize(core_config) # -------------------------- # the ActionLink for this action cattr_reader :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :table, :security_method => :search_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) cattr_writer :full_text_search def self.full_text_search? diff --git a/lib/active_scaffold/config/live_search.rb b/lib/active_scaffold/config/live_search.rb index 60c48b5abc..96ec54d359 100644 --- a/lib/active_scaffold/config/live_search.rb +++ b/lib/active_scaffold/config/live_search.rb @@ -16,7 +16,7 @@ def initialize(core_config) # -------------------------- # the ActionLink for this action cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :table, :security_method => :search_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) cattr_writer :full_text_search def self.full_text_search? diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index 7c1c246bdc..6401337978 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -18,7 +18,7 @@ def initialize(core_config) # Add a nested ActionLink def add_link(label, models, options = {}) - options.merge! :label => label, :type => :record, :security_method => :nested_authorized?, :position => :after, :parameters => {:associations => models.join(' ')} + options.merge! :label => label, :type => :member, :security_method => :nested_authorized?, :position => :after, :parameters => {:associations => models.join(' ')} options[:html_options] ||= {} options[:html_options][:class] = [options[:html_options][:class], models.join(' ')].compact.join(' ') @core.action_links.add('nested', options) diff --git a/lib/active_scaffold/config/search.rb b/lib/active_scaffold/config/search.rb index 1761082ecb..d589750a99 100644 --- a/lib/active_scaffold/config/search.rb +++ b/lib/active_scaffold/config/search.rb @@ -16,7 +16,7 @@ def initialize(core_config) # -------------------------- # the ActionLink for this action cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :table, :security_method => :search_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) cattr_writer :full_text_search def self.full_text_search? diff --git a/lib/active_scaffold/config/show.rb b/lib/active_scaffold/config/show.rb index 1aac87d201..dd63989b1c 100644 --- a/lib/active_scaffold/config/show.rb +++ b/lib/active_scaffold/config/show.rb @@ -11,7 +11,7 @@ def initialize(core_config) # global level configuration # -------------------------- cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('show', :label => :show, :type => :record, :security_method => :show_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('show', :label => :show, :type => :member, :security_method => :show_authorized?) # instance-level configuration # ---------------------------- diff --git a/lib/active_scaffold/config/update.rb b/lib/active_scaffold/config/update.rb index 1d6ad3ecf6..f75f1a802d 100644 --- a/lib/active_scaffold/config/update.rb +++ b/lib/active_scaffold/config/update.rb @@ -15,7 +15,7 @@ def self.link def self.link=(val) @@link = val end - @@link = ActiveScaffold::DataStructures::ActionLink.new('edit', :label => :edit, :type => :record, :security_method => :update_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('edit', :label => :edit, :type => :member, :security_method => :update_authorized?) # instance-level configuration # ---------------------------- diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 1c3a08aad8..318aad91fc 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -6,7 +6,7 @@ def initialize(action, options = {}) self.action = action.to_s self.label = action self.confirm = false - self.type = :table + self.type = :collection self.inline = true self.method = :get self.crud_type = :destroy if [:destroy].include?(action.to_sym) @@ -114,12 +114,12 @@ def page=(val) def page?; @page end # where the result of this action should insert in the display. - # for :type => :table, supported values are: + # for :type => :collection, supported values are: # :top # :bottom # :replace (for updating the entire table) # false (no attempt at positioning) - # for :type => :record, supported values are: + # for :type => :member, supported values are: # :before # :replace # :after @@ -127,13 +127,25 @@ def page?; @page end attr_writer :position def position return @position unless @position.nil? or @position == true - return :replace if self.type == :record - return :top if self.type == :table + return :replace if self.type == :member + return :top if self.type == :collection raise "what should the default position be for #{self.type}?" end - # what type of link this is. currently supported values are :table and :record. + # what type of link this is. currently supported values are :collection and :member. attr_accessor :type + # deprecated + def type=(value) + old_value = value + value = case value + when :table then :collection + when :record then :member + else value + end + ::ActiveSupport::Deprecation.warn(":#{old_value} is deprecated, use :#{value} instead", caller) if old_value != value + @type = value + end + # html options for the link attr_accessor :html_options end diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index dbc41642aa..dd7e1c64a8 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -129,7 +129,7 @@ def set_link(action, options = {}) else options[:label] ||= self.label options[:position] ||= :after unless options.has_key?(:position) - options[:type] ||= :record + options[:type] ||= :member @link = ActiveScaffold::DataStructures::ActionLink.new(action, options) end end diff --git a/test/config/create_test.rb b/test/config/create_test.rb index bc177a2ad0..e447e0834e 100644 --- a/test/config/create_test.rb +++ b/test/config/create_test.rb @@ -27,7 +27,7 @@ def test_link_defaults blank = {} assert_equal blank, link.html_options assert_equal :get, link.method - assert_equal :table, link.type + assert_equal :collection, link.type assert_equal :create, link.crud_type assert_equal :create_authorized?, link.security_method end diff --git a/test/config/show_test.rb b/test/config/show_test.rb index b00da6e4ee..ee120b2800 100644 --- a/test/config/show_test.rb +++ b/test/config/show_test.rb @@ -25,7 +25,7 @@ def test_link_defaults blank = {} assert_equal blank, link.html_options assert_equal :get, link.method - assert_equal :record, link.type + assert_equal :member, link.type assert_equal :read, link.crud_type assert_equal :show_authorized?, link.security_method end diff --git a/test/data_structures/action_link_test.rb b/test/data_structures/action_link_test.rb index 2a5f5945aa..0107ab874c 100644 --- a/test/data_structures/action_link_test.rb +++ b/test/data_structures/action_link_test.rb @@ -31,10 +31,10 @@ def test_simple_attributes assert_equal true, @link.security_method_set? assert_equal 'blueberry_pie', @link.security_method - @link.type = :table - assert_equal :table, @link.type - @link.type = :record - assert_equal :record, @link.type + @link.type = :collection + assert_equal :collection, @link.type + @link.type = :member + assert_equal :member, @link.type assert_equal :get, @link.method @link.method = :put @@ -44,10 +44,10 @@ def test_simple_attributes def test_position @link.position = true - @link.type = :table + @link.type = :collection assert_equal :top, @link.position - @link.type = :record + @link.type = :member assert_equal :replace, @link.position @link.position = :before @@ -78,4 +78,4 @@ def test_presentation_style assert !@link.popup? assert !@link.page? end -end \ No newline at end of file +end diff --git a/test/data_structures/action_links_test.rb b/test/data_structures/action_links_test.rb index 593b2543e5..380925534b 100644 --- a/test/data_structures/action_links_test.rb +++ b/test/data_structures/action_links_test.rb @@ -50,13 +50,13 @@ def test_cloning end def test_each - @links.add 'foo', :type => :table - @links.add 'bar', :type => :record + @links.add 'foo', :type => :collection + @links.add 'bar', :type => :member - @links.each :table do |link| + @links.each :collection do |link| assert_equal 'foo', link.action end - @links.each :record do |link| + @links.each :member do |link| assert_equal 'bar', link.action end end @@ -75,4 +75,4 @@ def test_delete end assert !@links['bar'].nil? end -end \ No newline at end of file +end From 5981299447f21af8a049888d34d155c69926a593 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Feb 2010 12:56:27 +0100 Subject: [PATCH 0160/2024] Fix issue #218 and add deprecation warning while keeping backwards compatibility --- lib/active_record_permissions.rb | 22 +++++++++++++++++-- lib/active_scaffold/actions/delete.rb | 4 ++-- lib/active_scaffold/config/base.rb | 4 ++-- lib/active_scaffold/config/delete.rb | 4 ++-- .../data_structures/action_link.rb | 4 ++-- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/lib/active_record_permissions.rb b/lib/active_record_permissions.rb index fa8e6e767b..47d99c1019 100644 --- a/lib/active_record_permissions.rb +++ b/lib/active_record_permissions.rb @@ -69,16 +69,25 @@ def self.included(base) # the actual permission methods can't be guaranteed to exist. And because we want to # intelligently combine multiple applicable methods. # - # options[:action] should be a CRUD verb (:create, :read, :update, :destroy) + # options[:action] should be a CRUD verb (:create, :read, :update, :delete) # options[:column] should be the name of a model attribute def authorized_for?(options = {}) - raise ArgumentError, "unknown action #{options[:action]}" if options[:action] and ![:create, :read, :update, :destroy].include?(options[:action]) + raise ArgumentError, "unknown action #{options[:action]}" if options[:action] and ![:create, :read, :update, :delete].include?(options[:action]) # column_authorized_for_action? has priority over other methods, # you can disable an action and enable that action for a column # (for example, disable update and enable inplace_edit in a column) method = column_and_action_security_method(options[:column], options[:action]) return send(method) if method and respond_to?(method) + # code for deprecation + if options[:action] == :delete + good_method = method + method = column_and_action_security_method(options[:column], :destroy) + if method and respond_to?(method) + ::ActiveSupport::Deprecation.warn("destroy crud type is deprecated, rename #{method} to #{good_method}", caller) + return send(method) + end + end # collect the possibly-related methods that actually exist methods = [ @@ -86,6 +95,15 @@ def authorized_for?(options = {}) action_security_method(options[:action]), ].compact.select {|m| respond_to?(m)} + # code for deprecation + if options[:action] == :delete + method = action_security_method(:destroy) + if respond_to?(method) + ::ActiveSupport::Deprecation.warn("destroy crud type is deprecated, rename #{method} to #{action_security_method(options[:action])}", caller) + methods << method + end + end + # if any method returns false, then return false return false if methods.any? {|m| !send(m)} diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index a2ccbbdb43..b3a67f7dcd 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -40,7 +40,7 @@ def destroy_respond_to_yaml end def destroy_find_record - @record = find_if_allowed(params[:id], :destroy) + @record = find_if_allowed(params[:id], :delete) end # A simple method to handle the actual destroying of a record @@ -58,7 +58,7 @@ def do_destroy # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def delete_authorized? - authorized_for?(:action => :destroy) + authorized_for?(:action => :delete) end private def delete_authorized_filter diff --git a/lib/active_scaffold/config/base.rb b/lib/active_scaffold/config/base.rb index a31fb8d005..414573571f 100644 --- a/lib/active_scaffold/config/base.rb +++ b/lib/active_scaffold/config/base.rb @@ -5,14 +5,14 @@ class Base def self.inherited(subclass) class << subclass - # the crud type of the action. possible values are :create, :read, :update, :destroy, and nil. + # the crud type of the action. possible values are :create, :read, :update, :delete, and nil. # this is not a setting for the developer. it's self-description for the actions. def crud_type; @crud_type; end protected def crud_type=(val) - raise ArgumentError, "unknown CRUD type #{val}" unless [:create, :read, :update, :destroy].include?(val.to_sym) + raise ArgumentError, "unknown CRUD type #{val}" unless [:create, :read, :update, :delete].include?(val.to_sym) @crud_type = val.to_sym end end diff --git a/lib/active_scaffold/config/delete.rb b/lib/active_scaffold/config/delete.rb index 185f753ed6..dd23ded460 100644 --- a/lib/active_scaffold/config/delete.rb +++ b/lib/active_scaffold/config/delete.rb @@ -1,6 +1,6 @@ module ActiveScaffold::Config class Delete < Base - self.crud_type = :destroy + self.crud_type = :delete def initialize(core_config) @core = core_config @@ -14,7 +14,7 @@ def initialize(core_config) # the ActionLink for this action cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('delete', :label => :delete, :type => :member, :confirm => :are_you_sure_to_delete, :crud_type => :destroy, :method => :delete, :position => false, :security_method => :delete_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('delete', :label => :delete, :type => :member, :confirm => :are_you_sure_to_delete, :crud_type => :delete, :method => :delete, :position => false, :security_method => :delete_authorized?) # instance-level configuration # ---------------------------- diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 318aad91fc..96b49a2ec0 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -9,7 +9,7 @@ def initialize(action, options = {}) self.type = :collection self.inline = true self.method = :get - self.crud_type = :destroy if [:destroy].include?(action.to_sym) + self.crud_type = :delete if [:destroy].include?(action.to_sym) self.crud_type = :create if [:create, :new].include?(action.to_sym) self.crud_type = :update if [:edit, :update].include?(action.to_sym) self.crud_type ||= :read @@ -71,7 +71,7 @@ def security_method_set? # the crud type of the (eventual?) action. different than :method, because this crud action may not be imminent. # this is used to determine record-level authorization (e.g. record.authorized_for?(:action => link.crud_type). - # options are :create, :read, :update, and :destroy + # options are :create, :read, :update, and :delete attr_accessor :crud_type # an "inline" link is inserted into the existing page From 70e74e42b8266eb670d19435a9556428ca8f90e9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Feb 2010 13:29:58 +0100 Subject: [PATCH 0161/2024] Fix issue #501, call before/after_update_save for inplace editing --- lib/active_scaffold/actions/update.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 7c092d41f1..a1d5023d5c 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -98,7 +98,9 @@ def do_update_column params[:value] ||= @record.column_for_attribute(params[:column]).default unless @record.column_for_attribute(params[:column]).nil? || @record.column_for_attribute(params[:column]).null params[:value] = column_value_from_param_value(@record, column, params[:value]) unless column.nil? @record.send("#{params[:column]}=", params[:value]) + before_update_save(@record) @record.save + after_update_save(@record) end end From 62bf83e8d911ee4bac719b742cae1005c29aeff4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Feb 2010 13:50:50 +0100 Subject: [PATCH 0162/2024] Fix issue #550, namespace support --- lib/active_scaffold.rb | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index f4e18c0af4..2c0b953367 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -186,23 +186,25 @@ def active_scaffold_config_for(klass) # Searches in the namespace of the current controller for singular and plural versions of the conventional "#{model}Controller" syntax. # You may override this method to customize the search routine. def active_scaffold_controller_for(klass) - namespace = self.to_s.split('::')[0...-1].join('::') + '::' + controller_namespace = self.to_s.split('::')[0...-1].join('::') + '::' error_message = [] - ["#{klass.to_s.underscore.pluralize}", "#{klass.to_s.underscore.pluralize.singularize}"].each do |controller_name| - begin - controller = "#{namespace}#{controller_name.camelize}Controller".constantize - rescue NameError => error - # Only rescue NameError associated with the controller constant not existing - not other compile errors - if error.message["uninitialized constant #{controller}"] - error_message << "#{namespace}#{controller_name.camelize}Controller" - next - else - raise + [controller_namespace, ''].each do |namespace| + ["#{klass.to_s.underscore.pluralize}", "#{klass.to_s.underscore.pluralize.singularize}"].each do |controller_name| + begin + controller = "#{namespace}#{controller_name.camelize}Controller".constantize + rescue NameError => error + # Only rescue NameError associated with the controller constant not existing - not other compile errors + if error.message["uninitialized constant #{controller}"] + error_message << "#{namespace}#{controller_name.camelize}Controller" + next + else + raise + end end + raise ActiveScaffold::ControllerNotFound, "#{controller} missing ActiveScaffold", caller unless controller.uses_active_scaffold? + raise ActiveScaffold::ControllerNotFound, "ActiveScaffold on #{controller} is not for #{klass} model.", caller unless controller.active_scaffold_config.model == klass + return controller end - raise ActiveScaffold::ControllerNotFound, "#{controller} missing ActiveScaffold", caller unless controller.uses_active_scaffold? - raise ActiveScaffold::ControllerNotFound, "ActiveScaffold on #{controller} is not for #{klass} model.", caller unless controller.active_scaffold_config.model == klass - return controller end raise ActiveScaffold::ControllerNotFound, "Could not find " + error_message.join(" or "), caller end From 7625d32ba743c57ef76001497735018103a7aad4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Feb 2010 14:38:59 +0100 Subject: [PATCH 0163/2024] Fix issue #594, allow to set page links window size --- .../views/_list_pagination_links.html.erb | 4 +-- lib/active_scaffold/config/list.rb | 8 +++++ .../helpers/pagination_helpers.rb | 14 ++++---- test/misc/pagination_helpers_test.rb | 35 +++++++++++++++++++ 4 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 test/misc/pagination_helpers_test.rb diff --git a/frontends/default/views/_list_pagination_links.html.erb b/frontends/default/views/_list_pagination_links.html.erb index a41f3acfdc..54679791a1 100644 --- a/frontends/default/views/_list_pagination_links.html.erb +++ b/frontends/default/views/_list_pagination_links.html.erb @@ -16,7 +16,7 @@ :method => :get }, { :href => previous_url, :class => "previous"}) if current_page.prev? %> - <%= pagination_ajax_links current_page, pagination_params %> + <%= pagination_ajax_links current_page, pagination_params, active_scaffold_config.list.page_links_window %> <%= link_to_remote(as_(:next), { :url => pagination_params.merge(:page => current_page.number + 1), :after => "$('#{loading_indicator_id(:action => :pagination)}').style.visibility = 'visible';", @@ -27,4 +27,4 @@ :method => :get }, { :href => next_url, :class => "next"}) if current_page.next? %> -<% end -%> \ No newline at end of file +<% end -%> diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index ef39248c0f..0d5666b05b 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -8,6 +8,7 @@ def initialize(core_config) # inherit from global scope # full configuration path is: defaults => global table => local table @per_page = self.class.per_page + @page_links_window = self.class.page_links_window # originates here @sorting = ActiveScaffold::DataStructures::Sorting.new(@core.columns) @@ -23,6 +24,10 @@ def initialize(core_config) cattr_accessor :per_page @@per_page = 15 + # how many page links around current page to show + cattr_accessor :page_links_window + @@page_links_window = 2 + # what string to use when a field is empty cattr_accessor :empty_field_text @@empty_field_text = '-' @@ -41,6 +46,9 @@ def columns # how many rows to show at once attr_accessor :per_page + # how many page links around current page to show + attr_accessor :page_links_window + # what string to use when a field is empty attr_accessor :empty_field_text diff --git a/lib/active_scaffold/helpers/pagination_helpers.rb b/lib/active_scaffold/helpers/pagination_helpers.rb index 61920309eb..a9141536f1 100644 --- a/lib/active_scaffold/helpers/pagination_helpers.rb +++ b/lib/active_scaffold/helpers/pagination_helpers.rb @@ -14,15 +14,15 @@ def pagination_ajax_link(page_number, params) { :href => url_for(params.merge(:page => page_number)) }) end - def pagination_ajax_links(current_page, params) - start_number = current_page.number - 2 - end_number = current_page.number + 2 + def pagination_ajax_links(current_page, params, window_size) + start_number = current_page.number - window_size + end_number = current_page.number + window_size start_number = 1 if start_number <= 0 end_number = current_page.pager.last.number if end_number > current_page.pager.last.number html = [] - html << pagination_ajax_link(1, params) unless current_page.number <= 3 - html << ".." unless current_page.number <= 4 + html << pagination_ajax_link(1, params) unless start_number == 1 + html << ".." unless start_number <= 2 start_number.upto(end_number) do |num| if current_page.number == num html << num @@ -30,8 +30,8 @@ def pagination_ajax_links(current_page, params) html << pagination_ajax_link(num, params) end end - html << ".." unless current_page.number >= current_page.pager.last.number - 3 - html << pagination_ajax_link(current_page.pager.last.number, params) unless current_page.number >= current_page.pager.last.number - 2 + html << ".." unless end_number < current_page.pager.last.number - 1 + html << pagination_ajax_link(current_page.pager.last.number, params) unless end_number < current_page.pager.last.number - window_size html.join(' ') end end diff --git a/test/misc/pagination_helpers_test.rb b/test/misc/pagination_helpers_test.rb new file mode 100644 index 0000000000..bc5312fd8f --- /dev/null +++ b/test/misc/pagination_helpers_test.rb @@ -0,0 +1,35 @@ +require File.join(File.dirname(__FILE__), '../test_helper.rb') + +class PaginationHelpersTest < Test::Unit::TestCase + include ActiveScaffold::Helpers::PaginationHelpers + + def test_links + self.stubs(:pagination_ajax_link).returns('l') + + assert '1', links(1, 1) + assert '1 l', links(1, 2) + assert '1 l l', links(1, 3) + assert '1 l l l', links(1, 4) + assert '1 l l .. l', links(1, 5) + assert '1 l l .. l', links(1, 6) + + assert 'l 1 l l .. l', links(2, 10) + assert 'l l 1 l l .. l', links(3, 10) + assert 'l l l 1 l l .. l', links(4, 10) + assert 'l .. l l 1 l l .. l', links(5, 10) + assert 'l .. l l 1 l l .. l', links(6, 10) + + assert '1 l l l l', links(1, 5, 3) + assert '1 l l l .. l', links(1, 6, 3) + assert 'l l l l 1 l l .. l', links(5, 10, 3) + assert 'l .. l l l 1 l l .. l', links(6, 10, 3) + assert 'l .. l l l 1 l l l .. l', links(6, 20, 3) + end + + private + def links(current, last_page, window_size = 2) + paginator = stub(:last => last_page = stub(:number => last_page)) + current_page = stub(:number => current, :pager => paginator) + pagination_ajax_links(current_page, {}, window_size) + end +end From b0cedeb58e07736a91de98b9d92c739e13dcfb4d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Feb 2010 14:45:15 +0100 Subject: [PATCH 0164/2024] Fix latest commit, test were wrong --- .../helpers/pagination_helpers.rb | 4 +-- test/misc/pagination_helpers_test.rb | 32 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/active_scaffold/helpers/pagination_helpers.rb b/lib/active_scaffold/helpers/pagination_helpers.rb index a9141536f1..9571fe5547 100644 --- a/lib/active_scaffold/helpers/pagination_helpers.rb +++ b/lib/active_scaffold/helpers/pagination_helpers.rb @@ -30,8 +30,8 @@ def pagination_ajax_links(current_page, params, window_size) html << pagination_ajax_link(num, params) end end - html << ".." unless end_number < current_page.pager.last.number - 1 - html << pagination_ajax_link(current_page.pager.last.number, params) unless end_number < current_page.pager.last.number - window_size + html << ".." unless end_number >= current_page.pager.last.number - 1 + html << pagination_ajax_link(current_page.pager.last.number, params) unless end_number == current_page.pager.last.number html.join(' ') end end diff --git a/test/misc/pagination_helpers_test.rb b/test/misc/pagination_helpers_test.rb index bc5312fd8f..68cccfb6fa 100644 --- a/test/misc/pagination_helpers_test.rb +++ b/test/misc/pagination_helpers_test.rb @@ -6,24 +6,24 @@ class PaginationHelpersTest < Test::Unit::TestCase def test_links self.stubs(:pagination_ajax_link).returns('l') - assert '1', links(1, 1) - assert '1 l', links(1, 2) - assert '1 l l', links(1, 3) - assert '1 l l l', links(1, 4) - assert '1 l l .. l', links(1, 5) - assert '1 l l .. l', links(1, 6) + assert_equal '1', links(1, 1) + assert_equal '1 l', links(1, 2) + assert_equal '1 l l', links(1, 3) + assert_equal '1 l l l', links(1, 4) + assert_equal '1 l l .. l', links(1, 5) + assert_equal '1 l l .. l', links(1, 6) - assert 'l 1 l l .. l', links(2, 10) - assert 'l l 1 l l .. l', links(3, 10) - assert 'l l l 1 l l .. l', links(4, 10) - assert 'l .. l l 1 l l .. l', links(5, 10) - assert 'l .. l l 1 l l .. l', links(6, 10) + assert_equal 'l 2 l l .. l', links(2, 10) + assert_equal 'l l 3 l l .. l', links(3, 10) + assert_equal 'l l l 4 l l .. l', links(4, 10) + assert_equal 'l .. l l 5 l l .. l', links(5, 10) + assert_equal 'l .. l l 6 l l .. l', links(6, 10) - assert '1 l l l l', links(1, 5, 3) - assert '1 l l l .. l', links(1, 6, 3) - assert 'l l l l 1 l l .. l', links(5, 10, 3) - assert 'l .. l l l 1 l l .. l', links(6, 10, 3) - assert 'l .. l l l 1 l l l .. l', links(6, 20, 3) + assert_equal '1 l l l l', links(1, 5, 3) + assert_equal '1 l l l .. l', links(1, 6, 3) + assert_equal 'l l l l 5 l l l .. l', links(5, 10, 3) + assert_equal 'l .. l l l 6 l l l l', links(6, 10, 3) + assert_equal 'l .. l l l 6 l l l .. l', links(6, 20, 3) end private From 1f03184b0e954f0229176b6728bd416fc9baf3b4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Feb 2010 14:46:48 +0100 Subject: [PATCH 0165/2024] colorize tests if redgreen gem is available --- test/test_helper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 1f1430ca84..dab52c3486 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,10 @@ require 'test/unit' require 'rubygems' require 'mocha' +begin + require 'redgreen' +rescue LoadError +end ENV['RAILS_ENV'] = 'test' ENV['RAILS_ROOT'] ||= File.join(File.dirname(__FILE__), 'mock_app') From 97c1eda742e69cc8cd0f2d7d3665e9f08b7b4d62 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Feb 2010 16:43:27 +0100 Subject: [PATCH 0166/2024] fix return_to_main --- lib/active_scaffold/helpers/controller_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index a6d47b1b74..75d9a0f414 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -23,7 +23,7 @@ def params_for(options = {}) # Parameters to generate url to the main page (override if the ActiveScaffold is used as a component on another controllers page) def main_path_to_return - parameters = params.clone + parameters = {} if params[:parent_controller] parameters[:controller] = params[:parent_controller] parameters[:eid] = params[:parent_controller] From 7c97bb87e73e2128bb9f7b1a5a53879291067295 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Feb 2010 17:51:28 +0100 Subject: [PATCH 0167/2024] missing destroy crud type, changing to delete --- frontends/default/views/_horizontal_subform_record.html.erb | 2 +- frontends/default/views/_vertical_subform_record.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index ea4eff341b..274df228ca 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -20,7 +20,7 @@ <% end -%> <% if show_actions -%> <td class="actions"> - <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:action => :destroy) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> + <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:action => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> <% unless @record.new_record? %> <input type="hidden" name="<%= "record#{scope}[id]" -%>" value="<%= @record.id -%>" /> <% end -%> diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index 1aabfa4545..7adeb093a4 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -22,7 +22,7 @@ <% end -%> <% if show_actions -%> <li class="actions"> - <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:action => :destroy) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> + <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:action => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> <% unless @record.new_record? %> <input type="hidden" name="<%= "record#{scope}[id]" -%>" value="<%= @record.id -%>" /> <% end -%> From 86fe6c5c55b978c22cba8c2906660f7160891956 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Feb 2010 18:02:20 +0100 Subject: [PATCH 0168/2024] fix for reverse associations --- lib/extensions/reverse_associations.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/extensions/reverse_associations.rb b/lib/extensions/reverse_associations.rb index 3b3c88aa33..f7a687f473 100644 --- a/lib/extensions/reverse_associations.rb +++ b/lib/extensions/reverse_associations.rb @@ -8,9 +8,9 @@ def reverse_for?(klass) attr_writer :reverse def reverse if @reverse.nil? and not self.options[:polymorphic] - reverse_matches = reverse_matches_for(self.class_name.constantize) + reverse_matches = reverse_matches_for(self.class_name.constantize) rescue nil # grab first association, or make a wild guess - @reverse = reverse_matches.empty? ? false : reverse_matches.first.name + @reverse = reverse_matches.blank? ? false : reverse_matches.first.name end @reverse end From 80c652f620a0fb3ca95edf986c7ad08f4d070687 Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Mon, 15 Feb 2010 10:15:57 +0100 Subject: [PATCH 0169/2024] fixed js error for select box inplace_editing in ie browers --- frontends/default/javascripts/active_scaffold.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index ec9e7b3eb2..b0f5ea5a24 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -435,6 +435,8 @@ ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.Act ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { setFieldFromAjax: function(url, options) { + if (typeof(this._controls.editor.remove) === 'undefined') + Element.extend(this._controls.editor); this._controls.editor.remove(); new Ajax.Request(url, { method: 'get', @@ -464,6 +466,8 @@ ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { this.setValue(fld, this._controls.editor.value); if (this.options.submitOnBlur) fld.onblur = this._boundSubmitHandler; + if (typeof(this._controls.editor.remove) === 'undefined') + Element.extend(this._controls.editor); this._controls.editor.remove(); this._controls.editor = fld; this._form.appendChild(this._controls.editor); From c936cf044222153cee0cc0d4c20368fc49bbc0b0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 15 Feb 2010 10:45:11 +0100 Subject: [PATCH 0170/2024] Cleanup last commit --- frontends/default/javascripts/active_scaffold.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index b0f5ea5a24..c605fa0cd8 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -435,9 +435,7 @@ ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.Act ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { setFieldFromAjax: function(url, options) { - if (typeof(this._controls.editor.remove) === 'undefined') - Element.extend(this._controls.editor); - this._controls.editor.remove(); + $(this._controls.editor).remove(); new Ajax.Request(url, { method: 'get', onComplete: function(response) { @@ -466,9 +464,7 @@ ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { this.setValue(fld, this._controls.editor.value); if (this.options.submitOnBlur) fld.onblur = this._boundSubmitHandler; - if (typeof(this._controls.editor.remove) === 'undefined') - Element.extend(this._controls.editor); - this._controls.editor.remove(); + $(this._controls.editor).remove(); this._controls.editor = fld; this._form.appendChild(this._controls.editor); From a887d5ea3b38d714707eed57152519b6b06b393b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 16 Feb 2010 09:49:02 +0100 Subject: [PATCH 0171/2024] Capture ActiveRecord::RecordNotSaved, fixes #400 --- lib/active_scaffold/actions/update.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index a1d5023d5c..9a0b97eeb1 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -88,6 +88,9 @@ def do_update rescue ActiveRecord::StaleObjectError @record.errors.add_to_base as_(:version_inconsistency) self.successful=false + rescue ActiveRecord::RecordNotSaved + @record.errors.add_to_base as_("Failed to save record cause of an unknown error") if @record.errors.empty? + self.successful = false end end From de62ae6363506af6f704af5e4a8dd8798182c2cb Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 16 Feb 2010 11:01:01 +0100 Subject: [PATCH 0172/2024] Fix response_status in json, xml and yaml formats and respect config columns, fixes #646 --- lib/active_scaffold/actions/core.rb | 6 +++++- lib/active_scaffold/actions/create.rb | 10 +++------- lib/active_scaffold/actions/delete.rb | 6 +++--- lib/active_scaffold/actions/list.rb | 6 +++--- lib/active_scaffold/actions/nested.rb | 12 ++++++------ lib/active_scaffold/actions/show.rb | 7 ++++--- lib/active_scaffold/actions/update.rb | 6 +++--- .../data_structures/action_columns.rb | 4 ++++ 8 files changed, 31 insertions(+), 26 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 2f5427b6a4..df9a90ed7d 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -61,7 +61,11 @@ def accepts?(*types) end def response_status - successful? ? 200 : 422 + if successful? + action_name == 'create' ? 201 : 200 + else + 422 + end end # API response object that will be converted to XML/YAML/JSON using to_xxx diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 75caf2c7f4..ca2a6b28bf 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -20,10 +20,6 @@ def create end protected - def response_status - successful? ? 201 : super - end - def response_location url_for(params_for(:action => "show", :id => @record.id)) if successful? end @@ -75,15 +71,15 @@ def create_respond_to_js end def create_respond_to_xml - render :xml => response_object.to_xml, :content_type => Mime::XML, :status => response_status, :location => response_location + render :xml => response_object.to_xml(:only => active_scaffold_config.create.columns.names), :content_type => Mime::XML, :status => response_status, :location => response_location end def create_respond_to_json - render :text => response_object.to_json, :content_type => Mime::JSON, :status => response_status, :location => response_location + render :text => response_object.to_json(:only => active_scaffold_config.create.columns.names), :content_type => Mime::JSON, :status => response_status, :location => response_location end def create_respond_to_yaml - render :text => response_object.to_yaml, :content_type => Mime::YAML, :status => response_status, :location => response_location + render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.create.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status, :location => response_location end def constraints_for_nested_create diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index b3a67f7dcd..9c654f799b 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -28,15 +28,15 @@ def destroy_respond_to_js end def destroy_respond_to_xml - render :xml => successful? ? "" : response_object.to_xml, :content_type => Mime::XML, :status => response_status + render :xml => successful? ? "" : response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status end def destroy_respond_to_json - render :text => successful? ? "" : response_object.to_json, :content_type => Mime::JSON, :status => response_status + render :text => successful? ? "" : response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status end def destroy_respond_to_yaml - render :text => successful? ? "" : response_object.to_yaml, :content_type => Mime::YAML, :status => response_status + render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end def destroy_find_record diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 907d36d9f2..f456668225 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -39,13 +39,13 @@ def list_respond_to_js render :action => 'list', :layout => false end def list_respond_to_xml - render :xml => response_object.to_xml, :content_type => Mime::XML, :status => response_status + render :xml => response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status end def list_respond_to_json - render :text => response_object.to_json, :content_type => Mime::JSON, :status => response_status + render :text => response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status end def list_respond_to_yaml - render :text => response_object.to_yaml, :content_type => Mime::YAML, :status => response_status + render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end def update_table_respond_to_html return_to_main diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 3d1dae6798..f4d416c806 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -136,13 +136,13 @@ def add_existing_respond_to_js end end def add_existing_respond_to_xml - render :xml => response_object.to_xml, :content_type => Mime::XML, :status => response_status + render :xml => response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status end def add_existing_respond_to_json - render :text => response_object.to_json, :content_type => Mime::JSON, :status => response_status + render :text => response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status end def add_existing_respond_to_yaml - render :text => response_object.to_yaml, :content_type => Mime::YAML, :status => response_status + render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end def destroy_existing_respond_to_html flash[:info] = as_(:deleted_model, :model => @record.to_label) @@ -154,15 +154,15 @@ def destroy_existing_respond_to_js end def destroy_existing_respond_to_xml - render :xml => successful? ? "" : response_object.to_xml, :content_type => Mime::XML, :status => response_status + render :xml => successful? ? "" : response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status end def destroy_existing_respond_to_json - render :text => successful? ? "" : response_object.to_json, :content_type => Mime::JSON, :status => response_status + render :text => successful? ? "" : response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status end def destroy_existing_respond_to_yaml - render :text => successful? ? "" : response_object.to_yaml, :content_type => Mime::YAML, :status => response_status + render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end def add_existing_authorized? diff --git a/lib/active_scaffold/actions/show.rb b/lib/active_scaffold/actions/show.rb index 37a41495cb..8facd3f250 100644 --- a/lib/active_scaffold/actions/show.rb +++ b/lib/active_scaffold/actions/show.rb @@ -13,15 +13,16 @@ def show protected def show_respond_to_json - render :text => response_object.to_json, :content_type => Mime::JSON, :status => response_status + render :text => response_object.to_json(:only => active_scaffold_config.show.columns.names), :content_type => Mime::JSON, :status => response_status end def show_respond_to_yaml - render :text => response_object.to_yaml, :content_type => Mime::YAML, :status => response_status + debugger + render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.show.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end def show_respond_to_xml - render :xml => response_object.to_xml, :content_type => Mime::XML, :status => response_status + render :xml => response_object.to_xml(:only => active_scaffold_config.show.columns.names), :content_type => Mime::XML, :status => response_status end def show_respond_to_js diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 9a0b97eeb1..a70337975a 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -56,13 +56,13 @@ def update_respond_to_js render :action => 'on_update' end def update_respond_to_xml - render :xml => response_object.to_xml, :content_type => Mime::XML, :status => response_status + render :xml => response_object.to_xml(:only => active_scaffold_config.update.columns.names), :content_type => Mime::XML, :status => response_status end def update_respond_to_json - render :text => response_object.to_json, :content_type => Mime::JSON, :status => response_status + render :text => response_object.to_json(:only => active_scaffold_config.update.columns.names), :content_type => Mime::JSON, :status => response_status end def update_respond_to_yaml - render :text => response_object.to_yaml, :content_type => Mime::YAML, :status => response_status + render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.update.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end # A simple method to find and prepare a record for editing # May be overridden to customize the record (set default values, etc.) diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index 6487c67234..fb47e5446f 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -34,6 +34,10 @@ def include?(item) return false end + def names + self.collect(&:name) + end + protected def collect_columns From e4c4e0693299a59b25402268b5ce4b8dd354ec76 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 16 Feb 2010 13:19:31 +0100 Subject: [PATCH 0173/2024] Remove debug --- lib/active_scaffold/actions/show.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/active_scaffold/actions/show.rb b/lib/active_scaffold/actions/show.rb index 8facd3f250..5720ce7da7 100644 --- a/lib/active_scaffold/actions/show.rb +++ b/lib/active_scaffold/actions/show.rb @@ -17,7 +17,6 @@ def show_respond_to_json end def show_respond_to_yaml - debugger render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.show.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end From a67548b20b74052b0b9ad00d84d9074f6ed0cc1f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 16 Feb 2010 14:24:34 +0100 Subject: [PATCH 0174/2024] Allow to change like search, fixes #369 applying it to search and live_search too --- lib/active_scaffold/actions/field_search.rb | 4 ++-- lib/active_scaffold/actions/live_search.rb | 4 ++-- lib/active_scaffold/actions/search.rb | 4 ++-- lib/active_scaffold/config/field_search.rb | 22 ++++++++++++++----- lib/active_scaffold/config/live_search.rb | 22 ++++++++++++++----- lib/active_scaffold/config/search.rb | 22 ++++++++++++++----- lib/active_scaffold/finder.rb | 15 +++++++++++-- .../default/active_scaffold.js | 4 ++-- 8 files changed, 69 insertions(+), 28 deletions(-) diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index dc65b0eb1f..a9e215bbcd 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -24,11 +24,11 @@ def field_search_respond_to_js def do_search unless params[:search].nil? - like_pattern = active_scaffold_config.field_search.full_text_search? ? '%?%' : '?%' + text_search = active_scaffold_config.field_search.text_search search_conditions = [] columns = active_scaffold_config.field_search.columns columns.each do |column| - search_conditions << self.class.condition_for_column(column, params[:search][column.name], like_pattern) + search_conditions << self.class.condition_for_column(column, params[:search][column.name], text_search) end search_conditions.compact! self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, *search_conditions) diff --git a/lib/active_scaffold/actions/live_search.rb b/lib/active_scaffold/actions/live_search.rb index 608b3f566d..c005e3f954 100644 --- a/lib/active_scaffold/actions/live_search.rb +++ b/lib/active_scaffold/actions/live_search.rb @@ -28,8 +28,8 @@ def do_search unless @query.empty? columns = active_scaffold_config.live_search.columns - like_pattern = active_scaffold_config.live_search.full_text_search? ? '%?%' : '?%' - search_conditions = self.class.create_conditions_for_columns(@query.split(' '), columns, like_pattern) + text_search = active_scaffold_config.live_search.text_search + search_conditions = self.class.create_conditions_for_columns(@query.split(' '), columns, text_search) self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, search_conditions) @filtered = !search_conditions.blank? diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index 5c58b442ad..5ef404f40b 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -21,8 +21,8 @@ def do_search unless @query.empty? columns = active_scaffold_config.search.columns - like_pattern = active_scaffold_config.search.full_text_search? ? '%?%' : '?%' - search_conditions = self.class.create_conditions_for_columns(@query.split(' '), columns, like_pattern) + text_search = active_scaffold_config.search.text_search + search_conditions = self.class.create_conditions_for_columns(@query.split(' '), columns, text_search) self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, search_conditions) @filtered = !search_conditions.blank? diff --git a/lib/active_scaffold/config/field_search.rb b/lib/active_scaffold/config/field_search.rb index 0b0f66ca2b..a0cfda9869 100644 --- a/lib/active_scaffold/config/field_search.rb +++ b/lib/active_scaffold/config/field_search.rb @@ -5,7 +5,7 @@ class FieldSearch < Base def initialize(core_config) @core = core_config - @full_text_search = self.class.full_text_search? + @text_search = self.class.text_search # start with the ActionLink defined globally @link = self.class.link.clone @@ -18,11 +18,16 @@ def initialize(core_config) cattr_reader :link @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) - cattr_writer :full_text_search + def self.full_text_search=(value) + ::ActiveSupport::Deprecation.warn("full_text_search is deprecated, use text_search = :full instead", caller) + @@text_search = :full + end def self.full_text_search? - @@full_text_search + ::ActiveSupport::Deprecation.warn("full_text_search? is deprecated, use text_search == :full instead", caller) + @@text_search == :full end - @@full_text_search = true + cattr_accessor :text_search + @@text_search = :full # instance-level configuration # ---------------------------- @@ -39,9 +44,14 @@ def columns public :columns= - attr_writer :full_text_search + attr_accessor :text_search + def full_text_search=(value) + ::ActiveSupport::Deprecation.warn("full_text_search is deprecated, use text_search = :full instead", caller) + @text_search = :full + end def full_text_search? - @full_text_search + ::ActiveSupport::Deprecation.warn("full_text_search? is deprecated, use text_search == :full instead", caller) + @text_search == :full end # the ActionLink for this action diff --git a/lib/active_scaffold/config/live_search.rb b/lib/active_scaffold/config/live_search.rb index 96ec54d359..985b71c78f 100644 --- a/lib/active_scaffold/config/live_search.rb +++ b/lib/active_scaffold/config/live_search.rb @@ -5,7 +5,7 @@ class LiveSearch < Base def initialize(core_config) @core = core_config - @full_text_search = self.class.full_text_search? + @text_search = self.class.text_search # start with the ActionLink defined globally @link = self.class.link.clone @@ -18,11 +18,16 @@ def initialize(core_config) cattr_accessor :link @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) - cattr_writer :full_text_search + def self.full_text_search=(value) + ::ActiveSupport::Deprecation.warn("full_text_search is deprecated, use text_search = :full instead", caller) + @@text_search = :full + end def self.full_text_search? - @@full_text_search + ::ActiveSupport::Deprecation.warn("full_text_search? is deprecated, use text_search == :full instead", caller) + @@text_search == :full end - @@full_text_search = true + cattr_accessor :text_search + @@text_search = :full # instance-level configuration # ---------------------------- @@ -38,9 +43,14 @@ def columns public :columns= - attr_writer :full_text_search + attr_accessor :text_search + def full_text_search=(value) + ::ActiveSupport::Deprecation.warn("full_text_search is deprecated, use text_search = :full instead", caller) + @text_search = :full + end def full_text_search? - @full_text_search + ::ActiveSupport::Deprecation.warn("full_text_search? is deprecated, use text_search == :full instead", caller) + @text_search == :full end # the ActionLink for this action diff --git a/lib/active_scaffold/config/search.rb b/lib/active_scaffold/config/search.rb index d589750a99..77db55a8bf 100644 --- a/lib/active_scaffold/config/search.rb +++ b/lib/active_scaffold/config/search.rb @@ -5,7 +5,7 @@ class Search < Base def initialize(core_config) @core = core_config - @full_text_search = self.class.full_text_search? + @text_search = self.class.text_search # start with the ActionLink defined globally @link = self.class.link.clone @@ -18,11 +18,16 @@ def initialize(core_config) cattr_accessor :link @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) - cattr_writer :full_text_search + def self.full_text_search=(value) + ::ActiveSupport::Deprecation.warn("full_text_search is deprecated, use text_search = :full instead", caller) + @@text_search = :full + end def self.full_text_search? - @@full_text_search + ::ActiveSupport::Deprecation.warn("full_text_search? is deprecated, use text_search == :full instead", caller) + @@text_search == :full end - @@full_text_search = true + cattr_accessor :text_search + @@text_search = :full # instance-level configuration # ---------------------------- @@ -38,9 +43,14 @@ def columns public :columns= - attr_writer :full_text_search + attr_accessor :text_search + def full_text_search=(value) + ::ActiveSupport::Deprecation.warn("full_text_search is deprecated, use text_search = :full instead", caller) + @text_search = :full + end def full_text_search? - @full_text_search + ::ActiveSupport::Deprecation.warn("full_text_search? is deprecated, use text_search == :full instead", caller) + @text_search == :full end # the ActionLink for this action diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 1d75b7bdef..a6768f93ff 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -4,9 +4,10 @@ module ClassMethods # Takes a collection of search terms (the tokens) and creates SQL that # searches all specified ActiveScaffold columns. A row will match if each # token is found in at least one of the columns. - def create_conditions_for_columns(tokens, columns, like_pattern = '%?%') + def create_conditions_for_columns(tokens, columns, text_search = :full) # if there aren't any columns, then just return a nil condition return unless columns.length > 0 + like_pattern = like_pattern(text_search) tokens = [tokens] if tokens.is_a? String @@ -27,7 +28,8 @@ def create_conditions_for_columns(tokens, columns, like_pattern = '%?%') # Generates an SQL condition for the given ActiveScaffold column based on # that column's database type (or form_ui ... for virtual columns?). # TODO: this should reside on the column, not the controller - def condition_for_column(column, value, like_pattern = '%?%') + def condition_for_column(column, value, text_search = :full) + like_pattern = like_pattern(text_search) # we must check false or not blank because we want to search for false but false is blank return unless column and column.search_sql and not value.blank? search_ui = column.search_ui || column.column.type @@ -84,6 +86,15 @@ def condition_for_datetime_type(column, value, like_pattern) alias_method :condition_for_date_type, :condition_for_datetime_type alias_method :condition_for_time_type, :condition_for_datetime_type alias_method :condition_for_timestamp_type, :condition_for_datetime_type + + def like_pattern(text_search) + case text_search + when :full then '%?%' + when :start then '?%' + when :end then '%?' + else '?' + end + end end NumericComparators = [ diff --git a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js index ec9e7b3eb2..c605fa0cd8 100644 --- a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +++ b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js @@ -435,7 +435,7 @@ ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.Act ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { setFieldFromAjax: function(url, options) { - this._controls.editor.remove(); + $(this._controls.editor).remove(); new Ajax.Request(url, { method: 'get', onComplete: function(response) { @@ -464,7 +464,7 @@ ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { this.setValue(fld, this._controls.editor.value); if (this.options.submitOnBlur) fld.onblur = this._boundSubmitHandler; - this._controls.editor.remove(); + $(this._controls.editor).remove(); this._controls.editor = fld; this._form.appendChild(this._controls.editor); From 22fa69b47e4eed2bd0d687fe397c1d970c6b0981 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 16 Feb 2010 14:28:56 +0100 Subject: [PATCH 0175/2024] Add global configuration for subform layout --- lib/active_scaffold/config/subform.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/subform.rb b/lib/active_scaffold/config/subform.rb index 25c43e47b7..580a283f20 100644 --- a/lib/active_scaffold/config/subform.rb +++ b/lib/active_scaffold/config/subform.rb @@ -2,12 +2,15 @@ module ActiveScaffold::Config class Subform < Base def initialize(core_config) @core = core_config - @layout = :horizontal # default layout + @layout = self.class.layout # default layout end # global level configuration # -------------------------- + cattr_accessor :layout + @@layout = :horizontal + # instance-level configuration # ---------------------------- From 2e152115de064d932b409ec74fd5ce4a6434995f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Feb 2010 09:33:52 +0100 Subject: [PATCH 0176/2024] Check column.params always, fix deleting file column (issue #702) --- lib/active_scaffold/attribute_params.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 668d2280e0..0347020c93 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -47,6 +47,11 @@ def update_record_from_params(parent_record, columns, attributes) end columns.each :for => parent_record, :action => action, :flatten => true do |column| + # Set any passthrough parameters that may be associated with this column (ie, file column "keep" and "temp" attributes) + unless column.params.empty? + column.params.each{|p| parent_record.send("#{p}=", attributes[p]) if attributes.has_key? p} + end + if multi_parameter_attributes.has_key? column.name parent_record.send(:assign_multiparameter_attributes, multi_parameter_attributes[column.name]) elsif attributes.has_key? column.name @@ -55,11 +60,6 @@ def update_record_from_params(parent_record, columns, attributes) # we avoid assigning a value that already exists because otherwise has_one associations will break (AR bug in has_one_association.rb#replace) parent_record.send("#{column.name}=", value) unless column.through_association? or parent_record.send(column.name) == value - # Set any passthrough parameters that may be associated with this column (ie, file column "keep" and "temp" attributes) - unless column.params.empty? - column.params.each{|p| parent_record.send("#{p}=", attributes[p])} - end - # plural associations may not actually appear in the params if all of the options have been unselected or cleared away. # NOTE: the "form_ui" check isn't really necessary, except that without it we have problems # with subforms. the UI cuts out deep associations, which means they're not present in the From 07f0ea5195ea30a455e3136e7b0426e2b0a30d7a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Feb 2010 10:37:58 +0100 Subject: [PATCH 0177/2024] Highlight row after create/update (issue #228), fix highlight of views (edit, create, search, show) after open --- frontends/default/javascripts/active_scaffold.js | 5 +++-- frontends/default/stylesheets/stylesheet.css | 14 +++++++++----- frontends/default/views/on_create.js.rjs | 3 ++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index c605fa0cd8..5d0b099572 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -355,7 +355,7 @@ ActiveScaffold.ActionLink.Record.prototype = Object.extend(new ActiveScaffold.Ac this.adapter.down('a.inline-adapter-close').observe('click', this.close_handler.bind(this)); this.register_cancel_hooks(); - new Effect.Highlight(this.adapter.down('td')); + new Effect.Highlight(this.adapter.down('td').down()); }, close_handler: function(event) { @@ -375,6 +375,7 @@ ActiveScaffold.ActionLink.Record.prototype = Object.extend(new ActiveScaffold.Ac if (this.target.hasClassName('even-record')) new_target.addClassName('even-record'); this.target = new_target; this.close(); + new Effect.Highlight(this.target); }.bind(this), onFailure: function(request) { @@ -424,7 +425,7 @@ ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.Act this.adapter.down('a.inline-adapter-close').observe('click', this.close_handler.bind(this)); this.register_cancel_hooks(); - new Effect.Highlight(this.adapter.down('td')); + new Effect.Highlight(this.adapter.down('td').down()); }, close_handler: function(event) { diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index a8804a6518..e1f880c040 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -190,29 +190,33 @@ background: #333 url(../../../images/active_scaffold/default/indicator-small.gif /* Table :: Record Rows ============================= */ +.active-scaffold tr.record { + background-color: #E6F2FF; +} .active-scaffold tr.record td { padding: 5px 4px; color: #333; font-family: Verdana, sans-serif; font-size: 11px; -background-color: #E6F2FF; border-bottom: solid 1px #C5DBF7; border-left: solid 1px #C5DBF7; } -.active-scaffold tr.even-record td { +.active-scaffold tr.even-record { background-color: #fff; -border-left: solid 1px #ddd; +} +.active-scaffold tr.even-record td { +border-left-color: #ddd; } .active-scaffold tr.record td.sorted { background-color: #B9DCFF; -border-bottom: solid 1px #AFD0F5; +border-bottom-color: #AFD0F5; } .active-scaffold tr.even-record td.sorted { background-color: #E6F2FF; -border-bottom: solid 1px #AFD0F5; +border-bottom-color: #AFD0F5; } .active-scaffold tbody.records td.empty { diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index 81f22f2b46..ef9968aa80 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -6,6 +6,7 @@ if controller.send :successful? page << "ActiveScaffold.stripe($('#{active_scaffold_tbody_id}'))" page << "ActiveScaffold.hide_empty_message('#{active_scaffold_tbody_id}','#{empty_message_id}');" page << "ActiveScaffold.increment_record_count('#{active_scaffold_id}');" + page[element_row_id(:action => :list, :id => @record.id)].highlight end if (active_scaffold_config.create.persistent) @@ -22,4 +23,4 @@ else page.replace element_form_id(:action => :create), :partial => 'create_form' page << "l.register_cancel_hooks();" end -page.replace_html active_scaffold_messages_id, :partial => 'messages' \ No newline at end of file +page.replace_html active_scaffold_messages_id, :partial => 'messages' From 26564c0e2120f0d899271b0b1620eaa9e7bd8491 Mon Sep 17 00:00:00 2001 From: Jake Cahoon <jcahoon@alliancehealth.com> Date: Tue, 20 Oct 2009 20:00:40 -0600 Subject: [PATCH 0178/2024] Fix the subforms on IE7 --- frontends/default/views/edit_associated.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/edit_associated.js.rjs b/frontends/default/views/edit_associated.js.rjs index da2fe2fe31..33e4a11d1b 100644 --- a/frontends/default/views/edit_associated.js.rjs +++ b/frontends/default/views/edit_associated.js.rjs @@ -4,7 +4,7 @@ if @column.singular_association? page << %| associated = #{associated_form.to_json}; if (current = $$('##{sub_form_list_id(:association => @column.name)} .association-record')[0]) { - Element.update(current, associated) + Element.replace(current, associated) } else { new Insertion.Top('#{sub_form_list_id(:association => @column.name)}', associated) } From 95067ec17d3283637032a65551b211ca845a5119 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Feb 2010 13:45:43 +0100 Subject: [PATCH 0179/2024] Fix renaming crud type from destroy to delete --- lib/active_record_permissions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_record_permissions.rb b/lib/active_record_permissions.rb index c4f65f3a01..6b44d278fd 100644 --- a/lib/active_record_permissions.rb +++ b/lib/active_record_permissions.rb @@ -82,7 +82,7 @@ module SecurityMethods # options[:column] should be the name of a model attribute # options[:action] is the name of a method def authorized_for?(options = {}) - raise ArgumentError, "unknown action #{options[:crud_type]}" if options[:crud_type] and ![:create, :read, :update, :destroy].include?(options[:crud_type]) + raise ArgumentError, "unknown crud type #{options[:crud_type]}" if options[:crud_type] and ![:create, :read, :update, :delete].include?(options[:crud_type]) # column_authorized_for_crud_type? has the highest priority over other methods, # you can disable a crud verb and enable that verb for a column From 29b341160f5eb4c344253199c0279caf2ae6ca82 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Feb 2010 13:46:18 +0100 Subject: [PATCH 0180/2024] Update assets in test --- .../active_scaffold/default/active_scaffold.js | 5 +++-- .../active_scaffold/default/stylesheet.css | 14 +++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js index c605fa0cd8..5d0b099572 100644 --- a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +++ b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js @@ -355,7 +355,7 @@ ActiveScaffold.ActionLink.Record.prototype = Object.extend(new ActiveScaffold.Ac this.adapter.down('a.inline-adapter-close').observe('click', this.close_handler.bind(this)); this.register_cancel_hooks(); - new Effect.Highlight(this.adapter.down('td')); + new Effect.Highlight(this.adapter.down('td').down()); }, close_handler: function(event) { @@ -375,6 +375,7 @@ ActiveScaffold.ActionLink.Record.prototype = Object.extend(new ActiveScaffold.Ac if (this.target.hasClassName('even-record')) new_target.addClassName('even-record'); this.target = new_target; this.close(); + new Effect.Highlight(this.target); }.bind(this), onFailure: function(request) { @@ -424,7 +425,7 @@ ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.Act this.adapter.down('a.inline-adapter-close').observe('click', this.close_handler.bind(this)); this.register_cancel_hooks(); - new Effect.Highlight(this.adapter.down('td')); + new Effect.Highlight(this.adapter.down('td').down()); }, close_handler: function(event) { diff --git a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css index a8804a6518..e1f880c040 100644 --- a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +++ b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css @@ -190,29 +190,33 @@ background: #333 url(../../../images/active_scaffold/default/indicator-small.gif /* Table :: Record Rows ============================= */ +.active-scaffold tr.record { + background-color: #E6F2FF; +} .active-scaffold tr.record td { padding: 5px 4px; color: #333; font-family: Verdana, sans-serif; font-size: 11px; -background-color: #E6F2FF; border-bottom: solid 1px #C5DBF7; border-left: solid 1px #C5DBF7; } -.active-scaffold tr.even-record td { +.active-scaffold tr.even-record { background-color: #fff; -border-left: solid 1px #ddd; +} +.active-scaffold tr.even-record td { +border-left-color: #ddd; } .active-scaffold tr.record td.sorted { background-color: #B9DCFF; -border-bottom: solid 1px #AFD0F5; +border-bottom-color: #AFD0F5; } .active-scaffold tr.even-record td.sorted { background-color: #E6F2FF; -border-bottom: solid 1px #AFD0F5; +border-bottom-color: #AFD0F5; } .active-scaffold tbody.records td.empty { From 31c7830e0d8f026aa03dc5d2ed6ba4a1a2f3238a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Feb 2010 14:29:16 +0100 Subject: [PATCH 0181/2024] Performance: manage updating in one request, formerly, two requests (update, row) were necessary --- .../default/javascripts/active_scaffold.js | 45 +++++++++++-------- frontends/default/views/on_update.js.rjs | 3 +- lib/responds_to_parent.rb | 2 +- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 5d0b099572..94df122136 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -364,24 +364,33 @@ ActiveScaffold.ActionLink.Record.prototype = Object.extend(new ActiveScaffold.Ac }, /* it might simplify things to just override the close function. then the Record and Table links could share more code ... wouldn't need custom close_handler functions, for instance */ - close_with_refresh: function() { - new Ajax.Request(this.refresh_url, { - asynchronous: true, - evalScripts: true, - method: this.method, - onSuccess: function(request) { - Element.replace(this.target, request.responseText); - var new_target = $(this.target.id); - if (this.target.hasClassName('even-record')) new_target.addClassName('even-record'); - this.target = new_target; - this.close(); - new Effect.Highlight(this.target); - }.bind(this), - - onFailure: function(request) { - ActiveScaffold.report_500_response(this.scaffold_id()); - } - }); + close_with_refresh: function(updatedRow) { + if (updatedRow) { + Element.replace(this.target, updatedRow); + var new_target = $(this.target.id); + if (this.target.hasClassName('even-record')) new_target.addClassName('even-record'); + this.target = new_target; + this.close(); + new Effect.Highlight(this.target); + } else { + new Ajax.Request(this.refresh_url, { + asynchronous: true, + evalScripts: true, + method: this.method, + onSuccess: function(request) { + Element.replace(this.target, request.responseText); + var new_target = $(this.target.id); + if (this.target.hasClassName('even-record')) new_target.addClassName('even-record'); + this.target = new_target; + this.close(); + new Effect.Highlight(this.target); + }.bind(this), + + onFailure: function(request) { + ActiveScaffold.report_500_response(this.scaffold_id()); + } + }); + } }, enable: function() { diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index fcd31779bc..d47ad63317 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -1,7 +1,8 @@ cancel_selector = "##{element_form_id(:action => :update)} a.cancel".to_json if controller.send :successful? - page << "$$(#{cancel_selector}).first().link.close_with_refresh();" + updated_row = render :partial => 'list_record', :locals => {:record => @record} + page << "$$(#{cancel_selector}).first().link.close_with_refresh('#{escape_javascript(updated_row)}');" page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} else page << "l = $$(#{cancel_selector}).first().link;" diff --git a/lib/responds_to_parent.rb b/lib/responds_to_parent.rb index f1adfe9d40..31ee781b6b 100644 --- a/lib/responds_to_parent.rb +++ b/lib/responds_to_parent.rb @@ -59,7 +59,7 @@ def responds_to_parent(&block) # window.eval - legal eval for Opera render :text => "<html><body><script type='text/javascript' charset='utf-8'> var loc = document.location; - with(window.parent) { setTimeout(function() { window.eval('#{script}'); loc.replace('about:blank'); }, 1) } + with(window.parent) { setTimeout(function() { window.eval('#{script}'); if (typeof(loc) !== 'undefined') loc.replace('about:blank'); }, 1) }; </script></body></html>" end end From 78ae8e5f4eb1af50131eda91184b50d80edae2f9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Feb 2010 17:18:06 +0100 Subject: [PATCH 0182/2024] Add generic view to update a row, simplify active_scaffold.js --- .../default/javascripts/active_scaffold.js | 125 ++++++++---------- frontends/default/views/on_create.js.rjs | 2 +- frontends/default/views/on_update.js.rjs | 4 +- frontends/default/views/update_row.js.rjs | 1 + 4 files changed, 60 insertions(+), 72 deletions(-) create mode 100644 frontends/default/views/update_row.js.rjs diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 94df122136..05511778c4 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -77,6 +77,13 @@ var ActiveScaffold = { count = $$('#' + scaffold_id + ' span.active-scaffold-records').last(); count.innerHTML = parseInt(count.innerHTML) + 1; }, + update_row: function(row, html) { + row = $(row); + Element.replace(row, html); + var new_row = $(row.id); + if (row.hasClassName('even-record')) new_row.addClassName('even-record'); + new Effect.Highlight(new_row); + }, server_error_response: '', report_500_response: function(active_scaffold_id) { @@ -166,8 +173,7 @@ Element.Methods.Simulated = { * A set of links. As a set, they can be controlled such that only one is "open" at a time, etc. */ ActiveScaffold.Actions = new Object(); -ActiveScaffold.Actions.Abstract = function(){} -ActiveScaffold.Actions.Abstract.prototype = { +ActiveScaffold.Actions.Abstract = Class.create({ initialize: function(links, target, loading_indicator, options) { this.target = $(target); this.loading_indicator = $(loading_indicator); @@ -180,15 +186,14 @@ ActiveScaffold.Actions.Abstract.prototype = { instantiate_link: function(link) { throw 'unimplemented' } -} +}); /** * A DataStructures::ActionLink, represented in JavaScript. * Concerned with AJAX-enabling a link and adapting the result for insertion into the table. */ ActiveScaffold.ActionLink = new Object(); -ActiveScaffold.ActionLink.Abstract = function(){} -ActiveScaffold.ActionLink.Abstract.prototype = { +ActiveScaffold.ActionLink.Abstract = Class.create({ initialize: function(a, target, loading_indicator) { this.tag = $(a); this.url = this.tag.href; @@ -226,37 +231,37 @@ ActiveScaffold.ActionLink.Abstract.prototype = { } }, - open_action: function() { - if (this.position) this.disable(); - - if (this.page_link) { - window.location = this.url; - } else { - if (this.loading_indicator) this.loading_indicator.style.visibility = 'visible'; - new Ajax.Request(this.url, { - asynchronous: true, - evalScripts: true, - method: this.method, - onSuccess: function(request) { - if (this.position) { - this.insert(request.responseText); - if (this.hide_target) this.target.hide(); - } else { - request.evalResponse(); - } - }.bind(this), - - onFailure: function(request) { - ActiveScaffold.report_500_response(this.scaffold_id()); - if (this.position) this.enable() - }.bind(this), - - onComplete: function(request) { - if (this.loading_indicator) this.loading_indicator.style.visibility = 'hidden'; - }.bind(this) - }); - } - }, + open_action: function() { + if (this.position) this.disable(); + + if (this.page_link) { + window.location = this.url; + } else { + if (this.loading_indicator) this.loading_indicator.style.visibility = 'visible'; + new Ajax.Request(this.url, { + asynchronous: true, + evalScripts: true, + method: this.method, + onSuccess: function(request) { + if (this.position) { + this.insert(request.responseText); + if (this.hide_target) this.target.hide(); + } else { + request.evalResponse(); + } + }.bind(this), + + onFailure: function(request) { + ActiveScaffold.report_500_response(this.scaffold_id()); + if (this.position) this.enable() + }.bind(this), + + onComplete: function(request) { + if (this.loading_indicator) this.loading_indicator.style.visibility = 'hidden'; + }.bind(this) + }); + } + }, insert: function(content) { throw 'unimplemented' @@ -268,6 +273,11 @@ ActiveScaffold.ActionLink.Abstract.prototype = { if (this.hide_target) this.target.show(); }, + close_handler: function(event) { + this.close(); + if (event) Event.stop(event); + }, + register_cancel_hooks: function() { // anything in the insert with a class of cancel gets the closer method, and a reference to this object for good measure var self = this; @@ -304,13 +314,12 @@ ActiveScaffold.ActionLink.Abstract.prototype = { scaffold_id: function() { return this.tag.up('div.active-scaffold').id; } -} +}); /** * Concrete classes for record actions */ -ActiveScaffold.Actions.Record = Class.create(); -ActiveScaffold.Actions.Record.prototype = Object.extend(new ActiveScaffold.Actions.Abstract(), { +ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, { instantiate_link: function(link) { var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); l.refresh_url = this.options.refresh_url; @@ -324,8 +333,7 @@ ActiveScaffold.Actions.Record.prototype = Object.extend(new ActiveScaffold.Actio } }); -ActiveScaffold.ActionLink.Record = Class.create(); -ActiveScaffold.ActionLink.Record.prototype = Object.extend(new ActiveScaffold.ActionLink.Abstract(), { +ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstract, { close_previous_adapter: function() { this.set.links.each(function(item) { if (item.url != this.url && item.is_disabled() && item.adapter) item.close(); @@ -358,32 +366,18 @@ ActiveScaffold.ActionLink.Record.prototype = Object.extend(new ActiveScaffold.Ac new Effect.Highlight(this.adapter.down('td').down()); }, - close_handler: function(event) { - this.close_with_refresh(); - if (event) Event.stop(event); - }, - - /* it might simplify things to just override the close function. then the Record and Table links could share more code ... wouldn't need custom close_handler functions, for instance */ - close_with_refresh: function(updatedRow) { + close: function($super, updatedRow) { if (updatedRow) { - Element.replace(this.target, updatedRow); - var new_target = $(this.target.id); - if (this.target.hasClassName('even-record')) new_target.addClassName('even-record'); - this.target = new_target; - this.close(); - new Effect.Highlight(this.target); + ActiveScaffold.update_row(this.target, updatedRow); + $super(); } else { new Ajax.Request(this.refresh_url, { asynchronous: true, evalScripts: true, method: this.method, onSuccess: function(request) { - Element.replace(this.target, request.responseText); - var new_target = $(this.target.id); - if (this.target.hasClassName('even-record')) new_target.addClassName('even-record'); - this.target = new_target; - this.close(); - new Effect.Highlight(this.target); + ActiveScaffold.update_row(this.target, request.responseText); + $super(); }.bind(this), onFailure: function(request) { @@ -411,8 +405,7 @@ ActiveScaffold.ActionLink.Record.prototype = Object.extend(new ActiveScaffold.Ac /** * Concrete classes for table actions */ -ActiveScaffold.Actions.Table = Class.create(); -ActiveScaffold.Actions.Table.prototype = Object.extend(new ActiveScaffold.Actions.Abstract(), { +ActiveScaffold.Actions.Table = Class.create(ActiveScaffold.Actions.Abstract, { instantiate_link: function(link) { var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator); if (l.position) l.url = l.url.append_params({adapter: '_list_inline_adapter'}); @@ -420,8 +413,7 @@ ActiveScaffold.Actions.Table.prototype = Object.extend(new ActiveScaffold.Action } }); -ActiveScaffold.ActionLink.Table = Class.create(); -ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.ActionLink.Abstract(), { +ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstract, { insert: function(content) { if (this.position == 'top') { new Insertion.Top(this.target, content); @@ -436,11 +428,6 @@ ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.Act new Effect.Highlight(this.adapter.down('td').down()); }, - - close_handler: function(event) { - this.close(); - if (event) Event.stop(event); - } }); ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index ef9968aa80..f464004780 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -12,7 +12,7 @@ if controller.send :successful? if (active_scaffold_config.create.persistent) page << "$$(#{cancel_selector}).first().link.reload();" else - page << "$$(#{cancel_selector}).first().link.close#{'_with_refresh' unless @insert_row}();" + page << "$$(#{cancel_selector}).first().link.close();" end if (active_scaffold_config.create.edit_after_create) page << "var link = $('#{action_link_id 'edit', @record.id}');" diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index d47ad63317..b17fa58c71 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -2,11 +2,11 @@ cancel_selector = "##{element_form_id(:action => :update)} a.cancel".to_json if controller.send :successful? updated_row = render :partial => 'list_record', :locals => {:record => @record} - page << "$$(#{cancel_selector}).first().link.close_with_refresh('#{escape_javascript(updated_row)}');" + page << "$$(#{cancel_selector}).first().link.close('#{escape_javascript(updated_row)}');" page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} else page << "l = $$(#{cancel_selector}).first().link;" page.replace element_form_id(:action => :update), :partial => 'update_form' page << "l.register_cancel_hooks();" end -page.replace_html active_scaffold_messages_id, :partial => 'messages' \ No newline at end of file +page.replace_html active_scaffold_messages_id, :partial => 'messages' diff --git a/frontends/default/views/update_row.js.rjs b/frontends/default/views/update_row.js.rjs new file mode 100644 index 0000000000..ac654a92ba --- /dev/null +++ b/frontends/default/views/update_row.js.rjs @@ -0,0 +1 @@ +page.call 'ActiveScaffold.update_row', element_row_id(:action => 'list', :id => @record.id), render(:partial => 'list_record', :locals => {:record => @record}) From 75d8ea8626d978253913f8f3fecf255ad255a865 Mon Sep 17 00:00:00 2001 From: Lionel Bouton <lionel.bouton@jtek.fr> Date: Wed, 22 Apr 2009 18:49:09 +0200 Subject: [PATCH 0183/2024] corrections --- lib/active_scaffold/locale/fr.rb | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 1e3621f363..335efade82 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -2,9 +2,9 @@ :'fr' => { :active_scaffold => { :add => 'Ajouter', - :add_existing => 'Ajouter un existant', - :add_existing_model => 'Ajouter un {{model}} existant', - :are_you_sure_to_delete => 'Etes vous sûr ?', + :add_existing => 'Ajouter un(e) existant(e)', + :add_existing_model => 'Ajouter un(e) {{model}} existant(e)', + :are_you_sure_to_delete => 'Êtes vous sûr?', :cancel => 'Annuler', :click_to_edit => 'Cliquer pour éditer', :close => 'Fermer', @@ -36,6 +36,7 @@ :print => 'Imprimer', :refresh => 'Rafraîchir', :remove => 'Supprimer', +<<<<<<< HEAD:lib/active_scaffold/locale/fr.rb :remove_file => 'Supprimer ou Remplacer le fichier', :replace_with_new => 'Remplacer avec le nouveau', :revisions_for_model => 'Version pour {{model}}', @@ -50,6 +51,22 @@ :update => 'Mettre à jour', :update_model => 'Mettre à jour {{model}}', :updated_model => '{{model}} mis à jour', +======= + :remove_file => 'Supprimer et remplacer le fichier', + :replace_with_new => 'Remplacer avec le nouveau', + :revisions_for_model => 'Révision pour {{model}}', + :reset => 'Annuler', + :saving => 'Sauvegarder…', + :search => 'Rechercher', + :search_terms => 'Recherche de termes', + :_select_ => '- sélectionner -', + :show => 'Montrer', + :show_model => 'Montrer {{model}}', + :_to_ => ' à ', + :update => 'Mettre à jour', + :update_model => 'Mettre à jour le(/la) {{model}}', + :udated_model => 'Mis à jour de {{model}}', +>>>>>>> b8368cb... corrections:lib/active_scaffold/locale/fr.rb :'=' => '=', :'>=' => '>=', :'<=' => '<=', @@ -60,6 +77,10 @@ # error_messages :internal_error => 'Erreur de la requête (code 500, Erreur interne)', +<<<<<<< HEAD:lib/active_scaffold/locale/fr.rb :version_inconsistency => "Inconsistante de version - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer.", +======= + :version_inconsistency => "Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer.", +>>>>>>> b8368cb... corrections:lib/active_scaffold/locale/fr.rb } }} From c5218c5e9997fd13e2d2a25689aa09afb7b80e3f Mon Sep 17 00:00:00 2001 From: Lionel Bouton <lionel.bouton@jtek.fr> Date: Wed, 17 Feb 2010 18:00:03 +0100 Subject: [PATCH 0184/2024] Fix render_action_link when url_options[:action] is a symbol --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index bbfcc6926d..dcfb6dd310 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -161,7 +161,7 @@ def render_action_link(link, url_options, record = nil) html_options[:position] = link.position if link.position and link.inline? html_options[:class] += ' action' if link.inline? html_options[:popup] = true if link.popup? - html_options[:id] = action_link_id("#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}" + "#{url_options[:associations].to_s + '-' if url_options[:associations]}" + url_options[:action],url_options[:id] || url_options[:parent_id]) + html_options[:id] = action_link_id("#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}" + "#{url_options[:associations].to_s + '-' if url_options[:associations]}" + url_options[:action].to_s,url_options[:id] || url_options[:parent_id]) if link.dhtml_confirm? html_options[:class] += ' action' if !link.inline? From 5cf2e053aee51ef4185817a0bd734b8deeed6323 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 18 Feb 2010 14:29:34 +0100 Subject: [PATCH 0185/2024] clean merge conflicts --- lib/active_scaffold/locale/fr.rb | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 335efade82..664757b8b6 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -36,22 +36,6 @@ :print => 'Imprimer', :refresh => 'Rafraîchir', :remove => 'Supprimer', -<<<<<<< HEAD:lib/active_scaffold/locale/fr.rb - :remove_file => 'Supprimer ou Remplacer le fichier', - :replace_with_new => 'Remplacer avec le nouveau', - :revisions_for_model => 'Version pour {{model}}', - :reset => 'Ré-initialiser', - :saving => 'Sauvegarde en cours…', - :search => 'Rechercher', - :search_terms => 'Rechercher les termes', - :_select_ => '- sélectionner -', - :show => 'Afficher', - :show_model => 'Afficher {{model}}', - :_to_ => ' à ', - :update => 'Mettre à jour', - :update_model => 'Mettre à jour {{model}}', - :updated_model => '{{model}} mis à jour', -======= :remove_file => 'Supprimer et remplacer le fichier', :replace_with_new => 'Remplacer avec le nouveau', :revisions_for_model => 'Révision pour {{model}}', @@ -65,8 +49,7 @@ :_to_ => ' à ', :update => 'Mettre à jour', :update_model => 'Mettre à jour le(/la) {{model}}', - :udated_model => 'Mis à jour de {{model}}', ->>>>>>> b8368cb... corrections:lib/active_scaffold/locale/fr.rb + :updated_model => 'Mis à jour de {{model}}', :'=' => '=', :'>=' => '>=', :'<=' => '<=', @@ -77,10 +60,6 @@ # error_messages :internal_error => 'Erreur de la requête (code 500, Erreur interne)', -<<<<<<< HEAD:lib/active_scaffold/locale/fr.rb - :version_inconsistency => "Inconsistante de version - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer.", -======= :version_inconsistency => "Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer.", ->>>>>>> b8368cb... corrections:lib/active_scaffold/locale/fr.rb } }} From 1b61e0166ac3a9a6bb122657ee9b5510c45a0663 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 18 Feb 2010 17:18:55 +0100 Subject: [PATCH 0186/2024] Support for infinite pagination (issue #523) Load last page when trying to load a page bigger than last one --- frontends/default/views/_list.html.erb | 4 +- lib/active_scaffold/actions/list.rb | 9 +- lib/active_scaffold/config/list.rb | 8 + lib/active_scaffold/finder.rb | 4 +- .../helpers/pagination_helpers.rb | 35 ++++- lib/paginator.rb | 12 +- test/misc/pagination_helpers_test.rb | 24 ++- .../default/active_scaffold.js | 144 +++++++++--------- 8 files changed, 149 insertions(+), 91 deletions(-) diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index 299ea875db..a47391ada2 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -29,9 +29,11 @@ </tbody> </table> <div class="active-scaffold-footer"> +<% unless @page.pager.infinite? -%> <div class="active-scaffold-found"><span class="active-scaffold-records"><%= @page.pager.count -%></span> <%=as_(:found, :count => @page.pager.count) %></div> +<% end -%> <div class="active-scaffold-pagination"> - <%= render :partial => 'list_pagination_links', :locals => { :current_page => @page } unless @page.pager.number_of_pages < 2 %> + <%= render :partial => 'list_pagination_links', :locals => { :current_page => @page } if @page.pager.infinite? || @page.pager.number_of_pages > 1 %> </div> <br clear="both" /><%# a hack for the Rico Corner problem %> </div> diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index f456668225..9a595322a9 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -64,14 +64,15 @@ def do_list if paginate options.merge!({ :per_page => active_scaffold_config.list.user.per_page, - :page => active_scaffold_config.list.user.page + :page => active_scaffold_config.list.user.page, + :infinite_pagination => active_scaffold_config.list.infinite_pagination }) end page = find_page(options); - if page.items.blank? - page = page.pager.first - active_scaffold_config.list.user.page = 1 + if page.items.blank? && !page.pager.infinite? + page = page.pager.last + active_scaffold_config.list.user.page = page.number end @page, @records = page, page.items end diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 0d5666b05b..8752708e46 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -16,6 +16,7 @@ def initialize(core_config) # inherit from global scope @empty_field_text = self.class.empty_field_text + @infinite_pagination = self.class.infinite_pagination end # global level configuration @@ -32,6 +33,10 @@ def initialize(core_config) cattr_accessor :empty_field_text @@empty_field_text = '-' + # Treat the source as having an infinite number of pages (i.e. don't count the records; useful for large tables where counting is slow and we don't really care anyway) + cattr_accessor :infinite_pagination + @@infinite_pagination = false + # instance-level configuration # ---------------------------- @@ -49,6 +54,9 @@ def columns # how many page links around current page to show attr_accessor :page_links_window + # Treat the source as having an infinite number of pages (i.e. don't count the records; useful for large tables where counting is slow and we don't really care anyway) + attr_accessor :infinite_pagination + # what string to use when a field is empty attr_accessor :empty_field_text diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index a6768f93ff..99c203bff2 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -182,7 +182,7 @@ def find_if_allowed(id, action, klass = nil) # * :page # TODO: this should reside on the model, not the controller def find_page(options = {}) - options.assert_valid_keys :sorting, :per_page, :page, :count_includes + options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :infinite_pagination full_includes = (active_scaffold_includes.blank? ? nil : active_scaffold_includes) search_conditions = all_conditions @@ -201,7 +201,7 @@ def find_page(options = {}) finder_options.merge! custom_finder_options # NOTE: we must use :include in the count query, because some conditions may reference other tables - count = klass.count(finder_options.reject{|k,v| [:select, :order].include? k}) + count = klass.count(finder_options.reject{|k,v| [:select, :order].include? k}) unless options[:infinite_pagination] # Converts count to an integer if ActiveRecord returned an OrderedHash # that happens when finder_options contains a :group key diff --git a/lib/active_scaffold/helpers/pagination_helpers.rb b/lib/active_scaffold/helpers/pagination_helpers.rb index 9571fe5547..08a27eca23 100644 --- a/lib/active_scaffold/helpers/pagination_helpers.rb +++ b/lib/active_scaffold/helpers/pagination_helpers.rb @@ -18,11 +18,29 @@ def pagination_ajax_links(current_page, params, window_size) start_number = current_page.number - window_size end_number = current_page.number + window_size start_number = 1 if start_number <= 0 - end_number = current_page.pager.last.number if end_number > current_page.pager.last.number + if current_page.pager.infinite? + offsets = [20, 100] + else + end_number = current_page.pager.last.number if end_number > current_page.pager.last.number + end html = [] - html << pagination_ajax_link(1, params) unless start_number == 1 - html << ".." unless start_number <= 2 + unless start_number == 1 + last_page = 1 + html << pagination_ajax_link(last_page, params) + if current_page.pager.infinite? + offsets.reverse.each do |offset| + page = current_page.number - offset + if page < start_number && page > 1 + html << '..' if page > last_page + 1 + html << pagination_ajax_link(page, params) + last_page = page + end + end + end + html << ".." if start_number > last_page + 1 + end + start_number.upto(end_number) do |num| if current_page.number == num html << num @@ -30,8 +48,15 @@ def pagination_ajax_links(current_page, params, window_size) html << pagination_ajax_link(num, params) end end - html << ".." unless end_number >= current_page.pager.last.number - 1 - html << pagination_ajax_link(current_page.pager.last.number, params) unless end_number == current_page.pager.last.number + + if current_page.pager.infinite? + offsets.each do |offset| + html << '..' << pagination_ajax_link(current_page.number + offset, params) + end + else + html << ".." unless end_number >= current_page.pager.last.number - 1 + html << pagination_ajax_link(current_page.pager.last.number, params) unless end_number == current_page.pager.last.number + end html.join(' ') end end diff --git a/lib/paginator.rb b/lib/paginator.rb index c4b89ee2c3..a7ff687853 100644 --- a/lib/paginator.rb +++ b/lib/paginator.rb @@ -13,7 +13,7 @@ class MissingSelectError < ArgumentError; end # Instantiate a new Paginator object # # Provide: - # * A total count of the number of objects to paginate + # * A total count of the number of objects to paginate. Use nil for infinite pagination # * The number of objects in each page # * A block that returns the array of items # * The block is passed the item offset @@ -27,9 +27,14 @@ def initialize(count, per_page, &select) @select = select end + # Is this an "infinite" paginator + def infinite? + @count.nil? + end + # Total number of pages def number_of_pages - (@count / @per_page).to_i + (@count % @per_page > 0 ? 1 : 0) + (@count / @per_page).to_i + (@count % @per_page > 0 ? 1 : 0) unless infinite? end # First page object @@ -105,6 +110,7 @@ def prev # Checks to see if there's a page after this one def next? + return true if @pager.infinite? @number < @pager.number_of_pages end @@ -133,4 +139,4 @@ def ==(other) #:nodoc: end -end \ No newline at end of file +end diff --git a/test/misc/pagination_helpers_test.rb b/test/misc/pagination_helpers_test.rb index 68cccfb6fa..e3235e7410 100644 --- a/test/misc/pagination_helpers_test.rb +++ b/test/misc/pagination_helpers_test.rb @@ -26,9 +26,29 @@ def test_links assert_equal 'l .. l l l 6 l l l .. l', links(6, 20, 3) end + def test_links_with_infinite_pagination + self.stubs(:pagination_ajax_link).returns('l') + + assert_equal '1 l l .. l .. l', links(1, nil, 2, true) + assert_equal 'l 2 l l .. l .. l', links(2, nil, 2, true) + assert_equal 'l l 3 l l .. l .. l', links(3, nil, 2, true) + assert_equal 'l l l 4 l l .. l .. l', links(4, nil, 2, true) + assert_equal 'l .. l l 5 l l .. l .. l', links(5, nil, 2, true) + + assert_equal 'l .. l l 20 l l .. l .. l', links(20, nil, 2, true) + assert_equal 'l .. l l 21 l l .. l .. l', links(21, nil, 2, true) + assert_equal 'l l .. l l 22 l l .. l .. l', links(22, nil, 2, true) + assert_equal 'l .. l .. l l 23 l l .. l .. l', links(23, nil, 2, true) + + assert_equal 'l .. l .. l l 100 l l .. l .. l', links(100, nil, 2, true) + assert_equal 'l .. l .. l l 101 l l .. l .. l', links(101, nil, 2, true) + assert_equal 'l l .. l .. l l 102 l l .. l .. l', links(102, nil, 2, true) + assert_equal 'l .. l .. l .. l l 103 l l .. l .. l', links(103, nil, 2, true) + end + private - def links(current, last_page, window_size = 2) - paginator = stub(:last => last_page = stub(:number => last_page)) + def links(current, last_page, window_size = 2, infinite = false) + paginator = stub(:last => last_page = stub(:number => last_page), :infinite? => infinite) current_page = stub(:number => current, :pager => paginator) pagination_ajax_links(current_page, {}, window_size) end diff --git a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js index 5d0b099572..05511778c4 100644 --- a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +++ b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js @@ -77,6 +77,13 @@ var ActiveScaffold = { count = $$('#' + scaffold_id + ' span.active-scaffold-records').last(); count.innerHTML = parseInt(count.innerHTML) + 1; }, + update_row: function(row, html) { + row = $(row); + Element.replace(row, html); + var new_row = $(row.id); + if (row.hasClassName('even-record')) new_row.addClassName('even-record'); + new Effect.Highlight(new_row); + }, server_error_response: '', report_500_response: function(active_scaffold_id) { @@ -166,8 +173,7 @@ Element.Methods.Simulated = { * A set of links. As a set, they can be controlled such that only one is "open" at a time, etc. */ ActiveScaffold.Actions = new Object(); -ActiveScaffold.Actions.Abstract = function(){} -ActiveScaffold.Actions.Abstract.prototype = { +ActiveScaffold.Actions.Abstract = Class.create({ initialize: function(links, target, loading_indicator, options) { this.target = $(target); this.loading_indicator = $(loading_indicator); @@ -180,15 +186,14 @@ ActiveScaffold.Actions.Abstract.prototype = { instantiate_link: function(link) { throw 'unimplemented' } -} +}); /** * A DataStructures::ActionLink, represented in JavaScript. * Concerned with AJAX-enabling a link and adapting the result for insertion into the table. */ ActiveScaffold.ActionLink = new Object(); -ActiveScaffold.ActionLink.Abstract = function(){} -ActiveScaffold.ActionLink.Abstract.prototype = { +ActiveScaffold.ActionLink.Abstract = Class.create({ initialize: function(a, target, loading_indicator) { this.tag = $(a); this.url = this.tag.href; @@ -226,37 +231,37 @@ ActiveScaffold.ActionLink.Abstract.prototype = { } }, - open_action: function() { - if (this.position) this.disable(); - - if (this.page_link) { - window.location = this.url; - } else { - if (this.loading_indicator) this.loading_indicator.style.visibility = 'visible'; - new Ajax.Request(this.url, { - asynchronous: true, - evalScripts: true, - method: this.method, - onSuccess: function(request) { - if (this.position) { - this.insert(request.responseText); - if (this.hide_target) this.target.hide(); - } else { - request.evalResponse(); - } - }.bind(this), - - onFailure: function(request) { - ActiveScaffold.report_500_response(this.scaffold_id()); - if (this.position) this.enable() - }.bind(this), - - onComplete: function(request) { - if (this.loading_indicator) this.loading_indicator.style.visibility = 'hidden'; - }.bind(this) - }); - } - }, + open_action: function() { + if (this.position) this.disable(); + + if (this.page_link) { + window.location = this.url; + } else { + if (this.loading_indicator) this.loading_indicator.style.visibility = 'visible'; + new Ajax.Request(this.url, { + asynchronous: true, + evalScripts: true, + method: this.method, + onSuccess: function(request) { + if (this.position) { + this.insert(request.responseText); + if (this.hide_target) this.target.hide(); + } else { + request.evalResponse(); + } + }.bind(this), + + onFailure: function(request) { + ActiveScaffold.report_500_response(this.scaffold_id()); + if (this.position) this.enable() + }.bind(this), + + onComplete: function(request) { + if (this.loading_indicator) this.loading_indicator.style.visibility = 'hidden'; + }.bind(this) + }); + } + }, insert: function(content) { throw 'unimplemented' @@ -268,6 +273,11 @@ ActiveScaffold.ActionLink.Abstract.prototype = { if (this.hide_target) this.target.show(); }, + close_handler: function(event) { + this.close(); + if (event) Event.stop(event); + }, + register_cancel_hooks: function() { // anything in the insert with a class of cancel gets the closer method, and a reference to this object for good measure var self = this; @@ -304,13 +314,12 @@ ActiveScaffold.ActionLink.Abstract.prototype = { scaffold_id: function() { return this.tag.up('div.active-scaffold').id; } -} +}); /** * Concrete classes for record actions */ -ActiveScaffold.Actions.Record = Class.create(); -ActiveScaffold.Actions.Record.prototype = Object.extend(new ActiveScaffold.Actions.Abstract(), { +ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, { instantiate_link: function(link) { var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); l.refresh_url = this.options.refresh_url; @@ -324,8 +333,7 @@ ActiveScaffold.Actions.Record.prototype = Object.extend(new ActiveScaffold.Actio } }); -ActiveScaffold.ActionLink.Record = Class.create(); -ActiveScaffold.ActionLink.Record.prototype = Object.extend(new ActiveScaffold.ActionLink.Abstract(), { +ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstract, { close_previous_adapter: function() { this.set.links.each(function(item) { if (item.url != this.url && item.is_disabled() && item.adapter) item.close(); @@ -358,30 +366,25 @@ ActiveScaffold.ActionLink.Record.prototype = Object.extend(new ActiveScaffold.Ac new Effect.Highlight(this.adapter.down('td').down()); }, - close_handler: function(event) { - this.close_with_refresh(); - if (event) Event.stop(event); - }, - - /* it might simplify things to just override the close function. then the Record and Table links could share more code ... wouldn't need custom close_handler functions, for instance */ - close_with_refresh: function() { - new Ajax.Request(this.refresh_url, { - asynchronous: true, - evalScripts: true, - method: this.method, - onSuccess: function(request) { - Element.replace(this.target, request.responseText); - var new_target = $(this.target.id); - if (this.target.hasClassName('even-record')) new_target.addClassName('even-record'); - this.target = new_target; - this.close(); - new Effect.Highlight(this.target); - }.bind(this), - - onFailure: function(request) { - ActiveScaffold.report_500_response(this.scaffold_id()); - } - }); + close: function($super, updatedRow) { + if (updatedRow) { + ActiveScaffold.update_row(this.target, updatedRow); + $super(); + } else { + new Ajax.Request(this.refresh_url, { + asynchronous: true, + evalScripts: true, + method: this.method, + onSuccess: function(request) { + ActiveScaffold.update_row(this.target, request.responseText); + $super(); + }.bind(this), + + onFailure: function(request) { + ActiveScaffold.report_500_response(this.scaffold_id()); + } + }); + } }, enable: function() { @@ -402,8 +405,7 @@ ActiveScaffold.ActionLink.Record.prototype = Object.extend(new ActiveScaffold.Ac /** * Concrete classes for table actions */ -ActiveScaffold.Actions.Table = Class.create(); -ActiveScaffold.Actions.Table.prototype = Object.extend(new ActiveScaffold.Actions.Abstract(), { +ActiveScaffold.Actions.Table = Class.create(ActiveScaffold.Actions.Abstract, { instantiate_link: function(link) { var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator); if (l.position) l.url = l.url.append_params({adapter: '_list_inline_adapter'}); @@ -411,8 +413,7 @@ ActiveScaffold.Actions.Table.prototype = Object.extend(new ActiveScaffold.Action } }); -ActiveScaffold.ActionLink.Table = Class.create(); -ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.ActionLink.Abstract(), { +ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstract, { insert: function(content) { if (this.position == 'top') { new Insertion.Top(this.target, content); @@ -427,11 +428,6 @@ ActiveScaffold.ActionLink.Table.prototype = Object.extend(new ActiveScaffold.Act new Effect.Highlight(this.adapter.down('td').down()); }, - - close_handler: function(event) { - this.close(); - if (event) Event.stop(event); - } }); ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { From d121ebba8a2a5b52c5c1da5f47beb6a89e9c620f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 22 Feb 2010 09:55:23 +0100 Subject: [PATCH 0187/2024] Don't modify paginator.rb, it's a copy from gem and changes are lost if the gem is used --- lib/extensions/paginator_extensions.rb | 26 ++++++++++++++++++++++++++ lib/paginator.rb | 10 ++-------- 2 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 lib/extensions/paginator_extensions.rb diff --git a/lib/extensions/paginator_extensions.rb b/lib/extensions/paginator_extensions.rb new file mode 100644 index 0000000000..63ebb651ef --- /dev/null +++ b/lib/extensions/paginator_extensions.rb @@ -0,0 +1,26 @@ +require 'paginator' + +class Paginator + + # Total number of pages + def number_of_pages_with_infinite + number_of_pages_without_infinite unless infinite? + end + alias_method_chain :number_of_pages, :infinite + + # Is this an "infinite" paginator + def infinite? + @count.nil? + end + + class Page + # Checks to see if there's a page after this one + def next_with_infinite? + return true if @pager.infinite? + next_without_infinite? + end + alias_method_chain :next?, :infinite + end + +end + diff --git a/lib/paginator.rb b/lib/paginator.rb index a7ff687853..b17b28bebf 100644 --- a/lib/paginator.rb +++ b/lib/paginator.rb @@ -13,7 +13,7 @@ class MissingSelectError < ArgumentError; end # Instantiate a new Paginator object # # Provide: - # * A total count of the number of objects to paginate. Use nil for infinite pagination + # * A total count of the number of objects to paginate # * The number of objects in each page # * A block that returns the array of items # * The block is passed the item offset @@ -27,14 +27,9 @@ def initialize(count, per_page, &select) @select = select end - # Is this an "infinite" paginator - def infinite? - @count.nil? - end - # Total number of pages def number_of_pages - (@count / @per_page).to_i + (@count % @per_page > 0 ? 1 : 0) unless infinite? + (@count / @per_page).to_i + (@count % @per_page > 0 ? 1 : 0) end # First page object @@ -110,7 +105,6 @@ def prev # Checks to see if there's a page after this one def next? - return true if @pager.infinite? @number < @pager.number_of_pages end From 77e8d59f38285c9331a6ff402852d27da38a2cf5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 22 Feb 2010 10:55:22 +0100 Subject: [PATCH 0188/2024] Change named_scopes_for_collection with beginning_of_chain --- lib/active_scaffold/actions/core.rb | 8 +++- lib/active_scaffold/finder.rb | 5 ++- test/misc/finder_test.rb | 4 +- test/misc/named_scope_test.rb | 69 ----------------------------- 4 files changed, 11 insertions(+), 75 deletions(-) delete mode 100644 test/misc/named_scope_test.rb diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index df9a90ed7d..b6e094c291 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -106,8 +106,12 @@ def custom_finder_options end #Overide this method on your controller to provide model with named scopes - def named_scopes_for_collection - nil + def beginning_of_chain + if respond_to? :named_scopes_for_collection + ::ActiveSupport::Deprecation.warn(":named_scope_for_collection is deprecated, override beginning_of_chain instead", caller) + return model_with_named_scope + end + active_scaffold_config.model end # Builds search conditions by search params for column names. This allows urls like "contacts/list?company_id=5". diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 99c203bff2..c525ec818c 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -148,6 +148,7 @@ def all_conditions ) end + # Deprecated def model_with_named_scope(model = active_scaffold_config.model, scope_definitions = named_scopes_for_collection) case scope_definitions when String @@ -168,7 +169,7 @@ def model_with_named_scope(model = active_scaffold_config.model, scope_definitio # returns a single record (the given id) but only if it's allowed for the specified action. # accomplishes this by checking model.#{action}_authorized? # TODO: this should reside on the model, not the controller - def find_if_allowed(id, action, klass = nil) + def find_if_allowed(id, action, klass = beginning_of_chain) klass ||= active_scaffold_config.model record = klass.find(id) raise ActiveScaffold::RecordNotAllowed unless record.authorized_for?(:action => action.to_sym) @@ -190,7 +191,7 @@ def find_page(options = {}) options[:page] ||= 1 options[:count_includes] ||= full_includes unless search_conditions.nil? - klass = model_with_named_scope + klass = beginning_of_chain # create a general-use options array that's compatible with Rails finders finder_options = { :order => options[:sorting].try(:clause), diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index e262c2e3e3..105e5d1840 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -10,8 +10,8 @@ def joins_for_collection; end def custom_finder_options {} end - def named_scopes_for_collection - nil + def beginning_of_chain + active_scaffold_config.model end end diff --git a/test/misc/named_scope_test.rb b/test/misc/named_scope_test.rb deleted file mode 100644 index 5b84ab81a5..0000000000 --- a/test/misc/named_scope_test.rb +++ /dev/null @@ -1,69 +0,0 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') - -class ClassWithFinder - include ActiveScaffold::Finder - def conditions_for_collection; end - def conditions_from_params; end - def conditions_from_constraints; end - def joins_for_collection; end - def custom_finder_options - {} - end - def named_scopes_for_collection - nil - end -end - -class NamedScopeTest < Test::Unit::TestCase - def setup - @klass = ClassWithFinder.new - @klass.stubs(:active_scaffold_config).returns(mock { stubs(:model).returns(ModelStub) }) - @klass.stubs(:active_scaffold_session_storage).returns({}) - ModelStub.nested_scope_calls.clear - end - - def test_named_scope_as_symbol - @klass.instance_eval do - def named_scopes_for_collection - :a_is_defined - end - end - model = @klass.send(:model_with_named_scope) - assert_equal 1, model.nested_scope_calls.length - end - - def test_named_scope_as_string - @klass.instance_eval do - def named_scopes_for_collection - "a_is_defined.b_like('hello')" - end - end - model = @klass.send(:model_with_named_scope) - assert_equal 2, model.nested_scope_calls.length - assert_equal :a_is_defined, model.nested_scope_calls.first - assert_equal :b_like, model.nested_scope_calls.last - end - - def test_named_scope_as_array - @klass.instance_eval do - def named_scopes_for_collection - [:b_like, 'hello'] - end - end - model = @klass.send(:model_with_named_scope) - assert_equal 1, model.nested_scope_calls.length - assert_equal :b_like, model.nested_scope_calls.first - end - - def test_named_scope_as_array_of_array - @klass.instance_eval do - def named_scopes_for_collection - [[:b_like, 'hello'], [:a_is_defined]] - end - end - model = @klass.send(:model_with_named_scope) - assert_equal 2, model.nested_scope_calls.length - assert_equal :b_like, model.nested_scope_calls.first - assert_equal :a_is_defined, model.nested_scope_calls.last - end -end From 29ddd470cbb6b310c4a161b9550777fa172a70f1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 22 Feb 2010 10:55:22 +0100 Subject: [PATCH 0189/2024] Change named_scopes_for_collection with beginning_of_chain --- lib/active_scaffold/actions/core.rb | 8 +++- lib/active_scaffold/finder.rb | 6 +-- test/misc/finder_test.rb | 4 +- test/misc/named_scope_test.rb | 69 ----------------------------- 4 files changed, 11 insertions(+), 76 deletions(-) delete mode 100644 test/misc/named_scope_test.rb diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index df9a90ed7d..b6e094c291 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -106,8 +106,12 @@ def custom_finder_options end #Overide this method on your controller to provide model with named scopes - def named_scopes_for_collection - nil + def beginning_of_chain + if respond_to? :named_scopes_for_collection + ::ActiveSupport::Deprecation.warn(":named_scope_for_collection is deprecated, override beginning_of_chain instead", caller) + return model_with_named_scope + end + active_scaffold_config.model end # Builds search conditions by search params for column names. This allows urls like "contacts/list?company_id=5". diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 99c203bff2..448733ce16 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -148,6 +148,7 @@ def all_conditions ) end + # Deprecated def model_with_named_scope(model = active_scaffold_config.model, scope_definitions = named_scopes_for_collection) case scope_definitions when String @@ -168,8 +169,7 @@ def model_with_named_scope(model = active_scaffold_config.model, scope_definitio # returns a single record (the given id) but only if it's allowed for the specified action. # accomplishes this by checking model.#{action}_authorized? # TODO: this should reside on the model, not the controller - def find_if_allowed(id, action, klass = nil) - klass ||= active_scaffold_config.model + def find_if_allowed(id, action, klass = beginning_of_chain) record = klass.find(id) raise ActiveScaffold::RecordNotAllowed unless record.authorized_for?(:action => action.to_sym) return record @@ -190,7 +190,7 @@ def find_page(options = {}) options[:page] ||= 1 options[:count_includes] ||= full_includes unless search_conditions.nil? - klass = model_with_named_scope + klass = beginning_of_chain # create a general-use options array that's compatible with Rails finders finder_options = { :order => options[:sorting].try(:clause), diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index e262c2e3e3..105e5d1840 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -10,8 +10,8 @@ def joins_for_collection; end def custom_finder_options {} end - def named_scopes_for_collection - nil + def beginning_of_chain + active_scaffold_config.model end end diff --git a/test/misc/named_scope_test.rb b/test/misc/named_scope_test.rb deleted file mode 100644 index 5b84ab81a5..0000000000 --- a/test/misc/named_scope_test.rb +++ /dev/null @@ -1,69 +0,0 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') - -class ClassWithFinder - include ActiveScaffold::Finder - def conditions_for_collection; end - def conditions_from_params; end - def conditions_from_constraints; end - def joins_for_collection; end - def custom_finder_options - {} - end - def named_scopes_for_collection - nil - end -end - -class NamedScopeTest < Test::Unit::TestCase - def setup - @klass = ClassWithFinder.new - @klass.stubs(:active_scaffold_config).returns(mock { stubs(:model).returns(ModelStub) }) - @klass.stubs(:active_scaffold_session_storage).returns({}) - ModelStub.nested_scope_calls.clear - end - - def test_named_scope_as_symbol - @klass.instance_eval do - def named_scopes_for_collection - :a_is_defined - end - end - model = @klass.send(:model_with_named_scope) - assert_equal 1, model.nested_scope_calls.length - end - - def test_named_scope_as_string - @klass.instance_eval do - def named_scopes_for_collection - "a_is_defined.b_like('hello')" - end - end - model = @klass.send(:model_with_named_scope) - assert_equal 2, model.nested_scope_calls.length - assert_equal :a_is_defined, model.nested_scope_calls.first - assert_equal :b_like, model.nested_scope_calls.last - end - - def test_named_scope_as_array - @klass.instance_eval do - def named_scopes_for_collection - [:b_like, 'hello'] - end - end - model = @klass.send(:model_with_named_scope) - assert_equal 1, model.nested_scope_calls.length - assert_equal :b_like, model.nested_scope_calls.first - end - - def test_named_scope_as_array_of_array - @klass.instance_eval do - def named_scopes_for_collection - [[:b_like, 'hello'], [:a_is_defined]] - end - end - model = @klass.send(:model_with_named_scope) - assert_equal 2, model.nested_scope_calls.length - assert_equal :b_like, model.nested_scope_calls.first - assert_equal :a_is_defined, model.nested_scope_calls.last - end -end From f9d14bbdcabcc37c2d0c9df2fee0a35d3cf2a817 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 22 Feb 2010 17:16:13 +0100 Subject: [PATCH 0190/2024] Support disabling pagination --- frontends/default/views/_list.html.erb | 2 ++ lib/active_scaffold/actions/list.rb | 2 +- lib/active_scaffold/config/list.rb | 26 ++++++++++++++++++++------ lib/active_scaffold/finder.rb | 9 +++++---- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index a47391ada2..f2dd3d7609 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -28,6 +28,7 @@ <% end -%> </tbody> </table> +<% if active_scaffold_config.list.pagination -%> <div class="active-scaffold-footer"> <% unless @page.pager.infinite? -%> <div class="active-scaffold-found"><span class="active-scaffold-records"><%= @page.pager.count -%></span> <%=as_(:found, :count => @page.pager.count) %></div> @@ -37,3 +38,4 @@ </div> <br clear="both" /><%# a hack for the Rico Corner problem %> </div> +<% end -%> diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 9a595322a9..3cea5fb77e 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -65,7 +65,7 @@ def do_list options.merge!({ :per_page => active_scaffold_config.list.user.per_page, :page => active_scaffold_config.list.user.page, - :infinite_pagination => active_scaffold_config.list.infinite_pagination + :pagination => active_scaffold_config.list.pagination }) end diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 8752708e46..03f08c9420 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -16,7 +16,7 @@ def initialize(core_config) # inherit from global scope @empty_field_text = self.class.empty_field_text - @infinite_pagination = self.class.infinite_pagination + @pagination = self.class.pagination end # global level configuration @@ -33,9 +33,16 @@ def initialize(core_config) cattr_accessor :empty_field_text @@empty_field_text = '-' - # Treat the source as having an infinite number of pages (i.e. don't count the records; useful for large tables where counting is slow and we don't really care anyway) - cattr_accessor :infinite_pagination - @@infinite_pagination = false + # What kind of pagination to use: + # * true: The usual pagination + # * :infinite: Treat the source as having an infinite number of pages (i.e. don't count the records; useful for large tables where counting is slow and we don't really care anyway) + # * false: Disable pagination + cattr_accessor :pagination + @@pagination = true + def self.infinite_pagination=(value) + ::ActiveSupport::Deprecation.warn("infinite_pagination is deprecated, use pagination = :infinite instead", caller) + self.pagination = :infinite + end # instance-level configuration # ---------------------------- @@ -54,8 +61,15 @@ def columns # how many page links around current page to show attr_accessor :page_links_window - # Treat the source as having an infinite number of pages (i.e. don't count the records; useful for large tables where counting is slow and we don't really care anyway) - attr_accessor :infinite_pagination + # What kind of pagination to use: + # * true: The usual pagination + # * :infinite: Treat the source as having an infinite number of pages (i.e. don't count the records; useful for large tables where counting is slow and we don't really care anyway) + # * false: Disable pagination + attr_accessor :pagination + def infinite_pagination=(value) + ::ActiveSupport::Deprecation.warn("infinite_pagination is deprecated, use pagination = :infinite instead", caller) + self.pagination = :infinite + end # what string to use when a field is empty attr_accessor :empty_field_text diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 448733ce16..0876e66de8 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -182,7 +182,7 @@ def find_if_allowed(id, action, klass = beginning_of_chain) # * :page # TODO: this should reside on the model, not the controller def find_page(options = {}) - options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :infinite_pagination + options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination full_includes = (active_scaffold_includes.blank? ? nil : active_scaffold_includes) search_conditions = all_conditions @@ -201,7 +201,7 @@ def find_page(options = {}) finder_options.merge! custom_finder_options # NOTE: we must use :include in the count query, because some conditions may reference other tables - count = klass.count(finder_options.reject{|k,v| [:select, :order].include? k}) unless options[:infinite_pagination] + count = klass.count(finder_options.reject{|k,v| [:select, :order].include? k}) unless options[:pagination] == :infinite # Converts count to an integer if ActiveRecord returned an OrderedHash # that happens when finder_options contains a :group key @@ -213,11 +213,12 @@ def find_page(options = {}) if options[:sorting] and options[:sorting].sorts_by_method? pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| sorted_collection = sort_collection_by_column(klass.all(finder_options), *options[:sorting].first) - sorted_collection.slice(offset, per_page) + sorted_collection.slice(offset, per_page) if options[:pagination] end else pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| - klass.all(finder_options.merge(:offset => offset, :limit => per_page)) + finder_options.merge!(:offset => offset, :limit => per_page) if options[:pagination] + klass.all(finder_options) end end From b81d39558462fffab4d268a8ba869bbc0a786c81 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 22 Feb 2010 18:03:23 +0100 Subject: [PATCH 0191/2024] Test infinite and disabled pagination --- test/misc/finder_test.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index 105e5d1840..3baf157663 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -70,9 +70,24 @@ def test_method_sorting def test_count_with_group @klass.expects(:custom_finder_options).returns({:group => :a}) ModelStub.expects(:count).returns(ActiveSupport::OrderedHash['foo', 5]) - page = @klass.send :find_page + ModelStub.expects(:find).with(:all, has_entries(:limit => 20, :offset => 0)) + page = @klass.send :find_page, :per_page => 20, :pagination => true + page.items - #assert_instance_of Integer, page.pager.count + assert_kind_of Integer, page.pager.count + assert_equal 1, page.pager.count assert_nothing_raised { page.pager.number_of_pages } end + + def test_disabled_pagination + ModelStub.expects(:count).returns(85) + ModelStub.expects(:find).with(:all, Not(has_entries(:limit => 20, :offset => 0))) + page = @klass.send :find_page, :per_page => 20, :pagination => false + page.items + end + + def test_infinite_pagination + ModelStub.expects(:count).never + page = @klass.send :find_page, :pagination => :infinite + end end From 637eb5fa33335db6357130c6f74dcf7ac5a4ea9b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 23 Feb 2010 11:34:13 +0100 Subject: [PATCH 0192/2024] Validate HTML for check boxes in list Cleanup inplace edit code --- frontends/default/views/update_column.js.rjs | 8 ++------ .../helpers/list_column_helpers.rb | 19 +++++-------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/frontends/default/views/update_column.js.rjs b/frontends/default/views/update_column.js.rjs index ed642b3adf..07792d0a94 100644 --- a/frontends/default/views/update_column.js.rjs +++ b/frontends/default/views/update_column.js.rjs @@ -4,9 +4,5 @@ unless controller.send :successful? @record.reload end column = active_scaffold_config.columns[params[:column]] -if column.inplace_edit - page.replace_html(column_span_id,format_inplace_edit_column(@record, column)) -else - formatted_value = get_column_value(@record, column) - page.replace_html(column_span_id, formatted_value) -end \ No newline at end of file +formatted_value = get_column_value(@record, column) +page.replace_html(column_span_id, formatted_value) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 1e922c6697..c2d0b376bf 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -113,11 +113,11 @@ def active_scaffold_column_checkbox(column, record) checked = column_value.class.to_s.include?('Class') ? column_value : column_value == 1 if column.inplace_edit and record.authorized_for?(:action => :update, :column => column.name) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} - tag_options = {:tag => "span", :id => element_cell_id(id_options), :class => "in_place_editor_field"} + tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field"} script = remote_function(:method => 'POST', :url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s, :value => !column_value, :eid => params[:eid]}) - content_tag(:span, check_box_tag(tag_options[:id], 1, checked, {:onclick => script}) , tag_options) + content_tag(:span, check_box_tag(nil, 1, checked, :onclick => script, :id => nil), tag_options) else - check_box_tag(nil, 1, checked, :disabled => true) + check_box_tag(nil, 1, checked, :disabled => true, :id => nil) end end @@ -234,19 +234,10 @@ def inplace_edit_cloning?(column) column.inplace_edit != :ajax and (override_form_field?(column) or column.form_ui or (column.column and override_input?(column.column.type))) end - def format_inplace_edit_column(record,column) - value = record.send(column.name) - if column.list_ui == :checkbox - active_scaffold_column_checkbox(column, record) - else - format_column_value(record, column) - end - end - def active_scaffold_inplace_edit(record, column) - formatted_column = format_inplace_edit_column(record,column) + formatted_column = format_column_value(record, column) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} - tag_options = {:tag => "span", :id => element_cell_id(id_options), :class => "in_place_editor_field"} + tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field"} in_place_editor_options = { :url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s}, :with => params[:eid] ? "Form.serialize(form) + '&eid=#{params[:eid]}'" : nil, From f6606736df33b1f588d81e65a19dae5bb125ce04 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 23 Feb 2010 11:34:13 +0100 Subject: [PATCH 0193/2024] Validate HTML for check boxes in list Cleanup inplace edit code --- frontends/default/views/update_column.js.rjs | 8 ++------ .../helpers/list_column_helpers.rb | 19 +++++-------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/frontends/default/views/update_column.js.rjs b/frontends/default/views/update_column.js.rjs index ed642b3adf..07792d0a94 100644 --- a/frontends/default/views/update_column.js.rjs +++ b/frontends/default/views/update_column.js.rjs @@ -4,9 +4,5 @@ unless controller.send :successful? @record.reload end column = active_scaffold_config.columns[params[:column]] -if column.inplace_edit - page.replace_html(column_span_id,format_inplace_edit_column(@record, column)) -else - formatted_value = get_column_value(@record, column) - page.replace_html(column_span_id, formatted_value) -end \ No newline at end of file +formatted_value = get_column_value(@record, column) +page.replace_html(column_span_id, formatted_value) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 1e922c6697..c2d0b376bf 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -113,11 +113,11 @@ def active_scaffold_column_checkbox(column, record) checked = column_value.class.to_s.include?('Class') ? column_value : column_value == 1 if column.inplace_edit and record.authorized_for?(:action => :update, :column => column.name) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} - tag_options = {:tag => "span", :id => element_cell_id(id_options), :class => "in_place_editor_field"} + tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field"} script = remote_function(:method => 'POST', :url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s, :value => !column_value, :eid => params[:eid]}) - content_tag(:span, check_box_tag(tag_options[:id], 1, checked, {:onclick => script}) , tag_options) + content_tag(:span, check_box_tag(nil, 1, checked, :onclick => script, :id => nil), tag_options) else - check_box_tag(nil, 1, checked, :disabled => true) + check_box_tag(nil, 1, checked, :disabled => true, :id => nil) end end @@ -234,19 +234,10 @@ def inplace_edit_cloning?(column) column.inplace_edit != :ajax and (override_form_field?(column) or column.form_ui or (column.column and override_input?(column.column.type))) end - def format_inplace_edit_column(record,column) - value = record.send(column.name) - if column.list_ui == :checkbox - active_scaffold_column_checkbox(column, record) - else - format_column_value(record, column) - end - end - def active_scaffold_inplace_edit(record, column) - formatted_column = format_inplace_edit_column(record,column) + formatted_column = format_column_value(record, column) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} - tag_options = {:tag => "span", :id => element_cell_id(id_options), :class => "in_place_editor_field"} + tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field"} in_place_editor_options = { :url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s}, :with => params[:eid] ? "Form.serialize(form) + '&eid=#{params[:eid]}'" : nil, From 23cb0c867dbec0ddcf468760c230c8f53134927f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 23 Feb 2010 16:19:51 +0100 Subject: [PATCH 0194/2024] Fix html validation errors in search forms --- frontends/default/views/_field_search.html.erb | 4 ++-- frontends/default/views/_live_search.html.erb | 2 +- frontends/default/views/_search.html.erb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_field_search.html.erb b/frontends/default/views/_field_search.html.erb index ea93a57b54..897efbf876 100644 --- a/frontends/default/views/_field_search.html.erb +++ b/frontends/default/views/_field_search.html.erb @@ -11,7 +11,7 @@ href = url_for(params_for(:action => :update_table, :escape => false).delete_if{ :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{search_form_id}');", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :update => active_scaffold_content_id, - :html => { :href => href, :id => search_form_id, :class => 'search', :method => :get } %> + :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> <ol class="form"> <% active_scaffold_config.field_search.columns.each do |column| -%> @@ -42,4 +42,4 @@ href = url_for(params_for(:action => :update_table, :escape => false).delete_if{ //<![CDATA[ Form.focusFirstElement('<%= search_form_id -%>'); //]]> -</script> \ No newline at end of file +</script> diff --git a/frontends/default/views/_live_search.html.erb b/frontends/default/views/_live_search.html.erb index 128ea0f473..3f9bb89a10 100644 --- a/frontends/default/views/_live_search.html.erb +++ b/frontends/default/views/_live_search.html.erb @@ -6,7 +6,7 @@ :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden';", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :update => active_scaffold_content_id, - :html => { :href => href, :id => search_form_id, :class => 'search', :method => :get } %> + :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> <input type="text" name="search" size="50" value="<%= params[:search] -%>" class="text-input" id="<%= search_input_id %>" autocompleted="off" /> <a href="javascript:void(0)" class="cancel" onclick="f = this.up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> <%= loading_indicator_tag(:action => :search) %> diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index a32203066a..bd6f9a02ab 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -6,7 +6,7 @@ :complete => "$('#{loading_indicator_id(:action => :search)}').style.visibility = 'hidden'; Form.enable('#{search_form_id}');", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :update => active_scaffold_content_id, - :html => { :href => href, :id => search_form_id, :class => 'search', :method => :get } %> + :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> <input type="text" name="search" size="50" value="<%= params[:search] -%>" class="text-input" id="<%= search_input_id %>" autocompleted="off" /> <%= submit_tag as_(:search), :class => "submit" %> <a href="javascript:void(0)" class="cancel" onclick="f = this.up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> From b55b1a237b6e2944cbdb57a54b56cf05c752f7dd Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 23 Feb 2010 16:56:28 +0100 Subject: [PATCH 0195/2024] Fix inplace editing, update_column view was broken recently --- frontends/default/views/update_column.js.rjs | 8 +++++-- .../helpers/list_column_helpers.rb | 21 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/frontends/default/views/update_column.js.rjs b/frontends/default/views/update_column.js.rjs index 07792d0a94..cf87bd9a2f 100644 --- a/frontends/default/views/update_column.js.rjs +++ b/frontends/default/views/update_column.js.rjs @@ -4,5 +4,9 @@ unless controller.send :successful? @record.reload end column = active_scaffold_config.columns[params[:column]] -formatted_value = get_column_value(@record, column) -page.replace_html(column_span_id, formatted_value) +if column.inplace_edit + page.replace_html(column_span_id, format_inplace_edit_column(@record, column)) +else + formatted_value = get_column_value(@record, column) + page.replace_html(column_span_id, formatted_value) +end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index c2d0b376bf..1c1dd4cba4 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -109,15 +109,12 @@ def active_scaffold_column_text(column, record) end def active_scaffold_column_checkbox(column, record) - column_value = record.send(column.name) - checked = column_value.class.to_s.include?('Class') ? column_value : column_value == 1 if column.inplace_edit and record.authorized_for?(:action => :update, :column => column.name) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field"} - script = remote_function(:method => 'POST', :url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s, :value => !column_value, :eid => params[:eid]}) - content_tag(:span, check_box_tag(nil, 1, checked, :onclick => script, :id => nil), tag_options) + content_tag(:span, format_column_checkbox(record, column), tag_options) else - check_box_tag(nil, 1, checked, :disabled => true, :id => nil) + check_box(:record, column.name, :disabled => true, :id => nil, :object => record) end end @@ -142,6 +139,12 @@ def override_column_ui(list_ui) ## Formatting ## + def format_column_checkbox(record, column) + checked = ActionView::Helpers::InstanceTag.check_box_checked?(record.send(column.name), '1') + script = remote_function(:method => 'POST', :url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s, :value => !checked, :eid => params[:eid]}) + check_box(:record, column.name, :onclick => script, :id => nil, :object => record) + end + def format_column_value(record, column) value = record.send(column.name) if value && column.association # cache association size before calling column_empty? @@ -234,6 +237,14 @@ def inplace_edit_cloning?(column) column.inplace_edit != :ajax and (override_form_field?(column) or column.form_ui or (column.column and override_input?(column.column.type))) end + def format_inplace_edit_column(record,column) + if column.list_ui == :checkbox + format_column_checkbox(record, column) + else + format_column_value(record, column) + end + end + def active_scaffold_inplace_edit(record, column) formatted_column = format_column_value(record, column) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} From 9c0e18d53f166bd666d34a324283ba155766fba0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 24 Feb 2010 10:40:12 +0100 Subject: [PATCH 0196/2024] remove deprecation warning when no option is set --- lib/active_scaffold/helpers/form_column_helpers.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 3b5df5274f..8a06b00643 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -93,12 +93,9 @@ def active_scaffold_input_singular_association(column, html_options) html_options[:name] += '[id]' options = {:selected => selected, :include_blank => as_(:_select_)} - # For backwards compatibility, to add method options is needed to set a html_options hash - # in other case all column.options will be added as html options - if column.options[:html_options] - html_options.update(column.options[:html_options] || {}) - options.update(column.options) - else + html_options.update(column.options[:html_options] || {}) + options.update(column.options) + unless column.options[:html_options] || column.options.empty? Rails.logger.warn "ActiveScaffold: Setting html options directly in a hash is deprecated for :select form_ui. Set the html options hash under html_options key, such as config.columns[:column_name].options = {:html_options => {...}, ...}" html_options.update(column.options) end From 33636b57ded2440523c074914ee8ffb4ed5d713f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 24 Feb 2010 13:52:33 +0100 Subject: [PATCH 0197/2024] Fix adding includes from constraints --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 0876e66de8..0ce1af8c5a 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -184,8 +184,8 @@ def find_if_allowed(id, action, klass = beginning_of_chain) def find_page(options = {}) options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination - full_includes = (active_scaffold_includes.blank? ? nil : active_scaffold_includes) search_conditions = all_conditions + full_includes = (active_scaffold_includes.blank? ? nil : active_scaffold_includes) options[:per_page] ||= 999999999 options[:page] ||= 1 options[:count_includes] ||= full_includes unless search_conditions.nil? From 40ac83494459a4116c8edb72d086effe2745132d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 25 Feb 2010 10:34:21 +0100 Subject: [PATCH 0198/2024] Automatically pass locals to parent template with render :super --- lib/extensions/action_view_rendering.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index 105eb3098a..0fcc6cd0e9 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -26,6 +26,7 @@ def render_with_active_scaffold(*args, &block) if args.first == :super options = args[1] || {} options[:locals] ||= {} + options[:locals].reverse_merge! @local_assigns known_extensions = [:erb, :rhtml, :rjs, :haml] # search through call stack for a template file (normally matches on first caller) @@ -86,3 +87,14 @@ def template_exists?(template_name, lookup_overrides = false) end end end + +module ActionView::Renderable + def render_with_active_scaffold(view, local_assigns = {}) + old_local_assigns = view.instance_variable_get(:@local_assigns) + view.instance_variable_set(:@local_assigns, local_assigns) + output = render_without_active_scaffold(view, local_assigns) + view.instance_variable_set(:@local_assigns, old_local_assigns) + output + end + alias_method_chain :render, :active_scaffold +end From 806b5bd0a7c9309d0ef7dd9800173945b2f2061d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 25 Feb 2010 10:48:55 +0100 Subject: [PATCH 0199/2024] Fix issue #731, xss in search form --- frontends/default/views/_live_search.html.erb | 2 +- frontends/default/views/_search.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_live_search.html.erb b/frontends/default/views/_live_search.html.erb index 3f9bb89a10..1fae18101c 100644 --- a/frontends/default/views/_live_search.html.erb +++ b/frontends/default/views/_live_search.html.erb @@ -7,7 +7,7 @@ :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :update => active_scaffold_content_id, :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> - <input type="text" name="search" size="50" value="<%= params[:search] -%>" class="text-input" id="<%= search_input_id %>" autocompleted="off" /> + <%= text_field_tag :search, params[:search], :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> <a href="javascript:void(0)" class="cancel" onclick="f = this.up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> <%= loading_indicator_tag(:action => :search) %> </form> diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index bd6f9a02ab..f96fd9a319 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -7,7 +7,7 @@ :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :update => active_scaffold_content_id, :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> - <input type="text" name="search" size="50" value="<%= params[:search] -%>" class="text-input" id="<%= search_input_id %>" autocompleted="off" /> + <%= text_field_tag :search, params[:search], :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> <%= submit_tag as_(:search), :class => "submit" %> <a href="javascript:void(0)" class="cancel" onclick="f = this.up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> <%= loading_indicator_tag(:action => :search) %> From c268c3237967a46c2a87e0e4d6949c69b2005d83 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 25 Feb 2010 11:40:01 +0100 Subject: [PATCH 0200/2024] Fix conflicts and an old authorized_for using action instead of crud_type --- frontends/default/views/_horizontal_subform_record.html.erb | 4 ---- frontends/default/views/_vertical_subform_record.html.erb | 4 ---- lib/active_scaffold/helpers/list_column_helpers.rb | 4 ++-- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index c3724f6566..51264a2477 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -20,11 +20,7 @@ <% end -%> <% if show_actions -%> <td class="actions"> -<<<<<<< HEAD:frontends/default/views/_horizontal_subform_record.html.erb <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> -======= - <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:action => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> ->>>>>>> master:frontends/default/views/_horizontal_subform_record.html.erb <% unless @record.new_record? %> <input type="hidden" name="<%= "record#{scope}[id]" -%>" value="<%= @record.id -%>" /> <% end -%> diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index de1ec89df6..6397722591 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -22,11 +22,7 @@ <% end -%> <% if show_actions -%> <li class="actions"> -<<<<<<< HEAD:frontends/default/views/_vertical_subform_record.html.erb <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> -======= - <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:action => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> ->>>>>>> master:frontends/default/views/_vertical_subform_record.html.erb <% unless @record.new_record? %> <input type="hidden" name="<%= "record#{scope}[id]" -%>" value="<%= @record.id -%>" /> <% end -%> diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 168abf6101..ea404e3f75 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -109,7 +109,7 @@ def active_scaffold_column_text(column, record) end def active_scaffold_column_checkbox(column, record) - if column.inplace_edit and record.authorized_for?(:action => :update, :column => column.name) + if inplace_edit?(record, column) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field"} content_tag(:span, format_column_checkbox(record, column), tag_options) @@ -230,7 +230,7 @@ def cache_association(value, column) # ========== def inplace_edit?(record, column) - column.inplace_edit and record.authorized_for?(:action => :update, :column => column.name) + column.inplace_edit and record.authorized_for?(:crud_type => :update, :column => column.name) end def inplace_edit_cloning?(column) From dd2f2c80e2f77d6f8d0748ac0a9ba774143a85a4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 25 Feb 2010 11:57:33 +0100 Subject: [PATCH 0201/2024] Get rid of update_table action and respond to js in list action updating the content --- .../default/javascripts/active_scaffold.js | 3 +-- .../default/javascripts/dhtml_history.js | 2 +- .../default/views/_field_search.html.erb | 3 +-- .../views/_list_column_headings.html.erb | 3 +-- .../views/_list_pagination_links.html.erb | 4 +--- frontends/default/views/_live_search.html.erb | 3 +-- frontends/default/views/_search.html.erb | 3 +-- frontends/default/views/destroy.js.rjs | 2 +- frontends/default/views/list.js.rjs | 1 + lib/active_scaffold/actions/list.rb | 19 ++----------------- .../helpers/pagination_helpers.rb | 1 - lib/extensions/resources.rb | 2 +- 12 files changed, 12 insertions(+), 34 deletions(-) create mode 100644 frontends/default/views/list.js.rjs diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 05511778c4..d71d5b2122 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -48,9 +48,8 @@ var ActiveScaffold = { } }, reload_if_empty: function(tbody, url) { - var content_container_id = tbody.replace('tbody', 'content'); if (this.records_for(tbody).length == 0) { - new Ajax.Updater($(content_container_id), url, { + new Ajax.Request(url, { method: 'get', asynchronous: true, evalScripts: true diff --git a/frontends/default/javascripts/dhtml_history.js b/frontends/default/javascripts/dhtml_history.js index 161417e2e3..3bf6275c48 100755 --- a/frontends/default/javascripts/dhtml_history.js +++ b/frontends/default/javascripts/dhtml_history.js @@ -858,7 +858,7 @@ var handleHistoryChange = function(pageId, pageData) { var info = pageId.split(':'); var id = info[0]; pageData += '&_method=get'; - new Ajax.Updater(id+'-content', pageData, {asynchronous:true, evalScripts:true, method: 'get', onLoading:function(request){Element.show(id+'-pagination-loading-indicator');}}); + new Ajax.Request(pageData, {asynchronous:true, evalScripts:true, method: 'get', onLoading:function(request){Element.show(id+'-pagination-loading-indicator');}}); } window.onload = function() { diff --git a/frontends/default/views/_field_search.html.erb b/frontends/default/views/_field_search.html.erb index 897efbf876..cc684c1e27 100644 --- a/frontends/default/views/_field_search.html.erb +++ b/frontends/default/views/_field_search.html.erb @@ -2,7 +2,7 @@ # We have to remove search form params before the url_for method call, otherwise it throughs it on search_params = params[:search] params.merge!(:search => nil) -href = url_for(params_for(:action => :update_table, :escape => false).delete_if{|k,v| k == 'search'}) +href = url_for(params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'}) -%> <%= form_remote_tag :url => href, :method => :get, @@ -10,7 +10,6 @@ href = url_for(params_for(:action => :update_table, :escape => false).delete_if{ :after => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{search_form_id}');", :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{search_form_id}');", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :update => active_scaffold_content_id, :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> <ol class="form"> diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index 306eed9360..fae35109b6 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -8,7 +8,7 @@ default_sorting_stages = ['ASC', 'DESC'] <% stages = default_sorting.sorts_on?(column) ? default_sorting_stages : sorting_stages column_sort_direction = stages.after(sorting.direction_of(column)) || 'ASC' - sort_params = params_for(:action => :update_table, :page => 1, + sort_params = params_for(:action => :index, :page => 1, :sort => column.name, :sort_direction => column_sort_direction) column_header_id = active_scaffold_column_header_id(column) -%> @@ -20,7 +20,6 @@ default_sorting_stages = ['ASC', 'DESC'] :before => "addActiveScaffoldPageToHistory('#{href}', '#{controller_id}')", :loading => "Element.addClassName('#{column_header_id}','loading');", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :update => active_scaffold_content_id, :method => :get }, { :href => href } %> <% else -%> diff --git a/frontends/default/views/_list_pagination_links.html.erb b/frontends/default/views/_list_pagination_links.html.erb index 54679791a1..258e748e02 100644 --- a/frontends/default/views/_list_pagination_links.html.erb +++ b/frontends/default/views/_list_pagination_links.html.erb @@ -1,5 +1,5 @@ <% unless current_page.nil? -%> - <% pagination_params = params_for(:action => 'update_table') -%> + <% pagination_params = params_for(:action => :index) -%> <% indicator_params = pagination_params.merge(:action => 'pagination') -%> <% previous_url = url_for(pagination_params.merge(:page => current_page.number - 1)) -%> <% next_url = url_for(pagination_params.merge(:page => current_page.number + 1)) -%> @@ -12,7 +12,6 @@ :before => "addActiveScaffoldPageToHistory('#{previous_url}', '#{controller_id}');", :complete => "$('#{loading_indicator_id(:action => :pagination)}').style.visibility = 'hidden';", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :update => active_scaffold_content_id, :method => :get }, { :href => previous_url, :class => "previous"}) if current_page.prev? %> @@ -23,7 +22,6 @@ :before => "addActiveScaffoldPageToHistory('#{next_url}', '#{controller_id}');", :complete => "$('#{loading_indicator_id(:action => :pagination)}').style.visibility = 'hidden';", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :update => active_scaffold_content_id, :method => :get }, { :href => next_url, :class => "next"}) if current_page.next? %> diff --git a/frontends/default/views/_live_search.html.erb b/frontends/default/views/_live_search.html.erb index 1fae18101c..3ef048cb9f 100644 --- a/frontends/default/views/_live_search.html.erb +++ b/frontends/default/views/_live_search.html.erb @@ -1,11 +1,10 @@ -<% href = url_for(params_for(:action => :update_table, :escape => false).delete_if{|k,v| k == 'search'}) -%> +<% href = url_for(params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'}) -%> <%= form_remote_tag :url => href, :method => :get, :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", :after => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'visible';", :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden';", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :update => active_scaffold_content_id, :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> <%= text_field_tag :search, params[:search], :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> <a href="javascript:void(0)" class="cancel" onclick="f = this.up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index f96fd9a319..c14cd51bb0 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -1,11 +1,10 @@ -<% href = url_for(params_for(:action => :update_table, :escape => false).delete_if{|k,v| k == 'search'}) -%> +<% href = url_for(params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'}) -%> <%= form_remote_tag :url => href, :method => :get, :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", :after => "$('#{loading_indicator_id(:action => :search)}').style.visibility = 'visible'; Form.disable('#{search_form_id}');", :complete => "$('#{loading_indicator_id(:action => :search)}').style.visibility = 'hidden'; Form.enable('#{search_form_id}');", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :update => active_scaffold_content_id, :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> <%= text_field_tag :search, params[:search], :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> <%= submit_tag as_(:search), :class => "submit" %> diff --git a/frontends/default/views/destroy.js.rjs b/frontends/default/views/destroy.js.rjs index ca287de40a..caf67eed90 100644 --- a/frontends/default/views/destroy.js.rjs +++ b/frontends/default/views/destroy.js.rjs @@ -1,7 +1,7 @@ if controller.send(:successful?) page << "$('#{action_link_id((respond_to?(:nested_habtm?) and nested_habtm? and active_scaffold_config.nested.shallow_delete) ? 'destroy_existing' : 'delete', params[:id])}').action_link.close_previous_adapter();" page.remove element_row_id(:action => 'list', :id => params[:id]) - page << "ActiveScaffold.reload_if_empty('#{active_scaffold_tbody_id}','#{url_for(params_for(:action => 'update_table', :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" + page << "ActiveScaffold.reload_if_empty('#{active_scaffold_tbody_id}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" page << "ActiveScaffold.stripe('#{active_scaffold_tbody_id}');" page << "ActiveScaffold.decrement_record_count('#{active_scaffold_id}');" page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} diff --git a/frontends/default/views/list.js.rjs b/frontends/default/views/list.js.rjs new file mode 100644 index 0000000000..7cbb9235fb --- /dev/null +++ b/frontends/default/views/list.js.rjs @@ -0,0 +1 @@ +page[active_scaffold_content_id].replace_html render(:partial => 'list', :layout => false) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 3cea5fb77e..7dbbd78e16 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -1,7 +1,7 @@ module ActiveScaffold::Actions module List def self.included(base) - base.before_filter :list_authorized_filter, :only => [:index, :table, :update_table, :row, :list] + base.before_filter :list_authorized_filter, :only => [:index, :table, :row, :list] end def index @@ -13,12 +13,6 @@ def table render(:action => 'list', :layout => false) end - # This is called when changing pages, sorts and search - def update_table - do_list - respond_to_action(:update_table) - end - # get just a single row def row render :partial => 'list_record', :locals => {:record => find_if_allowed(params[:id], :read)} @@ -36,7 +30,7 @@ def list_respond_to_html render :action => 'list' end def list_respond_to_js - render :action => 'list', :layout => false + render :action => 'list.js' end def list_respond_to_xml render :xml => response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status @@ -47,12 +41,6 @@ def list_respond_to_json def list_respond_to_yaml render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end - def update_table_respond_to_html - return_to_main - end - def update_table_respond_to_js - render(:partial => 'list') - end # The actual algorithm to prepare for the list view def do_list includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact @@ -86,9 +74,6 @@ def list_authorized? def list_authorized_filter raise ActiveScaffold::ActionNotAllowed unless list_authorized? end - def update_table_formats - (default_formats + active_scaffold_config.formats).uniq - end def list_formats (default_formats + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq end diff --git a/lib/active_scaffold/helpers/pagination_helpers.rb b/lib/active_scaffold/helpers/pagination_helpers.rb index 08a27eca23..aba87ad5df 100644 --- a/lib/active_scaffold/helpers/pagination_helpers.rb +++ b/lib/active_scaffold/helpers/pagination_helpers.rb @@ -8,7 +8,6 @@ def pagination_ajax_link(page_number, params) :before => "addActiveScaffoldPageToHistory('#{url}', '#{controller_id}');", :after => "$('#{loading_indicator_id(:action => :pagination)}').style.visibility = 'visible';", :complete => "$('#{loading_indicator_id(:action => :pagination)}').style.visibility = 'hidden';", - :update => active_scaffold_content_id, :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :method => :get }, { :href => url_for(params.merge(:page => page_number)) }) diff --git a/lib/extensions/resources.rb b/lib/extensions/resources.rb index 5e90a0b845..18161f7e88 100644 --- a/lib/extensions/resources.rb +++ b/lib/extensions/resources.rb @@ -2,7 +2,7 @@ module ActionController module Resources class Resource ACTIVE_SCAFFOLD_ROUTING = { - :collection => {:show_search => :get, :update_table => :get, :edit_associated => :get, :list => :get, :new_existing => :get, :add_existing => :post, :render_field => :get}, + :collection => {:show_search => :get, :edit_associated => :get, :list => :get, :new_existing => :get, :add_existing => :post, :render_field => :get}, :member => {:row => :get, :nested => :get, :edit_associated => :get, :add_association => :get, :update_column => :post, :destroy_existing => :delete, :render_field => :get, :delete => :get} } From 7ef49474bb05db5e57153bac6bcc1717eb964bc9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 26 Feb 2010 11:11:50 +0100 Subject: [PATCH 0202/2024] Fix autoloading of ActiveScaffold::Config::Form --- lib/active_scaffold/config/core.rb | 1 - lib/active_scaffold/config/create.rb | 2 +- lib/active_scaffold/config/update.rb | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index efabc59b69..8e08888289 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -1,4 +1,3 @@ -require 'active_scaffold/config/base' module ActiveScaffold::Config class Core < Base # global level configuration diff --git a/lib/active_scaffold/config/create.rb b/lib/active_scaffold/config/create.rb index 76b6671937..f76d7d5786 100644 --- a/lib/active_scaffold/config/create.rb +++ b/lib/active_scaffold/config/create.rb @@ -1,5 +1,5 @@ module ActiveScaffold::Config - class Create < Form + class Create < ActiveScaffold::Config::Form self.crud_type = :create def initialize(*args) super diff --git a/lib/active_scaffold/config/update.rb b/lib/active_scaffold/config/update.rb index f75f1a802d..aa40806f48 100644 --- a/lib/active_scaffold/config/update.rb +++ b/lib/active_scaffold/config/update.rb @@ -1,5 +1,5 @@ module ActiveScaffold::Config - class Update < Form + class Update < ActiveScaffold::Config::Form self.crud_type = :update def initialize(*args) super From 262225a04cec71d4506fff12f87640f82c4c4bac Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 2 Mar 2010 09:44:20 +0100 Subject: [PATCH 0203/2024] Fix nested scaffolds broken in dd2f2c8 --- lib/active_scaffold/actions/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 7dbbd78e16..a4f2ff61ff 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -10,7 +10,7 @@ def index def table do_list - render(:action => 'list', :layout => false) + render(:action => 'list.html', :layout => false) end # get just a single row From 91616ee4ee72f92287a2b2a4d6bcb25f65a44a14 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 2 Mar 2010 09:53:29 +0100 Subject: [PATCH 0204/2024] Fix closing previous adapter without reloading row --- frontends/default/javascripts/active_scaffold.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index d71d5b2122..48bc774a6a 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -335,7 +335,10 @@ ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, { ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstract, { close_previous_adapter: function() { this.set.links.each(function(item) { - if (item.url != this.url && item.is_disabled() && item.adapter) item.close(); + if (item.url != this.url && item.is_disabled() && item.adapter) { + item.enable(); + item.adapter.remove(); + } }.bind(this)); }, From 91c8911a0b11d767b2b63a582e619e52b93b1960 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 2 Mar 2010 14:50:20 +0100 Subject: [PATCH 0205/2024] Fix inplace edit for plural associations --- .../default/javascripts/active_scaffold.js | 28 +++++++++++++------ .../helpers/list_column_helpers.rb | 3 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 48bc774a6a..09e0e80311 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -434,18 +434,28 @@ ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstrac ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { setFieldFromAjax: function(url, options) { - $(this._controls.editor).remove(); + var ipe = this; + $(ipe._controls.editor).remove(); new Ajax.Request(url, { method: 'get', onComplete: function(response) { - this._form.insert({top: response.responseText}); - var fld = this._form.findFirstElement(); - fld.name = this.options.paramName; - fld.className = 'editor_field'; - if (this.options.submitOnBlur) - fld.onblur = this._boundSubmitHandler; - this._controls.editor = fld; - }.bind(this) + ipe._form.insert({top: response.responseText}); + if (options.plural) { + ipe._form.getElements().each(function(el) { + if (el.type != "submit" && el.type != "image") { + el.name = ipe.options.paramName + '[]'; + el.className = 'editor_field'; + } + }); + } else { + var fld = ipe._form.findFirstElement(); + fld.name = ipe.options.paramName; + fld.className = 'editor_field'; + if (ipe.options.submitOnBlur) + fld.onblur = ipe._boundSubmitHandler; + ipe._controls.editor = fld; + } + } }); }, diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 1c1dd4cba4..046b238e29 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -269,7 +269,8 @@ def active_scaffold_inplace_edit(record, column) ) elsif column.inplace_edit == :ajax url = url_for(:action => 'render_field', :id => record.id, :column => column.name, :update_column => column.name, :in_place_editing => true, :escape => false) - in_place_editor_options[:form_customization] = "element.setFieldFromAjax('#{escape_javascript(url)}');" + plural = column.plural_association? && !override_form_field?(column) && column.form_ui == :select + in_place_editor_options[:form_customization] = "element.setFieldFromAjax('#{escape_javascript(url)}', {plural: #{plural}});" elsif column.column.try(:type) == :text in_place_editor_options[:rows] = column.options[:rows] || 5 end From 7fded67fd6461f5b8561b72c01e58db98b5c6d40 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Mar 2010 17:29:43 +0100 Subject: [PATCH 0206/2024] Fix for IE6 --- frontends/default/javascripts/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 09e0e80311..97552d4486 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -429,7 +429,7 @@ ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstrac this.register_cancel_hooks(); new Effect.Highlight(this.adapter.down('td').down()); - }, + } }); ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { From 5c2d18d4ac57c7a4462fc444836003ebcf938b9c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 4 Mar 2010 17:49:38 +0100 Subject: [PATCH 0207/2024] Fix in-place editing with record_select for plural associations --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 046b238e29..296ffd77f0 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -269,7 +269,7 @@ def active_scaffold_inplace_edit(record, column) ) elsif column.inplace_edit == :ajax url = url_for(:action => 'render_field', :id => record.id, :column => column.name, :update_column => column.name, :in_place_editing => true, :escape => false) - plural = column.plural_association? && !override_form_field?(column) && column.form_ui == :select + plural = column.plural_association? && !override_form_field?(column) && [:select, :record_select].include?(column.form_ui) in_place_editor_options[:form_customization] = "element.setFieldFromAjax('#{escape_javascript(url)}', {plural: #{plural}});" elsif column.column.try(:type) == :text in_place_editor_options[:rows] = column.options[:rows] || 5 From e610f17a6619ef3b8b4fbcda65eb48a604cda18a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 9 Mar 2010 10:22:50 +0100 Subject: [PATCH 0208/2024] fix multi select search for singular associations --- lib/active_scaffold/helpers/search_column_helpers.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 56c342ce59..9ae4a82126 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -56,7 +56,9 @@ def active_scaffold_search_options(column) ## def active_scaffold_search_multi_select(column, options) - associated_options = @record.send(column.association.name).collect {|r| [r.to_label, r.id]} + associated_options = @record.send(column.association.name) + associated_options = [associated_options].compact unless associated_options.is_a? Array + associated_options.collect! {|r| [r.to_label, r.id]} select_options = associated_options | options_for_association(column.association, true) return as_(:no_options) if select_options.empty? From 79daab011b929b98ba5e6d53ab49b44ee6bbc5e0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 9 Mar 2010 10:47:06 +0100 Subject: [PATCH 0209/2024] Show HABTM associations in subform, :select form_ui works --- lib/active_scaffold/helpers/view_helpers.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index dcfb6dd310..47c91c8a67 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -54,12 +54,8 @@ def in_subform?(column, parent_record) # Polymorphic associations can't appear because they *might* be the reverse association, and because you generally don't assign an association from the polymorphic side ... I think. return false if column.polymorphic_association? - # We don't have the UI to currently handle habtm in subforms - return false if column.association.macro == :has_and_belongs_to_many - # A column shouldn't be in the subform if it's the reverse association to the parent return false if column.association.reverse_for?(parent_record.class) - #return false if column.association.klass == parent_record.class return true end From 6b07b591267520465eb55512562280abe7c961d8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 9 Mar 2010 17:44:07 +0100 Subject: [PATCH 0210/2024] Move validation reflection code to a bridge --- lib/active_scaffold/data_structures/column.rb | 12 +---------- lib/bridges/validation_reflection/bridge.rb | 8 +++++++ .../lib/validation_reflection_bridge.rb | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 lib/bridges/validation_reflection/bridge.rb create mode 100644 lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index dd7e1c64a8..ffaa427aca 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -255,17 +255,7 @@ def initialize(name, active_record_class) #:nodoc: # default all the configurable variables self.css_class = '' - if active_record_class.respond_to? :reflect_on_validations_for - column_names = [name] - column_names << @association.primary_key_name if @association - self.required = column_names.any? do |column_name| - active_record_class.reflect_on_validations_for(column_name.to_sym).any? do |val| - val.macro == :validates_presence_of or (val.macro == :validates_inclusion_of and not val.options[:allow_nil] and not val.options[:allow_blank]) - end - end - else - self.required = false - end + self.required = false self.sort = true self.search_sql = true diff --git a/lib/bridges/validation_reflection/bridge.rb b/lib/bridges/validation_reflection/bridge.rb new file mode 100644 index 0000000000..d563aca51a --- /dev/null +++ b/lib/bridges/validation_reflection/bridge.rb @@ -0,0 +1,8 @@ +ActiveScaffold.bridge "ValidationReflection" do + install do + require File.join(File.dirname(__FILE__), "lib/validation_reflection_bridge.rb") + end + install? do + ActiveRecord::Base.respond_to? :reflect_on_validations_for + end +end diff --git a/lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb b/lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb new file mode 100644 index 0000000000..777ddcdb38 --- /dev/null +++ b/lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb @@ -0,0 +1,21 @@ +module ActiveScaffold + module ValidationReflectionBridge + def self.included(base) + base.class_eval { alias_method_chain :initialize, :validation_reflection } + end + + def initialize_with_validation_reflection(name, active_record_class) + initialize_without_validation_reflection(name, active_record_class) + column_names = [name] + column_names << @association.primary_key_name if @association + self.required = column_names.any? do |column_name| + active_record_class.reflect_on_validations_for(column_name.to_sym).any? do |val| + val.macro == :validates_presence_of or (val.macro == :validates_inclusion_of and not val.options[:allow_nil] and not val.options[:allow_blank]) + end + end + end + end +end +ActiveScaffold::DataStructures::Column.class_eval do + include ActiveScaffold::ValidationReflectionBridge +end From 8810546f4741adf64d89cb1b1002f99fcf8f0ca1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 9 Mar 2010 18:24:03 +0100 Subject: [PATCH 0211/2024] Remove deprecated code --- README | 5 ++-- lib/active_record_permissions.rb | 18 ------------ lib/active_scaffold/actions/core.rb | 4 --- lib/active_scaffold/config/field_search.rb | 16 ----------- lib/active_scaffold/config/list.rb | 8 ------ lib/active_scaffold/config/live_search.rb | 16 ----------- lib/active_scaffold/config/search.rb | 16 ----------- .../data_structures/action_link.rb | 11 -------- lib/active_scaffold/data_structures/column.rb | 7 ----- lib/active_scaffold/finder.rb | 28 ------------------- .../helpers/form_column_helpers.rb | 17 +++-------- 11 files changed, 7 insertions(+), 139 deletions(-) diff --git a/README b/README index 5a7ad8f42e..f30d06d384 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ ** For all documentation see the project website: http://www.ActiveScaffold.com ** ********************************************************************************** -ActiveScaffold plugin by Scott Rutherford (scott@caronsoftware.com), Richard White (rrwhite@gmail.com), Lance Ivy (lance@cainlevy.net), Ed Moss, and Tim Harper +ActiveScaffold plugin by Scott Rutherford (scott@caronsoftware.com), Richard White (rrwhite@gmail.com), Lance Ivy (lance@cainlevy.net), Ed Moss, Tim Harper and Sergio Cambra (sergio@entrecables.com) Uses DhtmlHistory by Brad Neuberg (bkn3@columbia.edu) http://codinginparadise.org @@ -20,7 +20,8 @@ http://code.google.com/p/recordselect/ Please note the following list of Active Scaffold branches and Rails versions. Master will not work with Rails < 2.2 -Rails master (edge): Active Scaffold master +Active Scaffold master currently supports rails-2.3.5, but incompatible changes can be introduced, if you want an stable version, use rails-2.3 +Rails 2.3.*: Active Scaffold rails-2.3 Rails 2.2.*: Active Scaffold rails-2.2 Rails 2.1.*: Active Scaffold rails-2.1 Rails < 2.1: Active Scaffold 1-1-stable (no guarantees) diff --git a/lib/active_record_permissions.rb b/lib/active_record_permissions.rb index 47d99c1019..6b2f937938 100644 --- a/lib/active_record_permissions.rb +++ b/lib/active_record_permissions.rb @@ -79,15 +79,6 @@ def authorized_for?(options = {}) # (for example, disable update and enable inplace_edit in a column) method = column_and_action_security_method(options[:column], options[:action]) return send(method) if method and respond_to?(method) - # code for deprecation - if options[:action] == :delete - good_method = method - method = column_and_action_security_method(options[:column], :destroy) - if method and respond_to?(method) - ::ActiveSupport::Deprecation.warn("destroy crud type is deprecated, rename #{method} to #{good_method}", caller) - return send(method) - end - end # collect the possibly-related methods that actually exist methods = [ @@ -95,15 +86,6 @@ def authorized_for?(options = {}) action_security_method(options[:action]), ].compact.select {|m| respond_to?(m)} - # code for deprecation - if options[:action] == :delete - method = action_security_method(:destroy) - if respond_to?(method) - ::ActiveSupport::Deprecation.warn("destroy crud type is deprecated, rename #{method} to #{action_security_method(options[:action])}", caller) - methods << method - end - end - # if any method returns false, then return false return false if methods.any? {|m| !send(m)} diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index b6e094c291..b8203afe18 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -107,10 +107,6 @@ def custom_finder_options #Overide this method on your controller to provide model with named scopes def beginning_of_chain - if respond_to? :named_scopes_for_collection - ::ActiveSupport::Deprecation.warn(":named_scope_for_collection is deprecated, override beginning_of_chain instead", caller) - return model_with_named_scope - end active_scaffold_config.model end diff --git a/lib/active_scaffold/config/field_search.rb b/lib/active_scaffold/config/field_search.rb index a0cfda9869..b5a6ba9757 100644 --- a/lib/active_scaffold/config/field_search.rb +++ b/lib/active_scaffold/config/field_search.rb @@ -18,14 +18,6 @@ def initialize(core_config) cattr_reader :link @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) - def self.full_text_search=(value) - ::ActiveSupport::Deprecation.warn("full_text_search is deprecated, use text_search = :full instead", caller) - @@text_search = :full - end - def self.full_text_search? - ::ActiveSupport::Deprecation.warn("full_text_search? is deprecated, use text_search == :full instead", caller) - @@text_search == :full - end cattr_accessor :text_search @@text_search = :full @@ -45,14 +37,6 @@ def columns public :columns= attr_accessor :text_search - def full_text_search=(value) - ::ActiveSupport::Deprecation.warn("full_text_search is deprecated, use text_search = :full instead", caller) - @text_search = :full - end - def full_text_search? - ::ActiveSupport::Deprecation.warn("full_text_search? is deprecated, use text_search == :full instead", caller) - @text_search == :full - end # the ActionLink for this action attr_accessor :link diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 03f08c9420..8253b1926d 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -39,10 +39,6 @@ def initialize(core_config) # * false: Disable pagination cattr_accessor :pagination @@pagination = true - def self.infinite_pagination=(value) - ::ActiveSupport::Deprecation.warn("infinite_pagination is deprecated, use pagination = :infinite instead", caller) - self.pagination = :infinite - end # instance-level configuration # ---------------------------- @@ -66,10 +62,6 @@ def columns # * :infinite: Treat the source as having an infinite number of pages (i.e. don't count the records; useful for large tables where counting is slow and we don't really care anyway) # * false: Disable pagination attr_accessor :pagination - def infinite_pagination=(value) - ::ActiveSupport::Deprecation.warn("infinite_pagination is deprecated, use pagination = :infinite instead", caller) - self.pagination = :infinite - end # what string to use when a field is empty attr_accessor :empty_field_text diff --git a/lib/active_scaffold/config/live_search.rb b/lib/active_scaffold/config/live_search.rb index 985b71c78f..3f113222a0 100644 --- a/lib/active_scaffold/config/live_search.rb +++ b/lib/active_scaffold/config/live_search.rb @@ -18,14 +18,6 @@ def initialize(core_config) cattr_accessor :link @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) - def self.full_text_search=(value) - ::ActiveSupport::Deprecation.warn("full_text_search is deprecated, use text_search = :full instead", caller) - @@text_search = :full - end - def self.full_text_search? - ::ActiveSupport::Deprecation.warn("full_text_search? is deprecated, use text_search == :full instead", caller) - @@text_search == :full - end cattr_accessor :text_search @@text_search = :full @@ -44,14 +36,6 @@ def columns public :columns= attr_accessor :text_search - def full_text_search=(value) - ::ActiveSupport::Deprecation.warn("full_text_search is deprecated, use text_search = :full instead", caller) - @text_search = :full - end - def full_text_search? - ::ActiveSupport::Deprecation.warn("full_text_search? is deprecated, use text_search == :full instead", caller) - @text_search == :full - end # the ActionLink for this action attr_accessor :link diff --git a/lib/active_scaffold/config/search.rb b/lib/active_scaffold/config/search.rb index 77db55a8bf..161eef6cea 100644 --- a/lib/active_scaffold/config/search.rb +++ b/lib/active_scaffold/config/search.rb @@ -18,14 +18,6 @@ def initialize(core_config) cattr_accessor :link @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) - def self.full_text_search=(value) - ::ActiveSupport::Deprecation.warn("full_text_search is deprecated, use text_search = :full instead", caller) - @@text_search = :full - end - def self.full_text_search? - ::ActiveSupport::Deprecation.warn("full_text_search? is deprecated, use text_search == :full instead", caller) - @@text_search == :full - end cattr_accessor :text_search @@text_search = :full @@ -44,14 +36,6 @@ def columns public :columns= attr_accessor :text_search - def full_text_search=(value) - ::ActiveSupport::Deprecation.warn("full_text_search is deprecated, use text_search = :full instead", caller) - @text_search = :full - end - def full_text_search? - ::ActiveSupport::Deprecation.warn("full_text_search? is deprecated, use text_search == :full instead", caller) - @text_search == :full - end # the ActionLink for this action attr_accessor :link diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 96b49a2ec0..0ba5f89752 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -134,17 +134,6 @@ def position # what type of link this is. currently supported values are :collection and :member. attr_accessor :type - # deprecated - def type=(value) - old_value = value - value = case value - when :table then :collection - when :record then :member - else value - end - ::ActiveSupport::Deprecation.warn(":#{old_value} is deprecated, use :#{value} instead", caller) if old_value != value - @type = value - end # html options for the link attr_accessor :html_options diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index ffaa427aca..4c803fcdbb 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -96,13 +96,6 @@ def search_ui @search_ui || @form_ui end - # DEPRECATED - alias :ui_type :form_ui - def ui_type=(val) - ::ActiveSupport::Deprecation.warn("config.columns[:#{name}].ui_type will disappear in version 2.0. Please use config.columns[:#{name}].form_ui instead.", caller) - self.form_ui = val - end - # a place to store dev's column specific options attr_accessor :options def options diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 0ce1af8c5a..1fdf676c96 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -120,19 +120,9 @@ def active_scaffold_conditions attr_writer :active_scaffold_includes def active_scaffold_includes - if respond_to? :active_scaffold_joins - ::ActiveSupport::Deprecation.warn("You have defined active_scaffold_joins, but it's deprecated because it's confusing, you should use active_scaffold_includes now", caller) - return active_scaffold_joins - end @active_scaffold_includes ||= [] end - # Deprecated method - def active_scaffold_joins=(value) - ::ActiveSupport::Deprecation.warn("active_scaffold_joins is deprecated because it's confusing, you should use active_scaffold_includes now", caller) - self.active_scaffold_includes = value - end - attr_writer :active_scaffold_habtm_joins def active_scaffold_habtm_joins @active_scaffold_habtm_joins ||= [] @@ -148,24 +138,6 @@ def all_conditions ) end - # Deprecated - def model_with_named_scope(model = active_scaffold_config.model, scope_definitions = named_scopes_for_collection) - case scope_definitions - when String - model.instance_eval(scope_definitions) - when Symbol - model.send(scope_definitions) - when Array - if scope_definitions.any?{|element| element.is_a?(Array)} - scope_definitions.inject(model) {|records, scope_definition| records = model_with_named_scope(records, scope_definition)} - else - model.send(*scope_definitions) - end - else - model - end - end - # returns a single record (the given id) but only if it's allowed for the specified action. # accomplishes this by checking model.#{action}_authorized? # TODO: this should reside on the model, not the controller diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 8a06b00643..23c18088af 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -62,7 +62,7 @@ def active_scaffold_input_options(column, scope = nil) end def javascript_for_update_column(column, scope, options) - if column.options.is_a?(Hash) && column.options[:update_column] + if column.options[:update_column] form_action = :create form_action = :update if params[:action] == 'edit' url_params = {:action => 'render_field', :id => params[:id], :column => column.name, :update_column => column.options[:update_column]} @@ -95,10 +95,6 @@ def active_scaffold_input_singular_association(column, html_options) html_options.update(column.options[:html_options] || {}) options.update(column.options) - unless column.options[:html_options] || column.options.empty? - Rails.logger.warn "ActiveScaffold: Setting html options directly in a hash is deprecated for :select form_ui. Set the html options hash under html_options key, such as config.columns[:column_name].options = {:html_options => {...}, ...}" - html_options.update(column.options) - end select(:record, method, select_options.uniq, options, html_options) end @@ -134,14 +130,9 @@ def active_scaffold_input_select(column, html_options) active_scaffold_input_plural_association(column, html_options) else options = { :selected => @record.send(column.name) } - if column.options.is_a? Hash - options_for_select = column.options[:options] - html_options.update(column.options[:html_options] || {}) - options.update(column.options) - else - Rails.logger.warn "ActiveScaffold: Setting the options array directly is deprecated for :select form_ui. Set the options array in a hash under options key, such as config.columns[:column_name].options = {:options => [...], ...}" - options_for_select = column.options - end + options_for_select = column.options[:options] + html_options.update(column.options[:html_options] || {}) + options.update(column.options) select(:record, column.name, options_for_select, options, html_options) end end From a38a5a6430f10808735b7221b3a7db217b436b6a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 10 Mar 2010 09:54:34 +0100 Subject: [PATCH 0212/2024] fix javascript syntax --- frontends/default/views/list.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/list.html.erb b/frontends/default/views/list.html.erb index 409f010746..4edbcbad44 100644 --- a/frontends/default/views/list.html.erb +++ b/frontends/default/views/list.html.erb @@ -37,7 +37,7 @@ Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-header').first(), {color: 'fromElement', bgColor: 'fromParent', corners: 'top', compact: true}); Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-footer').first(), {color: 'fromElement', bgColor: 'fromParent', corners: 'bottom', compact: true}); <% end -%> -new ActiveScaffold.Actions.Table($$('#<%= active_scaffold_id -%> div.active-scaffold-header a.action'), $('<%= before_header_id -%>'), $('<%= loading_indicator_id(:action => :table) -%>')) +new ActiveScaffold.Actions.Table($$('#<%= active_scaffold_id -%> div.active-scaffold-header a.action'), $('<%= before_header_id -%>'), $('<%= loading_indicator_id(:action => :table) -%>')); ActiveScaffold.server_error_response = '<p class="error-message message">' + <%= as_(:internal_error).to_json %> + '<a href="#" onclick="Element.remove(this.parentNode); return false;">' From 2a3e4eff182d593e11207f0364bfcd698b55cd25 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 10 Mar 2010 11:11:25 +0100 Subject: [PATCH 0213/2024] Default search_ui to :select for columns with association which has no search_ui or form_ui --- lib/active_scaffold/data_structures/column.rb | 3 +- test/data_structures/column_test.rb | 25 ++++++++++++ .../default/active_scaffold.js | 38 ++++++++++++------- .../active_scaffold/default/dhtml_history.js | 2 +- 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index cf9afbe01c..3c3f9522ec 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -93,7 +93,7 @@ def list_ui attr_writer :search_ui def search_ui - @search_ui || @form_ui + @search_ui || @form_ui || (@association && !polymorphic_association? ? :select : nil) end # a place to store dev's column specific options @@ -243,7 +243,6 @@ def initialize(name, active_record_class) #:nodoc: @associated_number = self.class.associated_number @show_blank_record = self.class.show_blank_record @actions_for_association_links = self.class.actions_for_association_links.clone if @association - @search_ui = :select if @association and not polymorphic_association? @options = {:format => :i18n_number} if @column.try(:number?) # default all the configurable variables diff --git a/test/data_structures/column_test.rb b/test/data_structures/column_test.rb index 0efa7f13ac..04dd1dc857 100644 --- a/test/data_structures/column_test.rb +++ b/test/data_structures/column_test.rb @@ -3,6 +3,9 @@ class ColumnTest < Test::Unit::TestCase def setup @column = ActiveScaffold::DataStructures::Column.new(:a, ModelStub) + @association_col = ActiveScaffold::DataStructures::Column.new(:b, ModelStub) + @association_col.stubs(:polymorphic_association?).returns(false) + @association_col.instance_variable_set(:@association, true) end def test_column @@ -80,6 +83,28 @@ def test_equality assert @column != 0 end + def test_ui + assert_nil @column.form_ui + assert_nil @column.list_ui + assert_nil @column.search_ui + assert_equal :select, @association_col.search_ui + + @column.form_ui = :calendar + assert_equal :calendar, @column.form_ui + assert_equal :calendar, @column.list_ui + assert_equal :calendar, @column.search_ui + + @association_col.form_ui = :record_select + assert_equal :record_select, @association_col.form_ui + assert_equal :record_select, @association_col.search_ui + + @column.search_ui = :record_select + @column.list_ui = :checkbox + assert_equal :calendar, @column.form_ui + assert_equal :checkbox, @column.list_ui + assert_equal :record_select, @column.search_ui + end + def test_searchable @column.search_sql = nil assert !@column.searchable? diff --git a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js index 05511778c4..97552d4486 100644 --- a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +++ b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js @@ -48,9 +48,8 @@ var ActiveScaffold = { } }, reload_if_empty: function(tbody, url) { - var content_container_id = tbody.replace('tbody', 'content'); if (this.records_for(tbody).length == 0) { - new Ajax.Updater($(content_container_id), url, { + new Ajax.Request(url, { method: 'get', asynchronous: true, evalScripts: true @@ -336,7 +335,10 @@ ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, { ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstract, { close_previous_adapter: function() { this.set.links.each(function(item) { - if (item.url != this.url && item.is_disabled() && item.adapter) item.close(); + if (item.url != this.url && item.is_disabled() && item.adapter) { + item.enable(); + item.adapter.remove(); + } }.bind(this)); }, @@ -427,23 +429,33 @@ ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstrac this.register_cancel_hooks(); new Effect.Highlight(this.adapter.down('td').down()); - }, + } }); ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { setFieldFromAjax: function(url, options) { - $(this._controls.editor).remove(); + var ipe = this; + $(ipe._controls.editor).remove(); new Ajax.Request(url, { method: 'get', onComplete: function(response) { - this._form.insert({top: response.responseText}); - var fld = this._form.findFirstElement(); - fld.name = this.options.paramName; - fld.className = 'editor_field'; - if (this.options.submitOnBlur) - fld.onblur = this._boundSubmitHandler; - this._controls.editor = fld; - }.bind(this) + ipe._form.insert({top: response.responseText}); + if (options.plural) { + ipe._form.getElements().each(function(el) { + if (el.type != "submit" && el.type != "image") { + el.name = ipe.options.paramName + '[]'; + el.className = 'editor_field'; + } + }); + } else { + var fld = ipe._form.findFirstElement(); + fld.name = ipe.options.paramName; + fld.className = 'editor_field'; + if (ipe.options.submitOnBlur) + fld.onblur = ipe._boundSubmitHandler; + ipe._controls.editor = fld; + } + } }); }, diff --git a/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js b/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js index 161417e2e3..3bf6275c48 100755 --- a/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +++ b/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js @@ -858,7 +858,7 @@ var handleHistoryChange = function(pageId, pageData) { var info = pageId.split(':'); var id = info[0]; pageData += '&_method=get'; - new Ajax.Updater(id+'-content', pageData, {asynchronous:true, evalScripts:true, method: 'get', onLoading:function(request){Element.show(id+'-pagination-loading-indicator');}}); + new Ajax.Request(pageData, {asynchronous:true, evalScripts:true, method: 'get', onLoading:function(request){Element.show(id+'-pagination-loading-indicator');}}); } window.onload = function() { From 0cc9ae5243797e4aff71aea430176dae70ad9d17 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 10 Mar 2010 17:37:14 +0100 Subject: [PATCH 0214/2024] Allow to override security_method and position in nested.add_link --- lib/active_scaffold/config/nested.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index 6401337978..fdcec851e9 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -18,7 +18,8 @@ def initialize(core_config) # Add a nested ActionLink def add_link(label, models, options = {}) - options.merge! :label => label, :type => :member, :security_method => :nested_authorized?, :position => :after, :parameters => {:associations => models.join(' ')} + options.reverse_merge! :security_method => :nested_authorized?, :position => :after + options.merge! :label => label, :type => :member, :parameters => {:associations => models.join(' ')} options[:html_options] ||= {} options[:html_options][:class] = [options[:html_options][:class], models.join(' ')].compact.join(' ') @core.action_links.add('nested', options) From f3c68c10545f2a5e17940beb2d9f7e02a1b4dfe6 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 09:39:16 +0100 Subject: [PATCH 0215/2024] Fix reset search in IE --- frontends/default/views/_field_search.html.erb | 2 +- frontends/default/views/_live_search.html.erb | 2 +- frontends/default/views/_search.html.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_field_search.html.erb b/frontends/default/views/_field_search.html.erb index cc684c1e27..91c94a72ea 100644 --- a/frontends/default/views/_field_search.html.erb +++ b/frontends/default/views/_field_search.html.erb @@ -32,7 +32,7 @@ href = url_for(params_for(:action => :index, :escape => false).delete_if{|k,v| k </ol> <p class="form-footer"> <%= submit_tag as_(:search), :class => "submit" %> - <a href="javascript:void(0)" class="cancel" onclick="f = this.up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> + <a href="javascript:void(0)" class="cancel" onclick="f = $(this).up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> <%= loading_indicator_tag(:action => :search) %> </p> </form> diff --git a/frontends/default/views/_live_search.html.erb b/frontends/default/views/_live_search.html.erb index 3ef048cb9f..22a7f8ba1a 100644 --- a/frontends/default/views/_live_search.html.erb +++ b/frontends/default/views/_live_search.html.erb @@ -7,7 +7,7 @@ :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> <%= text_field_tag :search, params[:search], :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> - <a href="javascript:void(0)" class="cancel" onclick="f = this.up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> + <a href="javascript:void(0)" class="cancel" onclick="f = $(this).up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> <%= loading_indicator_tag(:action => :search) %> </form> diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index c14cd51bb0..fdacfe57a6 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -8,7 +8,7 @@ :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> <%= text_field_tag :search, params[:search], :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> <%= submit_tag as_(:search), :class => "submit" %> - <a href="javascript:void(0)" class="cancel" onclick="f = this.up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> + <a href="javascript:void(0)" class="cancel" onclick="f = $(this).up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> <%= loading_indicator_tag(:action => :search) %> </form> From 22cd968c47c3317f6ab6cc175a5753fd17091436 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 10:57:15 +0100 Subject: [PATCH 0216/2024] Copy from edwinmoss Improve css of nested views --- frontends/default/stylesheets/stylesheet.css | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index e1f880c040..a05af1b6a8 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -327,6 +327,12 @@ color: #06c; background-color: #ff8; } +.active-scaffold .active-scaffold .view { +background-color: transparent; +padding: 0px; +border: none; +} + .active-scaffold .active-scaffold td { background-color: #ECFFE7; border-bottom: solid 1px #CDF7C5; @@ -340,6 +346,13 @@ border: solid 1px #DDDF37; border-top: none; } +.active-scaffold .active-scaffold .active-scaffold td.inline-adapter-cell { +background-color: #DAFFCD; +padding: 4px; +border: solid 1px #7FcF00; +border-top: none; +} + .active-scaffold .active-scaffold .active-scaffold-footer { font-size: 11px; } @@ -824,3 +837,14 @@ font-size: 100%; .active-scaffold-found { float:left; } + +.active-scaffold .view .warning-message { + border-left: solid 1px #ff6; + background-color: #ffb; + margin: 0; +} +.active-scaffold .view .info-message { + border: solid 1px #66f; + background-color: #bbf; + margin: 0; +} From d32997fd6f1c88a732ce7dcf401a153bb21c94ce Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 11:44:09 +0100 Subject: [PATCH 0217/2024] Copy from edwinmoss Integrate record select with add existing --- .../default/views/_add_existing_form.html.erb | 8 ++----- .../helpers/form_column_helpers.rb | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/frontends/default/views/_add_existing_form.html.erb b/frontends/default/views/_add_existing_form.html.erb index 94c21135b6..41e4b3ff74 100644 --- a/frontends/default/views/_add_existing_form.html.erb +++ b/frontends/default/views/_add_existing_form.html.erb @@ -21,12 +21,8 @@ <%= render :partial => 'form_messages' %> <% end -%> - <label for="<%= "record_#{active_scaffold_config.model}" %>"><%= active_scaffold_config.model.human_name %></label> - <%# select_options = options_for_select(options_for_association(nested_association)) unless column.through_association? -%> - <% select_options ||= options_for_select(active_scaffold_config.model.find(:all).collect {|c| [h(c.to_label), c.id]}) -%> - <% unless select_options.empty? -%> - <%= select_tag 'associated_id', '<option value="">' + as_(:_select_) + '</option>' + select_options %> - <% end -%> + <label for="<%= "record_#{active_scaffold_config.model}" %>"><%= active_scaffold_add_existing_label %></label> + <%= active_scaffold_add_existing_input(:name => 'associated_id', :url_options => url_options) %> <p class="form-footer"> <%= submit_tag as_(:add), :class => "submit" %> diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 23c18088af..a3e52b4fdd 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -299,6 +299,28 @@ def column_scope(column) "[#{column.name}]" end end + + def active_scaffold_add_existing_input(options) + if controller.respond_to?(:record_select_config) + remote_controller = active_scaffold_controller_for(record_select_config.model).controller_path + options.merge!(:controller => remote_controller) + options.merge!(active_scaffold_input_text_options) + record_select_field(options[:name], @record, options) + else + column = active_scaffold_config_for(params[:parent_model]).columns[params[:parent_column]] + select_options = options_for_select(options_for_association(column.association)) unless column.through_association? + select_options ||= options_for_select(active_scaffold_config.model.find(:all).collect {|c| [h(c.to_label), c.id]}) + select_tag 'associated_id', '<option value="">' + as_(:_select_) + '</option>' + select_options unless select_options.empty? + end + end + + def active_scaffold_add_existing_label + if controller.respond_to?(:record_select_config) + record_select_config.model.human_name + else + active_scaffold_config.model.human_name + end + end end end end From 2131569976a65e2e6c0393bc7258888d97bbb951 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 12:00:23 +0100 Subject: [PATCH 0218/2024] Copy from edwinmoss Add model to create another string --- frontends/default/views/_form_association_footer.html.erb | 2 +- lib/active_scaffold/locale/en.rb | 2 +- lib/active_scaffold/locale/es.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index dfb4b8cf53..c92f3d4642 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -19,7 +19,7 @@ return unless show_add_new or show_add_existing <div class="footer-wrapper"> <div class="footer"> <% if show_add_new -%> - <% add_label = column.plural_association? ? as_(:create_another) : as_(:replace_with_new) -%> + <% add_label = column.plural_association? ? as_(:create_another, :model => column.association.klass.human_name) : as_(:replace_with_new) -%> <%= button_to_function add_label, "new Ajax.Request(#{add_new_url.to_json}, {asynchronous: true, method: 'get', evalScripts: true, onFailure: function(){ActiveScaffold.report_500_response(#{active_scaffold_id.to_json})}})" %> <% end -%> diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 697fd91386..f5d6951b50 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -10,7 +10,7 @@ :close => 'Close', :create => 'Create', :create_model => 'Create {{model}}', - :create_another => 'Create Another', + :create_another => 'Create Another {{model}}', :created_model => 'Created {{model}}', :create_new => 'Create New', :customize => 'Customize', diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index d30be81dd1..2bcd60dbb7 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -9,7 +9,7 @@ es: close: 'Cerrar' create: 'Crear' create_model: 'Crear {{model}}' - create_another: 'Crear Otro' + create_another: 'Crear Otro {{model}}' created_model: '{{model}} creado' create_new: 'Crear Nuevo' customize: 'Personalizar' From 4f040bdb514cdaa0d2e30859e6d95c48b5336deb Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 12:09:16 +0100 Subject: [PATCH 0219/2024] Copy from edwinmoss Column#allow_add_existing (Disable add existing controls on subform) --- .../default/views/_form_association_footer.html.erb | 12 +++++------- lib/active_scaffold/data_structures/column.rb | 4 ++++ lib/active_scaffold/helpers/view_helpers.rb | 10 ++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index c92f3d4642..07824a1902 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -5,16 +5,14 @@ rescue ActiveScaffold::ControllerNotFound remote_controller = nil end -show_add_existing = (!column.through_association? and options_for_association_count(column.association) > 0) - -show_add_new = !column.through_association? and (column.plural_association? or (column.singular_association? and not associated.empty?)) -show_add_new = false unless @record.class.authorized_for?(:crud_type => :create) - -edit_associated_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :associated_id => '--ID--', :escape => false, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) -add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :escape => false, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]); +show_add_existing = column_show_add_existing(column) +show_add_new = column_show_add_new(column, associated, @record) return unless show_add_new or show_add_existing +edit_associated_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :associated_id => '--ID--', :escape => false, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_existing +add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :escape => false, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_new + -%> <div class="footer-wrapper"> <div class="footer"> diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 3c3f9522ec..860758cc83 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -16,6 +16,10 @@ def inplace_edit=(value) # Whether this column set is collapsed by default in contexts where collapsing is supported attr_accessor :collapsed + + # Whether to enable add_existing for this column + attr_accessor :allow_add_existing + @allow_add_existing = true # Any extra parameters this particular column uses. This is for create/update purposes. def params diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 47c91c8a67..efbf084258 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -193,6 +193,16 @@ def column_calculation(column) calculation = active_scaffold_config.model.calculate(column.calculate, column.name, :conditions => controller.send(:all_conditions), :joins => controller.send(:joins_for_collection), :include => controller.send(:active_scaffold_includes)) end + + def column_show_add_existing(column) + (column.allow_add_existing and !column.through_association? and options_for_association_count(column.association) > 0) + end + + def column_show_add_new(column, associated, record) + value = !column.through_association? and (column.plural_association? or (column.singular_association? and not associated.empty?)) + value = false unless record.class.authorized_for?(:crud_type => :create) + value + end end end end From 48f96f8607c9832fd534114c7b84cd56d65fdfe7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 12:16:47 +0100 Subject: [PATCH 0220/2024] Remove unused css --- frontends/default/stylesheets/stylesheet.css | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index a05af1b6a8..b59b6a66f0 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -837,14 +837,3 @@ font-size: 100%; .active-scaffold-found { float:left; } - -.active-scaffold .view .warning-message { - border-left: solid 1px #ff6; - background-color: #ffb; - margin: 0; -} -.active-scaffold .view .info-message { - border: solid 1px #66f; - background-color: #bbf; - margin: 0; -} From bd7596dee628752390dcf8c5cee1972c9e08b84c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 12:37:47 +0100 Subject: [PATCH 0221/2024] Mark fields with error when submitting a multipart form to a iframe (for fake AJAX file uploads) --- frontends/default/views/_create_form.html.erb | 3 ++- frontends/default/views/_update_form.html.erb | 3 ++- frontends/default/views/form_messages_on_save.js.rjs | 10 ---------- frontends/default/views/on_create.js.rjs | 2 +- frontends/default/views/on_update.js.rjs | 2 +- lib/active_scaffold/actions/create.rb | 6 +----- lib/active_scaffold/actions/update.rb | 6 +----- 7 files changed, 8 insertions(+), 24 deletions(-) delete mode 100644 frontends/default/views/form_messages_on_save.js.rjs diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index ab2f5d484f..0c89d98820 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -1,6 +1,7 @@ <% url_options = params_for(:action => :create) -%> +<% xhr ||= request.xhr? -%> <%= -if request.xhr? +if xhr if active_scaffold_config.create.multipart? # file_uploads form_remote_upload_tag url_options.merge({:iframe => true}), :onsubmit => onsubmit, diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index 1163b08b35..ba248a142d 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -1,6 +1,7 @@ <% url_options = params_for(:action => :update) -%> +<% xhr ||= request.xhr? -%> <%= -if request.xhr? +if xhr if active_scaffold_config.update.multipart? # file_uploads form_remote_upload_tag url_options.merge({:iframe => true}), :onsubmit => onsubmit, diff --git a/frontends/default/views/form_messages_on_save.js.rjs b/frontends/default/views/form_messages_on_save.js.rjs deleted file mode 100644 index f577aadfc2..0000000000 --- a/frontends/default/views/form_messages_on_save.js.rjs +++ /dev/null @@ -1,10 +0,0 @@ -page.replace_html element_messages_id, :partial => 'form_messages' -active_scaffold_config.send(action_name).columns.each(:for => @record, :flatten => true) do |column| - next unless is_subform? column - associated = Array(@record.send(column.name)).compact - associated << column.association.klass.new if column.show_blank_record? associated - associated.each_with_index do |record, index| - page.replace_html element_messages_id(:action => record.class.name.underscore, :id => "#{@record.id}-#{index}"), error_messages_for(:record, :object => record, :object_name => record.class.human_name.downcase) if record.errors.count - end -end -page << "$('#{loading_indicator_id(:action => action_name, :id => params[:id])}').style.visibility = 'hidden';" diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index f464004780..bc507a18c9 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -20,7 +20,7 @@ if controller.send :successful? end else page << "l = $$(#{cancel_selector}).first().link;" - page.replace element_form_id(:action => :create), :partial => 'create_form' + page.replace element_form_id(:action => :create), :partial => 'create_form', :locals => {:xhr => true} page << "l.register_cancel_hooks();" end page.replace_html active_scaffold_messages_id, :partial => 'messages' diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index b17fa58c71..de63b3687d 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -6,7 +6,7 @@ if controller.send :successful? page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} else page << "l = $$(#{cancel_selector}).first().link;" - page.replace element_form_id(:action => :update), :partial => 'update_form' + page.replace element_form_id(:action => :update), :partial => 'update_form', :locals => {:xhr => true} page << "l.register_cancel_hooks();" end page.replace_html active_scaffold_messages_id, :partial => 'messages' diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index bd9d857c2a..15d6bf3cc2 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -39,11 +39,7 @@ def new_respond_to_js def create_respond_to_html if params[:iframe]=='true' # was this an iframe post ? responds_to_parent do - if successful? - render :action => 'on_create.js' - else - render :action => 'form_messages_on_save.js' - end + render :action => 'on_create.js' end else if successful? diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 284a9a0287..1321294d26 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -37,11 +37,7 @@ def edit_respond_to_js def update_respond_to_html if params[:iframe]=='true' # was this an iframe post ? responds_to_parent do - if successful? - render :action => 'on_update.js' - else - render :action => 'form_messages_on_save.js' - end + render :action => 'on_update.js' end else # just a regular post if successful? From 71d68d97afce3df390c844f247475117d582544e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 13:06:19 +0100 Subject: [PATCH 0222/2024] Copy from edwinmoss Add id to inline_adapter --- frontends/default/views/_list_inline_adapter.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index ab76b60de4..d302cfa9df 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -1,5 +1,6 @@ <%= update_page_tag { |page| page.replace_html active_scaffold_messages_id, :partial => 'messages' } %> -<tr class="inline-adapter"> +<%# nested_id, allows us to remove a nested scaffold programmatically %> +<tr class="inline-adapter" id="<%= element_row_id :action => :nested %>"> <td colspan="99" class="inline-adapter-cell"> <div class="<%= "#{params[:action]}-view" if params[:action] %> <%= "#{params[:associations] ? params[:associations] : params[:controller]}-view" %> view"> <a href="" class="inline-adapter-close" title="<%= as_(:close) %>"><%= as_(:close) %></a> From 4c305bc99cbc4c1bb874f28979406a5c3aa706bc Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 13:25:10 +0100 Subject: [PATCH 0223/2024] Simplify overriding layout of list --- .../default/views/_list_actions.html.erb | 18 +++++++++++- frontends/default/views/_list_record.html.erb | 28 +------------------ .../views/_list_record_columns.html.erb | 8 ++++++ 3 files changed, 26 insertions(+), 28 deletions(-) create mode 100644 frontends/default/views/_list_record_columns.html.erb diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index b2ac4c8a8c..d7a36afa40 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -1,4 +1,4 @@ -<table cellpadding="0" cellspacing="0"> +<td class="actions"><table cellpadding="0" cellspacing="0"> <tr> <td class="indicator-container"> <%= loading_indicator_tag(:action => :record, :id => record.id) %> @@ -11,3 +11,19 @@ <% end -%> </tr> </table> + +<% target_id = element_row_id(:action => :list, :id => record.id) -%> +<script type="text/javascript"> +//<![CDATA[ +new ActiveScaffold.Actions.Record( + $$('#<%= target_id -%> a.action'), + $('<%= target_id -%>'), + $('<%= loading_indicator_id(:action => :record, :id => record.id) -%>'), + {refresh_url: '<%= url_for params_for(:action => :row, :id => record.id, :_method => :get, :escape => false) -%>'} +); + <%= update_page do |page| + page.replace active_scaffold_calculations_id, :partial => 'list_calculations' + end if not dont_show_calculations and active_scaffold_config.list.columns.any? {|c| c.calculation?} %> +//]]> +</script> +</td> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 6cdf79a634..8759f60b54 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -7,31 +7,5 @@ url_options = params_for(:action => :list, :id => record.id) -%> <tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>"> - <% active_scaffold_config.list.columns.each do |column| %> - <% authorized = record.authorized_for?(:crud_type => :read, :column => column.name) -%> - <% column_value = authorized ? get_column_value(record, column) : active_scaffold_config.list.empty_field_text -%> - - <td class="<%= column_class(column, column_value) %>" > - <%= authorized ? render_list_column(column_value, column, record) : column_value %> - </td> - <% end -%> - <td class="actions"> - <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options} if active_scaffold_config.action_links.any? {|link| link.type == :member } %> - -<% target_id = element_row_id(:action => :list, :id => record.id) -%> -<script type="text/javascript"> -//<![CDATA[ -new ActiveScaffold.Actions.Record( - $$('#<%= target_id -%> a.action'), - $('<%= target_id -%>'), - $('<%= loading_indicator_id(:action => :record, :id => record.id) -%>'), - {refresh_url: '<%= url_for params_for(:action => :row, :id => record.id, :_method => :get, :escape => false) -%>'} -); - <%= update_page do |page| - page.replace active_scaffold_calculations_id, :partial => 'list_calculations' - end if not dont_show_calculations and active_scaffold_config.list.columns.any? {|c| c.calculation?} %> -//]]> -</script> - - </td> + <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options} if active_scaffold_config.action_links.any? {|link| link.type == :member } %> </tr> diff --git a/frontends/default/views/_list_record_columns.html.erb b/frontends/default/views/_list_record_columns.html.erb new file mode 100644 index 0000000000..c671178234 --- /dev/null +++ b/frontends/default/views/_list_record_columns.html.erb @@ -0,0 +1,8 @@ +<% active_scaffold_config.list.columns.each do |column| %> + <% authorized = record.authorized_for?(:crud_type => :read, :column => column.name) -%> + <% column_value = authorized ? get_column_value(record, column) : active_scaffold_config.list.empty_field_text -%> + + <td class="<%= column_class(column, column_value) %>" > + <%= authorized ? render_list_column(column_value, column, record) : column_value %> + </td> +<% end -%> From 06f96704ab62af7cdeeea0af6fba3e4015ee45c4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 13:28:06 +0100 Subject: [PATCH 0224/2024] Copy from edwinmoss Send string as parameter instead of class --- frontends/default/views/_nested.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_nested.html.erb b/frontends/default/views/_nested.html.erb index 7c2d228ae1..7922047827 100644 --- a/frontends/default/views/_nested.html.erb +++ b/frontends/default/views/_nested.html.erb @@ -36,7 +36,7 @@ :constraints => @constraints, :conditions => association.options[:conditions], :label => h(@label), - :params => {:nested => true, :parent_column => column_name, :parent_model => association.active_record} + :params => {:nested => true, :parent_column => column_name, :parent_model => association.active_record.name} ) end end From 20d78f4289b87d85783b40b929a40a27ae241c2a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 13:30:58 +0100 Subject: [PATCH 0225/2024] Copy from edwinmoss loading_indicator_id uses params[:id] --- frontends/default/views/_search.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index fdacfe57a6..8901fd4121 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -2,8 +2,8 @@ <%= form_remote_tag :url => href, :method => :get, :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", - :after => "$('#{loading_indicator_id(:action => :search)}').style.visibility = 'visible'; Form.disable('#{search_form_id}');", - :complete => "$('#{loading_indicator_id(:action => :search)}').style.visibility = 'hidden'; Form.enable('#{search_form_id}');", + :after => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{search_form_id}');", + :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{search_form_id}');", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> <%= text_field_tag :search, params[:search], :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> From 8e0ecfadd47666547ebd26f59444960c98ea2a62 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 14:11:09 +0100 Subject: [PATCH 0226/2024] Fix rendering list, was broken in a recent commit --- frontends/default/views/_list_actions.html.erb | 3 --- frontends/default/views/_list_record.html.erb | 8 ++++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index d7a36afa40..08736260a0 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -21,9 +21,6 @@ new ActiveScaffold.Actions.Record( $('<%= loading_indicator_id(:action => :record, :id => record.id) -%>'), {refresh_url: '<%= url_for params_for(:action => :row, :id => record.id, :_method => :get, :escape => false) -%>'} ); - <%= update_page do |page| - page.replace active_scaffold_calculations_id, :partial => 'list_calculations' - end if not dont_show_calculations and active_scaffold_config.list.columns.any? {|c| c.calculation?} %> //]]> </script> </td> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 8759f60b54..0fcc0404fe 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -7,5 +7,13 @@ url_options = params_for(:action => :list, :id => record.id) -%> <tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>"> + <%= render :partial => 'list_record_columns', :locals => {:record => record} %> <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options} if active_scaffold_config.action_links.any? {|link| link.type == :member } %> </tr> +<script type="text/javascript"> +//<![CDATA[ + <%= update_page do |page| + page.replace active_scaffold_calculations_id, :partial => 'list_calculations' + end if not dont_show_calculations and active_scaffold_config.list.columns.any? {|c| c.calculation?} %> +//]]> +</script> From 7fe86aaa183a40d41c40c8f09b16393cbd0b20d2 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 14:44:59 +0100 Subject: [PATCH 0227/2024] Copy from edwinmoss and improve saving search params in session and fill fields on restoring search form --- .../default/views/_field_search.html.erb | 12 +++------- frontends/default/views/_live_search.html.erb | 5 +++-- frontends/default/views/_search.html.erb | 5 +++-- lib/active_scaffold/actions/common_search.rb | 22 +++++++++++++++++++ lib/active_scaffold/actions/field_search.rb | 19 +++++++--------- lib/active_scaffold/actions/live_search.rb | 16 ++++++-------- lib/active_scaffold/actions/search.rb | 11 ++++++---- 7 files changed, 53 insertions(+), 37 deletions(-) create mode 100644 lib/active_scaffold/actions/common_search.rb diff --git a/frontends/default/views/_field_search.html.erb b/frontends/default/views/_field_search.html.erb index 91c94a72ea..7d4677c271 100644 --- a/frontends/default/views/_field_search.html.erb +++ b/frontends/default/views/_field_search.html.erb @@ -1,9 +1,4 @@ -<% -# We have to remove search form params before the url_for method call, otherwise it throughs it on -search_params = params[:search] -params.merge!(:search => nil) -href = url_for(params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'}) --%> +<% href = url_for(params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'}) -%> <%= form_remote_tag :url => href, :method => :get, :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", @@ -16,8 +11,6 @@ href = url_for(params_for(:action => :index, :escape => false).delete_if{|k,v| k <% active_scaffold_config.field_search.columns.each do |column| -%> <% next unless column.search_sql -%> <% name = "search[#{column.name}]" %> - <% value = nil %> - <% value = search_params[column.name] if search_params %> <li class="form-element"> <dl> <dt> @@ -32,7 +25,8 @@ href = url_for(params_for(:action => :index, :escape => false).delete_if{|k,v| k </ol> <p class="form-footer"> <%= submit_tag as_(:search), :class => "submit" %> - <a href="javascript:void(0)" class="cancel" onclick="f = $(this).up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> + <%= link_to_remote as_(:reset), {:url => href, :with => "'search='", :method => :get, + :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')"}, :class => 'cancel' %> <%= loading_indicator_tag(:action => :search) %> </p> </form> diff --git a/frontends/default/views/_live_search.html.erb b/frontends/default/views/_live_search.html.erb index 22a7f8ba1a..5ddb6697a9 100644 --- a/frontends/default/views/_live_search.html.erb +++ b/frontends/default/views/_live_search.html.erb @@ -6,8 +6,9 @@ :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden';", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> - <%= text_field_tag :search, params[:search], :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> - <a href="javascript:void(0)" class="cancel" onclick="f = $(this).up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> + <%= text_field_tag :search, search_params, :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> + <%= link_to_remote as_(:reset), {:url => href, :with => "'search='", :method => :get, + :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')"}, :class => 'cancel' %> <%= loading_indicator_tag(:action => :search) %> </form> diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index 8901fd4121..c0bb128dae 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -6,9 +6,10 @@ :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{search_form_id}');", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> - <%= text_field_tag :search, params[:search], :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> + <%= text_field_tag :search, search_params, :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> <%= submit_tag as_(:search), :class => "submit" %> - <a href="javascript:void(0)" class="cancel" onclick="f = $(this).up('form'); f.reset(); f.onsubmit();"><%= as_(:reset) -%></a> + <%= link_to_remote as_(:reset), {:url => href, :with => "'search='", :method => :get, + :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')"}, :class => 'cancel' %> <%= loading_indicator_tag(:action => :search) %> </form> diff --git a/lib/active_scaffold/actions/common_search.rb b/lib/active_scaffold/actions/common_search.rb new file mode 100644 index 0000000000..e95bed8724 --- /dev/null +++ b/lib/active_scaffold/actions/common_search.rb @@ -0,0 +1,22 @@ +module ActiveScaffold::Actions + module CommonSearch + def reset_search + update_table + end + + def store_search_params_into_session + active_scaffold_session_storage[:search] = params.delete :search if params[:search] + end + + def search_params + active_scaffold_session_storage[:search] + end + + protected + # The default security delegates to ActiveRecordPermissions. + # You may override the method to customize. + def search_authorized? + authorized_for?(:crud_type => :read) + end + end +end diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index 44aabfcb91..8051f5e2d9 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -1,15 +1,16 @@ module ActiveScaffold::Actions module FieldSearch + include ActiveScaffold::Actions::CommonSearch def self.included(base) base.before_filter :search_authorized_filter, :only => :show_search - base.before_filter :do_search + base.before_filter :store_search_params_into_session, :only => [:list, :index] + base.before_filter :do_search, :only => [:show_search, :list, :index] end # FieldSearch uses params[:search] and not @record because search conditions do not always pass the Model's validations. # This facilitates for example, textual searches against associations via .search_sql def show_search - params[:search] ||= {} - @record = active_scaffold_config.model.new + @record = update_record_from_params(active_scaffold_config.model.new, active_scaffold_config.field_search.columns, search_params) respond_to_action(:field_search) end @@ -23,12 +24,13 @@ def field_search_respond_to_js end def do_search - unless params[:search].nil? + unless search_params.nil? text_search = active_scaffold_config.field_search.text_search search_conditions = [] columns = active_scaffold_config.field_search.columns - columns.each do |column| - search_conditions << self.class.condition_for_column(column, params[:search][column.name], text_search) + search_params.each do |key, value| + next unless columns.include? key + search_conditions << self.class.condition_for_column(active_scaffold_config.columns[key], value, text_search) end search_conditions.compact! self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, *search_conditions) @@ -41,11 +43,6 @@ def do_search end end - # The default security delegates to ActiveRecordPermissions. - # You may override the method to customize. - def search_authorized? - authorized_for?(:crud_type => :read) - end private def search_authorized_filter link = active_scaffold_config.field_search.link || active_scaffold_config.field_search.class.link diff --git a/lib/active_scaffold/actions/live_search.rb b/lib/active_scaffold/actions/live_search.rb index 4aadd43503..aec0a6c9f3 100644 --- a/lib/active_scaffold/actions/live_search.rb +++ b/lib/active_scaffold/actions/live_search.rb @@ -1,8 +1,11 @@ module ActiveScaffold::Actions module LiveSearch + include ActiveScaffold::Actions::CommonSearch def self.included(base) base.before_filter :search_authorized_filter, :only => :show_search - base.before_filter :do_search + base.before_filter :store_search_params_into_session, :only => [:list, :index] + base.before_filter :do_search, :only => [:show_search, :list, :index] + base.helper_method :search_params end def show_search @@ -24,12 +27,12 @@ def live_search_respond_to_js end def do_search - @query = params[:search].to_s.strip rescue '' + query = search_params.to_s.strip rescue '' - unless @query.empty? + unless query.empty? columns = active_scaffold_config.live_search.columns text_search = active_scaffold_config.live_search.text_search - search_conditions = self.class.create_conditions_for_columns(@query.split(' '), columns, text_search) + search_conditions = self.class.create_conditions_for_columns(query.split(' '), columns, text_search) self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, search_conditions) @filtered = !search_conditions.blank? @@ -40,11 +43,6 @@ def do_search end end - # The default security delegates to ActiveRecordPermissions. - # You may override the method to customize. - def search_authorized? - authorized_for?(:crud_type => :read) - end private def search_authorized_filter link = active_scaffold_config.live_search.link || active_scaffold_config.live_search.class.link diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index 6e6b14ef0f..f6e63cfdca 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -1,8 +1,11 @@ module ActiveScaffold::Actions module Search + include ActiveScaffold::Actions::CommonSearch def self.included(base) base.before_filter :search_authorized_filter, :only => :show_search - base.before_filter :do_search + base.before_filter :store_search_params_into_session, :only => [:list, :index] + base.before_filter :do_search, :only => [:show_search, :list, :index] + base.helper_method :search_params end def show_search @@ -17,12 +20,12 @@ def search_respond_to_js render(:partial => "search") end def do_search - @query = params[:search].to_s.strip rescue '' + query = search_params.to_s.strip rescue '' - unless @query.empty? + unless query.empty? columns = active_scaffold_config.search.columns text_search = active_scaffold_config.search.text_search - search_conditions = self.class.create_conditions_for_columns(@query.split(' '), columns, text_search) + search_conditions = self.class.create_conditions_for_columns(query.split(' '), columns, text_search) self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, search_conditions) @filtered = !search_conditions.blank? From f99b89d67aec5b8d7cb6e739b43b97569d29c54e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 11 Mar 2010 17:24:15 +0100 Subject: [PATCH 0228/2024] Copy from edwinmoss, improve exception handling in finder --- lib/active_scaffold/finder.rb | 45 +++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 3977c233a0..61fed25782 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -33,29 +33,34 @@ def condition_for_column(column, value, text_search = :full) # we must check false or not blank because we want to search for false but false is blank return unless column and column.search_sql and not value.blank? search_ui = column.search_ui || column.column.type - if self.respond_to?("condition_for_#{column.name}_column") - self.send("condition_for_#{column.name}_column", column, value, like_pattern) - elsif self.respond_to?("condition_for_#{search_ui}_type") - self.send("condition_for_#{search_ui}_type", column, value, like_pattern) - else - case search_ui - when :boolean, :checkbox - ["#{column.search_sql} = ?", column.column.type_cast(value)] - when :select - ["#{column.search_sql} = ?", value[:id]] unless value[:id].blank? - when :multi_select - ["#{column.search_sql} in (?)", value.values.collect{|hash| hash[:id]}] - else - if column.column.nil? || column.column.text? - ["LOWER(#{column.search_sql}) LIKE ?", like_pattern.sub('?', value.downcase)] + begin + if self.respond_to?("condition_for_#{column.name}_column") + self.send("condition_for_#{column.name}_column", column, value, like_pattern) + elsif self.respond_to?("condition_for_#{search_ui}_type") + self.send("condition_for_#{search_ui}_type", column, value, like_pattern) + else + case search_ui + when :boolean, :checkbox + ["#{column.search_sql} = ?", column.column.type_cast(value)] + when :select + ["#{column.search_sql} = ?", value[:id]] unless value[:id].blank? + when :multi_select + ["#{column.search_sql} in (?)", value.values.collect{|hash| hash[:id]}] else - ["#{column.search_sql} = ?", column.column.type_cast(value)] - end + if column.column.nil? || column.column.text? + ["LOWER(#{column.search_sql}) LIKE ?", like_pattern.sub('?', value.downcase)] + else + ["#{column.search_sql} = ?", column.column.type_cast(value)] + end + end end + rescue Exception => e + logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column :#{column.name}, search_ui = #{search_ui} in #{@controller.class}" + raise e end end - def condition_for_integer_type(column, value, like_pattern) + def condition_for_integer_type(column, value, like_pattern = nil) if value['from'].blank? or not ActiveScaffold::Finder::NumericComparators.include?(value['opt']) nil elsif value['opt'] == 'BETWEEN' @@ -67,7 +72,7 @@ def condition_for_integer_type(column, value, like_pattern) alias_method :condition_for_decimal_type, :condition_for_integer_type alias_method :condition_for_float_type, :condition_for_integer_type - def condition_for_datetime_type(column, value, like_pattern) + def condition_for_datetime_type(column, value, like_pattern = nil) conversion = value['from']['hour'].blank? && value['to']['hour'].blank? ? 'to_date' : 'to_time' from_value, to_value = ['from', 'to'].collect do |field| Time.zone.local(*['year', 'month', 'day', 'hour', 'minutes', 'seconds'].collect {|part| value[field][part].to_i}) rescue nil @@ -143,7 +148,7 @@ def all_conditions # TODO: this should reside on the model, not the controller def find_if_allowed(id, crud_type, klass = beginning_of_chain) record = klass.find(id) - raise ActiveScaffold::RecordNotAllowed unless record.authorized_for?(:crud_type => crud_type.to_sym) + raise ActiveScaffold::RecordNotAllowed, "#{klass} with id = #{id}" unless record.authorized_for?(:crud_type => crud_type.to_sym) return record end From 64a8c20bddb5b6d680e9a78c07c588a10dc31a46 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 12 Mar 2010 09:41:03 +0100 Subject: [PATCH 0229/2024] Copy from edwinmoss Options in form helpers --- lib/active_scaffold/helpers/form_column_helpers.rb | 10 +++++----- .../active_scaffold/default/stylesheet.css | 13 +++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index a3e52b4fdd..b0ed25f72a 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -4,12 +4,12 @@ module Helpers module FormColumnHelpers # This method decides which input to use for the given column. # It does not do any rendering. It only decides which method is responsible for rendering. - def active_scaffold_input_for(column, scope = nil) - options = active_scaffold_input_options(column, scope) + def active_scaffold_input_for(column, scope = nil, options = {}) + options = active_scaffold_input_options(column, scope, options) options = javascript_for_update_column(column, scope, options) # first, check if the dev has created an override for this specific field if override_form_field?(column) - send(override_form_field(column), @record, options[:name]) + send(override_form_field(column), @record, options) # second, check if the dev has specified a valid form_ui for this column elsif column.form_ui and override_input?(column.form_ui) send(override_input(column.form_ui), column, options) @@ -51,14 +51,14 @@ def active_scaffold_input_text_options(options = {}) end # the standard active scaffold options used for class, name and scope - def active_scaffold_input_options(column, scope = nil) + def active_scaffold_input_options(column, scope = nil, options = {}) name = scope ? "record#{scope}[#{column.name}]" : "record[#{column.name}]" # Fix for keeping unique IDs in subform id_control = "record_#{column.name}_#{[params[:eid], params[:id]].compact.join '_'}" id_control += scope.gsub(/(\[|\])/, '_').gsub('__', '_').gsub(/_$/, '') if scope - { :name => name, :class => "#{column.name}-input", :id => id_control} + { :name => name, :class => "#{column.name}-input", :id => id_control}.merge(options) end def javascript_for_update_column(column, scope, options) diff --git a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css index e1f880c040..b59b6a66f0 100644 --- a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +++ b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css @@ -327,6 +327,12 @@ color: #06c; background-color: #ff8; } +.active-scaffold .active-scaffold .view { +background-color: transparent; +padding: 0px; +border: none; +} + .active-scaffold .active-scaffold td { background-color: #ECFFE7; border-bottom: solid 1px #CDF7C5; @@ -340,6 +346,13 @@ border: solid 1px #DDDF37; border-top: none; } +.active-scaffold .active-scaffold .active-scaffold td.inline-adapter-cell { +background-color: #DAFFCD; +padding: 4px; +border: solid 1px #7FcF00; +border-top: none; +} + .active-scaffold .active-scaffold .active-scaffold-footer { font-size: 11px; } From cdcba77689f84c169de24884d12e501bc06adf5a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 12 Mar 2010 09:42:38 +0100 Subject: [PATCH 0230/2024] Copy from edwinmoss Exception handling in forms --- .../helpers/form_column_helpers.rb | 66 ++++++++++--------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index b0ed25f72a..3d09610279 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -5,40 +5,46 @@ module FormColumnHelpers # This method decides which input to use for the given column. # It does not do any rendering. It only decides which method is responsible for rendering. def active_scaffold_input_for(column, scope = nil, options = {}) - options = active_scaffold_input_options(column, scope, options) - options = javascript_for_update_column(column, scope, options) - # first, check if the dev has created an override for this specific field - if override_form_field?(column) - send(override_form_field(column), @record, options) - # second, check if the dev has specified a valid form_ui for this column - elsif column.form_ui and override_input?(column.form_ui) - send(override_input(column.form_ui), column, options) - # fallback: we get to make the decision - else - if column.association - # if we get here, it's because the column has a form_ui but not one ActiveScaffold knows about. - raise "Unknown form_ui `#{column.form_ui}' for column `#{column.name}'" - elsif column.virtual? - active_scaffold_input_virtual(column, options) - - else # regular model attribute column - # if we (or someone else) have created a custom render option for the column type, use that - if override_input?(column.column.type) - send(override_input(column.column.type), column, options) - # final ultimate fallback: use rails' generic input method - else - # for textual fields we pass different options - text_types = [:text, :string, :integer, :float, :decimal] - options = active_scaffold_input_text_options(options) if text_types.include?(column.column.type) - if column.column.type == :string && options[:maxlength].blank? - options[:maxlength] = column.column.limit - options[:size] ||= ActionView::Helpers::InstanceTag::DEFAULT_FIELD_OPTIONS["size"] + begin + options = active_scaffold_input_options(column, scope, options) + options = javascript_for_update_column(column, scope, options) + # first, check if the dev has created an override for this specific field + if override_form_field?(column) + send(override_form_field(column), @record, options) + # second, check if the dev has specified a valid form_ui for this column + elsif column.form_ui and override_input?(column.form_ui) + send(override_input(column.form_ui), column, options) + # fallback: we get to make the decision + else + if column.association + # if we get here, it's because the column has a form_ui but not one ActiveScaffold knows about. + raise "Unknown form_ui `#{column.form_ui}' for column `#{column.name}'" + elsif column.virtual? + active_scaffold_input_virtual(column, options) + + else # regular model attribute column + # if we (or someone else) have created a custom render option for the column type, use that + if override_input?(column.column.type) + send(override_input(column.column.type), column, options) + # final ultimate fallback: use rails' generic input method + else + # for textual fields we pass different options + text_types = [:text, :string, :integer, :float, :decimal] + options = active_scaffold_input_text_options(options) if text_types.include?(column.column.type) + if column.column.type == :string && options[:maxlength].blank? + options[:maxlength] = column.column.limit + options[:size] ||= ActionView::Helpers::InstanceTag::DEFAULT_FIELD_OPTIONS["size"] + end + options.update(:value => format_number_value(@record.send(column.name), column.options)) if column.column.number? + input(:record, column.name, options.merge(column.options)) end - options.update(:value => format_number_value(@record.send(column.name), column.options)) if column.column.number? - input(:record, column.name, options.merge(column.options)) end end end + rescue Exception => e + logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" + raise e + end end alias form_column active_scaffold_input_for From 1a72bf86141b7149d96f77baf8e51ff6aeeb96d5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 12 Mar 2010 09:45:00 +0100 Subject: [PATCH 0231/2024] Copy from edwinmoss Exception handling --- .../helpers/list_column_helpers.rb | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 1342939521..ee67468e1d 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -4,26 +4,31 @@ module Helpers # Helpers that assist with the rendering of a List Column module ListColumnHelpers def get_column_value(record, column) - # check for an override helper - value = if column_override? column - # we only pass the record as the argument. we previously also passed the formatted_value, - # but mike perham pointed out that prohibited the usage of overrides to improve on the - # performance of our default formatting. see issue #138. - send(column_override(column), record) - # second, check if the dev has specified a valid list_ui for this column - elsif column.list_ui and override_column_ui?(column.list_ui) - send(override_column_ui(column.list_ui), column, record) + begin + # check for an override helper + value = if column_override? column + # we only pass the record as the argument. we previously also passed the formatted_value, + # but mike perham pointed out that prohibited the usage of overrides to improve on the + # performance of our default formatting. see issue #138. + send(column_override(column), record) + # second, check if the dev has specified a valid list_ui for this column + elsif column.list_ui and override_column_ui?(column.list_ui) + send(override_column_ui(column.list_ui), column, record) - elsif inplace_edit?(record, column) - active_scaffold_inplace_edit(record, column) - elsif column.column and override_column_ui?(column.column.type) - send(override_column_ui(column.column.type), column, record) - else - format_column_value(record, column) - end + elsif inplace_edit?(record, column) + active_scaffold_inplace_edit(record, column) + elsif column.column and override_column_ui?(column.column.type) + send(override_column_ui(column.column.type), column, record) + else + format_column_value(record, column) + end - value = ' ' if value.nil? or (value.respond_to?(:empty?) and value.empty?) # fix for IE 6 - return value + value = ' ' if value.nil? or (value.respond_to?(:empty?) and value.empty?) # fix for IE 6 + return value + rescue Exception => e + logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" + raise e + end end # TODO: move empty_field_text and   logic in here? From 552a9ea3f642bcfc1208dd0b1f7a2339cb900590 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 12 Mar 2010 09:49:22 +0100 Subject: [PATCH 0232/2024] Copy from edwinmoss Options in helpers --- lib/active_scaffold/helpers/form_column_helpers.rb | 1 - lib/active_scaffold/helpers/list_column_helpers.rb | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 3d09610279..1e95ab9b0d 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -40,7 +40,6 @@ def active_scaffold_input_for(column, scope = nil, options = {}) end end end - end rescue Exception => e logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" raise e diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index ee67468e1d..42a68d962a 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -250,8 +250,8 @@ def format_inplace_edit_column(record,column) end end - def active_scaffold_inplace_edit(record, column) - formatted_column = format_column_value(record, column) + def active_scaffold_inplace_edit(record, column, options = {}) + formatted_column = options[:formatted_column] || format_column_value(record, column) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field"} in_place_editor_options = { From bf9f35ea55a99503a5f5f0e0582bff28d7696832 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 15 Mar 2010 11:13:48 +0100 Subject: [PATCH 0233/2024] Allow search ui select with multiple selection --- lib/active_scaffold/actions/field_search.rb | 7 +++- lib/active_scaffold/finder.rb | 2 +- .../helpers/form_column_helpers.rb | 4 +-- .../helpers/search_column_helpers.rb | 34 +++++++++++-------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index 8051f5e2d9..7e28261005 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -5,16 +5,21 @@ def self.included(base) base.before_filter :search_authorized_filter, :only => :show_search base.before_filter :store_search_params_into_session, :only => [:list, :index] base.before_filter :do_search, :only => [:show_search, :list, :index] + base.helper_method :field_search_params end # FieldSearch uses params[:search] and not @record because search conditions do not always pass the Model's validations. # This facilitates for example, textual searches against associations via .search_sql def show_search - @record = update_record_from_params(active_scaffold_config.model.new, active_scaffold_config.field_search.columns, search_params) + @record = update_record_from_params(active_scaffold_config.model.new, active_scaffold_config.field_search.columns, field_search_params) respond_to_action(:field_search) end protected + def field_search_params + search_params || {} + end + def field_search_respond_to_html render(:action => "field_search") end diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 61fed25782..78f281fec4 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -43,7 +43,7 @@ def condition_for_column(column, value, text_search = :full) when :boolean, :checkbox ["#{column.search_sql} = ?", column.column.type_cast(value)] when :select - ["#{column.search_sql} = ?", value[:id]] unless value[:id].blank? + ["#{column.search_sql} in (?)", value] unless value.blank? when :multi_select ["#{column.search_sql} in (?)", value.values.collect{|hash| hash[:id]}] else diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 1e95ab9b0d..92a59b70d9 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -95,7 +95,7 @@ def active_scaffold_input_singular_association(column, html_options) selected = associated.nil? ? nil : associated.id method = column.name - html_options[:name] += '[id]' + #html_options[:name] += '[id]' options = {:selected => selected, :include_blank => as_(:_select_)} html_options.update(column.options[:html_options] || {}) @@ -113,7 +113,7 @@ def active_scaffold_input_plural_association(column, options) associated_ids = associated_options.collect {|a| a[1]} select_options.each_with_index do |option, i| label, id = option - this_name = "#{options[:name]}[#{i}][id]" + this_name = "#{options[:name]}[]" this_id = "#{options[:id]}_#{i}_id" html << "<li>" html << check_box_tag(this_name, id, associated_ids.include?(id), :id => this_id) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 9ae4a82126..0a127accd3 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -9,11 +9,7 @@ def active_scaffold_search_for(column) # first, check if the dev has created an override for this specific field for search if override_search_field?(column) - send(override_search_field(column), @record, options[:name]) - - # first, check if the dev has created an override for this specific field - elsif override_form_field?(column) - send(override_form_field(column), @record, options[:name]) + send(override_search_field(column), @record, options) # second, check if the dev has specified a valid search_ui for this column, using specific ui for searches elsif column.search_ui and override_search?(column.search_ui) @@ -23,6 +19,10 @@ def active_scaffold_search_for(column) elsif column.search_ui and override_input?(column.search_ui) send(override_input(column.search_ui), column, options) + # fourth, check if the dev has created an override for this specific field + elsif override_form_field?(column) + send(override_form_field(column), @record, options) + # fallback: we get to make the decision else if column.association or column.virtual? @@ -82,21 +82,25 @@ def active_scaffold_search_multi_select(column, options) html end - def active_scaffold_search_select(column, options) + def active_scaffold_search_select(column, html_options) + associated = field_search_params[column.name] if column.association - associated = @record.send(column.association.name) - associated = associated.first if associated.is_a?(Array) # for columns with plural association - + associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil? + method = column.association.macro == :belongs_to ? column.association.primary_key_name : column.name select_options = options_for_association(column.association, true) - select_options.unshift([ associated.to_label, associated.id ]) unless associated.nil? or select_options.find {|label, id| id == associated.id} + else + method = column.name + select_options = column.options[:options] + end - selected = associated.nil? ? nil : associated.id - method = column.association.macro == :belongs_to ? column.association.primary_key_name : column.name - options[:name] += '[id]' - select(:record, method, select_options.uniq, {:selected => selected, :include_blank => as_(:_select_)}, options) + options = { :selected => associated }.merge! column.options + html_options.merge! column.options[:html_options] || {} + if html_options[:multiple] + html_options[:name] += '[]' else - select(:record, column.name, column.options, { :selected => @record.send(column.name) }, options) + options[:include_blank] ||= as_(:_select_) end + select(:record, method, select_options, options, html_options) end def active_scaffold_search_text(column, options) From 191bf92e9bf69dbc82449abaf517a6f4efa15fc6 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 15 Mar 2010 12:35:21 +0100 Subject: [PATCH 0234/2024] Improve field search helpers --- lib/active_scaffold/actions/field_search.rb | 4 ++-- lib/active_scaffold/actions/live_search.rb | 2 +- lib/active_scaffold/actions/search.rb | 2 +- lib/active_scaffold/finder.rb | 4 +--- .../helpers/search_column_helpers.rb | 17 ++++++++--------- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index 7e28261005..b7f6306cce 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -4,14 +4,14 @@ module FieldSearch def self.included(base) base.before_filter :search_authorized_filter, :only => :show_search base.before_filter :store_search_params_into_session, :only => [:list, :index] - base.before_filter :do_search, :only => [:show_search, :list, :index] + base.before_filter :do_search, :only => [:list, :index] base.helper_method :field_search_params end # FieldSearch uses params[:search] and not @record because search conditions do not always pass the Model's validations. # This facilitates for example, textual searches against associations via .search_sql def show_search - @record = update_record_from_params(active_scaffold_config.model.new, active_scaffold_config.field_search.columns, field_search_params) + @record = active_scaffold_config.model.new respond_to_action(:field_search) end diff --git a/lib/active_scaffold/actions/live_search.rb b/lib/active_scaffold/actions/live_search.rb index aec0a6c9f3..d9f1115c8f 100644 --- a/lib/active_scaffold/actions/live_search.rb +++ b/lib/active_scaffold/actions/live_search.rb @@ -4,7 +4,7 @@ module LiveSearch def self.included(base) base.before_filter :search_authorized_filter, :only => :show_search base.before_filter :store_search_params_into_session, :only => [:list, :index] - base.before_filter :do_search, :only => [:show_search, :list, :index] + base.before_filter :do_search, :only => [:list, :index] base.helper_method :search_params end diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index f6e63cfdca..df11bb2fcd 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -4,7 +4,7 @@ module Search def self.included(base) base.before_filter :search_authorized_filter, :only => :show_search base.before_filter :store_search_params_into_session, :only => [:list, :index] - base.before_filter :do_search, :only => [:show_search, :list, :index] + base.before_filter :do_search, :only => [:list, :index] base.helper_method :search_params end diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 78f281fec4..c9e0fcda61 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -42,10 +42,8 @@ def condition_for_column(column, value, text_search = :full) case search_ui when :boolean, :checkbox ["#{column.search_sql} = ?", column.column.type_cast(value)] - when :select + when :select, :multi_select ["#{column.search_sql} in (?)", value] unless value.blank? - when :multi_select - ["#{column.search_sql} in (?)", value.values.collect{|hash| hash[:id]}] else if column.column.nil? || column.column.text? ["LOWER(#{column.search_sql}) LIKE ?", like_pattern.sub('?', value.downcase)] diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 0a127accd3..03006e97d5 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -48,7 +48,7 @@ def active_scaffold_search_for(column) # the standard active scaffold options used for class, name and scope def active_scaffold_search_options(column) - { :name => "search[#{column.name}]", :class => "#{column.name}-input", :id => "search_#{column.name}"} + { :name => "search[#{column.name}]", :class => "#{column.name}-input", :id => "search_#{column.name}", :value => field_search_params[column.name] } end ## @@ -56,21 +56,20 @@ def active_scaffold_search_options(column) ## def active_scaffold_search_multi_select(column, options) - associated_options = @record.send(column.association.name) - associated_options = [associated_options].compact unless associated_options.is_a? Array - associated_options.collect! {|r| [r.to_label, r.id]} - select_options = associated_options | options_for_association(column.association, true) + associated = options.delete :value + associated = [associated].compact unless associated.is_a? Array + associated.collect!(&:to_i) + select_options = options_for_association(column.association, true) return as_(:no_options) if select_options.empty? html = "<ul class=\"checkbox-list\" id=\"#{options[:id]}\">" - associated_ids = associated_options.collect {|a| a[1]} + options[:name] += '[]' select_options.each_with_index do |option, i| label, id = option - this_name = "#{options[:name]}[#{i}][id]" this_id = "#{options[:id]}_#{i}_id" html << "<li>" - html << check_box_tag(this_name, id, associated_ids.include?(id), :id => this_id) + html << check_box_tag(options[:name], id, associated.include?(id), :id => this_id) html << "<label for='#{this_id}'>" html << label html << "</label>" @@ -83,7 +82,7 @@ def active_scaffold_search_multi_select(column, options) end def active_scaffold_search_select(column, html_options) - associated = field_search_params[column.name] + associated = html_options.delete :value if column.association associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil? method = column.association.macro == :belongs_to ? column.association.primary_key_name : column.name From 3be85fd501d88dd9efeb3809ede5ef94f3de0baa Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 15 Mar 2010 12:43:16 +0100 Subject: [PATCH 0235/2024] Copy from edwinmoss, html_options in render_action_link --- lib/active_scaffold/helpers/view_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index efbf084258..31088fd86f 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -128,14 +128,14 @@ def skip_action_link(link) (link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method) end - def render_action_link(link, url_options, record = nil) + def render_action_link(link, url_options, record = nil, html_options = {}) url_options = url_options.clone url_options[:action] = link.action url_options[:controller] = link.controller if link.controller url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller] url_options.merge! link.parameters if link.parameters - html_options = link.html_options.merge({:class => link.action}) + html_options.reverse_merge! link.html_options.merge(:class => link.action) if link.inline? # NOTE this is in url_options instead of html_options on purpose. the reason is that the client-side # action link javascript needs to submit the proper method, but the normal html_options[:method] From 14f4fead4b10cafb1e898307c5ecfea951dd9e29 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 15 Mar 2010 13:16:41 +0100 Subject: [PATCH 0236/2024] Copy from edwinmoss Show link to reset the search next to filtered message --- frontends/default/views/_field_search.html.erb | 6 ++++-- frontends/default/views/_list.html.erb | 11 +++++++++++ lib/active_scaffold/config/list.rb | 4 ++++ lib/active_scaffold/locale/en.rb | 1 + lib/active_scaffold/locale/es.yml | 1 + 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_field_search.html.erb b/frontends/default/views/_field_search.html.erb index 7d4677c271..ed8c588434 100644 --- a/frontends/default/views/_field_search.html.erb +++ b/frontends/default/views/_field_search.html.erb @@ -1,4 +1,5 @@ -<% href = url_for(params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'}) -%> +<% href_params = params_for(:action => :index, :escape => false, :search => nil) -%> +<% href = url_for(href_params) -%> <%= form_remote_tag :url => href, :method => :get, :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", @@ -25,8 +26,9 @@ </ol> <p class="form-footer"> <%= submit_tag as_(:search), :class => "submit" %> + <% href = url_for(href_params.merge(:search => '')) -%> <%= link_to_remote as_(:reset), {:url => href, :with => "'search='", :method => :get, - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')"}, :class => 'cancel' %> + :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')"}, :class => 'cancel', :href => href %> <%= loading_indicator_tag(:action => :search) %> </p> </form> diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index f2dd3d7609..1e65a9379d 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -12,6 +12,17 @@ </div> <p class="filtered-message" <%= ' style="display:none;" ' unless @filtered %>> <%= as_(active_scaffold_config.list.filtered_message) %> + <% if active_scaffold_config.list.show_search_reset -%> + <% href = url_for(params_for(:action => :index, :escape => false, :search => '')) -%> + <%= link_to_remote as_(:click_to_reset), + { :url => href, + :method => :get, + :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", + :after => "$('#{loading_indicator_id(:action => :table)}').style.visibility = 'visible';", + :complete => "$('#{loading_indicator_id(:action => :table)}').style.visibility = 'hidden';", + :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')" + }, :href => href %> + <% end -%> </p> <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" ' unless @page.items.empty? %>> <%= as_(active_scaffold_config.list.no_entries_message) %> diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 8253b1926d..e122584969 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -17,6 +17,7 @@ def initialize(core_config) # inherit from global scope @empty_field_text = self.class.empty_field_text @pagination = self.class.pagination + @show_search_reset = true end # global level configuration @@ -66,6 +67,9 @@ def columns # what string to use when a field is empty attr_accessor :empty_field_text + # show a link to reset the search next to filtered message + attr_accessor :show_search_reset + # the default sorting. should be an array of hashes of {column_name => direction}, e.g. [{:a => 'desc'}, {:b => 'asc'}]. to just sort on one column, you can simply provide a hash, though, e.g. {:a => 'desc'}. def sorting=(val) val = [val] if val.is_a? Hash diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index f5d6951b50..85790e9e17 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -7,6 +7,7 @@ :are_you_sure_to_delete => 'Are you sure you want to delete {{label}}?', :cancel => 'Cancel', :click_to_edit => 'Click to edit', + :click_to_reset => 'Click to reset', :close => 'Close', :create => 'Create', :create_model => 'Create {{model}}', diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index 2bcd60dbb7..fb4fcd9507 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -6,6 +6,7 @@ es: are_you_sure_to_delete: '¿Estás seguro de que quieres borrar {{label}}?' cancel: 'Cancelar' click_to_edit: 'Pulsa para editar' + click_to_reset: 'Pulsa para restaurar' close: 'Cerrar' create: 'Crear' create_model: 'Crear {{model}}' From e0f17797a98399e9d1eef89978e7b7fe099e1a92 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 15 Mar 2010 17:40:04 +0100 Subject: [PATCH 0237/2024] Use checkbox for boolean columns which cannot be null --- lib/active_scaffold/data_structures/column.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 860758cc83..87e9ef8691 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -248,6 +248,7 @@ def initialize(name, active_record_class) #:nodoc: @show_blank_record = self.class.show_blank_record @actions_for_association_links = self.class.actions_for_association_links.clone if @association @options = {:format => :i18n_number} if @column.try(:number?) + @form_ui = :checkbox if @column and @column.type == :boolean # default all the configurable variables self.css_class = '' From b31d889d049f7b5987810b86cf5d9858c3be2293 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Mar 2010 10:34:01 +0100 Subject: [PATCH 0238/2024] Copy from edwinmoss Range search for strings in field search --- lib/active_scaffold/finder.rb | 37 ++++++++++++++----- .../helpers/search_column_helpers.rb | 25 ++++++++++--- lib/active_scaffold/locale/en.rb | 3 ++ lib/active_scaffold/locale/es.yml | 5 ++- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index c9e0fcda61..325f0bb489 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -30,7 +30,6 @@ def create_conditions_for_columns(tokens, columns, text_search = :full) # TODO: this should reside on the column, not the controller def condition_for_column(column, value, text_search = :full) like_pattern = like_pattern(text_search) - # we must check false or not blank because we want to search for false but false is blank return unless column and column.search_sql and not value.blank? search_ui = column.search_ui || column.column.type begin @@ -43,7 +42,7 @@ def condition_for_column(column, value, text_search = :full) when :boolean, :checkbox ["#{column.search_sql} = ?", column.column.type_cast(value)] when :select, :multi_select - ["#{column.search_sql} in (?)", value] unless value.blank? + ["#{column.search_sql} in (?)", value] else if column.column.nil? || column.column.text? ["LOWER(#{column.search_sql}) LIKE ?", like_pattern.sub('?', value.downcase)] @@ -59,21 +58,36 @@ def condition_for_column(column, value, text_search = :full) end def condition_for_integer_type(column, value, like_pattern = nil) - if value['from'].blank? or not ActiveScaffold::Finder::NumericComparators.include?(value['opt']) + if value[:from].blank? or not ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) nil - elsif value['opt'] == 'BETWEEN' - ["#{column.search_sql} BETWEEN ? AND ?", value['from'].to_f, value['to'].to_f] + elsif value[:opt] == 'BETWEEN' + ["#{column.search_sql} BETWEEN ? AND ?", value[:from].to_f, value[:to].to_f] else - ["#{column.search_sql} #{value['opt']} ?", value['from'].to_f] + ["#{column.search_sql} #{value[:opt]} ?", value[:from].to_f] end end alias_method :condition_for_decimal_type, :condition_for_integer_type alias_method :condition_for_float_type, :condition_for_integer_type + def condition_for_range_type(column, value, like_pattern = nil) + if value[:from].blank? + nil + elsif ActiveScaffold::Finder::StringComparators.values.include?(value[:opt]) + ["#{column.search_sql} LIKE ?", value[:opt].sub('?', value[:from])] + elsif value[:opt] == 'BETWEEN' + ["#{column.search_sql} BETWEEN ? AND ?", value[:from], value[:to]] + elsif ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) + ["#{column.search_sql} #{value[:opt]} ?", value[:from]] + else + nil + end + end + alias_method :condition_for_string_type, :condition_for_range_type + def condition_for_datetime_type(column, value, like_pattern = nil) - conversion = value['from']['hour'].blank? && value['to']['hour'].blank? ? 'to_date' : 'to_time' - from_value, to_value = ['from', 'to'].collect do |field| - Time.zone.local(*['year', 'month', 'day', 'hour', 'minutes', 'seconds'].collect {|part| value[field][part].to_i}) rescue nil + conversion = value[:from][:hour].blank? && value[:to][:hour].blank? ? :to_date : :to_time + from_value, to_value = [:from, :to].collect do |field| + Time.zone.local(*[:year, :month, :day, :hour, :minutes, :seconds].collect {|part| value[field][part].to_i}) rescue nil end if from_value.nil? and to_value.nil? @@ -109,6 +123,11 @@ def like_pattern(text_search) '!=', 'BETWEEN' ] + StringComparators = { + :contains => '%?%', + :begins_with => '?%', + :ends_with => '%?' + } def self.included(klass) klass.extend ClassMethods diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 03006e97d5..f6bb1106b8 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -119,20 +119,33 @@ def active_scaffold_search_boolean(column, options) # we can't use checkbox ui because it's not possible to decide whether search for this field or not alias_method :active_scaffold_search_checkbox, :active_scaffold_search_boolean - def active_scaffold_search_integer(column, options) + def field_search_params_range_values(column) + search_ui = column.search_ui || column.column.type + values = field_search_params[column.name] + return nil if values.nil? + return values[:opt], values[:from], values[:to] + end + + def active_scaffold_search_range(column, options) + opt_value, from_value, to_value = field_search_params_range_values(column) + select_options = ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} + select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} if column.column && column.column.text? + html = [] html << select_tag("#{options[:name]}[opt]", - options_for_select(ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]}), + options_for_select(select_options, opt_value), :id => "#{options[:id]}_opt", :onchange => "Element[this.value == 'BETWEEN' ? 'show' : 'hide']('#{options[:id]}_between');") - html << text_field_tag("#{options[:name]}[from]", nil, active_scaffold_input_text_options(:id => options[:id], :size => 10)) - html << content_tag(:span, ' - ' + text_field_tag("#{options[:name]}[to]", nil, + html << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(:id => options[:id], :size => 10)) + html << content_tag(:span, ' - ' + text_field_tag("#{options[:name]}[to]", to_value, active_scaffold_input_text_options(:id => "#{options[:id]}_to", :size => 10)), :id => "#{options[:id]}_between", :style => "display:none") html * ' ' end - alias_method :active_scaffold_search_decimal, :active_scaffold_search_integer - alias_method :active_scaffold_search_float, :active_scaffold_search_integer + alias_method :active_scaffold_search_integer, :active_scaffold_search_range + alias_method :active_scaffold_search_decimal, :active_scaffold_search_range + alias_method :active_scaffold_search_float, :active_scaffold_search_range + alias_method :active_scaffold_search_string, :active_scaffold_search_range def active_scaffold_search_datetime(column, options) options = column.options.merge(options) diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 85790e9e17..10a4c4f4f4 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -58,6 +58,9 @@ :'<' => '<', :'!=' => '!=', :between => 'Between', + :contains => 'Contains', + :begins_with => 'Begins with', + :ends_with => 'Ends with', # error_messages :cant_destroy_record => "{{record}} can't be destroyed", diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index fb4fcd9507..72f71430ae 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -58,7 +58,10 @@ es: '>': '>' '<': '<' '!=': '!=' - between: 'entre' + between: 'Entre' + contains: 'Contiene' + begins_with: 'Empieza con' + ends_with: 'Termina con' # error_messages cant_destroy_record: "No se pudo borrar {{record}}" From a7920ea85adbb6384b6cc057f500ad77528ce196 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Mar 2010 11:42:19 +0100 Subject: [PATCH 0239/2024] Copy from edwinmoss Record select integration in field search --- lib/active_scaffold/finder.rb | 8 +++++++ .../helpers/form_column_helpers.rb | 21 ++++++++++++------- .../helpers/search_column_helpers.rb | 18 ++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 325f0bb489..3622004747 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -104,6 +104,14 @@ def condition_for_datetime_type(column, value, like_pattern = nil) alias_method :condition_for_time_type, :condition_for_datetime_type alias_method :condition_for_timestamp_type, :condition_for_datetime_type + def condition_for_record_select_type(column, value, like_pattern = nil) + if value.is_a?(Array) + ["#{column.search_sql} IN (?)", value] + else + ["#{column.search_sql} = ?", value] + end + end + def like_pattern(text_search) case text_search when :full then '%?%' diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 92a59b70d9..1e4833bfa3 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -150,10 +150,17 @@ def active_scaffold_input_radio(column, html_options) end end - # only works for singular associations # requires RecordSelect plugin to be installed and configured. # ... maybe this should be provided in a bridge? def active_scaffold_input_record_select(column, options) + if column.singular_association? + active_scaffold_record_select(column, options, @record.send(column.name), false) + elsif column.plural_association? + active_scaffold_record_select(column, options, @record.send(column.name), true) + end + end + + def active_scaffold_record_select(column, options, value, multiple) unless column.association raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)." end @@ -164,16 +171,16 @@ def active_scaffold_input_record_select(column, options) if [:has_one, :has_many].include?(column.association.macro) params.merge!({column.association.primary_key_name => ''}) end - + record_select_options = {:controller => remote_controller, :id => options[:id]} record_select_options.merge!(active_scaffold_input_text_options) record_select_options.merge!(column.options) - if column.singular_association? - record_select_field(options[:name], (@record.send(column.name) || column.association.klass.new), record_select_options) - elsif column.plural_association? - record_multi_select_field(options[:name], @record.send(column.name), record_select_options) - end + if multiple + record_multi_select_field(options[:name], value || [], record_select_options) + else + record_select_field(options[:name], value || column.association.klass.new, record_select_options) + end end def active_scaffold_input_checkbox(column, options) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index f6bb1106b8..0cf936595f 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -147,6 +147,24 @@ def active_scaffold_search_range(column, options) alias_method :active_scaffold_search_float, :active_scaffold_search_range alias_method :active_scaffold_search_string, :active_scaffold_search_range + def active_scaffold_search_record_select(column, options) + begin + value = field_search_params[column.name] + value = unless value.blank? + if column.options[:multiple] + column.association.klass.find value.collect!(&:to_i) + else + column.association.klass.find(value.to_i) + end + end + rescue Exception => e + logger.error Time.now.to_s + "Sorry, we are not that smart yet. Attempted to restore search values to search fields but instead got -- #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" + raise e + end + + active_scaffold_record_select(column, options, value, column.options[:multiple]) + end + def active_scaffold_search_datetime(column, options) options = column.options.merge(options) helper = "select_#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}" From dc6e96fb8095bed67249ee48199b3d7f0c06219f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Mar 2010 11:56:22 +0100 Subject: [PATCH 0240/2024] Fix restoring search param for boolean columns --- lib/active_scaffold/helpers/search_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 0cf936595f..25bc96cc88 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -114,7 +114,7 @@ def active_scaffold_search_boolean(column, options) select_options << [as_(:true), true] select_options << [as_(:false), false] - select_tag(options[:name], options_for_select(select_options, @record.send(column.name))) + select_tag(options[:name], options_for_select(select_options, column.column.type_cast(field_search_params[column.name]))) end # we can't use checkbox ui because it's not possible to decide whether search for this field or not alias_method :active_scaffold_search_checkbox, :active_scaffold_search_boolean From 7a5a986157b3b3ff19519fdbe58b74931380bc03 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Mar 2010 13:21:44 +0100 Subject: [PATCH 0241/2024] Fix inplace edit ajax for non association columns --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 42a68d962a..12157238b5 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -275,7 +275,7 @@ def active_scaffold_inplace_edit(record, column, options = {}) elsif column.inplace_edit == :ajax url = url_for(:action => 'render_field', :id => record.id, :column => column.name, :update_column => column.name, :in_place_editing => true, :escape => false) plural = column.plural_association? && !override_form_field?(column) && [:select, :record_select].include?(column.form_ui) - in_place_editor_options[:form_customization] = "element.setFieldFromAjax('#{escape_javascript(url)}', {plural: #{plural}});" + in_place_editor_options[:form_customization] = "element.setFieldFromAjax('#{escape_javascript(url)}', {plural: #{!!plural}});" elsif column.column.try(:type) == :text in_place_editor_options[:rows] = column.options[:rows] || 5 end From b83aa06011dd01704ba9e9152cc8ac438af87fb2 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Mar 2010 13:24:20 +0100 Subject: [PATCH 0242/2024] Fix inplace edit ajax in nested scaffolds --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 12157238b5..51d4ee16c5 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -273,7 +273,7 @@ def active_scaffold_inplace_edit(record, column, options = {}) :form_customization => 'element.clonePatternField();' ) elsif column.inplace_edit == :ajax - url = url_for(:action => 'render_field', :id => record.id, :column => column.name, :update_column => column.name, :in_place_editing => true, :escape => false) + url = url_for(:controller => params_for[:controller], :action => 'render_field', :id => record.id, :column => column.name, :update_column => column.name, :in_place_editing => true, :escape => false) plural = column.plural_association? && !override_form_field?(column) && [:select, :record_select].include?(column.form_ui) in_place_editor_options[:form_customization] = "element.setFieldFromAjax('#{escape_javascript(url)}', {plural: #{!!plural}});" elsif column.column.try(:type) == :text From 63f3a02660c99c2a506256e603b6ebfe9285e2ad Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Mar 2010 14:05:00 +0100 Subject: [PATCH 0243/2024] Fix ja localization --- lib/active_scaffold/locale/ja.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/locale/ja.yml b/lib/active_scaffold/locale/ja.yml index 5684d54ebd..7240a5dfa4 100644 --- a/lib/active_scaffold/locale/ja.yml +++ b/lib/active_scaffold/locale/ja.yml @@ -14,7 +14,7 @@ ja: create_new: '新規作成' customize: 'カスタマイズ' delete: '削除' - deleted_model: '%sを削除しました' + deleted_model: '{{model}}を削除しました' delimiter: 'Delimiter' # needed? download: 'ダウンロード' edit: '編集' From c72b7dddc1ab4b39bdf274a4e7b5fc6e02fee9ef Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Mar 2010 16:42:32 +0100 Subject: [PATCH 0244/2024] Translate true and false --- lib/active_scaffold/locale/en.rb | 2 ++ lib/active_scaffold/locale/es.yml | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 10a4c4f4f4..889587e8ea 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -22,6 +22,7 @@ :edit => 'Edit', :export => 'Export', :nested_for_model => '{{nested_model}} for {{parent_model}}', + :false => 'False', :filtered => '(Filtered)', :found => 'Found', :hide => 'Hide', @@ -48,6 +49,7 @@ :show => 'Show', :show_model => 'Show {{model}}', :_to_ => ' to ', + :true => 'True', :update => 'Update', :update_model => 'Update {{model}}', :updated_model => 'Updated {{model}}', diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index 72f71430ae..9e42da2807 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -20,7 +20,7 @@ es: download: 'Descargar' edit: 'Editar' export: 'Exportar' - nested_for_model: '{{nested_model}} de {{parent_model}}' + 'false': 'No' filtered: '(Filtrado)' found: one: 'encontrado' @@ -28,6 +28,7 @@ es: hide: 'Ocultar' live_search: 'Buscar en Vivo' loading: 'Cargando…' + nested_for_model: '{{nested_model}} de {{parent_model}}' next: 'Siguiente' no_entries: 'Sin entradas' no_options: 'sin opciones' @@ -49,6 +50,7 @@ es: show: 'Ver' show_model: 'Ver {{model}}' _to_ : ' a ' + 'true': 'Sí' update: 'Actualizar' update_model: 'Actualizar {{model}}' updated_model: '{{model}} actualizado' From 1b2d4cefbcdaffed4f5192515eb6d5f61792095e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Mar 2010 16:51:21 +0100 Subject: [PATCH 0245/2024] cleanup country and usa state selects --- lib/active_scaffold/helpers/country_helpers.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/helpers/country_helpers.rb b/lib/active_scaffold/helpers/country_helpers.rb index 06a376a36a..902412d862 100644 --- a/lib/active_scaffold/helpers/country_helpers.rb +++ b/lib/active_scaffold/helpers/country_helpers.rb @@ -330,17 +330,13 @@ def active_scaffold_input_country(column, options) priority = ["United States"] select_options = {:prompt => as_(:_select_)} select_options.merge!(options) - options.delete(:prompt) - country_select(:record, column.name, column.options[:priority] || priority, select_options, column.options.merge(options)) + country_select(:record, column.name, column.options[:priority] || priority, select_options, column.options.merge(options).except!(:prompt, :priority)) end def active_scaffold_input_usa_state(column, options) select_options = {:prompt => as_(:_select_)} select_options.merge!(options) - select_options.delete(:size) - options.delete(:prompt) - options.delete(:priority) - usa_state_select(:record, column.name, column.options[:priority], select_options, column.options.merge(options)) + usa_state_select(:record, column.name, column.options[:priority], select_options, column.options.merge(options).except!(:prompt, :priority)) end end end From 9295508b16b0b9fdc0860733167adf93bf25478c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 17 Mar 2010 17:39:12 +0100 Subject: [PATCH 0246/2024] Allow using multiple with country and usa state selects for search --- lib/active_scaffold/finder.rb | 2 +- .../helpers/country_helpers.rb | 53 +++++++++++-------- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 3622004747..87a48efcea 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -41,7 +41,7 @@ def condition_for_column(column, value, text_search = :full) case search_ui when :boolean, :checkbox ["#{column.search_sql} = ?", column.column.type_cast(value)] - when :select, :multi_select + when :select, :multi_select, :country, :usa_state ["#{column.search_sql} in (?)", value] else if column.column.nil? || column.column.text? diff --git a/lib/active_scaffold/helpers/country_helpers.rb b/lib/active_scaffold/helpers/country_helpers.rb index 902412d862..fd46de1f15 100644 --- a/lib/active_scaffold/helpers/country_helpers.rb +++ b/lib/active_scaffold/helpers/country_helpers.rb @@ -16,14 +16,13 @@ def usa_state_select(object, method, priority_states = nil, options = {}, html_o # # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag. def country_options_for_select(selected = nil, priority_countries = nil) - country_options = "" - if priority_countries - country_options += options_for_select(priority_countries, selected) - country_options += "<option value=\"\" disabled=\"disabled\">-------------</option>\n" + country_options = options_for_select(priority_countries.collect {|country| [I18n.t("countries.#{country}", :default => country.to_s.titleize), country.to_s]} + [['-------------', '']], :selected => selected, :disabled => '') + else + country_options = "" end - return country_options + options_for_select(COUNTRIES.collect {|country| [I18n.t("countries.#{country}", :default => country.to_s.titleize), country]}, selected) + return country_options + options_for_select(COUNTRIES.collect {|country| [I18n.t("countries.#{country}", :default => country.to_s.titleize), country.to_s]}, :selected => selected) end # Returns a string of option tags for the states in the United States. Supply a state name as +selected to @@ -31,16 +30,16 @@ def country_options_for_select(selected = nil, priority_countries = nil) # in case you want to highligh a local area # NOTE: Only the option tags are returned from this method, wrap it in a <select> def usa_state_options_for_select(selected = nil, priority_states = nil) - state_options = "" if priority_states - state_options += options_for_select(priority_states, selected) - state_options += "<option>-------------</option>\n" + state_options = options_for_select(priority_states + [['-------------', '']], :selected => selected, :disabled => '') + else + state_options = "" end if priority_states && priority_states.include?(selected) - state_options += options_for_select(USASTATES - priority_states, selected) + state_options += options_for_select(USASTATES - priority_states, :selected => selected) else - state_options += options_for_select(USASTATES, selected) + state_options += options_for_select(USASTATES, :selected => selected) end return state_options @@ -303,10 +302,11 @@ def to_country_select_tag(priority_countries, options, html_options) html_options = html_options.stringify_keys add_default_name_and_id(html_options) value = value(object) + selected_value = options.has_key?(:selected) ? options[:selected] : value content_tag("select", add_options( - country_options_for_select(value, priority_countries), - options, value + country_options_for_select(selected_value, priority_countries), + options, selected_value ), html_options ) end @@ -314,29 +314,38 @@ def to_country_select_tag(priority_countries, options, html_options) def to_usa_state_select_tag(priority_states, options, html_options) html_options = html_options.stringify_keys add_default_name_and_id(html_options) - value = value(object) if method(:value).arity > 0 - if html_options['name'].include?('search') - html_options['name'] << '[]' - html_options['multiple'] = true - options[:include_blank] = true - end - content_tag("select", add_options(usa_state_options_for_select(value, priority_states), options, value), html_options) + value = value(object) + selected_value = options.has_key?(:selected) ? options[:selected] : value + content_tag("select", add_options(usa_state_options_for_select(selected_value, priority_states), options, selected_value), html_options) end end end module FormColumnHelpers def active_scaffold_input_country(column, options) - priority = ["United States"] select_options = {:prompt => as_(:_select_)} select_options.merge!(options) - country_select(:record, column.name, column.options[:priority] || priority, select_options, column.options.merge(options).except!(:prompt, :priority)) + options.reverse_merge!(column.options).except!(:prompt, :priority) + options[:name] += '[]' if options[:multiple] + country_select(:record, column.name, column.options[:priority] || [:united_states], select_options, options) end def active_scaffold_input_usa_state(column, options) select_options = {:prompt => as_(:_select_)} select_options.merge!(options) - usa_state_select(:record, column.name, column.options[:priority], select_options, column.options.merge(options).except!(:prompt, :priority)) + options.reverse_merge!(column.options).except!(:prompt, :priority) + options[:name] += '[]' if options[:multiple] + usa_state_select(:record, column.name, column.options[:priority], select_options, options) + end + end + + module SearchColumnHelpers + def active_scaffold_search_country(column, options) + active_scaffold_input_country(column, options.merge!(:selected => options.delete(:value))) + end + + def active_scaffold_search_usa_state(column, options) + active_scaffold_input_usa_state(column, options.merge!(:selected => options.delete(:value))) end end end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 31088fd86f..ddbf7e4589 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -9,8 +9,8 @@ module ViewHelpers include ActiveScaffold::Helpers::ListColumnHelpers include ActiveScaffold::Helpers::ShowColumnHelpers include ActiveScaffold::Helpers::FormColumnHelpers - include ActiveScaffold::Helpers::CountryHelpers include ActiveScaffold::Helpers::SearchColumnHelpers + include ActiveScaffold::Helpers::CountryHelpers ## ## Delegates From 82a192196ffdd1d23f3401361b95595f498b06f0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 18 Mar 2010 09:30:08 +0100 Subject: [PATCH 0247/2024] Fix default value for allow_add_existing --- lib/active_scaffold/data_structures/column.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 87e9ef8691..c9fe9c86e7 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -19,7 +19,6 @@ def inplace_edit=(value) # Whether to enable add_existing for this column attr_accessor :allow_add_existing - @allow_add_existing = true # Any extra parameters this particular column uses. This is for create/update purposes. def params @@ -249,6 +248,7 @@ def initialize(name, active_record_class) #:nodoc: @actions_for_association_links = self.class.actions_for_association_links.clone if @association @options = {:format => :i18n_number} if @column.try(:number?) @form_ui = :checkbox if @column and @column.type == :boolean + @allow_add_existing = true # default all the configurable variables self.css_class = '' From c51f17d13ccf4f137c18583393c07caeee254cf5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 19 Mar 2010 16:19:48 +0100 Subject: [PATCH 0248/2024] don't duplicate iframe when a form with errors is submitted --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index ddbf7e4589..7b52af4a71 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -71,8 +71,8 @@ def form_remote_upload_tag(url_for_options = {}, options = {}) options[:multipart] = true output="" - output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>" output << form_tag(url_for_options, options) + output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>" end # Provides list of javascripts to include with +javascript_include_tag+ From e9e4c13b778288330ed3038fc3e4f52c17e44320 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 19 Mar 2010 16:21:12 +0100 Subject: [PATCH 0249/2024] Scroll to top of form when there are errors --- frontends/default/views/on_create.js.rjs | 8 +++++--- frontends/default/views/on_update.js.rjs | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index bc507a18c9..815f746c49 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -1,4 +1,5 @@ -cancel_selector = "##{element_form_id(:action => :create)} a.cancel".to_json +form = element_form_id(:action => :create) +cancel_selector = "##{form} a.cancel".to_json if controller.send :successful? if @insert_row @@ -19,8 +20,9 @@ if controller.send :successful? page << "if (link) (function() { link.action_link.open() }).defer();" end else - page << "l = $$(#{cancel_selector}).first().link;" - page.replace element_form_id(:action => :create), :partial => 'create_form', :locals => {:xhr => true} + page << "var l = $$(#{cancel_selector}).first().link;" + page.replace form, :partial => 'create_form', :locals => {:xhr => true} page << "l.register_cancel_hooks();" + page[form].scroll_to end page.replace_html active_scaffold_messages_id, :partial => 'messages' diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index de63b3687d..42783c4fda 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -1,12 +1,14 @@ -cancel_selector = "##{element_form_id(:action => :update)} a.cancel".to_json +form = element_form_id(:action => :update) +cancel_selector = "##{form} a.cancel".to_json if controller.send :successful? updated_row = render :partial => 'list_record', :locals => {:record => @record} page << "$$(#{cancel_selector}).first().link.close('#{escape_javascript(updated_row)}');" page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} else - page << "l = $$(#{cancel_selector}).first().link;" - page.replace element_form_id(:action => :update), :partial => 'update_form', :locals => {:xhr => true} + page << "var l = $$(#{cancel_selector}).first().link;" + page.replace form, :partial => 'update_form', :locals => {:xhr => true} page << "l.register_cancel_hooks();" + page[form].scroll_to end page.replace_html active_scaffold_messages_id, :partial => 'messages' From f8051c17b8bf957a5b6432b2ca411b29be7ef34e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 22 Mar 2010 12:39:58 +0100 Subject: [PATCH 0250/2024] Copy from edwinmoss SemanticAttributes integration --- lib/bridges/semantic_attributes/bridge.rb | 5 +++++ .../lib/semantic_attributes_bridge.rb | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 lib/bridges/semantic_attributes/bridge.rb create mode 100644 lib/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb diff --git a/lib/bridges/semantic_attributes/bridge.rb b/lib/bridges/semantic_attributes/bridge.rb new file mode 100644 index 0000000000..d676018d45 --- /dev/null +++ b/lib/bridges/semantic_attributes/bridge.rb @@ -0,0 +1,5 @@ +ActiveScaffold.bridge "SemanticAttributes" do + install do + require File.join(File.dirname(__FILE__), "lib/semantic_attributes_bridge.rb") + end +end diff --git a/lib/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb b/lib/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb new file mode 100644 index 0000000000..b953e038b8 --- /dev/null +++ b/lib/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb @@ -0,0 +1,20 @@ +module ActiveScaffold + module SemanticAttributesBridge + def self.included(base) + base.class_eval { alias_method_chain :initialize, :semantic_attributes } + end + + def initialize_with_semantic_attributes(name, active_record_class) + initialize_without_semantic_attributes(name, active_record_class) + self.required = !active_record_class.semantic_attributes[self.name].predicates.find {|p| p.allow_empty? == false }.nil? + active_record_class.semantic_attributes[self.name].predicates.find do |p| + sem_type = p.class.to_s.split('::')[1].underscore.to_sym + next if [:required, :association].include?(sem_type) + @form_ui = sem_type + end + end + end +end +ActiveScaffold::DataStructures::Column.class_eval do + include ActiveScaffold::SemanticAttributesBridge +end From 955bd198d0f84ac9e3277076088de5a2fef75609 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 22 Mar 2010 17:01:43 +0100 Subject: [PATCH 0251/2024] Improve has_many through associations support --- .../views/_form_association_footer.html.erb | 2 +- frontends/default/views/_nested.html.erb | 10 +---- lib/active_scaffold/attribute_params.rb | 2 +- lib/active_scaffold/constraints.rb | 10 +---- lib/active_scaffold/data_structures/column.rb | 1 - lib/active_scaffold/helpers/view_helpers.rb | 4 +- lib/extensions/reverse_associations.rb | 38 +++++++++++-------- 7 files changed, 28 insertions(+), 39 deletions(-) diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index 07824a1902..8ae4912a38 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -27,7 +27,7 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as <% if remote_controller and remote_controller.respond_to? :uses_record_select? and remote_controller.uses_record_select? -%> <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "new Ajax.Request(#{edit_associated_url.to_json}.sub('--ID--', id), {asynchronous: true, evalScripts: true, onFailure: function(){ActiveScaffold.report_500_response(#{active_scaffold_id.to_json})}});" -%> <% else -%> - <% select_options = options_for_select(options_for_association(column.association)) unless column.through_association? -%> + <% select_options = options_for_select(options_for_association(column.association)) -%> <%= select_tag 'associated_id', '<option value="">' + as_(:_select_) + '</option>' + select_options %> <%= button_to_function as_(:add_existing), "new Ajax.Request(#{edit_associated_url.to_json}.sub('--ID--', Element.previous(this).value), {asynchronous: true, method: 'get', evalScripts: true, onFailure: function(){ActiveScaffold.report_500_response(#{active_scaffold_id.to_json})}})" %> <% end -%> diff --git a/frontends/default/views/_nested.html.erb b/frontends/default/views/_nested.html.erb index 7922047827..131dac41e1 100644 --- a/frontends/default/views/_nested.html.erb +++ b/frontends/default/views/_nested.html.erb @@ -14,15 +14,7 @@ association = column.association # determine what constraints we need - if column.through_association? - @constraints = { - association.source_reflection.reverse => { - association.through_reflection.reverse => parent_id - } - } - else - @constraints = { association.reverse => parent_id } - end + @constraints = { association.reverse => parent_id } # generate the customized label @label = as_(:nested_for_model, :nested_model => active_scaffold_config_for(association.klass).list.label, :parent_model => format_value(@record.to_label)) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 747153256f..14f076fd1e 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -58,7 +58,7 @@ def update_record_from_params(parent_record, columns, attributes) value = column_value_from_param_value(parent_record, column, attributes[column.name]) # we avoid assigning a value that already exists because otherwise has_one associations will break (AR bug in has_one_association.rb#replace) - parent_record.send("#{column.name}=", value) unless column.through_association? or parent_record.send(column.name) == value + parent_record.send("#{column.name}=", value) unless parent_record.send(column.name) == value # plural associations may not actually appear in the params if all of the options have been unselected or cleared away. # NOTE: the "form_ui" check isn't really necessary, except that without it we have problems diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 0a24256ecb..4dbf864852 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -141,15 +141,7 @@ def apply_constraints_to_record(record, options = {}) active_scaffold_constraints.each do |k, v| column = active_scaffold_config.columns[k] if column and column.association - if v.is_a? Hash # reverse of a through association ... we need to set the far association - # example - # data model: Park -> Den -> Bear - # constraint: :den => {:park => 5} - # remote_klass: Park - remote_klass = column.association.klass.reflect_on_association(v.keys.first).klass - first_associated = record.send("#{k}") - first_associated.send("#{v.keys.first}=", remote_klass.find(v.values.first)) if first_associated - elsif column.plural_association? + if column.plural_association? record.send("#{k}").send(:<<, column.association.klass.find(v)) elsif column.association.options[:polymorphic] record.send("#{k}=", params[:parent_model].constantize.find(v)) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index c9fe9c86e7..0babd5a86e 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -181,7 +181,6 @@ def associated_number? attr_writer :show_blank_record def show_blank_record?(associated) if @show_blank_record - return false if self.through_association? return false unless self.association.klass.authorized_for?(:crud_type => :create) self.plural_association? or (self.singular_association? and associated.empty?) end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 7b52af4a71..ac7f21d283 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -195,11 +195,11 @@ def column_calculation(column) end def column_show_add_existing(column) - (column.allow_add_existing and !column.through_association? and options_for_association_count(column.association) > 0) + (column.allow_add_existing and options_for_association_count(column.association) > 0) end def column_show_add_new(column, associated, record) - value = !column.through_association? and (column.plural_association? or (column.singular_association? and not associated.empty?)) + value = column.plural_association? or (column.singular_association? and not associated.empty?) value = false unless record.class.authorized_for?(:crud_type => :create) value end diff --git a/lib/extensions/reverse_associations.rb b/lib/extensions/reverse_associations.rb index f7a687f473..d17e119bb2 100644 --- a/lib/extensions/reverse_associations.rb +++ b/lib/extensions/reverse_associations.rb @@ -22,22 +22,28 @@ def reverse_matches_for(klass) # stage 1 filter: collect associations that point back to this model and use the same primary_key_name klass.reflect_on_all_associations.each do |assoc| - # skip over has_many :through associations - next if assoc.options[:through] - - next unless assoc.options[:polymorphic] or assoc.class_name.constantize == self.active_record - case [assoc.macro, self.macro].find_all{|m| m == :has_and_belongs_to_many}.length - # if both are a habtm, then match them based on the join table - when 2 - next unless assoc.options[:join_table] == self.options[:join_table] - - # if only one is a habtm, they do not match - when 1 - next - - # otherwise, match them based on the primary_key_name - when 0 - next unless assoc.primary_key_name.to_sym == self.primary_key_name.to_sym + if self.options[:through] + # only iterate has_many :through associations + next unless assoc.options[:through] + next unless assoc.through_reflection.klass == self.through_reflection.klass + else + # skip over has_many :through associations + next if assoc.options[:through] + next unless assoc.options[:polymorphic] or assoc.class_name.constantize == self.active_record + + case [assoc.macro, self.macro].find_all{|m| m == :has_and_belongs_to_many}.length + # if both are a habtm, then match them based on the join table + when 2 + next unless assoc.options[:join_table] == self.options[:join_table] + + # if only one is a habtm, they do not match + when 1 + next + + # otherwise, match them based on the primary_key_name + when 0 + next unless assoc.primary_key_name.to_sym == self.primary_key_name.to_sym + end end reverse_matches << assoc From 45ac37978f9d2d956054ba6e4b5a9c06d06b523b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 23 Mar 2010 16:52:01 +0100 Subject: [PATCH 0252/2024] Fix file_column bridge to work with validation_reflection bridge in all ruby versions --- lib/bridges/file_column/lib/as_file_column_bridge.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/bridges/file_column/lib/as_file_column_bridge.rb b/lib/bridges/file_column/lib/as_file_column_bridge.rb index a375a74378..72df7195af 100644 --- a/lib/bridges/file_column/lib/as_file_column_bridge.rb +++ b/lib/bridges/file_column/lib/as_file_column_bridge.rb @@ -1,8 +1,5 @@ -require 'active_scaffold/data_structures/column' -module ActiveScaffold::DataStructures - class Column - attr_accessor :file_column_display - end +class ActiveScaffold::DataStructures::Column.class_eval do + attr_accessor :file_column_display end module ActiveScaffold::Config @@ -46,4 +43,4 @@ def configure_file_column_field(field) end end -end \ No newline at end of file +end From 1f42ebb04389141f6d9a18e998dd9dd38d10a5c5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 23 Mar 2010 16:55:36 +0100 Subject: [PATCH 0253/2024] Fix gsub in a symbol --- lib/active_scaffold/helpers/id_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index 2d8de32dbc..0dd639f49b 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -3,7 +3,7 @@ module Helpers # A bunch of helper methods to produce the common view ids module IdHelpers def id_from_controller(controller) - controller.gsub("/", "__") + controller.to_s.gsub("/", "__") end def controller_id From 5cc8d77076e6ebdb2ec9e9990a7d37bd1043a92f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 23 Mar 2010 17:46:52 +0100 Subject: [PATCH 0254/2024] Fix file_column bridge to work with validation_reflection bridge in all ruby versions --- lib/bridges/file_column/lib/as_file_column_bridge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bridges/file_column/lib/as_file_column_bridge.rb b/lib/bridges/file_column/lib/as_file_column_bridge.rb index 72df7195af..6f9cfb1813 100644 --- a/lib/bridges/file_column/lib/as_file_column_bridge.rb +++ b/lib/bridges/file_column/lib/as_file_column_bridge.rb @@ -1,4 +1,4 @@ -class ActiveScaffold::DataStructures::Column.class_eval do +ActiveScaffold::DataStructures::Column.class_eval do attr_accessor :file_column_display end From b6bb0daa65184edc085939a63105cef4ae3eed2a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 24 Mar 2010 16:53:37 +0100 Subject: [PATCH 0255/2024] Allow empty date columns if column can be null --- lib/active_scaffold/helpers/form_column_helpers.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 1e4833bfa3..5c95236dd1 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -35,7 +35,8 @@ def active_scaffold_input_for(column, scope = nil, options = {}) options[:maxlength] = column.column.limit options[:size] ||= ActionView::Helpers::InstanceTag::DEFAULT_FIELD_OPTIONS["size"] end - options.update(:value => format_number_value(@record.send(column.name), column.options)) if column.column.number? + options[:include_blank] = true if column.column.null and [:date, :datetime, :time].include?(column.column.type) + options[:value] = format_number_value(@record.send(column.name), column.options) if column.column.number? input(:record, column.name, options.merge(column.options)) end end From facaeb92bd7cf25f026e7122d94f6ce37b2a4eb0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 25 Mar 2010 12:09:03 +0100 Subject: [PATCH 0256/2024] add some methods for testing using shoulda and mocha --- shoulda_macros/macros.rb | 78 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 shoulda_macros/macros.rb diff --git a/shoulda_macros/macros.rb b/shoulda_macros/macros.rb new file mode 100644 index 0000000000..11754ffbb5 --- /dev/null +++ b/shoulda_macros/macros.rb @@ -0,0 +1,78 @@ +class ActiveSupport::TestCase + def self.should_have_columns_in(action, *columns) + should "have columns in #{action}" do + assert_equal columns, @controller.active_scaffold_config.send(action).columns.map(&:name) + end + end + + def self.should_include_columns_in(action, *columns) + should "include columns in #{action}" do + action_columns = @controller.active_scaffold_config.send(action).columns.map(&:name) + columns.each do |column| + assert action_columns.include?(column.to_sym) + end + end + end + + def self.should_not_include_columns_in(action, *columns) + should "not include columns in #{action}" do + action_columns = @controller.active_scaffold_config.send(action).columns.map(&:name) + columns.each do |column| + assert !action_columns.include?(column.to_sym) + end + end + end + + def self.should_render_as_form_ui(column_name, form_ui) + before_should "render column #{column_name} as #{form_ui} form_ui" do + column = @controller.active_scaffold_config.columns[column_name] + ActionView::Base.any_instance.expects(:"active_scaffold_input_#{form_ui}").with(column, is_a(Hash)) + assert_equal form_ui, column.form_ui + end + end + + def self.should_render_as_form_override(column_name) + should "render column #{column_name} as form override" do + column = @controller.active_scaffold_config.columns[column_name] + assert @response.template.override_form_field?(column) + assert_template :partial => "_#{column_name}_form_column", :count => 0 + end + end + + def self.should_render_as_form_partial_override(column_name) + should "render column #{column_name} as form partial override" do + assert_template :partial => "_#{column_name}_form_column" + end + end + + def self.should_render_as_list_ui(column_name, list_ui) + before_should "render column #{column_name} as #{list_ui} list_ui" do + column = @controller.active_scaffold_config.columns[column_name] + ActionView::Base.any_instance.expects(:"active_scaffold_column_#{list_ui}").with(column, is_a(@controller.active_scaffold_config.model)) + assert_equal list_ui, column.list_ui + end + end + + def self.should_render_as_field_override(column_name) + should "render column #{column_name} as field override" do + column = @controller.active_scaffold_config.columns[column_name] + assert @response.template.override_form_field?(column) + assert_template :partial => "_#{column_name}_column", :count => 0 + end + end + + def self.should_render_as_field_partial_override(column_name) + should "render column #{column_name} as field partial override" do + assert_template :partial => "_#{column_name}_column" + end + end + + def self.should_render_as_inplace_edit(column_name) + before_should "render column #{column_name} as inplace edit" do + column = @controller.active_scaffold_config.columns[column_name] + method = column.list_ui == :checkbox ? :format_column_checkbox : :active_scaffold_inplace_edit + ActionView::Base.any_instance.expects(method).with(is_a(@controller.active_scaffold_config.model), column, optionally(is_a(Hash))) + assert column.inplace_edit + end + end +end From 83181bd9c86ad6f2bc8d322269c07b3db3bc2b72 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 25 Mar 2010 14:26:47 +0100 Subject: [PATCH 0257/2024] Don't include associations in calculations query if it's possible --- lib/active_scaffold/helpers/view_helpers.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index ac7f21d283..cc0afe8c83 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -190,8 +190,11 @@ def column_empty?(column_value) end def column_calculation(column) - calculation = active_scaffold_config.model.calculate(column.calculate, column.name, :conditions => controller.send(:all_conditions), - :joins => controller.send(:joins_for_collection), :include => controller.send(:active_scaffold_includes)) + conditions = controller.send(:all_conditions) + includes = active_scaffold_config.list.count_includes + includes ||= controller.send(:active_scaffold_includes) unless conditions.nil? + calculation = active_scaffold_config.model.calculate(column.calculate, column.name, :conditions => conditions, + :joins => controller.send(:joins_for_collection), :include => includes) end def column_show_add_existing(column) From 2d16759acc12fc64946a4370ceb935ed55ab235b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 25 Mar 2010 14:37:51 +0100 Subject: [PATCH 0258/2024] Update calculations after update a column with inplace edit --- frontends/default/views/_list_calculations.html.erb | 11 ++--------- frontends/default/views/update_column.js.rjs | 1 + lib/active_scaffold/helpers/id_helpers.rb | 4 ++-- lib/active_scaffold/helpers/view_helpers.rb | 8 ++++++++ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/frontends/default/views/_list_calculations.html.erb b/frontends/default/views/_list_calculations.html.erb index a3becfab68..67097e6d18 100644 --- a/frontends/default/views/_list_calculations.html.erb +++ b/frontends/default/views/_list_calculations.html.erb @@ -1,16 +1,9 @@ <% display_class = ( @records.kind_of?(Array) ? @records.first : @records ) -%> <tr id="<%= active_scaffold_calculations_id %>" class="active-scaffold-calculations"> <% active_scaffold_config.list.columns.each do |column| -%> - <td> + <td id="<%= active_scaffold_calculations_id(column) if column.calculation? %>"> <% if column.calculation? -%> - <% - calculation = column_calculation(column) - - override_formatter = "render_#{column.name}_#{column.calculate}" - calculation = self.method(override_formatter).call(calculation) if respond_to? override_formatter - - -%> - <%= as_(column.calculate) %>: <%= calculation.to_s %> + <%= render_column_calculation(column) %> <% else -%>   <% end -%> diff --git a/frontends/default/views/update_column.js.rjs b/frontends/default/views/update_column.js.rjs index cf87bd9a2f..9c19a18e79 100644 --- a/frontends/default/views/update_column.js.rjs +++ b/frontends/default/views/update_column.js.rjs @@ -10,3 +10,4 @@ else formatted_value = get_column_value(@record, column) page.replace_html(column_span_id, formatted_value) end +page.replace_html(active_scaffold_calculations_id(column), render_column_calculation(column)) if column.calculation? diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index 0dd639f49b..3cf7f9146a 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -26,8 +26,8 @@ def active_scaffold_messages_id "#{controller_id}-messages" end - def active_scaffold_calculations_id - "#{controller_id}-calculations" + def active_scaffold_calculations_id(column = nil) + "#{controller_id}-calculations#{'-' + column.name.to_s if column}" end def empty_message_id diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index cc0afe8c83..59001ade8f 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -197,6 +197,14 @@ def column_calculation(column) :joins => controller.send(:joins_for_collection), :include => includes) end + def render_column_calculation(column) + calculation = column_calculation(column) + override_formatter = "render_#{column.name}_#{column.calculate}" + calculation = send(override_formatter, calculation) if respond_to? override_formatter + + "#{as_(column.calculate)}: #{calculation}" + end + def column_show_add_existing(column) (column.allow_add_existing and options_for_association_count(column.association) > 0) end From 2623c891b84c37846a60a8d4a9e12222b420aec0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 26 Mar 2010 11:42:21 +0100 Subject: [PATCH 0259/2024] fix shoulda macros for form_ui, list_ui and inplace_edit when multiple columns uses the same ui or inplace_edit --- shoulda_macros/macros.rb | 42 +++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/shoulda_macros/macros.rb b/shoulda_macros/macros.rb index 11754ffbb5..bc829f150c 100644 --- a/shoulda_macros/macros.rb +++ b/shoulda_macros/macros.rb @@ -24,10 +24,15 @@ def self.should_not_include_columns_in(action, *columns) end def self.should_render_as_form_ui(column_name, form_ui) - before_should "render column #{column_name} as #{form_ui} form_ui" do - column = @controller.active_scaffold_config.columns[column_name] - ActionView::Base.any_instance.expects(:"active_scaffold_input_#{form_ui}").with(column, is_a(Hash)) - assert_equal form_ui, column.form_ui + should "render column #{column_name} as #{form_ui} form_ui", :before => lambda{ + @rendered_columns = [] + ActionView::Base.any_instance.expects(:"active_scaffold_input_#{form_ui}").at_least_once.with {|column, options| + @rendered_columns << column.name + true + } + } do + assert_equal form_ui, @controller.active_scaffold_config.columns[column_name].form_ui + assert @rendered_columns.include?(column_name) end end @@ -46,10 +51,15 @@ def self.should_render_as_form_partial_override(column_name) end def self.should_render_as_list_ui(column_name, list_ui) - before_should "render column #{column_name} as #{list_ui} list_ui" do - column = @controller.active_scaffold_config.columns[column_name] - ActionView::Base.any_instance.expects(:"active_scaffold_column_#{list_ui}").with(column, is_a(@controller.active_scaffold_config.model)) - assert_equal list_ui, column.list_ui + should "render column #{column_name} as #{list_ui} list_ui", :before => lambda{ + @rendered_columns = [] + ActionView::Base.any_instance.expects(:"active_scaffold_column_#{list_ui}").at_least_once.with {|column, options| + @rendered_columns << column.name + true + } + } do + assert_equal list_ui, @controller.active_scaffold_config.columns[column_name].list_ui + assert @rendered_columns.include?(column_name) end end @@ -68,11 +78,17 @@ def self.should_render_as_field_partial_override(column_name) end def self.should_render_as_inplace_edit(column_name) - before_should "render column #{column_name} as inplace edit" do - column = @controller.active_scaffold_config.columns[column_name] - method = column.list_ui == :checkbox ? :format_column_checkbox : :active_scaffold_inplace_edit - ActionView::Base.any_instance.expects(method).with(is_a(@controller.active_scaffold_config.model), column, optionally(is_a(Hash))) - assert column.inplace_edit + should "render column #{column_name} as inplace edit", :before => lambda{ + @column = @controller.active_scaffold_config.columns[column_name] + @rendered_columns = [] + method = @column.list_ui == :checkbox ? :format_column_checkbox : :active_scaffold_inplace_edit + ActionView::Base.any_instance.expects(method).at_least_once.with {|model, column, options| + @rendered_columns << column.name + true + } + } do + assert @column.inplace_edit + assert @rendered_columns.include?(column_name) end end end From 7cfe6f73762ca1942bb8e7bb6bc4a2bec148c7c8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 26 Mar 2010 13:29:37 +0100 Subject: [PATCH 0260/2024] Fix update subform when a column changes --- frontends/default/views/render_field.js.rjs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/render_field.js.rjs b/frontends/default/views/render_field.js.rjs index 071ada8605..aa4449435e 100644 --- a/frontends/default/views/render_field.js.rjs +++ b/frontends/default/views/render_field.js.rjs @@ -1,8 +1,13 @@ @update_columns.each do |update_column| column = update_column while column - field_id = active_scaffold_input_options(column, params[:scope])[:id] - page[field_id].up('dl').replace :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } + if column_renders_as(column) == :subform + field_id = sub_form_id(:association => column.name) + page[field_id].replace_html :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } + else + field_id = active_scaffold_input_options(column, params[:scope])[:id] + page[field_id].up('dl').replace :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } + end column = Hash === column.options ? column.options[:update_column] : nil column = active_scaffold_config.columns[column] if column end From b33b283430b69003782eb8b4c8ffee3e5151d367 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 29 Mar 2010 09:35:26 +0200 Subject: [PATCH 0261/2024] Fix #739, recognize action link with put method --- frontends/default/javascripts/active_scaffold.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 97552d4486..41f29d9e9a 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -201,6 +201,8 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ this.method = 'delete'; } else if(this.url.match('_method=post')){ this.method = 'post'; + } else if(this.url.match('_method=put')){ + this.method = 'put'; } this.target = target; this.loading_indicator = loading_indicator; From f17d3d978f384db763fac5dfc07e7f56e45b1f0b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 29 Mar 2010 10:08:16 +0200 Subject: [PATCH 0262/2024] Fix #740, format calculation using options[:format] --- lib/active_scaffold/helpers/list_column_helpers.rb | 4 ++-- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 51d4ee16c5..f10674538d 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -150,8 +150,8 @@ def format_column_checkbox(record, column) check_box(:record, column.name, :onclick => script, :id => nil, :object => record) end - def format_column_value(record, column) - value = record.send(column.name) + def format_column_value(record, column, value = nil) + value ||= record.send(column.name) if value && column.association # cache association size before calling column_empty? associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association cache_association(value, column) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 59001ade8f..dd83646110 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -202,7 +202,7 @@ def render_column_calculation(column) override_formatter = "render_#{column.name}_#{column.calculate}" calculation = send(override_formatter, calculation) if respond_to? override_formatter - "#{as_(column.calculate)}: #{calculation}" + "#{as_(column.calculate)}: #{format_column_value nil, column, calculation}" end def column_show_add_existing(column) From 37338324cef18898fd28a3b46c30684f4e56a038 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 29 Mar 2010 10:50:09 +0200 Subject: [PATCH 0263/2024] Fix remembering value in calendar_date_select and datetime search ui --- lib/active_scaffold/finder.rb | 2 +- lib/active_scaffold/helpers/search_column_helpers.rb | 10 +++++++--- lib/bridges/calendar_date_select/lib/as_cds_bridge.rb | 7 ++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 87a48efcea..12d1ebc877 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -87,7 +87,7 @@ def condition_for_range_type(column, value, like_pattern = nil) def condition_for_datetime_type(column, value, like_pattern = nil) conversion = value[:from][:hour].blank? && value[:to][:hour].blank? ? :to_date : :to_time from_value, to_value = [:from, :to].collect do |field| - Time.zone.local(*[:year, :month, :day, :hour, :minutes, :seconds].collect {|part| value[field][part].to_i}) rescue nil + Time.zone.local(*[:year, :month, :day, :hour, :minute, :second].collect {|part| value[field][part].to_i}) rescue nil end if from_value.nil? and to_value.nil? diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 25bc96cc88..c0c0c4035f 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -120,7 +120,6 @@ def active_scaffold_search_boolean(column, options) alias_method :active_scaffold_search_checkbox, :active_scaffold_search_boolean def field_search_params_range_values(column) - search_ui = column.search_ui || column.column.type values = field_search_params[column.name] return nil if values.nil? return values[:opt], values[:from], values[:to] @@ -164,13 +163,18 @@ def active_scaffold_search_record_select(column, options) active_scaffold_record_select(column, options, value, column.options[:multiple]) end + + def field_search_datetime_value(value) + DateTime.new(value[:year].to_i, value[:month].to_i, value[:day].to_i, value[:hour].to_i, value[:minute].to_i, value[:second].to_i) unless value.nil? || value[:year].blank? + end def active_scaffold_search_datetime(column, options) + opt_value, from_value, to_value = field_search_params_range_values(column) options = column.options.merge(options) helper = "select_#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}" html = [] - html << send(helper, nil, {:include_blank => true, :prefix => "#{options[:name]}[from]"}.merge(options)) - html << send(helper, nil, {:include_blank => true, :prefix => "#{options[:name]}[to]"}.merge(options)) + html << send(helper, field_search_datetime_value(from_value), {:include_blank => true, :prefix => "#{options[:name]}[from]"}.merge(options)) + html << send(helper, field_search_datetime_value(to_value), {:include_blank => true, :prefix => "#{options[:name]}[to]"}.merge(options)) html * ' - ' end diff --git a/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb index 19eae5745d..461f5f6547 100644 --- a/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb +++ b/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb @@ -32,11 +32,12 @@ def active_scaffold_input_calendar_date_select(column, options) module SearchColumnHelpers def active_scaffold_search_calendar_date_select(column, options) - options = column.options.merge(options) + opt_value, from_value, to_value = field_search_params_range_values(column) + options = column.options.merge(options).except!(:include_blank) helper = "select_#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}" html = [] - html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[from]", :id => "#{options[:id]}_from")) - html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[to]", :id => "#{options[:id]}_to")) + html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[from]", :id => "#{options[:id]}_from", :value => from_value)) + html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[to]", :id => "#{options[:id]}_to", :value => to_value)) html * ' - ' end end From 01e82ca7fd788c4fc5942ca83ef843e8016799b3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 29 Mar 2010 14:12:28 +0200 Subject: [PATCH 0264/2024] Fix render :super from HAML views --- lib/extensions/action_view_rendering.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index 0fcc6cd0e9..d3f7b02356 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -34,6 +34,7 @@ def render_with_active_scaffold(*args, &block) # solution is to count colons from the *right* of the string, not the left. see issue #299. template_path = caller.find{|c| known_extensions.include?(c.split(':')[-3].split('.').last.to_sym) } template = File.basename(template_path.split(':')[-3]) + template, format = template.split('.') # paths previous to current template_path must be ignored to avoid infinite loops when is called twice or more index = 0 @@ -42,8 +43,8 @@ def render_with_active_scaffold(*args, &block) end controller.class.active_scaffold_paths.slice(index..-1).each do |active_scaffold_template_path| - active_scaffold_template = File.join(active_scaffold_template_path, template) - return render(:file => active_scaffold_template, :locals => options[:locals]) if File.file? active_scaffold_template + active_scaffold_template = ActionView::PathSet.new([active_scaffold_template_path]).find_template_without_active_scaffold(template, format, false) rescue nil + return render(:file => active_scaffold_template, :locals => options[:locals]) if active_scaffold_template end elsif args.first.is_a?(Hash) and args.first[:active_scaffold] require 'digest/md5' From 8fdb2d9226b802698d4c2bc4c3b356900e8a1e14 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 29 Mar 2010 14:52:28 +0200 Subject: [PATCH 0265/2024] Improve render :super --- lib/extensions/action_view_rendering.rb | 6 ++---- .../javascripts/active_scaffold/default/active_scaffold.js | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index d3f7b02356..baee4a73ca 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -42,10 +42,8 @@ def render_with_active_scaffold(*args, &block) index = i + 1 and break if template_path.include? active_scaffold_template_path end - controller.class.active_scaffold_paths.slice(index..-1).each do |active_scaffold_template_path| - active_scaffold_template = ActionView::PathSet.new([active_scaffold_template_path]).find_template_without_active_scaffold(template, format, false) rescue nil - return render(:file => active_scaffold_template, :locals => options[:locals]) if active_scaffold_template - end + active_scaffold_template = controller.class.active_scaffold_paths.slice(index..-1).find_template(template, format, false) + render(:file => active_scaffold_template, :locals => options[:locals]) elsif args.first.is_a?(Hash) and args.first[:active_scaffold] require 'digest/md5' options = args.first diff --git a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js index 97552d4486..41f29d9e9a 100644 --- a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +++ b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js @@ -201,6 +201,8 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ this.method = 'delete'; } else if(this.url.match('_method=post')){ this.method = 'post'; + } else if(this.url.match('_method=put')){ + this.method = 'put'; } this.target = target; this.loading_indicator = loading_indicator; From 59d5925837deed9b6bf9870b93478667818af9f6 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Mar 2010 13:23:07 +0200 Subject: [PATCH 0266/2024] Translate select and radio options --- lib/active_scaffold/helpers/form_column_helpers.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 5c95236dd1..96ee1b6f9d 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -129,6 +129,11 @@ def active_scaffold_input_plural_association(column, options) html end + def active_scaffold_translated_option(column, text, value = nil) + value ||= text + [(text.is_a?(Symbol) ? column.active_record_class.human_attribute_name(text) : text), value] + end + def active_scaffold_input_select(column, html_options) if column.singular_association? active_scaffold_input_singular_association(column, html_options) @@ -136,7 +141,9 @@ def active_scaffold_input_select(column, html_options) active_scaffold_input_plural_association(column, html_options) else options = { :selected => @record.send(column.name) } - options_for_select = column.options[:options] + options_for_select = column.options[:options].collect do |(text, value)| + active_scaffold_translated_option(column, text, value) + end html_options.update(column.options[:html_options] || {}) options.update(column.options) select(:record, column.name, options_for_select, options, html_options) @@ -146,8 +153,8 @@ def active_scaffold_input_select(column, html_options) def active_scaffold_input_radio(column, html_options) html_options.update(column.options[:html_options] || {}) column.options[:options].inject('') do |html, (text, value)| - value ||= text - html << content_tag(:label, radio_button(:record, column.name, value, html_options.merge(:id => html_options[:id] + '-' + value)) + text) + text, value = active_scaffold_translated_option(column, text, value) + html << content_tag(:label, radio_button(:record, column.name, value, html_options.merge(:id => html_options[:id] + '-' + value.to_s)) + text) end end From b51e3cd45abe5379decf0a06351b783ee706a766 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Mar 2010 14:04:06 +0200 Subject: [PATCH 0267/2024] Support conditions for integer and string columns with an override which sends a simple value --- lib/active_scaffold/finder.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 12d1ebc877..0df752495f 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -58,19 +58,27 @@ def condition_for_column(column, value, text_search = :full) end def condition_for_integer_type(column, value, like_pattern = nil) - if value[:from].blank? or not ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) + if !value.is_a?(Hash) + ["#{column.search_sql} = ?", column.column.type_cast(value)] + elsif value[:from].blank? or not ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) nil elsif value[:opt] == 'BETWEEN' - ["#{column.search_sql} BETWEEN ? AND ?", value[:from].to_f, value[:to].to_f] + ["#{column.search_sql} BETWEEN ? AND ?", column.column.type_cast(value[:from]), column.column.type_cast(value[:to])] else - ["#{column.search_sql} #{value[:opt]} ?", value[:from].to_f] + ["#{column.search_sql} #{value[:opt]} ?", column.column.type_cast(value[:from])] end end alias_method :condition_for_decimal_type, :condition_for_integer_type alias_method :condition_for_float_type, :condition_for_integer_type def condition_for_range_type(column, value, like_pattern = nil) - if value[:from].blank? + if !value.is_a?(Hash) + if column.column.nil? || column.column.text? + ["LOWER(#{column.search_sql}) LIKE ?", like_pattern.sub('?', value.downcase)] + else + ["#{column.search_sql} = ?", column.column.type_cast(value)] + end + elsif value[:from].blank? nil elsif ActiveScaffold::Finder::StringComparators.values.include?(value[:opt]) ["#{column.search_sql} LIKE ?", value[:opt].sub('?', value[:from])] From 790e8ad0fc21b3dabc555b81de0beb5ce651cf2a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Mar 2010 16:14:34 +0200 Subject: [PATCH 0268/2024] Merge live_search into search --- frontends/default/views/_search.html.erb | 11 ++++++++-- lib/active_scaffold/config/field_search.rb | 12 +++++++++++ lib/active_scaffold/config/search.rb | 25 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index c0bb128dae..f0fd86c975 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -1,3 +1,4 @@ +<% live_search = active_scaffold_config.search.live? -%> <% href = url_for(params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'}) -%> <%= form_remote_tag :url => href, :method => :get, @@ -7,7 +8,7 @@ :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> <%= text_field_tag :search, search_params, :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> - <%= submit_tag as_(:search), :class => "submit" %> + <%= submit_tag as_(:search), :class => "submit" unless live_search %> <%= link_to_remote as_(:reset), {:url => href, :with => "'search='", :method => :get, :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')"}, :class => 'cancel' %> <%= loading_indicator_tag(:action => :search) %> @@ -15,6 +16,12 @@ <script type="text/javascript"> //<![CDATA[ - new TextFieldWithExample('<%= search_input_id %>', '<%= as_(:search_terms) %>', {focus: true}); + new TextFieldWithExample('<%= search_input_id %>', '<%= as_(live_search ? :live_search : :search_terms) %>', {focus: true}); +<% if live_search -%> + new Form.Element.Observer('<%= search_input_id %>', 1.5, function(element, value) { + if (!$(element.id)) return false; // because the element may have been destroyed + $(element).up('form').onsubmit(); + }); +<% end -%> //]]> </script> diff --git a/lib/active_scaffold/config/field_search.rb b/lib/active_scaffold/config/field_search.rb index b5a6ba9757..1286b68829 100644 --- a/lib/active_scaffold/config/field_search.rb +++ b/lib/active_scaffold/config/field_search.rb @@ -18,6 +18,12 @@ def initialize(core_config) cattr_reader :link @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) + # A flag for how the search should do full-text searching in the database: + # * :full: LIKE %?% + # * :start: LIKE ?% + # * :end: LIKE %? + # * false: LIKE ? + # Default is :full cattr_accessor :text_search @@text_search = :full @@ -36,6 +42,12 @@ def columns public :columns= + # A flag for how the search should do full-text searching in the database: + # * :full: LIKE %?% + # * :start: LIKE ?% + # * :end: LIKE %? + # * false: LIKE ? + # Default is :full attr_accessor :text_search # the ActionLink for this action diff --git a/lib/active_scaffold/config/search.rb b/lib/active_scaffold/config/search.rb index 161eef6cea..3447ed697f 100644 --- a/lib/active_scaffold/config/search.rb +++ b/lib/active_scaffold/config/search.rb @@ -6,6 +6,7 @@ def initialize(core_config) @core = core_config @text_search = self.class.text_search + @live = self.class.live? # start with the ActionLink defined globally @link = self.class.link.clone @@ -18,9 +19,21 @@ def initialize(core_config) cattr_accessor :link @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) + # A flag for how the search should do full-text searching in the database: + # * :full: LIKE %?% + # * :start: LIKE ?% + # * :end: LIKE %? + # * false: LIKE ? + # Default is :full cattr_accessor :text_search @@text_search = :full + # whether submits the search as you type + cattr_writer :live + def self.live? + @@live + end + # instance-level configuration # ---------------------------- @@ -35,9 +48,21 @@ def columns public :columns= + # A flag for how the search should do full-text searching in the database: + # * :full: LIKE %?% + # * :start: LIKE ?% + # * :end: LIKE %? + # * false: LIKE ? + # Default is :full attr_accessor :text_search # the ActionLink for this action attr_accessor :link + + # whether submits the search as you type + attr_writer :live + def live? + @live + end end end From db081cc3e5cb6ad05b648fa0524e0c55eecfe2a3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Mar 2010 16:23:41 +0200 Subject: [PATCH 0269/2024] Don't disable the form in live search --- frontends/default/views/_search.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index f0fd86c975..2f44fc6943 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -3,8 +3,8 @@ <%= form_remote_tag :url => href, :method => :get, :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", - :after => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{search_form_id}');", - :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{search_form_id}');", + :after => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'visible';#{"Form.disable('#{search_form_id}');" unless live_search }", + :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden';#{"Form.enable('#{search_form_id}');" unless live_search }", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> <%= text_field_tag :search, search_params, :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> From ddf9c752f9365a2aa72a2a94221c9b40416e40aa Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Mar 2010 16:29:27 +0200 Subject: [PATCH 0270/2024] Remove LiveSearch --- frontends/default/views/_live_search.html.erb | 23 -------- lib/active_scaffold/actions/live_search.rb | 55 ------------------- lib/active_scaffold/config/live_search.rb | 43 --------------- 3 files changed, 121 deletions(-) delete mode 100644 frontends/default/views/_live_search.html.erb delete mode 100644 lib/active_scaffold/actions/live_search.rb delete mode 100644 lib/active_scaffold/config/live_search.rb diff --git a/frontends/default/views/_live_search.html.erb b/frontends/default/views/_live_search.html.erb deleted file mode 100644 index 5ddb6697a9..0000000000 --- a/frontends/default/views/_live_search.html.erb +++ /dev/null @@ -1,23 +0,0 @@ -<% href = url_for(params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'}) -%> -<%= form_remote_tag :url => href, - :method => :get, - :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", - :after => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'visible';", - :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden';", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> - <%= text_field_tag :search, search_params, :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> - <%= link_to_remote as_(:reset), {:url => href, :with => "'search='", :method => :get, - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')"}, :class => 'cancel' %> - <%= loading_indicator_tag(:action => :search) %> -</form> - -<script type="text/javascript"> -//<![CDATA[ - new TextFieldWithExample('<%= search_input_id %>', '<%= as_(:live_search) %>', {focus: true}); - new Form.Element.Observer('<%= search_input_id %>', 1.5, function(element, value) { - if (!$(element.id)) return false; // because the element may have been destroyed - $(element).up('form').onsubmit(); - }); -//]]> -</script> diff --git a/lib/active_scaffold/actions/live_search.rb b/lib/active_scaffold/actions/live_search.rb deleted file mode 100644 index d9f1115c8f..0000000000 --- a/lib/active_scaffold/actions/live_search.rb +++ /dev/null @@ -1,55 +0,0 @@ -module ActiveScaffold::Actions - module LiveSearch - include ActiveScaffold::Actions::CommonSearch - def self.included(base) - base.before_filter :search_authorized_filter, :only => :show_search - base.before_filter :store_search_params_into_session, :only => [:list, :index] - base.before_filter :do_search, :only => [:list, :index] - base.helper_method :search_params - end - - def show_search - respond_to_action(:live_search) - end - - protected - - def live_search_respond_to_html - if successful? - render(:partial => "live_search", :layout => true) - else - return_to_main - end - end - - def live_search_respond_to_js - render(:partial => "live_search") - end - - def do_search - query = search_params.to_s.strip rescue '' - - unless query.empty? - columns = active_scaffold_config.live_search.columns - text_search = active_scaffold_config.live_search.text_search - search_conditions = self.class.create_conditions_for_columns(query.split(' '), columns, text_search) - self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, search_conditions) - @filtered = !search_conditions.blank? - - includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact - self.active_scaffold_includes.concat includes_for_search_columns - - active_scaffold_config.list.user.page = nil - end - end - - private - def search_authorized_filter - link = active_scaffold_config.live_search.link || active_scaffold_config.live_search.class.link - raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method) - end - def live_search_formats - (default_formats + active_scaffold_config.formats + active_scaffold_config.live_search.formats).uniq - end - end -end diff --git a/lib/active_scaffold/config/live_search.rb b/lib/active_scaffold/config/live_search.rb deleted file mode 100644 index 3f113222a0..0000000000 --- a/lib/active_scaffold/config/live_search.rb +++ /dev/null @@ -1,43 +0,0 @@ -module ActiveScaffold::Config - class LiveSearch < Base - self.crud_type = :read - - def initialize(core_config) - @core = core_config - - @text_search = self.class.text_search - - # start with the ActionLink defined globally - @link = self.class.link.clone - end - - - # global level configuration - # -------------------------- - # the ActionLink for this action - cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) - - cattr_accessor :text_search - @@text_search = :full - - # instance-level configuration - # ---------------------------- - - # provides access to the list of columns specifically meant for the Search to use - def columns - # we want to delay initializing to the @core.columns set for as long as possible. Too soon and .search_sql will not be available to .searchable? - unless @columns - self.columns = @core.columns.collect{|c| c.name if c.searchable? and c.column and c.column.text?}.compact - end - @columns - end - - public :columns= - - attr_accessor :text_search - - # the ActionLink for this action - attr_accessor :link - end -end From 02a0fa29121d7b192bb72a8d1f594e1ff8b691bb Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Mar 2010 16:39:09 +0200 Subject: [PATCH 0271/2024] Use DelayedObserver for live search, improve JS performance --- frontends/default/views/_search.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index 2f44fc6943..f62af86433 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -18,7 +18,7 @@ //<![CDATA[ new TextFieldWithExample('<%= search_input_id %>', '<%= as_(live_search ? :live_search : :search_terms) %>', {focus: true}); <% if live_search -%> - new Form.Element.Observer('<%= search_input_id %>', 1.5, function(element, value) { + new Form.Element.DelayedObserver('<%= search_input_id %>', 0.5, function(element, value) { if (!$(element.id)) return false; // because the element may have been destroyed $(element).up('form').onsubmit(); }); From f2d3fbe8ff3f72af32613ab83f00910046757465 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 31 Mar 2010 09:58:19 +0200 Subject: [PATCH 0272/2024] Don't fail when effects is not loaded --- frontends/default/javascripts/active_scaffold.js | 10 +++++++--- .../active_scaffold/default/active_scaffold.js | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 41f29d9e9a..10f8afbb7a 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -8,6 +8,8 @@ if (Prototype.Version.substring(0, 3) != '1.6') warning = "ActiveScaffold Error: Prototype version 1.6.x is required. Please update prototype.js (rake rails:update:javascripts)."; alert(warning); } +if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFunction}); + /* * Simple utility methods @@ -81,7 +83,7 @@ var ActiveScaffold = { Element.replace(row, html); var new_row = $(row.id); if (row.hasClassName('even-record')) new_row.addClassName('even-record'); - new Effect.Highlight(new_row); + new_row.highlight(); }, server_error_response: '', @@ -367,7 +369,7 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra this.adapter.down('a.inline-adapter-close').observe('click', this.close_handler.bind(this)); this.register_cancel_hooks(); - new Effect.Highlight(this.adapter.down('td').down()); + this.adapter.down('td').down().highlight(); }, close: function($super, updatedRow) { @@ -430,10 +432,11 @@ ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstrac this.adapter.down('a.inline-adapter-close').observe('click', this.close_handler.bind(this)); this.register_cancel_hooks(); - new Effect.Highlight(this.adapter.down('td').down()); + this.adapter.down('td').down().highlight(); } }); +if (Ajax.InPlaceEditor) { ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { setFieldFromAjax: function(url, options) { var ipe = this; @@ -526,3 +529,4 @@ ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { } } }); +} diff --git a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js index 41f29d9e9a..10f8afbb7a 100644 --- a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +++ b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js @@ -8,6 +8,8 @@ if (Prototype.Version.substring(0, 3) != '1.6') warning = "ActiveScaffold Error: Prototype version 1.6.x is required. Please update prototype.js (rake rails:update:javascripts)."; alert(warning); } +if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFunction}); + /* * Simple utility methods @@ -81,7 +83,7 @@ var ActiveScaffold = { Element.replace(row, html); var new_row = $(row.id); if (row.hasClassName('even-record')) new_row.addClassName('even-record'); - new Effect.Highlight(new_row); + new_row.highlight(); }, server_error_response: '', @@ -367,7 +369,7 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra this.adapter.down('a.inline-adapter-close').observe('click', this.close_handler.bind(this)); this.register_cancel_hooks(); - new Effect.Highlight(this.adapter.down('td').down()); + this.adapter.down('td').down().highlight(); }, close: function($super, updatedRow) { @@ -430,10 +432,11 @@ ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstrac this.adapter.down('a.inline-adapter-close').observe('click', this.close_handler.bind(this)); this.register_cancel_hooks(); - new Effect.Highlight(this.adapter.down('td').down()); + this.adapter.down('td').down().highlight(); } }); +if (Ajax.InPlaceEditor) { ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { setFieldFromAjax: function(url, options) { var ipe = this; @@ -526,3 +529,4 @@ ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { } } }); +} From 82f2a50599da815c873795100304394d8dca69a6 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 31 Mar 2010 10:11:57 +0200 Subject: [PATCH 0273/2024] Support virtual columns with :integer search_ui --- lib/active_scaffold/finder.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 0df752495f..2bb4845761 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -59,13 +59,18 @@ def condition_for_column(column, value, text_search = :full) def condition_for_integer_type(column, value, like_pattern = nil) if !value.is_a?(Hash) - ["#{column.search_sql} = ?", column.column.type_cast(value)] + ["#{column.search_sql} = ?", column.column.nil? ? value.to_f : column.column.type_cast(value)] elsif value[:from].blank? or not ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) nil elsif value[:opt] == 'BETWEEN' - ["#{column.search_sql} BETWEEN ? AND ?", column.column.type_cast(value[:from]), column.column.type_cast(value[:to])] + condition = "#{column.search_sql} BETWEEN ? AND ?" + if column.column.nil? + [condition, value[:from].to_f, value[:to].to_f] + else + [condition, column.column.type_cast(value[:from]), column.column.type_cast(value[:to])] + end else - ["#{column.search_sql} #{value[:opt]} ?", column.column.type_cast(value[:from])] + ["#{column.search_sql} #{value[:opt]} ?", column.column.nil? ? value[:from].to_f : column.column.type_cast(value[:from])] end end alias_method :condition_for_decimal_type, :condition_for_integer_type From 2602fc3b65dc1e407252b5adf80720d6d848a462 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 31 Mar 2010 10:44:31 +0200 Subject: [PATCH 0274/2024] Include css_class in vertical subform --- frontends/default/views/_vertical_subform_record.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index 6397722591..ec9ba8c90e 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -12,7 +12,7 @@ column = column.clone column.form_ui ||= :select if column.association -%> - <li class="form-element <%= 'required' if column.required? %>"> + <li class="form-element <%= 'required' if column.required? %> <%= column.css_class unless column.css_class.nil? %>"> <% unless readonly -%> <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%> <% else -%> From e7c1552edc2cbe0948235bff41525f3d63cf3d0c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 31 Mar 2010 10:57:27 +0200 Subject: [PATCH 0275/2024] Fix name and id for scoped hidden attributes --- frontends/default/views/_form_hidden_attribute.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_form_hidden_attribute.html.erb b/frontends/default/views/_form_hidden_attribute.html.erb index 370b589fdc..22922a2081 100644 --- a/frontends/default/views/_form_hidden_attribute.html.erb +++ b/frontends/default/views/_form_hidden_attribute.html.erb @@ -1 +1 @@ -<%= hidden_field :record, column.name %> +<%= hidden_field :record, column.name, active_scaffold_input_options(column, scope) %> From dd24881251985e9eaf5f90b8253c80b1080881e1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 31 Mar 2010 14:44:31 +0200 Subject: [PATCH 0276/2024] Add explanation message to shoulda macros --- shoulda_macros/macros.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shoulda_macros/macros.rb b/shoulda_macros/macros.rb index bc829f150c..a9a2e5cdef 100644 --- a/shoulda_macros/macros.rb +++ b/shoulda_macros/macros.rb @@ -9,7 +9,7 @@ def self.should_include_columns_in(action, *columns) should "include columns in #{action}" do action_columns = @controller.active_scaffold_config.send(action).columns.map(&:name) columns.each do |column| - assert action_columns.include?(column.to_sym) + assert action_columns.include?(column.to_sym), "#{column} is not included in #{action}" end end end @@ -18,7 +18,7 @@ def self.should_not_include_columns_in(action, *columns) should "not include columns in #{action}" do action_columns = @controller.active_scaffold_config.send(action).columns.map(&:name) columns.each do |column| - assert !action_columns.include?(column.to_sym) + assert !action_columns.include?(column.to_sym), "#{column} is included in #{action}" end end end From 4004b3673dd3cf9cbfd80555630c904f95007a0d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 31 Mar 2010 15:45:05 +0200 Subject: [PATCH 0277/2024] put some list content in partials --- frontends/default/views/_list.html.erb | 33 ++----------------- .../default/views/_list_messages.html.erb | 20 +++++++++++ .../default/views/_list_pagination.html.erb | 11 +++++++ 3 files changed, 33 insertions(+), 31 deletions(-) create mode 100644 frontends/default/views/_list_messages.html.erb create mode 100644 frontends/default/views/_list_pagination.html.erb diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index 1e65a9379d..9fbb2f488d 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -7,26 +7,7 @@ <tbody class="messages"> <tr> <td colspan="<%= active_scaffold_config.list.columns.length + 1 -%>" class="messages-container"> - <div id="<%= active_scaffold_messages_id -%>"> - <%= render :partial => 'messages' %> - </div> - <p class="filtered-message" <%= ' style="display:none;" ' unless @filtered %>> - <%= as_(active_scaffold_config.list.filtered_message) %> - <% if active_scaffold_config.list.show_search_reset -%> - <% href = url_for(params_for(:action => :index, :escape => false, :search => '')) -%> - <%= link_to_remote as_(:click_to_reset), - { :url => href, - :method => :get, - :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", - :after => "$('#{loading_indicator_id(:action => :table)}').style.visibility = 'visible';", - :complete => "$('#{loading_indicator_id(:action => :table)}').style.visibility = 'hidden';", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')" - }, :href => href %> - <% end -%> - </p> - <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" ' unless @page.items.empty? %>> - <%= as_(active_scaffold_config.list.no_entries_message) %> - </p> + <%= render :partial => 'list_messages' %> </td> </tr> </tbody> @@ -39,14 +20,4 @@ <% end -%> </tbody> </table> -<% if active_scaffold_config.list.pagination -%> -<div class="active-scaffold-footer"> -<% unless @page.pager.infinite? -%> - <div class="active-scaffold-found"><span class="active-scaffold-records"><%= @page.pager.count -%></span> <%=as_(:found, :count => @page.pager.count) %></div> -<% end -%> - <div class="active-scaffold-pagination"> - <%= render :partial => 'list_pagination_links', :locals => { :current_page => @page } if @page.pager.infinite? || @page.pager.number_of_pages > 1 %> - </div> - <br clear="both" /><%# a hack for the Rico Corner problem %> -</div> -<% end -%> +<%= render :partial => 'list_pagination' %> diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb new file mode 100644 index 0000000000..508609bb8f --- /dev/null +++ b/frontends/default/views/_list_messages.html.erb @@ -0,0 +1,20 @@ + <div id="<%= active_scaffold_messages_id -%>"> + <%= render :partial => 'messages' %> + </div> + <p class="filtered-message" <%= ' style="display:none;" ' unless @filtered %>> + <%= as_(active_scaffold_config.list.filtered_message) %> + <% if active_scaffold_config.list.show_search_reset -%> + <% href = url_for(params_for(:action => :index, :escape => false, :search => '')) -%> + <%= link_to_remote as_(:click_to_reset), + { :url => href, + :method => :get, + :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", + :after => "$('#{loading_indicator_id(:action => :table)}').style.visibility = 'visible';", + :complete => "$('#{loading_indicator_id(:action => :table)}').style.visibility = 'hidden';", + :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')" + }, :href => href %> + <% end -%> + </p> + <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" ' unless @page.items.empty? %>> + <%= as_(active_scaffold_config.list.no_entries_message) %> + </p> diff --git a/frontends/default/views/_list_pagination.html.erb b/frontends/default/views/_list_pagination.html.erb new file mode 100644 index 0000000000..863d2e109a --- /dev/null +++ b/frontends/default/views/_list_pagination.html.erb @@ -0,0 +1,11 @@ +<% if active_scaffold_config.list.pagination -%> +<div class="active-scaffold-footer"> +<% unless @page.pager.infinite? -%> + <div class="active-scaffold-found"><span class="active-scaffold-records"><%= @page.pager.count -%></span> <%=as_(:found, :count => @page.pager.count) %></div> +<% end -%> + <div class="active-scaffold-pagination"> + <%= render :partial => 'list_pagination_links', :locals => { :current_page => @page } if @page.pager.infinite? || @page.pager.number_of_pages > 1 %> + </div> + <br clear="both" /><%# a hack for the Rico Corner problem %> +</div> +<% end -%> From db5f69bcd529a69ccb75e90cbfa8b1f79b83a084 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 31 Mar 2010 15:56:05 +0200 Subject: [PATCH 0278/2024] Fix returning to nested scaffold with polymorphic constraint --- lib/active_scaffold/helpers/controller_helpers.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 75d9a0f414..a79ed04f66 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -29,7 +29,6 @@ def main_path_to_return parameters[:eid] = params[:parent_controller] end parameters[:nested] = nil - parameters[:parent_model] = nil parameters[:parent_column] = nil parameters[:parent_id] = nil parameters[:action] = "index" From 59c38bca7505d8fb585106bbcaead53ee43cb75f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 5 Apr 2010 09:27:27 +0200 Subject: [PATCH 0279/2024] Fix creating/deleting when pagination is disabled or infinite --- frontends/default/javascripts/active_scaffold.js | 4 ++-- .../javascripts/active_scaffold/default/active_scaffold.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 10f8afbb7a..6f2d56a617 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -71,12 +71,12 @@ var ActiveScaffold = { decrement_record_count: function(scaffold_id) { // decrement the last record count, firsts record count are in nested lists count = $$('#' + scaffold_id + ' span.active-scaffold-records').last(); - count.innerHTML = parseInt(count.innerHTML) - 1; + if (count) count.update(parseInt(count.innerHTML, 10) - 1); }, increment_record_count: function(scaffold_id) { // increment the last record count, firsts record count are in nested lists count = $$('#' + scaffold_id + ' span.active-scaffold-records').last(); - count.innerHTML = parseInt(count.innerHTML) + 1; + if (count) count.update(parseInt(count.innerHTML, 10) + 1); }, update_row: function(row, html) { row = $(row); diff --git a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js index 10f8afbb7a..6f2d56a617 100644 --- a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +++ b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js @@ -71,12 +71,12 @@ var ActiveScaffold = { decrement_record_count: function(scaffold_id) { // decrement the last record count, firsts record count are in nested lists count = $$('#' + scaffold_id + ' span.active-scaffold-records').last(); - count.innerHTML = parseInt(count.innerHTML) - 1; + if (count) count.update(parseInt(count.innerHTML, 10) - 1); }, increment_record_count: function(scaffold_id) { // increment the last record count, firsts record count are in nested lists count = $$('#' + scaffold_id + ' span.active-scaffold-records').last(); - count.innerHTML = parseInt(count.innerHTML) + 1; + if (count) count.update(parseInt(count.innerHTML, 10) + 1); }, update_row: function(row, html) { row = $(row); From 174f5be2ddfaf79194dde3fd17a4e39f592fa296 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 5 Apr 2010 15:44:15 +0200 Subject: [PATCH 0280/2024] Fix render hidden column out of subform --- frontends/default/views/_form_hidden_attribute.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/frontends/default/views/_form_hidden_attribute.html.erb b/frontends/default/views/_form_hidden_attribute.html.erb index 22922a2081..e7afb2964e 100644 --- a/frontends/default/views/_form_hidden_attribute.html.erb +++ b/frontends/default/views/_form_hidden_attribute.html.erb @@ -1 +1,2 @@ +<% scope ||= nil %> <%= hidden_field :record, column.name, active_scaffold_input_options(column, scope) %> From 143c22f214f1d6bd647960be5c7aec5b91b48688 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 5 Apr 2010 15:44:59 +0200 Subject: [PATCH 0281/2024] Add shoulda macro to test render as hidden field --- shoulda_macros/macros.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/shoulda_macros/macros.rb b/shoulda_macros/macros.rb index a9a2e5cdef..a034c1dadb 100644 --- a/shoulda_macros/macros.rb +++ b/shoulda_macros/macros.rb @@ -50,6 +50,19 @@ def self.should_render_as_form_partial_override(column_name) end end + def self.should_render_as_form_hidden(column_name) + should "render column #{column_name} as form hidden", :before => lambda{ + @rendered_columns = [] + ActionView::Base.any_instance.expects(:"hidden_field").at_least_once.with {|object, method, options| + @rendered_columns << method + true + } + } do + assert_template :partial => "_form_hidden_attribute" + assert @rendered_columns.include?(column_name) + end + end + def self.should_render_as_list_ui(column_name, list_ui) should "render column #{column_name} as #{list_ui} list_ui", :before => lambda{ @rendered_columns = [] From f5fdcf982ad4414c356da9f88ae315fce7221688 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 8 Apr 2010 10:22:52 +0200 Subject: [PATCH 0282/2024] Fix removing last associated in a has_many through association with :select form_ui --- lib/active_scaffold/attribute_params.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 14f076fd1e..99b1321c31 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -61,12 +61,11 @@ def update_record_from_params(parent_record, columns, attributes) parent_record.send("#{column.name}=", value) unless parent_record.send(column.name) == value # plural associations may not actually appear in the params if all of the options have been unselected or cleared away. - # NOTE: the "form_ui" check isn't really necessary, except that without it we have problems + # the "form_ui" check is necessary, becuase without it we have problems # with subforms. the UI cuts out deep associations, which means they're not present in the # params even though they're in the columns list. the result is that associations were being - # emptied out way too often. BUT ... this means there's still a lingering bug in the default association - # form code: you can't delete the last association in the list. - elsif column.form_ui and column.plural_association? and not column.through_association? + # emptied out way too often. + elsif column.form_ui and column.plural_association? parent_record.send("#{column.name}=", []) end end From fa151ce254389a3ca9c73ff5f53e45ab1f433e75 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 8 Apr 2010 14:59:18 +0200 Subject: [PATCH 0283/2024] Setup paths before executing configure block so is possible to add paths in the block --- lib/active_scaffold.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 2c0b953367..022e4fa5bf 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -57,14 +57,6 @@ def active_scaffold(model_id = nil, &block) @active_scaffold_config = ActiveScaffold::Config::Core.new(model_id) @active_scaffold_config_block = block self.links_for_associations - self.active_scaffold_superclasses_blocks.each {|superblock| self.active_scaffold_config.configure &superblock} - self.active_scaffold_config.configure &block if block_given? - self.active_scaffold_config._configure_sti unless self.active_scaffold_config.sti_children.nil? - self.active_scaffold_config._load_action_columns - - # defines the attribute read methods on the model, so record.send() doesn't find protected/private methods instead - klass = self.active_scaffold_config.model - klass.define_attribute_methods unless klass.generated_methods? @active_scaffold_overrides = [] ActionController::Base.view_paths.each do |dir| @@ -81,6 +73,15 @@ def active_scaffold(model_id = nil, &block) @active_scaffold_frontends << active_scaffold_default_frontend_path @active_scaffold_custom_paths = [] + self.active_scaffold_superclasses_blocks.each {|superblock| self.active_scaffold_config.configure &superblock} + self.active_scaffold_config.configure &block if block_given? + self.active_scaffold_config._configure_sti unless self.active_scaffold_config.sti_children.nil? + self.active_scaffold_config._load_action_columns + + # defines the attribute read methods on the model, so record.send() doesn't find protected/private methods instead + klass = self.active_scaffold_config.model + klass.define_attribute_methods unless klass.generated_methods? + # include the rest of the code into the controller: the action core and the included actions module_eval do include ActiveScaffold::Finder From da62c058bdfa87fb72832e28fb94457f38250db7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 8 Apr 2010 14:59:46 +0200 Subject: [PATCH 0284/2024] Add shoulda macro to test responds_to_parent --- shoulda_macros/macros.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/shoulda_macros/macros.rb b/shoulda_macros/macros.rb index a034c1dadb..842a648441 100644 --- a/shoulda_macros/macros.rb +++ b/shoulda_macros/macros.rb @@ -104,4 +104,19 @@ def self.should_render_as_inplace_edit(column_name) assert @rendered_columns.include?(column_name) end end + + def self.should_respond_to_parent_redirecting_to(description, &block) + should_respond_to_parent("redirecting to #{description}") { "document.location.href = \"#{instance_eval(&block)}\"" } + end + + def self.should_respond_to_parent(description = nil, &block) + should "respond to parent #{description}" do + script = block ? instance_eval(&block) : /.*/ + script = script.is_a?(Regexp) ? script.source : Regexp.quote(script) + script = script.gsub('\n', '\\\\\\n'). + gsub(/['"]/, '\\\\\\\\\&'). + gsub('</script>','</scr"+"ipt>') + assert_select 'script[type=text/javascript]', Regexp.new('.*' + Regexp.quote("with(window.parent) { setTimeout(function() { window.eval('") + script + Regexp.quote("'); if (typeof(loc) !== 'undefined') loc.replace('about:blank'); }, 1) };") + '.*') + end + end end From dc2c607b4f0e949a65ca0a91447d3efc20ef8130 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 8 Apr 2010 15:18:00 +0200 Subject: [PATCH 0285/2024] Make some methods protected, they are not actions --- lib/active_scaffold/actions/common_search.rb | 6 +----- lib/active_scaffold/attribute_params.rb | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/actions/common_search.rb b/lib/active_scaffold/actions/common_search.rb index e95bed8724..05cbe00ab0 100644 --- a/lib/active_scaffold/actions/common_search.rb +++ b/lib/active_scaffold/actions/common_search.rb @@ -1,9 +1,6 @@ module ActiveScaffold::Actions module CommonSearch - def reset_search - update_table - end - + protected def store_search_params_into_session active_scaffold_session_storage[:search] = params.delete :search if params[:search] end @@ -12,7 +9,6 @@ def search_params active_scaffold_session_storage[:search] end - protected # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def search_authorized? diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 99b1321c31..5ba4dbcf6a 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -29,6 +29,7 @@ module ActiveScaffold # 'location' => '12' # } module AttributeParams + protected # Takes attributes (as from params[:record]) and applies them to the parent_record. Also looks for # association attributes and attempts to instantiate them as associated objects. # From 2355defa131eb9f5483108c97ce7979b5849411d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 13 Apr 2010 10:50:14 +0200 Subject: [PATCH 0286/2024] Don't add an existing record if it's already added --- frontends/default/views/_horizontal_subform_record.html.erb | 6 ++++-- frontends/default/views/_vertical_subform_record.html.erb | 6 ++++-- frontends/default/views/edit_associated.js.rjs | 6 ++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index 51264a2477..1388f92b9d 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -2,8 +2,9 @@ <% readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) -%> <% crud_type = @record.new_record? ? :create : (readonly ? :read : nil) -%> <% show_actions = false -%> +<% config = active_scaffold_config_for(@record.class) -%> <tr class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> -<% active_scaffold_config_for(@record.class).subform.columns.each :for => @record.class, :crud_type => crud_type, :flatten => true do |column| %> +<% config.subform.columns.each :for => @record.class, :crud_type => crud_type, :flatten => true do |column| %> <% next unless in_subform?(column, parent_record) show_actions = true @@ -22,7 +23,8 @@ <td class="actions"> <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> <% unless @record.new_record? %> - <input type="hidden" name="<%= "record#{scope}[id]" -%>" value="<%= @record.id -%>" /> + <% options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) -%> + <input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= @record.id -%>" /> <% end -%> </td> <% end -%> diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index ec9ba8c90e..594a4b5738 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -3,9 +3,10 @@ readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) crud_type = @record.new_record? ? :create : (readonly ? :read : nil) show_actions = false + config = active_scaffold_config_for(@record.class) -%> <ol class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> -<% active_scaffold_config_for(@record.class).subform.columns.each :for => @record, :crud_type => crud_type, :flatten => true do |column| %> +<% config.subform.columns.each :for => @record, :crud_type => crud_type, :flatten => true do |column| %> <% next unless in_subform?(column, parent_record) show_actions = true @@ -24,7 +25,8 @@ <li class="actions"> <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> <% unless @record.new_record? %> - <input type="hidden" name="<%= "record#{scope}[id]" -%>" value="<%= @record.id -%>" /> + <% options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) -%> + <input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= @record.id -%>" /> <% end -%> </li> <% end -%> diff --git a/frontends/default/views/edit_associated.js.rjs b/frontends/default/views/edit_associated.js.rjs index 33e4a11d1b..a9715c564c 100644 --- a/frontends/default/views/edit_associated.js.rjs +++ b/frontends/default/views/edit_associated.js.rjs @@ -10,5 +10,11 @@ if @column.singular_association? } | else + unless @record.new_record? + column = active_scaffold_config_for(@record.class).columns[@record.class.primary_key] + id = active_scaffold_input_options(column, @scope)[:id] + page << "if (!$('#{id}')) {" + end page.insert_html :bottom, sub_form_list_id(:association => @column.name), associated_form + page << "}" unless @record.new_record? end From f6d80c15c24116b32db3e0e7c9b13fee66ea469b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Apr 2010 09:41:34 +0200 Subject: [PATCH 0287/2024] Fix RJS when form is not loaded by AJAX and send form in an iframe --- frontends/default/views/on_create.js.rjs | 2 +- frontends/default/views/on_update.js.rjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index 815f746c49..b997f8c729 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -22,7 +22,7 @@ if controller.send :successful? else page << "var l = $$(#{cancel_selector}).first().link;" page.replace form, :partial => 'create_form', :locals => {:xhr => true} - page << "l.register_cancel_hooks();" + page << "if (l) l.register_cancel_hooks();" page[form].scroll_to end page.replace_html active_scaffold_messages_id, :partial => 'messages' diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 42783c4fda..f162265b51 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -8,7 +8,7 @@ if controller.send :successful? else page << "var l = $$(#{cancel_selector}).first().link;" page.replace form, :partial => 'update_form', :locals => {:xhr => true} - page << "l.register_cancel_hooks();" + page << "if (l) l.register_cancel_hooks();" page[form].scroll_to end page.replace_html active_scaffold_messages_id, :partial => 'messages' From 53df4fe355de8741ee8b98b7018d2040c5f0b47e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Apr 2010 13:53:58 +0200 Subject: [PATCH 0288/2024] Set empty hash as default parameters --- lib/active_scaffold/data_structures/action_link.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index d19a264778..15c91efcb0 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -13,6 +13,7 @@ def initialize(action, options = {}) self.crud_type = :create if [:create, :new].include?(action.to_sym) self.crud_type = :update if [:edit, :update].include?(action.to_sym) self.crud_type ||= :read + self.parameters = {} self.html_options = {} # apply quick properties From adeb8dcce9db7b5ba703917d9bf1958836535095 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 15 Apr 2010 12:39:33 +0200 Subject: [PATCH 0289/2024] Fix some calculations in an empty list --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index f10674538d..73f016c6b0 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -151,7 +151,7 @@ def format_column_checkbox(record, column) end def format_column_value(record, column, value = nil) - value ||= record.send(column.name) + value ||= record.send(column.name) unless record.nil? if value && column.association # cache association size before calling column_empty? associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association cache_association(value, column) From e2800e20f41f0661b294ee3191abf3501537632a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 16 Apr 2010 11:00:29 +0200 Subject: [PATCH 0290/2024] Use i18n for columns with select list_ui in the same cases as select form_ui --- .../helpers/form_column_helpers.rb | 2 +- .../helpers/list_column_helpers.rb | 11 +++++++ test/helpers/form_column_helpers_test.rb | 31 +++++++++++++++++++ test/helpers/list_column_helpers_test.rb | 31 +++++++++++++++++++ .../pagination_helpers_test.rb | 0 test/test_helper.rb | 2 ++ 6 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 test/helpers/form_column_helpers_test.rb create mode 100644 test/helpers/list_column_helpers_test.rb rename test/{misc => helpers}/pagination_helpers_test.rb (100%) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 96ee1b6f9d..4718947e11 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -141,7 +141,7 @@ def active_scaffold_input_select(column, html_options) active_scaffold_input_plural_association(column, html_options) else options = { :selected => @record.send(column.name) } - options_for_select = column.options[:options].collect do |(text, value)| + options_for_select = column.options[:options].collect do |text, value| active_scaffold_translated_option(column, text, value) end html_options.update(column.options[:html_options] || {}) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 73f016c6b0..394ae46bf3 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -113,6 +113,17 @@ def active_scaffold_column_text(column, record) truncate(clean_column_value(record.send(column.name)), :length => column.options[:truncate] || 50) end + def active_scaffold_column_select(column, record) + if column.association + format_column_value(record, column) + else + value = record.send(column.name) + text, val = column.options[:options].find {|text, val| (val || text).to_s == value} + value = active_scaffold_translated_option(column, text, val).first if text + format_column_value(record, column, value) + end + end + def active_scaffold_column_checkbox(column, record) if inplace_edit?(record, column) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} diff --git a/test/helpers/form_column_helpers_test.rb b/test/helpers/form_column_helpers_test.rb new file mode 100644 index 0000000000..c7ed79a304 --- /dev/null +++ b/test/helpers/form_column_helpers_test.rb @@ -0,0 +1,31 @@ +require File.join(File.dirname(__FILE__), '../test_helper.rb') + +class FormColumnHelpersTest < ActionView::TestCase + include ActiveScaffold::Helpers::FormColumnHelpers + + def setup + @column = ActiveScaffold::DataStructures::Column.new(:a, ModelStub) + @record = stub(:a => nil) + end + + def test_choices_for_select_form_ui_for_simple_column + @column.options[:options] = [:value_1, :value_2, :value_3] + assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">Value 1</option><option value="value_2">Value 2</option><option value="value_3">Value 3</option></select>', active_scaffold_input_select(@column, {}) + + @column.options[:options] = %w(value_1 value_2 value_3) + assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">value_1</option><option value="value_2">value_2</option><option value="value_3">value_3</option></select>', active_scaffold_input_select(@column, {}) + + @column.options[:options] = [%w(text_1 value_1), %w(text_2 value_2), %w(text_3 value_3)] + assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">text_1</option><option value="value_2">text_2</option><option value="value_3">text_3</option></select>', active_scaffold_input_select(@column, {}) + + @column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]] + assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">Text 1</option><option value="value_2">Text 2</option><option value="value_3">Text 3</option></select>', active_scaffold_input_select(@column, {}) + end + + def test_options_for_select_form_ui_for_simple_column + @column.options = {:include_blank => 'None', :selected => 'value_2', :disabled => %w(value_1 value_3)} + @column.options[:options] = %w(value_1 value_2 value_3) + @column.options[:html_options] = {:class => 'big'} + assert_dom_equal '<select name="record[a]" class="big" id="record_a"><option value="">None</option><option disabled="disabled" value="value_1">value_1</option><option selected="selected" value="value_2">value_2</option><option disabled="disabled" value="value_3">value_3</option></select>', active_scaffold_input_select(@column, {}) + end +end diff --git a/test/helpers/list_column_helpers_test.rb b/test/helpers/list_column_helpers_test.rb new file mode 100644 index 0000000000..e963743b79 --- /dev/null +++ b/test/helpers/list_column_helpers_test.rb @@ -0,0 +1,31 @@ +require File.join(File.dirname(__FILE__), '../test_helper.rb') + +class ListColumnHelpersTest < ActionView::TestCase + include ActiveScaffold::Helpers::ListColumnHelpers + include ActiveScaffold::Helpers::ViewHelpers + + def setup + @column = ActiveScaffold::DataStructures::Column.new(:a, ModelStub) + @record = stub(:a => 'value_2') + @config = stub(:list => stub(:empty_field_text => '-')) + end + + def test_options_for_select_list_ui_for_simple_column + @column.options[:options] = [:value_1, :value_2, :value_3] + assert_equal 'Value 2', active_scaffold_column_select(@column, @record) + + @column.options[:options] = %w(value_1 value_2 value_3) + assert_equal 'value_2', active_scaffold_column_select(@column, @record) + + @column.options[:options] = [%w(text_1 value_1), %w(text_2 value_2), %w(text_3 value_3)] + assert_equal 'text_2', active_scaffold_column_select(@column, @record) + + @column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]] + assert_equal 'Text 2', active_scaffold_column_select(@column, @record) + end + + private + def active_scaffold_config + @config + end +end diff --git a/test/misc/pagination_helpers_test.rb b/test/helpers/pagination_helpers_test.rb similarity index 100% rename from test/misc/pagination_helpers_test.rb rename to test/helpers/pagination_helpers_test.rb diff --git a/test/test_helper.rb b/test/test_helper.rb index dab52c3486..1770d073cf 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,7 @@ require 'test/unit' require 'rubygems' +require 'action_controller' +require 'action_view/test_case' require 'mocha' begin require 'redgreen' From 541bc438490bf70257b1c7f0c1c249b9407b3779 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 16 Apr 2010 11:05:30 +0200 Subject: [PATCH 0291/2024] Add shoulda macro for test options for select form_ui and improve some test names --- shoulda_macros/macros.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/shoulda_macros/macros.rb b/shoulda_macros/macros.rb index 842a648441..b68088e263 100644 --- a/shoulda_macros/macros.rb +++ b/shoulda_macros/macros.rb @@ -1,12 +1,12 @@ class ActiveSupport::TestCase def self.should_have_columns_in(action, *columns) - should "have columns in #{action}" do + should "have #{columns.to_sentence} columns in #{action}" do assert_equal columns, @controller.active_scaffold_config.send(action).columns.map(&:name) end end def self.should_include_columns_in(action, *columns) - should "include columns in #{action}" do + should "include #{columns.to_sentence} columns in #{action}" do action_columns = @controller.active_scaffold_config.send(action).columns.map(&:name) columns.each do |column| assert action_columns.include?(column.to_sym), "#{column} is not included in #{action}" @@ -15,7 +15,7 @@ def self.should_include_columns_in(action, *columns) end def self.should_not_include_columns_in(action, *columns) - should "not include columns in #{action}" do + should "not include #{columns.to_sentence} columns in #{action}" do action_columns = @controller.active_scaffold_config.send(action).columns.map(&:name) columns.each do |column| assert !action_columns.include?(column.to_sym), "#{column} is included in #{action}" @@ -36,6 +36,13 @@ def self.should_render_as_form_ui(column_name, form_ui) end end + def self.should_render_with_options_for_select(column_name, *options) + should "render column #{column_name} with options for select" do + converting_sort = lambda{|a,b| a.to_s <=> b.to_s} + assert_equal options.sort(&converting_sort), @controller.active_scaffold_config.columns[column_name].options[:options].sort(&converting_sort) + end + end + def self.should_render_as_form_override(column_name) should "render column #{column_name} as form override" do column = @controller.active_scaffold_config.columns[column_name] From 6cd54acb668734ce93b6a77e33f7303168d57aad Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 20 Apr 2010 16:06:00 +0200 Subject: [PATCH 0292/2024] Fix shoulda macros to test action columns when subgroups are used --- shoulda_macros/macros.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/shoulda_macros/macros.rb b/shoulda_macros/macros.rb index b68088e263..bb810e1dc0 100644 --- a/shoulda_macros/macros.rb +++ b/shoulda_macros/macros.rb @@ -1,13 +1,13 @@ class ActiveSupport::TestCase def self.should_have_columns_in(action, *columns) should "have #{columns.to_sentence} columns in #{action}" do - assert_equal columns, @controller.active_scaffold_config.send(action).columns.map(&:name) + assert_equal columns, column_names(action) end end def self.should_include_columns_in(action, *columns) should "include #{columns.to_sentence} columns in #{action}" do - action_columns = @controller.active_scaffold_config.send(action).columns.map(&:name) + action_columns = column_names(action) columns.each do |column| assert action_columns.include?(column.to_sym), "#{column} is not included in #{action}" end @@ -16,7 +16,7 @@ def self.should_include_columns_in(action, *columns) def self.should_not_include_columns_in(action, *columns) should "not include #{columns.to_sentence} columns in #{action}" do - action_columns = @controller.active_scaffold_config.send(action).columns.map(&:name) + action_columns = column_names(action) columns.each do |column| assert !action_columns.include?(column.to_sym), "#{column} is included in #{action}" end @@ -126,4 +126,11 @@ def self.should_respond_to_parent(description = nil, &block) assert_select 'script[type=text/javascript]', Regexp.new('.*' + Regexp.quote("with(window.parent) { setTimeout(function() { window.eval('") + script + Regexp.quote("'); if (typeof(loc) !== 'undefined') loc.replace('about:blank'); }, 1) };") + '.*') end end + + private + def column_names(action) + columns = [] + @controller.active_scaffold_config.send(action).columns.each(:flatten => true) {|col| columns << col.name} + columns + end end From 30ceee8bd7e1a33f865c538830349ad7cee60624 Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Thu, 22 Apr 2010 09:01:07 +0200 Subject: [PATCH 0293/2024] added action to mark individual records in your list view, these are stored in controllers session container and can be selected with <Model>.marked to do batch processing --- .../views/_list_column_headings.html.erb | 6 +- lib/active_scaffold/actions/mark.rb | 60 +++++++++++++++++++ lib/active_scaffold/config/mark.rb | 22 +++++++ .../helpers/list_column_helpers.rb | 13 +++- lib/active_scaffold/marked_model.rb | 38 ++++++++++++ 5 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 lib/active_scaffold/actions/mark.rb create mode 100644 lib/active_scaffold/config/mark.rb create mode 100644 lib/active_scaffold/marked_model.rb diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index fae35109b6..0dcf855f3b 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -23,7 +23,11 @@ default_sorting_stages = ['ASC', 'DESC'] :method => :get }, { :href => href } %> <% else -%> - <p><%= column.label %></p> + <% if column.name != :marked -%> + <p><%= column.label %></p> + <% else -%> + <%= mark_column_heading -%> + <% end -%> <% end -%> <%= inplace_edit_control(column) -%> </th> diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb new file mode 100644 index 0000000000..5445a89266 --- /dev/null +++ b/lib/active_scaffold/actions/mark.rb @@ -0,0 +1,60 @@ +module ActiveScaffold::Actions + module Mark + + def self.included(base) + base.before_filter :mark_authorized?, :only => [:mark_all] + base.prepend_before_filter :assign_marked_records_to_model + base.helper_method :marked_records + end + + def mark_all + if mark_all? + do_mark_all + else + do_demark_all + end + do_list + respond_to_action(:list) + end + protected + + # We need to give the ActiveRecord classes a handle to currently marked records. We don't want to just pass the object, + # because the object may change. So we give ActiveRecord a proc that ties to the + # marked_records_method on this ApplicationController. + def assign_marked_records_to_model + active_scaffold_config.model.marked_records_proc = proc {send(:marked_records)} + end + + def marked_records + active_scaffold_session_storage[:marked_records] ||= [] + end + + def mark_all? + @mark_all ||= (params[:value] == 'true') + end + + def do_mark_all + each_record_in_scope {|record| marked_records << record.id} + end + + def do_demark_all + each_record_in_scope {|record| marked_records.delete(record.id)} + end + + def each_record_in_scope + finder_options = { :order => "#{active_scaffold_config.model.primary_key} ASC", + :conditions => all_conditions, + :joins => joins_for_finder} + finder_options.merge! custom_finder_options + finder_options.merge! :include => (active_scaffold_includes.blank? ? nil : active_scaffold_includes) + klass = beginning_of_chain + klass.all(finder_options).each {|record| yield record} + end + + # The default security delegates to ActiveRecordPermissions. + # You may override the method to customize. + def mark_authorized? + authorized_for?(:action => :read) + end + end +end \ No newline at end of file diff --git a/lib/active_scaffold/config/mark.rb b/lib/active_scaffold/config/mark.rb new file mode 100644 index 0000000000..a443c24d65 --- /dev/null +++ b/lib/active_scaffold/config/mark.rb @@ -0,0 +1,22 @@ +module ActiveScaffold::Config + class Mark < Base + self.crud_type = :read + + def initialize(core_config) + @core = core_config + @core.model.send(:include, ActiveScaffold::MarkedModel) unless @core.model.ancestors.include?(ActiveScaffold::MarkedModel) + add_mark_column + end + + protected + + def add_mark_column + @core.columns.add :marked + @core.columns[:marked].label = 'M' + @core.columns[:marked].form_ui = :checkbox + @core.columns[:marked].inplace_edit = true + @core.columns[:marked].sort = false + @core.list.columns = [:marked] + @core.list.columns.names unless @core.list.columns.include? :marked + end + end +end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 394ae46bf3..8c8d55005d 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -355,7 +355,18 @@ def active_scaffold_in_place_editor(field_id, options = {}) javascript_tag(function) end - + + def mark_column_heading + all_marked = (marked_records.length >= @page.pager.count) + tag_options = {:id => "mark_heading", :class => "mark_heading"} + url_params = {:action => 'mark_all'} + ajax_options = {:method => :post, + :url => url_for(url_params), :with => "'value=' + this.value", + :after => "this.disable();", + :complete => "this.enable();"} + script = remote_function(ajax_options) + content_tag(:span, check_box_tag(tag_options[:id], !all_marked, all_marked, {:onclick => script}) , tag_options) + end end end end diff --git a/lib/active_scaffold/marked_model.rb b/lib/active_scaffold/marked_model.rb new file mode 100644 index 0000000000..8e2fbd905c --- /dev/null +++ b/lib/active_scaffold/marked_model.rb @@ -0,0 +1,38 @@ +module ActiveScaffold + module MarkedModel + # This is a module aimed at making the make session_stored marked_records available to ActiveRecord models + + def self.included(base) + base.extend ClassMethods + base.named_scope :marked, lambda {{:conditions => {:id => base.marked_records}}} + end + + def marked + marked_records.include?(self.id) + end + + def marked=(value) + value = (value.downcase == 'true') if value.is_a? String + if value == true + marked_records << self.id if !marked + else + marked_records.delete(self.id) + end + end + + module ClassMethods + # The proc to call that retrieves the marked_records from the ApplicationController. + attr_accessor :marked_records_proc + + # Class-level access to the marked_records + def marked_records + (marked_records_proc.call || []) if marked_records_proc + end + end + + # Instance-level access to the marked_records + def marked_records + self.class.marked_records + end + end +end From 701808e046e8a7d0d5fb5339bbbf9286b0e3b412 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 22 Apr 2010 16:50:45 +0200 Subject: [PATCH 0294/2024] Fix reloading tinymce when form is submitted to an iframe with errors --- lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb b/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb index 49faf316e5..1fc0b8b246 100644 --- a/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb +++ b/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb @@ -20,7 +20,7 @@ def active_scaffold_input_text_editor(column, options) options[:class] = "#{options[:class]} mceEditor #{column.options[:class]}".strip html = [] html << send(override_input(:textarea), column, options) - html << javascript_tag("tinyMCE.execCommand('mceAddControl', false, '#{options[:id]}');") if request.xhr? + html << javascript_tag("tinyMCE.execCommand('mceAddControl', false, '#{options[:id]}');") if request.xhr? || params[:iframe] html.join "\n" end From ac1923db91019c224f72b1c4b45c992449ffdb2b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 27 Apr 2010 10:05:35 +0200 Subject: [PATCH 0295/2024] FIx active_scaffold_controller_for when is called with a string instead of a class --- lib/active_scaffold.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 022e4fa5bf..329580dd75 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -203,7 +203,7 @@ def active_scaffold_controller_for(klass) end end raise ActiveScaffold::ControllerNotFound, "#{controller} missing ActiveScaffold", caller unless controller.uses_active_scaffold? - raise ActiveScaffold::ControllerNotFound, "ActiveScaffold on #{controller} is not for #{klass} model.", caller unless controller.active_scaffold_config.model == klass + raise ActiveScaffold::ControllerNotFound, "ActiveScaffold on #{controller} is not for #{klass} model.", caller unless controller.active_scaffold_config.model.to_s == klass.to_s return controller end end From a52bb0cba335804b8136827cd7149bc03d29eddd Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Thu, 29 Apr 2010 10:42:11 +0200 Subject: [PATCH 0296/2024] Bugfix: mark_all did not work work embedded controllers --- .../helpers/list_column_helpers.rb | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 8c8d55005d..628d9eb1dc 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -6,7 +6,15 @@ module ListColumnHelpers def get_column_value(record, column) begin # check for an override helper - value = if column_override? column + value = if column.options[:format_call] + column_value = record.send(column.name) + if column_empty?(column_value) + active_scaffold_config.list.empty_field_text + else + column.options[:format_call][1] = column_value + send(*(column.options[:format_call])) + end + elsif column_override? column # we only pass the record as the argument. we previously also passed the formatted_value, # but mike perham pointed out that prohibited the usage of overrides to improve on the # performance of our default formatting. see issue #138. @@ -167,26 +175,32 @@ def format_column_value(record, column, value = nil) associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association cache_association(value, column) end - if column.association.nil? or column_empty?(value) + return active_scaffold_config.list.empty_field_text if column_empty?(value) + + if column.association.nil? if value.is_a? Numeric - format_number_value(value, column.options) + format_number_value(value, column.options, column) else - format_value(value, column.options) + format_value(value, column.options, column) end else format_association_value(value, column, associated_size) end end - def format_number_value(value, options = {}) + def format_number_value(value, options = {}, column = nil) value = case options[:format] when :size + column.options[:format_call] = [:number_to_human_size, :value, options[:i18n_options] || {}] if column number_to_human_size(value, options[:i18n_options] || {}) when :percentage + column.options[:format_call] = [:number_to_percentage, :value, options[:i18n_options] || {}] if column number_to_percentage(value, options[:i18n_options] || {}) when :currency + column.options[:format_call] = [:number_to_currency, :value, options[:i18n_options] || {}] if column number_to_currency(value, options[:i18n_options] || {}) when :i18n_number + column.options[:format_call] = ["number_with_#{value.is_a?(Integer) ? 'delimiter' : 'precision'}".to_sym, :value, options[:i18n_options] || {}] if column send("number_with_#{value.is_a?(Integer) ? 'delimiter' : 'precision'}", value, options[:i18n_options] || {}) else value @@ -197,7 +211,7 @@ def format_number_value(value, options = {}) def format_association_value(value, column, size) case column.association.macro when :has_one, :belongs_to - format_value(value.to_label) + format_value(value.to_label, {}, column) when :has_many, :has_and_belongs_to_many if column.associated_limit.nil? firsts = value.collect { |v| v.to_label } @@ -216,12 +230,14 @@ def format_association_value(value, column, size) end end - def format_value(column_value, options = {}) + def format_value(column_value, options = {}, column = nil) value = if column_empty?(column_value) active_scaffold_config.list.empty_field_text elsif column_value.is_a?(Time) || column_value.is_a?(Date) + column.options[:format_call] = [:l, :value, {:format => options[:format] || :default}] if column l(column_value, :format => options[:format] || :default) elsif [FalseClass, TrueClass].include?(column_value.class) + column.options[:format_call] = [:format_boolean_value, :value] if column as_(column_value.to_s.to_sym) else column_value.to_s @@ -229,6 +245,10 @@ def format_value(column_value, options = {}) clean_column_value(value) end + def format_boolean_value(value) + as_(column_value.to_s.to_sym) + end + def cache_association(value, column) # we are not using eager loading, cache firsts records in order not to query the database in a future unless value.loaded? @@ -359,7 +379,7 @@ def active_scaffold_in_place_editor(field_id, options = {}) def mark_column_heading all_marked = (marked_records.length >= @page.pager.count) tag_options = {:id => "mark_heading", :class => "mark_heading"} - url_params = {:action => 'mark_all'} + url_params = {:controller => params_for[:controller], :action => 'mark_all', :eid => params[:eid]} ajax_options = {:method => :post, :url => url_for(url_params), :with => "'value=' + this.value", :after => "this.disable();", From 953c13686486eca4d98c0462fd9f2e7d640ac74e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 30 Apr 2010 11:52:55 +0200 Subject: [PATCH 0297/2024] Add paperclip bridge --- lib/bridges/paperclip/bridge.rb | 12 ++++++++ lib/bridges/paperclip/lib/form_ui.rb | 20 +++++++++++++ lib/bridges/paperclip/lib/list_ui.rb | 16 +++++++++++ lib/bridges/paperclip/lib/paperclip_bridge.rb | 28 +++++++++++++++++++ .../paperclip/lib/paperclip_bridge_helpers.rb | 18 ++++++++++++ 5 files changed, 94 insertions(+) create mode 100644 lib/bridges/paperclip/bridge.rb create mode 100644 lib/bridges/paperclip/lib/form_ui.rb create mode 100644 lib/bridges/paperclip/lib/list_ui.rb create mode 100644 lib/bridges/paperclip/lib/paperclip_bridge.rb create mode 100644 lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb diff --git a/lib/bridges/paperclip/bridge.rb b/lib/bridges/paperclip/bridge.rb new file mode 100644 index 0000000000..52461f81e2 --- /dev/null +++ b/lib/bridges/paperclip/bridge.rb @@ -0,0 +1,12 @@ +require File.join(File.dirname(__FILE__), "lib/paperclip_bridge_helpers") +ActiveScaffold.bridge "Paperclip" do + install do + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip") + raise RuntimeError, "We've detected that you have active_scaffold_paperclip_bridge installed. This plugin has been moved to core. Please remove active_scaffold_paperclip_bridge to prevent any conflicts" + end + + require File.join(File.dirname(__FILE__), "lib/paperclip_bridge") + require File.join(File.dirname(__FILE__), "lib/form_ui") + require File.join(File.dirname(__FILE__), "lib/list_ui") + end +end \ No newline at end of file diff --git a/lib/bridges/paperclip/lib/form_ui.rb b/lib/bridges/paperclip/lib/form_ui.rb new file mode 100644 index 0000000000..795666d376 --- /dev/null +++ b/lib/bridges/paperclip/lib/form_ui.rb @@ -0,0 +1,20 @@ +module ActiveScaffold + module Helpers + module FormColumnHelpers + def active_scaffold_input_paperclip(column, options) + input = file_field(:record, column.name, options) + paperclip = @record.send("#{column.name}") + if paperclip.file? + content = active_scaffold_column_paperclip(column, @record) + content_tag(:div, + content + " | " + + link_to_function(as_(:remove_file), "$(this).next().value='true'; p=$(this).up(); p.hide(); p.next().show()") + + hidden_field(:record, "delete_#{column.name}", :value => "false") + ) + content_tag(:div, input, :style => "display: none") + else + input + end + end + end + end +end \ No newline at end of file diff --git a/lib/bridges/paperclip/lib/list_ui.rb b/lib/bridges/paperclip/lib/list_ui.rb new file mode 100644 index 0000000000..c06a351b53 --- /dev/null +++ b/lib/bridges/paperclip/lib/list_ui.rb @@ -0,0 +1,16 @@ +module ActiveScaffold + module Helpers + module ListColumnHelpers + def active_scaffold_column_paperclip(column, record) + paperclip = record.send("#{column.name}") + return nil unless paperclip.file? + content = if paperclip.styles.include?(PaperclipBridgeHelpers.thumbnail_style) + image_tag(paperclip.url(PaperclipBridgeHelpers.thumbnail_style), :border => 0) + else + paperclip.original_filename + end + link_to(content, paperclip.url, :popup => true) + end + end + end +end \ No newline at end of file diff --git a/lib/bridges/paperclip/lib/paperclip_bridge.rb b/lib/bridges/paperclip/lib/paperclip_bridge.rb new file mode 100644 index 0000000000..056a9ff969 --- /dev/null +++ b/lib/bridges/paperclip/lib/paperclip_bridge.rb @@ -0,0 +1,28 @@ +module ActiveScaffold::Config + class Core < Base + def initialize_with_paperclip(model_id) + initialize_without_paperclip(model_id) + return if self.model.attachment_definitions.nil? + + self.update.multipart = true + self.create.multipart = true + + self.model.attachment_definitions.keys.each do |field| + configure_paperclip_field(field.to_sym) + # define the "delete" helper for use with active scaffold, unless it's already defined + PaperclipBridgeHelpers.generate_delete_helper(self.model, field) + end + end + alias_method_chain :initialize, :paperclip + + def configure_paperclip_field(field) + self.columns << field + self.columns[field].form_ui ||= :paperclip + self.columns[field].params.add "delete_#{field}" + + [:file_name, :content_type, :file_size, :updated_at].each do |f| + self.columns.exclude("#{field}_#{f}".to_sym) + end + end + end +end diff --git a/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb b/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb new file mode 100644 index 0000000000..3dcb49dd3d --- /dev/null +++ b/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb @@ -0,0 +1,18 @@ +module PaperclipBridgeHelpers + mattr_accessor :thumbnail_style + self.thumbnail_style = :thumbnail + + def self.generate_delete_helper(klass, field) + klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("delete_#{field}=") + attr_reader :delete_#{field} + + def delete_#{field}=(value) + value = (value == "true") if String === value + return unless value + + # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! + self.#{field} = nil unless self.#{field}.dirty? + end + EOF + end +end \ No newline at end of file From cd617ac56b2b1d0278c480e203bbe7523cbabff5 Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Tue, 4 May 2010 11:54:57 +0200 Subject: [PATCH 0298/2024] switched to set collection type to store marked records --- lib/active_scaffold/actions/mark.rb | 2 +- lib/active_scaffold/marked_model.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index 5445a89266..77e0a8bf6b 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -26,7 +26,7 @@ def assign_marked_records_to_model end def marked_records - active_scaffold_session_storage[:marked_records] ||= [] + active_scaffold_session_storage[:marked_records] ||= Set.new end def mark_all? diff --git a/lib/active_scaffold/marked_model.rb b/lib/active_scaffold/marked_model.rb index 8e2fbd905c..b121b4c64e 100644 --- a/lib/active_scaffold/marked_model.rb +++ b/lib/active_scaffold/marked_model.rb @@ -4,7 +4,7 @@ module MarkedModel def self.included(base) base.extend ClassMethods - base.named_scope :marked, lambda {{:conditions => {:id => base.marked_records}}} + base.named_scope :marked, lambda {{:conditions => {:id => base.marked_records.to_a}}} end def marked @@ -26,7 +26,7 @@ module ClassMethods # Class-level access to the marked_records def marked_records - (marked_records_proc.call || []) if marked_records_proc + (marked_records_proc.call || Set.new) if marked_records_proc end end From 138c917f4a2b82e530bb71f3aeb19fe1dd7241c3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 4 May 2010 12:02:41 +0200 Subject: [PATCH 0299/2024] Fix enum columns in search --- lib/active_scaffold/helpers/form_column_helpers.rb | 10 +++++++--- lib/active_scaffold/helpers/search_column_helpers.rb | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 4718947e11..e62a870fd2 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -134,6 +134,12 @@ def active_scaffold_translated_option(column, text, value = nil) [(text.is_a?(Symbol) ? column.active_record_class.human_attribute_name(text) : text), value] end + def active_scaffold_translated_options(column) + column.options[:options].collect do |text, value| + active_scaffold_translated_option(column, text, value) + end + end + def active_scaffold_input_select(column, html_options) if column.singular_association? active_scaffold_input_singular_association(column, html_options) @@ -141,9 +147,7 @@ def active_scaffold_input_select(column, html_options) active_scaffold_input_plural_association(column, html_options) else options = { :selected => @record.send(column.name) } - options_for_select = column.options[:options].collect do |text, value| - active_scaffold_translated_option(column, text, value) - end + options_for_select = active_scaffold_translated_options(column) html_options.update(column.options[:html_options] || {}) options.update(column.options) select(:record, column.name, options_for_select, options, html_options) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index c0c0c4035f..80a08c1451 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -86,10 +86,10 @@ def active_scaffold_search_select(column, html_options) if column.association associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil? method = column.association.macro == :belongs_to ? column.association.primary_key_name : column.name - select_options = options_for_association(column.association, true) + options_for_select = options_for_association(column.association, true) else method = column.name - select_options = column.options[:options] + options_for_select = active_scaffold_translated_options(column) end options = { :selected => associated }.merge! column.options @@ -99,7 +99,7 @@ def active_scaffold_search_select(column, html_options) else options[:include_blank] ||= as_(:_select_) end - select(:record, method, select_options, options, html_options) + select(:record, method, options_for_select, options, html_options) end def active_scaffold_search_text(column, options) From d6ded78ae2e831afaa3b2da4b592588c480fb390 Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Tue, 4 May 2010 12:12:46 +0200 Subject: [PATCH 0300/2024] removed test code (checked in accidently...) --- .../helpers/list_column_helpers.rb | 35 +++++-------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 628d9eb1dc..e94ae78d58 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -6,15 +6,7 @@ module ListColumnHelpers def get_column_value(record, column) begin # check for an override helper - value = if column.options[:format_call] - column_value = record.send(column.name) - if column_empty?(column_value) - active_scaffold_config.list.empty_field_text - else - column.options[:format_call][1] = column_value - send(*(column.options[:format_call])) - end - elsif column_override? column + value = if column_override? column # we only pass the record as the argument. we previously also passed the formatted_value, # but mike perham pointed out that prohibited the usage of overrides to improve on the # performance of our default formatting. see issue #138. @@ -175,32 +167,26 @@ def format_column_value(record, column, value = nil) associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association cache_association(value, column) end - return active_scaffold_config.list.empty_field_text if column_empty?(value) - - if column.association.nil? + if column.association.nil? or column_empty?(value) if value.is_a? Numeric - format_number_value(value, column.options, column) + format_number_value(value, column.options) else - format_value(value, column.options, column) + format_value(value, column.options) end else format_association_value(value, column, associated_size) end end - def format_number_value(value, options = {}, column = nil) + def format_number_value(value, options = {}) value = case options[:format] when :size - column.options[:format_call] = [:number_to_human_size, :value, options[:i18n_options] || {}] if column number_to_human_size(value, options[:i18n_options] || {}) when :percentage - column.options[:format_call] = [:number_to_percentage, :value, options[:i18n_options] || {}] if column number_to_percentage(value, options[:i18n_options] || {}) when :currency - column.options[:format_call] = [:number_to_currency, :value, options[:i18n_options] || {}] if column number_to_currency(value, options[:i18n_options] || {}) when :i18n_number - column.options[:format_call] = ["number_with_#{value.is_a?(Integer) ? 'delimiter' : 'precision'}".to_sym, :value, options[:i18n_options] || {}] if column send("number_with_#{value.is_a?(Integer) ? 'delimiter' : 'precision'}", value, options[:i18n_options] || {}) else value @@ -211,7 +197,7 @@ def format_number_value(value, options = {}, column = nil) def format_association_value(value, column, size) case column.association.macro when :has_one, :belongs_to - format_value(value.to_label, {}, column) + format_value(value.to_label) when :has_many, :has_and_belongs_to_many if column.associated_limit.nil? firsts = value.collect { |v| v.to_label } @@ -230,14 +216,12 @@ def format_association_value(value, column, size) end end - def format_value(column_value, options = {}, column = nil) + def format_value(column_value, options = {}) value = if column_empty?(column_value) active_scaffold_config.list.empty_field_text elsif column_value.is_a?(Time) || column_value.is_a?(Date) - column.options[:format_call] = [:l, :value, {:format => options[:format] || :default}] if column l(column_value, :format => options[:format] || :default) elsif [FalseClass, TrueClass].include?(column_value.class) - column.options[:format_call] = [:format_boolean_value, :value] if column as_(column_value.to_s.to_sym) else column_value.to_s @@ -245,10 +229,6 @@ def format_value(column_value, options = {}, column = nil) clean_column_value(value) end - def format_boolean_value(value) - as_(column_value.to_s.to_sym) - end - def cache_association(value, column) # we are not using eager loading, cache firsts records in order not to query the database in a future unless value.loaded? @@ -387,6 +367,7 @@ def mark_column_heading script = remote_function(ajax_options) content_tag(:span, check_box_tag(tag_options[:id], !all_marked, all_marked, {:onclick => script}) , tag_options) end + end end end From 25bb0b3108b4ac2ded298d0ccc2f4b53dde612f9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 4 May 2010 12:54:44 +0200 Subject: [PATCH 0301/2024] Add split terms option to search to disable splitting of search term and enabling to set a different separator (issue #744) --- lib/active_scaffold/actions/search.rb | 3 ++- lib/active_scaffold/config/search.rb | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index df11bb2fcd..88350991a7 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -25,7 +25,8 @@ def do_search unless query.empty? columns = active_scaffold_config.search.columns text_search = active_scaffold_config.search.text_search - search_conditions = self.class.create_conditions_for_columns(query.split(' '), columns, text_search) + query = query.split(active_scaffold_config.search.split_terms) if active_scaffold_config.search.split_terms + search_conditions = self.class.create_conditions_for_columns(query, columns, text_search) self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, search_conditions) @filtered = !search_conditions.blank? diff --git a/lib/active_scaffold/config/search.rb b/lib/active_scaffold/config/search.rb index 3447ed697f..9a2aaa2dab 100644 --- a/lib/active_scaffold/config/search.rb +++ b/lib/active_scaffold/config/search.rb @@ -8,6 +8,8 @@ def initialize(core_config) @text_search = self.class.text_search @live = self.class.live? + @split_terms = self.class.split_terms + # start with the ActionLink defined globally @link = self.class.link.clone end @@ -56,6 +58,10 @@ def columns # Default is :full attr_accessor :text_search + @@split_terms = " " + cattr_accessor :split_terms + attr_accessor :split_terms + # the ActionLink for this action attr_accessor :link From 33c491c7f30ac43fcb189594163613ec5c3d3197 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 5 May 2010 11:33:44 +0200 Subject: [PATCH 0302/2024] Clean up mark records and DRY the code (without duplicating finder_options code) --- frontends/default/stylesheets/stylesheet.css | 4 ++ .../views/_list_column_headings.html.erb | 7 +- .../views/_list_record_columns.html.erb | 1 + lib/active_scaffold/actions/core.rb | 4 ++ lib/active_scaffold/actions/delete.rb | 1 + lib/active_scaffold/actions/list.rb | 12 +++- lib/active_scaffold/actions/mark.rb | 71 +++++++++++-------- lib/active_scaffold/config/list.rb | 7 ++ lib/active_scaffold/config/mark.rb | 22 ------ lib/active_scaffold/finder.rb | 49 ++++++++----- .../helpers/list_column_helpers.rb | 17 +++-- lib/extensions/resources.rb | 4 +- 12 files changed, 111 insertions(+), 88 deletions(-) delete mode 100644 lib/active_scaffold/config/mark.rb diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index b59b6a66f0..d4315f4d53 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -52,6 +52,10 @@ padding: 5px 20px 5px 5px; color: #333; } +.active-scaffold .mark_record_column { + width: 1px; +} + /* Header ======================== */ diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index 0dcf855f3b..dee87a3ab7 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -4,6 +4,7 @@ sorting_stages = ['reset', 'ASC', 'DESC'] default_sorting = active_scaffold_config.list.sorting default_sorting_stages = ['ASC', 'DESC'] -%> + <%= content_tag :th, mark_record(marked_records.length >= @page.pager.count), :class => 'mark_record_column' if active_scaffold_config.list.mark_records %> <% active_scaffold_config.list.columns.each do |column| -%> <% stages = default_sorting.sorts_on?(column) ? default_sorting_stages : sorting_stages @@ -23,11 +24,7 @@ default_sorting_stages = ['ASC', 'DESC'] :method => :get }, { :href => href } %> <% else -%> - <% if column.name != :marked -%> - <p><%= column.label %></p> - <% else -%> - <%= mark_column_heading -%> - <% end -%> + <p><%= column.label %></p> <% end -%> <%= inplace_edit_control(column) -%> </th> diff --git a/frontends/default/views/_list_record_columns.html.erb b/frontends/default/views/_list_record_columns.html.erb index c671178234..cbbba2890f 100644 --- a/frontends/default/views/_list_record_columns.html.erb +++ b/frontends/default/views/_list_record_columns.html.erb @@ -1,3 +1,4 @@ + <%= content_tag :td, mark_record(marked_records.include?(record.id.to_s), :id => record.id), :class => 'mark_record_column' if active_scaffold_config.list.mark_records %> <% active_scaffold_config.list.columns.each do |column| %> <% authorized = record.authorized_for?(:crud_type => :read, :column => column.name) -%> <% column_value = authorized ? get_column_value(record, column) : active_scaffold_config.list.empty_field_text -%> diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 9ee0861b1c..d65e2f75a0 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -41,6 +41,10 @@ def clear_flashes end end + def marked_records + active_scaffold_session_storage[:marked_records] ||= Set.new + end + def default_formats [:html, :js, :json, :xml, :yaml] end diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 36f4ec6890..8d60e510af 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -49,6 +49,7 @@ def do_destroy destroy_find_record begin self.successful = @record.destroy + marked_records.delete @record.id if successful? rescue flash[:warning] = as_(:cant_destroy_record, :record => @record.to_label) self.successful = false diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 10e8d340eb..cb42a79961 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -2,6 +2,7 @@ module ActiveScaffold::Actions module List def self.included(base) base.before_filter :list_authorized_filter, :only => [:index, :table, :row, :list] + base.send :include, ActiveScaffold::Actions::Mark if base.active_scaffold_config.list.mark_records end def index @@ -41,10 +42,15 @@ def list_respond_to_json def list_respond_to_yaml render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end - # The actual algorithm to prepare for the list view - def do_list + + def set_includes_for_list_columns includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact self.active_scaffold_includes.concat includes_for_list_columns + end + + # The actual algorithm to prepare for the list view + def do_list + set_includes_for_list_columns options = { :sorting => active_scaffold_config.list.user.sorting, :count_includes => active_scaffold_config.list.user.count_includes } @@ -57,7 +63,7 @@ def do_list }) end - page = find_page(options); + page = find_page(options) if page.items.blank? && !page.pager.infinite? page = page.pager.last active_scaffold_config.list.user.page = page.number diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index 77e0a8bf6b..128138989c 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -2,53 +2,66 @@ module ActiveScaffold::Actions module Mark def self.included(base) - base.before_filter :mark_authorized?, :only => [:mark_all] - base.prepend_before_filter :assign_marked_records_to_model + base.before_filter :mark_authorized?, :only => :mark + #base.prepend_before_filter :assign_marked_records_to_model base.helper_method :marked_records end - def mark_all - if mark_all? - do_mark_all + def mark + if mark? + do_mark else - do_demark_all + do_unmark end - do_list - respond_to_action(:list) + mark_respond_to_js end - protected - + + protected # We need to give the ActiveRecord classes a handle to currently marked records. We don't want to just pass the object, # because the object may change. So we give ActiveRecord a proc that ties to the # marked_records_method on this ApplicationController. def assign_marked_records_to_model active_scaffold_config.model.marked_records_proc = proc {send(:marked_records)} end - - def marked_records - active_scaffold_session_storage[:marked_records] ||= Set.new + + def mark? + params[:value] == 'true' end - def mark_all? - @mark_all ||= (params[:value] == 'true') - end - - def do_mark_all - each_record_in_scope {|record| marked_records << record.id} + def do_mark + if params[:id] + marked_records << params[:id] + else + each_record_in_scope {|record| marked_records << record.id.to_s} + end end - def do_demark_all - each_record_in_scope {|record| marked_records.delete(record.id)} + def do_unmark + if params[:id] + marked_records.delete params[:id] + else + each_record_in_scope {|record| marked_records.delete(record.id.to_s)} + end end def each_record_in_scope - finder_options = { :order => "#{active_scaffold_config.model.primary_key} ASC", - :conditions => all_conditions, - :joins => joins_for_finder} - finder_options.merge! custom_finder_options - finder_options.merge! :include => (active_scaffold_includes.blank? ? nil : active_scaffold_includes) - klass = beginning_of_chain - klass.all(finder_options).each {|record| yield record} + do_search if respond_to? :do_search + set_includes_for_list_columns + find_options = finder_options + find_options[:include] = nil if find_options[:conditions].nil? + beginning_of_chain.all(find_options).each {|record| yield record} + end + + def mark_respond_to_js + if params[:id] + do_search if respond_to? :do_search + set_includes_for_list_columns + count = beginning_of_chain.count(count_options(finder_options, active_scaffold_config.list.user.count_includes)) + # FIXME: It isn't right when there are filtered records by a search + render :js => "$('#{active_scaffold_id}').down('.mark_record').checked = #{marked_records.length >= count ? true : false};" + else + render :js => "$$('##{active_scaffold_tbody_id} > tr > td > .mark_record').each(function(checkbox) { checkbox.checked = #{mark? ? true : false};});" + end end # The default security delegates to ActiveRecordPermissions. @@ -57,4 +70,4 @@ def mark_authorized? authorized_for?(:action => :read) end end -end \ No newline at end of file +end diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index e122584969..fc4b33aba4 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -18,6 +18,7 @@ def initialize(core_config) @empty_field_text = self.class.empty_field_text @pagination = self.class.pagination @show_search_reset = true + @mark_records = self.class.mark_records end # global level configuration @@ -41,6 +42,9 @@ def initialize(core_config) cattr_accessor :pagination @@pagination = true + # Add a checkbox in front of each record to mark them and use them with a batch action later + cattr_accessor :mark_records + # instance-level configuration # ---------------------------- @@ -70,6 +74,9 @@ def columns # show a link to reset the search next to filtered message attr_accessor :show_search_reset + # Add a checkbox in front of each record to mark them and use them with a batch action later + attr_accessor :mark_records + # the default sorting. should be an array of hashes of {column_name => direction}, e.g. [{:a => 'desc'}, {:b => 'asc'}]. to just sort on one column, you can simply provide a hash, though, e.g. {:a => 'desc'}. def sorting=(val) val = [val] if val.is_a? Hash diff --git a/lib/active_scaffold/config/mark.rb b/lib/active_scaffold/config/mark.rb deleted file mode 100644 index a443c24d65..0000000000 --- a/lib/active_scaffold/config/mark.rb +++ /dev/null @@ -1,22 +0,0 @@ -module ActiveScaffold::Config - class Mark < Base - self.crud_type = :read - - def initialize(core_config) - @core = core_config - @core.model.send(:include, ActiveScaffold::MarkedModel) unless @core.model.ancestors.include?(ActiveScaffold::MarkedModel) - add_mark_column - end - - protected - - def add_mark_column - @core.columns.add :marked - @core.columns[:marked].label = 'M' - @core.columns[:marked].form_ui = :checkbox - @core.columns[:marked].inplace_edit = true - @core.columns[:marked].sort = false - @core.list.columns = [:marked] + @core.list.columns.names unless @core.list.columns.include? :marked - end - end -end diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 2bb4845761..28ee37559d 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -190,50 +190,63 @@ def find_if_allowed(id, crud_type, klass = beginning_of_chain) return record end - # returns a Paginator::Page (not from ActiveRecord::Paginator) for the given parameters - # options may include: + # returns a hash with options to find records + # valid options may include: # * :sorting - a Sorting DataStructure (basically an array of hashes of field => direction, e.g. [{:field1 => 'asc'}, {:field2 => 'desc'}]). please note that multi-column sorting has some limitations: if any column in a multi-field sort uses method-based sorting, it will be ignored. method sorting only works for single-column sorting. # * :per_page # * :page - # TODO: this should reside on the model, not the controller - def find_page(options = {}) - options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination + def finder_options(options = {}) + options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination, :select search_conditions = all_conditions full_includes = (active_scaffold_includes.blank? ? nil : active_scaffold_includes) - options[:per_page] ||= 999999999 - options[:page] ||= 1 - options[:count_includes] ||= full_includes unless search_conditions.nil? - klass = beginning_of_chain - # create a general-use options array that's compatible with Rails finders finder_options = { :order => options[:sorting].try(:clause), :conditions => search_conditions, :joins => joins_for_finder, - :include => options[:count_includes]} + :include => full_includes} finder_options.merge! custom_finder_options + finder_options + end + + # Returns a hash with options to count records, rejecting select and order options + # See finder_options for valid options + def count_options(find_options = {}, count_includes = nil) + count_includes ||= find_options[:include] unless find_options[:conditions].nil? + options = find_options.reject{|k,v| [:select, :order].include? k} + options[:include] = count_includes + options + end + # returns a Paginator::Page (not from ActiveRecord::Paginator) for the given parameters + # See finder_options for valid options + # TODO: this should reside on the model, not the controller + def find_page(options = {}) + options[:per_page] ||= 999999999 + options[:page] ||= 1 + + find_options = finder_options(options) + klass = beginning_of_chain + # NOTE: we must use :include in the count query, because some conditions may reference other tables - count = klass.count(finder_options.reject{|k,v| [:select, :order].include? k}) unless options[:pagination] == :infinite + count = klass.count(count_options(find_options, options[:count_includes])) if options[:pagination] && options[:pagination] != :infinite # Converts count to an integer if ActiveRecord returned an OrderedHash - # that happens when finder_options contains a :group key + # that happens when find_options contains a :group key count = count.length if count.is_a? ActiveSupport::OrderedHash - finder_options.merge! :include => full_includes - # we build the paginator differently for method- and sql-based sorting if options[:sorting] and options[:sorting].sorts_by_method? pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| - sorted_collection = sort_collection_by_column(klass.all(finder_options), *options[:sorting].first) + sorted_collection = sort_collection_by_column(klass.all(find_options), *options[:sorting].first) sorted_collection.slice(offset, per_page) if options[:pagination] end else pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| - finder_options.merge!(:offset => offset, :limit => per_page) if options[:pagination] - klass.all(finder_options) + find_options.merge!(:offset => offset, :limit => per_page) if options[:pagination] + klass.all(find_options) end end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index e94ae78d58..dd8bc2721d 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -356,16 +356,15 @@ def active_scaffold_in_place_editor(field_id, options = {}) javascript_tag(function) end - def mark_column_heading - all_marked = (marked_records.length >= @page.pager.count) - tag_options = {:id => "mark_heading", :class => "mark_heading"} - url_params = {:controller => params_for[:controller], :action => 'mark_all', :eid => params[:eid]} - ajax_options = {:method => :post, - :url => url_for(url_params), :with => "'value=' + this.value", - :after => "this.disable();", - :complete => "this.enable();"} + def mark_record(checked, url_params = {}) + url_params.reverse_merge!(:controller => params_for[:controller], :action => 'mark', :eid => params[:eid]) + ajax_options = {:method => :put, + :url => url_for(url_params), + :with => "'value=' + this.checked", + :after => "var checkbox = this; this.disable();", + :complete => "checkbox.enable();"} script = remote_function(ajax_options) - content_tag(:span, check_box_tag(tag_options[:id], !all_marked, all_marked, {:onclick => script}) , tag_options) + check_box_tag('mark', '1', checked, :onclick => script, :class => 'mark_record') end end diff --git a/lib/extensions/resources.rb b/lib/extensions/resources.rb index 18161f7e88..3699174649 100644 --- a/lib/extensions/resources.rb +++ b/lib/extensions/resources.rb @@ -2,8 +2,8 @@ module ActionController module Resources class Resource ACTIVE_SCAFFOLD_ROUTING = { - :collection => {:show_search => :get, :edit_associated => :get, :list => :get, :new_existing => :get, :add_existing => :post, :render_field => :get}, - :member => {:row => :get, :nested => :get, :edit_associated => :get, :add_association => :get, :update_column => :post, :destroy_existing => :delete, :render_field => :get, :delete => :get} + :collection => {:show_search => :get, :edit_associated => :get, :list => :get, :new_existing => :get, :add_existing => :post, :render_field => :get, :mark => :put}, + :member => {:row => :get, :nested => :get, :edit_associated => :get, :add_association => :get, :update_column => :post, :destroy_existing => :delete, :render_field => :get, :delete => :get, :mark => :put} } # by overwriting the attr_reader :options, we can parse out a special :active_scaffold flag just-in-time. From 5759445dae2ec61454d97b6854833bf447587080 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 5 May 2010 12:06:31 +0200 Subject: [PATCH 0303/2024] Fix showing text in select list_ui for integer columns --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index dd8bc2721d..1d39137c0c 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -118,7 +118,7 @@ def active_scaffold_column_select(column, record) format_column_value(record, column) else value = record.send(column.name) - text, val = column.options[:options].find {|text, val| (val || text).to_s == value} + text, val = column.options[:options].find {|text, val| (val || text).to_s == value.to_s} value = active_scaffold_translated_option(column, text, val).first if text format_column_value(record, column, value) end From b07115d50b621ae26d9b648d9ecbdced415ff4cc Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Wed, 5 May 2010 15:26:33 +0200 Subject: [PATCH 0304/2024] get an empty list view up and running with RAILS 3 --- .../views/_list_column_headings.html.erb | 5 +- .../default/views/_list_messages.html.erb | 5 +- frontends/default/views/list.html.erb | 4 +- init.rb | 4 +- lib/active_scaffold.rb | 13 +- lib/active_scaffold/finder.rb | 9 +- .../helpers/form_column_helpers.rb | 2 +- lib/active_scaffold/helpers/id_helpers.rb | 2 +- .../helpers/list_column_helpers.rb | 2 +- .../helpers/search_column_helpers.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 8 +- lib/extensions/action_view_rendering.rb | 163 ++++++++---------- lib/extensions/action_view_resolver.rb | 7 + lib/extensions/generic_view_paths.rb | 33 ---- lib/extensions/resources.rb | 48 +++--- 15 files changed, 142 insertions(+), 165 deletions(-) create mode 100644 lib/extensions/action_view_resolver.rb delete mode 100644 lib/extensions/generic_view_paths.rb diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index 0dcf855f3b..c33b55a1ae 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -15,8 +15,9 @@ default_sorting_stages = ['ASC', 'DESC'] <th id="<%= column_header_id %>" class="<%= column.css_class unless column.css_class.nil? %> <%= "sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column %>" title="<%= h column.description %>"> <% if column.sortable? -%> <% href = url_for(sort_params) -%> - <%= link_to_remote column.label, - { :url => sort_params, + <%= link_to column.label, + { :remote => true, + :url => sort_params, :before => "addActiveScaffoldPageToHistory('#{href}', '#{controller_id}')", :loading => "Element.addClassName('#{column_header_id}','loading');", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index 508609bb8f..a8d7bb3c1f 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -5,8 +5,9 @@ <%= as_(active_scaffold_config.list.filtered_message) %> <% if active_scaffold_config.list.show_search_reset -%> <% href = url_for(params_for(:action => :index, :escape => false, :search => '')) -%> - <%= link_to_remote as_(:click_to_reset), - { :url => href, + <%= link_to as_(:click_to_reset), + { :remote => true, + :url => href, :method => :get, :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", :after => "$('#{loading_indicator_id(:action => :table)}').style.visibility = 'visible';", diff --git a/frontends/default/views/list.html.erb b/frontends/default/views/list.html.erb index 4edbcbad44..22943e828a 100644 --- a/frontends/default/views/list.html.erb +++ b/frontends/default/views/list.html.erb @@ -39,9 +39,9 @@ Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-footer').fi <% end -%> new ActiveScaffold.Actions.Table($$('#<%= active_scaffold_id -%> div.active-scaffold-header a.action'), $('<%= before_header_id -%>'), $('<%= loading_indicator_id(:action => :table) -%>')); ActiveScaffold.server_error_response = '<p class="error-message message">' - + <%= as_(:internal_error).to_json %> + + <%= as_(:internal_error).to_json.html_safe %> + '<a href="#" onclick="Element.remove(this.parentNode); return false;">' - + <%= as_(:close).to_json %> + + <%= as_(:close).to_json.html_safe %> + '</a>' + '</p>'; //]]> diff --git a/init.rb b/init.rb index 019d73a582..46734751a9 100755 --- a/init.rb +++ b/init.rb @@ -1,8 +1,8 @@ ## ## Initialize the environment ## -unless Rails::VERSION::MAJOR == 2 && Rails::VERSION::MINOR >= 3 - raise "This version of ActiveScaffold requires Rails 2.3 or higher. Please use an earlier version." +unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 0 + raise "This version of ActiveScaffold requires Rails 3.0 or higher. Please use an earlier version." end require File.dirname(__FILE__) + '/environment' diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 022e4fa5bf..f3301381b7 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -60,7 +60,7 @@ def active_scaffold(model_id = nil, &block) @active_scaffold_overrides = [] ActionController::Base.view_paths.each do |dir| - active_scaffold_overrides_dir = File.join(dir,"active_scaffold_overrides") + active_scaffold_overrides_dir = File.join(dir.to_s,"active_scaffold_overrides") @active_scaffold_overrides << active_scaffold_overrides_dir if File.exists?(active_scaffold_overrides_dir) end @active_scaffold_overrides.uniq! # Fix rails duplicating some view_paths @@ -80,8 +80,7 @@ def active_scaffold(model_id = nil, &block) # defines the attribute read methods on the model, so record.send() doesn't find protected/private methods instead klass = self.active_scaffold_config.model - klass.define_attribute_methods unless klass.generated_methods? - + klass.define_attribute_methods unless klass.attribute_methods_generated? # include the rest of the code into the controller: the action core and the included actions module_eval do include ActiveScaffold::Finder @@ -98,6 +97,9 @@ def active_scaffold(model_id = nil, &block) end end end + active_scaffold_paths.each do |path| + self.append_view_path(ActionView::ActiveScaffoldResolver.new(path)) + end self.active_scaffold_config._add_sti_create_links if self.active_scaffold_config.add_sti_create_links? end @@ -142,8 +144,9 @@ def add_active_scaffold_override_path(path) def active_scaffold_paths return @active_scaffold_paths unless @active_scaffold_paths.nil? - @active_scaffold_paths = ActionView::PathSet.new - @active_scaffold_paths.concat @active_scaffold_overrides unless @active_scaffold_overrides.nil? + #@active_scaffold_paths = ActionView::PathSet.new + @active_scaffold_paths = [] + #@active_scaffold_paths.concat @active_scaffold_overrides unless @active_scaffold_overrides.nil? @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil? @active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil? @active_scaffold_paths diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 2bb4845761..bf8dbef1f6 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -252,7 +252,14 @@ def joins_for_finder end def merge_conditions(*conditions) - active_scaffold_config.model.merge_conditions(*conditions) + segments = [] + conditions.each do |condition| + unless condition.blank? + sql = active_scaffold_config.model.sanitize_sql(condition) + segments << sql unless sql.blank? + end + end + "(#{segments.join(') AND (')})" unless segments.empty? end # TODO: this should reside on the column, not the controller diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 4718947e11..24b601f029 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -42,7 +42,7 @@ def active_scaffold_input_for(column, scope = nil, options = {}) end end rescue Exception => e - logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" + logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}" raise e end end diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index 3cf7f9146a..c16c338ed1 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -7,7 +7,7 @@ def id_from_controller(controller) end def controller_id - @controller_id ||= 'as_' + id_from_controller(params[:eid] || params[:parent_controller] || params[:controller]) + controller_id ||= 'as_' + id_from_controller(params[:eid] || params[:parent_controller] || params[:controller]) end def active_scaffold_id diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index e94ae78d58..dfa08db910 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -26,7 +26,7 @@ def get_column_value(record, column) value = ' ' if value.nil? or (value.respond_to?(:empty?) and value.empty?) # fix for IE 6 return value rescue Exception => e - logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" + logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}" raise e end end diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index c0c0c4035f..066b1916be 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -157,7 +157,7 @@ def active_scaffold_search_record_select(column, options) end end rescue Exception => e - logger.error Time.now.to_s + "Sorry, we are not that smart yet. Attempted to restore search values to search fields but instead got -- #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" + logger.error Time.now.to_s + "Sorry, we are not that smart yet. Attempted to restore search values to search fields but instead got -- #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}" raise e end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index dd83646110..a9e0eae4cf 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -18,15 +18,15 @@ module ViewHelpers # access to the configuration variable def active_scaffold_config - @controller.class.active_scaffold_config + controller.class.active_scaffold_config end def active_scaffold_config_for(*args) - @controller.class.active_scaffold_config_for(*args) + controller.class.active_scaffold_config_for(*args) end def active_scaffold_controller_for(*args) - @controller.class.active_scaffold_controller_for(*args) + controller.class.active_scaffold_controller_for(*args) end ## @@ -105,7 +105,7 @@ def active_scaffold_includes(*args) options[:concat] += '_ie' if options[:concat].is_a? String ie_css = stylesheet_link_tag(*active_scaffold_ie_stylesheets(frontend).push(options)) - js + "\n" + css + "\n<!--[if IE]>" + ie_css + "<![endif]-->\n" + js + "\n" + css + "\n<!--[if IE]>".html_safe + ie_css + "<![endif]-->\n".html_safe end # a general-use loading indicator (the "stuff is happening, please wait" feedback) diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index baee4a73ca..ad56ad2847 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -1,99 +1,86 @@ # wrap the action rendering for ActiveScaffold views -module ActionView #:nodoc: - class Base - # Adds two rendering options. - # - # ==render :super - # - # This syntax skips all template overrides and goes directly to the provided ActiveScaffold templates. - # Useful if you want to wrap an existing template. Just call super! - # - # ==render :active_scaffold => #{controller.to_s}, options = {}+ - # - # Lets you embed an ActiveScaffold by referencing the controller where it's configured. - # - # You may specify options[:constraints] for the embedded scaffold. These constraints have three effects: - # * the scaffold's only displays records matching the constraint - # * all new records created will be assigned the constrained values - # * constrained columns will be hidden (they're pretty boring at this point) - # - # You may also specify options[:conditions] for the embedded scaffold. These only do 1/3 of what - # constraints do (they only limit search results). Any format accepted by ActiveRecord::Base.find is valid. - # - # Defining options[:label] lets you completely customize the list title for the embedded scaffold. - # - def render_with_active_scaffold(*args, &block) - if args.first == :super - options = args[1] || {} - options[:locals] ||= {} - options[:locals].reverse_merge! @local_assigns +module ActionView::Rendering #:nodoc: + # Adds two rendering options. + # + # ==render :super + # + # This syntax skips all template overrides and goes directly to the provided ActiveScaffold templates. + # Useful if you want to wrap an existing template. Just call super! + # + # ==render :active_scaffold => #{controller.to_s}, options = {}+ + # + # Lets you embed an ActiveScaffold by referencing the controller where it's configured. + # + # You may specify options[:constraints] for the embedded scaffold. These constraints have three effects: + # * the scaffold's only displays records matching the constraint + # * all new records created will be assigned the constrained values + # * constrained columns will be hidden (they're pretty boring at this point) + # + # You may also specify options[:conditions] for the embedded scaffold. These only do 1/3 of what + # constraints do (they only limit search results). Any format accepted by ActiveRecord::Base.find is valid. + # + # Defining options[:label] lets you completely customize the list title for the embedded scaffold. + # + def render_with_active_scaffold(*args, &block) + if args.first == :super + options = args[1] || {} + options[:locals] ||= {} + options[:locals].reverse_merge! @local_assigns - known_extensions = [:erb, :rhtml, :rjs, :haml] - # search through call stack for a template file (normally matches on first caller) - # note that we can't use split(':').first because windoze boxen may have an extra colon to specify the drive letter. the - # solution is to count colons from the *right* of the string, not the left. see issue #299. - template_path = caller.find{|c| known_extensions.include?(c.split(':')[-3].split('.').last.to_sym) } - template = File.basename(template_path.split(':')[-3]) - template, format = template.split('.') + known_extensions = [:erb, :rhtml, :rjs, :haml] + # search through call stack for a template file (normally matches on first caller) + # note that we can't use split(':').first because windoze boxen may have an extra colon to specify the drive letter. the + # solution is to count colons from the *right* of the string, not the left. see issue #299. + template_path = caller.find{|c| known_extensions.include?(c.split(':')[-3].split('.').last.to_sym) } + template = File.basename(template_path.split(':')[-3]) + template, format = template.split('.') - # paths previous to current template_path must be ignored to avoid infinite loops when is called twice or more - index = 0 - controller.class.active_scaffold_paths.each_with_index do |active_scaffold_template_path, i| - index = i + 1 and break if template_path.include? active_scaffold_template_path - end + # paths previous to current template_path must be ignored to avoid infinite loops when is called twice or more + index = 0 + controller.class.active_scaffold_paths.each_with_index do |active_scaffold_template_path, i| + index = i + 1 and break if template_path.include? active_scaffold_template_path + end - active_scaffold_template = controller.class.active_scaffold_paths.slice(index..-1).find_template(template, format, false) - render(:file => active_scaffold_template, :locals => options[:locals]) - elsif args.first.is_a?(Hash) and args.first[:active_scaffold] - require 'digest/md5' - options = args.first + active_scaffold_template = controller.class.active_scaffold_paths.slice(index..-1).find_template(template, format, false) + render(:file => active_scaffold_template, :locals => options[:locals]) + elsif args.first.is_a?(Hash) and args.first[:active_scaffold] + require 'digest/md5' + options = args.first - remote_controller = options[:active_scaffold] - constraints = options[:constraints] - conditions = options[:conditions] - eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s) - session["as:#{eid}"] = {:constraints => constraints, :conditions => conditions, :list => {:label => args.first[:label]}} - options[:params] ||= {} - options[:params].merge! :eid => eid + remote_controller = options[:active_scaffold] + constraints = options[:constraints] + conditions = options[:conditions] + eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s) + session["as:#{eid}"] = {:constraints => constraints, :conditions => conditions, :list => {:label => args.first[:label]}} + options[:params] ||= {} + options[:params].merge! :eid => eid - render_component :controller => remote_controller.to_s, :action => 'table', :params => options[:params] - else - render_without_active_scaffold(*args, &block) - end - end - alias_method_chain :render, :active_scaffold - - def partial_pieces(partial_path) - if partial_path.include?('/') - return File.dirname(partial_path), File.basename(partial_path) - else - return controller.class.controller_path, partial_path - end + render_component :controller => remote_controller.to_s, :action => 'table', :params => options[:params] + else + render_without_active_scaffold(*args, &block) end - - # This is the template finder logic, keep it updated with however we find stuff in rails - # currently this very similar to the logic in ActionBase::Base.render for options file - # TODO: Work with rails core team to find a better way to check for this. - def template_exists?(template_name, lookup_overrides = false) - begin - method = 'find_template' - method << '_without_active_scaffold' unless lookup_overrides - self.view_paths.send(method, template_name, @template_format) - return true - rescue ActionView::MissingTemplate => e - return false - end + end + alias_method_chain :render, :active_scaffold + + def partial_pieces(partial_path) + if partial_path.include?('/') + return File.dirname(partial_path), File.basename(partial_path) + else + return controller.class.controller_path, partial_path end end -end - -module ActionView::Renderable - def render_with_active_scaffold(view, local_assigns = {}) - old_local_assigns = view.instance_variable_get(:@local_assigns) - view.instance_variable_set(:@local_assigns, local_assigns) - output = render_without_active_scaffold(view, local_assigns) - view.instance_variable_set(:@local_assigns, old_local_assigns) - output + + # This is the template finder logic, keep it updated with however we find stuff in rails + # currently this very similar to the logic in ActionBase::Base.render for options file + # TODO: Work with rails core team to find a better way to check for this. + def template_exists?(template_name, lookup_overrides = false) + begin + method = 'find_template' + method << '_without_active_scaffold' unless lookup_overrides + self.view_paths.send(method, template_name, @template_format) + return true + rescue ActionView::MissingTemplate => e + return false + end end - alias_method_chain :render, :active_scaffold end diff --git a/lib/extensions/action_view_resolver.rb b/lib/extensions/action_view_resolver.rb new file mode 100644 index 0000000000..22f9d644e2 --- /dev/null +++ b/lib/extensions/action_view_resolver.rb @@ -0,0 +1,7 @@ +module ActionView + class ActiveScaffoldResolver < FileSystemResolver + def build_path(name, prefix, partial, details) + super(name, '', partial, details) + end + end +end diff --git a/lib/extensions/generic_view_paths.rb b/lib/extensions/generic_view_paths.rb deleted file mode 100644 index e79adaa842..0000000000 --- a/lib/extensions/generic_view_paths.rb +++ /dev/null @@ -1,33 +0,0 @@ -# wrap find_template to search in ActiveScaffold paths when template is missing -module ActionView #:nodoc: - class PathSet - attr_accessor :active_scaffold_paths - - def find_template_with_active_scaffold(original_template_path, format = nil, html_fallback = true) - begin - find_template_without_active_scaffold(original_template_path, format, html_fallback) - rescue MissingTemplate - if active_scaffold_paths && original_template_path.include?('/') - active_scaffold_paths.find_template_without_active_scaffold(original_template_path.split('/').last, format, html_fallback) - else - raise - end - end - end - alias_method_chain :find_template, :active_scaffold - end -end - -module ActionController #:nodoc: - class Base - def assign_names_with_active_scaffold - assign_names_without_active_scaffold - @template.view_paths.active_scaffold_paths = self.class.active_scaffold_paths if search_generic_view_paths? - end - alias_method_chain :assign_names, :active_scaffold - - def search_generic_view_paths? - !self.is_a?(ActionMailer::Base) && self.class.action_methods.include?(self.action_name) - end - end -end diff --git a/lib/extensions/resources.rb b/lib/extensions/resources.rb index 18161f7e88..0f99a6bfe9 100644 --- a/lib/extensions/resources.rb +++ b/lib/extensions/resources.rb @@ -1,26 +1,30 @@ -module ActionController - module Resources - class Resource - ACTIVE_SCAFFOLD_ROUTING = { - :collection => {:show_search => :get, :edit_associated => :get, :list => :get, :new_existing => :get, :add_existing => :post, :render_field => :get}, - :member => {:row => :get, :nested => :get, :edit_associated => :get, :add_association => :get, :update_column => :post, :destroy_existing => :delete, :render_field => :get, :delete => :get} - } - - # by overwriting the attr_reader :options, we can parse out a special :active_scaffold flag just-in-time. - def options_with_active_scaffold - if @options.delete :active_scaffold - logger.info "ActiveScaffold: extending RESTful routes for #{@plural}" - @options[:collection] ||= {} - @options[:collection].merge! ACTIVE_SCAFFOLD_ROUTING[:collection] - @options[:member] ||= {} - @options[:member].merge! ACTIVE_SCAFFOLD_ROUTING[:member] +module ActionDispatch + module Routing + class Mapper + module Resources + class Resource + ACTIVE_SCAFFOLD_ROUTING = { + :collection => {:show_search => :get, :edit_associated => :get, :list => :get, :new_existing => :get, :add_existing => :post, :render_field => :get}, + :member => {:row => :get, :nested => :get, :edit_associated => :get, :add_association => :get, :update_column => :post, :destroy_existing => :delete, :render_field => :get, :delete => :get} + } + + # by overwriting the attr_reader :options, we can parse out a special :active_scaffold flag just-in-time. + def options_with_active_scaffold + if @options.delete :active_scaffold + logger.info "ActiveScaffold: extending RESTful routes for #{@plural}" + @options[:collection] ||= {} + @options[:collection].merge! ACTIVE_SCAFFOLD_ROUTING[:collection] + @options[:member] ||= {} + @options[:member].merge! ACTIVE_SCAFFOLD_ROUTING[:member] + end + options_without_active_scaffold + end + alias_method_chain :options, :active_scaffold + + def logger + ActionController::Base::logger + end end - options_without_active_scaffold - end - alias_method_chain :options, :active_scaffold - - def logger - ActionController::Base::logger end end end From c02985e5a5426e38dacd56357fd61480b3cba4ce Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Wed, 5 May 2010 17:03:05 +0200 Subject: [PATCH 0305/2024] @params_for needs keys as symbols from params hash --- lib/active_scaffold/helpers/controller_helpers.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index a79ed04f66..4b61e549af 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -14,7 +14,8 @@ def params_for(options = {}) # :commit is a special rails variable for form buttons blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token] unless @params_for - @params_for = params.clone.delete_if { |key, value| blacklist.include? key.to_sym if key } + @params_for = {} + params.select { |key, value| blacklist.exclude? key.to_sym if key }.each {|key, value| @params_for[key.to_sym] = value.clone} @params_for[:controller] = '/' + @params_for[:controller] unless @params_for[:controller].first(1) == '/' # for namespaced controllers @params_for.delete(:id) if @params_for[:id].nil? end From 6e3407ddd3b9880e41e5b419fdb3abb4d34d7240 Mon Sep 17 00:00:00 2001 From: Volker Hochstein <v.hochstein@highstone.de> Date: Wed, 5 May 2010 17:04:59 +0200 Subject: [PATCH 0306/2024] fixed depreciation warning for model.human_name --- lib/active_scaffold/config/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index 8e08888289..1541691afe 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -91,7 +91,7 @@ def add_sti_create_links? # a generally-applicable name for this ActiveScaffold ... will be used for generating page/section headers attr_writer :label def label(options={}) - as_(@label, options) || model.human_name(options.merge(options[:count].to_i == 1 ? {} : {:default => model.name.pluralize})) + as_(@label, options) || model.model_name.human(options.merge(options[:count].to_i == 1 ? {} : {:default => model.name.pluralize})) end # STI children models, use an array of model names From 2c436196b06fa9953a8089e1881c0d820468521e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 5 May 2010 17:08:22 +0200 Subject: [PATCH 0307/2024] Fix use of false as value in select form_ui and list_ui --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index e62a870fd2..f6d79a51fc 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -130,7 +130,7 @@ def active_scaffold_input_plural_association(column, options) end def active_scaffold_translated_option(column, text, value = nil) - value ||= text + value = text if value.nil? [(text.is_a?(Symbol) ? column.active_record_class.human_attribute_name(text) : text), value] end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 1d39137c0c..7e6bda6a9c 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -118,7 +118,7 @@ def active_scaffold_column_select(column, record) format_column_value(record, column) else value = record.send(column.name) - text, val = column.options[:options].find {|text, val| (val || text).to_s == value.to_s} + text, val = column.options[:options].find {|text, val| (val.nil? ? text : val).to_s == value.to_s} value = active_scaffold_translated_option(column, text, val).first if text format_column_value(record, column, value) end From 4f60497e8b38fc8ba0b42abbce8409318e8f7929 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 6 May 2010 10:24:50 +0200 Subject: [PATCH 0308/2024] Fix ordering of string comparators --- lib/active_scaffold/finder.rb | 10 +++++----- test/misc/finder_test.rb | 1 - .../stylesheets/active_scaffold/default/stylesheet.css | 4 ++++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 28ee37559d..7e7fb0ab1a 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -144,11 +144,11 @@ def like_pattern(text_search) '!=', 'BETWEEN' ] - StringComparators = { - :contains => '%?%', - :begins_with => '?%', - :ends_with => '%?' - } + StringComparators = ActiveSupport::OrderedHash[ + :contains, '%?%', + :begins_with, '?%', + :ends_with, '%?' + ] def self.included(klass) klass.extend ClassMethods diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index 3baf157663..7423440e3b 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -80,7 +80,6 @@ def test_count_with_group end def test_disabled_pagination - ModelStub.expects(:count).returns(85) ModelStub.expects(:find).with(:all, Not(has_entries(:limit => 20, :offset => 0))) page = @klass.send :find_page, :per_page => 20, :pagination => false page.items diff --git a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css index b59b6a66f0..d4315f4d53 100644 --- a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +++ b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css @@ -52,6 +52,10 @@ padding: 5px 20px 5px 5px; color: #333; } +.active-scaffold .mark_record_column { + width: 1px; +} + /* Header ======================== */ From 2d1867bc7f54a359ef633119b73b8c90b53eefec Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 6 May 2010 12:02:56 +0200 Subject: [PATCH 0309/2024] Use crud_type with authorized_for? --- lib/active_scaffold/actions/mark.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index 128138989c..113d376975 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -67,7 +67,7 @@ def mark_respond_to_js # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def mark_authorized? - authorized_for?(:action => :read) + authorized_for?(:crud_type => :read) end end end From 446013d53771dfbeafa928f3ed80e929f49039d8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 6 May 2010 12:03:20 +0200 Subject: [PATCH 0310/2024] Fix selected value in select form_ui with simple columns, when options have only symbols to translate and use as values --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index f6d79a51fc..50f8e4b806 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -130,7 +130,7 @@ def active_scaffold_input_plural_association(column, options) end def active_scaffold_translated_option(column, text, value = nil) - value = text if value.nil? + value = text.to_s if value.nil? [(text.is_a?(Symbol) ? column.active_record_class.human_attribute_name(text) : text), value] end From e889038c2127b571500b7cd7e3d28034f50457c2 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 6 May 2010 15:31:57 +0200 Subject: [PATCH 0311/2024] Fix skip checking record is empty when show_blank_record is disabled --- lib/active_scaffold/attribute_params.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 5ba4dbcf6a..2d0d12d04f 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -148,7 +148,8 @@ def column_value_from_param_value(parent_record, column, value) def find_or_create_for_params(params, parent_column, parent_record) current = parent_record.send(parent_column.name) klass = parent_column.association.klass - return nil if parent_column.show_blank_record and attributes_hash_is_empty?(params, klass) + debugger + return nil if parent_column.show_blank_record?(current) and attributes_hash_is_empty?(params, klass) if params.has_key? :id # modifying the current object of a singular association From d5d3887fec21e18a3fb6009eb989f42be4086d98 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 6 May 2010 17:00:46 +0200 Subject: [PATCH 0312/2024] Remove debugger --- lib/active_scaffold/attribute_params.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 2d0d12d04f..37529c1bc7 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -148,7 +148,6 @@ def column_value_from_param_value(parent_record, column, value) def find_or_create_for_params(params, parent_column, parent_record) current = parent_record.send(parent_column.name) klass = parent_column.association.klass - debugger return nil if parent_column.show_blank_record?(current) and attributes_hash_is_empty?(params, klass) if params.has_key? :id From 0f8eb34d375cbfab5ee14841dd38c76d39d15f83 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 7 May 2010 13:20:30 +0200 Subject: [PATCH 0313/2024] Allow to enable string comparators in search_ui, needed to search in a string column of an association --- lib/active_scaffold/helpers/search_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 80a08c1451..51d34bfafd 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -128,7 +128,7 @@ def field_search_params_range_values(column) def active_scaffold_search_range(column, options) opt_value, from_value, to_value = field_search_params_range_values(column) select_options = ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} - select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} if column.column && column.column.text? + select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} if column.options[:string_comparators] || column.column && column.column.text? html = [] html << select_tag("#{options[:name]}[opt]", From 830e447fc5c97647f0e933be24256e43df4d2239 Mon Sep 17 00:00:00 2001 From: Dmitry Plashchynski <plashchynski@gmail.com> Date: Sat, 8 May 2010 23:51:29 +0300 Subject: [PATCH 0314/2024] Don't put empty span#description when column description is not present. --- frontends/default/views/_form_attribute.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_form_attribute.html.erb b/frontends/default/views/_form_attribute.html.erb index 821d97843d..01d68b4e58 100644 --- a/frontends/default/views/_form_attribute.html.erb +++ b/frontends/default/views/_form_attribute.html.erb @@ -8,7 +8,7 @@ <% if column.options.is_a?(Hash) && column.options[:update_column] -%> <%= loading_indicator_tag(:action => :render_field, :id => params[:id]) %> <% end -%> - <% if column.description -%> + <% if column.description.present? -%> <span class="description"><%= column.description %></span> <% end -%> </dd> From 95c3d212f36b0e044c70370822f1e1075d4893df Mon Sep 17 00:00:00 2001 From: Dmitry Plashchynski <plashchynski@gmail.com> Date: Tue, 11 May 2010 03:44:54 +0800 Subject: [PATCH 0315/2024] Fixed Object#type deprecated warning. This happens when search_ui is not defined and column.column is nil (virtual or association column). --- lib/active_scaffold/finder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 7e7fb0ab1a..7880850fdf 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -31,11 +31,11 @@ def create_conditions_for_columns(tokens, columns, text_search = :full) def condition_for_column(column, value, text_search = :full) like_pattern = like_pattern(text_search) return unless column and column.search_sql and not value.blank? - search_ui = column.search_ui || column.column.type + search_ui = column.search_ui || column.column.try(:type) begin if self.respond_to?("condition_for_#{column.name}_column") self.send("condition_for_#{column.name}_column", column, value, like_pattern) - elsif self.respond_to?("condition_for_#{search_ui}_type") + elsif search_ui && self.respond_to?("condition_for_#{search_ui}_type") self.send("condition_for_#{search_ui}_type", column, value, like_pattern) else case search_ui From aca81c20da12f3de9a013d69653d36e17af5e281 Mon Sep 17 00:00:00 2001 From: Chris Eppstein <chris@eppsteins.net> Date: Fri, 23 Apr 2010 05:43:42 +0800 Subject: [PATCH 0316/2024] Don't enforce this check on finder_sql associations --- lib/active_scaffold/attribute_params.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 37529c1bc7..3ed8c3da1e 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -73,7 +73,7 @@ def update_record_from_params(parent_record, columns, attributes) if parent_record.new_record? parent_record.class.reflect_on_all_associations.each do |a| - next unless [:has_one, :has_many].include?(a.macro) and not a.options[:through] + next unless [:has_one, :has_many].include?(a.macro) and not (a.options[:through] || a.options[:finder_sql]) next unless association_proxy = parent_record.send(a.name) raise ActiveScaffold::ReverseAssociationRequired, "Association #{a.name}: In order to support :has_one and :has_many where the parent record is new and the child record(s) validate the presence of the parent, ActiveScaffold requires the reverse association (the belongs_to)." unless a.reverse From 3551c40c762c1c7a1967b35c98efb17ccb1bb6a2 Mon Sep 17 00:00:00 2001 From: Joey Aghion <joey@aghion.com> Date: Mon, 3 May 2010 11:58:41 +0800 Subject: [PATCH 0317/2024] make active_scaffold_includes compatible with new html_safe behavior --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index dd83646110..5a62ad089c 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -105,7 +105,7 @@ def active_scaffold_includes(*args) options[:concat] += '_ie' if options[:concat].is_a? String ie_css = stylesheet_link_tag(*active_scaffold_ie_stylesheets(frontend).push(options)) - js + "\n" + css + "\n<!--[if IE]>" + ie_css + "<![endif]-->\n" + "#{js}\n#{css}\n<!--[if IE]>#{ie_css}<![endif]-->\n" end # a general-use loading indicator (the "stuff is happening, please wait" feedback) From 9ce394e16493dc1bccd076c6c61a3f3218e790d7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 12 May 2010 13:17:39 +0200 Subject: [PATCH 0318/2024] Show to_label in show header --- frontends/default/views/_show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_show.html.erb b/frontends/default/views/_show.html.erb index 14848254bf..b7863149d0 100644 --- a/frontends/default/views/_show.html.erb +++ b/frontends/default/views/_show.html.erb @@ -1,8 +1,8 @@ -<h4><%= active_scaffold_config.show.label -%></h4> +<h4><%= @record.to_label.nil? ? active_scaffold_config.show.label : as_(:show_model, :model => clean_column_value(@record.to_label)) %></h4> <%= render :partial => 'show_columns', :locals => {:columns => active_scaffold_config.show.columns} -%> <p class="form-footer"> <%= link_to as_(:close), main_path_to_return, :class => 'cancel' %> <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> -</p> \ No newline at end of file +</p> From a783e6bf47a6658133179f8275e48dd23eb01673 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 14 May 2010 13:16:21 +0200 Subject: [PATCH 0319/2024] Bridge for unobtrusive date picker --- .../helpers/form_column_helpers.rb | 10 +++++++++- lib/bridges/unobtrusive_date_picker/bridge.rb | 7 +++++++ .../unobtrusive_date_picker/lib/form_ui.rb | 14 ++++++++++++++ .../lib/unobtrusive_date_picker_bridge.rb | 12 ++++++++++++ .../unobtrusive_date_picker/lib/view_helpers.rb | 15 +++++++++++++++ lib/extensions/name_option_for_datetime.rb | 12 ------------ 6 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 lib/bridges/unobtrusive_date_picker/bridge.rb create mode 100644 lib/bridges/unobtrusive_date_picker/lib/form_ui.rb create mode 100644 lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb create mode 100644 lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb delete mode 100644 lib/extensions/name_option_for_datetime.rb diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 50f8e4b806..f8cca4aef9 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -30,12 +30,13 @@ def active_scaffold_input_for(column, scope = nil, options = {}) else # for textual fields we pass different options text_types = [:text, :string, :integer, :float, :decimal] + date_types = [:date, :datetime, :time] options = active_scaffold_input_text_options(options) if text_types.include?(column.column.type) + options = active_scaffold_input_date_options(column, options) if date_types.include?(column.column.type) if column.column.type == :string && options[:maxlength].blank? options[:maxlength] = column.column.limit options[:size] ||= ActionView::Helpers::InstanceTag::DEFAULT_FIELD_OPTIONS["size"] end - options[:include_blank] = true if column.column.null and [:date, :datetime, :time].include?(column.column.type) options[:value] = format_number_value(@record.send(column.name), column.options) if column.column.number? input(:record, column.name, options.merge(column.options)) end @@ -56,6 +57,13 @@ def active_scaffold_input_text_options(options = {}) options end + # the standard active scaffold options used for date, datetime and time inputs + def active_scaffold_input_date_options(column, options = {}) + options[:include_blank] = true if column.column.null + options[:prefix] = options[:name].gsub("[#{column.name}]", '') + options + end + # the standard active scaffold options used for class, name and scope def active_scaffold_input_options(column, scope = nil, options = {}) name = scope ? "record#{scope}[#{column.name}]" : "record[#{column.name}]" diff --git a/lib/bridges/unobtrusive_date_picker/bridge.rb b/lib/bridges/unobtrusive_date_picker/bridge.rb new file mode 100644 index 0000000000..2e7d1e4ba4 --- /dev/null +++ b/lib/bridges/unobtrusive_date_picker/bridge.rb @@ -0,0 +1,7 @@ +ActiveScaffold.bridge "UnobtrusiveDatePicker" do + install do + require File.join(File.dirname(__FILE__), "lib/unobtrusive_date_picker_bridge.rb") + require File.join(File.dirname(__FILE__), "lib/form_ui.rb") + require File.join(File.dirname(__FILE__), "lib/view_helpers.rb") + end +end diff --git a/lib/bridges/unobtrusive_date_picker/lib/form_ui.rb b/lib/bridges/unobtrusive_date_picker/lib/form_ui.rb new file mode 100644 index 0000000000..26c5df971a --- /dev/null +++ b/lib/bridges/unobtrusive_date_picker/lib/form_ui.rb @@ -0,0 +1,14 @@ +module ActiveScaffold + module Helpers + module FormColumnHelpers + def active_scaffold_input_datepicker(column, options) + method = "date#{'time' if column.column.type == :datetime}_select" + options[:include_blank] = true if column.column and column.column.null and [:date, :datetime, :time].include?(column.column.type) + html_options = options.update(column.options).delete(:html_options) || {} + options = active_scaffold_input_date_options(column, options) + args = [:record, column.name, options, html_options] + self.send(method, *args) + date_picker(*args) + end + end + end +end diff --git a/lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb b/lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb new file mode 100644 index 0000000000..867ef89f28 --- /dev/null +++ b/lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb @@ -0,0 +1,12 @@ +module ActiveScaffold::Config + class Core < Base + def initialize_with_unobtrusive_date_picker(model_id) + initialize_without_unobtrusive_date_picker(model_id) + date_fields = self.model.columns.select {|c| [:date, :datetime].include?(c.type) } + + # automatically set the forum_ui to a file column + date_fields.each {|field| self.columns[field.name.to_sym].form_ui = :datepicker} + end + alias_method_chain :initialize, :unobtrusive_date_picker + end +end diff --git a/lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb b/lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb new file mode 100644 index 0000000000..6a24a9acdc --- /dev/null +++ b/lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb @@ -0,0 +1,15 @@ +module ActiveScaffold + module Helpers + module ViewHelpers + def active_scaffold_stylesheets_with_date_picker(frontend = :default) + active_scaffold_stylesheets_without_date_picker(frontend) + unobtrusive_datepicker_stylesheets + end + alias_method_chain :active_scaffold_stylesheets, :date_picker + + def active_scaffold_javascripts_with_date_picker(frontend = :default) + active_scaffold_javascripts_without_date_picker(frontend) + unobtrusive_datepicker_javascripts + end + alias_method_chain :active_scaffold_javascripts, :date_picker + end + end +end diff --git a/lib/extensions/name_option_for_datetime.rb b/lib/extensions/name_option_for_datetime.rb deleted file mode 100644 index 48c4580cd1..0000000000 --- a/lib/extensions/name_option_for_datetime.rb +++ /dev/null @@ -1,12 +0,0 @@ -module ActionView - module Helpers - class InstanceTag - private - def datetime_selector_with_name(options, html_options) - options.merge!(:prefix => options[:name].gsub(/\[[^\[]*\]$/,'')) if options[:name] - datetime_selector_without_name(options, html_options) - end - alias_method_chain :datetime_selector, :name - end - end -end From b0e532bc3f48cfc2f4c64594acb4d6ec379cbe72 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 14 May 2010 17:36:00 +0200 Subject: [PATCH 0320/2024] Fix for setting non-string options in :select form_ui --- lib/active_scaffold/helpers/form_column_helpers.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index f8cca4aef9..1ca922f45f 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -138,8 +138,8 @@ def active_scaffold_input_plural_association(column, options) end def active_scaffold_translated_option(column, text, value = nil) - value = text.to_s if value.nil? - [(text.is_a?(Symbol) ? column.active_record_class.human_attribute_name(text) : text), value] + value = text if value.nil? + [(text.is_a?(Symbol) ? column.active_record_class.human_attribute_name(text) : text), value.to_s] end def active_scaffold_translated_options(column) @@ -154,7 +154,7 @@ def active_scaffold_input_select(column, html_options) elsif column.plural_association? active_scaffold_input_plural_association(column, html_options) else - options = { :selected => @record.send(column.name) } + options = { :selected => @record.send(column.name).to_s } options_for_select = active_scaffold_translated_options(column) html_options.update(column.options[:html_options] || {}) options.update(column.options) From 58f854465266948bb2d587ba9a955f20060387be Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 17 May 2010 12:46:52 +0200 Subject: [PATCH 0321/2024] Fix show_blank_record? for singular associations --- lib/active_scaffold/data_structures/column.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 0babd5a86e..c9da3c082c 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -182,7 +182,7 @@ def associated_number? def show_blank_record?(associated) if @show_blank_record return false unless self.association.klass.authorized_for?(:crud_type => :create) - self.plural_association? or (self.singular_association? and associated.empty?) + self.plural_association? or (self.singular_association? and associated.blank?) end end From dd05c3b5c7b30508e84441481490d6e67d48eb26 Mon Sep 17 00:00:00 2001 From: unknown <Install@.(none)> Date: Mon, 17 May 2010 15:12:48 +0200 Subject: [PATCH 0322/2024] verify was removed from Rails and is now available as a plugin --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index f30d06d384..f66c18beca 100644 --- a/README +++ b/README @@ -29,4 +29,7 @@ Rails < 2.1: Active Scaffold 1-1-stable (no guarantees) Since Rails 2.3, render_component plugin is needed for nested and embbeded scaffolds. It works with rails-2.3 branch from ewildgoose repository: script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3 +Since Rails 3.0, verification plugin is needed: +rails plugin install git://github.com/rails/verification.git + Released under the MIT license (included) From cbb6476533295e097397cc74a0964af676533281 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 17 May 2010 16:53:21 +0200 Subject: [PATCH 0323/2024] create view is shown without errors --- README | 3 ++- frontends/default/views/_create_form.html.erb | 18 +++++++++--------- .../default/views/_form_messages.html.erb | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README b/README index f66c18beca..6d45080d54 100644 --- a/README +++ b/README @@ -29,7 +29,8 @@ Rails < 2.1: Active Scaffold 1-1-stable (no guarantees) Since Rails 2.3, render_component plugin is needed for nested and embbeded scaffolds. It works with rails-2.3 branch from ewildgoose repository: script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3 -Since Rails 3.0, verification plugin is needed: +Since Rails 3.0, verification and dynamic form plugins are needed: rails plugin install git://github.com/rails/verification.git +rails plugin install git://github.com/rails/dynamic_form.git Released under the MIT license (included) diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index 0c89d98820..a613ba8dd1 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -9,16 +9,16 @@ if xhr :loading => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible';", :class => 'create' else - form_remote_tag :url => url_options, - :after => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => :create)}');", - :complete => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => :create)}');", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :html => { + form_tag :url => url_options, + :remote => true, + :after => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => :create)}');", + :complete => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => :create)}');", + :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", + :html => { :href => url_for(url_options), :onsubmit => onsubmit, :id => element_form_id(:action => :create), - :class => 'create' - } + :class => 'create'} end else form_tag url_options, @@ -28,11 +28,11 @@ else :class => 'create' end -%> - <h4><%= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.human_name(:count => 1) : nil) -%></h4> + <h4><%= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil) -%></h4> <div id="<%= element_messages_id(:action => :create) %>" class="messages-container"> <% if request.xhr? -%> - <%= error_messages_for :record, :object_name => @record.class.human_name.downcase %> + <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> <% else -%> <%= render :partial => 'form_messages' %> <% end -%> diff --git a/frontends/default/views/_form_messages.html.erb b/frontends/default/views/_form_messages.html.erb index ba7217a63f..7c258fe991 100644 --- a/frontends/default/views/_form_messages.html.erb +++ b/frontends/default/views/_form_messages.html.erb @@ -1,5 +1,5 @@ <%= render :partial => 'messages' %> <% unless @record.nil? %> - <%= error_messages_for :record, :object_name => @record.class.human_name.downcase %> + <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> <% end %> \ No newline at end of file From c0010a7a701eed9511572921e73ff691ee298a42 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 20 May 2010 09:47:47 +0200 Subject: [PATCH 0324/2024] Add is null and is not null comparators to field search --- lib/active_scaffold/finder.rb | 10 ++++++++-- lib/active_scaffold/helpers/search_column_helpers.rb | 1 + lib/active_scaffold/locale/de.rb | 5 +++++ lib/active_scaffold/locale/en.rb | 2 ++ lib/active_scaffold/locale/es.yml | 2 ++ lib/active_scaffold/locale/fr.rb | 5 +++++ lib/active_scaffold/locale/hu.yml | 5 +++++ lib/active_scaffold/locale/ja.yml | 5 +++++ lib/active_scaffold/locale/ru.yml | 5 +++++ 9 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 7880850fdf..2acf665e3a 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -60,7 +60,9 @@ def condition_for_column(column, value, text_search = :full) def condition_for_integer_type(column, value, like_pattern = nil) if !value.is_a?(Hash) ["#{column.search_sql} = ?", column.column.nil? ? value.to_f : column.column.type_cast(value)] - elsif value[:from].blank? or not ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) + elsif ActiveScaffold::Finder::NullComparators.include?(value[:opt]) + condition = "#{column.search_sql} #{value[:opt].humanize}" + elsif value[:from].blank? nil elsif value[:opt] == 'BETWEEN' condition = "#{column.search_sql} BETWEEN ? AND ?" @@ -69,7 +71,7 @@ def condition_for_integer_type(column, value, like_pattern = nil) else [condition, column.column.type_cast(value[:from]), column.column.type_cast(value[:to])] end - else + elsif ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) ["#{column.search_sql} #{value[:opt]} ?", column.column.nil? ? value[:from].to_f : column.column.type_cast(value[:from])] end end @@ -83,6 +85,8 @@ def condition_for_range_type(column, value, like_pattern = nil) else ["#{column.search_sql} = ?", column.column.type_cast(value)] end + elsif ActiveScaffold::Finder::NullComparators.include?(value[:opt]) + condition = "#{column.search_sql} #{value[:opt].humanize}" elsif value[:from].blank? nil elsif ActiveScaffold::Finder::StringComparators.values.include?(value[:opt]) @@ -150,6 +154,8 @@ def like_pattern(text_search) :ends_with, '%?' ] + NullComparators = ['is_null', 'is_not_null'] + def self.included(klass) klass.extend ClassMethods end diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 51d34bfafd..f5624162ad 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -129,6 +129,7 @@ def active_scaffold_search_range(column, options) opt_value, from_value, to_value = field_search_params_range_values(column) select_options = ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} if column.options[:string_comparators] || column.column && column.column.text? + select_options += ActiveScaffold::Finder::NullComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} if column.column && column.column.null html = [] html << select_tag("#{options[:name]}[opt]", diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 13de7d9eaa..ed4de77bf0 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -57,6 +57,11 @@ :'<' => '<', :'!=' => '!=', :between => 'Zwischen', + :is_null => 'Is null', + :is_not_null => 'Is not null', + :contains => 'Contains', + :begins_with => 'Begins with', + :ends_with => 'Ends with', # error_messages :cant_destroy_record => "{{record}} kann nicht gelöscht werden", diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 889587e8ea..5b4f3325c0 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -60,6 +60,8 @@ :'<' => '<', :'!=' => '!=', :between => 'Between', + :is_null => 'Is null', + :is_not_null => 'Is not null', :contains => 'Contains', :begins_with => 'Begins with', :ends_with => 'Ends with', diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index 9e42da2807..cf67caebb0 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -61,6 +61,8 @@ es: '<': '<' '!=': '!=' between: 'Entre' + is_null: 'Es nulo' + is_not_null: 'No es nulo' contains: 'Contiene' begins_with: 'Empieza con' ends_with: 'Termina con' diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 664757b8b6..a7cb2c095e 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -57,6 +57,11 @@ :'<' => '<', :'!=' => '!=', :between => 'Entre', + :is_null => 'Is null', + :is_not_null => 'Is not null', + :contains => 'Contains', + :begins_with => 'Begins with', + :ends_with => 'Ends with', # error_messages :internal_error => 'Erreur de la requête (code 500, Erreur interne)', diff --git a/lib/active_scaffold/locale/hu.yml b/lib/active_scaffold/locale/hu.yml index d9a47cd792..6fbf21c256 100644 --- a/lib/active_scaffold/locale/hu.yml +++ b/lib/active_scaffold/locale/hu.yml @@ -56,6 +56,11 @@ hu: '<': '<' '!=': '!=' between: 'Között' + is_null: 'Is null' + is_not_null: 'Is not null' + contains: 'Contains' + begins_with: 'Begins with' + ends_with: 'Ends with' # error_messages internal_error: 'A lekérés sikertelen (code 500, Internal Error)' diff --git a/lib/active_scaffold/locale/ja.yml b/lib/active_scaffold/locale/ja.yml index 7240a5dfa4..09e0282ed6 100644 --- a/lib/active_scaffold/locale/ja.yml +++ b/lib/active_scaffold/locale/ja.yml @@ -56,6 +56,11 @@ ja: '<': '<' '!=': '!=' between: 'Between' # needed? + is_null: 'Is null' + is_not_null: 'Is not null' + contains: 'Contains' + begins_with: 'Begins with' + ends_with: 'Ends with' # error_messages cant_destroy_record: "{{record}}を削除で来ません" diff --git a/lib/active_scaffold/locale/ru.yml b/lib/active_scaffold/locale/ru.yml index 77cb85e74e..f29e3bcbe1 100644 --- a/lib/active_scaffold/locale/ru.yml +++ b/lib/active_scaffold/locale/ru.yml @@ -55,6 +55,11 @@ ru: '<': '<' '!=': '!=' between: 'Между' + is_null: 'Is null' + is_not_null: 'Is not null' + contains: 'Contains' + begins_with: 'Begins with' + ends_with: 'Ends with' # error_messages internal_error: 'Внутренняя ошибка сервера.' From 8a630691b4f7343e02a76dcaab8dd26405cd9ec4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 20 May 2010 17:53:04 +0200 Subject: [PATCH 0325/2024] Add dependent protect bridge --- lib/bridges/dependent_protect/bridge.rb | 10 ++++ .../lib/dependent_protect_bridge.rb | 11 ++++ .../active_scaffold_dependent_protect_test.rb | 34 ++++++++++++ test/bridges/company.rb | 54 +++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 lib/bridges/dependent_protect/bridge.rb create mode 100644 lib/bridges/dependent_protect/lib/dependent_protect_bridge.rb create mode 100644 test/bridges/active_scaffold_dependent_protect_test.rb create mode 100644 test/bridges/company.rb diff --git a/lib/bridges/dependent_protect/bridge.rb b/lib/bridges/dependent_protect/bridge.rb new file mode 100644 index 0000000000..3ed3ba4693 --- /dev/null +++ b/lib/bridges/dependent_protect/bridge.rb @@ -0,0 +1,10 @@ +ActiveScaffold.bridge "DependentProtect" do + install do + # check to see if the old bridge was installed. If so, warn them + # we can detect this by checking to see if the bridge was installed before calling this code + if ActiveRecord::Base.instance_methods.include?("authorized_for_delete?") + raise RuntimeError, "We've detected that you have active_scaffold_dependent_protect installed. This plugin has been moved to core. Please remove active_scaffold_dependent_protect to prevent any conflicts" + end + require File.join(File.dirname(__FILE__), "lib/dependent_protect_bridge.rb") + end +end diff --git a/lib/bridges/dependent_protect/lib/dependent_protect_bridge.rb b/lib/bridges/dependent_protect/lib/dependent_protect_bridge.rb new file mode 100644 index 0000000000..3db3e2890a --- /dev/null +++ b/lib/bridges/dependent_protect/lib/dependent_protect_bridge.rb @@ -0,0 +1,11 @@ +module DependentProtectSecurity + def self.included(base) + base.class_inheritable_accessor :dependent_associations + end + protected + def authorized_for_delete? + self.class.dependent_associations ||= self.class.reflect_on_all_associations.select {|assoc| assoc.options[:dependent] == :protect} + self.class.dependent_associations.all? {|assoc| self.send(assoc.name).blank?} + end +end +ActiveRecord::Base.class_eval { include DependentProtectSecurity } diff --git a/test/bridges/active_scaffold_dependent_protect_test.rb b/test/bridges/active_scaffold_dependent_protect_test.rb new file mode 100644 index 0000000000..d5d1c99cf8 --- /dev/null +++ b/test/bridges/active_scaffold_dependent_protect_test.rb @@ -0,0 +1,34 @@ +require 'test/unit' +require File.join(File.dirname(__FILE__), 'company') + +class ActiveScaffoldDependentProtectTest < Test::Unit::TestCase + def test_destroy_protected_with_companies + protected_firm = Company.new(:with_companies) + assert !protected_firm.send(:authorized_for_delete?) + end + + def test_destroy_protected_with_company + protected_firm = Company.new(:with_company) + assert !protected_firm.send(:authorized_for_delete?) + end + + def test_destroy_protected_with_main_company + protected_firm = Company.new(:with_main_company) + assert !protected_firm.send(:authorized_for_delete?) + end + + def test_destroy_protected_without_companies + protected_firm_without_companies = Company.new(:without_companies) + assert protected_firm_without_companies.send(:authorized_for_delete?) + end + + def test_destroy_protected_without_company + protected_firm_without_company = Company.new(:without_company) + assert protected_firm_without_company.send(:authorized_for_delete?) + end + + def test_destroy_protected_without_main_company + protected_firm_without_main_company = Company.new(:without_main_company) + assert protected_firm_without_main_company.send(:authorized_for_delete?) + end +end diff --git a/test/bridges/company.rb b/test/bridges/company.rb new file mode 100644 index 0000000000..734da806e5 --- /dev/null +++ b/test/bridges/company.rb @@ -0,0 +1,54 @@ +require 'rubygems' +require 'active_record' +require 'active_record/reflection' +require File.join(File.dirname(__FILE__), '../../lib/bridges/dependent_protect/lib/dependent_protect_bridge') + +# Mocking everything necesary to test the plugin. +class Company + def initialize(with_or_without) + @with_companies = with_or_without == :with_companies + @with_company = with_or_without == :with_company + @with_main_company = with_or_without == :with_main_company + end + + def self.class_name + self.name + end + + # not the real signature of the method, but forgive me + def self.before_destroy(s=nil) + @@before = s + end + + include ActiveRecord::Reflection + include DependentProtectSecurity + + def self.has_many(association_id, options = {}) + reflection = create_reflection(:has_many, association_id, options, self) + end + def self.has_one(association_id, options = {}) + reflection = create_reflection(:has_one, association_id, options, self) + end + def self.belongs_to(association_id, options = {}) + reflection = create_reflection(:belongs_to, association_id, options, self) + end + has_many :companies, :dependent => :protect + has_one :company, :dependent => :protect + belongs_to :main_company, :dependent => :protect, :class_name => 'Company' + + def companies + if @with_companies + [nil] + else + [] + end + end + + def company + @with_company + end + + def main_company + @with_main_company + end +end From 4efbc089e5581e11c6fa293f43b77840dcdf3e9a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 21 May 2010 10:08:28 +0200 Subject: [PATCH 0326/2024] use new unobtrusive javascript api for create forms --- frontends/default/views/_create_form.html.erb | 26 ++++++++++++------- .../views/_create_form_on_list.html.erb | 26 ++++++++++++------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index a613ba8dd1..3000873ff4 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -9,16 +9,11 @@ if xhr :loading => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible';", :class => 'create' else - form_tag :url => url_options, + form_tag url_options, :remote => true, - :after => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => :create)}');", - :complete => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => :create)}');", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :html => { - :href => url_for(url_options), - :onsubmit => onsubmit, - :id => element_form_id(:action => :create), - :class => 'create'} + :id => element_form_id(:action => :create), + :onsubmit => onsubmit, + :class => 'create' end else form_tag url_options, @@ -26,7 +21,7 @@ else :id => element_form_id(:action => :create), :multipart => active_scaffold_config.create.multipart?, :class => 'create' -end -%> +end %> <h4><%= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil) -%></h4> @@ -49,4 +44,15 @@ end -%> </form> <script type="text/javascript"> Form.focusFirstElement('<%= element_form_id(:action => :create) -%>'); +$('<% element_form_id(:action => :create) %>').observe("ajax:after", function(event){ + $('<% loading_indicator_id(:action => :create, :id => params[:id]) %>').style.visibility = 'visible'; + Form.disable('<% element_form_id(:action => :create)%>'); +}) +$('<% element_form_id(:action => :create) %>').observe("ajax:complete", function(event){ + $('<% loading_indicator_id(:action => :create, :id => params[:id]) %>').style.visibility = 'hidden'; + Form.enable('<% element_form_id(:action => :create)%>'); +}) +$('<% element_form_id(:action => :create) %>').observe("ajax:failure", function(event){ + ActiveScaffold.report_500_response('<% active_scaffold_id %>'); +}) </script> diff --git a/frontends/default/views/_create_form_on_list.html.erb b/frontends/default/views/_create_form_on_list.html.erb index 2d15a9d6d3..fe91281f66 100644 --- a/frontends/default/views/_create_form_on_list.html.erb +++ b/frontends/default/views/_create_form_on_list.html.erb @@ -6,16 +6,11 @@ if active_scaffold_config.create.multipart? # file_uploads :id => element_form_id(:action => :create), :class => 'create' else - form_remote_tag :url => url_options, - :after => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => :create)}');", - :complete => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => :create)}');", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :html => { - :href => url_for(url_options), - :onsubmit => onsubmit, - :id => element_form_id(:action => :create), - :class => 'create' - } + form_tag url_options, + :remote => true, + :id => element_form_id(:action => :create), + :onsubmit => onsubmit, + :class => 'create' end -%> <h4><%= active_scaffold_config.create.label -%></h4> @@ -35,4 +30,15 @@ end -%> </form> <script type="text/javascript"> Form.focusFirstElement('<%= element_form_id(:action => :create) -%>'); +$('<% element_form_id(:action => :create) %>').observe("ajax:after", function(event){ + $('<% loading_indicator_id(:action => :create, :id => params[:id]) %>').style.visibility = 'visible'; + Form.disable('<% element_form_id(:action => :create)%>'); +}) +$('<% element_form_id(:action => :create) %>').observe("ajax:complete", function(event){ + $('<% loading_indicator_id(:action => :create, :id => params[:id]) %>').style.visibility = 'hidden'; + Form.enable('<% element_form_id(:action => :create)%>'); +}) +$('<% element_form_id(:action => :create) %>').observe("ajax:failure", function(event){ + ActiveScaffold.report_500_response('<% active_scaffold_id %>'); +}) </script> \ No newline at end of file From cbe2f31b1501b9a70930fa95f2f7e580710844a8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 21 May 2010 10:36:06 +0200 Subject: [PATCH 0327/2024] same for update form --- frontends/default/views/_update_form.html.erb | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index ba248a142d..82b925d893 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -10,17 +10,12 @@ if xhr :class => 'update', :method => :put else - form_remote_tag :url => url_options, - :after => "$('#{loading_indicator_id(:action => :update, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => :update)}');", - :complete => "$('#{loading_indicator_id(:action => :update, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => :update)}');", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :html => { - :href => url_for(url_options), - :onsubmit => onsubmit, - :id => element_form_id(:action => :update), - :class => 'update', - :method => :put - } + form_tag url_options, + :onsubmit => onsubmit, + :id => element_form_id(:action => :update), + :multipart => active_scaffold_config.update.multipart?, + :class => 'update', + :method => :put end else form_tag url_options, @@ -53,4 +48,15 @@ end </form> <script type="text/javascript"> Form.focusFirstElement('<%= element_form_id(:action => :update) -%>'); +$('<% element_form_id(:action => :update) %>').observe("ajax:after", function(event){ + $('<% loading_indicator_id(:action => :update, :id => params[:id]) %>').style.visibility = 'visible'; + Form.disable('<% element_form_id(:action => :update)%>'); +}) +$('<% element_form_id(:action => :update) %>').observe("ajax:complete", function(event){ + $('<% loading_indicator_id(:action => :update, :id => params[:id]) %>').style.visibility = 'hidden'; + Form.enable('<% element_form_id(:action => :update)%>'); +}) +$('<% element_form_id(:action => :update) %>').observe("ajax:failure", function(event){ + ActiveScaffold.report_500_response('<% active_scaffold_id %>'); +}) </script> From 568b018811375079ccf5359b423b0cdff8dfa32b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 21 May 2010 13:36:17 +0200 Subject: [PATCH 0328/2024] refactor form javascript into extra partial --- frontends/default/views/_create_form.html.erb | 15 +-------------- .../default/views/_create_form_on_list.html.erb | 15 +-------------- frontends/default/views/_form_js.html.erb | 14 ++++++++++++++ frontends/default/views/_update_form.html.erb | 15 +-------------- 4 files changed, 17 insertions(+), 42 deletions(-) create mode 100644 frontends/default/views/_form_js.html.erb diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index 3000873ff4..5c2e658b6b 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -42,17 +42,4 @@ end %> </p> </form> -<script type="text/javascript"> -Form.focusFirstElement('<%= element_form_id(:action => :create) -%>'); -$('<% element_form_id(:action => :create) %>').observe("ajax:after", function(event){ - $('<% loading_indicator_id(:action => :create, :id => params[:id]) %>').style.visibility = 'visible'; - Form.disable('<% element_form_id(:action => :create)%>'); -}) -$('<% element_form_id(:action => :create) %>').observe("ajax:complete", function(event){ - $('<% loading_indicator_id(:action => :create, :id => params[:id]) %>').style.visibility = 'hidden'; - Form.enable('<% element_form_id(:action => :create)%>'); -}) -$('<% element_form_id(:action => :create) %>').observe("ajax:failure", function(event){ - ActiveScaffold.report_500_response('<% active_scaffold_id %>'); -}) -</script> +<%= render :partial => 'form_js', :locals => {:action_type => :create, :id => params[:id]} %> diff --git a/frontends/default/views/_create_form_on_list.html.erb b/frontends/default/views/_create_form_on_list.html.erb index fe91281f66..40e5f0eba3 100644 --- a/frontends/default/views/_create_form_on_list.html.erb +++ b/frontends/default/views/_create_form_on_list.html.erb @@ -28,17 +28,4 @@ end -%> <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> </p> </form> -<script type="text/javascript"> -Form.focusFirstElement('<%= element_form_id(:action => :create) -%>'); -$('<% element_form_id(:action => :create) %>').observe("ajax:after", function(event){ - $('<% loading_indicator_id(:action => :create, :id => params[:id]) %>').style.visibility = 'visible'; - Form.disable('<% element_form_id(:action => :create)%>'); -}) -$('<% element_form_id(:action => :create) %>').observe("ajax:complete", function(event){ - $('<% loading_indicator_id(:action => :create, :id => params[:id]) %>').style.visibility = 'hidden'; - Form.enable('<% element_form_id(:action => :create)%>'); -}) -$('<% element_form_id(:action => :create) %>').observe("ajax:failure", function(event){ - ActiveScaffold.report_500_response('<% active_scaffold_id %>'); -}) -</script> \ No newline at end of file +<%= render :partial => 'form_js', :locals => {:action_type => :create, :id => params[:id]} %> \ No newline at end of file diff --git a/frontends/default/views/_form_js.html.erb b/frontends/default/views/_form_js.html.erb new file mode 100644 index 0000000000..43dbe449b0 --- /dev/null +++ b/frontends/default/views/_form_js.html.erb @@ -0,0 +1,14 @@ +<script type="text/javascript"> +Form.focusFirstElement('<%= element_form_id(:action => action_type) -%>'); +$('<%= element_form_id(:action => action_type) %>').observe("ajax:after", function(event){ + $('<%= loading_indicator_id(:action => action_type, :id => id) %>').style.visibility = 'visible'; + Form.disable('<%= element_form_id(:action => action_type)%>'); +}); +$('<%= element_form_id(:action => action_type) %>').observe("ajax:complete", function(event){ + $('<%= loading_indicator_id(:action => action_type, :id => id) %>').style.visibility = 'hidden'; + Form.enable('<%= element_form_id(:action => action_type)%>'); +}); +$('<%= element_form_id(:action => action_type) %>').observe("ajax:failure", function(event){ + ActiveScaffold.report_500_response('<%= active_scaffold_id %>'); +}); +</script> diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index 82b925d893..3dda7c2c99 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -46,17 +46,4 @@ end </p> </form> -<script type="text/javascript"> -Form.focusFirstElement('<%= element_form_id(:action => :update) -%>'); -$('<% element_form_id(:action => :update) %>').observe("ajax:after", function(event){ - $('<% loading_indicator_id(:action => :update, :id => params[:id]) %>').style.visibility = 'visible'; - Form.disable('<% element_form_id(:action => :update)%>'); -}) -$('<% element_form_id(:action => :update) %>').observe("ajax:complete", function(event){ - $('<% loading_indicator_id(:action => :update, :id => params[:id]) %>').style.visibility = 'hidden'; - Form.enable('<% element_form_id(:action => :update)%>'); -}) -$('<% element_form_id(:action => :update) %>').observe("ajax:failure", function(event){ - ActiveScaffold.report_500_response('<% active_scaffold_id %>'); -}) -</script> +<%= render :partial => 'form_js', :locals => {:action_type => :update, :id => params[:id]} %> From 7b6e8b9f780e1ae2cdb45f05c8b37b8826e2741f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 21 May 2010 13:58:41 +0200 Subject: [PATCH 0329/2024] remove dependency to input method, not in rails 3.0 core anymore --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 24b601f029..e47265eed7 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -37,7 +37,7 @@ def active_scaffold_input_for(column, scope = nil, options = {}) end options[:include_blank] = true if column.column.null and [:date, :datetime, :time].include?(column.column.type) options[:value] = format_number_value(@record.send(column.name), column.options) if column.column.number? - input(:record, column.name, options.merge(column.options)) + text_field(:record, column.name, options.merge(column.options)) end end end From 6e156254de0dcdc75b6c4452bf3dda49675eedd4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 21 May 2010 18:02:36 +0200 Subject: [PATCH 0330/2024] Test validation reflection bridge --- lib/bridges/validation_reflection/bridge.rb | 1 + .../lib/validation_reflection_bridge.rb | 4 +- test/bridges/bridge_test.rb | 43 ++++++++++++++ test/bridges/company.rb | 16 ++++++ test/bridges/validation_reflection_test.rb | 57 +++++++++++++++++++ 5 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 test/bridges/validation_reflection_test.rb diff --git a/lib/bridges/validation_reflection/bridge.rb b/lib/bridges/validation_reflection/bridge.rb index d563aca51a..5b603d425f 100644 --- a/lib/bridges/validation_reflection/bridge.rb +++ b/lib/bridges/validation_reflection/bridge.rb @@ -1,6 +1,7 @@ ActiveScaffold.bridge "ValidationReflection" do install do require File.join(File.dirname(__FILE__), "lib/validation_reflection_bridge.rb") + ActiveScaffold::DataStructures::Column.class_eval { include ActiveScaffold::ValidationReflectionBridge } end install? do ActiveRecord::Base.respond_to? :reflect_on_validations_for diff --git a/lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb b/lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb index 777ddcdb38..403d708732 100644 --- a/lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb +++ b/lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb @@ -16,6 +16,4 @@ def initialize_with_validation_reflection(name, active_record_class) end end end -ActiveScaffold::DataStructures::Column.class_eval do - include ActiveScaffold::ValidationReflectionBridge -end + diff --git a/test/bridges/bridge_test.rb b/test/bridges/bridge_test.rb index 4f1098523c..7f39ff2236 100644 --- a/test/bridges/bridge_test.rb +++ b/test/bridges/bridge_test.rb @@ -32,6 +32,49 @@ def test__file_column_bridge assert(bridge_will_be_installed("FileColumn")) end end + + def test__dependent_protect_bridge + ConstMocker.mock("DependentProtect") do |cm| + cm.remove + assert(! bridge_will_be_installed("DependentProtect")) + cm.declare + assert(bridge_will_be_installed("DependentProtect")) + end + end + + def test__paperclip_bridge + ConstMocker.mock("Paperclip") do |cm| + cm.remove + assert(! bridge_will_be_installed("Paperclip")) + cm.declare + assert(bridge_will_be_installed("Paperclip")) + end + end + + def test__unobtrusive_date_picker_bridge + ConstMocker.mock("UnobtrusiveDatePicker") do |cm| + cm.remove + assert(! bridge_will_be_installed("UnobtrusiveDatePicker")) + cm.declare + assert(bridge_will_be_installed("UnobtrusiveDatePicker")) + end + end + + def test__validation_reflection_bridge + class << ActiveRecord::Base; undef_method :reflect_on_validations_for; end rescue nil + assert(! bridge_will_be_installed("ValidationReflection")) + class << ActiveRecord::Base; define_method :reflect_on_validations_for, lambda{}; end + assert(bridge_will_be_installed("ValidationReflection")) + end + + def test__semantic_attributes_bridge + ConstMocker.mock("SemanticAttributes") do |cm| + cm.remove + assert(! bridge_will_be_installed("SemanticAttributes")) + cm.declare + assert(bridge_will_be_installed("SemanticAttributes")) + end + end protected diff --git a/test/bridges/company.rb b/test/bridges/company.rb index 734da806e5..ed98bfa337 100644 --- a/test/bridges/company.rb +++ b/test/bridges/company.rb @@ -11,10 +11,26 @@ def initialize(with_or_without) @with_main_company = with_or_without == :with_main_company end + def self.columns_hash + { + 'name' => ActiveRecord::ConnectionAdapters::Column.new('name', nil, 'varchar(255)'), + 'date' => ActiveRecord::ConnectionAdapters::Column.new('date', nil, 'date'), + 'datetime' => ActiveRecord::ConnectionAdapters::Column.new('datetime', nil, 'datetime') + } + end + + def self.columns + self.columns_hash.values + end + def self.class_name self.name end + def self.table_name + 'companies' + end + # not the real signature of the method, but forgive me def self.before_destroy(s=nil) @@before = s diff --git a/test/bridges/validation_reflection_test.rb b/test/bridges/validation_reflection_test.rb new file mode 100644 index 0000000000..f838fea6bf --- /dev/null +++ b/test/bridges/validation_reflection_test.rb @@ -0,0 +1,57 @@ +require 'test/unit' +require File.join(File.dirname(__FILE__), 'company') +require File.join(File.dirname(__FILE__), '../../lib/bridges/validation_reflection/lib/validation_reflection_bridge') + +class ColumnWithValidationReflection < ActiveScaffold::DataStructures::Column + include ActiveScaffold::ValidationReflectionBridge +end + +class ValidationReflectionTest < Test::Unit::TestCase + def test_set_required_for_validates_presence_of + Company.expects(:reflect_on_validations_for).with(:name).returns([stub(:macro => :validates_presence_of)]) + column = ColumnWithValidationReflection.new(:name, Company) + assert column.required? + end + + def test_set_required_for_validates_inclusion_of + Company.expects(:reflect_on_validations_for).with(:name).returns([stub(:macro => :validates_inclusion_of, :options => {})]) + column = ColumnWithValidationReflection.new(:name, Company) + assert column.required? + end + + def test_not_set_required_for_validates_inclusion_of_and_allow_nil + Company.expects(:reflect_on_validations_for).with(:name).returns([stub(:macro => :validates_inclusion_of, :options => {:allow_nil => true})]) + column = ColumnWithValidationReflection.new(:name, Company) + assert !column.required? + end + + def test_not_set_required_for_validates_inclusion_of_and_allow_blank + Company.expects(:reflect_on_validations_for).with(:name).returns([stub(:macro => :validates_inclusion_of, :options => {:allow_blank => true})]) + column = ColumnWithValidationReflection.new(:name, Company) + assert !column.required? + end + + def test_not_set_required_for_no_validation + Company.expects(:reflect_on_validations_for).with(:name).returns([]) + column = ColumnWithValidationReflection.new(:name, Company) + assert !column.required? + end + + def test_set_required_for_validates_presence_of_in_association + Company.stubs(:reflect_on_validations_for).returns([stub(:macro => :validates_presence_of)], []) + column = ColumnWithValidationReflection.new(:main_company, Company) + assert column.required? + end + + def test_set_required_for_validates_presence_of_in_foreign_key + Company.stubs(:reflect_on_validations_for).returns([], [stub(:macro => :validates_presence_of)]) + column = ColumnWithValidationReflection.new(:main_company, Company) + assert column.required? + end + + def test_not_set_required_for_no_validation_in_association_neither_foreign_key + Company.stubs(:reflect_on_validations_for).returns([]) + column = ColumnWithValidationReflection.new(:main_company, Company) + assert !column.required? + end +end From f8bea162caaaff91a61264ff8db532c98a6636f6 Mon Sep 17 00:00:00 2001 From: "Clifford T. Matthews" <ctm@devctm.com> Date: Sat, 22 May 2010 10:28:21 +0800 Subject: [PATCH 0331/2024] Uses quote_table_name to quote a table rather than quote_column_name. This fix should help people who use MySQL with more than one database. --- lib/active_scaffold/data_structures/column.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index c9da3c082c..85bcd0d798 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -303,7 +303,7 @@ def initialize_search_sql # the table.field name for this column, if applicable def field - @field ||= [@active_record_class.connection.quote_column_name(@table), field_name].join('.') + @field ||= [@active_record_class.connection.quote_table_name(@table), field_name].join('.') end end end From bdfc4b7a92da2b407239073d705f182665e9e9e4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 24 May 2010 11:07:57 +0200 Subject: [PATCH 0332/2024] test unobtrusive date picker bridge --- lib/bridges/unobtrusive_date_picker/bridge.rb | 1 + .../lib/unobtrusive_date_picker_bridge.rb | 11 ++-- test/bridges/unobtrusive_date_picker_test.rb | 51 +++++++++++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 test/bridges/unobtrusive_date_picker_test.rb diff --git a/lib/bridges/unobtrusive_date_picker/bridge.rb b/lib/bridges/unobtrusive_date_picker/bridge.rb index 2e7d1e4ba4..546a7fd830 100644 --- a/lib/bridges/unobtrusive_date_picker/bridge.rb +++ b/lib/bridges/unobtrusive_date_picker/bridge.rb @@ -3,5 +3,6 @@ require File.join(File.dirname(__FILE__), "lib/unobtrusive_date_picker_bridge.rb") require File.join(File.dirname(__FILE__), "lib/form_ui.rb") require File.join(File.dirname(__FILE__), "lib/view_helpers.rb") + ActiveScaffold::Config::Core.send :include, ActiveScaffold::UnobtrusiveDatePickerBridge end end diff --git a/lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb b/lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb index 867ef89f28..69624ed237 100644 --- a/lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb +++ b/lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb @@ -1,12 +1,15 @@ -module ActiveScaffold::Config - class Core < Base +module ActiveScaffold + module UnobtrusiveDatePickerBridge def initialize_with_unobtrusive_date_picker(model_id) initialize_without_unobtrusive_date_picker(model_id) date_fields = self.model.columns.select {|c| [:date, :datetime].include?(c.type) } - + # automatically set the forum_ui to a file column date_fields.each {|field| self.columns[field.name.to_sym].form_ui = :datepicker} end - alias_method_chain :initialize, :unobtrusive_date_picker + + def self.included(base) + base.alias_method_chain :initialize, :unobtrusive_date_picker + end end end diff --git a/test/bridges/unobtrusive_date_picker_test.rb b/test/bridges/unobtrusive_date_picker_test.rb new file mode 100644 index 0000000000..cc284106fa --- /dev/null +++ b/test/bridges/unobtrusive_date_picker_test.rb @@ -0,0 +1,51 @@ +require 'test/unit' +require File.join(File.dirname(__FILE__), 'company') +require File.join(File.dirname(__FILE__), '../../lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge') +require File.join(File.dirname(__FILE__), '../../lib/bridges/unobtrusive_date_picker/lib/view_helpers') +require File.join(File.dirname(__FILE__), '../../lib/bridges/unobtrusive_date_picker/lib/form_ui') + +class Core < ActiveScaffold::Config::Core + include ActiveScaffold::UnobtrusiveDatePickerBridge +end + +class UnobtrusiveDatePickerTest < ActionView::TestCase + include ActiveScaffold::Helpers::ViewHelpers + + def test_set_form_ui + config = Core.new(:company) + assert_equal nil, config.columns[:name].form_ui, 'form_ui for name' + assert_equal :datepicker, config.columns[:date].form_ui, 'form_ui for date' + assert_equal :datepicker, config.columns[:datetime].form_ui, 'form_ui for datetime' + end + + def test_stylesheets + assert active_scaffold_stylesheets.include?('datepicker.css') + end + + def test_javascripts + assert active_scaffold_javascripts.include?('datepicker.js') + assert active_scaffold_javascripts.include?('datepicker_lang/es.js') + end + + def test_form_ui + config = Core.new(:company) + self.expects(:date_select).returns('') + self.expects(:date_picker).returns('') + assert active_scaffold_input_datepicker(config.columns[:date], :name => 'record[date]', :id => 'record_date') + + self.expects(:datetime_select).returns('') + self.expects(:date_picker).returns('') + assert active_scaffold_input_datepicker(config.columns[:datetime], :name => 'record[datetime]', :id => 'record_datetime') + end + + private + def unobtrusive_datepicker_stylesheets + ['datepicker.css'] + end + def unobtrusive_datepicker_javascripts + ['datepicker.js', 'datepicker_lang/es.js'] + end + def date_picker(record, name, options, html_options) + javascript_tag '' + end +end From 65ebdb1d5162ba4378a4a2fb39f6600c7466d4f0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 24 May 2010 12:42:12 +0200 Subject: [PATCH 0333/2024] Allow using prototype 1.7 --- frontends/default/javascripts/active_scaffold.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 6f2d56a617..af64bd07f4 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -3,9 +3,9 @@ if (typeof Prototype == 'undefined') warning = "ActiveScaffold Error: Prototype could not be found. Please make sure that your application's layout includes prototype.js (e.g. <%= javascript_include_tag :defaults %>) *before* it includes active_scaffold.js (e.g. <%= active_scaffold_includes %>)."; alert(warning); } -if (Prototype.Version.substring(0, 3) != '1.6') +if (Prototype.Version.substring(0, 3) < '1.6') { - warning = "ActiveScaffold Error: Prototype version 1.6.x is required. Please update prototype.js (rake rails:update:javascripts)."; + warning = "ActiveScaffold Error: Prototype version 1.6.x or higher is required. Please update prototype.js (rake rails:update:javascripts)."; alert(warning); } if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFunction}); From 867314700ed833c96ca56e292162843ea82668ff Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 24 May 2010 13:06:45 +0200 Subject: [PATCH 0334/2024] Test paperclip bridge --- lib/bridges/paperclip/bridge.rb | 1 + lib/bridges/paperclip/lib/form_ui.rb | 2 +- lib/bridges/paperclip/lib/paperclip_bridge.rb | 10 ++- test/bridges/company.rb | 12 +++- test/bridges/paperclip_test.rb | 68 +++++++++++++++++++ test/bridges/unobtrusive_date_picker_test.rb | 9 +-- .../default/active_scaffold.js | 4 +- 7 files changed, 92 insertions(+), 14 deletions(-) create mode 100644 test/bridges/paperclip_test.rb diff --git a/lib/bridges/paperclip/bridge.rb b/lib/bridges/paperclip/bridge.rb index 52461f81e2..bdf507be7f 100644 --- a/lib/bridges/paperclip/bridge.rb +++ b/lib/bridges/paperclip/bridge.rb @@ -8,5 +8,6 @@ require File.join(File.dirname(__FILE__), "lib/paperclip_bridge") require File.join(File.dirname(__FILE__), "lib/form_ui") require File.join(File.dirname(__FILE__), "lib/list_ui") + ActiveScaffold::Config::Core.send :include, ActiveScaffold::PaperclipBridge end end \ No newline at end of file diff --git a/lib/bridges/paperclip/lib/form_ui.rb b/lib/bridges/paperclip/lib/form_ui.rb index 795666d376..025f1b694b 100644 --- a/lib/bridges/paperclip/lib/form_ui.rb +++ b/lib/bridges/paperclip/lib/form_ui.rb @@ -8,7 +8,7 @@ def active_scaffold_input_paperclip(column, options) content = active_scaffold_column_paperclip(column, @record) content_tag(:div, content + " | " + - link_to_function(as_(:remove_file), "$(this).next().value='true'; p=$(this).up(); p.hide(); p.next().show()") + + link_to_function(as_(:remove_file), "$(this).next().value='true'; $(this).up().hide().next().show()") + hidden_field(:record, "delete_#{column.name}", :value => "false") ) + content_tag(:div, input, :style => "display: none") else diff --git a/lib/bridges/paperclip/lib/paperclip_bridge.rb b/lib/bridges/paperclip/lib/paperclip_bridge.rb index 056a9ff969..38ac1bc188 100644 --- a/lib/bridges/paperclip/lib/paperclip_bridge.rb +++ b/lib/bridges/paperclip/lib/paperclip_bridge.rb @@ -1,5 +1,5 @@ -module ActiveScaffold::Config - class Core < Base +module ActiveScaffold + module PaperclipBridge def initialize_with_paperclip(model_id) initialize_without_paperclip(model_id) return if self.model.attachment_definitions.nil? @@ -13,8 +13,12 @@ def initialize_with_paperclip(model_id) PaperclipBridgeHelpers.generate_delete_helper(self.model, field) end end - alias_method_chain :initialize, :paperclip + def self.included(base) + base.alias_method_chain :initialize, :paperclip + end + + private def configure_paperclip_field(field) self.columns << field self.columns[field].form_ui ||= :paperclip diff --git a/test/bridges/company.rb b/test/bridges/company.rb index ed98bfa337..c934f88d8c 100644 --- a/test/bridges/company.rb +++ b/test/bridges/company.rb @@ -5,7 +5,7 @@ # Mocking everything necesary to test the plugin. class Company - def initialize(with_or_without) + def initialize(with_or_without = nil) @with_companies = with_or_without == :with_companies @with_company = with_or_without == :with_company @with_main_company = with_or_without == :with_main_company @@ -15,7 +15,11 @@ def self.columns_hash { 'name' => ActiveRecord::ConnectionAdapters::Column.new('name', nil, 'varchar(255)'), 'date' => ActiveRecord::ConnectionAdapters::Column.new('date', nil, 'date'), - 'datetime' => ActiveRecord::ConnectionAdapters::Column.new('datetime', nil, 'datetime') + 'datetime' => ActiveRecord::ConnectionAdapters::Column.new('datetime', nil, 'datetime'), + 'logo_file_name' => ActiveRecord::ConnectionAdapters::Column.new('logo_file_name', nil, 'varchar(255)'), + 'logo_content_type' => ActiveRecord::ConnectionAdapters::Column.new('logo_content_type', nil, 'varchar(255)'), + 'logo_file_size' => ActiveRecord::ConnectionAdapters::Column.new('logo_file_size', nil, 'int(11)'), + 'logo_updated_at' => ActiveRecord::ConnectionAdapters::Column.new('logo_updated_at', nil, 'datetime'), } end @@ -31,6 +35,10 @@ def self.table_name 'companies' end + def self.attachment_definitions + {:logo => {}} + end + # not the real signature of the method, but forgive me def self.before_destroy(s=nil) @@before = s diff --git a/test/bridges/paperclip_test.rb b/test/bridges/paperclip_test.rb new file mode 100644 index 0000000000..a2b7a33c37 --- /dev/null +++ b/test/bridges/paperclip_test.rb @@ -0,0 +1,68 @@ +require 'test/unit' +require File.join(File.dirname(__FILE__), 'company') +require File.join(File.dirname(__FILE__), '../../lib/bridges/paperclip/lib/paperclip_bridge') +require File.join(File.dirname(__FILE__), '../../lib/bridges/paperclip/lib/paperclip_bridge_helpers') +require File.join(File.dirname(__FILE__), '../../lib/bridges/paperclip/lib/form_ui') +require File.join(File.dirname(__FILE__), '../../lib/bridges/paperclip/lib/list_ui') + +class PaperclipCore < ActiveScaffold::Config::Core + include ActiveScaffold::PaperclipBridge +end + +class PaperclipTest < ActionView::TestCase + include ActiveScaffold::Helpers::ViewHelpers + + def test_initialization_without_paperclip + Company.expects(:attachment_definitions) + config = PaperclipCore.new(:company) + assert !config.create.multipart? + assert !config.update.multipart? + assert !config.columns.any? {|column| column.form_ui == :paperclip} + end + + def test_initialization + config = PaperclipCore.new(:company) + assert config.create.multipart? + assert config.update.multipart? + assert_equal :paperclip, config.columns[:logo].form_ui + assert_equal [:delete_logo], config.columns[:logo].params.to_a + %w(logo_file_name logo_file_size logo_updated_at logo_content_type).each do |attr| + assert !config.columns._inheritable.include?(attr.to_sym) + end + assert Company.instance_methods.include?('delete_logo') + assert Company.instance_methods.include?('delete_logo=') + end + + def test_delete + PaperclipCore.new(:company) + company = Company.new + company.expects(:logo=).never + company.delete_logo = 'false' + + company.expects(:logo).returns(stub(:dirty? => false)) + company.expects(:logo=) + company.delete_logo = 'true' + end + + def test_list_ui + config = PaperclipCore.new(:company) + company = Company.new + + company.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => Company.attachment_definitions[:logo])) + assert_dom_equal '<a href="/system/file" onclick="window.open(this.href);return false;">file</a>', active_scaffold_column_paperclip(config.columns[:logo], company) + + company.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => {:thumbnail => '40x40'})) + assert_dom_equal '<a href="/system/file" onclick="window.open(this.href);return false;"><img src="/system/file" border="0" alt="File"/></a>', active_scaffold_column_paperclip(config.columns[:logo], company) + end + + def test_form_ui + config = PaperclipCore.new(:company) + @record = Company.new + + @record.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => Company.attachment_definitions[:logo])) + assert_dom_equal '<div><a href="/system/file" onclick="window.open(this.href);return false;">file</a>|<a href="#" onclick="$(this).next().value=\'true\'; $(this).up().hide().next().show(); return false;">Remove or Replace file</a><input name="record[delete_logo]" type="hidden" id="record_delete_logo" value="false" /></div><div style="display: none"><input name="record[logo]" size="30" type="file" id="record_logo" /></div>', active_scaffold_input_paperclip(config.columns[:logo], :name => 'record[logo]', :id => 'record_logo') + + @record.stubs(:logo).returns(stub(:file? => false)) + assert_dom_equal '<input name="record[logo]" size="30" type="file" id="record_logo" />', active_scaffold_input_paperclip(config.columns[:logo], :name => 'record[logo]', :id => 'record_logo') + end +end diff --git a/test/bridges/unobtrusive_date_picker_test.rb b/test/bridges/unobtrusive_date_picker_test.rb index cc284106fa..7ab49189d7 100644 --- a/test/bridges/unobtrusive_date_picker_test.rb +++ b/test/bridges/unobtrusive_date_picker_test.rb @@ -4,7 +4,7 @@ require File.join(File.dirname(__FILE__), '../../lib/bridges/unobtrusive_date_picker/lib/view_helpers') require File.join(File.dirname(__FILE__), '../../lib/bridges/unobtrusive_date_picker/lib/form_ui') -class Core < ActiveScaffold::Config::Core +class UDPCore < ActiveScaffold::Config::Core include ActiveScaffold::UnobtrusiveDatePickerBridge end @@ -12,7 +12,7 @@ class UnobtrusiveDatePickerTest < ActionView::TestCase include ActiveScaffold::Helpers::ViewHelpers def test_set_form_ui - config = Core.new(:company) + config = UDPCore.new(:company) assert_equal nil, config.columns[:name].form_ui, 'form_ui for name' assert_equal :datepicker, config.columns[:date].form_ui, 'form_ui for date' assert_equal :datepicker, config.columns[:datetime].form_ui, 'form_ui for datetime' @@ -28,7 +28,7 @@ def test_javascripts end def test_form_ui - config = Core.new(:company) + config = UDPCore.new(:company) self.expects(:date_select).returns('') self.expects(:date_picker).returns('') assert active_scaffold_input_datepicker(config.columns[:date], :name => 'record[date]', :id => 'record_date') @@ -45,7 +45,4 @@ def unobtrusive_datepicker_stylesheets def unobtrusive_datepicker_javascripts ['datepicker.js', 'datepicker_lang/es.js'] end - def date_picker(record, name, options, html_options) - javascript_tag '' - end end diff --git a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js index 6f2d56a617..af64bd07f4 100644 --- a/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +++ b/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js @@ -3,9 +3,9 @@ if (typeof Prototype == 'undefined') warning = "ActiveScaffold Error: Prototype could not be found. Please make sure that your application's layout includes prototype.js (e.g. <%= javascript_include_tag :defaults %>) *before* it includes active_scaffold.js (e.g. <%= active_scaffold_includes %>)."; alert(warning); } -if (Prototype.Version.substring(0, 3) != '1.6') +if (Prototype.Version.substring(0, 3) < '1.6') { - warning = "ActiveScaffold Error: Prototype version 1.6.x is required. Please update prototype.js (rake rails:update:javascripts)."; + warning = "ActiveScaffold Error: Prototype version 1.6.x or higher is required. Please update prototype.js (rake rails:update:javascripts)."; alert(warning); } if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFunction}); From e71e668d43798c11d72c1b194a45d17e00f68d3c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 24 May 2010 14:08:42 +0200 Subject: [PATCH 0335/2024] test tiny mce bridge --- lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb | 18 +++++++++---- lib/bridges/unobtrusive_date_picker/bridge.rb | 1 + .../lib/view_helpers.rb | 21 ++++++++------- test/bridges/company.rb | 3 +++ test/bridges/tiny_mce_test.rb | 26 +++++++++++++++++++ test/bridges/unobtrusive_date_picker_test.rb | 1 + 6 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 test/bridges/tiny_mce_test.rb diff --git a/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb b/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb index 1fc0b8b246..95b0abb479 100644 --- a/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb +++ b/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb @@ -1,7 +1,11 @@ module ActiveScaffold module TinyMceBridge module ViewHelpers - def active_scaffold_includes(*args) + def self.included(base) + base.alias_method_chain :active_scaffold_includes, :tiny_mce + end + + def active_scaffold_includes_with_tiny_mce(*args) tiny_mce_js = javascript_tag(%| var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; ActiveScaffold.ActionLink.Abstract.prototype.close = function() { @@ -11,11 +15,15 @@ def active_scaffold_includes(*args) action_link_close.apply(this); }; |) if using_tiny_mce? - super(*args) + (include_tiny_mce_if_needed || '') + (tiny_mce_js || '') + active_scaffold_includes_without_tiny_mce(*args) + (include_tiny_mce_if_needed || '') + (tiny_mce_js || '') end end module FormColumnHelpers + def self.included(base) + base.alias_method_chain :onsubmit, :tiny_mce + end + def active_scaffold_input_text_editor(column, options) options[:class] = "#{options[:class]} mceEditor #{column.options[:class]}".strip html = [] @@ -24,9 +32,9 @@ def active_scaffold_input_text_editor(column, options) html.join "\n" end - def onsubmit + def onsubmit_with_tiny_mce submit_js = 'tinyMCE.triggerSave();this.select("textarea.mceEditor").each(function(elem) { tinyMCE.execCommand("mceRemoveControl", false, elem.id); });' if using_tiny_mce? - [super, submit_js].compact.join ';' + [onsubmit_without_tiny_mce, submit_js].compact.join ';' end end @@ -38,7 +46,7 @@ def self.included(base) end end -ActionView::Base.class_eval do +ActiveScaffold::Helpers::ViewHelpers.module_eval do include ActiveScaffold::TinyMceBridge::FormColumnHelpers include ActiveScaffold::TinyMceBridge::SearchColumnHelpers include ActiveScaffold::TinyMceBridge::ViewHelpers diff --git a/lib/bridges/unobtrusive_date_picker/bridge.rb b/lib/bridges/unobtrusive_date_picker/bridge.rb index 546a7fd830..878b762211 100644 --- a/lib/bridges/unobtrusive_date_picker/bridge.rb +++ b/lib/bridges/unobtrusive_date_picker/bridge.rb @@ -4,5 +4,6 @@ require File.join(File.dirname(__FILE__), "lib/form_ui.rb") require File.join(File.dirname(__FILE__), "lib/view_helpers.rb") ActiveScaffold::Config::Core.send :include, ActiveScaffold::UnobtrusiveDatePickerBridge + ActiveScaffold::Helpers::ViewHelpers.send :include, ActiveScaffold::UnobtrusiveDatePickerHelpers end end diff --git a/lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb b/lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb index 6a24a9acdc..981144227a 100644 --- a/lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb +++ b/lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb @@ -1,15 +1,16 @@ module ActiveScaffold - module Helpers - module ViewHelpers - def active_scaffold_stylesheets_with_date_picker(frontend = :default) - active_scaffold_stylesheets_without_date_picker(frontend) + unobtrusive_datepicker_stylesheets - end - alias_method_chain :active_scaffold_stylesheets, :date_picker + module UnobtrusiveDatePickerHelpers + def self.included(base) + base.alias_method_chain :active_scaffold_stylesheets, :date_picker + base.alias_method_chain :active_scaffold_javascripts, :date_picker + end + + def active_scaffold_stylesheets_with_date_picker(frontend = :default) + active_scaffold_stylesheets_without_date_picker(frontend) + unobtrusive_datepicker_stylesheets + end - def active_scaffold_javascripts_with_date_picker(frontend = :default) - active_scaffold_javascripts_without_date_picker(frontend) + unobtrusive_datepicker_javascripts - end - alias_method_chain :active_scaffold_javascripts, :date_picker + def active_scaffold_javascripts_with_date_picker(frontend = :default) + active_scaffold_javascripts_without_date_picker(frontend) + unobtrusive_datepicker_javascripts end end end diff --git a/test/bridges/company.rb b/test/bridges/company.rb index c934f88d8c..0c84d163ed 100644 --- a/test/bridges/company.rb +++ b/test/bridges/company.rb @@ -75,4 +75,7 @@ def company def main_company @with_main_company end + + def name + end end diff --git a/test/bridges/tiny_mce_test.rb b/test/bridges/tiny_mce_test.rb new file mode 100644 index 0000000000..590851ecbd --- /dev/null +++ b/test/bridges/tiny_mce_test.rb @@ -0,0 +1,26 @@ +require 'test/unit' +require File.join(File.dirname(__FILE__), 'company') +require File.join(File.dirname(__FILE__), '../../lib/bridges/tiny_mce/lib/tiny_mce_bridge') + +class TinyMceTest < ActionView::TestCase + include ActiveScaffold::Helpers::ViewHelpers + + def test_includes + assert_match /.*<script type="text\/javascript">.*ActiveScaffold\.ActionLink\.Abstract\.prototype\.close = function\(\).*<\/script>.*/m, active_scaffold_includes + end + + def test_form_ui + config = PaperclipCore.new(:company) + @record = Company.new + self.expects(:request).returns(stub(:xhr? => true)) + + assert_dom_equal "<textarea name=\"record[name]\" class=\"name-input mceEditor\" id=\"record_name\"></textarea><script type=\"text/javascript\">\n//<![CDATA[\ntinyMCE.execCommand('mceAddControl', false, 'record_name');\n//]]>\n</script>", active_scaffold_input_text_editor(config.columns[:name], :name => 'record[name]', :id => 'record_name', :class => 'name-input') + end + + protected + def include_tiny_mce_if_needed; end + def tiny_mce_js; end + def using_tiny_mce? + true + end +end diff --git a/test/bridges/unobtrusive_date_picker_test.rb b/test/bridges/unobtrusive_date_picker_test.rb index 7ab49189d7..98ee3bfec6 100644 --- a/test/bridges/unobtrusive_date_picker_test.rb +++ b/test/bridges/unobtrusive_date_picker_test.rb @@ -10,6 +10,7 @@ class UDPCore < ActiveScaffold::Config::Core class UnobtrusiveDatePickerTest < ActionView::TestCase include ActiveScaffold::Helpers::ViewHelpers + include ActiveScaffold::UnobtrusiveDatePickerHelpers def test_set_form_ui config = UDPCore.new(:company) From a275c7ffadd5d1a6c07a7791572d53f68d83da12 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 25 May 2010 10:02:33 +0200 Subject: [PATCH 0336/2024] Fix converting numbers to native format when separator and delimiter are different to native separator --- lib/active_scaffold/attribute_params.rb | 4 ++-- test/misc/attribute_params_test.rb | 27 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 3ed8c3da1e..7a7279a936 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -123,11 +123,11 @@ def column_value_from_param_value(parent_record, column, value) # it's an array of ids column.association.klass.find(value) if value and not value.empty? elsif column.column && column.column.number? && [:i18n_number, :currency].include?(column.options[:format]) - native = '.' + native = '.' # native ruby separator delimiter = I18n.t('number.format.delimiter') separator = I18n.t('number.format.separator') - unless delimiter == native && !value.include?(separator) && value !~ /\.\d{3}$/ + unless !value.include?(separator) && value.include?(native) && (delimiter != native || value !~ /\.\d{3}$/) value.gsub(/[^0-9\-#{I18n.t('number.format.separator')}]/, '').gsub(I18n.t('number.format.separator'), native) else value diff --git a/test/misc/attribute_params_test.rb b/test/misc/attribute_params_test.rb index a263169cd1..fd1842a2c7 100644 --- a/test/misc/attribute_params_test.rb +++ b/test/misc/attribute_params_test.rb @@ -19,6 +19,10 @@ def setup :delimiter => '.', :separator => ',' }} + I18n.backend.store_translations :ru, :number => {:format => { + :delimiter => '', + :separator => ',' + }} @config = config_for('number_model') class << @config.list.columns @@ -101,6 +105,29 @@ def test_spanish_format_with_separator_and_decimal_using_spanish_language assert_equal 1234000.1, convert_number('1.234.000,100') end + def test_english_format_with_decimal_separator_using_russian_language + I18n.locale = :ru + assert_equal 0.1, convert_number('.1') + assert_equal 0.1, convert_number('0.1') + assert_equal 0.12, convert_number('+0.12') + assert_equal -0.12, convert_number('-0.12') + assert_equal 9.1, convert_number('9.1') + assert_equal 90.1, convert_number('90.1') + end + + def test_russian_format_with_decimal_separator_using_russian_language + I18n.locale = :ru + assert_equal 0.1, convert_number(',1') + assert_equal 0.1, convert_number(',100') + assert_equal 0.1, convert_number('0,1') + assert_equal 0.345, convert_number('0,345') + assert_equal 0.345, convert_number('+0,345') + assert_equal -0.345, convert_number('-0,345') + assert_equal 9.1, convert_number('9,1') + assert_equal 90.1, convert_number('90,1') + assert_equal 9.1, convert_number('9,100') + end + private def convert_number(value) record = NumberModel.new From 616c00b4c53a65d8193440dad2e71470a18d922f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 25 May 2010 10:27:47 +0200 Subject: [PATCH 0337/2024] Show null comparators for associations --- .../helpers/search_column_helpers.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index f5624162ad..4a86ea9c52 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -128,8 +128,17 @@ def field_search_params_range_values(column) def active_scaffold_search_range(column, options) opt_value, from_value, to_value = field_search_params_range_values(column) select_options = ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} - select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} if column.options[:string_comparators] || column.column && column.column.text? - select_options += ActiveScaffold::Finder::NullComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} if column.column && column.column.null + select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} if column.options[:string_comparators] || column.column.try(:text?) + null_comparators = if column.association + if column.association.macro == :belongs_to + active_scaffold_config.columns[column.association.primary_key_name].column.try(:null) + else + true + end + else + column.column.try(:null) + end + select_options += ActiveScaffold::Finder::NullComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} if null_comparators html = [] html << select_tag("#{options[:name]}[opt]", From f3b2fd57a89863e9f2da150333607ca0f267a2f5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 25 May 2010 10:35:51 +0200 Subject: [PATCH 0338/2024] fix styles for subgroups in show view and remove blank spaces --- frontends/default/stylesheets/stylesheet.css | 3 +++ frontends/default/views/_show_columns.html.erb | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index d4315f4d53..e9e900fbc4 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -538,6 +538,9 @@ margin-bottom: 3px; .active-scaffold .show-view dl { margin-left: 5px; } +.active-scaffold .show-view dl dl { +margin-left: 0px; +} .active-scaffold .show-view dt { width: 12em; diff --git a/frontends/default/views/_show_columns.html.erb b/frontends/default/views/_show_columns.html.erb index 5cd3d0de23..830ea23c46 100644 --- a/frontends/default/views/_show_columns.html.erb +++ b/frontends/default/views/_show_columns.html.erb @@ -3,9 +3,9 @@ <dt><%= column.label -%></dt> <dd<%= " class=\"#{column.name}-view #{column.css_class}\"" unless column.is_a? ActiveScaffold::DataStructures::ActionColumns %>> <% if column.is_a? ActiveScaffold::DataStructures::ActionColumns -%> - <%= render :partial => 'show_columns', :locals => {:columns => column} %> +  <%= render :partial => 'show_columns', :locals => {:columns => column} %> <% else -%> - <%= show_column_value(@record, column) -%>   + <%= show_column_value(@record, column) %> <% end -%> </dd> <% end -%> From a3b61a3e88b8cce538b0f240681a1da2844118ec Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 26 May 2010 09:47:36 +0200 Subject: [PATCH 0339/2024] Allow override locale from app --- environment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.rb b/environment.rb index 6df90a85cc..3bb9036c9d 100644 --- a/environment.rb +++ b/environment.rb @@ -14,4 +14,4 @@ require 'bridges/bridge.rb' -I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'lib', 'active_scaffold', 'locale', '*.{rb,yml}')] +I18n.load_path.unshift *Dir[File.join(File.dirname(__FILE__), 'lib', 'active_scaffold', 'locale', '*.{rb,yml}')] From a422e19d38eac9a4f84b73c9756f1ea99c241ef2 Mon Sep 17 00:00:00 2001 From: Andrey Voronkov <andrey@linux-2n20.site> Date: Thu, 27 May 2010 10:59:06 +1000 Subject: [PATCH 0340/2024] Fix for issue #748 --- lib/active_scaffold/attribute_params.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 7a7279a936..0068bc67b7 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -124,11 +124,16 @@ def column_value_from_param_value(parent_record, column, value) column.association.klass.find(value) if value and not value.empty? elsif column.column && column.column.number? && [:i18n_number, :currency].include?(column.options[:format]) native = '.' # native ruby separator - delimiter = I18n.t('number.format.delimiter') - separator = I18n.t('number.format.separator') - + case column.options[:format] + when :currency + delimiter = I18n.t('number.currency.format.delimiter') + separator = I18n.t('number.currency.format.separator') + when :i18n_number + delimiter = I18n.t('number.format.delimiter') + separator = I18n.t('number.format.separator') + end unless !value.include?(separator) && value.include?(native) && (delimiter != native || value !~ /\.\d{3}$/) - value.gsub(/[^0-9\-#{I18n.t('number.format.separator')}]/, '').gsub(I18n.t('number.format.separator'), native) + value.gsub(/[^0-9\-#{separator}]/, '').gsub(separator, native) else value end From 5b3e7b93907598382a51a22db6e99067373633f9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 27 May 2010 10:41:20 +0200 Subject: [PATCH 0341/2024] Support language without localized format, convert to native format when options[:format] is :percentage or :size --- lib/active_scaffold/attribute_params.rb | 20 ++++---- .../helpers/list_column_helpers.rb | 2 +- test/misc/attribute_params_test.rb | 51 +++++++++++-------- .../active_scaffold/default/stylesheet.css | 3 ++ 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 0068bc67b7..dd290a7dd5 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -122,18 +122,20 @@ def column_value_from_param_value(parent_record, column, value) elsif column.plural_association? # it's an array of ids column.association.klass.find(value) if value and not value.empty? - elsif column.column && column.column.number? && [:i18n_number, :currency].include?(column.options[:format]) + elsif column.column && column.column.number? && column.options[:format] native = '.' # native ruby separator - case column.options[:format] + format = {:separator => '', :delimiter => ''}.merge! I18n.t('number.format', :default => {}) + specific = case column.options[:format] when :currency - delimiter = I18n.t('number.currency.format.delimiter') - separator = I18n.t('number.currency.format.separator') - when :i18n_number - delimiter = I18n.t('number.format.delimiter') - separator = I18n.t('number.format.separator') + I18n.t('number.currency.format', :default => nil) + when :size + I18n.t('number.human.format', :default => nil) + when :percentage + I18n.t('number.percentage.format', :default => nil) end - unless !value.include?(separator) && value.include?(native) && (delimiter != native || value !~ /\.\d{3}$/) - value.gsub(/[^0-9\-#{separator}]/, '').gsub(separator, native) + format.merge! specific unless specific.nil? + unless format[:separator].blank? || !value.include?(format[:separator]) && value.include?(native) && (format[:delimiter] != native || value !~ /\.\d{3}$/) + value.gsub(/[^0-9\-#{format[:separator]}]/, '').gsub(format[:separator], native) else value end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 7e6bda6a9c..c151dec9d4 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -187,7 +187,7 @@ def format_number_value(value, options = {}) when :currency number_to_currency(value, options[:i18n_options] || {}) when :i18n_number - send("number_with_#{value.is_a?(Integer) ? 'delimiter' : 'precision'}", value, options[:i18n_options] || {}) + number_with_delimiter(value, options[:i18n_options] || {}) else value end diff --git a/test/misc/attribute_params_test.rb b/test/misc/attribute_params_test.rb index fd1842a2c7..b956aeab34 100644 --- a/test/misc/attribute_params_test.rb +++ b/test/misc/attribute_params_test.rb @@ -19,9 +19,11 @@ def setup :delimiter => '.', :separator => ',' }} - I18n.backend.store_translations :ru, :number => {:format => { - :delimiter => '', - :separator => ',' + I18n.backend.store_translations :ru, :number => {:currency => { + :format => { + :separator => ',', + :delimiter => '' + } }} @config = config_for('number_model') @@ -105,32 +107,39 @@ def test_spanish_format_with_separator_and_decimal_using_spanish_language assert_equal 1234000.1, convert_number('1.234.000,100') end - def test_english_format_with_decimal_separator_using_russian_language + def test_english_currency_format_with_decimal_separator_using_russian_language I18n.locale = :ru - assert_equal 0.1, convert_number('.1') - assert_equal 0.1, convert_number('0.1') - assert_equal 0.12, convert_number('+0.12') - assert_equal -0.12, convert_number('-0.12') - assert_equal 9.1, convert_number('9.1') - assert_equal 90.1, convert_number('90.1') + assert_equal 0.1, convert_number('.1', :currency) + assert_equal 0.1, convert_number('0.1', :currency) + assert_equal 0.12, convert_number('+0.12', :currency) + assert_equal -0.12, convert_number('-0.12', :currency) + assert_equal 9.1, convert_number('9.1', :currency) + assert_equal 90.1, convert_number('90.1', :currency) end - def test_russian_format_with_decimal_separator_using_russian_language + def test_russian_currency_format_with_decimal_separator_using_russian_language I18n.locale = :ru - assert_equal 0.1, convert_number(',1') - assert_equal 0.1, convert_number(',100') - assert_equal 0.1, convert_number('0,1') - assert_equal 0.345, convert_number('0,345') - assert_equal 0.345, convert_number('+0,345') - assert_equal -0.345, convert_number('-0,345') - assert_equal 9.1, convert_number('9,1') - assert_equal 90.1, convert_number('90,1') - assert_equal 9.1, convert_number('9,100') + assert_equal 0.1, convert_number(',1', :currency) + assert_equal 0.1, convert_number(',100', :currency) + assert_equal 0.1, convert_number('0,1', :currency) + assert_equal 0.345, convert_number('0,345', :currency) + assert_equal 0.345, convert_number('+0,345', :currency) + assert_equal -0.345, convert_number('-0,345', :currency) + assert_equal 9.1, convert_number('9,1', :currency) + assert_equal 90.1, convert_number('90,1', :currency) + assert_equal 9.1, convert_number('9,100', :currency) + end + + def test_english_format_with_decimal_separator_with_no_localized_format + I18n.locale = :ru + assert_equal 0.1, convert_number('.1') + assert_equal 0.1, convert_number('0.1') end private - def convert_number(value) + def convert_number(value, format = nil) record = NumberModel.new + @config.columns[:number].options[:format] = format unless format.nil? update_record_from_params(record, @config.list.columns, HashWithIndifferentAccess.new({:number => value})) record.number end diff --git a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css index d4315f4d53..e9e900fbc4 100644 --- a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +++ b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css @@ -538,6 +538,9 @@ margin-bottom: 3px; .active-scaffold .show-view dl { margin-left: 5px; } +.active-scaffold .show-view dl dl { +margin-left: 0px; +} .active-scaffold .show-view dt { width: 12em; From c2a9a3f450218cdefcba998afd803d9f6f58e137 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 27 May 2010 13:27:57 +0200 Subject: [PATCH 0342/2024] Improve nested style --- frontends/default/stylesheets/stylesheet.css | 1 - frontends/default/views/_nested.html.erb | 1 - 2 files changed, 2 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index e9e900fbc4..b87f139af7 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -319,7 +319,6 @@ right: 0px; .active-scaffold .active-scaffold .active-scaffold-header div.actions a { font: bold 11px verdana, sans-serif; -padding: 0 2px 1px 17px; } .blue-theme .active-scaffold .active-scaffold-header div.actions a, diff --git a/frontends/default/views/_nested.html.erb b/frontends/default/views/_nested.html.erb index 131dac41e1..6206304620 100644 --- a/frontends/default/views/_nested.html.erb +++ b/frontends/default/views/_nested.html.erb @@ -1,4 +1,3 @@ -<h4> </h4> <% # TODO: shouldn't this logic happen in the controller action instead of the template? # Actually, maybe we should make render :active_scaffold work in the controller, and not even have a _nested.rhtml? From fd3bdd0e06a8b3e295e9e4d2e1e8abafcf10def5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 27 May 2010 13:42:51 +0200 Subject: [PATCH 0343/2024] Improve nested style --- frontends/default/stylesheets/stylesheet.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index b87f139af7..5040d04ff0 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -299,7 +299,7 @@ background: transparent; } .active-scaffold .active-scaffold .active-scaffold-header { -margin-right: 15px; +margin-right: 25px; } .active-scaffold .active-scaffold .active-scaffold-header h2 { From 756f54bed49faf3d093f6ea7b910146f24910581 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 27 May 2010 13:47:10 +0200 Subject: [PATCH 0344/2024] Fix position of indicator in header --- frontends/default/stylesheets/stylesheet.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 5040d04ff0..4ddb1b211c 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -528,7 +528,7 @@ margin: 0; } .active-scaffold .active-scaffold-header .loading-indicator { -margin-bottom: 3px; +margin-top: 3px; } /* Show From 88312c11ee9c9a8438f397ab8f141aa4a69c8d7e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 27 May 2010 17:44:29 +0200 Subject: [PATCH 0345/2024] Allow to force adding null comparators, and allow to avoid adding them too --- .../helpers/search_column_helpers.rb | 20 +++++++++---------- .../active_scaffold/default/stylesheet.css | 5 ++--- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 4a86ea9c52..e2c9913ce3 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -125,20 +125,20 @@ def field_search_params_range_values(column) return values[:opt], values[:from], values[:to] end + def include_null_comparators?(column) + return column.options[:null_comparators] if column.options.has_key? :null_comparators + if column.association + column.association.macro != :belongs_to || active_scaffold_config.columns[column.association.primary_key_name].column.try(:null) + else + column.column.try(:null) + end + end + def active_scaffold_search_range(column, options) opt_value, from_value, to_value = field_search_params_range_values(column) select_options = ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} if column.options[:string_comparators] || column.column.try(:text?) - null_comparators = if column.association - if column.association.macro == :belongs_to - active_scaffold_config.columns[column.association.primary_key_name].column.try(:null) - else - true - end - else - column.column.try(:null) - end - select_options += ActiveScaffold::Finder::NullComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} if null_comparators + select_options += ActiveScaffold::Finder::NullComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} if include_null_comparators? column html = [] html << select_tag("#{options[:name]}[opt]", diff --git a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css index e9e900fbc4..4ddb1b211c 100644 --- a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +++ b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css @@ -299,7 +299,7 @@ background: transparent; } .active-scaffold .active-scaffold .active-scaffold-header { -margin-right: 15px; +margin-right: 25px; } .active-scaffold .active-scaffold .active-scaffold-header h2 { @@ -319,7 +319,6 @@ right: 0px; .active-scaffold .active-scaffold .active-scaffold-header div.actions a { font: bold 11px verdana, sans-serif; -padding: 0 2px 1px 17px; } .blue-theme .active-scaffold .active-scaffold-header div.actions a, @@ -529,7 +528,7 @@ margin: 0; } .active-scaffold .active-scaffold-header .loading-indicator { -margin-bottom: 3px; +margin-top: 3px; } /* Show From 4b82c600b17b35073abebecf0fcdcaeeea2cdfa3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 28 May 2010 11:24:42 +0200 Subject: [PATCH 0346/2024] move action_link handling into new Rails 3 unobtrusive js direction reworked js event_handling --- .../default/javascripts/active_scaffold.js | 182 +++++++++++------- frontends/default/stylesheets/stylesheet.css | 2 +- frontends/default/views/_create_form.html.erb | 9 +- .../views/_create_form_on_list.html.erb | 3 +- frontends/default/views/_form_js.html.erb | 14 -- .../default/views/_list_actions.html.erb | 2 +- .../views/_list_inline_adapter.html.erb | 2 +- frontends/default/views/_update_form.html.erb | 12 +- frontends/default/views/list.html.erb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 17 +- 10 files changed, 140 insertions(+), 105 deletions(-) delete mode 100644 frontends/default/views/_form_js.html.erb diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 6f2d56a617..8b098bcb33 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -3,14 +3,93 @@ if (typeof Prototype == 'undefined') warning = "ActiveScaffold Error: Prototype could not be found. Please make sure that your application's layout includes prototype.js (e.g. <%= javascript_include_tag :defaults %>) *before* it includes active_scaffold.js (e.g. <%= active_scaffold_includes %>)."; alert(warning); } -if (Prototype.Version.substring(0, 3) != '1.6') +if (Prototype.Version.substring(0, 3) < '1.6') { - warning = "ActiveScaffold Error: Prototype version 1.6.x is required. Please update prototype.js (rake rails:update:javascripts)."; + warning = "ActiveScaffold Error: Prototype version 1.6.x or higher is required. Please update prototype.js (rake rails:update:javascripts)."; alert(warning); } if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFunction}); +document.observe("dom:loaded", function() { + Event.on($(document.body), 'ajax:before', 'form.as_form', function(event) { + var as_form = event.findElement('form'); + if (as_form) { + var loading_indicator = $(as_form.id.sub('--form', '-loading-indicator')); + if (loading_indicator) loading_indicator.style.visibility = 'visible'; + as_form.disable(); + } + return true; + }); + Event.on($(document.body), 'ajax:complete', 'form.as_form', function(event) { + var as_form = event.findElement('form'); + if (as_form) { + var loading_indicator = $(as_form.id.sub('--form', '-loading-indicator')); + if (loading_indicator) loading_indicator.style.visibility = 'hidden'; + as_form.enable(); + event.stop(); + return false; + } + }); + Event.on($(document.body), 'ajax:failure', 'form.as_form', function(event) { + var as_div = event.findElement('div.activescaffold'); + if (as_div) { + ActiveScaffold.report_500_response(as_div) + event.stop(); + return false; + } + }); + Event.on($(document.body), 'ajax:before', 'a.as_action', function(event) { + var as_action = event.findElement(); + if (as_action.action_link) { + var action_link = as_action_link; + if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'visible'; + } + return true; + }); + Event.on($(document.body), 'ajax:success', 'a.as_action', function(event) { + var as_action = event.findElement(); + if (as_action.action_link && event.memo && event.memo.request) { + var action_link = as_action.action_link; + if (action_link.position) { + action_link.insert(event.memo.request.responseText); + if (action_link.hide_target) action_link.target.hide(); + } else { + event.memo.request.evalResponse(); + } + event.stop(); + } + return true; + }); + Event.on($(document.body), 'ajax:complete', 'a.as_action', function(event) { + var as_action = event.findElement(); + if (as_action.action_link) { + var action_link = as_action_link; + if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'hidden'; + } + return true; + }); + Event.on($(document.body), 'ajax:failure', 'a.as_action', function(event) { + var as_action = event.findElement(); + if (as_action.action_link) { + var action_link = as_action_link; + ActiveScaffold.report_500_response(action_link.scaffold_id()); + if (action_link.position) action_link.enable(); + } + return true; + }); + Event.on($(document.body), 'click', 'a.as_cancel', function(event) { + var as_cancel = event.findElement(); + if (as_cancel.action_link) { + var action_link = as_cancel.action_link; + action_link.close(); + event.stop(); + } + return true; + }); +}); + + /* * Simple utility methods */ @@ -209,63 +288,37 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ this.target = target; this.loading_indicator = loading_indicator; this.hide_target = false; - this.position = this.tag.getAttribute('position'); - this.page_link = this.tag.getAttribute('page_link'); - - this.onclick = this.tag.onclick; - this.tag.onclick = null; - this.tag.observe('click', function(event) { - this.open(); - Event.stop(event); - }.bind(this)); + this.position = this.tag.getAttribute('data-position'); + var ajax_link = this.tag.getAttribute('data-remote'); + + if (ajax_link == 'true') { + this.onclick = this.tag.onclick; + this.tag.onclick = null; + this.tag.observe('click', function(event) { + this.open(event); + }.bind(this)); + } this.tag.action_link = this; }, - open: function() { - if (this.is_disabled()) return; - - if (this.tag.hasAttribute( "dhtml_confirm")) { + open: function(event) { + if (this.is_disabled()) { + if (event) Event.stop(event); + return; + } + +/* + if (this.tag.hasAttribute( "data-confirm")) { if (this.onclick) this.onclick(); return; } else { if (this.onclick && !this.onclick()) return;//e.g. confirmation messages this.open_action(); } +*/ }, - - open_action: function() { - if (this.position) this.disable(); - - if (this.page_link) { - window.location = this.url; - } else { - if (this.loading_indicator) this.loading_indicator.style.visibility = 'visible'; - new Ajax.Request(this.url, { - asynchronous: true, - evalScripts: true, - method: this.method, - onSuccess: function(request) { - if (this.position) { - this.insert(request.responseText); - if (this.hide_target) this.target.hide(); - } else { - request.evalResponse(); - } - }.bind(this), - - onFailure: function(request) { - ActiveScaffold.report_500_response(this.scaffold_id()); - if (this.position) this.enable() - }.bind(this), - - onComplete: function(request) { - if (this.loading_indicator) this.loading_indicator.style.visibility = 'hidden'; - }.bind(this) - }); - } - }, - + insert: function(content) { throw 'unimplemented' }, @@ -276,18 +329,12 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ if (this.hide_target) this.target.show(); }, - close_handler: function(event) { - this.close(); - if (event) Event.stop(event); - }, - register_cancel_hooks: function() { // anything in the insert with a class of cancel gets the closer method, and a reference to this object for good measure var self = this; - this.adapter.select('.cancel').each(function(elem) { - elem.observe('click', this.close_handler.bind(this)); - elem.link = self; - }.bind(this)) + this.adapter.select('.as_cancel').each(function(elem) { + elem.action_link = self; + }) }, reload: function() { @@ -330,7 +377,10 @@ ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, { l.url = l.url.replace(/\/delete(\?.*)?$/, '$1'); l.url = l.url.replace(/\/delete\/(.*)/, '/destroy/$1'); } - if (l.position) l.url = l.url.append_params({adapter: '_list_inline_adapter'}); + if (l.position) { + l.url = l.url.append_params({adapter: '_list_inline_adapter'}); + l.tag.href = l.url; + } l.set = this; return l; } @@ -355,20 +405,17 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra } if (this.position == 'after') { - new Insertion.After(this.target, content); + this.target.insert({after:content}); this.adapter = this.target.next(); } else if (this.position == 'before') { - new Insertion.Before(this.target, content); + this.target.insert({before:content}); this.adapter = this.target.previous(); } else { return false; } - - this.adapter.down('a.inline-adapter-close').observe('click', this.close_handler.bind(this)); this.register_cancel_hooks(); - this.adapter.down('td').down().highlight(); }, @@ -414,7 +461,10 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra ActiveScaffold.Actions.Table = Class.create(ActiveScaffold.Actions.Abstract, { instantiate_link: function(link) { var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator); - if (l.position) l.url = l.url.append_params({adapter: '_list_inline_adapter'}); + if (l.position) { + l.url = l.url.append_params({adapter: '_list_inline_adapter'}); + l.tag.href = l.url; + } return l; } }); @@ -422,16 +472,14 @@ ActiveScaffold.Actions.Table = Class.create(ActiveScaffold.Actions.Abstract, { ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstract, { insert: function(content) { if (this.position == 'top') { - new Insertion.Top(this.target, content); + this.target.insert({top:content}); this.adapter = this.target.immediateDescendants().first(); } else { throw 'Unknown position "' + this.position + '"' } - this.adapter.down('a.inline-adapter-close').observe('click', this.close_handler.bind(this)); this.register_cancel_hooks(); - this.adapter.down('td').down().highlight(); } }); diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index b59b6a66f0..560bdb2cb0 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -600,7 +600,7 @@ list-style: none; clear: both; } -.active-scaffold a.cancel, +.active-scaffold a.as_cancel, .active-scaffold p.form-footer a { font: bold 14px arial, sans-serif; letter-spacing: 0; diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index 5c2e658b6b..5785e2d2cf 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -7,20 +7,20 @@ if xhr :onsubmit => onsubmit, :id => element_form_id(:action => :create), :loading => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible';", - :class => 'create' + :class => 'as_form create' else form_tag url_options, :remote => true, :id => element_form_id(:action => :create), :onsubmit => onsubmit, - :class => 'create' + :class => 'as_form create' end else form_tag url_options, :onsubmit => onsubmit, :id => element_form_id(:action => :create), :multipart => active_scaffold_config.create.multipart?, - :class => 'create' + :class => 'as_fom create' end %> <h4><%= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil) -%></h4> @@ -37,9 +37,8 @@ end %> <p class="form-footer"> <%= submit_tag as_(:create), :class => "submit" %> - <%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %> + <%= link_to as_(:cancel), main_path_to_return, :class => 'as_cancel', :remote => true %> <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> </p> </form> -<%= render :partial => 'form_js', :locals => {:action_type => :create, :id => params[:id]} %> diff --git a/frontends/default/views/_create_form_on_list.html.erb b/frontends/default/views/_create_form_on_list.html.erb index 40e5f0eba3..898abf112d 100644 --- a/frontends/default/views/_create_form_on_list.html.erb +++ b/frontends/default/views/_create_form_on_list.html.erb @@ -27,5 +27,4 @@ end -%> <%= submit_tag as_(:create), :class => "submit" %> <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> </p> -</form> -<%= render :partial => 'form_js', :locals => {:action_type => :create, :id => params[:id]} %> \ No newline at end of file +</form> \ No newline at end of file diff --git a/frontends/default/views/_form_js.html.erb b/frontends/default/views/_form_js.html.erb deleted file mode 100644 index 43dbe449b0..0000000000 --- a/frontends/default/views/_form_js.html.erb +++ /dev/null @@ -1,14 +0,0 @@ -<script type="text/javascript"> -Form.focusFirstElement('<%= element_form_id(:action => action_type) -%>'); -$('<%= element_form_id(:action => action_type) %>').observe("ajax:after", function(event){ - $('<%= loading_indicator_id(:action => action_type, :id => id) %>').style.visibility = 'visible'; - Form.disable('<%= element_form_id(:action => action_type)%>'); -}); -$('<%= element_form_id(:action => action_type) %>').observe("ajax:complete", function(event){ - $('<%= loading_indicator_id(:action => action_type, :id => id) %>').style.visibility = 'hidden'; - Form.enable('<%= element_form_id(:action => action_type)%>'); -}); -$('<%= element_form_id(:action => action_type) %>').observe("ajax:failure", function(event){ - ActiveScaffold.report_500_response('<%= active_scaffold_id %>'); -}); -</script> diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 08736260a0..e7e7279980 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -16,7 +16,7 @@ <script type="text/javascript"> //<![CDATA[ new ActiveScaffold.Actions.Record( - $$('#<%= target_id -%> a.action'), + $$('#<%= target_id -%> a.as_action'), $('<%= target_id -%>'), $('<%= loading_indicator_id(:action => :record, :id => record.id) -%>'), {refresh_url: '<%= url_for params_for(:action => :row, :id => record.id, :_method => :get, :escape => false) -%>'} diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index d302cfa9df..abe43c4b86 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -3,7 +3,7 @@ <tr class="inline-adapter" id="<%= element_row_id :action => :nested %>"> <td colspan="99" class="inline-adapter-cell"> <div class="<%= "#{params[:action]}-view" if params[:action] %> <%= "#{params[:associations] ? params[:associations] : params[:controller]}-view" %> view"> - <a href="" class="inline-adapter-close" title="<%= as_(:close) %>"><%= as_(:close) %></a> + <a href="" class="inline-adapter-close as_cancel" title="<%= as_(:close) %>"><%= as_(:close) %></a> <%= payload -%> </div> </td> diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index 3dda7c2c99..c3cfad277b 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -7,14 +7,15 @@ if xhr :onsubmit => onsubmit, :id => element_form_id(:action => :update), :loading => "$('#{loading_indicator_id(:action => :update, :id => params[:id])}').style.visibility = 'visible';", - :class => 'update', + :class => 'as_form update', :method => :put else form_tag url_options, + :remote => true, :onsubmit => onsubmit, :id => element_form_id(:action => :update), :multipart => active_scaffold_config.update.multipart?, - :class => 'update', + :class => 'as_form update', :method => :put end else @@ -22,7 +23,7 @@ else :onsubmit => onsubmit, :id => element_form_id(:action => :update), :multipart => active_scaffold_config.update.multipart?, - :class => 'update', + :class => 'as_form update', :method => :put end %> @@ -31,7 +32,7 @@ end <div id="<%= element_messages_id(:action => :update) %>" class="messages-container"> <% if request.xhr? -%> - <%= error_messages_for :record, :object_name => @record.class.human_name.downcase %> + <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> <% else -%> <%= render :partial => 'form_messages' %> <% end -%> @@ -41,9 +42,8 @@ end <p class="form-footer"> <%= submit_tag as_(:update), :class => "submit" %> - <%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %> + <%= link_to as_(:cancel), main_path_to_return, :class => 'as_cancel', :remote => true %> <%= loading_indicator_tag(:action => :update, :id => params[:id]) %> </p> </form> -<%= render :partial => 'form_js', :locals => {:action_type => :update, :id => params[:id]} %> diff --git a/frontends/default/views/list.html.erb b/frontends/default/views/list.html.erb index 22943e828a..9f473a29ff 100644 --- a/frontends/default/views/list.html.erb +++ b/frontends/default/views/list.html.erb @@ -37,7 +37,7 @@ Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-header').first(), {color: 'fromElement', bgColor: 'fromParent', corners: 'top', compact: true}); Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-footer').first(), {color: 'fromElement', bgColor: 'fromParent', corners: 'bottom', compact: true}); <% end -%> -new ActiveScaffold.Actions.Table($$('#<%= active_scaffold_id -%> div.active-scaffold-header a.action'), $('<%= before_header_id -%>'), $('<%= loading_indicator_id(:action => :table) -%>')); +new ActiveScaffold.Actions.Table($$('#<%= active_scaffold_id -%> div.active-scaffold-header a.as_action'), $('<%= before_header_id -%>'), $('<%= loading_indicator_id(:action => :table) -%>')); ActiveScaffold.server_error_response = '<p class="error-message message">' + <%= as_(:internal_error).to_json.html_safe %> + '<a href="#" onclick="Element.remove(this.parentNode); return false;">' diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index a9e0eae4cf..792a60bceb 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -142,8 +142,11 @@ def render_action_link(link, url_options, record = nil, html_options = {}) # argument leaves no way to extract the proper method from the rendered tag. url_options[:_method] = link.method - if link.method != :get and respond_to?(:protect_against_forgery?) and protect_against_forgery? - url_options[:authenticity_token] = form_authenticity_token + #if link.method != :get and respond_to?(:protect_against_forgery?) and protect_against_forgery? + # url_options[:authenticity_token] = form_authenticity_token + #end + if link.method != :get + html_options['data-method'] = link.method end # robd: protect against submitting get links as forms, since this causes annoying @@ -153,14 +156,14 @@ def render_action_link(link, url_options, record = nil, html_options = {}) html_options[:method] = link.method end - html_options[:confirm] = link.confirm(record.try(:to_label)) if link.confirm? - html_options[:position] = link.position if link.position and link.inline? - html_options[:class] += ' action' if link.inline? + html_options['data-confirm'] = link.confirm(record.try(:to_label)) if link.confirm? + html_options['data-position'] = link.position if link.position and link.inline? + html_options[:class] += ' as_action' if link.inline? html_options[:popup] = true if link.popup? html_options[:id] = action_link_id("#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}" + "#{url_options[:associations].to_s + '-' if url_options[:associations]}" + url_options[:action].to_s,url_options[:id] || url_options[:parent_id]) - + html_options[:remote] = true unless link.page? || html_options['data-method'] if link.dhtml_confirm? - html_options[:class] += ' action' if !link.inline? + html_options[:class] += ' as_action' if !link.inline? html_options[:page_link] = 'true' if !link.inline? html_options[:dhtml_confirm] = link.dhtml_confirm.value html_options[:onclick] = link.dhtml_confirm.onclick_function(controller,action_link_id(url_options[:action],url_options[:id] || url_options[:parent_id])) From ffa701e5101597775a07d7c1d045573f3bd83a8a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 28 May 2010 12:50:56 +0200 Subject: [PATCH 0347/2024] move error_message_for into activescaffold to remove dependency on dynamic form plugin --- lib/active_scaffold/helpers/view_helpers.rb | 56 +++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 792a60bceb..fc8c539144 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -217,6 +217,62 @@ def column_show_add_new(column, associated, record) value = false unless record.class.authorized_for?(:crud_type => :create) value end + + def error_messages_for(*params) + options = params.extract_options!.symbolize_keys + + objects = Array.wrap(options.delete(:object) || params).map do |object| + object = instance_variable_get("@#{object}") unless object.respond_to?(:to_model) + object = convert_to_model(object) + + if object.class.respond_to?(:model_name) + options[:object_name] ||= object.class.model_name.human.downcase + end + + object + end + + objects.compact! + count = objects.inject(0) {|sum, object| sum + object.errors.count } + + unless count.zero? + html = {} + [:id, :class].each do |key| + if options.include?(key) + value = options[key] + html[key] = value unless value.blank? + else + html[key] = 'errorExplanation' + end + end + options[:object_name] ||= params.first + + I18n.with_options :locale => options[:locale], :scope => [:activerecord, :errors, :template] do |locale| + header_message = if options.include?(:header_message) + options[:header_message] + else + locale.t :header, :count => count, :model => options[:object_name].to_s.gsub('_', ' ') + end + + message = options.include?(:message) ? options[:message] : locale.t(:body) + + error_messages = objects.sum do |object| + object.errors.full_messages.map do |msg| + content_tag(:li, msg) + end + end.join.html_safe + + contents = '' + contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank? + contents << content_tag(:p, message) unless message.blank? + contents << content_tag(:ul, error_messages) + + content_tag(:div, contents.html_safe, html) + end + else + '' + end + end end end end From a5feddcecb3c98d316e32653c99074bfd1a8b9c3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 28 May 2010 13:58:27 +0200 Subject: [PATCH 0348/2024] set required flag for column if presence_validator is set in model --- lib/active_scaffold/data_structures/column.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 0babd5a86e..11ff313ae0 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -251,7 +251,7 @@ def initialize(name, active_record_class) #:nodoc: # default all the configurable variables self.css_class = '' - self.required = false + self.required = active_record_class.validators_on(self.name).map(&:class).include? ActiveModel::Validations::PresenceValidator self.sort = true self.search_sql = true From 024417355db9c4136ecefee1833eb288d7b774ac Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 28 May 2010 14:20:59 +0200 Subject: [PATCH 0349/2024] Bugfix: Cancel links generated two requests --- frontends/default/views/_create_form.html.erb | 2 +- frontends/default/views/_update_form.html.erb | 2 +- frontends/default/views/on_create.js.rjs | 4 ++-- frontends/default/views/on_update.js.rjs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index 5785e2d2cf..4f3724b20b 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -37,7 +37,7 @@ end %> <p class="form-footer"> <%= submit_tag as_(:create), :class => "submit" %> - <%= link_to as_(:cancel), main_path_to_return, :class => 'as_cancel', :remote => true %> + <%= link_to as_(:cancel), main_path_to_return, :class => 'as_cancel' %> <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> </p> diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index c3cfad277b..bd5d2a58ea 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -42,7 +42,7 @@ end <p class="form-footer"> <%= submit_tag as_(:update), :class => "submit" %> - <%= link_to as_(:cancel), main_path_to_return, :class => 'as_cancel', :remote => true %> + <%= link_to as_(:cancel), main_path_to_return, :class => 'as_cancel' %> <%= loading_indicator_tag(:action => :update, :id => params[:id]) %> </p> diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index b997f8c729..4ac3ca50e2 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -1,5 +1,5 @@ form = element_form_id(:action => :create) -cancel_selector = "##{form} a.cancel".to_json +cancel_selector = "##{form} a.as_cancel".to_json if controller.send :successful? if @insert_row @@ -20,7 +20,7 @@ if controller.send :successful? page << "if (link) (function() { link.action_link.open() }).defer();" end else - page << "var l = $$(#{cancel_selector}).first().link;" + page << "var l = $$(#{cancel_selector}).first().action_link;" page.replace form, :partial => 'create_form', :locals => {:xhr => true} page << "if (l) l.register_cancel_hooks();" page[form].scroll_to diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index f162265b51..61f278cca2 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -1,5 +1,5 @@ form = element_form_id(:action => :update) -cancel_selector = "##{form} a.cancel".to_json +cancel_selector = "##{form} a.as_cancel".to_json if controller.send :successful? updated_row = render :partial => 'list_record', :locals => {:record => @record} From b18f0c122ea17a1533e4ecae5a3daa3e51ec53c9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 28 May 2010 16:05:18 +0200 Subject: [PATCH 0350/2024] removed register_cancel_hooks --- .../default/javascripts/active_scaffold.js | 19 +++++++------------ frontends/default/views/on_create.js.rjs | 9 +++------ frontends/default/views/on_update.js.rjs | 7 ++----- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 8b098bcb33..433d45074a 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -79,7 +79,7 @@ document.observe("dom:loaded", function() { return true; }); Event.on($(document.body), 'click', 'a.as_cancel', function(event) { - var as_cancel = event.findElement(); + var as_cancel = event.findElement('.as_adapter'); if (as_cancel.action_link) { var action_link = as_cancel.action_link; action_link.close(); @@ -329,14 +329,6 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ if (this.hide_target) this.target.show(); }, - register_cancel_hooks: function() { - // anything in the insert with a class of cancel gets the closer method, and a reference to this object for good measure - var self = this; - this.adapter.select('.as_cancel').each(function(elem) { - elem.action_link = self; - }) - }, - reload: function() { this.close(); this.open(); @@ -407,15 +399,18 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra if (this.position == 'after') { this.target.insert({after:content}); this.adapter = this.target.next(); + this.adapter.addClassName('as_adapter'); + this.adapter.action_link = this; } else if (this.position == 'before') { this.target.insert({before:content}); this.adapter = this.target.previous(); + this.adapter.addClassName('as_adapter'); + this.adapter.action_link = this; } else { return false; } - this.register_cancel_hooks(); this.adapter.down('td').down().highlight(); }, @@ -474,12 +469,12 @@ ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstrac if (this.position == 'top') { this.target.insert({top:content}); this.adapter = this.target.immediateDescendants().first(); + this.adapter.addClassName('as_adapter'); + this.adapter.action_link = this; } else { throw 'Unknown position "' + this.position + '"' } - - this.register_cancel_hooks(); this.adapter.down('td').down().highlight(); } }); diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index 4ac3ca50e2..efe1a0d0a3 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -1,5 +1,4 @@ -form = element_form_id(:action => :create) -cancel_selector = "##{form} a.as_cancel".to_json +form_selector = "#{element_form_id(:action => :create)}".to_json if controller.send :successful? if @insert_row @@ -11,18 +10,16 @@ if controller.send :successful? end if (active_scaffold_config.create.persistent) - page << "$$(#{cancel_selector}).first().link.reload();" + page << "$(#{form_selector}).up('.as_adapter').action_link.reload();" else - page << "$$(#{cancel_selector}).first().link.close();" + page << "$(#{form_selector}).up('.as_adapter').action_link.close();" end if (active_scaffold_config.create.edit_after_create) page << "var link = $('#{action_link_id 'edit', @record.id}');" page << "if (link) (function() { link.action_link.open() }).defer();" end else - page << "var l = $$(#{cancel_selector}).first().action_link;" page.replace form, :partial => 'create_form', :locals => {:xhr => true} - page << "if (l) l.register_cancel_hooks();" page[form].scroll_to end page.replace_html active_scaffold_messages_id, :partial => 'messages' diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 61f278cca2..2f509a1928 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -1,14 +1,11 @@ -form = element_form_id(:action => :update) -cancel_selector = "##{form} a.as_cancel".to_json +form_selector = "#{element_form_id(:action => :update)}".to_json if controller.send :successful? updated_row = render :partial => 'list_record', :locals => {:record => @record} - page << "$$(#{cancel_selector}).first().link.close('#{escape_javascript(updated_row)}');" + page << "$(#{form_selector}).up('.as_adapter').action_link.close('#{escape_javascript(updated_row)}');" page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} else - page << "var l = $$(#{cancel_selector}).first().link;" page.replace form, :partial => 'update_form', :locals => {:xhr => true} - page << "if (l) l.register_cancel_hooks();" page[form].scroll_to end page.replace_html active_scaffold_messages_id, :partial => 'messages' From f72bde2c4e0a107a67aa2bcc90457dca72083189 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 31 May 2010 10:52:30 +0200 Subject: [PATCH 0351/2024] Lock associated record only when is added automatically --- frontends/default/views/_form_association.html.erb | 7 +++++-- frontends/default/views/_horizontal_subform.html.erb | 2 +- frontends/default/views/_vertical_subform.html.erb | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index c37fb32e22..e34b923513 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -3,10 +3,13 @@ parent_record = @record associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) -associated << column.association.klass.new if column.show_blank_record? associated +if column.show_blank_record? associated + associated << column.association.klass.new + locked = associated.last +end -%> <h5><%= column.label -%> (<%= link_to_visibility_toggle(:default_visible => !column.collapsed) -%>)</h5> <div <%= 'style="display: none;"' if column.collapsed -%>> -<%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated} %> +<%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :locked => locked} %> </div> <% @record = parent_record -%> diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index f04af620f1..3e392578c3 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -12,7 +12,7 @@ </td> </tr> <% end %> - <%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => @record.new_record? && @record == associated.last} %> + <%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => @record == locked} %> <% end -%> </tbody> </table> diff --git a/frontends/default/views/_vertical_subform.html.erb b/frontends/default/views/_vertical_subform.html.erb index 1d0c1d607e..eb374c1924 100644 --- a/frontends/default/views/_vertical_subform.html.erb +++ b/frontends/default/views/_vertical_subform.html.erb @@ -6,7 +6,7 @@ <%= error_messages_for :record, :object_name => @record.class.human_name.downcase %> </div> <% end %> - <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => @record.new_record? && @record == associated.last} %> + <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => @record == locked} %> <% end -%> </div> <%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%> From 7ba7d1c0b2c225b79da26586e8bd1624f69faea2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 31 May 2010 15:44:14 +0200 Subject: [PATCH 0352/2024] get resource routing at least running again eg resources :teams do ActiveScaffold.add_routes(self) end --- lib/active_scaffold.rb | 12 ++++++++++++ lib/extensions/resources.rb | 31 ------------------------------- 2 files changed, 12 insertions(+), 31 deletions(-) delete mode 100644 lib/extensions/resources.rb diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index f3301381b7..c9a90ff0b4 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -17,6 +17,18 @@ def self.included(base) def self.set_defaults(&block) ActiveScaffold::Config::Core.configure &block end + + def self.add_routes(resource) + resource.collection do + resource.get :show_search, :edit_associated, :list, :new_existing, :render_field + resource.post :add_existing + end + resource.member do + resource.get :row, :nested, :edit_associated, :add_association, :render_field, :delete + resource.post :update_column + resource.delete :destroy_existing + end + end def active_scaffold_config self.class.active_scaffold_config diff --git a/lib/extensions/resources.rb b/lib/extensions/resources.rb deleted file mode 100644 index 0f99a6bfe9..0000000000 --- a/lib/extensions/resources.rb +++ /dev/null @@ -1,31 +0,0 @@ -module ActionDispatch - module Routing - class Mapper - module Resources - class Resource - ACTIVE_SCAFFOLD_ROUTING = { - :collection => {:show_search => :get, :edit_associated => :get, :list => :get, :new_existing => :get, :add_existing => :post, :render_field => :get}, - :member => {:row => :get, :nested => :get, :edit_associated => :get, :add_association => :get, :update_column => :post, :destroy_existing => :delete, :render_field => :get, :delete => :get} - } - - # by overwriting the attr_reader :options, we can parse out a special :active_scaffold flag just-in-time. - def options_with_active_scaffold - if @options.delete :active_scaffold - logger.info "ActiveScaffold: extending RESTful routes for #{@plural}" - @options[:collection] ||= {} - @options[:collection].merge! ACTIVE_SCAFFOLD_ROUTING[:collection] - @options[:member] ||= {} - @options[:member].merge! ACTIVE_SCAFFOLD_ROUTING[:member] - end - options_without_active_scaffold - end - alias_method_chain :options, :active_scaffold - - def logger - ActionController::Base::logger - end - end - end - end - end -end From 58e9fbc88e2eaca31c3ac045bf79dd7e12bd84be Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 31 May 2010 15:58:48 +0200 Subject: [PATCH 0353/2024] mark empty value as html_safe --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index dfa08db910..c6f5772007 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -23,7 +23,7 @@ def get_column_value(record, column) format_column_value(record, column) end - value = ' ' if value.nil? or (value.respond_to?(:empty?) and value.empty?) # fix for IE 6 + value = ' '.html_safe if value.nil? or (value.respond_to?(:empty?) and value.empty?) # fix for IE 6 return value rescue Exception => e logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}" From ca95b44802206b174caa68aee1a44ae306357883 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 31 May 2010 16:36:31 +0200 Subject: [PATCH 0354/2024] Fix tiny mce bridge --- lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb | 14 +++++++++----- test/bridges/tiny_mce_test.rb | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb b/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb index 95b0abb479..5ab95ad01e 100644 --- a/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb +++ b/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb @@ -1,5 +1,13 @@ module ActiveScaffold module TinyMceBridge + def self.included(base) + base.class_eval do + include FormColumnHelpers + include SearchColumnHelpers + include ViewHelpers + end + end + module ViewHelpers def self.included(base) base.alias_method_chain :active_scaffold_includes, :tiny_mce @@ -46,8 +54,4 @@ def self.included(base) end end -ActiveScaffold::Helpers::ViewHelpers.module_eval do - include ActiveScaffold::TinyMceBridge::FormColumnHelpers - include ActiveScaffold::TinyMceBridge::SearchColumnHelpers - include ActiveScaffold::TinyMceBridge::ViewHelpers -end +ActionView::Base.class_eval { include ActiveScaffold::TinyMceBridge } diff --git a/test/bridges/tiny_mce_test.rb b/test/bridges/tiny_mce_test.rb index 590851ecbd..764e80ef40 100644 --- a/test/bridges/tiny_mce_test.rb +++ b/test/bridges/tiny_mce_test.rb @@ -4,6 +4,7 @@ class TinyMceTest < ActionView::TestCase include ActiveScaffold::Helpers::ViewHelpers + include ActiveScaffold::TinyMceBridge def test_includes assert_match /.*<script type="text\/javascript">.*ActiveScaffold\.ActionLink\.Abstract\.prototype\.close = function\(\).*<\/script>.*/m, active_scaffold_includes From 9a54f93a2317d4e9535509f54a4ef257b1f7d850 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 1 Jun 2010 14:27:28 +0200 Subject: [PATCH 0355/2024] get file uploads up and running with rails 3.0 and paperclip --- lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/actions/update.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 2 +- lib/bridges/paperclip/bridge.rb | 13 ++++++++ lib/bridges/paperclip/lib/form_ui.rb | 20 ++++++++++++ lib/bridges/paperclip/lib/list_ui.rb | 16 ++++++++++ lib/bridges/paperclip/lib/paperclip_bridge.rb | 32 +++++++++++++++++++ .../paperclip/lib/paperclip_bridge_helpers.rb | 18 +++++++++++ lib/responds_to_parent.rb | 8 +++-- 9 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 lib/bridges/paperclip/bridge.rb create mode 100644 lib/bridges/paperclip/lib/form_ui.rb create mode 100644 lib/bridges/paperclip/lib/list_ui.rb create mode 100644 lib/bridges/paperclip/lib/paperclip_bridge.rb create mode 100644 lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 15d6bf3cc2..0ac9fecba8 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -39,7 +39,7 @@ def new_respond_to_js def create_respond_to_html if params[:iframe]=='true' # was this an iframe post ? responds_to_parent do - render :action => 'on_create.js' + render :action => 'on_create.js', :layout => false end else if successful? diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 1321294d26..ddc3281fae 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -37,7 +37,7 @@ def edit_respond_to_js def update_respond_to_html if params[:iframe]=='true' # was this an iframe post ? responds_to_parent do - render :action => 'on_update.js' + render :action => 'on_update.js', :layout => false end else # just a regular post if successful? diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index fc8c539144..30349f9a39 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -72,7 +72,7 @@ def form_remote_upload_tag(url_for_options = {}, options = {}) output="" output << form_tag(url_for_options, options) - output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>" + (output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>").html_safe end # Provides list of javascripts to include with +javascript_include_tag+ diff --git a/lib/bridges/paperclip/bridge.rb b/lib/bridges/paperclip/bridge.rb new file mode 100644 index 0000000000..bdf507be7f --- /dev/null +++ b/lib/bridges/paperclip/bridge.rb @@ -0,0 +1,13 @@ +require File.join(File.dirname(__FILE__), "lib/paperclip_bridge_helpers") +ActiveScaffold.bridge "Paperclip" do + install do + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip") + raise RuntimeError, "We've detected that you have active_scaffold_paperclip_bridge installed. This plugin has been moved to core. Please remove active_scaffold_paperclip_bridge to prevent any conflicts" + end + + require File.join(File.dirname(__FILE__), "lib/paperclip_bridge") + require File.join(File.dirname(__FILE__), "lib/form_ui") + require File.join(File.dirname(__FILE__), "lib/list_ui") + ActiveScaffold::Config::Core.send :include, ActiveScaffold::PaperclipBridge + end +end \ No newline at end of file diff --git a/lib/bridges/paperclip/lib/form_ui.rb b/lib/bridges/paperclip/lib/form_ui.rb new file mode 100644 index 0000000000..025f1b694b --- /dev/null +++ b/lib/bridges/paperclip/lib/form_ui.rb @@ -0,0 +1,20 @@ +module ActiveScaffold + module Helpers + module FormColumnHelpers + def active_scaffold_input_paperclip(column, options) + input = file_field(:record, column.name, options) + paperclip = @record.send("#{column.name}") + if paperclip.file? + content = active_scaffold_column_paperclip(column, @record) + content_tag(:div, + content + " | " + + link_to_function(as_(:remove_file), "$(this).next().value='true'; $(this).up().hide().next().show()") + + hidden_field(:record, "delete_#{column.name}", :value => "false") + ) + content_tag(:div, input, :style => "display: none") + else + input + end + end + end + end +end \ No newline at end of file diff --git a/lib/bridges/paperclip/lib/list_ui.rb b/lib/bridges/paperclip/lib/list_ui.rb new file mode 100644 index 0000000000..c06a351b53 --- /dev/null +++ b/lib/bridges/paperclip/lib/list_ui.rb @@ -0,0 +1,16 @@ +module ActiveScaffold + module Helpers + module ListColumnHelpers + def active_scaffold_column_paperclip(column, record) + paperclip = record.send("#{column.name}") + return nil unless paperclip.file? + content = if paperclip.styles.include?(PaperclipBridgeHelpers.thumbnail_style) + image_tag(paperclip.url(PaperclipBridgeHelpers.thumbnail_style), :border => 0) + else + paperclip.original_filename + end + link_to(content, paperclip.url, :popup => true) + end + end + end +end \ No newline at end of file diff --git a/lib/bridges/paperclip/lib/paperclip_bridge.rb b/lib/bridges/paperclip/lib/paperclip_bridge.rb new file mode 100644 index 0000000000..89d7a0428e --- /dev/null +++ b/lib/bridges/paperclip/lib/paperclip_bridge.rb @@ -0,0 +1,32 @@ +module ActiveScaffold + module PaperclipBridge + def initialize_with_paperclip(model_id) + initialize_without_paperclip(model_id) + return unless self.model.respond_to?(:attachment_definitions) + + self.update.multipart = true + self.create.multipart = true + + self.model.attachment_definitions.keys.each do |field| + configure_paperclip_field(field.to_sym) + # define the "delete" helper for use with active scaffold, unless it's already defined + PaperclipBridgeHelpers.generate_delete_helper(self.model, field) + end + end + + def self.included(base) + base.alias_method_chain :initialize, :paperclip + end + + private + def configure_paperclip_field(field) + self.columns << field + self.columns[field].form_ui ||= :paperclip + self.columns[field].params.add "delete_#{field}" + + [:file_name, :content_type, :file_size, :updated_at].each do |f| + self.columns.exclude("#{field}_#{f}".to_sym) + end + end + end +end diff --git a/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb b/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb new file mode 100644 index 0000000000..3dcb49dd3d --- /dev/null +++ b/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb @@ -0,0 +1,18 @@ +module PaperclipBridgeHelpers + mattr_accessor :thumbnail_style + self.thumbnail_style = :thumbnail + + def self.generate_delete_helper(klass, field) + klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("delete_#{field}=") + attr_reader :delete_#{field} + + def delete_#{field}=(value) + value = (value == "true") if String === value + return unless value + + # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! + self.#{field} = nil unless self.#{field}.dirty? + end + EOF + end +end \ No newline at end of file diff --git a/lib/responds_to_parent.rb b/lib/responds_to_parent.rb index 31ee781b6b..aadd6ff17f 100644 --- a/lib/responds_to_parent.rb +++ b/lib/responds_to_parent.rb @@ -34,7 +34,9 @@ def responds_to_parent(&block) response.headers['Content-Type'] = 'text/html; charset=UTF-8' # Either pull out a redirect or the request body - script = if location = erase_redirect_results + script = if response.headers['Location'] + #TODO: erase_redirect_results is missing in rails 3.0 has to be implemented + #erase redirect "document.location.href = #{location.to_s.inspect}" else response.body @@ -49,7 +51,7 @@ def responds_to_parent(&block) gsub('</script>','</scr"+"ipt>') # Clear out the previous render to prevent double render - erase_results + response.request.env['action_controller.instance'].instance_variable_set(:@_response_body, nil) # Eval in parent scope and replace document location of this frame # so back button doesn't replay action on targeted forms @@ -60,7 +62,7 @@ def responds_to_parent(&block) render :text => "<html><body><script type='text/javascript' charset='utf-8'> var loc = document.location; with(window.parent) { setTimeout(function() { window.eval('#{script}'); if (typeof(loc) !== 'undefined') loc.replace('about:blank'); }, 1) }; - </script></body></html>" + </script></body></html>".html_safe end end alias respond_to_parent responds_to_parent From 1ae97609584bb3a520462efab5966783b75a30f9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 1 Jun 2010 14:57:08 +0200 Subject: [PATCH 0356/2024] further form refactorings --- frontends/default/views/_create_form.html.erb | 26 ++++++----------- .../views/_create_form_on_list.html.erb | 16 +++++------ frontends/default/views/_update_form.html.erb | 28 ++++++------------- lib/active_scaffold/helpers/view_helpers.rb | 3 +- 4 files changed, 24 insertions(+), 49 deletions(-) diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index 4f3724b20b..0b6b1ed28f 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -1,26 +1,16 @@ <% url_options = params_for(:action => :create) -%> <% xhr ||= request.xhr? -%> <%= -if xhr - if active_scaffold_config.create.multipart? # file_uploads - form_remote_upload_tag url_options.merge({:iframe => true}), - :onsubmit => onsubmit, - :id => element_form_id(:action => :create), - :loading => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible';", - :class => 'as_form create' - else - form_tag url_options, - :remote => true, - :id => element_form_id(:action => :create), - :onsubmit => onsubmit, - :class => 'as_form create' - end -else - form_tag url_options, - :onsubmit => onsubmit, +options = {:onsubmit => onsubmit, :id => element_form_id(:action => :create), :multipart => active_scaffold_config.create.multipart?, - :class => 'as_fom create' + :class => 'as_form create'} +if xhr && active_scaffold_config.create.multipart? # file_uploads + form_remote_upload_tag url_options.merge({:iframe => true}), + options.merge({:loading => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible';"}) +else + options[:remote] = true if xhr + form_tag url_options, options end %> <h4><%= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil) -%></h4> diff --git a/frontends/default/views/_create_form_on_list.html.erb b/frontends/default/views/_create_form_on_list.html.erb index 898abf112d..51e49907aa 100644 --- a/frontends/default/views/_create_form_on_list.html.erb +++ b/frontends/default/views/_create_form_on_list.html.erb @@ -1,16 +1,14 @@ <% url_options = params_for(:action => :create) -%> <%= +options = {:onsubmit => onsubmit, + :id => element_form_id(:action => :create), + :multipart => active_scaffold_config.create.multipart?, + :class => 'as_form create'} if active_scaffold_config.create.multipart? # file_uploads - form_remote_upload_tag url_options.merge({:iframe => true}), - :onsubmit => onsubmit, - :id => element_form_id(:action => :create), - :class => 'create' + form_remote_upload_tag url_options.merge({:iframe => true}), options else - form_tag url_options, - :remote => true, - :id => element_form_id(:action => :create), - :onsubmit => onsubmit, - :class => 'create' + options[:remote] = true if xhr + form_tag url_options, options end -%> <h4><%= active_scaffold_config.create.label -%></h4> diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index bd5d2a58ea..90ae7e7941 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -1,30 +1,18 @@ <% url_options = params_for(:action => :update) -%> <% xhr ||= request.xhr? -%> <%= -if xhr - if active_scaffold_config.update.multipart? # file_uploads - form_remote_upload_tag url_options.merge({:iframe => true}), - :onsubmit => onsubmit, - :id => element_form_id(:action => :update), - :loading => "$('#{loading_indicator_id(:action => :update, :id => params[:id])}').style.visibility = 'visible';", - :class => 'as_form update', - :method => :put - else - form_tag url_options, - :remote => true, - :onsubmit => onsubmit, +options = {:onsubmit => onsubmit, :id => element_form_id(:action => :update), :multipart => active_scaffold_config.update.multipart?, :class => 'as_form update', - :method => :put - end + :method => :put} +if xhr && active_scaffold_config.update.multipart? # file_uploads + form_remote_upload_tag url_options.merge({:iframe => true}), + options.merge({:loading => "$('#{loading_indicator_id(:action => :update, :id => params[:id])}').style.visibility = 'visible';"}) + else - form_tag url_options, - :onsubmit => onsubmit, - :id => element_form_id(:action => :update), - :multipart => active_scaffold_config.update.multipart?, - :class => 'as_form update', - :method => :put + options[:remote] = true if xhr + form_tag url_options, options end %> diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 30349f9a39..89906b9c60 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -68,8 +68,7 @@ def form_remote_upload_tag(url_for_options = {}, options = {}) options[:onsubmit] = onsubmits * ';' options[:target] = action_iframe_id(url_for_options) - options[:multipart] = true - + options[:multipart] ||= true output="" output << form_tag(url_for_options, options) (output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>").html_safe From 5321b6bb8153314795421cd4bd69fdda62d8d5ca Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 1 Jun 2010 15:09:03 +0200 Subject: [PATCH 0357/2024] fixed two npes --- frontends/default/views/_create_form_on_list.html.erb | 1 + lib/bridges/paperclip/lib/paperclip_bridge.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_create_form_on_list.html.erb b/frontends/default/views/_create_form_on_list.html.erb index 51e49907aa..ffbc12450d 100644 --- a/frontends/default/views/_create_form_on_list.html.erb +++ b/frontends/default/views/_create_form_on_list.html.erb @@ -1,4 +1,5 @@ <% url_options = params_for(:action => :create) -%> +<% xhr ||= request.xhr? -%> <%= options = {:onsubmit => onsubmit, :id => element_form_id(:action => :create), diff --git a/lib/bridges/paperclip/lib/paperclip_bridge.rb b/lib/bridges/paperclip/lib/paperclip_bridge.rb index 89d7a0428e..c01ce3473f 100644 --- a/lib/bridges/paperclip/lib/paperclip_bridge.rb +++ b/lib/bridges/paperclip/lib/paperclip_bridge.rb @@ -2,7 +2,7 @@ module ActiveScaffold module PaperclipBridge def initialize_with_paperclip(model_id) initialize_without_paperclip(model_id) - return unless self.model.respond_to?(:attachment_definitions) + return unless self.model.respond_to?(:attachment_definitions) && !self.model.attachment_definitions.nil? self.update.multipart = true self.create.multipart = true From f8a6d3f9d79e77408f377e070a1c37ca8a82e19d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 1 Jun 2010 15:54:51 +0200 Subject: [PATCH 0358/2024] harmonize form code --- frontends/default/views/_create_form.html.erb | 11 ++++---- .../views/_create_form_on_list.html.erb | 26 +++++++++++-------- frontends/default/views/_update_form.html.erb | 8 +++--- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index 0b6b1ed28f..6c1adaaeda 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -4,14 +4,15 @@ options = {:onsubmit => onsubmit, :id => element_form_id(:action => :create), :multipart => active_scaffold_config.create.multipart?, - :class => 'as_form create'} + :class => 'as_form create', + :method => :post} if xhr && active_scaffold_config.create.multipart? # file_uploads - form_remote_upload_tag url_options.merge({:iframe => true}), - options.merge({:loading => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible';"}) + form_remote_upload_tag url_options.merge({:iframe => true}), + options.merge({:loading => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible';"}) else - options[:remote] = true if xhr + options[:remote] = true if xhr && !active_scaffold_config.create.multipart? form_tag url_options, options -end %> +end -%> <h4><%= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil) -%></h4> diff --git a/frontends/default/views/_create_form_on_list.html.erb b/frontends/default/views/_create_form_on_list.html.erb index ffbc12450d..dc1dc74ea1 100644 --- a/frontends/default/views/_create_form_on_list.html.erb +++ b/frontends/default/views/_create_form_on_list.html.erb @@ -4,22 +4,26 @@ options = {:onsubmit => onsubmit, :id => element_form_id(:action => :create), :multipart => active_scaffold_config.create.multipart?, - :class => 'as_form create'} -if active_scaffold_config.create.multipart? # file_uploads - form_remote_upload_tag url_options.merge({:iframe => true}), options + :class => 'as_form create', + :method => :post} +if xhr && active_scaffold_config.create.multipart? # file_uploads + form_remote_upload_tag url_options.merge({:iframe => true}), + options.merge({:loading => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible';"}) else - options[:remote] = true if xhr + options[:remote] = true if xhr && !active_scaffold_config.create.multipart? form_tag url_options, options end -%> - <h4><%= active_scaffold_config.create.label -%></h4> - - <% if request.xhr? -%> - <div id="<%= element_messages_id(:action => :create) %>" class="messages-container"><%= error_messages_for :record, :object_name => @record.class.human_name.downcase %></div> - <% else -%> + <h4><%= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil) -%></h4> + + <div id="<%= element_messages_id(:action => :create) %>" class="messages-container"> +<% if request.xhr? -%> + <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> +<% else -%> <%= render :partial => 'form_messages' %> - <% end -%> - +<% end -%> + </div> + <%= render :partial => 'form', :locals => { :columns => active_scaffold_config.create.columns } %> <p class="form-footer"> diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index 90ae7e7941..46877133a4 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -9,14 +9,12 @@ options = {:onsubmit => onsubmit, if xhr && active_scaffold_config.update.multipart? # file_uploads form_remote_upload_tag url_options.merge({:iframe => true}), options.merge({:loading => "$('#{loading_indicator_id(:action => :update, :id => params[:id])}').style.visibility = 'visible';"}) - else - options[:remote] = true if xhr + options[:remote] = true if xhr && !active_scaffold_config.create.multipart? form_tag url_options, options -end -%> +end -%> - <h4><%= @record.to_label.nil? ? active_scaffold_config.update.label : as_(:update_model, :model => clean_column_value(@record.to_label)) %></h4> + <h4><%= @record.to_label.nil? ? active_scaffold_config.update.label : as_(:update_model, :model => clean_column_value(@record.to_label)) -%></h4> <div id="<%= element_messages_id(:action => :update) %>" class="messages-container"> <% if request.xhr? -%> From ef6ae3505f4b11e96239f55ddedc3cbc975b5fb9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 2 Jun 2010 10:01:51 +0200 Subject: [PATCH 0359/2024] Bugfix: event handling for ajax:failure on action_links failed --- frontends/default/javascripts/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 433d45074a..0d65c34872 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -72,7 +72,7 @@ document.observe("dom:loaded", function() { Event.on($(document.body), 'ajax:failure', 'a.as_action', function(event) { var as_action = event.findElement(); if (as_action.action_link) { - var action_link = as_action_link; + var action_link = as_action.action_link; ActiveScaffold.report_500_response(action_link.scaffold_id()); if (action_link.position) action_link.enable(); } From f7e7ec7367dea98409e4984b039f6cc9a3729698 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 2 Jun 2010 10:55:36 +0200 Subject: [PATCH 0360/2024] added partial _base_form: to refactor duplicated code --- frontends/default/views/_base_form.html.erb | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 frontends/default/views/_base_form.html.erb diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb new file mode 100644 index 0000000000..e973a0b3e3 --- /dev/null +++ b/frontends/default/views/_base_form.html.erb @@ -0,0 +1,36 @@ +<% url_options = params_for(:action => form_action) -%> +<% xhr ||= request.xhr? -%> +<% as_action_config = active_scaffold_config.send(form_action) -%> +<%= +options = {:onsubmit => onsubmit, + :id => element_form_id(:action => form_action), + :multipart => as_action_config.multipart?, + :class => "as_form #{form_action.to_s}", + :method => method} +if xhr && as_action_config.multipart? # file_uploads + form_remote_upload_tag url_options.merge({:iframe => true}), + options.merge({:loading => "$('#{loading_indicator_id(:action => form_action, :id => params[:id])}').style.visibility = 'visible';"}) +else + options[:remote] = true if xhr && !as_action_config.multipart? + form_tag url_options, options +end -%> + + <h4><%= headline -%></h4> + + <div id="<%= element_messages_id(:action => form_action) %>" class="messages-container"> +<% if request.xhr? -%> + <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> +<% else -%> + <%= render :partial => 'form_messages' %> +<% end -%> + </div> + + <%= render :partial => 'form', :locals => { :columns => as_action_config.columns } %> + + <p class="form-footer"> + <%= submit_tag as_(form_action), :class => "submit" %> + <%= link_to (as_(:cancel), main_path_to_return, :class => 'as_cancel') if cancel_link %> + <%= loading_indicator_tag(:action => form_action, :id => params[:id]) %> + </p> + +</form> From 07003198572b37fa2026df6f81edd6cc2d63ccef Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 2 Jun 2010 11:50:19 +0200 Subject: [PATCH 0361/2024] changed form partials to use new base_form --- frontends/default/views/_create_form.html.erb | 39 +++--------------- .../views/_create_form_on_list.html.erb | 38 +++--------------- frontends/default/views/_update_form.html.erb | 40 +++---------------- frontends/default/views/on_create.js.rjs | 10 ++--- frontends/default/views/on_update.js.rjs | 8 ++-- 5 files changed, 24 insertions(+), 111 deletions(-) diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index 6c1adaaeda..6e502c8afa 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -1,35 +1,6 @@ -<% url_options = params_for(:action => :create) -%> -<% xhr ||= request.xhr? -%> -<%= -options = {:onsubmit => onsubmit, - :id => element_form_id(:action => :create), - :multipart => active_scaffold_config.create.multipart?, - :class => 'as_form create', - :method => :post} -if xhr && active_scaffold_config.create.multipart? # file_uploads - form_remote_upload_tag url_options.merge({:iframe => true}), - options.merge({:loading => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible';"}) -else - options[:remote] = true if xhr && !active_scaffold_config.create.multipart? - form_tag url_options, options -end -%> +<%= render :partial => "base_form", :locals => {:xhr => xhr ||= nil, + :form_action => form_action ||= :create, + :method => method ||= :post, + :cancel_link => cancel_link ||= true, + :headline => headline ||= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil)} %> - <h4><%= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil) -%></h4> - - <div id="<%= element_messages_id(:action => :create) %>" class="messages-container"> -<% if request.xhr? -%> - <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> -<% else -%> - <%= render :partial => 'form_messages' %> -<% end -%> - </div> - - <%= render :partial => 'form', :locals => { :columns => active_scaffold_config.create.columns } %> - - <p class="form-footer"> - <%= submit_tag as_(:create), :class => "submit" %> - <%= link_to as_(:cancel), main_path_to_return, :class => 'as_cancel' %> - <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> - </p> - -</form> diff --git a/frontends/default/views/_create_form_on_list.html.erb b/frontends/default/views/_create_form_on_list.html.erb index dc1dc74ea1..a87517cb23 100644 --- a/frontends/default/views/_create_form_on_list.html.erb +++ b/frontends/default/views/_create_form_on_list.html.erb @@ -1,33 +1,5 @@ -<% url_options = params_for(:action => :create) -%> -<% xhr ||= request.xhr? -%> -<%= -options = {:onsubmit => onsubmit, - :id => element_form_id(:action => :create), - :multipart => active_scaffold_config.create.multipart?, - :class => 'as_form create', - :method => :post} -if xhr && active_scaffold_config.create.multipart? # file_uploads - form_remote_upload_tag url_options.merge({:iframe => true}), - options.merge({:loading => "$('#{loading_indicator_id(:action => :create, :id => params[:id])}').style.visibility = 'visible';"}) -else - options[:remote] = true if xhr && !active_scaffold_config.create.multipart? - form_tag url_options, options -end -%> - - <h4><%= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil) -%></h4> - - <div id="<%= element_messages_id(:action => :create) %>" class="messages-container"> -<% if request.xhr? -%> - <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> -<% else -%> - <%= render :partial => 'form_messages' %> -<% end -%> - </div> - - <%= render :partial => 'form', :locals => { :columns => active_scaffold_config.create.columns } %> - - <p class="form-footer"> - <%= submit_tag as_(:create), :class => "submit" %> - <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> - </p> -</form> \ No newline at end of file +<%= render :partial => "base_form", :locals => {:xhr => xhr ||= nil, + :form_action => form_action ||= :create, + :method => method ||= :post, + :cancel_link => cancel_link ||= false, + :headline => headline ||= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil) %> \ No newline at end of file diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index 46877133a4..f699f7dcb7 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -1,35 +1,5 @@ -<% url_options = params_for(:action => :update) -%> -<% xhr ||= request.xhr? -%> -<%= -options = {:onsubmit => onsubmit, - :id => element_form_id(:action => :update), - :multipart => active_scaffold_config.update.multipart?, - :class => 'as_form update', - :method => :put} -if xhr && active_scaffold_config.update.multipart? # file_uploads - form_remote_upload_tag url_options.merge({:iframe => true}), - options.merge({:loading => "$('#{loading_indicator_id(:action => :update, :id => params[:id])}').style.visibility = 'visible';"}) -else - options[:remote] = true if xhr && !active_scaffold_config.create.multipart? - form_tag url_options, options -end -%> - - <h4><%= @record.to_label.nil? ? active_scaffold_config.update.label : as_(:update_model, :model => clean_column_value(@record.to_label)) -%></h4> - - <div id="<%= element_messages_id(:action => :update) %>" class="messages-container"> -<% if request.xhr? -%> - <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> -<% else -%> - <%= render :partial => 'form_messages' %> -<% end -%> - </div> - - <%= render :partial => 'form', :locals => { :columns => active_scaffold_config.update.columns } %> - - <p class="form-footer"> - <%= submit_tag as_(:update), :class => "submit" %> - <%= link_to as_(:cancel), main_path_to_return, :class => 'as_cancel' %> - <%= loading_indicator_tag(:action => :update, :id => params[:id]) %> - </p> - -</form> +<%= render :partial => "base_form", :locals => {:xhr => xhr ||= nil, + :form_action => form_action ||= :update, + :method => method ||= :put, + :cancel_link => cancel_link ||= true, + :headline => headline ||= @record.to_label.nil? ? active_scaffold_config.update.label : as_(:update_model, :model => clean_column_value(@record.to_label))} %> diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index efe1a0d0a3..9f72b51c38 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -1,4 +1,4 @@ -form_selector = "#{element_form_id(:action => :create)}".to_json +form_selector = "#{element_form_id(:action => :create)}" if controller.send :successful? if @insert_row @@ -10,16 +10,16 @@ if controller.send :successful? end if (active_scaffold_config.create.persistent) - page << "$(#{form_selector}).up('.as_adapter').action_link.reload();" + page << "$('#{form_selector}').up('.as_adapter').action_link.reload();" else - page << "$(#{form_selector}).up('.as_adapter').action_link.close();" + page << "$('#{form_selector}').up('.as_adapter').action_link.close();" end if (active_scaffold_config.create.edit_after_create) page << "var link = $('#{action_link_id 'edit', @record.id}');" page << "if (link) (function() { link.action_link.open() }).defer();" end else - page.replace form, :partial => 'create_form', :locals => {:xhr => true} - page[form].scroll_to + page.replace form_selector, :partial => 'create_form', :locals => {:xhr => true} + page[form_selector].scroll_to end page.replace_html active_scaffold_messages_id, :partial => 'messages' diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 2f509a1928..88054b8b89 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -1,11 +1,11 @@ -form_selector = "#{element_form_id(:action => :update)}".to_json +form_selector = "#{element_form_id(:action => :update)}" if controller.send :successful? updated_row = render :partial => 'list_record', :locals => {:record => @record} - page << "$(#{form_selector}).up('.as_adapter').action_link.close('#{escape_javascript(updated_row)}');" + page << "$('#{form_selector}').up('.as_adapter').action_link.close('#{escape_javascript(updated_row)}');" page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} else - page.replace form, :partial => 'update_form', :locals => {:xhr => true} - page[form].scroll_to + page.replace form_selector, :partial => 'update_form', :locals => {:xhr => true} + page[form_selector].scroll_to end page.replace_html active_scaffold_messages_id, :partial => 'messages' From 74cb5b147102c75de81d30a3d9eccde84b3dca50 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 2 Jun 2010 11:57:12 +0200 Subject: [PATCH 0362/2024] improved as_routing definition: resources :teams do as_routes end --- lib/active_scaffold.rb | 12 ------------ lib/extensions/routing_mapper.rb | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 lib/extensions/routing_mapper.rb diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index c9a90ff0b4..2991e7192c 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -18,18 +18,6 @@ def self.set_defaults(&block) ActiveScaffold::Config::Core.configure &block end - def self.add_routes(resource) - resource.collection do - resource.get :show_search, :edit_associated, :list, :new_existing, :render_field - resource.post :add_existing - end - resource.member do - resource.get :row, :nested, :edit_associated, :add_association, :render_field, :delete - resource.post :update_column - resource.delete :destroy_existing - end - end - def active_scaffold_config self.class.active_scaffold_config end diff --git a/lib/extensions/routing_mapper.rb b/lib/extensions/routing_mapper.rb new file mode 100644 index 0000000000..dac7349901 --- /dev/null +++ b/lib/extensions/routing_mapper.rb @@ -0,0 +1,29 @@ +module ActionDispatch + module Routing + class Mapper + module Base + def as_routes(options = {:full => false}) + collection do + get :show_search, :list, :render_field + end + member do + get :row, :nested, :render_field, :delete + post :update_column + end + as_extended_routes if options[:full] + end + + def as_extended_routes + collection do + get :edit_associated, :new_existing + post :add_existing + end + member do + get :edit_associated, :add_association + delete :destroy_existing + end + end + end + end + end +end From 1d9fff3f4ee27729a601dec45a789482ea410619 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 3 Jun 2010 10:56:08 +0200 Subject: [PATCH 0363/2024] get delete running in rails3 --- frontends/default/javascripts/active_scaffold.js | 10 ++++++++++ frontends/default/views/delete.html.erb | 2 +- lib/active_scaffold/config/delete.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 15 ++------------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 0d65c34872..41bc7876c2 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -278,12 +278,22 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ this.tag = $(a); this.url = this.tag.href; this.method = 'get'; + if(this.url.match('_method=delete')){ this.method = 'delete'; + this.tag.writeAttribute('data-method', this.method); + // action delete is special case cause in ajax world it will be destroy + } else if(this.url.match('/delete')){ + this.url = this.url.replace('/delete', ''); + this.tag.href = this.url; + this.method = 'delete'; + this.tag.writeAttribute('data-method', this.method); } else if(this.url.match('_method=post')){ this.method = 'post'; + this.tag.writeAttribute('data-method', this.method); } else if(this.url.match('_method=put')){ this.method = 'put'; + this.tag.writeAttribute('data-method', this.method); } this.target = target; this.loading_indicator = loading_indicator; diff --git a/frontends/default/views/delete.html.erb b/frontends/default/views/delete.html.erb index bccc1b2840..426c02e9e8 100644 --- a/frontends/default/views/delete.html.erb +++ b/frontends/default/views/delete.html.erb @@ -1,7 +1,7 @@ <div class="active-scaffold"> <div class="delete-view view"> <%= form_tag params_for(:action => :destroy, :id => params[:id]), { :method => :delete } %> - <h4><%= as_(:are_you_sure) -%></h4> + <h4><%= as_(:are_you_sure_to_delete, :label => @record.try(:to_label)) -%></h4> <p class="form-footer"> <%= submit_tag as_(:delete), :class => 'submit' %> diff --git a/lib/active_scaffold/config/delete.rb b/lib/active_scaffold/config/delete.rb index dd23ded460..b73c441f4f 100644 --- a/lib/active_scaffold/config/delete.rb +++ b/lib/active_scaffold/config/delete.rb @@ -14,7 +14,7 @@ def initialize(core_config) # the ActionLink for this action cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('delete', :label => :delete, :type => :member, :confirm => :are_you_sure_to_delete, :crud_type => :delete, :method => :delete, :position => false, :security_method => :delete_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('delete', :label => :delete, :type => :member, :confirm => :are_you_sure_to_delete, :crud_type => :delete, :position => false, :security_method => :delete_authorized?) # instance-level configuration # ---------------------------- diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 89906b9c60..4ef112e759 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -136,18 +136,7 @@ def render_action_link(link, url_options, record = nil, html_options = {}) html_options.reverse_merge! link.html_options.merge(:class => link.action) if link.inline? - # NOTE this is in url_options instead of html_options on purpose. the reason is that the client-side - # action link javascript needs to submit the proper method, but the normal html_options[:method] - # argument leaves no way to extract the proper method from the rendered tag. - url_options[:_method] = link.method - - #if link.method != :get and respond_to?(:protect_against_forgery?) and protect_against_forgery? - # url_options[:authenticity_token] = form_authenticity_token - #end - if link.method != :get - html_options['data-method'] = link.method - end - + url_options[:_method] = link.method if link.method != :get # robd: protect against submitting get links as forms, since this causes annoying # 'Do you wish to resubmit your form?' messages whenever you go back and forwards. elsif link.method != :get @@ -160,7 +149,7 @@ def render_action_link(link, url_options, record = nil, html_options = {}) html_options[:class] += ' as_action' if link.inline? html_options[:popup] = true if link.popup? html_options[:id] = action_link_id("#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}" + "#{url_options[:associations].to_s + '-' if url_options[:associations]}" + url_options[:action].to_s,url_options[:id] || url_options[:parent_id]) - html_options[:remote] = true unless link.page? || html_options['data-method'] + html_options[:remote] = true unless link.page? if link.dhtml_confirm? html_options[:class] += ' as_action' if !link.inline? html_options[:page_link] = 'true' if !link.inline? From 3353abbfb6d227c806e53696c49374cef2f70fb9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 3 Jun 2010 13:46:58 +0200 Subject: [PATCH 0364/2024] Bugfix: perform ajax cancel in case of javascript enabled add option to enable or disable form loading-indicator --- frontends/default/javascripts/active_scaffold.js | 6 +++--- frontends/default/views/_base_form.html.erb | 5 +++-- frontends/default/views/_list_inline_adapter.html.erb | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 41bc7876c2..b96da9d9d9 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -14,7 +14,7 @@ if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFu document.observe("dom:loaded", function() { Event.on($(document.body), 'ajax:before', 'form.as_form', function(event) { var as_form = event.findElement('form'); - if (as_form) { + if (as_form && as_form.readAttribute('data-loading') == 'true') { var loading_indicator = $(as_form.id.sub('--form', '-loading-indicator')); if (loading_indicator) loading_indicator.style.visibility = 'visible'; as_form.disable(); @@ -23,7 +23,7 @@ document.observe("dom:loaded", function() { }); Event.on($(document.body), 'ajax:complete', 'form.as_form', function(event) { var as_form = event.findElement('form'); - if (as_form) { + if (as_form && as_form.readAttribute('data-loading') == 'true') { var loading_indicator = $(as_form.id.sub('--form', '-loading-indicator')); if (loading_indicator) loading_indicator.style.visibility = 'hidden'; as_form.enable(); @@ -78,7 +78,7 @@ document.observe("dom:loaded", function() { } return true; }); - Event.on($(document.body), 'click', 'a.as_cancel', function(event) { + Event.on($(document.body), 'ajax:before', 'a.as_cancel', function(event) { var as_cancel = event.findElement('.as_adapter'); if (as_cancel.action_link) { var action_link = as_cancel.action_link; diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index e973a0b3e3..d09a5db6f9 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -6,7 +6,8 @@ options = {:onsubmit => onsubmit, :id => element_form_id(:action => form_action), :multipart => as_action_config.multipart?, :class => "as_form #{form_action.to_s}", - :method => method} + :method => method, + 'data-loading' => true} if xhr && as_action_config.multipart? # file_uploads form_remote_upload_tag url_options.merge({:iframe => true}), options.merge({:loading => "$('#{loading_indicator_id(:action => form_action, :id => params[:id])}').style.visibility = 'visible';"}) @@ -29,7 +30,7 @@ end -%> <p class="form-footer"> <%= submit_tag as_(form_action), :class => "submit" %> - <%= link_to (as_(:cancel), main_path_to_return, :class => 'as_cancel') if cancel_link %> + <%= link_to(as_(:cancel), main_path_to_return, :class => 'as_cancel', :remote => true) if cancel_link %> <%= loading_indicator_tag(:action => form_action, :id => params[:id]) %> </p> diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index abe43c4b86..c72f288a83 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -3,7 +3,7 @@ <tr class="inline-adapter" id="<%= element_row_id :action => :nested %>"> <td colspan="99" class="inline-adapter-cell"> <div class="<%= "#{params[:action]}-view" if params[:action] %> <%= "#{params[:associations] ? params[:associations] : params[:controller]}-view" %> view"> - <a href="" class="inline-adapter-close as_cancel" title="<%= as_(:close) %>"><%= as_(:close) %></a> + <%= link_to(as_(:close), '', :class => 'inline-adapter-close as_cancel', :remote => true, :title => as_(:close)) -%> <%= payload -%> </div> </td> From 1b8aba62b6a60952c22314294cf324eac7419a95 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 3 Jun 2010 16:49:57 +0200 Subject: [PATCH 0365/2024] rework cancel link management in order to support reset search link --- .../default/javascripts/active_scaffold.js | 63 ++++++++++++------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index b96da9d9d9..acde200512 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -79,11 +79,38 @@ document.observe("dom:loaded", function() { return true; }); Event.on($(document.body), 'ajax:before', 'a.as_cancel', function(event) { - var as_cancel = event.findElement('.as_adapter'); - if (as_cancel.action_link) { - var action_link = as_cancel.action_link; - action_link.close(); - event.stop(); + var as_adapter = event.findElement('.as_adapter'); + var as_cancel = event.findElement(); + + if (as_adapter.action_link) { + var action_link = as_adapter.action_link; + if (action_link.refresh_url) { + event.memo.url = action_link.refresh_url; + } else if (typeof(event.memo.url) !== 'undefined' && event.memo.url.blank()) { + action_link.close(); + event.stop(); + } + } + return true; + }); + Event.on($(document.body), 'ajax:success', 'a.as_cancel', function(event) { + var as_adapter = event.findElement('.as_adapter'); + + if (as_adapter.action_link) { + var action_link = as_adapter.action_link; + if (action_link.position) { + action_link.close(event.memo.request.responseText); + } else { + event.memo.request.evalResponse(); + } + } + return true; + }); + Event.on($(document.body), 'ajax:failure', 'a.as_cancel', function(event) { + var as_adapter = event.findElement('.as_adapter'); + if (as_adapter.action_link) { + var action_link = as_adapter.action_link; + ActiveScaffold.report_500_response(action_link.scaffold_id()); } return true; }); @@ -374,10 +401,12 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, { instantiate_link: function(link) { var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); - l.refresh_url = this.options.refresh_url; + if (this.options.refresh_url) l.refresh_url = this.options.refresh_url; + if (link.hasClassName('delete')) { l.url = l.url.replace(/\/delete(\?.*)?$/, '$1'); l.url = l.url.replace(/\/delete\/(.*)/, '/destroy/$1'); + l.tag.href = l.url; } if (l.position) { l.url = l.url.append_params({adapter: '_list_inline_adapter'}); @@ -424,25 +453,11 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra this.adapter.down('td').down().highlight(); }, - close: function($super, updatedRow) { - if (updatedRow) { - ActiveScaffold.update_row(this.target, updatedRow); - $super(); - } else { - new Ajax.Request(this.refresh_url, { - asynchronous: true, - evalScripts: true, - method: this.method, - onSuccess: function(request) { - ActiveScaffold.update_row(this.target, request.responseText); - $super(); - }.bind(this), - - onFailure: function(request) { - ActiveScaffold.report_500_response(this.scaffold_id()); - } - }); + close: function($super, refreshed_content) { + if (refreshed_content) { + ActiveScaffold.update_row(this.target, refreshed_content); } + $super(); }, enable: function() { From aa81fd4cbecd9c29253f3cf7c744e58e6d9ce293 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 3 Jun 2010 16:52:08 +0200 Subject: [PATCH 0366/2024] sanitize_sql is protected in Rails 3 --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index bf8dbef1f6..98fef4c97c 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -255,7 +255,7 @@ def merge_conditions(*conditions) segments = [] conditions.each do |condition| unless condition.blank? - sql = active_scaffold_config.model.sanitize_sql(condition) + sql = active_scaffold_config.model.send(:sanitize_sql, condition) segments << sql unless sql.blank? end end From c1806e6bc3cc699866b89d87ed0699a68116ff28 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 3 Jun 2010 16:53:06 +0200 Subject: [PATCH 0367/2024] rails 3 compatible search form --- frontends/default/views/_search.html.erb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index f62af86433..d9fc97ee8e 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -1,16 +1,14 @@ <% live_search = active_scaffold_config.search.live? -%> -<% href = url_for(params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'}) -%> -<%= form_remote_tag :url => href, - :method => :get, - :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", - :after => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'visible';#{"Form.disable('#{search_form_id}');" unless live_search }", - :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden';#{"Form.enable('#{search_form_id}');" unless live_search }", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> +<% url_options = params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'} -%> +<%= +options = {:id => search_form_id, + :class => "as_form search", + :method => :get} +options['data-loading'] = true unless live_search + form_tag url_options, options %> <%= text_field_tag :search, search_params, :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> <%= submit_tag as_(:search), :class => "submit" unless live_search %> - <%= link_to_remote as_(:reset), {:url => href, :with => "'search='", :method => :get, - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')"}, :class => 'cancel' %> + <%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel', :remote => true %> <%= loading_indicator_tag(:action => :search) %> </form> From caa6ebbdcc0c19b3fe4912a2a64f56d2b9df33c9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 4 Jun 2010 11:24:55 +0200 Subject: [PATCH 0368/2024] generate loading indicator ids with same schema as the other form ids --- lib/active_scaffold/helpers/id_helpers.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index c16c338ed1..49f0b72057 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -88,11 +88,7 @@ def association_subform_id(column) def loading_indicator_id(options = {}) options[:action] ||= params[:action] - unless options[:id] - clean_id "#{controller_id}-#{options[:action]}-loading-indicator" - else - clean_id "#{controller_id}-#{options[:action]}-#{options[:id]}-loading-indicator" - end + clean_id "#{controller_id}-#{options[:action]}-#{options[:id]}-loading-indicator" end def sub_form_id(options = {}) From 16e904e354223f9add1257ba2fca7bd736995a05 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 4 Jun 2010 11:26:06 +0200 Subject: [PATCH 0369/2024] search form should be remote --- frontends/default/views/_search.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index d9fc97ee8e..4607c5a3bb 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -3,6 +3,7 @@ <%= options = {:id => search_form_id, :class => "as_form search", + :remote => true, :method => :get} options['data-loading'] = true unless live_search form_tag url_options, options %> From 43a9c9fcb9e5323ba2f9939cbeb7409b79eca009 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 4 Jun 2010 11:26:56 +0200 Subject: [PATCH 0370/2024] use document.on syntax adapted to new rails.js --- .../default/javascripts/active_scaffold.js | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index acde200512..27178e9ceb 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -12,26 +12,26 @@ if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFu document.observe("dom:loaded", function() { - Event.on($(document.body), 'ajax:before', 'form.as_form', function(event) { + document.on('ajax:loading', 'form.as_form', function(event) { var as_form = event.findElement('form'); if (as_form && as_form.readAttribute('data-loading') == 'true') { - var loading_indicator = $(as_form.id.sub('--form', '-loading-indicator')); + var loading_indicator = $(as_form.id.sub('-form', '-loading-indicator')); if (loading_indicator) loading_indicator.style.visibility = 'visible'; as_form.disable(); } return true; }); - Event.on($(document.body), 'ajax:complete', 'form.as_form', function(event) { + document.on('ajax:complete', 'form.as_form', function(event) { var as_form = event.findElement('form'); if (as_form && as_form.readAttribute('data-loading') == 'true') { - var loading_indicator = $(as_form.id.sub('--form', '-loading-indicator')); + var loading_indicator = $(as_form.id.sub('-form', '-loading-indicator')); if (loading_indicator) loading_indicator.style.visibility = 'hidden'; as_form.enable(); event.stop(); return false; } }); - Event.on($(document.body), 'ajax:failure', 'form.as_form', function(event) { + document.on('ajax:failure', 'form.as_form', function(event) { var as_div = event.findElement('div.activescaffold'); if (as_div) { ActiveScaffold.report_500_response(as_div) @@ -39,15 +39,15 @@ document.observe("dom:loaded", function() { return false; } }); - Event.on($(document.body), 'ajax:before', 'a.as_action', function(event) { + document.on('ajax:before', 'a.as_action', function(event) { var as_action = event.findElement(); if (as_action.action_link) { - var action_link = as_action_link; + var action_link = as_action.action_link; if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'visible'; } return true; }); - Event.on($(document.body), 'ajax:success', 'a.as_action', function(event) { + document.on('ajax:success', 'a.as_action', function(event) { var as_action = event.findElement(); if (as_action.action_link && event.memo && event.memo.request) { var action_link = as_action.action_link; @@ -61,15 +61,15 @@ document.observe("dom:loaded", function() { } return true; }); - Event.on($(document.body), 'ajax:complete', 'a.as_action', function(event) { + document.on('ajax:complete', 'a.as_action', function(event) { var as_action = event.findElement(); if (as_action.action_link) { - var action_link = as_action_link; + var action_link = as_action.action_link; if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'hidden'; } return true; }); - Event.on($(document.body), 'ajax:failure', 'a.as_action', function(event) { + document.on('ajax:failure', 'a.as_action', function(event) { var as_action = event.findElement(); if (as_action.action_link) { var action_link = as_action.action_link; @@ -78,7 +78,7 @@ document.observe("dom:loaded", function() { } return true; }); - Event.on($(document.body), 'ajax:before', 'a.as_cancel', function(event) { + document.on('ajax:before', 'a.as_cancel', function(event) { var as_adapter = event.findElement('.as_adapter'); var as_cancel = event.findElement(); @@ -86,14 +86,14 @@ document.observe("dom:loaded", function() { var action_link = as_adapter.action_link; if (action_link.refresh_url) { event.memo.url = action_link.refresh_url; - } else if (typeof(event.memo.url) !== 'undefined' && event.memo.url.blank()) { + } else if (as_cancel.readAttribute('href').blank()) { action_link.close(); event.stop(); } } return true; }); - Event.on($(document.body), 'ajax:success', 'a.as_cancel', function(event) { + document.on('ajax:success', 'a.as_cancel', function(event) { var as_adapter = event.findElement('.as_adapter'); if (as_adapter.action_link) { @@ -106,7 +106,7 @@ document.observe("dom:loaded", function() { } return true; }); - Event.on($(document.body), 'ajax:failure', 'a.as_cancel', function(event) { + document.on('ajax:failure', 'a.as_cancel', function(event) { var as_adapter = event.findElement('.as_adapter'); if (as_adapter.action_link) { var action_link = as_adapter.action_link; From 3a2ffe09e3faa03664da13da47c77f8b5e488e6e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 4 Jun 2010 12:03:03 +0200 Subject: [PATCH 0371/2024] refresh_url needs to be html_safe --- frontends/default/views/_list_actions.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index e7e7279980..5b29ecdc64 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -13,13 +13,14 @@ </table> <% target_id = element_row_id(:action => :list, :id => record.id) -%> + <script type="text/javascript"> //<![CDATA[ new ActiveScaffold.Actions.Record( $$('#<%= target_id -%> a.as_action'), $('<%= target_id -%>'), $('<%= loading_indicator_id(:action => :record, :id => record.id) -%>'), - {refresh_url: '<%= url_for params_for(:action => :row, :id => record.id, :_method => :get, :escape => false) -%>'} + {refresh_url: '<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get, :escape => false)).html_safe -%>'} ); //]]> </script> From 442e9d84240eeb6807c09c430052908e92e5d7e3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 4 Jun 2010 12:03:34 +0200 Subject: [PATCH 0372/2024] blacklist iframe parameter --- lib/active_scaffold/helpers/controller_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 4b61e549af..2ff24edbb9 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -12,7 +12,7 @@ def params_for(options = {}) # :sort, :sort_direction, and :page are arguments that stored in the session. they need not propagate. # and wow. no we don't want to propagate :record. # :commit is a special rails variable for form buttons - blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token] + blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token, :iframe] unless @params_for @params_for = {} params.select { |key, value| blacklist.exclude? key.to_sym if key }.each {|key, value| @params_for[key.to_sym] = value.clone} From 17cf331e8f610a598ee514b1a609c01b058b9695 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Jun 2010 09:38:11 +0200 Subject: [PATCH 0373/2024] live_search in Rails 3 --- frontends/default/views/_search.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index 4607c5a3bb..a17609d316 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -8,7 +8,7 @@ options = {:id => search_form_id, options['data-loading'] = true unless live_search form_tag url_options, options %> <%= text_field_tag :search, search_params, :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> - <%= submit_tag as_(:search), :class => "submit" unless live_search %> + <%= submit_tag as_(:search), :class => "submit" %> <%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel', :remote => true %> <%= loading_indicator_tag(:action => :search) %> </form> @@ -17,9 +17,10 @@ options['data-loading'] = true unless live_search //<![CDATA[ new TextFieldWithExample('<%= search_input_id %>', '<%= as_(live_search ? :live_search : :search_terms) %>', {focus: true}); <% if live_search -%> + $('<%= search_input_id %>').next().hide(); new Form.Element.DelayedObserver('<%= search_input_id %>', 0.5, function(element, value) { if (!$(element.id)) return false; // because the element may have been destroyed - $(element).up('form').onsubmit(); + $(element).next().click(); }); <% end -%> //]]> From a3623a2d327715672cb0d9e33fcaf2de5e0a0233 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Jun 2010 12:05:46 +0200 Subject: [PATCH 0374/2024] field_search in Rails 3.0 --- .../default/views/_field_search.html.erb | 22 ++++++++----------- .../helpers/search_column_helpers.rb | 20 ++++++++--------- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/frontends/default/views/_field_search.html.erb b/frontends/default/views/_field_search.html.erb index ed8c588434..d6ff208a8c 100644 --- a/frontends/default/views/_field_search.html.erb +++ b/frontends/default/views/_field_search.html.erb @@ -1,13 +1,11 @@ -<% href_params = params_for(:action => :index, :escape => false, :search => nil) -%> -<% href = url_for(href_params) -%> -<%= form_remote_tag :url => href, - :method => :get, - :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", - :after => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{search_form_id}');", - :complete => "$('#{loading_indicator_id(:action => :search, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{search_form_id}');", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :html => { :action => href, :id => search_form_id, :class => 'search', :method => :get } %> - +<% url_options = params_for(:action => :index, :escape => false, :search => nil) -%> +<%= +options = {:id => search_form_id, + :class => "as_form search", + :remote => true, + :method => :get, + 'data-loading' => true} +form_tag url_options, options %> <ol class="form"> <% active_scaffold_config.field_search.columns.each do |column| -%> <% next unless column.search_sql -%> @@ -26,9 +24,7 @@ </ol> <p class="form-footer"> <%= submit_tag as_(:search), :class => "submit" %> - <% href = url_for(href_params.merge(:search => '')) -%> - <%= link_to_remote as_(:reset), {:url => href, :with => "'search='", :method => :get, - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')"}, :class => 'cancel', :href => href %> + <%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel', :remote => true %> <%= loading_indicator_tag(:action => :search) %> </p> </form> diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 066b1916be..ee4be4d4ba 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -40,7 +40,7 @@ def active_scaffold_search_for(column) # for textual fields we pass different options text_types = [:text, :string, :integer, :float, :decimal] options = active_scaffold_input_text_options(options) if text_types.include?(column.column.type) - input(:record, column.name, options.merge(column.options)) + text_field(:record, column.name, options.merge(column.options)) end end end @@ -130,16 +130,15 @@ def active_scaffold_search_range(column, options) select_options = ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} if column.column && column.column.text? - html = [] - html << select_tag("#{options[:name]}[opt]", + html = select_tag("#{options[:name]}[opt]", options_for_select(select_options, opt_value), :id => "#{options[:id]}_opt", :onchange => "Element[this.value == 'BETWEEN' ? 'show' : 'hide']('#{options[:id]}_between');") - html << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(:id => options[:id], :size => 10)) - html << content_tag(:span, ' - ' + text_field_tag("#{options[:name]}[to]", to_value, - active_scaffold_input_text_options(:id => "#{options[:id]}_to", :size => 10)), + html << ' ' << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(:id => options[:id], :size => 10)) + html << ' ' << content_tag(:span, (' - ' + text_field_tag("#{options[:name]}[to]", to_value, + active_scaffold_input_text_options(:id => "#{options[:id]}_to", :size => 10))).html_safe, :id => "#{options[:id]}_between", :style => "display:none") - html * ' ' + html end alias_method :active_scaffold_search_integer, :active_scaffold_search_range alias_method :active_scaffold_search_decimal, :active_scaffold_search_range @@ -172,10 +171,9 @@ def active_scaffold_search_datetime(column, options) opt_value, from_value, to_value = field_search_params_range_values(column) options = column.options.merge(options) helper = "select_#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}" - html = [] - html << send(helper, field_search_datetime_value(from_value), {:include_blank => true, :prefix => "#{options[:name]}[from]"}.merge(options)) - html << send(helper, field_search_datetime_value(to_value), {:include_blank => true, :prefix => "#{options[:name]}[to]"}.merge(options)) - html * ' - ' + + send(helper, field_search_datetime_value(from_value), {:include_blank => true, :prefix => "#{options[:name]}[from]"}.merge(options)) << + ' - '.html_safe << send(helper, field_search_datetime_value(to_value), {:include_blank => true, :prefix => "#{options[:name]}[to]"}.merge(options)) end def active_scaffold_search_date(column, options) From 1d0e1666ca14159cddf0d2a31ebb8eaeba75e51c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Jun 2010 12:15:14 +0200 Subject: [PATCH 0375/2024] prototype 1.7 is needed --- README | 4 ++-- frontends/default/views/._search.html.erb.marks | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 frontends/default/views/._search.html.erb.marks diff --git a/README b/README index 6d45080d54..513b2163c8 100644 --- a/README +++ b/README @@ -29,8 +29,8 @@ Rails < 2.1: Active Scaffold 1-1-stable (no guarantees) Since Rails 2.3, render_component plugin is needed for nested and embbeded scaffolds. It works with rails-2.3 branch from ewildgoose repository: script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3 -Since Rails 3.0, verification and dynamic form plugins are needed: +Since Rails 3.0, the following is needed: rails plugin install git://github.com/rails/verification.git -rails plugin install git://github.com/rails/dynamic_form.git +Prototype 1.7 Released under the MIT license (included) diff --git a/frontends/default/views/._search.html.erb.marks b/frontends/default/views/._search.html.erb.marks new file mode 100644 index 0000000000..34bc6d87e7 --- /dev/null +++ b/frontends/default/views/._search.html.erb.marks @@ -0,0 +1,2 @@ +! +;970;970 From 608787b831b351c8cfbbdebb83c5ef6835edd7e5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Jun 2010 12:16:57 +0200 Subject: [PATCH 0376/2024] add full as routes set by default --- lib/extensions/routing_mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extensions/routing_mapper.rb b/lib/extensions/routing_mapper.rb index dac7349901..3b74d9c67e 100644 --- a/lib/extensions/routing_mapper.rb +++ b/lib/extensions/routing_mapper.rb @@ -2,7 +2,7 @@ module ActionDispatch module Routing class Mapper module Base - def as_routes(options = {:full => false}) + def as_routes(options = {:full => true}) collection do get :show_search, :list, :render_field end From 76c5697645a69609bdfac459c7ed8dd77565b518 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Jun 2010 15:32:00 +0200 Subject: [PATCH 0377/2024] removed depreciation warnings for human_name --- frontends/default/views/_form_association_footer.html.erb | 2 +- frontends/default/views/_horizontal_subform.html.erb | 2 +- frontends/default/views/_vertical_subform.html.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index 8ae4912a38..122680ca85 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -17,7 +17,7 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as <div class="footer-wrapper"> <div class="footer"> <% if show_add_new -%> - <% add_label = column.plural_association? ? as_(:create_another, :model => column.association.klass.human_name) : as_(:replace_with_new) -%> + <% add_label = column.plural_association? ? as_(:create_another, :model => column.association.klass.model_name.human) : as_(:replace_with_new) -%> <%= button_to_function add_label, "new Ajax.Request(#{add_new_url.to_json}, {asynchronous: true, method: 'get', evalScripts: true, onFailure: function(){ActiveScaffold.report_500_response(#{active_scaffold_id.to_json})}})" %> <% end -%> diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index f04af620f1..e44de29494 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -8,7 +8,7 @@ <% if @record.errors.count -%> <tr class="association-record-errors"> <td colspan="<%= active_scaffold_config_for(@record.class).subform.columns.length + 1 %>" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>"> - <%= error_messages_for :record, :object_name => @record.class.human_name.downcase %> + <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> </td> </tr> <% end %> diff --git a/frontends/default/views/_vertical_subform.html.erb b/frontends/default/views/_vertical_subform.html.erb index 1d0c1d607e..e9e95f4b60 100644 --- a/frontends/default/views/_vertical_subform.html.erb +++ b/frontends/default/views/_vertical_subform.html.erb @@ -3,7 +3,7 @@ <% @record = associated[index] -%> <% if @record.errors.count -%> <div class="association-record-errors" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>"> - <%= error_messages_for :record, :object_name => @record.class.human_name.downcase %> + <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> </div> <% end %> <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => @record.new_record? && @record == associated.last} %> From c228b76be5f91102f63f975552505477d6c8ef49 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Jun 2010 16:20:45 +0200 Subject: [PATCH 0378/2024] Use nested routes for nested scaffolds (cherry picked from commit a05c258c569c77afc25f41268d09edc4eb9c5acd) Conflicts: lib/active_scaffold.rb lib/active_scaffold/helpers/list_column_helpers.rb --- lib/active_scaffold.rb | 25 +++++++++++-------- lib/active_scaffold/actions/create.rb | 13 ---------- lib/active_scaffold/actions/nested.rb | 2 ++ lib/active_scaffold/constraints.rb | 17 ++++++++----- .../helpers/list_column_helpers.rb | 18 ++++++------- 5 files changed, 34 insertions(+), 41 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 2991e7192c..c06750453d 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -108,20 +108,23 @@ def links_for_associations return unless active_scaffold_config.actions.include? :list and active_scaffold_config.actions.include? :nested active_scaffold_config.columns.each do |column| next unless column.link.nil? and column.autolink? - if column.plural_association? - # note: we can't create nested scaffolds on :through associations because there's no reverse association. - column.set_link('nested', :parameters => {:associations => column.name.to_sym}, :html_options => {:class => column.name}) #unless column.through_association? - elsif column.polymorphic_association? + if column.polymorphic_association? # note: we can't create inline forms on singular polymorphic associations column.clear_link - else - model = column.association.klass - begin - controller = active_scaffold_controller_for(model) - rescue ActiveScaffold::ControllerNotFound - next - end + next + end + model = column.association.klass + begin + controller = active_scaffold_controller_for(model) + rescue ActiveScaffold::ControllerNotFound + next + end + + if column.plural_association? + # note: we can't create nested scaffolds on :through associations because there's no reverse association. + column.set_link('list', :controller => controller.controller_path) #unless column.through_association? + else actions = controller.active_scaffold_config.actions column.actions_for_association_links.delete :new unless actions.include? :create column.actions_for_association_links.delete :edit unless actions.include? :update diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 0ac9fecba8..9017762fdf 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -2,7 +2,6 @@ module ActiveScaffold::Actions module Create def self.included(base) base.before_filter :create_authorized_filter, :only => [:new, :create] - base.prepend_before_filter :constraints_for_nested_create, :only => [:new, :create] base.verify :method => :post, :only => :create, :redirect_to => { :action => :index } @@ -78,22 +77,11 @@ def create_respond_to_yaml render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.create.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status, :location => response_location end - def constraints_for_nested_create - if params[:parent_column] && params[:parent_id] - @old_eid = params[:eid] - @remove_eid = true - constraints = {params[:parent_column].to_sym => params[:parent_id]} - params[:eid] = Digest::MD5.hexdigest(params[:parent_controller] + params[:controller].to_s + constraints.to_s) - session["as:#{params[:eid]}"] = {:constraints => constraints} - end - end - # A simple method to find and prepare an example new record for the form # May be overridden to customize the behavior (add default values, for instance) def do_new @record = new_model apply_constraints_to_record(@record) - params[:eid] = @old_eid if @remove_eid @record end @@ -104,7 +92,6 @@ def do_create active_scaffold_config.model.transaction do @record = update_record_from_params(new_model, active_scaffold_config.create.columns, params[:record]) apply_constraints_to_record(@record, :allow_autosave => true) - params[:eid] = @old_eid if @remove_eid before_create_save(@record) self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit if successful? diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index f4d416c806..dd8142b953 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -5,6 +5,8 @@ module Nested def self.included(base) super base.module_eval do + before_filter :set_active_scaffold_constraints + before_filter :register_constraints_with_action_columns include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? {|a| a.macro == :has_and_belongs_to_many} end base.before_filter :include_habtm_actions diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 4dbf864852..0bd7d12443 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -1,16 +1,21 @@ module ActiveScaffold module Constraints - def self.included(base) - base.module_eval do - before_filter :register_constraints_with_action_columns - end - end protected # Returns the current constraints def active_scaffold_constraints - return active_scaffold_session_storage[:constraints] || {} + @active_scaffold_constraints ||= active_scaffold_session_storage[:constraints] || {} + end + + def set_active_scaffold_constraints + associations_by_params = {} + active_scaffold_config.model.reflect_on_all_associations.each do |association| + associations_by_params[association.klass.name.foreign_key] = association.name unless association.options[:polymorphic] + end + params.each do |key, value| + active_scaffold_constraints[associations_by_params[key]] = value if associations_by_params.include? key + end end # For each enabled action, adds the constrained columns to the ActionColumns object (if it exists). diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index c6f5772007..2dc2b6a796 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -39,20 +39,16 @@ def render_list_column(text, column, record) link = column.link associated = record.send(column.association.name) if column.association url_options = params_for(:action => nil, :id => record.id, :link => text) - url_options[:parent_controller] = params[:controller] if link.controller and link.controller.to_s != params[:controller] - url_options[:id] = associated.id if associated and link.controller and link.controller.to_s != params[:controller] + if column.association and link.controller.to_s != params[:controller] + url_options[record.class.name.foreign_key.to_sym] = url_options.delete(:id) + url_options[:id] = associated.id if associated and column.singular_association? + end # setup automatic link - if column.autolink? # link to nested scaffold or inline form - link = action_link_to_inline_form(column, associated) if link.crud_type.nil? # automatic link to inline form (singular association) + if column.autolink? && column.singular_association? # link to inline form + link = action_link_to_inline_form(column, associated) return text if link.crud_type.nil? - if link.crud_type == :create - url_options[:link] = as_(:create_new) - url_options[:parent_id] = record.id - url_options[:parent_column] = column.association.reverse - url_options[:parent_model] = record.class.name # needed for polymorphic associations - url_options.delete :id - end + url_options[:link] = as_(:create_new) if link.crud_type == :create end # check authorization From 6cb22458342ebd4ca62f44689f8f610f6756a40a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Jun 2010 16:23:32 +0200 Subject: [PATCH 0379/2024] do not call page_update if adapter param is specified --- lib/active_scaffold/actions/list.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 10e8d340eb..fcb91dd055 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -30,7 +30,11 @@ def list_respond_to_html render :action => 'list' end def list_respond_to_js - render :action => 'list.js' + if params[:adapter] + render(:partial => 'list', :layout => false) + else + render :action => 'list.js' + end end def list_respond_to_xml render :xml => response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status From f07fbbf158c010151ea4446ecdc744f1b8e3d5dc Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 8 Jun 2010 11:30:09 +0200 Subject: [PATCH 0380/2024] Bugfix: set parent_controller param for nested action_links with a different controller --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 2dc2b6a796..4bca15d699 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -39,9 +39,11 @@ def render_list_column(text, column, record) link = column.link associated = record.send(column.association.name) if column.association url_options = params_for(:action => nil, :id => record.id, :link => text) + if column.association and link.controller.to_s != params[:controller] url_options[record.class.name.foreign_key.to_sym] = url_options.delete(:id) url_options[:id] = associated.id if associated and column.singular_association? + url_options[:parent_controller] = params[:controller] end # setup automatic link From a88bc709e350bf5acaa819e5e762368c66d717e0 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 8 Jun 2010 11:31:23 +0200 Subject: [PATCH 0381/2024] disable action_link after click --- frontends/default/javascripts/active_scaffold.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 27178e9ceb..5fffa632ae 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -43,7 +43,8 @@ document.observe("dom:loaded", function() { var as_action = event.findElement(); if (as_action.action_link) { var action_link = as_action.action_link; - if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'visible'; + if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'visible'; + if (action_link.position) action_link.disable(); } return true; }); From 98874355cc85e01f396f977d995797c8c4ee6f44 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 8 Jun 2010 12:01:39 +0200 Subject: [PATCH 0382/2024] remove onclick handling for action_links --- .../default/javascripts/active_scaffold.js | 33 ++++--------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 5fffa632ae..0f8f6c6b19 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -43,8 +43,12 @@ document.observe("dom:loaded", function() { var as_action = event.findElement(); if (as_action.action_link) { var action_link = as_action.action_link; - if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'visible'; - if (action_link.position) action_link.disable(); + if (action_link.is_disabled()) { + event.stop(); + } else { + if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'visible'; + if (action_link.position) action_link.disable(); + } } return true; }); @@ -327,34 +331,11 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ this.loading_indicator = loading_indicator; this.hide_target = false; this.position = this.tag.getAttribute('data-position'); - var ajax_link = this.tag.getAttribute('data-remote'); - - if (ajax_link == 'true') { - this.onclick = this.tag.onclick; - this.tag.onclick = null; - this.tag.observe('click', function(event) { - this.open(event); - }.bind(this)); - } - + this.tag.action_link = this; }, open: function(event) { - if (this.is_disabled()) { - if (event) Event.stop(event); - return; - } - -/* - if (this.tag.hasAttribute( "data-confirm")) { - if (this.onclick) this.onclick(); - return; - } else { - if (this.onclick && !this.onclick()) return;//e.g. confirmation messages - this.open_action(); - } -*/ }, insert: function(content) { From cff838af1499e1b34a75ae022be5b3ca27043d86 Mon Sep 17 00:00:00 2001 From: Luke Wendling <luke@lukewendling.com> Date: Mon, 7 Jun 2010 17:07:39 -0500 Subject: [PATCH 0383/2024] add update config option to allow for specifying that a form should stay open after successful update (cherry picked from commit 3a7b28cd9fc9189ebf31a1fc70671ba2124d3cf4) --- frontends/default/views/_update_form.html.erb | 2 +- frontends/default/views/on_update.js.rjs | 6 +++++- lib/active_scaffold/config/update.rb | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index ba248a142d..04bdb6009f 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -46,7 +46,7 @@ end <p class="form-footer"> <%= submit_tag as_(:update), :class => "submit" %> - <%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %> + <%= link_to as_(:close), main_path_to_return, :class => 'cancel' %> <%= loading_indicator_tag(:action => :update, :id => params[:id]) %> </p> diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index f162265b51..d27e049d9f 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -3,7 +3,11 @@ cancel_selector = "##{form} a.cancel".to_json if controller.send :successful? updated_row = render :partial => 'list_record', :locals => {:record => @record} - page << "$$(#{cancel_selector}).first().link.close('#{escape_javascript(updated_row)}');" + if active_scaffold_config.update.persistent + flash.now[:info] = 'Update Succeeded!' + else + page << "$$(#{cancel_selector}).first().link.close('#{escape_javascript(updated_row)}');" + end page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} else page << "var l = $$(#{cancel_selector}).first().link;" diff --git a/lib/active_scaffold/config/update.rb b/lib/active_scaffold/config/update.rb index aa40806f48..8e867f0f17 100644 --- a/lib/active_scaffold/config/update.rb +++ b/lib/active_scaffold/config/update.rb @@ -4,6 +4,7 @@ class Update < ActiveScaffold::Config::Form def initialize(*args) super self.nested_links = self.class.nested_links + self.persistent = self.class.persistent end # global level configuration @@ -17,6 +18,10 @@ def self.link=(val) end @@link = ActiveScaffold::DataStructures::ActionLink.new('edit', :label => :edit, :type => :member, :security_method => :update_authorized?) + # whether the form stays open after an update or not + cattr_accessor :persistent + @@persistent = false + # instance-level configuration # ---------------------------- @@ -28,5 +33,8 @@ def label attr_accessor :nested_links cattr_accessor :nested_links @@nested_links = false + + # whether the form stays open after an update or not + attr_accessor :persistent end end From 3b6c4c6942fa961004383a37399f223272dfb666 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 8 Jun 2010 17:57:47 +0200 Subject: [PATCH 0384/2024] Don't render partial if it won't be displayed --- frontends/default/views/_update_form.html.erb | 2 +- frontends/default/views/on_update.js.rjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index 04bdb6009f..ba248a142d 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -46,7 +46,7 @@ end <p class="form-footer"> <%= submit_tag as_(:update), :class => "submit" %> - <%= link_to as_(:close), main_path_to_return, :class => 'cancel' %> + <%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %> <%= loading_indicator_tag(:action => :update, :id => params[:id]) %> </p> diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index d27e049d9f..b8b42ae92b 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -2,10 +2,10 @@ form = element_form_id(:action => :update) cancel_selector = "##{form} a.cancel".to_json if controller.send :successful? - updated_row = render :partial => 'list_record', :locals => {:record => @record} if active_scaffold_config.update.persistent flash.now[:info] = 'Update Succeeded!' else + updated_row = render :partial => 'list_record', :locals => {:record => @record} page << "$$(#{cancel_selector}).first().link.close('#{escape_javascript(updated_row)}');" end page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} From ba1f5f26c4d969b6ece6ac6b97129ea0cc1b3168 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 9 Jun 2010 11:29:45 +0200 Subject: [PATCH 0385/2024] nested action_links without render_component method signature has changed!! conf.nested.add_link(<attribute>[, options]) its not possible to add two associations to a nested link anymore --- lib/active_scaffold.rb | 28 +++++++++++-------- lib/active_scaffold/config/nested.rb | 13 +++++---- .../data_structures/action_link.rb | 4 +++ .../helpers/list_column_helpers.rb | 15 ++++++---- lib/active_scaffold/helpers/view_helpers.rb | 1 + 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index c06750453d..5ba2013bd7 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -113,24 +113,30 @@ def links_for_associations column.clear_link next end - - model = column.association.klass - begin - controller = active_scaffold_controller_for(model) - rescue ActiveScaffold::ControllerNotFound - next - end - + action_link = link_for_association(column) + column.set_link(action_link) unless action_link.nil? + end + end + + def link_for_association(column, options = {}) + begin + controller = active_scaffold_controller_for(column.association.klass) + rescue ActiveScaffold::ControllerNotFound + controller = nil + end + + unless controller.nil? + options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => controller.controller_path if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. - column.set_link('list', :controller => controller.controller_path) #unless column.through_association? + ActiveScaffold::DataStructures::ActionLink.new('list', options) #unless column.through_association? else actions = controller.active_scaffold_config.actions column.actions_for_association_links.delete :new unless actions.include? :create column.actions_for_association_links.delete :edit unless actions.include? :update column.actions_for_association_links.delete :show unless actions.include? :show - column.set_link(:none, :controller => controller.controller_path, :crud_type => nil, :html_options => {:class => column.name}) - end + ActiveScaffold::DataStructures::ActionLink.new(:none, options.merge({:crud_type => nil, :html_options => {:class => column.name}})) + end end end diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index fdcec851e9..3c170c0636 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -17,12 +17,13 @@ def initialize(core_config) attr_accessor :shallow_delete # Add a nested ActionLink - def add_link(label, models, options = {}) - options.reverse_merge! :security_method => :nested_authorized?, :position => :after - options.merge! :label => label, :type => :member, :parameters => {:associations => models.join(' ')} - options[:html_options] ||= {} - options[:html_options][:class] = [options[:html_options][:class], models.join(' ')].compact.join(' ') - @core.action_links.add('nested', options) + def add_link(attribute, options = {}) + column = @core.columns[attribute.to_sym] + unless column.nil? || column.association.nil? + options.reverse_merge! :security_method => :nested_authorized?, :column => column, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) + action_link = @core.link_for_association(column, options) + @core.action_links.add(action_link) unless action_link.nil? + end end # the label for this Nested action. used for the header. diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 15c91efcb0..31444f1b91 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -15,6 +15,7 @@ def initialize(action, options = {}) self.crud_type ||= :read self.parameters = {} self.html_options = {} + self.column = nil # apply quick properties options.each_pair do |k, v| @@ -138,5 +139,8 @@ def position # html options for the link attr_accessor :html_options + + # nested action_links are referencing a column + attr_accessor :column end end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 4bca15d699..9e38cd8f51 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -39,12 +39,7 @@ def render_list_column(text, column, record) link = column.link associated = record.send(column.association.name) if column.association url_options = params_for(:action => nil, :id => record.id, :link => text) - - if column.association and link.controller.to_s != params[:controller] - url_options[record.class.name.foreign_key.to_sym] = url_options.delete(:id) - url_options[:id] = associated.id if associated and column.singular_association? - url_options[:parent_controller] = params[:controller] - end + url_options_for_nested_link(column, record, link, url_options) # setup automatic link if column.autolink? && column.singular_association? # link to inline form @@ -74,6 +69,14 @@ def render_list_column(text, column, record) text end end + + def url_options_for_nested_link(column, record, link, url_options) + if column.association and link.controller.to_s != params[:controller] + url_options[record.class.name.foreign_key.to_sym] = url_options.delete(:id) + url_options[:id] = record.send(column.association.name) if column.singular_association? + url_options[:parent_controller] = params[:controller] + end + end # setup the action link to inline form def action_link_to_inline_form(column, associated) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 4ef112e759..3a4c4afa54 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -133,6 +133,7 @@ def render_action_link(link, url_options, record = nil, html_options = {}) url_options[:controller] = link.controller if link.controller url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller] url_options.merge! link.parameters if link.parameters + url_options_for_nested_link(link.column, record, link, url_options) unless link.column.nil? html_options.reverse_merge! link.html_options.merge(:class => link.action) if link.inline? From c1bce8e8adbcd8f4fb8b8a7e916f5d2ad51f2942 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 9 Jun 2010 11:55:03 +0200 Subject: [PATCH 0386/2024] Bugfix: nested_action_links html ids were not unique --- lib/active_scaffold/helpers/view_helpers.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 3a4c4afa54..e946272fc6 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -129,6 +129,7 @@ def skip_action_link(link) def render_action_link(link, url_options, record = nil, html_options = {}) url_options = url_options.clone + id = url_options[:id] || url_options[:parent_id] url_options[:action] = link.action url_options[:controller] = link.controller if link.controller url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller] @@ -149,13 +150,13 @@ def render_action_link(link, url_options, record = nil, html_options = {}) html_options['data-position'] = link.position if link.position and link.inline? html_options[:class] += ' as_action' if link.inline? html_options[:popup] = true if link.popup? - html_options[:id] = action_link_id("#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}" + "#{url_options[:associations].to_s + '-' if url_options[:associations]}" + url_options[:action].to_s,url_options[:id] || url_options[:parent_id]) + html_options[:id] = action_link_id("#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}" + url_options[:action].to_s, id) html_options[:remote] = true unless link.page? if link.dhtml_confirm? html_options[:class] += ' as_action' if !link.inline? html_options[:page_link] = 'true' if !link.inline? html_options[:dhtml_confirm] = link.dhtml_confirm.value - html_options[:onclick] = link.dhtml_confirm.onclick_function(controller,action_link_id(url_options[:action],url_options[:id] || url_options[:parent_id])) + html_options[:onclick] = link.dhtml_confirm.onclick_function(controller,action_link_id(url_options[:action],id)) end html_options[:class] += " #{link.html_options[:class]}" unless link.html_options[:class].blank? From 159cd207152da50422993912fd6898ec180bd2a3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 9 Jun 2010 13:29:46 +0200 Subject: [PATCH 0387/2024] next try to get unique action_link ids Warning: in case you define nested list link for column and as a explicit nested link you will still see double html ids --- lib/active_scaffold.rb | 2 +- lib/active_scaffold/config/nested.rb | 2 +- lib/active_scaffold/helpers/list_column_helpers.rb | 9 --------- lib/active_scaffold/helpers/view_helpers.rb | 8 ++++++++ 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 5ba2013bd7..58fdba9157 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -126,7 +126,7 @@ def link_for_association(column, options = {}) end unless controller.nil? - options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => controller.controller_path + options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => controller.controller_path, :column => column if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. ActiveScaffold::DataStructures::ActionLink.new('list', options) #unless column.through_association? diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index 3c170c0636..6d44a79a05 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -20,7 +20,7 @@ def initialize(core_config) def add_link(attribute, options = {}) column = @core.columns[attribute.to_sym] unless column.nil? || column.association.nil? - options.reverse_merge! :security_method => :nested_authorized?, :column => column, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) + options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) action_link = @core.link_for_association(column, options) @core.action_links.add(action_link) unless action_link.nil? end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 9e38cd8f51..f03daf787e 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -39,7 +39,6 @@ def render_list_column(text, column, record) link = column.link associated = record.send(column.association.name) if column.association url_options = params_for(:action => nil, :id => record.id, :link => text) - url_options_for_nested_link(column, record, link, url_options) # setup automatic link if column.autolink? && column.singular_association? # link to inline form @@ -70,14 +69,6 @@ def render_list_column(text, column, record) end end - def url_options_for_nested_link(column, record, link, url_options) - if column.association and link.controller.to_s != params[:controller] - url_options[record.class.name.foreign_key.to_sym] = url_options.delete(:id) - url_options[:id] = record.send(column.association.name) if column.singular_association? - url_options[:parent_controller] = params[:controller] - end - end - # setup the action link to inline form def action_link_to_inline_form(column, associated) link = column.link.clone diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index e946272fc6..a439cb6886 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -164,6 +164,14 @@ def render_action_link(link, url_options, record = nil, html_options = {}) label = url_options.delete(:link) || link.label link_to label, url_options, html_options end + + def url_options_for_nested_link(column, record, link, url_options) + if column.association and link.controller.to_s != params[:controller] + url_options[record.class.name.foreign_key.to_sym] = url_options.delete(:id) + url_options[:id] = record.send(column.association.name) if column.singular_association? + url_options[:parent_controller] = params[:controller] + end + end def column_class(column, column_value) classes = [] From 979eef7e6a77a427fa203544e942e88b68e0c647 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 9 Jun 2010 13:58:52 +0200 Subject: [PATCH 0388/2024] use eid param instead of parent_controller param for nested_links to get unique controller ids --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index a439cb6886..6416e3f716 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -169,7 +169,7 @@ def url_options_for_nested_link(column, record, link, url_options) if column.association and link.controller.to_s != params[:controller] url_options[record.class.name.foreign_key.to_sym] = url_options.delete(:id) url_options[:id] = record.send(column.association.name) if column.singular_association? - url_options[:parent_controller] = params[:controller] + url_options[:eid] = "#{params[:controller]}_#{ActiveSupport::SecureRandom.base64(10)}" end end From bfa996831938dcf1a1b0273f9bd708788eddc144 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 10 Jun 2010 08:11:43 +0200 Subject: [PATCH 0389/2024] that file should never been repository --- frontends/default/views/._search.html.erb.marks | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 frontends/default/views/._search.html.erb.marks diff --git a/frontends/default/views/._search.html.erb.marks b/frontends/default/views/._search.html.erb.marks deleted file mode 100644 index 34bc6d87e7..0000000000 --- a/frontends/default/views/._search.html.erb.marks +++ /dev/null @@ -1,2 +0,0 @@ -! -;970;970 From 6ec4f4b34d7c4c076dd9fd630db216a4b59dba89 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 10 Jun 2010 08:14:28 +0200 Subject: [PATCH 0390/2024] make render_component(no Rails 3 Version so far) optional for embedded controllers. They will be retrieved by ajax calls --- .../default/views/_list_with_header.html.erb | 48 ++++++++++++++++++ frontends/default/views/list.html.erb | 49 +------------------ lib/active_scaffold/actions/list.rb | 3 ++ lib/extensions/action_view_rendering.rb | 10 ++-- 4 files changed, 59 insertions(+), 51 deletions(-) create mode 100644 frontends/default/views/_list_with_header.html.erb diff --git a/frontends/default/views/_list_with_header.html.erb b/frontends/default/views/_list_with_header.html.erb new file mode 100644 index 0000000000..9f473a29ff --- /dev/null +++ b/frontends/default/views/_list_with_header.html.erb @@ -0,0 +1,48 @@ +<div id="<%= active_scaffold_id -%>" class="active-scaffold active-scaffold-<%= controller_id %> <%= "#{params[:controller]}-view" %> <%= active_scaffold_config.theme %>-theme"> + <div class="active-scaffold-header"> + <%= render :partial => 'list_header' %> + </div> + <table cellpadding="0" cellspacing="0"> + <tbody class="before-header" id="<%= before_header_id -%>"> + <% if active_scaffold_config.list.always_show_search %> + <tr> + <td> + <div class="active-scaffold show_search-view <%= "#{params[:controller]}-view" %> view"> + <%= render :partial => active_scaffold_config.list.search_partial %> + </div> + </td> + </tr> + <% else %> + <tr><td></td></tr> + <% end %> + <% if params[:nested].nil? && active_scaffold_config.list.always_show_create %> + <tr> + <td> + <div class="active-scaffold create-view <%= "#{params[:controller]}-view" %> view"> + <%= render :partial => 'create_form_on_list' %> + </div> + </td> + </tr> + <% end %> + </tbody> + </table> + <div id="<%= active_scaffold_content_id -%>"> + <%= render :partial => 'list' %> + </div> +</div> + +<script type="text/javascript"> +//<![CDATA[ +<% if active_scaffold_config.theme != :default -%> +Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-header').first(), {color: 'fromElement', bgColor: 'fromParent', corners: 'top', compact: true}); +Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-footer').first(), {color: 'fromElement', bgColor: 'fromParent', corners: 'bottom', compact: true}); +<% end -%> +new ActiveScaffold.Actions.Table($$('#<%= active_scaffold_id -%> div.active-scaffold-header a.as_action'), $('<%= before_header_id -%>'), $('<%= loading_indicator_id(:action => :table) -%>')); +ActiveScaffold.server_error_response = '<p class="error-message message">' + + <%= as_(:internal_error).to_json.html_safe %> + + '<a href="#" onclick="Element.remove(this.parentNode); return false;">' + + <%= as_(:close).to_json.html_safe %> + + '</a>' + + '</p>'; +//]]> +</script> diff --git a/frontends/default/views/list.html.erb b/frontends/default/views/list.html.erb index 9f473a29ff..8f51a58140 100644 --- a/frontends/default/views/list.html.erb +++ b/frontends/default/views/list.html.erb @@ -1,48 +1 @@ -<div id="<%= active_scaffold_id -%>" class="active-scaffold active-scaffold-<%= controller_id %> <%= "#{params[:controller]}-view" %> <%= active_scaffold_config.theme %>-theme"> - <div class="active-scaffold-header"> - <%= render :partial => 'list_header' %> - </div> - <table cellpadding="0" cellspacing="0"> - <tbody class="before-header" id="<%= before_header_id -%>"> - <% if active_scaffold_config.list.always_show_search %> - <tr> - <td> - <div class="active-scaffold show_search-view <%= "#{params[:controller]}-view" %> view"> - <%= render :partial => active_scaffold_config.list.search_partial %> - </div> - </td> - </tr> - <% else %> - <tr><td></td></tr> - <% end %> - <% if params[:nested].nil? && active_scaffold_config.list.always_show_create %> - <tr> - <td> - <div class="active-scaffold create-view <%= "#{params[:controller]}-view" %> view"> - <%= render :partial => 'create_form_on_list' %> - </div> - </td> - </tr> - <% end %> - </tbody> - </table> - <div id="<%= active_scaffold_content_id -%>"> - <%= render :partial => 'list' %> - </div> -</div> - -<script type="text/javascript"> -//<![CDATA[ -<% if active_scaffold_config.theme != :default -%> -Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-header').first(), {color: 'fromElement', bgColor: 'fromParent', corners: 'top', compact: true}); -Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-footer').first(), {color: 'fromElement', bgColor: 'fromParent', corners: 'bottom', compact: true}); -<% end -%> -new ActiveScaffold.Actions.Table($$('#<%= active_scaffold_id -%> div.active-scaffold-header a.as_action'), $('<%= before_header_id -%>'), $('<%= loading_indicator_id(:action => :table) -%>')); -ActiveScaffold.server_error_response = '<p class="error-message message">' - + <%= as_(:internal_error).to_json.html_safe %> - + '<a href="#" onclick="Element.remove(this.parentNode); return false;">' - + <%= as_(:close).to_json.html_safe %> - + '</a>' - + '</p>'; -//]]> -</script> +<%= render :partial => 'list_with_header' -%> diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index fcb91dd055..16745a617c 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -32,6 +32,9 @@ def list_respond_to_html def list_respond_to_js if params[:adapter] render(:partial => 'list', :layout => false) + elsif params[:embedded] + params.delete(:embedded) + render(:partial => 'list_with_header') else render :action => 'list.js' end diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index ad56ad2847..5ef216f150 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -53,9 +53,13 @@ def render_with_active_scaffold(*args, &block) eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s) session["as:#{eid}"] = {:constraints => constraints, :conditions => conditions, :list => {:label => args.first[:label]}} options[:params] ||= {} - options[:params].merge! :eid => eid - - render_component :controller => remote_controller.to_s, :action => 'table', :params => options[:params] + options[:params].merge! :eid => eid, :embedded => true + + id = "as_#{eid}-content" + url = url_for({:controller => remote_controller.to_s, :action => 'list'}.merge(options[:params])) + link_to(remote_controller.to_s, url, {:remote => true, :id => id}) << + javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get'})") + #render_component :controller => remote_controller.to_s, :action => 'table', :params => options[:params] else render_without_active_scaffold(*args, &block) end From 28a70e3d8920aa645dc440f8c45fe9fa5797efe3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 10 Jun 2010 08:27:46 +0200 Subject: [PATCH 0391/2024] render_component is nt needed anymore --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index 513b2163c8..82c7ffb52d 100644 --- a/README +++ b/README @@ -29,8 +29,11 @@ Rails < 2.1: Active Scaffold 1-1-stable (no guarantees) Since Rails 2.3, render_component plugin is needed for nested and embbeded scaffolds. It works with rails-2.3 branch from ewildgoose repository: script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3 +Since Rails 3.0 render_component is nt needed anymore + Since Rails 3.0, the following is needed: rails plugin install git://github.com/rails/verification.git Prototype 1.7 +rails.js in git://github.com/vhochstein/prototype-ujs.git Released under the MIT license (included) From bd069a3eb2f330b9b42eee220329f6aed5006d5f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 10 Jun 2010 08:39:26 +0200 Subject: [PATCH 0392/2024] be more restful (do not use list action anymore) --- lib/active_scaffold.rb | 2 +- lib/extensions/action_view_rendering.rb | 2 +- lib/extensions/routing_mapper.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 58fdba9157..6102ac0a2d 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -129,7 +129,7 @@ def link_for_association(column, options = {}) options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => controller.controller_path, :column => column if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. - ActiveScaffold::DataStructures::ActionLink.new('list', options) #unless column.through_association? + ActiveScaffold::DataStructures::ActionLink.new('index', options) #unless column.through_association? else actions = controller.active_scaffold_config.actions column.actions_for_association_links.delete :new unless actions.include? :create diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index 5ef216f150..17df713107 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -56,7 +56,7 @@ def render_with_active_scaffold(*args, &block) options[:params].merge! :eid => eid, :embedded => true id = "as_#{eid}-content" - url = url_for({:controller => remote_controller.to_s, :action => 'list'}.merge(options[:params])) + url = url_for({:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params])) link_to(remote_controller.to_s, url, {:remote => true, :id => id}) << javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get'})") #render_component :controller => remote_controller.to_s, :action => 'table', :params => options[:params] diff --git a/lib/extensions/routing_mapper.rb b/lib/extensions/routing_mapper.rb index 3b74d9c67e..f63a0dd103 100644 --- a/lib/extensions/routing_mapper.rb +++ b/lib/extensions/routing_mapper.rb @@ -4,7 +4,7 @@ class Mapper module Base def as_routes(options = {:full => true}) collection do - get :show_search, :list, :render_field + get :show_search, :render_field end member do get :row, :nested, :render_field, :delete From 068f32c8e6ed5da54ba35c933bf162f27a1c48e2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 10 Jun 2010 09:18:17 +0200 Subject: [PATCH 0393/2024] update to Rails 3.0 --- .../default/views/_add_existing_form.html.erb | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/frontends/default/views/_add_existing_form.html.erb b/frontends/default/views/_add_existing_form.html.erb index 41e4b3ff74..e11969b4a7 100644 --- a/frontends/default/views/_add_existing_form.html.erb +++ b/frontends/default/views/_add_existing_form.html.erb @@ -1,21 +1,18 @@ <% url_options = params_for(:action => :add_existing) -%> -<% if request.xhr? -%> -<%= form_remote_tag :url => url_options, - :after => "$('#{loading_indicator_id(:action => :add_existing, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => :add_existing)}');", - :complete => "$('#{loading_indicator_id(:action => :add_existing, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => :add_existing)}');", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :html => { :href => url_for(url_options), - :id => element_form_id(:action => :add_existing), - :class => 'create' } %> -<% else -%> -<%= form_tag url_options, - :id => element_form_id(:action => :add_existing), - :class => 'create' %> -<% end -%> +<% xhr = request.xhr? -%> +<% as_action_config = active_scaffold_config.send(:add_existing) -%> +<%= +options = {:id => element_form_id(:action => :add_existing), + :class => "as_form create", + :method => :post, + 'data-loading' => true} + options[:remote] = true if xhr + form_tag url_options, options +end -%> <h4><%= active_scaffold_config.nested.label -%></h4> - <% if request.xhr? -%> + <% if xhr -%> <div id="<%= element_messages_id(:action => :add_existing) %>" class="messages-container"></div> <% else -%> <%= render :partial => 'form_messages' %> @@ -26,7 +23,7 @@ <p class="form-footer"> <%= submit_tag as_(:add), :class => "submit" %> - <%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %> + <%= link_to as_(:cancel), main_path_to_return, :class => 'as_cancel', :remote => true %> <%= loading_indicator_tag(:action => :add_existing, :id => params[:id]) %> </p> From 7bcdbbed371b21658a8b2230edea363effbeeff3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 10 Jun 2010 09:18:53 +0200 Subject: [PATCH 0394/2024] Bugfix: use html_safe to display options in existing records select box --- frontends/default/views/_form_association_footer.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index 122680ca85..761e1cd485 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -28,7 +28,7 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "new Ajax.Request(#{edit_associated_url.to_json}.sub('--ID--', id), {asynchronous: true, evalScripts: true, onFailure: function(){ActiveScaffold.report_500_response(#{active_scaffold_id.to_json})}});" -%> <% else -%> <% select_options = options_for_select(options_for_association(column.association)) -%> - <%= select_tag 'associated_id', '<option value="">' + as_(:_select_) + '</option>' + select_options %> + <%= select_tag 'associated_id', '<option value="">'.html_safe + as_(:_select_) + '</option>'.html_safe + select_options %> <%= button_to_function as_(:add_existing), "new Ajax.Request(#{edit_associated_url.to_json}.sub('--ID--', Element.previous(this).value), {asynchronous: true, method: 'get', evalScripts: true, onFailure: function(){ActiveScaffold.report_500_response(#{active_scaffold_id.to_json})}})" %> <% end -%> <% end -%> From f889f39c8a4bec48666b819be0a5b6bed9069cf1 Mon Sep 17 00:00:00 2001 From: Laurence Colombet <Laurence.Colombet@fidesfit.com> Date: Tue, 8 Jun 2010 13:44:42 +0200 Subject: [PATCH 0395/2024] Untainting and escaping --- frontends/default/views/_list_actions.html.erb | 2 +- frontends/default/views/list.html.erb | 6 +++--- frontends/default/views/search.html.erb | 4 ++-- lib/active_scaffold/data_structures/sorting.rb | 2 +- lib/active_scaffold/helpers/id_helpers.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 4 ++++ 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 08736260a0..554c351cfe 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -19,7 +19,7 @@ new ActiveScaffold.Actions.Record( $$('#<%= target_id -%> a.action'), $('<%= target_id -%>'), $('<%= loading_indicator_id(:action => :record, :id => record.id) -%>'), - {refresh_url: '<%= url_for params_for(:action => :row, :id => record.id, :_method => :get, :escape => false) -%>'} + {refresh_url: '<%= url_for params_for(:action => :row, :id => record.id, :_method => :get, :escape => true) -%>'} ); //]]> </script> diff --git a/frontends/default/views/list.html.erb b/frontends/default/views/list.html.erb index 4edbcbad44..5fe5dfaed8 100644 --- a/frontends/default/views/list.html.erb +++ b/frontends/default/views/list.html.erb @@ -1,4 +1,4 @@ -<div id="<%= active_scaffold_id -%>" class="active-scaffold active-scaffold-<%= controller_id %> <%= "#{params[:controller]}-view" %> <%= active_scaffold_config.theme %>-theme"> +<div id="<%= active_scaffold_id -%>" class="active-scaffold active-scaffold-<%= controller_id %> <%= controller_class %> <%= active_scaffold_config.theme %>-theme"> <div class="active-scaffold-header"> <%= render :partial => 'list_header' %> </div> @@ -7,7 +7,7 @@ <% if active_scaffold_config.list.always_show_search %> <tr> <td> - <div class="active-scaffold show_search-view <%= "#{params[:controller]}-view" %> view"> + <div class="active-scaffold show_search-view <%= controller_class %> view"> <%= render :partial => active_scaffold_config.list.search_partial %> </div> </td> @@ -18,7 +18,7 @@ <% if params[:nested].nil? && active_scaffold_config.list.always_show_create %> <tr> <td> - <div class="active-scaffold create-view <%= "#{params[:controller]}-view" %> view"> + <div class="active-scaffold create-view <%= controller_class %> view"> <%= render :partial => 'create_form_on_list' %> </div> </td> diff --git a/frontends/default/views/search.html.erb b/frontends/default/views/search.html.erb index 6ed3901b86..45a80962f9 100644 --- a/frontends/default/views/search.html.erb +++ b/frontends/default/views/search.html.erb @@ -1,5 +1,5 @@ <div class="active-scaffold"> - <div class="search-view <%= "#{params[:controller]}-view" %> view"> + <div class="search-view <%= controller_class %> view"> <%= render :partial => 'search' -%> </div> -</div> \ No newline at end of file +</div> diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 7988ad28b8..62d90a0a1a 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -25,7 +25,7 @@ def add(column_name, direction = nil) column = get_column(column_name) raise ArgumentError, "Could not find column #{column_name}" if column.nil? raise ArgumentError, "Sorting direction unknown" unless [:ASC, :DESC].include? direction.to_sym - @clauses << [column, direction] if column.sortable? + @clauses << [column, direction.untaint] if column.sortable? raise ArgumentError, "Can't mix :method- and :sql-based sorting" if mixed_sorting? end diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index 3cf7f9146a..34bf9f9483 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -3,7 +3,7 @@ module Helpers # A bunch of helper methods to produce the common view ids module IdHelpers def id_from_controller(controller) - controller.to_s.gsub("/", "__") + h(controller.to_s).gsub("/", "__") end def controller_id diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 5a62ad089c..697d1b69d8 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -214,6 +214,10 @@ def column_show_add_new(column, associated, record) value = false unless record.class.authorized_for?(:crud_type => :create) value end + + def controller_class + "#{h params[:controller]}-view" + end end end end From 6baaf275649c2d00fadb66221157403d9e6733ce Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 10 Jun 2010 10:55:55 +0200 Subject: [PATCH 0396/2024] Bugfix: updating messages div failed --- frontends/default/views/_list_inline_adapter.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index c72f288a83..d89325690c 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -1,4 +1,3 @@ -<%= update_page_tag { |page| page.replace_html active_scaffold_messages_id, :partial => 'messages' } %> <%# nested_id, allows us to remove a nested scaffold programmatically %> <tr class="inline-adapter" id="<%= element_row_id :action => :nested %>"> <td colspan="99" class="inline-adapter-cell"> @@ -8,3 +7,4 @@ </div> </td> </tr> +<%= javascript_tag("$('#{element_row_id}').up('tbody.records').prev().down().replace('#{render :partial => 'messages'}');") %> From d00509f37402221192e0c0299444b70ede38ab28 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 10 Jun 2010 11:25:51 +0200 Subject: [PATCH 0397/2024] Bugfix: npe if sorts_by_method and pagination = false --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 98fef4c97c..8db68d77ae 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -229,6 +229,7 @@ def find_page(options = {}) pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| sorted_collection = sort_collection_by_column(klass.all(finder_options), *options[:sorting].first) sorted_collection.slice(offset, per_page) if options[:pagination] + sorted_collection end else pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| @@ -236,7 +237,6 @@ def find_page(options = {}) klass.all(finder_options) end end - pager.page(options[:page]) end From 4351dac95c78cb08a448214dae252c536ba800a9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 10 Jun 2010 15:40:55 +0200 Subject: [PATCH 0398/2024] Bugfix: update flash messages failed due to some issues --- frontends/default/views/_list_inline_adapter.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index d89325690c..c4030dc5c1 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -7,4 +7,4 @@ </div> </td> </tr> -<%= javascript_tag("$('#{element_row_id}').up('tbody.records').prev().down().replace('#{render :partial => 'messages'}');") %> +<%= javascript_tag("$('#{element_row_id(:action => :nested)}').up('tbody.records').previous().down().replace('#{escape_javascript(render(:partial => 'messages').strip)}');") %> From 6c52adb4ac09997451ce16d304825afdc701c274 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 10 Jun 2010 16:53:14 +0200 Subject: [PATCH 0399/2024] Fix sorting by method without pagination --- lib/active_scaffold/finder.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 2acf665e3a..ad972d0755 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -247,7 +247,8 @@ def find_page(options = {}) if options[:sorting] and options[:sorting].sorts_by_method? pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| sorted_collection = sort_collection_by_column(klass.all(find_options), *options[:sorting].first) - sorted_collection.slice(offset, per_page) if options[:pagination] + sorted_collection = sorted_collection.slice(offset, per_page) if options[:pagination] + sorted_collection end else pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| From 447695f0f0b59f38d9778bb2f4b6498e5c7cb877 Mon Sep 17 00:00:00 2001 From: Kenny Ortmann <kenny.ortmann@gmail.com> Date: Thu, 10 Jun 2010 14:51:38 -0500 Subject: [PATCH 0400/2024] changing german rb to yml --- lib/active_scaffold/locale/de.rb | 72 ------------------------------- lib/active_scaffold/locale/de.yml | 68 +++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 72 deletions(-) delete mode 100644 lib/active_scaffold/locale/de.rb create mode 100644 lib/active_scaffold/locale/de.yml diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb deleted file mode 100644 index ed4de77bf0..0000000000 --- a/lib/active_scaffold/locale/de.rb +++ /dev/null @@ -1,72 +0,0 @@ -{ - :'de' => { - :active_scaffold => { - :add => 'Hinzufügen', - :add_existing => 'Existierenden Eintrag hinzufügen', - :add_existing_model => 'Existierende {{model}} hinzufügen', - :are_you_sure_to_delete => 'Sind Sie sicher?', - :cancel => 'Abbrechen', - :click_to_edit => 'Zum Editieren anklicken', - :close => 'Schliessen', - :create => 'Anlegen', - :create_model => 'Lege {{model}} an', - :create_another => 'Weitere anlegen', - :created_model => '{{model}} anlegen', - :create_new => 'Neu anlegen', - :customize => 'Anpassen', - :delete => 'Löschen', - :deleted_model => '{{model}} gelöscht', - :delimiter => 'Trennzeichen', - :download => 'Download', - :edit => 'Bearbeiten', - :export => 'Exportieren', - :nested_for_model => '{{nested_model}} für {{parent_model}}', - :filtered => '(Gefiltert)', - :found => 'Gefunden', - :hide => 'Verstecken', - :live_search => 'Live-Suche', - :loading => 'Lade…', - :next => 'Vorwärts', - :no_entries => 'Keine Einträge', - :no_options => 'Keine Optionen', - :omit_header => 'Lasse Header weg', - :options => 'Optionen', - :pdf => 'PDF', - :previous => 'Zurück', - :print => 'Drucken', - :refresh => 'Neu laden', - :remove => 'Entfernen', - :remove_file => 'Entferne oder Ersetze Datei', - :replace_with_new => 'Mit Neuer ersetzen', - :revisions_for_model => 'Revisionen für {{model}}', - :reset => 'Zurücksetzen', - :saving => 'Speichern…', - :search => 'Suche', - :search_terms => 'Suchbegriffe', - :_select_ => '- Auswählen -', - :show => 'Anzeigen', - :show_model => 'Zeige {{model}} an', - :_to_ => ' zu ', - :update => 'Speichern', - :update_model => 'Editiere {{model}}', - :updated_model => '{{model}} aktualisiert', - :'=' => '=', - :'>=' => '>=', - :'<=' => '<=', - :'>' => '>', - :'<' => '<', - :'!=' => '!=', - :between => 'Zwischen', - :is_null => 'Is null', - :is_not_null => 'Is not null', - :contains => 'Contains', - :begins_with => 'Begins with', - :ends_with => 'Ends with', - - # error_messages - :cant_destroy_record => "{{record}} kann nicht gelöscht werden", - :internal_error => 'Fehler bei der Verarbeitung (code 500, Interner Fehler)', - :version_inconsistency => 'Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben.' - } - } -} diff --git a/lib/active_scaffold/locale/de.yml b/lib/active_scaffold/locale/de.yml new file mode 100644 index 0000000000..fece424cca --- /dev/null +++ b/lib/active_scaffold/locale/de.yml @@ -0,0 +1,68 @@ +'de': + active_scaffold: + add: 'Hinzufügen' + add_existing: 'Existierenden Eintrag hinzufügen' + add_existing_model: 'Existierende {{model}} hinzufügen' + are_you_sure_to_delete: 'Sind Sie sicher?' + cancel: 'Abbrechen' + click_to_edit: 'Zum Editieren anklicken' + close: 'Schliessen' + create: 'Anlegen' + create_model: 'Lege {{model}} an' + create_another: 'Weitere anlegen' + created_model: '{{model}} anlegen' + create_new: 'Neu anlegen' + customize: 'Anpassen' + delete: 'Löschen' + deleted_model: '{{model}} gelöscht' + delimiter: 'Trennzeichen' + download: 'Download' + edit: 'Bearbeiten' + export: 'Exportieren' + nested_for_model: '{{nested_model}} für {{parent_model}}' + filtered: '(Gefiltert)' + found: 'Gefunden' + hide: 'Verstecken' + live_search: 'Live-Suche' + loading: 'Lade…' + next: 'Vorwärts' + no_entries: 'Keine Einträge' + no_options: 'Keine Optionen' + omit_header: 'Lasse Header weg' + options: 'Optionen' + pdf: 'PDF' + previous: 'Zurück' + print: 'Drucken' + refresh: 'Neu laden' + remove: 'Entfernen' + remove_file: 'Entferne oder Ersetze Datei' + replace_with_new: 'Mit Neuer ersetzen' + revisions_for_model: 'Revisionen für {{model}}' + reset: 'Zurücksetzen' + saving: 'Speichern…' + search: 'Suche' + search_terms: 'Suchbegriffe' + _select_: '- Auswählen -' + show: 'Anzeigen' + show_model: 'Zeige {{model}} an' + _to_ : ' zu ' + update: 'Speichern' + update_model: 'Editiere {{model}}' + updated_model: '{{model}} aktualisiert' + '=': '=' + '>=': '>=' + '<=': '<=' + '>': '>' + '<': '<' + '!=': '!=' + between: 'Zwischen' + is_null: 'Is null' + is_not_null: 'Is not null' + contains: 'Contains' + begins_with: 'Begins with' + ends_with: 'Ends with' + + # error_messages + cant_destroy_record: "{{record}} kann nicht gelöscht werden" + internal_error: 'Fehler bei der Verarbeitung (code 500, Interner Fehler)' + version_inconsistency: 'Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben.' \ No newline at end of file From 6fca2ccd327dbed4be565fb14478565e6fba9306 Mon Sep 17 00:00:00 2001 From: Kenny Ortmann <kenny.ortmann@gmail.com> Date: Thu, 10 Jun 2010 14:54:55 -0500 Subject: [PATCH 0401/2024] changing english rb to yml --- lib/active_scaffold/locale/en.rb | 75 ------------------------------- lib/active_scaffold/locale/en.yml | 71 +++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 75 deletions(-) delete mode 100644 lib/active_scaffold/locale/en.rb create mode 100644 lib/active_scaffold/locale/en.yml diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb deleted file mode 100644 index 5b4f3325c0..0000000000 --- a/lib/active_scaffold/locale/en.rb +++ /dev/null @@ -1,75 +0,0 @@ -{ - :'en' => { - :active_scaffold => { - :add => 'Add', - :add_existing => 'Add Existing', - :add_existing_model => 'Add Existing {{model}}', - :are_you_sure_to_delete => 'Are you sure you want to delete {{label}}?', - :cancel => 'Cancel', - :click_to_edit => 'Click to edit', - :click_to_reset => 'Click to reset', - :close => 'Close', - :create => 'Create', - :create_model => 'Create {{model}}', - :create_another => 'Create Another {{model}}', - :created_model => 'Created {{model}}', - :create_new => 'Create New', - :customize => 'Customize', - :delete => 'Delete', - :deleted_model => 'Deleted {{model}}', - :delimiter => 'Delimiter', - :download => 'Download', - :edit => 'Edit', - :export => 'Export', - :nested_for_model => '{{nested_model}} for {{parent_model}}', - :false => 'False', - :filtered => '(Filtered)', - :found => 'Found', - :hide => 'Hide', - :live_search => 'Live Search', - :loading => 'Loading…', - :next => 'Next', - :no_entries => 'No Entries', - :no_options => 'no options', - :omit_header => 'Omit Header', - :options => 'Options', - :pdf => 'PDF', - :previous => 'Previous', - :print => 'Print', - :refresh => 'Refresh', - :remove => 'Remove', - :remove_file => 'Remove or Replace file', - :replace_with_new => 'Replace With New', - :revisions_for_model => 'Revisions for {{model}}', - :reset => 'Reset', - :saving => 'Saving…', - :search => 'Search', - :search_terms => 'Search Terms', - :_select_ => '- select -', - :show => 'Show', - :show_model => 'Show {{model}}', - :_to_ => ' to ', - :true => 'True', - :update => 'Update', - :update_model => 'Update {{model}}', - :updated_model => 'Updated {{model}}', - :'=' => '=', - :'>=' => '>=', - :'<=' => '<=', - :'>' => '>', - :'<' => '<', - :'!=' => '!=', - :between => 'Between', - :is_null => 'Is null', - :is_not_null => 'Is not null', - :contains => 'Contains', - :begins_with => 'Begins with', - :ends_with => 'Ends with', - - # error_messages - :cant_destroy_record => "{{record}} can't be destroyed", - :internal_error => 'Request Failed (code 500, Internal Error)', - :version_inconsistency => 'Version inconsistency - this record has been modified since you started editing it.' - } - } -} diff --git a/lib/active_scaffold/locale/en.yml b/lib/active_scaffold/locale/en.yml new file mode 100644 index 0000000000..537d01974b --- /dev/null +++ b/lib/active_scaffold/locale/en.yml @@ -0,0 +1,71 @@ +'en': + active_scaffold: + add: 'Add' + add_existing: 'Add Existing' + add_existing_model: 'Add Existing {{model}}' + are_you_sure_to_delete: 'Are you sure you want to delete {{label}}?' + cancel: 'Cancel' + click_to_edit: 'Click to edit' + click_to_reset: 'Click to reset' + close: 'Close' + create: 'Create' + create_model: 'Create {{model}}' + create_another: 'Create Another {{model}}' + created_model: 'Created {{model}}' + create_new: 'Create New' + customize: 'Customize' + delete: 'Delete' + deleted_model: 'Deleted {{model}}' + delimiter: 'Delimiter' + download: 'Download' + edit: 'Edit' + export: 'Export' + nested_for_model: '{{nested_model}} for {{parent_model}}' + false: 'False' + filtered: '(Filtered)' + found: 'Found' + hide: 'Hide' + live_search: 'Live Search' + loading: 'Loading…' + next: 'Next' + no_entries: 'No Entries' + no_options: 'no options' + omit_header: 'Omit Header' + options: 'Options' + pdf: 'PDF' + previous: 'Previous' + print: 'Print' + refresh: 'Refresh' + remove: 'Remove' + remove_file: 'Remove or Replace file' + replace_with_new: 'Replace With New' + revisions_for_model: 'Revisions for {{model}}' + reset: 'Reset' + saving: 'Saving…' + search: 'Search' + search_terms: 'Search Terms' + _select_: '- select -' + show: 'Show' + show_model: 'Show {{model}}' + _to_ : ' to ' + true: 'True' + update: 'Update' + update_model: 'Update {{model}}' + updated_model: 'Updated {{model}}' + '=': '=' + '>=': '>=' + '<=': '<=' + '>': '>' + '<': '<' + '!=': '!=' + between: 'Between' + is_null: 'Is null' + is_not_null: 'Is not null' + contains: 'Contains' + begins_with: 'Begins with' + ends_with: 'Ends with' + + # error_messages + cant_destroy_record: "{{record}} can't be destroyed" + internal_error: 'Request Failed (code 500, Internal Error)' + version_inconsistency: 'Version inconsistency - this record has been modified since you started editing it.' \ No newline at end of file From 8033adef7606a04d592607c3ead965e612119daf Mon Sep 17 00:00:00 2001 From: Kenny Ortmann <kenny.ortmann@gmail.com> Date: Thu, 10 Jun 2010 14:57:14 -0500 Subject: [PATCH 0402/2024] changing french from rb to yml --- lib/active_scaffold/locale/fr.rb | 70 ------------------------------- lib/active_scaffold/locale/fr.yml | 67 +++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 70 deletions(-) delete mode 100644 lib/active_scaffold/locale/fr.rb create mode 100644 lib/active_scaffold/locale/fr.yml diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb deleted file mode 100644 index a7cb2c095e..0000000000 --- a/lib/active_scaffold/locale/fr.rb +++ /dev/null @@ -1,70 +0,0 @@ -{ - :'fr' => { - :active_scaffold => { - :add => 'Ajouter', - :add_existing => 'Ajouter un(e) existant(e)', - :add_existing_model => 'Ajouter un(e) {{model}} existant(e)', - :are_you_sure_to_delete => 'Êtes vous sûr?', - :cancel => 'Annuler', - :click_to_edit => 'Cliquer pour éditer', - :close => 'Fermer', - :create => 'Créer', - :create_model => 'Créer {{model}}', - :create_another => 'Créer un autre', - :created_model => '{{model}} créé', - :create_new => 'Créer un nouveau', - :customize => 'Personnaliser', - :delete => 'Supprimer', - :deleted_model => 'Suppression de {{model}}', - :delimiter => 'Délimiteur', - :download => 'Télécharger', - :edit => 'Éditer', - :export => 'Exporter', - :nested_for_model => '{{nested_model}} pour {{parent_model}}', - :filtered => '(Filtré)', - :found => 'Trouvé', - :hide => 'Cacher', - :live_search => 'Recherche en temps réel', - :loading => 'Chargement…', - :next => 'Suivant', - :no_entries => "Pas d'entrée", - :no_options => "pas d'option", - :omit_header => 'Omettre les en-têtes', - :options => 'Options', - :pdf => 'PDF', - :previous => 'Précédent', - :print => 'Imprimer', - :refresh => 'Rafraîchir', - :remove => 'Supprimer', - :remove_file => 'Supprimer et remplacer le fichier', - :replace_with_new => 'Remplacer avec le nouveau', - :revisions_for_model => 'Révision pour {{model}}', - :reset => 'Annuler', - :saving => 'Sauvegarder…', - :search => 'Rechercher', - :search_terms => 'Recherche de termes', - :_select_ => '- sélectionner -', - :show => 'Montrer', - :show_model => 'Montrer {{model}}', - :_to_ => ' à ', - :update => 'Mettre à jour', - :update_model => 'Mettre à jour le(/la) {{model}}', - :updated_model => 'Mis à jour de {{model}}', - :'=' => '=', - :'>=' => '>=', - :'<=' => '<=', - :'>' => '>', - :'<' => '<', - :'!=' => '!=', - :between => 'Entre', - :is_null => 'Is null', - :is_not_null => 'Is not null', - :contains => 'Contains', - :begins_with => 'Begins with', - :ends_with => 'Ends with', - - # error_messages - :internal_error => 'Erreur de la requête (code 500, Erreur interne)', - :version_inconsistency => "Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer.", - } - }} diff --git a/lib/active_scaffold/locale/fr.yml b/lib/active_scaffold/locale/fr.yml new file mode 100644 index 0000000000..5a89ff23a3 --- /dev/null +++ b/lib/active_scaffold/locale/fr.yml @@ -0,0 +1,67 @@ +'fr': + active_scaffold: + add: 'Ajouter' + add_existing: 'Ajouter un(e) existant(e)' + add_existing_model: 'Ajouter un(e) {{model}} existant(e)' + are_you_sure_to_delete: 'Êtes vous sûr?' + cancel: 'Annuler' + click_to_edit: 'Cliquer pour éditer' + close: 'Fermer' + create: 'Créer' + create_model: 'Créer {{model}}' + create_another: 'Créer un autre' + created_model: '{{model}} créé' + create_new: 'Créer un nouveau' + customize: 'Personnaliser' + delete: 'Supprimer' + deleted_model: 'Suppression de {{model}}' + delimiter: 'Délimiteur' + download: 'Télécharger' + edit: 'Éditer' + export: 'Exporter' + nested_for_model: '{{nested_model}} pour {{parent_model}}' + filtered: '(Filtré)' + found: 'Trouvé' + hide: 'Cacher' + live_search: 'Recherche en temps réel' + loading: 'Chargement…' + next: 'Suivant' + no_entries: "Pas d'entrée" + no_options: "pas d'option" + omit_header: 'Omettre les en-têtes' + options: 'Options' + pdf: 'PDF' + previous: 'Précédent' + print: 'Imprimer' + refresh: 'Rafraîchir' + remove: 'Supprimer' + remove_file: 'Supprimer et remplacer le fichier' + replace_with_new: 'Remplacer avec le nouveau' + revisions_for_model: 'Révision pour {{model}}' + reset: 'Annuler' + saving: 'Sauvegarder…' + search: 'Rechercher' + search_terms: 'Recherche de termes' + _select_: '- sélectionner -' + show: 'Montrer' + show_model: 'Montrer {{model}}' + _to_ : ' à ' + update: 'Mettre à jour' + update_model: 'Mettre à jour le(/la) {{model}}' + updated_model: 'Mis à jour de {{model}}' + '=': '=' + '>=': '>=' + '<=': '<=' + '>': '>' + '<': '<' + '!=': '!=' + between: 'Entre' + is_null: 'Is null' + is_not_null: 'Is not null' + contains: 'Contains' + begins_with: 'Begins with' + ends_with: 'Ends with' + + # error_messages + internal_error: 'Erreur de la requête (code 500, Erreur interne)' + version_inconsistency: "Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer." From 603d0b9c786b99421ac496e1ca45bedf8a0769ad Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 11 Jun 2010 08:14:55 +0200 Subject: [PATCH 0403/2024] Bugfix: if pagination true and sort_by_method --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 8db68d77ae..66e84bed51 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -228,7 +228,7 @@ def find_page(options = {}) if options[:sorting] and options[:sorting].sorts_by_method? pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| sorted_collection = sort_collection_by_column(klass.all(finder_options), *options[:sorting].first) - sorted_collection.slice(offset, per_page) if options[:pagination] + sorted_collection = sorted_collection.slice(offset, per_page) if options[:pagination] sorted_collection end else From d9d7ac498e505772e335002dc309f300c266ab8f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 11 Jun 2010 08:29:13 +0200 Subject: [PATCH 0404/2024] list_action controller authorization gets access to current record --- lib/active_scaffold/actions/delete.rb | 2 +- lib/active_scaffold/actions/nested.rb | 2 +- lib/active_scaffold/actions/show.rb | 2 +- lib/active_scaffold/actions/update.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 36f4ec6890..66ab441992 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -57,7 +57,7 @@ def do_destroy # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. - def delete_authorized? + def delete_authorized?(record) authorized_for?(:crud_type => :delete) end private diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index dd8142b953..477b78a483 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -31,7 +31,7 @@ def do_nested @record = find_if_allowed(params[:id], :read) end - def nested_authorized? + def nested_authorized?(record) true end diff --git a/lib/active_scaffold/actions/show.rb b/lib/active_scaffold/actions/show.rb index 317c9d3d94..b461f1e49f 100644 --- a/lib/active_scaffold/actions/show.rb +++ b/lib/active_scaffold/actions/show.rb @@ -39,7 +39,7 @@ def do_show # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. - def show_authorized? + def show_authorized?(record) authorized_for?(:crud_type => :read) end private diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index ddc3281fae..561ac02517 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -111,7 +111,7 @@ def after_update_save(record); end # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. - def update_authorized? + def update_authorized?(record) authorized_for?(:crud_type => :update) end private diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 6416e3f716..491b98feb7 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -123,8 +123,8 @@ def link_to_visibility_toggle(options = {}) link_to_function link_text, "e = #{options[:of]}; e.toggle(); this.innerHTML = (e.style.display == 'none') ? '#{as_(:show)}' : '#{as_(:hide)}'", :class => 'visibility-toggle' end - def skip_action_link(link) - (link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method) + def skip_action_link(link, *args) + (link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args) end def render_action_link(link, url_options, record = nil, html_options = {}) From 9e4a0c6dd7eb2b2f2e76f36c71001aee2c604b04 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 11 Jun 2010 10:58:00 +0200 Subject: [PATCH 0405/2024] call skip_action_link with record parameter for list action_links --- frontends/default/views/_list_actions.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 5b29ecdc64..92c73f25e7 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -4,7 +4,7 @@ <%= loading_indicator_tag(:action => :record, :id => record.id) %> </td> <% active_scaffold_config.action_links.each :member do |link| -%> - <% next if skip_action_link(link) -%> + <% next if skip_action_link(link, record) -%> <td> <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : "<a class='disabled #{link.action}'>#{link.label}</a>" -%> </td> From 31285dd62babdfaeceafd9ad9984d2dfc3f56e4b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 11 Jun 2010 11:00:15 +0200 Subject: [PATCH 0406/2024] add default_setting association_form_ui (might be set to :select) --- lib/active_scaffold/data_structures/column.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 11ff313ae0..1a6cd64642 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -190,6 +190,9 @@ def show_blank_record?(associated) cattr_accessor :actions_for_association_links @@actions_for_association_links = [:new, :edit, :show] attr_accessor :actions_for_association_links + + cattr_accessor :association_form_ui + @@association_form_ui = nil # ----------------------------------------------------------------- # # the below functionality is intended for internal consumption only # @@ -248,6 +251,7 @@ def initialize(name, active_record_class) #:nodoc: @options = {:format => :i18n_number} if @column.try(:number?) @form_ui = :checkbox if @column and @column.type == :boolean @allow_add_existing = true + @form_ui = self.class.association_form_ui if @association && self.class.association_form_ui # default all the configurable variables self.css_class = '' From 944c7d1fb2471bce5d526e11234e92e23d94bece Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 11 Jun 2010 11:11:20 +0200 Subject: [PATCH 0407/2024] record attribute for list action_links authorization might be nil --- lib/active_scaffold/actions/delete.rb | 2 +- lib/active_scaffold/actions/nested.rb | 2 +- lib/active_scaffold/actions/show.rb | 2 +- lib/active_scaffold/actions/update.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 66ab441992..103319b2bd 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -57,7 +57,7 @@ def do_destroy # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. - def delete_authorized?(record) + def delete_authorized?(record = nil) authorized_for?(:crud_type => :delete) end private diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 477b78a483..b261168a49 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -31,7 +31,7 @@ def do_nested @record = find_if_allowed(params[:id], :read) end - def nested_authorized?(record) + def nested_authorized?(record = nil) true end diff --git a/lib/active_scaffold/actions/show.rb b/lib/active_scaffold/actions/show.rb index b461f1e49f..588db9d2c4 100644 --- a/lib/active_scaffold/actions/show.rb +++ b/lib/active_scaffold/actions/show.rb @@ -39,7 +39,7 @@ def do_show # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. - def show_authorized?(record) + def show_authorized?(record = nil) authorized_for?(:crud_type => :read) end private diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 561ac02517..12c8384c47 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -111,7 +111,7 @@ def after_update_save(record); end # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. - def update_authorized?(record) + def update_authorized?(record = nil) authorized_for?(:crud_type => :update) end private From 98f118e8677953e7f2413333aa5ebe9cc801f66f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 11 Jun 2010 12:23:47 +0200 Subject: [PATCH 0408/2024] input_plural_association html_safe --- .../helpers/form_column_helpers.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index e47265eed7..9a5ba593b4 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -110,23 +110,20 @@ def active_scaffold_input_plural_association(column, options) return content_tag(:span, as_(:no_options), :id => options[:id]) if select_options.empty? html = "<ul class=\"checkbox-list\" id=\"#{options[:id]}\">" - + associated_ids = associated_options.collect {|a| a[1]} select_options.each_with_index do |option, i| label, id = option this_name = "#{options[:name]}[]" this_id = "#{options[:id]}_#{i}_id" - html << "<li>" - html << check_box_tag(this_name, id, associated_ids.include?(id), :id => this_id) - html << "<label for='#{this_id}'>" - html << label - html << "</label>" - html << "</li>" + html << content_tag(:li) do + check_box_tag(this_name, id, associated_ids.include?(id), :id => this_id) << + content_tag(:label, h(label), :for => this_id) + end end - html << '</ul>' html << javascript_tag("new DraggableLists('#{options[:id]}')") if column.options[:draggable_lists] - html + html.html_safe end def active_scaffold_translated_option(column, text, value = nil) From 0e615d2cf3c6e5e33656e1716b1f2d8c4f8d0d96 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 11 Jun 2010 12:59:36 +0200 Subject: [PATCH 0409/2024] update instead of replace flash message (not working for table links..) --- frontends/default/views/_list_inline_adapter.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index c4030dc5c1..f82d9c89fe 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -7,4 +7,4 @@ </div> </td> </tr> -<%= javascript_tag("$('#{element_row_id(:action => :nested)}').up('tbody.records').previous().down().replace('#{escape_javascript(render(:partial => 'messages').strip)}');") %> +<%= javascript_tag("$('#{element_row_id(:action => :nested)}').up('tbody.records').previous().down().update('#{escape_javascript(render(:partial => 'messages').strip)}');") %> From 608251565a19ce87b36a4ab0f717e544d3a6d3d5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 11 Jun 2010 13:46:50 +0200 Subject: [PATCH 0410/2024] updating flash messages should work now --- frontends/default/javascripts/active_scaffold.js | 5 +++++ frontends/default/views/_list_inline_adapter.html.erb | 2 +- frontends/default/views/on_create.js.rjs | 2 +- frontends/default/views/on_update.js.rjs | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 0f8f6c6b19..8d13e1c329 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -374,6 +374,11 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ scaffold_id: function() { return this.tag.up('div.active-scaffold').id; + }, + + update_flash_messages: function(messages) { + message_node = $(this.scaffold_id().sub('-active-scaffold', '-messages')); + if (message_node) message_node.update(messages); } }); diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index f82d9c89fe..486c39806e 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -7,4 +7,4 @@ </div> </td> </tr> -<%= javascript_tag("$('#{element_row_id(:action => :nested)}').up('tbody.records').previous().down().update('#{escape_javascript(render(:partial => 'messages').strip)}');") %> +<%= javascript_tag("$('#{element_row_id(:action => :nested)}').action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');") %> diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index 9f72b51c38..bbebc1a7a2 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -1,5 +1,6 @@ form_selector = "#{element_form_id(:action => :create)}" +page << "$('#{form_selector}').up('.as_adapter').action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? if @insert_row page.insert_html :top, active_scaffold_tbody_id, :partial => 'list_record', :locals => {:record => @record} @@ -22,4 +23,3 @@ else page.replace form_selector, :partial => 'create_form', :locals => {:xhr => true} page[form_selector].scroll_to end -page.replace_html active_scaffold_messages_id, :partial => 'messages' diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 88054b8b89..5ca9f74106 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -1,5 +1,6 @@ form_selector = "#{element_form_id(:action => :update)}" +page << "$('#{form_selector}').up('.as_adapter').action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? updated_row = render :partial => 'list_record', :locals => {:record => @record} page << "$('#{form_selector}').up('.as_adapter').action_link.close('#{escape_javascript(updated_row)}');" @@ -8,4 +9,3 @@ else page.replace form_selector, :partial => 'update_form', :locals => {:xhr => true} page[form_selector].scroll_to end -page.replace_html active_scaffold_messages_id, :partial => 'messages' From ab50887f7fc3e644c28bb1db44b4693117df7d99 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Jun 2010 13:10:23 +0200 Subject: [PATCH 0411/2024] nested views should render list with header --- lib/active_scaffold/actions/list.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 16745a617c..bacf2cbd9c 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -31,7 +31,9 @@ def list_respond_to_html end def list_respond_to_js if params[:adapter] - render(:partial => 'list', :layout => false) + #list.user.label = as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => format_value(@record.to_label)) + active_scaffold_session_storage[:list][:label] = as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => 'Unknown') + render(:partial => 'list_with_header') elsif params[:embedded] params.delete(:embedded) render(:partial => 'list_with_header') From ab779b5c21957fd33493eef02a47d01e7122e01e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Jun 2010 14:14:54 +0200 Subject: [PATCH 0412/2024] remove human_name depreciation warning --- lib/active_scaffold/helpers/form_column_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 9a5ba593b4..e94b08f0ba 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -333,9 +333,9 @@ def active_scaffold_add_existing_input(options) def active_scaffold_add_existing_label if controller.respond_to?(:record_select_config) - record_select_config.model.human_name + record_select_config.model.model_name.human else - active_scaffold_config.model.human_name + active_scaffold_config.model.model_name.human end end end From 8b2ca212ee351a81d8d42ac1275405411c6bda87 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Jun 2010 15:21:20 +0200 Subject: [PATCH 0413/2024] remove link to embedded controller after Ajax Update --- lib/extensions/action_view_rendering.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index 17df713107..6064c4e9ae 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -57,8 +57,10 @@ def render_with_active_scaffold(*args, &block) id = "as_#{eid}-content" url = url_for({:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params])) - link_to(remote_controller.to_s, url, {:remote => true, :id => id}) << + content_tag(:div, {:id => id}) do + link_to(remote_controller.to_s, url, {:remote => true, :id => id}) << javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get'})") + end #render_component :controller => remote_controller.to_s, :action => 'table', :params => options[:params] else render_without_active_scaffold(*args, &block) From 33917a48d46e1e34006dbe6b98922f61dd68d38d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Jun 2010 15:45:32 +0200 Subject: [PATCH 0414/2024] eval javascript --- lib/extensions/action_view_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index 6064c4e9ae..5c13455a80 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -59,7 +59,7 @@ def render_with_active_scaffold(*args, &block) url = url_for({:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params])) content_tag(:div, {:id => id}) do link_to(remote_controller.to_s, url, {:remote => true, :id => id}) << - javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get'})") + javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true})") end #render_component :controller => remote_controller.to_s, :action => 'table', :params => options[:params] else From de89f277dffff2ef6b96bc58d3b1365045f9ac45 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Jun 2010 16:13:40 +0200 Subject: [PATCH 0415/2024] secure base64 replaced by secure hex to generate valid css ids --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 491b98feb7..f1fb0a671c 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -169,7 +169,7 @@ def url_options_for_nested_link(column, record, link, url_options) if column.association and link.controller.to_s != params[:controller] url_options[record.class.name.foreign_key.to_sym] = url_options.delete(:id) url_options[:id] = record.send(column.association.name) if column.singular_association? - url_options[:eid] = "#{params[:controller]}_#{ActiveSupport::SecureRandom.base64(10)}" + url_options[:eid] = "#{params[:controller]}_#{ActiveSupport::SecureRandom.hex(10)}" end end From ea94288e7348ad16e2f1192cccc5b5f1f3db0463 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Jun 2010 18:32:27 +0200 Subject: [PATCH 0416/2024] fixed syntax error in form --- frontends/default/views/_add_existing_form.html.erb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontends/default/views/_add_existing_form.html.erb b/frontends/default/views/_add_existing_form.html.erb index e11969b4a7..4a918bdf44 100644 --- a/frontends/default/views/_add_existing_form.html.erb +++ b/frontends/default/views/_add_existing_form.html.erb @@ -1,14 +1,12 @@ <% url_options = params_for(:action => :add_existing) -%> <% xhr = request.xhr? -%> -<% as_action_config = active_scaffold_config.send(:add_existing) -%> <%= options = {:id => element_form_id(:action => :add_existing), :class => "as_form create", :method => :post, 'data-loading' => true} options[:remote] = true if xhr - form_tag url_options, options -end -%> + form_tag url_options, options -%> <h4><%= active_scaffold_config.nested.label -%></h4> From 718d0d126266793f13636e57d795a95d5a0c444b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Jun 2010 18:34:19 +0200 Subject: [PATCH 0417/2024] readd nested_attribute to detect if we are in nested mode --- lib/active_scaffold.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 6102ac0a2d..fd5d41e63e 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -129,6 +129,8 @@ def link_for_association(column, options = {}) options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => controller.controller_path, :column => column if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. + options[:parameters] ||= {} + options[:parameters][:nested] = true ActiveScaffold::DataStructures::ActionLink.new('index', options) #unless column.through_association? else actions = controller.active_scaffold_config.actions From 5fb8ace0c17a5d9751a8194b1d7f6b6e17e698f4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Jun 2010 18:36:12 +0200 Subject: [PATCH 0418/2024] removed accidently checked in code fragment --- lib/active_scaffold/actions/list.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index bacf2cbd9c..cc5184a680 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -31,8 +31,6 @@ def list_respond_to_html end def list_respond_to_js if params[:adapter] - #list.user.label = as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => format_value(@record.to_label)) - active_scaffold_session_storage[:list][:label] = as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => 'Unknown') render(:partial => 'list_with_header') elsif params[:embedded] params.delete(:embedded) @@ -79,6 +77,7 @@ def do_list def list_authorized? authorized_for?(:crud_type => :read) end + private def list_authorized_filter raise ActiveScaffold::ActionNotAllowed unless list_authorized? From 9a2dd61498348a4a76de8dc2b94562619468b800 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Jun 2010 18:37:27 +0200 Subject: [PATCH 0419/2024] add_existing_form select box is working --- lib/active_scaffold/actions/nested.rb | 39 +++++++++++++++++-- .../helpers/form_column_helpers.rb | 7 ++-- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index b261168a49..fd029f0861 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -6,11 +6,14 @@ def self.included(base) super base.module_eval do before_filter :set_active_scaffold_constraints - before_filter :register_constraints_with_action_columns + #before_filter :register_constraints_with_action_columns + before_filter :set_nested_list_label include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? {|a| a.macro == :has_and_belongs_to_many} end base.before_filter :include_habtm_actions base.helper_method :nested_habtm? + base.helper_method :nested_column + base.helper_method :nested_parent_column end def nested @@ -61,13 +64,14 @@ def nested? def nested_habtm? begin - a = active_scaffold_config.columns[nested_association] - return a.association.macro == :has_and_belongs_to_many if a and nested? + return nested_column.association.macro == :has_and_belongs_to_many if nested? and nested_column false rescue raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, nested_association), caller end end + + def nested_association return active_scaffold_constraints.keys.to_s.to_sym if nested? @@ -78,6 +82,35 @@ def nested_parent_id return active_scaffold_constraints.values.to_s if nested? nil end + + def nested_parent_record + find_if_allowed(nested_parent_id, :read, nested_column.association.klass) + end + + def nested_parent + nested_column.association.klass + end + + def nested_parent_column + join_table = nested_column.association.options[:join_table] + parent_config = active_scaffold_config_for(nested_parent) + if join_table && parent_config + parent_config.columns.detect {|column| column.association and column.association.macro == :has_and_belongs_to_many and column.association.options[:join_table] and column.association.options[:join_table] == join_table} + end + end + + def nested_column + begin + @nested_column ||= active_scaffold_config.columns[nested_association] + rescue + raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, nested_association), caller + end + end + + def set_nested_list_label + active_scaffold_session_storage[:list][:label] = as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => nested_parent_record.to_label) if nested? + end + private def nested_formats (default_formats + active_scaffold_config.formats + active_scaffold_config.nested.formats).uniq diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index e94b08f0ba..7fdddc11e2 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -324,10 +324,9 @@ def active_scaffold_add_existing_input(options) options.merge!(active_scaffold_input_text_options) record_select_field(options[:name], @record, options) else - column = active_scaffold_config_for(params[:parent_model]).columns[params[:parent_column]] - select_options = options_for_select(options_for_association(column.association)) unless column.through_association? - select_options ||= options_for_select(active_scaffold_config.model.find(:all).collect {|c| [h(c.to_label), c.id]}) - select_tag 'associated_id', '<option value="">' + as_(:_select_) + '</option>' + select_options unless select_options.empty? + select_options = options_for_select(options_for_association(nested_parent_column.association)) #unless column.through_association? + select_options ||= options_for_select(active_scaffold_config.model.all.collect {|c| [h(c.to_label), c.id]}) + select_tag 'associated_id', ('<option value="">' + as_(:_select_) + '</option>' + select_options).html_safe unless select_options.empty? end end From fd621e8aca8aa24a567ff36ff9f534afe0f7bc38 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Jun 2010 18:50:15 +0200 Subject: [PATCH 0420/2024] add_existing adds records again --- lib/active_scaffold/actions/nested.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index fd029f0861..2974bf5b17 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -83,7 +83,7 @@ def nested_parent_id nil end - def nested_parent_record + def nested_parent_record(mode = :read) find_if_allowed(nested_parent_id, :read, nested_column.association.klass) end @@ -220,11 +220,14 @@ def nested_action_from_params # The actual "add_existing" algorithm def do_add_existing - parent_model, id, association = nested_action_from_params - parent_record = find_if_allowed(id, :update, parent_model) + parent_record = nested_parent_record(:update) @record = active_scaffold_config.model.find(params[:associated_id]) - parent_record.send(association) << @record - parent_record.save + if parent_record && @record + parent_record.send(nested_parent_column.name) << @record + parent_record.save + else + false + end end def do_destroy_existing From 29d196606c461909e2be91a5cac964df15fda7cc Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 15 Jun 2010 09:04:39 +0200 Subject: [PATCH 0421/2024] get destroy_existing up and running --- lib/active_scaffold/actions/nested.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 2974bf5b17..0dd03c1910 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -6,7 +6,7 @@ def self.included(base) super base.module_eval do before_filter :set_active_scaffold_constraints - #before_filter :register_constraints_with_action_columns + before_filter :register_constraints_with_action_columns before_filter :set_nested_list_label include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? {|a| a.macro == :has_and_belongs_to_many} end @@ -83,8 +83,8 @@ def nested_parent_id nil end - def nested_parent_record(mode = :read) - find_if_allowed(nested_parent_id, :read, nested_column.association.klass) + def nested_parent_record(crud = :read) + find_if_allowed(nested_parent_id, crud, nested_column.association.klass) end def nested_parent @@ -200,10 +200,10 @@ def destroy_existing_respond_to_yaml render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end - def add_existing_authorized? + def add_existing_authorized?(record = nil) true end - def delete_existing_authorized? + def delete_existing_authorized?(record = nil) true end @@ -214,10 +214,6 @@ def after_create_save(record) end end - def nested_action_from_params - return params[:parent_model].constantize, nested_parent_id, params[:parent_column] - end - # The actual "add_existing" algorithm def do_add_existing parent_record = nested_parent_record(:update) @@ -232,9 +228,8 @@ def do_add_existing def do_destroy_existing if active_scaffold_config.nested.shallow_delete - parent_model, id, association = nested_action_from_params - @record = find_if_allowed(id, :update, parent_model) - collection = @record.send(association) + @record = nested_parent_record(:update) + collection = @record.send(nested_parent_column.name) assoc_record = collection.find(params[:id]) collection.delete(assoc_record) else From 9db57ef59030f9698fb576c0fae145e1ab482260 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 15 Jun 2010 09:05:07 +0200 Subject: [PATCH 0422/2024] shallow_delete set to true as default --- lib/active_scaffold/config/nested.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index 6d44a79a05..9141a75b45 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -10,7 +10,7 @@ def initialize(core_config) # global level configuration # -------------------------- cattr_accessor :shallow_delete - @@shallow_delete = false + @@shallow_delete = true # instance-level configuration # ---------------------------- From c35fce38b007ea7d1d714cb79ceca0881c9520dd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 15 Jun 2010 09:16:25 +0200 Subject: [PATCH 0423/2024] removed controller action nested --- lib/active_scaffold/actions/nested.rb | 17 ----------------- lib/extensions/routing_mapper.rb | 2 +- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 0dd03c1910..e23ec0b63b 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -16,24 +16,7 @@ def self.included(base) base.helper_method :nested_parent_column end - def nested - do_nested - respond_to_action(:nested) - end - protected - def nested_respond_to_html - render :partial => 'nested', :layout => true - end - def nested_respond_to_js - render :partial => 'nested' - end - # A simple method to find the record we'll be nesting *from* - # May be overridden to customize the behavior - def do_nested - @record = find_if_allowed(params[:id], :read) - end - def nested_authorized?(record = nil) true end diff --git a/lib/extensions/routing_mapper.rb b/lib/extensions/routing_mapper.rb index f63a0dd103..10ea654bae 100644 --- a/lib/extensions/routing_mapper.rb +++ b/lib/extensions/routing_mapper.rb @@ -7,7 +7,7 @@ def as_routes(options = {:full => true}) get :show_search, :render_field end member do - get :row, :nested, :render_field, :delete + get :row, :render_field, :delete post :update_column end as_extended_routes if options[:full] From 353bd107c6397ff1f5a1fc56a255286330beffb6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 15 Jun 2010 09:23:38 +0200 Subject: [PATCH 0424/2024] remove nested view --- frontends/default/views/_nested.html.erb | 36 ------------------------ 1 file changed, 36 deletions(-) delete mode 100644 frontends/default/views/_nested.html.erb diff --git a/frontends/default/views/_nested.html.erb b/frontends/default/views/_nested.html.erb deleted file mode 100644 index 131dac41e1..0000000000 --- a/frontends/default/views/_nested.html.erb +++ /dev/null @@ -1,36 +0,0 @@ -<h4> </h4> -<% - # TODO: shouldn't this logic happen in the controller action instead of the template? - # Actually, maybe we should make render :active_scaffold work in the controller, and not even have a _nested.rhtml? - - # This assumes that the association is included as a column in the active_scaffold_config.columns collection - associated_columns = [] - associated_columns = params[:associations].split(" ") unless params[:associations].nil? - unless associated_columns.empty? - parent_id = params[:id] - associated_columns.each do | column_name | - # find the column and the association - column = active_scaffold_config.columns[column_name] - association = column.association - - # determine what constraints we need - @constraints = { association.reverse => parent_id } - - # generate the customized label - @label = as_(:nested_for_model, :nested_model => active_scaffold_config_for(association.klass).list.label, :parent_model => format_value(@record.to_label)) - - begin - controller = active_scaffold_controller_for(association.klass) - rescue ActiveScaffold::ControllerNotFound => error - concat "#{error.class} - #{error.message}" - else - concat render(:active_scaffold => controller.controller_path, - :constraints => @constraints, - :conditions => association.options[:conditions], - :label => h(@label), - :params => {:nested => true, :parent_column => column_name, :parent_model => association.active_record.name} - ) - end - end - end -%> From a794f812f0d09ac8051f5ddbb2f1030a742fbe61 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 15 Jun 2010 09:30:54 +0200 Subject: [PATCH 0425/2024] rails 3 renders date/time form fields as text_fields assign text class to them for common styling --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 7fdddc11e2..03f34e595e 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -29,7 +29,7 @@ def active_scaffold_input_for(column, scope = nil, options = {}) # final ultimate fallback: use rails' generic input method else # for textual fields we pass different options - text_types = [:text, :string, :integer, :float, :decimal] + text_types = [:text, :string, :integer, :float, :decimal, :date, :time, :datetime] options = active_scaffold_input_text_options(options) if text_types.include?(column.column.type) if column.column.type == :string && options[:maxlength].blank? options[:maxlength] = column.column.limit From 332308b1b1d962aaaa8f2038a94667422c8c2f17 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 15 Jun 2010 09:58:14 +0200 Subject: [PATCH 0426/2024] add_existing cancel forgot about nested state --- frontends/default/views/_add_existing_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_add_existing_form.html.erb b/frontends/default/views/_add_existing_form.html.erb index 4a918bdf44..afb9b84798 100644 --- a/frontends/default/views/_add_existing_form.html.erb +++ b/frontends/default/views/_add_existing_form.html.erb @@ -21,7 +21,7 @@ options = {:id => element_form_id(:action => :add_existing), <p class="form-footer"> <%= submit_tag as_(:add), :class => "submit" %> - <%= link_to as_(:cancel), main_path_to_return, :class => 'as_cancel', :remote => true %> + <%= link_to as_(:cancel), main_path_to_return.merge(:nested => true), :class => 'as_cancel', :remote => true %> <%= loading_indicator_tag(:action => :add_existing, :id => params[:id]) %> </p> From ebb1857aecb4cdb35221a844dbb25a9990976392 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 15 Jun 2010 15:59:37 +0200 Subject: [PATCH 0427/2024] readd custom override dirs --- lib/active_scaffold.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index fd5d41e63e..423c0ef79f 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -157,7 +157,7 @@ def active_scaffold_paths #@active_scaffold_paths = ActionView::PathSet.new @active_scaffold_paths = [] - #@active_scaffold_paths.concat @active_scaffold_overrides unless @active_scaffold_overrides.nil? + @active_scaffold_paths.concat @active_scaffold_overrides unless @active_scaffold_overrides.nil? @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil? @active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil? @active_scaffold_paths From c963b6a1a91fe55f508bb7abf3273ba6924c7349 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 15 Jun 2010 16:00:22 +0200 Subject: [PATCH 0428/2024] get render :super up and running --- lib/extensions/action_view_rendering.rb | 42 ++++++++++++++----------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index 5c13455a80..6ac75dfc91 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -1,3 +1,18 @@ +module ActionView + class LookupContext + module ViewPaths + def find_all_templates(name, prefix = nil, partial = false) + templates = [] + @view_paths.each do |resolver| + template = resolver.find_all(*args_for_lookup(name, prefix, partial)).first + templates << template unless template.nil? + end + templates + end + end + end +end + # wrap the action rendering for ActiveScaffold views module ActionView::Rendering #:nodoc: # Adds two rendering options. @@ -25,24 +40,11 @@ def render_with_active_scaffold(*args, &block) if args.first == :super options = args[1] || {} options[:locals] ||= {} - options[:locals].reverse_merge! @local_assigns - - known_extensions = [:erb, :rhtml, :rjs, :haml] - # search through call stack for a template file (normally matches on first caller) - # note that we can't use split(':').first because windoze boxen may have an extra colon to specify the drive letter. the - # solution is to count colons from the *right* of the string, not the left. see issue #299. - template_path = caller.find{|c| known_extensions.include?(c.split(':')[-3].split('.').last.to_sym) } - template = File.basename(template_path.split(':')[-3]) - template, format = template.split('.') - - # paths previous to current template_path must be ignored to avoid infinite loops when is called twice or more - index = 0 - controller.class.active_scaffold_paths.each_with_index do |active_scaffold_template_path, i| - index = i + 1 and break if template_path.include? active_scaffold_template_path - end - - active_scaffold_template = controller.class.active_scaffold_paths.slice(index..-1).find_template(template, format, false) - render(:file => active_scaffold_template, :locals => options[:locals]) + options[:locals].reverse_merge!(@last_partial[:locals] || {}) + templates = lookup_context.find_all_templates(@last_partial[:partial], nil, true) + @last_partial[:index] = @last_partial[:index].nil? ? 0 : @last_partial[:index] + 1 + options[:template] = templates[@last_partial[:index]] + render options elsif args.first.is_a?(Hash) and args.first[:active_scaffold] require 'digest/md5' options = args.first @@ -63,11 +65,15 @@ def render_with_active_scaffold(*args, &block) end #render_component :controller => remote_controller.to_s, :action => 'table', :params => options[:params] else + options = args.first + @last_partial = {:partial => options[:partial], :index => nil} if options[:partial] + @last_partial[:locals] = options[:locals] if options[:locals] render_without_active_scaffold(*args, &block) end end alias_method_chain :render, :active_scaffold + def partial_pieces(partial_path) if partial_path.include?('/') return File.dirname(partial_path), File.basename(partial_path) From 63a448163d910bde0aca12542969c7e957272ec0 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 16 Jun 2010 10:33:21 +0200 Subject: [PATCH 0429/2024] removed action table --- frontends/default/views/_list_header.html.erb | 2 +- lib/active_scaffold/actions/list.rb | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index 8a09fb71f7..95bb2cb2d5 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -1,6 +1,6 @@ <% if active_scaffold_config.action_links.any? { |link| link.type == :collection } -%> <div class="actions"> - <% new_params = params_for(:action => :table) %> + <% new_params = params_for %> <% active_scaffold_config.action_links.each :collection do |link| -%> <% next if skip_action_link(link) -%> <% next if link.action == 'new' && params[:nested].nil? && active_scaffold_config.list.always_show_create %> diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index cc5184a680..77265f40ca 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -1,18 +1,13 @@ module ActiveScaffold::Actions module List def self.included(base) - base.before_filter :list_authorized_filter, :only => [:index, :table, :row, :list] + base.before_filter :list_authorized_filter, :only => [:index, :row, :list] end def index list end - def table - do_list - render(:action => 'list.html', :layout => false) - end - # get just a single row def row render :partial => 'list_record', :locals => {:record => find_if_allowed(params[:id], :read)} From b3efb72af00e5175acd6d3e081eb0770572d8304 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 16 Jun 2010 12:47:54 +0200 Subject: [PATCH 0430/2024] add option to pass a list of action_links --- frontends/default/views/_list_actions.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 92c73f25e7..a086b3cf74 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -1,9 +1,10 @@ +<% action_links ||= active_scaffold_config.action_links %> <td class="actions"><table cellpadding="0" cellspacing="0"> <tr> <td class="indicator-container"> <%= loading_indicator_tag(:action => :record, :id => record.id) %> </td> - <% active_scaffold_config.action_links.each :member do |link| -%> + <% action_links.each :member do |link| -%> <% next if skip_action_link(link, record) -%> <td> <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : "<a class='disabled #{link.action}'>#{link.label}</a>" -%> From d93c020bc07eb28a634195ad72ccd14adf56f7bd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 16 Jun 2010 12:50:29 +0200 Subject: [PATCH 0431/2024] position reset_search link in line with list action_links --- frontends/default/views/_list.html.erb | 8 +-- .../default/views/_list_messages.html.erb | 49 +++++++++++-------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index 9fbb2f488d..f8a9704d70 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -4,13 +4,7 @@ <%= render :partial => 'list_column_headings' %> </tr> </thead> - <tbody class="messages"> - <tr> - <td colspan="<%= active_scaffold_config.list.columns.length + 1 -%>" class="messages-container"> - <%= render :partial => 'list_messages' %> - </td> - </tr> - </tbody> + <%= render :partial => 'list_messages' %> <tbody class="records" id="<%= active_scaffold_tbody_id %>"> <% if !@records.empty? -%> <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false, :dont_show_calculations => true } %> diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index a8d7bb3c1f..cb3a105955 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -1,21 +1,28 @@ - <div id="<%= active_scaffold_messages_id -%>"> - <%= render :partial => 'messages' %> - </div> - <p class="filtered-message" <%= ' style="display:none;" ' unless @filtered %>> - <%= as_(active_scaffold_config.list.filtered_message) %> - <% if active_scaffold_config.list.show_search_reset -%> - <% href = url_for(params_for(:action => :index, :escape => false, :search => '')) -%> - <%= link_to as_(:click_to_reset), - { :remote => true, - :url => href, - :method => :get, - :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", - :after => "$('#{loading_indicator_id(:action => :table)}').style.visibility = 'visible';", - :complete => "$('#{loading_indicator_id(:action => :table)}').style.visibility = 'hidden';", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')" - }, :href => href %> - <% end -%> - </p> - <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" ' unless @page.items.empty? %>> - <%= as_(active_scaffold_config.list.no_entries_message) %> - </p> +<tbody class="messages"> + <tr class="record even-record"> + <td colspan="<%= active_scaffold_config.list.columns.length -%>" class="messages-container"> + <div id="<%= active_scaffold_messages_id -%>"> + <%= render :partial => 'messages' %> + </div> + <p class="filtered-message" <%= ' style="display:none;" ' unless @filtered %>> + <%= as_(active_scaffold_config.list.filtered_message) %> + </p> + <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" ' unless @page.items.empty? %>> + <%= as_(active_scaffold_config.list.no_entries_message) %> + </p> + </td> + <% if active_scaffold_config.list.show_search_reset -%> + <% search_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :member, :position => false) + action_links = ActiveScaffold::DataStructures::ActionLinks.new + record = active_scaffold_config.model.new + record.id = 0 + action_links.add(search_link) -%> + <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links} %> + <% else %> + <td></td> + <% end -%> + + </tr> +</tbody> + + From 212a6c9d3a638d23d7310572123a51e212b1df8d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 16 Jun 2010 14:14:09 +0200 Subject: [PATCH 0432/2024] Add column.update_column and deprecate column.options[:update_column] --- frontends/default/views/render_field.js.rjs | 2 +- lib/active_scaffold/data_structures/column.rb | 3 +++ lib/active_scaffold/helpers/form_column_helpers.rb | 4 ++-- lib/active_scaffold/helpers/list_column_helpers.rb | 3 +-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/render_field.js.rjs b/frontends/default/views/render_field.js.rjs index aa4449435e..b52646d6f8 100644 --- a/frontends/default/views/render_field.js.rjs +++ b/frontends/default/views/render_field.js.rjs @@ -8,7 +8,7 @@ field_id = active_scaffold_input_options(column, params[:scope])[:id] page[field_id].up('dl').replace :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } end - column = Hash === column.options ? column.options[:update_column] : nil + column = column.update_column column = active_scaffold_config.columns[column] if column end end diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 85bcd0d798..c996ab1534 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -53,6 +53,9 @@ def required? @required end + # column to be updated in a form when this column change + attr_accessor :update_column + # sorting on a column can be configured four ways: # sort = true default, uses intelligent sorting sql default # sort = false sometimes sorting doesn't make sense diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 1ca922f45f..0f2219c147 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -76,10 +76,10 @@ def active_scaffold_input_options(column, scope = nil, options = {}) end def javascript_for_update_column(column, scope, options) - if column.options[:update_column] + if column.update_column form_action = :create form_action = :update if params[:action] == 'edit' - url_params = {:action => 'render_field', :id => params[:id], :column => column.name, :update_column => column.options[:update_column]} + url_params = {:action => 'render_field', :id => params[:id], :column => column.name, :update_column => column.update_column} url_params[:eid] = params[:eid] if params[:eid] url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope url_params[:scope] = params[:scope] if scope diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index c151dec9d4..bd7f2953b7 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -299,8 +299,7 @@ def inplace_edit_control(column) if inplace_edit?(active_scaffold_config.model, column) and inplace_edit_cloning?(column) @record = active_scaffold_config.model.new column = column.clone - column.options = column.options.clone - column.options.delete(:update_column) + column.update_column = nil column.form_ui = :select if (column.association && column.form_ui.nil?) content_tag(:div, active_scaffold_input_for(column), {:style => "display:none;", :class => inplace_edit_control_css_class}) end From 79664bc4ed35215761138f595db290896950f274 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 16 Jun 2010 14:18:52 +0200 Subject: [PATCH 0433/2024] safety check for hide_empty message --- frontends/default/javascripts/active_scaffold.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 8d13e1c329..597f8c4722 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -157,7 +157,8 @@ var ActiveScaffold = { }, hide_empty_message: function(tbody, empty_message_id) { if (this.records_for(tbody).length != 0) { - $(empty_message_id).hide(); + var empty_message_node = $(empty_message_id) + if (empty_message_node) empty_message_node.hide(); } }, reload_if_empty: function(tbody, url) { From a93f80dc07111c24485cae783e7e34ccee737ea8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 16 Jun 2010 14:19:28 +0200 Subject: [PATCH 0434/2024] fix hiding list messages --- frontends/default/stylesheets/stylesheet.css | 4 ++++ frontends/default/views/_list_messages.html.erb | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 560bdb2cb0..b713c33fd0 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -202,6 +202,10 @@ border-bottom: solid 1px #C5DBF7; border-left: solid 1px #C5DBF7; } +.active-scaffold tr.record td.messages-container { +padding: 0px; +} + .active-scaffold tr.even-record { background-color: #fff; } diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index cb3a105955..e2f5a0d299 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -4,14 +4,14 @@ <div id="<%= active_scaffold_messages_id -%>"> <%= render :partial => 'messages' %> </div> - <p class="filtered-message" <%= ' style="display:none;" ' unless @filtered %>> + <p class="filtered-message" <%= ' style="display:none;" '.html_safe unless @filtered %>> <%= as_(active_scaffold_config.list.filtered_message) %> </p> - <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" ' unless @page.items.empty? %>> + <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" '.html_safe unless @page.items.empty? %>> <%= as_(active_scaffold_config.list.no_entries_message) %> </p> </td> - <% if active_scaffold_config.list.show_search_reset -%> + <% if active_scaffold_config.list.show_search_reset && @filtered -%> <% search_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :member, :position => false) action_links = ActiveScaffold::DataStructures::ActionLinks.new record = active_scaffold_config.model.new @@ -19,7 +19,7 @@ action_links.add(search_link) -%> <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links} %> <% else %> - <td></td> + <td class='actions'></td> <% end -%> </tr> From 05de84abbc6dc23fe081cc856b7a07eae71712d1 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 16 Jun 2010 15:20:54 +0200 Subject: [PATCH 0435/2024] syntax error in partial --- frontends/default/views/_create_form_on_list.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_create_form_on_list.html.erb b/frontends/default/views/_create_form_on_list.html.erb index a87517cb23..cbfe9bf744 100644 --- a/frontends/default/views/_create_form_on_list.html.erb +++ b/frontends/default/views/_create_form_on_list.html.erb @@ -2,4 +2,4 @@ :form_action => form_action ||= :create, :method => method ||= :post, :cancel_link => cancel_link ||= false, - :headline => headline ||= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil) %> \ No newline at end of file + :headline => headline ||= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil)} %> \ No newline at end of file From 5309af17694b6da90196fda7b148162bcd5244f9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 16 Jun 2010 15:59:58 +0200 Subject: [PATCH 0436/2024] move code to hide create/search table actions to security method --- frontends/default/views/_list_header.html.erb | 2 -- lib/active_scaffold/actions/common_search.rb | 6 +++++- lib/active_scaffold/actions/create.rb | 6 +++++- lib/active_scaffold/actions/search.rb | 5 ----- lib/active_scaffold/config/list.rb | 1 - 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index 95bb2cb2d5..39693ebc51 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -3,8 +3,6 @@ <% new_params = params_for %> <% active_scaffold_config.action_links.each :collection do |link| -%> <% next if skip_action_link(link) -%> - <% next if link.action == 'new' && params[:nested].nil? && active_scaffold_config.list.always_show_create %> - <% next if link.action == 'show_search' && active_scaffold_config.list.always_show_search %> <%= render_action_link(link, new_params) -%> <% end -%> diff --git a/lib/active_scaffold/actions/common_search.rb b/lib/active_scaffold/actions/common_search.rb index 05cbe00ab0..a6dce7e2c3 100644 --- a/lib/active_scaffold/actions/common_search.rb +++ b/lib/active_scaffold/actions/common_search.rb @@ -12,7 +12,11 @@ def search_params # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def search_authorized? - authorized_for?(:crud_type => :read) + if active_scaffold_config.list.always_show_search + false + else + authorized_for?(:crud_type => :read) + end end end end diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 9017762fdf..c8d3da73c3 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -122,7 +122,11 @@ def after_create_save(record); end # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def create_authorized? - authorized_for?(:crud_type => :create) + if params[:nested].nil? && active_scaffold_config.list.always_show_create + false + else + authorized_for?(:crud_type => :create) + end end private def create_authorized_filter diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index df11bb2fcd..df42083434 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -36,11 +36,6 @@ def do_search end end - # The default security delegates to ActiveRecordPermissions. - # You may override the method to customize. - def search_authorized? - authorized_for?(:crud_type => :read) - end private def search_authorized_filter link = active_scaffold_config.search.link || active_scaffold_config.search.class.link diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index e122584969..e4ef51b728 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -106,7 +106,6 @@ def always_show_search def search_partial return "search" if @core.actions.include?(:search) - return "live_search" if @core.actions.include?(:live_search) return "field_search" if @core.actions.include?(:field_search) end From fb6c11d2f22ff4b6d0e15308ea95d4a5cf9e2125 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 16 Jun 2010 16:26:58 +0200 Subject: [PATCH 0437/2024] Option to send all the form instead of single value when a column changes --- lib/active_scaffold/actions/core.rb | 8 ++++++-- lib/active_scaffold/data_structures/column.rb | 7 ++++++- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index d65e2f75a0..cce09cb9ef 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -16,8 +16,12 @@ def render_field if params[:in_place_editing] render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>" elsif !column.nil? - value = column_value_from_param_value(@record, column, params[:value]) - @record.send "#{column.name}=", value + if column.send_form_on_update_column + @record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record]) + else + value = column_value_from_param_value(@record, column, params[:value]) + @record.send "#{column.name}=", value + end @update_columns << Array(params[:update_column]).collect {|column_name| active_scaffold_config.columns[column_name.to_sym]} @update_columns.flatten! after_render_field(@record, column) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index c996ab1534..2b3bdf2fdd 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -53,9 +53,13 @@ def required? @required end - # column to be updated in a form when this column change + # column to be updated in a form when this column changes attr_accessor :update_column + # send all the form instead of only new value when this column change + cattr_accessor :send_form_on_update_column + attr_accessor :send_form_on_update_column + # sorting on a column can be configured four ways: # sort = true default, uses intelligent sorting sql default # sort = false sometimes sorting doesn't make sense @@ -247,6 +251,7 @@ def initialize(name, active_record_class) #:nodoc: @associated_limit = self.class.associated_limit @associated_number = self.class.associated_number @show_blank_record = self.class.show_blank_record + @send_form_on_update_column = self.class.send_form_on_update_column @actions_for_association_links = self.class.actions_for_association_links.clone if @association @options = {:format => :i18n_number} if @column.try(:number?) @form_ui = :checkbox if @column and @column.type == :boolean diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 0f2219c147..2597d60464 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -84,7 +84,7 @@ def javascript_for_update_column(column, scope, options) url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope url_params[:scope] = params[:scope] if scope ajax_options = {:method => :get, - :url => url_for(url_params), :with => "'value=' + this.value", + :url => url_for(url_params), :with => column.send_form_on_update_column ? "Form.serialize(this.form)" : "'value=' + this.value", :after => "$('#{loading_indicator_id(:action => :render_field, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => form_action)}');", :complete => "$('#{loading_indicator_id(:action => :render_field, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => form_action)}');"} options[:onchange] = "#{remote_function(ajax_options)};#{options[:onchange]}" From c8c85e61d8b4deacee28787548576e143c4c5e35 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 16 Jun 2010 16:52:39 +0200 Subject: [PATCH 0438/2024] Fix multiple chaining with array in update_column --- frontends/default/views/_render_fields.js.rjs | 11 +++++++++++ frontends/default/views/render_field.js.rjs | 15 +-------------- lib/active_scaffold/actions/core.rb | 4 +--- 3 files changed, 13 insertions(+), 17 deletions(-) create mode 100644 frontends/default/views/_render_fields.js.rjs diff --git a/frontends/default/views/_render_fields.js.rjs b/frontends/default/views/_render_fields.js.rjs new file mode 100644 index 0000000000..884a6ae3e1 --- /dev/null +++ b/frontends/default/views/_render_fields.js.rjs @@ -0,0 +1,11 @@ +render_fields.each do |column_name| + column = active_scaffold_config.columns[column_name.to_sym] + if column_renders_as(column) == :subform + field_id = sub_form_id(:association => column.name) + page[field_id].replace_html :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } + else + field_id = active_scaffold_input_options(column, params[:scope])[:id] + page[field_id].up('dl').replace :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } + end + page << render(:partial => 'render_fields.js', :object => Array(column.update_column)) if column.update_column +end diff --git a/frontends/default/views/render_field.js.rjs b/frontends/default/views/render_field.js.rjs index b52646d6f8..fe381fa762 100644 --- a/frontends/default/views/render_field.js.rjs +++ b/frontends/default/views/render_field.js.rjs @@ -1,14 +1 @@ -@update_columns.each do |update_column| - column = update_column - while column - if column_renders_as(column) == :subform - field_id = sub_form_id(:association => column.name) - page[field_id].replace_html :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } - else - field_id = active_scaffold_input_options(column, params[:scope])[:id] - page[field_id].up('dl').replace :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } - end - column = column.update_column - column = active_scaffold_config.columns[column] if column - end -end +page << render(:partial => 'render_fields.js', :object => @update_columns) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index cce09cb9ef..e1d9557bde 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -11,7 +11,6 @@ def render_field else active_scaffold_config.model.new end - @update_columns = [] column = active_scaffold_config.columns[params[:column]] if params[:in_place_editing] render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>" @@ -22,8 +21,7 @@ def render_field value = column_value_from_param_value(@record, column, params[:value]) @record.send "#{column.name}=", value end - @update_columns << Array(params[:update_column]).collect {|column_name| active_scaffold_config.columns[column_name.to_sym]} - @update_columns.flatten! + @update_columns = Array(params[:update_column]) after_render_field(@record, column) end end From 317f8bd63f3e385377d0dd952b637ea6a4fe1f90 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 17 Jun 2010 09:58:32 +0200 Subject: [PATCH 0439/2024] column sorting in Rails 3.0 --- .../default/javascripts/active_scaffold.js | 12 ++++++++++++ .../views/_list_column_headings.html.erb | 17 ++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 597f8c4722..8016857a27 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -119,6 +119,18 @@ document.observe("dom:loaded", function() { } return true; }); + document.on('ajax:before', 'a.as_sort', function(event) { + var as_sort = event.findElement(); + var history_controller_id = as_sort.readAttribute('data-page-history'); + if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.readAttribute('href'), history_controller_id); + as_sort.up('th').addClassName('loading'); + return true; + }); + document.on('ajax:failure', 'a.as_sort', function(event) { + var as_scaffold = event.findElement('.active-scaffold'); + ActiveScaffold.report_500_response(as_scaffold); + return true; + }); }); diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index c33b55a1ae..38c0a624a6 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -8,21 +8,16 @@ default_sorting_stages = ['ASC', 'DESC'] <% stages = default_sorting.sorts_on?(column) ? default_sorting_stages : sorting_stages column_sort_direction = stages.after(sorting.direction_of(column)) || 'ASC' - sort_params = params_for(:action => :index, :page => 1, + url_options = params_for(:action => :index, :page => 1, :sort => column.name, :sort_direction => column_sort_direction) column_header_id = active_scaffold_column_header_id(column) -%> - <th id="<%= column_header_id %>" class="<%= column.css_class unless column.css_class.nil? %> <%= "sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column %>" title="<%= h column.description %>"> + <th id="<%= column_header_id %>" class="<%= column.css_class unless column.css_class.nil? %><%= " sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column %>" title="<%= h column.description %>"> <% if column.sortable? -%> - <% href = url_for(sort_params) -%> - <%= link_to column.label, - { :remote => true, - :url => sort_params, - :before => "addActiveScaffoldPageToHistory('#{href}', '#{controller_id}')", - :loading => "Element.addClassName('#{column_header_id}','loading');", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :method => :get }, - { :href => href } %> + <% options = {:id => search_form_id, :class => "as_sort", + 'data-page-history' => controller_id, + :remote => true, :method => :get} -%> + <%= link_to column.label, url_options, options -%> <% else -%> <% if column.name != :marked -%> <p><%= column.label %></p> From af06b06c4601cd16622f04ed4ac47346f8b8f3ff Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 17 Jun 2010 10:03:14 +0200 Subject: [PATCH 0440/2024] removed commented javascript code --- frontends/default/views/_form_association_footer.html.erb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index 761e1cd485..cdebe05281 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -34,7 +34,3 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as <% end -%> </div> </div> - -<script type="text/javascript"> -//Rico.Corner.round($$('#<%= sub_form_id(:association => column.name) %> .footer-wrapper').first(), {color: 'fromElement', bgColor: 'fromParent', compact: false}); -</script> From 851a502d0f140bb0102bfc165811ebba87c5614a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 17 Jun 2010 10:13:47 +0200 Subject: [PATCH 0441/2024] only add javascript tag if there are calculations defined --- frontends/default/views/_list_record.html.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 0fcc0404fe..baff9a5b19 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -10,10 +10,12 @@ url_options = params_for(:action => :list, :id => record.id) <%= render :partial => 'list_record_columns', :locals => {:record => record} %> <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options} if active_scaffold_config.action_links.any? {|link| link.type == :member } %> </tr> +<% if not dont_show_calculations and active_scaffold_config.list.columns.any? {|c| c.calculation?} %> <script type="text/javascript"> //<![CDATA[ <%= update_page do |page| page.replace active_scaffold_calculations_id, :partial => 'list_calculations' - end if not dont_show_calculations and active_scaffold_config.list.columns.any? {|c| c.calculation?} %> + end %> //]]> </script> +<% end %> From b8c5ab17067671e382bfb5a2dfbe4e9149ad229d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 17 Jun 2010 10:17:21 +0200 Subject: [PATCH 0442/2024] remove rico_corner code --- frontends/default/views/_list_with_header.html.erb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/frontends/default/views/_list_with_header.html.erb b/frontends/default/views/_list_with_header.html.erb index 9f473a29ff..2408906fe2 100644 --- a/frontends/default/views/_list_with_header.html.erb +++ b/frontends/default/views/_list_with_header.html.erb @@ -33,10 +33,6 @@ <script type="text/javascript"> //<![CDATA[ -<% if active_scaffold_config.theme != :default -%> -Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-header').first(), {color: 'fromElement', bgColor: 'fromParent', corners: 'top', compact: true}); -Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-footer').first(), {color: 'fromElement', bgColor: 'fromParent', corners: 'bottom', compact: true}); -<% end -%> new ActiveScaffold.Actions.Table($$('#<%= active_scaffold_id -%> div.active-scaffold-header a.as_action'), $('<%= before_header_id -%>'), $('<%= loading_indicator_id(:action => :table) -%>')); ActiveScaffold.server_error_response = '<p class="error-message message">' + <%= as_(:internal_error).to_json.html_safe %> From b7616488a90f1a1ec699e9ef53c0825d02387b58 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 17 Jun 2010 11:55:34 +0200 Subject: [PATCH 0443/2024] UJS: generate Table ActionLinks js objects on the fly --- frontends/default/javascripts/active_scaffold.js | 10 ++++++++++ frontends/default/views/_list_with_header.html.erb | 1 - 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 8016857a27..e4accef942 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -41,6 +41,16 @@ document.observe("dom:loaded", function() { }); document.on('ajax:before', 'a.as_action', function(event) { var as_action = event.findElement(); + if (typeof(as_action.action_link) === 'undefined') { + var parent = as_action.up(); + if (parent && parent.nodeName.toUpperCase() == 'TD') { + // record action + } else if (parent && parent.nodeName.toUpperCase() == 'DIV') { + //table action + new ActiveScaffold.Actions.Table(parent.select('a.as_action'), parent.up('div.active-scaffold').down('tbody.before-header'), parent.down('.loading-indicator')); + } + as_action = event.findElement(); + } if (as_action.action_link) { var action_link = as_action.action_link; if (action_link.is_disabled()) { diff --git a/frontends/default/views/_list_with_header.html.erb b/frontends/default/views/_list_with_header.html.erb index 2408906fe2..d74f361e0d 100644 --- a/frontends/default/views/_list_with_header.html.erb +++ b/frontends/default/views/_list_with_header.html.erb @@ -33,7 +33,6 @@ <script type="text/javascript"> //<![CDATA[ -new ActiveScaffold.Actions.Table($$('#<%= active_scaffold_id -%> div.active-scaffold-header a.as_action'), $('<%= before_header_id -%>'), $('<%= loading_indicator_id(:action => :table) -%>')); ActiveScaffold.server_error_response = '<p class="error-message message">' + <%= as_(:internal_error).to_json.html_safe %> + '<a href="#" onclick="Element.remove(this.parentNode); return false;">' From 7208112a1ee68612760787d7b4d966666a6b3297 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 17 Jun 2010 12:39:00 +0200 Subject: [PATCH 0444/2024] UJS: generate js list action_link objects on the fly --- frontends/default/javascripts/active_scaffold.js | 4 +++- frontends/default/views/_list_actions.html.erb | 13 ------------- frontends/default/views/_list_record.html.erb | 2 +- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index e4accef942..78d85be697 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -45,6 +45,8 @@ document.observe("dom:loaded", function() { var parent = as_action.up(); if (parent && parent.nodeName.toUpperCase() == 'TD') { // record action + parent = parent.up('tr') + new ActiveScaffold.Actions.Record(parent.select('a.as_action'), parent.up('tr.record'), parent.down('.loading-indicator')); } else if (parent && parent.nodeName.toUpperCase() == 'DIV') { //table action new ActiveScaffold.Actions.Table(parent.select('a.as_action'), parent.up('div.active-scaffold').down('tbody.before-header'), parent.down('.loading-indicator')); @@ -411,7 +413,7 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, { instantiate_link: function(link) { var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); - if (this.options.refresh_url) l.refresh_url = this.options.refresh_url; + if (!this.target.readAttribute('data-refresh').blank()) l.refresh_url = this.target.readAttribute('data-refresh'); if (link.hasClassName('delete')) { l.url = l.url.replace(/\/delete(\?.*)?$/, '$1'); diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index a086b3cf74..1dab9f45bf 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -12,17 +12,4 @@ <% end -%> </tr> </table> - -<% target_id = element_row_id(:action => :list, :id => record.id) -%> - -<script type="text/javascript"> -//<![CDATA[ -new ActiveScaffold.Actions.Record( - $$('#<%= target_id -%> a.as_action'), - $('<%= target_id -%>'), - $('<%= loading_indicator_id(:action => :record, :id => record.id) -%>'), - {refresh_url: '<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get, :escape => false)).html_safe -%>'} -); -//]]> -</script> </td> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index baff9a5b19..a07c5d24cd 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -6,7 +6,7 @@ tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class url_options = params_for(:action => :list, :id => record.id) -%> -<tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>"> +<tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get, :escape => false)).html_safe %>"> <%= render :partial => 'list_record_columns', :locals => {:record => record} %> <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options} if active_scaffold_config.action_links.any? {|link| link.type == :member } %> </tr> From 5dcc613a34ab94285c72cb2d9cdd9c595ab344a9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 17 Jun 2010 14:47:23 +0200 Subject: [PATCH 0445/2024] UJS: server_error messaging --- frontends/default/javascripts/active_scaffold.js | 9 ++++++--- frontends/default/views/_list_messages.html.erb | 4 ++++ frontends/default/views/_list_with_header.html.erb | 11 ----------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 78d85be697..5e52f3c4e7 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -222,10 +222,13 @@ var ActiveScaffold = { new_row.highlight(); }, - server_error_response: '', report_500_response: function(active_scaffold_id) { - messages_container = $(active_scaffold_id).down('td.messages-container'); - new Insertion.Top(messages_container, this.server_error_response); + server_error = $(active_scaffold_id).down('td.messages-container p.server-error'); + if (server_error.visible()) { + server_error.highlight(); + } else { + server_error.show(); + } } } diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index e2f5a0d299..d7ab315e31 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -1,6 +1,10 @@ <tbody class="messages"> <tr class="record even-record"> <td colspan="<%= active_scaffold_config.list.columns.length -%>" class="messages-container"> + <p class="error-message message server-error" style="display:none;"> + <%= as_(:internal_error).html_safe %> + <a href="#" onclick="Element.hide(this.parentNode); return false;" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a> + </p> <div id="<%= active_scaffold_messages_id -%>"> <%= render :partial => 'messages' %> </div> diff --git a/frontends/default/views/_list_with_header.html.erb b/frontends/default/views/_list_with_header.html.erb index d74f361e0d..043f7fffc1 100644 --- a/frontends/default/views/_list_with_header.html.erb +++ b/frontends/default/views/_list_with_header.html.erb @@ -30,14 +30,3 @@ <%= render :partial => 'list' %> </div> </div> - -<script type="text/javascript"> -//<![CDATA[ -ActiveScaffold.server_error_response = '<p class="error-message message">' - + <%= as_(:internal_error).to_json.html_safe %> - + '<a href="#" onclick="Element.remove(this.parentNode); return false;">' - + <%= as_(:close).to_json.html_safe %> - + '</a>' - + '</p>'; -//]]> -</script> From 0d12cb1c17ef12158aa486ae95fc13280bce71c7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 18 Jun 2010 10:42:19 +0200 Subject: [PATCH 0446/2024] move delete_record_row and add_record_row to javascript --- .../default/javascripts/active_scaffold.js | 36 ++++++++++++++++--- frontends/default/views/_list.html.erb | 2 +- frontends/default/views/_list_record.html.erb | 10 ------ frontends/default/views/_row.html.erb | 12 +++++++ frontends/default/views/add_existing.js.rjs | 7 ++-- frontends/default/views/destroy.js.rjs | 7 +--- frontends/default/views/on_create.js.rjs | 8 ++--- lib/active_scaffold/actions/list.rb | 2 +- 8 files changed, 52 insertions(+), 32 deletions(-) create mode 100644 frontends/default/views/_row.html.erb diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 5e52f3c4e7..9b910e32e1 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -32,7 +32,7 @@ document.observe("dom:loaded", function() { } }); document.on('ajax:failure', 'form.as_form', function(event) { - var as_div = event.findElement('div.activescaffold'); + var as_div = event.findElement('div.active-scaffold'); if (as_div) { ActiveScaffold.report_500_response(as_div) event.stop(); @@ -59,7 +59,7 @@ document.observe("dom:loaded", function() { event.stop(); } else { if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'visible'; - if (action_link.position) action_link.disable(); + action_link.disable(); } } return true; @@ -73,6 +73,7 @@ document.observe("dom:loaded", function() { if (action_link.hide_target) action_link.target.hide(); } else { event.memo.request.evalResponse(); + action_link.enable(); } event.stop(); } @@ -91,7 +92,7 @@ document.observe("dom:loaded", function() { if (as_action.action_link) { var action_link = as_action.action_link; ActiveScaffold.report_500_response(action_link.scaffold_id()); - if (action_link.position) action_link.enable(); + action_link.enable(); } return true; }); @@ -179,9 +180,9 @@ var ActiveScaffold = { } } }, - hide_empty_message: function(tbody, empty_message_id) { + hide_empty_message: function(tbody) { if (this.records_for(tbody).length != 0) { - var empty_message_node = $(empty_message_id) + var empty_message_node = $(tbody).up().down('tbody.messages p.empty-message') if (empty_message_node) empty_message_node.hide(); } }, @@ -221,6 +222,31 @@ var ActiveScaffold = { if (row.hasClassName('even-record')) new_row.addClassName('even-record'); new_row.highlight(); }, + + create_record_row: function(tbody, html) { + tbody = $(tbody); + tbody.insert({top: html}); + + var new_row = tbody.firstDescendant(); + this.stripe(tbody); + this.hide_empty_message(tbody); + this.increment_record_count(tbody.up('div.active-scaffold')); + new_row.highlight(); + }, + + delete_record_row: function(row, page_reload_url) { + row = $(row); + var tbody = row.up('tbody.records'); + + var current_action_node = row.down('td.actions a.disabled'); + if (current_action_node && current_action_node.action_link) { + current_action_node.action_link.close_previous_adapter(); + } + row.remove(); + this.reload_if_empty(tbody, page_reload_url); + this.stripe(tbody); + this.decrement_record_count(tbody.up('div.active-scaffold')); + }, report_500_response: function(active_scaffold_id) { server_error = $(active_scaffold_id).down('td.messages-container p.server-error'); diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index f8a9704d70..45f8d2213b 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -7,7 +7,7 @@ <%= render :partial => 'list_messages' %> <tbody class="records" id="<%= active_scaffold_tbody_id %>"> <% if !@records.empty? -%> - <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false, :dont_show_calculations => true } %> + <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false} %> <% end -%> <% if active_scaffold_config.list.columns.any? {|c| c.calculation?} -%> <%= render :partial => 'list_calculations' %> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index a07c5d24cd..60d9a46936 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -1,6 +1,5 @@ <% record = list_record if list_record # compat with render :partial :collection -dont_show_calculations ||= false tr_class = cycle("", "even-record") tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class url_options = params_for(:action => :list, :id => record.id) @@ -10,12 +9,3 @@ url_options = params_for(:action => :list, :id => record.id) <%= render :partial => 'list_record_columns', :locals => {:record => record} %> <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options} if active_scaffold_config.action_links.any? {|link| link.type == :member } %> </tr> -<% if not dont_show_calculations and active_scaffold_config.list.columns.any? {|c| c.calculation?} %> -<script type="text/javascript"> -//<![CDATA[ - <%= update_page do |page| - page.replace active_scaffold_calculations_id, :partial => 'list_calculations' - end %> -//]]> -</script> -<% end %> diff --git a/frontends/default/views/_row.html.erb b/frontends/default/views/_row.html.erb new file mode 100644 index 0000000000..8972fd5b93 --- /dev/null +++ b/frontends/default/views/_row.html.erb @@ -0,0 +1,12 @@ +<%= render :partial => 'list_record', :locals => {:record => record}%> +<% if active_scaffold_config.list.columns.any? {|c| c.calculation?} %> +<script type="text/javascript"> +//<![CDATA[ + <%= update_page do |page| + page.replace active_scaffold_calculations_id, :partial => 'list_calculations' + end %> +//]]> +</script> +<% end %> + + diff --git a/frontends/default/views/add_existing.js.rjs b/frontends/default/views/add_existing.js.rjs index aaee3cf6f0..abf5abfaff 100644 --- a/frontends/default/views/add_existing.js.rjs +++ b/frontends/default/views/add_existing.js.rjs @@ -1,7 +1,6 @@ -page.insert_html :top, active_scaffold_tbody_id, :partial => 'list_record', :locals => {:record => @record} -page << "ActiveScaffold.stripe($('#{active_scaffold_tbody_id}'))" -page << "ActiveScaffold.hide_empty_message('#{active_scaffold_tbody_id}','#{empty_message_id}');" -page << "ActiveScaffold.increment_record_count('#{active_scaffold_id}');" +new_row = render :partial => 'list_record', :locals => {:record => @record} +page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}');" +page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} if (form_stays_open = true) # why not just re-render the form? that wouldn't utilize a possible do_new override which sets default values. diff --git a/frontends/default/views/destroy.js.rjs b/frontends/default/views/destroy.js.rjs index caf67eed90..0a58c81287 100644 --- a/frontends/default/views/destroy.js.rjs +++ b/frontends/default/views/destroy.js.rjs @@ -1,10 +1,5 @@ if controller.send(:successful?) - page << "$('#{action_link_id((respond_to?(:nested_habtm?) and nested_habtm? and active_scaffold_config.nested.shallow_delete) ? 'destroy_existing' : 'delete', params[:id])}').action_link.close_previous_adapter();" - page.remove element_row_id(:action => 'list', :id => params[:id]) - page << "ActiveScaffold.reload_if_empty('#{active_scaffold_tbody_id}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" - page << "ActiveScaffold.stripe('#{active_scaffold_tbody_id}');" - page << "ActiveScaffold.decrement_record_count('#{active_scaffold_id}');" + page << "ActiveScaffold.delete_record_row('#{element_row_id(:action => 'list', :id => params[:id])}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} end - page.replace_html active_scaffold_messages_id, :partial => 'messages' diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index bbebc1a7a2..8f2cc5daf1 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -3,11 +3,9 @@ form_selector = "#{element_form_id(:action => :create)}" page << "$('#{form_selector}').up('.as_adapter').action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? if @insert_row - page.insert_html :top, active_scaffold_tbody_id, :partial => 'list_record', :locals => {:record => @record} - page << "ActiveScaffold.stripe($('#{active_scaffold_tbody_id}'))" - page << "ActiveScaffold.hide_empty_message('#{active_scaffold_tbody_id}','#{empty_message_id}');" - page << "ActiveScaffold.increment_record_count('#{active_scaffold_id}');" - page[element_row_id(:action => :list, :id => @record.id)].highlight + new_row = render :partial => 'list_record', :locals => {:record => @record} + page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}');" + page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} end if (active_scaffold_config.create.persistent) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 77265f40ca..dc9d232af4 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -10,7 +10,7 @@ def index # get just a single row def row - render :partial => 'list_record', :locals => {:record => find_if_allowed(params[:id], :read)} + render :partial => 'row', :locals => {:record => find_if_allowed(params[:id], :read)} end def list From f8b173cb1f7483b752f04f901c86429cc0c8f419 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 18 Jun 2010 13:11:12 +0200 Subject: [PATCH 0447/2024] add option to ignore an action_link --- lib/active_scaffold/actions/common_search.rb | 10 +++++----- lib/active_scaffold/actions/create.rb | 11 ++++++----- lib/active_scaffold/config/create.rb | 2 +- lib/active_scaffold/config/field_search.rb | 2 +- lib/active_scaffold/config/search.rb | 2 +- lib/active_scaffold/data_structures/action_link.rb | 4 +++- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/active_scaffold/actions/common_search.rb b/lib/active_scaffold/actions/common_search.rb index a6dce7e2c3..d6fa8adac9 100644 --- a/lib/active_scaffold/actions/common_search.rb +++ b/lib/active_scaffold/actions/common_search.rb @@ -9,14 +9,14 @@ def search_params active_scaffold_session_storage[:search] end + def search_ignore? + active_scaffold_config.list.always_show_search + end + # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def search_authorized? - if active_scaffold_config.list.always_show_search - false - else - authorized_for?(:crud_type => :read) - end + authorized_for?(:crud_type => :read) end end end diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index c8d3da73c3..144d4ed23e 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -121,12 +121,13 @@ def after_create_save(record); end # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. + + def create_ignore? + params[:nested].nil? && active_scaffold_config.list.always_show_create + end + def create_authorized? - if params[:nested].nil? && active_scaffold_config.list.always_show_create - false - else - authorized_for?(:crud_type => :create) - end + authorized_for?(:crud_type => :create) end private def create_authorized_filter diff --git a/lib/active_scaffold/config/create.rb b/lib/active_scaffold/config/create.rb index f76d7d5786..c34ab412ac 100644 --- a/lib/active_scaffold/config/create.rb +++ b/lib/active_scaffold/config/create.rb @@ -16,7 +16,7 @@ def self.link def self.link=(val) @@link = val end - @@link = ActiveScaffold::DataStructures::ActionLink.new('new', :label => :create_new, :type => :collection, :security_method => :create_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('new', :label => :create_new, :type => :collection, :security_method => :create_authorized?, :ignore_method => :create_ignore?) # whether the form stays open after a create or not cattr_accessor :persistent diff --git a/lib/active_scaffold/config/field_search.rb b/lib/active_scaffold/config/field_search.rb index 1286b68829..d973666b95 100644 --- a/lib/active_scaffold/config/field_search.rb +++ b/lib/active_scaffold/config/field_search.rb @@ -16,7 +16,7 @@ def initialize(core_config) # -------------------------- # the ActionLink for this action cattr_reader :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?, :ignore_method => :search_ignore?) # A flag for how the search should do full-text searching in the database: # * :full: LIKE %?% diff --git a/lib/active_scaffold/config/search.rb b/lib/active_scaffold/config/search.rb index 3447ed697f..d30c0d4bb0 100644 --- a/lib/active_scaffold/config/search.rb +++ b/lib/active_scaffold/config/search.rb @@ -17,7 +17,7 @@ def initialize(core_config) # -------------------------- # the ActionLink for this action cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('show_search', :label => :search, :type => :collection, :security_method => :search_authorized?, :ignore_method => :search_ignore?) # A flag for how the search should do full-text searching in the database: # * :full: LIKE %?% diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 31444f1b91..767d291ea9 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -70,7 +70,9 @@ def security_method def security_method_set? !!@security_method end - + + attr_accessor :ignore_method + # the crud type of the (eventual?) action. different than :method, because this crud action may not be imminent. # this is used to determine record-level authorization (e.g. record.authorized_for?(:crud_type => link.crud_type). # options are :create, :read, :update, and :delete diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index f1fb0a671c..ce665cd9c5 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -124,7 +124,7 @@ def link_to_visibility_toggle(options = {}) end def skip_action_link(link, *args) - (link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args) + (!link.ignore_method.nil? and controller.try(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args)) end def render_action_link(link, url_options, record = nil, html_options = {}) From 51396ee766218be79e2be9afed52dc4b79d491e5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 18 Jun 2010 16:08:54 +0200 Subject: [PATCH 0448/2024] Layout Fix in case user is nt authorized to read all list_columns --- .../data_structures/action_columns.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index 6575c41121..e41ae15eb6 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -15,7 +15,7 @@ def label # Whether this column set is collapsed by default in contexts where collapsing is supported attr_accessor :collapsed - + # nests a subgroup in the column set def add_subgroup(label, &proc) columns = ActiveScaffold::DataStructures::ActionColumns.new @@ -60,7 +60,7 @@ module AfterConfiguration # * :for - the record (or class) being iterated over. used for column-level security. default is the class. def each(options = {}, &proc) options[:for] ||= @columns.active_record_class - + self.unauthorized_columns = [] @set.each do |item| unless item.is_a? ActiveScaffold::DataStructures::ActionColumns item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class)) @@ -69,7 +69,10 @@ def each(options = {}, &proc) # skip if this matches the field_name of a constrained column next if item.field_name and constraint_columns.include?(item.field_name.to_sym) # skip this field if it's not authorized - next unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.crud_type, :column => item.name) + unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.crud_type, :column => item.name) + self.unauthorized_columns << item.name.to_sym + next + end end if item.is_a? ActiveScaffold::DataStructures::ActionColumns and options.has_key?(:flatten) and options[:flatten] item.each(options, &proc) @@ -78,6 +81,8 @@ def each(options = {}, &proc) end end end + + # registers a set of column objects (recursively, for all nested ActionColumns) def set_columns(columns) @@ -93,8 +98,13 @@ def constraint_columns @constraint_columns ||= [] end + attr_writer :unauthorized_columns + def unauthorized_columns + @unauthorized_columns ||= [] + end + def length - (@set - self.constraint_columns).length + ((@set - self.constraint_columns) - self.unauthorized_columns).length end end end From 6773bc4eecf4e4bf651121a866d7a9e938cd8e6a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 21 Jun 2010 09:55:36 +0200 Subject: [PATCH 0449/2024] Make Pagination work with rails_xss --- README | 2 +- init.rb | 4 ++-- lib/active_scaffold/helpers/pagination_helpers.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README b/README index f30d06d384..806d5b126d 100644 --- a/README +++ b/README @@ -20,7 +20,7 @@ http://code.google.com/p/recordselect/ Please note the following list of Active Scaffold branches and Rails versions. Master will not work with Rails < 2.2 -Active Scaffold master currently supports rails-2.3.5, but incompatible changes can be introduced, if you want an stable version, use rails-2.3 +Active Scaffold master currently supports rails-2.3.8, but incompatible changes can be introduced, if you want an stable version, use rails-2.3 Rails 2.3.*: Active Scaffold rails-2.3 Rails 2.2.*: Active Scaffold rails-2.2 Rails 2.1.*: Active Scaffold rails-2.1 diff --git a/init.rb b/init.rb index 019d73a582..9b147c724b 100755 --- a/init.rb +++ b/init.rb @@ -1,8 +1,8 @@ ## ## Initialize the environment ## -unless Rails::VERSION::MAJOR == 2 && Rails::VERSION::MINOR >= 3 - raise "This version of ActiveScaffold requires Rails 2.3 or higher. Please use an earlier version." +unless Rails::VERSION::MAJOR == 2 && Rails::VERSION::MINOR >= 3 && Rails::VERSION::TINY >= 8 + raise "This version of ActiveScaffold requires Rails 2.3.8 or higher. Please use an earlier version." end require File.dirname(__FILE__) + '/environment' diff --git a/lib/active_scaffold/helpers/pagination_helpers.rb b/lib/active_scaffold/helpers/pagination_helpers.rb index aba87ad5df..cedd105854 100644 --- a/lib/active_scaffold/helpers/pagination_helpers.rb +++ b/lib/active_scaffold/helpers/pagination_helpers.rb @@ -56,7 +56,7 @@ def pagination_ajax_links(current_page, params, window_size) html << ".." unless end_number >= current_page.pager.last.number - 1 html << pagination_ajax_link(current_page.pager.last.number, params) unless end_number == current_page.pager.last.number end - html.join(' ') + html.join(' ').html_safe end end end From 881e1641c6a970311e0a2f14a2a0e576600be901 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 22 Jun 2010 11:58:26 +0200 Subject: [PATCH 0450/2024] inc and dec_record_count function changed --- .../default/javascripts/active_scaffold.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 9b910e32e1..1e6a19607e 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -195,24 +195,27 @@ var ActiveScaffold = { }); } }, - removeSortClasses: function(scaffold_id) { - $$('#' + scaffold_id + ' td.sorted').each(function(element) { + removeSortClasses: function(scaffold) { + scaffold = $(scaffold) + scaffold.select('td.sorted').each(function(element) { element.removeClassName("sorted"); }); - $$('#' + scaffold_id + ' th.sorted').each(function(element) { + scaffold.select('th.sorted').each(function(element) { element.removeClassName("sorted"); element.removeClassName("asc"); element.removeClassName("desc"); }); }, - decrement_record_count: function(scaffold_id) { + decrement_record_count: function(scaffold) { // decrement the last record count, firsts record count are in nested lists - count = $$('#' + scaffold_id + ' span.active-scaffold-records').last(); + scaffold = $(scaffold) + count = scaffold.select('span.active-scaffold-records').last(); if (count) count.update(parseInt(count.innerHTML, 10) - 1); }, - increment_record_count: function(scaffold_id) { + increment_record_count: function(scaffold) { // increment the last record count, firsts record count are in nested lists - count = $$('#' + scaffold_id + ' span.active-scaffold-records').last(); + scaffold = $(scaffold) + count = scaffold.select('span.active-scaffold-records').last(); if (count) count.update(parseInt(count.innerHTML, 10) + 1); }, update_row: function(row, html) { @@ -243,9 +246,9 @@ var ActiveScaffold = { current_action_node.action_link.close_previous_adapter(); } row.remove(); - this.reload_if_empty(tbody, page_reload_url); this.stripe(tbody); this.decrement_record_count(tbody.up('div.active-scaffold')); + this.reload_if_empty(tbody, page_reload_url); }, report_500_response: function(active_scaffold_id) { From 272d5c11d0987b3af6969467a528088c2ebb9f7c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 22 Jun 2010 15:03:53 +0200 Subject: [PATCH 0451/2024] Bugfix: include column links into record actions set --- frontends/default/javascripts/active_scaffold.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 1e6a19607e..1643596f7e 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -45,8 +45,8 @@ document.observe("dom:loaded", function() { var parent = as_action.up(); if (parent && parent.nodeName.toUpperCase() == 'TD') { // record action - parent = parent.up('tr') - new ActiveScaffold.Actions.Record(parent.select('a.as_action'), parent.up('tr.record'), parent.down('.loading-indicator')); + parent = parent.up('tr.record') + new ActiveScaffold.Actions.Record(parent.select('a.as_action'), parent, parent.down('td.actions .loading-indicator')); } else if (parent && parent.nodeName.toUpperCase() == 'DIV') { //table action new ActiveScaffold.Actions.Table(parent.select('a.as_action'), parent.up('div.active-scaffold').down('tbody.before-header'), parent.down('.loading-indicator')); From 247e927dbf8ccd1e6db18a005f563bedeff3a2e5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 24 Jun 2010 10:25:32 +0200 Subject: [PATCH 0452/2024] Fix nested edit form --- frontends/default/views/on_update.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index b8b42ae92b..29d34be959 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -5,7 +5,7 @@ if controller.send :successful? if active_scaffold_config.update.persistent flash.now[:info] = 'Update Succeeded!' else - updated_row = render :partial => 'list_record', :locals => {:record => @record} + updated_row = render :partial => 'list_record', :locals => {:record => @record} if params[:parent_controller].nil? page << "$$(#{cancel_selector}).first().link.close('#{escape_javascript(updated_row)}');" end page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} From 607fc7028cc69787639a50cd604fb7bb825ae239 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 25 Jun 2010 09:12:36 +0200 Subject: [PATCH 0453/2024] unique id for mark column header and remove name_scope depreciation --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- lib/active_scaffold/marked_model.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index f03daf787e..fa20c0ff9b 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -350,7 +350,7 @@ def active_scaffold_in_place_editor(field_id, options = {}) def mark_column_heading all_marked = (marked_records.length >= @page.pager.count) - tag_options = {:id => "mark_heading", :class => "mark_heading"} + tag_options = {:id => "#{controller_id}_mark_heading", :class => "mark_heading"} url_params = {:controller => params_for[:controller], :action => 'mark_all', :eid => params[:eid]} ajax_options = {:method => :post, :url => url_for(url_params), :with => "'value=' + this.value", diff --git a/lib/active_scaffold/marked_model.rb b/lib/active_scaffold/marked_model.rb index b121b4c64e..b08d401b37 100644 --- a/lib/active_scaffold/marked_model.rb +++ b/lib/active_scaffold/marked_model.rb @@ -4,7 +4,7 @@ module MarkedModel def self.included(base) base.extend ClassMethods - base.named_scope :marked, lambda {{:conditions => {:id => base.marked_records.to_a}}} + base.scope :marked, lambda {{:conditions => {:id => base.marked_records.to_a}}} end def marked From 407b114d783e446b7b115f2f493c436ceb8d0a2f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 25 Jun 2010 12:39:55 +0200 Subject: [PATCH 0454/2024] change of nested architecture using just constraints is not working in all casesthis try will use specified asssocation of parent to generate list and create views --- lib/active_scaffold.rb | 5 +- lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/actions/nested.rb | 51 +++++++++++++++++---- lib/active_scaffold/helpers/view_helpers.rb | 4 +- 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 423c0ef79f..a663c9c7a8 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -127,10 +127,11 @@ def link_for_association(column, options = {}) unless controller.nil? options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => controller.controller_path, :column => column + options[:parameters] ||= {} + options[:parameters].reverse_merge! :nested => true, :parent_model => column.active_record_class, :association => column.association.name if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. - options[:parameters] ||= {} - options[:parameters][:nested] = true + ActiveScaffold::DataStructures::ActionLink.new('index', options) #unless column.through_association? else actions = controller.active_scaffold_config.actions diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 144d4ed23e..dafbd7920b 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -104,7 +104,7 @@ def do_create end def new_model - model = active_scaffold_config.model + model = beginning_of_chain if model.columns_hash[model.inheritance_column] params = self.params # in new action inheritance_column must be in params params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index e23ec0b63b..897ad999af 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -5,7 +5,8 @@ module Nested def self.included(base) super base.module_eval do - before_filter :set_active_scaffold_constraints + before_filter :set_parent_association + #before_filter :set_active_scaffold_constraints before_filter :register_constraints_with_action_columns before_filter :set_nested_list_label include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? {|a| a.macro == :has_and_belongs_to_many} @@ -17,6 +18,28 @@ def self.included(base) end protected + def parent_association + @parent_association ||= active_scaffold_session_storage[:parent_association].nil? ? nil : active_scaffold_session_storage[:parent_association].clone + @parent_association[:association] = @parent_association[:parent_model].reflect_on_association(@parent_association[:name]) if @parent_association + @parent_association + end + + def parent_association? + !parent_association.nil? + end + + def set_parent_association + if nested? + if params[:parent_model] && params[:association] && params[:assoc_id] + @parent_association = nil + active_scaffold_session_storage[:parent_association] = {:parent_model => params[:parent_model].constantize, + :name => params[:association].to_sym, + :parent_id => params[:assoc_id]} + end + params.delete_if {|key, value| [:parent_model, :association, :assoc_id].include? key.to_sym} + end + end + def nested_authorized?(record = nil) true end @@ -40,6 +63,15 @@ def include_habtm_actions end end + + def beginning_of_chain + if parent_association? && !parent_association[:association].belongs_to? + Rails.logger.info("begining of chain: #{parent_association[:association].inspect}") + parent_scope.send(parent_association[:name]) + else + active_scaffold_config.model + end + end def nested? !params[:nested].nil? @@ -47,31 +79,32 @@ def nested? def nested_habtm? begin - return nested_column.association.macro == :has_and_belongs_to_many if nested? and nested_column + #return nested_column.association.macro == :has_and_belongs_to_many if nested? and nested_column false rescue raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, nested_association), caller end end - - - + def nested_association return active_scaffold_constraints.keys.to_s.to_sym if nested? nil end def nested_parent_id - return active_scaffold_constraints.values.to_s if nested? - nil + parent_association? ? parent_association[:parent_id]: nil + end + + def parent_scope + nested_parent.find(nested_parent_id) end def nested_parent_record(crud = :read) - find_if_allowed(nested_parent_id, crud, nested_column.association.klass) + find_if_allowed(nested_parent_id, crud, nested_parent) end def nested_parent - nested_column.association.klass + parent_association? ? parent_association[:parent_model]: nil end def nested_parent_column diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index ce665cd9c5..1d7c00df68 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -166,8 +166,8 @@ def render_action_link(link, url_options, record = nil, html_options = {}) end def url_options_for_nested_link(column, record, link, url_options) - if column.association and link.controller.to_s != params[:controller] - url_options[record.class.name.foreign_key.to_sym] = url_options.delete(:id) + if column.association + url_options[:assoc_id] = url_options.delete(:id) url_options[:id] = record.send(column.association.name) if column.singular_association? url_options[:eid] = "#{params[:controller]}_#{ActiveSupport::SecureRandom.hex(10)}" end From 10c4e76ff4764064229743d4b71006edf6261fec Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 28 Jun 2010 09:18:30 +0200 Subject: [PATCH 0455/2024] habtm fixed in new nesting architecture --- lib/active_scaffold/actions/nested.rb | 14 ++++---------- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 897ad999af..4491150a8c 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -14,7 +14,7 @@ def self.included(base) base.before_filter :include_habtm_actions base.helper_method :nested_habtm? base.helper_method :nested_column - base.helper_method :nested_parent_column + base.helper_method :parent_association end protected @@ -66,7 +66,6 @@ def include_habtm_actions def beginning_of_chain if parent_association? && !parent_association[:association].belongs_to? - Rails.logger.info("begining of chain: #{parent_association[:association].inspect}") parent_scope.send(parent_association[:name]) else active_scaffold_config.model @@ -78,12 +77,7 @@ def nested? end def nested_habtm? - begin - #return nested_column.association.macro == :has_and_belongs_to_many if nested? and nested_column - false - rescue - raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, nested_association), caller - end + parent_association? ? parent_association[:association].macro == :has_and_belongs_to_many : false end def nested_association @@ -235,7 +229,7 @@ def do_add_existing parent_record = nested_parent_record(:update) @record = active_scaffold_config.model.find(params[:associated_id]) if parent_record && @record - parent_record.send(nested_parent_column.name) << @record + parent_record.send(parent_association[:name]) << @record parent_record.save else false @@ -245,7 +239,7 @@ def do_add_existing def do_destroy_existing if active_scaffold_config.nested.shallow_delete @record = nested_parent_record(:update) - collection = @record.send(nested_parent_column.name) + collection = @record.send(parent_association[:name]) assoc_record = collection.find(params[:id]) collection.delete(assoc_record) else diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 03f34e595e..8314a7b077 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -324,7 +324,7 @@ def active_scaffold_add_existing_input(options) options.merge!(active_scaffold_input_text_options) record_select_field(options[:name], @record, options) else - select_options = options_for_select(options_for_association(nested_parent_column.association)) #unless column.through_association? + select_options = options_for_select(options_for_association(parent_association[:association])) #unless column.through_association? select_options ||= options_for_select(active_scaffold_config.model.all.collect {|c| [h(c.to_label), c.id]}) select_tag 'associated_id', ('<option value="">' + as_(:_select_) + '</option>' + select_options).html_safe unless select_options.empty? end From 1677f18b4e754ddc234bd58af63e657ea822f831 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 28 Jun 2010 12:24:29 +0200 Subject: [PATCH 0456/2024] hide association columns in nested view --- lib/active_scaffold/actions/nested.rb | 16 +++++++++++++--- lib/active_scaffold/constraints.rb | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 4491150a8c..caf71741ae 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -5,9 +5,8 @@ module Nested def self.included(base) super base.module_eval do - before_filter :set_parent_association - #before_filter :set_active_scaffold_constraints before_filter :register_constraints_with_action_columns + before_filter :set_parent_association before_filter :set_nested_list_label include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? {|a| a.macro == :has_and_belongs_to_many} end @@ -20,10 +19,21 @@ def self.included(base) protected def parent_association @parent_association ||= active_scaffold_session_storage[:parent_association].nil? ? nil : active_scaffold_session_storage[:parent_association].clone - @parent_association[:association] = @parent_association[:parent_model].reflect_on_association(@parent_association[:name]) if @parent_association + if @parent_association && @parent_association[:association].nil? + @parent_association[:association] = @parent_association[:parent_model].reflect_on_association(@parent_association[:name]) + hide_association_columns(@parent_association[:association]) unless @parent_association[:association].belongs_to? + end @parent_association end + def hide_association_columns(nested_association) + constrained_fields = Array(@parent_association[:association].primary_key_name.to_sym) + active_scaffold_config.model.reflect_on_all_associations.each do |association| + constrained_fields << association.name.to_sym if association.belongs_to? && @parent_association[:association].primary_key_name == association.primary_key_name + end + register_constraints_with_action_columns(constrained_fields) + end + def parent_association? !parent_association.nil? end diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 0bd7d12443..2dfe53ef7b 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -22,9 +22,9 @@ def set_active_scaffold_constraints # This lets the ActionColumns object skip constrained columns. # # If the constraint value is a Hash, then we assume the constraint is a multi-level association constraint (the reverse of a has_many :through) and we do NOT register the constraint column. - def register_constraints_with_action_columns + def register_constraints_with_action_columns(association_constrained_fields = []) constrained_fields = active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect{|k| k.to_sym} - + constrained_fields = constrained_fields | association_constrained_fields if self.class.uses_active_scaffold? # we actually want to do this whether constrained_fields exist or not, so that we can reset the array when they don't active_scaffold_config.actions.each do |action_name| From c58c1201de3461ba73ec31e093a77e4c0c4d6cc6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 28 Jun 2010 13:38:00 +0200 Subject: [PATCH 0457/2024] remove unused code --- lib/active_scaffold/actions/nested.rb | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index caf71741ae..81a4022fce 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -12,7 +12,6 @@ def self.included(base) end base.before_filter :include_habtm_actions base.helper_method :nested_habtm? - base.helper_method :nested_column base.helper_method :parent_association end @@ -90,11 +89,6 @@ def nested_habtm? parent_association? ? parent_association[:association].macro == :has_and_belongs_to_many : false end - def nested_association - return active_scaffold_constraints.keys.to_s.to_sym if nested? - nil - end - def nested_parent_id parent_association? ? parent_association[:parent_id]: nil end @@ -111,22 +105,6 @@ def nested_parent parent_association? ? parent_association[:parent_model]: nil end - def nested_parent_column - join_table = nested_column.association.options[:join_table] - parent_config = active_scaffold_config_for(nested_parent) - if join_table && parent_config - parent_config.columns.detect {|column| column.association and column.association.macro == :has_and_belongs_to_many and column.association.options[:join_table] and column.association.options[:join_table] == join_table} - end - end - - def nested_column - begin - @nested_column ||= active_scaffold_config.columns[nested_association] - rescue - raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, nested_association), caller - end - end - def set_nested_list_label active_scaffold_session_storage[:list][:label] = as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => nested_parent_record.to_label) if nested? end From caff04379e3da5c837d081e66c23ade211fce94a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 28 Jun 2010 15:02:07 +0200 Subject: [PATCH 0458/2024] some further nested cleanup create_association_with_parent if necessary --- lib/active_scaffold/actions/create.rb | 3 ++- lib/active_scaffold/actions/nested.rb | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index dafbd7920b..07731b5ba4 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -14,7 +14,7 @@ def new def create do_create - @insert_row = params[:parent_controller].nil? + @insert_row = !(parent_association? && parent_belongs_to?) && params[:parent_controller].nil? respond_to_action(:create) end @@ -96,6 +96,7 @@ def do_create self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit if successful? @record.save! and @record.save_associated! + create_association_with_parent(@record) after_create_save(@record) end end diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 81a4022fce..500dffc7a1 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -11,7 +11,7 @@ def self.included(base) include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? {|a| a.macro == :has_and_belongs_to_many} end base.before_filter :include_habtm_actions - base.helper_method :nested_habtm? + base.helper_method :parent_habtm? base.helper_method :parent_association end @@ -54,7 +54,7 @@ def nested_authorized?(record = nil) end def include_habtm_actions - if nested_habtm? + if parent_habtm? # Production mode is ok with adding a link everytime the scaffold is nested - we ar not ok with that. active_scaffold_config.action_links.add('new_existing', :label => :add_existing, :type => :collection, :security_method => :add_existing_authorized?) unless active_scaffold_config.action_links['new_existing'] if active_scaffold_config.nested.shallow_delete @@ -74,7 +74,7 @@ def include_habtm_actions end def beginning_of_chain - if parent_association? && !parent_association[:association].belongs_to? + if parent_association? && !parent_belongs_to? parent_scope.send(parent_association[:name]) else active_scaffold_config.model @@ -85,9 +85,13 @@ def nested? !params[:nested].nil? end - def nested_habtm? + def parent_habtm? parent_association? ? parent_association[:association].macro == :has_and_belongs_to_many : false end + + def parent_belongs_to? + parent_association? && parent_association[:association].belongs_to? + end def nested_parent_id parent_association? ? parent_association[:parent_id]: nil @@ -109,6 +113,13 @@ def set_nested_list_label active_scaffold_session_storage[:list][:label] = as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => nested_parent_record.to_label) if nested? end + def create_association_with_parent(record) + if parent_association? && parent_belongs_to? + parent = nested_parent_record(:update) + parent.update_attributes!(parent_association[:name].to_sym => record) if parent + end + end + private def nested_formats (default_formats + active_scaffold_config.formats + active_scaffold_config.nested.formats).uniq From 0d8a857613221715b0a455efc32a5a26f304a31d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 28 Jun 2010 15:30:15 +0200 Subject: [PATCH 0459/2024] bugfix: update of a nested belongs_to association failed --- frontends/default/views/on_update.js.rjs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 5ca9f74106..b03ea20f6e 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -2,7 +2,11 @@ form_selector = "#{element_form_id(:action => :update)}" page << "$('#{form_selector}').up('.as_adapter').action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? - updated_row = render :partial => 'list_record', :locals => {:record => @record} + updated_row = if parent_association && parent_association[:association].belongs_to? + nil + else + render :partial => 'list_record', :locals => {:record => @record} + end page << "$('#{form_selector}').up('.as_adapter').action_link.close('#{escape_javascript(updated_row)}');" page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} else From 04abf9d340e36468f3c00e815fcf4070ab2f5550 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 28 Jun 2010 16:04:45 +0200 Subject: [PATCH 0460/2024] Bugfix: hide association columns for habtm --- lib/active_scaffold/actions/nested.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 500dffc7a1..d3c6496791 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -29,6 +29,7 @@ def hide_association_columns(nested_association) constrained_fields = Array(@parent_association[:association].primary_key_name.to_sym) active_scaffold_config.model.reflect_on_all_associations.each do |association| constrained_fields << association.name.to_sym if association.belongs_to? && @parent_association[:association].primary_key_name == association.primary_key_name + constrained_fields << association.name.to_sym if !association.belongs_to? && @parent_association[:association].primary_key_name == association.association_foreign_key end register_constraints_with_action_columns(constrained_fields) end From 315acee8357c8e06ce14a235ee23ca123091e536 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 29 Jun 2010 13:04:06 +0200 Subject: [PATCH 0461/2024] set default values if parent belongs_to child --- lib/active_scaffold/actions/create.rb | 3 ++- lib/active_scaffold/actions/nested.rb | 27 ++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 07731b5ba4..b9b54fc1b2 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -82,6 +82,7 @@ def create_respond_to_yaml def do_new @record = new_model apply_constraints_to_record(@record) + create_association_with_parent(@record) @record end @@ -92,11 +93,11 @@ def do_create active_scaffold_config.model.transaction do @record = update_record_from_params(new_model, active_scaffold_config.create.columns, params[:record]) apply_constraints_to_record(@record, :allow_autosave => true) + create_association_with_parent(@record) before_create_save(@record) self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit if successful? @record.save! and @record.save_associated! - create_association_with_parent(@record) after_create_save(@record) end end diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index d3c6496791..1fb130efa2 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -20,16 +20,24 @@ def parent_association @parent_association ||= active_scaffold_session_storage[:parent_association].nil? ? nil : active_scaffold_session_storage[:parent_association].clone if @parent_association && @parent_association[:association].nil? @parent_association[:association] = @parent_association[:parent_model].reflect_on_association(@parent_association[:name]) - hide_association_columns(@parent_association[:association]) unless @parent_association[:association].belongs_to? + hide_association_columns(@parent_association[:association]) end @parent_association end def hide_association_columns(nested_association) - constrained_fields = Array(@parent_association[:association].primary_key_name.to_sym) + constrained_fields = [] + constrained_fields << @parent_association[:association].primary_key_name.to_sym unless @parent_association[:association].belongs_to? active_scaffold_config.model.reflect_on_all_associations.each do |association| - constrained_fields << association.name.to_sym if association.belongs_to? && @parent_association[:association].primary_key_name == association.primary_key_name - constrained_fields << association.name.to_sym if !association.belongs_to? && @parent_association[:association].primary_key_name == association.association_foreign_key + if !association.belongs_to? && @parent_association[:association].primary_key_name == association.association_foreign_key + constrained_fields << association.name.to_sym + @parent_association[:child_association] = association + end + if @parent_association[:association].primary_key_name == association.primary_key_name + # show columns for has_many and has_one child associationes + constrained_fields << association.name.to_sym if association.belongs_to? + @parent_association[:child_association] = association + end end register_constraints_with_action_columns(constrained_fields) end @@ -115,9 +123,14 @@ def set_nested_list_label end def create_association_with_parent(record) - if parent_association? && parent_belongs_to? - parent = nested_parent_record(:update) - parent.update_attributes!(parent_association[:name].to_sym => record) if parent + if parent_association? && parent_belongs_to? && parent_association[:child_association] + parent = nested_parent_record(:read) + case parent_association[:child_association].macro + when :has_one + record.send("#{parent_association[:child_association].name}=", parent) + when :has_many + record.send("#{parent_association[:child_association].name}").send(:<<, parent) + end unless parent.nil? end end From e5b70e7c4651930e429305b67606a1bfd226ed48 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 30 Jun 2010 09:51:27 +0200 Subject: [PATCH 0462/2024] prefix polymorphic belongs_to values with model class name --- lib/active_scaffold/helpers/list_column_helpers.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index fa20c0ff9b..3a5651aafb 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -189,7 +189,11 @@ def format_number_value(value, options = {}) def format_association_value(value, column, size) case column.association.macro when :has_one, :belongs_to - format_value(value.to_label) + if column.association.options[:polymorphic] + format_value("#{value.class.model_name.human}: #{value.to_label}") + else + format_value(value.to_label) + end when :has_many, :has_and_belongs_to_many if column.associated_limit.nil? firsts = value.collect { |v| v.to_label } From 869640ec85464e5966612589c056a25b45f368ab Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 30 Jun 2010 14:02:53 +0200 Subject: [PATCH 0463/2024] add inline form editing for polymorphic belong_to associations --- lib/active_scaffold.rb | 12 ++++------- lib/active_scaffold/data_structures/column.rb | 2 +- .../helpers/list_column_helpers.rb | 21 ++++++++++++++++--- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index a663c9c7a8..b6288a93cb 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -108,11 +108,6 @@ def links_for_associations return unless active_scaffold_config.actions.include? :list and active_scaffold_config.actions.include? :nested active_scaffold_config.columns.each do |column| next unless column.link.nil? and column.autolink? - if column.polymorphic_association? - # note: we can't create inline forms on singular polymorphic associations - column.clear_link - next - end action_link = link_for_association(column) column.set_link(action_link) unless action_link.nil? end @@ -120,13 +115,13 @@ def links_for_associations def link_for_association(column, options = {}) begin - controller = active_scaffold_controller_for(column.association.klass) + controller = column.polymorphic_association? ? :polymorph : active_scaffold_controller_for(column.association.klass) rescue ActiveScaffold::ControllerNotFound controller = nil end unless controller.nil? - options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => controller.controller_path, :column => column + options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column options[:parameters] ||= {} options[:parameters].reverse_merge! :nested => true, :parent_model => column.active_record_class, :association => column.association.name if column.plural_association? @@ -134,7 +129,8 @@ def link_for_association(column, options = {}) ActiveScaffold::DataStructures::ActionLink.new('index', options) #unless column.through_association? else - actions = controller.active_scaffold_config.actions + actions = [:create, :update, :show] + actions = controller.active_scaffold_config.actions unless controller == :polymorph column.actions_for_association_links.delete :new unless actions.include? :create column.actions_for_association_links.delete :edit unless actions.include? :update column.actions_for_association_links.delete :show unless actions.include? :show diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 1a6cd64642..32ffa1cd37 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -110,7 +110,7 @@ def options # set an action_link to nested list or inline form in this column def autolink? - @autolink and self.association.reverse + @autolink end # this should not only delete any existing link but also prevent column links from being automatically added by later routines diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 3a5651aafb..ee945d32a7 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -42,7 +42,7 @@ def render_list_column(text, column, record) # setup automatic link if column.autolink? && column.singular_association? # link to inline form - link = action_link_to_inline_form(column, associated) + link = action_link_to_inline_form(column, record, associated) return text if link.crud_type.nil? url_options[:link] = as_(:create_new) if link.crud_type == :create end @@ -70,8 +70,14 @@ def render_list_column(text, column, record) end # setup the action link to inline form - def action_link_to_inline_form(column, associated) + def action_link_to_inline_form(column, record, associated) link = column.link.clone + if column.polymorphic_association? + polymorphic_controller = polymorphic_controller_for_nested_link(column, record) + return link if polymorphic_controller.nil? + link.controller = polymorphic_controller + end + if column_empty?(associated) # if association is empty, we only can link to create form if column.actions_for_association_links.include?(:new) link.action = 'new' @@ -86,6 +92,15 @@ def action_link_to_inline_form(column, associated) end link end + + def polymorphic_controller_for_nested_link(column, record) + begin + controller = active_scaffold_controller_for(record.send(column.association.name).class) + controller.controller_path + rescue ActiveScaffold::ControllerNotFound + controller = nil + end + end # There are two basic ways to clean a column's value: h() and sanitize(). The latter is useful # when the column contains *valid* html data, and you want to just disable any scripting. People @@ -189,7 +204,7 @@ def format_number_value(value, options = {}) def format_association_value(value, column, size) case column.association.macro when :has_one, :belongs_to - if column.association.options[:polymorphic] + if column.polymorphic_association? format_value("#{value.class.model_name.human}: #{value.to_label}") else format_value(value.to_label) From 1bcd879fde3405700f19c4d5e41325ad6fc2c976 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 30 Jun 2010 14:46:14 +0200 Subject: [PATCH 0464/2024] Bugfix: use correct condition to detect collection typed associations --- lib/active_scaffold/actions/nested.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 1fb130efa2..b256e373da 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -83,7 +83,7 @@ def include_habtm_actions end def beginning_of_chain - if parent_association? && !parent_belongs_to? + if parent_association? && parent_association[:association].collection? parent_scope.send(parent_association[:name]) else active_scaffold_config.model From bf6808367cb7a6c997ca1683c90ad832bb30eb29 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 30 Jun 2010 15:19:23 +0200 Subject: [PATCH 0465/2024] renaming in nested action --- .../default/views/_add_existing_form.html.erb | 2 +- frontends/default/views/on_update.js.rjs | 2 +- lib/active_scaffold/actions/create.rb | 4 +- lib/active_scaffold/actions/nested.rb | 81 +++++++++---------- .../helpers/form_column_helpers.rb | 2 +- 5 files changed, 44 insertions(+), 47 deletions(-) diff --git a/frontends/default/views/_add_existing_form.html.erb b/frontends/default/views/_add_existing_form.html.erb index afb9b84798..4a918bdf44 100644 --- a/frontends/default/views/_add_existing_form.html.erb +++ b/frontends/default/views/_add_existing_form.html.erb @@ -21,7 +21,7 @@ options = {:id => element_form_id(:action => :add_existing), <p class="form-footer"> <%= submit_tag as_(:add), :class => "submit" %> - <%= link_to as_(:cancel), main_path_to_return.merge(:nested => true), :class => 'as_cancel', :remote => true %> + <%= link_to as_(:cancel), main_path_to_return, :class => 'as_cancel', :remote => true %> <%= loading_indicator_tag(:action => :add_existing, :id => params[:id]) %> </p> diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index b03ea20f6e..663146abec 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -2,7 +2,7 @@ form_selector = "#{element_form_id(:action => :update)}" page << "$('#{form_selector}').up('.as_adapter').action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? - updated_row = if parent_association && parent_association[:association].belongs_to? + updated_row = if nested && nested[:association].belongs_to? nil else render :partial => 'list_record', :locals => {:record => @record} diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index b9b54fc1b2..ad7003b262 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -14,7 +14,7 @@ def new def create do_create - @insert_row = !(parent_association? && parent_belongs_to?) && params[:parent_controller].nil? + @insert_row = !(nested? && nested_belongs_to?) && params[:parent_controller].nil? respond_to_action(:create) end @@ -125,7 +125,7 @@ def after_create_save(record); end # You may override the method to customize. def create_ignore? - params[:nested].nil? && active_scaffold_config.list.always_show_create + nested? && active_scaffold_config.list.always_show_create end def create_authorized? diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index b256e373da..a0110d8802 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -6,56 +6,53 @@ def self.included(base) super base.module_eval do before_filter :register_constraints_with_action_columns - before_filter :set_parent_association + before_filter :set_nested before_filter :set_nested_list_label include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? {|a| a.macro == :has_and_belongs_to_many} end base.before_filter :include_habtm_actions - base.helper_method :parent_habtm? - base.helper_method :parent_association + base.helper_method :nested end protected - def parent_association - @parent_association ||= active_scaffold_session_storage[:parent_association].nil? ? nil : active_scaffold_session_storage[:parent_association].clone - if @parent_association && @parent_association[:association].nil? - @parent_association[:association] = @parent_association[:parent_model].reflect_on_association(@parent_association[:name]) - hide_association_columns(@parent_association[:association]) + def nested + @nested ||= active_scaffold_session_storage[:nested].nil? ? nil : active_scaffold_session_storage[:nested].clone + if @nested && @nested[:association].nil? + @nested[:association] = @nested[:parent_model].reflect_on_association(@nested[:name]) + hide_association_columns(@nested[:association]) end - @parent_association + @nested end def hide_association_columns(nested_association) constrained_fields = [] - constrained_fields << @parent_association[:association].primary_key_name.to_sym unless @parent_association[:association].belongs_to? + constrained_fields << @nested[:association].primary_key_name.to_sym unless @nested[:association].belongs_to? active_scaffold_config.model.reflect_on_all_associations.each do |association| - if !association.belongs_to? && @parent_association[:association].primary_key_name == association.association_foreign_key + if !association.belongs_to? && @nested[:association].primary_key_name == association.association_foreign_key constrained_fields << association.name.to_sym - @parent_association[:child_association] = association + @nested[:child_association] = association end - if @parent_association[:association].primary_key_name == association.primary_key_name + if @nested[:association].primary_key_name == association.primary_key_name # show columns for has_many and has_one child associationes constrained_fields << association.name.to_sym if association.belongs_to? - @parent_association[:child_association] = association + @nested[:child_association] = association end end register_constraints_with_action_columns(constrained_fields) end - def parent_association? - !parent_association.nil? + def nested? + !nested.nil? end - def set_parent_association - if nested? - if params[:parent_model] && params[:association] && params[:assoc_id] - @parent_association = nil - active_scaffold_session_storage[:parent_association] = {:parent_model => params[:parent_model].constantize, - :name => params[:association].to_sym, - :parent_id => params[:assoc_id]} - end - params.delete_if {|key, value| [:parent_model, :association, :assoc_id].include? key.to_sym} + def set_nested + if params[:parent_model] && params[:association] && params[:assoc_id] + @nested = nil + active_scaffold_session_storage[:nested] = {:parent_model => params[:parent_model].constantize, + :name => params[:association].to_sym, + :parent_id => params[:assoc_id]} end + params.delete_if {|key, value| [:parent_model, :association, :assoc_id].include? key.to_sym} end def nested_authorized?(record = nil) @@ -63,7 +60,7 @@ def nested_authorized?(record = nil) end def include_habtm_actions - if parent_habtm? + if nested_habtm? # Production mode is ok with adding a link everytime the scaffold is nested - we ar not ok with that. active_scaffold_config.action_links.add('new_existing', :label => :add_existing, :type => :collection, :security_method => :add_existing_authorized?) unless active_scaffold_config.action_links['new_existing'] if active_scaffold_config.nested.shallow_delete @@ -83,30 +80,30 @@ def include_habtm_actions end def beginning_of_chain - if parent_association? && parent_association[:association].collection? - parent_scope.send(parent_association[:name]) + if nested? && nested[:association].collection? + nested_scope.send(nested[:name]) else active_scaffold_config.model end end def nested? - !params[:nested].nil? + !nested.nil? end - def parent_habtm? - parent_association? ? parent_association[:association].macro == :has_and_belongs_to_many : false + def nested_habtm? + nested? ? nested[:association].macro == :has_and_belongs_to_many : false end - def parent_belongs_to? - parent_association? && parent_association[:association].belongs_to? + def nested_belongs_to? + nested? && nested[:association].belongs_to? end def nested_parent_id - parent_association? ? parent_association[:parent_id]: nil + nested? ? nested[:parent_id]: nil end - def parent_scope + def nested_scope nested_parent.find(nested_parent_id) end @@ -115,7 +112,7 @@ def nested_parent_record(crud = :read) end def nested_parent - parent_association? ? parent_association[:parent_model]: nil + nested? ? nested[:parent_model]: nil end def set_nested_list_label @@ -123,13 +120,13 @@ def set_nested_list_label end def create_association_with_parent(record) - if parent_association? && parent_belongs_to? && parent_association[:child_association] + if nested? && nested_belongs_to? && nested[:child_association] parent = nested_parent_record(:read) - case parent_association[:child_association].macro + case nested[:child_association].macro when :has_one - record.send("#{parent_association[:child_association].name}=", parent) + record.send("#{nested[:child_association].name}=", parent) when :has_many - record.send("#{parent_association[:child_association].name}").send(:<<, parent) + record.send("#{nested[:child_association].name}").send(:<<, parent) end unless parent.nil? end end @@ -242,7 +239,7 @@ def do_add_existing parent_record = nested_parent_record(:update) @record = active_scaffold_config.model.find(params[:associated_id]) if parent_record && @record - parent_record.send(parent_association[:name]) << @record + parent_record.send(nested[:name]) << @record parent_record.save else false @@ -252,7 +249,7 @@ def do_add_existing def do_destroy_existing if active_scaffold_config.nested.shallow_delete @record = nested_parent_record(:update) - collection = @record.send(parent_association[:name]) + collection = @record.send(nested[:name]) assoc_record = collection.find(params[:id]) collection.delete(assoc_record) else diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 8314a7b077..d27f3a06c9 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -324,7 +324,7 @@ def active_scaffold_add_existing_input(options) options.merge!(active_scaffold_input_text_options) record_select_field(options[:name], @record, options) else - select_options = options_for_select(options_for_association(parent_association[:association])) #unless column.through_association? + select_options = options_for_select(options_for_association(nested[:association])) #unless column.through_association? select_options ||= options_for_select(active_scaffold_config.model.all.collect {|c| [h(c.to_label), c.id]}) select_tag 'associated_id', ('<option value="">' + as_(:_select_) + '</option>' + select_options).html_safe unless select_options.empty? end From ea2c9182a92d016bee1a8161525e6c467c6728fb Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 1 Jul 2010 09:37:47 +0200 Subject: [PATCH 0466/2024] some refactoring to clean up the nested part --- lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/actions/nested.rb | 107 ++++++------------ .../data_structures/nested_info.rb | 58 ++++++++++ 3 files changed, 91 insertions(+), 76 deletions(-) create mode 100644 lib/active_scaffold/data_structures/nested_info.rb diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index ad7003b262..20d80e8fec 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -14,7 +14,7 @@ def new def create do_create - @insert_row = !(nested? && nested_belongs_to?) && params[:parent_controller].nil? + @insert_row = !(nested? && nested.belongs_to?) && params[:parent_controller].nil? respond_to_action(:create) end diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index a0110d8802..23082512dd 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -16,31 +16,11 @@ def self.included(base) protected def nested - @nested ||= active_scaffold_session_storage[:nested].nil? ? nil : active_scaffold_session_storage[:nested].clone - if @nested && @nested[:association].nil? - @nested[:association] = @nested[:parent_model].reflect_on_association(@nested[:name]) - hide_association_columns(@nested[:association]) - end + @nested ||= ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, active_scaffold_session_storage) + register_constraints_with_action_columns(@nested.constrained_fields) if !@nested.nil? && @nested.new_instance? @nested end - def hide_association_columns(nested_association) - constrained_fields = [] - constrained_fields << @nested[:association].primary_key_name.to_sym unless @nested[:association].belongs_to? - active_scaffold_config.model.reflect_on_all_associations.each do |association| - if !association.belongs_to? && @nested[:association].primary_key_name == association.association_foreign_key - constrained_fields << association.name.to_sym - @nested[:child_association] = association - end - if @nested[:association].primary_key_name == association.primary_key_name - # show columns for has_many and has_one child associationes - constrained_fields << association.name.to_sym if association.belongs_to? - @nested[:child_association] = association - end - end - register_constraints_with_action_columns(constrained_fields) - end - def nested? !nested.nil? end @@ -55,79 +35,56 @@ def set_nested params.delete_if {|key, value| [:parent_model, :association, :assoc_id].include? key.to_sym} end + def set_nested_list_label + active_scaffold_session_storage[:list][:label] = as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => nested_parent_record.to_label) if nested? + end + def nested_authorized?(record = nil) true end def include_habtm_actions - if nested_habtm? - # Production mode is ok with adding a link everytime the scaffold is nested - we ar not ok with that. - active_scaffold_config.action_links.add('new_existing', :label => :add_existing, :type => :collection, :security_method => :add_existing_authorized?) unless active_scaffold_config.action_links['new_existing'] - if active_scaffold_config.nested.shallow_delete - active_scaffold_config.action_links.add('destroy_existing', :label => :remove, :type => :member, :confirm => :are_you_sure_to_delete, :method => :delete, :position => false, :security_method => :delete_existing_authorized?) unless active_scaffold_config.action_links['destroy_existing'] - active_scaffold_config.action_links.delete("delete") if active_scaffold_config.action_links['delete'] - end - else - # Production mode is caching this link into a non nested scaffold - active_scaffold_config.action_links.delete('new_existing') if active_scaffold_config.action_links['new_existing'] - - if active_scaffold_config.nested.shallow_delete - active_scaffold_config.action_links.delete("destroy_existing") if active_scaffold_config.action_links['destroy_existing'] - active_scaffold_config.action_links.add(ActiveScaffold::Config::Delete.link) unless active_scaffold_config.action_links['delete'] + if nested? + if nested.habtm? + # Production mode is ok with adding a link everytime the scaffold is nested - we ar not ok with that. + active_scaffold_config.action_links.add('new_existing', :label => :add_existing, :type => :collection, :security_method => :add_existing_authorized?) unless active_scaffold_config.action_links['new_existing'] + if active_scaffold_config.nested.shallow_delete + active_scaffold_config.action_links.add('destroy_existing', :label => :remove, :type => :member, :confirm => :are_you_sure_to_delete, :method => :delete, :position => false, :security_method => :delete_existing_authorized?) unless active_scaffold_config.action_links['destroy_existing'] + active_scaffold_config.action_links.delete("delete") if active_scaffold_config.action_links['delete'] + end + else + # Production mode is caching this link into a non nested scaffold + active_scaffold_config.action_links.delete('new_existing') if active_scaffold_config.action_links['new_existing'] + + if active_scaffold_config.nested.shallow_delete + active_scaffold_config.action_links.delete("destroy_existing") if active_scaffold_config.action_links['destroy_existing'] + active_scaffold_config.action_links.add(ActiveScaffold::Config::Delete.link) unless active_scaffold_config.action_links['delete'] + end end - end end def beginning_of_chain - if nested? && nested[:association].collection? - nested_scope.send(nested[:name]) + if nested? && nested.association.collection? + nested.parent_scope.send(nested.association.name) else active_scaffold_config.model end end - def nested? - !nested.nil? - end - - def nested_habtm? - nested? ? nested[:association].macro == :has_and_belongs_to_many : false - end - - def nested_belongs_to? - nested? && nested[:association].belongs_to? - end - - def nested_parent_id - nested? ? nested[:parent_id]: nil - end - - def nested_scope - nested_parent.find(nested_parent_id) - end - def nested_parent_record(crud = :read) - find_if_allowed(nested_parent_id, crud, nested_parent) + find_if_allowed(nested.parent_id, crud, nested.parent_model) end - - def nested_parent - nested? ? nested[:parent_model]: nil - end - - def set_nested_list_label - active_scaffold_session_storage[:list][:label] = as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => nested_parent_record.to_label) if nested? - end - + def create_association_with_parent(record) - if nested? && nested_belongs_to? && nested[:child_association] + if nested? && nested.belongs_to? && nested.child_association parent = nested_parent_record(:read) - case nested[:child_association].macro + case nested.child_association.macro when :has_one - record.send("#{nested[:child_association].name}=", parent) + record.send("#{nested.child_association.name}=", parent) when :has_many - record.send("#{nested[:child_association].name}").send(:<<, parent) - end unless parent.nil? + record.send("#{nested.child_association.name}").send(:<<, parent) + end unless parent.nil? end end @@ -249,7 +206,7 @@ def do_add_existing def do_destroy_existing if active_scaffold_config.nested.shallow_delete @record = nested_parent_record(:update) - collection = @record.send(nested[:name]) + collection = @record.send(nested.association.name) assoc_record = collection.find(params[:id]) collection.delete(assoc_record) else diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb new file mode 100644 index 0000000000..ab8d1bcd63 --- /dev/null +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -0,0 +1,58 @@ +module ActiveScaffold::DataStructures + class NestedInfo + def self.get(model, session_storage) + if session_storage[:nested].nil? + nil + else + ActiveScaffold::DataStructures::NestedInfo.new(model, session_storage) + end + end + + attr_accessor :association, :child_association, :parent_model, :parent_id, :constrained_fields + + def initialize(model, session_storage) + info = session_storage[:nested].clone + @parent_model = info[:parent_model] + @association = @parent_model.reflect_on_association(info[:name]) + @parent_id = info[:parent_id] + iterate_model_associations(model) + end + + def new_instance? + result = @new_instance.nil? + @new_instance = false + result + end + + def parent_scope + parent_model.find(parent_id) + end + + def habtm? + association.macro == :has_and_belongs_to_many + end + + def belongs_to? + association.belongs_to? + end + + protected + def iterate_model_associations(model) + @constrained_fields = [] + @constrained_fields << association.primary_key_name.to_sym unless association.belongs_to? + model.reflect_on_all_associations.each do |current| + if !current.belongs_to? && association.primary_key_name == current.association_foreign_key + constrained_fields << current.name.to_sym + @child_association = current + end + if association.primary_key_name == current.primary_key_name + # show columns for has_many and has_one child associationes + constrained_fields << current.name.to_sym if current.belongs_to? + @child_association = current + end + end + end + + + end +end From 306fc197c43de741651c92dd8f913c60230662e5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 1 Jul 2010 11:20:19 +0200 Subject: [PATCH 0467/2024] remove nested url parameter --- frontends/default/views/_list_with_header.html.erb | 2 +- lib/active_scaffold.rb | 2 +- lib/active_scaffold/actions/core.rb | 7 ++++++- lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/helpers/controller_helpers.rb | 1 - 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/_list_with_header.html.erb b/frontends/default/views/_list_with_header.html.erb index 043f7fffc1..fcbe19c9b2 100644 --- a/frontends/default/views/_list_with_header.html.erb +++ b/frontends/default/views/_list_with_header.html.erb @@ -15,7 +15,7 @@ <% else %> <tr><td></td></tr> <% end %> - <% if params[:nested].nil? && active_scaffold_config.list.always_show_create %> + <% if !nested? && active_scaffold_config.list.always_show_create %> <tr> <td> <div class="active-scaffold create-view <%= "#{params[:controller]}-view" %> view"> diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index b6288a93cb..91f06fd425 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -123,7 +123,7 @@ def link_for_association(column, options = {}) unless controller.nil? options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column options[:parameters] ||= {} - options[:parameters].reverse_merge! :nested => true, :parent_model => column.active_record_class, :association => column.association.name + options[:parameters].reverse_merge! :parent_model => column.active_record_class, :association => column.association.name if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 9ee0861b1c..93fd3b3296 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -4,6 +4,7 @@ def self.included(base) base.class_eval do after_filter :clear_flashes end + base.helper_method :nested? end def render_field @record = if params[:in_place_editing] @@ -23,8 +24,12 @@ def render_field after_render_field(@record, column) end end - + protected + + def nested? + false + end # override this method if you want to do something after render_field def after_render_field(record, column); end diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 20d80e8fec..7530377f62 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -51,7 +51,7 @@ def create_respond_to_html return_to_main end else - if params[:nested].nil? && active_scaffold_config.actions.include?(:list) && active_scaffold_config.list.always_show_create + if !nested? && active_scaffold_config.actions.include?(:list) && active_scaffold_config.list.always_show_create do_list render(:action => 'list') else diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 2ff24edbb9..1fd65b482f 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -29,7 +29,6 @@ def main_path_to_return parameters[:controller] = params[:parent_controller] parameters[:eid] = params[:parent_controller] end - parameters[:nested] = nil parameters[:parent_column] = nil parameters[:parent_id] = nil parameters[:action] = "index" From be9114957d475b389e6a61f84d978c7232fbe84d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 1 Jul 2010 12:34:16 +0200 Subject: [PATCH 0468/2024] Bugfix: close link working correclty in inline_adapter view --- frontends/default/views/_show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_show.html.erb b/frontends/default/views/_show.html.erb index 14848254bf..0b4470cfc9 100644 --- a/frontends/default/views/_show.html.erb +++ b/frontends/default/views/_show.html.erb @@ -3,6 +3,6 @@ <%= render :partial => 'show_columns', :locals => {:columns => active_scaffold_config.show.columns} -%> <p class="form-footer"> - <%= link_to as_(:close), main_path_to_return, :class => 'cancel' %> + <%= link_to as_(:close), main_path_to_return, :class => 'as_cancel', :remote => true %> <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> </p> \ No newline at end of file From f5ccef6e668926cf9ee2e8825774e19d090aff7c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 1 Jul 2010 13:55:57 +0200 Subject: [PATCH 0469/2024] nested is nt a hash anymore --- frontends/default/views/on_update.js.rjs | 2 +- lib/active_scaffold/actions/nested.rb | 2 +- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 663146abec..4e288f8eb7 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -2,7 +2,7 @@ form_selector = "#{element_form_id(:action => :update)}" page << "$('#{form_selector}').up('.as_adapter').action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? - updated_row = if nested && nested[:association].belongs_to? + updated_row = if nested? && nested.association.belongs_to? nil else render :partial => 'list_record', :locals => {:record => @record} diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 23082512dd..5f150c3ac8 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -196,7 +196,7 @@ def do_add_existing parent_record = nested_parent_record(:update) @record = active_scaffold_config.model.find(params[:associated_id]) if parent_record && @record - parent_record.send(nested[:name]) << @record + parent_record.send(nested.association.name) << @record parent_record.save else false diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index d27f3a06c9..0f69df4652 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -324,7 +324,7 @@ def active_scaffold_add_existing_input(options) options.merge!(active_scaffold_input_text_options) record_select_field(options[:name], @record, options) else - select_options = options_for_select(options_for_association(nested[:association])) #unless column.through_association? + select_options = options_for_select(options_for_association(nested.association)) #unless column.through_association? select_options ||= options_for_select(active_scaffold_config.model.all.collect {|c| [h(c.to_label), c.id]}) select_tag 'associated_id', ('<option value="">' + as_(:_select_) + '</option>' + select_options).html_safe unless select_options.empty? end From 4f21e393cb572651e50f74dca8d4ccc629a9b999 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 1 Jul 2010 15:17:17 +0200 Subject: [PATCH 0470/2024] minor refactoring --- frontends/default/javascripts/active_scaffold.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/active_scaffold.js index 1643596f7e..dc5bc1a13b 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/active_scaffold.js @@ -370,20 +370,17 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ if(this.url.match('_method=delete')){ this.method = 'delete'; - this.tag.writeAttribute('data-method', this.method); - // action delete is special case cause in ajax world it will be destroy + // action delete is special case cause in ajax world it will be destroy } else if(this.url.match('/delete')){ this.url = this.url.replace('/delete', ''); this.tag.href = this.url; this.method = 'delete'; - this.tag.writeAttribute('data-method', this.method); } else if(this.url.match('_method=post')){ this.method = 'post'; - this.tag.writeAttribute('data-method', this.method); } else if(this.url.match('_method=put')){ this.method = 'put'; - this.tag.writeAttribute('data-method', this.method); } + if (this.method != 'get') this.tag.writeAttribute('data-method', this.method); this.target = target; this.loading_indicator = loading_indicator; this.hide_target = false; From eac0c4a1f9a42b8217ee26acf3954c1cb718e788 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 5 Jul 2010 09:16:21 +0200 Subject: [PATCH 0471/2024] Fix sorting and pagination for custom list actions --- frontends/default/views/_list_column_headings.html.erb | 3 +-- frontends/default/views/_list_pagination_links.html.erb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index dee87a3ab7..162e5babc1 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -9,8 +9,7 @@ default_sorting_stages = ['ASC', 'DESC'] <% stages = default_sorting.sorts_on?(column) ? default_sorting_stages : sorting_stages column_sort_direction = stages.after(sorting.direction_of(column)) || 'ASC' - sort_params = params_for(:action => :index, :page => 1, - :sort => column.name, :sort_direction => column_sort_direction) + sort_params = params_for(:page => 1, :sort => column.name, :sort_direction => column_sort_direction) column_header_id = active_scaffold_column_header_id(column) -%> <th id="<%= column_header_id %>" class="<%= column.css_class unless column.css_class.nil? %> <%= "sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column %>" title="<%= h column.description %>"> diff --git a/frontends/default/views/_list_pagination_links.html.erb b/frontends/default/views/_list_pagination_links.html.erb index 258e748e02..df08d1c56d 100644 --- a/frontends/default/views/_list_pagination_links.html.erb +++ b/frontends/default/views/_list_pagination_links.html.erb @@ -1,5 +1,5 @@ <% unless current_page.nil? -%> - <% pagination_params = params_for(:action => :index) -%> + <% pagination_params = params_for -%> <% indicator_params = pagination_params.merge(:action => 'pagination') -%> <% previous_url = url_for(pagination_params.merge(:page => current_page.number - 1)) -%> <% next_url = url_for(pagination_params.merge(:page => current_page.number + 1)) -%> From 1ffab7a30c00786f468a5ba8a220ed4bac0e342b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 7 Jul 2010 09:38:52 +0200 Subject: [PATCH 0472/2024] Fix #756 (Draggable lists don't render properly in IE7) --- frontends/default/stylesheets/stylesheet.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 4ddb1b211c..de55302c71 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -560,6 +560,10 @@ margin-bottom: 5px; /* Form ============================== */ +.active-scaffold dl { +margin: 0; +} + .active-scaffold .submit { font-weight: bold; font-size: 14px; From 1bd3c958f699668a356b42797d66ef1f806f56c3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 8 Jul 2010 08:33:40 +0200 Subject: [PATCH 0473/2024] Remove id from marked records when record is deleted --- lib/active_scaffold/actions/delete.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 8d60e510af..c2a3b4eb30 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -49,7 +49,7 @@ def do_destroy destroy_find_record begin self.successful = @record.destroy - marked_records.delete @record.id if successful? + marked_records.delete @record.id.to_s if successful? rescue flash[:warning] = as_(:cant_destroy_record, :record => @record.to_label) self.successful = false From f0867bfe771abcde2febf578615d8f8ac5e6b344 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 8 Jul 2010 08:39:16 +0200 Subject: [PATCH 0474/2024] Remove h method from id helpers because it cannot be used in controllers --- lib/active_scaffold/helpers/id_helpers.rb | 2 +- .../public/stylesheets/active_scaffold/default/stylesheet.css | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index 34bf9f9483..8a40cb1d4c 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -3,7 +3,7 @@ module Helpers # A bunch of helper methods to produce the common view ids module IdHelpers def id_from_controller(controller) - h(controller.to_s).gsub("/", "__") + controller.to_s.gsub("/", "__").html_safe end def controller_id diff --git a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css index 4ddb1b211c..de55302c71 100644 --- a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +++ b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css @@ -560,6 +560,10 @@ margin-bottom: 5px; /* Form ============================== */ +.active-scaffold dl { +margin: 0; +} + .active-scaffold .submit { font-weight: bold; font-size: 14px; From 9cfbb04afa3032bb93de6e9e481543b8fcb630fa Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 8 Jul 2010 10:30:09 +0200 Subject: [PATCH 0475/2024] add basic jquery support --- README | 4 + .../javascripts/jquery/active_scaffold.js | 685 ++++++++++++++++++ .../{ => prototype}/active_scaffold.js | 24 +- .../{ => prototype}/dhtml_history.js | 0 .../{ => prototype}/form_enhancements.js | 0 .../{ => prototype}/rico_corner.js | 0 frontends/default/views/_row.html.erb | 4 +- frontends/default/views/destroy.js.rjs | 4 +- frontends/default/views/list.js.rjs | 2 +- frontends/default/views/on_create.js.rjs | 12 +- frontends/default/views/on_update.js.rjs | 10 +- install_assets.rb | 13 +- 12 files changed, 737 insertions(+), 21 deletions(-) create mode 100644 frontends/default/javascripts/jquery/active_scaffold.js rename frontends/default/javascripts/{ => prototype}/active_scaffold.js (97%) rename frontends/default/javascripts/{ => prototype}/dhtml_history.js (100%) mode change 100755 => 100644 rename frontends/default/javascripts/{ => prototype}/form_enhancements.js (100%) rename frontends/default/javascripts/{ => prototype}/rico_corner.js (100%) diff --git a/README b/README index 82c7ffb52d..70121c6284 100644 --- a/README +++ b/README @@ -33,7 +33,11 @@ Since Rails 3.0 render_component is nt needed anymore Since Rails 3.0, the following is needed: rails plugin install git://github.com/rails/verification.git + Prototype 1.7 rails.js in git://github.com/vhochstein/prototype-ujs.git +JQuery 1.4.1 +rails.js in git://github.com/vhochstein/jquery-ujs.git + Released under the MIT license (included) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js new file mode 100644 index 0000000000..55d7a7e65d --- /dev/null +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -0,0 +1,685 @@ +$(document).ready(function() { + $('form.as_form').live('ajax:loading', function(event) { + var as_form = $(this).closest("form"); + if (as_form && as_form.attr('data-loading') == 'true') { + var loading_indicator = $('#' + as_form.get(0).id.replace(/-form$/, '-loading-indicator')); + if (loading_indicator) loading_indicator.css('visibility','visible'); + $('input[type=submit]', as_form).attr('disabled', 'disabled'); + $("input:disabled", as_form).attr('disabled', 'disabled'); + } + return true; + }); + $('form.as_form').live('ajax:complete', function(event) { + var as_form = $(this).closest("form"); + if (as_form && as_form.attr('data-loading') == 'true') { + var loading_indicator = $('#' + as_form.get(0).id.replace(/-form$/, '-loading-indicator')); + if (loading_indicator) loading_indicator.css('visibility','hidden'); + $('input[type=submit]', as_form).attr('disabled', ''); + $("input:disabled", as_form).attr('disabled', ''); + //event.stop(); + //return false; + } + }); + $('form.as_form').live('ajax:failure', function(event) { + var as_div = $(this).closest("div.active-scaffold"); + if (as_div) { + ActiveScaffold.report_500_response(as_div) + event.stop(); + return false; + } + }); + $('a.as_action').live('ajax:before', function(event) { + var as_action = $(this); + if (typeof(as_action.get(0).action_link) === 'undefined') { + var parent = as_action.parent(); + if (parent && parent.get(0).nodeName.toUpperCase() == 'TD') { + // record action + parent = parent.closest('tr.record'); + var target = parent.find('a.as_action'); + var loading_indicator = parent.find('td.actions .loading-indicator'); + new ActiveScaffold.Actions.Record(target, parent, loading_indicator); + } else if (parent && parent.get(0).nodeName.toUpperCase() == 'DIV') { + //table action + new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header'), parent.find('.loading-indicator')); + } + as_action = $(this); + } + if (as_action.get(0).action_link) { + var action_link = as_action.get(0).action_link; + if (action_link.is_disabled()) { + return false; + } else { + if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible'); + action_link.disable(); + } + } + return true; + }); + $('a.as_action').live('ajax:success', function(event, response) { + var as_action = $(this); + if (as_action.get(0).action_link) { + var action_link = as_action.get(0).action_link; + if (action_link.position) { + action_link.insert(response); + if (action_link.hide_target) action_link.target.hide(); + } else { + action_link.enable(); + } + //event.stop(); + return true; + } + return true; + }); + $('a.as_action').live('ajax:complete', function(event) { + var as_action = $(this); + if (as_action.get(0).action_link) { + var action_link = as_action.get(0).action_link; + if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden'); + } + return true; + }); + $('a.as_action').live('ajax:failure', function(event) { + var as_action = $this; + if (as_action.get(0).action_link) { + var action_link = as_action.get(0).action_link; + ActiveScaffold.report_500_response(action_link.scaffold_id()); + action_link.attr('disabled', ''); + } + return true; + }); + $('a.as_cancel').live('ajax:before', function(event) { + var as_adapter = $(this).closest('.as_adapter'); + var as_cancel = $(this); + + if (as_adapter.get(0).action_link) { + var action_link = as_adapter.get(0).action_link; + var cancel_url = as_cancel.attr('href'); + if (action_link.refresh_url) { + event.data_url = action_link.refresh_url; + if (action_link.position) event.data_type = 'html' + } else if (typeof(cancel_url) == 'undefined' || cancel_url.length == 0) { + action_link.close(); + return false; + } + } + return true; + }); + $('a.as_cancel').live('ajax:success', function(event, response) { + var as_adapter = $(this).closest('.as_adapter'); + + if (as_adapter.get(0).action_link) { + var action_link = as_adapter.get(0).action_link; + if (action_link.position) { + action_link.close(response); + } else { + response.evalResponse(); + } + } + return true; + }); + $('a.as_cancel').live('ajax:failure', function(event) { + var as_adapter = $(this).closest('.as_adapter'); + if (as_adapter.get(0).action_link) { + var action_link = as_adapter.get(0).action_link; + ActiveScaffold.report_500_response(action_link.scaffold_id()); + } + return true; + }); + $('a.as_sort').live('ajax:before', function(event) { + var as_sort = $(this); + var history_controller_id = as_sort.attr('data-page-history'); + if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.attr('href'), history_controller_id); + as_sort.closest('th').addClass('loading'); + return true; + }); + $('a.as_sort').live('ajax:failure', function(event) { + var as_scaffold = $(this).closest('.active-scaffold'); + ActiveScaffold.report_500_response(as_scaffold); + return true; + }); +}); + +/* Simple Inheritance + http://ejohn.org/blog/simple-javascript-inheritance/ +*/ +(function(){ + var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; + + // The base Class implementation (does nothing) + this.Class = function(){}; + + // Create a new Class that inherits from this class + Class.extend = function(prop) { + var _super = this.prototype; + + // Instantiate a base class (but only create the instance, + // don't run the init constructor) + initializing = true; + var prototype = new this(); + initializing = false; + + // Copy the properties over onto the new prototype + for (var name in prop) { + // Check if we're overwriting an existing function + prototype[name] = typeof prop[name] == "function" && + typeof _super[name] == "function" && fnTest.test(prop[name]) ? + (function(name, fn){ + return function() { + var tmp = this._super; + + // Add a new ._super() method that is the same method + // but on the super-class + this._super = _super[name]; + + // The method only need to be bound temporarily, so we + // remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; + + return ret; + }; + })(name, prop[name]) : + prop[name]; + } + + // The dummy class constructor + function Class() { + // All construction is actually done in the init method + if ( !initializing && this.init ) + this.init.apply(this, arguments); + } + + // Populate our constructed prototype object + Class.prototype = prototype; + + // Enforce the constructor to be what we expect + Class.constructor = Class; + + // And make this class extendable + Class.extend = arguments.callee; + + return Class; + }; +})(); + + +/* + * Simple utility methods + */ + +var ActiveScaffold = { + records_for: function(tbody_id) { + if (typeof(tbody_id) == 'string') tbody_id = '#' + tbody_id; + return $(tbody_id).children('.record'); + }, + stripe: function(tbody_id) { + var even = false; + var rows = this.records_for(tbody_id); + + rows.each(function (index, row_node) { + row = $(row_node); + if (row_node.tagName != 'SCRIPT' + && !row.hasClass("create") + && !row.hasClass("update") + && !row.hasClass("inline-adapter") + && !row.hasClass("active-scaffold-calculations")) { + + if (even) row.addClass("even-record"); + else row.removeClass("even-record"); + + even = !even; + } + }); + }, + hide_empty_message: function(tbody) { + if (this.records_for(tbody).length != 0) { + var empty_message_node = $(tbody).parent().find('tbody.messages p.empty-message') + if (empty_message_node) empty_message_node.hide(); + } + }, + reload_if_empty: function(tbody, url) { + if (this.records_for(tbody).length == 0) { + new Ajax.Request(url, { + method: 'get', + asynchronous: true, + evalScripts: true + }); + } + }, + removeSortClasses: function(scaffold) { + if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; + scaffold = $(scaffold) + scaffold.find('td.sorted').each(function(element) { + element.removeClass("sorted"); + }); + scaffold.find('th.sorted').each(function(element) { + element.removeClass("sorted"); + element.removeClass("asc"); + element.removeClass("desc"); + }); + }, + decrement_record_count: function(scaffold) { + // decrement the last record count, firsts record count are in nested lists + if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; + scaffold = $(scaffold) + count = scaffold.find('span.active-scaffold-records').last(); + if (count) count.html(parseInt(count.innerHTML, 10) - 1); + }, + increment_record_count: function(scaffold) { + // increment the last record count, firsts record count are in nested lists + if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; + scaffold = $(scaffold) + count = scaffold.find('span.active-scaffold-records').last(); + if (count) count.html(parseInt(count.innerHTML, 10) + 1); + }, + update_row: function(row, html) { + var even_row = false; + var replaced = null; + if (typeof(row) == 'string') row = '#' + row; + row = $(row); + if (row.hasClass('even-record')) even_row = true; + + replaced = this.replace(row, html); + if (even_row === true) replaced.addClass('even-record'); + //new_row.highlight(); + }, + + replace: function(element, html) { + if (typeof(element) == 'string') element = '#' + element; + element = $(element); + element.replaceWith(html); + element = $('#' + element.get(0).id); + return element; + }, + + replace_html: function(element, html) { + if (typeof(element) == 'string') element = '#' + element; + element = $(element); + element.html(html); + return element; + }, + + create_record_row: function(tbody, html) { + if (typeof(tbody) == 'string') tbody = '#' + tbody; + tbody = $(tbody); + tbody.prepend(html); + + var new_row = tbody.children('tr:first-child'); + this.stripe(tbody); + this.hide_empty_message(tbody); + this.increment_record_count(tbody.closest('div.active-scaffold')); + //new_row.highlight(); + }, + + delete_record_row: function(row, page_reload_url) { + if (typeof(row) == 'string') row = '#' + row; + row = $(row); + var tbody = row.closest('tbody.records'); + + var current_action_node = row.find('td.actions a.disabled').first(); + if (current_action_node && current_action_node.get(0).action_link) { + current_action_node.get(0).action_link.close_previous_adapter(); + } + row.remove(); + this.stripe(tbody); + this.decrement_record_count(tbody.closest('div.active-scaffold')); + this.reload_if_empty(tbody, page_reload_url); + }, + + report_500_response: function(active_scaffold_id) { + server_error = $(active_scaffold_id).find('td.messages-container p.server-error'); + if (!$(server_error).is(':visible')) { + server_error.show(); + } + }, + + find_action_link: function(element) { + if (typeof(element) == 'string') element = '#' + element; + var as_adapter = $(element).closest('.as_adapter'); + return as_adapter.get(0).action_link; + }, + + scroll_to: function(element) { + if (typeof(element) == 'string') element = '#' + element; + + } +} + +/* + * DHTML history tie-in + */ +function addActiveScaffoldPageToHistory(url, active_scaffold_id) { + if (typeof dhtmlHistory == 'undefined') return; // it may not be loaded + + var array = url.split('?'); + var qs = new Querystring(array[1]); + var sort = qs.get('sort') + var dir = qs.get('sort_direction') + var page = qs.get('page') + if (sort || dir || page) dhtmlHistory.add(active_scaffold_id+":"+page+":"+sort+":"+dir, url); +} + +/* + * URL modification support. Incomplete functionality. + */ +String.prototype.append_params = function(params) { + var url = this; + if (url.indexOf('?') == -1) url += '?'; + else if (url.lastIndexOf('&') != url.length) url += '&'; + + for(var key in params) { + if (key) url += (key + '=' + params[key] + '&'); + } + + // the loop leaves a comma dangling at the end of string, chop it off + url = url.substring(0, url.length-1); + return url; +}; + + +/** + * A set of links. As a set, they can be controlled such that only one is "open" at a time, etc. + */ +ActiveScaffold.Actions = new Object(); +ActiveScaffold.Actions.Abstract = Class.extend({ + init: function(links, target, loading_indicator, options) { + this.target = $(target); + this.loading_indicator = $(loading_indicator); + this.options = options; + var _this = this; + this.links = $.map(links, function(link) { + var my_link = _this.instantiate_link(link); + return my_link; + }); + }, + + instantiate_link: function(link) { + throw 'unimplemented' + } +}); + +/** + * A DataStructures::ActionLink, represented in JavaScript. + * Concerned with AJAX-enabling a link and adapting the result for insertion into the table. + */ +ActiveScaffold.ActionLink = new Object(); +ActiveScaffold.ActionLink.Abstract = Class.extend({ + init: function(a, target, loading_indicator) { + this.tag = $(a); + this.url = this.tag.get(0).href; + this.method = 'get'; + + if(this.url.match('_method=delete')){ + this.method = 'delete'; + // action delete is special case cause in ajax world it will be destroy + } else if(this.url.match('/delete')){ + this.url = this.url.replace('/delete', ''); + this.tag.get(0).href = this.url; + this.method = 'delete'; + } else if(this.url.match('_method=post')){ + this.method = 'post'; + } else if(this.url.match('_method=put')){ + this.method = 'put'; + } + if (this.method != 'get') this.tag.attr('data-method', this.method); + this.target = target; + this.loading_indicator = loading_indicator; + this.hide_target = false; + this.position = this.tag.attr('data-position'); + + this.tag.get(0).action_link = this; + return this; + }, + + open: function(event) { + }, + + insert: function(content) { + throw 'unimplemented' + }, + + close: function() { + this.enable(); + this.adapter.remove(); + if (this.hide_target) this.target.show(); + }, + + reload: function() { + this.close(); + this.open(); + }, + + get_new_adapter_id: function() { + var id = 'adapter_'; + var i = 0; + while ($(id + i)) i++; + return id + i; + }, + + enable: function() { + return this.tag.removeClass('disabled'); + }, + + disable: function() { + return this.tag.addClass('disabled'); + }, + + is_disabled: function() { + return this.tag.hasClass('disabled'); + }, + + scaffold_id: function() { + return '#' + this.tag.closest('div.active-scaffold').get(0).id; + }, + + update_flash_messages: function(messages) { + message_node = $(this.scaffold_id().replace(/-active-scaffold/, '-messages')); + if (message_node) message_node.html(messages); + }, + set_adapter: function(element) { + this.adapter = element; + this.adapter.addClass('as_adapter'); + this.adapter.get(0).action_link = this; + }, +}); + +/** + * Concrete classes for record actions + */ +ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({ + instantiate_link: function(link) { + var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); + var refresh = this.target.attr('data-refresh'); + if (refresh) l.refresh_url = refresh; + + if ($(link).hasClass('delete')) { + l.url = l.url.replace(/\/delete(\?.*)?$/, '$1'); + l.url = l.url.replace(/\/delete\/(.*)/, '/destroy/$1'); + l.tag.get(0).href = l.url; + } + if (l.position) { + l.url = l.url.append_params({adapter: '_list_inline_adapter'}); + l.tag.get(0).href = l.url; + } + l.set = this; + return l; + } +}); + +ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ + close_previous_adapter: function() { + var _this = this; + $.each(this.set.links, function(index, item) { + if (item.url != _this.url && item.is_disabled() && item.adapter) { + item.enable(); + item.adapter.remove(); + } + }); + }, + + insert: function(content) { + this.close_previous_adapter(); + + if (this.position == 'replace') { + this.position = 'after'; + this.hide_target = true; + } + + if (this.position == 'after') { + this.target.after(content); + this.set_adapter(this.target.next()); + } + else if (this.position == 'before') { + this.target.before(content); + this.set_adapter(this.target.prev()); + } + else { + return false; + } + }, + + close: function(refreshed_content) { + if (refreshed_content) { + ActiveScaffold.update_row(this.target, refreshed_content); + } + this._super(); + }, + + enable: function() { + var _this = this; + $.each(this.set.links, function(index, item) { + if (item.url != _this.url) return; + item.tag.removeClass('disabled'); + }); + }, + + disable: function() { + var _this = this; + $.each(this.set.links, function(index, item) { + if (item.url != _this.url) return; + item.tag.addClass('disabled'); + }); + } +}); + +/** + * Concrete classes for table actions + */ +ActiveScaffold.Actions.Table = ActiveScaffold.Actions.Abstract.extend({ + instantiate_link: function(link) { + var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator); + if (l.position) { + l.url = l.url.append_params({adapter: '_list_inline_adapter'}); + l.tag.get(0).href = l.url; + } + return l; + } +}); + +ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({ + insert: function(content) { + if (this.position == 'top') { + this.target.prepend(content); + this.set_adapter(this.target.children().first()); + } + else { + throw 'Unknown position "' + this.position + '"' + } + //this.adapter.find('td').first().children().highlight(); + } +}); + +if (typeof(Ajax) !== 'undefined' && Ajax.InPlaceEditor) { +ActiveScaffold.InPlaceEditor = Ajax.InPlaceEditor.extend({ + setFieldFromAjax: function(url, options) { + var ipe = this; + $(ipe._controls.editor).remove(); + new Ajax.Request(url, { + method: 'get', + onComplete: function(response) { + ipe._form.insert({top: response.responseText}); + if (options.plural) { + ipe._form.getElements().each(function(el) { + if (el.type != "submit" && el.type != "image") { + el.name = ipe.options.paramName + '[]'; + el.className = 'editor_field'; + } + }); + } else { + var fld = ipe._form.findFirstElement(); + fld.name = ipe.options.paramName; + fld.className = 'editor_field'; + if (ipe.options.submitOnBlur) + fld.onblur = ipe._boundSubmitHandler; + ipe._controls.editor = fld; + } + } + }); + }, + + clonePatternField: function() { + var patternNodes = this.getPatternNodes(this.options.inplacePatternSelector); + if (patternNodes.editNode == null) { + alert('did not find any matching node for ' + this.options.editFieldSelector); + return; + } + + var fld = patternNodes.editNode.cloneNode(true); + if (fld.id.length > 0) fld.id += this.options.nodeIdSuffix; + fld.name = this.options.paramName; + fld.className = 'editor_field'; + this.setValue(fld, this._controls.editor.value); + if (this.options.submitOnBlur) + fld.onblur = this._boundSubmitHandler; + $(this._controls.editor).remove(); + this._controls.editor = fld; + this._form.appendChild(this._controls.editor); + + $A(patternNodes.additionalNodes).each(function(node) { + var patternNode = node.cloneNode(true); + if (patternNode.id.length > 0) { + patternNode.id = patternNode.id + this.options.nodeIdSuffix; + } + this._form.appendChild(patternNode); + }.bind(this)); + }, + + getPatternNodes: function(inplacePatternSelector) { + var nodes = {editNode: null, additionalNodes: []}; + var selectedNodes = $$(inplacePatternSelector); + var firstNode = selectedNodes.first(); + + if (typeof(firstNode) !== 'undefined') { + // AS inplace_edit_control_container -> we have to select all child nodes + // Workaround for ie which does not support css > selector + if (firstNode.className.indexOf('as_inplace_pattern') !== -1) { + selectedNodes = firstNode.childElements(); + } + nodes.editNode = selectedNodes.first(); + selectedNodes.shift(); + nodes.additionalNodes = selectedNodes; + } + return nodes; + }, + + setValue: function(editField, textValue) { + var function_name = 'setValueFor' + editField.nodeName.toLowerCase(); + if (typeof(this[function_name]) == 'function') { + this[function_name](editField, textValue); + } else { + editField.value = textValue; + } + }, + + setValueForselect: function(editField, textValue) { + var len = editField.options.length; + var i = 0; + while (i < len && editField.options[i].text != textValue) { + i++; + } + if (i < len) { + editField.value = editField.options[i].value + } + } +}); +} diff --git a/frontends/default/javascripts/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js similarity index 97% rename from frontends/default/javascripts/active_scaffold.js rename to frontends/default/javascripts/prototype/active_scaffold.js index dc5bc1a13b..5778f4ceec 100644 --- a/frontends/default/javascripts/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -220,12 +220,24 @@ var ActiveScaffold = { }, update_row: function(row, html) { row = $(row); - Element.replace(row, html); - var new_row = $(row.id); + var new_row = this.replace(row, html) if (row.hasClassName('even-record')) new_row.addClassName('even-record'); new_row.highlight(); }, + replace: function(element, html) { + element = $(element) + Element.replace(element, html); + element = $(element.id); + return element; + }, + + replace_html: function(element, html) { + element = $(element); + element.update(html); + return element; + }, + create_record_row: function(tbody, html) { tbody = $(tbody); tbody.insert({top: html}); @@ -258,6 +270,14 @@ var ActiveScaffold = { } else { server_error.show(); } + }, + + find_action_link: function(element) { + return $(element).up('.as_adapter').action_link; + }, + + scroll_to: function(element) { + $(element).scrollTo();; } } diff --git a/frontends/default/javascripts/dhtml_history.js b/frontends/default/javascripts/prototype/dhtml_history.js old mode 100755 new mode 100644 similarity index 100% rename from frontends/default/javascripts/dhtml_history.js rename to frontends/default/javascripts/prototype/dhtml_history.js diff --git a/frontends/default/javascripts/form_enhancements.js b/frontends/default/javascripts/prototype/form_enhancements.js similarity index 100% rename from frontends/default/javascripts/form_enhancements.js rename to frontends/default/javascripts/prototype/form_enhancements.js diff --git a/frontends/default/javascripts/rico_corner.js b/frontends/default/javascripts/prototype/rico_corner.js similarity index 100% rename from frontends/default/javascripts/rico_corner.js rename to frontends/default/javascripts/prototype/rico_corner.js diff --git a/frontends/default/views/_row.html.erb b/frontends/default/views/_row.html.erb index 8972fd5b93..3044d61143 100644 --- a/frontends/default/views/_row.html.erb +++ b/frontends/default/views/_row.html.erb @@ -3,8 +3,8 @@ <script type="text/javascript"> //<![CDATA[ <%= update_page do |page| - page.replace active_scaffold_calculations_id, :partial => 'list_calculations' - end %> + page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') + end %> //]]> </script> <% end %> diff --git a/frontends/default/views/destroy.js.rjs b/frontends/default/views/destroy.js.rjs index 0a58c81287..cc0a0c81c1 100644 --- a/frontends/default/views/destroy.js.rjs +++ b/frontends/default/views/destroy.js.rjs @@ -1,5 +1,5 @@ if controller.send(:successful?) page << "ActiveScaffold.delete_record_row('#{element_row_id(:action => 'list', :id => params[:id])}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" - page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} + page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} end -page.replace_html active_scaffold_messages_id, :partial => 'messages' +page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, :partial => 'messages' diff --git a/frontends/default/views/list.js.rjs b/frontends/default/views/list.js.rjs index 7cbb9235fb..d98c799e87 100644 --- a/frontends/default/views/list.js.rjs +++ b/frontends/default/views/list.js.rjs @@ -1 +1 @@ -page[active_scaffold_content_id].replace_html render(:partial => 'list', :layout => false) +page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index 8f2cc5daf1..6217a9da25 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -1,23 +1,23 @@ form_selector = "#{element_form_id(:action => :create)}" -page << "$('#{form_selector}').up('.as_adapter').action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" +page << "ActiveScaffold.find_action_link('#{form_selector}').update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? if @insert_row new_row = render :partial => 'list_record', :locals => {:record => @record} page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}');" - page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} + page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} end if (active_scaffold_config.create.persistent) - page << "$('#{form_selector}').up('.as_adapter').action_link.reload();" + page << "ActiveScaffold.find_action_link('#{form_selector}').reload();" else - page << "$('#{form_selector}').up('.as_adapter').action_link.close();" + page << "ActiveScaffold.find_action_link('#{form_selector}').close();" end if (active_scaffold_config.create.edit_after_create) page << "var link = $('#{action_link_id 'edit', @record.id}');" page << "if (link) (function() { link.action_link.open() }).defer();" end else - page.replace form_selector, :partial => 'create_form', :locals => {:xhr => true} - page[form_selector].scroll_to + page.call 'ActiveScaffold.replace', form_selector, render(:partial => 'create_form', :locals => {:xhr => true}) + page.call 'ActiveScaffold.scroll_to', form_selector end diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 4e288f8eb7..5e245de8ad 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -1,15 +1,15 @@ form_selector = "#{element_form_id(:action => :update)}" -page << "$('#{form_selector}').up('.as_adapter').action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" +page << "ActiveScaffold.find_action_link('#{form_selector}').update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? updated_row = if nested? && nested.association.belongs_to? nil else render :partial => 'list_record', :locals => {:record => @record} end - page << "$('#{form_selector}').up('.as_adapter').action_link.close('#{escape_javascript(updated_row)}');" - page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} + page << "ActiveScaffold.find_action_link('#{form_selector}').close('#{escape_javascript(updated_row)}');" + page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} else - page.replace form_selector, :partial => 'update_form', :locals => {:xhr => true} - page[form_selector].scroll_to + page.call 'ActiveScaffold.replace', form_selector, render (:partial => 'update_form', :locals => {:xhr => true}) + page.call 'ActiveScaffold.scroll_to', form_selector end diff --git a/install_assets.rb b/install_assets.rb index 74d54ea166..f2df6a292f 100755 --- a/install_assets.rb +++ b/install_assets.rb @@ -6,9 +6,12 @@ ## Copy over asset files (javascript/css/images) from the plugin directory to public/ ## -def copy_files(source_path, destination_path, directory) +def copy_files(source_path, destination_path, directory, clean_up_destination = false) source, destination = File.join(directory, source_path), File.join(Rails.root, destination_path) FileUtils.mkdir_p(destination) unless File.exist?(destination) + Dir.glob('*.so') + + FileUtils.rm Dir.glob("#{destination}/*") if clean_up_destination FileUtils.cp_r(Dir.glob(source+'/*.*'), destination) end @@ -27,9 +30,13 @@ def copy_files(source_path, destination_path, directory) end available_frontends.each do |frontend| - source = "/frontends/#{frontend}/#{asset_type}/" + if asset_type == :javascripts + source = "/frontends/#{frontend}/#{asset_type}/prototype/" + else + source = "/frontends/#{frontend}/#{asset_type}/" + end destination = "/public/#{asset_type}/active_scaffold/#{frontend}" - copy_files(source, destination, directory) + copy_files(source, destination, directory, true) end end From f59002abb0d303d3208bd56388d5275d196bb202 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 8 Jul 2010 12:33:24 +0200 Subject: [PATCH 0476/2024] do not refresh from server if cancel link is clicked --- frontends/default/javascripts/jquery/active_scaffold.js | 5 +++-- frontends/default/javascripts/prototype/active_scaffold.js | 5 +++-- frontends/default/views/_base_form.html.erb | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 55d7a7e65d..2723ae37c6 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -94,10 +94,11 @@ $(document).ready(function() { if (as_adapter.get(0).action_link) { var action_link = as_adapter.get(0).action_link; var cancel_url = as_cancel.attr('href'); - if (action_link.refresh_url) { + var refresh_data = as_cancel.attr('data-refresh'); + if (refresh_data === 'true' && action_link.refresh_url) { event.data_url = action_link.refresh_url; if (action_link.position) event.data_type = 'html' - } else if (typeof(cancel_url) == 'undefined' || cancel_url.length == 0) { + } else if (refresh_data === 'false' || typeof(cancel_url) == 'undefined' || cancel_url.length == 0) { action_link.close(); return false; } diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 5778f4ceec..3fba5189f1 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -102,9 +102,10 @@ document.observe("dom:loaded", function() { if (as_adapter.action_link) { var action_link = as_adapter.action_link; - if (action_link.refresh_url) { + var refresh_data = as_cancel.readAttribute('data-refresh'); + if (refresh_data === 'true' && action_link.refresh_url) { event.memo.url = action_link.refresh_url; - } else if (as_cancel.readAttribute('href').blank()) { + } else if (refresh_data === 'false' || as_cancel.readAttribute('href').blank()) { action_link.close(); event.stop(); } diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index d09a5db6f9..9ac9bd7f90 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -30,7 +30,7 @@ end -%> <p class="form-footer"> <%= submit_tag as_(form_action), :class => "submit" %> - <%= link_to(as_(:cancel), main_path_to_return, :class => 'as_cancel', :remote => true) if cancel_link %> + <%= link_to(as_(:cancel), main_path_to_return, :class => 'as_cancel', :remote => true, 'data-refresh' => false) if cancel_link %> <%= loading_indicator_tag(:action => form_action, :id => params[:id]) %> </p> From d33f490753560d14601fe3c8f4583f280d037fe3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 9 Jul 2010 08:54:07 +0200 Subject: [PATCH 0477/2024] that extension is nt used anymore --- .../component_response_with_namespacing.rb | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 lib/extensions/component_response_with_namespacing.rb diff --git a/lib/extensions/component_response_with_namespacing.rb b/lib/extensions/component_response_with_namespacing.rb deleted file mode 100644 index b700781bb0..0000000000 --- a/lib/extensions/component_response_with_namespacing.rb +++ /dev/null @@ -1,17 +0,0 @@ -module ActionController #:nodoc: - module Components - module InstanceMethods - # Extracts the action_name from the request parameters and performs that action. - private - # This is to fix a bug in Rails. 1.2.2 was calling klass.controller_name instead of klass.controller_path, which was in turn setting the params[:controller] => "contacts", instead of params[:controller] => "two/contact". Submitted ticket #7545 - # Namespaces only supported in ActiveScaffold with Rails 1.2.2 - def component_response(options, reuse_response) - klass = component_class(options) - request = request_for_component(klass.controller_path, options) - new_response = reuse_response ? response : response.dup - - klass.process_with_components(request, new_response, self) - end - end - end -end \ No newline at end of file From 36038bc5cb30b1a4eb163c99f96394708cb81ee8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 15 Jul 2010 09:12:35 +0200 Subject: [PATCH 0478/2024] do not allow create, update, delete if association is readonly or if it is a through association --- lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/actions/delete.rb | 2 +- lib/active_scaffold/actions/update.rb | 2 +- lib/active_scaffold/data_structures/nested_info.rb | 10 +++++++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 7530377f62..b85c8aa54d 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -129,7 +129,7 @@ def create_ignore? end def create_authorized? - authorized_for?(:crud_type => :create) + (!nested? || !nested.readonly?) && authorized_for?(:crud_type => :create) end private def create_authorized_filter diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 103319b2bd..a99bf7d131 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -58,7 +58,7 @@ def do_destroy # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def delete_authorized?(record = nil) - authorized_for?(:crud_type => :delete) + (!nested? || !nested.readonly?) && authorized_for?(:crud_type => :delete) end private def delete_authorized_filter diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 12c8384c47..4cb72de283 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -112,7 +112,7 @@ def after_update_save(record); end # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def update_authorized?(record = nil) - authorized_for?(:crud_type => :update) + (!nested? || !nested.readonly?) && authorized_for?(:crud_type => :update) end private def update_authorized_filter diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index ab8d1bcd63..680c1a0bbc 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -13,7 +13,7 @@ def self.get(model, session_storage) def initialize(model, session_storage) info = session_storage[:nested].clone @parent_model = info[:parent_model] - @association = @parent_model.reflect_on_association(info[:name]) + @association = @parent_model.reflect_on_association(info[:name]) @parent_id = info[:parent_id] iterate_model_associations(model) end @@ -36,6 +36,14 @@ def belongs_to? association.belongs_to? end + def readonly? + if association.options.has_key? :readonly + association.options[:readonly] + else + association.options.has_key? :through + end + end + protected def iterate_model_associations(model) @constrained_fields = [] From 96ad5a3d8d5d241172370149f4f4b45b2425fb92 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 15 Jul 2010 17:28:54 +0200 Subject: [PATCH 0479/2024] extract method to define column heading classes --- frontends/default/views/_list_column_headings.html.erb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index 38c0a624a6..6e2ff29eec 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -12,7 +12,7 @@ default_sorting_stages = ['ASC', 'DESC'] :sort => column.name, :sort_direction => column_sort_direction) column_header_id = active_scaffold_column_header_id(column) -%> - <th id="<%= column_header_id %>" class="<%= column.css_class unless column.css_class.nil? %><%= " sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column %>" title="<%= h column.description %>"> + <th id="<%= column_header_id %>" class="<%= column_heading_class(column, sorting)%>" title="<%= h column.description %>"> <% if column.sortable? -%> <% options = {:id => search_form_id, :class => "as_sort", 'data-page-history' => controller_id, diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 1d7c00df68..48f99d913e 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -182,6 +182,14 @@ def column_class(column, column_value) classes << 'numeric' if column.column and [:decimal, :float, :integer].include?(column.column.type) classes.join(' ') end + + def column_heading_class(column, sorting) + classes = [] + classes << "#{column.name}-column_heading" + classes << "sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column + classes << column.css_class unless column.css_class.nil? + classes.join(' ') + end def column_empty?(column_value) empty = column_value.nil? From 4be0a6fdf45e60dcebe1c2fe02ab259702ca7c55 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 16 Jul 2010 13:49:32 +0200 Subject: [PATCH 0480/2024] Prototype: unobtrusive inplace editing --- .../javascripts/prototype/active_scaffold.js | 52 ++++++++ frontends/default/stylesheets/stylesheet.css | 2 +- .../views/_list_column_headings.html.erb | 24 +--- .../helpers/list_column_helpers.rb | 119 +++++++----------- 4 files changed, 102 insertions(+), 95 deletions(-) diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 3fba5189f1..6f70a0b1d2 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -145,6 +145,58 @@ document.observe("dom:loaded", function() { ActiveScaffold.report_500_response(as_scaffold); return true; }); + + document.on('click', 'span.in_place_editor_field', function(event) { + var span = event.findElement(); + + if (typeof(span.inplace_edit) === 'undefined') { + var options = {htmlResponse: false, + onEnterHover: null, + onLeaveHover: null, + onComplete: null, + ajaxOptions: {method: 'post'}}, + csrf_param = $$('meta[name=csrf-param]')[0], + csrf_token = $$('meta[name=csrf-token]')[0], + heading_selector = '.' + span.up().readAttribute('class').split(' ')[0] + '_heading', + column_heading = span.up('.active-scaffold').down(heading_selector), + render_url = column_heading.readAttribute('data-ie_render_url'), + mode = column_heading.readAttribute('data-ie_mode'), + record_id = span.readAttribute('data-ie_id'); + + + if (column_heading.readAttribute('data-ie_cancel_text')) options.cancelText = column_heading.readAttribute('data-ie_cancel_text'); + if (column_heading.readAttribute('data-ie_loading_text')) options.loadingText = column_heading.readAttribute('data-ie_loading_text'); + if (column_heading.readAttribute('data-ie_saving_text')) options.savingText = column_heading.readAttribute('data-ie_saving_text'); + if (column_heading.readAttribute('data-ie_save_text')) options.okText = column_heading.readAttribute('data-ie_save_text'); + if (column_heading.readAttribute('data-ie_rows')) options.rows = column_heading.readAttribute('data-ie_rows'); + if (column_heading.readAttribute('data-ie_cols')) options.cols = column_heading.readAttribute('data-ie_cols'); + if (column_heading.readAttribute('data-ie_size')) options.size = column_heading.readAttribute('data-ie_size'); + + if (csrf_param) { + var param = csrf_param.readAttribute('content'), + token = csrf_token.readAttribute('content'); + options['callback'] = new Function('form', 'return Form.serialize(form) + ' + "'&" + param + '=' + token + "';"); + } + + if (mode && mode === 'clone') { + options.nodeIdSuffix = record_id; + options.inplacePatternSelector = '#' + column_heading.id + ' .as_inplace_pattern'; + options['onFormCustomization'] = new Function('element', 'form', 'element.clonePatternField();'); + } + + if (render_url) { + var plural = false; + if (column_heading.readAttribute('data-ie_plural')) plural = true; + options['onFormCustomization'] = new Function('element', 'form', 'element.setFieldFromAjax(' + "'" + render_url.sub('__id__', record_id) + "', {plural: " + plural + '});'); + } + + span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.id, column_heading.readAttribute('data-ie_url').sub('__id__', record_id), options) + span.inplace_edit.enterEditMode(); + } + return true; + }); + + }); diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index b713c33fd0..41cedcaa19 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -35,7 +35,7 @@ text-decoration: none; color: #999; } -.active-scaffold a:hover { +.active-scaffold a:hover, .active-scaffold span.in_place_editor_field:hover { background-color: #ff8; } diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index 6e2ff29eec..40113c797d 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -5,28 +5,8 @@ default_sorting = active_scaffold_config.list.sorting default_sorting_stages = ['ASC', 'DESC'] -%> <% active_scaffold_config.list.columns.each do |column| -%> - <% - stages = default_sorting.sorts_on?(column) ? default_sorting_stages : sorting_stages - column_sort_direction = stages.after(sorting.direction_of(column)) || 'ASC' - url_options = params_for(:action => :index, :page => 1, - :sort => column.name, :sort_direction => column_sort_direction) - column_header_id = active_scaffold_column_header_id(column) - -%> - <th id="<%= column_header_id %>" class="<%= column_heading_class(column, sorting)%>" title="<%= h column.description %>"> - <% if column.sortable? -%> - <% options = {:id => search_form_id, :class => "as_sort", - 'data-page-history' => controller_id, - :remote => true, :method => :get} -%> - <%= link_to column.label, url_options, options -%> - <% else -%> - <% if column.name != :marked -%> - <p><%= column.label %></p> - <% else -%> - <%= mark_column_heading -%> - <% end -%> - <% end -%> - <%= inplace_edit_control(column) -%> - </th> + <% stages = default_sorting.sorts_on?(column) ? default_sorting_stages : sorting_stages -%> + <%= render_column_heading(column, sorting, stages.after(sorting.direction_of(column)) || 'ASC') %> <% end -%> <th class="actions"> </th> diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index ee945d32a7..e514008607 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -275,35 +275,10 @@ def format_inplace_edit_column(record,column) def active_scaffold_inplace_edit(record, column, options = {}) formatted_column = options[:formatted_column] || format_column_value(record, column) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} - tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field"} - in_place_editor_options = { - :url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s}, - :with => params[:eid] ? "Form.serialize(form) + '&eid=#{params[:eid]}'" : nil, - :click_to_edit_text => as_(:click_to_edit), - :cancel_text => as_(:cancel), - :loading_text => as_(:loading), - :save_text => as_(:update), - :saving_text => as_(:saving), - :ajax_options => "{method: 'post'}", - :script => true - } + tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field", + :title => as_(:click_to_edit), 'data-ie_id' => record.id.to_s} - if inplace_edit_cloning?(column) - in_place_editor_options.merge!( - :inplace_pattern_selector => "##{active_scaffold_column_header_id(column)} .#{inplace_edit_control_css_class}", - :node_id_suffix => record.id.to_s, - :form_customization => 'element.clonePatternField();' - ) - elsif column.inplace_edit == :ajax - url = url_for(:controller => params_for[:controller], :action => 'render_field', :id => record.id, :column => column.name, :update_column => column.name, :in_place_editing => true, :escape => false) - plural = column.plural_association? && !override_form_field?(column) && [:select, :record_select].include?(column.form_ui) - in_place_editor_options[:form_customization] = "element.setFieldFromAjax('#{escape_javascript(url)}', {plural: #{!!plural}});" - elsif column.column.try(:type) == :text - in_place_editor_options[:rows] = column.options[:rows] || 5 - end - - in_place_editor_options.merge!(column.options) - content_tag(:span, formatted_column, tag_options) + active_scaffold_in_place_editor(tag_options[:id], in_place_editor_options) + content_tag(:span, formatted_column, tag_options) end def inplace_edit_control(column) @@ -321,50 +296,27 @@ def inplace_edit_control_css_class "as_inplace_pattern" end - def active_scaffold_in_place_editor(field_id, options = {}) - function = "new ActiveScaffold.InPlaceEditor(" - function << "'#{field_id}', " - function << "'#{url_for(options[:url])}'" - - js_options = {} - - if protect_against_forgery? - options[:with] ||= "Form.serialize(form)" - options[:with] += " + '&authenticity_token=' + encodeURIComponent('#{form_authenticity_token}')" - end - - js_options['cancelText'] = %('#{options[:cancel_text]}') if options[:cancel_text] - js_options['okText'] = %('#{options[:save_text]}') if options[:save_text] - js_options['okControl'] = %('#{options[:save_control_type]}') if options[:save_control_type] - js_options['cancelControl'] = %('#{options[:cancel_control_type]}') if options[:cancel_control_type] - js_options['loadingText'] = %('#{options[:loading_text]}') if options[:loading_text] - js_options['savingText'] = %('#{options[:saving_text]}') if options[:saving_text] - js_options['rows'] = options[:rows] if options[:rows] - js_options['cols'] = options[:cols] if options[:cols] - js_options['size'] = options[:size] if options[:size] - js_options['externalControl'] = "'#{options[:external_control]}'" if options[:external_control] - js_options['externalControlOnly'] = "true" if options[:external_control_only] - js_options['submitOnBlur'] = "'#{options[:submit_on_blur]}'" if options[:submit_on_blur] - js_options['loadTextURL'] = "'#{url_for(options[:load_text_url])}'" if options[:load_text_url] - js_options['ajaxOptions'] = options[:ajax_options] if options[:ajax_options] - js_options['htmlResponse'] = !options[:script] if options[:script] - js_options['callback'] = "function(form) { return #{options[:with]} }" if options[:with] - js_options['clickToEditText'] = %('#{options[:click_to_edit_text]}') if options[:click_to_edit_text] - js_options['textBetweenControls'] = %('#{options[:text_between_controls]}') if options[:text_between_controls] - js_options['highlightcolor'] = %('#{options[:highlight_color]}') if options[:highlight_color] - js_options['highlightendcolor'] = %('#{options[:highlight_end_color]}') if options[:highlight_end_color] - js_options['onFailure'] = "function(element, transport) { #{options[:failure]} }" if options[:failure] - js_options['onComplete'] = "function(transport, element) { #{options[:complete]} }" if options[:complete] - js_options['onEnterEditMode'] = "function(element) { #{options[:enter_editing]} }" if options[:enter_editing] - js_options['onLeaveEditMode'] = "function(element) { #{options[:exit_editing]} }" if options[:exit_editing] - js_options['onFormCustomization'] = "function(element, form) { #{options[:form_customization]} }" if options[:form_customization] - js_options['inplacePatternSelector'] = %('#{options[:inplace_pattern_selector]}') if options[:inplace_pattern_selector] - js_options['nodeIdSuffix'] = %('#{options[:node_id_suffix]}') if options[:node_id_suffix] - function << (', ' + options_for_javascript(js_options)) unless js_options.empty? + def inplace_edit_tag_attributes(column) + tag_options = {} + tag_options['data-ie_url'] = url_for({:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => '__id__'}) + tag_options['data-ie_cancel_text'] = column.options[:cancel_text] || as_(:cancel) + tag_options['data-ie_loading_text'] = column.options[:loading_text] || as_(:loading) + tag_options['data-ie_save_text'] = column.options[:save_text] || as_(:update) + tag_options['data-ie_saving_text'] = column.options[:saving_text] || as_(:saving) + tag_options['data-ie_rows'] = column.options[:rows] || 5 if column.column.try(:type) == :text + tag_options['data-ie_cols'] = column.options[:cols] if column.options[:cols] + tag_options['data-ie_size'] = column.options[:size] if column.options[:size] - function << ')' - - javascript_tag(function) + if inplace_edit_cloning?(column) + tag_options['data-ie_mode'] = :clone + elsif column.inplace_edit == :ajax + url = url_for(:controller => params_for[:controller], :action => 'render_field', :id => '__id__', :column => column.name, :update_column => column.name, :in_place_editing => true, :escape => false) + plural = column.plural_association? && !override_form_field?(column) && [:select, :record_select].include?(column.form_ui) + tag_options['data-ie_render_url'] = url + tag_options['data-ie_mode'] = :ajax + tag_options['data-ie_plural'] = plural + end + tag_options end def mark_column_heading @@ -378,7 +330,30 @@ def mark_column_heading script = remote_function(ajax_options) content_tag(:span, check_box_tag(tag_options[:id], !all_marked, all_marked, {:onclick => script}) , tag_options) end - + + def render_column_heading(column, sorting, sort_direction) + tag_options = {:id => active_scaffold_column_header_id(column), :class => column_heading_class(column, sorting), :title => column.description} + tag_options.merge!(inplace_edit_tag_attributes(column)) if column.inplace_edit + content_tag(:th, column_heading_value(column, sorting, sort_direction) + inplace_edit_control(column), tag_options) + end + + + def column_heading_value(column, sorting, sort_direction) + if column.sortable? + options = {:id => search_form_id, :class => "as_sort", + 'data-page-history' => controller_id, + :remote => true, :method => :get} + url_options = params_for(:action => :index, :page => 1, + :sort => column.name, :sort_direction => sort_direction) + link_to column.label, url_options, options + else + if column.name != :marked + content_tag(:p, column.label) + else + mark_column_heading + end + end + end end end end From 1a9ff3880af196ab7a7976aa31c377d4f63d5b07 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 16 Jul 2010 15:38:50 +0200 Subject: [PATCH 0481/2024] Bugfix: inplace hover effect --- .../javascripts/prototype/active_scaffold.js | 16 ++++++++++++++-- frontends/default/stylesheets/stylesheet.css | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 6f70a0b1d2..4214083cec 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -145,7 +145,12 @@ document.observe("dom:loaded", function() { ActiveScaffold.report_500_response(as_scaffold); return true; }); - + document.on('mouseover', 'span.in_place_editor_field', function(event) { + event.findElement().addClassName('hover'); + }); + document.on('mouseout', 'span.in_place_editor_field', function(event) { + event.findElement().removeClassName('hover'); + }); document.on('click', 'span.in_place_editor_field', function(event) { var span = event.findElement(); @@ -189,7 +194,7 @@ document.observe("dom:loaded", function() { if (column_heading.readAttribute('data-ie_plural')) plural = true; options['onFormCustomization'] = new Function('element', 'form', 'element.setFieldFromAjax(' + "'" + render_url.sub('__id__', record_id) + "', {plural: " + plural + '});'); } - + span.removeClassName('hover'); span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.id, column_heading.readAttribute('data-ie_url').sub('__id__', record_id), options) span.inplace_edit.enterEditMode(); } @@ -620,6 +625,13 @@ ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstrac if (Ajax.InPlaceEditor) { ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { + initialize: function($super, element, url, options) { + $super(element, url, options); + if (this._originalBackground == 'transparent') { + this._originalBackground = null; + } + }, + setFieldFromAjax: function(url, options) { var ipe = this; $(ipe._controls.editor).remove(); diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 41cedcaa19..ad2861ab66 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -35,7 +35,7 @@ text-decoration: none; color: #999; } -.active-scaffold a:hover, .active-scaffold span.in_place_editor_field:hover { +.active-scaffold a:hover, .active-scaffold span.hover { background-color: #ff8; } From cff4082e7d0bfaf1271d6ae3e1ab62744400913e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 16 Jul 2010 16:58:52 +0200 Subject: [PATCH 0482/2024] jquery: minimize usage of get(0) --- .../javascripts/jquery/active_scaffold.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 2723ae37c6..90ba8e517b 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -2,7 +2,7 @@ $(document).ready(function() { $('form.as_form').live('ajax:loading', function(event) { var as_form = $(this).closest("form"); if (as_form && as_form.attr('data-loading') == 'true') { - var loading_indicator = $('#' + as_form.get(0).id.replace(/-form$/, '-loading-indicator')); + var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); if (loading_indicator) loading_indicator.css('visibility','visible'); $('input[type=submit]', as_form).attr('disabled', 'disabled'); $("input:disabled", as_form).attr('disabled', 'disabled'); @@ -12,7 +12,7 @@ $(document).ready(function() { $('form.as_form').live('ajax:complete', function(event) { var as_form = $(this).closest("form"); if (as_form && as_form.attr('data-loading') == 'true') { - var loading_indicator = $('#' + as_form.get(0).id.replace(/-form$/, '-loading-indicator')); + var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); if (loading_indicator) loading_indicator.css('visibility','hidden'); $('input[type=submit]', as_form).attr('disabled', ''); $("input:disabled", as_form).attr('disabled', ''); @@ -289,7 +289,7 @@ var ActiveScaffold = { if (typeof(element) == 'string') element = '#' + element; element = $(element); element.replaceWith(html); - element = $('#' + element.get(0).id); + element = $('#' + element.attr('id')); return element; }, @@ -407,7 +407,7 @@ ActiveScaffold.ActionLink = new Object(); ActiveScaffold.ActionLink.Abstract = Class.extend({ init: function(a, target, loading_indicator) { this.tag = $(a); - this.url = this.tag.get(0).href; + this.url = this.tag.attr('href'); this.method = 'get'; if(this.url.match('_method=delete')){ @@ -415,7 +415,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ // action delete is special case cause in ajax world it will be destroy } else if(this.url.match('/delete')){ this.url = this.url.replace('/delete', ''); - this.tag.get(0).href = this.url; + this.tag.attr('href', this.url); this.method = 'delete'; } else if(this.url.match('_method=post')){ this.method = 'post'; @@ -470,7 +470,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ }, scaffold_id: function() { - return '#' + this.tag.closest('div.active-scaffold').get(0).id; + return '#' + this.tag.closest('div.active-scaffold').attr('id'); }, update_flash_messages: function(messages) { @@ -496,11 +496,11 @@ ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({ if ($(link).hasClass('delete')) { l.url = l.url.replace(/\/delete(\?.*)?$/, '$1'); l.url = l.url.replace(/\/delete\/(.*)/, '/destroy/$1'); - l.tag.get(0).href = l.url; + l.tag.attr('href', l.url); } if (l.position) { l.url = l.url.append_params({adapter: '_list_inline_adapter'}); - l.tag.get(0).href = l.url; + l.tag.attr('href', l.url); } l.set = this; return l; @@ -571,7 +571,7 @@ ActiveScaffold.Actions.Table = ActiveScaffold.Actions.Abstract.extend({ var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator); if (l.position) { l.url = l.url.append_params({adapter: '_list_inline_adapter'}); - l.tag.get(0).href = l.url; + l.tag.attr('href', l.url); } return l; } From 214b9281ead04a89045331b3e1da26ca678d5f1a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 19 Jul 2010 09:33:57 +0200 Subject: [PATCH 0483/2024] Fix nested scaffolds --- frontends/default/views/_nested.html.erb | 2 +- lib/active_scaffold/actions/list.rb | 7 +------ lib/active_scaffold/helpers/controller_helpers.rb | 2 +- lib/active_scaffold/helpers/id_helpers.rb | 4 ---- lib/extensions/action_view_rendering.rb | 2 +- 5 files changed, 4 insertions(+), 13 deletions(-) diff --git a/frontends/default/views/_nested.html.erb b/frontends/default/views/_nested.html.erb index 6206304620..51b30f83cd 100644 --- a/frontends/default/views/_nested.html.erb +++ b/frontends/default/views/_nested.html.erb @@ -27,7 +27,7 @@ :constraints => @constraints, :conditions => association.options[:conditions], :label => h(@label), - :params => {:nested => true, :parent_column => column_name, :parent_model => association.active_record.name} + :params => {:nested => true, :parent_column => column_name, :parent_model => association.active_record.name, :format => 'html'} ) end end diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index cb42a79961..8b6f582cf5 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -9,11 +9,6 @@ def index list end - def table - do_list - render(:action => 'list.html', :layout => false) - end - # get just a single row def row render :partial => 'list_record', :locals => {:record => find_if_allowed(params[:id], :read)} @@ -28,7 +23,7 @@ def list protected def list_respond_to_html - render :action => 'list' + render :action => 'list', :layout => !respond_to?(:nested?) || !nested? end def list_respond_to_js render :action => 'list.js' diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index a79ed04f66..a9f2cd6530 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -12,7 +12,7 @@ def params_for(options = {}) # :sort, :sort_direction, and :page are arguments that stored in the session. they need not propagate. # and wow. no we don't want to propagate :record. # :commit is a special rails variable for form buttons - blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token] + blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token, :format] unless @params_for @params_for = params.clone.delete_if { |key, value| blacklist.include? key.to_sym if key } @params_for[:controller] = '/' + @params_for[:controller] unless @params_for[:controller].first(1) == '/' # for namespaced controllers diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index 8a40cb1d4c..93c956f12c 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -46,10 +46,6 @@ def search_input_id "#{controller_id}-search-input" end - def table_action_id(name) - "#{controller_id}-action-table-#{name}" - end - def action_link_id(link_action,link_id) "#{controller_id}-#{link_action}-#{link_id}-link" end diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index baee4a73ca..06822df817 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -56,7 +56,7 @@ def render_with_active_scaffold(*args, &block) options[:params] ||= {} options[:params].merge! :eid => eid - render_component :controller => remote_controller.to_s, :action => 'table', :params => options[:params] + render_component :controller => remote_controller.to_s, :action => 'index', :params => options[:params] else render_without_active_scaffold(*args, &block) end From 0885ce64a6b66858a7f2c75e4e2860f56a6411c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D0=B1=D0=BA=D0=BE=D0=B2?= <korobkov@neverbox.org> Date: Mon, 19 Jul 2010 21:12:48 +0400 Subject: [PATCH 0484/2024] rename :table to :index --- frontends/default/views/_list_header.html.erb | 4 ++-- frontends/default/views/_list_messages.html.erb | 4 ++-- frontends/default/views/list.html.erb | 2 +- lib/active_scaffold/actions/list.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index 8a09fb71f7..6027fbad97 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -1,6 +1,6 @@ <% if active_scaffold_config.action_links.any? { |link| link.type == :collection } -%> <div class="actions"> - <% new_params = params_for(:action => :table) %> + <% new_params = params_for(:action => :index) %> <% active_scaffold_config.action_links.each :collection do |link| -%> <% next if skip_action_link(link) -%> <% next if link.action == 'new' && params[:nested].nil? && active_scaffold_config.list.always_show_create %> @@ -8,7 +8,7 @@ <%= render_action_link(link, new_params) -%> <% end -%> - <%= loading_indicator_tag(:action => :table) %> + <%= loading_indicator_tag(:action => :index) %> </div> <% end %> <h2><%= active_scaffold_config.list.user.label %></h2> diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index 508609bb8f..2f20a3a4d8 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -9,8 +9,8 @@ { :url => href, :method => :get, :before => "addActiveScaffoldPageToHistory('#{href}', '#{params[:controller]}')", - :after => "$('#{loading_indicator_id(:action => :table)}').style.visibility = 'visible';", - :complete => "$('#{loading_indicator_id(:action => :table)}').style.visibility = 'hidden';", + :after => "$('#{loading_indicator_id(:action => :index)}').style.visibility = 'visible';", + :complete => "$('#{loading_indicator_id(:action => :index)}').style.visibility = 'hidden';", :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')" }, :href => href %> <% end -%> diff --git a/frontends/default/views/list.html.erb b/frontends/default/views/list.html.erb index 5fe5dfaed8..6337153e9d 100644 --- a/frontends/default/views/list.html.erb +++ b/frontends/default/views/list.html.erb @@ -37,7 +37,7 @@ Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-header').first(), {color: 'fromElement', bgColor: 'fromParent', corners: 'top', compact: true}); Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-footer').first(), {color: 'fromElement', bgColor: 'fromParent', corners: 'bottom', compact: true}); <% end -%> -new ActiveScaffold.Actions.Table($$('#<%= active_scaffold_id -%> div.active-scaffold-header a.action'), $('<%= before_header_id -%>'), $('<%= loading_indicator_id(:action => :table) -%>')); +new ActiveScaffold.Actions.Table($$('#<%= active_scaffold_id -%> div.active-scaffold-header a.action'), $('<%= before_header_id -%>'), $('<%= loading_indicator_id(:action => :index) -%>')); ActiveScaffold.server_error_response = '<p class="error-message message">' + <%= as_(:internal_error).to_json %> + '<a href="#" onclick="Element.remove(this.parentNode); return false;">' diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 8b6f582cf5..a137892c26 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -1,7 +1,7 @@ module ActiveScaffold::Actions module List def self.included(base) - base.before_filter :list_authorized_filter, :only => [:index, :table, :row, :list] + base.before_filter :list_authorized_filter, :only => [:index, :row, :list] base.send :include, ActiveScaffold::Actions::Mark if base.active_scaffold_config.list.mark_records end From 7770d5669ad6fbbf2438346f9ea40f25ffa61383 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 20 Jul 2010 08:45:40 +0200 Subject: [PATCH 0485/2024] jquery: support scroll_to --- frontends/default/javascripts/jquery/active_scaffold.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 90ba8e517b..387edb8d1f 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -342,7 +342,9 @@ var ActiveScaffold = { scroll_to: function(element) { if (typeof(element) == 'string') element = '#' + element; - + var form_offset = $(element).offset(), + destination = form_offset.top; + $(document).scrollTop(destination); } } From ec27c68bcab903914d327662db1de1df35bf143c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 20 Jul 2010 10:29:48 +0200 Subject: [PATCH 0486/2024] jquery: use jquery.data --- .../javascripts/jquery/active_scaffold.js | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 387edb8d1f..1c75517929 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -30,7 +30,7 @@ $(document).ready(function() { }); $('a.as_action').live('ajax:before', function(event) { var as_action = $(this); - if (typeof(as_action.get(0).action_link) === 'undefined') { + if (typeof(as_action.data('action_link')) === 'undefined') { var parent = as_action.parent(); if (parent && parent.get(0).nodeName.toUpperCase() == 'TD') { // record action @@ -44,8 +44,8 @@ $(document).ready(function() { } as_action = $(this); } - if (as_action.get(0).action_link) { - var action_link = as_action.get(0).action_link; + if (as_action.data('action_link')) { + var action_link = as_action.data('action_link'); if (action_link.is_disabled()) { return false; } else { @@ -57,8 +57,8 @@ $(document).ready(function() { }); $('a.as_action').live('ajax:success', function(event, response) { var as_action = $(this); - if (as_action.get(0).action_link) { - var action_link = as_action.get(0).action_link; + if (as_action.data('action_link')) { + var action_link = as_action.data('action_link'); if (action_link.position) { action_link.insert(response); if (action_link.hide_target) action_link.target.hide(); @@ -72,16 +72,16 @@ $(document).ready(function() { }); $('a.as_action').live('ajax:complete', function(event) { var as_action = $(this); - if (as_action.get(0).action_link) { - var action_link = as_action.get(0).action_link; + if (as_action.data('action_link')) { + var action_link = as_action.data('action_link'); if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden'); } return true; }); $('a.as_action').live('ajax:failure', function(event) { var as_action = $this; - if (as_action.get(0).action_link) { - var action_link = as_action.get(0).action_link; + if (as_action.data('action_link')) { + var action_link = as_action.data('action_link'); ActiveScaffold.report_500_response(action_link.scaffold_id()); action_link.attr('disabled', ''); } @@ -91,8 +91,8 @@ $(document).ready(function() { var as_adapter = $(this).closest('.as_adapter'); var as_cancel = $(this); - if (as_adapter.get(0).action_link) { - var action_link = as_adapter.get(0).action_link; + if (as_adapter.data('action_link')) { + var action_link = as_adapter.data('action_link'); var cancel_url = as_cancel.attr('href'); var refresh_data = as_cancel.attr('data-refresh'); if (refresh_data === 'true' && action_link.refresh_url) { @@ -108,8 +108,8 @@ $(document).ready(function() { $('a.as_cancel').live('ajax:success', function(event, response) { var as_adapter = $(this).closest('.as_adapter'); - if (as_adapter.get(0).action_link) { - var action_link = as_adapter.get(0).action_link; + if (as_adapter.data('action_link')) { + var action_link = as_adapter.data('action_link'); if (action_link.position) { action_link.close(response); } else { @@ -120,8 +120,8 @@ $(document).ready(function() { }); $('a.as_cancel').live('ajax:failure', function(event) { var as_adapter = $(this).closest('.as_adapter'); - if (as_adapter.get(0).action_link) { - var action_link = as_adapter.get(0).action_link; + if (as_adapter.data('action_link')) { + var action_link = as_adapter.data('action_link'); ActiveScaffold.report_500_response(action_link.scaffold_id()); } return true; @@ -318,8 +318,8 @@ var ActiveScaffold = { var tbody = row.closest('tbody.records'); var current_action_node = row.find('td.actions a.disabled').first(); - if (current_action_node && current_action_node.get(0).action_link) { - current_action_node.get(0).action_link.close_previous_adapter(); + if (current_action_node && current_action_node.data('action_link')) { + current_action_node.data('action_link').close_previous_adapter(); } row.remove(); this.stripe(tbody); @@ -337,7 +337,7 @@ var ActiveScaffold = { find_action_link: function(element) { if (typeof(element) == 'string') element = '#' + element; var as_adapter = $(element).closest('.as_adapter'); - return as_adapter.get(0).action_link; + return as_adapter.data('action_link'); }, scroll_to: function(element) { @@ -430,7 +430,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ this.hide_target = false; this.position = this.tag.attr('data-position'); - this.tag.get(0).action_link = this; + this.tag.data('action_link', this); return this; }, @@ -482,7 +482,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ set_adapter: function(element) { this.adapter = element; this.adapter.addClass('as_adapter'); - this.adapter.get(0).action_link = this; + this.adapter.data('action_link', this); }, }); From c4b50773c1e4c471791d7723e98c34e02c33c973 Mon Sep 17 00:00:00 2001 From: Andy Hartford <hartforda@gmail.com> Date: Tue, 20 Jul 2010 15:34:20 -0700 Subject: [PATCH 0487/2024] fix escaping issue with remote multipart forms --- lib/active_scaffold/helpers/view_helpers.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 697d1b69d8..b003359652 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -70,9 +70,8 @@ def form_remote_upload_tag(url_for_options = {}, options = {}) options[:target] = action_iframe_id(url_for_options) options[:multipart] = true - output="" - output << form_tag(url_for_options, options) - output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>" + output = form_tag(url_for_options, options) + output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>".html_safe end # Provides list of javascripts to include with +javascript_include_tag+ From e7a45c0c7e7a8a693512f09f358b37afe0895cb3 Mon Sep 17 00:00:00 2001 From: Andy Hartford <hartforda@gmail.com> Date: Tue, 20 Jul 2010 15:37:31 -0700 Subject: [PATCH 0488/2024] fix escaping issue with javascript error message --- frontends/default/views/list.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/list.html.erb b/frontends/default/views/list.html.erb index 6337153e9d..7548b2fe78 100644 --- a/frontends/default/views/list.html.erb +++ b/frontends/default/views/list.html.erb @@ -39,9 +39,9 @@ Rico.Corner.round($$('#<%= active_scaffold_id %> div.active-scaffold-footer').fi <% end -%> new ActiveScaffold.Actions.Table($$('#<%= active_scaffold_id -%> div.active-scaffold-header a.action'), $('<%= before_header_id -%>'), $('<%= loading_indicator_id(:action => :index) -%>')); ActiveScaffold.server_error_response = '<p class="error-message message">' - + <%= as_(:internal_error).to_json %> + + <%= as_(:internal_error).to_json.html_safe %> + '<a href="#" onclick="Element.remove(this.parentNode); return false;">' - + <%= as_(:close).to_json %> + + <%= as_(:close).to_json.html_safe %> + '</a>' + '</p>'; //]]> From f7a7c8d13577f791385f05b2f5aa4951574e4759 Mon Sep 17 00:00:00 2001 From: Andy Hartford <hartforda@gmail.com> Date: Tue, 20 Jul 2010 15:47:56 -0700 Subject: [PATCH 0489/2024] fix escaping problem with   literals --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index bd7f2953b7..08b248a703 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -23,7 +23,7 @@ def get_column_value(record, column) format_column_value(record, column) end - value = ' ' if value.nil? or (value.respond_to?(:empty?) and value.empty?) # fix for IE 6 + value = ' '.html_safe if value.nil? or (value.respond_to?(:empty?) and value.empty?) # fix for IE 6 return value rescue Exception => e logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index b003359652..038ccc173f 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -184,7 +184,7 @@ def column_class(column, column_value) def column_empty?(column_value) empty = column_value.nil? empty ||= column_value.empty? if column_value.respond_to? :empty? - empty ||= [' ', active_scaffold_config.list.empty_field_text].include? column_value if String === column_value + empty ||= [' '.html_safe, active_scaffold_config.list.empty_field_text].include? column_value if String === column_value return empty end From 9c3d9817b719cc62ebbd72aee0c35f2ab88f589d Mon Sep 17 00:00:00 2001 From: Andy Hartford <hartforda@gmail.com> Date: Tue, 20 Jul 2010 15:54:16 -0700 Subject: [PATCH 0490/2024] fix escape issue with display:none styling --- frontends/default/views/_list_messages.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index 2f20a3a4d8..f62acaac37 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -1,7 +1,7 @@ <div id="<%= active_scaffold_messages_id -%>"> <%= render :partial => 'messages' %> </div> - <p class="filtered-message" <%= ' style="display:none;" ' unless @filtered %>> + <p class="filtered-message" <%= ' style="display:none;" '.html_safe unless @filtered %>> <%= as_(active_scaffold_config.list.filtered_message) %> <% if active_scaffold_config.list.show_search_reset -%> <% href = url_for(params_for(:action => :index, :escape => false, :search => '')) -%> @@ -15,6 +15,6 @@ }, :href => href %> <% end -%> </p> - <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" ' unless @page.items.empty? %>> + <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" '.html_safe unless @page.items.empty? %>> <%= as_(active_scaffold_config.list.no_entries_message) %> </p> From 039bb9df60fdadcc1f73df949a0ce8f99bf76cbe Mon Sep 17 00:00:00 2001 From: Andy Hartford <hartforda@gmail.com> Date: Tue, 20 Jul 2010 16:43:47 -0700 Subject: [PATCH 0491/2024] fix escape issue with html includes --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 038ccc173f..74cf48051c 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -104,7 +104,7 @@ def active_scaffold_includes(*args) options[:concat] += '_ie' if options[:concat].is_a? String ie_css = stylesheet_link_tag(*active_scaffold_ie_stylesheets(frontend).push(options)) - "#{js}\n#{css}\n<!--[if IE]>#{ie_css}<![endif]-->\n" + "#{js}\n#{css}\n<!--[if IE]>#{ie_css}<![endif]-->\n".html_safe end # a general-use loading indicator (the "stuff is happening, please wait" feedback) From 4c7c166cafd5026b3a6660ed6888d5e6819584ce Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 21 Jul 2010 10:12:08 +0200 Subject: [PATCH 0492/2024] Fix update column for scoped fields --- .../helpers/form_column_helpers.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 2597d60464..6b36a997cd 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -79,14 +79,19 @@ def javascript_for_update_column(column, scope, options) if column.update_column form_action = :create form_action = :update if params[:action] == 'edit' - url_params = {:action => 'render_field', :id => params[:id], :column => column.name, :update_column => column.update_column} - url_params[:eid] = params[:eid] if params[:eid] + url_params = { + :action => 'render_field', + :id => params[:id], + :column => column.name, + :update_column => column.update_column, + :eid => params[:eid], + :scope => scope + } url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope - url_params[:scope] = params[:scope] if scope ajax_options = {:method => :get, :url => url_for(url_params), :with => column.send_form_on_update_column ? "Form.serialize(this.form)" : "'value=' + this.value", - :after => "$('#{loading_indicator_id(:action => :render_field, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => form_action)}');", - :complete => "$('#{loading_indicator_id(:action => :render_field, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => form_action)}');"} + :after => "$('#{loading_indicator_id(:action => form_action, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => form_action)}');", + :complete => "$('#{loading_indicator_id(:action => form_action, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => form_action)}');"} options[:onchange] = "#{remote_function(ajax_options)};#{options[:onchange]}" end options From 8d60d2bda5b67086aa7e9f2db4efc26a7995e3d8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 21 Jul 2010 12:47:15 +0200 Subject: [PATCH 0493/2024] Prefix overrides with record class name, it fixes #77 --- .../helpers/form_column_helpers.rb | 29 ++++++++++++------- .../helpers/list_column_helpers.rb | 15 +++++++--- .../helpers/search_column_helpers.rb | 15 +++++++--- .../helpers/show_column_helpers.rb | 15 +++++++--- lib/active_scaffold/helpers/view_helpers.rb | 8 +++++ 5 files changed, 59 insertions(+), 23 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 6b36a997cd..250fca6946 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -256,24 +256,27 @@ def override_subform_partial(column, subform_partial) File.join(active_scaffold_controller_for(column.association.klass).controller_path, subform_partial) if column_renders_as(column) == :subform end - def override_form_field_partial?(column) - path, partial_name = partial_pieces(override_form_field_partial(column)) + def override_form_field_partial?(column, old = false) + path, partial_name = partial_pieces(override_form_field_partial(column, old)) template_exists?(File.join(path, "_#{partial_name}"), true) end - # the naming convention for overriding form fields with partials - def override_form_field_partial(column) - "#{column.name}_form_column" - end - - def override_form_field?(column) - respond_to?(override_form_field(column)) + def override_form_field(column) + method = override_form_field_name(column) + return method if respond_to?(method) + old_method = override_form_field_name(column, true) + if respond_to?(old_method) + ActiveSupport::Deprecation.warn("You are using an old naming schema for overrides, you should name the helper #{method} instead of #{old_method}") + old_method + end end + alias_method :override_form_field?, :override_form_field # the naming convention for overriding form fields with helpers - def override_form_field(column) - "#{column.name}_form_column" + def override_form_field_name(column, old = false) + "#{clean_class_name(column.active_record_class.name) + '_' unless old}#{clean_column_name(column.name)}_form_column" end + alias_method :override_form_field_partial, :override_form_field_name def override_input?(form_ui) respond_to?(override_input(form_ui)) @@ -287,6 +290,10 @@ def override_input(form_ui) def form_partial_for_column(column) if override_form_field_partial?(column) override_form_field_partial(column) + # try old override partial naming + elsif override_form_field_partial?(column, true) + ActiveSupport::Deprecation.warn("You are using an old naming schema for overrides, you should name the partial #{override_form_field_partial(column)} instead of #{override_form_field_partial(column, true)}") + override_form_field_partial(column, true) elsif column_renders_as(column) == :field or override_form_field?(column) "form_attribute" elsif column_renders_as(column) == :subform diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 08b248a703..d2edbcd563 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -134,13 +134,20 @@ def active_scaffold_column_checkbox(column, record) end end - def column_override(column) - "#{column.name.to_s.gsub('?', '')}_column" # parse out any question marks (see issue 227) + def column_override_name(column, old = false) + "#{clean_class_name(column.active_record_class.name) + '_' unless old}#{clean_column_name(column.name)}_column" end - def column_override?(column) - respond_to?(column_override(column)) + def column_override(column) + method = column_override_name(column) + return method if respond_to?(method) + old_method = column_override_name(column, true) + if respond_to?(old_method) + ActiveSupport::Deprecation.warn("You are using an old naming schema for overrides, you should name the helper #{method} instead of #{old_method}") + old_method + end end + alias_method :column_override?, :column_override def override_column_ui?(list_ui) respond_to?(override_column_ui(list_ui)) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index e2c9913ce3..831910a9dc 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -200,13 +200,20 @@ def active_scaffold_search_time(column, options) ## Search column override signatures ## - def override_search_field?(column) - respond_to?(override_search_field(column)) + def override_search_field(column) + method = override_search_field_name(column) + return method if respond_to?(method) + old_method = override_search_field_name(column, true) + if respond_to?(old_method) + ActiveSupport::Deprecation.warn("You are using an old naming schema for overrides, you should name the helper #{method} instead of #{old_method}") + old_method + end end + alias_method :override_search_field?, :override_search_field # the naming convention for overriding form fields with helpers - def override_search_field(column) - "#{column.name}_search_column" + def override_search_field_name(column, old = false) + "#{clean_class_name(column.active_record_class.name) + '_' unless old}#{clean_column_name(column.name)}_search_column" end def override_search?(search_ui) diff --git a/lib/active_scaffold/helpers/show_column_helpers.rb b/lib/active_scaffold/helpers/show_column_helpers.rb index a330e63c68..27e500643e 100644 --- a/lib/active_scaffold/helpers/show_column_helpers.rb +++ b/lib/active_scaffold/helpers/show_column_helpers.rb @@ -25,13 +25,20 @@ def active_scaffold_show_text(column, record) simple_format(clean_column_value(record.send(column.name))) end - def show_column_override(column) - "#{column.name.to_s.gsub('?', '')}_show_column" # parse out any question marks (see issue 227) + def show_column_override_name(column, old = false) + "#{clean_class_name(column.active_record_class.name) + '_' unless old}#{clean_column_name(column.name)}_show_column" end - def show_column_override?(column) - respond_to?(show_column_override(column)) + def show_column_override(column) + method = show_column_override_name(column) + return method if respond_to?(method) + old_method = show_column_override_name(column, true) + if respond_to?(old_method) + ActiveSupport::Deprecation.warn("You are using an old naming schema for overrides, you should name the helper #{method} instead of #{old_method}") + old_method + end end + alias_method :show_column_override?, :show_column_override def override_show_column_ui?(list_ui) respond_to?(override_show_column_ui(list_ui)) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 74cf48051c..9fba63e994 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -217,6 +217,14 @@ def column_show_add_new(column, associated, record) def controller_class "#{h params[:controller]}-view" end + + def clean_column_name(name) + name.to_s.gsub('?', '') + end + + def clean_class_name(name) + name.underscore.gsub('/', '_') + end end end end From 9323d755ebd3ed0ea2b3cc79094b36879450efcb Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 21 Jul 2010 13:37:35 +0200 Subject: [PATCH 0494/2024] Use subform partials from subform controller instead of current controller. --- .../helpers/form_column_helpers.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 250fca6946..b4e253df0b 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -256,11 +256,17 @@ def override_subform_partial(column, subform_partial) File.join(active_scaffold_controller_for(column.association.klass).controller_path, subform_partial) if column_renders_as(column) == :subform end - def override_form_field_partial?(column, old = false) - path, partial_name = partial_pieces(override_form_field_partial(column, old)) + def override_form_field_partial?(column) + path, partial_name = partial_pieces(override_form_field_partial(column)) template_exists?(File.join(path, "_#{partial_name}"), true) end + # the naming convention for overriding form fields with helpers + def override_form_field_partial(column) + path = active_scaffold_controller_for(column.active_record_class).controller_path + File.join(path, "#{clean_column_name(column.name)}_form_column") + end + def override_form_field(column) method = override_form_field_name(column) return method if respond_to?(method) @@ -276,7 +282,6 @@ def override_form_field(column) def override_form_field_name(column, old = false) "#{clean_class_name(column.active_record_class.name) + '_' unless old}#{clean_column_name(column.name)}_form_column" end - alias_method :override_form_field_partial, :override_form_field_name def override_input?(form_ui) respond_to?(override_input(form_ui)) @@ -290,10 +295,6 @@ def override_input(form_ui) def form_partial_for_column(column) if override_form_field_partial?(column) override_form_field_partial(column) - # try old override partial naming - elsif override_form_field_partial?(column, true) - ActiveSupport::Deprecation.warn("You are using an old naming schema for overrides, you should name the partial #{override_form_field_partial(column)} instead of #{override_form_field_partial(column, true)}") - override_form_field_partial(column, true) elsif column_renders_as(column) == :field or override_form_field?(column) "form_attribute" elsif column_renders_as(column) == :subform From b980b83518f787eab4f18f883c020d034e5c1a0a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 21 Jul 2010 17:31:18 +0200 Subject: [PATCH 0495/2024] Prototype independent --- frontends/default/views/update_column.js.rjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/update_column.js.rjs b/frontends/default/views/update_column.js.rjs index 9c19a18e79..7a5d4ed248 100644 --- a/frontends/default/views/update_column.js.rjs +++ b/frontends/default/views/update_column.js.rjs @@ -1,13 +1,13 @@ column_span_id = element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column]) unless controller.send :successful? - page.alert(@record.errors.full_messages(active_scaffold_config).join("\n")) + page.call 'alert', @record.errors.full_messages(active_scaffold_config).join("\n") @record.reload end column = active_scaffold_config.columns[params[:column]] if column.inplace_edit - page.replace_html(column_span_id, format_inplace_edit_column(@record, column)) + page.call 'ActiveScaffold.replace_html', column_span_id, format_inplace_edit_column(@record, column) else formatted_value = get_column_value(@record, column) - page.replace_html(column_span_id, formatted_value) + page.call 'ActiveScaffold.replace_html', column_span_id, formatted_value end -page.replace_html(active_scaffold_calculations_id(column), render_column_calculation(column)) if column.calculation? +page.call 'ActiveScaffold.replace_html', active_scaffold_calculations_id(column), render_column_calculation(column) if column.calculation? From 4c3308a478676ac4a8c2f3bd4e0c8de5c9ff87de Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 21 Jul 2010 17:33:55 +0200 Subject: [PATCH 0496/2024] jquery: inplace edit support for text input fields --- .../javascripts/jquery/active_scaffold.js | 50 ++ .../javascripts/jquery/jquery.editinplace.js | 647 ++++++++++++++++++ 2 files changed, 697 insertions(+) create mode 100644 frontends/default/javascripts/jquery/jquery.editinplace.js diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 1c75517929..5d47eb06d2 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -138,6 +138,56 @@ $(document).ready(function() { ActiveScaffold.report_500_response(as_scaffold); return true; }); + $('span.in_place_editor_field').live('click', function(event) { + var span = $(this); + + if (typeof(span.data('editInPlace')) === 'undefined') { + var options = {show_buttons: true, + hover_class: 'hover', + element_id: 'editor_id', + ajax_data_type: "script", + update_value: 'value'}, + csrf_param = $('meta[name=csrf-param]').first(), + csrf_token = $('meta[name=csrf-token]').first(), + heading_selector = '.' + span.parent().attr('class').split(' ')[0] + '_heading', + column_heading = span.closest('.active-scaffold').find(heading_selector), + render_url = column_heading.attr('data-ie_render_url'), + mode = column_heading.attr('data-ie_mode'), + record_id = span.attr('data-ie_id'); + + + options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id) + if (column_heading.attr('data-ie_cancel_text')) options.cancel_button = '<button class="inplace_save">' + column_heading.attr('data-ie_cancel_text') + "</button>"; + if (column_heading.attr('data-ie_loading_text')) options.loadingText = column_heading.attr('data-ie_loading_text'); + if (column_heading.attr('data-ie_saving_text')) options.saving_text = column_heading.attr('data-ie_saving_text'); + if (column_heading.attr('data-ie_save_text')) options.save_button = '<button class="inplace_save">' + column_heading.attr('data-ie_save_text') + "</button>"; + if (column_heading.attr('data-ie_rows')) options.textarea_rows = column_heading.attr('data-ie_rows'); + if (column_heading.attr('data-ie_cols')) options.textarea_cols = column_heading.attr('data-ie_cols'); + if (column_heading.attr('data-ie_size')) options.text_size = column_heading.attr('data-ie_size'); + + if (csrf_param) { + var param = csrf_param.attr('content'), + token = csrf_token.attr('content'); + options['params'] = param + '=' + token + } + + if (mode && mode === 'clone') { + options.nodeIdSuffix = record_id; + options.inplacePatternSelector = '#' + column_heading.id + ' .as_inplace_pattern'; + options['onFormCustomization'] = new Function('element', 'form', 'element.clonePatternField();'); + } + + if (render_url) { + var plural = false; + if (column_heading.attr('data-ie_plural')) plural = true; + options['onFormCustomization'] = new Function('element', 'form', 'element.setFieldFromAjax(' + "'" + render_url.sub('__id__', record_id) + "', {plural: " + plural + '});'); + } + span.removeClass('hover'); + span.editInPlace(options); + span.trigger('click.editInPlace'); + //span.inplace_edit.enterEditMode(); + } + }); }); /* Simple Inheritance diff --git a/frontends/default/javascripts/jquery/jquery.editinplace.js b/frontends/default/javascripts/jquery/jquery.editinplace.js new file mode 100644 index 0000000000..4492e0e995 --- /dev/null +++ b/frontends/default/javascripts/jquery/jquery.editinplace.js @@ -0,0 +1,647 @@ +/* + +A jQuery edit in place plugin + +Version 2.2.0 + +Authors: + Dave Hauenstein + Martin Häcker <spamfaenger [at] gmx [dot] de> + +Project home: + http://code.google.com/p/jquery-in-place-editor/ + +Patches with tests welcomed! For guidance see the tests at </spec/unit/spec.js>. To submit, attach them to the bug tracker. + +License: +This source file is subject to the BSD license bundled with this package. +Available online: {@link http://www.opensource.org/licenses/bsd-license.php} +If you did not receive a copy of the license, and are unable to obtain it, +learn to use a search engine. + +*/ + +(function($){ + +$.fn.editInPlace = function(options) { + + var settings = $.extend({}, $.fn.editInPlace.defaults, options); + + assertMandatorySettingsArePresent(settings); + + preloadImage(settings.saving_image); + + return this.each(function() { + var dom = $(this); + // This won't work with live queries as there is no specific element to attach this + // one way to deal with this could be to store a reference to self and then compare that in click? + if (dom.data('editInPlace')) + return; // already an editor here + dom.data('editInPlace', true); + + new InlineEditor(settings, dom).init(); + }); +}; + +/// Switch these through the dictionary argument to $(aSelector).editInPlace(overideOptions) +/// Required Options: Either url or callback, so the editor knows what to do with the edited values. +$.fn.editInPlace.defaults = { + url: "", // string: POST URL to send edited content + ajax_data_type: "html", // string: dataType (html|script) for ajax call to save updated value + bg_over: "#ffc", // string: background color of hover of unactivated editor + bg_out: "transparent", // string: background color on restore from hover + hover_class: "", // string: class added to root element during hover. Will override bg_over and bg_out + show_buttons: false, // boolean: will show the buttons: cancel or save; will automatically cancel out the onBlur functionality + save_button: '<button class="inplace_save">Save</button>', // string: image button tag to use as “Save” button + cancel_button: '<button class="inplace_cancel">Cancel</button>', // string: image button tag to use as “Cancel” button + params: "", // string: example: first_name=dave&last_name=hauenstein extra paramters sent via the post request to the server + field_type: "text", // string: "text", "textarea", or "select"; The type of form field that will appear on instantiation + default_text: "(Click here to add text)", // string: text to show up if the element that has this functionality is empty + use_html: false, // boolean, set to true if the editor should use jQuery.fn.html() to extract the value to show from the dom node + textarea_rows: 10, // integer: set rows attribute of textarea, if field_type is set to textarea. Use CSS if possible though + textarea_cols: 25, // integer: set cols attribute of textarea, if field_type is set to textarea. Use CSS if possible though + select_text: "Choose new value", // string: default text to show up in select box + select_options: "", // string or array: Used if field_type is set to 'select'. Can be comma delimited list of options 'textandValue,text:value', Array of options ['textAndValue', 'text:value'] or array of arrays ['textAndValue', ['text', 'value']]. The last form is especially usefull if your labels or values contain colons) + text_size: null, // integer: set cols attribute of text input, if field_type is set to text. Use CSS if possible though + + // Specifying callback_skip_dom_reset will disable all saving_* options + saving_text: undefined, // string: text to be used when server is saving information. Example "Saving..." + saving_image: "", // string: uses saving text specify an image location instead of text while server is saving + saving_animation_color: 'transparent', // hex color string, will be the color the pulsing animation during the save pulses to. Note: Only works if jquery-ui is loaded + + value_required: false, // boolean: if set to true, the element will not be saved unless a value is entered + element_id: "element_id", // string: name of parameter holding the id or the editable + update_value: "update_value", // string: name of parameter holding the updated/edited value + original_value: 'original_value', // string: name of parameter holding the updated/edited value + original_html: "original_html", // string: name of parameter holding original_html value of the editable /* DEPRECATED in 2.2.0 */ use original_value instead. + save_if_nothing_changed: false, // boolean: submit to function or server even if the user did not change anything + on_blur: "save", // string: "save" or null; what to do on blur; will be overridden if show_buttons is true + cancel: "", // string: if not empty, a jquery selector for elements that will not cause the editor to open even though they are clicked. E.g. if you have extra buttons inside editable fields + + // All callbacks will have this set to the DOM node of the editor that triggered the callback + + callback: null, // function: function to be called when editing is complete; cancels ajax submission to the url param. Prototype: function(idOfEditor, enteredText, orinalHTMLContent, settingsParams, callbacks). The function needs to return the value that should be shown in the dom. Returning undefined means cancel and will restore the dom and trigger an error. callbacks is a dictionary with two functions didStartSaving and didEndSaving() that you can use to tell the inline editor that it should start and stop any saving animations it has configured. /* DEPRECATED in 2.1.0 */ Parameter idOfEditor, use $(this).attr('id') instead + callback_skip_dom_reset: false, // boolean: set this to true if the callback should handle replacing the editor with the new value to show + success: null, // function: this function gets called if server responds with a success. Prototype: function(newEditorContentString) + error: null, // function: this function gets called if server responds with an error. Prototype: function(request) + error_sink: function(idOfEditor, errorString) { alert(errorString); }, // function: gets id of the editor and the error. Make sure the editor has an id, or it will just be undefined. If set to null, no error will be reported. /* DEPRECATED in 2.1.0 */ Parameter idOfEditor, use $(this).attr('id') instead + preinit: null, // function: this function gets called after a click on an editable element but before the editor opens. If you return false, the inline editor will not open. Prototype: function(currentDomNode). DEPRECATED in 2.2.0 use delegate shouldOpenEditInPlace call instead + postclose: null, // function: this function gets called after the inline editor has closed and all values are updated. Prototype: function(currentDomNode). DEPRECATED in 2.2.0 use delegate didCloseEditInPlace call instead + delegate: null // object: if it has methods with the name of the callbacks documented below in delegateExample these will be called. This means that you just need to impelment the callbacks you are interested in. +}; + +// Lifecycle events that the delegate can implement +// this will always be fixed to the delegate +var delegateExample = { + // called while opening the editor. + // return false to prevent editor from opening + shouldOpenEditInPlace: function(aDOMNode, aSettingsDict, triggeringEvent) {}, + // return content to show in inplace editor + willOpenEditInPlace: function(aDOMNode, aSettingsDict) {}, + didOpenEditInPlace: function(aDOMNode, aSettingsDict) {}, + + // called while closing the editor + // return false to prevent the editor from closing + shouldCloseEditInPlace: function(aDOMNode, aSettingsDict, triggeringEvent) {}, + // return value will be shown during saving + willCloseEditInPlace: function(aDOMNode, aSettingsDict) {}, + didCloseEditInPlace: function(aDOMNode, aSettingsDict) {}, + + missingCommaErrorPreventer:'' +}; + + +function InlineEditor(settings, dom) { + this.settings = settings; + this.dom = dom; + this.originalValue = null; + this.didInsertDefaultText = false; + this.shouldDelayReinit = false; +}; + +$.extend(InlineEditor.prototype, { + + init: function() { + this.setDefaultTextIfNeccessary(); + this.connectOpeningEvents(); + }, + + reinit: function() { + if (this.shouldDelayReinit) + return; + + this.triggerCallback(this.settings.postclose, /* DEPRECATED in 2.1.0 */ this.dom); + this.triggerDelegateCall('didCloseEditInPlace'); + + this.markEditorAsInactive(); + this.connectOpeningEvents(); + }, + + setDefaultTextIfNeccessary: function() { + if('' !== this.dom.html()) + return; + + this.dom.html(this.settings.default_text); + this.didInsertDefaultText = true; + }, + + connectOpeningEvents: function() { + var that = this; + this.dom + .bind('mouseenter.editInPlace', function(){ that.addHoverEffect(); }) + .bind('mouseleave.editInPlace', function(){ that.removeHoverEffect(); }) + .bind('click.editInPlace', function(anEvent){ that.openEditor(anEvent); }); + }, + + disconnectOpeningEvents: function() { + // prevent re-opening the editor when it is already open + this.dom.unbind('.editInPlace'); + }, + + addHoverEffect: function() { + if (this.settings.hover_class) + this.dom.addClass(this.settings.hover_class); + else + this.dom.css("background-color", this.settings.bg_over); + }, + + removeHoverEffect: function() { + if (this.settings.hover_class) + this.dom.removeClass(this.settings.hover_class); + else + this.dom.css("background-color", this.settings.bg_out); + }, + + openEditor: function(anEvent) { + if ( ! this.shouldOpenEditor(anEvent)) + return; + + this.workAroundFirefoxBlurBug(); + this.disconnectOpeningEvents(); + this.removeHoverEffect(); + this.removeInsertedDefaultTextIfNeccessary(); + this.saveOriginalValue(); + this.markEditorAsActive(); + this.replaceContentWithEditor(); + this.connectOpeningEventsToEditor(); + this.triggerDelegateCall('didOpenEditInPlace'); + }, + + shouldOpenEditor: function(anEvent) { + if (this.isClickedObjectCancelled(anEvent.target)) + return false; + + if (false === this.triggerCallback(this.settings.preinit, /* DEPRECATED in 2.1.0 */ this.dom)) + return false; + + if (false === this.triggerDelegateCall('shouldOpenEditInPlace', true, anEvent)) + return false; + + return true; + }, + + removeInsertedDefaultTextIfNeccessary: function() { + if ( ! this.didInsertDefaultText + || this.dom.html() !== this.settings.default_text) + return; + + this.dom.html(''); + this.didInsertDefaultText = false; + }, + + isClickedObjectCancelled: function(eventTarget) { + if ( ! this.settings.cancel) + return false; + + var eventTargetAndParents = $(eventTarget).parents().andSelf(); + var elementsMatchingCancelSelector = eventTargetAndParents.filter(this.settings.cancel); + return 0 !== elementsMatchingCancelSelector.length; + }, + + saveOriginalValue: function() { + if (this.settings.use_html) + this.originalValue = this.dom.html(); + else + this.originalValue = trim(this.dom.text()); + }, + + restoreOriginalValue: function() { + this.setClosedEditorContent(this.originalValue); + }, + + setClosedEditorContent: function(aValue) { + if (this.settings.use_html) + this.dom.html(aValue); + else + this.dom.text(aValue); + }, + + workAroundFirefoxBlurBug: function() { + if ( ! $.browser.mozilla) + return; + + // TODO: Opera seems to also have this bug.... + + // Firefox will forget to send a blur event to an input element when another one is + // created and selected programmatically. This means that if another inline editor is + // opened, existing inline editors will _not_ close if they are configured to submit when blurred. + // This is actually the first time I've written browser specific code for a browser different than IE! Wohoo! + + // Using parents() instead document as base to workaround the fact that in the unittests + // the editor is not a child of window.document but of a document fragment + this.dom.parents(':last').find('.editInPlace-active :input').blur(); + }, + + replaceContentWithEditor: function() { + var buttons_html = (this.settings.show_buttons) ? this.settings.save_button + ' ' + this.settings.cancel_button : ''; + var editorElement = this.createEditorElement(); // needs to happen before anything is replaced + /* insert the new in place form after the element they click, then empty out the original element */ + this.dom.html('<form class="inplace_form" style="display: inline; margin: 0; padding: 0;"></form>') + .find('form') + .append(editorElement) + .append(buttons_html); + }, + + createEditorElement: function() { + if (-1 === $.inArray(this.settings.field_type, ['text', 'textarea', 'select'])) + throw "Unknown field_type <fnord>, supported are 'text', 'textarea' and 'select'"; + + var editor = null; + if ("select" === this.settings.field_type) + editor = this.createSelectEditor(); + else if ("text" === this.settings.field_type) + editor = $('<input type="text" ' + this.inputNameAndClass() + + ' size="' + this.settings.text_size + '" />'); + else if ("textarea" === this.settings.field_type) + editor = $('<textarea ' + this.inputNameAndClass() + + ' rows="' + this.settings.textarea_rows + '" ' + + ' cols="' + this.settings.textarea_cols + '" />'); + + editor.val(this.triggerDelegateCall('willOpenEditInPlace', this.originalValue)); + return editor; + }, + + inputNameAndClass: function() { + return ' name="inplace_value" class="inplace_field" '; + }, + + createSelectEditor: function() { + var editor = $('<select' + this.inputNameAndClass() + '>' + + '<option disabled="true" value="">' + this.settings.select_text + '</option>' + + '</select>'); + + var optionsArray = this.settings.select_options; + if ( ! $.isArray(optionsArray)) + optionsArray = optionsArray.split(','); + + for (var i=0; i<optionsArray.length; i++) { + + var currentTextAndValue = optionsArray[i]; + if ( ! $.isArray(currentTextAndValue)) + currentTextAndValue = currentTextAndValue.split(':'); + + var value = trim(currentTextAndValue[1] || currentTextAndValue[0]); + var text = trim(currentTextAndValue[0]); + + var selected = (value == this.originalValue) ? 'selected="selected" ' : ''; + var option = $('<option ' + selected + ' ></option>').val(value).text(text); + editor.append(option); + } + return editor; + + }, + + // REFACT: rename opening is not what it's about. Its about closing events really + connectOpeningEventsToEditor: function() { + var that = this; + function cancelEditorAction(anEvent) { + that.handleCancelEditor(anEvent); + return false; // stop event bubbling + } + function saveEditorAction(anEvent) { + that.handleSaveEditor(anEvent); + return false; // stop event bubbling + } + + var form = this.dom.find("form"); + + form.find(".inplace_field").focus().select(); + form.find(".inplace_cancel").click(cancelEditorAction); + form.find(".inplace_save").click(saveEditorAction); + + if ( ! this.settings.show_buttons) { + // TODO: Firefox has a bug where blur is not reliably called when focus is lost + // (for example by another editor appearing) + if ("save" === this.settings.on_blur) + form.find(".inplace_field").blur(saveEditorAction); + else + form.find(".inplace_field").blur(cancelEditorAction); + + // workaround for firefox bug where it won't submit on enter if no button is shown + if ($.browser.mozilla) + this.bindSubmitOnEnterInInput(); + } + + form.keyup(function(anEvent) { + // allow canceling with escape + var escape = 27; + if (escape === anEvent.which) + return cancelEditorAction(); + }); + + // workaround for webkit nightlies where they won't submit at all on enter + // REFACT: find a way to just target the nightlies + if ($.browser.safari) + this.bindSubmitOnEnterInInput(); + + + form.submit(saveEditorAction); + }, + + bindSubmitOnEnterInInput: function() { + if ('textarea' === this.settings.field_type) + return; // can't enter newlines otherwise + + var that = this; + this.dom.find(':input').keyup(function(event) { + var enter = 13; + if (enter === event.which) + return that.dom.find('form').submit(); + }); + + }, + + handleCancelEditor: function(anEvent) { + // REFACT: remove duplication between save and cancel + if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent)) + return; + + var enteredText = this.dom.find(':input').val(); + enteredText = this.triggerDelegateCall('willCloseEditInPlace', enteredText); + + this.restoreOriginalValue(); + if (hasContent(enteredText) + && ! this.isDisabledDefaultSelectChoice()) + this.setClosedEditorContent(enteredText); + this.reinit(); + }, + + handleSaveEditor: function(anEvent) { + if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent)) + return; + + var enteredText = this.dom.find(':input').val(); + enteredText = this.triggerDelegateCall('willCloseEditInPlace', enteredText); + + if (this.isDisabledDefaultSelectChoice() + || this.isUnchangedInput(enteredText)) { + this.handleCancelEditor(anEvent); + return; + } + + if (this.didForgetRequiredText(enteredText)) { + this.handleCancelEditor(anEvent); + this.reportError("Error: You must enter a value to save this field"); + return; + } + + this.showSaving(enteredText); + + if (this.settings.callback) + this.handleSubmitToCallback(enteredText); + else + this.handleSubmitToServer(enteredText); + }, + + didForgetRequiredText: function(enteredText) { + return this.settings.value_required + && ("" === enteredText + || undefined === enteredText + || null === enteredText); + }, + + isDisabledDefaultSelectChoice: function() { + return this.dom.find('option').eq(0).is(':selected:disabled'); + }, + + isUnchangedInput: function(enteredText) { + return ! this.settings.save_if_nothing_changed + && this.originalValue === enteredText; + }, + + showSaving: function(enteredText) { + if (this.settings.callback && this.settings.callback_skip_dom_reset) + return; + + var savingMessage = enteredText; + if (hasContent(this.settings.saving_text)) + savingMessage = this.settings.saving_text; + if(hasContent(this.settings.saving_image)) + // REFACT: alt should be the configured saving message + savingMessage = $('<img />').attr('src', this.settings.saving_image).attr('alt', savingMessage); + this.dom.html(savingMessage); + }, + + handleSubmitToCallback: function(enteredText) { + // REFACT: consider to encode enteredText and originalHTML before giving it to the callback + this.enableOrDisableAnimationCallbacks(true, false); + var newHTML = this.triggerCallback(this.settings.callback, /* DEPRECATED in 2.1.0 */ this.id(), enteredText, this.originalValue, + this.settings.params, this.savingAnimationCallbacks()); + + if (this.settings.callback_skip_dom_reset) + ; // do nothing + else if (undefined === newHTML) { + // failure; put original back + this.reportError("Error: Failed to save value: " + enteredText); + this.restoreOriginalValue(); + } + else + // REFACT: use setClosedEditorContent + this.dom.html(newHTML); + + if (this.didCallNoCallbacks()) { + this.enableOrDisableAnimationCallbacks(false, false); + this.reinit(); + } + }, + + handleSubmitToServer: function(enteredText) { + var data = this.settings.update_value + '=' + encodeURIComponent(enteredText) + + '&' + this.settings.element_id + '=' + this.dom.attr("id") + + ((this.settings.params) ? '&' + this.settings.params : '') + + '&' + this.settings.original_html + '=' + encodeURIComponent(this.originalValue) /* DEPRECATED in 2.2.0 */ + + '&' + this.settings.original_value + '=' + encodeURIComponent(this.originalValue); + + this.enableOrDisableAnimationCallbacks(true, false); + this.didStartSaving(); + var that = this; + $.ajax({ + url: that.settings.url, + type: "POST", + data: data, + dataType: that.settings.ajax_data_type, + complete: function(request){ + that.didEndSaving(); + }, + success: function(data){ + if (that.settings.ajax_data_type == 'html') { + var new_text = data || that.settings.default_text; + + /* put the newly updated info into the original element */ + // FIXME: should be affected by the preferences switch + that.dom.html(new_text); + // REFACT: remove dom parameter, already in this, not documented, should be easy to remove + // REFACT: callback should be able to override what gets put into the DOM + } + that.triggerCallback(that.settings.success,data); + }, + error: function(request) { + that.dom.html(that.originalHTML); // REFACT: what about a restorePreEditingContent() + if (that.settings.error) + // REFACT: remove dom parameter, already in this, not documented, can remove without deprecation + // REFACT: callback should be able to override what gets entered into the DOM + that.triggerCallback(that.settings.error, request); + else + that.reportError("Failed to save value: " + request.responseText || 'Unspecified Error'); + } + }); + }, + + // Utilities ......................................................... + + triggerCallback: function(aCallback /*, arguments */) { + if ( ! aCallback) + return; // callback wasn't specified after all + + var callbackArguments = Array.prototype.splice.call(arguments, 1); + return aCallback.apply(this.dom[0], callbackArguments); + }, + + /// defaultReturnValue is only used if the delegate returns undefined + triggerDelegateCall: function(aDelegateMethodName, defaultReturnValue, optionalEvent) { + // REFACT: consider to trigger equivalent callbacks automatically via a mapping table? + if ( ! this.settings.delegate + || ! $.isFunction(this.settings.delegate[aDelegateMethodName])) + return defaultReturnValue; + + var delegateReturnValue = this.settings.delegate[aDelegateMethodName](this.dom, this.settings, optionalEvent); + return (undefined === delegateReturnValue) + ? defaultReturnValue + : delegateReturnValue; + }, + + reportError: function(anErrorString) { + this.triggerCallback(this.settings.error_sink, /* DEPRECATED in 2.1.0 */ this.id(), anErrorString); + }, + + // REFACT: this method should go, callbacks should get the dom node itself as an argument + id: function() { + return this.dom.attr('id'); + }, + + markEditorAsActive: function() { + this.dom.addClass('editInPlace-active'); + }, + + markEditorAsInactive: function() { + this.dom.removeClass('editInPlace-active'); + }, + + // REFACT: consider rename, doesn't deal with animation directly + savingAnimationCallbacks: function() { + var that = this; + return { + didStartSaving: function() { that.didStartSaving(); }, + didEndSaving: function() { that.didEndSaving(); } + }; + }, + + enableOrDisableAnimationCallbacks: function(shouldEnableStart, shouldEnableEnd) { + this.didStartSaving.enabled = shouldEnableStart; + this.didEndSaving.enabled = shouldEnableEnd; + }, + + didCallNoCallbacks: function() { + return this.didStartSaving.enabled && ! this.didEndSaving.enabled; + }, + + assertCanCall: function(methodName) { + if ( ! this[methodName].enabled) + throw new Error('Cannot call ' + methodName + ' now. See documentation for details.'); + }, + + didStartSaving: function() { + this.assertCanCall('didStartSaving'); + this.shouldDelayReinit = true; + this.enableOrDisableAnimationCallbacks(false, true); + + this.startSavingAnimation(); + }, + + didEndSaving: function() { + this.assertCanCall('didEndSaving'); + this.shouldDelayReinit = false; + this.enableOrDisableAnimationCallbacks(false, false); + this.reinit(); + + this.stopSavingAnimation(); + }, + + startSavingAnimation: function() { + var that = this; + this.dom + .animate({ backgroundColor: this.settings.saving_animation_color }, 400) + .animate({ backgroundColor: 'transparent'}, 400, 'swing', function(){ + // In the tests animations are turned off - i.e they happen instantaneously. + // Hence we need to prevent this from becomming an unbounded recursion. + setTimeout(function(){ that.startSavingAnimation(); }, 10); + }); + }, + + stopSavingAnimation: function() { + this.dom + .stop(true) + .css({backgroundColor: ''}); + }, + + missingCommaErrorPreventer:'' +}); + + + +// Private helpers ....................................................... + +function assertMandatorySettingsArePresent(options) { + // one of these needs to be non falsy + if (options.url || options.callback) + return; + + throw new Error("Need to set either url: or callback: option for the inline editor to work."); +} + +/* preload the loading icon if it is configured */ +function preloadImage(anImageURL) { + if ('' === anImageURL) + return; + + var loading_image = new Image(); + loading_image.src = anImageURL; +} + +function trim(aString) { + return aString + .replace(/^\s+/, '') + .replace(/\s+$/, ''); +} + +function hasContent(something) { + if (undefined === something || null === something) + return false; + + if (0 === something.length) + return false; + + return true; +} + +})(jQuery); From b20e166478b7af0ab84e4e401c2ffd0a35ad76ba Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 21 Jul 2010 19:08:24 +0200 Subject: [PATCH 0497/2024] jquery: inplace_edit supports type :ajax --- .../javascripts/jquery/active_scaffold.js | 4 ++-- .../javascripts/jquery/jquery.editinplace.js | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 5d47eb06d2..71b92c0f50 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -180,12 +180,12 @@ $(document).ready(function() { if (render_url) { var plural = false; if (column_heading.attr('data-ie_plural')) plural = true; - options['onFormCustomization'] = new Function('element', 'form', 'element.setFieldFromAjax(' + "'" + render_url.sub('__id__', record_id) + "', {plural: " + plural + '});'); + options.field_type = 'remote'; + options.editor_url = render_url.replace(/__id__/, record_id) } span.removeClass('hover'); span.editInPlace(options); span.trigger('click.editInPlace'); - //span.inplace_edit.enterEditMode(); } }); }); diff --git a/frontends/default/javascripts/jquery/jquery.editinplace.js b/frontends/default/javascripts/jquery/jquery.editinplace.js index 4492e0e995..27ce3a8a72 100644 --- a/frontends/default/javascripts/jquery/jquery.editinplace.js +++ b/frontends/default/javascripts/jquery/jquery.editinplace.js @@ -55,7 +55,7 @@ $.fn.editInPlace.defaults = { save_button: '<button class="inplace_save">Save</button>', // string: image button tag to use as “Save” button cancel_button: '<button class="inplace_cancel">Cancel</button>', // string: image button tag to use as “Cancel” button params: "", // string: example: first_name=dave&last_name=hauenstein extra paramters sent via the post request to the server - field_type: "text", // string: "text", "textarea", or "select"; The type of form field that will appear on instantiation + field_type: "text", // string: "text", "textarea", or "select", or "remote"; The type of form field that will appear on instantiation default_text: "(Click here to add text)", // string: text to show up if the element that has this functionality is empty use_html: false, // boolean, set to true if the editor should use jQuery.fn.html() to extract the value to show from the dom node textarea_rows: 10, // integer: set rows attribute of textarea, if field_type is set to textarea. Use CSS if possible though @@ -63,6 +63,7 @@ $.fn.editInPlace.defaults = { select_text: "Choose new value", // string: default text to show up in select box select_options: "", // string or array: Used if field_type is set to 'select'. Can be comma delimited list of options 'textandValue,text:value', Array of options ['textAndValue', 'text:value'] or array of arrays ['textAndValue', ['text', 'value']]. The last form is especially usefull if your labels or values contain colons) text_size: null, // integer: set cols attribute of text input, if field_type is set to text. Use CSS if possible though + editor_url: null, // for field_type: remote url to get html_code for edit_control // Specifying callback_skip_dom_reset will disable all saving_* options saving_text: undefined, // string: text to be used when server is saving information. Example "Saving..." @@ -263,8 +264,8 @@ $.extend(InlineEditor.prototype, { }, createEditorElement: function() { - if (-1 === $.inArray(this.settings.field_type, ['text', 'textarea', 'select'])) - throw "Unknown field_type <fnord>, supported are 'text', 'textarea' and 'select'"; + if (-1 === $.inArray(this.settings.field_type, ['text', 'textarea', 'select', 'remote'])) + throw "Unknown field_type <fnord>, supported are 'text', 'textarea', 'select' and 'remote'"; var editor = null; if ("select" === this.settings.field_type) @@ -276,11 +277,20 @@ $.extend(InlineEditor.prototype, { editor = $('<textarea ' + this.inputNameAndClass() + ' rows="' + this.settings.textarea_rows + '" ' + ' cols="' + this.settings.textarea_cols + '" />'); + else if ("remote" === this.settings.field_type) + editor = this.createRemoteGeneratedEditor(); editor.val(this.triggerDelegateCall('willOpenEditInPlace', this.originalValue)); return editor; }, + createRemoteGeneratedEditor: function () { + return $($.ajax({ + url: this.settings.editor_url, + async: false + }).responseText); + }, + inputNameAndClass: function() { return ' name="inplace_value" class="inplace_field" '; }, From d82857f4b3125e2790e410f64e3d9332f2221ebb Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 22 Jul 2010 09:03:41 +0200 Subject: [PATCH 0498/2024] Bugfix: use correct cancel button class for jquery inplace edit --- frontends/default/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 71b92c0f50..df7da08063 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -157,7 +157,7 @@ $(document).ready(function() { options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id) - if (column_heading.attr('data-ie_cancel_text')) options.cancel_button = '<button class="inplace_save">' + column_heading.attr('data-ie_cancel_text') + "</button>"; + if (column_heading.attr('data-ie_cancel_text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.attr('data-ie_cancel_text') + "</button>"; if (column_heading.attr('data-ie_loading_text')) options.loadingText = column_heading.attr('data-ie_loading_text'); if (column_heading.attr('data-ie_saving_text')) options.saving_text = column_heading.attr('data-ie_saving_text'); if (column_heading.attr('data-ie_save_text')) options.save_button = '<button class="inplace_save">' + column_heading.attr('data-ie_save_text') + "</button>"; From 0cbb8038f67dd250d7ed53b3417c422f4d96c046 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 22 Jul 2010 09:34:54 +0200 Subject: [PATCH 0499/2024] Sort hashes by id or temporary id so associated records are created in the same order as user write them --- lib/active_scaffold/attribute_params.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index dd290a7dd5..651da79a60 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -111,7 +111,8 @@ def column_value_from_param_value(parent_record, column, value) elsif column.singular_association? manage_nested_record_from_params(parent_record, column, value) elsif column.plural_association? - value.collect {|key_value_pair| manage_nested_record_from_params(parent_record, column, key_value_pair[1])}.compact + # sort by id or temporary id so new records are created in the same order as user write them + value.sort.collect {|key_value_pair| manage_nested_record_from_params(parent_record, column, key_value_pair[1])}.compact else value end From 9f62578efc8100bb598f594bedae74fdd18476f1 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 22 Jul 2010 10:34:16 +0200 Subject: [PATCH 0500/2024] fix {{key}} interpolation syntax in I18n message is deprecated --- lib/active_scaffold/locale/de.rb | 20 ++++++++++---------- lib/active_scaffold/locale/en.rb | 24 ++++++++++++------------ lib/active_scaffold/locale/es.yml | 24 ++++++++++++------------ lib/active_scaffold/locale/fr.rb | 20 ++++++++++---------- lib/active_scaffold/locale/hu.yml | 18 +++++++++--------- lib/active_scaffold/locale/ja.yml | 20 ++++++++++---------- lib/active_scaffold/locale/ru.yml | 18 +++++++++--------- 7 files changed, 72 insertions(+), 72 deletions(-) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 13de7d9eaa..1942c113d6 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -3,24 +3,24 @@ :active_scaffold => { :add => 'Hinzufügen', :add_existing => 'Existierenden Eintrag hinzufügen', - :add_existing_model => 'Existierende {{model}} hinzufügen', + :add_existing_model => 'Existierende %{model} hinzufügen', :are_you_sure_to_delete => 'Sind Sie sicher?', :cancel => 'Abbrechen', :click_to_edit => 'Zum Editieren anklicken', :close => 'Schliessen', :create => 'Anlegen', - :create_model => 'Lege {{model}} an', + :create_model => 'Lege %{model} an', :create_another => 'Weitere anlegen', - :created_model => '{{model}} anlegen', + :created_model => '%{model} anlegen', :create_new => 'Neu anlegen', :customize => 'Anpassen', :delete => 'Löschen', - :deleted_model => '{{model}} gelöscht', + :deleted_model => '%{model} gelöscht', :delimiter => 'Trennzeichen', :download => 'Download', :edit => 'Bearbeiten', :export => 'Exportieren', - :nested_for_model => '{{nested_model}} für {{parent_model}}', + :nested_for_model => '%{nested_model} für %{parent_model}', :filtered => '(Gefiltert)', :found => 'Gefunden', :hide => 'Verstecken', @@ -38,18 +38,18 @@ :remove => 'Entfernen', :remove_file => 'Entferne oder Ersetze Datei', :replace_with_new => 'Mit Neuer ersetzen', - :revisions_for_model => 'Revisionen für {{model}}', + :revisions_for_model => 'Revisionen für %{model}', :reset => 'Zurücksetzen', :saving => 'Speichern…', :search => 'Suche', :search_terms => 'Suchbegriffe', :_select_ => '- Auswählen -', :show => 'Anzeigen', - :show_model => 'Zeige {{model}} an', + :show_model => 'Zeige %{model} an', :_to_ => ' zu ', :update => 'Speichern', - :update_model => 'Editiere {{model}}', - :updated_model => '{{model}} aktualisiert', + :update_model => 'Editiere %{model}', + :updated_model => '%{model} aktualisiert', :'=' => '=', :'>=' => '>=', :'<=' => '<=', @@ -59,7 +59,7 @@ :between => 'Zwischen', # error_messages - :cant_destroy_record => "{{record}} kann nicht gelöscht werden", + :cant_destroy_record => "%{record} kann nicht gelöscht werden", :internal_error => 'Fehler bei der Verarbeitung (code 500, Interner Fehler)', :version_inconsistency => 'Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben.' } diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 889587e8ea..0d59136730 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -3,25 +3,25 @@ :active_scaffold => { :add => 'Add', :add_existing => 'Add Existing', - :add_existing_model => 'Add Existing {{model}}', - :are_you_sure_to_delete => 'Are you sure you want to delete {{label}}?', + :add_existing_model => 'Add Existing %{model}', + :are_you_sure_to_delete => 'Are you sure you want to delete %{label}?', :cancel => 'Cancel', :click_to_edit => 'Click to edit', :click_to_reset => 'Click to reset', :close => 'Close', :create => 'Create', - :create_model => 'Create {{model}}', - :create_another => 'Create Another {{model}}', - :created_model => 'Created {{model}}', + :create_model => 'Create %{model}', + :create_another => 'Create Another %{model}', + :created_model => 'Created %{model}', :create_new => 'Create New', :customize => 'Customize', :delete => 'Delete', - :deleted_model => 'Deleted {{model}}', + :deleted_model => 'Deleted %{model}', :delimiter => 'Delimiter', :download => 'Download', :edit => 'Edit', :export => 'Export', - :nested_for_model => '{{nested_model}} for {{parent_model}}', + :nested_for_model => '%{nested_model} for %{parent_model}', :false => 'False', :filtered => '(Filtered)', :found => 'Found', @@ -40,19 +40,19 @@ :remove => 'Remove', :remove_file => 'Remove or Replace file', :replace_with_new => 'Replace With New', - :revisions_for_model => 'Revisions for {{model}}', + :revisions_for_model => 'Revisions for %{model}', :reset => 'Reset', :saving => 'Saving…', :search => 'Search', :search_terms => 'Search Terms', :_select_ => '- select -', :show => 'Show', - :show_model => 'Show {{model}}', + :show_model => 'Show %{model}', :_to_ => ' to ', :true => 'True', :update => 'Update', - :update_model => 'Update {{model}}', - :updated_model => 'Updated {{model}}', + :update_model => 'Update %{model}', + :updated_model => 'Updated %{model}', :'=' => '=', :'>=' => '>=', :'<=' => '<=', @@ -65,7 +65,7 @@ :ends_with => 'Ends with', # error_messages - :cant_destroy_record => "{{record}} can't be destroyed", + :cant_destroy_record => "%{record} can't be destroyed", :internal_error => 'Request Failed (code 500, Internal Error)', :version_inconsistency => 'Version inconsistency - this record has been modified since you started editing it.' } diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index 9e42da2807..691099784b 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -2,20 +2,20 @@ es: active_scaffold: add: 'Añadir' add_existing: 'Añadir Existente' - add_existing_model: 'Añadir {{model}} Existente' - are_you_sure_to_delete: '¿Estás seguro de que quieres borrar {{label}}?' + add_existing_model: 'Añadir %{model} Existente' + are_you_sure_to_delete: '¿Estás seguro de que quieres borrar %{label}?' cancel: 'Cancelar' click_to_edit: 'Pulsa para editar' click_to_reset: 'Pulsa para restaurar' close: 'Cerrar' create: 'Crear' - create_model: 'Crear {{model}}' - create_another: 'Crear Otro {{model}}' - created_model: '{{model}} creado' + create_model: 'Crear %{model}' + create_another: 'Crear Otro %{model}' + created_model: '%{model} creado' create_new: 'Crear Nuevo' customize: 'Personalizar' delete: 'Borrar' - deleted_model: '{{model}} borrado' + deleted_model: '%{model} borrado' delimiter: 'Delimitador' download: 'Descargar' edit: 'Editar' @@ -28,7 +28,7 @@ es: hide: 'Ocultar' live_search: 'Buscar en Vivo' loading: 'Cargando…' - nested_for_model: '{{nested_model}} de {{parent_model}}' + nested_for_model: '%{nested_model} de %{parent_model}' next: 'Siguiente' no_entries: 'Sin entradas' no_options: 'sin opciones' @@ -41,19 +41,19 @@ es: remove: 'Eliminar' remove_file: 'Eliminar o Reemplazar archivo' replace_with_new: 'Reemplazar con Nuevo' - revisions_for_model: 'Revisiones de {{model}}' + revisions_for_model: 'Revisiones de %{model}' reset: 'Restaurar' saving: 'Guardando…' search: 'Buscar' search_terms: 'Términos a buscar' _select_: '- seleccionar -' show: 'Ver' - show_model: 'Ver {{model}}' + show_model: 'Ver %{model}' _to_ : ' a ' 'true': 'Sí' update: 'Actualizar' - update_model: 'Actualizar {{model}}' - updated_model: '{{model}} actualizado' + update_model: 'Actualizar %{model}' + updated_model: '%{model} actualizado' '=': '=' '>=': '>=' '<=': '<=' @@ -66,6 +66,6 @@ es: ends_with: 'Termina con' # error_messages - cant_destroy_record: "No se pudo borrar {{record}}" + cant_destroy_record: "No se pudo borrar %{record}" internal_error: 'Petición fallida (código 500, error interno)' version_inconsistency: 'Inconsistencia de versiones - este registro se ha modificado después de que empezó a editarlo.' diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 664757b8b6..d7371325f5 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -3,24 +3,24 @@ :active_scaffold => { :add => 'Ajouter', :add_existing => 'Ajouter un(e) existant(e)', - :add_existing_model => 'Ajouter un(e) {{model}} existant(e)', + :add_existing_model => 'Ajouter un(e) %{model} existant(e)', :are_you_sure_to_delete => 'Êtes vous sûr?', :cancel => 'Annuler', :click_to_edit => 'Cliquer pour éditer', :close => 'Fermer', :create => 'Créer', - :create_model => 'Créer {{model}}', + :create_model => 'Créer %{model}', :create_another => 'Créer un autre', - :created_model => '{{model}} créé', + :created_model => '%{model} créé', :create_new => 'Créer un nouveau', :customize => 'Personnaliser', :delete => 'Supprimer', - :deleted_model => 'Suppression de {{model}}', + :deleted_model => 'Suppression de %{model}', :delimiter => 'Délimiteur', :download => 'Télécharger', :edit => 'Éditer', :export => 'Exporter', - :nested_for_model => '{{nested_model}} pour {{parent_model}}', + :nested_for_model => '%{nested_model} pour %{parent_model}', :filtered => '(Filtré)', :found => 'Trouvé', :hide => 'Cacher', @@ -38,18 +38,18 @@ :remove => 'Supprimer', :remove_file => 'Supprimer et remplacer le fichier', :replace_with_new => 'Remplacer avec le nouveau', - :revisions_for_model => 'Révision pour {{model}}', + :revisions_for_model => 'Révision pour %{model}', :reset => 'Annuler', :saving => 'Sauvegarder…', :search => 'Rechercher', :search_terms => 'Recherche de termes', :_select_ => '- sélectionner -', :show => 'Montrer', - :show_model => 'Montrer {{model}}', + :show_model => 'Montrer %{model}', :_to_ => ' à ', :update => 'Mettre à jour', - :update_model => 'Mettre à jour le(/la) {{model}}', - :updated_model => 'Mis à jour de {{model}}', + :update_model => 'Mettre à jour le(/la) %{model}', + :updated_model => 'Mis à jour de %{model}', :'=' => '=', :'>=' => '>=', :'<=' => '<=', @@ -62,4 +62,4 @@ :internal_error => 'Erreur de la requête (code 500, Erreur interne)', :version_inconsistency => "Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer.", } - }} + } diff --git a/lib/active_scaffold/locale/hu.yml b/lib/active_scaffold/locale/hu.yml index d9a47cd792..decc13d1a4 100644 --- a/lib/active_scaffold/locale/hu.yml +++ b/lib/active_scaffold/locale/hu.yml @@ -2,24 +2,24 @@ hu: active_scaffold: add: 'Hozzáadás' add_existing: 'Meglevő hozzáadása' - add_existing_model: 'Meglevő {{model}} hozzáadása' + add_existing_model: 'Meglevő %{model} hozzáadása' are_you_sure_to_delete: 'Biztos vagy benne?' cancel: 'Mégse' click_to_edit: 'Kattints a szerkesztéshez' close: 'Bezárás' create: 'Létrehozás' - create_model: '{{model}} létrehozása' + create_model: '%{model} létrehozása' create_another: 'Mégegy hozzáadása' - created_model: '{{model}} létrehozva' + created_model: '%{model} létrehozva' create_new: 'Új létrehozása' customize: 'Testreszabás' delete: 'Törlés' - deleted_model: '{{model}} törölve' + deleted_model: '%{model} törölve' delimiter: 'Elválasztó' download: 'Letöltés' edit: 'Szerkesztés' export: 'Exportálás' - nested_for_model: '{{nested_model}} / {{parent_model}}' + nested_for_model: '%{nested_model} / %{parent_model}' filtered: '(Szűrt)' found: 'Találat' hide: 'Elrejtés' @@ -37,18 +37,18 @@ hu: remove: 'Törlés' remove_file: 'Fájl törlése, vagy cseréje' replace_with_new: 'Csere újjal' - revisions_for_model: '{{model}} revíziói' + revisions_for_model: '%{model} revíziói' reset: 'Alapállapot' saving: 'Mentés…' search: 'Keresés' search_terms: 'Keresési kifejezések' _select_: '- válassz -' show: 'Mutatás' - show_model: '{{model}} mutatása' + show_model: '%{model} mutatása' _to_ : ' – ' update: 'Modosítás' - update_model: '{{model}} modosítása' - updated_model: '{{model}} módosítva' + update_model: '%{model} modosítása' + updated_model: '%{model} módosítva' '=': '=' '>=': '>=' '<=': '<=' diff --git a/lib/active_scaffold/locale/ja.yml b/lib/active_scaffold/locale/ja.yml index 7240a5dfa4..c047b1f548 100644 --- a/lib/active_scaffold/locale/ja.yml +++ b/lib/active_scaffold/locale/ja.yml @@ -2,24 +2,24 @@ ja: active_scaffold: add: '追加' add_existing: '既存のものを追加' - add_existing_model: '既存の{{model}}を追加' + add_existing_model: '既存の%{model}を追加' are_you_sure_to_delete: '本当によいですか?' cancel: 'キャンセル' click_to_edit: 'クリックして編集' close: '閉じる' create: '作成' - create_model: '{{model}}を作成' + create_model: '%{model}を作成' create_another: '別のものを作成' - created_model: '{{model}}を作成しました' + created_model: '%{model}を作成しました' create_new: '新規作成' customize: 'カスタマイズ' delete: '削除' - deleted_model: '{{model}}を削除しました' + deleted_model: '%{model}を削除しました' delimiter: 'Delimiter' # needed? download: 'ダウンロード' edit: '編集' export: 'Export' # needed? - nested_for_model: '{{parent_model}}の{{nested_model}}' + nested_for_model: '%{parent_model}の%{nested_model}' filtered: '(フィルタ中)' found: '個ありました' hide: '隠す' @@ -37,18 +37,18 @@ ja: remove: '削除' remove_file: 'ファイルを削除または置換' replace_with_new: '新しいもので置換' - revisions_for_model: 'Revisions for {{model}}' # neede? + revisions_for_model: 'Revisions for %{model}' # neede? reset: 'リセット' saving: '保存中…' search: '検索' search_terms: '検索単語' _select_: '- 選択してください -' show: '表示' - show_model: '{{model}}を表示' + show_model: '%{model}を表示' _to_ : ' to ' # needed? update: '更新' - update_model: '{{model}}を更新' - updated_model: '{{model}}を更新しました' + update_model: '%{model}を更新' + updated_model: '%{model}を更新しました' '=': '=' '>=': '>=' '<=': '<=' @@ -58,6 +58,6 @@ ja: between: 'Between' # needed? # error_messages - cant_destroy_record: "{{record}}を削除で来ません" + cant_destroy_record: "%{record}を削除で来ません" internal_error: 'リクエストが失敗しました(コード500: 内部エラー)' version_inconsistency: 'バージョンが一致しません - あなたが編集している間にこのレコードが変更されました。' diff --git a/lib/active_scaffold/locale/ru.yml b/lib/active_scaffold/locale/ru.yml index 77cb85e74e..07714d568b 100644 --- a/lib/active_scaffold/locale/ru.yml +++ b/lib/active_scaffold/locale/ru.yml @@ -2,24 +2,24 @@ ru: active_scaffold: add: 'Добавить запись' add_existing: 'Добавить существующую запись' - add_existing_model: 'Добавить существующую запись {{model}}' + add_existing_model: 'Добавить существующую запись %{model}' are_you_sure_to_delete: 'Вы уверены?' cancel: 'Отмена' click_to_edit: 'Нажмите для редактирования' close: 'Закрыть' create: 'Создать запись' - create_model: 'Создать запись {{model}}' + create_model: 'Создать запись %{model}' create_another: 'Создать другую запись' - created_model: 'Создана запись {{model}}' + created_model: 'Создана запись %{model}' create_new: 'Создать новую запись' customize: 'Настроить' delete: 'Удалить' - deleted_model: 'Удалена запись {{model}}' + deleted_model: 'Удалена запись %{model}' delimiter: 'Разделитель' download: 'Загрузить' edit: 'Изменить' export: 'Экспорт' - nested_for_model: '{{parent_model}} / {{nested_model}}' + nested_for_model: '%{parent_model} / %{nested_model}' filtered: '(Найденное)' found: 'Найдено' hide: 'Скрыть' @@ -36,18 +36,18 @@ ru: remove: 'Удалить' remove_file: 'Удалить или заменить файл' replace_with_new: 'Заменить новым' - revisions_for_model: 'Редакции {{model}}' + revisions_for_model: 'Редакции %{model}' reset: 'Сбросить' saving: 'Сохранение...' search: 'Поиск' search_terms: 'Ключевые слова' _select_: '- выбрать -' show: 'Показать' - show_model: 'Показать запись {{model}}' + show_model: 'Показать запись %{model}' _to_ : ' to ' update: 'Обновить запись' - update_model: 'Обновить запись {{model}}' - updated_model: 'Обновлена запись {{model}}' + update_model: 'Обновить запись %{model}' + updated_model: 'Обновлена запись %{model}' '=': '=' '>=': '>=' '<=': '<=' From 231a6aaa5304256f42985af88c00124450fd12cd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 22 Jul 2010 10:42:56 +0200 Subject: [PATCH 0501/2024] Bugfix: Syntax error introduced in prev commit --- lib/active_scaffold/locale/fr.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index d7371325f5..95339780dc 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -63,3 +63,4 @@ :version_inconsistency => "Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer.", } } +} From 3046a693fb76384f5b95ade526d688ba78062e2c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 22 Jul 2010 12:32:16 +0200 Subject: [PATCH 0502/2024] Feature: inplace edit works for all get_column_value types UJS version of list_ui :checkbox and inplace_edit --- .../javascripts/jquery/active_scaffold.js | 24 +++++++++++---- .../javascripts/prototype/active_scaffold.js | 30 +++++++++++++++---- .../helpers/list_column_helpers.rb | 25 ++++------------ 3 files changed, 49 insertions(+), 30 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index df7da08063..2bc1e1f8f3 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -153,7 +153,8 @@ $(document).ready(function() { column_heading = span.closest('.active-scaffold').find(heading_selector), render_url = column_heading.attr('data-ie_render_url'), mode = column_heading.attr('data-ie_mode'), - record_id = span.attr('data-ie_id'); + record_id = span.attr('data-ie_id'), + field_type = column_heading.attr('data-ie_field_type'); options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id) @@ -168,7 +169,7 @@ $(document).ready(function() { if (csrf_param) { var param = csrf_param.attr('content'), token = csrf_token.attr('content'); - options['params'] = param + '=' + token + options['params'] = param + '=' + token; } if (mode && mode === 'clone') { @@ -183,9 +184,22 @@ $(document).ready(function() { options.field_type = 'remote'; options.editor_url = render_url.replace(/__id__/, record_id) } - span.removeClass('hover'); - span.editInPlace(options); - span.trigger('click.editInPlace'); + if (field_type === 'inline_checkbox') { + var checked = span.find('input:checkbox').is(':checked'); + if (checked === true) options['params'] += '&value=1'; + $.ajax({ + url: options.url, + type: "POST", + data: options['params'], + dataType: options.ajax_data_type, + complete: function(request){ + } + }); + } else { + span.removeClass('hover'); + span.editInPlace(options); + span.trigger('click.editInPlace'); + } } }); }); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 4214083cec..b162f11ed0 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -152,13 +152,14 @@ document.observe("dom:loaded", function() { event.findElement().removeClassName('hover'); }); document.on('click', 'span.in_place_editor_field', function(event) { - var span = event.findElement(); + var span = event.findElement('span.in_place_editor_field'); if (typeof(span.inplace_edit) === 'undefined') { var options = {htmlResponse: false, onEnterHover: null, onLeaveHover: null, onComplete: null, + params: '', ajaxOptions: {method: 'post'}}, csrf_param = $$('meta[name=csrf-param]')[0], csrf_token = $$('meta[name=csrf-token]')[0], @@ -166,7 +167,8 @@ document.observe("dom:loaded", function() { column_heading = span.up('.active-scaffold').down(heading_selector), render_url = column_heading.readAttribute('data-ie_render_url'), mode = column_heading.readAttribute('data-ie_mode'), - record_id = span.readAttribute('data-ie_id'); + record_id = span.readAttribute('data-ie_id'), + field_type = column_heading.readAttribute('data-ie_field_type'); if (column_heading.readAttribute('data-ie_cancel_text')) options.cancelText = column_heading.readAttribute('data-ie_cancel_text'); @@ -180,7 +182,7 @@ document.observe("dom:loaded", function() { if (csrf_param) { var param = csrf_param.readAttribute('content'), token = csrf_token.readAttribute('content'); - options['callback'] = new Function('form', 'return Form.serialize(form) + ' + "'&" + param + '=' + token + "';"); + options['params'] = param + '=' + token; } if (mode && mode === 'clone') { @@ -194,9 +196,25 @@ document.observe("dom:loaded", function() { if (column_heading.readAttribute('data-ie_plural')) plural = true; options['onFormCustomization'] = new Function('element', 'form', 'element.setFieldFromAjax(' + "'" + render_url.sub('__id__', record_id) + "', {plural: " + plural + '});'); } - span.removeClassName('hover'); - span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.id, column_heading.readAttribute('data-ie_url').sub('__id__', record_id), options) - span.inplace_edit.enterEditMode(); + + if (field_type === 'inline_checkbox') { + var checked = span.down('input[type="checkbox"]').readAttribute('checked'); + // checked attribute is nt updated + if (checked !== 'checked') options['params'] += '&value=1'; + new Ajax.Request(column_heading.readAttribute('data-ie_url').sub('__id__', record_id), { + method: 'post', + parameters: options['params'], + onComplete: function(response) { + } + }); + } else { + if (options['params'].length > 0) { + options['callback'] = new Function('form', 'return Form.serialize(form) + ' + "'&" + options['params'] + "';"); + } + span.removeClassName('hover'); + span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.id, column_heading.readAttribute('data-ie_url').sub('__id__', record_id), options) + span.inplace_edit.enterEditMode(); + } } return true; }); diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index e514008607..bce7fd04b8 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -14,9 +14,6 @@ def get_column_value(record, column) # second, check if the dev has specified a valid list_ui for this column elsif column.list_ui and override_column_ui?(column.list_ui) send(override_column_ui(column.list_ui), column, record) - - elsif inplace_edit?(record, column) - active_scaffold_inplace_edit(record, column) elsif column.column and override_column_ui?(column.column.type) send(override_column_ui(column.column.type), column, record) else @@ -32,7 +29,6 @@ def get_column_value(record, column) end # TODO: move empty_field_text and   logic in here? - # TODO: move active_scaffold_inplace_edit in here? # TODO: we need to distinguish between the automatic links *we* create and the ones that the dev specified. some logic may not apply if the dev specified the link. def render_list_column(text, column, record) if column.link @@ -65,6 +61,7 @@ def render_list_column(text, column, record) render_action_link(link, url_options, record) else + text = active_scaffold_inplace_edit(record, column, {:formatted_column => text}) if inplace_edit?(record, column) text end end @@ -132,13 +129,9 @@ def active_scaffold_column_select(column, record) end def active_scaffold_column_checkbox(column, record) - if inplace_edit?(record, column) - id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} - tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field"} - content_tag(:span, format_column_checkbox(record, column), tag_options) - else - check_box(:record, column.name, :disabled => true, :id => nil, :object => record) - end + options = {:disabled => true, :id => nil, :object => record} + options.delete(:disabled) if inplace_edit?(record, column) + check_box(:record, column.name, options) end def column_override(column) @@ -161,13 +154,6 @@ def override_column_ui(list_ui) ## ## Formatting ## - - def format_column_checkbox(record, column) - checked = ActionView::Helpers::InstanceTag.check_box_checked?(record.send(column.name), '1') - script = remote_function(:method => 'POST', :url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s, :value => !checked, :eid => params[:eid]}) - check_box(:record, column.name, :onclick => script, :id => nil, :object => record) - end - def format_column_value(record, column, value = nil) value ||= record.send(column.name) unless record.nil? if value && column.association # cache association size before calling column_empty? @@ -266,7 +252,7 @@ def inplace_edit_cloning?(column) def format_inplace_edit_column(record,column) if column.list_ui == :checkbox - format_column_checkbox(record, column) + active_scaffold_column_checkbox(column, record) else format_column_value(record, column) end @@ -306,6 +292,7 @@ def inplace_edit_tag_attributes(column) tag_options['data-ie_rows'] = column.options[:rows] || 5 if column.column.try(:type) == :text tag_options['data-ie_cols'] = column.options[:cols] if column.options[:cols] tag_options['data-ie_size'] = column.options[:size] if column.options[:size] + tag_options['data-ie_field_type'] = 'inline_checkbox' if column.list_ui == :checkbox if inplace_edit_cloning?(column) tag_options['data-ie_mode'] = :clone From cee8c2cb6d52397e57d6a6eda90e42f61b6318ce Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 22 Jul 2010 13:51:55 +0200 Subject: [PATCH 0503/2024] js inplace_edit refactoring --- .../javascripts/jquery/active_scaffold.js | 67 +++++++++------- .../javascripts/prototype/active_scaffold.js | 76 +++++++++++-------- 2 files changed, 83 insertions(+), 60 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 2bc1e1f8f3..c789f1d0b6 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -156,22 +156,11 @@ $(document).ready(function() { record_id = span.attr('data-ie_id'), field_type = column_heading.attr('data-ie_field_type'); + ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options); + options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id); - options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id) - if (column_heading.attr('data-ie_cancel_text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.attr('data-ie_cancel_text') + "</button>"; - if (column_heading.attr('data-ie_loading_text')) options.loadingText = column_heading.attr('data-ie_loading_text'); - if (column_heading.attr('data-ie_saving_text')) options.saving_text = column_heading.attr('data-ie_saving_text'); - if (column_heading.attr('data-ie_save_text')) options.save_button = '<button class="inplace_save">' + column_heading.attr('data-ie_save_text') + "</button>"; - if (column_heading.attr('data-ie_rows')) options.textarea_rows = column_heading.attr('data-ie_rows'); - if (column_heading.attr('data-ie_cols')) options.textarea_cols = column_heading.attr('data-ie_cols'); - if (column_heading.attr('data-ie_size')) options.text_size = column_heading.attr('data-ie_size'); - - if (csrf_param) { - var param = csrf_param.attr('content'), - token = csrf_token.attr('content'); - options['params'] = param + '=' + token; - } - + if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content'); + if (mode && mode === 'clone') { options.nodeIdSuffix = record_id; options.inplacePatternSelector = '#' + column_heading.id + ' .as_inplace_pattern'; @@ -185,20 +174,9 @@ $(document).ready(function() { options.editor_url = render_url.replace(/__id__/, record_id) } if (field_type === 'inline_checkbox') { - var checked = span.find('input:checkbox').is(':checked'); - if (checked === true) options['params'] += '&value=1'; - $.ajax({ - url: options.url, - type: "POST", - data: options['params'], - dataType: options.ajax_data_type, - complete: function(request){ - } - }); + ActiveScaffold.process_checkbox_inplace_edit(span.find('input:checkbox'), options); } else { - span.removeClass('hover'); - span.editInPlace(options); - span.trigger('click.editInPlace'); + ActiveScaffold.create_inplace_editor(span, options); } } }); @@ -409,6 +387,39 @@ var ActiveScaffold = { var form_offset = $(element).offset(), destination = form_offset.top; $(document).scrollTop(destination); + }, + + process_checkbox_inplace_edit: function(checkbox, options) { + var checked = checkbox.is(':checked'); + if (checked === true) options['params'] += '&value=1'; + $.ajax({ + url: options.url, + type: "POST", + data: options['params'], + dataType: options.ajax_data_type, + after: function(request){ + checkbox.attr('disabled', 'disabled'); + }, + complete: function(request){ + checkbox.attr('disabled', ''); + } + }); + }, + + read_inplace_edit_heading_attributes: function(column_heading, options) { + if (column_heading.attr('data-ie_cancel_text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.attr('data-ie_cancel_text') + "</button>"; + if (column_heading.attr('data-ie_loading_text')) options.loadingText = column_heading.attr('data-ie_loading_text'); + if (column_heading.attr('data-ie_saving_text')) options.saving_text = column_heading.attr('data-ie_saving_text'); + if (column_heading.attr('data-ie_save_text')) options.save_button = '<button class="inplace_save">' + column_heading.attr('data-ie_save_text') + "</button>"; + if (column_heading.attr('data-ie_rows')) options.textarea_rows = column_heading.attr('data-ie_rows'); + if (column_heading.attr('data-ie_cols')) options.textarea_cols = column_heading.attr('data-ie_cols'); + if (column_heading.attr('data-ie_size')) options.text_size = column_heading.attr('data-ie_size'); + }, + + create_inplace_editor: function(span, options) { + span.removeClass('hover'); + span.editInPlace(options); + span.trigger('click.editInPlace'); } } diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index b162f11ed0..911ed4bf74 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -169,22 +169,12 @@ document.observe("dom:loaded", function() { mode = column_heading.readAttribute('data-ie_mode'), record_id = span.readAttribute('data-ie_id'), field_type = column_heading.readAttribute('data-ie_field_type'); - - - if (column_heading.readAttribute('data-ie_cancel_text')) options.cancelText = column_heading.readAttribute('data-ie_cancel_text'); - if (column_heading.readAttribute('data-ie_loading_text')) options.loadingText = column_heading.readAttribute('data-ie_loading_text'); - if (column_heading.readAttribute('data-ie_saving_text')) options.savingText = column_heading.readAttribute('data-ie_saving_text'); - if (column_heading.readAttribute('data-ie_save_text')) options.okText = column_heading.readAttribute('data-ie_save_text'); - if (column_heading.readAttribute('data-ie_rows')) options.rows = column_heading.readAttribute('data-ie_rows'); - if (column_heading.readAttribute('data-ie_cols')) options.cols = column_heading.readAttribute('data-ie_cols'); - if (column_heading.readAttribute('data-ie_size')) options.size = column_heading.readAttribute('data-ie_size'); - - if (csrf_param) { - var param = csrf_param.readAttribute('content'), - token = csrf_token.readAttribute('content'); - options['params'] = param + '=' + token; - } - + + ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options); + options.url = column_heading.readAttribute('data-ie_url').sub('__id__', record_id); + + if (csrf_param) options['params'] = csrf_param.readAttribute('content') + '=' + csrf_token.readAttribute('content'); + if (mode && mode === 'clone') { options.nodeIdSuffix = record_id; options.inplacePatternSelector = '#' + column_heading.id + ' .as_inplace_pattern'; @@ -198,22 +188,9 @@ document.observe("dom:loaded", function() { } if (field_type === 'inline_checkbox') { - var checked = span.down('input[type="checkbox"]').readAttribute('checked'); - // checked attribute is nt updated - if (checked !== 'checked') options['params'] += '&value=1'; - new Ajax.Request(column_heading.readAttribute('data-ie_url').sub('__id__', record_id), { - method: 'post', - parameters: options['params'], - onComplete: function(response) { - } - }); + ActiveScaffold.process_checkbox_inplace_edit(span.down('input[type="checkbox"]'), options); } else { - if (options['params'].length > 0) { - options['callback'] = new Function('form', 'return Form.serialize(form) + ' + "'&" + options['params'] + "';"); - } - span.removeClassName('hover'); - span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.id, column_heading.readAttribute('data-ie_url').sub('__id__', record_id), options) - span.inplace_edit.enterEditMode(); + ActiveScaffold.create_inplace_editor(span, options); } } return true; @@ -353,7 +330,42 @@ var ActiveScaffold = { }, scroll_to: function(element) { - $(element).scrollTo();; + $(element).scrollTo(); + }, + + process_checkbox_inplace_edit: function(checkbox, options) { + var checked = checkbox.readAttribute('checked'); + // checked attribute is nt updated + if (checked !== 'checked') options['params'] += '&value=1'; + new Ajax.Request(options.url, { + method: 'post', + parameters: options['params'], + onCreate: function(response) { + checkbox.disable(); + }, + onComplete: function(response) { + checkbox.enable(); + } + }); + }, + + read_inplace_edit_heading_attributes: function(column_heading, options) { + if (column_heading.readAttribute('data-ie_cancel_text')) options.cancelText = column_heading.readAttribute('data-ie_cancel_text'); + if (column_heading.readAttribute('data-ie_loading_text')) options.loadingText = column_heading.readAttribute('data-ie_loading_text'); + if (column_heading.readAttribute('data-ie_saving_text')) options.savingText = column_heading.readAttribute('data-ie_saving_text'); + if (column_heading.readAttribute('data-ie_save_text')) options.okText = column_heading.readAttribute('data-ie_save_text'); + if (column_heading.readAttribute('data-ie_rows')) options.rows = column_heading.readAttribute('data-ie_rows'); + if (column_heading.readAttribute('data-ie_cols')) options.cols = column_heading.readAttribute('data-ie_cols'); + if (column_heading.readAttribute('data-ie_size')) options.size = column_heading.readAttribute('data-ie_size'); + }, + + create_inplace_editor: function(span, options) { + if (options['params'].length > 0) { + options['callback'] = new Function('form', 'return Form.serialize(form) + ' + "'&" + options['params'] + "';"); + } + span.removeClassName('hover'); + span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.id, options.url, options) + span.inplace_edit.enterEditMode(); } } From 4a2594de549ef5f646d628fe5ab5c3a14fc818cc Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 22 Jul 2010 14:33:31 +0200 Subject: [PATCH 0504/2024] Bugfix: improved string to boolean conversion --- lib/active_scaffold/marked_model.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/marked_model.rb b/lib/active_scaffold/marked_model.rb index b08d401b37..ab8374e6bf 100644 --- a/lib/active_scaffold/marked_model.rb +++ b/lib/active_scaffold/marked_model.rb @@ -12,7 +12,7 @@ def marked end def marked=(value) - value = (value.downcase == 'true') if value.is_a? String + value = [true, 'true', 1, '1', 'T', 't'].include?(value.class == String ? value.downcase : value) if value == true marked_records << self.id if !marked else From b05eb19bc9ea95f4e863835c435325148c760685 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 22 Jul 2010 16:35:52 +0200 Subject: [PATCH 0505/2024] improved string to boolean conversion --- lib/active_scaffold/actions/mark.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index 77e0a8bf6b..68e50636fc 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -30,7 +30,7 @@ def marked_records end def mark_all? - @mark_all ||= (params[:value] == 'true') + @mark_all ||= [true, 'true', 1, '1', 'T', 't'].include?(params[:value].class == String ? params[:value].downcase : params[:value]) end def do_mark_all From 6a6ee65276f8f4f076e7da283421c74dfbd3031c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 22 Jul 2010 16:37:43 +0200 Subject: [PATCH 0506/2024] UJS version of mark_all --- .../javascripts/jquery/active_scaffold.js | 28 +++++++++++++----- .../javascripts/prototype/active_scaffold.js | 29 ++++++++++++++----- .../helpers/list_column_helpers.rb | 18 +++++------- 3 files changed, 48 insertions(+), 27 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index c789f1d0b6..bec2832ad6 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -149,19 +149,31 @@ $(document).ready(function() { update_value: 'value'}, csrf_param = $('meta[name=csrf-param]').first(), csrf_token = $('meta[name=csrf-token]').first(), - heading_selector = '.' + span.parent().attr('class').split(' ')[0] + '_heading', - column_heading = span.closest('.active-scaffold').find(heading_selector), - render_url = column_heading.attr('data-ie_render_url'), + my_parent = span.parent(), + column_heading = null; + + if (my_parent.is('td')) { + var column_no = my_parent.prevAll('td').length; + column_heading = my_parent.closest('.active-scaffold').find('th:eq(' + column_no + ')'); + } else if (my_parent.is('th')) { + column_heading = my_parent; + } + + var render_url = column_heading.attr('data-ie_render_url'), mode = column_heading.attr('data-ie_mode'), - record_id = span.attr('data-ie_id'), - field_type = column_heading.attr('data-ie_field_type'); + record_id = span.attr('data-ie_id'); ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options); - options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id); + + if (span.attr('data-ie_url')) { + options.url = span.attr('data-ie_url').replace(/__id__/, record_id); + } else { + options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id); + } if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content'); - if (mode && mode === 'clone') { + if (mode === 'clone') { options.nodeIdSuffix = record_id; options.inplacePatternSelector = '#' + column_heading.id + ' .as_inplace_pattern'; options['onFormCustomization'] = new Function('element', 'form', 'element.clonePatternField();'); @@ -173,7 +185,7 @@ $(document).ready(function() { options.field_type = 'remote'; options.editor_url = render_url.replace(/__id__/, record_id) } - if (field_type === 'inline_checkbox') { + if (mode === 'inline_checkbox') { ActiveScaffold.process_checkbox_inplace_edit(span.find('input:checkbox'), options); } else { ActiveScaffold.create_inplace_editor(span, options); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 911ed4bf74..9d4606c782 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -163,19 +163,32 @@ document.observe("dom:loaded", function() { ajaxOptions: {method: 'post'}}, csrf_param = $$('meta[name=csrf-param]')[0], csrf_token = $$('meta[name=csrf-token]')[0], - heading_selector = '.' + span.up().readAttribute('class').split(' ')[0] + '_heading', - column_heading = span.up('.active-scaffold').down(heading_selector), - render_url = column_heading.readAttribute('data-ie_render_url'), + my_parent = span.up(), + column_heading = null; + + if (my_parent.nodeName.toLowerCase() === 'td') { + var heading_selector = '.' + span.up().readAttribute('class').split(' ')[0] + '_heading'; + column_heading = span.up('.active-scaffold').down(heading_selector); + } else if (my_parent.nodeName.toLowerCase() === 'th') { + column_heading = my_parent; + } + + var render_url = column_heading.readAttribute('data-ie_render_url'), mode = column_heading.readAttribute('data-ie_mode'), - record_id = span.readAttribute('data-ie_id'), - field_type = column_heading.readAttribute('data-ie_field_type'); + record_id = span.readAttribute('data-ie_id'); ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options); - options.url = column_heading.readAttribute('data-ie_url').sub('__id__', record_id); + + if (span.readAttribute('data-ie_url')) { + options.url = span.readAttribute('data-ie_url'); + } else { + options.url = column_heading.readAttribute('data-ie_url'); + } + if (record_id) options.url = options.url.sub('__id__', record_id); if (csrf_param) options['params'] = csrf_param.readAttribute('content') + '=' + csrf_token.readAttribute('content'); - if (mode && mode === 'clone') { + if (mode === 'clone') { options.nodeIdSuffix = record_id; options.inplacePatternSelector = '#' + column_heading.id + ' .as_inplace_pattern'; options['onFormCustomization'] = new Function('element', 'form', 'element.clonePatternField();'); @@ -187,7 +200,7 @@ document.observe("dom:loaded", function() { options['onFormCustomization'] = new Function('element', 'form', 'element.setFieldFromAjax(' + "'" + render_url.sub('__id__', record_id) + "', {plural: " + plural + '});'); } - if (field_type === 'inline_checkbox') { + if (mode === 'inline_checkbox') { ActiveScaffold.process_checkbox_inplace_edit(span.down('input[type="checkbox"]'), options); } else { ActiveScaffold.create_inplace_editor(span, options); diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index bce7fd04b8..9dd84a0f94 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -292,9 +292,10 @@ def inplace_edit_tag_attributes(column) tag_options['data-ie_rows'] = column.options[:rows] || 5 if column.column.try(:type) == :text tag_options['data-ie_cols'] = column.options[:cols] if column.options[:cols] tag_options['data-ie_size'] = column.options[:size] if column.options[:size] - tag_options['data-ie_field_type'] = 'inline_checkbox' if column.list_ui == :checkbox - - if inplace_edit_cloning?(column) + + if column.list_ui == :checkbox + tag_options['data-ie_mode'] = :inline_checkbox + elsif inplace_edit_cloning?(column) tag_options['data-ie_mode'] = :clone elsif column.inplace_edit == :ajax url = url_for(:controller => params_for[:controller], :action => 'render_field', :id => '__id__', :column => column.name, :update_column => column.name, :in_place_editing => true, :escape => false) @@ -308,14 +309,9 @@ def inplace_edit_tag_attributes(column) def mark_column_heading all_marked = (marked_records.length >= @page.pager.count) - tag_options = {:id => "#{controller_id}_mark_heading", :class => "mark_heading"} - url_params = {:controller => params_for[:controller], :action => 'mark_all', :eid => params[:eid]} - ajax_options = {:method => :post, - :url => url_for(url_params), :with => "'value=' + this.value", - :after => "this.disable();", - :complete => "this.enable();"} - script = remote_function(ajax_options) - content_tag(:span, check_box_tag(tag_options[:id], !all_marked, all_marked, {:onclick => script}) , tag_options) + tag_options = {:id => "#{controller_id}_mark_heading", :class => "mark_heading in_place_editor_field"} + tag_options['data-ie_url'] = url_for({:controller => params_for[:controller], :action => 'mark_all', :eid => params[:eid]}) + content_tag(:span, check_box_tag(nil, !all_marked, all_marked), tag_options) end def render_column_heading(column, sorting, sort_direction) From c4b94a45bf234f893e88cd6100ce4239b2914992 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 23 Jul 2010 09:14:25 +0200 Subject: [PATCH 0507/2024] Fix autoloading issue with ckeditor bridge --- lib/active_scaffold/config/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index 8e08888289..7f342c9e89 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -1,5 +1,5 @@ module ActiveScaffold::Config - class Core < Base + class Core < ActiveScaffold::Config::Base # global level configuration # -------------------------- From 3721a21ec68fe34109c5c67dce1fa21c708fc39a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 23 Jul 2010 09:43:53 +0200 Subject: [PATCH 0508/2024] add loading_text, will be shown when server is asked to render edit control --- frontends/default/javascripts/jquery/jquery.editinplace.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/jquery.editinplace.js b/frontends/default/javascripts/jquery/jquery.editinplace.js index 27ce3a8a72..ae1225981f 100644 --- a/frontends/default/javascripts/jquery/jquery.editinplace.js +++ b/frontends/default/javascripts/jquery/jquery.editinplace.js @@ -64,7 +64,7 @@ $.fn.editInPlace.defaults = { select_options: "", // string or array: Used if field_type is set to 'select'. Can be comma delimited list of options 'textandValue,text:value', Array of options ['textAndValue', 'text:value'] or array of arrays ['textAndValue', ['text', 'value']]. The last form is especially usefull if your labels or values contain colons) text_size: null, // integer: set cols attribute of text input, if field_type is set to text. Use CSS if possible though editor_url: null, // for field_type: remote url to get html_code for edit_control - + loading_text: 'Loading...', // shown if inplace editor is loaded from server // Specifying callback_skip_dom_reset will disable all saving_* options saving_text: undefined, // string: text to be used when server is saving information. Example "Saving..." saving_image: "", // string: uses saving text specify an image location instead of text while server is saving @@ -285,6 +285,7 @@ $.extend(InlineEditor.prototype, { }, createRemoteGeneratedEditor: function () { + this.dom.html(this.settings.loading_text); return $($.ajax({ url: this.settings.editor_url, async: false From 8421007586363043b20938b6e7362c8fb50841ff Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 23 Jul 2010 09:44:46 +0200 Subject: [PATCH 0509/2024] jquery: add first view inplace_edit highlighting --- .../default/javascripts/jquery/active_scaffold.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index bec2832ad6..2a44f4f4ce 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -138,6 +138,15 @@ $(document).ready(function() { ActiveScaffold.report_500_response(as_scaffold); return true; }); + $('span.in_place_editor_field').live('hover', function(event) { + if (event.type == 'mouseenter') { + if (typeof($(this).data('editInPlace')) === 'undefined') $(this).addClass("hover"); + } + if (event.type == 'mouseleave') { + if (typeof($(this).data('editInPlace')) === 'undefined') $(this).removeClass("hover"); + } + return true; + }); $('span.in_place_editor_field').live('click', function(event) { var span = $(this); @@ -420,7 +429,7 @@ var ActiveScaffold = { read_inplace_edit_heading_attributes: function(column_heading, options) { if (column_heading.attr('data-ie_cancel_text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.attr('data-ie_cancel_text') + "</button>"; - if (column_heading.attr('data-ie_loading_text')) options.loadingText = column_heading.attr('data-ie_loading_text'); + if (column_heading.attr('data-ie_loading_text')) options.loading_text = column_heading.attr('data-ie_loading_text'); if (column_heading.attr('data-ie_saving_text')) options.saving_text = column_heading.attr('data-ie_saving_text'); if (column_heading.attr('data-ie_save_text')) options.save_button = '<button class="inplace_save">' + column_heading.attr('data-ie_save_text') + "</button>"; if (column_heading.attr('data-ie_rows')) options.textarea_rows = column_heading.attr('data-ie_rows'); From e8b69c96440b5fe70087465b3d8f955717fa7dd1 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 23 Jul 2010 11:12:14 +0200 Subject: [PATCH 0510/2024] add configuration option to switch js_framework --- environment.rb | 1 + install_assets.rb | 2 +- lib/active_scaffold.rb | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/environment.rb b/environment.rb index 6df90a85cc..0979088009 100644 --- a/environment.rb +++ b/environment.rb @@ -15,3 +15,4 @@ require 'bridges/bridge.rb' I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'lib', 'active_scaffold', 'locale', '*.{rb,yml}')] +#ActiveScaffold.js_framework = :jquery diff --git a/install_assets.rb b/install_assets.rb index f2df6a292f..7a1e1041d2 100755 --- a/install_assets.rb +++ b/install_assets.rb @@ -31,7 +31,7 @@ def copy_files(source_path, destination_path, directory, clean_up_destination = available_frontends.each do |frontend| if asset_type == :javascripts - source = "/frontends/#{frontend}/#{asset_type}/prototype/" + source = "/frontends/#{frontend}/#{asset_type}/#{ActiveScaffold.js_framework}/" else source = "/frontends/#{frontend}/#{asset_type}/" end diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 91f06fd425..4b56706393 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -44,6 +44,14 @@ def handle_user_settings end end end + + def self.js_framework=(framework) + @@js_framework = framework + end + + def self.js_framework + @@js_framework ||= :prototype + end module ClassMethods def active_scaffold(model_id = nil, &block) From 88fcc4b4e7818ad068c859edfc304e04d0f87fb6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 23 Jul 2010 11:16:29 +0200 Subject: [PATCH 0511/2024] add jquery support to readme file --- README | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README b/README index 70121c6284..629539e529 100644 --- a/README +++ b/README @@ -34,10 +34,11 @@ Since Rails 3.0 render_component is nt needed anymore Since Rails 3.0, the following is needed: rails plugin install git://github.com/rails/verification.git -Prototype 1.7 +Prototype 1.7 (default js framework) rails.js in git://github.com/vhochstein/prototype-ujs.git JQuery 1.4.1 rails.js in git://github.com/vhochstein/jquery-ujs.git +uncomment last line in ...plugins/active_scaffold/environment.rb in order tu use jquery instead of prototype Released under the MIT license (included) From 2366365d6ae3f82968776430e838cb565d3411f0 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 23 Jul 2010 14:00:57 +0200 Subject: [PATCH 0512/2024] Bugfix: refresh parent row on cancel if action equals :index in inline_adapter view --- frontends/default/views/_list_inline_adapter.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index 486c39806e..0b5e9af4d9 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -2,7 +2,7 @@ <tr class="inline-adapter" id="<%= element_row_id :action => :nested %>"> <td colspan="99" class="inline-adapter-cell"> <div class="<%= "#{params[:action]}-view" if params[:action] %> <%= "#{params[:associations] ? params[:associations] : params[:controller]}-view" %> view"> - <%= link_to(as_(:close), '', :class => 'inline-adapter-close as_cancel', :remote => true, :title => as_(:close)) -%> + <%= link_to(as_(:close), '', :class => 'inline-adapter-close as_cancel', :remote => true, :title => as_(:close), 'data-refresh' => (action_name == 'index' ? true : false)) -%> <%= payload -%> </div> </td> From f63fe2baa10339b2ef8c1e157495b1f823beae3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D0=B1=D0=BA=D0=BE=D0=B2?= <korobkov@neverbox.org> Date: Fri, 23 Jul 2010 20:09:04 +0400 Subject: [PATCH 0513/2024] updated russian locale --- lib/active_scaffold/locale/ru.yml | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/active_scaffold/locale/ru.yml b/lib/active_scaffold/locale/ru.yml index f29e3bcbe1..789ee15f0e 100644 --- a/lib/active_scaffold/locale/ru.yml +++ b/lib/active_scaffold/locale/ru.yml @@ -3,13 +3,14 @@ ru: add: 'Добавить запись' add_existing: 'Добавить существующую запись' add_existing_model: 'Добавить существующую запись {{model}}' - are_you_sure_to_delete: 'Вы уверены?' + are_you_sure_to_delete: 'Удалить {{label}}?' cancel: 'Отмена' click_to_edit: 'Нажмите для редактирования' + click_to_reset: 'Нажмите для сброса' close: 'Закрыть' create: 'Создать запись' create_model: 'Создать запись {{model}}' - create_another: 'Создать другую запись' + create_another: 'Создать другую запись {{model}}' created_model: 'Создана запись {{model}}' create_new: 'Создать новую запись' customize: 'Настроить' @@ -20,13 +21,15 @@ ru: edit: 'Изменить' export: 'Экспорт' nested_for_model: '{{parent_model}} / {{nested_model}}' + false: 'Нет' filtered: '(Найденное)' found: 'Найдено' hide: 'Скрыть' live_search: 'Поиск' - loading: 'Загрузка...' + loading: 'Загрузка…' next: 'Следующее' no_entries: 'Нет записей' + no_options: 'Нет вариантов' omit_header: 'Omit Header' options: 'Настройки' pdf: 'PDF' @@ -38,13 +41,14 @@ ru: replace_with_new: 'Заменить новым' revisions_for_model: 'Редакции {{model}}' reset: 'Сбросить' - saving: 'Сохранение...' + saving: 'Сохранение…' search: 'Поиск' search_terms: 'Ключевые слова' _select_: '- выбрать -' show: 'Показать' show_model: 'Показать запись {{model}}' _to_ : ' to ' + true: 'Да' update: 'Обновить запись' update_model: 'Обновить запись {{model}}' updated_model: 'Обновлена запись {{model}}' @@ -54,13 +58,14 @@ ru: '>': '>' '<': '<' '!=': '!=' - between: 'Между' - is_null: 'Is null' - is_not_null: 'Is not null' - contains: 'Contains' - begins_with: 'Begins with' - ends_with: 'Ends with' + between: 'В интервале' + is_null: 'Пусто' + is_not_null: 'Не пусто' + contains: 'Содержит' + begins_with: 'Начинается с' + ends_with: 'Оканчивается на' # error_messages - internal_error: 'Внутренняя ошибка сервера.' - version_inconsistency: 'Эта запись была обновлена с того момента, как вы начали ее редактировать.' + cant_destroy_record: 'Запись {{record}} не может быть удалена' + internal_error: '500 Внутренняя ошибка сервера' + version_inconsistency: 'Несоответствие версий: эта запись была обновлена с того момента, как вы начали ее редактировать' From 732818eb2cbf2b06f24a0b2b6650ceb1bd4a7117 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 26 Jul 2010 08:36:16 +0200 Subject: [PATCH 0514/2024] remove layout in embedded scaffolds --- lib/active_scaffold/actions/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index a137892c26..e485c22c22 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -23,7 +23,7 @@ def list protected def list_respond_to_html - render :action => 'list', :layout => !respond_to?(:nested?) || !nested? + render :action => 'list', :layout => (!respond_to?(:nested?) || !nested?) && (!respond_to?(:component_request?) || !component_request?) end def list_respond_to_js render :action => 'list.js' From dd5cf2985607a0d198a524e601e2768cc59a9870 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 26 Jul 2010 08:58:59 +0200 Subject: [PATCH 0515/2024] remove empty script tag --- frontends/default/views/_list.html.erb | 2 +- frontends/default/views/_list_record.html.erb | 8 -------- frontends/default/views/add_existing.js.rjs | 3 ++- frontends/default/views/on_create.js.rjs | 1 + frontends/default/views/update_row.js.rjs | 1 + 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index 9fbb2f488d..b7fca590cd 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -13,7 +13,7 @@ </tbody> <tbody class="records" id="<%= active_scaffold_tbody_id %>"> <% if !@records.empty? -%> - <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false, :dont_show_calculations => true } %> + <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false } %> <% end -%> <% if active_scaffold_config.list.columns.any? {|c| c.calculation?} -%> <%= render :partial => 'list_calculations' %> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 0fcc0404fe..b3c0e4347c 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -1,6 +1,5 @@ <% record = list_record if list_record # compat with render :partial :collection -dont_show_calculations ||= false tr_class = cycle("", "even-record") tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class url_options = params_for(:action => :list, :id => record.id) @@ -10,10 +9,3 @@ url_options = params_for(:action => :list, :id => record.id) <%= render :partial => 'list_record_columns', :locals => {:record => record} %> <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options} if active_scaffold_config.action_links.any? {|link| link.type == :member } %> </tr> -<script type="text/javascript"> -//<![CDATA[ - <%= update_page do |page| - page.replace active_scaffold_calculations_id, :partial => 'list_calculations' - end if not dont_show_calculations and active_scaffold_config.list.columns.any? {|c| c.calculation?} %> -//]]> -</script> diff --git a/frontends/default/views/add_existing.js.rjs b/frontends/default/views/add_existing.js.rjs index aaee3cf6f0..50ac40c37b 100644 --- a/frontends/default/views/add_existing.js.rjs +++ b/frontends/default/views/add_existing.js.rjs @@ -1,4 +1,5 @@ page.insert_html :top, active_scaffold_tbody_id, :partial => 'list_record', :locals => {:record => @record} +page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} page << "ActiveScaffold.stripe($('#{active_scaffold_tbody_id}'))" page << "ActiveScaffold.hide_empty_message('#{active_scaffold_tbody_id}','#{empty_message_id}');" page << "ActiveScaffold.increment_record_count('#{active_scaffold_id}');" @@ -13,4 +14,4 @@ if (form_stays_open = true) end else page << "$$('##{element_form_id(:action => :new_existing)} a.cancel').first().link.close();" -end \ No newline at end of file +end diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index b997f8c729..3a56904113 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -4,6 +4,7 @@ cancel_selector = "##{form} a.cancel".to_json if controller.send :successful? if @insert_row page.insert_html :top, active_scaffold_tbody_id, :partial => 'list_record', :locals => {:record => @record} + page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} page << "ActiveScaffold.stripe($('#{active_scaffold_tbody_id}'))" page << "ActiveScaffold.hide_empty_message('#{active_scaffold_tbody_id}','#{empty_message_id}');" page << "ActiveScaffold.increment_record_count('#{active_scaffold_id}');" diff --git a/frontends/default/views/update_row.js.rjs b/frontends/default/views/update_row.js.rjs index ac654a92ba..238bcdc099 100644 --- a/frontends/default/views/update_row.js.rjs +++ b/frontends/default/views/update_row.js.rjs @@ -1 +1,2 @@ page.call 'ActiveScaffold.update_row', element_row_id(:action => 'list', :id => @record.id), render(:partial => 'list_record', :locals => {:record => @record}) +page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} From 01398dfc7a4cb08c6b0440cf219a9466bec5dc12 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 26 Jul 2010 09:12:33 +0200 Subject: [PATCH 0516/2024] move mark response to a view --- frontends/default/views/mark.js.rjs | 6 ++++++ lib/active_scaffold/actions/mark.rb | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 frontends/default/views/mark.js.rjs diff --git a/frontends/default/views/mark.js.rjs b/frontends/default/views/mark.js.rjs new file mode 100644 index 0000000000..d5bc8718c0 --- /dev/null +++ b/frontends/default/views/mark.js.rjs @@ -0,0 +1,6 @@ +if params[:id] + # FIXME: It isn't right when there are filtered records by a search + page << "$('#{active_scaffold_id}').down('.mark_record').checked = #{@mark ? true : false};" +else + page << "$$('##{active_scaffold_tbody_id} > tr > td > .mark_record').each(function(checkbox) { checkbox.checked = #{@mark ? true : false};});" +end diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index 113d376975..d8bd7b7cc2 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -57,10 +57,9 @@ def mark_respond_to_js do_search if respond_to? :do_search set_includes_for_list_columns count = beginning_of_chain.count(count_options(finder_options, active_scaffold_config.list.user.count_includes)) - # FIXME: It isn't right when there are filtered records by a search - render :js => "$('#{active_scaffold_id}').down('.mark_record').checked = #{marked_records.length >= count ? true : false};" + @mark = marked_records.length >= count else - render :js => "$$('##{active_scaffold_tbody_id} > tr > td > .mark_record').each(function(checkbox) { checkbox.checked = #{mark? ? true : false};});" + @mark = mark? end end From c423b5def784d80e1d5af3561713c2674f94db16 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 26 Jul 2010 10:31:01 +0200 Subject: [PATCH 0517/2024] fix update_column in record_select --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index b4e253df0b..3bf982f1cc 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -198,8 +198,10 @@ def active_scaffold_record_select(column, options, value, multiple) end record_select_options = {:controller => remote_controller, :id => options[:id]} + record_select_options.merge!(options) record_select_options.merge!(active_scaffold_input_text_options) record_select_options.merge!(column.options) + record_select_options[:onchange] = "function(id, label) { this.value = id; #{record_select_options[:onchange]} }" if record_select_options[:onchange] if multiple record_multi_select_field(options[:name], value || [], record_select_options) From fda49e082d7fe7142883388aea65379bd8e25899 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 26 Jul 2010 10:38:07 +0200 Subject: [PATCH 0518/2024] move record_select helpers to a bridge --- .../helpers/form_column_helpers.rb | 35 -------- .../helpers/search_column_helpers.rb | 18 ----- lib/bridges/record_select/bridge.rb | 5 ++ .../record_select/lib/record_select_bridge.rb | 79 +++++++++++++++++++ 4 files changed, 84 insertions(+), 53 deletions(-) create mode 100644 lib/bridges/record_select/bridge.rb create mode 100644 lib/bridges/record_select/lib/record_select_bridge.rb diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 3bf982f1cc..35919c5f1b 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -175,41 +175,6 @@ def active_scaffold_input_radio(column, html_options) end end - # requires RecordSelect plugin to be installed and configured. - # ... maybe this should be provided in a bridge? - def active_scaffold_input_record_select(column, options) - if column.singular_association? - active_scaffold_record_select(column, options, @record.send(column.name), false) - elsif column.plural_association? - active_scaffold_record_select(column, options, @record.send(column.name), true) - end - end - - def active_scaffold_record_select(column, options, value, multiple) - unless column.association - raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)." - end - remote_controller = active_scaffold_controller_for(column.association.klass).controller_path - - # if the opposite association is a :belongs_to (in that case association in this class must be has_one or has_many) - # then only show records that have not been associated yet - if [:has_one, :has_many].include?(column.association.macro) - params.merge!({column.association.primary_key_name => ''}) - end - - record_select_options = {:controller => remote_controller, :id => options[:id]} - record_select_options.merge!(options) - record_select_options.merge!(active_scaffold_input_text_options) - record_select_options.merge!(column.options) - record_select_options[:onchange] = "function(id, label) { this.value = id; #{record_select_options[:onchange]} }" if record_select_options[:onchange] - - if multiple - record_multi_select_field(options[:name], value || [], record_select_options) - else - record_select_field(options[:name], value || column.association.klass.new, record_select_options) - end - end - def active_scaffold_input_checkbox(column, options) check_box(:record, column.name, options) end diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 831910a9dc..d232af0583 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -156,24 +156,6 @@ def active_scaffold_search_range(column, options) alias_method :active_scaffold_search_float, :active_scaffold_search_range alias_method :active_scaffold_search_string, :active_scaffold_search_range - def active_scaffold_search_record_select(column, options) - begin - value = field_search_params[column.name] - value = unless value.blank? - if column.options[:multiple] - column.association.klass.find value.collect!(&:to_i) - else - column.association.klass.find(value.to_i) - end - end - rescue Exception => e - logger.error Time.now.to_s + "Sorry, we are not that smart yet. Attempted to restore search values to search fields but instead got -- #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" - raise e - end - - active_scaffold_record_select(column, options, value, column.options[:multiple]) - end - def field_search_datetime_value(value) DateTime.new(value[:year].to_i, value[:month].to_i, value[:day].to_i, value[:hour].to_i, value[:minute].to_i, value[:second].to_i) unless value.nil? || value[:year].blank? end diff --git a/lib/bridges/record_select/bridge.rb b/lib/bridges/record_select/bridge.rb new file mode 100644 index 0000000000..f3ccb37ec7 --- /dev/null +++ b/lib/bridges/record_select/bridge.rb @@ -0,0 +1,5 @@ +ActiveScaffold.bridge "RecordSelect" do + install do + require File.join(File.dirname(__FILE__), "lib/record_select_bridge.rb") + end +end diff --git a/lib/bridges/record_select/lib/record_select_bridge.rb b/lib/bridges/record_select/lib/record_select_bridge.rb new file mode 100644 index 0000000000..db5fef2b5b --- /dev/null +++ b/lib/bridges/record_select/lib/record_select_bridge.rb @@ -0,0 +1,79 @@ +module ActiveScaffold + module RecordSelectBridge + def self.included(base) + base.class_eval do + include FormColumnHelpers + include SearchColumnHelpers + include ViewHelpers + end + end + + module ViewHelpers + def self.included(base) + base.alias_method_chain :active_scaffold_includes, :record_select + end + + def active_scaffold_includes_with_record_select(*args) + active_scaffold_includes_without_record_select(*args) + record_select_includes + end + end + + module FormColumnHelpers + # requires RecordSelect plugin to be installed and configured. + def active_scaffold_input_record_select(column, options) + if column.singular_association? + active_scaffold_record_select(column, options, @record.send(column.name), false) + elsif column.plural_association? + active_scaffold_record_select(column, options, @record.send(column.name), true) + end + end + + def active_scaffold_record_select(column, options, value, multiple) + unless column.association + raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)." + end + remote_controller = active_scaffold_controller_for(column.association.klass).controller_path + + # if the opposite association is a :belongs_to (in that case association in this class must be has_one or has_many) + # then only show records that have not been associated yet + if [:has_one, :has_many].include?(column.association.macro) + params.merge!({column.association.primary_key_name => ''}) + end + + record_select_options = {:controller => remote_controller, :id => options[:id]} + record_select_options.merge!(options) + record_select_options.merge!(active_scaffold_input_text_options) + record_select_options.merge!(column.options) + record_select_options[:onchange] = "function(id, label) { this.value = id; #{record_select_options[:onchange]} }" if record_select_options[:onchange] + + if multiple + record_multi_select_field(options[:name], value || [], record_select_options) + else + record_select_field(options[:name], value || column.association.klass.new, record_select_options) + end + end + end + + module SearchColumnHelpers + def active_scaffold_search_record_select(column, options) + begin + value = field_search_params[column.name] + value = unless value.blank? + if column.options[:multiple] + column.association.klass.find value.collect!(&:to_i) + else + column.association.klass.find(value.to_i) + end + end + rescue Exception => e + logger.error Time.now.to_s + "Sorry, we are not that smart yet. Attempted to restore search values to search fields but instead got -- #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" + raise e + end + + active_scaffold_record_select(column, options, value, column.options[:multiple]) + end + end + end +end + +ActionView::Base.class_eval { include ActiveScaffold::RecordSelectBridge } From 08c76fa9f5cce7a67ed14a056c59cc8fc6fd20e0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 27 Jul 2010 12:22:09 +0200 Subject: [PATCH 0519/2024] Fix rendering layout in nested scaffolds when they are requested directly (without nested action and render_component) --- lib/active_scaffold/actions/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index e485c22c22..a977d7338c 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -23,7 +23,7 @@ def list protected def list_respond_to_html - render :action => 'list', :layout => (!respond_to?(:nested?) || !nested?) && (!respond_to?(:component_request?) || !component_request?) + render :action => 'list', :layout => !respond_to?(:component_request?) || !component_request? end def list_respond_to_js render :action => 'list.js' From 4afd7f009b2a15ddc7db8053dd38399ca98aa27d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 28 Jul 2010 10:21:15 +0200 Subject: [PATCH 0520/2024] Bugfix: only clone values which a duplicable? --- lib/active_scaffold/helpers/controller_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 1fd65b482f..939a479aa7 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -15,7 +15,7 @@ def params_for(options = {}) blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token, :iframe] unless @params_for @params_for = {} - params.select { |key, value| blacklist.exclude? key.to_sym if key }.each {|key, value| @params_for[key.to_sym] = value.clone} + params.select { |key, value| blacklist.exclude? key.to_sym if key }.each {|key, value| @params_for[key.to_sym] = value.duplicable? ? value.clone : value} @params_for[:controller] = '/' + @params_for[:controller] unless @params_for[:controller].first(1) == '/' # for namespaced controllers @params_for.delete(:id) if @params_for[:id].nil? end From f6c292c0a742c1710b87f6f5d4808aaf08b90977 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 28 Jul 2010 10:23:06 +0200 Subject: [PATCH 0521/2024] if render_component is installed use it for embedded scaffolds --- lib/active_scaffold/actions/list.rb | 6 +++++- lib/extensions/action_view_rendering.rb | 16 +++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index dc9d232af4..d3d2af16e7 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -22,7 +22,11 @@ def list protected def list_respond_to_html - render :action => 'list' + if params.delete(:embedded) + render :action => 'list', :layout => false + else + render :action => 'list' + end end def list_respond_to_js if params[:adapter] diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index 6ac75dfc91..a88d199bf3 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -58,12 +58,18 @@ def render_with_active_scaffold(*args, &block) options[:params].merge! :eid => eid, :embedded => true id = "as_#{eid}-content" - url = url_for({:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params])) - content_tag(:div, {:id => id}) do - link_to(remote_controller.to_s, url, {:remote => true, :id => id}) << - javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true})") + url_options = {:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params]) + + if respond_to? :render_component + render_component url_options + else + content_tag(:div, {:id => id}) do + url = url_for(url_options + link_to(remote_controller.to_s, url, {:remote => true, :id => id}) << + javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true})") + end end - #render_component :controller => remote_controller.to_s, :action => 'table', :params => options[:params] + else options = args.first @last_partial = {:partial => options[:partial], :index => nil} if options[:partial] From 690a75d712ebeccb1cd46806bf2e4b9e0c4696d5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 28 Jul 2010 10:33:07 +0200 Subject: [PATCH 0522/2024] Add link to rails 3.0 render_component --- README | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README b/README index 629539e529..6d646636fb 100644 --- a/README +++ b/README @@ -29,11 +29,18 @@ Rails < 2.1: Active Scaffold 1-1-stable (no guarantees) Since Rails 2.3, render_component plugin is needed for nested and embbeded scaffolds. It works with rails-2.3 branch from ewildgoose repository: script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3 -Since Rails 3.0 render_component is nt needed anymore +Rails 3.0 compatible fork of activesaffold by Volker Hochstein: + +Since Rails 3.0 render_component is nt used for nesting, but optional for embedded scaffolds +Rails 3.0 version of render_component: +rails plugin install git://github.com/vhochstein/render_component.git Since Rails 3.0, the following is needed: rails plugin install git://github.com/rails/verification.git +Fork uses unobtrusive Javascript, so you are basically free to pick your javascript framework +Out of the box Prototype or JQuery are supported: + Prototype 1.7 (default js framework) rails.js in git://github.com/vhochstein/prototype-ujs.git From 13c8798a6805b478fed8bb2b5afb0fc0ec9adae4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 28 Jul 2010 12:49:54 +0200 Subject: [PATCH 0523/2024] Bugfix: Syntax error --- lib/extensions/action_view_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index a88d199bf3..71a4ac4326 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -64,7 +64,7 @@ def render_with_active_scaffold(*args, &block) render_component url_options else content_tag(:div, {:id => id}) do - url = url_for(url_options + url = url_for(url_options) link_to(remote_controller.to_s, url, {:remote => true, :id => id}) << javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true})") end From 84e11a78521cd9ae4d64d86ff05290d7d0954035 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 28 Jul 2010 14:50:12 +0200 Subject: [PATCH 0524/2024] jquery: add support for inplace_edit=true and select form_ui --- .../javascripts/jquery/active_scaffold.js | 101 +----------------- .../javascripts/jquery/jquery.editinplace.js | 78 +++++++++++++- 2 files changed, 76 insertions(+), 103 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 2a44f4f4ce..7f41965823 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -183,9 +183,9 @@ $(document).ready(function() { if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content'); if (mode === 'clone') { - options.nodeIdSuffix = record_id; - options.inplacePatternSelector = '#' + column_heading.id + ' .as_inplace_pattern'; - options['onFormCustomization'] = new Function('element', 'form', 'element.clonePatternField();'); + options.clone_id_suffix = record_id; + options.clone_selector = '#' + column_heading.attr('id') + ' .as_inplace_pattern'; + options.field_type = 'clone'; } if (render_url) { @@ -687,98 +687,3 @@ ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({ //this.adapter.find('td').first().children().highlight(); } }); - -if (typeof(Ajax) !== 'undefined' && Ajax.InPlaceEditor) { -ActiveScaffold.InPlaceEditor = Ajax.InPlaceEditor.extend({ - setFieldFromAjax: function(url, options) { - var ipe = this; - $(ipe._controls.editor).remove(); - new Ajax.Request(url, { - method: 'get', - onComplete: function(response) { - ipe._form.insert({top: response.responseText}); - if (options.plural) { - ipe._form.getElements().each(function(el) { - if (el.type != "submit" && el.type != "image") { - el.name = ipe.options.paramName + '[]'; - el.className = 'editor_field'; - } - }); - } else { - var fld = ipe._form.findFirstElement(); - fld.name = ipe.options.paramName; - fld.className = 'editor_field'; - if (ipe.options.submitOnBlur) - fld.onblur = ipe._boundSubmitHandler; - ipe._controls.editor = fld; - } - } - }); - }, - - clonePatternField: function() { - var patternNodes = this.getPatternNodes(this.options.inplacePatternSelector); - if (patternNodes.editNode == null) { - alert('did not find any matching node for ' + this.options.editFieldSelector); - return; - } - - var fld = patternNodes.editNode.cloneNode(true); - if (fld.id.length > 0) fld.id += this.options.nodeIdSuffix; - fld.name = this.options.paramName; - fld.className = 'editor_field'; - this.setValue(fld, this._controls.editor.value); - if (this.options.submitOnBlur) - fld.onblur = this._boundSubmitHandler; - $(this._controls.editor).remove(); - this._controls.editor = fld; - this._form.appendChild(this._controls.editor); - - $A(patternNodes.additionalNodes).each(function(node) { - var patternNode = node.cloneNode(true); - if (patternNode.id.length > 0) { - patternNode.id = patternNode.id + this.options.nodeIdSuffix; - } - this._form.appendChild(patternNode); - }.bind(this)); - }, - - getPatternNodes: function(inplacePatternSelector) { - var nodes = {editNode: null, additionalNodes: []}; - var selectedNodes = $$(inplacePatternSelector); - var firstNode = selectedNodes.first(); - - if (typeof(firstNode) !== 'undefined') { - // AS inplace_edit_control_container -> we have to select all child nodes - // Workaround for ie which does not support css > selector - if (firstNode.className.indexOf('as_inplace_pattern') !== -1) { - selectedNodes = firstNode.childElements(); - } - nodes.editNode = selectedNodes.first(); - selectedNodes.shift(); - nodes.additionalNodes = selectedNodes; - } - return nodes; - }, - - setValue: function(editField, textValue) { - var function_name = 'setValueFor' + editField.nodeName.toLowerCase(); - if (typeof(this[function_name]) == 'function') { - this[function_name](editField, textValue); - } else { - editField.value = textValue; - } - }, - - setValueForselect: function(editField, textValue) { - var len = editField.options.length; - var i = 0; - while (i < len && editField.options[i].text != textValue) { - i++; - } - if (i < len) { - editField.value = editField.options[i].value - } - } -}); -} diff --git a/frontends/default/javascripts/jquery/jquery.editinplace.js b/frontends/default/javascripts/jquery/jquery.editinplace.js index ae1225981f..636d9fe91b 100644 --- a/frontends/default/javascripts/jquery/jquery.editinplace.js +++ b/frontends/default/javascripts/jquery/jquery.editinplace.js @@ -55,7 +55,7 @@ $.fn.editInPlace.defaults = { save_button: '<button class="inplace_save">Save</button>', // string: image button tag to use as “Save” button cancel_button: '<button class="inplace_cancel">Cancel</button>', // string: image button tag to use as “Cancel” button params: "", // string: example: first_name=dave&last_name=hauenstein extra paramters sent via the post request to the server - field_type: "text", // string: "text", "textarea", or "select", or "remote"; The type of form field that will appear on instantiation + field_type: "text", // string: "text", "textarea", or "select", or "remote", or "clone"; The type of form field that will appear on instantiation default_text: "(Click here to add text)", // string: text to show up if the element that has this functionality is empty use_html: false, // boolean, set to true if the editor should use jQuery.fn.html() to extract the value to show from the dom node textarea_rows: 10, // integer: set rows attribute of textarea, if field_type is set to textarea. Use CSS if possible though @@ -69,6 +69,8 @@ $.fn.editInPlace.defaults = { saving_text: undefined, // string: text to be used when server is saving information. Example "Saving..." saving_image: "", // string: uses saving text specify an image location instead of text while server is saving saving_animation_color: 'transparent', // hex color string, will be the color the pulsing animation during the save pulses to. Note: Only works if jquery-ui is loaded + clone_selector: null, // if field_type clone a selector to clone editor from + clone_id_suffix: null, // if field_type clone a suffix to create unique ids value_required: false, // boolean: if set to true, the element will not be saved unless a value is entered element_id: "element_id", // string: name of parameter holding the id or the editable @@ -264,7 +266,7 @@ $.extend(InlineEditor.prototype, { }, createEditorElement: function() { - if (-1 === $.inArray(this.settings.field_type, ['text', 'textarea', 'select', 'remote'])) + if (-1 === $.inArray(this.settings.field_type, ['text', 'textarea', 'select', 'remote', 'clone'])) throw "Unknown field_type <fnord>, supported are 'text', 'textarea', 'select' and 'remote'"; var editor = null; @@ -279,7 +281,10 @@ $.extend(InlineEditor.prototype, { + ' cols="' + this.settings.textarea_cols + '" />'); else if ("remote" === this.settings.field_type) editor = this.createRemoteGeneratedEditor(); - + else if ("clone" === this.settings.field_type) { + editor = this.cloneEditor(); + return editor; + } editor.val(this.triggerDelegateCall('willOpenEditInPlace', this.originalValue)); return editor; }, @@ -292,6 +297,68 @@ $.extend(InlineEditor.prototype, { }).responseText); }, + cloneEditor: function() { + var patternNodes = this.getPatternNodes(this.settings.clone_selector); + if (patternNodes.editNode == null) { + alert('did not find any matching node for ' + this.settings.clone_selector); + return; + } + + var editorNode = patternNodes.editNode.clone(); + var clonedNodes = null; + if (editorNode.attr('id').length > 0) editorNode.attr('id', editorNode.attr('id') + this.settings.clone_id_suffix); + editorNode.attr('name', 'inplace_value'); + editorNode.attr('class', 'editor_field'); + this.setValue(editorNode, this.originalValue); + clonedNodes = editorNode; + + if (patternNodes.additionalNodes) { + patternNodes.additionalNodes.each(function (index, node) { + var patternNode = $(node).clone(); + if (patternNode.attr('id').length > 0) { + patternNode.attr('id', patternNode.attr('id') + this.settings.clone_id_suffix); + } + clonedNodes = clonedNodes.after(patternNode); + }); + } + return clonedNodes; + }, + + getPatternNodes: function(clone_selector) { + var nodes = {editNode: null, additionalNodes: null}; + var selectedNodes = $(clone_selector); + var firstNode = selectedNodes.first(); + + if (typeof(firstNode) !== 'undefined') { + // AS inplace_edit_control_container -> we have to select all child nodes + // Workaround for ie which does not support css > selector + if (firstNode.hasClass('as_inplace_pattern')) { + selectedNodes = firstNode.children(); + } + nodes.editNode = selectedNodes.first(); + // buggy... + //nodes.additionalNodes = selectedNodes.find(':gt(0)'); + } + return nodes; + }, + + setValue: function(editField, textValue) { + var function_name = 'setValueFor' + editField.get(0).nodeName.toLowerCase(); + if (typeof(this[function_name]) == 'function') { + this[function_name](editField, textValue); + } else { + editField.val(textValue); + } + }, + + setValueForselect: function(editField, textValue) { + var option_value = editField.children("option:contains('" + textValue + "')").val(); + + if (typeof(option_value) !== 'undefined') { + editField.val(option_value); + } + }, + inputNameAndClass: function() { return ' name="inplace_value" class="inplace_field" '; }, @@ -387,12 +454,13 @@ $.extend(InlineEditor.prototype, { if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent)) return; - var enteredText = this.dom.find(':input').val(); + var editor = this.dom.find(':input'); + var enteredText = editor.val(); enteredText = this.triggerDelegateCall('willCloseEditInPlace', enteredText); this.restoreOriginalValue(); if (hasContent(enteredText) - && ! this.isDisabledDefaultSelectChoice()) + && ! this.isDisabledDefaultSelectChoice() && !editor.is('select')) this.setClosedEditorContent(enteredText); this.reinit(); }, From 39434eec76f5e353fcac1790fe7477f62732afa9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 28 Jul 2010 15:43:16 +0200 Subject: [PATCH 0525/2024] jquery Bugfix: ajax:failure event for action_links generated script errors --- frontends/default/javascripts/jquery/active_scaffold.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 7f41965823..89da64881f 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -79,11 +79,11 @@ $(document).ready(function() { return true; }); $('a.as_action').live('ajax:failure', function(event) { - var as_action = $this; + var as_action = $(this); if (as_action.data('action_link')) { var action_link = as_action.data('action_link'); ActiveScaffold.report_500_response(action_link.scaffold_id()); - action_link.attr('disabled', ''); + action_link.enable(); } return true; }); From f02823f31b1b8ed687d6bbf8bc61596943961c45 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 28 Jul 2010 16:11:14 +0200 Subject: [PATCH 0526/2024] Fixed prototype specific code --- .../default/javascripts/jquery/active_scaffold.js | 9 +++++++++ .../default/javascripts/prototype/active_scaffold.js | 10 +++++++++- frontends/default/views/_list_messages.html.erb | 2 +- frontends/default/views/_messages.html.erb | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 89da64881f..a7736df2d4 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -363,6 +363,15 @@ var ActiveScaffold = { return element; }, + remove: function(element) { + if (typeof(element) == 'string') element = '#' + element; + $(element).remove(); + }, + + hide: function(element) { + $(element).hide(); + }, + create_record_row: function(tbody, html) { if (typeof(tbody) == 'string') tbody = '#' + tbody; tbody = $(tbody); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 9d4606c782..eb311253a3 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -297,13 +297,21 @@ var ActiveScaffold = { element = $(element.id); return element; }, - + replace_html: function(element, html) { element = $(element); element.update(html); return element; }, + remove: function(element) { + $(element).remove(); + }, + + hide: function(element) { + $(element).hide(); + }, + create_record_row: function(tbody, html) { tbody = $(tbody); tbody.insert({top: html}); diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index d7ab315e31..0aa9ff560f 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -3,7 +3,7 @@ <td colspan="<%= active_scaffold_config.list.columns.length -%>" class="messages-container"> <p class="error-message message server-error" style="display:none;"> <%= as_(:internal_error).html_safe %> - <a href="#" onclick="Element.hide(this.parentNode); return false;" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a> + <a href="#" onclick="ActiveScaffold.hide(this.parentNode); return false;" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a> </p> <div id="<%= active_scaffold_messages_id -%>"> <%= render :partial => 'messages' %> diff --git a/frontends/default/views/_messages.html.erb b/frontends/default/views/_messages.html.erb index f21e14ca41..bf2c26a749 100644 --- a/frontends/default/views/_messages.html.erb +++ b/frontends/default/views/_messages.html.erb @@ -3,7 +3,7 @@ <p class="<%= "#{name}-message message" %>" > <%= h flash[name] %> <% if request.xhr? %> - <a href="#" onclick="Element.remove(this.parentNode); return false;" title="<%= as_(:close) %>"></a> + <a href="#" onclick="ActiveScaffold.remove(this.parentNode); return false;" title="<%= as_(:close) %>"></a> <% end %> </p> <% end %> From c6f2a3b109ef544abb261bc35d4bdf2661a78421 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 28 Jul 2010 16:42:07 +0200 Subject: [PATCH 0527/2024] column actions_for_associations_links might be :index as well --- lib/active_scaffold/actions/nested.rb | 5 ++++- lib/active_scaffold/helpers/list_column_helpers.rb | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 5f150c3ac8..c200d76151 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -17,7 +17,10 @@ def self.included(base) protected def nested @nested ||= ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, active_scaffold_session_storage) - register_constraints_with_action_columns(@nested.constrained_fields) if !@nested.nil? && @nested.new_instance? + if !@nested.nil? && @nested.new_instance? + register_constraints_with_action_columns(@nested.constrained_fields) + active_scaffold_constraints[:id] = nested.parent_id if @nested.belongs_to? + end @nested end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 9dd84a0f94..85cedf0e20 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -86,6 +86,10 @@ def action_link_to_inline_form(column, record, associated) elsif column.actions_for_association_links.include?(:show) link.action = 'show' link.crud_type = :read + elsif column.actions_for_association_links.include?(:index) + link.parameters[:id] = record.send(column.association.name).id + link.action = 'index' + link.crud_type = :read end link end From bfda16be6e5a92b1704673a6645e10eebae0be39 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 29 Jul 2010 08:47:13 +0200 Subject: [PATCH 0528/2024] use :list instead of _index for actions_for_association_links column configuration --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 85cedf0e20..e524748b7c 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -86,7 +86,7 @@ def action_link_to_inline_form(column, record, associated) elsif column.actions_for_association_links.include?(:show) link.action = 'show' link.crud_type = :read - elsif column.actions_for_association_links.include?(:index) + elsif column.actions_for_association_links.include?(:list) link.parameters[:id] = record.send(column.association.name).id link.action = 'index' link.crud_type = :read From 10597e5a5802c1e19d37224e129c64f04722f036 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 29 Jul 2010 09:06:43 +0200 Subject: [PATCH 0529/2024] add appropriate nested list header if parent belongs_to nested model --- lib/active_scaffold/actions/nested.rb | 8 +++++++- lib/active_scaffold/locale/de.rb | 1 + lib/active_scaffold/locale/en.rb | 1 + lib/active_scaffold/locale/es.yml | 1 + lib/active_scaffold/locale/fr.rb | 1 + lib/active_scaffold/locale/hu.yml | 1 + lib/active_scaffold/locale/ja.yml | 1 + lib/active_scaffold/locale/ru.yml | 1 + 8 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index c200d76151..7ec5f73d9d 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -39,7 +39,13 @@ def set_nested end def set_nested_list_label - active_scaffold_session_storage[:list][:label] = as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => nested_parent_record.to_label) if nested? + if nested? + active_scaffold_session_storage[:list][:label] = if nested.belongs_to? + as_(:nested_of_model, :nested_model => active_scaffold_config.model.model_name.human, :parent_model => nested_parent_record.to_label) + else + as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => nested_parent_record.to_label) + end + end end def nested_authorized?(record = nil) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 1942c113d6..dcb5d2d91d 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -21,6 +21,7 @@ :edit => 'Bearbeiten', :export => 'Exportieren', :nested_for_model => '%{nested_model} für %{parent_model}', + :nested_of_model => '%{nested_model} von %{parent_model}', :filtered => '(Gefiltert)', :found => 'Gefunden', :hide => 'Verstecken', diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 0d59136730..74ed23b301 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -22,6 +22,7 @@ :edit => 'Edit', :export => 'Export', :nested_for_model => '%{nested_model} for %{parent_model}', + :nested_of_model => '%{nested_model} of %{parent_model}', :false => 'False', :filtered => '(Filtered)', :found => 'Found', diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index 691099784b..d506b4e25d 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -29,6 +29,7 @@ es: live_search: 'Buscar en Vivo' loading: 'Cargando…' nested_for_model: '%{nested_model} de %{parent_model}' + nested_of_model: '%{nested_model} of %{parent_model}' next: 'Siguiente' no_entries: 'Sin entradas' no_options: 'sin opciones' diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 95339780dc..1c384cf577 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -21,6 +21,7 @@ :edit => 'Éditer', :export => 'Exporter', :nested_for_model => '%{nested_model} pour %{parent_model}', + :nested_of_model => '%{nested_model} de %{parent_model}', :filtered => '(Filtré)', :found => 'Trouvé', :hide => 'Cacher', diff --git a/lib/active_scaffold/locale/hu.yml b/lib/active_scaffold/locale/hu.yml index decc13d1a4..41300eec26 100644 --- a/lib/active_scaffold/locale/hu.yml +++ b/lib/active_scaffold/locale/hu.yml @@ -20,6 +20,7 @@ hu: edit: 'Szerkesztés' export: 'Exportálás' nested_for_model: '%{nested_model} / %{parent_model}' + nested_of_model: '%{nested_model} of %{parent_model}' filtered: '(Szűrt)' found: 'Találat' hide: 'Elrejtés' diff --git a/lib/active_scaffold/locale/ja.yml b/lib/active_scaffold/locale/ja.yml index c047b1f548..df23a66b77 100644 --- a/lib/active_scaffold/locale/ja.yml +++ b/lib/active_scaffold/locale/ja.yml @@ -20,6 +20,7 @@ ja: edit: '編集' export: 'Export' # needed? nested_for_model: '%{parent_model}の%{nested_model}' + nested_of_model: '%{nested_model} of %{parent_model}' filtered: '(フィルタ中)' found: '個ありました' hide: '隠す' diff --git a/lib/active_scaffold/locale/ru.yml b/lib/active_scaffold/locale/ru.yml index 07714d568b..ec8e710426 100644 --- a/lib/active_scaffold/locale/ru.yml +++ b/lib/active_scaffold/locale/ru.yml @@ -20,6 +20,7 @@ ru: edit: 'Изменить' export: 'Экспорт' nested_for_model: '%{parent_model} / %{nested_model}' + nested_of_model: '%{nested_model} of %{parent_model}' filtered: '(Найденное)' found: 'Найдено' hide: 'Скрыть' From 9e841d6302774f6bbf526ec66f336502804b87db Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 30 Jul 2010 16:28:11 +0200 Subject: [PATCH 0530/2024] added active_scaffold_generator example: rails g active_scaffold country name:string --- lib/generators/active_scaffold/USAGE | 29 +++++++++++++++++++ .../active_scaffold_generator.rb | 20 +++++++++++++ .../active_scaffold_controller/USAGE | 19 ++++++++++++ .../active_scaffold_controller_generator.rb | 28 ++++++++++++++++++ .../templates/controller.rb | 4 +++ 5 files changed, 100 insertions(+) create mode 100644 lib/generators/active_scaffold/USAGE create mode 100644 lib/generators/active_scaffold/active_scaffold_generator.rb create mode 100644 lib/generators/active_scaffold_controller/USAGE create mode 100644 lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb create mode 100644 lib/generators/active_scaffold_controller/templates/controller.rb diff --git a/lib/generators/active_scaffold/USAGE b/lib/generators/active_scaffold/USAGE new file mode 100644 index 0000000000..f3794e7737 --- /dev/null +++ b/lib/generators/active_scaffold/USAGE @@ -0,0 +1,29 @@ +Description: + Scaffolds an entire resource, from model and migration to controller, + along with a full test suite and configured to use active_scaffold. + The resource is ready to use as a starting point for your RESTful, + resource-oriented application. + + Pass the name of the model (in singular form), either CamelCased or + under_scored, as the first argument, and an optional list of attribute + pairs. + + Attribute pairs are field:type arguments specifying the + model's attributes. Timestamps are added by default, so you don't have to + specify them by hand as 'created_at:datetime updated_at:datetime'. + + You don't have to think up every attribute up front, but it helps to + sketch out a few so you can start working with the resource immediately. + + For example, 'active_scaffold post title:string body:text published:boolean' + gives you a model with those three attributes, a controller configured to use active_scaffold, + as well as a resources :posts with additional active_scaffold routes + declaration in config/routes.rb. + + If you want to remove all the generated files, run + 'rails destroy active_scaffold ModelName'. + +Examples: + `rails generate active_scaffold post` + `rails generate active_scaffold post title:string body:text published:boolean` + `rails generate active_scaffold purchase order_id:integer amount:decimal` \ No newline at end of file diff --git a/lib/generators/active_scaffold/active_scaffold_generator.rb b/lib/generators/active_scaffold/active_scaffold_generator.rb new file mode 100644 index 0000000000..8dd1928df4 --- /dev/null +++ b/lib/generators/active_scaffold/active_scaffold_generator.rb @@ -0,0 +1,20 @@ +require 'rails/generators/rails/resource/resource_generator' +#require 'generators/active_scaffold_controller/active_scaffold_controller_generator' + +module Rails + module Generators + class ActiveScaffoldGenerator < ResourceGenerator #metagenerator + remove_hook_for :resource_controller + remove_class_option :actions + + def add_resource_route + route_config = class_path.collect{|namespace| "namespace :#{namespace} do " }.join(" ") + route_config << "resources :#{file_name.pluralize} do as_routes end" + route_config << " end" * class_path.size + route route_config + end + + invoke "active_scaffold_controller" + end + end +end diff --git a/lib/generators/active_scaffold_controller/USAGE b/lib/generators/active_scaffold_controller/USAGE new file mode 100644 index 0000000000..414889a3c7 --- /dev/null +++ b/lib/generators/active_scaffold_controller/USAGE @@ -0,0 +1,19 @@ +Description: + Stubs out a active_scaffolded controller. Pass the model name, + either CamelCased or under_scored. + The controller name is retrieved as a pluralized version of the model + name. + + To create a controller within a module, specify the model name as a + path like 'parent_module/controller_name'. + + This generates a controller class in app/controllers and invokes helper, + template engine and test framework generators. + +Example: + `rails generate active_scaffold_controller CreditCard` + + Credit card controller with URLs like /credit_card/debit. + Controller: app/controllers/credit_cards_controller.rb + Functional Test: test/functional/credit_cards_controller_test.rb + Helper: app/helpers/credit_cards_helper.rb \ No newline at end of file diff --git a/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb b/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb new file mode 100644 index 0000000000..232f9700cc --- /dev/null +++ b/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb @@ -0,0 +1,28 @@ +#require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator' + +module Rails + module Generators + class ActiveScaffoldControllerGenerator < NamedBase #metagenerator + include ResourceHelpers + + def self.source_root + @source_root ||= File.join(File.dirname(__FILE__), 'templates') + end + + check_class_collision :suffix => "Controller" + + class_option :orm, :banner => "NAME", :type => :string, :required => true, + :desc => "ORM to generate the controller for" + + def create_controller_files + template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb") + end + + hook_for :test_framework, :as => :scaffold + + def create_view_root_folder + empty_directory File.join("app/views", controller_file_path) + end + end + end +end \ No newline at end of file diff --git a/lib/generators/active_scaffold_controller/templates/controller.rb b/lib/generators/active_scaffold_controller/templates/controller.rb new file mode 100644 index 0000000000..c150f7a06e --- /dev/null +++ b/lib/generators/active_scaffold_controller/templates/controller.rb @@ -0,0 +1,4 @@ +class <%= controller_class_name %>Controller < ApplicationController + active_scaffold :<%= class_name.demodulize %> do |conf| + end +end \ No newline at end of file From f657256d6babfff62ff34108b24a9d10e4260ae6 Mon Sep 17 00:00:00 2001 From: Stephen Murdoch <stephenjamesmurdoch@gmail.com> Date: Sun, 1 Aug 2010 22:58:40 +0800 Subject: [PATCH 0531/2024] adding raw method to ensure that html gets rendered properly --- frontends/default/views/_list_actions.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 1dab9f45bf..f7f31df2df 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -7,9 +7,10 @@ <% action_links.each :member do |link| -%> <% next if skip_action_link(link, record) -%> <td> - <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : "<a class='disabled #{link.action}'>#{link.label}</a>" -%> + <%= raw record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : "<a class='disabled #{link.action}'>#{link.label}</a>" -%> </td> <% end -%> </tr> </table> </td> + From c2d96fad2c7e56cd4075e5c76ca33f9304c4bde4 Mon Sep 17 00:00:00 2001 From: Stephen Murdoch <stephenjamesmurdoch@gmail.com> Date: Sun, 1 Aug 2010 22:59:08 +0800 Subject: [PATCH 0532/2024] adding html_safe method to ensure that html is rendered properly --- .../helpers/list_column_helpers.rb | 52 ++++++++++--------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index e524748b7c..bb4c86299e 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -27,7 +27,7 @@ def get_column_value(record, column) raise e end end - + # TODO: move empty_field_text and   logic in here? # TODO: we need to distinguish between the automatic links *we* create and the ones that the dev specified. some logic may not apply if the dev specified the link. def render_list_column(text, column, record) @@ -57,15 +57,16 @@ def render_list_column(text, column, record) else authorized = record.authorized_for?(:crud_type => link.crud_type) end - return "<a class='disabled'>#{text}</a>" unless authorized - + #return "<a class='disabled'>#{text}</a>" unless authorized + # to make html render properly + return "<a class='disabled'>#{text}</a>".html_safe unless authorized render_action_link(link, url_options, record) else text = active_scaffold_inplace_edit(record, column, {:formatted_column => text}) if inplace_edit?(record, column) text end end - + # setup the action link to inline form def action_link_to_inline_form(column, record, associated) link = column.link.clone @@ -74,7 +75,7 @@ def action_link_to_inline_form(column, record, associated) return link if polymorphic_controller.nil? link.controller = polymorphic_controller end - + if column_empty?(associated) # if association is empty, we only can link to create form if column.actions_for_association_links.include?(:new) link.action = 'new' @@ -93,13 +94,13 @@ def action_link_to_inline_form(column, record, associated) end link end - + def polymorphic_controller_for_nested_link(column, record) begin controller = active_scaffold_controller_for(record.send(column.association.name).class) controller.controller_path rescue ActiveScaffold::ControllerNotFound - controller = nil + controller = nil end end @@ -174,7 +175,7 @@ def format_column_value(record, column, value = nil) format_association_value(value, column, associated_size) end end - + def format_number_value(value, options = {}) value = case options[:format] when :size @@ -190,7 +191,7 @@ def format_number_value(value, options = {}) end clean_column_value(value) end - + def format_association_value(value, column, size) case column.association.macro when :has_one, :belongs_to @@ -216,7 +217,7 @@ def format_association_value(value, column, size) end end end - + def format_value(column_value, options = {}) value = if column_empty?(column_value) active_scaffold_config.list.empty_field_text @@ -229,7 +230,7 @@ def format_value(column_value, options = {}) end clean_column_value(value) end - + def cache_association(value, column) # we are not using eager loading, cache firsts records in order not to query the database in a future unless value.loaded? @@ -245,15 +246,15 @@ def cache_association(value, column) # ========== # = Inline Edit = # ========== - + def inplace_edit?(record, column) column.inplace_edit and record.authorized_for?(:crud_type => :update, :column => column.name) end - + def inplace_edit_cloning?(column) column.inplace_edit != :ajax and (override_form_field?(column) or column.form_ui or (column.column and override_input?(column.column.type))) end - + def format_inplace_edit_column(record,column) if column.list_ui == :checkbox active_scaffold_column_checkbox(column, record) @@ -261,7 +262,7 @@ def format_inplace_edit_column(record,column) format_column_value(record, column) end end - + def active_scaffold_inplace_edit(record, column, options = {}) formatted_column = options[:formatted_column] || format_column_value(record, column) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} @@ -270,7 +271,7 @@ def active_scaffold_inplace_edit(record, column, options = {}) content_tag(:span, formatted_column, tag_options) end - + def inplace_edit_control(column) if inplace_edit?(active_scaffold_config.model, column) and inplace_edit_cloning?(column) @record = active_scaffold_config.model.new @@ -281,14 +282,14 @@ def inplace_edit_control(column) content_tag(:div, active_scaffold_input_for(column), {:style => "display:none;", :class => inplace_edit_control_css_class}) end end - + def inplace_edit_control_css_class "as_inplace_pattern" end - + def inplace_edit_tag_attributes(column) tag_options = {} - tag_options['data-ie_url'] = url_for({:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => '__id__'}) + tag_options['data-ie_url'] = url_for({:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => '__id__'}) tag_options['data-ie_cancel_text'] = column.options[:cancel_text] || as_(:cancel) tag_options['data-ie_loading_text'] = column.options[:loading_text] || as_(:loading) tag_options['data-ie_save_text'] = column.options[:save_text] || as_(:update) @@ -310,21 +311,21 @@ def inplace_edit_tag_attributes(column) end tag_options end - + def mark_column_heading all_marked = (marked_records.length >= @page.pager.count) tag_options = {:id => "#{controller_id}_mark_heading", :class => "mark_heading in_place_editor_field"} tag_options['data-ie_url'] = url_for({:controller => params_for[:controller], :action => 'mark_all', :eid => params[:eid]}) content_tag(:span, check_box_tag(nil, !all_marked, all_marked), tag_options) end - + def render_column_heading(column, sorting, sort_direction) tag_options = {:id => active_scaffold_column_header_id(column), :class => column_heading_class(column, sorting), :title => column.description} tag_options.merge!(inplace_edit_tag_attributes(column)) if column.inplace_edit content_tag(:th, column_heading_value(column, sorting, sort_direction) + inplace_edit_control(column), tag_options) end - - + + def column_heading_value(column, sorting, sort_direction) if column.sortable? options = {:id => search_form_id, :class => "as_sort", @@ -333,8 +334,8 @@ def column_heading_value(column, sorting, sort_direction) url_options = params_for(:action => :index, :page => 1, :sort => column.name, :sort_direction => sort_direction) link_to column.label, url_options, options - else - if column.name != :marked + else + if column.name != :marked content_tag(:p, column.label) else mark_column_heading @@ -344,3 +345,4 @@ def column_heading_value(column, sorting, sort_direction) end end end + From 657c12b015aba4215b60c404ac86488c11a62d8e Mon Sep 17 00:00:00 2001 From: Stephen Murdoch <stephenjamesmurdoch@gmail.com> Date: Mon, 2 Aug 2010 03:20:31 +0800 Subject: [PATCH 0533/2024] fixing the ckeditor autoload problem --- lib/active_scaffold/config/core.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index 1541691afe..60d25c8cc9 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -1,5 +1,8 @@ module ActiveScaffold::Config - class Core < Base + # to fix the ckeditor bridge problem + class Core < ActiveScaffold::Config::Base + # code commented out (see above) + #class Core < Base # global level configuration # -------------------------- @@ -158,7 +161,7 @@ def _add_sti_create_links new_action_link = @action_links['new'] unless new_action_link.nil? @action_links.delete('new') - self.sti_children.each do |child| + self.sti_children.each do |child| new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone new_sti_link.label = as_(:create_model, :model => child.to_s.camelize.constantize.human_name) new_sti_link.parameters = {model.inheritance_column => child} @@ -227,3 +230,4 @@ def self.available_frontends end end end + From aa97776eb11ffe5b2572bf53ae9a273292ac23db Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 2 Aug 2010 12:25:47 +0200 Subject: [PATCH 0534/2024] Fixed bridges autoloading issues with Rails 3.0 rc1 --- lib/active_scaffold/bridges/bridge.rb | 52 +++++++++++ .../bridges/calendar_date_select/bridge.rb | 11 +++ .../calendar_date_select/lib/as_cds_bridge.rb | 89 +++++++++++++++++++ .../bridges/file_column/bridge.rb | 11 +++ .../file_column/lib/as_file_column_bridge.rb | 46 ++++++++++ .../file_column/lib/file_column_helpers.rb | 59 ++++++++++++ .../bridges/file_column/lib/form_ui.rb | 32 +++++++ .../bridges/file_column/lib/list_ui.rb | 26 ++++++ .../test/functional/file_column_keep_test.rb | 43 +++++++++ .../bridges/file_column/test/mock_model.rb | 9 ++ .../bridges/file_column/test/test_helper.rb | 15 ++++ .../bridges/paperclip/bridge.rb | 10 +++ .../bridges/paperclip/lib/form_ui.rb | 20 +++++ .../bridges/paperclip/lib/list_ui.rb | 16 ++++ .../bridges/paperclip/lib/paperclip_bridge.rb | 39 ++++++++ .../paperclip/lib/paperclip_bridge_helpers.rb | 26 ++++++ .../bridges/semantic_attributes/bridge.rb | 5 ++ .../lib/semantic_attributes_bridge.rb | 20 +++++ .../bridges/tiny_mce/bridge.rb | 5 ++ .../bridges/tiny_mce/lib/tiny_mce_bridge.rb | 45 ++++++++++ .../bridges/validation_reflection/bridge.rb | 8 ++ .../lib/validation_reflection_bridge.rb | 21 +++++ 22 files changed, 608 insertions(+) create mode 100644 lib/active_scaffold/bridges/bridge.rb create mode 100644 lib/active_scaffold/bridges/calendar_date_select/bridge.rb create mode 100644 lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb create mode 100644 lib/active_scaffold/bridges/file_column/bridge.rb create mode 100644 lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb create mode 100644 lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb create mode 100644 lib/active_scaffold/bridges/file_column/lib/form_ui.rb create mode 100644 lib/active_scaffold/bridges/file_column/lib/list_ui.rb create mode 100644 lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb create mode 100644 lib/active_scaffold/bridges/file_column/test/mock_model.rb create mode 100644 lib/active_scaffold/bridges/file_column/test/test_helper.rb create mode 100644 lib/active_scaffold/bridges/paperclip/bridge.rb create mode 100644 lib/active_scaffold/bridges/paperclip/lib/form_ui.rb create mode 100644 lib/active_scaffold/bridges/paperclip/lib/list_ui.rb create mode 100644 lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb create mode 100644 lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb create mode 100644 lib/active_scaffold/bridges/semantic_attributes/bridge.rb create mode 100644 lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb create mode 100644 lib/active_scaffold/bridges/tiny_mce/bridge.rb create mode 100644 lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb create mode 100644 lib/active_scaffold/bridges/validation_reflection/bridge.rb create mode 100644 lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb diff --git a/lib/active_scaffold/bridges/bridge.rb b/lib/active_scaffold/bridges/bridge.rb new file mode 100644 index 0000000000..7b85bca2ac --- /dev/null +++ b/lib/active_scaffold/bridges/bridge.rb @@ -0,0 +1,52 @@ +module ActiveScaffold + module Bridges + def self.bridge(name, &block) + ActiveScaffold::Bridges::Bridge.new(name, &block) + end + + class Bridge + attr_accessor :name + cattr_accessor :bridges + cattr_accessor :bridges_run + self.bridges = [] + + def initialize(name, &block) + self.name = name + @install = nil + # by convention and default, use the bridge name as the required constant for installation + @install_if = lambda { Object.const_defined?(name) } + self.instance_eval(&block) + + ActiveScaffold::Bridges::Bridge.bridges << self + end + + # Set the install block + def install(&block) + @install = block + end + + # Set the install_if block (to check to see whether or not to install the block) + def install?(&block) + @install_if = block + end + + + def run + raise(ArgumentError, "install and install? not defined for bridge #{name}" ) unless @install && @install_if + @install.call if @install_if.call + end + + def self.run_all + return false if self.bridges_run + ActiveScaffold::Bridges::Bridge.bridges.each{|bridge| + bridge.run + } + self.bridges_run=true + end + end + end +end + +Dir[File.join(File.dirname(__FILE__), "*/bridge.rb")].each{|bridge_require| + require bridge_require +} \ No newline at end of file diff --git a/lib/active_scaffold/bridges/calendar_date_select/bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/bridge.rb new file mode 100644 index 0000000000..3b0b53139e --- /dev/null +++ b/lib/active_scaffold/bridges/calendar_date_select/bridge.rb @@ -0,0 +1,11 @@ +ActiveScaffold::Bridges.bridge "CalendarDateSelect" do + install do + # check to see if the old bridge was installed. If so, warn them + # we can detect this by checking to see if the bridge was installed before calling this code + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_calendar_date_select") + raise RuntimeError, "We've detected that you have active_scaffold_calendar_date_select_bridge installed. This plugin has been moved to core. Please remove active_scaffold_calendar_date_select_bridge to prevent any conflicts" + end + + require File.join(File.dirname(__FILE__), "lib/as_cds_bridge.rb") + end +end diff --git a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb new file mode 100644 index 0000000000..d7f48af60e --- /dev/null +++ b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb @@ -0,0 +1,89 @@ +module ActiveScaffold::Config + class Core < Base + + def initialize_with_calendar_date_select(model_id) + initialize_without_calendar_date_select(model_id) + + calendar_date_select_fields = self.model.columns.collect{|c| c.name.to_sym if [:date, :datetime].include?(c.type) }.compact + # check to see if file column was used on the model + return if calendar_date_select_fields.empty? + + # automatically set the forum_ui to a file column + calendar_date_select_fields.each{|field| + self.columns[field].form_ui = :calendar_date_select + } + end + + alias_method_chain :initialize, :calendar_date_select + + end +end + + +module ActiveScaffold + module Bridges + module CalendarDateSelectBridge + # Helpers that assist with the rendering of a Form Column + module FormColumnHelpers + def active_scaffold_input_calendar_date_select(column, options) + options[:class] = "#{options[:class]} text-input".strip + calendar_date_select("record", column.name, options.merge(column.options)) + end + end + + module SearchColumnHelpers + def active_scaffold_search_calendar_date_select(column, options) + opt_value, from_value, to_value = field_search_params_range_values(column) + options = column.options.merge(options).except!(:include_blank) + helper = "select_#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}" + html = [] + html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[from]", :id => "#{options[:id]}_from", :value => from_value)) + html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[to]", :id => "#{options[:id]}_to", :value => to_value)) + html * ' - ' + end + end + + module ViewHelpers + # Provides stylesheets to include with +stylesheet_link_tag+ + def active_scaffold_stylesheets(frontend = :default) + super #+ [calendar_date_select_stylesheets] + end + + # Provides stylesheets to include with +stylesheet_link_tag+ + def active_scaffold_javascripts(frontend = :default) + super #+ [calendar_date_select_javascripts] + end + end + + module Finder + module ClassMethods + def condition_for_calendar_date_select_type(column, value, like_pattern) + conversion = column.column.type == :date ? 'to_date' : 'to_time' + from_value, to_value = ['from', 'to'].collect do |field| + Time.zone.parse(value[field]) rescue nil + end + + if from_value.nil? and to_value.nil? + nil + elsif !from_value + ["#{column.search_sql} <= ?", to_value.send(conversion).to_s(:db)] + elsif !to_value + ["#{column.search_sql} >= ?", from_value.send(conversion).to_s(:db)] + else + ["#{column.search_sql} BETWEEN ? AND ?", from_value.send(conversion).to_s(:db), to_value.send(conversion).to_s(:db)] + end + end + end + end + end + end +end + +ActionView::Base.class_eval do + include ActiveScaffold::Bridges::CalendarDateSelectBridge::FormColumnHelpers + include ActiveScaffold::Bridges::CalendarDateSelectBridge::SearchColumnHelpers + include ActiveScaffold::Bridges::CalendarDateSelectBridge::ViewHelpers +end +ActiveScaffold::Finder::ClassMethods.module_eval do + include ActiveScaffold::Bridges::CalendarDateSelectBridge::Finder::ClassMethods +end diff --git a/lib/active_scaffold/bridges/file_column/bridge.rb b/lib/active_scaffold/bridges/file_column/bridge.rb new file mode 100644 index 0000000000..ab517a4a9e --- /dev/null +++ b/lib/active_scaffold/bridges/file_column/bridge.rb @@ -0,0 +1,11 @@ +ActiveScaffold::Bridges.bridge "FileColumn" do + install do + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_file_column") + raise RuntimeError, "We've detected that you have active_scaffold_file_column_bridge installed. This plugin has been moved to core. Please remove active_scaffold_file_column_bridge to prevent any conflicts" + end + require File.join(File.dirname(__FILE__), "lib/as_file_column_bridge") + require File.join(File.dirname(__FILE__), "lib/form_ui") + require File.join(File.dirname(__FILE__), "lib/list_ui") + require File.join(File.dirname(__FILE__), "lib/file_column_helpers") + end +end diff --git a/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb b/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb new file mode 100644 index 0000000000..472b32c371 --- /dev/null +++ b/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb @@ -0,0 +1,46 @@ +ActiveScaffold::DataStructures::Column.class_eval do + attr_accessor :file_column_display +end + +module ActiveScaffold::Config + class Core < Base + attr_accessor :file_column_fields + def initialize_with_file_column(model_id) + initialize_without_file_column(model_id) + + return unless ActiveScaffold::Bridges::Paperclip::Lib::FileColumnHelpers.klass_has_file_column_fields?(self.model) + + self.model.send :extend, ActiveScaffold::Bridges::Paperclip::Lib::FileColumnHelpers + + # include the "delete" helpers for use with active scaffold, unless they are already included + self.model.generate_delete_helpers + + # switch on multipart + self.update.multipart = true + self.create.multipart = true + + self.model.file_column_fields.each{ |field| + configure_file_column_field(field) + } + end + + alias_method_chain :initialize, :file_column unless self.instance_methods.include?("initialize_without_file_column") + + def configure_file_column_field(field) + # set list_ui first because it gets its default value from form_ui + self.columns[field].list_ui ||= self.model.field_has_image_version?(field, "thumb") ? :thumbnail : :download_link_with_filename + self.columns[field].form_ui ||= :file_column + + # these 2 parameters are necessary helper attributes for the file column that must be allowed to be set to the model by active scaffold. + self.columns[field].params.add "#{field}_temp", "delete_#{field}" + + # set null to false so active_scaffold wont set it to null + # delete_file_column will take care of deleting a file or not. + self.model.columns_hash[field.to_s].instance_variable_set("@null", false) + + rescue + false + end + + end +end diff --git a/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb b/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb new file mode 100644 index 0000000000..9aa607417a --- /dev/null +++ b/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb @@ -0,0 +1,59 @@ +module ActiveScaffold + module Bridges + module Paperclip + module Lib + module FileColumnHelpers + class << self + def file_column_fields(klass) + klass.instance_methods.grep(/_just_uploaded\?$/).collect{|m| m[0..-16].to_sym } + end + + def generate_delete_helpers(klass) + file_column_fields(klass).each { |field| + klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("#{field}_with_delete=") + attr_reader :delete_#{field} + + def delete_#{field}=(value) + value = (value=="true") if String===value + return unless value + + # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! + self.#{field} = nil unless self.#{field}_just_uploaded? + end + EOF + } + end + + def klass_has_file_column_fields?(klass) + true unless file_column_fields(klass).empty? + end + end + + def file_column_fields + @file_column_fields||=FileColumnHelpers.file_column_fields(self) + end + + def options_for_file_column_field(field) + self.allocate.send("#{field}_options") + end + + def field_has_image_version?(field, version="thumb") + begin + # the only way to get to the options of a particular field is to use the instance method + options = options_for_file_column_field(field) + versions = options[:magick][:versions] + raise unless versions.stringify_keys[version] + true + rescue + false + end + end + + def generate_delete_helpers + FileColumnHelpers.generate_delete_helpers(self) + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/file_column/lib/form_ui.rb b/lib/active_scaffold/bridges/file_column/lib/form_ui.rb new file mode 100644 index 0000000000..b169d8e045 --- /dev/null +++ b/lib/active_scaffold/bridges/file_column/lib/form_ui.rb @@ -0,0 +1,32 @@ +module ActiveScaffold + module Helpers + # Helpers that assist with the rendering of a Form Column + module FormColumnHelpers + def active_scaffold_input_file_column(column, options) + if @record.send(column.name) + # we already have a value? display the form for deletion. + content_tag( + :div, + content_tag( + :div, + get_column_value(@record, column) + " " + + hidden_field(:record, "delete_#{column.name}", :value => "false") + + " | " + + link_to_function(as_(:remove_file), "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show();"), + {} + ) + + content_tag( + :div, + file_column_field("record", column.name, options), + :style => "display: none" + ), + {} + ) + else + # no, just display the file_column_field + file_column_field("record", column.name, options) + end + end + end + end +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/file_column/lib/list_ui.rb b/lib/active_scaffold/bridges/file_column/lib/list_ui.rb new file mode 100644 index 0000000000..edb7199319 --- /dev/null +++ b/lib/active_scaffold/bridges/file_column/lib/list_ui.rb @@ -0,0 +1,26 @@ +module ActiveScaffold + module Helpers + # Helpers that assist with the rendering of a List Column + module ListColumnHelpers + def active_scaffold_column_download_link_with_filename(column, record) + return nil if record.send(column.name).nil? + active_scaffold_column_download_link(column, record, File.basename(record.send(column.name))) + end + + def active_scaffold_column_download_link(column, record, label = nil) + return nil if record.send(column.name).nil? + label||=as_(:download) + link_to( label, url_for_file_column(record, column.name.to_s), :popup => true) + end + + def active_scaffold_column_thumbnail(column, record) + return nil if record.send(column.name).nil? + link_to( + image_tag(url_for_file_column(record, column.name.to_s, "thumb"), :border => 0), + url_for_file_column(record, column.name.to_s), + :popup => true) + end + + end + end +end diff --git a/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb b/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb new file mode 100644 index 0000000000..fa2aeec001 --- /dev/null +++ b/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb @@ -0,0 +1,43 @@ +require File.join(File.dirname(__FILE__), "../test_helper.rb") + +class DeleteFileColumnTest < Test::Unit::TestCase + def setup + DeleteFileColumn.generate_delete_helpers(MockModel) + @model = MockModel.new + @model.band_image = "coolio.jpg" + end + + def test__file_column_fields + assert_equal(1, @model.file_column_fields.length) + end + + def test__delete_band_image__boolean__should_delete + @model.delete_band_image = true + assert_nil @model.band_image + end + + def test__delete_band_image__string__should_delete + @model.delete_band_image = "true" + assert_nil @model.band_image + end + + + def test__delete_band_image__boolean_false__shouldnt_delete + @model.delete_band_image = false + assert_not_nil @model.band_image + end + + def test__delete_band_image__string_false__shouldnt_delete + @model.delete_band_image = "false" + assert_not_nil @model.band_image + end + + + def test__just_uploaded__shouldnt_delete + @model.band_image_just_uploaded = true + @model.delete_band_image = "true" + assert_not_nil(@model.band_image) + end + + +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/file_column/test/mock_model.rb b/lib/active_scaffold/bridges/file_column/test/mock_model.rb new file mode 100644 index 0000000000..90fa827f16 --- /dev/null +++ b/lib/active_scaffold/bridges/file_column/test/mock_model.rb @@ -0,0 +1,9 @@ +class MockModel + attr_accessor :name + attr_accessor :bio + + attr_accessor :band_image + attr_accessor :band_image_just_uploaded + def band_image_just_uploaded?; self.band_image_just_uploaded ? true : false; end + +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/file_column/test/test_helper.rb b/lib/active_scaffold/bridges/file_column/test/test_helper.rb new file mode 100644 index 0000000000..8d9457774b --- /dev/null +++ b/lib/active_scaffold/bridges/file_column/test/test_helper.rb @@ -0,0 +1,15 @@ +require 'test/unit' +require "rubygems" +require 'active_support' + +for file in ["../lib/delete_file_column.rb", "mock_model.rb"] + require File.expand_path(File.join(File.dirname(__FILE__), file)) +end + + + +def dbg + require 'ruby-debug' + Debugger.start + debugger +end diff --git a/lib/active_scaffold/bridges/paperclip/bridge.rb b/lib/active_scaffold/bridges/paperclip/bridge.rb new file mode 100644 index 0000000000..8c7e209064 --- /dev/null +++ b/lib/active_scaffold/bridges/paperclip/bridge.rb @@ -0,0 +1,10 @@ +ActiveScaffold::Bridges.bridge "Paperclip" do + install do + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip") + raise RuntimeError, "We've detected that you have active_scaffold_paperclip_bridge installed. This plugin has been moved to core. Please remove active_scaffold_paperclip_bridge to prevent any conflicts" + end + require File.join(File.dirname(__FILE__), "lib/form_ui") + require File.join(File.dirname(__FILE__), "lib/list_ui") + ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Paperclip::Lib::PaperclipBridge + end +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb b/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb new file mode 100644 index 0000000000..025f1b694b --- /dev/null +++ b/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb @@ -0,0 +1,20 @@ +module ActiveScaffold + module Helpers + module FormColumnHelpers + def active_scaffold_input_paperclip(column, options) + input = file_field(:record, column.name, options) + paperclip = @record.send("#{column.name}") + if paperclip.file? + content = active_scaffold_column_paperclip(column, @record) + content_tag(:div, + content + " | " + + link_to_function(as_(:remove_file), "$(this).next().value='true'; $(this).up().hide().next().show()") + + hidden_field(:record, "delete_#{column.name}", :value => "false") + ) + content_tag(:div, input, :style => "display: none") + else + input + end + end + end + end +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb b/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb new file mode 100644 index 0000000000..aa71b79847 --- /dev/null +++ b/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb @@ -0,0 +1,16 @@ +module ActiveScaffold + module Helpers + module ListColumnHelpers + def active_scaffold_column_paperclip(column, record) + paperclip = record.send("#{column.name}") + return nil unless paperclip.file? + content = if paperclip.styles.include?(ActiveScaffold::Bridges::Paperclip::Lib::PaperclipBridgeHelpers.thumbnail_style) + image_tag(paperclip.url(ActiveScaffold::Bridges::Paperclip::Lib::PaperclipBridgeHelpers.thumbnail_style), :border => 0) + else + paperclip.original_filename + end + link_to(content, paperclip.url, :popup => true) + end + end + end +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb b/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb new file mode 100644 index 0000000000..606c4a3bfa --- /dev/null +++ b/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb @@ -0,0 +1,39 @@ +module ActiveScaffold + module Bridges + module Paperclip + module Lib + module PaperclipBridge + def initialize_with_paperclip(model_id) + initialize_without_paperclip(model_id) + return unless self.model.respond_to?(:attachment_definitions) && !self.model.attachment_definitions.nil? + + self.update.multipart = true + self.create.multipart = true + + self.model.attachment_definitions.keys.each do |field| + configure_paperclip_field(field.to_sym) + # define the "delete" helper for use with active scaffold, unless it's already defined + ActiveScaffold::Bridges::Paperclip::Lib::PaperclipBridgeHelpers.generate_delete_helper(self.model, field) + end + end + + def self.included(base) + base.alias_method_chain :initialize, :paperclip + end + + private + def configure_paperclip_field(field) + Rails.logger.info("configure paperclip field: #{field}") + self.columns << field + self.columns[field].form_ui ||= :paperclip + self.columns[field].params.add "delete_#{field}" + + [:file_name, :content_type, :file_size, :updated_at].each do |f| + self.columns.exclude("#{field}_#{f}".to_sym) + end + end + end + end + end + end +end diff --git a/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb b/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb new file mode 100644 index 0000000000..359a79544a --- /dev/null +++ b/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb @@ -0,0 +1,26 @@ +module ActiveScaffold + module Bridges + module Paperclip + module Lib + module PaperclipBridgeHelpers + mattr_accessor :thumbnail_style + self.thumbnail_style = :thumbnail + + def self.generate_delete_helper(klass, field) + klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("delete_#{field}=") + attr_reader :delete_#{field} + + def delete_#{field}=(value) + value = (value == "true") if String === value + return unless value + + # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! + self.#{field} = nil unless self.#{field}.dirty? + end + EOF + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/semantic_attributes/bridge.rb b/lib/active_scaffold/bridges/semantic_attributes/bridge.rb new file mode 100644 index 0000000000..7c51235f1b --- /dev/null +++ b/lib/active_scaffold/bridges/semantic_attributes/bridge.rb @@ -0,0 +1,5 @@ +ActiveScaffold::Bridges.bridge "SemanticAttributes" do + install do + require File.join(File.dirname(__FILE__), "lib/semantic_attributes_bridge.rb") + end +end diff --git a/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb b/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb new file mode 100644 index 0000000000..b953e038b8 --- /dev/null +++ b/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb @@ -0,0 +1,20 @@ +module ActiveScaffold + module SemanticAttributesBridge + def self.included(base) + base.class_eval { alias_method_chain :initialize, :semantic_attributes } + end + + def initialize_with_semantic_attributes(name, active_record_class) + initialize_without_semantic_attributes(name, active_record_class) + self.required = !active_record_class.semantic_attributes[self.name].predicates.find {|p| p.allow_empty? == false }.nil? + active_record_class.semantic_attributes[self.name].predicates.find do |p| + sem_type = p.class.to_s.split('::')[1].underscore.to_sym + next if [:required, :association].include?(sem_type) + @form_ui = sem_type + end + end + end +end +ActiveScaffold::DataStructures::Column.class_eval do + include ActiveScaffold::SemanticAttributesBridge +end diff --git a/lib/active_scaffold/bridges/tiny_mce/bridge.rb b/lib/active_scaffold/bridges/tiny_mce/bridge.rb new file mode 100644 index 0000000000..dd4abcaa01 --- /dev/null +++ b/lib/active_scaffold/bridges/tiny_mce/bridge.rb @@ -0,0 +1,5 @@ +ActiveScaffold::Bridges.bridge "TinyMCE" do + install do + require File.join(File.dirname(__FILE__), "lib/tiny_mce_bridge.rb") + end +end diff --git a/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb b/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb new file mode 100644 index 0000000000..49faf316e5 --- /dev/null +++ b/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb @@ -0,0 +1,45 @@ +module ActiveScaffold + module TinyMceBridge + module ViewHelpers + def active_scaffold_includes(*args) + tiny_mce_js = javascript_tag(%| +var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; +ActiveScaffold.ActionLink.Abstract.prototype.close = function() { + this.adapter.select('textarea.mceEditor').each(function(elem) { + tinyMCE.execCommand('mceRemoveControl', false, elem.id); + }); + action_link_close.apply(this); +}; + |) if using_tiny_mce? + super(*args) + (include_tiny_mce_if_needed || '') + (tiny_mce_js || '') + end + end + + module FormColumnHelpers + def active_scaffold_input_text_editor(column, options) + options[:class] = "#{options[:class]} mceEditor #{column.options[:class]}".strip + html = [] + html << send(override_input(:textarea), column, options) + html << javascript_tag("tinyMCE.execCommand('mceAddControl', false, '#{options[:id]}');") if request.xhr? + html.join "\n" + end + + def onsubmit + submit_js = 'tinyMCE.triggerSave();this.select("textarea.mceEditor").each(function(elem) { tinyMCE.execCommand("mceRemoveControl", false, elem.id); });' if using_tiny_mce? + [super, submit_js].compact.join ';' + end + end + + module SearchColumnHelpers + def self.included(base) + base.class_eval { alias_method :active_scaffold_search_text_editor, :active_scaffold_search_text } + end + end + end +end + +ActionView::Base.class_eval do + include ActiveScaffold::TinyMceBridge::FormColumnHelpers + include ActiveScaffold::TinyMceBridge::SearchColumnHelpers + include ActiveScaffold::TinyMceBridge::ViewHelpers +end diff --git a/lib/active_scaffold/bridges/validation_reflection/bridge.rb b/lib/active_scaffold/bridges/validation_reflection/bridge.rb new file mode 100644 index 0000000000..2abe2e932d --- /dev/null +++ b/lib/active_scaffold/bridges/validation_reflection/bridge.rb @@ -0,0 +1,8 @@ +ActiveScaffold::Bridges.bridge "ValidationReflection" do + install do + require File.join(File.dirname(__FILE__), "lib/validation_reflection_bridge.rb") + end + install? do + ActiveRecord::Base.respond_to? :reflect_on_validations_for + end +end diff --git a/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb b/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb new file mode 100644 index 0000000000..777ddcdb38 --- /dev/null +++ b/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb @@ -0,0 +1,21 @@ +module ActiveScaffold + module ValidationReflectionBridge + def self.included(base) + base.class_eval { alias_method_chain :initialize, :validation_reflection } + end + + def initialize_with_validation_reflection(name, active_record_class) + initialize_without_validation_reflection(name, active_record_class) + column_names = [name] + column_names << @association.primary_key_name if @association + self.required = column_names.any? do |column_name| + active_record_class.reflect_on_validations_for(column_name.to_sym).any? do |val| + val.macro == :validates_presence_of or (val.macro == :validates_inclusion_of and not val.options[:allow_nil] and not val.options[:allow_blank]) + end + end + end + end +end +ActiveScaffold::DataStructures::Column.class_eval do + include ActiveScaffold::ValidationReflectionBridge +end From 6bb2656194cba6ee3405a3ccd46da0e5cec1a8cb Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 2 Aug 2010 13:48:53 +0200 Subject: [PATCH 0535/2024] remove bridge files (were added to another dir to enable autoloading) --- lib/active_scaffold.rb | 2 +- lib/bridges/bridge.rb | 52 ----------- lib/bridges/calendar_date_select/bridge.rb | 11 --- .../calendar_date_select/lib/as_cds_bridge.rb | 87 ------------------- lib/bridges/file_column/bridge.rb | 12 --- .../file_column/lib/as_file_column_bridge.rb | 46 ---------- .../file_column/lib/file_column_helpers.rb | 51 ----------- lib/bridges/file_column/lib/form_ui.rb | 32 ------- lib/bridges/file_column/lib/list_ui.rb | 26 ------ .../test/functional/file_column_keep_test.rb | 43 --------- lib/bridges/file_column/test/mock_model.rb | 9 -- lib/bridges/file_column/test/test_helper.rb | 15 ---- lib/bridges/paperclip/bridge.rb | 13 --- lib/bridges/paperclip/lib/form_ui.rb | 20 ----- lib/bridges/paperclip/lib/list_ui.rb | 16 ---- lib/bridges/paperclip/lib/paperclip_bridge.rb | 32 ------- .../paperclip/lib/paperclip_bridge_helpers.rb | 18 ---- lib/bridges/semantic_attributes/bridge.rb | 5 -- .../lib/semantic_attributes_bridge.rb | 20 ----- lib/bridges/tiny_mce/bridge.rb | 5 -- lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb | 45 ---------- lib/bridges/validation_reflection/bridge.rb | 8 -- .../lib/validation_reflection_bridge.rb | 21 ----- 23 files changed, 1 insertion(+), 588 deletions(-) delete mode 100644 lib/bridges/bridge.rb delete mode 100644 lib/bridges/calendar_date_select/bridge.rb delete mode 100644 lib/bridges/calendar_date_select/lib/as_cds_bridge.rb delete mode 100644 lib/bridges/file_column/bridge.rb delete mode 100644 lib/bridges/file_column/lib/as_file_column_bridge.rb delete mode 100644 lib/bridges/file_column/lib/file_column_helpers.rb delete mode 100644 lib/bridges/file_column/lib/form_ui.rb delete mode 100644 lib/bridges/file_column/lib/list_ui.rb delete mode 100644 lib/bridges/file_column/test/functional/file_column_keep_test.rb delete mode 100644 lib/bridges/file_column/test/mock_model.rb delete mode 100644 lib/bridges/file_column/test/test_helper.rb delete mode 100644 lib/bridges/paperclip/bridge.rb delete mode 100644 lib/bridges/paperclip/lib/form_ui.rb delete mode 100644 lib/bridges/paperclip/lib/list_ui.rb delete mode 100644 lib/bridges/paperclip/lib/paperclip_bridge.rb delete mode 100644 lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb delete mode 100644 lib/bridges/semantic_attributes/bridge.rb delete mode 100644 lib/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb delete mode 100644 lib/bridges/tiny_mce/bridge.rb delete mode 100644 lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb delete mode 100644 lib/bridges/validation_reflection/bridge.rb delete mode 100644 lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 4b56706393..7f3f74d76b 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -56,7 +56,7 @@ def self.js_framework module ClassMethods def active_scaffold(model_id = nil, &block) # initialize bridges here - ActiveScaffold::Bridge.run_all + ActiveScaffold::Bridges::Bridge.run_all # converts Foo::BarController to 'bar' and FooBarsController to 'foo_bar' and AddressController to 'address' model_id = self.to_s.split('::').last.sub(/Controller$/, '').pluralize.singularize.underscore unless model_id diff --git a/lib/bridges/bridge.rb b/lib/bridges/bridge.rb deleted file mode 100644 index 794177f4a0..0000000000 --- a/lib/bridges/bridge.rb +++ /dev/null @@ -1,52 +0,0 @@ -module ActiveScaffold - def self.bridge(name, &block) - ActiveScaffold::Bridge.new(name, &block) - end - - class Bridge - attr_accessor :name - cattr_accessor :bridges - cattr_accessor :bridges_run - self.bridges = [] - - def initialize(name, &block) - self.name = name - @install = nil - # by convention and default, use the bridge name as the required constant for installation - @install_if = lambda { Object.const_defined?(name) } - self.instance_eval(&block) - - ActiveScaffold::Bridge.bridges << self - end - - # Set the install block - def install(&block) - @install = block - end - - # Set the install_if block (to check to see whether or not to install the block) - def install?(&block) - @install_if = block - end - - - def run - raise(ArgumentError, "install and install? not defined for bridge #{name}" ) unless @install && @install_if - @install.call if @install_if.call - end - - def self.run_all - return false if self.bridges_run - ActiveScaffold::Bridge.bridges.each{|bridge| - bridge.run - } - - - self.bridges_run=true - end - end -end - -Dir[File.join(File.dirname(__FILE__), "*/bridge.rb")].each{|bridge_require| - require bridge_require -} \ No newline at end of file diff --git a/lib/bridges/calendar_date_select/bridge.rb b/lib/bridges/calendar_date_select/bridge.rb deleted file mode 100644 index 1ca1b41a2b..0000000000 --- a/lib/bridges/calendar_date_select/bridge.rb +++ /dev/null @@ -1,11 +0,0 @@ -ActiveScaffold.bridge "CalendarDateSelect" do - install do - # check to see if the old bridge was installed. If so, warn them - # we can detect this by checking to see if the bridge was installed before calling this code - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_calendar_date_select") - raise RuntimeError, "We've detected that you have active_scaffold_calendar_date_select_bridge installed. This plugin has been moved to core. Please remove active_scaffold_calendar_date_select_bridge to prevent any conflicts" - end - - require File.join(File.dirname(__FILE__), "lib/as_cds_bridge.rb") - end -end diff --git a/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb deleted file mode 100644 index 461f5f6547..0000000000 --- a/lib/bridges/calendar_date_select/lib/as_cds_bridge.rb +++ /dev/null @@ -1,87 +0,0 @@ -module ActiveScaffold::Config - class Core < Base - - def initialize_with_calendar_date_select(model_id) - initialize_without_calendar_date_select(model_id) - - calendar_date_select_fields = self.model.columns.collect{|c| c.name.to_sym if [:date, :datetime].include?(c.type) }.compact - # check to see if file column was used on the model - return if calendar_date_select_fields.empty? - - # automatically set the forum_ui to a file column - calendar_date_select_fields.each{|field| - self.columns[field].form_ui = :calendar_date_select - } - end - - alias_method_chain :initialize, :calendar_date_select - - end -end - - -module ActiveScaffold - module CalendarDateSelectBridge - # Helpers that assist with the rendering of a Form Column - module FormColumnHelpers - def active_scaffold_input_calendar_date_select(column, options) - options[:class] = "#{options[:class]} text-input".strip - calendar_date_select("record", column.name, options.merge(column.options)) - end - end - - module SearchColumnHelpers - def active_scaffold_search_calendar_date_select(column, options) - opt_value, from_value, to_value = field_search_params_range_values(column) - options = column.options.merge(options).except!(:include_blank) - helper = "select_#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}" - html = [] - html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[from]", :id => "#{options[:id]}_from", :value => from_value)) - html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[to]", :id => "#{options[:id]}_to", :value => to_value)) - html * ' - ' - end - end - - module ViewHelpers - # Provides stylesheets to include with +stylesheet_link_tag+ - def active_scaffold_stylesheets(frontend = :default) - super + [calendar_date_select_stylesheets] - end - - # Provides stylesheets to include with +stylesheet_link_tag+ - def active_scaffold_javascripts(frontend = :default) - super + [calendar_date_select_javascripts] - end - end - - module Finder - module ClassMethods - def condition_for_calendar_date_select_type(column, value, like_pattern) - conversion = column.column.type == :date ? 'to_date' : 'to_time' - from_value, to_value = ['from', 'to'].collect do |field| - Time.zone.parse(value[field]) rescue nil - end - - if from_value.nil? and to_value.nil? - nil - elsif !from_value - ["#{column.search_sql} <= ?", to_value.send(conversion).to_s(:db)] - elsif !to_value - ["#{column.search_sql} >= ?", from_value.send(conversion).to_s(:db)] - else - ["#{column.search_sql} BETWEEN ? AND ?", from_value.send(conversion).to_s(:db), to_value.send(conversion).to_s(:db)] - end - end - end - end - end -end - -ActionView::Base.class_eval do - include ActiveScaffold::CalendarDateSelectBridge::FormColumnHelpers - include ActiveScaffold::CalendarDateSelectBridge::SearchColumnHelpers - include ActiveScaffold::CalendarDateSelectBridge::ViewHelpers -end -ActiveScaffold::Finder::ClassMethods.module_eval do - include ActiveScaffold::CalendarDateSelectBridge::Finder::ClassMethods -end diff --git a/lib/bridges/file_column/bridge.rb b/lib/bridges/file_column/bridge.rb deleted file mode 100644 index 94b2329375..0000000000 --- a/lib/bridges/file_column/bridge.rb +++ /dev/null @@ -1,12 +0,0 @@ -ActiveScaffold.bridge "FileColumn" do - install do - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_file_column") - raise RuntimeError, "We've detected that you have active_scaffold_file_column_bridge installed. This plugin has been moved to core. Please remove active_scaffold_file_column_bridge to prevent any conflicts" - end - - require File.join(File.dirname(__FILE__), "lib/as_file_column_bridge") - require File.join(File.dirname(__FILE__), "lib/form_ui") - require File.join(File.dirname(__FILE__), "lib/list_ui") - require File.join(File.dirname(__FILE__), "lib/file_column_helpers") - end -end diff --git a/lib/bridges/file_column/lib/as_file_column_bridge.rb b/lib/bridges/file_column/lib/as_file_column_bridge.rb deleted file mode 100644 index 6f9cfb1813..0000000000 --- a/lib/bridges/file_column/lib/as_file_column_bridge.rb +++ /dev/null @@ -1,46 +0,0 @@ -ActiveScaffold::DataStructures::Column.class_eval do - attr_accessor :file_column_display -end - -module ActiveScaffold::Config - class Core < Base - attr_accessor :file_column_fields - def initialize_with_file_column(model_id) - initialize_without_file_column(model_id) - - return unless FileColumnHelpers.klass_has_file_column_fields?(self.model) - - self.model.send :extend, FileColumnHelpers - - # include the "delete" helpers for use with active scaffold, unless they are already included - self.model.generate_delete_helpers - - # switch on multipart - self.update.multipart = true - self.create.multipart = true - - self.model.file_column_fields.each{ |field| - configure_file_column_field(field) - } - end - - alias_method_chain :initialize, :file_column unless self.instance_methods.include?("initialize_without_file_column") - - def configure_file_column_field(field) - # set list_ui first because it gets its default value from form_ui - self.columns[field].list_ui ||= self.model.field_has_image_version?(field, "thumb") ? :thumbnail : :download_link_with_filename - self.columns[field].form_ui ||= :file_column - - # these 2 parameters are necessary helper attributes for the file column that must be allowed to be set to the model by active scaffold. - self.columns[field].params.add "#{field}_temp", "delete_#{field}" - - # set null to false so active_scaffold wont set it to null - # delete_file_column will take care of deleting a file or not. - self.model.columns_hash[field.to_s].instance_variable_set("@null", false) - - rescue - false - end - - end -end diff --git a/lib/bridges/file_column/lib/file_column_helpers.rb b/lib/bridges/file_column/lib/file_column_helpers.rb deleted file mode 100644 index 9c60f1c618..0000000000 --- a/lib/bridges/file_column/lib/file_column_helpers.rb +++ /dev/null @@ -1,51 +0,0 @@ -module FileColumnHelpers - class << self - def file_column_fields(klass) - klass.instance_methods.grep(/_just_uploaded\?$/).collect{|m| m[0..-16].to_sym } - end - - def generate_delete_helpers(klass) - file_column_fields(klass).each { |field| - klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("#{field}_with_delete=") - attr_reader :delete_#{field} - - def delete_#{field}=(value) - value = (value=="true") if String===value - return unless value - - # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! - self.#{field} = nil unless self.#{field}_just_uploaded? - end - EOF - } - end - - def klass_has_file_column_fields?(klass) - true unless file_column_fields(klass).empty? - end - end - - def file_column_fields - @file_column_fields||=FileColumnHelpers.file_column_fields(self) - end - - def options_for_file_column_field(field) - self.allocate.send("#{field}_options") - end - - def field_has_image_version?(field, version="thumb") - begin - # the only way to get to the options of a particular field is to use the instance method - options = options_for_file_column_field(field) - versions = options[:magick][:versions] - raise unless versions.stringify_keys[version] - true - rescue - false - end - end - - def generate_delete_helpers - FileColumnHelpers.generate_delete_helpers(self) - end -end \ No newline at end of file diff --git a/lib/bridges/file_column/lib/form_ui.rb b/lib/bridges/file_column/lib/form_ui.rb deleted file mode 100644 index b169d8e045..0000000000 --- a/lib/bridges/file_column/lib/form_ui.rb +++ /dev/null @@ -1,32 +0,0 @@ -module ActiveScaffold - module Helpers - # Helpers that assist with the rendering of a Form Column - module FormColumnHelpers - def active_scaffold_input_file_column(column, options) - if @record.send(column.name) - # we already have a value? display the form for deletion. - content_tag( - :div, - content_tag( - :div, - get_column_value(@record, column) + " " + - hidden_field(:record, "delete_#{column.name}", :value => "false") + - " | " + - link_to_function(as_(:remove_file), "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show();"), - {} - ) + - content_tag( - :div, - file_column_field("record", column.name, options), - :style => "display: none" - ), - {} - ) - else - # no, just display the file_column_field - file_column_field("record", column.name, options) - end - end - end - end -end \ No newline at end of file diff --git a/lib/bridges/file_column/lib/list_ui.rb b/lib/bridges/file_column/lib/list_ui.rb deleted file mode 100644 index edb7199319..0000000000 --- a/lib/bridges/file_column/lib/list_ui.rb +++ /dev/null @@ -1,26 +0,0 @@ -module ActiveScaffold - module Helpers - # Helpers that assist with the rendering of a List Column - module ListColumnHelpers - def active_scaffold_column_download_link_with_filename(column, record) - return nil if record.send(column.name).nil? - active_scaffold_column_download_link(column, record, File.basename(record.send(column.name))) - end - - def active_scaffold_column_download_link(column, record, label = nil) - return nil if record.send(column.name).nil? - label||=as_(:download) - link_to( label, url_for_file_column(record, column.name.to_s), :popup => true) - end - - def active_scaffold_column_thumbnail(column, record) - return nil if record.send(column.name).nil? - link_to( - image_tag(url_for_file_column(record, column.name.to_s, "thumb"), :border => 0), - url_for_file_column(record, column.name.to_s), - :popup => true) - end - - end - end -end diff --git a/lib/bridges/file_column/test/functional/file_column_keep_test.rb b/lib/bridges/file_column/test/functional/file_column_keep_test.rb deleted file mode 100644 index fa2aeec001..0000000000 --- a/lib/bridges/file_column/test/functional/file_column_keep_test.rb +++ /dev/null @@ -1,43 +0,0 @@ -require File.join(File.dirname(__FILE__), "../test_helper.rb") - -class DeleteFileColumnTest < Test::Unit::TestCase - def setup - DeleteFileColumn.generate_delete_helpers(MockModel) - @model = MockModel.new - @model.band_image = "coolio.jpg" - end - - def test__file_column_fields - assert_equal(1, @model.file_column_fields.length) - end - - def test__delete_band_image__boolean__should_delete - @model.delete_band_image = true - assert_nil @model.band_image - end - - def test__delete_band_image__string__should_delete - @model.delete_band_image = "true" - assert_nil @model.band_image - end - - - def test__delete_band_image__boolean_false__shouldnt_delete - @model.delete_band_image = false - assert_not_nil @model.band_image - end - - def test__delete_band_image__string_false__shouldnt_delete - @model.delete_band_image = "false" - assert_not_nil @model.band_image - end - - - def test__just_uploaded__shouldnt_delete - @model.band_image_just_uploaded = true - @model.delete_band_image = "true" - assert_not_nil(@model.band_image) - end - - -end \ No newline at end of file diff --git a/lib/bridges/file_column/test/mock_model.rb b/lib/bridges/file_column/test/mock_model.rb deleted file mode 100644 index 90fa827f16..0000000000 --- a/lib/bridges/file_column/test/mock_model.rb +++ /dev/null @@ -1,9 +0,0 @@ -class MockModel - attr_accessor :name - attr_accessor :bio - - attr_accessor :band_image - attr_accessor :band_image_just_uploaded - def band_image_just_uploaded?; self.band_image_just_uploaded ? true : false; end - -end \ No newline at end of file diff --git a/lib/bridges/file_column/test/test_helper.rb b/lib/bridges/file_column/test/test_helper.rb deleted file mode 100644 index 8d9457774b..0000000000 --- a/lib/bridges/file_column/test/test_helper.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'test/unit' -require "rubygems" -require 'active_support' - -for file in ["../lib/delete_file_column.rb", "mock_model.rb"] - require File.expand_path(File.join(File.dirname(__FILE__), file)) -end - - - -def dbg - require 'ruby-debug' - Debugger.start - debugger -end diff --git a/lib/bridges/paperclip/bridge.rb b/lib/bridges/paperclip/bridge.rb deleted file mode 100644 index bdf507be7f..0000000000 --- a/lib/bridges/paperclip/bridge.rb +++ /dev/null @@ -1,13 +0,0 @@ -require File.join(File.dirname(__FILE__), "lib/paperclip_bridge_helpers") -ActiveScaffold.bridge "Paperclip" do - install do - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip") - raise RuntimeError, "We've detected that you have active_scaffold_paperclip_bridge installed. This plugin has been moved to core. Please remove active_scaffold_paperclip_bridge to prevent any conflicts" - end - - require File.join(File.dirname(__FILE__), "lib/paperclip_bridge") - require File.join(File.dirname(__FILE__), "lib/form_ui") - require File.join(File.dirname(__FILE__), "lib/list_ui") - ActiveScaffold::Config::Core.send :include, ActiveScaffold::PaperclipBridge - end -end \ No newline at end of file diff --git a/lib/bridges/paperclip/lib/form_ui.rb b/lib/bridges/paperclip/lib/form_ui.rb deleted file mode 100644 index 025f1b694b..0000000000 --- a/lib/bridges/paperclip/lib/form_ui.rb +++ /dev/null @@ -1,20 +0,0 @@ -module ActiveScaffold - module Helpers - module FormColumnHelpers - def active_scaffold_input_paperclip(column, options) - input = file_field(:record, column.name, options) - paperclip = @record.send("#{column.name}") - if paperclip.file? - content = active_scaffold_column_paperclip(column, @record) - content_tag(:div, - content + " | " + - link_to_function(as_(:remove_file), "$(this).next().value='true'; $(this).up().hide().next().show()") + - hidden_field(:record, "delete_#{column.name}", :value => "false") - ) + content_tag(:div, input, :style => "display: none") - else - input - end - end - end - end -end \ No newline at end of file diff --git a/lib/bridges/paperclip/lib/list_ui.rb b/lib/bridges/paperclip/lib/list_ui.rb deleted file mode 100644 index c06a351b53..0000000000 --- a/lib/bridges/paperclip/lib/list_ui.rb +++ /dev/null @@ -1,16 +0,0 @@ -module ActiveScaffold - module Helpers - module ListColumnHelpers - def active_scaffold_column_paperclip(column, record) - paperclip = record.send("#{column.name}") - return nil unless paperclip.file? - content = if paperclip.styles.include?(PaperclipBridgeHelpers.thumbnail_style) - image_tag(paperclip.url(PaperclipBridgeHelpers.thumbnail_style), :border => 0) - else - paperclip.original_filename - end - link_to(content, paperclip.url, :popup => true) - end - end - end -end \ No newline at end of file diff --git a/lib/bridges/paperclip/lib/paperclip_bridge.rb b/lib/bridges/paperclip/lib/paperclip_bridge.rb deleted file mode 100644 index c01ce3473f..0000000000 --- a/lib/bridges/paperclip/lib/paperclip_bridge.rb +++ /dev/null @@ -1,32 +0,0 @@ -module ActiveScaffold - module PaperclipBridge - def initialize_with_paperclip(model_id) - initialize_without_paperclip(model_id) - return unless self.model.respond_to?(:attachment_definitions) && !self.model.attachment_definitions.nil? - - self.update.multipart = true - self.create.multipart = true - - self.model.attachment_definitions.keys.each do |field| - configure_paperclip_field(field.to_sym) - # define the "delete" helper for use with active scaffold, unless it's already defined - PaperclipBridgeHelpers.generate_delete_helper(self.model, field) - end - end - - def self.included(base) - base.alias_method_chain :initialize, :paperclip - end - - private - def configure_paperclip_field(field) - self.columns << field - self.columns[field].form_ui ||= :paperclip - self.columns[field].params.add "delete_#{field}" - - [:file_name, :content_type, :file_size, :updated_at].each do |f| - self.columns.exclude("#{field}_#{f}".to_sym) - end - end - end -end diff --git a/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb b/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb deleted file mode 100644 index 3dcb49dd3d..0000000000 --- a/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb +++ /dev/null @@ -1,18 +0,0 @@ -module PaperclipBridgeHelpers - mattr_accessor :thumbnail_style - self.thumbnail_style = :thumbnail - - def self.generate_delete_helper(klass, field) - klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("delete_#{field}=") - attr_reader :delete_#{field} - - def delete_#{field}=(value) - value = (value == "true") if String === value - return unless value - - # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! - self.#{field} = nil unless self.#{field}.dirty? - end - EOF - end -end \ No newline at end of file diff --git a/lib/bridges/semantic_attributes/bridge.rb b/lib/bridges/semantic_attributes/bridge.rb deleted file mode 100644 index d676018d45..0000000000 --- a/lib/bridges/semantic_attributes/bridge.rb +++ /dev/null @@ -1,5 +0,0 @@ -ActiveScaffold.bridge "SemanticAttributes" do - install do - require File.join(File.dirname(__FILE__), "lib/semantic_attributes_bridge.rb") - end -end diff --git a/lib/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb b/lib/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb deleted file mode 100644 index b953e038b8..0000000000 --- a/lib/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +++ /dev/null @@ -1,20 +0,0 @@ -module ActiveScaffold - module SemanticAttributesBridge - def self.included(base) - base.class_eval { alias_method_chain :initialize, :semantic_attributes } - end - - def initialize_with_semantic_attributes(name, active_record_class) - initialize_without_semantic_attributes(name, active_record_class) - self.required = !active_record_class.semantic_attributes[self.name].predicates.find {|p| p.allow_empty? == false }.nil? - active_record_class.semantic_attributes[self.name].predicates.find do |p| - sem_type = p.class.to_s.split('::')[1].underscore.to_sym - next if [:required, :association].include?(sem_type) - @form_ui = sem_type - end - end - end -end -ActiveScaffold::DataStructures::Column.class_eval do - include ActiveScaffold::SemanticAttributesBridge -end diff --git a/lib/bridges/tiny_mce/bridge.rb b/lib/bridges/tiny_mce/bridge.rb deleted file mode 100644 index 09b8805dc3..0000000000 --- a/lib/bridges/tiny_mce/bridge.rb +++ /dev/null @@ -1,5 +0,0 @@ -ActiveScaffold.bridge "TinyMCE" do - install do - require File.join(File.dirname(__FILE__), "lib/tiny_mce_bridge.rb") - end -end diff --git a/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb b/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb deleted file mode 100644 index 49faf316e5..0000000000 --- a/lib/bridges/tiny_mce/lib/tiny_mce_bridge.rb +++ /dev/null @@ -1,45 +0,0 @@ -module ActiveScaffold - module TinyMceBridge - module ViewHelpers - def active_scaffold_includes(*args) - tiny_mce_js = javascript_tag(%| -var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; -ActiveScaffold.ActionLink.Abstract.prototype.close = function() { - this.adapter.select('textarea.mceEditor').each(function(elem) { - tinyMCE.execCommand('mceRemoveControl', false, elem.id); - }); - action_link_close.apply(this); -}; - |) if using_tiny_mce? - super(*args) + (include_tiny_mce_if_needed || '') + (tiny_mce_js || '') - end - end - - module FormColumnHelpers - def active_scaffold_input_text_editor(column, options) - options[:class] = "#{options[:class]} mceEditor #{column.options[:class]}".strip - html = [] - html << send(override_input(:textarea), column, options) - html << javascript_tag("tinyMCE.execCommand('mceAddControl', false, '#{options[:id]}');") if request.xhr? - html.join "\n" - end - - def onsubmit - submit_js = 'tinyMCE.triggerSave();this.select("textarea.mceEditor").each(function(elem) { tinyMCE.execCommand("mceRemoveControl", false, elem.id); });' if using_tiny_mce? - [super, submit_js].compact.join ';' - end - end - - module SearchColumnHelpers - def self.included(base) - base.class_eval { alias_method :active_scaffold_search_text_editor, :active_scaffold_search_text } - end - end - end -end - -ActionView::Base.class_eval do - include ActiveScaffold::TinyMceBridge::FormColumnHelpers - include ActiveScaffold::TinyMceBridge::SearchColumnHelpers - include ActiveScaffold::TinyMceBridge::ViewHelpers -end diff --git a/lib/bridges/validation_reflection/bridge.rb b/lib/bridges/validation_reflection/bridge.rb deleted file mode 100644 index d563aca51a..0000000000 --- a/lib/bridges/validation_reflection/bridge.rb +++ /dev/null @@ -1,8 +0,0 @@ -ActiveScaffold.bridge "ValidationReflection" do - install do - require File.join(File.dirname(__FILE__), "lib/validation_reflection_bridge.rb") - end - install? do - ActiveRecord::Base.respond_to? :reflect_on_validations_for - end -end diff --git a/lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb b/lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb deleted file mode 100644 index 777ddcdb38..0000000000 --- a/lib/bridges/validation_reflection/lib/validation_reflection_bridge.rb +++ /dev/null @@ -1,21 +0,0 @@ -module ActiveScaffold - module ValidationReflectionBridge - def self.included(base) - base.class_eval { alias_method_chain :initialize, :validation_reflection } - end - - def initialize_with_validation_reflection(name, active_record_class) - initialize_without_validation_reflection(name, active_record_class) - column_names = [name] - column_names << @association.primary_key_name if @association - self.required = column_names.any? do |column_name| - active_record_class.reflect_on_validations_for(column_name.to_sym).any? do |val| - val.macro == :validates_presence_of or (val.macro == :validates_inclusion_of and not val.options[:allow_nil] and not val.options[:allow_blank]) - end - end - end - end -end -ActiveScaffold::DataStructures::Column.class_eval do - include ActiveScaffold::ValidationReflectionBridge -end From 0ace6d4e805b259a3d11c677404c29ec2f992c32 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 2 Aug 2010 13:50:52 +0200 Subject: [PATCH 0536/2024] no need to explicitly require master bridge file --- environment.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/environment.rb b/environment.rb index 0979088009..1a85eede0a 100644 --- a/environment.rb +++ b/environment.rb @@ -12,7 +12,5 @@ ActiveRecord::Base.class_eval {include ActiveRecordPermissions::ModelUserAccess::Model} ActiveRecord::Base.class_eval {include ActiveRecordPermissions::Permissions} -require 'bridges/bridge.rb' - I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'lib', 'active_scaffold', 'locale', '*.{rb,yml}')] #ActiveScaffold.js_framework = :jquery From 54fb281db9e62240264b6785dff3f3bda5d988aa Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 2 Aug 2010 13:51:25 +0200 Subject: [PATCH 0537/2024] jquery: file column remove function --- lib/active_scaffold/bridges/file_column/lib/form_ui.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/file_column/lib/form_ui.rb b/lib/active_scaffold/bridges/file_column/lib/form_ui.rb index b169d8e045..973f4949cd 100644 --- a/lib/active_scaffold/bridges/file_column/lib/form_ui.rb +++ b/lib/active_scaffold/bridges/file_column/lib/form_ui.rb @@ -5,6 +5,11 @@ module FormColumnHelpers def active_scaffold_input_file_column(column, options) if @record.send(column.name) # we already have a value? display the form for deletion. + if ActiveScaffold.js_framework == :jquery + js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show();"; + else + js_remove_file_code = "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show();"; + end content_tag( :div, content_tag( @@ -12,7 +17,7 @@ def active_scaffold_input_file_column(column, options) get_column_value(@record, column) + " " + hidden_field(:record, "delete_#{column.name}", :value => "false") + " | " + - link_to_function(as_(:remove_file), "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show();"), + link_to_function(as_(:remove_file), js_remove_file_code ), {} ) + content_tag( From b42a2a52e745da45ff66a6f5f7f65504dd3db161 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 3 Aug 2010 10:23:39 +0200 Subject: [PATCH 0538/2024] remove logger statement --- lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb b/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb index 606c4a3bfa..daf98a33f7 100644 --- a/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +++ b/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb @@ -23,7 +23,6 @@ def self.included(base) private def configure_paperclip_field(field) - Rails.logger.info("configure paperclip field: #{field}") self.columns << field self.columns[field].form_ui ||= :paperclip self.columns[field].params.add "delete_#{field}" From 3442027dab9354d2173535ce52fe4762de967781 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 3 Aug 2010 10:46:05 +0200 Subject: [PATCH 0539/2024] jquery: add highlight effect (only if jquery_ui effect highlight is available ) --- .../default/javascripts/jquery/active_scaffold.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index a7736df2d4..9882eb21d9 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -345,7 +345,7 @@ var ActiveScaffold = { replaced = this.replace(row, html); if (even_row === true) replaced.addClass('even-record'); - //new_row.highlight(); + ActiveScaffold.highlight(replaced); }, replace: function(element, html) { @@ -381,7 +381,7 @@ var ActiveScaffold = { this.stripe(tbody); this.hide_empty_message(tbody); this.increment_record_count(tbody.closest('div.active-scaffold')); - //new_row.highlight(); + ActiveScaffold.highlight(new_row); }, delete_record_row: function(row, page_reload_url) { @@ -450,6 +450,13 @@ var ActiveScaffold = { span.removeClass('hover'); span.editInPlace(options); span.trigger('click.editInPlace'); + }, + + highlight: function(element) { + if (typeof(element) == 'string') element = '#' + element; + if (typeof(element.effect) == 'function') { + element.effect("highlight", {}, 3000); + } } } @@ -644,6 +651,7 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ else { return false; } + ActiveScaffold.highlight(this.adapter.find('td')); }, close: function(refreshed_content) { @@ -693,6 +701,6 @@ ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({ else { throw 'Unknown position "' + this.position + '"' } - //this.adapter.find('td').first().children().highlight(); + ActiveScaffold.highlight(this.adapter.find('td').first().children()); } }); From e13a97e5b60311e776b470ce9ac3079dae9aba0a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 3 Aug 2010 16:10:40 +0200 Subject: [PATCH 0540/2024] Bugfix: only load calendar_date_select bridge if prototype is active --- lib/active_scaffold/bridges/calendar_date_select/bridge.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/active_scaffold/bridges/calendar_date_select/bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/bridge.rb index 3b0b53139e..de4946ae61 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/bridge.rb @@ -2,10 +2,15 @@ install do # check to see if the old bridge was installed. If so, warn them # we can detect this by checking to see if the bridge was installed before calling this code + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_calendar_date_select") raise RuntimeError, "We've detected that you have active_scaffold_calendar_date_select_bridge installed. This plugin has been moved to core. Please remove active_scaffold_calendar_date_select_bridge to prevent any conflicts" end require File.join(File.dirname(__FILE__), "lib/as_cds_bridge.rb") end + + install? do + Object.const_defined?(name) && ActiveScaffold.js_framework == :prototype + end end From 5e22abcb65d2b32a2e66ae302ac27a90b75dac15 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 4 Aug 2010 10:01:54 +0200 Subject: [PATCH 0541/2024] jquery: added a bridge to use jquery_ui DatePicker for date attributes and http://trentrichardson.com/examples/timepicker/ for dateTime attributes --- .../bridges/date_picker/bridge.rb | 19 ++++ .../date_picker/lib/datepicker_bridge.rb | 89 +++++++++++++++++++ .../public/javascripts/date_picker_bridge.js | 22 +++++ 3 files changed, 130 insertions(+) create mode 100644 lib/active_scaffold/bridges/date_picker/bridge.rb create mode 100644 lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb create mode 100644 lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js diff --git a/lib/active_scaffold/bridges/date_picker/bridge.rb b/lib/active_scaffold/bridges/date_picker/bridge.rb new file mode 100644 index 0000000000..f992a451f5 --- /dev/null +++ b/lib/active_scaffold/bridges/date_picker/bridge.rb @@ -0,0 +1,19 @@ +ActiveScaffold::Bridges.bridge "DatePicker" do + install do + directory = File.dirname(__FILE__) + source = File.join(directory, "public/javascripts/date_picker_bridge.js") + destination = File.join(Rails.root, "public/javascripts/active_scaffold/default/") + + if ActiveScaffold.js_framework == :jquery + require File.join(directory, "lib/datepicker_bridge.rb") + FileUtils.cp(source, destination) + else + # make sure that jquery files are removed + FileUtils.rm(File.join(destination, 'date_picker_bridge.js')) if File.exist?(File.join(destination, 'date_picker_bridge.js')) + end + end + + install? do + true + end +end diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb new file mode 100644 index 0000000000..73361258c4 --- /dev/null +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -0,0 +1,89 @@ +module ActiveScaffold::Config + class Core < Base + + def initialize_with_date_picker(model_id) + initialize_without_date_picker(model_id) + + date_picker_fields = self.model.columns.collect{|c| {:name => c.name.to_sym, :type => c.type} if [:date, :datetime].include?(c.type) }.compact + # check to see if file column was used on the model + return if date_picker_fields.empty? + + # automatically set the forum_ui to a file column + date_picker_fields.each{|field| + col_config = self.columns[field[:name]] + form_ui = (field[:type] == :date ? :date_picker : :datetime_picker) + + col_config.form_ui = form_ui + if col_config.options[:class] + col_config.options[:class] += " #{form_ui.to_s} text-input" + else + col_config.options[:class] = "#{form_ui.to_s} text-input" + end + } + end + + alias_method_chain :initialize, :date_picker + + end +end + + +module ActiveScaffold + module Bridges + module DatePickerBridge + module SearchColumnHelpers + def active_scaffold_search_date_picker(column, options) + opt_value, from_value, to_value = field_search_params_range_values(column) + options = column.options.merge(options).except!(:include_blank) + helper = "select_#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}" + html = [] + html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[from]", :id => "#{options[:id]}_from", :value => from_value)) + html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[to]", :id => "#{options[:id]}_to", :value => to_value)) + html * ' - ' + end + end + + module ViewHelpers + # Provides stylesheets to include with +stylesheet_link_tag+ + def active_scaffold_stylesheets(frontend = :default) + super #+ [calendar_date_select_stylesheets] + end + + # Provides stylesheets to include with +stylesheet_link_tag+ + def active_scaffold_javascripts(frontend = :default) + super #+ [calendar_date_select_javascripts] + end + end + + module Finder + module ClassMethods + def condition_for_date_picker_type(column, value, like_pattern) + conversion = column.column.type == :date ? 'to_date' : 'to_time' + from_value, to_value = ['from', 'to'].collect do |field| + Time.zone.parse(value[field]) rescue nil + end + + if from_value.nil? and to_value.nil? + nil + elsif !from_value + ["#{column.search_sql} <= ?", to_value.send(conversion).to_s(:db)] + elsif !to_value + ["#{column.search_sql} >= ?", from_value.send(conversion).to_s(:db)] + else + ["#{column.search_sql} BETWEEN ? AND ?", from_value.send(conversion).to_s(:db), to_value.send(conversion).to_s(:db)] + end + end + alias_method :condition_for_datetime_picker_type, :condition_for_date_picker_type + end + end + end + end +end + +ActionView::Base.class_eval do + include ActiveScaffold::Bridges::DatePickerBridge::SearchColumnHelpers + include ActiveScaffold::Bridges::DatePickerBridge::ViewHelpers +end +ActiveScaffold::Finder::ClassMethods.module_eval do + include ActiveScaffold::Bridges::DatePickerBridge::Finder::ClassMethods +end diff --git a/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js b/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js new file mode 100644 index 0000000000..300e837577 --- /dev/null +++ b/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js @@ -0,0 +1,22 @@ +$(document).ready(function() { + $('input.date_picker').live('click', function(event) { + var date_picker = $(this); + if (typeof(date_picker.datepicker) == 'function') { + if (!date_picker.hasClass('hasDatepicker')) { + date_picker.datepicker(); + date_picker.trigger('focus'); + } + } + return true; + }); + $('input.datetime_picker').live('click', function(event) { + var date_picker = $(this); + if (typeof(date_picker.datetimepicker) == 'function') { + if (!date_picker.hasClass('hasDatepicker')) { + date_picker.datetimepicker(); + date_picker.trigger('focus'); + } + } + return true; + }); +}); \ No newline at end of file From 6f81662a4e08e11ddce2545cf28add72468547f8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 9 Aug 2010 08:46:40 +0200 Subject: [PATCH 0542/2024] Set current page inside a span tag so it's possible to style it --- lib/active_scaffold/helpers/pagination_helpers.rb | 2 +- test/helpers/pagination_helpers_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/pagination_helpers.rb b/lib/active_scaffold/helpers/pagination_helpers.rb index cedd105854..568634116d 100644 --- a/lib/active_scaffold/helpers/pagination_helpers.rb +++ b/lib/active_scaffold/helpers/pagination_helpers.rb @@ -42,7 +42,7 @@ def pagination_ajax_links(current_page, params, window_size) start_number.upto(end_number) do |num| if current_page.number == num - html << num + html << content_tag(:span, num) else html << pagination_ajax_link(num, params) end diff --git a/test/helpers/pagination_helpers_test.rb b/test/helpers/pagination_helpers_test.rb index e3235e7410..bdf50c0bb2 100644 --- a/test/helpers/pagination_helpers_test.rb +++ b/test/helpers/pagination_helpers_test.rb @@ -52,4 +52,8 @@ def links(current, last_page, window_size = 2, infinite = false) current_page = stub(:number => current, :pager => paginator) pagination_ajax_links(current_page, {}, window_size) end + + def content_tag(tag, text) + text + end end From 891c2bb0ea4b4a37eeee0c32e1db02a35c39796f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 11 Aug 2010 11:47:24 +0200 Subject: [PATCH 0543/2024] update pagination to work with Rails 3.0 --- .../javascripts/jquery/active_scaffold.js | 16 ++++++++++ .../javascripts/prototype/active_scaffold.js | 21 ++++++++++++++ .../views/_list_pagination_links.html.erb | 29 ++++--------------- .../helpers/pagination_helpers.rb | 26 ++++++----------- 4 files changed, 51 insertions(+), 41 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 9882eb21d9..32cb897c46 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -201,6 +201,22 @@ $(document).ready(function() { } } }); + $('a.as_paginate').live('ajax:before',function(event) { + var as_paginate = $(this); + var history_controller_id = as_paginate.attr('data-page-history'); + if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.attr('href'), history_controller_id); + as_paginate.prevAll('img.loading-indicator').css('visibility','visible'); + return true; + }); + $('a.as_paginate').live('ajax:failure', function(event) { + var as_scaffold = $(this).closest('.active-scaffold'); + ActiveScaffold.report_500_response(as_scaffold); + return true; + }); + $('a.as_paginate').live('ajax:complete', function(event) { + $(this).prevAll('img.loading-indicator').css('visibility','hidden'); + return true; + }); }); /* Simple Inheritance diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index eb311253a3..30423a9557 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -208,6 +208,27 @@ document.observe("dom:loaded", function() { } return true; }); + document.on('ajax:before', 'a.as_paginate', function(event) { + var as_paginate = event.findElement(); + var loading_indicator = as_paginate.up().down('img.loading-indicator'); + var history_controller_id = as_paginate.readAttribute('data-page-history'); + + if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.readAttribute('href'), history_controller_id); + if (loading_indicator) loading_indicator.style.visibility = 'visible'; + return true; + }); + document.on('ajax:failure', 'a.as_paginate', function(event) { + var as_scaffold = event.findElement('.active-scaffold'); + ActiveScaffold.report_500_response(as_scaffold); + return true; + }); + document.on('ajax:complete', 'a.as_paginate', function(event) { + var as_paginate = event.findElement(); + var loading_indicator = as_paginate.up().down('img.loading-indicator'); + + if(loading_indicator) loading_indicator.style.visibility = 'hidden'; + return true; + }); }); diff --git a/frontends/default/views/_list_pagination_links.html.erb b/frontends/default/views/_list_pagination_links.html.erb index 258e748e02..119a0a99fc 100644 --- a/frontends/default/views/_list_pagination_links.html.erb +++ b/frontends/default/views/_list_pagination_links.html.erb @@ -1,28 +1,9 @@ <% unless current_page.nil? -%> - <% pagination_params = params_for(:action => :index) -%> - <% indicator_params = pagination_params.merge(:action => 'pagination') -%> - <% previous_url = url_for(pagination_params.merge(:page => current_page.number - 1)) -%> - <% next_url = url_for(pagination_params.merge(:page => current_page.number + 1)) -%> - <% current_url = url_for(pagination_params.merge(:page => current_page.number)) -%> + <% url_options = params_for(:action => :index) -%> + <% options = {'data-page-history' => controller_id, :remote => true, :method => :get} -%> <%= loading_indicator_tag :action => :pagination %> - <%= link_to_remote(as_(:previous), - { :url => pagination_params.merge(:page => current_page.number - 1), - :after => "$('#{loading_indicator_id(:action => :pagination)}').style.visibility = 'visible';", - :before => "addActiveScaffoldPageToHistory('#{previous_url}', '#{controller_id}');", - :complete => "$('#{loading_indicator_id(:action => :pagination)}').style.visibility = 'hidden';", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :method => :get }, - { :href => previous_url, - :class => "previous"}) if current_page.prev? %> - <%= pagination_ajax_links current_page, pagination_params, active_scaffold_config.list.page_links_window %> - <%= link_to_remote(as_(:next), - { :url => pagination_params.merge(:page => current_page.number + 1), - :after => "$('#{loading_indicator_id(:action => :pagination)}').style.visibility = 'visible';", - :before => "addActiveScaffoldPageToHistory('#{next_url}', '#{controller_id}');", - :complete => "$('#{loading_indicator_id(:action => :pagination)}').style.visibility = 'hidden';", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :method => :get }, - { :href => next_url, - :class => "next"}) if current_page.next? %> + <%= link_to as_(:previous), url_options.merge(:page => current_page.number - 1), options.merge(:class => "as_paginate previous") if current_page.prev? %> + <%= pagination_ajax_links current_page, url_options, options, active_scaffold_config.list.page_links_window %> + <%= link_to as_(:next), url_options.merge(:page => current_page.number + 1), options.merge(:class => "as_paginate next") if current_page.next? %> <% end -%> diff --git a/lib/active_scaffold/helpers/pagination_helpers.rb b/lib/active_scaffold/helpers/pagination_helpers.rb index aba87ad5df..4df2e5bd42 100644 --- a/lib/active_scaffold/helpers/pagination_helpers.rb +++ b/lib/active_scaffold/helpers/pagination_helpers.rb @@ -1,19 +1,11 @@ module ActiveScaffold module Helpers module PaginationHelpers - def pagination_ajax_link(page_number, params) - url = url_for params.merge(:page => page_number) - page_link = link_to_remote(page_number, - { :url => url, - :before => "addActiveScaffoldPageToHistory('#{url}', '#{controller_id}');", - :after => "$('#{loading_indicator_id(:action => :pagination)}').style.visibility = 'visible';", - :complete => "$('#{loading_indicator_id(:action => :pagination)}').style.visibility = 'hidden';", - :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", - :method => :get }, - { :href => url_for(params.merge(:page => page_number)) }) + def pagination_ajax_link(page_number, url_options, options) + link_to page_number, url_options.merge(:page => page_number), options.merge(:class => "as_paginate") end - def pagination_ajax_links(current_page, params, window_size) + def pagination_ajax_links(current_page, url_options, options, window_size) start_number = current_page.number - window_size end_number = current_page.number + window_size start_number = 1 if start_number <= 0 @@ -26,7 +18,7 @@ def pagination_ajax_links(current_page, params, window_size) html = [] unless start_number == 1 last_page = 1 - html << pagination_ajax_link(last_page, params) + html << pagination_ajax_link(last_page, url_options, options) if current_page.pager.infinite? offsets.reverse.each do |offset| page = current_page.number - offset @@ -42,21 +34,21 @@ def pagination_ajax_links(current_page, params, window_size) start_number.upto(end_number) do |num| if current_page.number == num - html << num + html << content_tag(:span, num.to_s, {:class => "as_paginate current"}) else - html << pagination_ajax_link(num, params) + html << pagination_ajax_link(num, url_options, options) end end if current_page.pager.infinite? offsets.each do |offset| - html << '..' << pagination_ajax_link(current_page.number + offset, params) + html << '..' << pagination_ajax_link(current_page.number + offset, url_options, options) end else html << ".." unless end_number >= current_page.pager.last.number - 1 - html << pagination_ajax_link(current_page.pager.last.number, params) unless end_number == current_page.pager.last.number + html << pagination_ajax_link(current_page.pager.last.number, url_options, options) unless end_number == current_page.pager.last.number end - html.join(' ') + html.join(' ').html_safe end end end From ec2337ef0b394be6684f680d18835a3d3039ffc1 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 11 Aug 2010 14:29:05 +0200 Subject: [PATCH 0544/2024] generator: use underscored model_name in controller file --- .../active_scaffold_controller/templates/controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/active_scaffold_controller/templates/controller.rb b/lib/generators/active_scaffold_controller/templates/controller.rb index c150f7a06e..6f0581e738 100644 --- a/lib/generators/active_scaffold_controller/templates/controller.rb +++ b/lib/generators/active_scaffold_controller/templates/controller.rb @@ -1,4 +1,4 @@ class <%= controller_class_name %>Controller < ApplicationController - active_scaffold :<%= class_name.demodulize %> do |conf| + active_scaffold :<%= class_name.demodulize.underscore %> do |conf| end end \ No newline at end of file From a33ce8f2f5b1292e2554e3f021614b40a251e384 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 12 Aug 2010 09:09:48 +0200 Subject: [PATCH 0545/2024] render :super support in template rendering --- lib/extensions/action_view_rendering.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index 71a4ac4326..80f1a954be 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -40,11 +40,11 @@ def render_with_active_scaffold(*args, &block) if args.first == :super options = args[1] || {} options[:locals] ||= {} - options[:locals].reverse_merge!(@last_partial[:locals] || {}) - templates = lookup_context.find_all_templates(@last_partial[:partial], nil, true) - @last_partial[:index] = @last_partial[:index].nil? ? 0 : @last_partial[:index] + 1 - options[:template] = templates[@last_partial[:index]] - render options + options[:locals].reverse_merge!(@last_view[:locals] || {}) + templates = lookup_context.find_all_templates(@last_view[:view], nil, !@last_view[:is_template]) + @last_view[:index] = @last_view[:index].nil? ? 0 : @last_view[:index] + 1 + options[:template] = templates[@last_view[:index]] + render_without_active_scaffold options elsif args.first.is_a?(Hash) and args.first[:active_scaffold] require 'digest/md5' options = args.first @@ -72,8 +72,8 @@ def render_with_active_scaffold(*args, &block) else options = args.first - @last_partial = {:partial => options[:partial], :index => nil} if options[:partial] - @last_partial[:locals] = options[:locals] if options[:locals] + @last_view = {:view => options[:partial] ? options[:partial] : options[:template], :index => !!options[:template] ? 0 : nil, :is_template => !!options[:template]} if options[:partial] || options[:template] + @last_view[:locals] = options[:locals] if options[:locals] render_without_active_scaffold(*args, &block) end end From 72daffe585d4881cbc9c7277f04c3b211d97b276 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 12 Aug 2010 12:59:46 +0200 Subject: [PATCH 0546/2024] refactored routing --- lib/extensions/routing_mapper.rb | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/extensions/routing_mapper.rb b/lib/extensions/routing_mapper.rb index 10ea654bae..d4311e02ad 100644 --- a/lib/extensions/routing_mapper.rb +++ b/lib/extensions/routing_mapper.rb @@ -1,26 +1,31 @@ module ActionDispatch module Routing + ACTIVE_SCAFFOLD_CORE_ROUTING = { + :collection => {:show_search => :get, :render_field => :get}, + :member => {:row => :get, :update_column => :post, :render_field => :get, :delete => :get} + } + ACTIVE_SCAFFOLD_HABTM_ROUTING = { + :collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post}, + :member => {:edit_associated => :get, :add_association => :get, :destroy_existing => :delete} + } class Mapper module Base - def as_routes(options = {:full => true}) - collection do - get :show_search, :render_field + def as_routes(options = {:habtm => true}) + collection do + ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].each {|name, type| send(type, name)} end member do - get :row, :render_field, :delete - post :update_column + ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each {|name, type| send(type, name)} end - as_extended_routes if options[:full] + as_habtm_routes if options[:habtm] end - def as_extended_routes + def as_habtm_routes collection do - get :edit_associated, :new_existing - post :add_existing + ActionDispatch::Routing::ACTIVE_SCAFFOLD_HABTM_ROUTING[:collection].each {|name, type| send(type, name)} end member do - get :edit_associated, :add_association - delete :destroy_existing + ActionDispatch::Routing::ACTIVE_SCAFFOLD_HABTM_ROUTING[:member].each {|name, type| send(type, name)} end end end From b5cc032aed9128d12d6e9f3a548bad370fad0a42 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 12 Aug 2010 16:02:21 +0200 Subject: [PATCH 0547/2024] Bugfix: render super failed under certain conditions --- lib/extensions/action_view_rendering.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index 80f1a954be..3764810e6c 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -72,8 +72,9 @@ def render_with_active_scaffold(*args, &block) else options = args.first - @last_view = {:view => options[:partial] ? options[:partial] : options[:template], :index => !!options[:template] ? 0 : nil, :is_template => !!options[:template]} if options[:partial] || options[:template] - @last_view[:locals] = options[:locals] if options[:locals] + @last_view = {:view => options[:partial], :index => nil, :is_template => false} if options[:partial] + @last_view = {:view => options[:template], :index => !!options[:template] ? 0 : nil, :is_template => !!options[:template]} if @last_view.nil? && options[:template] + @last_view[:locals] = options[:locals] if !@last_view.nil? && options[:locals] render_without_active_scaffold(*args, &block) end end From 1b952291e26f044720ab912857f649310f5cd483 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 13 Aug 2010 09:12:49 +0200 Subject: [PATCH 0548/2024] fix exception in new and create if nested action is excluded --- lib/active_scaffold/actions/create.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index b85c8aa54d..feb2dccea4 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -82,7 +82,7 @@ def create_respond_to_yaml def do_new @record = new_model apply_constraints_to_record(@record) - create_association_with_parent(@record) + create_association_with_parent(@record) if nested? @record end @@ -93,7 +93,7 @@ def do_create active_scaffold_config.model.transaction do @record = update_record_from_params(new_model, active_scaffold_config.create.columns, params[:record]) apply_constraints_to_record(@record, :allow_autosave => true) - create_association_with_parent(@record) + create_association_with_parent(@record) if nested? before_create_save(@record) self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit if successful? From 73b2d23471932daddacd6b0cee245eac8d1aaff5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 13 Aug 2010 15:54:39 +0200 Subject: [PATCH 0549/2024] further fix to support render :super --- lib/extensions/action_view_rendering.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index 3764810e6c..b979b71dba 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -41,9 +41,11 @@ def render_with_active_scaffold(*args, &block) options = args[1] || {} options[:locals] ||= {} options[:locals].reverse_merge!(@last_view[:locals] || {}) - templates = lookup_context.find_all_templates(@last_view[:view], nil, !@last_view[:is_template]) - @last_view[:index] = @last_view[:index].nil? ? 0 : @last_view[:index] + 1 - options[:template] = templates[@last_view[:index]] + if @last_view[:templates].nil? + @last_view[:templates] = lookup_context.find_all_templates(@last_view[:view], controller_path, !@last_view[:is_template]) + @last_view[:templates].shift + end + options[:template] = @last_view[:templates].shift render_without_active_scaffold options elsif args.first.is_a?(Hash) and args.first[:active_scaffold] require 'digest/md5' @@ -72,8 +74,8 @@ def render_with_active_scaffold(*args, &block) else options = args.first - @last_view = {:view => options[:partial], :index => nil, :is_template => false} if options[:partial] - @last_view = {:view => options[:template], :index => !!options[:template] ? 0 : nil, :is_template => !!options[:template]} if @last_view.nil? && options[:template] + @last_view = {:view => options[:partial], :is_template => false} if options[:partial] + @last_view = {:view => options[:template], :is_template => !!options[:template]} if @last_view.nil? && options[:template] @last_view[:locals] = options[:locals] if !@last_view.nil? && options[:locals] render_without_active_scaffold(*args, &block) end From 1f92feff7bc25ee29fb425819547a706db02ddd6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 16 Aug 2010 16:26:10 +0200 Subject: [PATCH 0550/2024] Bugfix: Fix autoloading issue --- .../date_picker/lib/datepicker_bridge.rb | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 73361258c4..6033777b43 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -1,30 +1,26 @@ -module ActiveScaffold::Config - class Core < Base - - def initialize_with_date_picker(model_id) - initialize_without_date_picker(model_id) - - date_picker_fields = self.model.columns.collect{|c| {:name => c.name.to_sym, :type => c.type} if [:date, :datetime].include?(c.type) }.compact - # check to see if file column was used on the model - return if date_picker_fields.empty? - - # automatically set the forum_ui to a file column - date_picker_fields.each{|field| - col_config = self.columns[field[:name]] - form_ui = (field[:type] == :date ? :date_picker : :datetime_picker) - - col_config.form_ui = form_ui - if col_config.options[:class] - col_config.options[:class] += " #{form_ui.to_s} text-input" - else - col_config.options[:class] = "#{form_ui.to_s} text-input" - end - } - end +ActiveScaffold::Config::Core.class_eval do + def initialize_with_date_picker(model_id) + initialize_without_date_picker(model_id) - alias_method_chain :initialize, :date_picker + date_picker_fields = self.model.columns.collect{|c| {:name => c.name.to_sym, :type => c.type} if [:date, :datetime].include?(c.type) }.compact + # check to see if file column was used on the model + return if date_picker_fields.empty? + # automatically set the forum_ui to a file column + date_picker_fields.each{|field| + col_config = self.columns[field[:name]] + form_ui = (field[:type] == :date ? :date_picker : :datetime_picker) + + col_config.form_ui = form_ui + if col_config.options[:class] + col_config.options[:class] += " #{form_ui.to_s} text-input" + else + col_config.options[:class] = "#{form_ui.to_s} text-input" + end + } end + + alias_method_chain :initialize, :date_picker end From 84928e7672f07afd4e8b2e61dd33efb3b3c67979 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 16 Aug 2010 16:49:42 +0200 Subject: [PATCH 0551/2024] generator to setup active_scaffold in a just created Rails 3 app ex. rails g active_scaffold_setup --- lib/generators/active_scaffold_setup/USAGE | 10 +++++ .../active_scaffold_setup_generator.rb | 45 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 lib/generators/active_scaffold_setup/USAGE create mode 100644 lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb diff --git a/lib/generators/active_scaffold_setup/USAGE b/lib/generators/active_scaffold_setup/USAGE new file mode 100644 index 0000000000..f256e54c3e --- /dev/null +++ b/lib/generators/active_scaffold_setup/USAGE @@ -0,0 +1,10 @@ +Description: + Setup a new Rails 3 Application with active_scaffold. + Pass 'jquery' in case you would like to use it instead of prototype + + This installs required plugins and configures active_scaffold to use + specified js lib and application layout file to include all required + assets + +Example: + `rails generate active_scaffold_setup jquery` \ No newline at end of file diff --git a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb new file mode 100644 index 0000000000..5b467598f9 --- /dev/null +++ b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb @@ -0,0 +1,45 @@ +module Rails + module Generators + class ActiveScaffoldSetupGenerator < Rails::Generators::Base #metagenerator + argument :js_lib, :type => :string, :default => 'prototype', :desc => 'js_lib for activescaffold (prototype|jquery)' + + def self.source_root + @source_root ||= File.join(File.dirname(__FILE__), 'templates') + end + + def install_plugins + plugin 'verification', :git => 'git://github.com/rails/verification.git' + plugin 'render_component', :git => 'git://github.com/vhochstein/render_component.git' + if js_lib == 'prototype' + get "http://github.com/vhochstein/prototype-ujs/raw/master/src/rails.js", "public/javascripts/rails.js" + elsif js_lib == 'jquery' + get "http://github.com/vhochstein/jquery-ujs/raw/master/src/rails.js", "public/javascripts/rails_jquery.js" + end + end + + def configure_active_scaffold + if js_lib == 'jquery' + gsub_file 'vendor/plugins/active_scaffold/environment.rb', /#ActiveScaffold.js_framework = :jquery/, 'ActiveScaffold.js_framework = :jquery' + end + end + + def configure_application_layout + if js_lib == 'prototype' + inject_into_file "app/views/layouts/application.html.erb", + " <%= active_scaffold_includes %>\n", + :after => "<%= javascript_include_tag :defaults %>\n" + elsif js_lib == 'jquery' + inject_into_file "app/views/layouts/application.html.erb", +" <%= stylesheet_link_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/ui-lightness/jquery-ui.css' %> + <%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js' %> + <%= javascript_include_tag 'rails_jquery.js' %> + <%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.js' %> + <%= javascript_include_tag 'application.js' %> + <%= active_scaffold_includes %>\n", + :after => "<%= javascript_include_tag :defaults %>\n" + gsub_file 'app/views/layouts/application.html.erb', /<%= javascript_include_tag :defaults/, '<%# javascript_include_tag :defaults' + end + end + end + end +end \ No newline at end of file From 773db4f1f5b0aeb1e5f834fae32b86e9dc4ce8df Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 17 Aug 2010 15:27:37 +0200 Subject: [PATCH 0552/2024] add collect method --- .../data_structures/action_columns.rb | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index e41ae15eb6..3ae4b9e775 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -64,15 +64,7 @@ def each(options = {}, &proc) @set.each do |item| unless item.is_a? ActiveScaffold::DataStructures::ActionColumns item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class)) - # skip if this matches a constrained column - next if constraint_columns.include?(item.name.to_sym) - # skip if this matches the field_name of a constrained column - next if item.field_name and constraint_columns.include?(item.field_name.to_sym) - # skip this field if it's not authorized - unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.crud_type, :column => item.name) - self.unauthorized_columns << item.name.to_sym - next - end + next if self.skip_column?(item, options) end if item.is_a? ActiveScaffold::DataStructures::ActionColumns and options.has_key?(:flatten) and options[:flatten] item.each(options, &proc) @@ -82,7 +74,37 @@ def each(options = {}, &proc) end end + def collect(options = {}, &proc) + columns = [] + options[:for] ||= @columns.active_record_class + self.unauthorized_columns = [] + @set.each do |item| + unless item.is_a? ActiveScaffold::DataStructures::ActionColumns + item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class)) + next if self.skip_column?(item, options) + end + if item.is_a? ActiveScaffold::DataStructures::ActionColumns and options.has_key?(:flatten) and options[:flatten] + columns = columns + item.collect(options, &proc) + else + columns << item + end + end + columns + end + def skip_column?(column, options) + result = false + # skip if this matches a constrained column + result = true if constraint_columns.include?(column.name.to_sym) + # skip if this matches the field_name of a constrained column + result = true if column.field_name and constraint_columns.include?(column.field_name.to_sym) + # skip this field if it's not authorized + unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.crud_type, :column => column.name) + self.unauthorized_columns << column.name.to_sym + result = true + end + return result + end # registers a set of column objects (recursively, for all nested ActionColumns) def set_columns(columns) From 37f84b95dcce6bccd0776a913b19571e4d27b752 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 17 Aug 2010 15:31:26 +0200 Subject: [PATCH 0553/2024] use ActionColumns.collect once instead of many times ActionColumns.each --- frontends/default/views/_list.html.erb | 11 ++++++----- frontends/default/views/_list_calculations.html.erb | 5 +++-- .../default/views/_list_column_headings.html.erb | 2 +- frontends/default/views/_list_messages.html.erb | 2 +- frontends/default/views/_list_record.html.erb | 3 ++- frontends/default/views/_list_record_columns.html.erb | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index 45f8d2213b..05e861c6eb 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -1,16 +1,17 @@ <table cellpadding="0" cellspacing="0"> <thead> <tr> - <%= render :partial => 'list_column_headings' %> + <% columns = active_scaffold_config.list.columns.collect %> + <%= render :partial => 'list_column_headings', :locals => {:columns => columns} %> </tr> </thead> - <%= render :partial => 'list_messages' %> + <%= render :partial => 'list_messages', :locals => {:columns => columns} %> <tbody class="records" id="<%= active_scaffold_tbody_id %>"> <% if !@records.empty? -%> - <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false} %> + <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false, :columns => columns} %> <% end -%> - <% if active_scaffold_config.list.columns.any? {|c| c.calculation?} -%> - <%= render :partial => 'list_calculations' %> + <% if columns.any? {|c| c.calculation?} -%> + <%= render :partial => 'list_calculations', locals => {:columns => columns} %> <% end -%> </tbody> </table> diff --git a/frontends/default/views/_list_calculations.html.erb b/frontends/default/views/_list_calculations.html.erb index 67097e6d18..1db7892d60 100644 --- a/frontends/default/views/_list_calculations.html.erb +++ b/frontends/default/views/_list_calculations.html.erb @@ -1,6 +1,7 @@ -<% display_class = ( @records.kind_of?(Array) ? @records.first : @records ) -%> +<% display_class = ( @records.kind_of?(Array) ? @records.first : @records ) + columns = active_scaffold_config.list.columns.collect if columns.nil? -%> <tr id="<%= active_scaffold_calculations_id %>" class="active-scaffold-calculations"> - <% active_scaffold_config.list.columns.each do |column| -%> + <% columns.each do |column| -%> <td id="<%= active_scaffold_calculations_id(column) if column.calculation? %>"> <% if column.calculation? -%> <%= render_column_calculation(column) %> diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index 40113c797d..94b7120ac6 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -4,7 +4,7 @@ sorting_stages = ['reset', 'ASC', 'DESC'] default_sorting = active_scaffold_config.list.sorting default_sorting_stages = ['ASC', 'DESC'] -%> -<% active_scaffold_config.list.columns.each do |column| -%> +<% columns.each do |column| -%> <% stages = default_sorting.sorts_on?(column) ? default_sorting_stages : sorting_stages -%> <%= render_column_heading(column, sorting, stages.after(sorting.direction_of(column)) || 'ASC') %> <% end -%> diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index 0aa9ff560f..c0449ea9b6 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -1,6 +1,6 @@ <tbody class="messages"> <tr class="record even-record"> - <td colspan="<%= active_scaffold_config.list.columns.length -%>" class="messages-container"> + <td colspan="<%= columns.length -%>" class="messages-container"> <p class="error-message message server-error" style="display:none;"> <%= as_(:internal_error).html_safe %> <a href="#" onclick="ActiveScaffold.hide(this.parentNode); return false;" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 60d9a46936..4ec2a19e9c 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -1,11 +1,12 @@ <% record = list_record if list_record # compat with render :partial :collection +columns = active_scaffold_config.list.columns.collect if columns.nil? tr_class = cycle("", "even-record") tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class url_options = params_for(:action => :list, :id => record.id) -%> <tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get, :escape => false)).html_safe %>"> - <%= render :partial => 'list_record_columns', :locals => {:record => record} %> + <%= render :partial => 'list_record_columns', :locals => {:record => record, :columns => columns} %> <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options} if active_scaffold_config.action_links.any? {|link| link.type == :member } %> </tr> diff --git a/frontends/default/views/_list_record_columns.html.erb b/frontends/default/views/_list_record_columns.html.erb index c671178234..d1892fa260 100644 --- a/frontends/default/views/_list_record_columns.html.erb +++ b/frontends/default/views/_list_record_columns.html.erb @@ -1,4 +1,4 @@ -<% active_scaffold_config.list.columns.each do |column| %> +<% columns.each do |column| %> <% authorized = record.authorized_for?(:crud_type => :read, :column => column.name) -%> <% column_value = authorized ? get_column_value(record, column) : active_scaffold_config.list.empty_field_text -%> From 84479a5e9b522862bb3f05d135d740ad2320e9b6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 17 Aug 2010 16:43:38 +0200 Subject: [PATCH 0554/2024] bugfix: syntax error introduced in prev commit --- frontends/default/views/_list.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index 05e861c6eb..caf05acffb 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -11,7 +11,7 @@ <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false, :columns => columns} %> <% end -%> <% if columns.any? {|c| c.calculation?} -%> - <%= render :partial => 'list_calculations', locals => {:columns => columns} %> + <%= render :partial => 'list_calculations', :locals => {:columns => columns} %> <% end -%> </tbody> </table> From d7b94dab1df330c4838ac10f87116919c3251027 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 18 Aug 2010 13:52:28 +0200 Subject: [PATCH 0555/2024] get link_to_visibility_toggle ready for Rails 3 --- .../default/javascripts/jquery/active_scaffold.js | 13 +++++++++++++ .../javascripts/prototype/active_scaffold.js | 14 ++++++++++++++ frontends/default/views/_form.html.erb | 9 ++++++--- frontends/default/views/_form_association.html.erb | 6 ++++-- lib/active_scaffold/helpers/id_helpers.rb | 8 +++++++- lib/active_scaffold/helpers/view_helpers.rb | 9 ++++----- 6 files changed, 48 insertions(+), 11 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 32cb897c46..a408616698 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -473,6 +473,19 @@ var ActiveScaffold = { if (typeof(element.effect) == 'function') { element.effect("highlight", {}, 3000); } + }, + + create_visibility_toggle: function(element, options) { + if (typeof(element) == 'string') element = '#' + element; + var toggable = $(element); + var toggler = toggable.prev(); + var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label; + + toggler.append(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)'); + toggler.children('a').click(function() { + toggable.toggle(); + $(this).html((toggable.is(':hidden')) ? options.show_label : options.hide_label); + }); } } diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 30423a9557..a41a0ed280 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -408,7 +408,21 @@ var ActiveScaffold = { span.removeClassName('hover'); span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.id, options.url, options) span.inplace_edit.enterEditMode(); + }, + + create_visibility_toggle: function(element, options) { + var toggable = $(element); + var toggler = toggable.previous(); + var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label; + + toggler.insert(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)'); + toggler.firstDescendant().observe('click', function(event) { + var element = event.element(); + toggable.toggle(); + element.innerHTML = (toggable.style.display == 'none') ? options.show_label : options.hide_label; + }); } + } /* diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index 238adef474..feefeeaec4 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -1,9 +1,12 @@ -<ol class="form" <%= 'style="display: none;"' if columns.collapsed -%>> +<% subsection_id ||= nil %> +<ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= 'style="display: none;"' if columns.collapsed -%>> <% columns.each :for => @record do |column| -%> <% if is_subsection? column -%> + <% subsection_id = sub_section_id(:sub_section => column.label) %> <li class="sub-section"> - <h5><%= column.label %> (<%= link_to_visibility_toggle(:default_visible => !column.collapsed) -%>)</h5> - <%= render :partial => 'form', :locals => { :columns => column } %> + <h5><%= column.label %></h5> + <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id} %> + <%= link_to_visibility_toggle(subsection_id, {:default_visible => !column.collapsed}) -%> </li> <% elsif is_subform? column and !override_form_field?(column) -%> <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? %>" id="<%= sub_form_id(:association => column.name) %>"> diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index c37fb32e22..958881a9d0 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -4,9 +4,11 @@ associated = column.singular_association? ? [parent_record.send(column.name)].co associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) associated << column.association.klass.new if column.show_blank_record? associated +subform_div_id = sub_form_id({:association => column.name, :id => parent_record.id || 99999999999}) -%> -<h5><%= column.label -%> (<%= link_to_visibility_toggle(:default_visible => !column.collapsed) -%>)</h5> -<div <%= 'style="display: none;"' if column.collapsed -%>> +<h5><%= column.label -%></h5> +<div id ="<%= subform_div_id %>" <%= 'style="display: none;"'.html_safe if column.collapsed -%>> <%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated} %> </div> +<%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%> <% @record = parent_record -%> diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index 49f0b72057..9e2d27d542 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -90,13 +90,19 @@ def loading_indicator_id(options = {}) options[:action] ||= params[:action] clean_id "#{controller_id}-#{options[:action]}-#{options[:id]}-loading-indicator" end + + def sub_section_id(options = {}) + options[:id] ||= params[:id] + options[:id] ||= params[:parent_id] + clean_id "#{controller_id}-#{options[:id]}-#{options[:sub_section]}-subsection" + end def sub_form_id(options = {}) options[:id] ||= params[:id] options[:id] ||= params[:parent_id] clean_id "#{controller_id}-#{options[:id]}-#{options[:association]}-subform" end - + def sub_form_list_id(options = {}) options[:id] ||= params[:id] options[:id] ||= params[:parent_id] diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 48f99d913e..6fa9dc75a8 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -115,12 +115,11 @@ def loading_indicator_tag(options) # Creates a javascript-based link that toggles the visibility of some element on the page. # By default, it toggles the visibility of the sibling after the one it's nested in. You may pass custom javascript logic in options[:of] to change that, though. For example, you could say :of => '$("my_div_id")'. # You may also flag whether the other element is visible by default or not, and the initial text will adjust accordingly. - def link_to_visibility_toggle(options = {}) - options[:of] ||= '$(this.parentNode).next()' + def link_to_visibility_toggle(id, options = {}) options[:default_visible] = true if options[:default_visible].nil? - - link_text = options[:default_visible] ? as_(:hide) : as_(:show) - link_to_function link_text, "e = #{options[:of]}; e.toggle(); this.innerHTML = (e.style.display == 'none') ? '#{as_(:show)}' : '#{as_(:hide)}'", :class => 'visibility-toggle' + options[:hide_label] = as_(:hide) + options[:show_label] = as_(:show) + javascript_tag("ActiveScaffold.create_visibility_toggle('#{id}', #{options.to_json});") end def skip_action_link(link, *args) From caa467a9396931f012636aa17c3b15749361e898 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 18 Aug 2010 14:00:15 +0200 Subject: [PATCH 0556/2024] correct initialization of columns --- frontends/default/views/_list_calculations.html.erb | 2 +- frontends/default/views/_list_record.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_list_calculations.html.erb b/frontends/default/views/_list_calculations.html.erb index 1db7892d60..63b86f7673 100644 --- a/frontends/default/views/_list_calculations.html.erb +++ b/frontends/default/views/_list_calculations.html.erb @@ -1,5 +1,5 @@ <% display_class = ( @records.kind_of?(Array) ? @records.first : @records ) - columns = active_scaffold_config.list.columns.collect if columns.nil? -%> + columns ||= active_scaffold_config.list.columns.collect -%> <tr id="<%= active_scaffold_calculations_id %>" class="active-scaffold-calculations"> <% columns.each do |column| -%> <td id="<%= active_scaffold_calculations_id(column) if column.calculation? %>"> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 4ec2a19e9c..c811e1f1d1 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -1,6 +1,6 @@ <% record = list_record if list_record # compat with render :partial :collection -columns = active_scaffold_config.list.columns.collect if columns.nil? +columns ||= active_scaffold_config.list.columns.collect tr_class = cycle("", "even-record") tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class url_options = params_for(:action => :list, :id => record.id) From 85a79979038afdef6e2fc3f0729648b3a69dd7f0 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 18 Aug 2010 15:19:08 +0200 Subject: [PATCH 0557/2024] Bugfix: (inc/dec)remement_record_count with jquery fixed --- frontends/default/javascripts/jquery/active_scaffold.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index a408616698..be8d61ff3d 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -343,14 +343,14 @@ var ActiveScaffold = { if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; scaffold = $(scaffold) count = scaffold.find('span.active-scaffold-records').last(); - if (count) count.html(parseInt(count.innerHTML, 10) - 1); + if (count) count.html(parseInt(count.html(), 10) - 1); }, increment_record_count: function(scaffold) { // increment the last record count, firsts record count are in nested lists if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; scaffold = $(scaffold) count = scaffold.find('span.active-scaffold-records').last(); - if (count) count.html(parseInt(count.innerHTML, 10) + 1); + if (count) count.html(parseInt(count.html(), 10) + 1); }, update_row: function(row, html) { var even_row = false; From add8f0c0167b26e9aebed0d5cf293d56b7b046db Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 18 Aug 2010 15:58:41 +0200 Subject: [PATCH 0558/2024] Bugfix: open datepicker if input element is focused --- .../date_picker/public/javascripts/date_picker_bridge.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js b/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js index 300e837577..6a4b864b73 100644 --- a/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +++ b/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js @@ -1,5 +1,5 @@ $(document).ready(function() { - $('input.date_picker').live('click', function(event) { + $('input.date_picker').live('focus', function(event) { var date_picker = $(this); if (typeof(date_picker.datepicker) == 'function') { if (!date_picker.hasClass('hasDatepicker')) { @@ -9,7 +9,7 @@ $(document).ready(function() { } return true; }); - $('input.datetime_picker').live('click', function(event) { + $('input.datetime_picker').live('focus', function(event) { var date_picker = $(this); if (typeof(date_picker.datetimepicker) == 'function') { if (!date_picker.hasClass('hasDatepicker')) { From 64ebede2676f6434c10259200f2b92cef06c937e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 19 Aug 2010 11:50:29 +0200 Subject: [PATCH 0559/2024] first steps to get create_another and add_existing buttons running with Rails 3 --- .../default/javascripts/jquery/active_scaffold.js | 15 +++++++++++---- .../javascripts/prototype/active_scaffold.js | 12 ++++++++++-- .../views/_form_association_footer.html.erb | 12 ++++++++---- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index be8d61ff3d..567ba8d90a 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -16,16 +16,12 @@ $(document).ready(function() { if (loading_indicator) loading_indicator.css('visibility','hidden'); $('input[type=submit]', as_form).attr('disabled', ''); $("input:disabled", as_form).attr('disabled', ''); - //event.stop(); - //return false; } }); $('form.as_form').live('ajax:failure', function(event) { var as_div = $(this).closest("div.active-scaffold"); if (as_div) { ActiveScaffold.report_500_response(as_div) - event.stop(); - return false; } }); $('a.as_action').live('ajax:before', function(event) { @@ -217,6 +213,12 @@ $(document).ready(function() { $(this).prevAll('img.loading-indicator').css('visibility','hidden'); return true; }); + $('input[type=button].as_add_existing').live('ajax:before', function(event) { + var url = $(this).attr('href').replace('--ID--', $(this).prev().val()); + event.data_url = url; + return true; + }); + }); /* Simple Inheritance @@ -388,6 +390,11 @@ var ActiveScaffold = { $(element).hide(); }, + show: function(element) { + if (typeof(element) == 'string') element = '#' + element; + $(element).show(); + }, + create_record_row: function(tbody, html) { if (typeof(tbody) == 'string') tbody = '#' + tbody; tbody = $(tbody); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index a41a0ed280..f682e836e1 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -229,8 +229,12 @@ document.observe("dom:loaded", function() { if(loading_indicator) loading_indicator.style.visibility = 'hidden'; return true; }); - - + document.on('ajax:before', 'input[type=button].as_add_existing', function(event) { + var button = event.findElement(); + var url = button.readAttribute('href').sub('--ID--', button.previous().getValue()); + event.memo.url = url; + return true; + }); }); @@ -333,6 +337,10 @@ var ActiveScaffold = { $(element).hide(); }, + show: function(element) { + $(element).show(); + }, + create_record_row: function(tbody, html) { tbody = $(tbody); tbody.insert({top: html}); diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index cdebe05281..71b69585da 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -17,8 +17,10 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as <div class="footer-wrapper"> <div class="footer"> <% if show_add_new -%> - <% add_label = column.plural_association? ? as_(:create_another, :model => column.association.klass.model_name.human) : as_(:replace_with_new) -%> - <%= button_to_function add_label, "new Ajax.Request(#{add_new_url.to_json}, {asynchronous: true, method: 'get', evalScripts: true, onFailure: function(){ActiveScaffold.report_500_response(#{active_scaffold_id.to_json})}})" %> + <% add_label = column.plural_association? ? as_(:create_another, :model => column.association.klass.model_name.human) : as_(:replace_with_new) + create_another_id = "#{sub_form_id(:association => column.name)}-create-another" %> + <%= tag(:input, {:id => create_another_id, :type => 'button', :value => add_label, :href => add_new_url.html_safe, 'data-remote' => true, :style=> "display: none;"}) %> + <%= javascript_tag("ActiveScaffold.show('#{create_another_id}');") %> <% end -%> <%= '|' if show_add_new and show_add_existing %> @@ -27,9 +29,11 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as <% if remote_controller and remote_controller.respond_to? :uses_record_select? and remote_controller.uses_record_select? -%> <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "new Ajax.Request(#{edit_associated_url.to_json}.sub('--ID--', id), {asynchronous: true, evalScripts: true, onFailure: function(){ActiveScaffold.report_500_response(#{active_scaffold_id.to_json})}});" -%> <% else -%> - <% select_options = options_for_select(options_for_association(column.association)) -%> + <% select_options = options_for_select(options_for_association(column.association)) + add_existing_id = "#{sub_form_id(:association => column.name)}-add-existing" %> <%= select_tag 'associated_id', '<option value="">'.html_safe + as_(:_select_) + '</option>'.html_safe + select_options %> - <%= button_to_function as_(:add_existing), "new Ajax.Request(#{edit_associated_url.to_json}.sub('--ID--', Element.previous(this).value), {asynchronous: true, method: 'get', evalScripts: true, onFailure: function(){ActiveScaffold.report_500_response(#{active_scaffold_id.to_json})}})" %> + <%= tag(:input, {:id => add_existing_id, :type => 'button', :value => as_(:add_existing), :href => edit_associated_url.html_safe, 'data-remote' => true, :class=> 'as_add_existing', :style => "display: none;"}) %> + <%= javascript_tag("ActiveScaffold.show('#{add_existing_id}');") %> <% end -%> <% end -%> </div> From d3ab75d255639ec537e6a5548a0ac457055fa74c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 19 Aug 2010 11:58:31 +0200 Subject: [PATCH 0560/2024] Bugfix: use a unique id --- frontends/default/views/_form_association.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index 958881a9d0..8ede212341 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -4,7 +4,7 @@ associated = column.singular_association? ? [parent_record.send(column.name)].co associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) associated << column.association.klass.new if column.show_blank_record? associated -subform_div_id = sub_form_id({:association => column.name, :id => parent_record.id || 99999999999}) +subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_record.id || 99999999999})}-div" -%> <h5><%= column.label -%></h5> <div id ="<%= subform_div_id %>" <%= 'style="display: none;"'.html_safe if column.collapsed -%>> From 6998c6ac05debed6be98214e875b78744389a12e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 19 Aug 2010 14:03:39 +0200 Subject: [PATCH 0561/2024] destroy_link in subform running with Rails 3 --- .../views/_horizontal_subform_record.html.erb | 24 ++++++++++++------- .../views/_vertical_subform_record.html.erb | 13 ++++++---- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index 1388f92b9d..803db1c5da 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -1,9 +1,12 @@ -<% record_column = column -%> -<% readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) -%> -<% crud_type = @record.new_record? ? :create : (readonly ? :read : nil) -%> -<% show_actions = false -%> -<% config = active_scaffold_config_for(@record.class) -%> -<tr class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> +<% record_column = column + readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) + crud_type = @record.new_record? ? :create : (readonly ? :read : nil) + show_actions = false + config = active_scaffold_config_for(@record.class) + options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) + tr_id = "association-#{options[:id]}" +%> +<tr id=<%= tr_id %> class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> <% config.subform.columns.each :for => @record.class, :crud_type => crud_type, :flatten => true do |column| %> <% next unless in_subform?(column, parent_record) @@ -21,10 +24,13 @@ <% end -%> <% if show_actions -%> <td class="actions"> - <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> + <% if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> + <% destroy_id = "#{options[:id]}-destroy" %> + <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.remove(\"#{tr_id}\"); return false;", :style=> "display: none;" %> + <%= javascript_tag("ActiveScaffold.show('#{destroy_id}');") if !locked %> + <% end %> <% unless @record.new_record? %> - <% options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) -%> - <input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= @record.id -%>" /> + <input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= @record.id -%>" /> <% end -%> </td> <% end -%> diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index 594a4b5738..325f186b2c 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -4,8 +4,10 @@ crud_type = @record.new_record? ? :create : (readonly ? :read : nil) show_actions = false config = active_scaffold_config_for(@record.class) + options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) + tr_id = "association-#{options[:id]}" -%> -<ol class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> +<ol id=<%= tr_id %> class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> <% config.subform.columns.each :for => @record, :crud_type => crud_type, :flatten => true do |column| %> <% next unless in_subform?(column, parent_record) @@ -23,10 +25,13 @@ <% end -%> <% if show_actions -%> <li class="actions"> - <%= link_to_function as_(:remove), '$(this).up(".association-record").remove()', { :class => "destroy" } if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> + <% if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> + <% destroy_id = "#{options[:id]}-destroy" %> + <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.remove(\"#{tr_id}\"); return false;", :style=> "display: none;" %> + <%= javascript_tag("ActiveScaffold.show('#{destroy_id}');") if !locked %> + <% end %> <% unless @record.new_record? %> - <% options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) -%> - <input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= @record.id -%>" /> + <input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= @record.id -%>" /> <% end -%> </li> <% end -%> From c5f610ac7025f6ea41085da25e755ba24a45e2d9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 19 Aug 2010 14:49:46 +0200 Subject: [PATCH 0562/2024] do not show columns in form which represent readonly associations --- frontends/default/views/_form.html.erb | 1 + lib/active_scaffold/data_structures/column.rb | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index feefeeaec4..9716740628 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -1,6 +1,7 @@ <% subsection_id ||= nil %> <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= 'style="display: none;"' if columns.collapsed -%>> <% columns.each :for => @record do |column| -%> + <% next if column.readonly_association? %> <% if is_subsection? column -%> <% subsection_id = sub_section_id(:sub_section => column.label) %> <li class="sub-section"> diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 32ffa1cd37..a036b538a1 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -215,6 +215,15 @@ def through_association? def polymorphic_association? self.association and self.association.options.has_key? :polymorphic and self.association.options[:polymorphic] end + def readonly_association? + if self.association + if self.association.options.has_key? :readonly + self.association.options[:readonly] + else + self.through_association? + end + end + end # an interpreted property. the column is virtual if it isn't from the active record model or any associated models def virtual? From b39675e849da215fe75cf17d60521c953e5d573c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 19 Aug 2010 15:39:52 +0200 Subject: [PATCH 0563/2024] Bugfix: do not delete nested params if not all of them are present --- lib/active_scaffold/actions/nested.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 7ec5f73d9d..5d04bf81fe 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -34,8 +34,8 @@ def set_nested active_scaffold_session_storage[:nested] = {:parent_model => params[:parent_model].constantize, :name => params[:association].to_sym, :parent_id => params[:assoc_id]} + params.delete_if {|key, value| [:parent_model, :association, :assoc_id].include? key.to_sym} end - params.delete_if {|key, value| [:parent_model, :association, :assoc_id].include? key.to_sym} end def set_nested_list_label From fd3606ef8eef5e20453fbf3a75247648b255fcf6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 20 Aug 2010 10:21:13 +0200 Subject: [PATCH 0564/2024] edit_associated for non-singular association running --- frontends/default/javascripts/jquery/active_scaffold.js | 8 ++++++++ .../default/javascripts/prototype/active_scaffold.js | 7 +++++++ frontends/default/views/edit_associated.js.rjs | 9 ++++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 567ba8d90a..0f9aec1854 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -493,6 +493,14 @@ var ActiveScaffold = { toggable.toggle(); $(this).html((toggable.is(':hidden')) ? options.show_label : options.hide_label); }); + }, + + create_associated_record_form: function(element, content, options) { + if (typeof(element) == 'string') element = '#' + element; + var element = $(element); + if (!(options.id && $(options.id))) { + element.append(content); + } } } diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index f682e836e1..f7af1a6342 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -429,6 +429,13 @@ var ActiveScaffold = { toggable.toggle(); element.innerHTML = (toggable.style.display == 'none') ? options.show_label : options.hide_label; }); + }, + + create_associated_record_form: function(element, content, options) { + var element = $(element); + if (!(options.id && $(options.id))) { + element.insert(content); + } } } diff --git a/frontends/default/views/edit_associated.js.rjs b/frontends/default/views/edit_associated.js.rjs index a9715c564c..1665cc0343 100644 --- a/frontends/default/views/edit_associated.js.rjs +++ b/frontends/default/views/edit_associated.js.rjs @@ -1,5 +1,5 @@ associated_form = render :partial => "#{subform_partial_for_column(@column)}_record", :locals => {:scope => @scope, :parent_record => @parent_record, :column => @column, :locked => @record.new_record? && @column.singular_association?} - +options = {} if @column.singular_association? page << %| associated = #{associated_form.to_json}; @@ -12,9 +12,8 @@ if @column.singular_association? else unless @record.new_record? column = active_scaffold_config_for(@record.class).columns[@record.class.primary_key] - id = active_scaffold_input_options(column, @scope)[:id] - page << "if (!$('#{id}')) {" + options[:id] = active_scaffold_input_options(column, @scope)[:id] end - page.insert_html :bottom, sub_form_list_id(:association => @column.name), associated_form - page << "}" unless @record.new_record? + page.call 'ActiveScaffold.create_associated_record_form', sub_form_list_id(:association => @column.name), associated_form, options.to_json + end From 6850c9a661aa9d1bd4bc4e1a7fd09bafa395971c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 20 Aug 2010 10:36:27 +0200 Subject: [PATCH 0565/2024] Workaround: Protype or rails seem to screw up event handling if create_another button is clicked --- .../javascripts/prototype/active_scaffold.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index f7af1a6342..6fda748c34 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -13,11 +13,18 @@ if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFu document.observe("dom:loaded", function() { document.on('ajax:loading', 'form.as_form', function(event) { + var source = event.findElement(); var as_form = event.findElement('form'); - if (as_form && as_form.readAttribute('data-loading') == 'true') { - var loading_indicator = $(as_form.id.sub('-form', '-loading-indicator')); - if (loading_indicator) loading_indicator.style.visibility = 'visible'; - as_form.disable(); + if (source.nodeName.toUpperCase() == 'INPUT' && source.readAttribute('type') == 'button') { + // Hack: Prototype or rails.js somehow screw up event handling if someone clicks + // a button of type button such as Create Another <Association> + // as a result form is disabled but never reenabled.. + } else { + if (as_form && as_form.readAttribute('data-loading') == 'true') { + var loading_indicator = $(as_form.id.sub('-form', '-loading-indicator')); + if (loading_indicator) loading_indicator.style.visibility = 'visible'; + as_form.disable(); + } } return true; }); From ac56e3d9562ba3959a156a7eeacc1c0fccef84ff Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 20 Aug 2010 10:39:54 +0200 Subject: [PATCH 0566/2024] remove warning: don't put space before argument parentheses --- frontends/default/views/on_update.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 5e245de8ad..f761ca38e8 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -10,6 +10,6 @@ if controller.send :successful? page << "ActiveScaffold.find_action_link('#{form_selector}').close('#{escape_javascript(updated_row)}');" page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} else - page.call 'ActiveScaffold.replace', form_selector, render (:partial => 'update_form', :locals => {:xhr => true}) + page.call 'ActiveScaffold.replace', form_selector, render(:partial => 'update_form', :locals => {:xhr => true}) page.call 'ActiveScaffold.scroll_to', form_selector end From c421558ebb9ec45e687caa2eacb17ea55c7ab5e7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 20 Aug 2010 11:12:59 +0200 Subject: [PATCH 0567/2024] edit_associated for singular associations running --- .../default/javascripts/jquery/active_scaffold.js | 12 ++++++++++-- .../javascripts/prototype/active_scaffold.js | 12 ++++++++++-- frontends/default/views/edit_associated.js.rjs | 14 +++----------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 0f9aec1854..7fc54cf7fe 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -498,8 +498,16 @@ var ActiveScaffold = { create_associated_record_form: function(element, content, options) { if (typeof(element) == 'string') element = '#' + element; var element = $(element); - if (!(options.id && $(options.id))) { - element.append(content); + if (options.singular == false) { + if (!(options.id && $(options.id))) { + element.append(content); + } + } else { + if (current = $('#' + element.attr('id') + '.association-record')[0]) { + this.replace(current, content); + } else { + element.prepend(content); + } } } } diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 6fda748c34..04096f87c7 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -440,8 +440,16 @@ var ActiveScaffold = { create_associated_record_form: function(element, content, options) { var element = $(element); - if (!(options.id && $(options.id))) { - element.insert(content); + if (options.singular == false) { + if (!(options.id && $(options.id))) { + element.insert(content); + } + } else { + if (current = $$('#' + element.id + '.association-record')[0]) { + this.replace(current, content); + } else { + element.insert({top: content}); + } } } diff --git a/frontends/default/views/edit_associated.js.rjs b/frontends/default/views/edit_associated.js.rjs index 1665cc0343..07f0834e6b 100644 --- a/frontends/default/views/edit_associated.js.rjs +++ b/frontends/default/views/edit_associated.js.rjs @@ -1,19 +1,11 @@ associated_form = render :partial => "#{subform_partial_for_column(@column)}_record", :locals => {:scope => @scope, :parent_record => @parent_record, :column => @column, :locked => @record.new_record? && @column.singular_association?} -options = {} +options = {:singular => false} if @column.singular_association? - page << %| - associated = #{associated_form.to_json}; - if (current = $$('##{sub_form_list_id(:association => @column.name)} .association-record')[0]) { - Element.replace(current, associated) - } else { - new Insertion.Top('#{sub_form_list_id(:association => @column.name)}', associated) - } - | + options[:singular] = true else unless @record.new_record? column = active_scaffold_config_for(@record.class).columns[@record.class.primary_key] options[:id] = active_scaffold_input_options(column, @scope)[:id] end - page.call 'ActiveScaffold.create_associated_record_form', sub_form_list_id(:association => @column.name), associated_form, options.to_json - end +page.call 'ActiveScaffold.create_associated_record_form', sub_form_list_id(:association => @column.name), associated_form, options.to_json From 49947b61a6e8f8ec3b901dea08b106fd7dd84276 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 20 Aug 2010 14:36:56 +0200 Subject: [PATCH 0568/2024] Bugfix: generate a correct source path and only cp js files for javascript --- install_assets.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/install_assets.rb b/install_assets.rb index 7a1e1041d2..4351d80e7f 100755 --- a/install_assets.rb +++ b/install_assets.rb @@ -6,13 +6,13 @@ ## Copy over asset files (javascript/css/images) from the plugin directory to public/ ## -def copy_files(source_path, destination_path, directory, clean_up_destination = false) +def copy_files(source_path, destination_path, directory, file_mask = '*.*', clean_up_destination = false) source, destination = File.join(directory, source_path), File.join(Rails.root, destination_path) FileUtils.mkdir_p(destination) unless File.exist?(destination) Dir.glob('*.so') FileUtils.rm Dir.glob("#{destination}/*") if clean_up_destination - FileUtils.cp_r(Dir.glob(source+'/*.*'), destination) + FileUtils.cp_r(Dir.glob("#{source}/#{file_mask}"), destination) end directory = File.dirname(__FILE__) @@ -31,12 +31,14 @@ def copy_files(source_path, destination_path, directory, clean_up_destination = available_frontends.each do |frontend| if asset_type == :javascripts - source = "/frontends/#{frontend}/#{asset_type}/#{ActiveScaffold.js_framework}/" + file_mask = '*.js' + source = "/frontends/#{frontend}/#{asset_type}/#{ActiveScaffold.js_framework}" else - source = "/frontends/#{frontend}/#{asset_type}/" + file_mask = '*.*' + source = "/frontends/#{frontend}/#{asset_type}" end destination = "/public/#{asset_type}/active_scaffold/#{frontend}" - copy_files(source, destination, directory, true) + copy_files(source, destination, directory, file_mask, true) end end From 21d1c2ba8bc0ebdb9d8a61d989dd50d4614e146e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 20 Aug 2010 14:43:33 +0200 Subject: [PATCH 0569/2024] generate correct id selector for javascript call --- frontends/default/views/_list_inline_adapter.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index 0b5e9af4d9..761ae64cf2 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -7,4 +7,5 @@ </div> </td> </tr> -<%= javascript_tag("$('#{element_row_id(:action => :nested)}').action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');") %> +<% row_id = "#{ActiveScaffold.js_framework == :jquery ? '#' : ''}#{element_row_id(:action => :nested)}" %> +<%= javascript_tag("$('#{row_id}').action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');") %> From ca5681b7a6011d604d513787b5691aa34080d09b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 20 Aug 2010 14:45:20 +0200 Subject: [PATCH 0570/2024] generate a valid html id attribute --- frontends/default/views/_horizontal_subform_record.html.erb | 2 +- frontends/default/views/_vertical_subform_record.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index 803db1c5da..c1d91f7b40 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -6,7 +6,7 @@ options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) tr_id = "association-#{options[:id]}" %> -<tr id=<%= tr_id %> class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> +<tr id="<%= tr_id %>" class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> <% config.subform.columns.each :for => @record.class, :crud_type => crud_type, :flatten => true do |column| %> <% next unless in_subform?(column, parent_record) diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index 325f186b2c..aa646ec8c9 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -7,7 +7,7 @@ options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) tr_id = "association-#{options[:id]}" -%> -<ol id=<%= tr_id %> class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> +<ol id="<%= tr_id %>" class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> <% config.subform.columns.each :for => @record, :crud_type => crud_type, :flatten => true do |column| %> <% next unless in_subform?(column, parent_record) From 6f44b58600e0a2b10fd2536a47ce18975234e187 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 20 Aug 2010 14:46:39 +0200 Subject: [PATCH 0571/2024] Bugfix: do not call .to_json for params in page.call --- frontends/default/views/edit_associated.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/edit_associated.js.rjs b/frontends/default/views/edit_associated.js.rjs index 07f0834e6b..1afaba9998 100644 --- a/frontends/default/views/edit_associated.js.rjs +++ b/frontends/default/views/edit_associated.js.rjs @@ -8,4 +8,4 @@ else options[:id] = active_scaffold_input_options(column, @scope)[:id] end end -page.call 'ActiveScaffold.create_associated_record_form', sub_form_list_id(:association => @column.name), associated_form, options.to_json +page.call 'ActiveScaffold.create_associated_record_form', sub_form_list_id(:association => @column.name), associated_form, options From 5c5416d80c1194d4d17a591de4c919722555c496 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 20 Aug 2010 16:12:44 +0200 Subject: [PATCH 0572/2024] get update_column running with rails 3 --- .../javascripts/jquery/active_scaffold.js | 38 +++++++++++++++++-- .../javascripts/prototype/active_scaffold.js | 27 +++++++++++++ frontends/default/views/render_field.js.rjs | 5 ++- .../helpers/form_column_helpers.rb | 8 ++-- 4 files changed, 67 insertions(+), 11 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 7fc54cf7fe..ae468be9f1 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -5,7 +5,7 @@ $(document).ready(function() { var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); if (loading_indicator) loading_indicator.css('visibility','visible'); $('input[type=submit]', as_form).attr('disabled', 'disabled'); - $("input:disabled", as_form).attr('disabled', 'disabled'); + $("input:enabled,select:enabled", as_form).attr('disabled', 'disabled'); } return true; }); @@ -15,7 +15,7 @@ $(document).ready(function() { var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); if (loading_indicator) loading_indicator.css('visibility','hidden'); $('input[type=submit]', as_form).attr('disabled', ''); - $("input:disabled", as_form).attr('disabled', ''); + $("input:disabled,select:disabled", as_form).attr('disabled', ''); } }); $('form.as_form').live('ajax:failure', function(event) { @@ -218,7 +218,25 @@ $(document).ready(function() { event.data_url = url; return true; }); - + $('input.update_form').live('change', function(event) { + var element = $(this); + var as_form = element.closest('form.as_form'); + $.ajax({ + url: element.attr('data-update_url'), + data: {value: element.val()}, + beforeSend: function(event) { + element.nextAll('img.loading-indicator').css('visibility','visible'); + $('input[type=submit]', as_form).attr('disabled', 'disabled'); + $("input:enabled,select:enabled", as_form).attr('disabled', 'disabled'); + }, + complete: function(event) { + element.nextAll('img.loading-indicator').css('visibility','hidden'); + $('input[type=submit]', as_form).attr('disabled', ''); + $("input:disabled,select:disabled", as_form).attr('disabled', ''); + } + }); + return true; + }); }); /* Simple Inheritance @@ -370,7 +388,9 @@ var ActiveScaffold = { if (typeof(element) == 'string') element = '#' + element; element = $(element); element.replaceWith(html); - element = $('#' + element.attr('id')); + if (element.attr('id')) { + element = $('#' + element.attr('id')); + } return element; }, @@ -509,6 +529,16 @@ var ActiveScaffold = { element.prepend(content); } } + }, + + render_form_field: function(element, content, options) { + if (typeof(element) == 'string') element = '#' + element; + var element = $(element); + if (options.is_subform == false) { + this.replace(element.closest('dl'), content); + } else { + this.replace_html(element, content); + } } } diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 04096f87c7..f3fd4865a6 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -241,6 +241,24 @@ document.observe("dom:loaded", function() { var url = button.readAttribute('href').sub('--ID--', button.previous().getValue()); event.memo.url = url; return true; + }); + document.on('change', 'input.update_form', function(event) { + var element = event.findElement(); + var as_form = element.up('form.as_form'); + + new Ajax.Request(element.readAttribute('data-update_url'), { + method: 'get', + parameters: {value: element.getValue()}, + onLoading: function(response) { + element.next('img.loading-indicator').style.visibility = 'visible'; + as_form.disable(); + }, + onComplete: function(response) { + element.next('img.loading-indicator').style.visibility = 'hidden'; + as_form.enable(); + } + }); + return true; }); }); @@ -451,6 +469,15 @@ var ActiveScaffold = { element.insert({top: content}); } } + }, + + render_form_field: function(element, content, options) { + var element = $(element); + if (options.is_subform == false) { + this.replace(element.up('dl'), content); + } else { + this.replace_html(element, content); + } } } diff --git a/frontends/default/views/render_field.js.rjs b/frontends/default/views/render_field.js.rjs index aa4449435e..b34c161d75 100644 --- a/frontends/default/views/render_field.js.rjs +++ b/frontends/default/views/render_field.js.rjs @@ -1,13 +1,14 @@ @update_columns.each do |update_column| column = update_column while column + options = {:is_subform => false} if column_renders_as(column) == :subform + options[:is_subform] = true field_id = sub_form_id(:association => column.name) - page[field_id].replace_html :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } else field_id = active_scaffold_input_options(column, params[:scope])[:id] - page[field_id].up('dl').replace :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } end + page.call 'ActiveScaffold.render_form_field', field_id, render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] }), options column = Hash === column.options ? column.options[:update_column] : nil column = active_scaffold_config.columns[column] if column end diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 0f69df4652..02d80119ec 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -75,11 +75,9 @@ def javascript_for_update_column(column, scope, options) url_params[:eid] = params[:eid] if params[:eid] url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope url_params[:scope] = params[:scope] if scope - ajax_options = {:method => :get, - :url => url_for(url_params), :with => "'value=' + this.value", - :after => "$('#{loading_indicator_id(:action => :render_field, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => form_action)}');", - :complete => "$('#{loading_indicator_id(:action => :render_field, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => form_action)}');"} - options[:onchange] = "#{remote_function(ajax_options)};#{options[:onchange]}" + + options[:class] = "#{options[:class]} update_form".strip + options['data-update_url'] = url_for(url_params) end options end From dcdffe17abc74143f0f5be865b7ed926bf753b62 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 23 Aug 2010 10:03:25 +0200 Subject: [PATCH 0573/2024] jquery: basic support for embedded controllers without render_component --- lib/extensions/action_view_rendering.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index b979b71dba..7fd7830197 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -68,7 +68,11 @@ def render_with_active_scaffold(*args, &block) content_tag(:div, {:id => id}) do url = url_for(url_options) link_to(remote_controller.to_s, url, {:remote => true, :id => id}) << - javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true})") + if ActiveScaffold.js_framework == :prototype + javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true});") + elsif ActiveScaffold.js_framework == :jquery + javascript_tag("$('##{id}').load('#{url}');") + end end end From 2eedeaf98cfd9676a293de0c831f2400670898b1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 23 Aug 2010 11:09:51 +0200 Subject: [PATCH 0574/2024] Fix sending all form on update column with record_select --- frontends/default/views/_form_association_footer.html.erb | 2 +- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index 8ae4912a38..5cd90bff86 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -25,7 +25,7 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as <% if show_add_existing -%> <% if remote_controller and remote_controller.respond_to? :uses_record_select? and remote_controller.uses_record_select? -%> - <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "new Ajax.Request(#{edit_associated_url.to_json}.sub('--ID--', id), {asynchronous: true, evalScripts: true, onFailure: function(){ActiveScaffold.report_500_response(#{active_scaffold_id.to_json})}});" -%> + <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "new Ajax.Request(#{edit_associated_url.to_json}.sub('--ID--', id), {asynchronous: true, method: 'get', evalScripts: true, onFailure: function(){ActiveScaffold.report_500_response(#{active_scaffold_id.to_json})}});" -%> <% else -%> <% select_options = options_for_select(options_for_association(column.association)) -%> <%= select_tag 'associated_id', '<option value="">' + as_(:_select_) + '</option>' + select_options %> diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 35919c5f1b..69eee5a270 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -89,7 +89,7 @@ def javascript_for_update_column(column, scope, options) } url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope ajax_options = {:method => :get, - :url => url_for(url_params), :with => column.send_form_on_update_column ? "Form.serialize(this.form)" : "'value=' + this.value", + :url => url_for(url_params), :with => column.send_form_on_update_column ? "Form.serialize('#{element_form_id(:action => form_action)}')" : "'value=' + this.value", :after => "$('#{loading_indicator_id(:action => form_action, :id => params[:id])}').style.visibility = 'visible'; Form.disable('#{element_form_id(:action => form_action)}');", :complete => "$('#{loading_indicator_id(:action => form_action, :id => params[:id])}').style.visibility = 'hidden'; Form.enable('#{element_form_id(:action => form_action)}');"} options[:onchange] = "#{remote_function(ajax_options)};#{options[:onchange]}" From 1366f99223c8333887de235da2c09488148a28e9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 23 Aug 2010 11:23:00 +0200 Subject: [PATCH 0575/2024] Allow to set html options for checkbox form_ui --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 69eee5a270..475dd27fbd 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -176,7 +176,7 @@ def active_scaffold_input_radio(column, html_options) end def active_scaffold_input_checkbox(column, options) - check_box(:record, column.name, options) + check_box(:record, column.name, options.merge(column.options)) end def active_scaffold_input_password(column, options) From 8c1843a2e22617ea04356dda770c48cd2080f12b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 23 Aug 2010 12:12:54 +0200 Subject: [PATCH 0576/2024] Bugfix: render partial messages in replace_html call --- frontends/default/views/destroy.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/destroy.js.rjs b/frontends/default/views/destroy.js.rjs index cc0a0c81c1..a69fe0d127 100644 --- a/frontends/default/views/destroy.js.rjs +++ b/frontends/default/views/destroy.js.rjs @@ -2,4 +2,4 @@ if controller.send(:successful?) page << "ActiveScaffold.delete_record_row('#{element_row_id(:action => 'list', :id => params[:id])}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} end -page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, :partial => 'messages' +page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages') From 2d3e6d3de54edeac1cc0c970d533afb34036ac65 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 23 Aug 2010 12:14:44 +0200 Subject: [PATCH 0577/2024] get add_existing running with rails 3 --- .../default/javascripts/jquery/active_scaffold.js | 10 ++++++++++ .../javascripts/prototype/active_scaffold.js | 8 ++++++++ .../default/views/_add_existing_form.html.erb | 5 ++--- frontends/default/views/add_existing.js.rjs | 14 ++++++++------ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index ae468be9f1..a38ee2002d 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -415,6 +415,16 @@ var ActiveScaffold = { $(element).show(); }, + reset_form: function(element) { + if (typeof(element) == 'string') element = '#' + element; + $(element).get(0).reset(); + }, + + focus_first_element_of_form: function(form_element) { + if (typeof(form_element) == 'string') form_element = '#' + form_element; + $("#{form_element}:first *:input[type!=hidden]:first").focus(); + }, + create_record_row: function(tbody, html) { if (typeof(tbody) == 'string') tbody = '#' + tbody; tbody = $(tbody); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index f3fd4865a6..6238e725cd 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -366,6 +366,14 @@ var ActiveScaffold = { $(element).show(); }, + reset_form: function(element) { + $(element).reset(); + }, + + focus_first_element_of_form: function(form_element) { + Form.focusFirstElement(form_element); + }, + create_record_row: function(tbody, html) { tbody = $(tbody); tbody.insert({top: html}); diff --git a/frontends/default/views/_add_existing_form.html.erb b/frontends/default/views/_add_existing_form.html.erb index 4a918bdf44..7feb11a6b4 100644 --- a/frontends/default/views/_add_existing_form.html.erb +++ b/frontends/default/views/_add_existing_form.html.erb @@ -26,6 +26,5 @@ options = {:id => element_form_id(:action => :add_existing), </p> </form> -<script type="text/javascript"> -Form.focusFirstElement('<%= element_form_id(:action => :add_existing) -%>'); -</script> +<%= javascript_tag("ActiveScaffold.focus_first_element_of_form('#{element_form_id(:action => :add_existing)}');") %> + diff --git a/frontends/default/views/add_existing.js.rjs b/frontends/default/views/add_existing.js.rjs index abf5abfaff..88cabc8239 100644 --- a/frontends/default/views/add_existing.js.rjs +++ b/frontends/default/views/add_existing.js.rjs @@ -1,15 +1,17 @@ new_row = render :partial => 'list_record', :locals => {:record => @record} page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}');" -page.replace active_scaffold_calculations_id, :partial => 'list_calculations' if active_scaffold_config.list.columns.any? {|c| c.calculation?} +page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} if (form_stays_open = true) # why not just re-render the form? that wouldn't utilize a possible do_new override which sets default values. - page << "$('#{element_form_id}').reset()" - page.replace_html element_messages_id(:action => :add_existing), :partial => 'form_messages' + page.call 'ActiveScaffold.reset_form', element_form_id + page.call 'ActiveScaffold.replace_html', element_messages_id(:action => :add_existing), render(:partial => 'form_messages') # have to delay the focus, because there's no "firstElement" in prototype until at least one element is not disabled - page.delay 0.1 do - page << "Form.focusFirstElement('#{element_form_id}');" + if ActiveScaffold.js_framework == :prototype + page.delay 0.1 do + page << "ActiveScaffold.focus_first_element_of_form('#{element_form_id}');" + end end else - page << "$$('##{element_form_id(:action => :new_existing)} a.cancel').first().link.close();" + page << "ActiveScaffold.find_action_link('#{element_form_id(:action => :new_existing)}').close();" end \ No newline at end of file From 9d495312baeddbc94a6058979fb37077f38366cd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 23 Aug 2010 12:16:33 +0200 Subject: [PATCH 0578/2024] add_existing: record_select mode only if prototype is in use --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 02d80119ec..4f12c50aa8 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -316,7 +316,7 @@ def column_scope(column) end def active_scaffold_add_existing_input(options) - if controller.respond_to?(:record_select_config) + if ActiveScaffold.js_framework == :prototype && controller.respond_to?(:record_select_config) remote_controller = active_scaffold_controller_for(record_select_config.model).controller_path options.merge!(:controller => remote_controller) options.merge!(active_scaffold_input_text_options) From c4d2d8dac8af121054e7714744185ebd05c1cc06 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 23 Aug 2010 12:30:02 +0200 Subject: [PATCH 0579/2024] Bugfix: jquery reload_if_empty used prototype code --- frontends/default/javascripts/jquery/active_scaffold.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index a38ee2002d..dc48537af6 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -339,11 +339,7 @@ var ActiveScaffold = { }, reload_if_empty: function(tbody, url) { if (this.records_for(tbody).length == 0) { - new Ajax.Request(url, { - method: 'get', - asynchronous: true, - evalScripts: true - }); + $.getScript(url); } }, removeSortClasses: function(scaffold) { From 6b0694c11699985228e812aeeb765efd1e2ec150 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 23 Aug 2010 16:14:38 +0200 Subject: [PATCH 0580/2024] renamed column attribute update_column to update_columns and some code cleanup --- frontends/default/views/_form_attribute.html.erb | 2 +- frontends/default/views/_render_field.js.rjs | 13 +++++++++++++ frontends/default/views/render_field.js.rjs | 15 --------------- lib/active_scaffold/actions/core.rb | 4 +--- lib/active_scaffold/data_structures/column.rb | 9 +++++++++ .../helpers/form_column_helpers.rb | 11 +++++------ .../helpers/list_column_helpers.rb | 1 - 7 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 frontends/default/views/_render_field.js.rjs delete mode 100644 frontends/default/views/render_field.js.rjs diff --git a/frontends/default/views/_form_attribute.html.erb b/frontends/default/views/_form_attribute.html.erb index 821d97843d..ce5aa6cce3 100644 --- a/frontends/default/views/_form_attribute.html.erb +++ b/frontends/default/views/_form_attribute.html.erb @@ -5,7 +5,7 @@ </dt> <dd> <%= active_scaffold_input_for column, scope %> - <% if column.options.is_a?(Hash) && column.options[:update_column] -%> + <% if column.update_columns -%> <%= loading_indicator_tag(:action => :render_field, :id => params[:id]) %> <% end -%> <% if column.description -%> diff --git a/frontends/default/views/_render_field.js.rjs b/frontends/default/views/_render_field.js.rjs new file mode 100644 index 0000000000..8c60611db2 --- /dev/null +++ b/frontends/default/views/_render_field.js.rjs @@ -0,0 +1,13 @@ +column = active_scaffold_config.columns[render_field.to_sym] +options = {:is_subform => false} +if column_renders_as(column) == :subform + options[:is_subform] = true + field_id = sub_form_id(:association => column.name) +else + field_id = active_scaffold_input_options(column, params[:scope])[:id] +end +page.call 'ActiveScaffold.render_form_field', field_id, render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] }), options +render(:partial => "render_field", :collection => column.update_columns) if column.update_columns && !column.update_columns.empty? + + + diff --git a/frontends/default/views/render_field.js.rjs b/frontends/default/views/render_field.js.rjs deleted file mode 100644 index b34c161d75..0000000000 --- a/frontends/default/views/render_field.js.rjs +++ /dev/null @@ -1,15 +0,0 @@ -@update_columns.each do |update_column| - column = update_column - while column - options = {:is_subform => false} - if column_renders_as(column) == :subform - options[:is_subform] = true - field_id = sub_form_id(:association => column.name) - else - field_id = active_scaffold_input_options(column, params[:scope])[:id] - end - page.call 'ActiveScaffold.render_form_field', field_id, render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] }), options - column = Hash === column.options ? column.options[:update_column] : nil - column = active_scaffold_config.columns[column] if column - end -end diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 93fd3b3296..9fba33252d 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -12,16 +12,14 @@ def render_field else active_scaffold_config.model.new end - @update_columns = [] column = active_scaffold_config.columns[params[:column]] if params[:in_place_editing] render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>" elsif !column.nil? value = column_value_from_param_value(@record, column, params[:value]) @record.send "#{column.name}=", value - @update_columns << Array(params[:update_column]).collect {|column_name| active_scaffold_config.columns[column_name.to_sym]} - @update_columns.flatten! after_render_field(@record, column) + render :partial => "render_field", :collection => Array(params[:update_columns]), :content_type => 'text/javascript' end end diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index a036b538a1..1b299d1e73 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -52,6 +52,15 @@ def description def required? @required end + + attr_reader :update_columns + + # update dependent columns after value change in form + # update_columns = :name + # update_columns = [:name, :age] + def update_columns=(column_names) + @update_columns = Array(column_names) + end # sorting on a column can be configured four ways: # sort = true default, uses intelligent sorting sql default diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 4f12c50aa8..a91ee7a9ea 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -7,7 +7,7 @@ module FormColumnHelpers def active_scaffold_input_for(column, scope = nil, options = {}) begin options = active_scaffold_input_options(column, scope, options) - options = javascript_for_update_column(column, scope, options) + options = update_columns_options(column, scope, options) # first, check if the dev has created an override for this specific field if override_form_field?(column) send(override_form_field(column), @record, options) @@ -67,11 +67,10 @@ def active_scaffold_input_options(column, scope = nil, options = {}) { :name => name, :class => "#{column.name}-input", :id => id_control}.merge(options) end - def javascript_for_update_column(column, scope, options) - if column.options[:update_column] - form_action = :create - form_action = :update if params[:action] == 'edit' - url_params = {:action => 'render_field', :id => params[:id], :column => column.name, :update_column => column.options[:update_column]} + def update_columns_options(column, scope, options) + if column.update_columns + form_action = params[:action] == 'edit' ? :update : :create + url_params = {:action => 'render_field', :id => params[:id], :column => column.name, :update_columns => column.update_columns} url_params[:eid] = params[:eid] if params[:eid] url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope url_params[:scope] = params[:scope] if scope diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index bb4c86299e..8fcc060dfa 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -277,7 +277,6 @@ def inplace_edit_control(column) @record = active_scaffold_config.model.new column = column.clone column.options = column.options.clone - column.options.delete(:update_column) column.form_ui = :select if (column.association && column.form_ui.nil?) content_tag(:div, active_scaffold_input_for(column), {:style => "display:none;", :class => inplace_edit_control_css_class}) end From 23291e8e64576f62ef3b5211e1003f6a3e21ac3b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 23 Aug 2010 16:26:04 +0200 Subject: [PATCH 0581/2024] if ajax request render_field fails show an error --- frontends/default/javascripts/jquery/active_scaffold.js | 6 ++++++ frontends/default/javascripts/prototype/active_scaffold.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index dc48537af6..37c0fd24b6 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -233,6 +233,12 @@ $(document).ready(function() { element.nextAll('img.loading-indicator').css('visibility','hidden'); $('input[type=submit]', as_form).attr('disabled', ''); $("input:disabled,select:disabled", as_form).attr('disabled', ''); + }, + error: function (xhr, status, error) { + var as_div = element.closest("div.active-scaffold"); + if (as_div) { + ActiveScaffold.report_500_response(as_div) + } } }); return true; diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 6238e725cd..01cd836949 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -256,6 +256,12 @@ document.observe("dom:loaded", function() { onComplete: function(response) { element.next('img.loading-indicator').style.visibility = 'hidden'; as_form.enable(); + }, + onFailure: function(request) { + var as_div = event.findElement('div.active-scaffold'); + if (as_div) { + ActiveScaffold.report_500_response(as_div) + } } }); return true; From 5cd53f89313ccbf3e9999a4ba7357ed2e216c013 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 24 Aug 2010 09:17:03 +0200 Subject: [PATCH 0582/2024] Fix inplace edit checkbox for sybase db --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index d2edbcd563..a814d9b8a3 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -164,7 +164,7 @@ def override_column_ui(list_ui) def format_column_checkbox(record, column) checked = ActionView::Helpers::InstanceTag.check_box_checked?(record.send(column.name), '1') - script = remote_function(:method => 'POST', :url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s, :value => !checked, :eid => params[:eid]}) + script = remote_function(:method => 'POST', :url => {:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => record.id.to_s, :value => checked ? false : 1, :eid => params[:eid]}) check_box(:record, column.name, :onclick => script, :id => nil, :object => record) end From c3750069a1b7d0e346931c093ae2d1719e7e91e3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 24 Aug 2010 11:17:04 +0200 Subject: [PATCH 0583/2024] improved hash_is_empty? detection --- lib/active_scaffold/attribute_params.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 5ba4dbcf6a..600215fb55 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -175,14 +175,18 @@ def find_or_create_for_params(params, parent_column, parent_record) # Determines whether the given attributes hash is "empty". # This isn't a literal emptiness - it's an attempt to discern whether the user intended it to be empty or not. def attributes_hash_is_empty?(hash, klass) + ignore_column_types = [:boolean] hash.all? do |key,value| # convert any possible multi-parameter attributes like 'created_at(5i)' to simply 'created_at' - column_name = key.to_s.split('(').first + parts = key.to_s.split('(') + #old style date form management... ignore them too + ignore_column_types = [:boolean, :datetime, :date, :time] if parts.length > 1 + column_name = parts.first column = klass.columns_hash[column_name] # booleans and datetimes will always have a value. so we ignore them when checking whether the hash is empty. # this could be a bad idea. but the current situation (excess record entry) seems worse. - next true if column and [:boolean, :datetime, :date, :time].include?(column.type) + next true if column and ignore_column_types.include?(column.type) # defaults are pre-filled on the form. we can't use them to determine if the user intends a new row. next true if column and value == column.default.to_s From ed87490d45383427d76d235fa57959b57f09c455 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 24 Aug 2010 16:22:56 +0200 Subject: [PATCH 0584/2024] add option to action_links to specify an image, useful if you just want to show an icon without text --- frontends/default/stylesheets/stylesheet.css | 11 +++++++++++ frontends/default/views/_list_actions.html.erb | 2 +- .../data_structures/action_link.rb | 4 ++++ lib/active_scaffold/helpers/view_helpers.rb | 15 +++++++++++++-- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index ad2861ab66..9217d65ba1 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -39,6 +39,17 @@ color: #999; background-color: #ff8; } +.active-scaffold div.actions a img, +.active-scaffold td.actions a img { +border: none; +vertical-align: middle; +} + +.active-scaffold div.actions a.disabled img, +.active-scaffold td.actions a.disabled img { +opacity: 0.5; +} + .active-scaffold .clear-fix { clear: both; } diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index f7f31df2df..4158403242 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -7,7 +7,7 @@ <% action_links.each :member do |link| -%> <% next if skip_action_link(link, record) -%> <td> - <%= raw record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : "<a class='disabled #{link.action}'>#{link.label}</a>" -%> + <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}) %> </td> <% end -%> </tr> diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 767d291ea9..8f7af06305 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -16,6 +16,7 @@ def initialize(action, options = {}) self.parameters = {} self.html_options = {} self.column = nil + self.image = nil # apply quick properties options.each_pair do |k, v| @@ -41,6 +42,9 @@ def initialize(action, options = {}) def label @label.is_a?(Symbol) ? as_(@label) : @label end + + # image to use {:name => 'arrow.png', :size => '16x16'} + attr_accessor :image # if the action requires confirmation attr_writer :confirm diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 6fa9dc75a8..c78781bcc2 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -159,9 +159,20 @@ def render_action_link(link, url_options, record = nil, html_options = {}) end html_options[:class] += " #{link.html_options[:class]}" unless link.html_options[:class].blank? + action_link_html(link, url_options, html_options) + end + + def action_link_html(link, url, html_options) # issue 260, use url_options[:link] if it exists. This prevents DB data from being localized. - label = url_options.delete(:link) || link.label - link_to label, url_options, html_options + label = url.delete(:link) if url.is_a?(Hash) + label ||= link.label + if link.image.nil? + html = link_to(label, url, html_options) + else + html = link_to(image_tag(link.image[:name] , :size => link.image[:size], :alt => label), url, html_options) + end + # if url is nil we would like to generate an anchor without href attribute + url.nil? ? html.sub(/href=".*?"/, '') : html end def url_options_for_nested_link(column, record, link, url_options) From c144d75fd25eb7eb820115cd0c45554198f4fd32 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 25 Aug 2010 12:53:48 +0200 Subject: [PATCH 0585/2024] Bugfix: calendar_date_select field search html_safe --- lib/active_scaffold/bridges/date_picker/bridge.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/active_scaffold/bridges/date_picker/bridge.rb b/lib/active_scaffold/bridges/date_picker/bridge.rb index f992a451f5..3e81ce2af6 100644 --- a/lib/active_scaffold/bridges/date_picker/bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/bridge.rb @@ -5,6 +5,8 @@ destination = File.join(Rails.root, "public/javascripts/active_scaffold/default/") if ActiveScaffold.js_framework == :jquery + date_options = I18n.t 'date' + Rails.logger.info(date_options.inspect) require File.join(directory, "lib/datepicker_bridge.rb") FileUtils.cp(source, destination) else From 010e3b87df46eb1303c5b34d34313dd2250cd6f2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 25 Aug 2010 15:35:38 +0200 Subject: [PATCH 0586/2024] revert change of last commit (wrong file committed) --- lib/active_scaffold/bridges/date_picker/bridge.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/bridge.rb b/lib/active_scaffold/bridges/date_picker/bridge.rb index 3e81ce2af6..f992a451f5 100644 --- a/lib/active_scaffold/bridges/date_picker/bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/bridge.rb @@ -5,8 +5,6 @@ destination = File.join(Rails.root, "public/javascripts/active_scaffold/default/") if ActiveScaffold.js_framework == :jquery - date_options = I18n.t 'date' - Rails.logger.info(date_options.inspect) require File.join(directory, "lib/datepicker_bridge.rb") FileUtils.cp(source, destination) else From 5ddffa1b083f14ea0324304d1b10301f8071bbd7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 25 Aug 2010 15:37:38 +0200 Subject: [PATCH 0587/2024] Bugfix: calendar-date_select field search html_safe --- .../bridges/calendar_date_select/lib/as_cds_bridge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb index d7f48af60e..8ba074b331 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb @@ -39,7 +39,7 @@ def active_scaffold_search_calendar_date_select(column, options) html = [] html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[from]", :id => "#{options[:id]}_from", :value => from_value)) html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[to]", :id => "#{options[:id]}_to", :value => to_value)) - html * ' - ' + (html * ' - ').html_safe end end From 3513c881eb778750e7f17bb2cae7f790b10197fc Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 25 Aug 2010 15:39:58 +0200 Subject: [PATCH 0588/2024] use jquery ui datepicker for dates in field_search --- .../date_picker/lib/datepicker_bridge.rb | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 6033777b43..e10be719d7 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -28,26 +28,14 @@ module ActiveScaffold module Bridges module DatePickerBridge module SearchColumnHelpers - def active_scaffold_search_date_picker(column, options) + def active_scaffold_search_datetime(column, options) opt_value, from_value, to_value = field_search_params_range_values(column) - options = column.options.merge(options).except!(:include_blank) - helper = "select_#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}" + options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date) + options[:class] << " #{column.options[:class]}" if column.options[:class] html = [] - html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[from]", :id => "#{options[:id]}_from", :value => from_value)) - html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[to]", :id => "#{options[:id]}_to", :value => to_value)) - html * ' - ' - end - end - - module ViewHelpers - # Provides stylesheets to include with +stylesheet_link_tag+ - def active_scaffold_stylesheets(frontend = :default) - super #+ [calendar_date_select_stylesheets] - end - - # Provides stylesheets to include with +stylesheet_link_tag+ - def active_scaffold_javascripts(frontend = :default) - super #+ [calendar_date_select_javascripts] + html << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(options.merge(:id => "#{options[:id]}_from"))) + html << text_field_tag("#{options[:name]}[to]", to_value, active_scaffold_input_text_options(options.merge(:id => "#{options[:id]}_to"))) + (html * ' - ').html_safe end end @@ -78,7 +66,6 @@ def condition_for_date_picker_type(column, value, like_pattern) ActionView::Base.class_eval do include ActiveScaffold::Bridges::DatePickerBridge::SearchColumnHelpers - include ActiveScaffold::Bridges::DatePickerBridge::ViewHelpers end ActiveScaffold::Finder::ClassMethods.module_eval do include ActiveScaffold::Bridges::DatePickerBridge::Finder::ClassMethods From 89446f4439313b76d040c6eb36b97fcce5a5b75b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 25 Aug 2010 15:50:26 +0200 Subject: [PATCH 0589/2024] automatically include calendar_date_select resources again --- .../bridges/calendar_date_select/lib/as_cds_bridge.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb index 8ba074b331..69c3b386a8 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb @@ -46,12 +46,12 @@ def active_scaffold_search_calendar_date_select(column, options) module ViewHelpers # Provides stylesheets to include with +stylesheet_link_tag+ def active_scaffold_stylesheets(frontend = :default) - super #+ [calendar_date_select_stylesheets] + super + [calendar_date_select_stylesheets] end # Provides stylesheets to include with +stylesheet_link_tag+ def active_scaffold_javascripts(frontend = :default) - super #+ [calendar_date_select_javascripts] + super + [calendar_date_select_javascripts] end end From 1ab2fe25393d98a6560dd204e18c28d62bec477a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 25 Aug 2010 16:32:25 +0200 Subject: [PATCH 0590/2024] ujs: hide and show of range between field search form control --- frontends/default/javascripts/jquery/active_scaffold.js | 5 +++++ frontends/default/javascripts/prototype/active_scaffold.js | 6 +++++- lib/active_scaffold/helpers/search_column_helpers.rb | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 37c0fd24b6..bf17a910a8 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -243,6 +243,11 @@ $(document).ready(function() { }); return true; }); + + $('select.as_search_range_option').live('change', function(event) { + ActiveScaffold[$(this).val() == 'BETWEEN' ? 'show' : 'hide']($(this).nextAll('.as_search_range_between')); + }); + }); /* Simple Inheritance diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 01cd836949..ccb8163405 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -265,7 +265,11 @@ document.observe("dom:loaded", function() { } }); return true; - }); + }); + document.on('change', 'select.as_search_range_option', function(event) { + var element = event.findElement(); + Element[element.value == 'BETWEEN' ? 'show' : 'hide'](element.id.sub('_opt', '_between')); + }); }); diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index ee4be4d4ba..13e20ccc18 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -133,11 +133,11 @@ def active_scaffold_search_range(column, options) html = select_tag("#{options[:name]}[opt]", options_for_select(select_options, opt_value), :id => "#{options[:id]}_opt", - :onchange => "Element[this.value == 'BETWEEN' ? 'show' : 'hide']('#{options[:id]}_between');") + :class => "as_search_range_option") html << ' ' << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(:id => options[:id], :size => 10)) html << ' ' << content_tag(:span, (' - ' + text_field_tag("#{options[:name]}[to]", to_value, active_scaffold_input_text_options(:id => "#{options[:id]}_to", :size => 10))).html_safe, - :id => "#{options[:id]}_between", :style => "display:none") + :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => "display:none") html end alias_method :active_scaffold_search_integer, :active_scaffold_search_range From 333c4f91d514de48ffd077edb85bd70cbf149a84 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 26 Aug 2010 08:25:56 +0200 Subject: [PATCH 0591/2024] Rename edit_after_create to more generic action_after_create (it allows to redirect to show action) --- frontends/default/views/on_create.js.rjs | 4 ++-- lib/active_scaffold/actions/create.rb | 4 ++-- lib/active_scaffold/config/create.rb | 8 ++++---- test/config/create_test.rb | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index 3a56904113..9350fef684 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -16,8 +16,8 @@ if controller.send :successful? else page << "$$(#{cancel_selector}).first().link.close();" end - if (active_scaffold_config.create.edit_after_create) - page << "var link = $('#{action_link_id 'edit', @record.id}');" + if (action = active_scaffold_config.create.action_after_create) + page << "var link = $('#{action_link_id action, @record.id}');" page << "if (link) (function() { link.action_link.open() }).defer();" end else diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 15d6bf3cc2..e2460d38b8 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -44,8 +44,8 @@ def create_respond_to_html else if successful? flash[:info] = as_(:created_model, :model => @record.to_label) - if active_scaffold_config.create.edit_after_create - redirect_to params_for(:action => "edit", :id => @record.id) + if action = active_scaffold_config.create.action_after_create + redirect_to params_for(:action => action, :id => @record.id) elsif active_scaffold_config.create.persistent redirect_to params_for(:action => "new") else diff --git a/lib/active_scaffold/config/create.rb b/lib/active_scaffold/config/create.rb index f76d7d5786..d5ba3c3d3f 100644 --- a/lib/active_scaffold/config/create.rb +++ b/lib/active_scaffold/config/create.rb @@ -4,7 +4,7 @@ class Create < ActiveScaffold::Config::Form def initialize(*args) super self.persistent = self.class.persistent - self.edit_after_create = self.class.edit_after_create + self.action_after_create = self.class.action_after_create end # global level configuration @@ -23,8 +23,8 @@ def self.link=(val) @@persistent = false # whether update form is opened after a create or not - cattr_accessor :edit_after_create - @@edit_after_create = false + cattr_accessor :action_after_create + @@action_after_create = nil # instance-level configuration # ---------------------------- @@ -38,6 +38,6 @@ def label(model = nil) attr_accessor :persistent # whether the form stays open after a create or not - attr_accessor :edit_after_create + attr_accessor :action_after_create end end diff --git a/test/config/create_test.rb b/test/config/create_test.rb index e447e0834e..eea320b164 100644 --- a/test/config/create_test.rb +++ b/test/config/create_test.rb @@ -12,7 +12,7 @@ def teardown def test_default_options assert !@config.create.persistent - assert !@config.create.edit_after_create + assert @config.create.action_after_create.nil? assert_equal 'Create Modelstub', @config.create.label end @@ -48,8 +48,8 @@ def test_persistent assert @config.create.persistent end - def test_edit_after_create - @config.create.edit_after_create = true - assert @config.create.edit_after_create + def test_action_after_create + @config.create.action_after_create = :edit + assert_equal :edit, @config.create.action_after_create end end From 976d07ff88a5cce14ea0476c8d4cfae6501acb22 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 26 Aug 2010 09:46:54 +0200 Subject: [PATCH 0592/2024] Fix :select form_ui with inplace edit --- .../helpers/list_column_helpers.rb | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index a814d9b8a3..bb9a79a0e6 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -113,17 +113,6 @@ def active_scaffold_column_text(column, record) truncate(clean_column_value(record.send(column.name)), :length => column.options[:truncate] || 50) end - def active_scaffold_column_select(column, record) - if column.association - format_column_value(record, column) - else - value = record.send(column.name) - text, val = column.options[:options].find {|text, val| (val.nil? ? text : val).to_s == value.to_s} - value = active_scaffold_translated_option(column, text, val).first if text - format_column_value(record, column, value) - end - end - def active_scaffold_column_checkbox(column, record) if inplace_edit?(record, column) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} @@ -175,6 +164,10 @@ def format_column_value(record, column, value = nil) cache_association(value, column) end if column.association.nil? or column_empty?(value) + if column.form_ui == :select + text, val = column.options[:options].find {|text, val| (val.nil? ? text : val).to_s == value.to_s} + value = active_scaffold_translated_option(column, text, val).first if text + end if value.is_a? Numeric format_number_value(value, column.options) else From d9a3e650ed454496aff5a9c7545dd37aeaabe4bd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 26 Aug 2010 10:17:43 +0200 Subject: [PATCH 0593/2024] Bugfix: renamed collect in action_columns to collect_visible; field_search should work again --- frontends/default/views/_list.html.erb | 2 +- frontends/default/views/_list_calculations.html.erb | 2 +- frontends/default/views/_list_record.html.erb | 2 +- lib/active_scaffold/data_structures/action_columns.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index caf05acffb..b26f3f2a6e 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -1,7 +1,7 @@ <table cellpadding="0" cellspacing="0"> <thead> <tr> - <% columns = active_scaffold_config.list.columns.collect %> + <% columns = active_scaffold_config.list.columns.collect_visible %> <%= render :partial => 'list_column_headings', :locals => {:columns => columns} %> </tr> </thead> diff --git a/frontends/default/views/_list_calculations.html.erb b/frontends/default/views/_list_calculations.html.erb index 63b86f7673..5dcbad0184 100644 --- a/frontends/default/views/_list_calculations.html.erb +++ b/frontends/default/views/_list_calculations.html.erb @@ -1,5 +1,5 @@ <% display_class = ( @records.kind_of?(Array) ? @records.first : @records ) - columns ||= active_scaffold_config.list.columns.collect -%> + columns ||= active_scaffold_config.list.columns.collect_visible -%> <tr id="<%= active_scaffold_calculations_id %>" class="active-scaffold-calculations"> <% columns.each do |column| -%> <td id="<%= active_scaffold_calculations_id(column) if column.calculation? %>"> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index c811e1f1d1..aacb78b09e 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -1,6 +1,6 @@ <% record = list_record if list_record # compat with render :partial :collection -columns ||= active_scaffold_config.list.columns.collect +columns ||= active_scaffold_config.list.columns.collect_visible tr_class = cycle("", "even-record") tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class url_options = params_for(:action => :list, :id => record.id) diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index 3ae4b9e775..d610f496d9 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -74,7 +74,7 @@ def each(options = {}, &proc) end end - def collect(options = {}, &proc) + def collect_visible(options = {}, &proc) columns = [] options[:for] ||= @columns.active_record_class self.unauthorized_columns = [] From c9111441e83a4b58276a5af410eafb790d4ba2c8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 26 Aug 2010 14:00:28 +0200 Subject: [PATCH 0594/2024] Bugfix: generate correct text_field name attributes --- .../bridges/date_picker/lib/datepicker_bridge.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index e10be719d7..9528c0db20 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -33,8 +33,8 @@ def active_scaffold_search_datetime(column, options) options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date) options[:class] << " #{column.options[:class]}" if column.options[:class] html = [] - html << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(options.merge(:id => "#{options[:id]}_from"))) - html << text_field_tag("#{options[:name]}[to]", to_value, active_scaffold_input_text_options(options.merge(:id => "#{options[:id]}_to"))) + html << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(options.merge(:id => "#{options[:id]}_from", :name => "#{options[:name]}[from]"))) + html << text_field_tag("#{options[:name]}[to]", to_value, active_scaffold_input_text_options(options.merge(:id => "#{options[:id]}_to", :name => "#{options[:name]}[to]"))) (html * ' - ').html_safe end end From b33f1ee4c139f363b45119a0aea30dc79f88c77d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 26 Aug 2010 17:04:28 +0200 Subject: [PATCH 0595/2024] rarely searched columns may be placed in a hidden subgroup --- .../default/views/_field_search.html.erb | 34 ++++++++----------- .../default/views/_search_attribute.html.erb | 10 ++++++ lib/active_scaffold/actions/search.rb | 1 - lib/active_scaffold/config/field_search.rb | 9 +++++ .../helpers/search_column_helpers.rb | 14 ++++++++ lib/active_scaffold/locale/de.rb | 1 + lib/active_scaffold/locale/en.rb | 1 + lib/active_scaffold/locale/fr.rb | 1 + 8 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 frontends/default/views/_search_attribute.html.erb diff --git a/frontends/default/views/_field_search.html.erb b/frontends/default/views/_field_search.html.erb index d6ff208a8c..2c48ed8143 100644 --- a/frontends/default/views/_field_search.html.erb +++ b/frontends/default/views/_field_search.html.erb @@ -7,20 +7,21 @@ options = {:id => search_form_id, 'data-loading' => true} form_tag url_options, options %> <ol class="form"> - <% active_scaffold_config.field_search.columns.each do |column| -%> - <% next unless column.search_sql -%> - <% name = "search[#{column.name}]" %> - <li class="form-element"> - <dl> - <dt> - <label for="<%= "search_#{column.name}" %>"><%= column.label %></label> - </dt> - <dd> - <%= active_scaffold_search_for(column) %> - </dd> - </dl> - </li> + <% visibles, hiddens = visibles_and_hiddens(active_scaffold_config.field_search) %> + <% visibles.each do |column| -%> + <%= render :partial => 'search_attribute', :locals => {:column => column} %> <% end -%> + <% unless hiddens.empty? -%> + <li class="sub-section"> + <h5><%= as_(:optional_attributes) %></h5> + <ol id ="<%= sub_section_id(:sub_section => 'further_options') %>" class="form" 'style="display: none;"'> + <% hiddens.each do |column| -%> + <%= render :partial => 'search_attribute', :locals => {:column => column} %> + <% end -%> + </ol> + <%= link_to_visibility_toggle(sub_section_id(:sub_section => 'further_options'), {:default_visible => false}) %> + </li> + <% end -%> </ol> <p class="form-footer"> <%= submit_tag as_(:search), :class => "submit" %> @@ -28,9 +29,4 @@ form_tag url_options, options %> <%= loading_indicator_tag(:action => :search) %> </p> </form> - -<script type="text/javascript"> -//<![CDATA[ - Form.focusFirstElement('<%= search_form_id -%>'); -//]]> -</script> +<%= javascript_tag("ActiveScaffold.focus_first_element_of_form('#{search_form_id}');") %> diff --git a/frontends/default/views/_search_attribute.html.erb b/frontends/default/views/_search_attribute.html.erb new file mode 100644 index 0000000000..fff5053223 --- /dev/null +++ b/frontends/default/views/_search_attribute.html.erb @@ -0,0 +1,10 @@ +<li class="form-element"> + <dl> + <dt> + <label for="<%= "search_#{column.name}" %>"><%= column.label %></label> + </dt> + <dd> + <%= active_scaffold_search_for(column) %> + </dd> + </dl> +</li> \ No newline at end of file diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index df42083434..eff8c8ad75 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -21,7 +21,6 @@ def search_respond_to_js end def do_search query = search_params.to_s.strip rescue '' - unless query.empty? columns = active_scaffold_config.search.columns text_search = active_scaffold_config.search.text_search diff --git a/lib/active_scaffold/config/field_search.rb b/lib/active_scaffold/config/field_search.rb index d973666b95..c60abb9632 100644 --- a/lib/active_scaffold/config/field_search.rb +++ b/lib/active_scaffold/config/field_search.rb @@ -52,5 +52,14 @@ def columns # the ActionLink for this action attr_accessor :link + + # rarely searched columns may be placed in a hidden subgroup + def optional_columns=(optionals) + @optional_columns= Array(optionals) + end + + def optional_columns + @optional_columns ||= [] + end end end diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 13e20ccc18..786ae85fd9 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -205,6 +205,20 @@ def override_search?(search_ui) def override_search(form_ui) "active_scaffold_search_#{form_ui}" end + + def visibles_and_hiddens(search_config) + visibles = [] + hiddens = [] + search_config.columns.each do |column| + next unless column.search_sql + if search_config.optional_columns.include?(column.name) + hiddens << column + else + visibles << column + end + end + return visibles, hiddens + end end end end diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index dcb5d2d91d..778aba7bc7 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -58,6 +58,7 @@ :'<' => '<', :'!=' => '!=', :between => 'Zwischen', + :optional_attributes => 'Further Options', # error_messages :cant_destroy_record => "%{record} kann nicht gelöscht werden", diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 74ed23b301..46ac2bc6fd 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -64,6 +64,7 @@ :contains => 'Contains', :begins_with => 'Begins with', :ends_with => 'Ends with', + :optional_attributes => 'Further Options', # error_messages :cant_destroy_record => "%{record} can't be destroyed", diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 1c384cf577..fbdcb9eaa4 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -58,6 +58,7 @@ :'<' => '<', :'!=' => '!=', :between => 'Entre', + :optional_attributes => 'Further Options', # error_messages :internal_error => 'Erreur de la requête (code 500, Erreur interne)', From 6506fc7c055351526253b1ac91055a6c3d7da249 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 27 Aug 2010 08:56:55 +0200 Subject: [PATCH 0596/2024] optional search columns should nt be added to subgroup if they are currently in use for searching --- .../helpers/search_column_helpers.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 786ae85fd9..5562014474 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -211,7 +211,7 @@ def visibles_and_hiddens(search_config) hiddens = [] search_config.columns.each do |column| next unless column.search_sql - if search_config.optional_columns.include?(column.name) + if search_config.optional_columns.include?(column.name) && !searched_by?(column) hiddens << column else visibles << column @@ -219,6 +219,18 @@ def visibles_and_hiddens(search_config) end return visibles, hiddens end + + def searched_by?(column) + value = field_search_params[column.name] + case value + when Hash + !value['from'].blank? + when String + !value.blank? + else + false + end + end end end end From 87a6690c33b89880bbc512bc7c7bb693e38f7be3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 27 Aug 2010 10:39:49 +0200 Subject: [PATCH 0597/2024] you may define default_params for field_search --- lib/active_scaffold/actions/field_search.rb | 17 +++++++++++++++++ lib/active_scaffold/config/field_search.rb | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index b7f6306cce..4db720ddb7 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -16,6 +16,23 @@ def show_search end protected + + def store_search_params_into_session + set_field_search_default_params(active_scaffold_config.field_search.default_params) unless active_scaffold_config.field_search.default_params.nil? + super + end + + def set_field_search_default_params(default_params) + if (params[:search].nil? && search_params.nil?) || (params[:search].is_a?(String) && params[:search].blank?) + if default_params.is_a?(Proc) + #find a way to call this in controller context to avoid passing all that stuff to the block + params[:search] = default_params.call(current_user, params) + else + params[:search] = default_params + end + end + end + def field_search_params search_params || {} end diff --git a/lib/active_scaffold/config/field_search.rb b/lib/active_scaffold/config/field_search.rb index c60abb9632..12e8ffe9e5 100644 --- a/lib/active_scaffold/config/field_search.rb +++ b/lib/active_scaffold/config/field_search.rb @@ -61,5 +61,10 @@ def optional_columns=(optionals) def optional_columns @optional_columns ||= [] end + + # default search params + # default_params = {:title => {"from"=>"test", "to"=>"", "opt"=>"%?%"}} + attr_accessor :default_params + end end From 9b87b6447d599d97d1e6c3db8e477b9bbc31753a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 27 Aug 2010 11:04:57 +0200 Subject: [PATCH 0598/2024] bugfix: jquery focus first element of form --- frontends/default/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index bf17a910a8..7b45840c7b 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -429,7 +429,7 @@ var ActiveScaffold = { focus_first_element_of_form: function(form_element) { if (typeof(form_element) == 'string') form_element = '#' + form_element; - $("#{form_element}:first *:input[type!=hidden]:first").focus(); + $(form_element + ":first *:input[type!=hidden]:first").focus(); }, create_record_row: function(tbody, html) { From ce7764f7db4af0af64430767d67bd74372e116d2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 27 Aug 2010 11:06:00 +0200 Subject: [PATCH 0599/2024] focus first element of form --- frontends/default/views/_base_form.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index 9ac9bd7f90..44ff09ff63 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -35,3 +35,4 @@ end -%> </p> </form> +<%= javascript_tag("ActiveScaffold.focus_first_element_of_form('#{element_form_id(:action => form_action)}');") %> From 4bf7f9187e13eacf901dd98ddb4a1a81bac69e7d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 27 Aug 2010 15:48:22 +0200 Subject: [PATCH 0600/2024] assign updated_at and created_at a column weight of 1 --- lib/active_scaffold/data_structures/column.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 1b299d1e73..31b8541515 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -261,7 +261,7 @@ def initialize(name, active_record_class) #:nodoc: @autolink = !@association.nil? @active_record_class = active_record_class @table = active_record_class.table_name - @weight = 0 + @weight = [:created_at, :updated_at].include?(self.name) ? 1 : 0 @associated_limit = self.class.associated_limit @associated_number = self.class.associated_number @show_blank_record = self.class.show_blank_record From c44f4d6fb6042b8685cfaab2a98183cd5541c23a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 30 Aug 2010 10:40:20 +0200 Subject: [PATCH 0601/2024] fix listing records with empty associations and :select form_ui --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index bb9a79a0e6..b66fce2bca 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -164,7 +164,7 @@ def format_column_value(record, column, value = nil) cache_association(value, column) end if column.association.nil? or column_empty?(value) - if column.form_ui == :select + if column.form_ui == :select && column.options[:options] text, val = column.options[:options].find {|text, val| (val.nil? ? text : val).to_s == value.to_s} value = active_scaffold_translated_option(column, text, val).first if text end From 24210f190ac3eb7ea03ece31d97214c5bc0bc00e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 31 Aug 2010 16:03:03 +0200 Subject: [PATCH 0602/2024] Add association_join_text to set what string to use to join records from plural associations --- lib/active_scaffold/config/list.rb | 8 ++++++++ lib/active_scaffold/helpers/list_column_helpers.rb | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index fc4b33aba4..688943748a 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -16,6 +16,7 @@ def initialize(core_config) # inherit from global scope @empty_field_text = self.class.empty_field_text + @association_join_text = self.class.association_join_text @pagination = self.class.pagination @show_search_reset = true @mark_records = self.class.mark_records @@ -35,6 +36,10 @@ def initialize(core_config) cattr_accessor :empty_field_text @@empty_field_text = '-' + # what string to use to join records from plural associations + cattr_accessor :association_join_text + @@association_join_text = ', ' + # What kind of pagination to use: # * true: The usual pagination # * :infinite: Treat the source as having an infinite number of pages (i.e. don't count the records; useful for large tables where counting is slow and we don't really care anyway) @@ -71,6 +76,9 @@ def columns # what string to use when a field is empty attr_accessor :empty_field_text + # what string to use to join records from plural associations + attr_accessor :association_join_text + # show a link to reset the search next to filtered message attr_accessor :show_search_reset diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index b66fce2bca..2757febf72 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -200,16 +200,16 @@ def format_association_value(value, column, size) format_value(value.to_label) when :has_many, :has_and_belongs_to_many if column.associated_limit.nil? - firsts = value.collect { |v| v.to_label } + firsts = value.collect { |v| clean_column_value(v.to_label) } else firsts = value.first(column.associated_limit) - firsts.collect! { |v| v.to_label } + firsts.collect! { |v| clean_column_value(v.to_label) } firsts[column.associated_limit] = '…' if value.size > column.associated_limit end if column.associated_limit == 0 size if column.associated_number? else - joined_associated = format_value(firsts.join(', ')) + joined_associated = firsts.join(active_scaffold_config.list.association_join_text) joined_associated << " (#{size})" if column.associated_number? and column.associated_limit and value.size > column.associated_limit joined_associated end From d3060e72145555cd2128d31f9da934a48d98b847 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 31 Aug 2010 16:08:52 +0200 Subject: [PATCH 0603/2024] fix test for :select list_ui change --- test/helpers/list_column_helpers_test.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/helpers/list_column_helpers_test.rb b/test/helpers/list_column_helpers_test.rb index e963743b79..fa6d7603e4 100644 --- a/test/helpers/list_column_helpers_test.rb +++ b/test/helpers/list_column_helpers_test.rb @@ -6,22 +6,23 @@ class ListColumnHelpersTest < ActionView::TestCase def setup @column = ActiveScaffold::DataStructures::Column.new(:a, ModelStub) + @column.form_ui = :select @record = stub(:a => 'value_2') @config = stub(:list => stub(:empty_field_text => '-')) end def test_options_for_select_list_ui_for_simple_column @column.options[:options] = [:value_1, :value_2, :value_3] - assert_equal 'Value 2', active_scaffold_column_select(@column, @record) + assert_equal 'Value 2', format_column_value(@record, @column) @column.options[:options] = %w(value_1 value_2 value_3) - assert_equal 'value_2', active_scaffold_column_select(@column, @record) + assert_equal 'value_2', format_column_value(@record, @column) @column.options[:options] = [%w(text_1 value_1), %w(text_2 value_2), %w(text_3 value_3)] - assert_equal 'text_2', active_scaffold_column_select(@column, @record) + assert_equal 'text_2', format_column_value(@record, @column) @column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]] - assert_equal 'Text 2', active_scaffold_column_select(@column, @record) + assert_equal 'Text 2', format_column_value(@record, @column) end private From ff84405edaf4668f1094d9db76f21439805ca3c9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 31 Aug 2010 16:27:05 +0200 Subject: [PATCH 0604/2024] Test association_join_text --- test/helpers/list_column_helpers_test.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/helpers/list_column_helpers_test.rb b/test/helpers/list_column_helpers_test.rb index fa6d7603e4..38f4c781a9 100644 --- a/test/helpers/list_column_helpers_test.rb +++ b/test/helpers/list_column_helpers_test.rb @@ -8,7 +8,9 @@ def setup @column = ActiveScaffold::DataStructures::Column.new(:a, ModelStub) @column.form_ui = :select @record = stub(:a => 'value_2') - @config = stub(:list => stub(:empty_field_text => '-')) + @config = stub(:list => stub(:empty_field_text => '-', :association_join_text => ', ')) + @association_column = ActiveScaffold::DataStructures::Column.new(:b, ModelStub) + @association_column.stubs(:association).returns(stub(:macro => :has_many)) end def test_options_for_select_list_ui_for_simple_column @@ -25,6 +27,14 @@ def test_options_for_select_list_ui_for_simple_column assert_equal 'Text 2', format_column_value(@record, @column) end + def test_association_join_text + value = [1, 2, 3, 4].map(&:to_s) + value.each {|v| v.stubs(:to_label).returns(v)} + assert_equal '1, 2, 3, … (4)', format_association_value(value, @association_column, value.size) + @config.list.stubs(:association_join_text => ',<br/>') + assert_equal '1,<br/>2,<br/>3,<br/>… (4)', format_association_value(value, @association_column, value.size) + end + private def active_scaffold_config @config From 7e5ab4a6d732a19cd363ba1c0516dab2424b96f8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 31 Aug 2010 16:54:09 +0200 Subject: [PATCH 0605/2024] enhanced search_helper for bridged date/time fields --- .../javascripts/jquery/active_scaffold.js | 12 +- .../javascripts/prototype/active_scaffold.js | 8 + .../calendar_date_select/lib/as_cds_bridge.rb | 40 ++--- .../date_picker/lib/datepicker_bridge.rb | 36 +---- .../bridges/shared/date_bridge.rb | 138 ++++++++++++++++++ 5 files changed, 173 insertions(+), 61 deletions(-) create mode 100644 lib/active_scaffold/bridges/shared/date_bridge.rb diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 7b45840c7b..d4ddec2f61 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -245,7 +245,16 @@ $(document).ready(function() { }); $('select.as_search_range_option').live('change', function(event) { - ActiveScaffold[$(this).val() == 'BETWEEN' ? 'show' : 'hide']($(this).nextAll('.as_search_range_between')); + ActiveScaffold[$(this).val() == 'BETWEEN' ? 'show' : 'hide']($(this).parent().find('.as_search_range_between')); + return true; + }); + + $('select.as_search_range_option').live('change', function(event) { + var element = $(this); + ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric')); + ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend')); + ActiveScaffold[(element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_range')); + return true; }); }); @@ -414,6 +423,7 @@ var ActiveScaffold = { }, hide: function(element) { + if (typeof(element) == 'string') element = '#' + element; $(element).hide(); }, diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index ccb8163405..dd0dd6e59b 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -269,7 +269,15 @@ document.observe("dom:loaded", function() { document.on('change', 'select.as_search_range_option', function(event) { var element = event.findElement(); Element[element.value == 'BETWEEN' ? 'show' : 'hide'](element.id.sub('_opt', '_between')); + return true; }); + document.on('change', 'select.as_search_date_time_option', function(event) { + var element = event.findElement(); + Element[!(element.value == 'PAST' || element.value == 'FUTURE' || element.value == 'RANGE') ? 'show' : 'hide'](element.id.sub('_opt', '_numeric')); + Element[(element.value == 'PAST' || element.value == 'FUTURE') ? 'show' : 'hide'](element.id.sub('_opt', '_trend')); + Element[element.value == 'RANGE' ? 'show' : 'hide'](element.id.sub('_opt', '_range')); + return true; + }); }); diff --git a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb index 69c3b386a8..8b31f8e487 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb @@ -30,16 +30,11 @@ def active_scaffold_input_calendar_date_select(column, options) calendar_date_select("record", column.name, options.merge(column.options)) end end - + module SearchColumnHelpers - def active_scaffold_search_calendar_date_select(column, options) - opt_value, from_value, to_value = field_search_params_range_values(column) - options = column.options.merge(options).except!(:include_blank) - helper = "select_#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}" - html = [] - html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[from]", :id => "#{options[:id]}_from", :value => from_value)) - html << calendar_date_select("record", column.name, options.merge(:name => "#{options[:name]}[to]", :id => "#{options[:id]}_to", :value => to_value)) - (html * ' - ').html_safe + def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) + calendar_date_select("record", column.name, + {:name => "#{options[:name]}[#{name}]", :value => current_search[name], :class => 'text-input', :id => "#{options[:id]}_#{name}", :time => column_datetime?(column) ? true : false}) end end @@ -54,36 +49,19 @@ def active_scaffold_javascripts(frontend = :default) super + [calendar_date_select_javascripts] end end - - module Finder - module ClassMethods - def condition_for_calendar_date_select_type(column, value, like_pattern) - conversion = column.column.type == :date ? 'to_date' : 'to_time' - from_value, to_value = ['from', 'to'].collect do |field| - Time.zone.parse(value[field]) rescue nil - end - - if from_value.nil? and to_value.nil? - nil - elsif !from_value - ["#{column.search_sql} <= ?", to_value.send(conversion).to_s(:db)] - elsif !to_value - ["#{column.search_sql} >= ?", from_value.send(conversion).to_s(:db)] - else - ["#{column.search_sql} BETWEEN ? AND ?", from_value.send(conversion).to_s(:db), to_value.send(conversion).to_s(:db)] - end - end - end - end end end end ActionView::Base.class_eval do include ActiveScaffold::Bridges::CalendarDateSelectBridge::FormColumnHelpers + include ActiveScaffold::Bridges::Shared::DateBridge::SearchColumnHelpers + alias_method :active_scaffold_search_calendar_date_select, :active_scaffold_search_date_bridge include ActiveScaffold::Bridges::CalendarDateSelectBridge::SearchColumnHelpers include ActiveScaffold::Bridges::CalendarDateSelectBridge::ViewHelpers end + ActiveScaffold::Finder::ClassMethods.module_eval do - include ActiveScaffold::Bridges::CalendarDateSelectBridge::Finder::ClassMethods + include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods + alias_method :condition_for_calendar_date_select_type, :condition_for_date_bridge_type end diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 9528c0db20..0a51543975 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -28,36 +28,10 @@ module ActiveScaffold module Bridges module DatePickerBridge module SearchColumnHelpers - def active_scaffold_search_datetime(column, options) - opt_value, from_value, to_value = field_search_params_range_values(column) + def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date) options[:class] << " #{column.options[:class]}" if column.options[:class] - html = [] - html << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(options.merge(:id => "#{options[:id]}_from", :name => "#{options[:name]}[from]"))) - html << text_field_tag("#{options[:name]}[to]", to_value, active_scaffold_input_text_options(options.merge(:id => "#{options[:id]}_to", :name => "#{options[:name]}[to]"))) - (html * ' - ').html_safe - end - end - - module Finder - module ClassMethods - def condition_for_date_picker_type(column, value, like_pattern) - conversion = column.column.type == :date ? 'to_date' : 'to_time' - from_value, to_value = ['from', 'to'].collect do |field| - Time.zone.parse(value[field]) rescue nil - end - - if from_value.nil? and to_value.nil? - nil - elsif !from_value - ["#{column.search_sql} <= ?", to_value.send(conversion).to_s(:db)] - elsif !to_value - ["#{column.search_sql} >= ?", from_value.send(conversion).to_s(:db)] - else - ["#{column.search_sql} BETWEEN ? AND ?", from_value.send(conversion).to_s(:db), to_value.send(conversion).to_s(:db)] - end - end - alias_method :condition_for_datetime_picker_type, :condition_for_date_picker_type + text_field_tag("#{options[:name]}[#{name}]", current_search[name], options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) end end end @@ -65,8 +39,12 @@ def condition_for_date_picker_type(column, value, like_pattern) end ActionView::Base.class_eval do + include ActiveScaffold::Bridges::Shared::DateBridge::SearchColumnHelpers + alias_method :active_scaffold_search_datetime, :active_scaffold_search_date_bridge include ActiveScaffold::Bridges::DatePickerBridge::SearchColumnHelpers end ActiveScaffold::Finder::ClassMethods.module_eval do - include ActiveScaffold::Bridges::DatePickerBridge::Finder::ClassMethods + include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods + alias_method :condition_for_date_picker_type, :condition_for_date_bridge_type + alias_method :condition_for_datetime_picker_type, :condition_for_date_picker_type end diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb new file mode 100644 index 0000000000..983e3c568a --- /dev/null +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -0,0 +1,138 @@ +module ActiveScaffold + module Bridges + module Shared + module DateBridge + module SearchColumnHelpers + def active_scaffold_search_date_bridge(column, options) + current_search = {'from' => nil, 'to' => nil, 'opt' => 'BETWEEN', + 'number' => 1, 'unit' => 'DAYS', 'range' => nil} + current_search.merge!(field_search_params[column.name]) unless field_search_params[column.name].nil? + tags = [] + tags << active_scaffold_search_date_bridge_comparator_tag(column, options, current_search) + tags << active_scaffold_search_date_bridge_trend_tag(column, options, current_search) + tags << active_scaffold_search_date_bridge_numeric_tag(column, options, current_search) + tags << active_scaffold_search_date_bridge_range_tag(column, options, current_search) + tags.join(" ").html_safe + end + + def active_scaffold_search_date_bridge_comparator_options(column) + select_options = ActiveScaffold::Finder::DateComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} + select_options + ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} + end + + def active_scaffold_search_date_bridge_comparator_tag(column, options, current_search) + select_tag("#{options[:name]}[opt]", options_for_select(active_scaffold_search_date_bridge_comparator_options(column),current_search['opt']), :id => "#{options[:id]}_opt", :class => "as_search_range_option as_search_date_time_option") + end + + def active_scaffold_search_date_bridge_numeric_tag(column, options, current_search) + numeric_controls = "" << + active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'from') << + content_tag(:span, (" - " + active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'to')).html_safe, + :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => "display:#{current_search['opt'] == 'BETWEEN' ? '' : 'none'}") + content_tag("span", numeric_controls.html_safe, :id => "#{options[:id]}_numeric", :style => "display:#{ActiveScaffold::Finder::NumericComparators.include?(current_search['opt']) ? '' : 'none'}") + end + + def active_scaffold_search_date_bridge_trend_tag(column, options, current_search) + trend_controls = text_field_tag("search[#{column.name}][number]", current_search['number'], :class => 'text-input', :size => 10) << " " << + select_tag("search[#{column.name}][unit]", + options_for_select( ActiveScaffold::Finder::DateUnits.collect{|date_unit| [as_(date_unit.downcase.to_sym), date_unit]}, current_search["unit"]), + :class => 'text-input') + content_tag("span", trend_controls.html_safe, :id => "#{options[:id]}_trend", :style => "display:#{(current_search['opt'] == 'PAST' || current_search['opt'] == 'FUTURE') ? '' : 'none'}") + end + + def active_scaffold_search_date_bridge_range_tag(column, options, current_search) + range_controls = select_tag("search[#{column.name}][range]", + options_for_select( ActiveScaffold::Finder::DateRanges.collect{|range| [as_(range.downcase.to_sym), range]}, current_search["range"]), + :class => 'text-input') + content_tag("span", range_controls.html_safe, :id => "#{options[:id]}_range", :style => "display:#{(current_search['opt'] == 'RANGE') ? '' : 'none'}") + end + + def column_datetime?(column) + (!column.column.nil? && column.column.type == :datetime) + end + end + + + + + module Finder + module ClassMethods + def condition_for_date_bridge_type(column, value, like_pattern) + operator = ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) && value[:opt] != 'BETWEEN' ? value[:opt] : nil + conversion = column.column.type == :date ? 'to_date' : 'to_time' + + from_value, to_value = date_bridge_from_to(column, value) + + if column.search_sql.is_a? Proc + column.search_sql.call(from_value, to_value, operator) + else + unless operator.nil? + ["#{column.search_sql} #{value[:opt]} ?", from_value.send(conversion).to_s(:db)] unless from_value.nil? + else + ["#{column.search_sql} BETWEEN ? AND ?", from_value.send(conversion).to_s(:db), to_value.send(conversion).to_s(:db)] unless from_value.nil? && to_value.nil? + end + end + end + + def date_bridge_from_to(column, value) + case value[:opt] + when 'RANGE' + date_bridge_from_to_for_range(column, value) + when 'PAST', 'FUTURE' + date_bridge_from_to_for_trend(column, value) + else + ['from', 'to'].collect { |field| Time.zone.parse(value[field]) rescue nil} + end + end + + def date_bridge_from_to_for_trend(column, value) + case value['opt'] + when "PAST" + trend_number = [value['number'].to_i, 1].max + return eval("Time.zone.now.beginning_of_#{value['unit'].downcase.singularize}.ago(#{trend_number - 1}.#{value['unit'].downcase.singularize})"), Time.zone.now.end_of_day + when "FUTURE" + trend_number = [search_criterion['number'].to_i, 1].max + return Time.zone.now.beginning_of_day, eval("Time.zone.now.end_of_#{value['unit'].downcase.singularize}.in(#{trend_number - 1}.#{value['unit'].downcase.singularize})") + end + end + + def date_bridge_from_to_for_range(column, value) + case value[:range] + when 'TODAY' + return Time.zone.now.beginning_of_day, Time.zone.now.end_of_day + when 'YESTERDAY' + return Time.zone.now.ago(1.day).beginning_of_day, Time.zone.now.ago(1.day).end_of_day + when 'TOMMORROW' + return Time.zone.now.in(1.day).beginning_of_day, Time.zone.now.in(1.day).end_of_day + else + range_type, range = value[:range].downcase.split('_') + raise ArgumentError unless ['week', 'month', 'year'].include?(range) + case range_type + when 'this' + return Time.zone.now.send("beginning_of_#{range}".to_sym), Time.zone.now.send("end_of_#{range}") + when 'prev' + return Time.zone.now.ago(1.send(range.to_sym)).send("beginning_of_#{range}".to_sym), Time.zone.now.ago(1.send(range.to_sym)).send("end_of_#{range}".to_sym) + when 'next' + return Time.zone.now.in(1.send(range.to_sym)).send("beginning_of_#{range}".to_sym), Time.zone.now.in(1.send(range.to_sym)).send("end_of_#{range}".to_sym) + else + return nil, nil + end + end + end + end + end + end + end + end +end + +ActiveScaffold::Finder.const_set('DateComparators', ["PAST", "FUTURE", "RANGE"]) +ActiveScaffold::Finder.const_set('DateUnits', ["DAYS", "WEEKS", "MONTHS", "YEARS"]) +ActiveScaffold::Finder.const_set('DateRanges', ["TODAY", "YESTERDAY", "TOMORROW", + "THIS_WEEK", "PREV_WEEK", "NEXT_WEEK", + "THIS_MONTH", "PREV_MONTH", "NEXT_MONTH", + "THIS_YEAR", "PREV_YEAR", "NEXT_YEAR"]) + + + + From b0039d244d0751fcefdd31491191e9e158bf60fd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 1 Sep 2010 09:02:59 +0200 Subject: [PATCH 0606/2024] Bugfix provided by jesusmercado: subgroups in forms raised Exceptions --- frontends/default/views/_form.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index 9716740628..3e2d47de87 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -1,7 +1,6 @@ <% subsection_id ||= nil %> <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= 'style="display: none;"' if columns.collapsed -%>> <% columns.each :for => @record do |column| -%> - <% next if column.readonly_association? %> <% if is_subsection? column -%> <% subsection_id = sub_section_id(:sub_section => column.label) %> <li class="sub-section"> @@ -9,6 +8,8 @@ <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id} %> <%= link_to_visibility_toggle(subsection_id, {:default_visible => !column.collapsed}) -%> </li> + <% elsif column.readonly_association? + next %> <% elsif is_subform? column and !override_form_field?(column) -%> <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? %>" id="<%= sub_form_id(:association => column.name) %>"> <%= render :partial => form_partial_for_column(column), :locals => { :column => column } -%> From 2a03a6d101c75799d54dddecfac463d31f3f7af3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 1 Sep 2010 09:42:57 +0200 Subject: [PATCH 0607/2024] reduce column_renders_as calls --- frontends/default/views/_form.html.erb | 11 ++++++----- .../helpers/form_column_helpers.rb | 17 +++++------------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index 3e2d47de87..03703801b0 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -1,7 +1,8 @@ <% subsection_id ||= nil %> <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= 'style="display: none;"' if columns.collapsed -%>> - <% columns.each :for => @record do |column| -%> - <% if is_subsection? column -%> + <% columns.each :for => @record do |column| %> + <% renders_as = column_renders_as(column) %> + <% if renders_as == :subsection -%> <% subsection_id = sub_section_id(:sub_section => column.label) %> <li class="sub-section"> <h5><%= column.label %></h5> @@ -10,13 +11,13 @@ </li> <% elsif column.readonly_association? next %> - <% elsif is_subform? column and !override_form_field?(column) -%> + <% elsif renders_as == :subform and !override_form_field?(column) -%> <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? %>" id="<%= sub_form_id(:association => column.name) %>"> - <%= render :partial => form_partial_for_column(column), :locals => { :column => column } -%> + <%= render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%> </li> <% else -%> <li class="form-element <%= 'required' if column.required? %> <%= column.css_class unless column.css_class.nil? %>"> - <%= render :partial => form_partial_for_column(column), :locals => { :column => column } -%> + <%= render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%> </li> <% end -%> <% end -%> diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index a91ee7a9ea..315248258a 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -261,14 +261,15 @@ def override_input(form_ui) "active_scaffold_input_#{form_ui}" end - def form_partial_for_column(column) + def form_partial_for_column(column, renders_as = nil) + renders_as ||= column_renders_as(column) if override_form_field_partial?(column) override_form_field_partial(column) - elsif column_renders_as(column) == :field or override_form_field?(column) + elsif renders_as == :field or override_form_field?(column) "form_attribute" - elsif column_renders_as(column) == :subform + elsif renders_as == :subform "form_association" - elsif column_renders_as(column) == :hidden + elsif renders_as == :hidden "form_hidden_attribute" end end @@ -298,14 +299,6 @@ def column_renders_as(column) end end - def is_subsection?(column) - column_renders_as(column) == :subsection - end - - def is_subform?(column) - column_renders_as(column) == :subform - end - def column_scope(column) if column.plural_association? "[#{column.name}][#{@record.id || generate_temporary_id}]" From f42f4ca6be310bb26e41fcb5b4a26e0eef253f12 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 1 Sep 2010 09:53:28 +0200 Subject: [PATCH 0608/2024] field_search: default_params proc running in controller context --- lib/active_scaffold/actions/field_search.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index 4db720ddb7..ea876522cb 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -24,12 +24,7 @@ def store_search_params_into_session def set_field_search_default_params(default_params) if (params[:search].nil? && search_params.nil?) || (params[:search].is_a?(String) && params[:search].blank?) - if default_params.is_a?(Proc) - #find a way to call this in controller context to avoid passing all that stuff to the block - params[:search] = default_params.call(current_user, params) - else - params[:search] = default_params - end + params[:search] = default_params.is_a?(Proc) ? self.instance_eval(&default_params) : default_params end end From 3af86d2412e09bf1ed4535459288a987093cddac Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 1 Sep 2010 11:48:18 +0200 Subject: [PATCH 0609/2024] refactoring of render_action_link --- lib/active_scaffold/helpers/view_helpers.rb | 38 ++++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index c78781bcc2..e98344b0a8 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -127,23 +127,28 @@ def skip_action_link(link, *args) end def render_action_link(link, url_options, record = nil, html_options = {}) - url_options = url_options.clone + url_options = action_link_url_options(link, url_options, record) + html_options = action_link_html_options(link, url_options, record, html_options) + action_link_html(link, url_options, html_options) + end + + def action_link_url_options(link, url_options, record) + options = url_options.clone + options[:action] = link.action + options[:controller] = link.controller if link.controller + options.delete(:search) if link.controller and link.controller.to_s != params[:controller] + options.merge! link.parameters if link.parameters + url_options_for_nested_link(link.column, record, link, options) unless link.column.nil? + options[:_method] = link.method if link.inline? && link.method != :get + options + end + + def action_link_html_options(link, url_options, record, html_options) id = url_options[:id] || url_options[:parent_id] - url_options[:action] = link.action - url_options[:controller] = link.controller if link.controller - url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller] - url_options.merge! link.parameters if link.parameters - url_options_for_nested_link(link.column, record, link, url_options) unless link.column.nil? - html_options.reverse_merge! link.html_options.merge(:class => link.action) - if link.inline? - url_options[:_method] = link.method if link.method != :get - # robd: protect against submitting get links as forms, since this causes annoying - # 'Do you wish to resubmit your form?' messages whenever you go back and forwards. - elsif link.method != :get - # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails - html_options[:method] = link.method - end + + # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails + html_options[:method] = link.method if !link.inline? && link.method != :get html_options['data-confirm'] = link.confirm(record.try(:to_label)) if link.confirm? html_options['data-position'] = link.position if link.position and link.inline? @@ -158,8 +163,7 @@ def render_action_link(link, url_options, record = nil, html_options = {}) html_options[:onclick] = link.dhtml_confirm.onclick_function(controller,action_link_id(url_options[:action],id)) end html_options[:class] += " #{link.html_options[:class]}" unless link.html_options[:class].blank? - - action_link_html(link, url_options, html_options) + html_options end def action_link_html(link, url, html_options) From 2408722cd8bc17725f5f4bf9b5c331cd9057876b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 1 Sep 2010 15:29:43 +0200 Subject: [PATCH 0610/2024] Bugfix: do not pass class object into parameters hash --- lib/active_scaffold.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 7f3f74d76b..2b5e8f9470 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -131,7 +131,7 @@ def link_for_association(column, options = {}) unless controller.nil? options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column options[:parameters] ||= {} - options[:parameters].reverse_merge! :parent_model => column.active_record_class, :association => column.association.name + options[:parameters].reverse_merge! :parent_model => column.active_record_class.to_s, :association => column.association.name if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. From 00e2db3a55c1e5321e3928e95fe5bdf5cf9f73d5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Sep 2010 09:28:10 +0200 Subject: [PATCH 0611/2024] extract method ActionLink.get --- .../javascripts/jquery/active_scaffold.js | 41 ++++++++++--------- .../javascripts/prototype/active_scaffold.js | 36 ++++++++-------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index d4ddec2f61..a77620b15d 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -25,23 +25,8 @@ $(document).ready(function() { } }); $('a.as_action').live('ajax:before', function(event) { - var as_action = $(this); - if (typeof(as_action.data('action_link')) === 'undefined') { - var parent = as_action.parent(); - if (parent && parent.get(0).nodeName.toUpperCase() == 'TD') { - // record action - parent = parent.closest('tr.record'); - var target = parent.find('a.as_action'); - var loading_indicator = parent.find('td.actions .loading-indicator'); - new ActiveScaffold.Actions.Record(target, parent, loading_indicator); - } else if (parent && parent.get(0).nodeName.toUpperCase() == 'DIV') { - //table action - new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header'), parent.find('.loading-indicator')); - } - as_action = $(this); - } - if (as_action.data('action_link')) { - var action_link = as_action.data('action_link'); + var action_link = ActiveScaffold.ActionLink.get($(this)); + if (action_link) { if (action_link.is_disabled()) { return false; } else { @@ -61,7 +46,6 @@ $(document).ready(function() { } else { action_link.enable(); } - //event.stop(); return true; } return true; @@ -626,7 +610,26 @@ ActiveScaffold.Actions.Abstract = Class.extend({ * A DataStructures::ActionLink, represented in JavaScript. * Concerned with AJAX-enabling a link and adapting the result for insertion into the table. */ -ActiveScaffold.ActionLink = new Object(); +ActiveScaffold.ActionLink = { + get: function(as_action) { + if (typeof(as_action.data('action_link')) === 'undefined') { + var parent = as_action.parent(); + + if (parent && parent.is('td')) { + // record action + parent = parent.closest('tr.record'); + var target = parent.find('a.as_action'); + var loading_indicator = parent.find('td.actions .loading-indicator'); + new ActiveScaffold.Actions.Record(target, parent, loading_indicator); + } else if (parent && parent.is('div')) { + //table action + new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header'), parent.find('.loading-indicator')); + } + as_action = $(as_action); + } + return as_action.data('action_link'); + } +}; ActiveScaffold.ActionLink.Abstract = Class.extend({ init: function(a, target, loading_indicator) { this.tag = $(a); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index dd0dd6e59b..392f637c55 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -47,21 +47,8 @@ document.observe("dom:loaded", function() { } }); document.on('ajax:before', 'a.as_action', function(event) { - var as_action = event.findElement(); - if (typeof(as_action.action_link) === 'undefined') { - var parent = as_action.up(); - if (parent && parent.nodeName.toUpperCase() == 'TD') { - // record action - parent = parent.up('tr.record') - new ActiveScaffold.Actions.Record(parent.select('a.as_action'), parent, parent.down('td.actions .loading-indicator')); - } else if (parent && parent.nodeName.toUpperCase() == 'DIV') { - //table action - new ActiveScaffold.Actions.Table(parent.select('a.as_action'), parent.up('div.active-scaffold').down('tbody.before-header'), parent.down('.loading-indicator')); - } - as_action = event.findElement(); - } - if (as_action.action_link) { - var action_link = as_action.action_link; + var action_link = ActiveScaffold.ActionLink.get(event.findElement()); + if (action_link) { if (action_link.is_disabled()) { event.stop(); } else { @@ -608,7 +595,24 @@ ActiveScaffold.Actions.Abstract = Class.create({ * A DataStructures::ActionLink, represented in JavaScript. * Concerned with AJAX-enabling a link and adapting the result for insertion into the table. */ -ActiveScaffold.ActionLink = new Object(); +ActiveScaffold.ActionLink = { + get: function(as_action) { + if (typeof(as_action.action_link) === 'undefined') { + var parent = as_action.up(); + if (parent && parent.nodeName.toUpperCase() == 'TD') { + // record action + parent = parent.up('tr.record') + new ActiveScaffold.Actions.Record(parent.select('a.as_action'), parent, parent.down('td.actions .loading-indicator')); + } else if (parent && parent.nodeName.toUpperCase() == 'DIV') { + //table action + new ActiveScaffold.Actions.Table(parent.select('a.as_action'), parent.up('div.active-scaffold').down('tbody.before-header'), parent.down('.loading-indicator')); + } + as_action = $(as_action); + } + return as_action.action_link; + } +}; + ActiveScaffold.ActionLink.Abstract = Class.create({ initialize: function(a, target, loading_indicator) { this.tag = $(a); From 72b6465a01515627afe2a9061a2aad1f2a835d18 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Sep 2010 09:39:24 +0200 Subject: [PATCH 0612/2024] use new ActionLink.get method --- .../javascripts/jquery/active_scaffold.js | 15 ++++++--------- .../javascripts/prototype/active_scaffold.js | 17 +++++++---------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index a77620b15d..eb464ade60 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -37,9 +37,8 @@ $(document).ready(function() { return true; }); $('a.as_action').live('ajax:success', function(event, response) { - var as_action = $(this); - if (as_action.data('action_link')) { - var action_link = as_action.data('action_link'); + var action_link = ActiveScaffold.ActionLink.get($(this)); + if (action_link) { if (action_link.position) { action_link.insert(response); if (action_link.hide_target) action_link.target.hide(); @@ -51,17 +50,15 @@ $(document).ready(function() { return true; }); $('a.as_action').live('ajax:complete', function(event) { - var as_action = $(this); - if (as_action.data('action_link')) { - var action_link = as_action.data('action_link'); + var action_link = ActiveScaffold.ActionLink.get($(this)); + if (action_link) { if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden'); } return true; }); $('a.as_action').live('ajax:failure', function(event) { - var as_action = $(this); - if (as_action.data('action_link')) { - var action_link = as_action.data('action_link'); + var action_link = ActiveScaffold.ActionLink.get($(this)); + if (action_link) { ActiveScaffold.report_500_response(action_link.scaffold_id()); action_link.enable(); } diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 392f637c55..a0e542fb56 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -59,9 +59,8 @@ document.observe("dom:loaded", function() { return true; }); document.on('ajax:success', 'a.as_action', function(event) { - var as_action = event.findElement(); - if (as_action.action_link && event.memo && event.memo.request) { - var action_link = as_action.action_link; + var action_link = ActiveScaffold.ActionLink.get(event.findElement()); + if (action_link && event.memo && event.memo.request) { if (action_link.position) { action_link.insert(event.memo.request.responseText); if (action_link.hide_target) action_link.target.hide(); @@ -74,17 +73,15 @@ document.observe("dom:loaded", function() { return true; }); document.on('ajax:complete', 'a.as_action', function(event) { - var as_action = event.findElement(); - if (as_action.action_link) { - var action_link = as_action.action_link; - if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'hidden'; + var action_link = ActiveScaffold.ActionLink.get(event.findElement()); + if (action_link && action_link.loading_indicator) { + action_link.loading_indicator.style.visibility = 'hidden'; } return true; }); document.on('ajax:failure', 'a.as_action', function(event) { - var as_action = event.findElement(); - if (as_action.action_link) { - var action_link = as_action.action_link; + var action_link = ActiveScaffold.ActionLink.get(event.findElement()); + if (action_link) { ActiveScaffold.report_500_response(action_link.scaffold_id()); action_link.enable(); } From 5274e2650a003da7ec237ab0f61d83eb057c76d4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Sep 2010 09:55:05 +0200 Subject: [PATCH 0613/2024] extract method set_adapter --- .../javascripts/prototype/active_scaffold.js | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index a0e542fb56..ff8087c70e 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -681,7 +681,13 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ update_flash_messages: function(messages) { message_node = $(this.scaffold_id().sub('-active-scaffold', '-messages')); if (message_node) message_node.update(messages); - } + }, + + set_adapter: function(element) { + this.adapter = element; + this.adapter.addClassName('as_adapter'); + this.adapter.action_link = this; + }, }); /** @@ -726,15 +732,11 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra if (this.position == 'after') { this.target.insert({after:content}); - this.adapter = this.target.next(); - this.adapter.addClassName('as_adapter'); - this.adapter.action_link = this; + this.set_adapter(this.target.next()); } else if (this.position == 'before') { this.target.insert({before:content}); - this.adapter = this.target.previous(); - this.adapter.addClassName('as_adapter'); - this.adapter.action_link = this; + this.set_adapter(this.target.previous()); } else { return false; @@ -782,9 +784,7 @@ ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstrac insert: function(content) { if (this.position == 'top') { this.target.insert({top:content}); - this.adapter = this.target.immediateDescendants().first(); - this.adapter.addClassName('as_adapter'); - this.adapter.action_link = this; + this.set_adapter(this.target.immediateDescendants().first()); } else { throw 'Unknown position "' + this.position + '"' From ed62909d43647e1b4953e6fbb8a1629da1e2a09f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Sep 2010 10:31:41 +0200 Subject: [PATCH 0614/2024] further refactoring to unify getting action_link object --- .../javascripts/jquery/active_scaffold.js | 35 +++++++++--------- .../javascripts/prototype/active_scaffold.js | 36 +++++++++---------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index eb464ade60..849fb062b9 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -65,11 +65,10 @@ $(document).ready(function() { return true; }); $('a.as_cancel').live('ajax:before', function(event) { - var as_adapter = $(this).closest('.as_adapter'); var as_cancel = $(this); + var action_link = ActiveScaffold.find_action_link(as_cancel); - if (as_adapter.data('action_link')) { - var action_link = as_adapter.data('action_link'); + if (action_link) { var cancel_url = as_cancel.attr('href'); var refresh_data = as_cancel.attr('data-refresh'); if (refresh_data === 'true' && action_link.refresh_url) { @@ -83,10 +82,9 @@ $(document).ready(function() { return true; }); $('a.as_cancel').live('ajax:success', function(event, response) { - var as_adapter = $(this).closest('.as_adapter'); + var action_link = ActiveScaffold.find_action_link($(this)); - if (as_adapter.data('action_link')) { - var action_link = as_adapter.data('action_link'); + if (action_link) { if (action_link.position) { action_link.close(response); } else { @@ -96,9 +94,8 @@ $(document).ready(function() { return true; }); $('a.as_cancel').live('ajax:failure', function(event) { - var as_adapter = $(this).closest('.as_adapter'); - if (as_adapter.data('action_link')) { - var action_link = as_adapter.data('action_link'); + var action_link = ActiveScaffold.find_action_link($(this)); + if (action_link) { ActiveScaffold.report_500_response(action_link.scaffold_id()); } return true; @@ -441,9 +438,13 @@ var ActiveScaffold = { var tbody = row.closest('tbody.records'); var current_action_node = row.find('td.actions a.disabled').first(); - if (current_action_node && current_action_node.data('action_link')) { - current_action_node.data('action_link').close_previous_adapter(); + if (current_action_node) { + var action_link = ActiveScaffold.ActionLink.get(current_action_node); + if (action_link) { + action_link.close_previous_adapter(); + } } + row.remove(); this.stripe(tbody); this.decrement_record_count(tbody.closest('div.active-scaffold')); @@ -460,7 +461,7 @@ var ActiveScaffold = { find_action_link: function(element) { if (typeof(element) == 'string') element = '#' + element; var as_adapter = $(element).closest('.as_adapter'); - return as_adapter.data('action_link'); + return ActiveScaffold.ActionLink.get(as_adapter);; }, scroll_to: function(element) { @@ -608,9 +609,9 @@ ActiveScaffold.Actions.Abstract = Class.extend({ * Concerned with AJAX-enabling a link and adapting the result for insertion into the table. */ ActiveScaffold.ActionLink = { - get: function(as_action) { - if (typeof(as_action.data('action_link')) === 'undefined') { - var parent = as_action.parent(); + get: function(element) { + if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) { + var parent = element.parent(); if (parent && parent.is('td')) { // record action @@ -622,9 +623,9 @@ ActiveScaffold.ActionLink = { //table action new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header'), parent.find('.loading-indicator')); } - as_action = $(as_action); + element = $(element); } - return as_action.data('action_link'); + return element.data('action_link'); } }; ActiveScaffold.ActionLink.Abstract = Class.extend({ diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index ff8087c70e..8c66b839b2 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -88,11 +88,10 @@ document.observe("dom:loaded", function() { return true; }); document.on('ajax:before', 'a.as_cancel', function(event) { - var as_adapter = event.findElement('.as_adapter'); var as_cancel = event.findElement(); + var action_link = ActiveScaffold.find_action_link(as_cancel); - if (as_adapter.action_link) { - var action_link = as_adapter.action_link; + if (action_link) { var refresh_data = as_cancel.readAttribute('data-refresh'); if (refresh_data === 'true' && action_link.refresh_url) { event.memo.url = action_link.refresh_url; @@ -104,10 +103,8 @@ document.observe("dom:loaded", function() { return true; }); document.on('ajax:success', 'a.as_cancel', function(event) { - var as_adapter = event.findElement('.as_adapter'); - - if (as_adapter.action_link) { - var action_link = as_adapter.action_link; + var action_link = ActiveScaffold.find_action_link(event.findElement()); + if (action_link) { if (action_link.position) { action_link.close(event.memo.request.responseText); } else { @@ -117,9 +114,8 @@ document.observe("dom:loaded", function() { return true; }); document.on('ajax:failure', 'a.as_cancel', function(event) { - var as_adapter = event.findElement('.as_adapter'); - if (as_adapter.action_link) { - var action_link = as_adapter.action_link; + var action_link = ActiveScaffold.find_action_link(event.findElement()); + if (action_link) { ActiveScaffold.report_500_response(action_link.scaffold_id()); } return true; @@ -392,8 +388,12 @@ var ActiveScaffold = { var tbody = row.up('tbody.records'); var current_action_node = row.down('td.actions a.disabled'); - if (current_action_node && current_action_node.action_link) { - current_action_node.action_link.close_previous_adapter(); + + if (current_action_node) { + var action_link = ActiveScaffold.ActionLink.get(current_action_node); + if (action_link) { + action_link.close_previous_adapter(); + } } row.remove(); this.stripe(tbody); @@ -411,7 +411,7 @@ var ActiveScaffold = { }, find_action_link: function(element) { - return $(element).up('.as_adapter').action_link; + return ActiveScaffold.ActionLink.get($(element).up('.as_adapter')); }, scroll_to: function(element) { @@ -593,9 +593,9 @@ ActiveScaffold.Actions.Abstract = Class.create({ * Concerned with AJAX-enabling a link and adapting the result for insertion into the table. */ ActiveScaffold.ActionLink = { - get: function(as_action) { - if (typeof(as_action.action_link) === 'undefined') { - var parent = as_action.up(); + get: function(element) { + if (typeof(element.action_link) === 'undefined' && !element.hasClassName('as_adapter')) { + var parent = element.up(); if (parent && parent.nodeName.toUpperCase() == 'TD') { // record action parent = parent.up('tr.record') @@ -604,9 +604,9 @@ ActiveScaffold.ActionLink = { //table action new ActiveScaffold.Actions.Table(parent.select('a.as_action'), parent.up('div.active-scaffold').down('tbody.before-header'), parent.down('.loading-indicator')); } - as_action = $(as_action); + element = $(element); } - return as_action.action_link; + return element.action_link; } }; From 4221a7637e3c2f05c83ab5f50895451b5c5e5bfd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Sep 2010 10:50:19 +0200 Subject: [PATCH 0615/2024] use prototypes storage api to prevent memory leaks --- .../default/javascripts/prototype/active_scaffold.js | 8 ++++---- frontends/default/views/_list_inline_adapter.html.erb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 8c66b839b2..856e699b4e 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -594,7 +594,7 @@ ActiveScaffold.Actions.Abstract = Class.create({ */ ActiveScaffold.ActionLink = { get: function(element) { - if (typeof(element.action_link) === 'undefined' && !element.hasClassName('as_adapter')) { + if (typeof(element.retrieve('action_link')) === 'undefined' && !element.hasClassName('as_adapter')) { var parent = element.up(); if (parent && parent.nodeName.toUpperCase() == 'TD') { // record action @@ -606,7 +606,7 @@ ActiveScaffold.ActionLink = { } element = $(element); } - return element.action_link; + return element.retrieve('action_link'); } }; @@ -634,7 +634,7 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ this.hide_target = false; this.position = this.tag.getAttribute('data-position'); - this.tag.action_link = this; + this.tag.store('action_link', this); }, open: function(event) { @@ -686,7 +686,7 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ set_adapter: function(element) { this.adapter = element; this.adapter.addClassName('as_adapter'); - this.adapter.action_link = this; + this.adapter.store('action_link', this); }, }); diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index 761ae64cf2..836007a060 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -8,4 +8,4 @@ </td> </tr> <% row_id = "#{ActiveScaffold.js_framework == :jquery ? '#' : ''}#{element_row_id(:action => :nested)}" %> -<%= javascript_tag("$('#{row_id}').action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');") %> +<%= javascript_tag("ActiveScaffold.ActionLink.get($('#{row_id}')).update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');") %> From a871d3f8400d619d45f4eed2117dd1cfae1ac9b6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Sep 2010 11:24:00 +0200 Subject: [PATCH 0616/2024] Bugfix: jquery javascript error in list_inline_adapter --- .../default/javascripts/jquery/active_scaffold.js | 12 ++++++++++++ .../default/javascripts/prototype/active_scaffold.js | 1 + .../default/views/_list_inline_adapter.html.erb | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 849fb062b9..a61383cb30 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -610,6 +610,8 @@ ActiveScaffold.Actions.Abstract = Class.extend({ */ ActiveScaffold.ActionLink = { get: function(element) { + if (typeof(element) == 'string') element = '#' + element; + var element = $(element); if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) { var parent = element.parent(); @@ -785,6 +787,16 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ if (item.url != _this.url) return; item.tag.addClass('disabled'); }); + }, + + set_opened: function() { + if (this.position == 'after') { + this.set_adapter(this.target.next()); + } + else if (this.position == 'before') { + this.set_adapter(this.target.prev()); + } + this.disable(); } }); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 856e699b4e..b8d185b2c6 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -594,6 +594,7 @@ ActiveScaffold.Actions.Abstract = Class.create({ */ ActiveScaffold.ActionLink = { get: function(element) { + var element = $(element); if (typeof(element.retrieve('action_link')) === 'undefined' && !element.hasClassName('as_adapter')) { var parent = element.up(); if (parent && parent.nodeName.toUpperCase() == 'TD') { diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index 836007a060..996256cf38 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -8,4 +8,4 @@ </td> </tr> <% row_id = "#{ActiveScaffold.js_framework == :jquery ? '#' : ''}#{element_row_id(:action => :nested)}" %> -<%= javascript_tag("ActiveScaffold.ActionLink.get($('#{row_id}')).update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');") %> +<%= javascript_tag("ActiveScaffold.ActionLink.get('#{row_id}').update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');") %> From 6857d25ded5dbab9c96606744907fa57a08602bd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Sep 2010 13:04:15 +0200 Subject: [PATCH 0617/2024] Bugfix: check if we got an action_link --- frontends/default/views/_list_inline_adapter.html.erb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index 996256cf38..67109a02b0 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -7,5 +7,4 @@ </div> </td> </tr> -<% row_id = "#{ActiveScaffold.js_framework == :jquery ? '#' : ''}#{element_row_id(:action => :nested)}" %> -<%= javascript_tag("ActiveScaffold.ActionLink.get('#{row_id}').update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');") %> +<%= javascript_tag("var action_link = ActiveScaffold.ActionLink.get('#{element_row_id(:action => :nested)}'); if (action_link) action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');") %> From 6c47698517fa0cc293d088025cac3993aa2f0b90 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Sep 2010 13:26:06 +0200 Subject: [PATCH 0618/2024] add option to identify a nested action_link --- lib/active_scaffold/config/nested.rb | 2 +- lib/active_scaffold/data_structures/action_link.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index 9141a75b45..c8c501c577 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -20,7 +20,7 @@ def initialize(core_config) def add_link(attribute, options = {}) column = @core.columns[attribute.to_sym] unless column.nil? || column.association.nil? - options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) + options.reverse_merge! :nested_link => true, :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) action_link = @core.link_for_association(column, options) @core.action_links.add(action_link) unless action_link.nil? end diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 8f7af06305..c15198f9c2 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -148,5 +148,15 @@ def position # nested action_links are referencing a column attr_accessor :column + + # indicates that this a nested_link + def nested_link? + @column + end + + # Internal use: generated eid for this action_link + attr_accessor :eid + + end end From bab1795751d06fd0c05f4d6fbb7697ceceff0553 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Sep 2010 13:27:25 +0200 Subject: [PATCH 0619/2024] Bugfix: generate unique action_link ids --- lib/active_scaffold/helpers/view_helpers.rb | 36 ++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index e98344b0a8..e5562ac273 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -132,19 +132,19 @@ def render_action_link(link, url_options, record = nil, html_options = {}) action_link_html(link, url_options, html_options) end - def action_link_url_options(link, url_options, record) - options = url_options.clone - options[:action] = link.action - options[:controller] = link.controller if link.controller - options.delete(:search) if link.controller and link.controller.to_s != params[:controller] - options.merge! link.parameters if link.parameters - url_options_for_nested_link(link.column, record, link, options) unless link.column.nil? - options[:_method] = link.method if link.inline? && link.method != :get - options + def action_link_url_options(link, url_options, record, options = {}) + url_options = url_options.clone + url_options[:action] = link.action + url_options[:controller] = link.controller if link.controller + url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller] + url_options.merge! link.parameters if link.parameters + url_options_for_nested_link(link.column, record, link, url_options, options) unless link.column.nil? + url_options[:_method] = link.method if link.inline? && link.method != :get + url_options end def action_link_html_options(link, url_options, record, html_options) - id = url_options[:id] || url_options[:parent_id] + link_id = get_action_link_id(url_options) html_options.reverse_merge! link.html_options.merge(:class => link.action) # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails @@ -154,17 +154,21 @@ def action_link_html_options(link, url_options, record, html_options) html_options['data-position'] = link.position if link.position and link.inline? html_options[:class] += ' as_action' if link.inline? html_options[:popup] = true if link.popup? - html_options[:id] = action_link_id("#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}" + url_options[:action].to_s, id) + html_options[:id] = link_id html_options[:remote] = true unless link.page? if link.dhtml_confirm? html_options[:class] += ' as_action' if !link.inline? html_options[:page_link] = 'true' if !link.inline? html_options[:dhtml_confirm] = link.dhtml_confirm.value - html_options[:onclick] = link.dhtml_confirm.onclick_function(controller,action_link_id(url_options[:action],id)) + html_options[:onclick] = link.dhtml_confirm.onclick_function(controller, link_id) end html_options[:class] += " #{link.html_options[:class]}" unless link.html_options[:class].blank? html_options end + def get_action_link_id(url_options) + action_id = "#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}#{url_options[:action].to_s}" + action_link_id(action_id, url_options[:id] || url_options[:parent_id]) + end def action_link_html(link, url, html_options) # issue 260, use url_options[:link] if it exists. This prevents DB data from being localized. @@ -179,11 +183,13 @@ def action_link_html(link, url, html_options) url.nil? ? html.sub(/href=".*?"/, '') : html end - def url_options_for_nested_link(column, record, link, url_options) + def url_options_for_nested_link(column, record, link, url_options, options = {}) if column.association url_options[:assoc_id] = url_options.delete(:id) - url_options[:id] = record.send(column.association.name) if column.singular_association? - url_options[:eid] = "#{params[:controller]}_#{ActiveSupport::SecureRandom.hex(10)}" + url_options[:id] = "#{column.association.name}-#{record.send(column.association.name).id}" if column.singular_association? + url_options[:id] = "#{column.association.name}-#{record.id}" if column.plural_association? + link.eid = "#{params[:controller]}_#{ActiveSupport::SecureRandom.hex(10)}" unless options.has_key?(:reuse_eid) + url_options[:eid] = link.eid end end From 29d619a43ceff9bc0dce2da8ef42cbb55ea18868 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Sep 2010 13:49:50 +0200 Subject: [PATCH 0620/2024] Bugfix: next try to generate unique action_link_ids --- lib/active_scaffold/helpers/view_helpers.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index e5562ac273..9c7bb8f533 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -144,7 +144,7 @@ def action_link_url_options(link, url_options, record, options = {}) end def action_link_html_options(link, url_options, record, html_options) - link_id = get_action_link_id(url_options) + link_id = get_action_link_id(url_options, record, link.column) html_options.reverse_merge! link.html_options.merge(:class => link.action) # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails @@ -165,9 +165,12 @@ def action_link_html_options(link, url_options, record, html_options) html_options[:class] += " #{link.html_options[:class]}" unless link.html_options[:class].blank? html_options end - def get_action_link_id(url_options) + def get_action_link_id(url_options, record = nil, column = nil) + id = url_options[:id] || url_options[:parent_id] + id = "#{column.association.name}-#{record.id}" if column && column.plural_association? + id = "#{column.association.name}-#{record.send(column.association.name).id}" if column && column.singular_association? action_id = "#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}#{url_options[:action].to_s}" - action_link_id(action_id, url_options[:id] || url_options[:parent_id]) + action_link_id(action_id, id) end def action_link_html(link, url, html_options) @@ -186,8 +189,7 @@ def action_link_html(link, url, html_options) def url_options_for_nested_link(column, record, link, url_options, options = {}) if column.association url_options[:assoc_id] = url_options.delete(:id) - url_options[:id] = "#{column.association.name}-#{record.send(column.association.name).id}" if column.singular_association? - url_options[:id] = "#{column.association.name}-#{record.id}" if column.plural_association? + url_options[:id] = record.send(column.association.name).id if column.singular_association? link.eid = "#{params[:controller]}_#{ActiveSupport::SecureRandom.hex(10)}" unless options.has_key?(:reuse_eid) url_options[:eid] = link.eid end From 75409254c78cb2042c64813f24f7ceb5a92750be Mon Sep 17 00:00:00 2001 From: Blaz Grilc <blaz@spletnik.si> Date: Thu, 2 Sep 2010 18:15:24 +0800 Subject: [PATCH 0621/2024] fixed template_exists? arguments so partial overrides work with Rails 3.0.0 --- lib/active_scaffold/helpers/form_column_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 315248258a..864f9e30b2 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -226,7 +226,7 @@ def onsubmit # add functionality for overriding subform partials from association class path def override_subform_partial?(column, subform_partial) path, partial_name = partial_pieces(override_subform_partial(column, subform_partial)) - template_exists?(File.join(path, "_#{partial_name}")) + template_exists?(partial_name, path, true) end def override_subform_partial(column, subform_partial) @@ -235,7 +235,7 @@ def override_subform_partial(column, subform_partial) def override_form_field_partial?(column) path, partial_name = partial_pieces(override_form_field_partial(column)) - template_exists?(File.join(path, "_#{partial_name}"), true) + template_exists?(partial_name, path, true) end # the naming convention for overriding form fields with partials From e285a3e73c96d2a98464fec59f310165a514b6fd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Sep 2010 16:55:15 +0200 Subject: [PATCH 0622/2024] revert: setting a nested_link option --- lib/active_scaffold/config/nested.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index c8c501c577..9141a75b45 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -20,7 +20,7 @@ def initialize(core_config) def add_link(attribute, options = {}) column = @core.columns[attribute.to_sym] unless column.nil? || column.association.nil? - options.reverse_merge! :nested_link => true, :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) + options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) action_link = @core.link_for_association(column, options) @core.action_links.add(action_link) unless action_link.nil? end From 8a8e19accec9512561bec70a0eb854f40590b83e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Sep 2010 16:58:51 +0200 Subject: [PATCH 0623/2024] add list option nested_auto_open (render_component needed) conf.list.nested_auto_open = {:players => 2} will open nested views if there are 2 or less records in view --- frontends/default/views/_list_record.html.erb | 13 ++++++++++++- lib/active_scaffold/actions/list.rb | 1 + lib/active_scaffold/config/list.rb | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index aacb78b09e..7a757ca8f1 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -4,9 +4,20 @@ columns ||= active_scaffold_config.list.columns.collect_visible tr_class = cycle("", "even-record") tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class url_options = params_for(:action => :list, :id => record.id) +action_links = active_scaffold_config.action_links -%> <tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get, :escape => false)).html_safe %>"> <%= render :partial => 'list_record_columns', :locals => {:record => record, :columns => columns} %> - <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options} if active_scaffold_config.action_links.any? {|link| link.type == :member } %> + <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options, :action_links => action_links} if action_links.any? {|link| link.type == :member } %> + <% unless @nested_auto_open.nil? || %> + <% action_links.each(:member) do |link| %> + <% if link.nested_link? && @nested_auto_open[link.column.name] && @records.length <= @nested_auto_open[link.column.name] && respond_to?(:render_component) %> + <% link_url_options = {:adapter => '_list_inline_adapter', :format => :js}.merge(action_link_url_options(link, url_options, record, options = {:reuse_eid => true})) + link_id = get_action_link_id(link_url_options, record, link.column)%> + <%= render_component(link_url_options).html_safe %> + <%= javascript_tag("ActiveScaffold.ActionLink.get('#{link_id}').set_opened();") %> + <% end %> + <% end %> + <% end %> </tr> diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index d3d2af16e7..004bc6b0ce 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -17,6 +17,7 @@ def list do_list do_new if active_scaffold_config.list.always_show_create @record ||= active_scaffold_config.model.new if active_scaffold_config.list.always_show_search + @nested_auto_open = active_scaffold_config.list.nested_auto_open respond_to_action(:list) end diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index e4ef51b728..d5440cc8a4 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -115,6 +115,12 @@ def always_show_create @always_show_create && @core.actions.include?(:create) end + # might be set to open nested_link automatically in view + # conf.nested.add_link(:players) + # conf.list.nested_auto_open = {:players => 2} + # will open nested views if there are 2 or less records in view + attr_accessor :nested_auto_open + class UserSettings < UserSettings # This label has alread been localized. def label From cdaadbb38ee699e3d432475ab38e598dbfe592cc Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 2 Sep 2010 17:04:17 +0200 Subject: [PATCH 0624/2024] Delay calling dhtmlHistory.create, it fixes issue #760 --- .../default/javascripts/dhtml_history.js | 39 +++++++++---------- .../active_scaffold/default/dhtml_history.js | 39 +++++++++---------- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/frontends/default/javascripts/dhtml_history.js b/frontends/default/javascripts/dhtml_history.js index 3bf6275c48..323239c3ca 100755 --- a/frontends/default/javascripts/dhtml_history.js +++ b/frontends/default/javascripts/dhtml_history.js @@ -831,26 +831,6 @@ Querystring.prototype.contains = function(key) { return (value != null); } -/*******************************************************************/ -/* Added by Ed Wildgoose - MailASail */ -/* Initialise the library and add our history callback */ -/*******************************************************************/ -window.dhtmlHistory.create({ - toJSON: function(o) { - return Object.toJSON(o); - } - , fromJSON: function(s) { - return s.evalJSON(); - } - - // Enable this to assist with debugging -// , debugMode: true - - // dhtmlHistory has been modified not to need the next line - // But left in for robustness when updating dhtmlHistory - , blankURL: '/blank.html?' -}); - /** Our callback to receive history change events. */ var handleHistoryChange = function(pageId, pageData) { @@ -862,6 +842,25 @@ var handleHistoryChange = function(pageId, pageData) { } window.onload = function() { + /*******************************************************************/ + /* Added by Ed Wildgoose - MailASail */ + /* Initialise the library and add our history callback */ + /*******************************************************************/ + dhtmlHistory.create({ + toJSON: function(o) { + return Object.toJSON(o); + } + , fromJSON: function(s) { + return s.evalJSON(); + } + + // Enable this to assist with debugging + //, debugMode: true + + // dhtmlHistory has been modified not to need the next line + // But left in for robustness when updating dhtmlHistory + , blankURL: '/blank.html?' + }); dhtmlHistory.initialize(handleHistoryChange); }; diff --git a/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js b/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js index 3bf6275c48..323239c3ca 100755 --- a/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +++ b/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js @@ -831,26 +831,6 @@ Querystring.prototype.contains = function(key) { return (value != null); } -/*******************************************************************/ -/* Added by Ed Wildgoose - MailASail */ -/* Initialise the library and add our history callback */ -/*******************************************************************/ -window.dhtmlHistory.create({ - toJSON: function(o) { - return Object.toJSON(o); - } - , fromJSON: function(s) { - return s.evalJSON(); - } - - // Enable this to assist with debugging -// , debugMode: true - - // dhtmlHistory has been modified not to need the next line - // But left in for robustness when updating dhtmlHistory - , blankURL: '/blank.html?' -}); - /** Our callback to receive history change events. */ var handleHistoryChange = function(pageId, pageData) { @@ -862,6 +842,25 @@ var handleHistoryChange = function(pageId, pageData) { } window.onload = function() { + /*******************************************************************/ + /* Added by Ed Wildgoose - MailASail */ + /* Initialise the library and add our history callback */ + /*******************************************************************/ + dhtmlHistory.create({ + toJSON: function(o) { + return Object.toJSON(o); + } + , fromJSON: function(s) { + return s.evalJSON(); + } + + // Enable this to assist with debugging + //, debugMode: true + + // dhtmlHistory has been modified not to need the next line + // But left in for robustness when updating dhtmlHistory + , blankURL: '/blank.html?' + }); dhtmlHistory.initialize(handleHistoryChange); }; From 8bfa708ca9489f4e0b93b035d78efca0c7ca9d7f Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@entrecables.com> Date: Thu, 2 Sep 2010 22:15:59 +0200 Subject: [PATCH 0625/2024] Revert "Delay calling dhtmlHistory.create, it fixes issue #760" It breaks ActiveScaffol This reverts commit cdaadbb38ee699e3d432475ab38e598dbfe592cc. --- .../default/javascripts/dhtml_history.js | 39 ++++++++++--------- .../active_scaffold/default/dhtml_history.js | 39 ++++++++++--------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/frontends/default/javascripts/dhtml_history.js b/frontends/default/javascripts/dhtml_history.js index 323239c3ca..3bf6275c48 100755 --- a/frontends/default/javascripts/dhtml_history.js +++ b/frontends/default/javascripts/dhtml_history.js @@ -831,6 +831,26 @@ Querystring.prototype.contains = function(key) { return (value != null); } +/*******************************************************************/ +/* Added by Ed Wildgoose - MailASail */ +/* Initialise the library and add our history callback */ +/*******************************************************************/ +window.dhtmlHistory.create({ + toJSON: function(o) { + return Object.toJSON(o); + } + , fromJSON: function(s) { + return s.evalJSON(); + } + + // Enable this to assist with debugging +// , debugMode: true + + // dhtmlHistory has been modified not to need the next line + // But left in for robustness when updating dhtmlHistory + , blankURL: '/blank.html?' +}); + /** Our callback to receive history change events. */ var handleHistoryChange = function(pageId, pageData) { @@ -842,25 +862,6 @@ var handleHistoryChange = function(pageId, pageData) { } window.onload = function() { - /*******************************************************************/ - /* Added by Ed Wildgoose - MailASail */ - /* Initialise the library and add our history callback */ - /*******************************************************************/ - dhtmlHistory.create({ - toJSON: function(o) { - return Object.toJSON(o); - } - , fromJSON: function(s) { - return s.evalJSON(); - } - - // Enable this to assist with debugging - //, debugMode: true - - // dhtmlHistory has been modified not to need the next line - // But left in for robustness when updating dhtmlHistory - , blankURL: '/blank.html?' - }); dhtmlHistory.initialize(handleHistoryChange); }; diff --git a/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js b/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js index 323239c3ca..3bf6275c48 100755 --- a/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +++ b/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js @@ -831,6 +831,26 @@ Querystring.prototype.contains = function(key) { return (value != null); } +/*******************************************************************/ +/* Added by Ed Wildgoose - MailASail */ +/* Initialise the library and add our history callback */ +/*******************************************************************/ +window.dhtmlHistory.create({ + toJSON: function(o) { + return Object.toJSON(o); + } + , fromJSON: function(s) { + return s.evalJSON(); + } + + // Enable this to assist with debugging +// , debugMode: true + + // dhtmlHistory has been modified not to need the next line + // But left in for robustness when updating dhtmlHistory + , blankURL: '/blank.html?' +}); + /** Our callback to receive history change events. */ var handleHistoryChange = function(pageId, pageData) { @@ -842,25 +862,6 @@ var handleHistoryChange = function(pageId, pageData) { } window.onload = function() { - /*******************************************************************/ - /* Added by Ed Wildgoose - MailASail */ - /* Initialise the library and add our history callback */ - /*******************************************************************/ - dhtmlHistory.create({ - toJSON: function(o) { - return Object.toJSON(o); - } - , fromJSON: function(s) { - return s.evalJSON(); - } - - // Enable this to assist with debugging - //, debugMode: true - - // dhtmlHistory has been modified not to need the next line - // But left in for robustness when updating dhtmlHistory - , blankURL: '/blank.html?' - }); dhtmlHistory.initialize(handleHistoryChange); }; From a51a51bccf63c67f11b87a52fa59d569e238982e Mon Sep 17 00:00:00 2001 From: Blaz Grilc <blaz@spletnik.si> Date: Thu, 2 Sep 2010 21:04:50 +0800 Subject: [PATCH 0626/2024] work around jquery 1.4.2 .data() access bug see: http://github.com/jquery/jquery/commit/9e06903a99caf5619d0db858ed3d24f0e6ee15db --- frontends/default/javascripts/jquery/active_scaffold.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index a61383cb30..b532f0ff24 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -113,6 +113,7 @@ $(document).ready(function() { return true; }); $('span.in_place_editor_field').live('hover', function(event) { + $(this).data(); // jquery 1.4.2 workaround if (event.type == 'mouseenter') { if (typeof($(this).data('editInPlace')) === 'undefined') $(this).addClass("hover"); } @@ -123,7 +124,7 @@ $(document).ready(function() { }); $('span.in_place_editor_field').live('click', function(event) { var span = $(this); - + span.data(); // jquery 1.4.2 workaround if (typeof(span.data('editInPlace')) === 'undefined') { var options = {show_buttons: true, hover_class: 'hover', @@ -612,6 +613,7 @@ ActiveScaffold.ActionLink = { get: function(element) { if (typeof(element) == 'string') element = '#' + element; var element = $(element); + element.data(); // jquery 1.4.2 workaround if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) { var parent = element.parent(); From 2f94945d176439d27c209545eb268406eed99906 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 3 Sep 2010 13:43:56 +0200 Subject: [PATCH 0627/2024] extract method render_nested_view --- frontends/default/views/_list_record.html.erb | 11 +---------- lib/active_scaffold/helpers/list_column_helpers.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 7a757ca8f1..1e6555d84e 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -10,14 +10,5 @@ action_links = active_scaffold_config.action_links <tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get, :escape => false)).html_safe %>"> <%= render :partial => 'list_record_columns', :locals => {:record => record, :columns => columns} %> <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options, :action_links => action_links} if action_links.any? {|link| link.type == :member } %> - <% unless @nested_auto_open.nil? || %> - <% action_links.each(:member) do |link| %> - <% if link.nested_link? && @nested_auto_open[link.column.name] && @records.length <= @nested_auto_open[link.column.name] && respond_to?(:render_component) %> - <% link_url_options = {:adapter => '_list_inline_adapter', :format => :js}.merge(action_link_url_options(link, url_options, record, options = {:reuse_eid => true})) - link_id = get_action_link_id(link_url_options, record, link.column)%> - <%= render_component(link_url_options).html_safe %> - <%= javascript_tag("ActiveScaffold.ActionLink.get('#{link_id}').set_opened();") %> - <% end %> - <% end %> - <% end %> + <%= render_nested_view(action_links, url_options, record) unless @nested_auto_open.nil? %> </tr> diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 8fcc060dfa..82969e5c76 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -341,6 +341,19 @@ def column_heading_value(column, sorting, sort_direction) end end end + + def render_nested_view(action_links, url_options, record) + rendered = [] + action_links.each(:member) do |link| + if link.nested_link? && @nested_auto_open[link.column.name] && @records.length <= @nested_auto_open[link.column.name] && respond_to?(:render_component) + link_url_options = {:adapter => '_list_inline_adapter', :format => :js}.merge(action_link_url_options(link, url_options, record, options = {:reuse_eid => true})) + link_id = get_action_link_id(link_url_options, record, link.column) + rendered << (render_component(link_url_options) + javascript_tag("ActiveScaffold.ActionLink.get('#{link_id}').set_opened();")) + end + end + rendered.join(' ').html_safe + end + end end end From 6870322299c83fcd00c5202ffcfecd4f303774b9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 3 Sep 2010 16:43:33 +0200 Subject: [PATCH 0628/2024] Bugfix: Field Search datepicker input boxes with wrong value after first view --- .../bridges/date_picker/lib/datepicker_bridge.rb | 2 +- lib/active_scaffold/bridges/shared/date_bridge.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 0a51543975..fabbd2ab80 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -29,7 +29,7 @@ module Bridges module DatePickerBridge module SearchColumnHelpers def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) - options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date) + options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date, :value) options[:class] << " #{column.options[:class]}" if column.options[:class] text_field_tag("#{options[:name]}[#{name}]", current_search[name], options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) end diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index 983e3c568a..d6a9f4f6ab 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -6,7 +6,7 @@ module SearchColumnHelpers def active_scaffold_search_date_bridge(column, options) current_search = {'from' => nil, 'to' => nil, 'opt' => 'BETWEEN', 'number' => 1, 'unit' => 'DAYS', 'range' => nil} - current_search.merge!(field_search_params[column.name]) unless field_search_params[column.name].nil? + current_search.merge!(options[:value]) unless options[:value].nil? tags = [] tags << active_scaffold_search_date_bridge_comparator_tag(column, options, current_search) tags << active_scaffold_search_date_bridge_trend_tag(column, options, current_search) From 9d28516f0a4b5d9a499c53d7662f4050e4de7fb6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 3 Sep 2010 17:08:37 +0200 Subject: [PATCH 0629/2024] column.search_sql might be a proc --- lib/active_scaffold/finder.rb | 42 +++++++++++---------- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 66e84bed51..7063754ba8 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -38,17 +38,27 @@ def condition_for_column(column, value, text_search = :full) elsif self.respond_to?("condition_for_#{search_ui}_type") self.send("condition_for_#{search_ui}_type", column, value, like_pattern) else - case search_ui - when :boolean, :checkbox - ["#{column.search_sql} = ?", column.column.type_cast(value)] - when :select, :multi_select, :country, :usa_state - ["#{column.search_sql} in (?)", value] - else - if column.column.nil? || column.column.text? - ["LOWER(#{column.search_sql}) LIKE ?", like_pattern.sub('?', value.downcase)] + unless column.search_sql.instance_of? Proc + case search_ui + when :boolean, :checkbox + ["#{column.search_sql} = ?", column.column.type_cast(value)] + when :integer, :decimal, :float + condition_for_numeric(column, value) + when :string, :range + condition_for_range(column, value, like_pattern) + when :date, :time, :datetime, :timestamp + condition_for_datetime(column, value) + when :select, :multi_select, :country, :usa_state + ["#{column.search_sql} in (?)", value] else - ["#{column.search_sql} = ?", column.column.type_cast(value)] - end + if column.column.nil? || column.column.text? + ["LOWER(#{column.search_sql}) LIKE ?", like_pattern.sub('?', value.downcase)] + else + ["#{column.search_sql} = ?", column.column.type_cast(value)] + end + end + else + column.search_sql.call(value) end end rescue Exception => e @@ -57,7 +67,7 @@ def condition_for_column(column, value, text_search = :full) end end - def condition_for_integer_type(column, value, like_pattern = nil) + def condition_for_numeric(column, value) if !value.is_a?(Hash) ["#{column.search_sql} = ?", column.column.nil? ? value.to_f : column.column.type_cast(value)] elsif value[:from].blank? or not ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) @@ -73,10 +83,8 @@ def condition_for_integer_type(column, value, like_pattern = nil) ["#{column.search_sql} #{value[:opt]} ?", column.column.nil? ? value[:from].to_f : column.column.type_cast(value[:from])] end end - alias_method :condition_for_decimal_type, :condition_for_integer_type - alias_method :condition_for_float_type, :condition_for_integer_type - def condition_for_range_type(column, value, like_pattern = nil) + def condition_for_range(column, value, like_pattern = nil) if !value.is_a?(Hash) if column.column.nil? || column.column.text? ["LOWER(#{column.search_sql}) LIKE ?", like_pattern.sub('?', value.downcase)] @@ -95,9 +103,8 @@ def condition_for_range_type(column, value, like_pattern = nil) nil end end - alias_method :condition_for_string_type, :condition_for_range_type - def condition_for_datetime_type(column, value, like_pattern = nil) + def condition_for_datetime(column, value, like_pattern = nil) conversion = value[:from][:hour].blank? && value[:to][:hour].blank? ? :to_date : :to_time from_value, to_value = [:from, :to].collect do |field| Time.zone.local(*[:year, :month, :day, :hour, :minute, :second].collect {|part| value[field][part].to_i}) rescue nil @@ -113,9 +120,6 @@ def condition_for_datetime_type(column, value, like_pattern = nil) ["#{column.search_sql} BETWEEN ? AND ?", from_value.send(conversion).to_s(:db), to_value.send(conversion).to_s(:db)] end end - alias_method :condition_for_date_type, :condition_for_datetime_type - alias_method :condition_for_time_type, :condition_for_datetime_type - alias_method :condition_for_timestamp_type, :condition_for_datetime_type def condition_for_record_select_type(column, value, like_pattern = nil) if value.is_a?(Array) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 9c7bb8f533..087339c4bb 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -190,7 +190,7 @@ def url_options_for_nested_link(column, record, link, url_options, options = {}) if column.association url_options[:assoc_id] = url_options.delete(:id) url_options[:id] = record.send(column.association.name).id if column.singular_association? - link.eid = "#{params[:controller]}_#{ActiveSupport::SecureRandom.hex(10)}" unless options.has_key?(:reuse_eid) + link.eid = "#{controller_id.from(3)}_#{record.id}_#{column.association.name}" unless options.has_key?(:reuse_eid) url_options[:eid] = link.eid end end From e9e0c9c272ca203df803349325f73ba196974b54 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Sep 2010 10:49:14 +0200 Subject: [PATCH 0630/2024] added search_ui :null --- lib/active_scaffold/finder.rb | 8 ++++++++ lib/active_scaffold/helpers/search_column_helpers.rb | 8 ++++++++ lib/active_scaffold/locale/de.rb | 2 ++ lib/active_scaffold/locale/en.rb | 2 ++ lib/active_scaffold/locale/fr.rb | 2 ++ 5 files changed, 22 insertions(+) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 7063754ba8..48d337d68e 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -128,6 +128,14 @@ def condition_for_record_select_type(column, value, like_pattern = nil) ["#{column.search_sql} = ?", value] end end + + def condition_for_null_type(column, value, like_pattern = nil) + if ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(value) + ["#{column.search_sql} is null"] + else + ["#{column.search_sql} is not null"] + end + end def like_pattern(text_search) case text_search diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 5562014474..91b35bab9c 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -118,6 +118,14 @@ def active_scaffold_search_boolean(column, options) end # we can't use checkbox ui because it's not possible to decide whether search for this field or not alias_method :active_scaffold_search_checkbox, :active_scaffold_search_boolean + + def active_scaffold_search_null(column, options) + select_options = [] + select_options << [as_(:_select_), nil] + select_options << [as_(:null), true] + select_options << [as_(:not_null), false] + select_tag(options[:name], options_for_select(select_options, ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(field_search_params[column.name]))) + end def field_search_params_range_values(column) values = field_search_params[column.name] diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 778aba7bc7..6b564c1b7e 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -59,6 +59,8 @@ :'!=' => '!=', :between => 'Zwischen', :optional_attributes => 'Further Options', + :null => 'Definiert', + :not_null => 'Undefiniert', # error_messages :cant_destroy_record => "%{record} kann nicht gelöscht werden", diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 46ac2bc6fd..40a982afb5 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -65,6 +65,8 @@ :begins_with => 'Begins with', :ends_with => 'Ends with', :optional_attributes => 'Further Options', + :null => 'Null', + :not_null => 'Not Null', # error_messages :cant_destroy_record => "%{record} can't be destroyed", diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index fbdcb9eaa4..50d1ae6fa9 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -59,6 +59,8 @@ :'!=' => '!=', :between => 'Entre', :optional_attributes => 'Further Options', + :null => 'Null', + :not_null => 'Not Null', # error_messages :internal_error => 'Erreur de la requête (code 500, Erreur interne)', From cf7fdca50d2155adb0fa64e6c2760bcd082ebddc Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Sep 2010 10:50:41 +0200 Subject: [PATCH 0631/2024] added german translation --- lib/active_scaffold/locale/de.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 6b564c1b7e..fca317ae6e 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -58,7 +58,7 @@ :'<' => '<', :'!=' => '!=', :between => 'Zwischen', - :optional_attributes => 'Further Options', + :optional_attributes => 'Weitere', :null => 'Definiert', :not_null => 'Undefiniert', From 3375abc6587616ea32deb570f3bd6abed7fe3881 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Sep 2010 11:04:31 +0200 Subject: [PATCH 0632/2024] add missing enhanced date/time search localizations --- lib/active_scaffold/locale/de.rb | 19 +++++++++++++++++++ lib/active_scaffold/locale/en.rb | 19 +++++++++++++++++++ lib/active_scaffold/locale/fr.rb | 19 +++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index fca317ae6e..bc260a77fd 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -58,6 +58,25 @@ :'<' => '<', :'!=' => '!=', :between => 'Zwischen', + :today => 'Heute', + :yesterday => 'Gestern', + :tomorrow => 'Morgen', + :this_week => 'Diese Woche', + :prev_week => 'Letzte Woche', + :next_week => 'Nächste Woche', + :this_month => 'Diesen Monat', + :prev_month => 'Letzten Monat', + :next_month => 'Nächsten Monat', + :this_year => 'Dieses Jahr', + :prev_year => 'Letztes Jahr', + :next_year => 'Nächstes Jahr', + :past => 'Letzten..', + :future => 'Nächsten..', + :range => 'Spanne', + :days => 'Tage', + :weeks => 'Wochen', + :months => 'Monate', + :years => 'Jahre', :optional_attributes => 'Weitere', :null => 'Definiert', :not_null => 'Undefiniert', diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 40a982afb5..6aa4092046 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -64,6 +64,25 @@ :contains => 'Contains', :begins_with => 'Begins with', :ends_with => 'Ends with', + :today => 'Today', + :yesterday => 'Yesterday', + :tomorrow => 'Tommorrow', + :this_week => 'This Week', + :prev_week => 'Last Week', + :next_week => 'Next Week', + :this_month => 'This Month', + :prev_month => 'Last Month', + :next_month => 'Next Month', + :this_year => 'This Year', + :prev_year => 'Last Year', + :next_year => 'Next Year', + :past => 'Past', + :future => 'Future', + :range => 'Range', + :days => 'Days', + :weeks => 'Weeks', + :months => 'Months', + :years => 'Years', :optional_attributes => 'Further Options', :null => 'Null', :not_null => 'Not Null', diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 50d1ae6fa9..3e0ea867fb 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -58,6 +58,25 @@ :'<' => '<', :'!=' => '!=', :between => 'Entre', + :today => 'Today', + :yesterday => 'Yesterday', + :tomorrow => 'Tommorrow', + :this_week => 'This Week', + :prev_week => 'Last Week', + :next_week => 'Next Week', + :this_month => 'This Month', + :prev_month => 'Last Month', + :next_month => 'Next Month', + :this_year => 'This Year', + :prev_year => 'Last Year', + :next_year => 'Next Year', + :past => 'Past', + :future => 'Future', + :range => 'Range', + :days => 'Days', + :weeks => 'Weeks', + :months => 'Months', + :years => 'Years', :optional_attributes => 'Further Options', :null => 'Null', :not_null => 'Not Null', From b8814aa5c4ae9e7d609354554990e2133aaf51b4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Sep 2010 11:40:25 +0200 Subject: [PATCH 0633/2024] allow setting @record instance_variable --- lib/active_scaffold/actions/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 9fba33252d..3fc6a0274d 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -7,7 +7,7 @@ def self.included(base) base.helper_method :nested? end def render_field - @record = if params[:in_place_editing] + @record ||= if params[:in_place_editing] active_scaffold_config.model.find params[:id] else active_scaffold_config.model.new From b62bc08ebaeab650014a3bebb0ce324d8f1c240c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Sep 2010 11:52:14 +0200 Subject: [PATCH 0634/2024] always return an action_link --- lib/active_scaffold/data_structures/action_links.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index b36fb86e52..9c1242e2e2 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -10,7 +10,13 @@ def initialize def add(action, options = {}) link = action.is_a?(ActiveScaffold::DataStructures::ActionLink) ? action : ActiveScaffold::DataStructures::ActionLink.new(action, options) # NOTE: this duplicate check should be done by defining the comparison operator for an Action data structure - @set << link unless @set.any? {|a| a.action == link.action and a.controller == link.controller and a.parameters == link.parameters} + existing = @set.find {|a| a.action == link.action and a.controller == link.controller and a.parameters == link.parameters} + unless existing + @set << link + link + else + existing + end end alias_method :<<, :add From 74aeafdf7a0cabbf78d8a0c5431bdb00ef5cfbf3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Sep 2010 12:07:41 +0200 Subject: [PATCH 0635/2024] column css_class property might be a proc --- frontends/default/views/_list_record_columns.html.erb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_list_record_columns.html.erb b/frontends/default/views/_list_record_columns.html.erb index d1892fa260..7a18c31cfb 100644 --- a/frontends/default/views/_list_record_columns.html.erb +++ b/frontends/default/views/_list_record_columns.html.erb @@ -2,7 +2,7 @@ <% authorized = record.authorized_for?(:crud_type => :read, :column => column.name) -%> <% column_value = authorized ? get_column_value(record, column) : active_scaffold_config.list.empty_field_text -%> - <td class="<%= column_class(column, column_value) %>" > + <td class="<%= column_class(column, column_value, record) %>" > <%= authorized ? render_list_column(column_value, column, record) : column_value %> </td> <% end -%> diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 087339c4bb..25ffdd669b 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -195,10 +195,16 @@ def url_options_for_nested_link(column, record, link, url_options, options = {}) end end - def column_class(column, column_value) + def column_class(column, column_value, record) classes = [] classes << "#{column.name}-column" - classes << column.css_class unless column.css_class.nil? + if column.css_class.is_a?(Proc) + css_class = column.css_class.call(column_value, record) + classes << css_class unless css_class.nil? + else + classes << column.css_class + end unless column.css_class.nil? + classes << 'empty' if column_empty? column_value classes << 'sorted' if active_scaffold_config.list.user.sorting.sorts_on?(column) classes << 'numeric' if column.column and [:decimal, :float, :integer].include?(column.column.type) From 136f68ad0e98cf7a28f82e684f45e2396b9225df Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Sep 2010 13:55:33 +0200 Subject: [PATCH 0636/2024] do not add all records to search-select and search-multi-select --- lib/active_scaffold/helpers/search_column_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 91b35bab9c..caabd9d646 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -59,7 +59,7 @@ def active_scaffold_search_multi_select(column, options) associated = options.delete :value associated = [associated].compact unless associated.is_a? Array associated.collect!(&:to_i) - select_options = options_for_association(column.association, true) + select_options = options_for_association(column.association, false) return as_(:no_options) if select_options.empty? html = "<ul class=\"checkbox-list\" id=\"#{options[:id]}\">" @@ -86,7 +86,7 @@ def active_scaffold_search_select(column, html_options) if column.association associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil? method = column.association.macro == :belongs_to ? column.association.primary_key_name : column.name - select_options = options_for_association(column.association, true) + select_options = options_for_association(column.association, false) else method = column.name select_options = column.options[:options] From 50a79a80a31e4d1c26b444c2870679e7e2dec3d7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Sep 2010 14:00:48 +0200 Subject: [PATCH 0637/2024] Bugfix: virtual columns with form_ui boolean generated npe --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 864f9e30b2..79aa88f8b4 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -209,7 +209,7 @@ def active_scaffold_input_virtual(column, options) def active_scaffold_input_boolean(column, options) select_options = [] - select_options << [as_(:_select_), nil] if column.column.null + select_options << [as_(:_select_), nil] if !column.virtual? && column.column.null select_options << [as_(:true), true] select_options << [as_(:false), false] From 3e784b0553c6b6e2db8971571c42e378b2bdc1c8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Sep 2010 14:09:14 +0200 Subject: [PATCH 0638/2024] Record_Not_Saved error message should be localizable --- lib/active_scaffold/actions/update.rb | 2 +- lib/active_scaffold/locale/de.rb | 3 ++- lib/active_scaffold/locale/en.rb | 3 ++- lib/active_scaffold/locale/fr.rb | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 4cb72de283..6afa748d1a 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -85,7 +85,7 @@ def do_update @record.errors.add_to_base as_(:version_inconsistency) self.successful=false rescue ActiveRecord::RecordNotSaved - @record.errors.add_to_base as_("Failed to save record cause of an unknown error") if @record.errors.empty? + @record.errors.add_to_base as_(:record_not_saved) if @record.errors.empty? self.successful = false end end diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index bc260a77fd..f5292a6c43 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -84,7 +84,8 @@ # error_messages :cant_destroy_record => "%{record} kann nicht gelöscht werden", :internal_error => 'Fehler bei der Verarbeitung (code 500, Interner Fehler)', - :version_inconsistency => 'Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben.' + :version_inconsistency => 'Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben.', + :record_not_saved => 'Eintrag kann nicht gespeichert werden. Ursache unbekannt.' } } } diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 6aa4092046..857249a6b8 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -90,7 +90,8 @@ # error_messages :cant_destroy_record => "%{record} can't be destroyed", :internal_error => 'Request Failed (code 500, Internal Error)', - :version_inconsistency => 'Version inconsistency - this record has been modified since you started editing it.' + :version_inconsistency => 'Version inconsistency - this record has been modified since you started editing it.', + :record_not_saved => 'Failed to save record cause of an unknown error' } } } diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 3e0ea867fb..eebf223005 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -82,8 +82,10 @@ :not_null => 'Not Null', # error_messages + :cant_destroy_record => "%{record} can't be destroyed", :internal_error => 'Erreur de la requête (code 500, Erreur interne)', :version_inconsistency => "Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer.", + :record_not_saved => 'Failed to save record cause of an unknown error' } } } From 21194e58f4fd7f5340a0a55f452f89b7c344b6a4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Sep 2010 14:25:02 +0200 Subject: [PATCH 0639/2024] guarantee an array for in(?) condition --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 48d337d68e..bf71e5b38b 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -49,7 +49,7 @@ def condition_for_column(column, value, text_search = :full) when :date, :time, :datetime, :timestamp condition_for_datetime(column, value) when :select, :multi_select, :country, :usa_state - ["#{column.search_sql} in (?)", value] + ["#{column.search_sql} in (?)", Array(value)] else if column.column.nil? || column.column.text? ["LOWER(#{column.search_sql}) LIKE ?", like_pattern.sub('?', value.downcase)] From 781d43a224f80c31fbe657821da566d5c4e11fde Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Sep 2010 15:14:43 +0200 Subject: [PATCH 0640/2024] get multi_select search up and running --- .../helpers/search_column_helpers.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index caabd9d646..5e55f04369 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -59,7 +59,12 @@ def active_scaffold_search_multi_select(column, options) associated = options.delete :value associated = [associated].compact unless associated.is_a? Array associated.collect!(&:to_i) - select_options = options_for_association(column.association, false) + + if column.association + select_options = options_for_association(column.association, false) + else + select_options = Array(column.options[:options]) + end return as_(:no_options) if select_options.empty? html = "<ul class=\"checkbox-list\" id=\"#{options[:id]}\">" @@ -71,14 +76,14 @@ def active_scaffold_search_multi_select(column, options) html << "<li>" html << check_box_tag(options[:name], id, associated.include?(id), :id => this_id) html << "<label for='#{this_id}'>" - html << label + html << label.to_s html << "</label>" html << "</li>" end html << '</ul>' html << javascript_tag("new DraggableLists('#{options[:id]}')") if column.options[:draggable_lists] - html + html.html_safe end def active_scaffold_search_select(column, html_options) @@ -89,7 +94,7 @@ def active_scaffold_search_select(column, html_options) select_options = options_for_association(column.association, false) else method = column.name - select_options = column.options[:options] + select_options = Array(column.options[:options]) end options = { :selected => associated }.merge! column.options From deebd90be5d7aeddd1ab20ccdd38767009c4a1c0 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Sep 2010 15:40:46 +0200 Subject: [PATCH 0641/2024] extract method active_scaffold_checkbox_list --- .../helpers/form_column_helpers.rb | 10 ++++++---- .../helpers/search_column_helpers.rb | 18 +----------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 79aa88f8b4..766c4b7323 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -106,15 +106,17 @@ def active_scaffold_input_plural_association(column, options) select_options = associated_options | options_for_association(column.association) return content_tag(:span, as_(:no_options), :id => options[:id]) if select_options.empty? + active_scaffold_checkbox_list(column, select_options, associated_options.collect {|a| a[1]}, options) + end + + def active_scaffold_checkbox_list(column, select_options, associated_ids, options) html = "<ul class=\"checkbox-list\" id=\"#{options[:id]}\">" - - associated_ids = associated_options.collect {|a| a[1]} + select_options.each_with_index do |option, i| label, id = option - this_name = "#{options[:name]}[]" this_id = "#{options[:id]}_#{i}_id" html << content_tag(:li) do - check_box_tag(this_name, id, associated_ids.include?(id), :id => this_id) << + check_box_tag("#{options[:name]}[]", id, associated_ids.include?(id), :id => this_id) << content_tag(:label, h(label), :for => this_id) end end diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 5e55f04369..df87648c32 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -67,23 +67,7 @@ def active_scaffold_search_multi_select(column, options) end return as_(:no_options) if select_options.empty? - html = "<ul class=\"checkbox-list\" id=\"#{options[:id]}\">" - - options[:name] += '[]' - select_options.each_with_index do |option, i| - label, id = option - this_id = "#{options[:id]}_#{i}_id" - html << "<li>" - html << check_box_tag(options[:name], id, associated.include?(id), :id => this_id) - html << "<label for='#{this_id}'>" - html << label.to_s - html << "</label>" - html << "</li>" - end - - html << '</ul>' - html << javascript_tag("new DraggableLists('#{options[:id]}')") if column.options[:draggable_lists] - html.html_safe + active_scaffold_checkbox_list(column, select_options, associated, options) end def active_scaffold_search_select(column, html_options) From 98a6abeab73978da492dcf4b31eda6b4538af334 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Sep 2010 16:24:57 +0200 Subject: [PATCH 0642/2024] fixed npe reported by IncubuS --- lib/active_scaffold/helpers/view_helpers.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 25ffdd669b..4cdc642e08 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -168,7 +168,11 @@ def action_link_html_options(link, url_options, record, html_options) def get_action_link_id(url_options, record = nil, column = nil) id = url_options[:id] || url_options[:parent_id] id = "#{column.association.name}-#{record.id}" if column && column.plural_association? - id = "#{column.association.name}-#{record.send(column.association.name).id}" if column && column.singular_association? + if record.try(column.association.name.to_sym).present? + id = "#{column.association.name}-#{record.send(column.association.name).id}" + else + id = "#{column.association.name}-#{record.id}" unless record.nil? + end if column && column.singular_association? action_id = "#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}#{url_options[:action].to_s}" action_link_id(action_id, id) end @@ -189,7 +193,7 @@ def action_link_html(link, url, html_options) def url_options_for_nested_link(column, record, link, url_options, options = {}) if column.association url_options[:assoc_id] = url_options.delete(:id) - url_options[:id] = record.send(column.association.name).id if column.singular_association? + url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present? link.eid = "#{controller_id.from(3)}_#{record.id}_#{column.association.name}" unless options.has_key?(:reuse_eid) url_options[:eid] = link.eid end From e26d9ba2d473b53c523c9734889482dbd097064f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 6 Sep 2010 17:45:35 +0200 Subject: [PATCH 0643/2024] Fix support for has_one :through, empty? raises an exception, blank? works --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 9fba63e994..c0190daa66 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -183,7 +183,7 @@ def column_class(column, column_value) def column_empty?(column_value) empty = column_value.nil? - empty ||= column_value.empty? if column_value.respond_to? :empty? + empty ||= column_value.blank? if column_value.respond_to? :blank? empty ||= [' '.html_safe, active_scaffold_config.list.empty_field_text].include? column_value if String === column_value return empty end From 39fc161a08bf3b9352c1a74f23e9a2e1c6b18b0d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 6 Sep 2010 17:56:31 +0200 Subject: [PATCH 0644/2024] Fix support for has_one :through, empty? raises an exception, blank? works --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 2757febf72..7cdecdf52f 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -57,7 +57,7 @@ def render_list_column(text, column, record) # check authorization if column.association - associated_for_authorized = if associated.nil? || (associated.respond_to?(:empty?) && associated.empty?) + associated_for_authorized = if associated.nil? || (associated.respond_to?(:blank?) && associated.blank?) column.association.klass elsif column.plural_association? associated.first From 081bf3f3dbbbead3897d204bccbb3c6003ee76f4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 7 Sep 2010 09:17:34 +0200 Subject: [PATCH 0645/2024] use same authorization process for update and inplace_edit --- lib/active_scaffold/helpers/list_column_helpers.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 82969e5c76..eb7ad5a640 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -57,7 +57,6 @@ def render_list_column(text, column, record) else authorized = record.authorized_for?(:crud_type => link.crud_type) end - #return "<a class='disabled'>#{text}</a>" unless authorized # to make html render properly return "<a class='disabled'>#{text}</a>".html_safe unless authorized render_action_link(link, url_options, record) @@ -248,7 +247,11 @@ def cache_association(value, column) # ========== def inplace_edit?(record, column) - column.inplace_edit and record.authorized_for?(:crud_type => :update, :column => column.name) + if column.inplace_edit + editable = controller.send(:update_authorized?, record) if controller.respond_to?(:update_authorized?) + editable = record.authorized_for?(:action => :update, :column => column.name) if editable.nil? || editable == true + editable + end end def inplace_edit_cloning?(column) From b256163aaf08362da993bf9ce8d36042e6fdac40 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 7 Sep 2010 10:46:58 +0200 Subject: [PATCH 0646/2024] UJS to disable a remote file upload form --- .../javascripts/jquery/active_scaffold.js | 36 ++++++++++++++----- .../javascripts/prototype/active_scaffold.js | 29 +++++++++++---- frontends/default/views/_base_form.html.erb | 3 +- lib/active_scaffold/helpers/view_helpers.rb | 7 +--- 4 files changed, 53 insertions(+), 22 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index b532f0ff24..5dba3b3d7d 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -2,20 +2,15 @@ $(document).ready(function() { $('form.as_form').live('ajax:loading', function(event) { var as_form = $(this).closest("form"); if (as_form && as_form.attr('data-loading') == 'true') { - var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); - if (loading_indicator) loading_indicator.css('visibility','visible'); - $('input[type=submit]', as_form).attr('disabled', 'disabled'); - $("input:enabled,select:enabled", as_form).attr('disabled', 'disabled'); + ActiveScaffold.disable_form(as_form); } return true; }); + $('form.as_form').live('ajax:complete', function(event) { var as_form = $(this).closest("form"); if (as_form && as_form.attr('data-loading') == 'true') { - var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); - if (loading_indicator) loading_indicator.css('visibility','hidden'); - $('input[type=submit]', as_form).attr('disabled', ''); - $("input:disabled,select:disabled", as_form).attr('disabled', ''); + ActiveScaffold.enable_form(as_form); } }); $('form.as_form').live('ajax:failure', function(event) { @@ -24,6 +19,13 @@ $(document).ready(function() { ActiveScaffold.report_500_response(as_div) } }); + $('form.as_form.as_remote_upload').live('submit', function(event) { + var as_form = $(this).closest("form"); + if (as_form && as_form.attr('data-loading') == 'true') { + setTimeout("ActiveScaffold.disable_form('" + as_form.attr('id') + "')", 10); + } + return true; + }); $('a.as_action').live('ajax:before', function(event) { var action_link = ActiveScaffold.ActionLink.get($(this)); if (action_link) { @@ -416,6 +418,24 @@ var ActiveScaffold = { $(element).get(0).reset(); }, + disable_form: function(as_form) { + if (typeof(as_form) == 'string') as_form = '#' + as_form; + as_form = $(as_form) + var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); + if (loading_indicator) loading_indicator.css('visibility','visible'); + $('input[type=submit]', as_form).attr('disabled', 'disabled'); + $("input:enabled,select:enabled", as_form).attr('disabled', 'disabled'); + }, + + enable_form: function(as_form) { + if (typeof(as_form) == 'string') as_form = '#' + as_form; + as_form = $(as_form) + var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); + if (loading_indicator) loading_indicator.css('visibility','hidden'); + $('input[type=submit]', as_form).attr('disabled', ''); + $("input:disabled,select:disabled", as_form).attr('disabled', ''); + }, + focus_first_element_of_form: function(form_element) { if (typeof(form_element) == 'string') form_element = '#' + form_element; $(form_element + ":first *:input[type!=hidden]:first").focus(); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index b8d185b2c6..5de9c07561 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -21,9 +21,7 @@ document.observe("dom:loaded", function() { // as a result form is disabled but never reenabled.. } else { if (as_form && as_form.readAttribute('data-loading') == 'true') { - var loading_indicator = $(as_form.id.sub('-form', '-loading-indicator')); - if (loading_indicator) loading_indicator.style.visibility = 'visible'; - as_form.disable(); + ActiveScaffold.disable_form(as_form); } } return true; @@ -31,9 +29,7 @@ document.observe("dom:loaded", function() { document.on('ajax:complete', 'form.as_form', function(event) { var as_form = event.findElement('form'); if (as_form && as_form.readAttribute('data-loading') == 'true') { - var loading_indicator = $(as_form.id.sub('-form', '-loading-indicator')); - if (loading_indicator) loading_indicator.style.visibility = 'hidden'; - as_form.enable(); + ActiveScaffold.enable_form(as_form); event.stop(); return false; } @@ -46,6 +42,13 @@ document.observe("dom:loaded", function() { return false; } }); + document.on('submit', 'form.as_form.as_remote_upload', function(event) { + var as_form = event.findElement('form'); + if (as_form && as_form.readAttribute('data-loading') == 'true') { + setTimeout("ActiveScaffold.disable_form('" + as_form.id + "')", 10); + } + return true; + }); document.on('ajax:before', 'a.as_action', function(event) { var action_link = ActiveScaffold.ActionLink.get(event.findElement()); if (action_link) { @@ -368,6 +371,20 @@ var ActiveScaffold = { $(element).reset(); }, + disable_form: function(as_form) { + as_form = $(as_form) + var loading_indicator = $(as_form.id.sub('-form', '-loading-indicator')); + if (loading_indicator) loading_indicator.style.visibility = 'visible'; + as_form.disable(); + }, + + enable_form: function(as_form) { + as_form = $(as_form) + var loading_indicator = $(as_form.id.sub('-form', '-loading-indicator')); + if (loading_indicator) loading_indicator.style.visibility = 'hidden'; + as_form.enable(); + }, + focus_first_element_of_form: function(form_element) { Form.focusFirstElement(form_element); }, diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index 44ff09ff63..3708662506 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -9,8 +9,7 @@ options = {:onsubmit => onsubmit, :method => method, 'data-loading' => true} if xhr && as_action_config.multipart? # file_uploads - form_remote_upload_tag url_options.merge({:iframe => true}), - options.merge({:loading => "$('#{loading_indicator_id(:action => form_action, :id => params[:id])}').style.visibility = 'visible';"}) + form_remote_upload_tag url_options.merge({:iframe => true}), options else options[:remote] = true if xhr && !as_action_config.multipart? form_tag url_options, options diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 4cdc642e08..2ea1353fc2 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -61,14 +61,9 @@ def in_subform?(column, parent_record) end def form_remote_upload_tag(url_for_options = {}, options = {}) - onsubmits = options[:onsubmit] ? [ options[:onsubmit] ] : [ ] - # simulate a "loading". the setTimeout prevents the Form.disable from being called before the submit, so that data actually posts. - onsubmits << "setTimeout(function() { #{options[:loading]} }, 10); " - onsubmits << "return true" # make sure the form still submits - - options[:onsubmit] = onsubmits * ';' options[:target] = action_iframe_id(url_for_options) options[:multipart] ||= true + options[:class] = "#{options[:class]} as_remote_upload".strip output="" output << form_tag(url_for_options, options) (output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>").html_safe From 4e6d35b707e73abb291635ff1e1decf12b37e8aa Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 7 Sep 2010 12:08:40 +0200 Subject: [PATCH 0647/2024] improved empty hash detection --- lib/active_scaffold/attribute_params.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 600215fb55..c7337797b8 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -121,7 +121,10 @@ def column_value_from_param_value(parent_record, column, value) column.association.klass.find(value) if value and not value.empty? elsif column.plural_association? # it's an array of ids - column.association.klass.find(value) if value and not value.empty? + if value and not value.empty? + ids = value.select {|id| id.respond_to?(:empty?) ? !id.empty? : true} + ids.empty? ? [] : column.association.klass.find(ids) + end elsif column.column && column.column.number? && [:i18n_number, :currency].include?(column.options[:format]) native = '.' delimiter = I18n.t('number.format.delimiter') @@ -193,6 +196,8 @@ def attributes_hash_is_empty?(hash, klass) if value.is_a?(Hash) attributes_hash_is_empty?(value, klass) + elsif value.is_a?(Array) + value.any? {|id| id.respond_to?(:empty?) ? !id.empty? : true} else value.respond_to?(:empty?) ? value.empty? : false end From a86f5903b8d62819daefb3fc564d86d4ee34be73 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 7 Sep 2010 14:37:43 +0200 Subject: [PATCH 0648/2024] estimate column weight for each created column to improve out of the box column ordering --- lib/active_scaffold/data_structures/column.rb | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 31b8541515..619b2781aa 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -261,7 +261,6 @@ def initialize(name, active_record_class) #:nodoc: @autolink = !@association.nil? @active_record_class = active_record_class @table = active_record_class.table_name - @weight = [:created_at, :updated_at].include?(self.name) ? 1 : 0 @associated_limit = self.class.associated_limit @associated_number = self.class.associated_number @show_blank_record = self.class.show_blank_record @@ -270,12 +269,14 @@ def initialize(name, active_record_class) #:nodoc: @form_ui = :checkbox if @column and @column.type == :boolean @allow_add_existing = true @form_ui = self.class.association_form_ui if @association && self.class.association_form_ui - + # default all the configurable variables self.css_class = '' self.required = active_record_class.validators_on(self.name).map(&:class).include? ActiveModel::Validations::PresenceValidator self.sort = true self.search_sql = true + + @weight = estimate_weight self.includes = (association and not polymorphic_association?) ? [association.name] : [] end @@ -307,7 +308,7 @@ def initialize_sort end end end - + def initialize_search_sql self.search_sql = unless self.virtual? if association.nil? @@ -327,5 +328,21 @@ def initialize_search_sql def field @field ||= [@active_record_class.connection.quote_column_name(@table), field_name].join('.') end + + def estimate_weight + if singular_association? + 400 + elsif plural_association? + 500 + elsif [:created_at, :updated_at].include?(self.name) + 600 + elsif [:name, :label, :title].include?(self.name) + 100 + elsif required? + 200 + else + 300 + end + end end end From a06c1a00a6e7e092da18b7b1ce01967d49bba408 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 8 Sep 2010 09:40:30 +0200 Subject: [PATCH 0649/2024] Update i18n interpolation syntax --- lib/active_scaffold/locale/de.yml | 20 ++++++++++---------- lib/active_scaffold/locale/en.yml | 26 +++++++++++++------------- lib/active_scaffold/locale/es.yml | 24 ++++++++++++------------ lib/active_scaffold/locale/fr.yml | 18 +++++++++--------- lib/active_scaffold/locale/hu.yml | 18 +++++++++--------- lib/active_scaffold/locale/ja.yml | 20 ++++++++++---------- lib/active_scaffold/locale/ru.yml | 24 ++++++++++++------------ 7 files changed, 75 insertions(+), 75 deletions(-) diff --git a/lib/active_scaffold/locale/de.yml b/lib/active_scaffold/locale/de.yml index fece424cca..4d4949e48e 100644 --- a/lib/active_scaffold/locale/de.yml +++ b/lib/active_scaffold/locale/de.yml @@ -2,24 +2,24 @@ active_scaffold: add: 'Hinzufügen' add_existing: 'Existierenden Eintrag hinzufügen' - add_existing_model: 'Existierende {{model}} hinzufügen' + add_existing_model: 'Existierende %{model} hinzufügen' are_you_sure_to_delete: 'Sind Sie sicher?' cancel: 'Abbrechen' click_to_edit: 'Zum Editieren anklicken' close: 'Schliessen' create: 'Anlegen' - create_model: 'Lege {{model}} an' + create_model: 'Lege %{model} an' create_another: 'Weitere anlegen' - created_model: '{{model}} anlegen' + created_model: '%{model} anlegen' create_new: 'Neu anlegen' customize: 'Anpassen' delete: 'Löschen' - deleted_model: '{{model}} gelöscht' + deleted_model: '%{model} gelöscht' delimiter: 'Trennzeichen' download: 'Download' edit: 'Bearbeiten' export: 'Exportieren' - nested_for_model: '{{nested_model}} für {{parent_model}}' + nested_for_model: '%{nested_model} für %{parent_model}' filtered: '(Gefiltert)' found: 'Gefunden' hide: 'Verstecken' @@ -37,18 +37,18 @@ remove: 'Entfernen' remove_file: 'Entferne oder Ersetze Datei' replace_with_new: 'Mit Neuer ersetzen' - revisions_for_model: 'Revisionen für {{model}}' + revisions_for_model: 'Revisionen für %{model}' reset: 'Zurücksetzen' saving: 'Speichern…' search: 'Suche' search_terms: 'Suchbegriffe' _select_: '- Auswählen -' show: 'Anzeigen' - show_model: 'Zeige {{model}} an' + show_model: 'Zeige %{model} an' _to_ : ' zu ' update: 'Speichern' - update_model: 'Editiere {{model}}' - updated_model: '{{model}} aktualisiert' + update_model: 'Editiere %{model}' + updated_model: '%{model} aktualisiert' '=': '=' '>=': '>=' '<=': '<=' @@ -63,6 +63,6 @@ ends_with: 'Ends with' # error_messages - cant_destroy_record: "{{record}} kann nicht gelöscht werden" + cant_destroy_record: "%{record} kann nicht gelöscht werden" internal_error: 'Fehler bei der Verarbeitung (code 500, Interner Fehler)' version_inconsistency: 'Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben.' \ No newline at end of file diff --git a/lib/active_scaffold/locale/en.yml b/lib/active_scaffold/locale/en.yml index 537d01974b..3a365a3b97 100644 --- a/lib/active_scaffold/locale/en.yml +++ b/lib/active_scaffold/locale/en.yml @@ -2,25 +2,25 @@ active_scaffold: add: 'Add' add_existing: 'Add Existing' - add_existing_model: 'Add Existing {{model}}' - are_you_sure_to_delete: 'Are you sure you want to delete {{label}}?' + add_existing_model: 'Add Existing %{model}' + are_you_sure_to_delete: 'Are you sure you want to delete %{label}?' cancel: 'Cancel' click_to_edit: 'Click to edit' click_to_reset: 'Click to reset' close: 'Close' create: 'Create' - create_model: 'Create {{model}}' - create_another: 'Create Another {{model}}' - created_model: 'Created {{model}}' + create_model: 'Create %{model}' + create_another: 'Create Another %{model}' + created_model: 'Created %{model}' create_new: 'Create New' customize: 'Customize' delete: 'Delete' - deleted_model: 'Deleted {{model}}' + deleted_model: 'Deleted %{model}' delimiter: 'Delimiter' download: 'Download' edit: 'Edit' export: 'Export' - nested_for_model: '{{nested_model}} for {{parent_model}}' + nested_for_model: '%{nested_model} for %{parent_model}' false: 'False' filtered: '(Filtered)' found: 'Found' @@ -39,19 +39,19 @@ remove: 'Remove' remove_file: 'Remove or Replace file' replace_with_new: 'Replace With New' - revisions_for_model: 'Revisions for {{model}}' + revisions_for_model: 'Revisions for %{model}' reset: 'Reset' saving: 'Saving…' search: 'Search' search_terms: 'Search Terms' _select_: '- select -' show: 'Show' - show_model: 'Show {{model}}' + show_model: 'Show %{model}' _to_ : ' to ' true: 'True' update: 'Update' - update_model: 'Update {{model}}' - updated_model: 'Updated {{model}}' + update_model: 'Update %{model}' + updated_model: 'Updated %{model}' '=': '=' '>=': '>=' '<=': '<=' @@ -66,6 +66,6 @@ ends_with: 'Ends with' # error_messages - cant_destroy_record: "{{record}} can't be destroyed" + cant_destroy_record: "%{record} can't be destroyed" internal_error: 'Request Failed (code 500, Internal Error)' - version_inconsistency: 'Version inconsistency - this record has been modified since you started editing it.' \ No newline at end of file + version_inconsistency: 'Version inconsistency - this record has been modified since you started editing it.' diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index cf67caebb0..83c51f4973 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -2,20 +2,20 @@ es: active_scaffold: add: 'Añadir' add_existing: 'Añadir Existente' - add_existing_model: 'Añadir {{model}} Existente' - are_you_sure_to_delete: '¿Estás seguro de que quieres borrar {{label}}?' + add_existing_model: 'Añadir %{model} Existente' + are_you_sure_to_delete: '¿Estás seguro de que quieres borrar %{label}?' cancel: 'Cancelar' click_to_edit: 'Pulsa para editar' click_to_reset: 'Pulsa para restaurar' close: 'Cerrar' create: 'Crear' - create_model: 'Crear {{model}}' - create_another: 'Crear Otro {{model}}' - created_model: '{{model}} creado' + create_model: 'Crear %{model}' + create_another: 'Crear Otro %{model}' + created_model: '%{model} creado' create_new: 'Crear Nuevo' customize: 'Personalizar' delete: 'Borrar' - deleted_model: '{{model}} borrado' + deleted_model: '%{model} borrado' delimiter: 'Delimitador' download: 'Descargar' edit: 'Editar' @@ -28,7 +28,7 @@ es: hide: 'Ocultar' live_search: 'Buscar en Vivo' loading: 'Cargando…' - nested_for_model: '{{nested_model}} de {{parent_model}}' + nested_for_model: '%{nested_model} de %{parent_model}' next: 'Siguiente' no_entries: 'Sin entradas' no_options: 'sin opciones' @@ -41,19 +41,19 @@ es: remove: 'Eliminar' remove_file: 'Eliminar o Reemplazar archivo' replace_with_new: 'Reemplazar con Nuevo' - revisions_for_model: 'Revisiones de {{model}}' + revisions_for_model: 'Revisiones de %{model}' reset: 'Restaurar' saving: 'Guardando…' search: 'Buscar' search_terms: 'Términos a buscar' _select_: '- seleccionar -' show: 'Ver' - show_model: 'Ver {{model}}' + show_model: 'Ver %{model}' _to_ : ' a ' 'true': 'Sí' update: 'Actualizar' - update_model: 'Actualizar {{model}}' - updated_model: '{{model}} actualizado' + update_model: 'Actualizar %{model}' + updated_model: '%{model} actualizado' '=': '=' '>=': '>=' '<=': '<=' @@ -68,6 +68,6 @@ es: ends_with: 'Termina con' # error_messages - cant_destroy_record: "No se pudo borrar {{record}}" + cant_destroy_record: "No se pudo borrar %{record}" internal_error: 'Petición fallida (código 500, error interno)' version_inconsistency: 'Inconsistencia de versiones - este registro se ha modificado después de que empezó a editarlo.' diff --git a/lib/active_scaffold/locale/fr.yml b/lib/active_scaffold/locale/fr.yml index 5a89ff23a3..b08107b4d9 100644 --- a/lib/active_scaffold/locale/fr.yml +++ b/lib/active_scaffold/locale/fr.yml @@ -2,24 +2,24 @@ active_scaffold: add: 'Ajouter' add_existing: 'Ajouter un(e) existant(e)' - add_existing_model: 'Ajouter un(e) {{model}} existant(e)' + add_existing_model: 'Ajouter un(e) %{model} existant(e)' are_you_sure_to_delete: 'Êtes vous sûr?' cancel: 'Annuler' click_to_edit: 'Cliquer pour éditer' close: 'Fermer' create: 'Créer' - create_model: 'Créer {{model}}' + create_model: 'Créer %{model}' create_another: 'Créer un autre' - created_model: '{{model}} créé' + created_model: '%{model} créé' create_new: 'Créer un nouveau' customize: 'Personnaliser' delete: 'Supprimer' - deleted_model: 'Suppression de {{model}}' + deleted_model: 'Suppression de %{model}' delimiter: 'Délimiteur' download: 'Télécharger' edit: 'Éditer' export: 'Exporter' - nested_for_model: '{{nested_model}} pour {{parent_model}}' + nested_for_model: '%{nested_model} pour %{parent_model}' filtered: '(Filtré)' found: 'Trouvé' hide: 'Cacher' @@ -37,18 +37,18 @@ remove: 'Supprimer' remove_file: 'Supprimer et remplacer le fichier' replace_with_new: 'Remplacer avec le nouveau' - revisions_for_model: 'Révision pour {{model}}' + revisions_for_model: 'Révision pour %{model}' reset: 'Annuler' saving: 'Sauvegarder…' search: 'Rechercher' search_terms: 'Recherche de termes' _select_: '- sélectionner -' show: 'Montrer' - show_model: 'Montrer {{model}}' + show_model: 'Montrer %{model}' _to_ : ' à ' update: 'Mettre à jour' - update_model: 'Mettre à jour le(/la) {{model}}' - updated_model: 'Mis à jour de {{model}}' + update_model: 'Mettre à jour le(/la) %{model}' + updated_model: 'Mis à jour de %{model}' '=': '=' '>=': '>=' '<=': '<=' diff --git a/lib/active_scaffold/locale/hu.yml b/lib/active_scaffold/locale/hu.yml index 6fbf21c256..5d445445e1 100644 --- a/lib/active_scaffold/locale/hu.yml +++ b/lib/active_scaffold/locale/hu.yml @@ -2,24 +2,24 @@ hu: active_scaffold: add: 'Hozzáadás' add_existing: 'Meglevő hozzáadása' - add_existing_model: 'Meglevő {{model}} hozzáadása' + add_existing_model: 'Meglevő %{model} hozzáadása' are_you_sure_to_delete: 'Biztos vagy benne?' cancel: 'Mégse' click_to_edit: 'Kattints a szerkesztéshez' close: 'Bezárás' create: 'Létrehozás' - create_model: '{{model}} létrehozása' + create_model: '%{model} létrehozása' create_another: 'Mégegy hozzáadása' - created_model: '{{model}} létrehozva' + created_model: '%{model} létrehozva' create_new: 'Új létrehozása' customize: 'Testreszabás' delete: 'Törlés' - deleted_model: '{{model}} törölve' + deleted_model: '%{model} törölve' delimiter: 'Elválasztó' download: 'Letöltés' edit: 'Szerkesztés' export: 'Exportálás' - nested_for_model: '{{nested_model}} / {{parent_model}}' + nested_for_model: '%{nested_model} / %{parent_model}' filtered: '(Szűrt)' found: 'Találat' hide: 'Elrejtés' @@ -37,18 +37,18 @@ hu: remove: 'Törlés' remove_file: 'Fájl törlése, vagy cseréje' replace_with_new: 'Csere újjal' - revisions_for_model: '{{model}} revíziói' + revisions_for_model: '%{model} revíziói' reset: 'Alapállapot' saving: 'Mentés…' search: 'Keresés' search_terms: 'Keresési kifejezések' _select_: '- válassz -' show: 'Mutatás' - show_model: '{{model}} mutatása' + show_model: '%{model} mutatása' _to_ : ' – ' update: 'Modosítás' - update_model: '{{model}} modosítása' - updated_model: '{{model}} módosítva' + update_model: '%{model} modosítása' + updated_model: '%{model} módosítva' '=': '=' '>=': '>=' '<=': '<=' diff --git a/lib/active_scaffold/locale/ja.yml b/lib/active_scaffold/locale/ja.yml index 09e0282ed6..6648c958f6 100644 --- a/lib/active_scaffold/locale/ja.yml +++ b/lib/active_scaffold/locale/ja.yml @@ -2,24 +2,24 @@ ja: active_scaffold: add: '追加' add_existing: '既存のものを追加' - add_existing_model: '既存の{{model}}を追加' + add_existing_model: '既存の%{model}を追加' are_you_sure_to_delete: '本当によいですか?' cancel: 'キャンセル' click_to_edit: 'クリックして編集' close: '閉じる' create: '作成' - create_model: '{{model}}を作成' + create_model: '%{model}を作成' create_another: '別のものを作成' - created_model: '{{model}}を作成しました' + created_model: '%{model}を作成しました' create_new: '新規作成' customize: 'カスタマイズ' delete: '削除' - deleted_model: '{{model}}を削除しました' + deleted_model: '%{model}を削除しました' delimiter: 'Delimiter' # needed? download: 'ダウンロード' edit: '編集' export: 'Export' # needed? - nested_for_model: '{{parent_model}}の{{nested_model}}' + nested_for_model: '%{parent_model}の%{nested_model}' filtered: '(フィルタ中)' found: '個ありました' hide: '隠す' @@ -37,18 +37,18 @@ ja: remove: '削除' remove_file: 'ファイルを削除または置換' replace_with_new: '新しいもので置換' - revisions_for_model: 'Revisions for {{model}}' # neede? + revisions_for_model: 'Revisions for %{model}' # neede? reset: 'リセット' saving: '保存中…' search: '検索' search_terms: '検索単語' _select_: '- 選択してください -' show: '表示' - show_model: '{{model}}を表示' + show_model: '%{model}を表示' _to_ : ' to ' # needed? update: '更新' - update_model: '{{model}}を更新' - updated_model: '{{model}}を更新しました' + update_model: '%{model}を更新' + updated_model: '%{model}を更新しました' '=': '=' '>=': '>=' '<=': '<=' @@ -63,6 +63,6 @@ ja: ends_with: 'Ends with' # error_messages - cant_destroy_record: "{{record}}を削除で来ません" + cant_destroy_record: "%{record}を削除で来ません" internal_error: 'リクエストが失敗しました(コード500: 内部エラー)' version_inconsistency: 'バージョンが一致しません - あなたが編集している間にこのレコードが変更されました。' diff --git a/lib/active_scaffold/locale/ru.yml b/lib/active_scaffold/locale/ru.yml index 789ee15f0e..a79ca4e0a7 100644 --- a/lib/active_scaffold/locale/ru.yml +++ b/lib/active_scaffold/locale/ru.yml @@ -2,25 +2,25 @@ ru: active_scaffold: add: 'Добавить запись' add_existing: 'Добавить существующую запись' - add_existing_model: 'Добавить существующую запись {{model}}' - are_you_sure_to_delete: 'Удалить {{label}}?' + add_existing_model: 'Добавить существующую запись %{model}' + are_you_sure_to_delete: 'Удалить %{label}?' cancel: 'Отмена' click_to_edit: 'Нажмите для редактирования' click_to_reset: 'Нажмите для сброса' close: 'Закрыть' create: 'Создать запись' - create_model: 'Создать запись {{model}}' - create_another: 'Создать другую запись {{model}}' - created_model: 'Создана запись {{model}}' + create_model: 'Создать запись %{model}' + create_another: 'Создать другую запись %{model}' + created_model: 'Создана запись %{model}' create_new: 'Создать новую запись' customize: 'Настроить' delete: 'Удалить' - deleted_model: 'Удалена запись {{model}}' + deleted_model: 'Удалена запись %{model}' delimiter: 'Разделитель' download: 'Загрузить' edit: 'Изменить' export: 'Экспорт' - nested_for_model: '{{parent_model}} / {{nested_model}}' + nested_for_model: '%{parent_model} / %{nested_model}' false: 'Нет' filtered: '(Найденное)' found: 'Найдено' @@ -39,19 +39,19 @@ ru: remove: 'Удалить' remove_file: 'Удалить или заменить файл' replace_with_new: 'Заменить новым' - revisions_for_model: 'Редакции {{model}}' + revisions_for_model: 'Редакции %{model}' reset: 'Сбросить' saving: 'Сохранение…' search: 'Поиск' search_terms: 'Ключевые слова' _select_: '- выбрать -' show: 'Показать' - show_model: 'Показать запись {{model}}' + show_model: 'Показать запись %{model}' _to_ : ' to ' true: 'Да' update: 'Обновить запись' - update_model: 'Обновить запись {{model}}' - updated_model: 'Обновлена запись {{model}}' + update_model: 'Обновить запись %{model}' + updated_model: 'Обновлена запись %{model}' '=': '=' '>=': '>=' '<=': '<=' @@ -66,6 +66,6 @@ ru: ends_with: 'Оканчивается на' # error_messages - cant_destroy_record: 'Запись {{record}} не может быть удалена' + cant_destroy_record: 'Запись %{record} не может быть удалена' internal_error: '500 Внутренняя ошибка сервера' version_inconsistency: 'Несоответствие версий: эта запись была обновлена с того момента, как вы начали ее редактировать' From e2756d60a6d576b925d7c1cd8ebf6ecee148a352 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 8 Sep 2010 10:28:40 +0200 Subject: [PATCH 0650/2024] use new ActiveRecord Query Interface internally --- lib/active_scaffold/finder.rb | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index bf71e5b38b..ea65b03c6c 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -221,36 +221,44 @@ def find_page(options = {}) # create a general-use options array that's compatible with Rails finders finder_options = { :order => options[:sorting].try(:clause), - :conditions => search_conditions, + :where => search_conditions, :joins => joins_for_finder, - :include => options[:count_includes]} + :includes => options[:count_includes]} finder_options.merge! custom_finder_options # NOTE: we must use :include in the count query, because some conditions may reference other tables - count = klass.count(finder_options.reject{|k,v| [:select, :order].include? k}) unless options[:pagination] == :infinite - + count_query = append_to_query(klass, finder_options.reject{|k, v| [:select, :order].include?(k)}) + count = count_query.count unless options[:pagination] == :infinite + # Converts count to an integer if ActiveRecord returned an OrderedHash # that happens when finder_options contains a :group key count = count.length if count.is_a? ActiveSupport::OrderedHash - finder_options.merge! :include => full_includes + finder_options.merge! :includes => full_includes # we build the paginator differently for method- and sql-based sorting if options[:sorting] and options[:sorting].sorts_by_method? pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| - sorted_collection = sort_collection_by_column(klass.all(finder_options), *options[:sorting].first) + sorted_collection = sort_collection_by_column(append_to_query(klass, finder_options).all, *options[:sorting].first) sorted_collection = sorted_collection.slice(offset, per_page) if options[:pagination] sorted_collection end else pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| finder_options.merge!(:offset => offset, :limit => per_page) if options[:pagination] - klass.all(finder_options) + append_to_query(klass, finder_options).all end end pager.page(options[:page]) end + + def append_to_query(query, options) + options.assert_valid_keys :where, :select, :group, :order, :limit, :offset, :joins, :includes, :lock, :readonly, :from + options.reject{|k, v| v.blank?}.inject(query) do |query, (k, v)| + query.send((k.to_sym), v) + end + end def joins_for_finder case joins_for_collection From 7248b73c890284fe22e992e85f77f14a3ae44ea5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 8 Sep 2010 15:55:25 +0200 Subject: [PATCH 0651/2024] disable confirm when dhtml_confirm is set, disable dhtml_confirm when confirm is set, they are uncompatible --- .../data_structures/action_link.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 15c91efcb0..46c27611c0 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -42,21 +42,25 @@ def label end # if the action requires confirmation - attr_writer :confirm + def confirm=(value) + @dhtml_confirm = nil if value + @confirm = value + end def confirm(label = '') @confirm.is_a?(String) ? @confirm : as_(@confirm, :label => label) end def confirm? - @confirm ? true : false + !!@confirm end # if the action uses a DHTML based (i.e. 2-phase) confirmation - attr_writer :dhtml_confirm - def dhtml_confirm - @dhtml_confirm + attr_accessor :dhtml_confirm + def dhtml_confirm=(value) + @confirm = nil if value + @dhtml_confirm = value end def dhtml_confirm? - @dhtml_confirm + !!@dhtml_confirm end # what method to call on the controller to see if this action_link should be visible From ba0bb42b647c0e92ec261f177988ad629dd748fc Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 9 Sep 2010 10:07:15 +0200 Subject: [PATCH 0652/2024] notes about documentation --- README | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README b/README index 806d5b126d..63cbf8566c 100644 --- a/README +++ b/README @@ -1,6 +1,12 @@ -********************************************************************************** -** For all documentation see the project website: http://www.ActiveScaffold.com ** -********************************************************************************** +*********************************************************************************************** +** For all documentation see the wiki: http://wiki.github.com/activescaffold/active_scaffold ** +*********************************************************************************************** + +Read http://wiki.github.com/activescaffold/active_scaffold/getting-started:"Getting Started" guide to start using ActiveScaffold + +********************************************************************* +** For news see the project website: http://www.ActiveScaffold.com ** +********************************************************************* ActiveScaffold plugin by Scott Rutherford (scott@caronsoftware.com), Richard White (rrwhite@gmail.com), Lance Ivy (lance@cainlevy.net), Ed Moss, Tim Harper and Sergio Cambra (sergio@entrecables.com) From 034b6c6b4071b7d5fe797354dd0ee36177803241 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 10 Sep 2010 10:19:25 +0200 Subject: [PATCH 0653/2024] convert i18n number formats in field search --- lib/active_scaffold/attribute_params.rb | 17 +---------------- lib/active_scaffold/data_structures/column.rb | 19 +++++++++++++++++++ lib/active_scaffold/finder.rb | 9 +++++++++ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 651da79a60..0600f7f642 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -124,22 +124,7 @@ def column_value_from_param_value(parent_record, column, value) # it's an array of ids column.association.klass.find(value) if value and not value.empty? elsif column.column && column.column.number? && column.options[:format] - native = '.' # native ruby separator - format = {:separator => '', :delimiter => ''}.merge! I18n.t('number.format', :default => {}) - specific = case column.options[:format] - when :currency - I18n.t('number.currency.format', :default => nil) - when :size - I18n.t('number.human.format', :default => nil) - when :percentage - I18n.t('number.percentage.format', :default => nil) - end - format.merge! specific unless specific.nil? - unless format[:separator].blank? || !value.include?(format[:separator]) && value.include?(native) && (format[:delimiter] != native || value !~ /\.\d{3}$/) - value.gsub(/[^0-9\-#{format[:separator]}]/, '').gsub(format[:separator], native) - else - value - end + column.number_to_native(value) else # convert empty strings into nil. this works better with 'null => true' columns (and validations), # and 'null => false' columns should just convert back to an empty string. diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 2b3bdf2fdd..2ad8d6f613 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -277,6 +277,25 @@ def <=>(other_column) order_weight != 0 ? order_weight : self.name.to_s <=> other_column.name.to_s end + def number_to_native(value) + native = '.' # native ruby separator + format = {:separator => '', :delimiter => ''}.merge! I18n.t('number.format', :default => {}) + specific = case self.options[:format] + when :currency + I18n.t('number.currency.format', :default => nil) + when :size + I18n.t('number.human.format', :default => nil) + when :percentage + I18n.t('number.percentage.format', :default => nil) + end + format.merge! specific unless specific.nil? + unless format[:separator].blank? || !value.include?(format[:separator]) && value.include?(native) && (format[:delimiter] != native || value !~ /\.\d{3}$/) + value.gsub(/[^0-9\-#{format[:separator]}]/, '').gsub(format[:separator], native) + else + value + end + end + protected def initialize_sort diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index ad972d0755..17cc879e74 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -58,6 +58,15 @@ def condition_for_column(column, value, text_search = :full) end def condition_for_integer_type(column, value, like_pattern = nil) + if column.options[:format] + if value.is_a?(Hash) + value[:from] = column.number_to_native(value[:from]) + value[:to] = column.number_to_native(value[:to]) + else + value = column.number_to_native(value) + end + end + if !value.is_a?(Hash) ["#{column.search_sql} = ?", column.column.nil? ? value.to_f : column.column.type_cast(value)] elsif ActiveScaffold::Finder::NullComparators.include?(value[:opt]) From 1a6cf241046cb79169ab35491e61674f57e71cee Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 10 Sep 2010 11:41:45 +0200 Subject: [PATCH 0654/2024] added field_search config option human_conditions will show user a humanized search condition statement instead of just filtered message --- .../default/views/_list_messages.html.erb | 2 +- lib/active_scaffold/actions/field_search.rb | 14 ++++- .../calendar_date_select/lib/as_cds_bridge.rb | 1 + .../date_picker/lib/datepicker_bridge.rb | 2 + .../bridges/shared/date_bridge.rb | 13 +++++ lib/active_scaffold/config/field_search.rb | 6 +- lib/active_scaffold/finder.rb | 56 +++++++++++++++++-- 7 files changed, 83 insertions(+), 11 deletions(-) diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index c0449ea9b6..c2ad9d4ed2 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -9,7 +9,7 @@ <%= render :partial => 'messages' %> </div> <p class="filtered-message" <%= ' style="display:none;" '.html_safe unless @filtered %>> - <%= as_(active_scaffold_config.list.filtered_message) %> + <%= @filtered.is_a?(String) ? @filtered : as_(active_scaffold_config.list.filtered_message) %> </p> <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" '.html_safe unless @page.items.empty? %>> <%= as_(active_scaffold_config.list.no_entries_message) %> diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index ea876522cb..da01c2f4c4 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -44,14 +44,22 @@ def do_search unless search_params.nil? text_search = active_scaffold_config.field_search.text_search search_conditions = [] + human_conditions = [] if active_scaffold_config.field_search.human_conditions columns = active_scaffold_config.field_search.columns search_params.each do |key, value| next unless columns.include? key - search_conditions << self.class.condition_for_column(active_scaffold_config.columns[key], value, text_search) + search_condition = self.class.condition_for_column(active_scaffold_config.columns[key], value, text_search) + unless search_condition.blank? + search_conditions << search_condition + human_conditions << self.class.human_condition_for_column(active_scaffold_config.columns[key], value) unless human_conditions.nil? + end end - search_conditions.compact! self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, *search_conditions) - @filtered = !search_conditions.blank? + if search_conditions.blank? + @filtered = false + else + @filtered = human_conditions.nil? ? true : human_conditions.compact.join(' and ') + end includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact self.active_scaffold_includes.concat includes_for_search_columns diff --git a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb index 8b31f8e487..9a841db33e 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb @@ -64,4 +64,5 @@ def active_scaffold_javascripts(frontend = :default) ActiveScaffold::Finder::ClassMethods.module_eval do include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods alias_method :condition_for_calendar_date_select_type, :condition_for_date_bridge_type + alias_method :human_condition_for_calendar_date_select_type, :human_condition_for_date_bridge_type end diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index fabbd2ab80..27aa86a93c 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -47,4 +47,6 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods alias_method :condition_for_date_picker_type, :condition_for_date_bridge_type alias_method :condition_for_datetime_picker_type, :condition_for_date_picker_type + alias_method :human_condition_for_date_picker_type, :human_condition_for_date_bridge_type + alias_method :human_condition_for_datetime_picker_type, :human_condition_for_date_bridge_type end diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index d6a9f4f6ab..535000a81a 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -119,6 +119,19 @@ def date_bridge_from_to_for_range(column, value) end end end + + def human_condition_for_date_bridge_type(column, value) + case value[:opt] + when 'RANGE' + "#{column.active_record_class.human_attribute_name(column.name)} = #{as_(value[:range]).downcase}" + when 'PAST', 'FUTURE' + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt]).downcase} #{as_(value[:number])} #{as_(value[:unit]).downcase}" + else + from, to = date_bridge_from_to(column, value) + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt]).downcase} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '-' + I18n.l(to) : ''}" + end + end + end end end diff --git a/lib/active_scaffold/config/field_search.rb b/lib/active_scaffold/config/field_search.rb index 12e8ffe9e5..91c3c353a6 100644 --- a/lib/active_scaffold/config/field_search.rb +++ b/lib/active_scaffold/config/field_search.rb @@ -49,7 +49,7 @@ def columns # * false: LIKE ? # Default is :full attr_accessor :text_search - + # the ActionLink for this action attr_accessor :link @@ -66,5 +66,9 @@ def optional_columns # default_params = {:title => {"from"=>"test", "to"=>"", "opt"=>"%?%"}} attr_accessor :default_params + # human conditions + # instead of just filtered you may show the user a humanized search condition statment + attr_accessor :human_conditions + end end diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index ea65b03c6c..c6b9b2f876 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -41,7 +41,7 @@ def condition_for_column(column, value, text_search = :full) unless column.search_sql.instance_of? Proc case search_ui when :boolean, :checkbox - ["#{column.search_sql} = ?", column.column.type_cast(value)] + ["#{column.search_sql} = ?", column.column.type_cast(value)] when :integer, :decimal, :float condition_for_numeric(column, value) when :string, :range @@ -103,21 +103,26 @@ def condition_for_range(column, value, like_pattern = nil) nil end end - - def condition_for_datetime(column, value, like_pattern = nil) + + def condition_value_for_datetime(value) conversion = value[:from][:hour].blank? && value[:to][:hour].blank? ? :to_date : :to_time from_value, to_value = [:from, :to].collect do |field| Time.zone.local(*[:year, :month, :day, :hour, :minute, :second].collect {|part| value[field][part].to_i}) rescue nil end + return from_value, to_value + end + + def condition_for_datetime(column, value, like_pattern = nil) + from_value, to_value = condition_value_for_datetime(value) if from_value.nil? and to_value.nil? nil elsif !from_value - ["#{column.search_sql} <= ?", to_value.send(conversion).to_s(:db)] + ["#{column.search_sql} <= ?", to_value.to_s(:db)] elsif !to_value - ["#{column.search_sql} >= ?", from_value.send(conversion).to_s(:db)] + ["#{column.search_sql} >= ?", from_value.to_s(:db)] else - ["#{column.search_sql} BETWEEN ? AND ?", from_value.send(conversion).to_s(:db), to_value.send(conversion).to_s(:db)] + ["#{column.search_sql} BETWEEN ? AND ?", from_value.to_s(:db), to_value.to_s(:db)] end end @@ -145,6 +150,45 @@ def like_pattern(text_search) else '?' end end + + def override_human_condition?(search_ui) + respond_to?(override_human_condition(search_ui)) + end + + # the naming convention for overriding human condition search_ui types + def override_human_condition(search_ui) + "human_condition_for_#{search_ui}_type" + end + + def human_condition_for_column(column, value) + if column.search_ui and override_human_condition?(column.search_ui) + send(override_human_condition(column.search_ui), column, value) + else + search_ui = column.search_ui + search_ui ||= column.column.type if column.column + case search_ui + when :integer, :decimal, :float + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt])} #{value[:from]} #{value[:opt] == 'BETWEEN' ? '-' + value[:to].to_s : ''}" + when :string + opt = ActiveScaffold::Finder::StringComparators.index(value[:opt]) || value[:opt] + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(opt).downcase} '#{value[:from]}' #{opt == 'BETWEEN' ? '-' + value[:to].to_s : ''}" + when :date, :time, :datetime, :timestamp + from, to = condition_value_for_datetime(value) + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt])} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '-' + I18n.l(to) : ''}" + when :select, :multi_select + associated = value + associated = [associated].compact unless associated.is_a? Array + associated = column.association.klass.find(associated.map(&:to_i)).collect(&:to_label) if column.association + "#{column.active_record_class.human_attribute_name(column.name)} = #{associated.join(', ')}" + when :record_select + associated = value + "#{column.active_record_class.human_attribute_name(column.name)} = #{associated.to_s}" + when :boolean, :checkbox + label = column.column.type_cast(value) ? as_(:true) : as_(:false) + "#{column.active_record_class.human_attribute_name(column.name)} = #{label}" + end + end + end end NumericComparators = [ From 022e5c2bc09f08980505bdc59a50f6612fe275a7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 10 Sep 2010 13:09:27 +0200 Subject: [PATCH 0655/2024] extract method field_search_record_select_value --- .../helpers/search_column_helpers.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index df87648c32..6a5855d2eb 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -75,7 +75,7 @@ def active_scaffold_search_select(column, html_options) if column.association associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil? method = column.association.macro == :belongs_to ? column.association.primary_key_name : column.name - select_options = options_for_association(column.association, false) + select_options = options_for_association(column.association, true) else method = column.name select_options = Array(column.options[:options]) @@ -143,9 +143,14 @@ def active_scaffold_search_range(column, options) alias_method :active_scaffold_search_string, :active_scaffold_search_range def active_scaffold_search_record_select(column, options) - begin + value = field_search_record_select_value(column) + active_scaffold_record_select(column, options, value, column.options[:multiple]) + end + + def field_search_record_select_value(column) + begin value = field_search_params[column.name] - value = unless value.blank? + unless value.blank? if column.options[:multiple] column.association.klass.find value.collect!(&:to_i) else @@ -156,8 +161,6 @@ def active_scaffold_search_record_select(column, options) logger.error Time.now.to_s + "Sorry, we are not that smart yet. Attempted to restore search values to search fields but instead got -- #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}" raise e end - - active_scaffold_record_select(column, options, value, column.options[:multiple]) end def field_search_datetime_value(value) From 5ba89a85edb23b2b59fd5d2c04b96308a27bcb6b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 10 Sep 2010 16:36:49 +0200 Subject: [PATCH 0656/2024] unify date/time parsing and correctly localize in date/time bridges --- .../calendar_date_select/lib/as_cds_bridge.rb | 5 +++-- .../date_picker/lib/datepicker_bridge.rb | 3 ++- .../bridges/shared/date_bridge.rb | 13 +++++------ lib/active_scaffold/finder.rb | 22 ++++++++++++------- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb index 9a841db33e..ae89f2e218 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb @@ -32,9 +32,10 @@ def active_scaffold_input_calendar_date_select(column, options) end module SearchColumnHelpers - def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) + def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) + value = controller.class.condition_value_for_datetime(current_search[name], column.column.type == :date ? :to_date : :to_time) calendar_date_select("record", column.name, - {:name => "#{options[:name]}[#{name}]", :value => current_search[name], :class => 'text-input', :id => "#{options[:id]}_#{name}", :time => column_datetime?(column) ? true : false}) + {:name => "#{options[:name]}[#{name}]", :value => (value ? l(value) : nil), :class => 'text-input', :id => "#{options[:id]}_#{name}", :time => column_datetime?(column) ? true : false}) end end diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 27aa86a93c..7467334755 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -29,9 +29,10 @@ module Bridges module DatePickerBridge module SearchColumnHelpers def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) + value = controller.class.condition_value_for_datetime(current_search[name], column.column.type == :date ? :to_date : :to_time) options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date, :value) options[:class] << " #{column.options[:class]}" if column.options[:class] - text_field_tag("#{options[:name]}[#{name}]", current_search[name], options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) + text_field_tag("#{options[:name]}[#{name}]", value ? l(value) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) end end end diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index 535000a81a..dbabb4a634 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -59,29 +59,28 @@ module Finder module ClassMethods def condition_for_date_bridge_type(column, value, like_pattern) operator = ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) && value[:opt] != 'BETWEEN' ? value[:opt] : nil - conversion = column.column.type == :date ? 'to_date' : 'to_time' - from_value, to_value = date_bridge_from_to(column, value) if column.search_sql.is_a? Proc column.search_sql.call(from_value, to_value, operator) else unless operator.nil? - ["#{column.search_sql} #{value[:opt]} ?", from_value.send(conversion).to_s(:db)] unless from_value.nil? + ["#{column.search_sql} #{value[:opt]} ?", from_value.to_s(:db)] unless from_value.nil? else - ["#{column.search_sql} BETWEEN ? AND ?", from_value.send(conversion).to_s(:db), to_value.send(conversion).to_s(:db)] unless from_value.nil? && to_value.nil? + ["#{column.search_sql} BETWEEN ? AND ?", from_value.to_s(:db), to_value.to_s(:db)] unless from_value.nil? && to_value.nil? end end end def date_bridge_from_to(column, value) + conversion = column.column.type == :date ? :to_date : :to_time case value[:opt] when 'RANGE' - date_bridge_from_to_for_range(column, value) + date_bridge_from_to_for_range(column, value).collect(&conversion) when 'PAST', 'FUTURE' - date_bridge_from_to_for_trend(column, value) + date_bridge_from_to_for_trend(column, value).collect(&conversion) else - ['from', 'to'].collect { |field| Time.zone.parse(value[field]) rescue nil} + ['from', 'to'].collect { |field| condition_value_for_datetime(value[field], conversion)} end end diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index c6b9b2f876..802b126715 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -104,16 +104,20 @@ def condition_for_range(column, value, like_pattern = nil) end end - def condition_value_for_datetime(value) - conversion = value[:from][:hour].blank? && value[:to][:hour].blank? ? :to_date : :to_time - from_value, to_value = [:from, :to].collect do |field| + def condition_value_for_datetime(value, conversion = :to_time) + if value.is_a? Hash Time.zone.local(*[:year, :month, :day, :hour, :minute, :second].collect {|part| value[field][part].to_i}) rescue nil - end - return from_value, to_value + elsif value.respond_to?(:strftime) + value.send(conversion) + else + Time.zone.parse(value).in_time_zone.send(conversion) rescue nil + end unless value.nil? || value.blank? end - + def condition_for_datetime(column, value, like_pattern = nil) - from_value, to_value = condition_value_for_datetime(value) + conversion = column.column.type == :date ? :to_date : :to_time + from_value = condition_value_for_datetime(value[:from], conversion) + to_value = condition_value_for_datetime(value[:to], conversion) if from_value.nil? and to_value.nil? nil @@ -173,7 +177,9 @@ def human_condition_for_column(column, value) opt = ActiveScaffold::Finder::StringComparators.index(value[:opt]) || value[:opt] "#{column.active_record_class.human_attribute_name(column.name)} #{as_(opt).downcase} '#{value[:from]}' #{opt == 'BETWEEN' ? '-' + value[:to].to_s : ''}" when :date, :time, :datetime, :timestamp - from, to = condition_value_for_datetime(value) + conversion = column.column.type == :date ? :to_date : :to_time + from = condition_value_for_datetime(value[:from], conversion) + to = condition_value_for_datetime(value[:to], conversion) "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt])} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '-' + I18n.l(to) : ''}" when :select, :multi_select associated = value From 65a79f6276379774ed4642868d2196504e26bbf7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 10 Sep 2010 16:54:12 +0200 Subject: [PATCH 0657/2024] Bugfix: update_columns did not work for select fields reported by Atastor --- frontends/default/javascripts/jquery/active_scaffold.js | 2 +- frontends/default/javascripts/prototype/active_scaffold.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 5dba3b3d7d..251a32f756 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -199,7 +199,7 @@ $(document).ready(function() { event.data_url = url; return true; }); - $('input.update_form').live('change', function(event) { + $('input.update_form, select.update_form').live('change', function(event) { var element = $(this); var as_form = element.closest('form.as_form'); $.ajax({ diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 5de9c07561..85ce45d6de 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -225,7 +225,7 @@ document.observe("dom:loaded", function() { event.memo.url = url; return true; }); - document.on('change', 'input.update_form', function(event) { + document.on('change', 'input.update_form, select.update_form', function(event) { var element = event.findElement(); var as_form = element.up('form.as_form'); From 18d37c6ba50a08ed198a582c933615752e5025a7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 13 Sep 2010 15:44:25 +0200 Subject: [PATCH 0658/2024] remove reference to activescaffold website --- README | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README b/README index 6d646636fb..9aab254287 100644 --- a/README +++ b/README @@ -1,6 +1,6 @@ -********************************************************************************** -** For all documentation see the project website: http://www.ActiveScaffold.com ** -********************************************************************************** +****************************************************************************************************** +** For all documentation see the project website: http://github.com/vhochstein/active_scaffold/wiki ** +****************************************************************************************************** ActiveScaffold plugin by Scott Rutherford (scott@caronsoftware.com), Richard White (rrwhite@gmail.com), Lance Ivy (lance@cainlevy.net), Ed Moss, Tim Harper and Sergio Cambra (sergio@entrecables.com) From b762e98e22888d4919dcb61ba6b71d93c09ebc3e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 13 Sep 2010 16:02:40 +0200 Subject: [PATCH 0659/2024] Bugfix: human_condition for record_select --- lib/active_scaffold/finder.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 802b126715..43c236b3a8 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -181,14 +181,11 @@ def human_condition_for_column(column, value) from = condition_value_for_datetime(value[:from], conversion) to = condition_value_for_datetime(value[:to], conversion) "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt])} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '-' + I18n.l(to) : ''}" - when :select, :multi_select + when :select, :multi_select, :record_select associated = value associated = [associated].compact unless associated.is_a? Array associated = column.association.klass.find(associated.map(&:to_i)).collect(&:to_label) if column.association "#{column.active_record_class.human_attribute_name(column.name)} = #{associated.join(', ')}" - when :record_select - associated = value - "#{column.active_record_class.human_attribute_name(column.name)} = #{associated.to_s}" when :boolean, :checkbox label = column.column.type_cast(value) ? as_(:true) : as_(:false) "#{column.active_record_class.human_attribute_name(column.name)} = #{label}" From 9e78778c1c9e9e02bdaa9386bf4b901513d8b22a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 13 Sep 2010 16:08:34 +0200 Subject: [PATCH 0660/2024] use new ActiveRecord Query Interface --- lib/active_scaffold/helpers/association_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/association_helpers.rb b/lib/active_scaffold/helpers/association_helpers.rb index 2048bd1b1e..194297397b 100644 --- a/lib/active_scaffold/helpers/association_helpers.rb +++ b/lib/active_scaffold/helpers/association_helpers.rb @@ -3,11 +3,11 @@ module Helpers module AssociationHelpers # Provides a way to honor the :conditions on an association while searching the association's klass def association_options_find(association, conditions = nil) - association.klass.find(:all, :conditions => controller.send(:merge_conditions, conditions, association.options[:conditions])) + association.klass.where(controller.send(:merge_conditions, conditions, association.options[:conditions])).all end def association_options_count(association, conditions = nil) - association.klass.count(:all, :conditions => controller.send(:merge_conditions, conditions, association.options[:conditions])) + association.klass.where(controller.send(:merge_conditions, conditions, association.options[:conditions])).count end # returns options for the given association as a collection of [id, label] pairs intended for the +options_for_select+ helper. From 414b8c44f8dcb7cdddb1cb7e4e20d9782784d54e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 13 Sep 2010 16:14:53 +0200 Subject: [PATCH 0661/2024] human_conditions: use two words connector for proper I18n --- lib/active_scaffold/actions/field_search.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index da01c2f4c4..ff3b821827 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -58,7 +58,7 @@ def do_search if search_conditions.blank? @filtered = false else - @filtered = human_conditions.nil? ? true : human_conditions.compact.join(' and ') + @filtered = human_conditions.nil? ? true : human_conditions.compact.join(I18n.t('support.array.two_words_connector')) end includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact From f01c78cf62406114c636b7ffaf75efd9f81b141f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 13 Sep 2010 16:41:53 +0200 Subject: [PATCH 0662/2024] human_condition for null search_ui --- lib/active_scaffold/finder.rb | 15 +++++++++++++-- .../helpers/search_column_helpers.rb | 5 ++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 43c236b3a8..0c06477344 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -139,10 +139,13 @@ def condition_for_record_select_type(column, value, like_pattern = nil) end def condition_for_null_type(column, value, like_pattern = nil) - if ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(value) + case value.to_sym + when :null ["#{column.search_sql} is null"] - else + when :not_null ["#{column.search_sql} is not null"] + else + nil end end @@ -189,6 +192,8 @@ def human_condition_for_column(column, value) when :boolean, :checkbox label = column.column.type_cast(value) ? as_(:true) : as_(:false) "#{column.active_record_class.human_attribute_name(column.name)} = #{label}" + when :null + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value.to_sym)}" end end end @@ -208,6 +213,12 @@ def human_condition_for_column(column, value) :begins_with => '?%', :ends_with => '%?' } + NullComparators = [ + :null, + :not_null + ] + + def self.included(klass) klass.extend ClassMethods diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 6a5855d2eb..864bc7b97d 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -111,9 +111,8 @@ def active_scaffold_search_boolean(column, options) def active_scaffold_search_null(column, options) select_options = [] select_options << [as_(:_select_), nil] - select_options << [as_(:null), true] - select_options << [as_(:not_null), false] - select_tag(options[:name], options_for_select(select_options, ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(field_search_params[column.name]))) + select_options.concat ActiveScaffold::Finder::NullComparators.collect {|comp| [as_(comp), comp]} + select_tag(options[:name], options_for_select(select_options, field_search_params[column.name])) end def field_search_params_range_values(column) From 30d950ee636aff500561db67f3bc0511cbcd08de Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 14 Sep 2010 15:09:38 +0200 Subject: [PATCH 0663/2024] Get rid of LOWER functions in SQL where clause so index can be used, fix issues with encodings and casts needed in postgres, and check postgres to use ILIKE instead of LIKE operator --- lib/active_scaffold/finder.rb | 12 ++++++++---- test/misc/finder_test.rb | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 17cc879e74..136b0c1437 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -1,5 +1,9 @@ module ActiveScaffold module Finder + def self.like_operator + @@like_operator ||= ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE" + end + module ClassMethods # Takes a collection of search terms (the tokens) and creates SQL that # searches all specified ActiveScaffold columns. A row will match if each @@ -13,13 +17,13 @@ def create_conditions_for_columns(tokens, columns, text_search = :full) where_clauses = [] columns.each do |column| - where_clauses << ((column.column.nil? || column.column.text?) ? "LOWER(#{column.search_sql}) LIKE ?" : "#{column.search_sql} = ?") + where_clauses << ((column.column.nil? || column.column.text?) ? "#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?" : "#{column.search_sql} = ?") end phrase = "(#{where_clauses.join(' OR ')})" sql = ([phrase] * tokens.length).join(' AND ') tokens = tokens.collect do |value| - columns.collect {|column| (column.column.nil? || column.column.text?) ? like_pattern.sub('?', value.downcase) : column.column.type_cast(value)} + columns.collect {|column| (column.column.nil? || column.column.text?) ? like_pattern.sub('?', value) : column.column.type_cast(value)} end.flatten [sql, *tokens] @@ -45,7 +49,7 @@ def condition_for_column(column, value, text_search = :full) ["#{column.search_sql} in (?)", value] else if column.column.nil? || column.column.text? - ["LOWER(#{column.search_sql}) LIKE ?", like_pattern.sub('?', value.downcase)] + ["#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] else ["#{column.search_sql} = ?", column.column.type_cast(value)] end @@ -90,7 +94,7 @@ def condition_for_integer_type(column, value, like_pattern = nil) def condition_for_range_type(column, value, like_pattern = nil) if !value.is_a?(Hash) if column.column.nil? || column.column.text? - ["LOWER(#{column.search_sql}) LIKE ?", like_pattern.sub('?', value.downcase)] + ["#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] else ["#{column.search_sql} = ?", column.column.type_cast(value)] end diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index 7423440e3b..cc57c3877f 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -33,13 +33,13 @@ def test_create_conditions_for_columns ] expected_conditions = [ - '(LOWER("model_stubs"."a") LIKE ? OR LOWER("model_stubs"."b") LIKE ?) AND (LOWER("model_stubs"."a") LIKE ? OR LOWER("model_stubs"."b") LIKE ?)', + '("model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?) AND ("model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?)', '%foo%', '%foo%', '%bar%', '%bar%' ] assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns(tokens, columns) expected_conditions = [ - '(LOWER("model_stubs"."a") LIKE ? OR LOWER("model_stubs"."b") LIKE ?)', + '("model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?)', '%foo%', '%foo%' ] assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns('foo', columns) From ed75472668363759f07743cc7199169f41978ec2 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 14 Sep 2010 15:22:59 +0200 Subject: [PATCH 0664/2024] another fix for has_one :through --- lib/extensions/unsaved_associated.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extensions/unsaved_associated.rb b/lib/extensions/unsaved_associated.rb index 1a9ae4b836..c2683c99a9 100644 --- a/lib/extensions/unsaved_associated.rb +++ b/lib/extensions/unsaved_associated.rb @@ -48,7 +48,7 @@ def associations_for_update # returns true otherwise, even when none of the associations have been instantiated. build wrapper methods accordingly. def with_unsaved_associated associations_for_update.all? do |association| - association_proxy = instance_variable_get("@#{association.name}") + association_proxy = send(association.name) if association_proxy records = association_proxy records = [records] unless records.is_a? Array # convert singular associations into collections for ease of use From cb243526a1e550f71b2f43de282f72b2e6e2e5be Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 14 Sep 2010 15:27:55 +0200 Subject: [PATCH 0665/2024] use rails date localization settings for jquery datepicker --- .../bridges/date_picker/bridge.rb | 3 + .../date_picker/lib/datepicker_bridge.rb | 65 +++++++++++++++++++ lib/active_scaffold/locale/de.rb | 6 ++ lib/active_scaffold/locale/en.rb | 7 +- lib/active_scaffold/locale/fr.rb | 6 ++ 5 files changed, 86 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/date_picker/bridge.rb b/lib/active_scaffold/bridges/date_picker/bridge.rb index f992a451f5..75f2ac8b87 100644 --- a/lib/active_scaffold/bridges/date_picker/bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/bridge.rb @@ -1,3 +1,5 @@ + + ActiveScaffold::Bridges.bridge "DatePicker" do install do directory = File.dirname(__FILE__) @@ -7,6 +9,7 @@ if ActiveScaffold.js_framework == :jquery require File.join(directory, "lib/datepicker_bridge.rb") FileUtils.cp(source, destination) + ActiveScaffold::Bridges::DatePickerBridge.localization(File.join(destination, 'date_picker_bridge.js')) else # make sure that jquery files are removed FileUtils.rm(File.join(destination, 'date_picker_bridge.js')) if File.exist?(File.join(destination, 'date_picker_bridge.js')) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 7467334755..c6f8b40e49 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -1,3 +1,13 @@ +class File #:nodoc: + + unless File.respond_to?(:binread) + def self.binread(file) + File.open(file, 'rb') { |f| f.read } + end + end + +end + ActiveScaffold::Config::Core.class_eval do def initialize_with_date_picker(model_id) initialize_without_date_picker(model_id) @@ -27,6 +37,61 @@ def initialize_with_date_picker(model_id) module ActiveScaffold module Bridges module DatePickerBridge + DATE_FORMAT_CONVERSION = { + '%a' => 'D', + '%A' => 'DD', + '%b' => 'M', + '$B' => 'MM', + '%d' => 'dd', + '%j' => 'oo', + '%m' => 'mm', + '%y' => 'y', + '%Y' => 'yy' + } + + def self.localization(js_file) + date_options = I18n.t 'date' + date_picker_options = { :closeText => as_(:close), + :prevText => as_(:previous), + :nextText => as_(:next), + :currentText => as_(:today), + :monthNames => date_options[:month_names][1, (date_options[:month_names].length - 1)], + :monthNamesShort => date_options[:abbr_month_names][1, (date_options[:abbr_month_names].length - 1)], + :dayNames => date_options[:day_names], + :dayNamesShort => date_options[:abbr_day_names], + :dayNamesMin => date_options[:abbr_day_names] + }.merge(as_(:date_picker_options)) + + date_time_picker_options = + # what about time format + js_format = self.date_format_converter(date_options[:formats][:default]) + date_picker_options[:dateFormat] = js_format unless js_format.nil? + localization = "jQuery(function($){ + $.datepicker.regional['#{I18n.locale}'] = #{date_picker_options.to_json}; + $.datepicker.setDefaults($.datepicker.regional['#{I18n.locale}']); +});\n" + prepend_js_file(js_file, localization) + end + + def self.prepend_js_file(js_file, prepend) + content = File.binread(js_file) + content.gsub!(/\A/, prepend) + File.open(js_file, 'wb') { |file| file.write(content) } + end + + def self.date_format_converter(rails_format) + if rails_format =~ /%[cUWwxX]/ + Rails.logger.warning("AS DatePickerBridge: Can t convert rails date format: #{rails_format} to jquery datepicker format. Options %c, %U, %W, %w, %x %X are not supported by datepicker]") + nil + else + js_format = rails_format.dup + DATE_FORMAT_CONVERSION.each do |key, value| + js_format.gsub!(Regexp.new("#{key}"), value) + end + js_format + end + end + module SearchColumnHelpers def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) value = controller.class.condition_value_for_datetime(current_search[name], column.column.type == :date ? :to_date : :to_time) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index f5292a6c43..dd4f611960 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -80,6 +80,12 @@ :optional_attributes => 'Weitere', :null => 'Definiert', :not_null => 'Undefiniert', + :date_picker_options => { + :weekHeader => 'Wo', + :firstDay => 1, + :isRTL => false, + :showMonthAfterYear => false, + }, # error_messages :cant_destroy_record => "%{record} kann nicht gelöscht werden", diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 857249a6b8..50414b5d07 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -86,7 +86,12 @@ :optional_attributes => 'Further Options', :null => 'Null', :not_null => 'Not Null', - + :date_picker_options => { + :weekHeader => 'Wk', + :firstDay => 0, + :isRTL => false, + :showMonthAfterYear => false + }, # error_messages :cant_destroy_record => "%{record} can't be destroyed", :internal_error => 'Request Failed (code 500, Internal Error)', diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index eebf223005..4c69125df6 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -80,6 +80,12 @@ :optional_attributes => 'Further Options', :null => 'Null', :not_null => 'Not Null', + :date_picker_options => { + :weekHeader => 'Sm', + :firstDay => 1, + :isRTL => false, + :showMonthAfterYear => false, + }, # error_messages :cant_destroy_record => "%{record} can't be destroyed", From 280af9bbf0fee3d311fea23f100d4bbc2215077d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 14 Sep 2010 16:02:59 +0200 Subject: [PATCH 0666/2024] Allow to override create new text in association columns, setting a symbol in column.link.label (defaults to :create_model) --- lib/active_scaffold.rb | 2 +- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 329580dd75..6ce327cd44 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -124,7 +124,7 @@ def links_for_associations column.actions_for_association_links.delete :new unless actions.include? :create column.actions_for_association_links.delete :edit unless actions.include? :update column.actions_for_association_links.delete :show unless actions.include? :show - column.set_link(:none, :controller => controller.controller_path, :crud_type => nil, :html_options => {:class => column.name}) + column.set_link(:none, :controller => controller.controller_path, :crud_type => nil, :label => :create_model, :html_options => {:class => column.name}) end end end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 7cdecdf52f..7c8cdc2c6f 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -47,7 +47,7 @@ def render_list_column(text, column, record) link = action_link_to_inline_form(column, associated) if link.crud_type.nil? # automatic link to inline form (singular association) return text if link.crud_type.nil? if link.crud_type == :create - url_options[:link] = as_(:create_new) + url_options[:link] = as_(link.label, :model => column.association.klass.human_name, :parent => column.association.active_record.human_name) url_options[:parent_id] = record.id url_options[:parent_column] = column.association.reverse url_options[:parent_model] = record.class.name # needed for polymorphic associations From 5771bc2d3c8177bf156e694120266e74afa56149 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 14 Sep 2010 17:40:20 +0200 Subject: [PATCH 0667/2024] Fix untranslated error message --- lib/active_scaffold/actions/update.rb | 2 +- lib/active_scaffold/locale/de.yml | 3 ++- lib/active_scaffold/locale/en.yml | 1 + lib/active_scaffold/locale/es.yml | 1 + lib/active_scaffold/locale/fr.yml | 1 + lib/active_scaffold/locale/hu.yml | 1 + lib/active_scaffold/locale/ja.yml | 1 + lib/active_scaffold/locale/ru.yml | 1 + 8 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 1321294d26..a37b9bf100 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -85,7 +85,7 @@ def do_update @record.errors.add_to_base as_(:version_inconsistency) self.successful=false rescue ActiveRecord::RecordNotSaved - @record.errors.add_to_base as_("Failed to save record cause of an unknown error") if @record.errors.empty? + @record.errors.add_to_base as_(:failed_to_save_record) if @record.errors.empty? self.successful = false end end diff --git a/lib/active_scaffold/locale/de.yml b/lib/active_scaffold/locale/de.yml index 4d4949e48e..832f6a74c0 100644 --- a/lib/active_scaffold/locale/de.yml +++ b/lib/active_scaffold/locale/de.yml @@ -65,4 +65,5 @@ # error_messages cant_destroy_record: "%{record} kann nicht gelöscht werden" internal_error: 'Fehler bei der Verarbeitung (code 500, Interner Fehler)' - version_inconsistency: 'Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben.' \ No newline at end of file + version_inconsistency: 'Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben.' + failed_to_save_record: 'Failed to save record cause of an unknown error' diff --git a/lib/active_scaffold/locale/en.yml b/lib/active_scaffold/locale/en.yml index 3a365a3b97..b14f20b28a 100644 --- a/lib/active_scaffold/locale/en.yml +++ b/lib/active_scaffold/locale/en.yml @@ -69,3 +69,4 @@ cant_destroy_record: "%{record} can't be destroyed" internal_error: 'Request Failed (code 500, Internal Error)' version_inconsistency: 'Version inconsistency - this record has been modified since you started editing it.' + failed_to_save_record: 'Failed to save record cause of an unknown error' diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index 83c51f4973..159058e0f9 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -71,3 +71,4 @@ es: cant_destroy_record: "No se pudo borrar %{record}" internal_error: 'Petición fallida (código 500, error interno)' version_inconsistency: 'Inconsistencia de versiones - este registro se ha modificado después de que empezó a editarlo.' + failed_to_save_record: 'Fallo al guardar el registro debido a un error desconocido' diff --git a/lib/active_scaffold/locale/fr.yml b/lib/active_scaffold/locale/fr.yml index b08107b4d9..74e8441aa8 100644 --- a/lib/active_scaffold/locale/fr.yml +++ b/lib/active_scaffold/locale/fr.yml @@ -65,3 +65,4 @@ # error_messages internal_error: 'Erreur de la requête (code 500, Erreur interne)' version_inconsistency: "Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer." + failed_to_save_record: 'Failed to save record cause of an unknown error' diff --git a/lib/active_scaffold/locale/hu.yml b/lib/active_scaffold/locale/hu.yml index 5d445445e1..0639dfa2a9 100644 --- a/lib/active_scaffold/locale/hu.yml +++ b/lib/active_scaffold/locale/hu.yml @@ -65,3 +65,4 @@ hu: # error_messages internal_error: 'A lekérés sikertelen (code 500, Internal Error)' version_inconsistency: 'Verzió ütközés - ezt a rekordot módosították mióta elkezdted szerkeszteni.' + failed_to_save_record: 'Failed to save record cause of an unknown error' diff --git a/lib/active_scaffold/locale/ja.yml b/lib/active_scaffold/locale/ja.yml index 6648c958f6..d7402c8de0 100644 --- a/lib/active_scaffold/locale/ja.yml +++ b/lib/active_scaffold/locale/ja.yml @@ -66,3 +66,4 @@ ja: cant_destroy_record: "%{record}を削除で来ません" internal_error: 'リクエストが失敗しました(コード500: 内部エラー)' version_inconsistency: 'バージョンが一致しません - あなたが編集している間にこのレコードが変更されました。' + failed_to_save_record: 'Failed to save record cause of an unknown error' diff --git a/lib/active_scaffold/locale/ru.yml b/lib/active_scaffold/locale/ru.yml index a79ca4e0a7..541ec5ad18 100644 --- a/lib/active_scaffold/locale/ru.yml +++ b/lib/active_scaffold/locale/ru.yml @@ -69,3 +69,4 @@ ru: cant_destroy_record: 'Запись %{record} не может быть удалена' internal_error: '500 Внутренняя ошибка сервера' version_inconsistency: 'Несоответствие версий: эта запись была обновлена с того момента, как вы начали ее редактировать' + failed_to_save_record: 'Failed to save record cause of an unknown error' From c96f65eca6839742526e82e30bd0a79331778c60 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 14 Sep 2010 18:12:12 +0200 Subject: [PATCH 0668/2024] DRY label method in config classes --- lib/active_scaffold/config/base.rb | 8 ++++++++ lib/active_scaffold/config/create.rb | 11 ++--------- lib/active_scaffold/config/delete.rb | 3 +-- lib/active_scaffold/config/field_search.rb | 3 +-- lib/active_scaffold/config/form.rb | 6 +----- lib/active_scaffold/config/list.rb | 3 +-- lib/active_scaffold/config/nested.rb | 7 ++----- lib/active_scaffold/config/search.rb | 3 +-- lib/active_scaffold/config/show.rb | 6 ++---- lib/active_scaffold/config/subform.rb | 2 +- lib/active_scaffold/config/update.rb | 8 ++------ test/config/base_test.rb | 2 +- 12 files changed, 23 insertions(+), 39 deletions(-) diff --git a/lib/active_scaffold/config/base.rb b/lib/active_scaffold/config/base.rb index 414573571f..b83cae53b9 100644 --- a/lib/active_scaffold/config/base.rb +++ b/lib/active_scaffold/config/base.rb @@ -3,6 +3,10 @@ class Base include ActiveScaffold::Configurable extend ActiveScaffold::Configurable + def initialize(core_config) + @core = core_config + end + def self.inherited(subclass) class << subclass # the crud type of the action. possible values are :create, :read, :update, :delete, and nil. @@ -20,6 +24,10 @@ def crud_type=(val) # delegate def crud_type; self.class.crud_type end + def label(model = nil) + as_(@label, :model => model || @core.label(:count => 1)) + end + # the user property gets set to the instantiation of the local UserSettings class during the automatic instantiation of this class. attr_accessor :user diff --git a/lib/active_scaffold/config/create.rb b/lib/active_scaffold/config/create.rb index d5ba3c3d3f..5a8e9620df 100644 --- a/lib/active_scaffold/config/create.rb +++ b/lib/active_scaffold/config/create.rb @@ -1,8 +1,9 @@ module ActiveScaffold::Config class Create < ActiveScaffold::Config::Form self.crud_type = :create - def initialize(*args) + def initialize(core_config) super + @label = :create_model self.persistent = self.class.persistent self.action_after_create = self.class.action_after_create end @@ -26,14 +27,6 @@ def self.link=(val) cattr_accessor :action_after_create @@action_after_create = nil - # instance-level configuration - # ---------------------------- - # the label= method already exists in the Form base class - def label(model = nil) - model ||= @core.label(:count => 1) - @label ? as_(@label) : as_(:create_model, :model => model) - end - # whether the form stays open after a create or not attr_accessor :persistent diff --git a/lib/active_scaffold/config/delete.rb b/lib/active_scaffold/config/delete.rb index dd23ded460..b23b5ac5e3 100644 --- a/lib/active_scaffold/config/delete.rb +++ b/lib/active_scaffold/config/delete.rb @@ -3,8 +3,7 @@ class Delete < Base self.crud_type = :delete def initialize(core_config) - @core = core_config - + super # start with the ActionLink defined globally @link = self.class.link.clone end diff --git a/lib/active_scaffold/config/field_search.rb b/lib/active_scaffold/config/field_search.rb index 1286b68829..a6b4ca6cfc 100644 --- a/lib/active_scaffold/config/field_search.rb +++ b/lib/active_scaffold/config/field_search.rb @@ -3,8 +3,7 @@ class FieldSearch < Base self.crud_type = :read def initialize(core_config) - @core = core_config - + super @text_search = self.class.text_search # start with the ActionLink defined globally diff --git a/lib/active_scaffold/config/form.rb b/lib/active_scaffold/config/form.rb index 47fcde94cf..fb4b226bc2 100644 --- a/lib/active_scaffold/config/form.rb +++ b/lib/active_scaffold/config/form.rb @@ -1,8 +1,7 @@ module ActiveScaffold::Config class Form < Base def initialize(core_config) - @core = core_config - + super # start with the ActionLink defined globally @link = self.class.link.clone @@ -21,9 +20,6 @@ def initialize(core_config) # the label for this Form action. used for the header. attr_writer :label - def label - as_(@label) - end # provides access to the list of columns specifically meant for the Form to use def columns diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 688943748a..82aa8d553d 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -3,8 +3,7 @@ class List < Base self.crud_type = :read def initialize(core_config) - @core = core_config - + super # inherit from global scope # full configuration path is: defaults => global table => local table @per_page = self.class.per_page diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index fdcec851e9..233ae5f45f 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -3,7 +3,8 @@ class Nested < Base self.crud_type = :read def initialize(core_config) - @core = core_config + super + @label = :add_existing_model self.shallow_delete = self.class.shallow_delete end @@ -27,9 +28,5 @@ def add_link(label, models, options = {}) # the label for this Nested action. used for the header. attr_writer :label - def label - @label ? as_(@label) : as_(:add_existing_model, :model => @core.label) - end - end end diff --git a/lib/active_scaffold/config/search.rb b/lib/active_scaffold/config/search.rb index 9a2aaa2dab..7f0b961e39 100644 --- a/lib/active_scaffold/config/search.rb +++ b/lib/active_scaffold/config/search.rb @@ -3,8 +3,7 @@ class Search < Base self.crud_type = :read def initialize(core_config) - @core = core_config - + super @text_search = self.class.text_search @live = self.class.live? diff --git a/lib/active_scaffold/config/show.rb b/lib/active_scaffold/config/show.rb index dd63989b1c..41357ce4ae 100644 --- a/lib/active_scaffold/config/show.rb +++ b/lib/active_scaffold/config/show.rb @@ -3,9 +3,10 @@ class Show < Base self.crud_type = :read def initialize(core_config) - @core = core_config + super # start with the ActionLink defined globally @link = self.class.link.clone + @label = :show_model end # global level configuration @@ -19,9 +20,6 @@ def initialize(core_config) attr_accessor :link # the label for this action. used for the header. attr_writer :label - def label - @label ? as_(@label) : as_(:show_model, :model => @core.label(:count => 1)) - end # provides access to the list of columns specifically meant for this action to use def columns diff --git a/lib/active_scaffold/config/subform.rb b/lib/active_scaffold/config/subform.rb index 580a283f20..19159865f0 100644 --- a/lib/active_scaffold/config/subform.rb +++ b/lib/active_scaffold/config/subform.rb @@ -1,7 +1,7 @@ module ActiveScaffold::Config class Subform < Base def initialize(core_config) - @core = core_config + super @layout = self.class.layout # default layout end diff --git a/lib/active_scaffold/config/update.rb b/lib/active_scaffold/config/update.rb index 8e867f0f17..521414e92e 100644 --- a/lib/active_scaffold/config/update.rb +++ b/lib/active_scaffold/config/update.rb @@ -1,10 +1,11 @@ module ActiveScaffold::Config class Update < ActiveScaffold::Config::Form self.crud_type = :update - def initialize(*args) + def initialize(core_config) super self.nested_links = self.class.nested_links self.persistent = self.class.persistent + @label = :update_model end # global level configuration @@ -25,11 +26,6 @@ def self.link=(val) # instance-level configuration # ---------------------------- - # the label= method already exists in the Form base class - def label - @label ? as_(@label) : as_(:update_model, :model => @core.label(:count => 1)) - end - attr_accessor :nested_links cattr_accessor :nested_links @@nested_links = false diff --git a/test/config/base_test.rb b/test/config/base_test.rb index 23e0fef437..467bc2fb00 100644 --- a/test/config/base_test.rb +++ b/test/config/base_test.rb @@ -2,7 +2,7 @@ class Config::BaseTest < Test::Unit::TestCase def setup - @base = ActiveScaffold::Config::Base.new + @base = ActiveScaffold::Config::Base.new(nil) end def test_formats From 401cebd4fbb441aca2a4155b58bef2c0b023effb Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 15 Sep 2010 11:07:15 +0200 Subject: [PATCH 0669/2024] Remove unused method --- lib/active_scaffold/data_structures/set.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/active_scaffold/data_structures/set.rb b/lib/active_scaffold/data_structures/set.rb index b25cdb24e8..1cae9c7c42 100644 --- a/lib/active_scaffold/data_structures/set.rb +++ b/lib/active_scaffold/data_structures/set.rb @@ -3,11 +3,6 @@ class Set include Enumerable include ActiveScaffold::Configurable - attr_writer :label - def label - as_(@label) - end - def initialize(*args) @set = [] self.add *args @@ -59,4 +54,4 @@ def empty? end end -end \ No newline at end of file +end From c563de979a8a438830d6db2bf35df05e66dcb71d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 15 Sep 2010 11:16:32 +0200 Subject: [PATCH 0670/2024] Add note about updating to master branch --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index 63cbf8566c..e49fdc7ba6 100644 --- a/README +++ b/README @@ -27,6 +27,9 @@ http://code.google.com/p/recordselect/ Please note the following list of Active Scaffold branches and Rails versions. Master will not work with Rails < 2.2 Active Scaffold master currently supports rails-2.3.8, but incompatible changes can be introduced, if you want an stable version, use rails-2.3 + +If you are using rails-2.3 with no deprecation warnings, you can update to master branch, although you will have to update your form and search helper overrides, because they will get an options hash instead of input name. + Rails 2.3.*: Active Scaffold rails-2.3 Rails 2.2.*: Active Scaffold rails-2.2 Rails 2.1.*: Active Scaffold rails-2.1 From 07681f0f15e1f440d3ef704764beca25c0e1d56b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 15 Sep 2010 14:10:48 +0200 Subject: [PATCH 0671/2024] Use label defined in show --- frontends/default/views/_show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_show.html.erb b/frontends/default/views/_show.html.erb index b7863149d0..52c944d1a4 100644 --- a/frontends/default/views/_show.html.erb +++ b/frontends/default/views/_show.html.erb @@ -1,4 +1,4 @@ -<h4><%= @record.to_label.nil? ? active_scaffold_config.show.label : as_(:show_model, :model => clean_column_value(@record.to_label)) %></h4> +<h4><%= active_scaffold_config.show.label(@record.to_label.nil? ? nil : clean_column_value(@record.to_label)) %></h4> <%= render :partial => 'show_columns', :locals => {:columns => active_scaffold_config.show.columns} -%> From 24c9c9949fc72325f82b372b4a0554be8913265d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 15 Sep 2010 15:03:19 +0200 Subject: [PATCH 0672/2024] add localization support for datetime input fields using jquery_ui and http://github.com/vhochstein/jQuery-Timepicker-Addon --- .../date_picker/lib/datepicker_bridge.rb | 46 ++++++++++++++----- lib/active_scaffold/locale/de.rb | 3 +- lib/active_scaffold/locale/en.rb | 2 + lib/active_scaffold/locale/fr.rb | 3 +- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index c6f8b40e49..466c2a76fa 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -46,10 +46,29 @@ module DatePickerBridge '%j' => 'oo', '%m' => 'mm', '%y' => 'y', - '%Y' => 'yy' + '%Y' => 'yy', + '%H' => 'hh', # options ampm => false + '%I' => 'hh', # options ampm => true + '%M' => 'mm', + '%p' => 'TT', + '%S' => 'ss' } def self.localization(js_file) + localization = "jQuery(function($){ + if (typeof($.datepicker) === 'object') { + $.datepicker.regional['#{I18n.locale}'] = #{date_options.to_json}; + $.datepicker.setDefaults($.datepicker.regional['#{I18n.locale}']); + } + if (typeof($.timepicker) === 'object') { + $.timepicker.regional['#{I18n.locale}'] = #{datetime_options.to_json}; + $.timepicker.setDefaults($.timepicker.regional['#{I18n.locale}']); + } +});\n" + prepend_js_file(js_file, localization) + end + + def self.date_options date_options = I18n.t 'date' date_picker_options = { :closeText => as_(:close), :prevText => as_(:previous), @@ -61,16 +80,20 @@ def self.localization(js_file) :dayNamesShort => date_options[:abbr_day_names], :dayNamesMin => date_options[:abbr_day_names] }.merge(as_(:date_picker_options)) - - date_time_picker_options = - # what about time format js_format = self.date_format_converter(date_options[:formats][:default]) date_picker_options[:dateFormat] = js_format unless js_format.nil? - localization = "jQuery(function($){ - $.datepicker.regional['#{I18n.locale}'] = #{date_picker_options.to_json}; - $.datepicker.setDefaults($.datepicker.regional['#{I18n.locale}']); -});\n" - prepend_js_file(js_file, localization) + date_picker_options + end + + def self.datetime_options + time_options = I18n.t 'time' + datetime_picker_options = {:ampm => false}.merge(as_(:datetime_picker_options)) + js_format = self.date_format_converter(time_options[:formats][:time] || '%H:%M') + unless js_format.nil? + datetime_picker_options[:timeFormat] = js_format + datetime_picker_options[:ampm] = true if time_options[:formats][:time].present? && time_options[:formats][:time].include?('%I') + end + datetime_picker_options end def self.prepend_js_file(js_file, prepend) @@ -80,8 +103,9 @@ def self.prepend_js_file(js_file, prepend) end def self.date_format_converter(rails_format) - if rails_format =~ /%[cUWwxX]/ - Rails.logger.warning("AS DatePickerBridge: Can t convert rails date format: #{rails_format} to jquery datepicker format. Options %c, %U, %W, %w, %x %X are not supported by datepicker]") + return nil if rails_format.nil? + if rails_format =~ /%[cUWwxXZ]/ + Rails.logger.warn("AS DatePickerBridge: Can t convert rails date format: #{rails_format} to jquery datepicker format. Options %c, %U, %W, %w, %x %X are not supported by datepicker]") nil else js_format = rails_format.dup diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index dd4f611960..4bfbd8d46c 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -86,7 +86,8 @@ :isRTL => false, :showMonthAfterYear => false, }, - + :datetime_picker_options => { + }, # error_messages :cant_destroy_record => "%{record} kann nicht gelöscht werden", :internal_error => 'Fehler bei der Verarbeitung (code 500, Interner Fehler)', diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 50414b5d07..5ac3df9e77 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -92,6 +92,8 @@ :isRTL => false, :showMonthAfterYear => false }, + :datetime_picker_options => { + }, # error_messages :cant_destroy_record => "%{record} can't be destroyed", :internal_error => 'Request Failed (code 500, Internal Error)', diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 4c69125df6..25c7a64246 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -86,7 +86,8 @@ :isRTL => false, :showMonthAfterYear => false, }, - + :datetime_picker_options => { + }, # error_messages :cant_destroy_record => "%{record} can't be destroyed", :internal_error => 'Erreur de la requête (code 500, Erreur interne)', From ba867b6a35789f1f27e10930c457a10adde6f104 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 15 Sep 2010 15:10:47 +0200 Subject: [PATCH 0673/2024] set changeMonth and changeYear options to true for jquery datepicker --- .../bridges/date_picker/lib/datepicker_bridge.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 466c2a76fa..c5acc8b16b 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -78,7 +78,9 @@ def self.date_options :monthNamesShort => date_options[:abbr_month_names][1, (date_options[:abbr_month_names].length - 1)], :dayNames => date_options[:day_names], :dayNamesShort => date_options[:abbr_day_names], - :dayNamesMin => date_options[:abbr_day_names] + :dayNamesMin => date_options[:abbr_day_names], + :changeYear => true, + :changeMonth => true, }.merge(as_(:date_picker_options)) js_format = self.date_format_converter(date_options[:formats][:default]) date_picker_options[:dateFormat] = js_format unless js_format.nil? From f81b546d5ca7304b881eff054c66f854d44fd920 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 15 Sep 2010 15:51:17 +0200 Subject: [PATCH 0674/2024] add jquery time_addon js file to setup generator --- .../active_scaffold_setup/active_scaffold_setup_generator.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb index 5b467598f9..df81310d56 100644 --- a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +++ b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb @@ -14,6 +14,7 @@ def install_plugins get "http://github.com/vhochstein/prototype-ujs/raw/master/src/rails.js", "public/javascripts/rails.js" elsif js_lib == 'jquery' get "http://github.com/vhochstein/jquery-ujs/raw/master/src/rails.js", "public/javascripts/rails_jquery.js" + get "http://github.com/vhochstein/jQuery-Timepicker-Addon/raw/master/jquery-ui-timepicker-addon.js", "public/javascripts/jquery-ui-timepicker-addon.js" end end @@ -34,6 +35,7 @@ def configure_application_layout <%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js' %> <%= javascript_include_tag 'rails_jquery.js' %> <%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.js' %> + <%= javascript_include_tag 'jquery-ui-timepicker-addon.js' %> <%= javascript_include_tag 'application.js' %> <%= active_scaffold_includes %>\n", :after => "<%= javascript_include_tag :defaults %>\n" From 0e09b5fbb050f94565a825fd5c5ef8d9d470d871 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 15 Sep 2010 17:32:20 +0200 Subject: [PATCH 0675/2024] Complete config tests --- lib/active_scaffold/config/list.rb | 1 - lib/active_scaffold/config/search.rb | 1 - test/config/base_test.rb | 2 +- test/config/create_test.rb | 3 ++ test/config/delete_test.rb | 33 +++++++++++++ test/config/field_search_test.rb | 47 ++++++++++++++++++ test/config/list_test.rb | 73 ++++++++++++++++++++++++---- test/config/nested_test.rb | 44 +++++++++++++++++ test/config/search_test.rb | 60 +++++++++++++++++++++++ test/config/show_test.rb | 10 ++-- test/config/subform_test.rb | 17 +++++++ test/config/update_test.rb | 31 ++++++++++-- test/misc/lang_test.rb | 5 +- 13 files changed, 303 insertions(+), 24 deletions(-) create mode 100644 test/config/delete_test.rb create mode 100644 test/config/field_search_test.rb create mode 100644 test/config/nested_test.rb create mode 100644 test/config/search_test.rb create mode 100644 test/config/subform_test.rb diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 82aa8d553d..4a69813c5d 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -120,7 +120,6 @@ def always_show_search def search_partial return "search" if @core.actions.include?(:search) - return "live_search" if @core.actions.include?(:live_search) return "field_search" if @core.actions.include?(:field_search) end diff --git a/lib/active_scaffold/config/search.rb b/lib/active_scaffold/config/search.rb index 7f0b961e39..11af10d9e3 100644 --- a/lib/active_scaffold/config/search.rb +++ b/lib/active_scaffold/config/search.rb @@ -6,7 +6,6 @@ def initialize(core_config) super @text_search = self.class.text_search @live = self.class.live? - @split_terms = self.class.split_terms # start with the ActionLink defined globally diff --git a/test/config/base_test.rb b/test/config/base_test.rb index 467bc2fb00..9fab684293 100644 --- a/test/config/base_test.rb +++ b/test/config/base_test.rb @@ -2,7 +2,7 @@ class Config::BaseTest < Test::Unit::TestCase def setup - @base = ActiveScaffold::Config::Base.new(nil) + @base = ActiveScaffold::Config::Base.new(ActiveScaffold::Config::Core.new(:model_stub)) end def test_formats diff --git a/test/config/create_test.rb b/test/config/create_test.rb index eea320b164..3298c47fb3 100644 --- a/test/config/create_test.rb +++ b/test/config/create_test.rb @@ -41,6 +41,9 @@ def test_label label = 'create new monkeys' @config.create.label = label assert_equal label, @config.create.label + I18n.backend.store_translations :en, :active_scaffold => {:create_model => 'Create new %{model}'} + @config.create.label = :create_model + assert_equal 'Create new Modelstub', @config.create.label end def test_persistent diff --git a/test/config/delete_test.rb b/test/config/delete_test.rb new file mode 100644 index 0000000000..8d3f11674d --- /dev/null +++ b/test/config/delete_test.rb @@ -0,0 +1,33 @@ +require File.join(File.dirname(__FILE__), '../test_helper.rb') + +class Config::DeleteTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + @default_link = @config.delete.link + end + + def teardown + @config.delete.link = @default_link + end + + def test_link_defaults + link = @config.delete.link + assert !link.page? + assert !link.popup? + assert link.confirm? + assert_equal "delete", link.action + assert_equal "Delete", link.label + assert link.inline? + blank = {} + assert_equal blank, link.html_options + assert_equal :delete, link.method + assert_equal :member, link.type + assert_equal :delete, link.crud_type + assert_equal :delete_authorized?, link.security_method + end + + def test_setting_link + @config.delete.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys') + assert_not_equal(@default_link, @config.delete.link) + end +end diff --git a/test/config/field_search_test.rb b/test/config/field_search_test.rb new file mode 100644 index 0000000000..ed6f9c49e6 --- /dev/null +++ b/test/config/field_search_test.rb @@ -0,0 +1,47 @@ +require File.join(File.dirname(__FILE__), '../test_helper.rb') + +class Config::FieldSearchTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + @config.actions.swap :search, :field_search + @default_link = @config.field_search.link + end + + def teardown + @config.field_search.link = @default_link + end + + def test_default_options + assert_equal :full, @config.field_search.text_search + end + + def test_text_search + @config.field_search.text_search = :start + assert_equal :start, @config.field_search.text_search + @config.field_search.text_search = :end + assert_equal :end, @config.field_search.text_search + @config.field_search.text_search = false + assert !@config.field_search.text_search + end + + def test_link_defaults + link = @config.field_search.link + assert !link.page? + assert !link.popup? + assert !link.confirm? + assert_equal "show_search", link.action + assert_equal "Search", link.label + assert link.inline? + blank = {} + assert_equal blank, link.html_options + assert_equal :get, link.method + assert_equal :collection, link.type + assert_equal :read, link.crud_type + assert_equal :search_authorized?, link.security_method + end + + def test_setting_link + @config.field_search.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys') + assert_not_equal(@default_link, @config.field_search.link) + end +end diff --git a/test/config/list_test.rb b/test/config/list_test.rb index 1171e6c8e2..057e5e06d2 100644 --- a/test/config/list_test.rb +++ b/test/config/list_test.rb @@ -5,15 +5,41 @@ def setup @config = ActiveScaffold::Config::Core.new :model_stub end + def test_label + I18n.backend.store_translations :en, :active_scaffold => {:resource => {:one => 'Resource', :other => 'Resources'}} + @config.list.label = :resource + assert_equal 'Resources', @config.list.label + label = 'monkeys' + @config.list.label = label + assert_equal label, @config.list.label + end + def test_default_options assert_equal 15, @config.list.per_page + assert_equal 2, @config.list.page_links_window assert_equal '-', @config.list.empty_field_text - assert @config.actions.include?(:search) + assert_equal ', ', @config.list.association_join_text + assert_equal true, @config.list.pagination assert_equal 'search', @config.list.search_partial assert_equal :no_entries, @config.list.no_entries_message assert_equal :filtered, @config.list.filtered_message assert !@config.list.always_show_create assert !@config.list.always_show_search + assert !@config.list.mark_records + assert @config.list.count_includes.nil? + assert_equal 'ModelStubs', @config.list.label + assert @config.list.sorting.sorts_on?(:id) + assert_equal 'ASC', @config.list.sorting.direction_of(:id) + end + + def test_empty_field_text + @config.list.empty_field_text = '(missing)' + assert_equal '(missing)', @config.list.empty_field_text + end + + def test_association_join_text + @config.list.association_join_text = '<br/>' + assert_equal '<br/>', @config.list.association_join_text end def test_no_entries @@ -26,12 +52,44 @@ def test_filtered_message assert_equal 'filtered items', @config.list.filtered_message end + def test_pagination + @config.list.pagination = :infinite + assert_equal :infinite, @config.list.pagination + @config.list.pagination = false + assert !@config.list.pagination + end + + def test_sorting + @config.list.sorting = {:a => :desc} + assert @config.list.sorting.sorts_on?(:a) + assert_equal 'DESC', @config.list.sorting.direction_of(:a) + assert !@config.list.sorting.sorts_on?(:id) + + @config.list.sorting = [{:a => :asc}, {:b => :desc}] + assert @config.list.sorting.sorts_on?(:a) + assert_equal 'ASC', @config.list.sorting.direction_of(:a) + assert @config.list.sorting.sorts_on?(:b) + assert_equal 'DESC', @config.list.sorting.direction_of(:b) + assert !@config.list.sorting.sorts_on?(:id) + end + + def test_mark_records + @config.list.mark_records = true + assert @config.list.mark_records + end + def test_per_page per_page = 35 @config.list.per_page = per_page assert_equal per_page, @config.list.per_page end + def test_page_links_window + page_links_window = 3 + @config.list.page_links_window = page_links_window + assert_equal page_links_window, @config.list.page_links_window + end + def test_always_show_create always_show_create = true @config.list.always_show_create = always_show_create @@ -56,13 +114,6 @@ def test_always_show_search_when_search_is_not_enabled @config.actions.exclude :search assert_equal false, @config.list.always_show_search end - - def test_always_show_search_when_field_search - @config.list.always_show_search = true - @config.actions.swap :search, :live_search - assert @config.list.always_show_search - assert_equal 'live_search', @config.list.search_partial - end def test_always_show_search_when_field_search @config.list.always_show_search = true @@ -70,5 +121,9 @@ def test_always_show_search_when_field_search assert @config.list.always_show_search assert_equal 'field_search', @config.list.search_partial end - + + def test_count_includes + @config.list.count_includes = [:assoc_1, :assoc_2] + assert_equal [:assoc_1, :assoc_2], @config.list.count_includes + end end diff --git a/test/config/nested_test.rb b/test/config/nested_test.rb new file mode 100644 index 0000000000..866195d8af --- /dev/null +++ b/test/config/nested_test.rb @@ -0,0 +1,44 @@ +require File.join(File.dirname(__FILE__), '../test_helper.rb') + +class Config::NestedTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + end + + def test_default_options + assert !@config.nested.shallow_delete + assert_equal 'Add Existing Modelstub', @config.nested.label + end + + def test_label + label = 'nested monkeys' + @config.nested.label = label + assert_equal label, @config.nested.label + I18n.backend.store_translations :en, :active_scaffold => {:create_model => 'Add new %{model}'} + @config.nested.label = :create_model + assert_equal 'Add new Modelstub', @config.nested.label + end + + def test_shallow_delete + @config.nested.shallow_delete = true + assert @config.nested.shallow_delete + end + + def test_add_link + @config.nested.add_link :custom_link, [:assoc_1, :assoc_2] + link = @config.action_links['nested'] + assert_equal 'Custom Link', link.label + assert_equal 'nested', link.action + assert_equal :after, link.position + assert !link.page? + assert !link.popup? + assert !link.confirm? + assert link.inline? + assert_equal 'assoc_1 assoc_2', link.parameters[:associations] + assert_equal 'assoc_1 assoc_2', link.html_options[:class] + assert_equal :get, link.method + assert_equal :member, link.type + assert_equal :read, link.crud_type + assert_equal :nested_authorized?, link.security_method + end +end diff --git a/test/config/search_test.rb b/test/config/search_test.rb new file mode 100644 index 0000000000..5db57a6a5b --- /dev/null +++ b/test/config/search_test.rb @@ -0,0 +1,60 @@ +require File.join(File.dirname(__FILE__), '../test_helper.rb') + +class Config::SearchTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + @default_link = @config.search.link + end + + def teardown + @config.search.link = @default_link + end + + def test_default_options + assert_equal :full, @config.search.text_search + assert !@config.search.live? + assert_equal ' ', @config.search.split_terms + end + + def test_text_search + @config.search.text_search = :start + assert_equal :start, @config.search.text_search + @config.search.text_search = :end + assert_equal :end, @config.search.text_search + @config.search.text_search = false + assert !@config.search.text_search + end + + def test_live + @config.search.live = true + assert @config.search.live? + end + + def test_split_terms + @config.search.split_terms = nil + assert @config.search.split_terms.nil? + @config.search.split_terms = ',' + assert_equal ',', @config.search.split_terms + end + + def test_link_defaults + link = @config.search.link + assert !link.page? + assert !link.popup? + assert !link.confirm? + assert_equal "show_search", link.action + assert_equal "Search", link.label + assert link.inline? + blank = {} + assert_equal blank, link.html_options + assert_equal :get, link.method + assert_equal :collection, link.type + assert_equal :read, link.crud_type + assert_equal :search_authorized?, link.security_method + end + + def test_setting_link + @config.search.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys') + assert_not_equal(@default_link, @config.search.link) + end +end diff --git a/test/config/show_test.rb b/test/config/show_test.rb index ee120b2800..b4beac7fc9 100644 --- a/test/config/show_test.rb +++ b/test/config/show_test.rb @@ -10,10 +10,6 @@ def teardown @config.show.link = @default_link end - def test_default_options - assert_equal 'Show Modelstub', @config.show.label - end - def test_link_defaults link = @config.show.link assert !link.page? @@ -36,8 +32,12 @@ def test_setting_link end def test_label - label = 'create new monkeys' + label = 'show monkeys' @config.show.label = label assert_equal label, @config.show.label + I18n.backend.store_translations :en, :active_scaffold => {:show_model => 'Show %{model}'} + @config.show.label = :show_model + assert_equal 'Show Modelstub', @config.show.label + assert_equal 'Show record', @config.show.label('record') end end diff --git a/test/config/subform_test.rb b/test/config/subform_test.rb new file mode 100644 index 0000000000..aed277f73c --- /dev/null +++ b/test/config/subform_test.rb @@ -0,0 +1,17 @@ +require File.join(File.dirname(__FILE__), '../test_helper.rb') + +class Config::SubformTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + end + + def test_defaults + assert_equal :horizontal, @config.subform.layout + end + + def test_setting_layout + layout = :vertical + @config.subform.layout = layout + assert_equal layout, @config.subform.layout + end +end diff --git a/test/config/update_test.rb b/test/config/update_test.rb index 7a2d0d899d..adccda016a 100644 --- a/test/config/update_test.rb +++ b/test/config/update_test.rb @@ -3,15 +3,38 @@ class Config::UpdateTest < Test::Unit::TestCase def setup @config = ActiveScaffold::Config::Core.new :model_stub - @update = @config.update - - @config._load_action_columns end def test__params_for_columns__returns_all_params + @config._load_action_columns @config.columns[:a].params.add :keep_a, :a_temp - assert @config.columns[:a].params.include?(:keep_a) assert @config.columns[:a].params.include?(:a_temp) end + + def test_default_options + assert !@config.update.persistent + assert !@config.update.nested_links + assert_equal 'Update Modelstub', @config.update.label + end + + def test_persistent + @config.update.persistent = true + assert @config.update.persistent + end + + def test_nested_links + @config.update.nested_links = true + assert @config.update.nested_links + end + + def test_label + label = 'update new monkeys' + @config.update.label = label + assert_equal label, @config.update.label + I18n.backend.store_translations :en, :active_scaffold => {:update_model => 'Update %{model}'} + @config.update.label = :update_model + assert_equal 'Update Modelstub', @config.update.label + assert_equal 'Update record', @config.update.label('record') + end end \ No newline at end of file diff --git a/test/misc/lang_test.rb b/test/misc/lang_test.rb index 07810318be..bcd0600c94 100644 --- a/test/misc/lang_test.rb +++ b/test/misc/lang_test.rb @@ -3,10 +3,9 @@ class LocalizationTest < Test::Unit::TestCase def test_localization - ## - ## test no language specified - ## assert_equal "Dutch", as_(:dutch) + assert_equal "dutch", as_('dutch') + I18n.backend.store_translations :en, :active_scaffold => {:create_model => 'Create %{model}'} assert_equal "Create Test", as_(:create_model, :model => 'Test') end end From 1f8007b4df271565d67f9b57ccc22df66601310d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 15 Sep 2010 17:57:41 +0200 Subject: [PATCH 0676/2024] Core config test --- lib/active_scaffold/config/core.rb | 2 +- test/config/core_test.rb | 58 ++++++++++++++++++++++++++++++ test/config/create_test.rb | 8 ++--- test/config/nested_test.rb | 4 +-- test/config/show_test.rb | 8 ++--- test/config/update_test.rb | 10 +++--- 6 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 test/config/core_test.rb diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index 7f342c9e89..1d8ea196d0 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -91,7 +91,7 @@ def add_sti_create_links? # a generally-applicable name for this ActiveScaffold ... will be used for generating page/section headers attr_writer :label def label(options={}) - as_(@label, options) || model.human_name(options.merge(options[:count].to_i == 1 ? {} : {:default => model.name.pluralize})) + as_(@label, options) || model.human_name(options.merge(:default => options[:count].to_i == 1 ? model.name : model.name.pluralize)) end # STI children models, use an array of model names diff --git a/test/config/core_test.rb b/test/config/core_test.rb new file mode 100644 index 0000000000..c1994d5ee7 --- /dev/null +++ b/test/config/core_test.rb @@ -0,0 +1,58 @@ +require File.join(File.dirname(__FILE__), '../test_helper.rb') + +class Config::CoreTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + end + + def test_default_options + assert !@config.add_sti_create_links? + assert !@config.sti_children + assert_equal [:create, :list, :search, :update, :delete, :show, :nested, :subform], @config.actions.to_a + assert_equal :default, @config.frontend + assert_equal :default, @config.theme + assert_equal 'ModelStub', @config.label(:count => 1) + assert_equal 'ModelStubs', @config.label + end + + def test_add_sti_children + @config.sti_create_links = true + assert !@config.add_sti_create_links? + @config.sti_children = [:a] + assert @config.add_sti_create_links? + end + + def test_sti_children + @config.sti_children = [:a] + assert_equal [:a], @config.sti_children + end + + def test_actions + assert @config.actions.include?(:create) + @config.actions = [:list] + assert !@config.actions.include?(:create) + assert_equal [:list], @config.actions.to_a + end + + def test_form_ui_in_sti + @config.columns << :type + + @config.sti_children = [:model_stub] + @config._configure_sti + assert_equal :select, @config.columns[:type].form_ui + assert_equal [['Modelstub', 'ModelStub']], @config.columns[:type].options[:options] + + @config.columns[:type].form_ui = nil + @config.sti_create_links = true + @config._configure_sti + assert_equal :hidden, @config.columns[:type].form_ui + end + + def test_sti_children_links + @config.sti_children = [:model_stub] + @config.sti_create_links = true + @config.action_links.add @config.create.link + @config._add_sti_create_links + assert_equal 'Create Modelstub', @config.action_links[:new].label + end +end diff --git a/test/config/create_test.rb b/test/config/create_test.rb index 3298c47fb3..0f9f002ab0 100644 --- a/test/config/create_test.rb +++ b/test/config/create_test.rb @@ -13,7 +13,7 @@ def teardown def test_default_options assert !@config.create.persistent assert @config.create.action_after_create.nil? - assert_equal 'Create Modelstub', @config.create.label + assert_equal 'Create ModelStub', @config.create.label end def test_link_defaults @@ -41,9 +41,9 @@ def test_label label = 'create new monkeys' @config.create.label = label assert_equal label, @config.create.label - I18n.backend.store_translations :en, :active_scaffold => {:create_model => 'Create new %{model}'} - @config.create.label = :create_model - assert_equal 'Create new Modelstub', @config.create.label + I18n.backend.store_translations :en, :active_scaffold => {:create_new_model => 'Create new %{model}'} + @config.create.label = :create_new_model + assert_equal 'Create new ModelStub', @config.create.label end def test_persistent diff --git a/test/config/nested_test.rb b/test/config/nested_test.rb index 866195d8af..c4445a990f 100644 --- a/test/config/nested_test.rb +++ b/test/config/nested_test.rb @@ -7,7 +7,7 @@ def setup def test_default_options assert !@config.nested.shallow_delete - assert_equal 'Add Existing Modelstub', @config.nested.label + assert_equal 'Add Existing ModelStub', @config.nested.label end def test_label @@ -16,7 +16,7 @@ def test_label assert_equal label, @config.nested.label I18n.backend.store_translations :en, :active_scaffold => {:create_model => 'Add new %{model}'} @config.nested.label = :create_model - assert_equal 'Add new Modelstub', @config.nested.label + assert_equal 'Add new ModelStub', @config.nested.label end def test_shallow_delete diff --git a/test/config/show_test.rb b/test/config/show_test.rb index b4beac7fc9..59110411d6 100644 --- a/test/config/show_test.rb +++ b/test/config/show_test.rb @@ -35,9 +35,9 @@ def test_label label = 'show monkeys' @config.show.label = label assert_equal label, @config.show.label - I18n.backend.store_translations :en, :active_scaffold => {:show_model => 'Show %{model}'} - @config.show.label = :show_model - assert_equal 'Show Modelstub', @config.show.label - assert_equal 'Show record', @config.show.label('record') + I18n.backend.store_translations :en, :active_scaffold => {:view_model => 'View %{model}'} + @config.show.label = :view_model + assert_equal 'View ModelStub', @config.show.label + assert_equal 'View record', @config.show.label('record') end end diff --git a/test/config/update_test.rb b/test/config/update_test.rb index adccda016a..497227828c 100644 --- a/test/config/update_test.rb +++ b/test/config/update_test.rb @@ -15,7 +15,7 @@ def test__params_for_columns__returns_all_params def test_default_options assert !@config.update.persistent assert !@config.update.nested_links - assert_equal 'Update Modelstub', @config.update.label + assert_equal 'Update ModelStub', @config.update.label end def test_persistent @@ -32,9 +32,9 @@ def test_label label = 'update new monkeys' @config.update.label = label assert_equal label, @config.update.label - I18n.backend.store_translations :en, :active_scaffold => {:update_model => 'Update %{model}'} - @config.update.label = :update_model - assert_equal 'Update Modelstub', @config.update.label - assert_equal 'Update record', @config.update.label('record') + I18n.backend.store_translations :en, :active_scaffold => {:change_model => 'Change %{model}'} + @config.update.label = :change_model + assert_equal 'Change ModelStub', @config.update.label + assert_equal 'Change record', @config.update.label('record') end end \ No newline at end of file From 1d4e96303df36415d49f726904c359f03be8e676 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 16 Sep 2010 09:15:12 +0200 Subject: [PATCH 0677/2024] further localization options for jquery timepicker add on --- .../bridges/date_picker/lib/datepicker_bridge.rb | 7 ++++++- lib/active_scaffold/locale/de.rb | 1 + lib/active_scaffold/locale/fr.rb | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index c5acc8b16b..5941c7fd76 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -89,7 +89,12 @@ def self.date_options def self.datetime_options time_options = I18n.t 'time' - datetime_picker_options = {:ampm => false}.merge(as_(:datetime_picker_options)) + datetime_options = I18n.t 'datetime.prompts' + datetime_picker_options = {:ampm => false, + :hourText => datetime_options[:hour], + :minuteText => datetime_options[:minute], + :secondText => datetime_options[:second], + }.merge(as_(:datetime_picker_options)) js_format = self.date_format_converter(time_options[:formats][:time] || '%H:%M') unless js_format.nil? datetime_picker_options[:timeFormat] = js_format diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 4bfbd8d46c..c77314bbe5 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -87,6 +87,7 @@ :showMonthAfterYear => false, }, :datetime_picker_options => { + :timeText => 'Uhrzeit' }, # error_messages :cant_destroy_record => "%{record} kann nicht gelöscht werden", diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 25c7a64246..85a4bbf6f7 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -87,6 +87,7 @@ :showMonthAfterYear => false, }, :datetime_picker_options => { + :timeText => 'Heure' }, # error_messages :cant_destroy_record => "%{record} can't be destroyed", From 9392a4470490aba1e9dd8df64fa423ac6374c897 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 16 Sep 2010 09:44:51 +0200 Subject: [PATCH 0678/2024] checkbox form_ui by default only when column cannot be null --- lib/active_scaffold/data_structures/column.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 2ad8d6f613..18ab7db664 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -254,7 +254,7 @@ def initialize(name, active_record_class) #:nodoc: @send_form_on_update_column = self.class.send_form_on_update_column @actions_for_association_links = self.class.actions_for_association_links.clone if @association @options = {:format => :i18n_number} if @column.try(:number?) - @form_ui = :checkbox if @column and @column.type == :boolean + @form_ui = :checkbox if @column and @column.type == :boolean and !@column.null @allow_add_existing = true # default all the configurable variables From 97b1004da3ada5af26a2545b058a2753f726cfec Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 16 Sep 2010 14:34:41 +0200 Subject: [PATCH 0679/2024] Bugfix: jquery datepicker form text_fields should use localized date format --- .../bridges/date_picker/lib/datepicker_bridge.rb | 12 ++++++++++++ lib/active_scaffold/bridges/shared/date_bridge.rb | 5 +---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 5941c7fd76..24f27ef05f 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -131,6 +131,16 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current text_field_tag("#{options[:name]}[#{name}]", value ? l(value) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) end end + + module FormColumnHelpers + def active_scaffold_input_date_picker(column, options) + options = active_scaffold_input_text_options(options) + value = controller.class.condition_value_for_datetime(@record.send(column.name), column.column.type == :date ? :to_date : :to_time) + options[:value] = (value ? l(value) : nil) + Rails.logger.info("column.name: #{column.name}: #{options[:value]}") + text_field(:record, column.name, options.merge(column.options)) + end + end end end end @@ -139,6 +149,8 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current include ActiveScaffold::Bridges::Shared::DateBridge::SearchColumnHelpers alias_method :active_scaffold_search_datetime, :active_scaffold_search_date_bridge include ActiveScaffold::Bridges::DatePickerBridge::SearchColumnHelpers + include ActiveScaffold::Bridges::DatePickerBridge::FormColumnHelpers + alias_method :active_scaffold_input_datetime_picker, :active_scaffold_input_date_picker end ActiveScaffold::Finder::ClassMethods.module_eval do include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index dbabb4a634..83031ada59 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -48,13 +48,10 @@ def active_scaffold_search_date_bridge_range_tag(column, options, current_search end def column_datetime?(column) - (!column.column.nil? && column.column.type == :datetime) + (!column.column.nil? && [:datetime, :time].include?(column.column.type)) end end - - - module Finder module ClassMethods def condition_for_date_bridge_type(column, value, like_pattern) From b9391b77aab6154e9b61ecce0b48c4f2eaca3733 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 16 Sep 2010 16:03:08 +0200 Subject: [PATCH 0680/2024] Bugfix: setting column options should nt break jquery date/time controls --- .../date_picker/lib/datepicker_bridge.rb | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 24f27ef05f..d8cf955565 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -19,14 +19,7 @@ def initialize_with_date_picker(model_id) # automatically set the forum_ui to a file column date_picker_fields.each{|field| col_config = self.columns[field[:name]] - form_ui = (field[:type] == :date ? :date_picker : :datetime_picker) - - col_config.form_ui = form_ui - if col_config.options[:class] - col_config.options[:class] += " #{form_ui.to_s} text-input" - else - col_config.options[:class] = "#{form_ui.to_s} text-input" - end + col_config.form_ui = (field[:type] == :date ? :date_picker : :datetime_picker) } end @@ -127,18 +120,19 @@ module SearchColumnHelpers def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) value = controller.class.condition_value_for_datetime(current_search[name], column.column.type == :date ? :to_date : :to_time) options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date, :value) - options[:class] << " #{column.options[:class]}" if column.options[:class] + options = active_scaffold_input_text_options(options.merge(column.options)) + options[:class] << " #{column.search_ui.to_s}" text_field_tag("#{options[:name]}[#{name}]", value ? l(value) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) end end module FormColumnHelpers def active_scaffold_input_date_picker(column, options) - options = active_scaffold_input_text_options(options) + options = active_scaffold_input_text_options(options.merge(column.options)) + options[:class] << " #{column.form_ui.to_s}" value = controller.class.condition_value_for_datetime(@record.send(column.name), column.column.type == :date ? :to_date : :to_time) options[:value] = (value ? l(value) : nil) - Rails.logger.info("column.name: #{column.name}: #{options[:value]}") - text_field(:record, column.name, options.merge(column.options)) + text_field(:record, column.name, options) end end end @@ -147,7 +141,8 @@ def active_scaffold_input_date_picker(column, options) ActionView::Base.class_eval do include ActiveScaffold::Bridges::Shared::DateBridge::SearchColumnHelpers - alias_method :active_scaffold_search_datetime, :active_scaffold_search_date_bridge + alias_method :active_scaffold_search_date_picker, :active_scaffold_search_date_bridge + alias_method :active_scaffold_search_datetime_picker, :active_scaffold_search_date_bridge include ActiveScaffold::Bridges::DatePickerBridge::SearchColumnHelpers include ActiveScaffold::Bridges::DatePickerBridge::FormColumnHelpers alias_method :active_scaffold_input_datetime_picker, :active_scaffold_input_date_picker From 05a89c57ee2fe63bd021d5b278bff6e90cb18476 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 17 Sep 2010 10:30:10 +0200 Subject: [PATCH 0681/2024] jquery: time columns use time.formats.default as default time format --- .../date_picker/lib/datepicker_bridge.rb | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index d8cf955565..ff7474902a 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -43,7 +43,7 @@ module DatePickerBridge '%H' => 'hh', # options ampm => false '%I' => 'hh', # options ampm => true '%M' => 'mm', - '%p' => 'TT', + '%p' => 'tt', '%S' => 'ss' } @@ -81,17 +81,18 @@ def self.date_options end def self.datetime_options - time_options = I18n.t 'time' + rails_time_format = I18n.t 'time.formats.default' datetime_options = I18n.t 'datetime.prompts' datetime_picker_options = {:ampm => false, :hourText => datetime_options[:hour], :minuteText => datetime_options[:minute], :secondText => datetime_options[:second], }.merge(as_(:datetime_picker_options)) - js_format = self.date_format_converter(time_options[:formats][:time] || '%H:%M') - unless js_format.nil? - datetime_picker_options[:timeFormat] = js_format - datetime_picker_options[:ampm] = true if time_options[:formats][:time].present? && time_options[:formats][:time].include?('%I') + date_format, time_format = self.split_datetime_format(self.date_format_converter(rails_time_format)) + datetime_picker_options[:dateFormat] = date_format unless date_format.nil? + unless time_format.nil? + datetime_picker_options[:timeFormat] = time_format + datetime_picker_options[:ampm] = true if rails_time_format.include?('%I') end datetime_picker_options end @@ -116,6 +117,21 @@ def self.date_format_converter(rails_format) end end + def self.split_datetime_format(datetime_format) + date_format = datetime_format + time_format = nil + time_start_indicators = %w{hh mm tt ss} + unless datetime_format.nil? + start_indicator = time_start_indicators.detect {|indicator| datetime_format.include?(indicator)} + unless start_indicator.nil? + pos_time_format = datetime_format.index(start_indicator) + date_format = datetime_format.to(pos_time_format - 1) + time_format = datetime_format.from(pos_time_format) + end + end + return date_format, time_format + end + module SearchColumnHelpers def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) value = controller.class.condition_value_for_datetime(current_search[name], column.column.type == :date ? :to_date : :to_time) From dae2cf8af580641ce6d65e90e19693fed97215f1 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 17 Sep 2010 15:42:11 +0200 Subject: [PATCH 0682/2024] jquery datepicker enable format specification per column ie: columns[]:founded_on].options = {:format => :short} --- .../date_picker/lib/datepicker_bridge.rb | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index ff7474902a..569539c34b 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -36,6 +36,7 @@ module DatePickerBridge '%b' => 'M', '$B' => 'MM', '%d' => 'dd', + '%e' => 'd', '%j' => 'oo', '%m' => 'mm', '%y' => 'y', @@ -45,7 +46,7 @@ module DatePickerBridge '%M' => 'mm', '%p' => 'tt', '%S' => 'ss' - } + } def self.localization(js_file) localization = "jQuery(function($){ @@ -75,7 +76,7 @@ def self.date_options :changeYear => true, :changeMonth => true, }.merge(as_(:date_picker_options)) - js_format = self.date_format_converter(date_options[:formats][:default]) + js_format = self.to_datepicker_format(date_options[:formats][:default]) date_picker_options[:dateFormat] = js_format unless js_format.nil? date_picker_options end @@ -88,7 +89,7 @@ def self.datetime_options :minuteText => datetime_options[:minute], :secondText => datetime_options[:second], }.merge(as_(:datetime_picker_options)) - date_format, time_format = self.split_datetime_format(self.date_format_converter(rails_time_format)) + date_format, time_format = self.split_datetime_format(self.to_datepicker_format(rails_time_format)) datetime_picker_options[:dateFormat] = date_format unless date_format.nil? unless time_format.nil? datetime_picker_options[:timeFormat] = time_format @@ -103,7 +104,7 @@ def self.prepend_js_file(js_file, prepend) File.open(js_file, 'wb') { |file| file.write(content) } end - def self.date_format_converter(rails_format) + def self.to_datepicker_format(rails_format) return nil if rails_format.nil? if rails_format =~ /%[cUWwxXZ]/ Rails.logger.warn("AS DatePickerBridge: Can t convert rails date format: #{rails_format} to jquery datepicker format. Options %c, %U, %W, %w, %x %X are not supported by datepicker]") @@ -132,13 +133,39 @@ def self.split_datetime_format(datetime_format) return date_format, time_format end + module DatepickerColumnHelpers + def datepicker_split_datetime_format(datetime_format) + ActiveScaffold::Bridges::DatePickerBridge.datepicker_split_datetime_format(datetime_format) + end + + def to_datepicker_format(rails_format) + ActiveScaffold::Bridges::DatePickerBridge.to_datepicker_format(rails_format) + end + + def datepicker_format_options(column, format, options) + if column.form_ui == :date_picker + js_format = to_datepicker_format(I18n.t("date.formats.#{format}")) + options['date:dateFormat'] = js_format unless js_format.nil? + else + rails_time_format = I18n.t("time.formats.#{format}") + date_format, time_format = self.split_datetime_format(self.to_datepicker_format(rails_time_format)) + unless time_format.nil? + datetime_picker_options['time:timeFormat'] = time_format + datetime_picker_options['time:ampm'] = true if rails_time_format.include?('%I') + end + end unless format == :default + end + end + module SearchColumnHelpers def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) - value = controller.class.condition_value_for_datetime(current_search[name], column.column.type == :date ? :to_date : :to_time) + value = controller.class.condition_value_for_datetime(current_search[name], column.form_ui == :date_picker ? :to_date : :to_time) options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date, :value) options = active_scaffold_input_text_options(options.merge(column.options)) options[:class] << " #{column.search_ui.to_s}" - text_field_tag("#{options[:name]}[#{name}]", value ? l(value) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) + format = options.delete(:format) || :default + datepicker_format_options(column, format, options) + text_field_tag("#{options[:name]}[#{name}]", value ? l(value, :format => format) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) end end @@ -146,8 +173,10 @@ module FormColumnHelpers def active_scaffold_input_date_picker(column, options) options = active_scaffold_input_text_options(options.merge(column.options)) options[:class] << " #{column.form_ui.to_s}" - value = controller.class.condition_value_for_datetime(@record.send(column.name), column.column.type == :date ? :to_date : :to_time) - options[:value] = (value ? l(value) : nil) + value = controller.class.condition_value_for_datetime(@record.send(column.name), column.form_ui == :date_picker ? :to_date : :to_time) + format = options.delete(:format) || :default + datepicker_format_options(column, format, options) + options[:value] = (value ? l(value, :format => format) : nil) text_field(:record, column.name, options) end end @@ -162,6 +191,7 @@ def active_scaffold_input_date_picker(column, options) include ActiveScaffold::Bridges::DatePickerBridge::SearchColumnHelpers include ActiveScaffold::Bridges::DatePickerBridge::FormColumnHelpers alias_method :active_scaffold_input_datetime_picker, :active_scaffold_input_date_picker + include ActiveScaffold::Bridges::DatePickerBridge::DatepickerColumnHelpers end ActiveScaffold::Finder::ClassMethods.module_eval do include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods From 4330d43e4425e76042cc6f2c1af70c8b0b93a591 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 17 Sep 2010 16:55:00 +0200 Subject: [PATCH 0683/2024] jquery datetime picker enable column specific configuration --- .../bridges/date_picker/lib/datepicker_bridge.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 569539c34b..9e56f95478 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -135,7 +135,7 @@ def self.split_datetime_format(datetime_format) module DatepickerColumnHelpers def datepicker_split_datetime_format(datetime_format) - ActiveScaffold::Bridges::DatePickerBridge.datepicker_split_datetime_format(datetime_format) + ActiveScaffold::Bridges::DatePickerBridge.split_datetime_format(datetime_format) end def to_datepicker_format(rails_format) @@ -148,10 +148,11 @@ def datepicker_format_options(column, format, options) options['date:dateFormat'] = js_format unless js_format.nil? else rails_time_format = I18n.t("time.formats.#{format}") - date_format, time_format = self.split_datetime_format(self.to_datepicker_format(rails_time_format)) + date_format, time_format = datepicker_split_datetime_format(self.to_datepicker_format(rails_time_format)) + options['date:dateFormat'] = date_format unless date_format.nil? unless time_format.nil? - datetime_picker_options['time:timeFormat'] = time_format - datetime_picker_options['time:ampm'] = true if rails_time_format.include?('%I') + options['time:timeFormat'] = time_format + options['time:ampm'] = true if rails_time_format.include?('%I') end end unless format == :default end From 60f521c405e3fdab6d38b7049ab09410c6b00681 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 21 Sep 2010 10:41:45 +0200 Subject: [PATCH 0684/2024] Same order for collection action links in nested scaffold --- frontends/default/stylesheets/stylesheet.css | 4 ---- 1 file changed, 4 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index de55302c71..29cef1dbdf 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -91,10 +91,6 @@ background-position: 1px 50%; background-repeat: no-repeat; } -.view .active-scaffold-header div.actions a { -float: left; -} - .blue-theme .active-scaffold-header div.actions a { color: #fff; } From d9c0e89491a2b16f304862e2c174bb7dd98fcb80 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 22 Sep 2010 09:44:04 +0200 Subject: [PATCH 0685/2024] Note about changelog not updated --- CHANGELOG | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 635c051fef..a6edd9a94e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +This file is not maintained, many more changes were added after 1.2RC1 + = 1.2RC1 == FEATURES @@ -149,4 +151,4 @@ * fixes for edge rails compatibility * small improvements for localization accessibility * minor string renaming (will affect localization tables, though) -* closed a few XSS holes \ No newline at end of file +* closed a few XSS holes From 8597eecbf6e14e895531e043c3ad9c281ee7f73f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 22 Sep 2010 16:38:40 +0200 Subject: [PATCH 0686/2024] collect member action_links once --- frontends/default/views/_list.html.erb | 2 +- frontends/default/views/_list_actions.html.erb | 2 +- frontends/default/views/_list_record.html.erb | 4 ++-- lib/active_scaffold/data_structures/action_links.rb | 6 ++++++ lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index b26f3f2a6e..89102f2b1b 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -8,7 +8,7 @@ <%= render :partial => 'list_messages', :locals => {:columns => columns} %> <tbody class="records" id="<%= active_scaffold_tbody_id %>"> <% if !@records.empty? -%> - <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false, :columns => columns} %> + <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false, :columns => columns, :action_links => active_scaffold_config.action_links.collect_by_type(:member)} %> <% end -%> <% if columns.any? {|c| c.calculation?} -%> <%= render :partial => 'list_calculations', :locals => {:columns => columns} %> diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 4158403242..d6ccc88cbc 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -4,7 +4,7 @@ <td class="indicator-container"> <%= loading_indicator_tag(:action => :record, :id => record.id) %> </td> - <% action_links.each :member do |link| -%> + <% action_links.each do |link| -%> <% next if skip_action_link(link, record) -%> <td> <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}) %> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 1e6555d84e..6f3bb8a5ea 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -4,11 +4,11 @@ columns ||= active_scaffold_config.list.columns.collect_visible tr_class = cycle("", "even-record") tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class url_options = params_for(:action => :list, :id => record.id) -action_links = active_scaffold_config.action_links +action_links ||= active_scaffold_config.action_links.collect_by_type(:member) -%> <tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get, :escape => false)).html_safe %>"> <%= render :partial => 'list_record_columns', :locals => {:record => record, :columns => columns} %> - <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options, :action_links => action_links} if action_links.any? {|link| link.type == :member } %> + <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options, :action_links => action_links} unless action_links.empty? %> <%= render_nested_view(action_links, url_options, record) unless @nested_auto_open.nil? %> </tr> diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 9c1242e2e2..fd6d21d113 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -37,6 +37,12 @@ def each(type = nil) yield item } end + + def collect_by_type(type = nil) + links = [] + each(type) {|link| links << link} + links + end def empty? @set.size == 0 diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index eb7ad5a640..ba61e3f7d7 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -347,7 +347,7 @@ def column_heading_value(column, sorting, sort_direction) def render_nested_view(action_links, url_options, record) rendered = [] - action_links.each(:member) do |link| + action_links.each do |link| if link.nested_link? && @nested_auto_open[link.column.name] && @records.length <= @nested_auto_open[link.column.name] && respond_to?(:render_component) link_url_options = {:adapter => '_list_inline_adapter', :format => :js}.merge(action_link_url_options(link, url_options, record, options = {:reuse_eid => true})) link_id = get_action_link_id(link_url_options, record, link.column) From 2eb379a3fedc070c45a3ceee7ed37ea0b0e8f0b8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 22 Sep 2010 16:44:42 +0200 Subject: [PATCH 0687/2024] collect collection action_links once --- frontends/default/views/_list_header.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index 39693ebc51..8420985dff 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -1,11 +1,11 @@ -<% if active_scaffold_config.action_links.any? { |link| link.type == :collection } -%> +<% action_links = active_scaffold_config.action_links.collect_by_type(:collection) + unless action_links.empty? -%> <div class="actions"> <% new_params = params_for %> - <% active_scaffold_config.action_links.each :collection do |link| -%> + <% action_links.each do |link| -%> <% next if skip_action_link(link) -%> <%= render_action_link(link, new_params) -%> <% end -%> - <%= loading_indicator_tag(:action => :table) %> </div> <% end %> From 8e141c163a1ad805e756942539352beb25062345 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 23 Sep 2010 08:32:17 +0200 Subject: [PATCH 0688/2024] Patch ActiveRecord Bug: Model.offset(1).limit(1) --- lib/extensions/active_record_offset.rb | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 lib/extensions/active_record_offset.rb diff --git a/lib/extensions/active_record_offset.rb b/lib/extensions/active_record_offset.rb new file mode 100644 index 0000000000..a61eab2816 --- /dev/null +++ b/lib/extensions/active_record_offset.rb @@ -0,0 +1,4 @@ +# Bugfix: Team.offset(1).limit(1) throws an error +ActiveRecord::Base.instance_eval do + delegate :offset, :to => :scoped +end From 73a93f9b4dade515fea9250c961f25d75199e10a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 23 Sep 2010 10:21:54 +0200 Subject: [PATCH 0689/2024] next try to fix ActiveRecord offset issue --- lib/extensions/active_record_offset.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/extensions/active_record_offset.rb b/lib/extensions/active_record_offset.rb index a61eab2816..4bbd6d9779 100644 --- a/lib/extensions/active_record_offset.rb +++ b/lib/extensions/active_record_offset.rb @@ -1,4 +1,12 @@ # Bugfix: Team.offset(1).limit(1) throws an error ActiveRecord::Base.instance_eval do - delegate :offset, :to => :scoped + def offset(*args, &block) + scoped.__send__(:offset, *args, &block) + rescue NoMethodError + if scoped.nil? + 'depends on :allow_nil' + else + raise + end + end end From d9884a6c4dd002415e689656f2c242e5f04877bb Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 23 Sep 2010 10:41:13 +0200 Subject: [PATCH 0690/2024] Bugfix: Exclude TextFieldWithExample for jquery cause not ported so far --- frontends/default/views/_search.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index a17609d316..6eed0e74b7 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -15,7 +15,9 @@ options['data-loading'] = true unless live_search <script type="text/javascript"> //<![CDATA[ +<% if ActiveScaffold.js_framework == :prototype %> new TextFieldWithExample('<%= search_input_id %>', '<%= as_(live_search ? :live_search : :search_terms) %>', {focus: true}); +<% end -%> <% if live_search -%> $('<%= search_input_id %>').next().hide(); new Form.Element.DelayedObserver('<%= search_input_id %>', 0.5, function(element, value) { From cbe6803b309a9ae82ecfbde09d55757df3c80bd7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 23 Sep 2010 10:42:49 +0200 Subject: [PATCH 0691/2024] bugfix: exclude live search code for jquery, cause not supported so far --- frontends/default/views/_search.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index 6eed0e74b7..b7dee48690 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -18,7 +18,7 @@ options['data-loading'] = true unless live_search <% if ActiveScaffold.js_framework == :prototype %> new TextFieldWithExample('<%= search_input_id %>', '<%= as_(live_search ? :live_search : :search_terms) %>', {focus: true}); <% end -%> -<% if live_search -%> +<% if live_search && ActiveScaffold.js_framework == :prototype -%> $('<%= search_input_id %>').next().hide(); new Form.Element.DelayedObserver('<%= search_input_id %>', 0.5, function(element, value) { if (!$(element.id)) return false; // because the element may have been destroyed From e09acdfc11f82cbaaaef57c242758e7257d4db71 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 23 Sep 2010 12:06:34 +0200 Subject: [PATCH 0692/2024] active record error localization was removed in rails 3.0. added them to as localization --- lib/active_scaffold/helpers/view_helpers.rb | 35 ++++++++++----------- lib/active_scaffold/locale/de.rb | 9 ++++++ lib/active_scaffold/locale/en.rb | 9 ++++++ lib/active_scaffold/locale/fr.rb | 9 ++++++ 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 2ea1353fc2..1d93713b2d 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -280,28 +280,27 @@ def error_messages_for(*params) end options[:object_name] ||= params.first - I18n.with_options :locale => options[:locale], :scope => [:activerecord, :errors, :template] do |locale| - header_message = if options.include?(:header_message) - options[:header_message] - else - locale.t :header, :count => count, :model => options[:object_name].to_s.gsub('_', ' ') - end + header_message = if options.include?(:header_message) + options[:header_message] + else + as_('errors.template.header', :count => count, :model => options[:object_name].to_s.gsub('_', ' ')) + end - message = options.include?(:message) ? options[:message] : locale.t(:body) + message = options.include?(:message) ? options[:message] : as_('errors.template.body') - error_messages = objects.sum do |object| - object.errors.full_messages.map do |msg| - content_tag(:li, msg) - end - end.join.html_safe + error_messages = objects.sum do |object| + object.errors.full_messages.map do |msg| + content_tag(:li, msg) + end + end.join.html_safe - contents = '' - contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank? - contents << content_tag(:p, message) unless message.blank? - contents << content_tag(:ul, error_messages) + contents = '' + contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank? + contents << content_tag(:p, message) unless message.blank? + contents << content_tag(:ul, error_messages) + + content_tag(:div, contents.html_safe, html) - content_tag(:div, contents.html_safe, html) - end else '' end diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index c77314bbe5..5db12dbf37 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -89,6 +89,15 @@ :datetime_picker_options => { :timeText => 'Uhrzeit' }, + :errors => { + :template => { + :header => { + :one => "Konnte {{model}} nicht speichern: ein Fehler.", + :other => "Konnte {{model}} nicht speichern: {{count}} Fehler." + }, + :body => "Bitte überprüfen Sie die folgenden Felder:" + } + }, # error_messages :cant_destroy_record => "%{record} kann nicht gelöscht werden", :internal_error => 'Fehler bei der Verarbeitung (code 500, Interner Fehler)', diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 5ac3df9e77..5a643dd647 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -94,6 +94,15 @@ }, :datetime_picker_options => { }, + :errors => { + :template => { + :header => { + :one => "1 error prohibited this {{model}} from being saved.", + :other => "{{count}} errors prohibited this {{model}} from being saved" + }, + :body => "There were problems with the following fields:" + } + }, # error_messages :cant_destroy_record => "%{record} can't be destroyed", :internal_error => 'Request Failed (code 500, Internal Error)', diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 85a4bbf6f7..41d741e4ef 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -89,6 +89,15 @@ :datetime_picker_options => { :timeText => 'Heure' }, + :errors => { + :template => { + :header => { + :one => "1 error prohibited this {{model}} from being saved.", + :other => "{{count}} errors prohibited this {{model}} from being saved" + }, + :body => "There were problems with the following fields:" + } + }, # error_messages :cant_destroy_record => "%{record} can't be destroyed", :internal_error => 'Erreur de la requête (code 500, Erreur interne)', From 739dabf704c9ce1b331f22722326e32e37fe4280 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 23 Sep 2010 13:07:23 +0200 Subject: [PATCH 0693/2024] Updating stylesheets in test --- .../public/stylesheets/active_scaffold/default/stylesheet.css | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css index de55302c71..29cef1dbdf 100644 --- a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +++ b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css @@ -91,10 +91,6 @@ background-position: 1px 50%; background-repeat: no-repeat; } -.view .active-scaffold-header div.actions a { -float: left; -} - .blue-theme .active-scaffold-header div.actions a { color: #fff; } From 6da6e0127e2d0a01e3c03f0c600f721965d2dd7d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 23 Sep 2010 13:59:06 +0200 Subject: [PATCH 0694/2024] get live search up and running for jquery --- .../javascripts/jquery/active_scaffold.js | 59 +++++++++++++++++++ frontends/default/views/_search.html.erb | 9 ++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 251a32f756..fdbaddfa85 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -303,6 +303,65 @@ $(document).ready(function() { }; })(); +/* + jQuery delayed observer + (c) 2007 - Maxime Haineault (max@centdessin.com) + + Special thanks to Stephen Goguen & Tane Piper. + + Slight modifications by Elliot Winkler +*/ + +if (typeof(jQuery.fn.delayedObserver) === 'undefined') { + (function() { + var delayedObserverStack = []; + var observed; + + function delayedObserverCallback(stackPos) { + observed = delayedObserverStack[stackPos]; + if (observed.timer) return; + + observed.timer = setTimeout(function(){ + observed.timer = null; + observed.callback(observed.obj.val(), observed.obj); + }, observed.delay * 1000); + + observed.oldVal = observed.obj.val(); + } + + // going by + // <http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx> + // I think these codes only work when using keyup or keydown + function isNonPrintableKey(event) { + var code = event.keyCode; + return ( + event.metaKey || + (code >= 9 && code <= 16) || (code >= 27 && code <= 40) || (code >= 91 && code <= 93) || (code >= 112 && code <= 145) + ); + } + + jQuery.fn.extend({ + delayedObserver:function(delay, callback){ + $this = $(this); + + delayedObserverStack.push({ + obj: $this, timer: null, delay: delay, + oldVal: $this.val(), callback: callback + }); + + stackPos = delayedObserverStack.length-1; + + $this.keyup(function(event) { + if (isNonPrintableKey(event)) return; + observed = delayedObserverStack[stackPos]; + if (observed.obj.val() == observed.obj.oldVal) return; + else delayedObserverCallback(stackPos); + }); + } + }); + })(); +}; + /* * Simple utility methods diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index b7dee48690..7387fc9dd7 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -7,7 +7,7 @@ options = {:id => search_form_id, :method => :get} options['data-loading'] = true unless live_search form_tag url_options, options %> - <%= text_field_tag :search, search_params, :class => 'text-input', :id => search_input_id, :size => 50, :autocompleted => :off %> + <%= text_field_tag :search, search_params, :class => 'text-input', :id => search_input_id, :size => 50, :autocomplete => :off %> <%= submit_tag as_(:search), :class => "submit" %> <%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel', :remote => true %> <%= loading_indicator_tag(:action => :search) %> @@ -19,11 +19,16 @@ options['data-loading'] = true unless live_search new TextFieldWithExample('<%= search_input_id %>', '<%= as_(live_search ? :live_search : :search_terms) %>', {focus: true}); <% end -%> <% if live_search && ActiveScaffold.js_framework == :prototype -%> - $('<%= search_input_id %>').next().hide(); + $(<%= search_input_id.to_json.html_safe %>).next().hide(); new Form.Element.DelayedObserver('<%= search_input_id %>', 0.5, function(element, value) { if (!$(element.id)) return false; // because the element may have been destroyed $(element).next().click(); }); +<% elsif live_search && ActiveScaffold.js_framework == :jquery %> + $(<%= "##{search_input_id}".to_json.html_safe %>).next().hide(); + $(<%= "##{search_input_id}".to_json.html_safe %>).delayedObserver(0.5, function() { + $(<%= "##{search_input_id}".to_json.html_safe %>).parent().trigger("submit");}); <% end -%> +ActiveScaffold.focus_first_element_of_form('<%= search_form_id %>'); //]]> </script> From f6872bc1d68b06228e7bc3d4dae5c69a998fe45a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 23 Sep 2010 14:14:56 +0200 Subject: [PATCH 0695/2024] Bugfix: use Activescaffold form control css styles --- lib/active_scaffold/bridges/paperclip/lib/form_ui.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb b/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb index 025f1b694b..be0b4a5542 100644 --- a/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb +++ b/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb @@ -2,6 +2,7 @@ module ActiveScaffold module Helpers module FormColumnHelpers def active_scaffold_input_paperclip(column, options) + options = active_scaffold_input_text_options(options) input = file_field(:record, column.name, options) paperclip = @record.send("#{column.name}") if paperclip.file? From 1a9b8f206870159f577c4659d8ebb2e405ffa259 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 23 Sep 2010 15:19:24 +0200 Subject: [PATCH 0696/2024] Bugfix: same order of table_actions in nested views --- frontends/default/views/_list_header.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index 8420985dff..5fe805e06e 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -2,7 +2,7 @@ unless action_links.empty? -%> <div class="actions"> <% new_params = params_for %> - <% action_links.each do |link| -%> + <% action_links.send(nested.nil? ? :each : :reverse_each) do |link| -%> <% next if skip_action_link(link) -%> <%= render_action_link(link, new_params) -%> <% end -%> From eb4bec5d858dcd7d27d99daee4832a369e9b579e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 23 Sep 2010 18:06:36 +0200 Subject: [PATCH 0697/2024] Add deprecation warning about nested.add_link multiple associations --- lib/active_scaffold/config/nested.rb | 15 ++++++++++++--- test/config/nested_test.rb | 24 +++++++++++++++++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index 233ae5f45f..bf1bbddd27 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -18,11 +18,20 @@ def initialize(core_config) attr_accessor :shallow_delete # Add a nested ActionLink - def add_link(label, models, options = {}) + def add_link(label, association, options = {}) + if association.is_a? Array + msg = "config.nested.add_link with multiple associations is not already supported. " + if association.size == 1 + ::ActiveSupport::Deprecation.warn(msg + "Remove array", caller) + else + ::ActiveSupport::Deprecation.warn(msg + "The first model will be used", caller) + end + association = association.first + end options.reverse_merge! :security_method => :nested_authorized?, :position => :after - options.merge! :label => label, :type => :member, :parameters => {:associations => models.join(' ')} + options.merge! :label => label, :type => :member, :parameters => {:associations => association} options[:html_options] ||= {} - options[:html_options][:class] = [options[:html_options][:class], models.join(' ')].compact.join(' ') + options[:html_options][:class] = [options[:html_options][:class], association].compact.join(' ') @core.action_links.add('nested', options) end diff --git a/test/config/nested_test.rb b/test/config/nested_test.rb index c4445a990f..0bc54a2209 100644 --- a/test/config/nested_test.rb +++ b/test/config/nested_test.rb @@ -24,8 +24,26 @@ def test_shallow_delete assert @config.nested.shallow_delete end + def test_add_link_deprecation + ActiveSupport::Deprecation.silence { @config.nested.add_link :custom_link, [:assoc_1, :assoc_2] } + link = @config.action_links['nested'] + assert_equal 'Custom Link', link.label + assert_equal 'nested', link.action + assert_equal :after, link.position + assert !link.page? + assert !link.popup? + assert !link.confirm? + assert link.inline? + assert_equal :assoc_1, link.parameters[:associations] + assert_equal 'assoc_1', link.html_options[:class] + assert_equal :get, link.method + assert_equal :member, link.type + assert_equal :read, link.crud_type + assert_equal :nested_authorized?, link.security_method + end + def test_add_link - @config.nested.add_link :custom_link, [:assoc_1, :assoc_2] + @config.nested.add_link :custom_link, :assoc_1 link = @config.action_links['nested'] assert_equal 'Custom Link', link.label assert_equal 'nested', link.action @@ -34,8 +52,8 @@ def test_add_link assert !link.popup? assert !link.confirm? assert link.inline? - assert_equal 'assoc_1 assoc_2', link.parameters[:associations] - assert_equal 'assoc_1 assoc_2', link.html_options[:class] + assert_equal :assoc_1, link.parameters[:associations] + assert_equal 'assoc_1', link.html_options[:class] assert_equal :get, link.method assert_equal :member, link.type assert_equal :read, link.crud_type From 0132a721df92cd3539c0de1eec95ec2e898cdbd3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 24 Sep 2010 08:46:54 +0200 Subject: [PATCH 0698/2024] %z format option is not supported by jquery datetimepicker --- .../bridges/date_picker/lib/datepicker_bridge.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 9e56f95478..e6425d2646 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -106,8 +106,8 @@ def self.prepend_js_file(js_file, prepend) def self.to_datepicker_format(rails_format) return nil if rails_format.nil? - if rails_format =~ /%[cUWwxXZ]/ - Rails.logger.warn("AS DatePickerBridge: Can t convert rails date format: #{rails_format} to jquery datepicker format. Options %c, %U, %W, %w, %x %X are not supported by datepicker]") + if rails_format =~ /%[cUWwxXZz]/ + Rails.logger.warn("AS DatePickerBridge: Can t convert rails date format: #{rails_format} to jquery datepicker format. Options %c, %U, %W, %w, %x %X, %z, %Z are not supported by datepicker]") nil else js_format = rails_format.dup From 7efae75462a5b1e42252f6f3bae723e9dae5750f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 24 Sep 2010 11:20:52 +0200 Subject: [PATCH 0699/2024] rudimentary support for scopes which represent an association eg ancestry plugin --- lib/active_scaffold.rb | 7 +++ lib/active_scaffold/actions/nested.rb | 10 ++-- lib/active_scaffold/config/nested.rb | 7 +++ .../data_structures/action_link.rb | 2 +- .../data_structures/nested_info.rb | 52 +++++++++++++++---- .../helpers/list_column_helpers.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 8 ++- 7 files changed, 69 insertions(+), 19 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 2b5e8f9470..7192041296 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -146,6 +146,13 @@ def link_for_association(column, options = {}) end end end + + def link_for_association_as_scope(scope, options = {}) + options.reverse_merge! :label => scope, :position => :after, :type => :member, :controller => controller_path + options[:parameters] ||= {} + options[:parameters].reverse_merge! :parent_model => active_scaffold_config.model.to_s, :named_scope => scope + ActiveScaffold::DataStructures::ActionLink.new('index', options) + end def add_active_scaffold_path(path) @active_scaffold_paths = nil # Force active_scaffold_paths to rebuild diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 5d04bf81fe..5f6a1215e1 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -29,12 +29,12 @@ def nested? end def set_nested - if params[:parent_model] && params[:association] && params[:assoc_id] + if params[:parent_model] && ((params[:association] && params[:assoc_id]) || params[:named_scope]) @nested = nil active_scaffold_session_storage[:nested] = {:parent_model => params[:parent_model].constantize, - :name => params[:association].to_sym, + :name => (params[:association] || params[:named_scope]).to_sym, :parent_id => params[:assoc_id]} - params.delete_if {|key, value| [:parent_model, :association, :assoc_id].include? key.to_sym} + params.delete_if {|key, value| [:parent_model, :association, :named_scope, :assoc_id].include? key.to_sym} end end @@ -74,8 +74,10 @@ def include_habtm_actions end def beginning_of_chain - if nested? && nested.association.collection? + if nested? && nested.association && nested.association.collection? nested.parent_scope.send(nested.association.name) + elsif nested? && nested.scope + nested.parent_scope.send(nested.scope) else active_scaffold_config.model end diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index 9141a75b45..c343be1894 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -23,8 +23,15 @@ def add_link(attribute, options = {}) options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) action_link = @core.link_for_association(column, options) @core.action_links.add(action_link) unless action_link.nil? + else + end end + + def add_scoped_link(named_scope, options = {}) + action_link = @core.link_for_association_as_scope(named_scope.to_sym, options) + @core.action_links.add(action_link) unless action_link.nil? + end # the label for this Nested action. used for the header. attr_writer :label diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index c15198f9c2..9f80b93471 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -151,7 +151,7 @@ def position # indicates that this a nested_link def nested_link? - @column + @column || (parameters && parameters[:named_scope]) end # Internal use: generated eid for this action_link diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 680c1a0bbc..d1a64297f1 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -4,18 +4,21 @@ def self.get(model, session_storage) if session_storage[:nested].nil? nil else - ActiveScaffold::DataStructures::NestedInfo.new(model, session_storage) + session_info = session_storage[:nested].clone + session_info[:association] = session_info[:parent_model].reflect_on_association(session_info[:name]) + unless session_info[:association].nil? + ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, session_info) + else + ActiveScaffold::DataStructures::NestedInfoScope.new(model, session_info) + end end end - attr_accessor :association, :child_association, :parent_model, :parent_id, :constrained_fields - - def initialize(model, session_storage) - info = session_storage[:nested].clone - @parent_model = info[:parent_model] - @association = @parent_model.reflect_on_association(info[:name]) - @parent_id = info[:parent_id] - iterate_model_associations(model) + attr_accessor :association, :child_association, :parent_model, :parent_id, :constrained_fields, :scope + + def initialize(model, session_info) + @parent_model = session_info[:parent_model] + @parent_id = session_info[:parent_id] end def new_instance? @@ -28,6 +31,26 @@ def parent_scope parent_model.find(parent_id) end + def habtm? + false + end + + def belongs_to? + false + end + + def readonly? + false + end + end + + class NestedInfoAssociation < NestedInfo + def initialize(model, session_info) + super(model, session_info) + @association = session_info[:association] + iterate_model_associations(model) + end + def habtm? association.macro == :has_and_belongs_to_many end @@ -45,6 +68,7 @@ def readonly? end protected + def iterate_model_associations(model) @constrained_fields = [] @constrained_fields << association.primary_key_name.to_sym unless association.belongs_to? @@ -60,7 +84,13 @@ def iterate_model_associations(model) end end end - - + end + + class NestedInfoScope < NestedInfo + def initialize(model, session_info) + super(model, session_info) + @scope = session_info[:name] + @constrained_fields = [] + end end end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index ba61e3f7d7..d751c57bb2 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -348,7 +348,7 @@ def column_heading_value(column, sorting, sort_direction) def render_nested_view(action_links, url_options, record) rendered = [] action_links.each do |link| - if link.nested_link? && @nested_auto_open[link.column.name] && @records.length <= @nested_auto_open[link.column.name] && respond_to?(:render_component) + if link.nested_link? && link.column && @nested_auto_open[link.column.name] && @records.length <= @nested_auto_open[link.column.name] && respond_to?(:render_component) link_url_options = {:adapter => '_list_inline_adapter', :format => :js}.merge(action_link_url_options(link, url_options, record, options = {:reuse_eid => true})) link_id = get_action_link_id(link_url_options, record, link.column) rendered << (render_component(link_url_options) + javascript_tag("ActiveScaffold.ActionLink.get('#{link_id}').set_opened();")) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 1d93713b2d..da7c3794ad 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -133,7 +133,7 @@ def action_link_url_options(link, url_options, record, options = {}) url_options[:controller] = link.controller if link.controller url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller] url_options.merge! link.parameters if link.parameters - url_options_for_nested_link(link.column, record, link, url_options, options) unless link.column.nil? + url_options_for_nested_link(link.column, record, link, url_options, options) if link.nested_link? url_options[:_method] = link.method if link.inline? && link.method != :get url_options end @@ -186,11 +186,15 @@ def action_link_html(link, url, html_options) end def url_options_for_nested_link(column, record, link, url_options, options = {}) - if column.association + if column && column.association url_options[:assoc_id] = url_options.delete(:id) url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present? link.eid = "#{controller_id.from(3)}_#{record.id}_#{column.association.name}" unless options.has_key?(:reuse_eid) url_options[:eid] = link.eid + elsif link.parameters && link.parameters[:named_scope] + url_options[:assoc_id] = url_options.delete(:id) + link.eid = "#{controller_id.from(3)}_#{record.id}_#{link.parameters[:named_scope]}" unless options.has_key?(:reuse_eid) + url_options[:eid] = link.eid end end From 3aa84f801862c05a735f952c193664ff4d76a088 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 24 Sep 2010 15:28:03 +0200 Subject: [PATCH 0700/2024] add sortable method for jquery --- .../default/javascripts/jquery/active_scaffold.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index fdbaddfa85..535ee889da 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -628,7 +628,20 @@ var ActiveScaffold = { } else { this.replace_html(element, content); } - } + }, + + sortable: function(element, controller, reorder_params) { + if (typeof(element) == 'string') element = '#' + element; + var element = $(element); + reorder_params.authenticity_token = $('meta[name=csrf-param]').attr('content'); + element.sortable({ + update: function(event, ui) { + var url = controller + '/reorder?' + url += $(this).sortable('serialize',{key: encodeURIComponent($(this).attr('id') + '[]'), expression:/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/}); + $.post(url.append_params(reorder_params)); + } + }); + } } /* From d6c692053248a2b9ddbd028f10536f262ae3d084 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 27 Sep 2010 11:12:59 +0200 Subject: [PATCH 0701/2024] Bugfix: Actionlink.get() generated js errors if element was missing --- .../javascripts/jquery/active_scaffold.js | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 535ee889da..874cb19f3c 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -541,7 +541,7 @@ var ActiveScaffold = { find_action_link: function(element) { if (typeof(element) == 'string') element = '#' + element; var as_adapter = $(element).closest('.as_adapter'); - return ActiveScaffold.ActionLink.get(as_adapter);; + return ActiveScaffold.ActionLink.get(as_adapter); }, scroll_to: function(element) { @@ -705,23 +705,27 @@ ActiveScaffold.ActionLink = { get: function(element) { if (typeof(element) == 'string') element = '#' + element; var element = $(element); - element.data(); // jquery 1.4.2 workaround - if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) { - var parent = element.parent(); - - if (parent && parent.is('td')) { - // record action - parent = parent.closest('tr.record'); - var target = parent.find('a.as_action'); - var loading_indicator = parent.find('td.actions .loading-indicator'); - new ActiveScaffold.Actions.Record(target, parent, loading_indicator); - } else if (parent && parent.is('div')) { - //table action - new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header'), parent.find('.loading-indicator')); + if (element.length > 0) { + element.data(); // jquery 1.4.2 workaround + if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) { + var parent = element.parent(); + + if (parent && parent.is('td')) { + // record action + parent = parent.closest('tr.record'); + var target = parent.find('a.as_action'); + var loading_indicator = parent.find('td.actions .loading-indicator'); + new ActiveScaffold.Actions.Record(target, parent, loading_indicator); + } else if (parent && parent.is('div')) { + //table action + new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header'), parent.find('.loading-indicator')); + } + element = $(element); } - element = $(element); + return element.data('action_link'); + } else { + return null; } - return element.data('action_link'); } }; ActiveScaffold.ActionLink.Abstract = Class.extend({ From 6d4f6cb55b4df69e52e89cdf28a021de6c6d8bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= <github@spam.raszi.hu> Date: Fri, 24 Sep 2010 16:29:57 +0200 Subject: [PATCH 0702/2024] hungarian locale updated --- lib/active_scaffold/locale/hu.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/locale/hu.yml b/lib/active_scaffold/locale/hu.yml index 0639dfa2a9..f2161fc9e5 100644 --- a/lib/active_scaffold/locale/hu.yml +++ b/lib/active_scaffold/locale/hu.yml @@ -3,13 +3,14 @@ hu: add: 'Hozzáadás' add_existing: 'Meglevő hozzáadása' add_existing_model: 'Meglevő %{model} hozzáadása' - are_you_sure_to_delete: 'Biztos vagy benne?' + are_you_sure_to_delete: 'Biztos vagy benne, hogy törölni szeretnéd?' cancel: 'Mégse' click_to_edit: 'Kattints a szerkesztéshez' + click_to_reset: 'Kattints az alapállapothoz' close: 'Bezárás' create: 'Létrehozás' create_model: '%{model} létrehozása' - create_another: 'Mégegy hozzáadása' + create_another: 'Még egy hozzáadása' created_model: '%{model} létrehozva' create_new: 'Új létrehozása' customize: 'Testreszabás' @@ -20,6 +21,7 @@ hu: edit: 'Szerkesztés' export: 'Exportálás' nested_for_model: '%{nested_model} / %{parent_model}' + false: 'Hamis' filtered: '(Szűrt)' found: 'Találat' hide: 'Elrejtés' @@ -27,8 +29,8 @@ hu: loading: 'Betöltés…' next: 'Következő' no_entries: 'Nincs elem' - no_options: 'nincsenek' - omit_header: 'Fejléc nélkül' + no_options: 'nincsenek opciók' + omit_header: 'Fejléc mellőzése' options: 'Opciók' pdf: 'PDF' previous: 'Előző' @@ -46,8 +48,9 @@ hu: show: 'Mutatás' show_model: '%{model} mutatása' _to_ : ' – ' - update: 'Modosítás' - update_model: '%{model} modosítása' + true: 'Igaz' + update: 'Módosítás' + update_model: '%{model} módosítása' updated_model: '%{model} módosítva' '=': '=' '>=': '>=' @@ -63,6 +66,7 @@ hu: ends_with: 'Ends with' # error_messages + cant_destroy_record: "nem törölhető: %{record}" internal_error: 'A lekérés sikertelen (code 500, Internal Error)' version_inconsistency: 'Verzió ütközés - ezt a rekordot módosították mióta elkezdted szerkeszteni.' failed_to_save_record: 'Failed to save record cause of an unknown error' From 10c3b9199cba77d8b186d4280fc2725dd76cb0f0 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 27 Sep 2010 14:00:15 +0200 Subject: [PATCH 0703/2024] Bugfix: do not render layout in adapter mode --- lib/extensions/action_controller_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extensions/action_controller_rendering.rb b/lib/extensions/action_controller_rendering.rb index eaadda40ad..2264ab5a1d 100644 --- a/lib/extensions/action_controller_rendering.rb +++ b/lib/extensions/action_controller_rendering.rb @@ -6,7 +6,7 @@ def render_with_active_scaffold(*args, &block) @rendering_adapter = true # recursion control # if we need an adapter, then we render the actual stuff to a string and insert it into the adapter template render :partial => params[:adapter][1..-1], - :locals => {:payload => render_to_string(args.first, &block)}, + :locals => {:payload => render_to_string(args.first.merge(:layout => false), &block)}, :use_full_path => true, :layout => false @rendering_adapter = nil # recursion control else From 1f5cbb3ef3476d6f4f795bd8a87e8111dd2d5d1b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 27 Sep 2010 14:01:03 +0200 Subject: [PATCH 0704/2024] bugfix: chrome generated js errors on action ajax requests --- frontends/default/javascripts/jquery/active_scaffold.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 874cb19f3c..d6cfb57a1f 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -32,6 +32,10 @@ $(document).ready(function() { if (action_link.is_disabled()) { return false; } else { + // hack: rails jquery defaults to dataType script + // but activescaffold is returning html content + // which chrome does nt like + if (action_link.position) event.data_type = 'dummy'; if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible'); action_link.disable(); } From 6a1f5b8e07ef0c91589c324ebc244a530f24dc9e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 27 Sep 2010 16:15:58 +0200 Subject: [PATCH 0705/2024] Bugfix: close link needs a label --- frontends/default/views/_messages.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_messages.html.erb b/frontends/default/views/_messages.html.erb index bf2c26a749..9925482491 100644 --- a/frontends/default/views/_messages.html.erb +++ b/frontends/default/views/_messages.html.erb @@ -3,7 +3,7 @@ <p class="<%= "#{name}-message message" %>" > <%= h flash[name] %> <% if request.xhr? %> - <a href="#" onclick="ActiveScaffold.remove(this.parentNode); return false;" title="<%= as_(:close) %>"></a> + <a href="#" onclick="ActiveScaffold.remove(this.parentNode); return false;" title="<%= as_(:close) %>"><%= as_(:close) %></a> <% end %> </p> <% end %> From cbcb844866a9064868aab01c859bbb39d573040e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 27 Sep 2010 16:35:17 +0200 Subject: [PATCH 0706/2024] improved and simplified action link response management --- .../default/views/on_action_update.js.rjs | 8 ++++++++ lib/active_scaffold/actions/list.rb | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 frontends/default/views/on_action_update.js.rjs diff --git a/frontends/default/views/on_action_update.js.rjs b/frontends/default/views/on_action_update.js.rjs new file mode 100644 index 0000000000..a91758caa5 --- /dev/null +++ b/frontends/default/views/on_action_update.js.rjs @@ -0,0 +1,8 @@ +page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages') +if controller.send :successful? + page.call 'ActiveScaffold.replace', element_row_id(:action => :list, :id => @record.id), render(:partial => 'list_record', :locals => {:record => @record}) if @record + page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} +else + page.call 'ActiveScaffold.scroll_to', active_scaffold_messages_id +end + diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 004bc6b0ce..04308b8774 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -77,6 +77,22 @@ def do_list def list_authorized? authorized_for?(:crud_type => :read) end + + def action_update_respond_to_js + render(:action => 'on_action_update') + end + + def action_update_respond_to_xml + render :xml => successful? ? "" : response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status + end + + def action_update_respond_to_json + render :text => successful? ? "" : response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status + end + + def action_update_respond_to_yaml + render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status + end private def list_authorized_filter @@ -85,5 +101,8 @@ def list_authorized_filter def list_formats (default_formats + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq end + def action_update_formats + (default_formats + active_scaffold_config.formats).uniq + end end end From 6060090d7a3a8fd1b8fe043023f91b8cf8f72bb1 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 28 Sep 2010 10:08:39 +0200 Subject: [PATCH 0707/2024] Bugfix: or is not the same as || --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index da7c3794ad..7578ccd4ac 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -250,7 +250,7 @@ def column_show_add_existing(column) end def column_show_add_new(column, associated, record) - value = column.plural_association? or (column.singular_association? and not associated.empty?) + value = column.plural_association? || (column.singular_association? and not associated.empty?) value = false unless record.class.authorized_for?(:crud_type => :create) value end From f4b5125046a0533cdb8e069f45998a9b048b6bce Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 28 Sep 2010 10:35:31 +0200 Subject: [PATCH 0708/2024] Bugfix: edit_associated should replace existing one and not creating a new row --- frontends/default/javascripts/jquery/active_scaffold.js | 2 +- frontends/default/javascripts/prototype/active_scaffold.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index d6cfb57a1f..1e17cade1c 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -616,7 +616,7 @@ var ActiveScaffold = { element.append(content); } } else { - if (current = $('#' + element.attr('id') + '.association-record')[0]) { + if (current = $('#' + element.attr('id') + ' tr.association-record')[0]) { this.replace(current, content); } else { element.prepend(content); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 85ce45d6de..69454da1cb 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -490,7 +490,7 @@ var ActiveScaffold = { element.insert(content); } } else { - if (current = $$('#' + element.id + '.association-record')[0]) { + if (current = $$('#' + element.id + ' tr.association-record')[0]) { this.replace(current, content); } else { element.insert({top: content}); From 81860c1526b4db3e5efb15d42de00b9f24afa982 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 28 Sep 2010 11:40:53 +0200 Subject: [PATCH 0709/2024] paperclip/file_column bridge: remove file link for jquery --- lib/active_scaffold/bridges/file_column/lib/form_ui.rb | 6 +++--- lib/active_scaffold/bridges/paperclip/lib/form_ui.rb | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/bridges/file_column/lib/form_ui.rb b/lib/active_scaffold/bridges/file_column/lib/form_ui.rb index 973f4949cd..0cc39035ac 100644 --- a/lib/active_scaffold/bridges/file_column/lib/form_ui.rb +++ b/lib/active_scaffold/bridges/file_column/lib/form_ui.rb @@ -6,9 +6,9 @@ def active_scaffold_input_file_column(column, options) if @record.send(column.name) # we already have a value? display the form for deletion. if ActiveScaffold.js_framework == :jquery - js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show();"; + js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;"; else - js_remove_file_code = "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show();"; + js_remove_file_code = "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show(); return false;"; end content_tag( :div, @@ -17,7 +17,7 @@ def active_scaffold_input_file_column(column, options) get_column_value(@record, column) + " " + hidden_field(:record, "delete_#{column.name}", :value => "false") + " | " + - link_to_function(as_(:remove_file), js_remove_file_code ), + content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}), {} ) + content_tag( diff --git a/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb b/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb index be0b4a5542..324b9789f0 100644 --- a/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb +++ b/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb @@ -6,11 +6,17 @@ def active_scaffold_input_paperclip(column, options) input = file_field(:record, column.name, options) paperclip = @record.send("#{column.name}") if paperclip.file? + if ActiveScaffold.js_framework == :jquery + js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;"; + else + js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;"; + end + content = active_scaffold_column_paperclip(column, @record) content_tag(:div, content + " | " + - link_to_function(as_(:remove_file), "$(this).next().value='true'; $(this).up().hide().next().show()") + - hidden_field(:record, "delete_#{column.name}", :value => "false") + hidden_field(:record, "delete_#{column.name}", :value => "false") + + content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}) ) + content_tag(:div, input, :style => "display: none") else input From b5604ea5676b41190960057ecd5cc8b0857d8de8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 28 Sep 2010 11:56:10 +0200 Subject: [PATCH 0710/2024] horizontal subform layout hides selected record labels for multi_record_select --- frontends/default/stylesheets/stylesheet.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 9217d65ba1..52a9a89542 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -776,7 +776,7 @@ padding: 0 5px 0 1px; background: none; } -.active-scaffold .horizontal-sub-form td label { +.active-scaffold .horizontal-sub-form td dt label { display: none; } From d8502a43fc30412b8af2b513b5c410b4a9a841ea Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 28 Sep 2010 15:09:45 +0200 Subject: [PATCH 0711/2024] use a more appropriate name --- lib/extensions/routing_mapper.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/extensions/routing_mapper.rb b/lib/extensions/routing_mapper.rb index d4311e02ad..58ed1c9287 100644 --- a/lib/extensions/routing_mapper.rb +++ b/lib/extensions/routing_mapper.rb @@ -4,28 +4,28 @@ module Routing :collection => {:show_search => :get, :render_field => :get}, :member => {:row => :get, :update_column => :post, :render_field => :get, :delete => :get} } - ACTIVE_SCAFFOLD_HABTM_ROUTING = { + ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = { :collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post}, :member => {:edit_associated => :get, :add_association => :get, :destroy_existing => :delete} } class Mapper module Base - def as_routes(options = {:habtm => true}) + def as_routes(options = {:association => true}) collection do ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].each {|name, type| send(type, name)} end member do ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each {|name, type| send(type, name)} end - as_habtm_routes if options[:habtm] + as_association_routes if options[:association] end - def as_habtm_routes + def as_association_routes collection do - ActionDispatch::Routing::ACTIVE_SCAFFOLD_HABTM_ROUTING[:collection].each {|name, type| send(type, name)} + ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:collection].each {|name, type| send(type, name)} end member do - ActionDispatch::Routing::ACTIVE_SCAFFOLD_HABTM_ROUTING[:member].each {|name, type| send(type, name)} + ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each {|name, type| send(type, name)} end end end From 18c8bd7984abb67c2560b952f0495d425bb45f20 Mon Sep 17 00:00:00 2001 From: David FRANCOIS <david.francois@webflows.fr> Date: Wed, 29 Sep 2010 06:29:18 +0800 Subject: [PATCH 0712/2024] Fixed a bug when a default_scope was set in a model preventing default ordering to be correctly set --- lib/active_scaffold/data_structures/sorting.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 7988ad28b8..2a1b58a37b 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -9,12 +9,16 @@ def initialize(columns) end def set_default_sorting(model) - last_scope = model.default_scoping.last - if last_scope.nil? || last_scope[:find].nil? || last_scope[:find][:order].nil? - set(model.primary_key, 'ASC') if model.column_names.include?(model.primary_key) - else - set_sorting_from_order_clause(last_scope[:find][:order].to_s, model.table_name) + model_scope = model.send(:current_scoped_methods) + order_clause = model_scope.arel.order_clauses.join(",") if model_scope + + # If an ORDER BY clause is found set default sorting according to it, else + # fallback to setting primary key ordering + if order_clause + set_sorting_from_order_clause(order_clause, model.table_name) @default_sorting = true + else + set(model.primary_key, 'ASC') if model.column_names.include?(model.primary_key) end end @@ -131,7 +135,7 @@ def extract_order_parts(criterion_parts) column_name_part, direction_part = criterion_parts.strip.split(' ') column_name_parts = column_name_part.split('.') order = {:direction => extract_direction(direction_part), - :column_name => remove_quotes(column_name_parts.last)} + :column_name => remove_quotes(column_name_parts.last)} order[:table_name] = remove_quotes(column_name_parts[-2]) if column_name_parts.length >= 2 order end From 5d2e9cb255b046b3db21b683835018ff5f21cd8a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 29 Sep 2010 09:30:50 +0200 Subject: [PATCH 0713/2024] set a jquery compatible rails default time format --- .../active_scaffold_setup_generator.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb index df81310d56..d8b0198b16 100644 --- a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +++ b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb @@ -39,6 +39,12 @@ def configure_application_layout <%= javascript_include_tag 'application.js' %> <%= active_scaffold_includes %>\n", :after => "<%= javascript_include_tag :defaults %>\n" + + inject_into_file "config/locales/en.yml", +" time: + formats: + default: \"%a, %d %b %Y %H:%M:%S\"", + :after => "hello: \"Hello world\"\n" gsub_file 'app/views/layouts/application.html.erb', /<%= javascript_include_tag :defaults/, '<%# javascript_include_tag :defaults' end end From b6b406bd6b2674a30a705381f8e27ff925c488f8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 29 Sep 2010 14:52:56 +0200 Subject: [PATCH 0714/2024] add option to add a created record at bottom of record list --- .../default/javascripts/jquery/active_scaffold.js | 12 ++++++++---- .../javascripts/prototype/active_scaffold.js | 14 ++++++++++---- frontends/default/views/on_create.js.rjs | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 1e17cade1c..7ddfc2ffe3 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -504,12 +504,16 @@ var ActiveScaffold = { $(form_element + ":first *:input[type!=hidden]:first").focus(); }, - create_record_row: function(tbody, html) { + create_record_row: function(tbody, html, options) { if (typeof(tbody) == 'string') tbody = '#' + tbody; tbody = $(tbody); - tbody.prepend(html); - - var new_row = tbody.children('tr:first-child'); + + if (options.insert_at == 'top') { + tbody.prepend(html); + var new_row = tbody.children('tr.record:first-child'); + } else if (options.insert_at == 'bottom') { + var new_row = tbody.children('tr.record').last().after(html).next(); + } this.stripe(tbody); this.hide_empty_message(tbody); this.increment_record_count(tbody.closest('div.active-scaffold')); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 69454da1cb..50d51e5fd0 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -389,11 +389,17 @@ var ActiveScaffold = { Form.focusFirstElement(form_element); }, - create_record_row: function(tbody, html) { + create_record_row: function(tbody, html, options) { tbody = $(tbody); - tbody.insert({top: html}); - - var new_row = tbody.firstDescendant(); + + if (options.insert_at == 'top') { + tbody.insert({top: html}); + var new_row = tbody.firstDescendant(); + } else if (options.insert_at == 'bottom') { + Selector.findChildElements(tbody, ['tr.record']).last().insert({after: html}); + var new_row = Selector.findChildElements(tbody, ['tr.record']).last(); + } + this.stripe(tbody); this.hide_empty_message(tbody); this.increment_record_count(tbody.up('div.active-scaffold')); diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index 6217a9da25..69e39f0522 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -4,7 +4,8 @@ page << "ActiveScaffold.find_action_link('#{form_selector}').update_flash_messag if controller.send :successful? if @insert_row new_row = render :partial => 'list_record', :locals => {:record => @record} - page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}');" + insert_at ||= :top + page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}', #{{:insert_at => insert_at}.to_json});" page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} end From d7e256d74cddd64b23ed145a5d7006a3c17987c5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 29 Sep 2010 16:28:31 +0200 Subject: [PATCH 0715/2024] Bugfix: nested create form should nt show parent column --- lib/active_scaffold/actions/create.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index feb2dccea4..9c62912b31 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -82,7 +82,10 @@ def create_respond_to_yaml def do_new @record = new_model apply_constraints_to_record(@record) - create_association_with_parent(@record) if nested? + if nested? + create_association_with_parent(@record) + register_constraints_with_action_columns(nested.constrained_fields) + end @record end @@ -93,7 +96,10 @@ def do_create active_scaffold_config.model.transaction do @record = update_record_from_params(new_model, active_scaffold_config.create.columns, params[:record]) apply_constraints_to_record(@record, :allow_autosave => true) - create_association_with_parent(@record) if nested? + if nested? + create_association_with_parent(@record) + register_constraints_with_action_columns(nested.constrained_fields) + end before_create_save(@record) self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit if successful? From 9d15015c8194cd6a0e24cac99727393000e87fbf Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 29 Sep 2010 16:50:53 +0200 Subject: [PATCH 0716/2024] Bugfix: update form should nt show parent column --- lib/active_scaffold/actions/update.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 6afa748d1a..334aee2698 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -63,6 +63,7 @@ def update_respond_to_yaml # A simple method to find and prepare a record for editing # May be overridden to customize the record (set default values, etc.) def do_edit + register_constraints_with_action_columns(nested.constrained_fields) if nested? @record = find_if_allowed(params[:id], :update) end From 2182dc1594770fecbc2081676db4e9bfd8ad434c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 4 Oct 2010 16:32:15 +0200 Subject: [PATCH 0717/2024] add update option: hide_nested_column, defaults to true; adds basic support to move child to another parent --- lib/active_scaffold/actions/update.rb | 2 +- lib/active_scaffold/config/update.rb | 6 ++++++ lib/active_scaffold/constraints.rb | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 334aee2698..22483d0bbf 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -63,7 +63,7 @@ def update_respond_to_yaml # A simple method to find and prepare a record for editing # May be overridden to customize the record (set default values, etc.) def do_edit - register_constraints_with_action_columns(nested.constrained_fields) if nested? + register_constraints_with_action_columns(nested.constrained_fields, active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested? @record = find_if_allowed(params[:id], :update) end diff --git a/lib/active_scaffold/config/update.rb b/lib/active_scaffold/config/update.rb index aa40806f48..98e2ebc9a9 100644 --- a/lib/active_scaffold/config/update.rb +++ b/lib/active_scaffold/config/update.rb @@ -28,5 +28,11 @@ def label attr_accessor :nested_links cattr_accessor :nested_links @@nested_links = false + + attr_writer :hide_nested_column + def hide_nested_column + @hide_nested_column.nil? ? true : @hide_nested_column + end + end end diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 2dfe53ef7b..2b85c308a4 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -22,12 +22,13 @@ def set_active_scaffold_constraints # This lets the ActionColumns object skip constrained columns. # # If the constraint value is a Hash, then we assume the constraint is a multi-level association constraint (the reverse of a has_many :through) and we do NOT register the constraint column. - def register_constraints_with_action_columns(association_constrained_fields = []) + def register_constraints_with_action_columns(association_constrained_fields = [], exclude_actions = []) constrained_fields = active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect{|k| k.to_sym} constrained_fields = constrained_fields | association_constrained_fields if self.class.uses_active_scaffold? # we actually want to do this whether constrained_fields exist or not, so that we can reset the array when they don't active_scaffold_config.actions.each do |action_name| + next if exclude_actions.include?(action_name) action = active_scaffold_config.send(action_name) next unless action.respond_to? :columns action.columns.constraint_columns = constrained_fields From a9b8adca56a87e6196be5cf0cc38fc596e4ce55b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 5 Oct 2010 08:09:10 +0200 Subject: [PATCH 0718/2024] Bugfix: create row at bottom failed if last row represents an inline-adapter --- frontends/default/javascripts/jquery/active_scaffold.js | 2 +- frontends/default/javascripts/prototype/active_scaffold.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 7ddfc2ffe3..3dc7083e2b 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -512,7 +512,7 @@ var ActiveScaffold = { tbody.prepend(html); var new_row = tbody.children('tr.record:first-child'); } else if (options.insert_at == 'bottom') { - var new_row = tbody.children('tr.record').last().after(html).next(); + var new_row = tbody.children('tr.record, tr.inline-adapter').last().after(html).next(); } this.stripe(tbody); this.hide_empty_message(tbody); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 50d51e5fd0..20b8fd9c1b 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -396,7 +396,7 @@ var ActiveScaffold = { tbody.insert({top: html}); var new_row = tbody.firstDescendant(); } else if (options.insert_at == 'bottom') { - Selector.findChildElements(tbody, ['tr.record']).last().insert({after: html}); + tbody.childElements().reverse().detect(function(node) { return node.hasClassName('record') || node.hasClassName('inline-adapter')}).insert({after: html}); var new_row = Selector.findChildElements(tbody, ['tr.record']).last(); } From edae65f6da7618d6702b047951a06a33b11c2e79 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 5 Oct 2010 09:36:04 +0200 Subject: [PATCH 0719/2024] bugfix: use correct scope for nested calculations --- lib/active_scaffold/actions/core.rb | 1 + lib/active_scaffold/helpers/view_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 3fc6a0274d..64e6e455cb 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -5,6 +5,7 @@ def self.included(base) after_filter :clear_flashes end base.helper_method :nested? + base.helper_method :beginning_of_chain end def render_field @record ||= if params[:in_place_editing] diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 7578ccd4ac..156502fb8c 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -233,7 +233,7 @@ def column_calculation(column) conditions = controller.send(:all_conditions) includes = active_scaffold_config.list.count_includes includes ||= controller.send(:active_scaffold_includes) unless conditions.nil? - calculation = active_scaffold_config.model.calculate(column.calculate, column.name, :conditions => conditions, + calculation = beginning_of_chain.calculate(column.calculate, column.name, :conditions => conditions, :joins => controller.send(:joins_for_collection), :include => includes) end From 786c58a0234e24a998527dada5fc6356b35d1a81 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 5 Oct 2010 10:00:56 +0200 Subject: [PATCH 0720/2024] Bugfix: create_record_row failed to insert at bottom if no record so far --- .../default/javascripts/jquery/active_scaffold.js | 8 +++++++- .../default/javascripts/prototype/active_scaffold.js | 12 +++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 3dc7083e2b..1f840a637c 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -512,7 +512,13 @@ var ActiveScaffold = { tbody.prepend(html); var new_row = tbody.children('tr.record:first-child'); } else if (options.insert_at == 'bottom') { - var new_row = tbody.children('tr.record, tr.inline-adapter').last().after(html).next(); + var rows = tbody.children('tr.record, tr.inline-adapter'); + var new_row = null; + if (rows.length > 0) { + new_row = rows.last().after(html).next(); + } else { + new_row = tbody.append(html).children().last(); + } } this.stripe(tbody); this.hide_empty_message(tbody); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 20b8fd9c1b..098c870cb5 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -391,13 +391,19 @@ var ActiveScaffold = { create_record_row: function(tbody, html, options) { tbody = $(tbody); + var new_row = null; if (options.insert_at == 'top') { tbody.insert({top: html}); - var new_row = tbody.firstDescendant(); + new_row = tbody.firstDescendant(); } else if (options.insert_at == 'bottom') { - tbody.childElements().reverse().detect(function(node) { return node.hasClassName('record') || node.hasClassName('inline-adapter')}).insert({after: html}); - var new_row = Selector.findChildElements(tbody, ['tr.record']).last(); + var last_row = tbody.childElements().reverse().detect(function(node) { return node.hasClassName('record') || node.hasClassName('inline-adapter')}); + if (last_row) { + last_row.insert({after: html}); + } else { + tbody.insert({bottom: html}); + } + new_row = Selector.findChildElements(tbody, ['tr.record']).last(); } this.stripe(tbody); From 90583ded2b87a40bc4f80cf4db0258f7be0d6261 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 5 Oct 2010 10:12:14 +0200 Subject: [PATCH 0721/2024] Bugfix: Updating models using ancestry plugin failed --- frontends/default/views/on_update.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index f761ca38e8..5a17e9b6ff 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -2,7 +2,7 @@ form_selector = "#{element_form_id(:action => :update)}" page << "ActiveScaffold.find_action_link('#{form_selector}').update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? - updated_row = if nested? && nested.association.belongs_to? + updated_row = if nested? && nested.belongs_to? nil else render :partial => 'list_record', :locals => {:record => @record} From ebd8426a368f45ceb8abd4fd224427b558d51382 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 6 Oct 2010 11:10:54 +0200 Subject: [PATCH 0722/2024] added ancestry plugin bridge --- .../bridges/ancestry/bridge.rb | 5 +++ .../bridges/ancestry/lib/ancestry_bridge.rb | 38 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 lib/active_scaffold/bridges/ancestry/bridge.rb create mode 100644 lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb diff --git a/lib/active_scaffold/bridges/ancestry/bridge.rb b/lib/active_scaffold/bridges/ancestry/bridge.rb new file mode 100644 index 0000000000..364d974d27 --- /dev/null +++ b/lib/active_scaffold/bridges/ancestry/bridge.rb @@ -0,0 +1,5 @@ +ActiveScaffold::Bridges.bridge "Ancestry" do + install do + require File.join(File.dirname(__FILE__), "lib/ancestry_bridge.rb") + end +end diff --git a/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb b/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb new file mode 100644 index 0000000000..16098d2228 --- /dev/null +++ b/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb @@ -0,0 +1,38 @@ +ActiveScaffold::Config::Core.class_eval do + def initialize_with_ancestry(model_id) + initialize_without_ancestry(model_id) + + return unless self.model.singleton_methods.include?('has_ancestry') + + col_config = self.columns[self.model.ancestry_column] + unless col_config.nil? + col_config.form_ui = :ancestry + create.columns.exclude :ancestry + list.columns.exclude :ancestry + end + end + + alias_method_chain :initialize, :ancestry +end + +module ActiveScaffold + module AncestryBridge + module FormColumnHelpers + def active_scaffold_input_ancestry(column, options) + select_options = [] + traverse_ancestry = lambda do|key, value| + unless key == @record + select_options << ["#{'__' * key.depth}#{key.to_label}", key.id] + value.each(&traverse_ancestry) if value.is_a?(Hash) && !value.empty? + end + end + @record.class.arrange.each(&traverse_ancestry) + select(:record, :ancestry, select_options, { :selected => @record.send(:ancestry) }, options) + end + end + end +end + +ActionView::Base.class_eval do + include ActiveScaffold::AncestryBridge::FormColumnHelpers +end From afbbabe9b923d766078d15dc875179f06babc00a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 6 Oct 2010 16:12:47 +0200 Subject: [PATCH 0723/2024] Bugfix: model using ancestry check failed --- lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb b/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb index 16098d2228..66408acbda 100644 --- a/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +++ b/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb @@ -2,7 +2,7 @@ def initialize_with_ancestry(model_id) initialize_without_ancestry(model_id) - return unless self.model.singleton_methods.include?('has_ancestry') + return unless self.model.respond_to? :ancestry_column col_config = self.columns[self.model.ancestry_column] unless col_config.nil? From 548ba5ea455ed07acb34db5050e9492790ff49d7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 6 Oct 2010 16:55:46 +0200 Subject: [PATCH 0724/2024] Bugfix: close button generated js errors --- frontends/default/views/_show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_show.html.erb b/frontends/default/views/_show.html.erb index 0b4470cfc9..1110dd986f 100644 --- a/frontends/default/views/_show.html.erb +++ b/frontends/default/views/_show.html.erb @@ -3,6 +3,6 @@ <%= render :partial => 'show_columns', :locals => {:columns => active_scaffold_config.show.columns} -%> <p class="form-footer"> - <%= link_to as_(:close), main_path_to_return, :class => 'as_cancel', :remote => true %> + <%= link_to as_(:close), main_path_to_return, :class => 'as_cancel', :remote => true, 'data-refresh' => false %> <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> </p> \ No newline at end of file From 39dbd696c0ea885551375340ac0d0f1661baa353 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 7 Oct 2010 09:32:52 +0200 Subject: [PATCH 0725/2024] use underscored model name as url param --- lib/active_scaffold.rb | 4 ++-- lib/active_scaffold/actions/nested.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 7192041296..f404da7c92 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -131,7 +131,7 @@ def link_for_association(column, options = {}) unless controller.nil? options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column options[:parameters] ||= {} - options[:parameters].reverse_merge! :parent_model => column.active_record_class.to_s, :association => column.association.name + options[:parameters].reverse_merge! :parent_model => column.active_record_class.to_s.underscore, :association => column.association.name if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. @@ -150,7 +150,7 @@ def link_for_association(column, options = {}) def link_for_association_as_scope(scope, options = {}) options.reverse_merge! :label => scope, :position => :after, :type => :member, :controller => controller_path options[:parameters] ||= {} - options[:parameters].reverse_merge! :parent_model => active_scaffold_config.model.to_s, :named_scope => scope + options[:parameters].reverse_merge! :parent_model => active_scaffold_config.model.to_s.underscore, :named_scope => scope ActiveScaffold::DataStructures::ActionLink.new('index', options) end diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 5f6a1215e1..b0aa3ad940 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -31,7 +31,7 @@ def nested? def set_nested if params[:parent_model] && ((params[:association] && params[:assoc_id]) || params[:named_scope]) @nested = nil - active_scaffold_session_storage[:nested] = {:parent_model => params[:parent_model].constantize, + active_scaffold_session_storage[:nested] = {:parent_model => params[:parent_model].camelize.constantize, :name => (params[:association] || params[:named_scope]).to_sym, :parent_id => params[:assoc_id]} params.delete_if {|key, value| [:parent_model, :association, :named_scope, :assoc_id].include? key.to_sym} From 3d804e3b5beedb30c0d43866b283e8dd85f075b4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 7 Oct 2010 10:46:49 +0200 Subject: [PATCH 0726/2024] Fix file_column in subform --- lib/bridges/file_column/lib/form_ui.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/bridges/file_column/lib/form_ui.rb b/lib/bridges/file_column/lib/form_ui.rb index b169d8e045..f31c3e45c8 100644 --- a/lib/bridges/file_column/lib/form_ui.rb +++ b/lib/bridges/file_column/lib/form_ui.rb @@ -5,12 +5,20 @@ module FormColumnHelpers def active_scaffold_input_file_column(column, options) if @record.send(column.name) # we already have a value? display the form for deletion. + + # generate hidden field tag + hidden_options = options.dup + hidden_options[:id] += '_delete' + hidden_options[:name].sub!("[#{column.name}]", "[delete_#{column.name}]") + hidden_options[:value] = 'false' + custom_hidden_field_tag = hidden_field(:record, column.name, hidden_options) + content_tag( :div, content_tag( :div, get_column_value(@record, column) + " " + - hidden_field(:record, "delete_#{column.name}", :value => "false") + + custom_hidden_field_tag + " | " + link_to_function(as_(:remove_file), "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show();"), {} @@ -29,4 +37,4 @@ def active_scaffold_input_file_column(column, options) end end end -end \ No newline at end of file +end From 1c9411c0eec73d53ee017f78ea109ae8e064295f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 11 Oct 2010 08:54:39 +0200 Subject: [PATCH 0727/2024] extract method i18n_number_to_native_format --- lib/active_scaffold/attribute_params.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index c7337797b8..6d33959c93 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -126,15 +126,7 @@ def column_value_from_param_value(parent_record, column, value) ids.empty? ? [] : column.association.klass.find(ids) end elsif column.column && column.column.number? && [:i18n_number, :currency].include?(column.options[:format]) - native = '.' - delimiter = I18n.t('number.format.delimiter') - separator = I18n.t('number.format.separator') - - unless delimiter == native && !value.include?(separator) && value !~ /\.\d{3}$/ - value.gsub(/[^0-9\-#{I18n.t('number.format.separator')}]/, '').gsub(I18n.t('number.format.separator'), native) - else - value - end + i18n_number_to_native_format(value) else # convert empty strings into nil. this works better with 'null => true' columns (and validations), # and 'null => false' columns should just convert back to an empty string. @@ -145,6 +137,18 @@ def column_value_from_param_value(parent_record, column, value) end end + def i18n_number_to_native_format(value) + native = '.' + delimiter = I18n.t('number.format.delimiter') + separator = I18n.t('number.format.separator') + + unless delimiter == native && !value.include?(separator) && value !~ /\.\d{3}$/ + value.gsub(/[^0-9\-#{I18n.t('number.format.separator')}]/, '').gsub(I18n.t('number.format.separator'), native) + else + value + end + end + # Attempts to create or find an instance of klass (which must be an ActiveRecord object) from the # request parameters given. If params[:id] exists it will attempt to find an existing object # otherwise it will build a new one. From a614c91af725d4588c7481f4d1154ee990379648 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 11 Oct 2010 10:12:35 +0200 Subject: [PATCH 0728/2024] extract method condition_value_for_numeric --- lib/active_scaffold/attribute_params.rb | 14 +-------- lib/active_scaffold/finder.rb | 42 ++++++++++++++++++------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 6d33959c93..a9c68f4bd9 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -126,7 +126,7 @@ def column_value_from_param_value(parent_record, column, value) ids.empty? ? [] : column.association.klass.find(ids) end elsif column.column && column.column.number? && [:i18n_number, :currency].include?(column.options[:format]) - i18n_number_to_native_format(value) + self.class.i18n_number_to_native_format(value) else # convert empty strings into nil. this works better with 'null => true' columns (and validations), # and 'null => false' columns should just convert back to an empty string. @@ -137,18 +137,6 @@ def column_value_from_param_value(parent_record, column, value) end end - def i18n_number_to_native_format(value) - native = '.' - delimiter = I18n.t('number.format.delimiter') - separator = I18n.t('number.format.separator') - - unless delimiter == native && !value.include?(separator) && value !~ /\.\d{3}$/ - value.gsub(/[^0-9\-#{I18n.t('number.format.separator')}]/, '').gsub(I18n.t('number.format.separator'), native) - else - value - end - end - # Attempts to create or find an instance of klass (which must be an ActiveRecord object) from the # request parameters given. If params[:id] exists it will attempt to find an existing object # otherwise it will build a new one. diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 0c06477344..323da09d73 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -69,18 +69,13 @@ def condition_for_column(column, value, text_search = :full) def condition_for_numeric(column, value) if !value.is_a?(Hash) - ["#{column.search_sql} = ?", column.column.nil? ? value.to_f : column.column.type_cast(value)] + ["#{column.search_sql} = ?", condition_value_for_numeric(column, value)] elsif value[:from].blank? or not ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) nil elsif value[:opt] == 'BETWEEN' - condition = "#{column.search_sql} BETWEEN ? AND ?" - if column.column.nil? - [condition, value[:from].to_f, value[:to].to_f] - else - [condition, column.column.type_cast(value[:from]), column.column.type_cast(value[:to])] - end - else - ["#{column.search_sql} #{value[:opt]} ?", column.column.nil? ? value[:from].to_f : column.column.type_cast(value[:from])] + ["#{column.search_sql} BETWEEN ? AND ?", condition_value_for_numeric(column, value[:from]), condition_value_for_numeric(column, value[:to])] + else + ["#{column.search_sql} #{value[:opt]} ?", condition_value_for_numeric(column, value[:from])] end end @@ -113,6 +108,29 @@ def condition_value_for_datetime(value, conversion = :to_time) Time.zone.parse(value).in_time_zone.send(conversion) rescue nil end unless value.nil? || value.blank? end + + def condition_value_for_numeric(column, value) + value = i18n_number_to_native_format(value) if [:i18n_number, :currency].include?(column.options[:format]) + case (column.search_ui || column.column.type) + when :integer then value.to_i rescue value ? 1 : 0 + when :float then value.to_f + when :decimal then ActiveRecord::ConnectionAdapters::Column.value_to_decimal(value) + else + value + end + end + + def i18n_number_to_native_format(value) + native = '.' + delimiter = I18n.t('number.format.delimiter') + separator = I18n.t('number.format.separator') + + unless delimiter == native && !value.include?(separator) && value !~ /\.\d{3}$/ + value.gsub(/[^0-9\-#{I18n.t('number.format.separator')}]/, '').gsub(I18n.t('number.format.separator'), native) + else + value + end + end def condition_for_datetime(column, value, like_pattern = nil) conversion = column.column.type == :date ? :to_date : :to_time @@ -175,15 +193,15 @@ def human_condition_for_column(column, value) search_ui ||= column.column.type if column.column case search_ui when :integer, :decimal, :float - "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt])} #{value[:from]} #{value[:opt] == 'BETWEEN' ? '-' + value[:to].to_s : ''}" + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{condition_value_for_numeric(column, value[:from])} #{value[:opt] == 'BETWEEN' ? '- ' + condition_value_for_numeric(column, value[:to]).to_s : ''}" when :string opt = ActiveScaffold::Finder::StringComparators.index(value[:opt]) || value[:opt] - "#{column.active_record_class.human_attribute_name(column.name)} #{as_(opt).downcase} '#{value[:from]}' #{opt == 'BETWEEN' ? '-' + value[:to].to_s : ''}" + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(opt).downcase} '#{value[:from]}' #{opt == 'BETWEEN' ? '- ' + value[:to].to_s : ''}" when :date, :time, :datetime, :timestamp conversion = column.column.type == :date ? :to_date : :to_time from = condition_value_for_datetime(value[:from], conversion) to = condition_value_for_datetime(value[:to], conversion) - "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt])} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '-' + I18n.l(to) : ''}" + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt])} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '- ' + I18n.l(to) : ''}" when :select, :multi_select, :record_select associated = value associated = [associated].compact unless associated.is_a? Array From ae52bc617a8e7164e20ebd05a46803a0cc674c47 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 11 Oct 2010 13:30:07 +0200 Subject: [PATCH 0729/2024] moved human_conditions into partial, view helpers --- .../default/views/_human_conditions.html.erb | 1 + .../default/views/_list_messages.html.erb | 2 +- lib/active_scaffold/actions/field_search.rb | 7 ++- lib/active_scaffold/finder.rb | 40 ------------- .../helpers/human_condition_helpers.rb | 59 +++++++++++++++++++ lib/active_scaffold/helpers/view_helpers.rb | 1 + 6 files changed, 66 insertions(+), 44 deletions(-) create mode 100644 frontends/default/views/_human_conditions.html.erb create mode 100644 lib/active_scaffold/helpers/human_condition_helpers.rb diff --git a/frontends/default/views/_human_conditions.html.erb b/frontends/default/views/_human_conditions.html.erb new file mode 100644 index 0000000000..b1a09cd9ef --- /dev/null +++ b/frontends/default/views/_human_conditions.html.erb @@ -0,0 +1 @@ +<%= columns.collect {|column| active_scaffold_human_condition_for(column)}.compact.join(I18n.t('support.array.two_words_connector')) %> \ No newline at end of file diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index c2ad9d4ed2..e6a7c098d9 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -9,7 +9,7 @@ <%= render :partial => 'messages' %> </div> <p class="filtered-message" <%= ' style="display:none;" '.html_safe unless @filtered %>> - <%= @filtered.is_a?(String) ? @filtered : as_(active_scaffold_config.list.filtered_message) %> + <%= @filtered.is_a?(Array) ? render(:partial => 'human_conditions', :locals => {:columns => @filtered}) : as_(active_scaffold_config.list.filtered_message) %> </p> <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" '.html_safe unless @page.items.empty? %>> <%= as_(active_scaffold_config.list.no_entries_message) %> diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index ff3b821827..27fbbaf9e8 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -44,21 +44,21 @@ def do_search unless search_params.nil? text_search = active_scaffold_config.field_search.text_search search_conditions = [] - human_conditions = [] if active_scaffold_config.field_search.human_conditions + human_condition_columns = [] if active_scaffold_config.field_search.human_conditions columns = active_scaffold_config.field_search.columns search_params.each do |key, value| next unless columns.include? key search_condition = self.class.condition_for_column(active_scaffold_config.columns[key], value, text_search) unless search_condition.blank? search_conditions << search_condition - human_conditions << self.class.human_condition_for_column(active_scaffold_config.columns[key], value) unless human_conditions.nil? + human_condition_columns << active_scaffold_config.columns[key] unless human_condition_columns.nil? end end self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, *search_conditions) if search_conditions.blank? @filtered = false else - @filtered = human_conditions.nil? ? true : human_conditions.compact.join(I18n.t('support.array.two_words_connector')) + @filtered = human_condition_columns.nil? ? true : human_condition_columns end includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact @@ -69,6 +69,7 @@ def do_search end private + def search_authorized_filter link = active_scaffold_config.field_search.link || active_scaffold_config.field_search.class.link raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 323da09d73..83b75742d3 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -175,46 +175,6 @@ def like_pattern(text_search) else '?' end end - - def override_human_condition?(search_ui) - respond_to?(override_human_condition(search_ui)) - end - - # the naming convention for overriding human condition search_ui types - def override_human_condition(search_ui) - "human_condition_for_#{search_ui}_type" - end - - def human_condition_for_column(column, value) - if column.search_ui and override_human_condition?(column.search_ui) - send(override_human_condition(column.search_ui), column, value) - else - search_ui = column.search_ui - search_ui ||= column.column.type if column.column - case search_ui - when :integer, :decimal, :float - "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{condition_value_for_numeric(column, value[:from])} #{value[:opt] == 'BETWEEN' ? '- ' + condition_value_for_numeric(column, value[:to]).to_s : ''}" - when :string - opt = ActiveScaffold::Finder::StringComparators.index(value[:opt]) || value[:opt] - "#{column.active_record_class.human_attribute_name(column.name)} #{as_(opt).downcase} '#{value[:from]}' #{opt == 'BETWEEN' ? '- ' + value[:to].to_s : ''}" - when :date, :time, :datetime, :timestamp - conversion = column.column.type == :date ? :to_date : :to_time - from = condition_value_for_datetime(value[:from], conversion) - to = condition_value_for_datetime(value[:to], conversion) - "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt])} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '- ' + I18n.l(to) : ''}" - when :select, :multi_select, :record_select - associated = value - associated = [associated].compact unless associated.is_a? Array - associated = column.association.klass.find(associated.map(&:to_i)).collect(&:to_label) if column.association - "#{column.active_record_class.human_attribute_name(column.name)} = #{associated.join(', ')}" - when :boolean, :checkbox - label = column.column.type_cast(value) ? as_(:true) : as_(:false) - "#{column.active_record_class.human_attribute_name(column.name)} = #{label}" - when :null - "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value.to_sym)}" - end - end - end end NumericComparators = [ diff --git a/lib/active_scaffold/helpers/human_condition_helpers.rb b/lib/active_scaffold/helpers/human_condition_helpers.rb new file mode 100644 index 0000000000..e26e56c21d --- /dev/null +++ b/lib/active_scaffold/helpers/human_condition_helpers.rb @@ -0,0 +1,59 @@ +module ActiveScaffold + module Helpers + # Helpers that assist with rendering of a human readable search statement + module HumanConditionHelpers + + def active_scaffold_human_condition_for(column) + value = field_search_params[column.name] + if override_human_condition_column?(column) + send(override_human_condition_column(column), value, {}) + elsif column.search_ui and override_human_condition?(column.search_ui) + send(override_human_condition(column.search_ui), column, value) + else + search_ui = column.search_ui + search_ui ||= column.column.type if column.column + case search_ui + when :integer, :decimal, :float + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{controller.class.condition_value_for_numeric(column, value[:from])} #{value[:opt] == 'BETWEEN' ? '- ' + controller.class.condition_value_for_numeric(column, value[:to]).to_s : ''}" + when :string + opt = ActiveScaffold::Finder::StringComparators.index(value[:opt]) || value[:opt] + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(opt).downcase} '#{value[:from]}' #{opt == 'BETWEEN' ? '- ' + value[:to].to_s : ''}" + when :date, :time, :datetime, :timestamp + conversion = column.column.type == :date ? :to_date : :to_time + from = controller.condition_value_for_datetime(value[:from], conversion) + to = controller.condition_value_for_datetime(value[:to], conversion) + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt])} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '- ' + I18n.l(to) : ''}" + when :select, :multi_select, :record_select + associated = value + associated = [associated].compact unless associated.is_a? Array + associated = column.association.klass.find(associated.map(&:to_i)).collect(&:to_label) if column.association + "#{column.active_record_class.human_attribute_name(column.name)} = #{associated.join(', ')}" + when :boolean, :checkbox + label = column.column.type_cast(value) ? as_(:true) : as_(:false) + "#{column.active_record_class.human_attribute_name(column.name)} = #{label}" + when :null + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value.to_sym)}" + end + end unless value.nil? + end + + def override_human_condition_column?(column) + respond_to?(override_human_condition_column(column)) + end + + # the naming convention for overriding form fields with helpers + def override_human_condition_column(column) + "#{column.name}_human_condition_column" + end + + def override_human_condition?(search_ui) + respond_to?(override_human_condition(search_ui)) + end + + # the naming convention for overriding human condition search_ui types + def override_human_condition(search_ui) + "active_scaffold_human_condition_#{search_ui}" + end + end + end +end \ No newline at end of file diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 156502fb8c..8bac0b08a7 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -11,6 +11,7 @@ module ViewHelpers include ActiveScaffold::Helpers::FormColumnHelpers include ActiveScaffold::Helpers::SearchColumnHelpers include ActiveScaffold::Helpers::CountryHelpers + include ActiveScaffold::Helpers::HumanConditionHelpers ## ## Delegates From 8cfa8b8d4e31b04bce6746277289090f93a84d4d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 11 Oct 2010 14:48:16 +0200 Subject: [PATCH 0730/2024] Bugfix: format numeric according to locale setting --- lib/active_scaffold/helpers/human_condition_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/human_condition_helpers.rb b/lib/active_scaffold/helpers/human_condition_helpers.rb index e26e56c21d..7e3825fa4a 100644 --- a/lib/active_scaffold/helpers/human_condition_helpers.rb +++ b/lib/active_scaffold/helpers/human_condition_helpers.rb @@ -14,7 +14,7 @@ def active_scaffold_human_condition_for(column) search_ui ||= column.column.type if column.column case search_ui when :integer, :decimal, :float - "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{controller.class.condition_value_for_numeric(column, value[:from])} #{value[:opt] == 'BETWEEN' ? '- ' + controller.class.condition_value_for_numeric(column, value[:to]).to_s : ''}" + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{format_number_value(controller.class.condition_value_for_numeric(column, value[:from]), column.options)} #{value[:opt] == 'BETWEEN' ? '- ' + format_number_value(controller.class.condition_value_for_numeric(column, value[:to]), column.options).to_s : ''}" when :string opt = ActiveScaffold::Finder::StringComparators.index(value[:opt]) || value[:opt] "#{column.active_record_class.human_attribute_name(column.name)} #{as_(opt).downcase} '#{value[:from]}' #{opt == 'BETWEEN' ? '- ' + value[:to].to_s : ''}" From 2c5ec2705e07ae944c4e695f8afffa6a08899485 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 11 Oct 2010 15:04:48 +0200 Subject: [PATCH 0731/2024] Bugfix: field_search format numeric values according to locale settings --- lib/active_scaffold/helpers/search_column_helpers.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 864bc7b97d..7c4c5dc5df 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -125,7 +125,10 @@ def active_scaffold_search_range(column, options) opt_value, from_value, to_value = field_search_params_range_values(column) select_options = ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} if column.column && column.column.text? - + from_value = controller.class.condition_value_for_numeric(column, from_value) + to_value = controller.class.condition_value_for_numeric(column, to_value) + from_value = format_number_value(from_value, column.options) if from_value.is_a?(Numeric) + to_value = format_number_value(to_value, column.options) if to_value.is_a?(Numeric) html = select_tag("#{options[:name]}[opt]", options_for_select(select_options, opt_value), :id => "#{options[:id]}_opt", From b2c85d1c0ae971be7e0aec4febf08bd2fb0b7981 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 11 Oct 2010 16:24:15 +0200 Subject: [PATCH 0732/2024] adapt human_condition code for datepicker --- .../calendar_date_select/lib/as_cds_bridge.rb | 3 ++- .../date_picker/lib/datepicker_bridge.rb | 5 ++-- .../bridges/shared/date_bridge.rb | 27 ++++++++++--------- .../helpers/human_condition_helpers.rb | 6 ++--- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb index ae89f2e218..c6dba801ec 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb @@ -58,6 +58,8 @@ def active_scaffold_javascripts(frontend = :default) include ActiveScaffold::Bridges::CalendarDateSelectBridge::FormColumnHelpers include ActiveScaffold::Bridges::Shared::DateBridge::SearchColumnHelpers alias_method :active_scaffold_search_calendar_date_select, :active_scaffold_search_date_bridge + include ActiveScaffold::Bridges::Shared::DateBridge::HumanConditionHelpers + alias_method :active_scaffold_human_condition_calendar_date_select, :active_scaffold_human_condition_date_bridge include ActiveScaffold::Bridges::CalendarDateSelectBridge::SearchColumnHelpers include ActiveScaffold::Bridges::CalendarDateSelectBridge::ViewHelpers end @@ -65,5 +67,4 @@ def active_scaffold_javascripts(frontend = :default) ActiveScaffold::Finder::ClassMethods.module_eval do include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods alias_method :condition_for_calendar_date_select_type, :condition_for_date_bridge_type - alias_method :human_condition_for_calendar_date_select_type, :human_condition_for_date_bridge_type end diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index e6425d2646..c90717fec8 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -189,6 +189,9 @@ def active_scaffold_input_date_picker(column, options) include ActiveScaffold::Bridges::Shared::DateBridge::SearchColumnHelpers alias_method :active_scaffold_search_date_picker, :active_scaffold_search_date_bridge alias_method :active_scaffold_search_datetime_picker, :active_scaffold_search_date_bridge + include ActiveScaffold::Bridges::Shared::DateBridge::HumanConditionHelpers + alias_method :active_scaffold_human_condition_date_picker, :active_scaffold_human_condition_date_bridge + alias_method :active_scaffold_human_condition_datetime_picker, :active_scaffold_human_condition_date_bridge include ActiveScaffold::Bridges::DatePickerBridge::SearchColumnHelpers include ActiveScaffold::Bridges::DatePickerBridge::FormColumnHelpers alias_method :active_scaffold_input_datetime_picker, :active_scaffold_input_date_picker @@ -198,6 +201,4 @@ def active_scaffold_input_date_picker(column, options) include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods alias_method :condition_for_date_picker_type, :condition_for_date_bridge_type alias_method :condition_for_datetime_picker_type, :condition_for_date_picker_type - alias_method :human_condition_for_date_picker_type, :human_condition_for_date_bridge_type - alias_method :human_condition_for_datetime_picker_type, :human_condition_for_date_bridge_type end diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index 83031ada59..00069854f8 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -51,6 +51,20 @@ def column_datetime?(column) (!column.column.nil? && [:datetime, :time].include?(column.column.type)) end end + + module HumanConditionHelpers + def active_scaffold_human_condition_date_bridge(column, value) + case value[:opt] + when 'RANGE' + "#{column.active_record_class.human_attribute_name(column.name)} = #{as_(value[:range].downcase).downcase}" + when 'PAST', 'FUTURE' + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{as_(value[:number])} #{as_(value[:unit].downcase)}" + else + from, to = controller.class.date_bridge_from_to(column, value) + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '- ' + I18n.l(to) : ''}" + end + end + end module Finder module ClassMethods @@ -115,19 +129,6 @@ def date_bridge_from_to_for_range(column, value) end end end - - def human_condition_for_date_bridge_type(column, value) - case value[:opt] - when 'RANGE' - "#{column.active_record_class.human_attribute_name(column.name)} = #{as_(value[:range]).downcase}" - when 'PAST', 'FUTURE' - "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt]).downcase} #{as_(value[:number])} #{as_(value[:unit]).downcase}" - else - from, to = date_bridge_from_to(column, value) - "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt]).downcase} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '-' + I18n.l(to) : ''}" - end - end - end end end diff --git a/lib/active_scaffold/helpers/human_condition_helpers.rb b/lib/active_scaffold/helpers/human_condition_helpers.rb index 7e3825fa4a..7ab504dda3 100644 --- a/lib/active_scaffold/helpers/human_condition_helpers.rb +++ b/lib/active_scaffold/helpers/human_condition_helpers.rb @@ -5,13 +5,13 @@ module HumanConditionHelpers def active_scaffold_human_condition_for(column) value = field_search_params[column.name] + search_ui = column.search_ui + search_ui ||= column.column.type if column.column if override_human_condition_column?(column) send(override_human_condition_column(column), value, {}) - elsif column.search_ui and override_human_condition?(column.search_ui) + elsif search_ui and override_human_condition?(column.search_ui) send(override_human_condition(column.search_ui), column, value) else - search_ui = column.search_ui - search_ui ||= column.column.type if column.column case search_ui when :integer, :decimal, :float "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{format_number_value(controller.class.condition_value_for_numeric(column, value[:from]), column.options)} #{value[:opt] == 'BETWEEN' ? '- ' + format_number_value(controller.class.condition_value_for_numeric(column, value[:to]), column.options).to_s : ''}" From 9f2000ccc0c27718d70e69b7080a7d33eb981999 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 11 Oct 2010 16:26:30 +0200 Subject: [PATCH 0733/2024] updated de localization --- lib/active_scaffold/locale/de.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 5db12dbf37..fa4f42589f 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -70,8 +70,8 @@ :this_year => 'Dieses Jahr', :prev_year => 'Letztes Jahr', :next_year => 'Nächstes Jahr', - :past => 'Letzten..', - :future => 'Nächsten..', + :past => 'Letzten', + :future => 'Nächsten', :range => 'Spanne', :days => 'Tage', :weeks => 'Wochen', From 04a6fdb89671b7a2d48689bd1854fadff17d0310 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 11 Oct 2010 17:19:46 +0200 Subject: [PATCH 0734/2024] Bugfix: show to controls for range searches if option = BETWEEN --- lib/active_scaffold/helpers/search_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 7c4c5dc5df..ff889a2260 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -136,7 +136,7 @@ def active_scaffold_search_range(column, options) html << ' ' << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(:id => options[:id], :size => 10)) html << ' ' << content_tag(:span, (' - ' + text_field_tag("#{options[:name]}[to]", to_value, active_scaffold_input_text_options(:id => "#{options[:id]}_to", :size => 10))).html_safe, - :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => "display:none") + :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => "display:#{(opt_value == 'BETWEEN') ? '' : 'none'}") html end alias_method :active_scaffold_search_integer, :active_scaffold_search_range From 51d70de0fad6bb2f10145b8a46134a3241daf2e4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 12 Oct 2010 16:46:28 +0200 Subject: [PATCH 0735/2024] Bugfix: fixe npe in condition_value_for_numeric --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 83b75742d3..d31a20439d 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -110,6 +110,7 @@ def condition_value_for_datetime(value, conversion = :to_time) end def condition_value_for_numeric(column, value) + return value if value.nil? value = i18n_number_to_native_format(value) if [:i18n_number, :currency].include?(column.options[:format]) case (column.search_ui || column.column.type) when :integer then value.to_i rescue value ? 1 : 0 @@ -270,7 +271,6 @@ def find_page(options = {}) # Converts count to an integer if ActiveRecord returned an OrderedHash # that happens when finder_options contains a :group key count = count.length if count.is_a? ActiveSupport::OrderedHash - finder_options.merge! :includes => full_includes # we build the paginator differently for method- and sql-based sorting From 9a8e3176f4a996d64dcd6d3b062375fe4148ab79 Mon Sep 17 00:00:00 2001 From: aladin <aladin@citrin.ch> Date: Thu, 14 Oct 2010 17:43:45 +0800 Subject: [PATCH 0736/2024] Fixes bug when primary key is not :id --- lib/active_scaffold/attribute_params.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 0600f7f642..1ce6667973 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -135,24 +135,26 @@ def column_value_from_param_value(parent_record, column, value) end end - # Attempts to create or find an instance of klass (which must be an ActiveRecord object) from the + # Attempts to create or find an instance of klass (which must be an ActiveRecord object) from the # request parameters given. If params[:id] exists it will attempt to find an existing object # otherwise it will build a new one. def find_or_create_for_params(params, parent_column, parent_record) current = parent_record.send(parent_column.name) klass = parent_column.association.klass + pk = klass.primary_key.to_sym return nil if parent_column.show_blank_record?(current) and attributes_hash_is_empty?(params, klass) - if params.has_key? :id + if params.has_key? pk # modifying the current object of a singular association - if current and current.is_a? ActiveRecord::Base and current.id.to_s == params[:id] + pk_val = params[pk] + if current and current.is_a? ActiveRecord::Base and current.id.to_s == pk_val return current # modifying one of the current objects in a plural association - elsif current and current.respond_to?(:any?) and current.any? {|o| o.id.to_s == params[:id]} - return current.detect {|o| o.id.to_s == params[:id]} + elsif current and current.respond_to?(:any?) and current.any? {|o| o.id.to_s == pk_val} + return current.detect {|o| o.id.to_s == pk_val} # attaching an existing but not-current object else - return klass.find(params[:id]) + return klass.find(pk_val) end else if klass.authorized_for?(:crud_type => :create) @@ -164,7 +166,6 @@ def find_or_create_for_params(params, parent_column, parent_record) end end end - # Determines whether the given attributes hash is "empty". # This isn't a literal emptiness - it's an attempt to discern whether the user intended it to be empty or not. def attributes_hash_is_empty?(hash, klass) From 9e13c3f5148eec78ab069a5e8ce769f7afe3fa27 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 14 Oct 2010 20:23:03 +0200 Subject: [PATCH 0737/2024] Bugfix: jquery create-associated_record_form used prototype code; issue 14 reported by clyfe --- frontends/default/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 1f840a637c..d13eb30e21 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -622,7 +622,7 @@ var ActiveScaffold = { if (typeof(element) == 'string') element = '#' + element; var element = $(element); if (options.singular == false) { - if (!(options.id && $(options.id))) { + if (!(options.id && $('#' + options.id).size() > 0)) { element.append(content); } } else { From deb7aaea9ca3f0830842cf2d325a8b4037f1c3d7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 14 Oct 2010 20:30:48 +0200 Subject: [PATCH 0738/2024] Bugfix: Habtm nested RJS error optoins is undefined; issue 16 reported by clyfe --- frontends/default/views/add_existing.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/add_existing.js.rjs b/frontends/default/views/add_existing.js.rjs index 88cabc8239..a0d364f50c 100644 --- a/frontends/default/views/add_existing.js.rjs +++ b/frontends/default/views/add_existing.js.rjs @@ -1,5 +1,5 @@ new_row = render :partial => 'list_record', :locals => {:record => @record} -page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}');" +page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}', #{{:insert_at => :top}.to_json});" page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} if (form_stays_open = true) From 03884cd4f51f3e1bc26549275351cbbf2f9633bb Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <clyfe@ubuntu.(none)> Date: Sat, 16 Oct 2010 02:53:54 -0700 Subject: [PATCH 0739/2024] Fix multiple record_selects (of recordselect plugin bridge) Fix action links and double-eval on prototype version --- .../javascripts/jquery/active_scaffold.js | 11 ++++++++++- .../javascripts/prototype/active_scaffold.js | 17 ++++++++++++++--- .../views/_form_association_footer.html.erb | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index d13eb30e21..514c20572a 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -655,7 +655,16 @@ var ActiveScaffold = { $.post(url.append_params(reorder_params)); } }); - } + }, + + record_select_onselect: function(edit_associated_url, active_scaffold_id, id){ + $.ajax({ + url: edit_associated_url.split('--ID--').join(id), + error: function(xhr, textStatus, errorThrown){ + ActiveScaffold.report_500_response(active_scaffold_id) + } + }); + } } /* diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 098c870cb5..70671b6eec 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -65,10 +65,10 @@ document.observe("dom:loaded", function() { var action_link = ActiveScaffold.ActionLink.get(event.findElement()); if (action_link && event.memo && event.memo.request) { if (action_link.position) { - action_link.insert(event.memo.request.responseText); + action_link.insert(event.memo.request.transport.responseText); if (action_link.hide_target) action_link.target.hide(); } else { - event.memo.request.evalResponse(); + //event.memo.request.evalResponse(); // (clyfe) prototype evals the response by itself checking headers, this would eval twice action_link.enable(); } event.stop(); @@ -517,8 +517,19 @@ var ActiveScaffold = { } else { this.replace_html(element, content); } + }, + + record_select_onselect: function(edit_associated_url, active_scaffold_id, id){ + new Ajax.Request( + edit_associated_url.sub('--ID--', id), { + asynchronous: true, + evalScripts: true, + onFailure: function(){ + ActiveScaffold.report_500_response(active_scaffold_id.to_json) + } + } + ); } - } /* diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index 71b69585da..7a8071278d 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -27,7 +27,7 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as <% if show_add_existing -%> <% if remote_controller and remote_controller.respond_to? :uses_record_select? and remote_controller.uses_record_select? -%> - <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "new Ajax.Request(#{edit_associated_url.to_json}.sub('--ID--', id), {asynchronous: true, evalScripts: true, onFailure: function(){ActiveScaffold.report_500_response(#{active_scaffold_id.to_json})}});" -%> + <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "ActiveScaffold.record_select_onselect(#{edit_associated_url.to_json}, #{active_scaffold_id.to_json}, id);" -%> <% else -%> <% select_options = options_for_select(options_for_association(column.association)) add_existing_id = "#{sub_form_id(:association => column.name)}-add-existing" %> From 622bfc46d1ada696655d18a01daa809b4eb6a701 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <clyfe@ubuntu.(none)> Date: Sat, 16 Oct 2010 03:21:24 -0700 Subject: [PATCH 0740/2024] enable bridges --- environment.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/environment.rb b/environment.rb index 1a85eede0a..40bca2ce74 100644 --- a/environment.rb +++ b/environment.rb @@ -12,5 +12,6 @@ ActiveRecord::Base.class_eval {include ActiveRecordPermissions::ModelUserAccess::Model} ActiveRecord::Base.class_eval {include ActiveRecordPermissions::Permissions} +require "#{File.dirname __FILE__}/lib/active_scaffold/bridges/bridge.rb" I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'lib', 'active_scaffold', 'locale', '*.{rb,yml}')] -#ActiveScaffold.js_framework = :jquery +ActiveScaffold.js_framework = :jquery From 4c5b18db699c81a76d3bb22978ea3fa7712d3370 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <clyfe@ubuntu.(none)> Date: Sat, 16 Oct 2010 03:22:29 -0700 Subject: [PATCH 0741/2024] Feature: creater carrierwave bridge --- .../bridges/carrierwave/bridge.rb | 7 ++++ .../carrierwave/lib/carrierwave_bridge.rb | 38 +++++++++++++++++++ .../lib/carrierwave_bridge_helpers.rb | 26 +++++++++++++ .../bridges/carrierwave/lib/form_ui.rb | 28 ++++++++++++++ .../bridges/carrierwave/lib/list_ui.rb | 17 +++++++++ 5 files changed, 116 insertions(+) create mode 100644 lib/active_scaffold/bridges/carrierwave/bridge.rb create mode 100644 lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb create mode 100644 lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb create mode 100644 lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb create mode 100644 lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb diff --git a/lib/active_scaffold/bridges/carrierwave/bridge.rb b/lib/active_scaffold/bridges/carrierwave/bridge.rb new file mode 100644 index 0000000000..84364fa70e --- /dev/null +++ b/lib/active_scaffold/bridges/carrierwave/bridge.rb @@ -0,0 +1,7 @@ +ActiveScaffold::Bridges.bridge "CarrierWave" do + install do + require File.join(File.dirname(__FILE__), "lib/form_ui") + require File.join(File.dirname(__FILE__), "lib/list_ui") + ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Carrierwave::Lib::CarrierwaveBridge + end +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb new file mode 100644 index 0000000000..9b9ba34213 --- /dev/null +++ b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb @@ -0,0 +1,38 @@ +module ActiveScaffold + module Bridges + module Carrierwave + module Lib + module CarrierwaveBridge + def initialize_with_carrierwave(model_id) + initialize_without_carrierwave(model_id) + return unless self.model.respond_to?(:uploaders) && self.model.uploaders.present? + + self.update.multipart = true + self.create.multipart = true + + self.model.uploaders.keys.each do |field| + configure_carrierwave_field(field.to_sym) + # define the "delete" helper for use with active scaffold, unless it's already defined + ActiveScaffold::Bridges::Carrierwave::Lib::CarrierwaveBridgeHelpers.generate_delete_helper(self.model, field) + end + end + + def self.included(base) + base.alias_method_chain :initialize, :carrierwave + end + + private + def configure_carrierwave_field(field) + self.columns << field + self.columns[field].form_ui ||= :carrierwave + self.columns[field].params.add "delete_#{field}" + +# [:file_name, :content_type, :file_size, :updated_at].each do |f| +# self.columns.exclude("#{field}_#{f}".to_sym) +# end + end + end + end + end + end +end diff --git a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb new file mode 100644 index 0000000000..8720764cfd --- /dev/null +++ b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb @@ -0,0 +1,26 @@ +module ActiveScaffold + module Bridges + module Carrierwave + module Lib + module CarrierwaveBridgeHelpers + mattr_accessor :thumbnail_style + self.thumbnail_style = :thumbnail + + def self.generate_delete_helper(klass, field) + klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("delete_#{field}=") + attr_reader :delete_#{field} + + def delete_#{field}=(value) + value = (value == "true") if String === value + return unless value + + # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! + self.remove_#{field}! unless new_record? + end + EOF + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb new file mode 100644 index 0000000000..a334d354ec --- /dev/null +++ b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb @@ -0,0 +1,28 @@ +module ActiveScaffold + module Helpers + module FormColumnHelpers + def active_scaffold_input_carrierwave(column, options) + options = active_scaffold_input_text_options(options) + input = file_field(:record, column.name, options) + carrierwave = @record.send("#{column.name}") + if carrierwave.current_path.present? && File.exist?(carrierwave.current_path) + if ActiveScaffold.js_framework == :jquery + js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;"; + else + js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;"; + end + + content = active_scaffold_column_carrierwave(column, @record) + content_tag(:div, + (content + " | " + + hidden_field(:record, "delete_#{column.name}", :value => "false") + + content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}) + ).html_safe + ) + content_tag(:div, input, :style => "display: none") + else + input + end + end + end + end +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb b/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb new file mode 100644 index 0000000000..cb6a1218c1 --- /dev/null +++ b/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb @@ -0,0 +1,17 @@ +module ActiveScaffold + module Helpers + module ListColumnHelpers + def active_scaffold_column_carrierwave(column, record) + carrierwave = record.send("#{column.name}") + return nil unless carrierwave.current_path.present? && File.exist?(carrierwave.current_path) + thumbnail_style = ActiveScaffold::Bridges::Carrierwave::Lib::CarrierwaveBridgeHelpers.thumbnail_style + content = if carrierwave.versions.keys.include?(thumbnail_style) + image_tag(carrierwave.url(thumbnail_style), :border => 0).html_safe + else + record.send(record.send(:_mounter, column.name).send(:serialization_column)) + end + link_to(content, carrierwave.url, :target => '_blank') + end + end + end +end From ca3fb608bc9d18f2cc719338a07d1cf42a6124f8 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <clyfe@ubuntu.(none)> Date: Sat, 16 Oct 2010 10:59:11 -0700 Subject: [PATCH 0742/2024] allow carrierwave bridge to work with other storages besides FS --- .../bridges/carrierwave/lib/form_ui.rb | 25 ++++++++++++------- .../bridges/carrierwave/lib/list_ui.rb | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb index a334d354ec..4f4fe26bf0 100644 --- a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +++ b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb @@ -5,20 +5,27 @@ def active_scaffold_input_carrierwave(column, options) options = active_scaffold_input_text_options(options) input = file_field(:record, column.name, options) carrierwave = @record.send("#{column.name}") - if carrierwave.current_path.present? && File.exist?(carrierwave.current_path) + if carrierwave.file.present? && !carrierwave.file.empty? if ActiveScaffold.js_framework == :jquery js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;"; else js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;"; end - - content = active_scaffold_column_carrierwave(column, @record) - content_tag(:div, - (content + " | " + - hidden_field(:record, "delete_#{column.name}", :value => "false") + - content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}) - ).html_safe - ) + content_tag(:div, input, :style => "display: none") + + hidden_field_options = { + :name => options[:name].gsub(/\[#{column.name}\]$/, "[delete_#{column.name}]"), + :id => options[:id] + '_delete', + :value => "false" + } + + content_tag( :div, + content_tag(:div, ( + get_column_value(@record, column) + " | " + + hidden_field(:record, "delete_#{column.name}", hidden_field_options) + + content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}) + ).html_safe + ) + content_tag(:div, input, :style => "display: none") + ) else input end diff --git a/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb b/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb index cb6a1218c1..a6129d56d6 100644 --- a/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +++ b/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb @@ -3,7 +3,7 @@ module Helpers module ListColumnHelpers def active_scaffold_column_carrierwave(column, record) carrierwave = record.send("#{column.name}") - return nil unless carrierwave.current_path.present? && File.exist?(carrierwave.current_path) + return nil unless carrierwave.file.present? && !carrierwave.file.empty? thumbnail_style = ActiveScaffold::Bridges::Carrierwave::Lib::CarrierwaveBridgeHelpers.thumbnail_style content = if carrierwave.versions.keys.include?(thumbnail_style) image_tag(carrierwave.url(thumbnail_style), :border => 0).html_safe From c753b43cf87f03f64c2d883a311ff540d581cb38 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 18 Oct 2010 12:43:50 +0200 Subject: [PATCH 0743/2024] Check condition_for_{name}_column even when value is blank --- lib/active_scaffold/finder.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 136b0c1437..d1734a3973 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -34,12 +34,13 @@ def create_conditions_for_columns(tokens, columns, text_search = :full) # TODO: this should reside on the column, not the controller def condition_for_column(column, value, text_search = :full) like_pattern = like_pattern(text_search) + if self.respond_to?("condition_for_#{column.name}_column") + return self.send("condition_for_#{column.name}_column", column, value, like_pattern) + end return unless column and column.search_sql and not value.blank? search_ui = column.search_ui || column.column.try(:type) begin - if self.respond_to?("condition_for_#{column.name}_column") - self.send("condition_for_#{column.name}_column", column, value, like_pattern) - elsif search_ui && self.respond_to?("condition_for_#{search_ui}_type") + if search_ui && self.respond_to?("condition_for_#{search_ui}_type") self.send("condition_for_#{search_ui}_type", column, value, like_pattern) else case search_ui From 0fec4efbb7ad5999215530968607e4345a24464e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 18 Oct 2010 21:44:26 +0200 Subject: [PATCH 0744/2024] default js library should be still prototype --- environment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.rb b/environment.rb index 40bca2ce74..b8547f3f21 100644 --- a/environment.rb +++ b/environment.rb @@ -14,4 +14,4 @@ require "#{File.dirname __FILE__}/lib/active_scaffold/bridges/bridge.rb" I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'lib', 'active_scaffold', 'locale', '*.{rb,yml}')] -ActiveScaffold.js_framework = :jquery +#ActiveScaffold.js_framework = :jquery From 479d18faf8324b9d0088d04da45eac8c0617b519 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 18 Oct 2010 21:49:46 +0200 Subject: [PATCH 0745/2024] fixed interpolation syntax error (issue 13 by MikeBlyth) --- lib/active_scaffold/locale/de.rb | 4 ++-- lib/active_scaffold/locale/en.rb | 4 ++-- lib/active_scaffold/locale/fr.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index fa4f42589f..278895a45d 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -92,8 +92,8 @@ :errors => { :template => { :header => { - :one => "Konnte {{model}} nicht speichern: ein Fehler.", - :other => "Konnte {{model}} nicht speichern: {{count}} Fehler." + :one => "Konnte %{model} nicht speichern: ein Fehler.", + :other => "Konnte %{model} nicht speichern: %{count} Fehler." }, :body => "Bitte überprüfen Sie die folgenden Felder:" } diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 5a643dd647..c362e58d3f 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -97,8 +97,8 @@ :errors => { :template => { :header => { - :one => "1 error prohibited this {{model}} from being saved.", - :other => "{{count}} errors prohibited this {{model}} from being saved" + :one => "1 error prohibited this %{model} from being saved.", + :other => "%{count} errors prohibited this %{model} from being saved" }, :body => "There were problems with the following fields:" } diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 41d741e4ef..fdac048080 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -92,8 +92,8 @@ :errors => { :template => { :header => { - :one => "1 error prohibited this {{model}} from being saved.", - :other => "{{count}} errors prohibited this {{model}} from being saved" + :one => "1 error prohibited this %{model} from being saved.", + :other => "%{count} errors prohibited this %{model} from being saved" }, :body => "There were problems with the following fields:" } From 1046f6677743ec4870c2c54bb7716bf289197f81 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <clyfe@ubuntu.(none)> Date: Wed, 20 Oct 2010 07:11:58 -0700 Subject: [PATCH 0746/2024] partial fix for ugly list-actions-square when list empty --- .../default/views/_list_messages.html.erb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index e6a7c098d9..52d4c8c9f5 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -16,17 +16,17 @@ </p> </td> <% if active_scaffold_config.list.show_search_reset && @filtered -%> - <% search_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :member, :position => false) - action_links = ActiveScaffold::DataStructures::ActionLinks.new - record = active_scaffold_config.model.new - record.id = 0 - action_links.add(search_link) -%> - <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links} %> + <% search_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :member, :position => false) + action_links = ActiveScaffold::DataStructures::ActionLinks.new + record = active_scaffold_config.model.new + record.id = 0 + action_links.add(search_link) -%> + <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links} %> <% else %> - <td class='actions'></td> + <td class='actions'><%= '<p class="empty-message"> </p>'.html_safe if @page.items.empty? %></td> <% end -%> - + </tr> </tbody> - + From f64a5654e9ae711d0a32df4d2add232df4a22cfa Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <clyfe@ubuntu.(none)> Date: Wed, 20 Oct 2010 07:13:56 -0700 Subject: [PATCH 0747/2024] allow `render 'some_string'`, the new rails3 magic syntax, this still needs work --- lib/extensions/action_view_rendering.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/extensions/action_view_rendering.rb b/lib/extensions/action_view_rendering.rb index 7fd7830197..87fdf7790d 100644 --- a/lib/extensions/action_view_rendering.rb +++ b/lib/extensions/action_view_rendering.rb @@ -69,18 +69,20 @@ def render_with_active_scaffold(*args, &block) url = url_for(url_options) link_to(remote_controller.to_s, url, {:remote => true, :id => id}) << if ActiveScaffold.js_framework == :prototype - javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true});") - elsif ActiveScaffold.js_framework == :jquery - javascript_tag("$('##{id}').load('#{url}');") - end + javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true});") + elsif ActiveScaffold.js_framework == :jquery + javascript_tag("$('##{id}').load('#{url}');") + end end end else options = args.first - @last_view = {:view => options[:partial], :is_template => false} if options[:partial] - @last_view = {:view => options[:template], :is_template => !!options[:template]} if @last_view.nil? && options[:template] - @last_view[:locals] = options[:locals] if !@last_view.nil? && options[:locals] + if options.is_a?(Hash) + @last_view = {:view => options[:partial], :is_template => false} if options[:partial] + @last_view = {:view => options[:template], :is_template => !!options[:template]} if @last_view.nil? && options[:template] + @last_view[:locals] = options[:locals] if !@last_view.nil? && options[:locals] + end render_without_active_scaffold(*args, &block) end end From 1b11a791de9d33319b5cc2b0a28d46bfde653f0b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 20 Oct 2010 19:08:39 +0200 Subject: [PATCH 0748/2024] Bugfix: if controller param value is a symbol --- lib/active_scaffold/helpers/controller_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 939a479aa7..beeba32134 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -16,7 +16,7 @@ def params_for(options = {}) unless @params_for @params_for = {} params.select { |key, value| blacklist.exclude? key.to_sym if key }.each {|key, value| @params_for[key.to_sym] = value.duplicable? ? value.clone : value} - @params_for[:controller] = '/' + @params_for[:controller] unless @params_for[:controller].first(1) == '/' # for namespaced controllers + @params_for[:controller] = '/' + @params_for[:controller].to_s unless @params_for[:controller].to_s.first(1) == '/' # for namespaced controllers @params_for.delete(:id) if @params_for[:id].nil? end @params_for.merge(options) From 5d3ff1b2d5bcc9c62fdc936f0991a3927ecddbaf Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 20 Oct 2010 19:24:18 +0200 Subject: [PATCH 0749/2024] Bugfix: add missing set_opened method for record action_link --- .../default/javascripts/prototype/active_scaffold.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 70671b6eec..6cd919e79c 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -728,7 +728,7 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ this.adapter = element; this.adapter.addClassName('as_adapter'); this.adapter.store('action_link', this); - }, + } }); /** @@ -804,6 +804,16 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra if (item.url != this.url) return; item.tag.addClassName('disabled'); }.bind(this)); + }, + + set_opened: function() { + if (this.position == 'after') { + this.set_adapter(this.target.next()); + } + else if (this.position == 'before') { + this.set_adapter(this.target.previous()); + } + this.disable(); } }); From 4c06e83aaa5e9d505c88933dd03ac5c34397aa86 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 21 Oct 2010 09:09:08 +0200 Subject: [PATCH 0750/2024] Bugfix: inplace_edit in nested_views (issue 21 by MikeBlyth) --- frontends/default/views/update_column.js.rjs | 2 +- lib/active_scaffold/actions/update.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/update_column.js.rjs b/frontends/default/views/update_column.js.rjs index 7a5d4ed248..1d452e3bf6 100644 --- a/frontends/default/views/update_column.js.rjs +++ b/frontends/default/views/update_column.js.rjs @@ -1,4 +1,4 @@ -column_span_id = element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column]) +column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column]) unless controller.send :successful? page.call 'alert', @record.errors.full_messages(active_scaffold_config).join("\n") @record.reload diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 22483d0bbf..4d79fb23a3 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -20,7 +20,7 @@ def update # for inline (inlist) editing def update_column do_update_column - render :action => 'update_column' + render :action => 'update_column', :locals => {:column_span_id => params[:editor_id] || params[:editorId]} end protected From e5ef1942f2d83822f64287734c2108f2ebf16805 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 21 Oct 2010 12:23:22 +0200 Subject: [PATCH 0751/2024] Bugfix: if order option is specified for association, use it as default_sorting in nested view --- .../default/views/_list_column_headings.html.erb | 2 +- lib/active_scaffold/actions/nested.rb | 9 ++++++--- lib/active_scaffold/config/list.rb | 13 ++++++++++++- lib/active_scaffold/data_structures/nested_info.rb | 14 +++++++++++++- lib/active_scaffold/data_structures/sorting.rb | 5 +++++ 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/frontends/default/views/_list_column_headings.html.erb b/frontends/default/views/_list_column_headings.html.erb index 94b7120ac6..e2ad42c2d5 100644 --- a/frontends/default/views/_list_column_headings.html.erb +++ b/frontends/default/views/_list_column_headings.html.erb @@ -1,7 +1,7 @@ <% sorting = active_scaffold_config.list.user.sorting sorting_stages = ['reset', 'ASC', 'DESC'] -default_sorting = active_scaffold_config.list.sorting +default_sorting = active_scaffold_config.list.user.default_sorting default_sorting_stages = ['ASC', 'DESC'] -%> <% columns.each do |column| -%> diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index b0aa3ad940..a118736068 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -7,7 +7,7 @@ def self.included(base) base.module_eval do before_filter :register_constraints_with_action_columns before_filter :set_nested - before_filter :set_nested_list_label + before_filter :configure_nested include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? {|a| a.macro == :has_and_belongs_to_many} end base.before_filter :include_habtm_actions @@ -38,13 +38,16 @@ def set_nested end end - def set_nested_list_label + def configure_nested if nested? active_scaffold_session_storage[:list][:label] = if nested.belongs_to? - as_(:nested_of_model, :nested_model => active_scaffold_config.model.model_name.human, :parent_model => nested_parent_record.to_label) + as_(:nested_of_model, :nested_model => active_scaffold_config.model.model_name.human, :parent_model => nested_parent_record.to_label) else as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => nested_parent_record.to_label) end + if nested.sorted? + active_scaffold_config.list.user.nested_default_sorting = {:table_name => active_scaffold_config.model.model_name, :default_sorting => nested.default_sorting} + end end end diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index d5440cc8a4..4cd88ff7a4 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -141,6 +141,17 @@ def page=(value = nil) @session['page'] = value end + attr_reader :nested_default_sorting + + def nested_default_sorting=(options) + @nested_default_sorting ||= @conf.sorting.clone + @nested_default_sorting.set_nested_sorting(options[:table_name], options[:default_sorting]) + end + + def default_sorting + nested_default_sorting.nil? ? @conf.sorting : nested_default_sorting + end + def sorting # we want to store as little as possible in the session, but we want to return a Sorting data structure. so we recreate it each page load based on session data. @session['sort'] = [@params['sort'], @params['sort_direction']] if @params['sort'] and @params['sort_direction'] @@ -151,7 +162,7 @@ def sorting sorting.set(*@session['sort']) return sorting else - return @conf.sorting + return default_sorting end end diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index d1a64297f1..e76d43e1f9 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -41,7 +41,11 @@ def belongs_to? def readonly? false - end + end + + def sorted? + false + end end class NestedInfoAssociation < NestedInfo @@ -66,6 +70,14 @@ def readonly? association.options.has_key? :through end end + + def sorted? + association.options.has_key? :order + end + + def default_sorting + association.options[:order] + end protected diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 2a1b58a37b..f4724e4b9a 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -21,6 +21,11 @@ def set_default_sorting(model) set(model.primary_key, 'ASC') if model.column_names.include?(model.primary_key) end end + + def set_nested_sorting(table_name, order_clause) + clear + set_sorting_from_order_clause(order_clause, table_name) + end # add a clause to the sorting, assuming the column is sortable def add(column_name, direction = nil) From 23d71851a90cb91f7a225fc42eb94d18438a6b9f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 22 Oct 2010 09:16:12 +0200 Subject: [PATCH 0752/2024] Upgrade to latest version of http://github.com/vhochstein/prototype-ujs !!update your rails.js file if you are using prototype!! --- frontends/default/javascripts/prototype/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 6cd919e79c..8ea8bf6c30 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -12,7 +12,7 @@ if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFu document.observe("dom:loaded", function() { - document.on('ajax:loading', 'form.as_form', function(event) { + document.on('ajax:create', 'form.as_form', function(event) { var source = event.findElement(); var as_form = event.findElement('form'); if (source.nodeName.toUpperCase() == 'INPUT' && source.readAttribute('type') == 'button') { From e94848c934c563ea6edf1d403c9cbbf92916db9b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 22 Oct 2010 09:43:33 +0200 Subject: [PATCH 0753/2024] Bugfix: prototype hide_empty_message should hide all elements including class empty_message --- frontends/default/javascripts/prototype/active_scaffold.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 8ea8bf6c30..6fbe9d1f0f 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -299,8 +299,8 @@ var ActiveScaffold = { }, hide_empty_message: function(tbody) { if (this.records_for(tbody).length != 0) { - var empty_message_node = $(tbody).up().down('tbody.messages p.empty-message') - if (empty_message_node) empty_message_node.hide(); + var empty_message_nodes = $(tbody).up().select('tbody.messages p.empty-message') + empty_message_nodes.invoke('hide'); } }, reload_if_empty: function(tbody, url) { From 262ac616d06946eabd950fb648a0528c449e172f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 25 Oct 2010 13:09:30 +0200 Subject: [PATCH 0754/2024] Bugfix: npe if resetting field_search with ruby 1.9.2 --- lib/active_scaffold/actions/field_search.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index 27fbbaf9e8..b85c2701bf 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -20,6 +20,7 @@ def show_search def store_search_params_into_session set_field_search_default_params(active_scaffold_config.field_search.default_params) unless active_scaffold_config.field_search.default_params.nil? super + active_scaffold_session_storage[:search] = nil if search_params.is_a?(String) end def set_field_search_default_params(default_params) From 73f107b06742c711d28aa6b388c2272a4736762d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 25 Oct 2010 14:09:01 +0200 Subject: [PATCH 0755/2024] bugfix: use proc instead of lambda for ruby 1.9.2 --- lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb b/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb index 66408acbda..8b6cbb08b3 100644 --- a/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +++ b/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb @@ -20,7 +20,7 @@ module AncestryBridge module FormColumnHelpers def active_scaffold_input_ancestry(column, options) select_options = [] - traverse_ancestry = lambda do|key, value| + traverse_ancestry = proc do|key, value| unless key == @record select_options << ["#{'__' * key.depth}#{key.to_label}", key.id] value.each(&traverse_ancestry) if value.is_a?(Hash) && !value.empty? From 3de214d26629b5715b69e85bc5414a68b005115d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 25 Oct 2010 15:31:49 +0200 Subject: [PATCH 0756/2024] base_form partial might be called with a form body partial name --- frontends/default/views/_base_form.html.erb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index 3708662506..39c9b6c29b 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -1,6 +1,7 @@ -<% url_options = params_for(:action => form_action) -%> -<% xhr ||= request.xhr? -%> -<% as_action_config = active_scaffold_config.send(form_action) -%> +<% url_options = params_for(:action => form_action) + xhr ||= request.xhr? + as_action_config = active_scaffold_config.send(form_action) + body_partial ||= 'form' %> <%= options = {:onsubmit => onsubmit, :id => element_form_id(:action => form_action), @@ -19,13 +20,15 @@ end -%> <div id="<%= element_messages_id(:action => form_action) %>" class="messages-container"> <% if request.xhr? -%> - <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> + <% if @record -%> + <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> + <% end %> <% else -%> <%= render :partial => 'form_messages' %> <% end -%> </div> - <%= render :partial => 'form', :locals => { :columns => as_action_config.columns } %> + <%= render :partial => body_partial, :locals => { :columns => as_action_config.columns } %> <p class="form-footer"> <%= submit_tag as_(form_action), :class => "submit" %> From dc806c3cc4e3bbc74ffb58436b8a73e8886eac1f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 25 Oct 2010 16:32:12 +0200 Subject: [PATCH 0757/2024] base_form: url_options might be set via locals hash --- frontends/default/views/_base_form.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index 39c9b6c29b..474079f0fa 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -1,5 +1,5 @@ -<% url_options = params_for(:action => form_action) - xhr ||= request.xhr? +<% url_options ||= params_for(:action => form_action) + xhr = request.xhr? if xhr.nil? as_action_config = active_scaffold_config.send(form_action) body_partial ||= 'form' %> <%= From 4eb87fd49060a5fb36012ff313aacad40b806083 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 26 Oct 2010 15:57:32 +0200 Subject: [PATCH 0758/2024] added list_columns helper --- frontends/default/views/_list.html.erb | 2 +- frontends/default/views/_list_calculations.html.erb | 2 +- frontends/default/views/_list_record.html.erb | 2 +- lib/active_scaffold/actions/list.rb | 7 ++++++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index 89102f2b1b..840448dd21 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -1,7 +1,7 @@ <table cellpadding="0" cellspacing="0"> <thead> <tr> - <% columns = active_scaffold_config.list.columns.collect_visible %> + <% columns = list_columns %> <%= render :partial => 'list_column_headings', :locals => {:columns => columns} %> </tr> </thead> diff --git a/frontends/default/views/_list_calculations.html.erb b/frontends/default/views/_list_calculations.html.erb index 5dcbad0184..816356513c 100644 --- a/frontends/default/views/_list_calculations.html.erb +++ b/frontends/default/views/_list_calculations.html.erb @@ -1,5 +1,5 @@ <% display_class = ( @records.kind_of?(Array) ? @records.first : @records ) - columns ||= active_scaffold_config.list.columns.collect_visible -%> + columns ||= list_columns -%> <tr id="<%= active_scaffold_calculations_id %>" class="active-scaffold-calculations"> <% columns.each do |column| -%> <td id="<%= active_scaffold_calculations_id(column) if column.calculation? %>"> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 6f3bb8a5ea..c5f2aeee9f 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -1,6 +1,6 @@ <% record = list_record if list_record # compat with render :partial :collection -columns ||= active_scaffold_config.list.columns.collect_visible +columns ||= list_columns tr_class = cycle("", "even-record") tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class url_options = params_for(:action => :list, :id => record.id) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 04308b8774..1b792b0eb1 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -1,7 +1,8 @@ module ActiveScaffold::Actions module List def self.included(base) - base.before_filter :list_authorized_filter, :only => [:index, :row, :list] + base.before_filter :list_authorized_filter, :only => [:index, :row] + base.helper_method :list_columns end def index @@ -104,5 +105,9 @@ def list_formats def action_update_formats (default_formats + active_scaffold_config.formats).uniq end + + def list_columns + active_scaffold_config.list.columns.collect_visible + end end end From 05cf21bedde84528328bfdf007c721a57d0bf0a6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 27 Oct 2010 12:39:11 +0200 Subject: [PATCH 0759/2024] Bugfix: checkboxes in forms positioned higher than label --- frontends/default/stylesheets/stylesheet.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 52a9a89542..f6b42da3a2 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -644,6 +644,10 @@ padding: 6px 0; float: left; } +.active-scaffold li.form-element dd input[type="checkbox"] { +margin-top: 6px; +} + .active-scaffold .form dd { margin: 0; } From d94cb7e22702aff60ec4a8f9fc74ddf0b764baee Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 27 Oct 2010 15:16:03 +0200 Subject: [PATCH 0760/2024] generalized sortable method --- .../javascripts/jquery/active_scaffold.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 514c20572a..76382bf645 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -644,17 +644,19 @@ var ActiveScaffold = { } }, - sortable: function(element, controller, reorder_params) { + sortable: function(element, controller, options, url_params) { if (typeof(element) == 'string') element = '#' + element; var element = $(element); - reorder_params.authenticity_token = $('meta[name=csrf-param]').attr('content'); - element.sortable({ - update: function(event, ui) { - var url = controller + '/reorder?' + var sortable_options = {}; + if (options.update === true) { + url_params.authenticity_token = $('meta[name=csrf-param]').attr('content'); + sortable_options.update = function(event, ui) { + var url = controller + '/' + options.action + '?' url += $(this).sortable('serialize',{key: encodeURIComponent($(this).attr('id') + '[]'), expression:/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/}); - $.post(url.append_params(reorder_params)); + $.post(url.append_params(url_params)); } - }); + } + element.sortable(sortable_options); }, record_select_onselect: function(edit_associated_url, active_scaffold_id, id){ From 1b6a3beb206667f0596cbdfc28b22956a8fe5821 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 28 Oct 2010 10:41:04 +0200 Subject: [PATCH 0761/2024] Bugfix: Throw translation missing exception if date/time localizations are missing (issue 22 reported by sdr) --- .../bridges/date_picker/lib/datepicker_bridge.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index c90717fec8..f69a870889 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -63,7 +63,7 @@ def self.localization(js_file) end def self.date_options - date_options = I18n.t 'date' + date_options = I18n.translate! 'date' date_picker_options = { :closeText => as_(:close), :prevText => as_(:previous), :nextText => as_(:next), @@ -82,8 +82,8 @@ def self.date_options end def self.datetime_options - rails_time_format = I18n.t 'time.formats.default' - datetime_options = I18n.t 'datetime.prompts' + rails_time_format = I18n.translate! 'time.formats.default' + datetime_options = I18n.translate! 'datetime.prompts' datetime_picker_options = {:ampm => false, :hourText => datetime_options[:hour], :minuteText => datetime_options[:minute], @@ -144,10 +144,10 @@ def to_datepicker_format(rails_format) def datepicker_format_options(column, format, options) if column.form_ui == :date_picker - js_format = to_datepicker_format(I18n.t("date.formats.#{format}")) + js_format = to_datepicker_format(I18n.translate!("date.formats.#{format}")) options['date:dateFormat'] = js_format unless js_format.nil? else - rails_time_format = I18n.t("time.formats.#{format}") + rails_time_format = I18n.translate!("time.formats.#{format}") date_format, time_format = datepicker_split_datetime_format(self.to_datepicker_format(rails_time_format)) options['date:dateFormat'] = date_format unless date_format.nil? unless time_format.nil? From b8769ae75f8f688a3007666f218f5c35b9d868a4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 28 Oct 2010 11:15:11 +0200 Subject: [PATCH 0762/2024] Bugfix: jquery inplace_edit: do not overwrite existing class attribute --- frontends/default/javascripts/jquery/jquery.editinplace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/jquery.editinplace.js b/frontends/default/javascripts/jquery/jquery.editinplace.js index 636d9fe91b..9b2884ac06 100644 --- a/frontends/default/javascripts/jquery/jquery.editinplace.js +++ b/frontends/default/javascripts/jquery/jquery.editinplace.js @@ -308,7 +308,7 @@ $.extend(InlineEditor.prototype, { var clonedNodes = null; if (editorNode.attr('id').length > 0) editorNode.attr('id', editorNode.attr('id') + this.settings.clone_id_suffix); editorNode.attr('name', 'inplace_value'); - editorNode.attr('class', 'editor_field'); + editorNode.addClass('editor_field'); this.setValue(editorNode, this.originalValue); clonedNodes = editorNode; From 9045cf9d41b2dd739bcd45dc2f019f2b95feb6e0 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 28 Oct 2010 12:46:55 +0200 Subject: [PATCH 0763/2024] add localization for config_list plugin --- lib/active_scaffold/locale/de.rb | 2 ++ lib/active_scaffold/locale/en.rb | 2 ++ lib/active_scaffold/locale/fr.rb | 2 ++ 3 files changed, 6 insertions(+) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 278895a45d..22bc133681 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -8,6 +8,8 @@ :cancel => 'Abbrechen', :click_to_edit => 'Zum Editieren anklicken', :close => 'Schliessen', + :config_list => 'Konfigurieren', + :config_list_model => 'Konfiguriere Spalten für %{model}', :create => 'Anlegen', :create_model => 'Lege %{model} an', :create_another => 'Weitere anlegen', diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index c362e58d3f..32008411ea 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -9,6 +9,8 @@ :click_to_edit => 'Click to edit', :click_to_reset => 'Click to reset', :close => 'Close', + :config_list => 'Configure', + :config_list_model => 'Configure Columns for %{model}', :create => 'Create', :create_model => 'Create %{model}', :create_another => 'Create Another %{model}', diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index fdac048080..92937c9867 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -8,6 +8,8 @@ :cancel => 'Annuler', :click_to_edit => 'Cliquer pour éditer', :close => 'Fermer', + :config_list => 'Configure', + :config_list_model => 'Configure Columns for %{model}', :create => 'Créer', :create_model => 'Créer %{model}', :create_another => 'Créer un autre', From 50cedee89eaa3c9a71a45c961759e5d8367ceb45 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 28 Oct 2010 16:49:06 +0200 Subject: [PATCH 0764/2024] improved documentation for nested_auto_open --- lib/active_scaffold/config/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 4cd88ff7a4..aeadf84a5f 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -118,7 +118,7 @@ def always_show_create # might be set to open nested_link automatically in view # conf.nested.add_link(:players) # conf.list.nested_auto_open = {:players => 2} - # will open nested views if there are 2 or less records in view + # will open nested players view if there are 2 or less records in parent attr_accessor :nested_auto_open class UserSettings < UserSettings From 05bbf10ef3d5e40d11c92773d3ade971fef6d9ba Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 29 Oct 2010 09:22:29 +0200 Subject: [PATCH 0765/2024] Bugfix: missing jquery date_picker options in Activescaffold localization, issue 26 reported by sdr --- .../date_picker/lib/datepicker_bridge.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index f69a870889..3206a0542d 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -75,7 +75,13 @@ def self.date_options :dayNamesMin => date_options[:abbr_day_names], :changeYear => true, :changeMonth => true, - }.merge(as_(:date_picker_options)) + } + if as_(:date_picker_options).is_a? Hash + date_picker_options.merge!(as_(:date_picker_options)) + else + Rails.logger.warn "ActiveScaffold: Missing date picker localization for your locale: #{I18n.locale}" + end + js_format = self.to_datepicker_format(date_options[:formats][:default]) date_picker_options[:dateFormat] = js_format unless js_format.nil? date_picker_options @@ -88,7 +94,14 @@ def self.datetime_options :hourText => datetime_options[:hour], :minuteText => datetime_options[:minute], :secondText => datetime_options[:second], - }.merge(as_(:datetime_picker_options)) + } + + if as_(:datetime_picker_options).is_a? Hash + datetime_picker_options.merge!(as_(:datetime_picker_options)) + else + Rails.logger.warn "ActiveScaffold: Missing datetime picker localization for your locale: #{I18n.locale}" + end + date_format, time_format = self.split_datetime_format(self.to_datepicker_format(rails_time_format)) datetime_picker_options[:dateFormat] = date_format unless date_format.nil? unless time_format.nil? From 144c5039ccc747534e00e9985bf123710e47def8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 29 Oct 2010 11:19:33 +0200 Subject: [PATCH 0766/2024] improve detection of missing datepicker options --- .../date_picker/lib/datepicker_bridge.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 3206a0542d..3f54dc7e96 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -76,9 +76,11 @@ def self.date_options :changeYear => true, :changeMonth => true, } - if as_(:date_picker_options).is_a? Hash - date_picker_options.merge!(as_(:date_picker_options)) - else + + begin + as_date_picker_options = I18n.translate! 'active_scaffold.date_picker_options' + date_picker_options.merge!(as_date_picker_options) if as_date_picker_options.is_a? Hash + rescue Rails.logger.warn "ActiveScaffold: Missing date picker localization for your locale: #{I18n.locale}" end @@ -95,10 +97,11 @@ def self.datetime_options :minuteText => datetime_options[:minute], :secondText => datetime_options[:second], } - - if as_(:datetime_picker_options).is_a? Hash - datetime_picker_options.merge!(as_(:datetime_picker_options)) - else + + begin + as_datetime_picker_options = I18n.translate! 'active_scaffold.datetime_picker_options' + datetime_picker_options.merge!(as_datetime_picker_options) if as_datetime_picker_options.is_a? Hash + rescue Rails.logger.warn "ActiveScaffold: Missing datetime picker localization for your locale: #{I18n.locale}" end From 36041033bafb7f1c9594257d3deb9c3943cd712b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 29 Oct 2010 11:20:08 +0200 Subject: [PATCH 0767/2024] remove unnecessary , --- lib/active_scaffold/locale/de.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 22bc133681..fec044a513 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -86,7 +86,7 @@ :weekHeader => 'Wo', :firstDay => 1, :isRTL => false, - :showMonthAfterYear => false, + :showMonthAfterYear => false }, :datetime_picker_options => { :timeText => 'Uhrzeit' From 4b24e42f03edbe8822d6af47963d26811776dee7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 29 Oct 2010 11:20:35 +0200 Subject: [PATCH 0768/2024] update es locale with new keys => needs translation --- lib/active_scaffold/locale/es.yml | 39 ++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index d506b4e25d..2e456b198b 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -8,7 +8,9 @@ es: click_to_edit: 'Pulsa para editar' click_to_reset: 'Pulsa para restaurar' close: 'Cerrar' - create: 'Crear' + config_list: 'Configure' + config_list_model: 'Configure Columns for %{model}' + 'create': 'Crear' create_model: 'Crear %{model}' create_another: 'Crear Otro %{model}' created_model: '%{model} creado' @@ -65,6 +67,41 @@ es: contains: 'Contiene' begins_with: 'Empieza con' ends_with: 'Termina con' + today: 'Today' + yesterday: 'Yesterday' + tomorrow: 'Tommorrow' + this_week: 'This Week' + prev_week: 'Last Week' + next_week: 'Next Week' + this_month: 'This Month' + prev_month: 'Last Month' + next_month: 'Next Month' + this_year: 'This Year' + prev_year: 'Last Year' + next_year: 'Next Year' + past: 'Past' + future: 'Future' + range: 'Range' + days: 'Days' + weeks: 'Weeks' + months: 'Months' + years: 'Years' + optional_attributes: 'Further Options' + null: 'Null' + not_null: 'Not Null' + date_picker_options: + weekHeader: 'Sm' + firstDay: 1 + isRTL: false + showMonthAfterYear: false + datetime_picker_options: + timeText: 'Hora' + errors: + template: + header: + one: "1 error prohibited this %{model} from being saved." + other: "%{count} errors prohibited this %{model} from being saved" + body: "There were problems with the following fields:" # error_messages cant_destroy_record: "No se pudo borrar %{record}" From ba8245de13ca2a7a644fbb958df91f8f4d67b1d9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 29 Oct 2010 11:35:40 +0200 Subject: [PATCH 0769/2024] remove unnecessary characters in es.yml --- lib/active_scaffold/locale/es.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index 2e456b198b..e21a0f2123 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -10,7 +10,7 @@ es: close: 'Cerrar' config_list: 'Configure' config_list_model: 'Configure Columns for %{model}' - 'create': 'Crear' + create: 'Crear' create_model: 'Crear %{model}' create_another: 'Crear Otro %{model}' created_model: '%{model} creado' From df152bd6b4edf5a91507a4f7fdcc4d6a1188facb Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 1 Nov 2010 14:26:35 +0100 Subject: [PATCH 0770/2024] FieldSearch: add option to search x hours, minutes, seconds in the past and future for time columns --- .../bridges/shared/date_bridge.rb | 39 +++++++++++++++++-- lib/active_scaffold/locale/de.rb | 3 ++ lib/active_scaffold/locale/en.rb | 3 ++ lib/active_scaffold/locale/es.yml | 3 ++ lib/active_scaffold/locale/fr.rb | 3 ++ 5 files changed, 47 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index 00069854f8..0689c53eb6 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -35,10 +35,16 @@ def active_scaffold_search_date_bridge_numeric_tag(column, options, current_sear def active_scaffold_search_date_bridge_trend_tag(column, options, current_search) trend_controls = text_field_tag("search[#{column.name}][number]", current_search['number'], :class => 'text-input', :size => 10) << " " << select_tag("search[#{column.name}][unit]", - options_for_select( ActiveScaffold::Finder::DateUnits.collect{|date_unit| [as_(date_unit.downcase.to_sym), date_unit]}, current_search["unit"]), + options_for_select(active_scaffold_search_date_bridge_trend_units(column), current_search["unit"]), :class => 'text-input') content_tag("span", trend_controls.html_safe, :id => "#{options[:id]}_trend", :style => "display:#{(current_search['opt'] == 'PAST' || current_search['opt'] == 'FUTURE') ? '' : 'none'}") end + + def active_scaffold_search_date_bridge_trend_units(column) + options = ActiveScaffold::Finder::DateUnits.collect{|unit| [as_(unit.downcase.to_sym), unit]} + options = ActiveScaffold::Finder::TimeUnits.collect{|unit| [as_(unit.downcase.to_sym), unit]} + options if column_datetime?(column) + options + end def active_scaffold_search_date_bridge_range_tag(column, options, current_search) range_controls = select_tag("search[#{column.name}][range]", @@ -99,10 +105,26 @@ def date_bridge_from_to_for_trend(column, value) case value['opt'] when "PAST" trend_number = [value['number'].to_i, 1].max - return eval("Time.zone.now.beginning_of_#{value['unit'].downcase.singularize}.ago(#{trend_number - 1}.#{value['unit'].downcase.singularize})"), Time.zone.now.end_of_day + now = Time.zone.now + if date_bridge_column_date?(column) + from = now.beginning_of_day.ago((trend_number).send(value['unit'].downcase.singularize.to_sym)) + to = now.end_of_day + else + from = now.ago((trend_number).send(value['unit'].downcase.singularize.to_sym)) + to = now + end + return from, to when "FUTURE" - trend_number = [search_criterion['number'].to_i, 1].max - return Time.zone.now.beginning_of_day, eval("Time.zone.now.end_of_#{value['unit'].downcase.singularize}.in(#{trend_number - 1}.#{value['unit'].downcase.singularize})") + trend_number = [value['number'].to_i, 1].max + now = Time.zone.now + if date_bridge_column_date?(column) + from = now.beginning_of_day + to = now.end_of_day.in((trend_number).send(value['unit'].downcase.singularize.to_sym)) + else + from = now + to = now.in((trend_number).send(value['unit'].downcase.singularize.to_sym)) + end + return from, to end end @@ -129,6 +151,14 @@ def date_bridge_from_to_for_range(column, value) end end end + + def date_bridge_column_date?(column) + if [:date_picker, :datetime_picker].include? column.form_ui + column.form_ui == :date_picker + else + (!column.column.nil? && [:date].include?(column.column.type)) + end + end end end end @@ -138,6 +168,7 @@ def date_bridge_from_to_for_range(column, value) ActiveScaffold::Finder.const_set('DateComparators', ["PAST", "FUTURE", "RANGE"]) ActiveScaffold::Finder.const_set('DateUnits', ["DAYS", "WEEKS", "MONTHS", "YEARS"]) +ActiveScaffold::Finder.const_set('TimeUnits', ["SECONDS", "MINUTES", "HOURS"]) ActiveScaffold::Finder.const_set('DateRanges', ["TODAY", "YESTERDAY", "TOMORROW", "THIS_WEEK", "PREV_WEEK", "NEXT_WEEK", "THIS_MONTH", "PREV_MONTH", "NEXT_MONTH", diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index fec044a513..39f9570366 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -75,6 +75,9 @@ :past => 'Letzten', :future => 'Nächsten', :range => 'Spanne', + :seconds => 'Sekunden', + :minutes => 'Minuten', + :hours => 'Stunden', :days => 'Tage', :weeks => 'Wochen', :months => 'Monate', diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 32008411ea..736bf81ae9 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -81,6 +81,9 @@ :past => 'Past', :future => 'Future', :range => 'Range', + :seconds => 'Seconds', + :minutes => 'Minutes', + :hours => 'Hours', :days => 'Days', :weeks => 'Weeks', :months => 'Months', diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index e21a0f2123..9194db21d9 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -82,6 +82,9 @@ es: past: 'Past' future: 'Future' range: 'Range' + seconds: 'Seconds' + minutes: 'Minutes' + hours: 'Hours' days: 'Days' weeks: 'Weeks' months: 'Months' diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 92937c9867..ddd948e6cc 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -75,6 +75,9 @@ :past => 'Past', :future => 'Future', :range => 'Range', + :seconds => 'Seconds', + :minutes => 'Minutes', + :hours => 'Hours', :days => 'Days', :weeks => 'Weeks', :months => 'Months', From 1303ab1f447d1d3cea5f514d24c5d52f17d4c26e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 2 Nov 2010 08:40:47 +0100 Subject: [PATCH 0771/2024] assume form_ui :select if nothing is specified for association columns --- lib/active_scaffold/helpers/form_column_helpers.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 766c4b7323..67b737b226 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -17,8 +17,13 @@ def active_scaffold_input_for(column, scope = nil, options = {}) # fallback: we get to make the decision else if column.association - # if we get here, it's because the column has a form_ui but not one ActiveScaffold knows about. - raise "Unknown form_ui `#{column.form_ui}' for column `#{column.name}'" + if column.form_ui.nil? + # its an association and nothing is specified, we will assume form_ui :select + active_scaffold_input_select(column, options) + else + # if we get here, it's because the column has a form_ui but not one ActiveScaffold knows about. + raise "Unknown form_ui `#{column.form_ui}' for column `#{column.name}'" + end elsif column.virtual? active_scaffold_input_virtual(column, options) From 3dcf708e6b7da0f71579cbd731f907ca65abb8ab Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 2 Nov 2010 12:03:26 +0100 Subject: [PATCH 0772/2024] extracted method update_save --- lib/active_scaffold/actions/update.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 4d79fb23a3..c090e2f6c9 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -71,9 +71,13 @@ def do_edit # If you want to customize this algorithm, consider using the +before_update_save+ callback def do_update do_edit + @record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record]) + update_save + end + + def update_save begin active_scaffold_config.model.transaction do - @record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record]) before_update_save(@record) self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit if successful? From 54eb2917177bd29ecbaae4f1ab406f0488c2b597 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 2 Nov 2010 12:09:01 +0100 Subject: [PATCH 0773/2024] missing html_safe --- frontends/default/views/_list_actions.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 554c351cfe..70771693df 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -6,7 +6,7 @@ <% active_scaffold_config.action_links.each :member do |link| -%> <% next if skip_action_link(link) -%> <td> - <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : "<a class='disabled #{link.action}'>#{link.label}</a>" -%> + <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : "<a class='disabled #{link.action}'>#{link.label}</a>".html_safe -%> </td> <% end -%> </tr> From 893e0262abc480d438ea4bcc21b7a225a11265e9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 2 Nov 2010 13:50:33 +0100 Subject: [PATCH 0774/2024] Bugfix: do not show marked column in forms --- lib/active_scaffold/config/form.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/form.rb b/lib/active_scaffold/config/form.rb index 47fcde94cf..635adb21ad 100644 --- a/lib/active_scaffold/config/form.rb +++ b/lib/active_scaffold/config/form.rb @@ -29,7 +29,7 @@ def label def columns unless @columns # lazy evaluation self.columns = @core.columns._inheritable - self.columns.exclude :created_on, :created_at, :updated_on, :updated_at + self.columns.exclude :created_on, :created_at, :updated_on, :updated_at, :marked self.columns.exclude *@core.columns.collect{|c| c.name if c.polymorphic_association?}.compact end @columns From 15ed0cbd6cc9e3f5da1fa345b2f18f5881864932 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 4 Nov 2010 15:41:53 +0100 Subject: [PATCH 0775/2024] Bugfix: change all git urls from http to https --- .../active_scaffold_setup_generator.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb index d8b0198b16..28e9fdb3ea 100644 --- a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +++ b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb @@ -11,10 +11,10 @@ def install_plugins plugin 'verification', :git => 'git://github.com/rails/verification.git' plugin 'render_component', :git => 'git://github.com/vhochstein/render_component.git' if js_lib == 'prototype' - get "http://github.com/vhochstein/prototype-ujs/raw/master/src/rails.js", "public/javascripts/rails.js" + get "https://github.com/vhochstein/prototype-ujs/raw/master/src/rails.js", "public/javascripts/rails.js" elsif js_lib == 'jquery' - get "http://github.com/vhochstein/jquery-ujs/raw/master/src/rails.js", "public/javascripts/rails_jquery.js" - get "http://github.com/vhochstein/jQuery-Timepicker-Addon/raw/master/jquery-ui-timepicker-addon.js", "public/javascripts/jquery-ui-timepicker-addon.js" + get "https://github.com/vhochstein/jquery-ujs/raw/master/src/rails.js", "public/javascripts/rails_jquery.js" + get "https://github.com/vhochstein/jQuery-Timepicker-Addon/raw/master/jquery-ui-timepicker-addon.js", "public/javascripts/jquery-ui-timepicker-addon.js" end end From 9c162f8929dd28116780b724de37fc0f3c70080b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 4 Nov 2010 17:12:30 +0100 Subject: [PATCH 0776/2024] minor refactoring --- lib/active_scaffold/attribute_params.rb | 68 ++++++++++++++----------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index a9c68f4bd9..b084df866d 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -99,41 +99,49 @@ def manage_nested_record_from_params(parent_record, column, attributes) def column_value_from_param_value(parent_record, column, value) # convert the value, possibly by instantiating associated objects if value.is_a?(Hash) - # this is just for backwards compatibility. we should clean this up in 2.0. - if column.form_ui == :select - ids = if column.singular_association? - value[:id] - else - value.values.collect {|hash| hash[:id]} - end - (ids and not ids.empty?) ? column.association.klass.find(ids) : nil + column_value_from_param_hash_value(parent_record, column, value) + else + column_value_from_param_simple_value(parent_record, column, value) + end + end - elsif column.singular_association? - manage_nested_record_from_params(parent_record, column, value) - elsif column.plural_association? - value.collect {|key_value_pair| manage_nested_record_from_params(parent_record, column, key_value_pair[1])}.compact - else - value + def column_value_from_param_simple_value(parent_record, column, value) + if column.singular_association? + # it's a single id + column.association.klass.find(value) if value and not value.empty? + elsif column.plural_association? + # it's an array of ids + if value and not value.empty? + ids = value.select {|id| id.respond_to?(:empty?) ? !id.empty? : true} + ids.empty? ? [] : column.association.klass.find(ids) end + elsif column.column && column.column.number? && [:i18n_number, :currency].include?(column.options[:format]) + self.class.i18n_number_to_native_format(value) else - if column.singular_association? - # it's a single id - column.association.klass.find(value) if value and not value.empty? - elsif column.plural_association? - # it's an array of ids - if value and not value.empty? - ids = value.select {|id| id.respond_to?(:empty?) ? !id.empty? : true} - ids.empty? ? [] : column.association.klass.find(ids) - end - elsif column.column && column.column.number? && [:i18n_number, :currency].include?(column.options[:format]) - self.class.i18n_number_to_native_format(value) + # convert empty strings into nil. this works better with 'null => true' columns (and validations), + # and 'null => false' columns should just convert back to an empty string. + # ... but we can at least check the ConnectionAdapter::Column object to see if nulls are allowed + value = nil if value.is_a? String and value.empty? and !column.column.nil? and column.column.null + value + end + end + + def column_value_from_param_hash_value(parent_record, column, value) + # this is just for backwards compatibility. we should clean this up in 2.0. + if column.form_ui == :select + ids = if column.singular_association? + value[:id] else - # convert empty strings into nil. this works better with 'null => true' columns (and validations), - # and 'null => false' columns should just convert back to an empty string. - # ... but we can at least check the ConnectionAdapter::Column object to see if nulls are allowed - value = nil if value.is_a? String and value.empty? and !column.column.nil? and column.column.null - value + value.values.collect {|hash| hash[:id]} end + (ids and not ids.empty?) ? column.association.klass.find(ids) : nil + + elsif column.singular_association? + manage_nested_record_from_params(parent_record, column, value) + elsif column.plural_association? + value.collect {|key_value_pair| manage_nested_record_from_params(parent_record, column, key_value_pair[1])}.compact + else + value end end From c00e861275a8ff24b4bb5c97d36e31a34b2fde5d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 5 Nov 2010 09:26:27 +0100 Subject: [PATCH 0777/2024] fix field search when search_params is blank string --- lib/active_scaffold/actions/field_search.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index b7f6306cce..1dc70bebcc 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -29,7 +29,7 @@ def field_search_respond_to_js end def do_search - unless search_params.nil? + unless search_params.blank? text_search = active_scaffold_config.field_search.text_search search_conditions = [] columns = active_scaffold_config.field_search.columns From e46462c43296a73fd6ceae8011e3d6683377b8f7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 5 Nov 2010 16:44:52 +0100 Subject: [PATCH 0778/2024] preparations for batch_update and date columns --- .../javascripts/jquery/active_scaffold.js | 6 ++++++ .../javascripts/prototype/active_scaffold.js | 9 ++++++++- .../calendar_date_select/lib/as_cds_bridge.rb | 6 +++++- .../bridges/date_picker/lib/datepicker_bridge.rb | 6 +++++- .../bridges/shared/date_bridge.rb | 16 ++++++++++++---- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 76382bf645..bfcbe0f651 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -241,6 +241,12 @@ $(document).ready(function() { ActiveScaffold[(element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_range')); return true; }); + + $('select.as_update_date_operator').live('change', function(event) { + ActiveScaffold[$(this).val() == 'REPLACE' ? 'show' : 'hide']($(this).next()); + ActiveScaffold[$(this).val() == 'REPLACE' ? 'hide' : 'show']($(this).next().next()); + return true; + }); }); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 6fbe9d1f0f..13e4f0241a 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -260,7 +260,14 @@ document.observe("dom:loaded", function() { Element[(element.value == 'PAST' || element.value == 'FUTURE') ? 'show' : 'hide'](element.id.sub('_opt', '_trend')); Element[element.value == 'RANGE' ? 'show' : 'hide'](element.id.sub('_opt', '_range')); return true; - }); + }); + document.on('change', 'select.as_update_date_operator', function(event) { + var element = event.findElement(); + Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next()); + Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next().next()); + Element[element.value == 'REPLACE' ? 'hide' : 'show'](element.next('span')); + return true; + }); }); diff --git a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb index c6dba801ec..e22c3ca628 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb @@ -33,7 +33,11 @@ def active_scaffold_input_calendar_date_select(column, options) module SearchColumnHelpers def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) - value = controller.class.condition_value_for_datetime(current_search[name], column.column.type == :date ? :to_date : :to_time) + if current_search.is_a? Hash + value = controller.class.condition_value_for_datetime(current_search[name], column.column.type == :date ? :to_date : :to_time) + else + value = current_search + end calendar_date_select("record", column.name, {:name => "#{options[:name]}[#{name}]", :value => (value ? l(value) : nil), :class => 'text-input', :id => "#{options[:id]}_#{name}", :time => column_datetime?(column) ? true : false}) end diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 3f54dc7e96..69077a9130 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -176,7 +176,11 @@ def datepicker_format_options(column, format, options) module SearchColumnHelpers def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) - value = controller.class.condition_value_for_datetime(current_search[name], column.form_ui == :date_picker ? :to_date : :to_time) + if current_search.is_a? Hash + value = controller.class.condition_value_for_datetime(current_search[name], column.form_ui == :date_picker ? :to_date : :to_time) + else + value = current_search + end options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date, :value) options = active_scaffold_input_text_options(options.merge(column.options)) options[:class] << " #{column.search_ui.to_s}" diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index 0689c53eb6..e17860c700 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -33,11 +33,19 @@ def active_scaffold_search_date_bridge_numeric_tag(column, options, current_sear end def active_scaffold_search_date_bridge_trend_tag(column, options, current_search) - trend_controls = text_field_tag("search[#{column.name}][number]", current_search['number'], :class => 'text-input', :size => 10) << " " << - select_tag("search[#{column.name}][unit]", - options_for_select(active_scaffold_search_date_bridge_trend_units(column), current_search["unit"]), + active_scaffold_date_bridge_trend_tag(column, options, + {:name_prefix => 'search', + :number_value => current_search['number'], + :unit_value => current_search["unit"], + :show => (current_search['opt'] == 'PAST' || current_search['opt'] == 'FUTURE')}) + end + + def active_scaffold_date_bridge_trend_tag(column, options, trend_options) + trend_controls = text_field_tag("#{trend_options[:name_prefix]}[#{column.name}][number]", trend_options[:number_value], :class => 'text-input', :size => 10) << " " << + select_tag("#{trend_options[:name_prefix]}[#{column.name}][unit]", + options_for_select(active_scaffold_search_date_bridge_trend_units(column), trend_options[:name_prefix]), :class => 'text-input') - content_tag("span", trend_controls.html_safe, :id => "#{options[:id]}_trend", :style => "display:#{(current_search['opt'] == 'PAST' || current_search['opt'] == 'FUTURE') ? '' : 'none'}") + content_tag("span", trend_controls.html_safe, :id => "#{options[:id]}_trend", :style => "display:#{trend_options[:show] ? '' : 'none'}") end def active_scaffold_search_date_bridge_trend_units(column) From b01e114402e90549ca86e356bd06f01882b191d3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 8 Nov 2010 12:33:05 +0100 Subject: [PATCH 0779/2024] extract method active_scaffold_render_input --- lib/active_scaffold/helpers/form_column_helpers.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 67b737b226..f3e64545a4 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -5,9 +5,15 @@ module FormColumnHelpers # This method decides which input to use for the given column. # It does not do any rendering. It only decides which method is responsible for rendering. def active_scaffold_input_for(column, scope = nil, options = {}) + options = active_scaffold_input_options(column, scope, options) + options = update_columns_options(column, scope, options) + active_scaffold_render_input(column, options) + end + + alias form_column active_scaffold_input_for + + def active_scaffold_render_input(column, options) begin - options = active_scaffold_input_options(column, scope, options) - options = update_columns_options(column, scope, options) # first, check if the dev has created an override for this specific field if override_form_field?(column) send(override_form_field(column), @record, options) @@ -52,8 +58,6 @@ def active_scaffold_input_for(column, scope = nil, options = {}) end end - alias form_column active_scaffold_input_for - # the standard active scaffold options used for textual inputs def active_scaffold_input_text_options(options = {}) options[:autocomplete] = 'off' From 46e64a1c8de43a2c77ccc87d9eaa973d5aed14f7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 8 Nov 2010 15:04:59 +0100 Subject: [PATCH 0780/2024] corrected german localization --- lib/active_scaffold/locale/de.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 39f9570366..ad46eb8171 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -83,8 +83,8 @@ :months => 'Monate', :years => 'Jahre', :optional_attributes => 'Weitere', - :null => 'Definiert', - :not_null => 'Undefiniert', + :null => 'Undefiniert', + :not_null => 'Definiert', :date_picker_options => { :weekHeader => 'Wo', :firstDay => 1, From 73eff2f60a7b62d6701b6f2e6ffc3453116b7057 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 9 Nov 2010 12:15:01 +0100 Subject: [PATCH 0781/2024] fix removing all associated record when show_blank_record is disabled --- lib/active_scaffold/attribute_params.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 1ce6667973..f8bf4f3033 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -61,12 +61,7 @@ def update_record_from_params(parent_record, columns, attributes) # we avoid assigning a value that already exists because otherwise has_one associations will break (AR bug in has_one_association.rb#replace) parent_record.send("#{column.name}=", value) unless parent_record.send(column.name) == value - # plural associations may not actually appear in the params if all of the options have been unselected or cleared away. - # the "form_ui" check is necessary, becuase without it we have problems - # with subforms. the UI cuts out deep associations, which means they're not present in the - # params even though they're in the columns list. the result is that associations were being - # emptied out way too often. - elsif column.form_ui and column.plural_association? + elsif column.plural_association? parent_record.send("#{column.name}=", []) end end From c71abc0439e9d5a2261630f4924f17b5df692db1 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 9 Nov 2010 13:51:48 +0100 Subject: [PATCH 0782/2024] search before_filters only for action :index --- lib/active_scaffold/actions/field_search.rb | 4 ++-- lib/active_scaffold/actions/search.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index b85c2701bf..912195ec35 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -3,8 +3,8 @@ module FieldSearch include ActiveScaffold::Actions::CommonSearch def self.included(base) base.before_filter :search_authorized_filter, :only => :show_search - base.before_filter :store_search_params_into_session, :only => [:list, :index] - base.before_filter :do_search, :only => [:list, :index] + base.before_filter :store_search_params_into_session, :only => [:index] + base.before_filter :do_search, :only => [:index] base.helper_method :field_search_params end diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index eff8c8ad75..16fb9caf0b 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -3,8 +3,8 @@ module Search include ActiveScaffold::Actions::CommonSearch def self.included(base) base.before_filter :search_authorized_filter, :only => :show_search - base.before_filter :store_search_params_into_session, :only => [:list, :index] - base.before_filter :do_search, :only => [:list, :index] + base.before_filter :store_search_params_into_session, :only => [:index] + base.before_filter :do_search, :only => [:index] base.helper_method :search_params end From 104dd30417c424df6d1091b478e17bfc8f16dc88 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 9 Nov 2010 14:08:49 +0100 Subject: [PATCH 0783/2024] moved each_record_in_scope to list action --- lib/active_scaffold/actions/list.rb | 11 +++++++++++ lib/active_scaffold/actions/mark.rb | 10 ---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 1b792b0eb1..57067938c0 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -73,6 +73,17 @@ def do_list @page, @records = page, page.items end + def each_record_in_scope + do_search if respond_to? :do_search + finder_options = { :order => "#{active_scaffold_config.model.primary_key} ASC", + :conditions => all_conditions, + :joins => joins_for_finder} + finder_options.merge! custom_finder_options + finder_options.merge! :include => (active_scaffold_includes.blank? ? nil : active_scaffold_includes) + klass = beginning_of_chain + klass.all(finder_options).each {|record| yield record} + end + # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def list_authorized? diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index 68e50636fc..eedf784693 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -41,16 +41,6 @@ def do_demark_all each_record_in_scope {|record| marked_records.delete(record.id)} end - def each_record_in_scope - finder_options = { :order => "#{active_scaffold_config.model.primary_key} ASC", - :conditions => all_conditions, - :joins => joins_for_finder} - finder_options.merge! custom_finder_options - finder_options.merge! :include => (active_scaffold_includes.blank? ? nil : active_scaffold_includes) - klass = beginning_of_chain - klass.all(finder_options).each {|record| yield record} - end - # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def mark_authorized? From acab4a3038f1ffc7ed932431b20bf79a52b823bb Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 10 Nov 2010 08:34:36 +0100 Subject: [PATCH 0784/2024] Bugfix: Users which are not authorized to read all columns could simply call index action with format xml or json --- lib/active_scaffold/actions/list.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 57067938c0..05456d97c2 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -41,13 +41,13 @@ def list_respond_to_js end end def list_respond_to_xml - render :xml => response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status + render :xml => response_object.to_xml(:only => list_columns_names), :content_type => Mime::XML, :status => response_status end def list_respond_to_json - render :text => response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status + render :text => response_object.to_json(:only => list.columns.names), :content_type => Mime::JSON, :status => response_status end def list_respond_to_yaml - render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status + render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status end # The actual algorithm to prepare for the list view def do_list @@ -95,15 +95,15 @@ def action_update_respond_to_js end def action_update_respond_to_xml - render :xml => successful? ? "" : response_object.to_xml(:only => active_scaffold_config.list.columns.names), :content_type => Mime::XML, :status => response_status + render :xml => successful? ? "" : response_object.to_xml(:only => list_columns_names), :content_type => Mime::XML, :status => response_status end def action_update_respond_to_json - render :text => successful? ? "" : response_object.to_json(:only => active_scaffold_config.list.columns.names), :content_type => Mime::JSON, :status => response_status + render :text => successful? ? "" : response_object.to_json(:only => list_columns_names), :content_type => Mime::JSON, :status => response_status end def action_update_respond_to_yaml - render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.list.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status + render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status end private @@ -120,5 +120,9 @@ def action_update_formats def list_columns active_scaffold_config.list.columns.collect_visible end + + def list_columns_names + list_columns.collect(&:name) + end end end From d9b516fc32faa59479f010dd7fadf8deb6ed6f00 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 10 Nov 2010 10:55:04 +0100 Subject: [PATCH 0785/2024] Bugfix: typo in my prev commit --- lib/active_scaffold/actions/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 05456d97c2..733b2bcb79 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -44,7 +44,7 @@ def list_respond_to_xml render :xml => response_object.to_xml(:only => list_columns_names), :content_type => Mime::XML, :status => response_status end def list_respond_to_json - render :text => response_object.to_json(:only => list.columns.names), :content_type => Mime::JSON, :status => response_status + render :text => response_object.to_json(:only => list_columns_names), :content_type => Mime::JSON, :status => response_status end def list_respond_to_yaml render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status From 8eb0058747a748ee3642b17e1f2eb0364659ae82 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 10 Nov 2010 16:56:28 +0100 Subject: [PATCH 0786/2024] include record.to_label in error message header --- frontends/default/views/_base_form.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index 474079f0fa..0a618a1950 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -20,8 +20,9 @@ end -%> <div id="<%= element_messages_id(:action => form_action) %>" class="messages-container"> <% if request.xhr? -%> - <% if @record -%> - <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> + <% records = @error_records || Array(@record) + records.each do |record| %> + <%= error_messages_for record, :object_name => "#{record.class.model_name.human.downcase}#{record.new_record? ? '' : ": #{record.to_label}"}" %> <% end %> <% else -%> <%= render :partial => 'form_messages' %> From e0bd65d0d65e0aaf7488761fe754162421d821b8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 11 Nov 2010 13:31:39 +0100 Subject: [PATCH 0787/2024] disable autocompletion for date trend number field --- lib/active_scaffold/bridges/shared/date_bridge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index e17860c700..774609222b 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -41,7 +41,7 @@ def active_scaffold_search_date_bridge_trend_tag(column, options, current_search end def active_scaffold_date_bridge_trend_tag(column, options, trend_options) - trend_controls = text_field_tag("#{trend_options[:name_prefix]}[#{column.name}][number]", trend_options[:number_value], :class => 'text-input', :size => 10) << " " << + trend_controls = text_field_tag("#{trend_options[:name_prefix]}[#{column.name}][number]", trend_options[:number_value], :class => 'text-input', :size => 10, :autocomplete => 'off') << " " << select_tag("#{trend_options[:name_prefix]}[#{column.name}][unit]", options_for_select(active_scaffold_search_date_bridge_trend_units(column), trend_options[:name_prefix]), :class => 'text-input') From 091c1eaa5394a7595711e1cfa227a70d1313afee Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 11 Nov 2010 14:14:23 +0100 Subject: [PATCH 0788/2024] add option to hide calendar date select field --- .../bridges/calendar_date_select/lib/as_cds_bridge.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb index e22c3ca628..b79ef8c8d9 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb @@ -39,7 +39,12 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current value = current_search end calendar_date_select("record", column.name, - {:name => "#{options[:name]}[#{name}]", :value => (value ? l(value) : nil), :class => 'text-input', :id => "#{options[:id]}_#{name}", :time => column_datetime?(column) ? true : false}) + {:name => "#{options[:name]}[#{name}]", + :value => (value ? l(value) : nil), + :class => 'text-input', + :id => "#{options[:id]}_#{name}", + :time => column_datetime?(column) ? true : false, + :style => "display:#{(options[:show].nil? || options[:show]) ? '' : 'none'}"}) end end From ef0d80e7d5d0ab5a2a6779e67efe73309d29e2b5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 11 Nov 2010 14:18:06 +0100 Subject: [PATCH 0789/2024] prev commit for jquery --- lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index 69077a9130..c08ae8b144 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -184,6 +184,7 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date, :value) options = active_scaffold_input_text_options(options.merge(column.options)) options[:class] << " #{column.search_ui.to_s}" + options[:style] = "display:#{(options[:show].nil? || options[:show]) ? '' : 'none'}" format = options.delete(:format) || :default datepicker_format_options(column, format, options) text_field_tag("#{options[:name]}[#{name}]", value ? l(value, :format => format) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) From c2b1cc05647f790e89f1d5dbc461ea33519675e7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 16 Nov 2010 16:52:22 +0100 Subject: [PATCH 0790/2024] Bugfix: correctly format class attribute --- frontends/default/views/_show_columns.html.erb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_show_columns.html.erb b/frontends/default/views/_show_columns.html.erb index 5cd3d0de23..2577ffcedf 100644 --- a/frontends/default/views/_show_columns.html.erb +++ b/frontends/default/views/_show_columns.html.erb @@ -1,10 +1,13 @@ <dl> <% columns.each :for => @record do |column| %> <dt><%= column.label -%></dt> - <dd<%= " class=\"#{column.name}-view #{column.css_class}\"" unless column.is_a? ActiveScaffold::DataStructures::ActionColumns %>> <% if column.is_a? ActiveScaffold::DataStructures::ActionColumns -%> + <dd> <%= render :partial => 'show_columns', :locals => {:columns => column} %> <% else -%> + <% css_class = "#{column.name}-view" + css_class.concat(" #{column.css_class}") unless column.css_class.nil? %> + <dd class="<%= css_class.strip %>"> <%= show_column_value(@record, column) -%>   <% end -%> </dd> From 34c62811560681a9a6a63494b84d3cc621cb1773 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 16 Nov 2010 16:57:47 +0100 Subject: [PATCH 0791/2024] Bugfix: column_class remove whitespace at the end --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 8bac0b08a7..cbbd16cecd 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -212,7 +212,7 @@ def column_class(column, column_value, record) classes << 'empty' if column_empty? column_value classes << 'sorted' if active_scaffold_config.list.user.sorting.sorts_on?(column) classes << 'numeric' if column.column and [:decimal, :float, :integer].include?(column.column.type) - classes.join(' ') + classes.join(' ').rstrip end def column_heading_class(column, sorting) From 70874627e050ef359eb4123e3b87be70be84f1ac Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 18 Nov 2010 14:37:02 +0100 Subject: [PATCH 0792/2024] first steps: subgrouped action_links --- frontends/default/views/_list.html.erb | 2 +- .../default/views/_list_actions.html.erb | 2 +- frontends/default/views/_list_header.html.erb | 2 +- .../default/views/_list_messages.html.erb | 2 +- frontends/default/views/_list_record.html.erb | 2 +- .../default/views/_update_actions.html.erb | 2 +- frontends/default/views/update.html.erb | 2 +- .../data_structures/action_links.rb | 68 +++++++++++++++++-- 8 files changed, 69 insertions(+), 13 deletions(-) diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index 840448dd21..b163eb48bf 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -8,7 +8,7 @@ <%= render :partial => 'list_messages', :locals => {:columns => columns} %> <tbody class="records" id="<%= active_scaffold_tbody_id %>"> <% if !@records.empty? -%> - <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false, :columns => columns, :action_links => active_scaffold_config.action_links.collect_by_type(:member)} %> + <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false, :columns => columns, :action_links => active_scaffold_config.action_links.member} %> <% end -%> <% if columns.any? {|c| c.calculation?} -%> <%= render :partial => 'list_calculations', :locals => {:columns => columns} %> diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index d6ccc88cbc..da4f0d7d7e 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -1,4 +1,4 @@ -<% action_links ||= active_scaffold_config.action_links %> +<% action_links ||= active_scaffold_config.action_links.member %> <td class="actions"><table cellpadding="0" cellspacing="0"> <tr> <td class="indicator-container"> diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index 5fe805e06e..ca7575697e 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -1,4 +1,4 @@ -<% action_links = active_scaffold_config.action_links.collect_by_type(:collection) +<% action_links = active_scaffold_config.action_links.collection.collect unless action_links.empty? -%> <div class="actions"> <% new_params = params_for %> diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index 52d4c8c9f5..bdfbbd08c6 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -21,7 +21,7 @@ record = active_scaffold_config.model.new record.id = 0 action_links.add(search_link) -%> - <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links} %> + <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links.member} %> <% else %> <td class='actions'><%= '<p class="empty-message"> </p>'.html_safe if @page.items.empty? %></td> <% end -%> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index c5f2aeee9f..1ac0e0691c 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -4,7 +4,7 @@ columns ||= list_columns tr_class = cycle("", "even-record") tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class url_options = params_for(:action => :list, :id => record.id) -action_links ||= active_scaffold_config.action_links.collect_by_type(:member) +action_links ||= active_scaffold_config.action_links.member.collect -%> <tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get, :escape => false)).html_safe %>"> diff --git a/frontends/default/views/_update_actions.html.erb b/frontends/default/views/_update_actions.html.erb index ecb85faac0..e16e05ab91 100644 --- a/frontends/default/views/_update_actions.html.erb +++ b/frontends/default/views/_update_actions.html.erb @@ -1,6 +1,6 @@ <div class="active-scaffold-header"> <div class="actions"> - <% active_scaffold_config.action_links.each :member do |link| -%> + <% active_scaffold_config.action_links.member.each do |link| -%> <% next unless link.action == 'nested' -%> <% next if skip_action_link(link) -%> <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : "<a class='disabled'>#{link.label}</a>" -%> diff --git a/frontends/default/views/update.html.erb b/frontends/default/views/update.html.erb index d31da15f9b..d8e3da1821 100644 --- a/frontends/default/views/update.html.erb +++ b/frontends/default/views/update.html.erb @@ -1,6 +1,6 @@ <div class="active-scaffold"> <div class="update-view <%= "#{params[:controller]}-view" %> view"> - <% if active_scaffold_config.update.nested_links and active_scaffold_config.action_links.any? {|link| link.type == :member } -%> + <% if active_scaffold_config.update.nested_links and active_scaffold_config.action_links.member.empty? -%> <%= render :partial => 'update_actions', :locals => {:record => @record, :url_options => params_for(:action => :list, :id => @record.id)} %> <% end -%> <%= render :partial => 'update_form' -%> diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index fd6d21d113..24ea4373d6 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -8,11 +8,11 @@ def initialize # adds an ActionLink, creating one from the arguments if need be def add(action, options = {}) - link = action.is_a?(ActiveScaffold::DataStructures::ActionLink) ? action : ActiveScaffold::DataStructures::ActionLink.new(action, options) + link = action.is_a?(ActiveScaffold::DataStructures::ActionLink) || action.is_a?(ActiveScaffold::DataStructures::ActionLinks) ? action : ActiveScaffold::DataStructures::ActionLink.new(action, options) # NOTE: this duplicate check should be done by defining the comparison operator for an Action data structure - existing = @set.find {|a| a.action == link.action and a.controller == link.controller and a.parameters == link.parameters} + existing = find_duplicate(link) unless existing - @set << link + subgroup(link.type, link.type).add_to_set(link) link else existing @@ -20,13 +20,39 @@ def add(action, options = {}) end alias_method :<<, :add + def add_to_set(link) + @set << link + end + # finds an ActionLink by matching the action def [](val) - @set.find {|item| item.action == val.to_s} + @set.find do |item| + if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) + item[val] + else + item.action == val.to_s + end + end + end + + def find_duplicate(link) + @set.find do |item| + if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) + item.find_duplicate(link) + else + item.action == link.action and item.controller == link.controller and item.parameters == link.parameters + end + end end def delete(val) - @set.delete_if{|item| item.action == val.to_s} + @set.delete_if do |item| + if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) + delete(val) + else + item.action == val.to_s + end + end end # iterates over the links, possibly by type @@ -40,14 +66,44 @@ def each(type = nil) def collect_by_type(type = nil) links = [] - each(type) {|link| links << link} + subgroup(type).each(type) {|link| links << link} links end + def collect + @set.collect + end + def empty? @set.size == 0 end + def subgroup(name, label = nil) + group = @set.find do |item| + name == item.name if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) + end + + if group.nil? + group = ActiveScaffold::DataStructures::ActionLinks.new + group.label = label + group.name = name + add_to_set group + end + yield group if block_given? + group + end + + attr_writer :label + def label + as_(@label) if @label + end + + def method_missing(name, *args) + subgroup(name, name) + end + + attr_accessor :name + protected # called during clone or dup. makes the clone/dup deeper. From 688a360e1a7c1e7f225122f593d3768892b2ad9f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 18 Nov 2010 15:13:53 +0100 Subject: [PATCH 0793/2024] action_links: create method for each new subgroup --- lib/active_scaffold/data_structures/action_links.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 24ea4373d6..c7e13080c6 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -82,7 +82,6 @@ def subgroup(name, label = nil) group = @set.find do |item| name == item.name if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) end - if group.nil? group = ActiveScaffold::DataStructures::ActionLinks.new group.label = label @@ -99,7 +98,12 @@ def label end def method_missing(name, *args) - subgroup(name, name) + class_eval %{ + def #{name} + @#{name} ||= subgroup('#{name}'.to_sym) + end + } + send(name) end attr_accessor :name From 52f4cbbe8525dae1a04e2861bbe0e3da598f4d7f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 19 Nov 2010 14:32:57 +0100 Subject: [PATCH 0794/2024] add feature to nest record action_links (not finished yet) --- frontends/default/stylesheets/stylesheet.css | 27 +++++++++++- .../default/views/_list_actions.html.erb | 19 ++++++--- .../data_structures/action_links.rb | 41 +++++++++++++++---- 3 files changed, 72 insertions(+), 15 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index f6b42da3a2..e4e90e97db 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -246,7 +246,6 @@ text-align: right; /* Table :: Actions (Edit, Delete) ============================= */ - .active-scaffold tr.record td.actions { border-right: solid 1px #ccc; padding: 0; @@ -274,6 +273,32 @@ line-height: 16px; white-space: nowrap; } +.active-scaffold tr.record td.action_list ul { + display: none; + margin: 0; + border: 0 none; + padding: 0; + list-style: none; + height: 22px; + width: 160px; + position: absolute; + left: 0; + top: 22px; +} + +.active-scaffold tr.record td.action_list ul li { + margin: 0; + border: 0 none; + padding: 0; + float: none; /*For Gecko*/ + display: block !important; + display: inline; /*For IE*/ + list-style: none; + position: relative; + height: 22px; + z-index: 2; +} + /* Table :: Inline Adapter ============================= */ diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index da4f0d7d7e..aae123c36d 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -4,12 +4,19 @@ <td class="indicator-container"> <%= loading_indicator_tag(:action => :record, :id => record.id) %> </td> - <% action_links.each do |link| -%> - <% next if skip_action_link(link, record) -%> - <td> - <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}) %> - </td> - <% end -%> + <% level = 0 %> + <% action_links.traverse(controller, {:record => record}) do |parent, link, options| -%> + <% tag = (level == 0 ? 'td' : 'li') %> + <% if (options[:node] == :finished_traversing) -%> + <%= "</ul></#{tag}>".html_safe %> + <% level -= 1 %> + <% elsif (options[:node] == :start_traversing) -%> + <%= "<#{tag} #{"class=\"action_list\"" if tag == 'td'}> #{content_tag('span', parent.name)}<ul>".html_safe %> + <% level += 1 %> + <% else -%> + <%= content_tag(tag, options[:authorized] ? render_action_link(link, url_options, record) : action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"})) %> + <% end -%> + <% end -%> </tr> </table> </td> diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index c7e13080c6..509360db85 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -8,7 +8,11 @@ def initialize # adds an ActionLink, creating one from the arguments if need be def add(action, options = {}) - link = action.is_a?(ActiveScaffold::DataStructures::ActionLink) || action.is_a?(ActiveScaffold::DataStructures::ActionLinks) ? action : ActiveScaffold::DataStructures::ActionLink.new(action, options) + link = if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || action.is_a?(ActiveScaffold::DataStructures::ActionLinks) + action + else + ActiveScaffold::DataStructures::ActionLink.new(action, options) + end # NOTE: this duplicate check should be done by defining the comparison operator for an Action data structure existing = find_duplicate(link) unless existing @@ -57,9 +61,7 @@ def delete(val) # iterates over the links, possibly by type def each(type = nil) - type = type.to_sym if type @set.each {|item| - next if type and item.type != type yield item } end @@ -70,6 +72,22 @@ def collect_by_type(type = nil) links end + def traverse(controller, options = {}, &block) + @set.each do |link| + if link.is_a?(ActiveScaffold::DataStructures::ActionLinks) + # add top node only if there is anything in the list + #yield({:kind => :node, :level => 1, :last => false, :link => link}) + yield(link, nil, {:node => :start_traversing}) + link.traverse(options, &block) + yield(link, nil, {:node => :finished_traversing}) + #yield({:kind => :completed_group, :level => 1, :last => false, :link => link}) + elsif controller.nil? || !skip_action_link(controller, link, options) + authorized = options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action) + yield(self, link, {:authorized => authorized}) + end + end + end + def collect @set.collect end @@ -79,16 +97,17 @@ def empty? end def subgroup(name, label = nil) - group = @set.find do |item| + group = self if name == self.name + group ||= @set.find do |item| name == item.name if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) end + if group.nil? group = ActiveScaffold::DataStructures::ActionLinks.new - group.label = label + group.label = label || name group.name = name add_to_set group end - yield group if block_given? group end @@ -97,19 +116,25 @@ def label as_(@label) if @label end - def method_missing(name, *args) + def method_missing(name, *args, &block) class_eval %{ def #{name} @#{name} ||= subgroup('#{name}'.to_sym) + yield @#{name} if block_given? + @#{name} end } - send(name) + send(name, &block) end attr_accessor :name protected + def skip_action_link(controller, link, *args) + (!link.ignore_method.nil? and controller.try(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args)) + end + # called during clone or dup. makes the clone/dup deeper. def initialize_copy(from) @set = [] From 4a49fbf1fbf43be3691a5b0f1a767f806b569140 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 19 Nov 2010 15:01:50 +0100 Subject: [PATCH 0795/2024] Bugfix: npe in list_record --- frontends/default/views/_list_record.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 1ac0e0691c..cf4ef59b6b 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -4,7 +4,7 @@ columns ||= list_columns tr_class = cycle("", "even-record") tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class url_options = params_for(:action => :list, :id => record.id) -action_links ||= active_scaffold_config.action_links.member.collect +action_links ||= active_scaffold_config.action_links.member -%> <tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get, :escape => false)).html_safe %>"> From e275266bda1a0ede2b42e6b72ea9c3613714252b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 19 Nov 2010 15:09:43 +0100 Subject: [PATCH 0796/2024] Bugfix: call skip_action_link with correct parameters --- lib/active_scaffold/data_structures/action_links.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 509360db85..86a25651e7 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -81,7 +81,7 @@ def traverse(controller, options = {}, &block) link.traverse(options, &block) yield(link, nil, {:node => :finished_traversing}) #yield({:kind => :completed_group, :level => 1, :last => false, :link => link}) - elsif controller.nil? || !skip_action_link(controller, link, options) + elsif controller.nil? || !skip_action_link(controller, link, options[:record]) authorized = options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action) yield(self, link, {:authorized => authorized}) end From 06a6719b67a9d1a0d82eafb4745ef3a42670228e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 19 Nov 2010 16:43:49 +0100 Subject: [PATCH 0797/2024] Bugfix: if nested action_link close td tag correctly --- frontends/default/views/_list_actions.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index aae123c36d..0a7143b07a 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -8,8 +8,8 @@ <% action_links.traverse(controller, {:record => record}) do |parent, link, options| -%> <% tag = (level == 0 ? 'td' : 'li') %> <% if (options[:node] == :finished_traversing) -%> - <%= "</ul></#{tag}>".html_safe %> <% level -= 1 %> + <%= "</ul></#{(level == 0 ? 'td' : 'li')}>".html_safe %> <% elsif (options[:node] == :start_traversing) -%> <%= "<#{tag} #{"class=\"action_list\"" if tag == 'td'}> #{content_tag('span', parent.name)}<ul>".html_safe %> <% level += 1 %> From b84b200b51c896124bdecd269d5f95742df21feb Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 19 Nov 2010 17:00:45 +0100 Subject: [PATCH 0798/2024] removed css for nested action_links --- frontends/default/stylesheets/stylesheet.css | 26 -------------------- 1 file changed, 26 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index e4e90e97db..45587edc6b 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -273,32 +273,6 @@ line-height: 16px; white-space: nowrap; } -.active-scaffold tr.record td.action_list ul { - display: none; - margin: 0; - border: 0 none; - padding: 0; - list-style: none; - height: 22px; - width: 160px; - position: absolute; - left: 0; - top: 22px; -} - -.active-scaffold tr.record td.action_list ul li { - margin: 0; - border: 0 none; - padding: 0; - float: none; /*For Gecko*/ - display: block !important; - display: inline; /*For IE*/ - list-style: none; - position: relative; - height: 22px; - z-index: 2; -} - /* Table :: Inline Adapter ============================= */ From 91c9786696a6742a4808e20bd7f96393006a97a8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 19 Nov 2010 17:09:38 +0100 Subject: [PATCH 0799/2024] sorting anchor ids used duplicate values -> removed id attribute --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index d751c57bb2..a5c8e018b0 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -330,7 +330,7 @@ def render_column_heading(column, sorting, sort_direction) def column_heading_value(column, sorting, sort_direction) if column.sortable? - options = {:id => search_form_id, :class => "as_sort", + options = {:id => nil, :class => "as_sort", 'data-page-history' => controller_id, :remote => true, :method => :get} url_options = params_for(:action => :index, :page => 1, From 88ed2bbfaa3a8117ffca2c8b87a36048ab30ae0d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 19 Nov 2010 17:15:44 +0100 Subject: [PATCH 0800/2024] remove blank html id attribute values --- frontends/default/views/_list_calculations.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_calculations.html.erb b/frontends/default/views/_list_calculations.html.erb index 816356513c..7afbcb67c8 100644 --- a/frontends/default/views/_list_calculations.html.erb +++ b/frontends/default/views/_list_calculations.html.erb @@ -2,7 +2,7 @@ columns ||= list_columns -%> <tr id="<%= active_scaffold_calculations_id %>" class="active-scaffold-calculations"> <% columns.each do |column| -%> - <td id="<%= active_scaffold_calculations_id(column) if column.calculation? %>"> + <td <%= "id=#{active_scaffold_calculations_id(column)}" if column.calculation? %>> <% if column.calculation? -%> <%= render_column_calculation(column) %> <% else -%> From c73d7e4005d7997e134993251dd823d345ece54e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 22 Nov 2010 09:10:27 +0100 Subject: [PATCH 0801/2024] Bugfix: fixed ruby 1.9.2 exception Missing method empty? for Enumerator --- lib/active_scaffold/data_structures/action_links.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 86a25651e7..a970611291 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -89,7 +89,7 @@ def traverse(controller, options = {}, &block) end def collect - @set.collect + @set end def empty? From 41f7dd82bc105152fd8765dc6a19d84037844c63 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 22 Nov 2010 11:35:21 +0100 Subject: [PATCH 0802/2024] Bugfix: Chrome gap between form elements due to line break before description span tag --- frontends/default/stylesheets/stylesheet.css | 1 + 1 file changed, 1 insertion(+) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 45587edc6b..ff37f66b39 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -653,6 +653,7 @@ margin: 0; .active-scaffold .description { +display: inline-block; color: #999; font-size: 10px; margin-left: 5px; From e5a24e4ca39cb46a06b09bf30a6a9565254cea8d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 22 Nov 2010 11:39:31 +0100 Subject: [PATCH 0803/2024] Reduce gap between form-elements in chrome 2px doesn t seem to be interpreted correctly so remove it --- frontends/default/stylesheets/stylesheet.css | 1 - 1 file changed, 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index ff37f66b39..75453d5469 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -625,7 +625,6 @@ letter-spacing: 0; .active-scaffold li.form-element { clear: both; -padding-top: 2px; } .active-scaffold label { From ce8267bc1890b5e6c9aa37e740618ac8dda02e86 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 22 Nov 2010 15:48:59 +0100 Subject: [PATCH 0804/2024] nested action_links for records up and running --- frontends/default/stylesheets/stylesheet.css | 40 +++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 75453d5469..766a0a0964 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -264,7 +264,8 @@ text-align: right; padding: 0 2px; } -.active-scaffold tr.record td.actions a { +.active-scaffold tr.record td.actions a, +.active-scaffold tr.record td.actions span { font: bold 11px verdana, sans-serif; letter-spacing: -1px; padding: 2px; @@ -273,6 +274,43 @@ line-height: 16px; white-space: nowrap; } +.active-scaffold tr.record td.actions td.action_list { + position:relative; + text-align: left; + color: #0066CC; +} + +.active-scaffold tr.record td.actions .action_list ul { +border:medium none; +list-style-type:none; +margin:0; +padding:0; +position:absolute; +line-height:200%; +display: none; +width:100%; +} + +.active-scaffold tr.record td.actions .action_list ul li { +background:none repeat scroll 0 0 #FFF; +border-bottom:1px solid #AFD0F5; +border-left:1px solid #AFD0F5; +border-right:1px solid #AFD0F5; +color:#000000; +display:block; +padding-bottom:5px; +position:relative; +width:160px; +z-index: 2; +} + +.active-scaffold tr.record td.actions td.action_list:hover ul { +display:block; +} + + + + /* Table :: Inline Adapter ============================= */ From a8de722272054a3d8115178d0a13e87587878a57 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 22 Nov 2010 16:26:43 +0100 Subject: [PATCH 0805/2024] pass controller parameter correctly when traversing --- lib/active_scaffold/data_structures/action_links.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index a970611291..d44662a4c0 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -73,12 +73,13 @@ def collect_by_type(type = nil) end def traverse(controller, options = {}, &block) - @set.each do |link| + traverse_method = options.delete(:reverse).nil? ? :each : :reverse_each + @set.send(traverse_method) do |link| if link.is_a?(ActiveScaffold::DataStructures::ActionLinks) # add top node only if there is anything in the list #yield({:kind => :node, :level => 1, :last => false, :link => link}) yield(link, nil, {:node => :start_traversing}) - link.traverse(options, &block) + link.traverse(controller,options, &block) yield(link, nil, {:node => :finished_traversing}) #yield({:kind => :completed_group, :level => 1, :last => false, :link => link}) elsif controller.nil? || !skip_action_link(controller, link, options[:record]) From a1181a2b760062267844c8a8c7dbb7cfcdafade5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 22 Nov 2010 16:39:36 +0100 Subject: [PATCH 0806/2024] renamed action_list to action_group --- frontends/default/stylesheets/stylesheet.css | 8 ++++---- frontends/default/views/_list_actions.html.erb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 766a0a0964..c2768d89b7 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -274,13 +274,13 @@ line-height: 16px; white-space: nowrap; } -.active-scaffold tr.record td.actions td.action_list { +.active-scaffold tr.record td.actions td.action_group { position:relative; text-align: left; color: #0066CC; } -.active-scaffold tr.record td.actions .action_list ul { +.active-scaffold tr.record td.actions .action_group ul { border:medium none; list-style-type:none; margin:0; @@ -291,7 +291,7 @@ display: none; width:100%; } -.active-scaffold tr.record td.actions .action_list ul li { +.active-scaffold tr.record td.actions .action_group ul li { background:none repeat scroll 0 0 #FFF; border-bottom:1px solid #AFD0F5; border-left:1px solid #AFD0F5; @@ -304,7 +304,7 @@ width:160px; z-index: 2; } -.active-scaffold tr.record td.actions td.action_list:hover ul { +.active-scaffold tr.record td.actions .action_group:hover ul { display:block; } diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 0a7143b07a..b9383d2400 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -11,7 +11,7 @@ <% level -= 1 %> <%= "</ul></#{(level == 0 ? 'td' : 'li')}>".html_safe %> <% elsif (options[:node] == :start_traversing) -%> - <%= "<#{tag} #{"class=\"action_list\"" if tag == 'td'}> #{content_tag('span', parent.name)}<ul>".html_safe %> + <%= "<#{tag} #{"class=\"action_group\"" if tag == 'td'}> #{content_tag('span', parent.name)}<ul>".html_safe %> <% level += 1 %> <% else -%> <%= content_tag(tag, options[:authorized] ? render_action_link(link, url_options, record) : action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"})) %> From 0e77d66b50f742342a1f9a5d4cd303845aa2fcff Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 23 Nov 2010 13:44:49 +0100 Subject: [PATCH 0807/2024] action_group can include another action_group --- frontends/default/stylesheets/stylesheet.css | 67 ++++++++++++------- .../default/views/_list_actions.html.erb | 8 ++- 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index c2768d89b7..f25b119435 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -274,37 +274,54 @@ line-height: 16px; white-space: nowrap; } -.active-scaffold tr.record td.actions td.action_group { - position:relative; - text-align: left; - color: #0066CC; -} - -.active-scaffold tr.record td.actions .action_group ul { -border:medium none; -list-style-type:none; -margin:0; -padding:0; -position:absolute; -line-height:200%; +.active-scaffold .actions .action_group span:hover { +background-color: #ff8; +} + +.active-scaffold .actions .action_group { +position: relative; +text-align: right; +color: #0066CC; +} + +.active-scaffold .actions .action_group ul { +border: medium none; +list-style-type: none; +margin: 0; +padding: 0; +position: absolute; +line-height: 200%; display: none; -width:100%; +width: 100%; +left: -80px; } -.active-scaffold tr.record td.actions .action_group ul li { -background:none repeat scroll 0 0 #FFF; -border-bottom:1px solid #AFD0F5; -border-left:1px solid #AFD0F5; -border-right:1px solid #AFD0F5; -color:#000000; -display:block; -padding-bottom:5px; -position:relative; -width:160px; +.active-scaffold .actions .action_group ul ul { +display: none; +position: absolute; +top: 0; +left: -120px; +} + +.active-scaffold .actions .action_group ul li { +background: none repeat scroll 0 0 #FFF; +border-bottom: 1px solid #AFD0F5; +border-left: 1px solid #AFD0F5; +border-right: 1px solid #AFD0F5; +display: block; +padding-bottom: 5px; +position: relative; +width: 120px; z-index: 2; } -.active-scaffold tr.record td.actions .action_group:hover ul { +.active-scaffold .actions .action_group:hover ul ul, +.active-scaffold .actions .action_group:hover ul ul ul { +display: none; +} + +.active-scaffold .actions .action_group:hover ul, +.active-scaffold .actions .action_group ul li:hover ul { display:block; } diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index b9383d2400..c8cbc8f3fa 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -9,9 +9,13 @@ <% tag = (level == 0 ? 'td' : 'li') %> <% if (options[:node] == :finished_traversing) -%> <% level -= 1 %> - <%= "</ul></#{(level == 0 ? 'td' : 'li')}>".html_safe %> + <%= "</ul></#{(level == 0 ? 'div></td' : 'li')}>".html_safe %> <% elsif (options[:node] == :start_traversing) -%> - <%= "<#{tag} #{"class=\"action_group\"" if tag == 'td'}> #{content_tag('span', parent.name)}<ul>".html_safe %> + <% if tag == 'td' %> + <%= "<td><div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> + <% else %> + <%= "<li>#{content_tag('span', parent.name)}<ul>".html_safe %> + <% end %> <% level += 1 %> <% else -%> <%= content_tag(tag, options[:authorized] ? render_action_link(link, url_options, record) : action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"})) %> From 113275b36af5aa67240a7437e11a3c7d4db0a4c7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 23 Nov 2010 15:53:49 +0100 Subject: [PATCH 0808/2024] Bugfix: call skip_action_link correctly if record param is missing --- lib/active_scaffold/data_structures/action_links.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index d44662a4c0..0775b96185 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -82,7 +82,7 @@ def traverse(controller, options = {}, &block) link.traverse(controller,options, &block) yield(link, nil, {:node => :finished_traversing}) #yield({:kind => :completed_group, :level => 1, :last => false, :link => link}) - elsif controller.nil? || !skip_action_link(controller, link, options[:record]) + elsif controller.nil? || !skip_action_link(controller, link, *(Array(options[:record]))) authorized = options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action) yield(self, link, {:authorized => authorized}) end From 29c14f5626f03a37290ace4edb2e9501a3b0a1ae Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 23 Nov 2010 15:55:26 +0100 Subject: [PATCH 0809/2024] first version of grouped actions for collection links --- frontends/default/stylesheets/stylesheet.css | 22 ++++++++++++-- frontends/default/views/_list_header.html.erb | 30 +++++++++++++++---- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index f25b119435..19c60bdd3e 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -86,7 +86,8 @@ color: #fff; padding: 2px 5px 4px 5px; } -.active-scaffold-header div.actions a { +.active-scaffold-header div.actions a, +.active-scaffold-header div.actions span { float: right; font: bold 14px arial; letter-spacing: -1px; @@ -98,7 +99,24 @@ background-position: 1px 50%; background-repeat: no-repeat; } -.view .active-scaffold-header div.actions a { +.active-scaffold-header div.actions div.action_group { +display: inline; +float: right; +} + +.active-scaffold-header div.actions div.action_group a { +float: none; +margin: 0 2px; +padding: 2px; +} + +.active-scaffold-header div.actions .action_group ul { +line-height: 130%; +top: 14px; +} + +.view .active-scaffold-header div.actions a, +.view .active-scaffold-header div.actions div.action_group { float: left; } diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index ca7575697e..d41c6e0a06 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -1,10 +1,30 @@ -<% action_links = active_scaffold_config.action_links.collection.collect +<% action_links = active_scaffold_config.action_links.collection unless action_links.empty? -%> <div class="actions"> - <% new_params = params_for %> - <% action_links.send(nested.nil? ? :each : :reverse_each) do |link| -%> - <% next if skip_action_link(link) -%> - <%= render_action_link(link, new_params) -%> + <% level = 0 + new_params = params_for + traverse_options = {} + traverse_options[:reverse] = true unless nested.nil? + %> + <% action_links.traverse(controller, traverse_options) do |parent, link, options| -%> + <% tag = (level == 0 ? 'div' : 'li') %> + <% if (options[:node] == :finished_traversing) -%> + <% level -= 1 %> + <%= "</ul></#{(level == 0 ? 'div': 'li')}>".html_safe %> + <% elsif (options[:node] == :start_traversing) -%> + <% if tag == 'div' %> + <%= "<div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> + <% else %> + <%= "<li>#{content_tag('span', parent.name)}<ul>".html_safe %> + <% end %> + <% level += 1 %> + <% else -%> + <% if tag == 'li' %> + <%= content_tag('li', render_action_link(link, new_params)) %> + <% else %> + <%= render_action_link(link, new_params) %> + <% end %> + <% end -%> <% end -%> <%= loading_indicator_tag(:action => :table) %> </div> From 1afaff519a1b997f02aa812d21130565bfc0a689 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 24 Nov 2010 09:37:31 +0100 Subject: [PATCH 0810/2024] grouped actions: improve backwards compatibility --- lib/active_scaffold/data_structures/action_links.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 0775b96185..03581611fa 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -4,6 +4,7 @@ class ActionLinks def initialize @set = [] + @name = :root end # adds an ActionLink, creating one from the arguments if need be @@ -16,7 +17,10 @@ def add(action, options = {}) # NOTE: this duplicate check should be done by defining the comparison operator for an Action data structure existing = find_duplicate(link) unless existing - subgroup(link.type, link.type).add_to_set(link) + # That s for backwards compatibility if we are in root of action_links + # we have to move actionlink into members or collection subgroup + group = (name == :root ? subgroup(link.type, link.type) : self) + group.add_to_set(link) link else existing From 3eacfb95c65d838f755360847bdbbfa02e2ee14a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 24 Nov 2010 10:23:12 +0100 Subject: [PATCH 0811/2024] improve visualization of action_groups --- frontends/default/stylesheets/stylesheet.css | 10 +++++++--- frontends/default/views/_list_actions.html.erb | 4 ++-- frontends/default/views/_list_header.html.erb | 4 ++-- lib/active_scaffold/data_structures/action_links.rb | 8 +++++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 19c60bdd3e..6240132837 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -323,9 +323,9 @@ left: -120px; .active-scaffold .actions .action_group ul li { background: none repeat scroll 0 0 #FFF; -border-bottom: 1px solid #AFD0F5; -border-left: 1px solid #AFD0F5; -border-right: 1px solid #AFD0F5; +border-bottom: 2px solid #005CB8; +border-left: 2px solid #005CB8; +border-right: 2px solid #005CB8; display: block; padding-bottom: 5px; position: relative; @@ -333,6 +333,10 @@ width: 120px; z-index: 2; } +.active-scaffold .actions .action_group ul li.top { +border-top: 1px solid #005CB8; +} + .active-scaffold .actions .action_group:hover ul ul, .active-scaffold .actions .action_group:hover ul ul ul { display: none; diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index c8cbc8f3fa..22f7bde2ae 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -14,11 +14,11 @@ <% if tag == 'td' %> <%= "<td><div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> <% else %> - <%= "<li>#{content_tag('span', parent.name)}<ul>".html_safe %> + <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag('span', parent.name)}<ul>".html_safe %> <% end %> <% level += 1 %> <% else -%> - <%= content_tag(tag, options[:authorized] ? render_action_link(link, url_options, record) : action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"})) %> + <%= content_tag(tag, options[:authorized] ? render_action_link(link, url_options, record) : action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}), options[:first_action] ? {:class => 'top'}: {}) %> <% end -%> <% end -%> </tr> diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index d41c6e0a06..9c9c8a70da 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -15,12 +15,12 @@ <% if tag == 'div' %> <%= "<div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> <% else %> - <%= "<li>#{content_tag('span', parent.name)}<ul>".html_safe %> + <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag('span', parent.name)}<ul>".html_safe %> <% end %> <% level += 1 %> <% else -%> <% if tag == 'li' %> - <%= content_tag('li', render_action_link(link, new_params)) %> + <%= content_tag('li', render_action_link(link, new_params), options[:first_action] ? {:class => 'top'}: {}) %> <% else %> <%= render_action_link(link, new_params) %> <% end %> diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 03581611fa..65666c31f0 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -78,18 +78,20 @@ def collect_by_type(type = nil) def traverse(controller, options = {}, &block) traverse_method = options.delete(:reverse).nil? ? :each : :reverse_each + first_action = true @set.send(traverse_method) do |link| if link.is_a?(ActiveScaffold::DataStructures::ActionLinks) # add top node only if there is anything in the list #yield({:kind => :node, :level => 1, :last => false, :link => link}) - yield(link, nil, {:node => :start_traversing}) + yield(link, nil, {:node => :start_traversing, :first_action => first_action}) link.traverse(controller,options, &block) - yield(link, nil, {:node => :finished_traversing}) + yield(link, nil, {:node => :finished_traversing, :first_action => first_action}) #yield({:kind => :completed_group, :level => 1, :last => false, :link => link}) elsif controller.nil? || !skip_action_link(controller, link, *(Array(options[:record]))) authorized = options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action) - yield(self, link, {:authorized => authorized}) + yield(self, link, {:authorized => authorized, :first_action => first_action}) end + first_action = false end end From 4d2901160dd9c28f7b321f91c97a4700fe5a3a12 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 24 Nov 2010 11:01:26 +0100 Subject: [PATCH 0812/2024] fixed ui for collection action_groups in another action_group --- frontends/default/stylesheets/stylesheet.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 6240132837..c343d0d413 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -104,7 +104,8 @@ display: inline; float: right; } -.active-scaffold-header div.actions div.action_group a { +.active-scaffold-header div.actions div.action_group a, +.active-scaffold-header div.actions div.action_group span { float: none; margin: 0 2px; padding: 2px; From aa313ae50421ddf0c4d426abfc9ebd1e0928a25a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 24 Nov 2010 11:38:37 +0100 Subject: [PATCH 0813/2024] traverse action_links: pass current level to block --- frontends/default/views/_list_actions.html.erb | 10 +++------- frontends/default/views/_list_header.html.erb | 16 ++++++---------- .../data_structures/action_links.rb | 9 ++++++--- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 22f7bde2ae..893b55a462 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -4,21 +4,17 @@ <td class="indicator-container"> <%= loading_indicator_tag(:action => :record, :id => record.id) %> </td> - <% level = 0 %> <% action_links.traverse(controller, {:record => record}) do |parent, link, options| -%> - <% tag = (level == 0 ? 'td' : 'li') %> <% if (options[:node] == :finished_traversing) -%> - <% level -= 1 %> - <%= "</ul></#{(level == 0 ? 'div></td' : 'li')}>".html_safe %> + <%= "</ul></#{(options[:level] == 0 ? 'div></td' : 'li')}>".html_safe %> <% elsif (options[:node] == :start_traversing) -%> - <% if tag == 'td' %> + <% if options[:level] == 0 %> <%= "<td><div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> <% else %> <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag('span', parent.name)}<ul>".html_safe %> <% end %> - <% level += 1 %> <% else -%> - <%= content_tag(tag, options[:authorized] ? render_action_link(link, url_options, record) : action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}), options[:first_action] ? {:class => 'top'}: {}) %> + <%= content_tag((options[:level] == 0 ? 'td' : 'li'), options[:authorized] ? render_action_link(link, url_options, record) : action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}), options[:first_action] ? {:class => 'top'}: {}) %> <% end -%> <% end -%> </tr> diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index 9c9c8a70da..9374acb901 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -1,28 +1,24 @@ <% action_links = active_scaffold_config.action_links.collection unless action_links.empty? -%> <div class="actions"> - <% level = 0 - new_params = params_for + <% new_params = params_for traverse_options = {} traverse_options[:reverse] = true unless nested.nil? %> <% action_links.traverse(controller, traverse_options) do |parent, link, options| -%> - <% tag = (level == 0 ? 'div' : 'li') %> <% if (options[:node] == :finished_traversing) -%> - <% level -= 1 %> - <%= "</ul></#{(level == 0 ? 'div': 'li')}>".html_safe %> + <%= "</ul></#{(options[:level] == 0 ? 'div': 'li')}>".html_safe %> <% elsif (options[:node] == :start_traversing) -%> - <% if tag == 'div' %> + <% if options[:level] == 0 %> <%= "<div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> <% else %> <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag('span', parent.name)}<ul>".html_safe %> <% end %> - <% level += 1 %> <% else -%> - <% if tag == 'li' %> - <%= content_tag('li', render_action_link(link, new_params), options[:first_action] ? {:class => 'top'}: {}) %> - <% else %> + <% if options[:level] == 0 %> <%= render_action_link(link, new_params) %> + <% else %> + <%= content_tag('li', render_action_link(link, new_params), options[:first_action] ? {:class => 'top'}: {}) %> <% end %> <% end -%> <% end -%> diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 65666c31f0..2def309102 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -78,21 +78,24 @@ def collect_by_type(type = nil) def traverse(controller, options = {}, &block) traverse_method = options.delete(:reverse).nil? ? :each : :reverse_each + options[:level] ||= -1 + options[:level] += 1 first_action = true @set.send(traverse_method) do |link| if link.is_a?(ActiveScaffold::DataStructures::ActionLinks) # add top node only if there is anything in the list #yield({:kind => :node, :level => 1, :last => false, :link => link}) - yield(link, nil, {:node => :start_traversing, :first_action => first_action}) + yield(link, nil, {:node => :start_traversing, :first_action => first_action, :level => options[:level]}) link.traverse(controller,options, &block) - yield(link, nil, {:node => :finished_traversing, :first_action => first_action}) + yield(link, nil, {:node => :finished_traversing, :first_action => first_action, :level => options[:level]}) #yield({:kind => :completed_group, :level => 1, :last => false, :link => link}) elsif controller.nil? || !skip_action_link(controller, link, *(Array(options[:record]))) authorized = options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action) - yield(self, link, {:authorized => authorized, :first_action => first_action}) + yield(self, link, {:authorized => authorized, :first_action => first_action, :level => options[:level]}) end first_action = false end + options[:level] -= 1 end def collect From f5d91a14ba5058e872b07e278e3cda39d0568b4d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 24 Nov 2010 13:31:46 +0100 Subject: [PATCH 0814/2024] align code to generate ui for action_groups --- frontends/default/views/_list_actions.html.erb | 16 ++++++++++++---- frontends/default/views/_list_header.html.erb | 12 +++++++----- lib/active_scaffold/helpers/view_helpers.rb | 9 +++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 893b55a462..500c987827 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -4,17 +4,25 @@ <td class="indicator-container"> <%= loading_indicator_tag(:action => :record, :id => record.id) %> </td> - <% action_links.traverse(controller, {:record => record}) do |parent, link, options| -%> + <% traverse_options = {:record => record} + start_level_0_tag = '<td>' + end_level_0_tag = '</td>' + %> + <% action_links.traverse(controller, traverse_options) do |parent, link, options| -%> <% if (options[:node] == :finished_traversing) -%> - <%= "</ul></#{(options[:level] == 0 ? 'div></td' : 'li')}>".html_safe %> + <%= "</ul>#{(options[:level] == 0 ? "</div>#{end_level_0_tag}": '</li>')}".html_safe %> <% elsif (options[:node] == :start_traversing) -%> <% if options[:level] == 0 %> - <%= "<td><div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> + <%= "#{start_level_0_tag}<div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> <% else %> <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag('span', parent.name)}<ul>".html_safe %> <% end %> <% else -%> - <%= content_tag((options[:level] == 0 ? 'td' : 'li'), options[:authorized] ? render_action_link(link, url_options, record) : action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}), options[:first_action] ? {:class => 'top'}: {}) %> + <% if options[:level] == 0 %> + <%= "#{start_level_0_tag}#{h(render_member_action_link(link, url_options, record, options[:authorized]))}#{end_level_0_tag}".html_safe %> + <% else %> + <%= content_tag('li', render_member_action_link(link, url_options, record, options[:authorized]), options[:first_action] ? {:class => 'top'}: {}) %> + <% end %> <% end -%> <% end -%> </tr> diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index 9374acb901..4a3f892fca 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -1,24 +1,26 @@ <% action_links = active_scaffold_config.action_links.collection unless action_links.empty? -%> <div class="actions"> - <% new_params = params_for + <% url_options = params_for traverse_options = {} traverse_options[:reverse] = true unless nested.nil? + start_level_0_tag = '' + end_level_0_tag = '' %> <% action_links.traverse(controller, traverse_options) do |parent, link, options| -%> <% if (options[:node] == :finished_traversing) -%> - <%= "</ul></#{(options[:level] == 0 ? 'div': 'li')}>".html_safe %> + <%= "</ul>#{(options[:level] == 0 ? "</div>#{end_level_0_tag}": '</li>')}".html_safe %> <% elsif (options[:node] == :start_traversing) -%> <% if options[:level] == 0 %> - <%= "<div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> + <%= "#{start_level_0_tag}<div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> <% else %> <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag('span', parent.name)}<ul>".html_safe %> <% end %> <% else -%> <% if options[:level] == 0 %> - <%= render_action_link(link, new_params) %> + <%= "#{start_level_0_tag}#{h(render_action_link(link, url_options))}#{end_level_0_tag}".html_safe %> <% else %> - <%= content_tag('li', render_action_link(link, new_params), options[:first_action] ? {:class => 'top'}: {}) %> + <%= content_tag('li', render_action_link(link, url_options), options[:first_action] ? {:class => 'top'}: {}) %> <% end %> <% end -%> <% end -%> diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index cbbd16cecd..5383bded6a 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -127,6 +127,14 @@ def render_action_link(link, url_options, record = nil, html_options = {}) html_options = action_link_html_options(link, url_options, record, html_options) action_link_html(link, url_options, html_options) end + + def render_member_action_link(link, url_options, record, authorized = true) + if authorized + render_action_link(link, url_options, record) + else + action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}) + end + end def action_link_url_options(link, url_options, record, options = {}) url_options = url_options.clone @@ -161,6 +169,7 @@ def action_link_html_options(link, url_options, record, html_options) html_options[:class] += " #{link.html_options[:class]}" unless link.html_options[:class].blank? html_options end + def get_action_link_id(url_options, record = nil, column = nil) id = url_options[:id] || url_options[:parent_id] id = "#{column.association.name}-#{record.id}" if column && column.plural_association? From f187c512efaa8fe95aadae475efcd4c7d0a8ef35 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 24 Nov 2010 13:47:58 +0100 Subject: [PATCH 0815/2024] align code to generate ui for action_groups part 2 --- frontends/default/views/_list_actions.html.erb | 4 ++-- frontends/default/views/_list_header.html.erb | 4 ++-- lib/active_scaffold/helpers/view_helpers.rb | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 500c987827..84bca4fe75 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -19,9 +19,9 @@ <% end %> <% else -%> <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}#{h(render_member_action_link(link, url_options, record, options[:authorized]))}#{end_level_0_tag}".html_safe %> + <%= "#{start_level_0_tag}#{h(render_group_action_link(link, url_options, options, record))}#{end_level_0_tag}".html_safe %> <% else %> - <%= content_tag('li', render_member_action_link(link, url_options, record, options[:authorized]), options[:first_action] ? {:class => 'top'}: {}) %> + <%= content_tag('li', render_group_action_link(link, url_options, options, record), options[:first_action] ? {:class => 'top'}: {}) %> <% end %> <% end -%> <% end -%> diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index 4a3f892fca..58c8d7fff3 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -18,9 +18,9 @@ <% end %> <% else -%> <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}#{h(render_action_link(link, url_options))}#{end_level_0_tag}".html_safe %> + <%= "#{start_level_0_tag}#{h(render_group_action_link(link, url_options, options))}#{end_level_0_tag}".html_safe %> <% else %> - <%= content_tag('li', render_action_link(link, url_options), options[:first_action] ? {:class => 'top'}: {}) %> + <%= content_tag('li', render_group_action_link(link, url_options, options), options[:first_action] ? {:class => 'top'}: {}) %> <% end %> <% end -%> <% end -%> diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 5383bded6a..305c0afac6 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -128,11 +128,11 @@ def render_action_link(link, url_options, record = nil, html_options = {}) action_link_html(link, url_options, html_options) end - def render_member_action_link(link, url_options, record, authorized = true) - if authorized - render_action_link(link, url_options, record) - else + def render_group_action_link(link, url_options, options, record = nil) + if link.type == :member && !options[:authorized] action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}) + else + render_action_link(link, url_options, record) end end From a9cbd0ca4f1f1135b34977354abd41f3f49ffce3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 24 Nov 2010 14:09:58 +0100 Subject: [PATCH 0816/2024] refactored action_group ui into its own partial --- .../default/views/_action_group.html.erb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 frontends/default/views/_action_group.html.erb diff --git a/frontends/default/views/_action_group.html.erb b/frontends/default/views/_action_group.html.erb new file mode 100644 index 0000000000..9c61018538 --- /dev/null +++ b/frontends/default/views/_action_group.html.erb @@ -0,0 +1,20 @@ +<% record ||= nil + start_level_0_tag ||= '' + end_level_0_tag ||= ''%> +<% action_links.traverse(controller, traverse_options) do |parent, link, options| -%> + <% if (options[:node] == :finished_traversing) -%> + <%= "</ul>#{(options[:level] == 0 ? "</div>#{end_level_0_tag}": '</li>')}".html_safe %> + <% elsif (options[:node] == :start_traversing) -%> + <% if options[:level] == 0 %> + <%= "#{start_level_0_tag}<div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> + <% else %> + <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag('span', parent.name)}<ul>".html_safe %> + <% end %> + <% else -%> + <% if options[:level] == 0 %> + <%= "#{start_level_0_tag}#{h(render_group_action_link(link, url_options, options, record))}#{end_level_0_tag}".html_safe %> + <% else %> + <%= content_tag('li', render_group_action_link(link, url_options, options, record), options[:first_action] ? {:class => 'top'}: {}) %> + <% end %> + <% end -%> +<% end -%> \ No newline at end of file From 5697e5081b3ee6865ffcfdd4f93474849a42fcde Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 24 Nov 2010 16:07:03 +0100 Subject: [PATCH 0817/2024] use new action-group partial --- .../default/views/_list_actions.html.erb | 28 ++++--------------- frontends/default/views/_list_header.html.erb | 26 ++--------------- 2 files changed, 9 insertions(+), 45 deletions(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 84bca4fe75..6ff05ec44d 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -1,30 +1,14 @@ -<% action_links ||= active_scaffold_config.action_links.member %> <td class="actions"><table cellpadding="0" cellspacing="0"> <tr> <td class="indicator-container"> <%= loading_indicator_tag(:action => :record, :id => record.id) %> </td> - <% traverse_options = {:record => record} - start_level_0_tag = '<td>' - end_level_0_tag = '</td>' - %> - <% action_links.traverse(controller, traverse_options) do |parent, link, options| -%> - <% if (options[:node] == :finished_traversing) -%> - <%= "</ul>#{(options[:level] == 0 ? "</div>#{end_level_0_tag}": '</li>')}".html_safe %> - <% elsif (options[:node] == :start_traversing) -%> - <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}<div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> - <% else %> - <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag('span', parent.name)}<ul>".html_safe %> - <% end %> - <% else -%> - <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}#{h(render_group_action_link(link, url_options, options, record))}#{end_level_0_tag}".html_safe %> - <% else %> - <%= content_tag('li', render_group_action_link(link, url_options, options, record), options[:first_action] ? {:class => 'top'}: {}) %> - <% end %> - <% end -%> - <% end -%> + <%= render :partial => 'action_group', :locals => {:action_links => action_links || active_scaffold_config.action_links.member, + :url_options => url_options, + :record => record, + :traverse_options => {:record => record}, + :start_level_0_tag => '<td>', + :end_level_0_tag => '</td>'} %> </tr> </table> </td> diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index 58c8d7fff3..65f181e27e 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -1,29 +1,9 @@ <% action_links = active_scaffold_config.action_links.collection unless action_links.empty? -%> <div class="actions"> - <% url_options = params_for - traverse_options = {} - traverse_options[:reverse] = true unless nested.nil? - start_level_0_tag = '' - end_level_0_tag = '' - %> - <% action_links.traverse(controller, traverse_options) do |parent, link, options| -%> - <% if (options[:node] == :finished_traversing) -%> - <%= "</ul>#{(options[:level] == 0 ? "</div>#{end_level_0_tag}": '</li>')}".html_safe %> - <% elsif (options[:node] == :start_traversing) -%> - <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}<div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> - <% else %> - <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag('span', parent.name)}<ul>".html_safe %> - <% end %> - <% else -%> - <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}#{h(render_group_action_link(link, url_options, options))}#{end_level_0_tag}".html_safe %> - <% else %> - <%= content_tag('li', render_group_action_link(link, url_options, options), options[:first_action] ? {:class => 'top'}: {}) %> - <% end %> - <% end -%> - <% end -%> + <%= render :partial => 'action_group', :locals => {:action_links => action_links, + :url_options => params_for, + :traverse_options => nested.nil? ? {} : {:reverse => true}} %> <%= loading_indicator_tag(:action => :table) %> </div> <% end %> From d30a5ad73a8a3a21cdf5ad5b8cc628a2de1886db Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 24 Nov 2010 16:07:31 +0100 Subject: [PATCH 0818/2024] Bugfix: show action_group label correctly aligned in nested view --- frontends/default/stylesheets/stylesheet.css | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index c343d0d413..ed09e4a5b8 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -104,8 +104,8 @@ display: inline; float: right; } -.active-scaffold-header div.actions div.action_group a, -.active-scaffold-header div.actions div.action_group span { +.active-scaffold-header div.actions div.action_group li a, +.active-scaffold-header div.actions div.action_group li span { float: none; margin: 0 2px; padding: 2px; @@ -117,6 +117,7 @@ top: 14px; } .view .active-scaffold-header div.actions a, +.view .active-scaffold-header div.actions span, .view .active-scaffold-header div.actions div.action_group { float: left; } @@ -405,7 +406,8 @@ top: 0px; right: 0px; } -.active-scaffold .active-scaffold .active-scaffold-header div.actions a { +.active-scaffold .active-scaffold .active-scaffold-header div.actions a, +.active-scaffold .active-scaffold .active-scaffold-header div.actions span { font: bold 11px verdana, sans-serif; padding: 0 2px 1px 17px; } From aa33251a5d9dba5b1258931c3185a19235d1c933 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 25 Nov 2010 08:34:13 +0100 Subject: [PATCH 0819/2024] extract method active_scaffold_input_enum --- .../helpers/form_column_helpers.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index f3e64545a4..1f2d03a318 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -139,19 +139,23 @@ def active_scaffold_translated_option(column, text, value = nil) [(text.is_a?(Symbol) ? column.active_record_class.human_attribute_name(text) : text), value] end + def active_scaffold_input_enum(column, html_options) + options = { :selected => @record.send(column.name) } + options_for_select = column.options[:options].collect do |text, value| + active_scaffold_translated_option(column, text, value) + end + html_options.update(column.options[:html_options] || {}) + options.update(column.options) + select(:record, column.name, options_for_select, options, html_options) + end + def active_scaffold_input_select(column, html_options) if column.singular_association? active_scaffold_input_singular_association(column, html_options) elsif column.plural_association? active_scaffold_input_plural_association(column, html_options) else - options = { :selected => @record.send(column.name) } - options_for_select = column.options[:options].collect do |text, value| - active_scaffold_translated_option(column, text, value) - end - html_options.update(column.options[:html_options] || {}) - options.update(column.options) - select(:record, column.name, options_for_select, options, html_options) + active_scaffold_input_enum(column, html_options) end end From 4aa6053fd919ad1ff96f05cca7fc594db306557c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 25 Nov 2010 14:06:59 +0100 Subject: [PATCH 0820/2024] you may define an action_group for actions --- lib/active_scaffold.rb | 6 +++++- lib/active_scaffold/config/base.rb | 8 ++++++++ lib/active_scaffold/config/delete.rb | 1 + lib/active_scaffold/config/field_search.rb | 1 + lib/active_scaffold/config/form.rb | 1 + lib/active_scaffold/config/search.rb | 1 + lib/active_scaffold/config/show.rb | 1 + 7 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index f404da7c92..98a04e8274 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -101,7 +101,11 @@ def active_scaffold(model_id = nil, &block) # sneak the action links from the actions into the main set if link = active_scaffold_config.send(mod).link rescue nil - active_scaffold_config.action_links << link + if action_group = active_scaffold_config.send(mod).action_group + action_group.split('.').inject(active_scaffold_config.action_links){|group, group_name| group.send(group_name)}.add link + else + active_scaffold_config.action_links << link + end end end end diff --git a/lib/active_scaffold/config/base.rb b/lib/active_scaffold/config/base.rb index 414573571f..589897107b 100644 --- a/lib/active_scaffold/config/base.rb +++ b/lib/active_scaffold/config/base.rb @@ -17,12 +17,20 @@ def crud_type=(val) end end end + # delegate def crud_type; self.class.crud_type end # the user property gets set to the instantiation of the local UserSettings class during the automatic instantiation of this class. attr_accessor :user + # define a default action_group for this action + # e.g. 'members.crud' + class_inheritable_accessor :action_group + + # action_group this action should belong to + attr_accessor :action_group + class UserSettings def initialize(conf, storage, params) # the session hash relevant to this action diff --git a/lib/active_scaffold/config/delete.rb b/lib/active_scaffold/config/delete.rb index b73c441f4f..8397451610 100644 --- a/lib/active_scaffold/config/delete.rb +++ b/lib/active_scaffold/config/delete.rb @@ -7,6 +7,7 @@ def initialize(core_config) # start with the ActionLink defined globally @link = self.class.link.clone + @action_group = self.class.action_group.clone if self.class.action_group end # global level configuration diff --git a/lib/active_scaffold/config/field_search.rb b/lib/active_scaffold/config/field_search.rb index 91c3c353a6..8c5ec5cd94 100644 --- a/lib/active_scaffold/config/field_search.rb +++ b/lib/active_scaffold/config/field_search.rb @@ -9,6 +9,7 @@ def initialize(core_config) # start with the ActionLink defined globally @link = self.class.link.clone + @action_group = self.class.action_group.clone if self.class.action_group end diff --git a/lib/active_scaffold/config/form.rb b/lib/active_scaffold/config/form.rb index 635adb21ad..1b5275ef8a 100644 --- a/lib/active_scaffold/config/form.rb +++ b/lib/active_scaffold/config/form.rb @@ -5,6 +5,7 @@ def initialize(core_config) # start with the ActionLink defined globally @link = self.class.link.clone + @action_group = self.class.action_group.clone if self.class.action_group # no global setting here because multipart should only be set for specific forms @multipart = false diff --git a/lib/active_scaffold/config/search.rb b/lib/active_scaffold/config/search.rb index d30c0d4bb0..999c3584f8 100644 --- a/lib/active_scaffold/config/search.rb +++ b/lib/active_scaffold/config/search.rb @@ -10,6 +10,7 @@ def initialize(core_config) # start with the ActionLink defined globally @link = self.class.link.clone + @action_group = self.class.action_group.clone if self.class.action_group end diff --git a/lib/active_scaffold/config/show.rb b/lib/active_scaffold/config/show.rb index dd63989b1c..8dde4f65f8 100644 --- a/lib/active_scaffold/config/show.rb +++ b/lib/active_scaffold/config/show.rb @@ -6,6 +6,7 @@ def initialize(core_config) @core = core_config # start with the ActionLink defined globally @link = self.class.link.clone + @action_group = self.class.action_group.clone if self.class.action_group end # global level configuration From dfa89c6331dd5ca70cd9eb9934616901444708b7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 25 Nov 2010 14:43:22 +0100 Subject: [PATCH 0821/2024] Bugfix: align icons for actions correctly if in a actiongroup --- frontends/default/stylesheets/stylesheet.css | 1 - 1 file changed, 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index ed09e4a5b8..37acb530d8 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -108,7 +108,6 @@ float: right; .active-scaffold-header div.actions div.action_group li span { float: none; margin: 0 2px; -padding: 2px; } .active-scaffold-header div.actions .action_group ul { From d91ea935c608876fb9361d23fa7194b0b89c4388 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 25 Nov 2010 15:36:47 +0100 Subject: [PATCH 0822/2024] Fixed endless loop --- lib/active_scaffold/data_structures/action_links.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 2def309102..787334ee76 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -56,7 +56,7 @@ def find_duplicate(link) def delete(val) @set.delete_if do |item| if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) - delete(val) + item.delete(val) else item.action == val.to_s end From 08e540f8def267feff70f1aee8ca88028464d7d4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 25 Nov 2010 15:40:08 +0100 Subject: [PATCH 0823/2024] use localization for action_group name --- frontends/default/views/_action_group.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_action_group.html.erb b/frontends/default/views/_action_group.html.erb index 9c61018538..b6634f11fa 100644 --- a/frontends/default/views/_action_group.html.erb +++ b/frontends/default/views/_action_group.html.erb @@ -6,9 +6,9 @@ <%= "</ul>#{(options[:level] == 0 ? "</div>#{end_level_0_tag}": '</li>')}".html_safe %> <% elsif (options[:node] == :start_traversing) -%> <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}<div class=\"action_group\"> #{content_tag('span', parent.name)}<ul>".html_safe %> + <%= "#{start_level_0_tag}<div class=\"action_group\"> #{content_tag('span', as_(parent.name))}<ul>".html_safe %> <% else %> - <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag('span', parent.name)}<ul>".html_safe %> + <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag('span', as_(parent.name))}<ul>".html_safe %> <% end %> <% else -%> <% if options[:level] == 0 %> From 4c1f052a7e1cb753988b7ffdb43c59e9fdea757d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 25 Nov 2010 15:59:05 +0100 Subject: [PATCH 0824/2024] Bugfix: ajax calls of grouped action_links failed --- frontends/default/javascripts/jquery/active_scaffold.js | 2 +- frontends/default/javascripts/prototype/active_scaffold.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index bfcbe0f651..63d05f852b 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -739,7 +739,7 @@ ActiveScaffold.ActionLink = { if (element.length > 0) { element.data(); // jquery 1.4.2 workaround if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) { - var parent = element.parent(); + var parent = element.closest('.actions'); if (parent && parent.is('td')) { // record action diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 13e4f0241a..82cc512f9f 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -643,7 +643,7 @@ ActiveScaffold.ActionLink = { get: function(element) { var element = $(element); if (typeof(element.retrieve('action_link')) === 'undefined' && !element.hasClassName('as_adapter')) { - var parent = element.up(); + var parent = element.up('.actions'); if (parent && parent.nodeName.toUpperCase() == 'TD') { // record action parent = parent.up('tr.record') From 78ba6d9a6d920d1450aa35a197bee8b2a3509863 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 25 Nov 2010 16:55:56 +0100 Subject: [PATCH 0825/2024] nested action_links might be grouped as well --- .../javascripts/jquery/active_scaffold.js | 5 ++++- .../javascripts/prototype/active_scaffold.js | 4 ++++ lib/active_scaffold.rb | 6 +----- lib/active_scaffold/config/nested.rb | 5 +++-- .../data_structures/action_links.rb | 19 +++++++++++++++++-- .../helpers/list_column_helpers.rb | 2 +- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 63d05f852b..d27390cc86 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -740,7 +740,10 @@ ActiveScaffold.ActionLink = { element.data(); // jquery 1.4.2 workaround if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) { var parent = element.closest('.actions'); - + if (typeof(parent) === 'undefined') { + // maybe an column action_link + parent = elment.parent(); + } if (parent && parent.is('td')) { // record action parent = parent.closest('tr.record'); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 82cc512f9f..00d6c30f23 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -644,6 +644,10 @@ ActiveScaffold.ActionLink = { var element = $(element); if (typeof(element.retrieve('action_link')) === 'undefined' && !element.hasClassName('as_adapter')) { var parent = element.up('.actions'); + if (typeof(parent) === 'undefined') { + // maybe an column action_link + parent = element.up(); + } if (parent && parent.nodeName.toUpperCase() == 'TD') { // record action parent = parent.up('tr.record') diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 98a04e8274..79b7f6e9ec 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -101,11 +101,7 @@ def active_scaffold(model_id = nil, &block) # sneak the action links from the actions into the main set if link = active_scaffold_config.send(mod).link rescue nil - if action_group = active_scaffold_config.send(mod).action_group - action_group.split('.').inject(active_scaffold_config.action_links){|group, group_name| group.send(group_name)}.add link - else - active_scaffold_config.action_links << link - end + active_scaffold_config.action_links.add_to_group(link, active_scaffold_config.send(mod).action_group) end end end diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index c343be1894..462a56d1cc 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -5,6 +5,7 @@ class Nested < Base def initialize(core_config) @core = core_config self.shallow_delete = self.class.shallow_delete + @action_group = self.class.action_group.clone if self.class.action_group end # global level configuration @@ -22,7 +23,7 @@ def add_link(attribute, options = {}) unless column.nil? || column.association.nil? options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) action_link = @core.link_for_association(column, options) - @core.action_links.add(action_link) unless action_link.nil? + @core.action_links.add_to_group(action_link, action_group) unless action_link.nil? else end @@ -30,7 +31,7 @@ def add_link(attribute, options = {}) def add_scoped_link(named_scope, options = {}) action_link = @core.link_for_association_as_scope(named_scope.to_sym, options) - @core.action_links.add(action_link) unless action_link.nil? + @core.action_links.add_to_group(action_link, action_group) unless action_link.nil? end # the label for this Nested action. used for the header. diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 787334ee76..7da5e66897 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -32,6 +32,17 @@ def add_to_set(link) @set << link end + # adds a link to a specific group + # groups are represented as a string separated by a dot + # eg member.crud + def add_to_group(link, group = nil) + if group + group.split('.').inject(root){|group, group_name| group.send(group_name)}.add link + else + root << link + end + end + # finds an ActionLink by matching the action def [](val) @set.find do |item| @@ -64,9 +75,13 @@ def delete(val) end # iterates over the links, possibly by type - def each(type = nil) + def each(type = nil, &block) @set.each {|item| - yield item + if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) + item.each(type, &block) + else + yield item + end } end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index a5c8e018b0..6cee1b8b02 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -347,7 +347,7 @@ def column_heading_value(column, sorting, sort_direction) def render_nested_view(action_links, url_options, record) rendered = [] - action_links.each do |link| + action_links.member.each do |link| if link.nested_link? && link.column && @nested_auto_open[link.column.name] && @records.length <= @nested_auto_open[link.column.name] && respond_to?(:render_component) link_url_options = {:adapter => '_list_inline_adapter', :format => :js}.merge(action_link_url_options(link, url_options, record, options = {:reuse_eid => true})) link_id = get_action_link_id(link_url_options, record, link.column) From 5462769c6ac8e03efddb0efd3cb645db36422235 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 26 Nov 2010 08:55:27 +0100 Subject: [PATCH 0826/2024] Bugfix: if we had to skip first action in group, we failed to set top css class --- lib/active_scaffold/data_structures/action_links.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 7da5e66897..dc5a1dca36 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -98,17 +98,15 @@ def traverse(controller, options = {}, &block) first_action = true @set.send(traverse_method) do |link| if link.is_a?(ActiveScaffold::DataStructures::ActionLinks) - # add top node only if there is anything in the list - #yield({:kind => :node, :level => 1, :last => false, :link => link}) yield(link, nil, {:node => :start_traversing, :first_action => first_action, :level => options[:level]}) link.traverse(controller,options, &block) yield(link, nil, {:node => :finished_traversing, :first_action => first_action, :level => options[:level]}) - #yield({:kind => :completed_group, :level => 1, :last => false, :link => link}) + first_action = false elsif controller.nil? || !skip_action_link(controller, link, *(Array(options[:record]))) authorized = options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action) yield(self, link, {:authorized => authorized, :first_action => first_action, :level => options[:level]}) + first_action = false end - first_action = false end options[:level] -= 1 end From 01f3a917fc4cba5f8b6613e70e72dc819d717a8e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 26 Nov 2010 12:01:27 +0100 Subject: [PATCH 0827/2024] add another hierarchy level for action_groups --- frontends/default/stylesheets/stylesheet.css | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 37acb530d8..a3260e92c2 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -344,8 +344,9 @@ display: none; } .active-scaffold .actions .action_group:hover ul, -.active-scaffold .actions .action_group ul li:hover ul { -display:block; +.active-scaffold .actions .action_group ul li:hover > ul, +.active-scaffold .actions .action_group ul ul li:hover ul { +display: block; } From d206528fa52b63c929128daf15e81bced6d864ec Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 26 Nov 2010 13:56:11 +0100 Subject: [PATCH 0828/2024] use pattern of sentinent_user to pass marked_records in a thread_safe way to model --- lib/active_scaffold/actions/mark.rb | 2 +- lib/active_scaffold/marked_model.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index eedf784693..e5575e5e11 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -22,7 +22,7 @@ def mark_all # because the object may change. So we give ActiveRecord a proc that ties to the # marked_records_method on this ApplicationController. def assign_marked_records_to_model - active_scaffold_config.model.marked_records_proc = proc {send(:marked_records)} + active_scaffold_config.model.marked_records = marked_records end def marked_records diff --git a/lib/active_scaffold/marked_model.rb b/lib/active_scaffold/marked_model.rb index ab8374e6bf..bccad358c8 100644 --- a/lib/active_scaffold/marked_model.rb +++ b/lib/active_scaffold/marked_model.rb @@ -21,12 +21,12 @@ def marked=(value) end module ClassMethods - # The proc to call that retrieves the marked_records from the ApplicationController. - attr_accessor :marked_records_proc - - # Class-level access to the marked_records def marked_records - (marked_records_proc.call || Set.new) if marked_records_proc + Thread.current[:marked_records] ||= Set.new + end + + def marked_records=(marked) + Thread.current[:marked_records] = marked end end From 93ee64ba8d5bc7aa6bbcf36b54ac8c4101b7e382 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 29 Nov 2010 08:41:25 +0100 Subject: [PATCH 0829/2024] Bugfix: jquery ajax request was nt fired for list column action_links (issue: 40 reported by Naokij) --- frontends/default/javascripts/jquery/active_scaffold.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index d27390cc86..6bbc50d570 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -740,9 +740,9 @@ ActiveScaffold.ActionLink = { element.data(); // jquery 1.4.2 workaround if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) { var parent = element.closest('.actions'); - if (typeof(parent) === 'undefined') { + if (parent.length === 0) { // maybe an column action_link - parent = elment.parent(); + parent = element.parent(); } if (parent && parent.is('td')) { // record action From a9f545b3cb8147fce5ca40a77f7badaf0f58a257 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 29 Nov 2010 14:29:26 +0100 Subject: [PATCH 0830/2024] some refactoring --- .../helpers/list_column_helpers.rb | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 6cee1b8b02..3ac23c181e 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -43,23 +43,11 @@ def render_list_column(text, column, record) url_options[:link] = as_(:create_new) if link.crud_type == :create end - # check authorization - if column.association - associated_for_authorized = if associated.nil? || (associated.respond_to?(:empty?) && associated.empty?) - column.association.klass - elsif column.plural_association? - associated.first - else - associated - end - authorized = associated_for_authorized.authorized_for?(:crud_type => link.crud_type) - authorized = authorized and record.authorized_for?(:crud_type => :update, :column => column.name) if link.crud_type == :create + if column_link_authorized?(link, column, record, associated) + render_action_link(link, url_options, record) else - authorized = record.authorized_for?(:crud_type => link.crud_type) + "<a class='disabled'>#{text}</a>".html_safe end - # to make html render properly - return "<a class='disabled'>#{text}</a>".html_safe unless authorized - render_action_link(link, url_options, record) else text = active_scaffold_inplace_edit(record, column, {:formatted_column => text}) if inplace_edit?(record, column) text @@ -75,25 +63,46 @@ def action_link_to_inline_form(column, record, associated) link.controller = polymorphic_controller end + configure_column_link(link, associated, column.actions_for_association_links) + end + + def configure_column_link(link, associated, actions) if column_empty?(associated) # if association is empty, we only can link to create form - if column.actions_for_association_links.include?(:new) + if actions.include?(:new) link.action = 'new' link.crud_type = :create end - elsif column.actions_for_association_links.include?(:edit) + elsif actions.include?(:edit) link.action = 'edit' link.crud_type = :update - elsif column.actions_for_association_links.include?(:show) + elsif actions.include?(:show) link.action = 'show' link.crud_type = :read - elsif column.actions_for_association_links.include?(:list) - link.parameters[:id] = record.send(column.association.name).id + elsif actions.include?(:list) + link.parameters[:id] = associated.id link.action = 'index' link.crud_type = :read end link end + def column_link_authorized?(link, column, record, associated) + if column.association + associated_for_authorized = if associated.nil? || (associated.respond_to?(:empty?) && associated.empty?) + column.association.klass + elsif [:has_many, :has_and_belongs_to_many].include? column.association.macro + associated.first + else + associated + end + authorized = associated_for_authorized.authorized_for?(:crud_type => link.crud_type) + authorized = authorized and record.authorized_for?(:crud_type => :update, :column => column.name) if link.crud_type == :create + authorized + else + record.authorized_for?(:crud_type => link.crud_type) + end + end + def polymorphic_controller_for_nested_link(column, record) begin controller = active_scaffold_controller_for(record.send(column.association.name).class) From 10f9af059d0cd6a76058312ab359f410104d27e4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 29 Nov 2010 15:01:43 +0100 Subject: [PATCH 0831/2024] th a padding right only if column is sorted --- frontends/default/stylesheets/stylesheet.css | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index a3260e92c2..95e4391e91 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -185,7 +185,7 @@ background-color: #555; .active-scaffold th a, .active-scaffold th a:visited { color: #fff; -padding: 2px 15px 2px 5px; +padding: 2px 2px 2px 5px; } .active-scaffold th p { @@ -202,6 +202,10 @@ color: #ff8; background-color: #333; } +.active-scaffold th.sorted a { +padding-right: 18px; +} + .active-scaffold th.asc a, .active-scaffold th.asc a:hover { background: #333 url(../../../images/active_scaffold/default/arrow_up.gif) right 50% no-repeat; From 42661332ce794b86cc1d9fea1c7116181204016c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 30 Nov 2010 15:21:16 +0100 Subject: [PATCH 0832/2024] only call destroy_find_record if @record is nil --- lib/active_scaffold/actions/delete.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index a99bf7d131..a2c9338296 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -46,7 +46,7 @@ def destroy_find_record # A simple method to handle the actual destroying of a record # May be overridden to customize the behavior def do_destroy - destroy_find_record + @record ||= destroy_find_record begin self.successful = @record.destroy rescue From 2722ff9e93a47bb630cf97b51f218144a6b4052c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 30 Nov 2010 15:21:42 +0100 Subject: [PATCH 0833/2024] action s may define more than one action_link --- lib/active_scaffold.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 79b7f6e9ec..1c8f0d4185 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -101,7 +101,12 @@ def active_scaffold(model_id = nil, &block) # sneak the action links from the actions into the main set if link = active_scaffold_config.send(mod).link rescue nil - active_scaffold_config.action_links.add_to_group(link, active_scaffold_config.send(mod).action_group) + if link.is_a? Array + link.each {|current| active_scaffold_config.action_links.add_to_group(current, active_scaffold_config.send(mod).action_group)} + else + active_scaffold_config.action_links.add_to_group(link, active_scaffold_config.send(mod).action_group) + end + end end end From d37e53ed5bf6dcfdd890ab033fbff9c48e43b196 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 1 Dec 2010 10:22:54 +0100 Subject: [PATCH 0834/2024] add new jquery TimePicker localication options --- lib/active_scaffold/locale/de.rb | 4 +++- lib/active_scaffold/locale/es.yml | 2 ++ lib/active_scaffold/locale/fr.rb | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index ad46eb8171..f3fb8bd5a5 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -92,7 +92,9 @@ :showMonthAfterYear => false }, :datetime_picker_options => { - :timeText => 'Uhrzeit' + :timeText => 'Uhrzeit', + :currentText => 'Jetzt', + :closeText => 'Schließen' }, :errors => { :template => { diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index 9194db21d9..3cde253e85 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -99,6 +99,8 @@ es: showMonthAfterYear: false datetime_picker_options: timeText: 'Hora' + currentText: 'Ahora' + closeText: 'Cerrar' errors: template: header: diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index ddd948e6cc..bbd2ef8f8e 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -92,7 +92,9 @@ :showMonthAfterYear => false, }, :datetime_picker_options => { - :timeText => 'Heure' + :timeText => 'Heure', + :currentText => 'Maintenant', + :closeText => 'Fermer' }, :errors => { :template => { From c08f8ebb2556c7b7b51fd347e9ae4a0926c58e26 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 1 Dec 2010 17:55:10 +0100 Subject: [PATCH 0835/2024] Bugfix: form_ui radio control needs to be html_safe (issue: 42 reported by PanosJee) --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 1f2d03a318..124559b893 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -164,7 +164,7 @@ def active_scaffold_input_radio(column, html_options) column.options[:options].inject('') do |html, (text, value)| text, value = active_scaffold_translated_option(column, text, value) html << content_tag(:label, radio_button(:record, column.name, value, html_options.merge(:id => html_options[:id] + '-' + value.to_s)) + text) - end + end.html_safe end # requires RecordSelect plugin to be installed and configured. From 120d4eff531fb6a7a99e9bc454beb27b51e785d6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Dec 2010 13:22:15 +0100 Subject: [PATCH 0836/2024] Bugfix: Close link in show partial should only use ajax if request was ajax --- frontends/default/views/_show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_show.html.erb b/frontends/default/views/_show.html.erb index 1110dd986f..ce07757e8e 100644 --- a/frontends/default/views/_show.html.erb +++ b/frontends/default/views/_show.html.erb @@ -3,6 +3,6 @@ <%= render :partial => 'show_columns', :locals => {:columns => active_scaffold_config.show.columns} -%> <p class="form-footer"> - <%= link_to as_(:close), main_path_to_return, :class => 'as_cancel', :remote => true, 'data-refresh' => false %> + <%= link_to as_(:close), main_path_to_return, :class => 'as_cancel', :remote => request.xhr?, 'data-refresh' => false %> <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> </p> \ No newline at end of file From dafb7b01dd1653934cb44d7b5b93506efa85369a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Dec 2010 16:25:24 +0100 Subject: [PATCH 0837/2024] get action_link popup option up and running with rails 3 --- frontends/default/javascripts/jquery/active_scaffold.js | 5 +++++ frontends/default/javascripts/prototype/active_scaffold.js | 5 +++++ lib/active_scaffold/helpers/view_helpers.rb | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 6bbc50d570..dd2f58a380 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -247,6 +247,11 @@ $(document).ready(function() { ActiveScaffold[$(this).val() == 'REPLACE' ? 'hide' : 'show']($(this).next().next()); return true; }); + + $('a[data-popup]').live('click', function(e) { + window.open($(this).attr('href')); + e.preventDefault(); + }); }); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 00d6c30f23..4bef7f4913 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -268,6 +268,11 @@ document.observe("dom:loaded", function() { Element[element.value == 'REPLACE' ? 'hide' : 'show'](element.next('span')); return true; }); + document.on("click", "a[data-popup]", function(event, element) { + if (event.stopped) return; + window.open($(element).href); + event.stop(); + }); }); diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 305c0afac6..abdf9ab299 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -157,9 +157,9 @@ def action_link_html_options(link, url_options, record, html_options) html_options['data-confirm'] = link.confirm(record.try(:to_label)) if link.confirm? html_options['data-position'] = link.position if link.position and link.inline? html_options[:class] += ' as_action' if link.inline? - html_options[:popup] = true if link.popup? + html_options['data-popup'] = true if link.popup? html_options[:id] = link_id - html_options[:remote] = true unless link.page? + html_options[:remote] = true unless link.page? || link.popup? if link.dhtml_confirm? html_options[:class] += ' as_action' if !link.inline? html_options[:page_link] = 'true' if !link.inline? From 6c25235b391143ede6b7cf0f860e306b12ffd3d1 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 3 Dec 2010 08:42:40 +0100 Subject: [PATCH 0838/2024] add target _blank to popup action_links to open a new window in case of deactivated javascript --- lib/active_scaffold/helpers/view_helpers.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index abdf9ab299..7f04bd1a0f 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -157,7 +157,10 @@ def action_link_html_options(link, url_options, record, html_options) html_options['data-confirm'] = link.confirm(record.try(:to_label)) if link.confirm? html_options['data-position'] = link.position if link.position and link.inline? html_options[:class] += ' as_action' if link.inline? - html_options['data-popup'] = true if link.popup? + if link.popup? + html_options['data-popup'] = true + html_options[:target] = '_blank' + end html_options[:id] = link_id html_options[:remote] = true unless link.page? || link.popup? if link.dhtml_confirm? From 640db60c01f1150548d9a5100d82e690f95df100 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 3 Dec 2010 09:47:51 +0100 Subject: [PATCH 0839/2024] Bugfix: possible ambigous column error --- lib/active_scaffold/actions/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 733b2bcb79..67e29b7f86 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -75,7 +75,7 @@ def do_list def each_record_in_scope do_search if respond_to? :do_search - finder_options = { :order => "#{active_scaffold_config.model.primary_key} ASC", + finder_options = { :order => "#{active_scaffold_config.model.connection.quote_table_name(active_scaffold_config.model.table_name)}.#{active_scaffold_config.model.primary_key} ASC", :conditions => all_conditions, :joins => joins_for_finder} finder_options.merge! custom_finder_options From c5a3708f9aaf7e686cec3029805aee88e724a97f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 3 Dec 2010 11:40:34 +0100 Subject: [PATCH 0840/2024] Bugfix: member action_links failed to render response in case of disabled javascript --- lib/active_scaffold/actions/list.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 67e29b7f86..3c2e0c1905 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -89,7 +89,13 @@ def each_record_in_scope def list_authorized? authorized_for?(:crud_type => :read) end - + + def action_update_respond_to_html + do_search if respond_to? :do_search + do_list + render :action => 'list' + end + def action_update_respond_to_js render(:action => 'on_action_update') end From df658feae5700648b50cee280bd621e304a99a85 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 3 Dec 2010 16:17:36 +0100 Subject: [PATCH 0841/2024] show action_link confirmation also if javascript is disabled new method process_action_link_action to further simplify action handling --- .../views/action_confirmation.html.erb | 13 ++++++ lib/active_scaffold/actions/list.rb | 41 ++++++++++++++++++- .../data_structures/action_links.rb | 18 +++++--- lib/active_scaffold/helpers/view_helpers.rb | 4 +- lib/active_scaffold/locale/de.rb | 3 +- lib/active_scaffold/locale/en.rb | 3 +- lib/active_scaffold/locale/es.yml | 1 + lib/active_scaffold/locale/fr.rb | 3 +- 8 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 frontends/default/views/action_confirmation.html.erb diff --git a/frontends/default/views/action_confirmation.html.erb b/frontends/default/views/action_confirmation.html.erb new file mode 100644 index 0000000000..aa3af23fa5 --- /dev/null +++ b/frontends/default/views/action_confirmation.html.erb @@ -0,0 +1,13 @@ +<div class="active-scaffold"> + <div class="delete-view view"> + <%= form_tag params_for(:action => link.action, :id => params[:id]), { :method => link.method } %> + <h4><%= link.confirm(record.try(:to_label)) -%></h4> + + <p class="form-footer"> + <%= submit_tag as_(link.action), :class => 'submit' %> + <%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %> + </p> + + </form> + </div> +</div> \ No newline at end of file diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 3c2e0c1905..db2bc49232 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -90,10 +90,43 @@ def list_authorized? authorized_for?(:crud_type => :read) end + # call this method in your action_link action to simplify processing of actions + # eg for member action_link :fire + # process_action_link_action do |record| + # record.update_attributes(:fired => true) + # self.successful = true + # flash[:info] = 'Player fired' + # end + def process_action_link_action + if request.get? + # someone has disabled javascript, we have to show confirmation form first + @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0 + respond_to_action(:action_confirmation) + else + if params[:id] && params[:id] && params[:id].to_i > 0 + @record = find_if_allowed(params[:id], (request.post? || request.put?) ? :update : :delete) + unless @record.nil? + yield @record + else + self.successful = false + flash[:error] = as_(:no_authorization_for_action, :action => action_name) + end + else + yield + end + respond_to_action(:action_update) + end + end + + def action_confirmation_respond_to_html + link = active_scaffold_config.action_links[action_name.to_sym] + render :action => 'action_confirmation', :locals => {:record => @record, :link => link} + end + def action_update_respond_to_html do_search if respond_to? :do_search do_list - render :action => 'list' + redirect_to :action => 'index' end def action_update_respond_to_js @@ -116,13 +149,19 @@ def action_update_respond_to_yaml def list_authorized_filter raise ActiveScaffold::ActionNotAllowed unless list_authorized? end + def list_formats (default_formats + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq end + def action_update_formats (default_formats + active_scaffold_config.formats).uniq end + def action_confirmation_formats + (default_formats + active_scaffold_config.formats).uniq + end + def list_columns active_scaffold_config.list.columns.collect_visible end diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index dc5a1dca36..726cf5ddee 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -45,23 +45,29 @@ def add_to_group(link, group = nil) # finds an ActionLink by matching the action def [](val) - @set.find do |item| + links = [] + @set.each do |item| if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) - item[val] + collected = item[val] + links << collected unless collected.nil? else - item.action == val.to_s + links << item if item.action == val.to_s end end + links.first end def find_duplicate(link) - @set.find do |item| + links = [] + @set.each do |item| if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) - item.find_duplicate(link) + collected = item.find_duplicate(link) + links << collected unless collected.nil? else - item.action == link.action and item.controller == link.controller and item.parameters == link.parameters + links << item if item.action == link.action and item.controller == link.controller and item.parameters == link.parameters end end + links.first end def delete(val) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 7f04bd1a0f..20643542bc 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -143,7 +143,7 @@ def action_link_url_options(link, url_options, record, options = {}) url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller] url_options.merge! link.parameters if link.parameters url_options_for_nested_link(link.column, record, link, url_options, options) if link.nested_link? - url_options[:_method] = link.method if link.inline? && link.method != :get + url_options[:_method] = link.method if !link.confirm? && link.inline? && link.method != :get url_options end @@ -152,7 +152,7 @@ def action_link_html_options(link, url_options, record, html_options) html_options.reverse_merge! link.html_options.merge(:class => link.action) # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails - html_options[:method] = link.method if !link.inline? && link.method != :get + html_options[:method] = link.method if link.method != :get html_options['data-confirm'] = link.confirm(record.try(:to_label)) if link.confirm? html_options['data-position'] = link.position if link.position and link.inline? diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index f3fb8bd5a5..d06de709d9 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -109,7 +109,8 @@ :cant_destroy_record => "%{record} kann nicht gelöscht werden", :internal_error => 'Fehler bei der Verarbeitung (code 500, Interner Fehler)', :version_inconsistency => 'Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben.', - :record_not_saved => 'Eintrag kann nicht gespeichert werden. Ursache unbekannt.' + :record_not_saved => 'Eintrag kann nicht gespeichert werden. Ursache unbekannt.', + :no_authorization_for_action => "Keine Berechtigung für Aktion %{action}" } } } diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb index 736bf81ae9..61fe874d23 100644 --- a/lib/active_scaffold/locale/en.rb +++ b/lib/active_scaffold/locale/en.rb @@ -112,7 +112,8 @@ :cant_destroy_record => "%{record} can't be destroyed", :internal_error => 'Request Failed (code 500, Internal Error)', :version_inconsistency => 'Version inconsistency - this record has been modified since you started editing it.', - :record_not_saved => 'Failed to save record cause of an unknown error' + :record_not_saved => 'Failed to save record cause of an unknown error', + :no_authorization_for_action => "No Authorization for action %{action}" } } } diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index 3cde253e85..339f1ea1f7 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -112,3 +112,4 @@ es: cant_destroy_record: "No se pudo borrar %{record}" internal_error: 'Petición fallida (código 500, error interno)' version_inconsistency: 'Inconsistencia de versiones - este registro se ha modificado después de que empezó a editarlo.' + no_authorization_for_action: "No Authorization for action %{action}" diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index bbd2ef8f8e..0205295b4e 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -109,7 +109,8 @@ :cant_destroy_record => "%{record} can't be destroyed", :internal_error => 'Erreur de la requête (code 500, Erreur interne)', :version_inconsistency => "Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer.", - :record_not_saved => 'Failed to save record cause of an unknown error' + :record_not_saved => 'Failed to save record cause of an unknown error', + :no_authorization_for_action => "No Authorization for action %{action}" } } } From e2c3bacc72e0b33f87c5d328feea8f8bb6c19266 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Dec 2010 13:26:14 +0100 Subject: [PATCH 0842/2024] Bugfix: use link.label for button label instead of link.action --- frontends/default/views/action_confirmation.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/action_confirmation.html.erb b/frontends/default/views/action_confirmation.html.erb index aa3af23fa5..dedc2baf53 100644 --- a/frontends/default/views/action_confirmation.html.erb +++ b/frontends/default/views/action_confirmation.html.erb @@ -4,7 +4,7 @@ <h4><%= link.confirm(record.try(:to_label)) -%></h4> <p class="form-footer"> - <%= submit_tag as_(link.action), :class => 'submit' %> + <%= submit_tag as_(link.label), :class => 'submit' %> <%= link_to as_(:cancel), main_path_to_return, :class => 'cancel' %> </p> From bc36f36380b30447aab1cdb8a8bc991bc9f7698d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Dec 2010 13:49:33 +0100 Subject: [PATCH 0843/2024] replace delete action by using action_confirmation for destroy method --- lib/active_scaffold/actions/delete.rb | 20 +++++++++----------- lib/active_scaffold/actions/list.rb | 4 ++-- lib/active_scaffold/actions/show.rb | 13 ++++++++++--- lib/active_scaffold/config/delete.rb | 2 +- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index a2c9338296..7e3d1b9b89 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -1,20 +1,18 @@ module ActiveScaffold::Actions module Delete def self.included(base) - base.before_filter :delete_authorized_filter, :only => [:delete, :destroy] - end - - # this method is for html mode. it provides "the missing action" (http://thelucid.com/articles/2006/07/26/simply-restful-the-missing-action). - # it also gives us delete confirmation for html mode. woo! - def delete - destroy_find_record - render :action => 'delete' + base.before_filter :delete_authorized_filter, :only => [:destroy] end def destroy - return redirect_to(params.merge(:action => :delete)) if request.get? - do_destroy - respond_to_action(:destroy) + if request.get? + # someone has disabled javascript, we have to show confirmation form first + @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0 + respond_to_action(:action_confirmation) + else + do_destroy + respond_to_action(:destroy) + end end protected diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index db2bc49232..10b9d45784 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -118,8 +118,8 @@ def process_action_link_action end end - def action_confirmation_respond_to_html - link = active_scaffold_config.action_links[action_name.to_sym] + def action_confirmation_respond_to_html(confirm_action = action_name.to_sym) + link = active_scaffold_config.action_links[confirm_action] render :action => 'action_confirmation', :locals => {:record => @record, :link => link} end diff --git a/lib/active_scaffold/actions/show.rb b/lib/active_scaffold/actions/show.rb index 588db9d2c4..b4896a98bf 100644 --- a/lib/active_scaffold/actions/show.rb +++ b/lib/active_scaffold/actions/show.rb @@ -5,9 +5,16 @@ def self.included(base) end def show - do_show - successful? - respond_to_action(:show) + # rest destroy falls back to rest show in case of disabled javascript + # just render action_confirmation message for destroy + unless params.delete :destroy_action + do_show + successful? + respond_to_action(:show) + else + @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0 + action_confirmation_respond_to_html(:destroy) + end end protected diff --git a/lib/active_scaffold/config/delete.rb b/lib/active_scaffold/config/delete.rb index 8397451610..80438aa60c 100644 --- a/lib/active_scaffold/config/delete.rb +++ b/lib/active_scaffold/config/delete.rb @@ -15,7 +15,7 @@ def initialize(core_config) # the ActionLink for this action cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('delete', :label => :delete, :type => :member, :confirm => :are_you_sure_to_delete, :crud_type => :delete, :position => false, :security_method => :delete_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('destroy', :label => :delete, :type => :member, :confirm => :are_you_sure_to_delete, :method => :delete, :crud_type => :delete, :position => false, :parameters => {:destroy_action => true}, :security_method => :delete_authorized?) # instance-level configuration # ---------------------------- From ad41d6a9ebb0b24f5d34a0ba02dfa4b6a66d4dbd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Dec 2010 13:52:16 +0100 Subject: [PATCH 0844/2024] remove delete action in as_routes --- lib/extensions/routing_mapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extensions/routing_mapper.rb b/lib/extensions/routing_mapper.rb index 58ed1c9287..c027385a91 100644 --- a/lib/extensions/routing_mapper.rb +++ b/lib/extensions/routing_mapper.rb @@ -2,7 +2,7 @@ module ActionDispatch module Routing ACTIVE_SCAFFOLD_CORE_ROUTING = { :collection => {:show_search => :get, :render_field => :get}, - :member => {:row => :get, :update_column => :post, :render_field => :get, :delete => :get} + :member => {:row => :get, :update_column => :post, :render_field => :get} } ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = { :collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post}, From bf18595a26d4da96a4ae2f4465cc8e4c9ba5ba60 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Dec 2010 14:55:01 +0100 Subject: [PATCH 0845/2024] code cleanup concerning data-method parameter --- .../javascripts/jquery/active_scaffold.js | 16 +--------------- .../javascripts/prototype/active_scaffold.js | 18 ++---------------- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index dd2f58a380..784c05bc7b 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -771,21 +771,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ init: function(a, target, loading_indicator) { this.tag = $(a); this.url = this.tag.attr('href'); - this.method = 'get'; - - if(this.url.match('_method=delete')){ - this.method = 'delete'; - // action delete is special case cause in ajax world it will be destroy - } else if(this.url.match('/delete')){ - this.url = this.url.replace('/delete', ''); - this.tag.attr('href', this.url); - this.method = 'delete'; - } else if(this.url.match('_method=post')){ - this.method = 'post'; - } else if(this.url.match('_method=put')){ - this.method = 'put'; - } - if (this.method != 'get') this.tag.attr('data-method', this.method); + this.method = this.tag.attr('data-method') || 'get'; this.target = target; this.loading_indicator = loading_indicator; this.hide_target = false; diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 4bef7f4913..d23f1a9e53 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -671,25 +671,11 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ initialize: function(a, target, loading_indicator) { this.tag = $(a); this.url = this.tag.href; - this.method = 'get'; - - if(this.url.match('_method=delete')){ - this.method = 'delete'; - // action delete is special case cause in ajax world it will be destroy - } else if(this.url.match('/delete')){ - this.url = this.url.replace('/delete', ''); - this.tag.href = this.url; - this.method = 'delete'; - } else if(this.url.match('_method=post')){ - this.method = 'post'; - } else if(this.url.match('_method=put')){ - this.method = 'put'; - } - if (this.method != 'get') this.tag.writeAttribute('data-method', this.method); + this.method = this.tag.readAttribute('data-method') || 'get'; this.target = target; this.loading_indicator = loading_indicator; this.hide_target = false; - this.position = this.tag.getAttribute('data-position'); + this.position = this.tag.readAttribute('data-position'); this.tag.store('action_link', this); }, From cff3d3fdfaa9e68f0cc4108f89247639694d8947 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Dec 2010 15:14:33 +0100 Subject: [PATCH 0846/2024] remove hack which replaces delete action with destroy action --- frontends/default/javascripts/jquery/active_scaffold.js | 7 +------ frontends/default/javascripts/prototype/active_scaffold.js | 5 ----- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 784c05bc7b..73a58c4f7f 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -830,7 +830,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ this.adapter = element; this.adapter.addClass('as_adapter'); this.adapter.data('action_link', this); - }, + } }); /** @@ -842,11 +842,6 @@ ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({ var refresh = this.target.attr('data-refresh'); if (refresh) l.refresh_url = refresh; - if ($(link).hasClass('delete')) { - l.url = l.url.replace(/\/delete(\?.*)?$/, '$1'); - l.url = l.url.replace(/\/delete\/(.*)/, '/destroy/$1'); - l.tag.attr('href', l.url); - } if (l.position) { l.url = l.url.append_params({adapter: '_list_inline_adapter'}); l.tag.attr('href', l.url); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index d23f1a9e53..ba4b582257 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -741,11 +741,6 @@ ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, { var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); if (!this.target.readAttribute('data-refresh').blank()) l.refresh_url = this.target.readAttribute('data-refresh'); - if (link.hasClassName('delete')) { - l.url = l.url.replace(/\/delete(\?.*)?$/, '$1'); - l.url = l.url.replace(/\/delete\/(.*)/, '/destroy/$1'); - l.tag.href = l.url; - } if (l.position) { l.url = l.url.append_params({adapter: '_list_inline_adapter'}); l.tag.href = l.url; From 9d2b8cd495369974b95cf182da2c15e1978d6ffd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Dec 2010 15:20:25 +0100 Subject: [PATCH 0847/2024] call Activescaffold.update_row instead of Activescaffold.replac --- frontends/default/views/on_action_update.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/on_action_update.js.rjs b/frontends/default/views/on_action_update.js.rjs index a91758caa5..009e4481a9 100644 --- a/frontends/default/views/on_action_update.js.rjs +++ b/frontends/default/views/on_action_update.js.rjs @@ -1,6 +1,6 @@ page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages') if controller.send :successful? - page.call 'ActiveScaffold.replace', element_row_id(:action => :list, :id => @record.id), render(:partial => 'list_record', :locals => {:record => @record}) if @record + page.call 'ActiveScaffold.update_row', element_row_id(:action => :list, :id => @record.id), render(:partial => 'list_record', :locals => {:record => @record}) if @record page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} else page.call 'ActiveScaffold.scroll_to', active_scaffold_messages_id From 4b2bae6f7b0dca33b6a8014c12f409f34b9f8a64 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 6 Dec 2010 16:22:07 +0100 Subject: [PATCH 0848/2024] process_action_link_action accepts optional render_action parameter --- lib/active_scaffold/actions/delete.rb | 7 +------ lib/active_scaffold/actions/list.rb | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 7e3d1b9b89..ea0cf37a7c 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -5,13 +5,8 @@ def self.included(base) end def destroy - if request.get? - # someone has disabled javascript, we have to show confirmation form first - @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0 - respond_to_action(:action_confirmation) - else + process_action_link_action(:destroy) do |record| do_destroy - respond_to_action(:destroy) end end diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 10b9d45784..e5433acfc4 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -97,7 +97,7 @@ def list_authorized? # self.successful = true # flash[:info] = 'Player fired' # end - def process_action_link_action + def process_action_link_action(render_action = :action_update) if request.get? # someone has disabled javascript, we have to show confirmation form first @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0 @@ -114,7 +114,7 @@ def process_action_link_action else yield end - respond_to_action(:action_update) + respond_to_action(render_action) end end From 174415b7953d19683b271158fb1ae97e33a795a8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 8 Dec 2010 11:43:51 +0100 Subject: [PATCH 0849/2024] actions_for_association_links = [:list] was broken (issue 49 reported by MikeBlyth) --- lib/active_scaffold/actions/nested.rb | 2 +- lib/active_scaffold/helpers/list_column_helpers.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index a118736068..dd38329e55 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -19,7 +19,7 @@ def nested @nested ||= ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, active_scaffold_session_storage) if !@nested.nil? && @nested.new_instance? register_constraints_with_action_columns(@nested.constrained_fields) - active_scaffold_constraints[:id] = nested.parent_id if @nested.belongs_to? + active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to? end @nested end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 3ac23c181e..471780248c 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -62,7 +62,6 @@ def action_link_to_inline_form(column, record, associated) return link if polymorphic_controller.nil? link.controller = polymorphic_controller end - configure_column_link(link, associated, column.actions_for_association_links) end @@ -79,7 +78,6 @@ def configure_column_link(link, associated, actions) link.action = 'show' link.crud_type = :read elsif actions.include?(:list) - link.parameters[:id] = associated.id link.action = 'index' link.crud_type = :read end From d89aa03fcecdfcac28c54745c223491289615371 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 9 Dec 2010 09:59:29 +0100 Subject: [PATCH 0850/2024] Allow to set :selected for :select form_ui --- lib/active_scaffold/helpers/form_column_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 475dd27fbd..83217d7ea4 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -107,13 +107,13 @@ def active_scaffold_input_singular_association(column, html_options) select_options = options_for_association(column.association) select_options.unshift([ associated.to_label, associated.id ]) unless associated.nil? or select_options.find {|label, id| id == associated.id} - selected = associated.nil? ? nil : associated.id method = column.name #html_options[:name] += '[id]' - options = {:selected => selected, :include_blank => as_(:_select_)} + options = {:include_blank => as_(:_select_)} html_options.update(column.options[:html_options] || {}) options.update(column.options) + options[:selected] = associated.id unless associated.nil? select(:record, method, select_options.uniq, options, html_options) end From ca842c3f8d4dd40f718a6964e4779be0173da1d6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 13 Dec 2010 10:11:02 +0100 Subject: [PATCH 0851/2024] fix issue in list_header if nested action is excluded (issue 51 by korobkov) --- frontends/default/views/_list_header.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index 65f181e27e..e46c82ca9d 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -3,7 +3,7 @@ <div class="actions"> <%= render :partial => 'action_group', :locals => {:action_links => action_links, :url_options => params_for, - :traverse_options => nested.nil? ? {} : {:reverse => true}} %> + :traverse_options => nested? ? {:reverse => true} : {}} %> <%= loading_indicator_tag(:action => :table) %> </div> <% end %> From 2cb54de5c9059e2110073c5a4f54a0880afec007 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 13 Dec 2010 10:40:25 +0100 Subject: [PATCH 0852/2024] align mark_all checkbox in header correctly --- frontends/default/stylesheets/stylesheet.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 95e4391e91..19373ea8cb 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -221,6 +221,10 @@ background: #333 url(../../../images/active_scaffold/default/arrow_down.gif) rig background: #333 url(../../../images/active_scaffold/default/indicator-small.gif) right 50% no-repeat; } +.active-scaffold th .mark_heading { +margin-left: 5px; +} + /* Table :: Record Rows ============================= */ From cbab2892a0ecb8644ddb1bf418e347f56face22b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 18 Dec 2010 17:49:20 +0100 Subject: [PATCH 0853/2024] Bugfix: if form_action is nt :create use it for label too --- frontends/default/views/_create_form.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index 6e502c8afa..77c711b46c 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -1,6 +1,7 @@ +<% form_action ||= :create %> <%= render :partial => "base_form", :locals => {:xhr => xhr ||= nil, - :form_action => form_action ||= :create, + :form_action => form_action, :method => method ||= :post, :cancel_link => cancel_link ||= true, - :headline => headline ||= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil)} %> + :headline => headline ||= active_scaffold_config.send(form_action).label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil)} %> From db1446f5e9ad723dc36f985aca38daa3a57ef632 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 20 Dec 2010 09:54:19 +0100 Subject: [PATCH 0854/2024] Fix colspan with mark records enabled --- frontends/default/views/_list.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index b7fca590cd..b7c6036b20 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -6,7 +6,7 @@ </thead> <tbody class="messages"> <tr> - <td colspan="<%= active_scaffold_config.list.columns.length + 1 -%>" class="messages-container"> + <td colspan="<%= active_scaffold_config.list.columns.length + (active_scaffold_config.list.mark_records ? 2 : 1) -%>" class="messages-container"> <%= render :partial => 'list_messages' %> </td> </tr> From 5f58923bea69ca7f1b4b9d6155176dbb903d5c98 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 20 Dec 2010 17:50:07 +0100 Subject: [PATCH 0855/2024] Bugfix: do not add delete actionlink in nested_mode if delete action is excluded --- lib/active_scaffold/actions/nested.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index dd38329e55..e22ecee2f3 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -62,7 +62,9 @@ def include_habtm_actions active_scaffold_config.action_links.add('new_existing', :label => :add_existing, :type => :collection, :security_method => :add_existing_authorized?) unless active_scaffold_config.action_links['new_existing'] if active_scaffold_config.nested.shallow_delete active_scaffold_config.action_links.add('destroy_existing', :label => :remove, :type => :member, :confirm => :are_you_sure_to_delete, :method => :delete, :position => false, :security_method => :delete_existing_authorized?) unless active_scaffold_config.action_links['destroy_existing'] - active_scaffold_config.action_links.delete("delete") if active_scaffold_config.action_links['delete'] + if active_scaffold_config.actions.include?(:delete) + active_scaffold_config.action_links.delete("delete") if active_scaffold_config.action_links['delete'] + end end else # Production mode is caching this link into a non nested scaffold @@ -70,7 +72,9 @@ def include_habtm_actions if active_scaffold_config.nested.shallow_delete active_scaffold_config.action_links.delete("destroy_existing") if active_scaffold_config.action_links['destroy_existing'] - active_scaffold_config.action_links.add(ActiveScaffold::Config::Delete.link) unless active_scaffold_config.action_links['delete'] + if active_scaffold_config.actions.include?(:delete) + active_scaffold_config.action_links.add(ActiveScaffold::Config::Delete.link) unless active_scaffold_config.action_links['delete'] + end end end end From e7747710301620ef3b64a6ace74a846ce3596923 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 20 Dec 2010 20:45:57 +0100 Subject: [PATCH 0856/2024] column calculate might be a Proc for complex calculations --- lib/active_scaffold/helpers/view_helpers.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 20643542bc..b83b47d1e5 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -243,11 +243,15 @@ def column_empty?(column_value) end def column_calculation(column) - conditions = controller.send(:all_conditions) - includes = active_scaffold_config.list.count_includes - includes ||= controller.send(:active_scaffold_includes) unless conditions.nil? - calculation = beginning_of_chain.calculate(column.calculate, column.name, :conditions => conditions, - :joins => controller.send(:joins_for_collection), :include => includes) + unless column.calculate.instance_of? Proc + conditions = controller.send(:all_conditions) + includes = active_scaffold_config.list.count_includes + includes ||= controller.send(:active_scaffold_includes) unless conditions.nil? + calculation = beginning_of_chain.calculate(column.calculate, column.name, :conditions => conditions, + :joins => controller.send(:joins_for_collection), :include => includes) + else + column.calculate.call(@records) + end end def render_column_calculation(column) @@ -255,7 +259,7 @@ def render_column_calculation(column) override_formatter = "render_#{column.name}_#{column.calculate}" calculation = send(override_formatter, calculation) if respond_to? override_formatter - "#{as_(column.calculate)}: #{format_column_value nil, column, calculation}" + "#{"#{as_(column.calculate)}: " unless column.calculate.is_a? Proc}#{format_column_value nil, column, calculation}" end def column_show_add_existing(column) From 020537983b9993d1666d6881f76a90a2caeb470e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 20 Dec 2010 21:43:58 +0100 Subject: [PATCH 0857/2024] Bugfix: calculation update working after inplace edit in embedded/nested controller --- frontends/default/javascripts/jquery/active_scaffold.js | 9 ++++++++- .../default/javascripts/prototype/active_scaffold.js | 7 +++++++ frontends/default/views/_list_with_header.html.erb | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 73a58c4f7f..495a0bef6a 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -162,7 +162,14 @@ $(document).ready(function() { } if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content'); - + + if (span.closest('div.active-scaffold').attr('data-eid')) { + if (options['params'].length > 0) { + options['params'] += ";"; + } + options['params'] += ("eid=" + span.closest('div.active-scaffold').attr('data-eid')); + } + if (mode === 'clone') { options.clone_id_suffix = record_id; options.clone_selector = '#' + column_heading.attr('id') + ' .as_inplace_pattern'; diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index ba4b582257..c2a782bf75 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -177,6 +177,13 @@ document.observe("dom:loaded", function() { if (record_id) options.url = options.url.sub('__id__', record_id); if (csrf_param) options['params'] = csrf_param.readAttribute('content') + '=' + csrf_token.readAttribute('content'); + + if (span.up('div.active-scaffold').readAttribute('data-eid')) { + if (options['params'].length > 0) { + options['params'] += ";"; + } + options['params'] += ("eid=" + span.up('div.active-scaffold').readAttribute('data-eid')); + } if (mode === 'clone') { options.nodeIdSuffix = record_id; diff --git a/frontends/default/views/_list_with_header.html.erb b/frontends/default/views/_list_with_header.html.erb index fcbe19c9b2..ba2a002357 100644 --- a/frontends/default/views/_list_with_header.html.erb +++ b/frontends/default/views/_list_with_header.html.erb @@ -1,4 +1,4 @@ -<div id="<%= active_scaffold_id -%>" class="active-scaffold active-scaffold-<%= controller_id %> <%= "#{params[:controller]}-view" %> <%= active_scaffold_config.theme %>-theme"> +<div id="<%= active_scaffold_id -%>" class="active-scaffold active-scaffold-<%= controller_id %> <%= "#{params[:controller]}-view" %> <%= active_scaffold_config.theme %>-theme" <%= "data-eid=#{id_from_controller(params[:eid])}" if params[:eid]%>> <div class="active-scaffold-header"> <%= render :partial => 'list_header' %> </div> From 431f3432e224d91fdcf9600967d05fdb3374659d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 21 Dec 2010 10:27:09 +0100 Subject: [PATCH 0858/2024] Bugfix: jquery inplace_edit plural associations did not work (issue: 54 reported by victor-ono) --- .../javascripts/jquery/jquery.editinplace.js | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/frontends/default/javascripts/jquery/jquery.editinplace.js b/frontends/default/javascripts/jquery/jquery.editinplace.js index 9b2884ac06..2f6586fcfb 100644 --- a/frontends/default/javascripts/jquery/jquery.editinplace.js +++ b/frontends/default/javascripts/jquery/jquery.editinplace.js @@ -455,6 +455,7 @@ $.extend(InlineEditor.prototype, { return; var editor = this.dom.find(':input'); + var enteredText = editor.val(); enteredText = this.triggerDelegateCall('willCloseEditInPlace', enteredText); @@ -468,8 +469,16 @@ $.extend(InlineEditor.prototype, { handleSaveEditor: function(anEvent) { if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent)) return; - - var enteredText = this.dom.find(':input').val(); + + var editor = this.dom.find(':input:not(:button)').not('input:checkbox:not(:checked)'); + var enteredText = ''; + if (editor.length > 1) { + enteredText = jQuery.map(editor, function(item, index) { + return $(item).val(); + }); + } else { + enteredText = editor.val(); + } enteredText = this.triggerDelegateCall('willCloseEditInPlace', enteredText); if (this.isDisabledDefaultSelectChoice() @@ -545,8 +554,16 @@ $.extend(InlineEditor.prototype, { }, handleSubmitToServer: function(enteredText) { - var data = this.settings.update_value + '=' + encodeURIComponent(enteredText) - + '&' + this.settings.element_id + '=' + this.dom.attr("id") + var data = ''; + if (typeof(enteredText) === 'string') { + data += this.settings.update_value + '=' + encodeURIComponent(enteredText) + '&'; + } else { + for(var i = 0;i < enteredText.length; i++) { + data += this.settings.update_value + '[]=' + encodeURIComponent(enteredText[i]) + '&'; + } + } + + data += this.settings.element_id + '=' + this.dom.attr("id") + ((this.settings.params) ? '&' + this.settings.params : '') + '&' + this.settings.original_html + '=' + encodeURIComponent(this.originalValue) /* DEPRECATED in 2.2.0 */ + '&' + this.settings.original_value + '=' + encodeURIComponent(this.originalValue); From 1d0bb65780c86618d059a335d03f59f7fd5666ef Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 21 Dec 2010 12:55:14 +0100 Subject: [PATCH 0859/2024] Bugfix: jquery inplace_edit plural associations only one selected --- frontends/default/javascripts/jquery/jquery.editinplace.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/jquery.editinplace.js b/frontends/default/javascripts/jquery/jquery.editinplace.js index 2f6586fcfb..9bc523a155 100644 --- a/frontends/default/javascripts/jquery/jquery.editinplace.js +++ b/frontends/default/javascripts/jquery/jquery.editinplace.js @@ -470,10 +470,10 @@ $.extend(InlineEditor.prototype, { if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent)) return; - var editor = this.dom.find(':input:not(:button)').not('input:checkbox:not(:checked)'); + var editor = this.dom.find(':input:not(:button)'); var enteredText = ''; if (editor.length > 1) { - enteredText = jQuery.map(editor, function(item, index) { + enteredText = jQuery.map(editor.not('input:checkbox:not(:checked)'), function(item, index) { return $(item).val(); }); } else { From c952f755808a7f89917f88791aa416f6eaea9fb9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 21 Dec 2010 15:03:29 +0100 Subject: [PATCH 0860/2024] add some missing german localizations --- lib/active_scaffold/locale/de.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index d06de709d9..162f504477 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -60,6 +60,9 @@ :'<' => '<', :'!=' => '!=', :between => 'Zwischen', + :contains => 'Enthält', + :begins_with => 'Beginnt', + :ends_with => 'Ended', :today => 'Heute', :yesterday => 'Gestern', :tomorrow => 'Morgen', From a35719b48c8f682692aebcfbd143fbeddb32073d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 21 Dec 2010 15:56:07 +0100 Subject: [PATCH 0861/2024] text_fields for search_range for strings should be bigger than for numeric --- lib/active_scaffold/helpers/search_column_helpers.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index ff889a2260..79f1f7c6f8 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -123,8 +123,13 @@ def field_search_params_range_values(column) def active_scaffold_search_range(column, options) opt_value, from_value, to_value = field_search_params_range_values(column) + + text_field_size = 10 select_options = ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} - select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} if column.column && column.column.text? + if column.column && column.column.text? + select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} + text_field_size = 15 + end from_value = controller.class.condition_value_for_numeric(column, from_value) to_value = controller.class.condition_value_for_numeric(column, to_value) from_value = format_number_value(from_value, column.options) if from_value.is_a?(Numeric) @@ -133,9 +138,9 @@ def active_scaffold_search_range(column, options) options_for_select(select_options, opt_value), :id => "#{options[:id]}_opt", :class => "as_search_range_option") - html << ' ' << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(:id => options[:id], :size => 10)) + html << ' ' << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(:id => options[:id], :size => text_field_size)) html << ' ' << content_tag(:span, (' - ' + text_field_tag("#{options[:name]}[to]", to_value, - active_scaffold_input_text_options(:id => "#{options[:id]}_to", :size => 10))).html_safe, + active_scaffold_input_text_options(:id => "#{options[:id]}_to", :size => text_field_size))).html_safe, :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => "display:#{(opt_value == 'BETWEEN') ? '' : 'none'}") html end From 58fbcd3d7325a71f5091231fbf592a3de05cc62d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 21 Dec 2010 18:03:44 +0100 Subject: [PATCH 0862/2024] querying nested_parent_record once should be enough --- lib/active_scaffold/actions/nested.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index e22ecee2f3..eb91b885df 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -91,7 +91,7 @@ def beginning_of_chain end def nested_parent_record(crud = :read) - find_if_allowed(nested.parent_id, crud, nested.parent_model) + @nested_parent_record ||= find_if_allowed(nested.parent_id, crud, nested.parent_model) end def create_association_with_parent(record) From a46ab52d2b77283b659b4096d9b83e224dba8a91 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 21 Dec 2010 18:04:32 +0100 Subject: [PATCH 0863/2024] check if column.css_class is a Proc --- frontends/default/views/_form.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index 03703801b0..ab0befcee6 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -12,11 +12,11 @@ <% elsif column.readonly_association? next %> <% elsif renders_as == :subform and !override_form_field?(column) -%> - <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? %>" id="<%= sub_form_id(:association => column.name) %>"> + <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %>" id="<%= sub_form_id(:association => column.name) %>"> <%= render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%> </li> <% else -%> - <li class="form-element <%= 'required' if column.required? %> <%= column.css_class unless column.css_class.nil? %>"> + <li class="form-element <%= 'required' if column.required? %> <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %>"> <%= render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%> </li> <% end -%> From 2a4eb1cf76c0a5e050b6153b02ab6f187aa6375c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 21 Dec 2010 19:26:38 +0100 Subject: [PATCH 0864/2024] Bugfix: issue 54 --- lib/active_scaffold/actions/update.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index c090e2f6c9..9e0d19f71f 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -100,7 +100,10 @@ def do_update_column if @record.authorized_for?(:crud_type => :update, :column => params[:column]) column = active_scaffold_config.columns[params[:column].to_sym] params[:value] ||= @record.column_for_attribute(params[:column]).default unless @record.column_for_attribute(params[:column]).nil? || @record.column_for_attribute(params[:column]).null - params[:value] = column_value_from_param_value(@record, column, params[:value]) unless column.nil? + unless column.nil? + params[:value] = column_value_from_param_value(@record, column, params[:value]) + params[:value] = [] if params[:value].nil? && column.form_ui && column.plural_association? + end @record.send("#{params[:column]}=", params[:value]) before_update_save(@record) @record.save From 35294656b2e69cfe76283aebafcb6840edf65254 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 22 Dec 2010 09:43:38 +0100 Subject: [PATCH 0865/2024] added create option refresh_list_after_create --- frontends/default/views/on_create.js.rjs | 4 +++- lib/active_scaffold/actions/create.rb | 4 ++++ lib/active_scaffold/config/create.rb | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index 69e39f0522..a145b88940 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -2,7 +2,9 @@ form_selector = "#{element_form_id(:action => :create)}" page << "ActiveScaffold.find_action_link('#{form_selector}').update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? - if @insert_row + if (active_scaffold_config.create.refresh_list_after_create) + page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) + elsif @insert_row new_row = render :partial => 'list_record', :locals => {:record => @record} insert_at ||= :top page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}', #{{:insert_at => insert_at}.to_json});" diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 9c62912b31..a5401ac5c6 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -62,6 +62,10 @@ def create_respond_to_html end def create_respond_to_js + if active_scaffold_config.create.refresh_list_after_create && successful? + do_search if respond_to? :do_search + do_list + end render :action => 'on_create' end diff --git a/lib/active_scaffold/config/create.rb b/lib/active_scaffold/config/create.rb index c34ab412ac..f1e3286293 100644 --- a/lib/active_scaffold/config/create.rb +++ b/lib/active_scaffold/config/create.rb @@ -26,6 +26,10 @@ def self.link=(val) cattr_accessor :edit_after_create @@edit_after_create = false + # whether we should refresh list after create or not + cattr_accessor :refresh_list_after_create + @@refresh_list_after_create = false + # instance-level configuration # ---------------------------- # the label= method already exists in the Form base class @@ -39,5 +43,8 @@ def label(model = nil) # whether the form stays open after a create or not attr_accessor :edit_after_create + + # whether we should refresh list after create or not + attr_accessor :refresh_list_after_create end end From b76ce6185b68155ec6c05a7b1bc2637dbea8bf8d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 22 Dec 2010 13:32:51 +0100 Subject: [PATCH 0866/2024] nested_parent_record should be available for helpers --- lib/active_scaffold/actions/nested.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index eb91b885df..ab2bdf12cf 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -12,6 +12,7 @@ def self.included(base) end base.before_filter :include_habtm_actions base.helper_method :nested + base.helper_method :nested_parent_record end protected From e6b63161c5329f27ed1d4bff3a14b90526e08d20 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 22 Dec 2010 13:50:22 +0100 Subject: [PATCH 0867/2024] missing german localization --- lib/active_scaffold/locale/de.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 162f504477..04b8534d57 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -7,6 +7,7 @@ :are_you_sure_to_delete => 'Sind Sie sicher?', :cancel => 'Abbrechen', :click_to_edit => 'Zum Editieren anklicken', + :click_to_reset => 'Reset', :close => 'Schliessen', :config_list => 'Konfigurieren', :config_list_model => 'Konfiguriere Spalten für %{model}', From 22278a5d0acc298fec26abdbf93f5f8a16eb44f4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 22 Dec 2010 14:47:17 +0100 Subject: [PATCH 0868/2024] Bugfix: have to delete destroy_action param --- lib/active_scaffold/actions/delete.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index ea0cf37a7c..c008fc154d 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -5,6 +5,7 @@ def self.included(base) end def destroy + params.delete :destroy_action process_action_link_action(:destroy) do |record| do_destroy end From 62211904696c83d194d9de0b13930c0047108839 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 22 Dec 2010 14:53:56 +0100 Subject: [PATCH 0869/2024] Bugfix: assign class level refresh_list_after_create to instance level --- lib/active_scaffold/config/create.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/config/create.rb b/lib/active_scaffold/config/create.rb index f1e3286293..b02250886e 100644 --- a/lib/active_scaffold/config/create.rb +++ b/lib/active_scaffold/config/create.rb @@ -5,6 +5,7 @@ def initialize(*args) super self.persistent = self.class.persistent self.edit_after_create = self.class.edit_after_create + self.refresh_list_after_create = self.class.refresh_list_after_create end # global level configuration From 929a64e712773dcfa3e2f7729b17f728e888a8c6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 22 Dec 2010 15:45:42 +0100 Subject: [PATCH 0870/2024] update add option refresh_list_after_update --- frontends/default/views/on_update.js.rjs | 14 +++++++++----- lib/active_scaffold/actions/update.rb | 4 ++++ lib/active_scaffold/config/update.rb | 8 ++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 5a17e9b6ff..fa04730d46 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -2,13 +2,17 @@ form_selector = "#{element_form_id(:action => :update)}" page << "ActiveScaffold.find_action_link('#{form_selector}').update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? - updated_row = if nested? && nested.belongs_to? - nil + if (active_scaffold_config.update.refresh_list_after_update) + page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) else - render :partial => 'list_record', :locals => {:record => @record} + updated_row = if nested? && nested.belongs_to? + nil + else + render :partial => 'list_record', :locals => {:record => @record} + end + page << "ActiveScaffold.find_action_link('#{form_selector}').close('#{escape_javascript(updated_row)}');" + page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} end - page << "ActiveScaffold.find_action_link('#{form_selector}').close('#{escape_javascript(updated_row)}');" - page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} else page.call 'ActiveScaffold.replace', form_selector, render(:partial => 'update_form', :locals => {:xhr => true}) page.call 'ActiveScaffold.scroll_to', form_selector diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 9e0d19f71f..f3383abe88 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -49,6 +49,10 @@ def update_respond_to_html end end def update_respond_to_js + if active_scaffold_config.update.refresh_list_after_update && successful? + do_search if respond_to? :do_search + do_list + end render :action => 'on_update' end def update_respond_to_xml diff --git a/lib/active_scaffold/config/update.rb b/lib/active_scaffold/config/update.rb index 98e2ebc9a9..fd459d03de 100644 --- a/lib/active_scaffold/config/update.rb +++ b/lib/active_scaffold/config/update.rb @@ -4,6 +4,7 @@ class Update < ActiveScaffold::Config::Form def initialize(*args) super self.nested_links = self.class.nested_links + self.refresh_list_after_update = self.class.refresh_list_after_update end # global level configuration @@ -17,6 +18,10 @@ def self.link=(val) end @@link = ActiveScaffold::DataStructures::ActionLink.new('edit', :label => :edit, :type => :member, :security_method => :update_authorized?) + # whether we should refresh list after create or not + cattr_accessor :refresh_list_after_update + @@refresh_list_after_update = false + # instance-level configuration # ---------------------------- @@ -33,6 +38,9 @@ def label def hide_nested_column @hide_nested_column.nil? ? true : @hide_nested_column end + + # whether we should refresh list after create or not + attr_accessor :refresh_list_after_update end end From 57af2044b0edff9a24fb47dd448b008d51b636ed Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 22 Dec 2010 18:21:30 +0100 Subject: [PATCH 0871/2024] corrected comment create should be update --- lib/active_scaffold/config/update.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/config/update.rb b/lib/active_scaffold/config/update.rb index fd459d03de..5b14d5f874 100644 --- a/lib/active_scaffold/config/update.rb +++ b/lib/active_scaffold/config/update.rb @@ -18,7 +18,7 @@ def self.link=(val) end @@link = ActiveScaffold::DataStructures::ActionLink.new('edit', :label => :edit, :type => :member, :security_method => :update_authorized?) - # whether we should refresh list after create or not + # whether we should refresh list after update or not cattr_accessor :refresh_list_after_update @@refresh_list_after_update = false @@ -39,7 +39,7 @@ def hide_nested_column @hide_nested_column.nil? ? true : @hide_nested_column end - # whether we should refresh list after create or not + # whether we should refresh list after update or not attr_accessor :refresh_list_after_update end From 112341cf0e2acddb02b3d61f3cb0722b00f4a57a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 28 Dec 2010 10:01:26 +0100 Subject: [PATCH 0872/2024] Bugfix: ancestry_bridge fix updating parent --- .../bridges/ancestry/lib/ancestry_bridge.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb b/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb index 8b6cbb08b3..f1bb9c76b5 100644 --- a/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +++ b/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb @@ -3,13 +3,12 @@ def initialize_with_ancestry(model_id) initialize_without_ancestry(model_id) return unless self.model.respond_to? :ancestry_column - - col_config = self.columns[self.model.ancestry_column] - unless col_config.nil? - col_config.form_ui = :ancestry - create.columns.exclude :ancestry - list.columns.exclude :ancestry - end + + self.columns << :parent_id + self.columns[:parent_id].form_ui = :ancestry + update.columns.exclude :ancestry + create.columns.exclude :ancestry, :parent_id + list.columns.exclude :ancestry, :parent_id end alias_method_chain :initialize, :ancestry @@ -20,6 +19,8 @@ module AncestryBridge module FormColumnHelpers def active_scaffold_input_ancestry(column, options) select_options = [] + select_control_options = {:selected => @record.parent_id} + select_control_options[:include_blank] = as_(:_select_) if @record.parent_id.nil? traverse_ancestry = proc do|key, value| unless key == @record select_options << ["#{'__' * key.depth}#{key.to_label}", key.id] @@ -27,7 +28,7 @@ def active_scaffold_input_ancestry(column, options) end end @record.class.arrange.each(&traverse_ancestry) - select(:record, :ancestry, select_options, { :selected => @record.send(:ancestry) }, options) + select(:record, :ancestry, select_options, select_control_options, options) end end end From 93cf4d12e0fe7333403d94310ef3a66c80bcce59 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 28 Dec 2010 13:28:10 +0100 Subject: [PATCH 0873/2024] Bugfix: rename error_messages_for to as specific one (issue 57 reported by niblh) --- frontends/default/views/_base_form.html.erb | 2 +- frontends/default/views/_form_messages.html.erb | 2 +- frontends/default/views/_horizontal_subform.html.erb | 2 +- frontends/default/views/_vertical_subform.html.erb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index 0a618a1950..c23eed6068 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -22,7 +22,7 @@ end -%> <% if request.xhr? -%> <% records = @error_records || Array(@record) records.each do |record| %> - <%= error_messages_for record, :object_name => "#{record.class.model_name.human.downcase}#{record.new_record? ? '' : ": #{record.to_label}"}" %> + <%= active_scaffold_error_messages_for record, :object_name => "#{record.class.model_name.human.downcase}#{record.new_record? ? '' : ": #{record.to_label}"}" %> <% end %> <% else -%> <%= render :partial => 'form_messages' %> diff --git a/frontends/default/views/_form_messages.html.erb b/frontends/default/views/_form_messages.html.erb index 7c258fe991..5095dd03cd 100644 --- a/frontends/default/views/_form_messages.html.erb +++ b/frontends/default/views/_form_messages.html.erb @@ -1,5 +1,5 @@ <%= render :partial => 'messages' %> <% unless @record.nil? %> - <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> + <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> <% end %> \ No newline at end of file diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index e44de29494..89186df852 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -8,7 +8,7 @@ <% if @record.errors.count -%> <tr class="association-record-errors"> <td colspan="<%= active_scaffold_config_for(@record.class).subform.columns.length + 1 %>" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>"> - <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> + <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> </td> </tr> <% end %> diff --git a/frontends/default/views/_vertical_subform.html.erb b/frontends/default/views/_vertical_subform.html.erb index e9e95f4b60..130de78a2a 100644 --- a/frontends/default/views/_vertical_subform.html.erb +++ b/frontends/default/views/_vertical_subform.html.erb @@ -3,7 +3,7 @@ <% @record = associated[index] -%> <% if @record.errors.count -%> <div class="association-record-errors" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>"> - <%= error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> + <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> </div> <% end %> <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => @record.new_record? && @record == associated.last} %> diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index b83b47d1e5..b6464d2c80 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -272,7 +272,7 @@ def column_show_add_new(column, associated, record) value end - def error_messages_for(*params) + def active_scaffold_error_messages_for(*params) options = params.extract_options!.symbolize_keys objects = Array.wrap(options.delete(:object) || params).map do |object| From 881e8d183feb4243f1268b6b6ec062e38f81454f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 28 Dec 2010 14:10:36 +0100 Subject: [PATCH 0874/2024] Bugfix: model authorization is nt called for member action_link rendering (issue: 44 reported by PanosJee) --- frontends/default/views/_list_actions.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 6ff05ec44d..019938eed9 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -6,7 +6,7 @@ <%= render :partial => 'action_group', :locals => {:action_links => action_links || active_scaffold_config.action_links.member, :url_options => url_options, :record => record, - :traverse_options => {:record => record}, + :traverse_options => {:for => record}, :start_level_0_tag => '<td>', :end_level_0_tag => '</td>'} %> </tr> From b1f55eebdd378242681dc66c12feacbe08ec9f77 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 28 Dec 2010 20:29:42 +0100 Subject: [PATCH 0875/2024] Bugfix: Prototype do not call id directly on element use readAttribute instead --- .../javascripts/prototype/active_scaffold.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index c2a782bf75..b1e3612371 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -45,7 +45,7 @@ document.observe("dom:loaded", function() { document.on('submit', 'form.as_form.as_remote_upload', function(event) { var as_form = event.findElement('form'); if (as_form && as_form.readAttribute('data-loading') == 'true') { - setTimeout("ActiveScaffold.disable_form('" + as_form.id + "')", 10); + setTimeout("ActiveScaffold.disable_form('" + as_form.readAttribute('id') + "')", 10); } return true; }); @@ -187,7 +187,7 @@ document.observe("dom:loaded", function() { if (mode === 'clone') { options.nodeIdSuffix = record_id; - options.inplacePatternSelector = '#' + column_heading.id + ' .as_inplace_pattern'; + options.inplacePatternSelector = '#' + column_heading.readAttribute('id') + ' .as_inplace_pattern'; options['onFormCustomization'] = new Function('element', 'form', 'element.clonePatternField();'); } @@ -258,14 +258,14 @@ document.observe("dom:loaded", function() { }); document.on('change', 'select.as_search_range_option', function(event) { var element = event.findElement(); - Element[element.value == 'BETWEEN' ? 'show' : 'hide'](element.id.sub('_opt', '_between')); + Element[element.value == 'BETWEEN' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_between')); return true; }); document.on('change', 'select.as_search_date_time_option', function(event) { var element = event.findElement(); - Element[!(element.value == 'PAST' || element.value == 'FUTURE' || element.value == 'RANGE') ? 'show' : 'hide'](element.id.sub('_opt', '_numeric')); - Element[(element.value == 'PAST' || element.value == 'FUTURE') ? 'show' : 'hide'](element.id.sub('_opt', '_trend')); - Element[element.value == 'RANGE' ? 'show' : 'hide'](element.id.sub('_opt', '_range')); + Element[!(element.value == 'PAST' || element.value == 'FUTURE' || element.value == 'RANGE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_numeric')); + Element[(element.value == 'PAST' || element.value == 'FUTURE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_trend')); + Element[element.value == 'RANGE' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_range')); return true; }); document.on('change', 'select.as_update_date_operator', function(event) { @@ -364,7 +364,7 @@ var ActiveScaffold = { replace: function(element, html) { element = $(element) Element.replace(element, html); - element = $(element.id); + element = $(element.read_attribute('id')); return element; }, @@ -392,14 +392,14 @@ var ActiveScaffold = { disable_form: function(as_form) { as_form = $(as_form) - var loading_indicator = $(as_form.id.sub('-form', '-loading-indicator')); + var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator')); if (loading_indicator) loading_indicator.style.visibility = 'visible'; as_form.disable(); }, enable_form: function(as_form) { as_form = $(as_form) - var loading_indicator = $(as_form.id.sub('-form', '-loading-indicator')); + var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator')); if (loading_indicator) loading_indicator.style.visibility = 'hidden'; as_form.enable(); }, @@ -497,7 +497,7 @@ var ActiveScaffold = { options['callback'] = new Function('form', 'return Form.serialize(form) + ' + "'&" + options['params'] + "';"); } span.removeClassName('hover'); - span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.id, options.url, options) + span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.readAttribute('id'), options.url, options) span.inplace_edit.enterEditMode(); }, @@ -521,7 +521,7 @@ var ActiveScaffold = { element.insert(content); } } else { - if (current = $$('#' + element.id + ' tr.association-record')[0]) { + if (current = $$('#' + element.readAttribute('id') + ' tr.association-record')[0]) { this.replace(current, content); } else { element.insert({top: content}); @@ -725,7 +725,7 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ }, scaffold_id: function() { - return this.tag.up('div.active-scaffold').id; + return this.tag.up('div.active-scaffold').readAttribute('id'); }, update_flash_messages: function(messages) { From 12a4f8ae40929f41344c79180972f3248816b30c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 29 Dec 2010 13:27:45 +0100 Subject: [PATCH 0876/2024] Bugfix: update has_one associations via inline edit link (issue 56 by eugenekorpan) --- frontends/default/views/on_update.js.rjs | 2 +- lib/active_scaffold/data_structures/nested_info.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index fa04730d46..0f7db32358 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -5,7 +5,7 @@ if controller.send :successful? if (active_scaffold_config.update.refresh_list_after_update) page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) else - updated_row = if nested? && nested.belongs_to? + updated_row = if nested? && (nested.belongs_to? || nested.has_one?) nil else render :partial => 'list_record', :locals => {:record => @record} diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index e76d43e1f9..0be9b1df6a 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -38,6 +38,10 @@ def habtm? def belongs_to? false end + + def has_one? + false + end def readonly? false @@ -62,6 +66,10 @@ def habtm? def belongs_to? association.belongs_to? end + + def has_one? + association.macro == :has_one + end def readonly? if association.options.has_key? :readonly From 774c69f7fdc63dcf8f39039899fb3a057e9ee607 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 29 Dec 2010 14:04:42 +0100 Subject: [PATCH 0877/2024] Bugfix: create has_one association via create inline link (issue 56) --- lib/active_scaffold/actions/nested.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index ab2bdf12cf..d3a00b9d83 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -96,14 +96,18 @@ def nested_parent_record(crud = :read) end def create_association_with_parent(record) - if nested? && nested.belongs_to? && nested.child_association - parent = nested_parent_record(:read) - case nested.child_association.macro - when :has_one - record.send("#{nested.child_association.name}=", parent) - when :has_many - record.send("#{nested.child_association.name}").send(:<<, parent) - end unless parent.nil? + if nested? + if (nested.belongs_to? || nested.has_one?) && nested.child_association + parent = nested_parent_record(:read) + case nested.child_association.macro + when :has_one + record.send("#{nested.child_association.name}=", parent) + when :belongs_to + record.send("#{nested.child_association.name}=", parent) + when :has_many + record.send("#{nested.child_association.name}").send(:<<, parent) + end unless parent.nil? + end end end From f7e17de081b656dd47e563396525a03068604be7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 29 Dec 2010 14:24:10 +0100 Subject: [PATCH 0878/2024] Bugfix: js error after creating has_one association via create inline link (issue: 56) --- lib/active_scaffold/actions/create.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index a5401ac5c6..5b091cdb72 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -14,7 +14,7 @@ def new def create do_create - @insert_row = !(nested? && nested.belongs_to?) && params[:parent_controller].nil? + @insert_row = !(nested? && (nested.belongs_to? || nested.has_one?)) && params[:parent_controller].nil? respond_to_action(:create) end From 53dafeb51a93f877cb5993973481bb5dc86b0aa5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 29 Dec 2010 15:42:31 +0100 Subject: [PATCH 0879/2024] updated ru locale with new keys --- lib/active_scaffold/locale/ru.yml | 51 ++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/locale/ru.yml b/lib/active_scaffold/locale/ru.yml index ec8e710426..1f57054f28 100644 --- a/lib/active_scaffold/locale/ru.yml +++ b/lib/active_scaffold/locale/ru.yml @@ -6,7 +6,10 @@ ru: are_you_sure_to_delete: 'Вы уверены?' cancel: 'Отмена' click_to_edit: 'Нажмите для редактирования' + click_to_reset: 'Pulsa para restaurar' close: 'Закрыть' + config_list: 'Configure' + config_list_model: 'Configure Columns for %{model}' create: 'Создать запись' create_model: 'Создать запись %{model}' create_another: 'Создать другую запись' @@ -22,12 +25,15 @@ ru: nested_for_model: '%{parent_model} / %{nested_model}' nested_of_model: '%{nested_model} of %{parent_model}' filtered: '(Найденное)' - found: 'Найдено' + found: + one: 'Найдено' + other: 'Найдено' hide: 'Скрыть' live_search: 'Поиск' loading: 'Загрузка...' next: 'Следующее' no_entries: 'Нет записей' + no_options: 'sin opciones' omit_header: 'Omit Header' options: 'Настройки' pdf: 'PDF' @@ -56,6 +62,49 @@ ru: '<': '<' '!=': '!=' between: 'Между' + contains: 'Contiene' + begins_with: 'Empieza con' + ends_with: 'Termina con' + today: 'Today' + yesterday: 'Yesterday' + tomorrow: 'Tommorrow' + this_week: 'This Week' + prev_week: 'Last Week' + next_week: 'Next Week' + this_month: 'This Month' + prev_month: 'Last Month' + next_month: 'Next Month' + this_year: 'This Year' + prev_year: 'Last Year' + next_year: 'Next Year' + past: 'Past' + future: 'Future' + range: 'Range' + seconds: 'Seconds' + minutes: 'Minutes' + hours: 'Hours' + days: 'Days' + weeks: 'Weeks' + months: 'Months' + years: 'Years' + optional_attributes: 'Further Options' + null: 'Null' + not_null: 'Not Null' + date_picker_options: + weekHeader: 'Нед' + firstDay: 1 + isRTL: false + showMonthAfterYear: false + datetime_picker_options: + timeText: 'Hora' + currentText: 'Ahora' + closeText: 'Cerrar' + errors: + template: + header: + one: "1 error prohibited this %{model} from being saved." + other: "%{count} errors prohibited this %{model} from being saved" + body: "There were problems with the following fields:" # error_messages internal_error: 'Внутренняя ошибка сервера.' From d8d10d4faee8250bc068d622d16111c171def8b2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 29 Dec 2010 16:11:49 +0100 Subject: [PATCH 0880/2024] Bugfix: prototype typo read_attribute -> readAttribute --- frontends/default/javascripts/prototype/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index b1e3612371..9d9a4b1059 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -364,7 +364,7 @@ var ActiveScaffold = { replace: function(element, html) { element = $(element) Element.replace(element, html); - element = $(element.read_attribute('id')); + element = $(element.readAttribute('id')); return element; }, From 974882557bb143d4a67a8c0a8f5962430bec076f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 30 Dec 2010 07:55:04 +0100 Subject: [PATCH 0881/2024] bugfix: cancel_link in create form not working if create.link.page=true (issue:60 reported by victor-ono) --- frontends/default/views/_base_form.html.erb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index c23eed6068..9b8378c52b 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -9,10 +9,15 @@ options = {:onsubmit => onsubmit, :class => "as_form #{form_action.to_s}", :method => method, 'data-loading' => true} +cancel_options = {:class => 'as_cancel', 'data-refresh' => false} + if xhr && as_action_config.multipart? # file_uploads form_remote_upload_tag url_options.merge({:iframe => true}), options else - options[:remote] = true if xhr && !as_action_config.multipart? + if xhr && !as_action_config.multipart? + options[:remote] = true + cancel_options[:remote] = true + end form_tag url_options, options end -%> @@ -33,7 +38,7 @@ end -%> <p class="form-footer"> <%= submit_tag as_(form_action), :class => "submit" %> - <%= link_to(as_(:cancel), main_path_to_return, :class => 'as_cancel', :remote => true, 'data-refresh' => false) if cancel_link %> + <%= link_to(as_(:cancel), main_path_to_return, cancel_options) if cancel_link %> <%= loading_indicator_tag(:action => form_action, :id => params[:id]) %> </p> From a73cf45b491a0968df3bc79f03cb5976b93677b7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 30 Dec 2010 10:23:27 +0100 Subject: [PATCH 0882/2024] controller flash messages container from p to div to enable use of more html tags inside of messages --- frontends/default/views/_messages.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_messages.html.erb b/frontends/default/views/_messages.html.erb index 9925482491..4d87e191f4 100644 --- a/frontends/default/views/_messages.html.erb +++ b/frontends/default/views/_messages.html.erb @@ -1,10 +1,10 @@ <% for name in [:info, :warning, :error] %> <% if flash[name] %> - <p class="<%= "#{name}-message message" %>" > + <div class="<%= "#{name}-message message" %>"> <%= h flash[name] %> <% if request.xhr? %> <a href="#" onclick="ActiveScaffold.remove(this.parentNode); return false;" title="<%= as_(:close) %>"><%= as_(:close) %></a> <% end %> - </p> + </div> <% end %> <% end %> From ff9687875255871dc448020eb6ba4ff0254035bd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 30 Dec 2010 10:31:58 +0100 Subject: [PATCH 0883/2024] add some more options to active_scaffold_error_messages_for --- lib/active_scaffold/helpers/view_helpers.rb | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index b6464d2c80..146cc9dc37 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -274,6 +274,7 @@ def column_show_add_new(column, associated, record) def active_scaffold_error_messages_for(*params) options = params.extract_options!.symbolize_keys + options.reverse_merge!(:container_tag => :div, :list_type => :ul) objects = Array.wrap(options.delete(:object) || params).map do |object| object = instance_variable_get("@#{object}") unless object.respond_to?(:to_model) @@ -311,17 +312,21 @@ def active_scaffold_error_messages_for(*params) error_messages = objects.sum do |object| object.errors.full_messages.map do |msg| - content_tag(:li, msg) + options[:list_type] != :br ? content_tag(:li, msg) : msg end - end.join.html_safe + end + error_messages = if options[:list_type] == :br + error_messages.join('<br/>').html_safe + else + content_tag(options[:list_type], error_messages.join.html_safe) + end - contents = '' + contents = [] contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank? contents << content_tag(:p, message) unless message.blank? - contents << content_tag(:ul, error_messages) - - content_tag(:div, contents.html_safe, html) - + contents << error_messages + contents = contents.join.html_safe + options[:container_tag] ? content_tag(options[:container_tag], contents, html) : contents else '' end From 7409123bbe8bda95abb4c563f3cd40d7673e8f89 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 30 Dec 2010 12:01:37 +0100 Subject: [PATCH 0884/2024] change logging to debug --- lib/extensions/resources.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extensions/resources.rb b/lib/extensions/resources.rb index 3699174649..8e7d658417 100644 --- a/lib/extensions/resources.rb +++ b/lib/extensions/resources.rb @@ -9,7 +9,7 @@ class Resource # by overwriting the attr_reader :options, we can parse out a special :active_scaffold flag just-in-time. def options_with_active_scaffold if @options.delete :active_scaffold - logger.info "ActiveScaffold: extending RESTful routes for #{@plural}" + logger.debug "ActiveScaffold: extending RESTful routes for #{@plural}" @options[:collection] ||= {} @options[:collection].merge! ACTIVE_SCAFFOLD_ROUTING[:collection] @options[:member] ||= {} From 6f71f35b6d36fc9bc74fc328d1da8e671005281d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 30 Dec 2010 12:47:35 +0100 Subject: [PATCH 0885/2024] use Null as well in german --- lib/active_scaffold/locale/de.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index 04b8534d57..dc994bad67 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -87,8 +87,8 @@ :months => 'Monate', :years => 'Jahre', :optional_attributes => 'Weitere', - :null => 'Undefiniert', - :not_null => 'Definiert', + :null => 'Null', + :not_null => 'Nicht Null', :date_picker_options => { :weekHeader => 'Wo', :firstDay => 1, From 634e45657c91597f895b176e32a992f3dd278b13 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 30 Dec 2010 13:52:21 +0100 Subject: [PATCH 0886/2024] Feature: show record.errors in case of a unsuccesfull destroy action(issue 37 requested by MikeBlyth) --- frontends/default/views/destroy.js.rjs | 2 ++ lib/active_scaffold/actions/delete.rb | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/destroy.js.rjs b/frontends/default/views/destroy.js.rjs index a69fe0d127..8d8c1ae6b7 100644 --- a/frontends/default/views/destroy.js.rjs +++ b/frontends/default/views/destroy.js.rjs @@ -1,5 +1,7 @@ if controller.send(:successful?) page << "ActiveScaffold.delete_record_row('#{element_row_id(:action => 'list', :id => params[:id])}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} +else + flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) end page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages') diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index c008fc154d..75c347c23a 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -13,7 +13,12 @@ def destroy protected def destroy_respond_to_html - flash[:info] = as_(:deleted_model, :model => @record.to_label) if self.successful? + if self.successful? + flash[:info] = as_(:deleted_model, :model => @record.to_label) + else + #error_message_for not available in controller... + #flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) + end return_to_main end From a8c510e357f8b6b8b6686502549cb0c0e6c9a216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D0=B1=D0=BA=D0=BE=D0=B2?= <korobkov@neverbox.org> Date: Thu, 30 Dec 2010 18:20:14 +0300 Subject: [PATCH 0887/2024] Updated russian locale --- lib/active_scaffold/locale/ru.yml | 128 ++++++++++++++++-------------- 1 file changed, 68 insertions(+), 60 deletions(-) diff --git a/lib/active_scaffold/locale/ru.yml b/lib/active_scaffold/locale/ru.yml index 1f57054f28..8952f1c7a6 100644 --- a/lib/active_scaffold/locale/ru.yml +++ b/lib/active_scaffold/locale/ru.yml @@ -2,110 +2,118 @@ ru: active_scaffold: add: 'Добавить запись' add_existing: 'Добавить существующую запись' - add_existing_model: 'Добавить существующую запись %{model}' - are_you_sure_to_delete: 'Вы уверены?' + add_existing_model: '%{model}: добавить существующую запись' + are_you_sure_to_delete: 'Удалить %{label}?' cancel: 'Отмена' click_to_edit: 'Нажмите для редактирования' - click_to_reset: 'Pulsa para restaurar' + click_to_reset: 'Нажмите для сброса' close: 'Закрыть' - config_list: 'Configure' - config_list_model: 'Configure Columns for %{model}' - create: 'Создать запись' - create_model: 'Создать запись %{model}' + config_list: 'Настройки списка' + config_list_model: '%{model}: настройки списка' + create: 'Создать' + create_model: '%{model}: создать запись' create_another: 'Создать другую запись' - created_model: 'Создана запись %{model}' + created_model: '%{model}: запись создана' create_new: 'Создать новую запись' customize: 'Настроить' delete: 'Удалить' - deleted_model: 'Удалена запись %{model}' + deleted_model: '%{model}: запись удалена' delimiter: 'Разделитель' download: 'Загрузить' edit: 'Изменить' export: 'Экспорт' nested_for_model: '%{parent_model} / %{nested_model}' - nested_of_model: '%{nested_model} of %{parent_model}' + nested_of_model: '%{nested_model} @ %{parent_model}' + false: 'Нет' filtered: '(Найденное)' found: - one: 'Найдено' - other: 'Найдено' + one: 'запись' + few: 'записи' + many: 'записей' + other: 'записи' hide: 'Скрыть' live_search: 'Поиск' - loading: 'Загрузка...' + loading: 'Загрузка…' next: 'Следующее' no_entries: 'Нет записей' - no_options: 'sin opciones' - omit_header: 'Omit Header' + no_options: 'Нет вариантов' + omit_header: 'Пропустить заголовок' options: 'Настройки' pdf: 'PDF' previous: 'Предыдущее' - print: 'Распечатать' + print: 'Печать' refresh: 'Обновить' remove: 'Удалить' remove_file: 'Удалить или заменить файл' replace_with_new: 'Заменить новым' - revisions_for_model: 'Редакции %{model}' - reset: 'Сбросить' - saving: 'Сохранение...' + revisions_for_model: '%{model}: редакции' + reset: 'Сброс' + saving: 'Сохранение…' search: 'Поиск' search_terms: 'Ключевые слова' _select_: '- выбрать -' show: 'Показать' - show_model: 'Показать запись %{model}' + show_model: '%{model}: показать запись' _to_ : ' to ' + true: 'Да' update: 'Обновить запись' - update_model: 'Обновить запись %{model}' - updated_model: 'Обновлена запись %{model}' + update_model: '%{model}: обновить запись' + updated_model: '%{model}: запись обновлена' '=': '=' '>=': '>=' '<=': '<=' '>': '>' '<': '<' '!=': '!=' - between: 'Между' - contains: 'Contiene' - begins_with: 'Empieza con' - ends_with: 'Termina con' - today: 'Today' - yesterday: 'Yesterday' - tomorrow: 'Tommorrow' - this_week: 'This Week' - prev_week: 'Last Week' - next_week: 'Next Week' - this_month: 'This Month' - prev_month: 'Last Month' - next_month: 'Next Month' - this_year: 'This Year' - prev_year: 'Last Year' - next_year: 'Next Year' - past: 'Past' - future: 'Future' - range: 'Range' - seconds: 'Seconds' - minutes: 'Minutes' - hours: 'Hours' - days: 'Days' - weeks: 'Weeks' - months: 'Months' - years: 'Years' - optional_attributes: 'Further Options' - null: 'Null' - not_null: 'Not Null' + between: 'В интервале' + contains: 'Содержит' + begins_with: 'Начинается с' + ends_with: 'Оканчивается на' + today: 'Сегодня' + yesterday: 'Вчера' + tomorrow: 'Завтра' + this_week: 'На этой неделе' + prev_week: 'На прошлой неделе' + next_week: 'На следующей неделе' + this_month: 'В этом месяце' + prev_month: 'В прошлом месяце' + next_month: 'В следующем месяце' + this_year: 'В этом году' + prev_year: 'В прошлом году' + next_year: 'В следующем году' + past: 'Прошлое' + future: 'Будущее' + range: 'Интервал' + seconds: 'секунд' + minutes: 'минут' + hours: 'часов' + days: 'дней' + weeks: 'недель' + months: 'месяцев' + years: 'лет' + optional_attributes: 'Дополнительные настройки' + null: 'Пусто' + not_null: 'Не пусто' date_picker_options: - weekHeader: 'Нед' + weekHeader: 'Нед.' firstDay: 1 isRTL: false showMonthAfterYear: false datetime_picker_options: - timeText: 'Hora' - currentText: 'Ahora' - closeText: 'Cerrar' + timeText: 'Время' + currentText: 'Сегодня' + closeText: 'Закрыть' errors: template: header: - one: "1 error prohibited this %{model} from being saved." - other: "%{count} errors prohibited this %{model} from being saved" - body: "There were problems with the following fields:" + one: '%{model}: сохранение не удалось из-за %{count} ошибки' + few: '%{model}: сохранение не удалось из-за %{count} ошибок' + many: '%{model}: сохранение не удалось из-за %{count} ошибок' + other: '%{model}: сохранение не удалось из-за %{count} ошибки' + body: 'Проблемы возникли со следующими полями:' # error_messages - internal_error: 'Внутренняя ошибка сервера.' - version_inconsistency: 'Эта запись была обновлена с того момента, как вы начали ее редактировать.' + cant_destroy_record: 'Запись %{record} не может быть удалена' + failed_to_save_record: 'Запись не может быть сохранена из-за неизвестной ошибки' + internal_error: '500 Внутренняя ошибка сервера' + version_inconsistency: 'Эта запись была обновлена с того момента, как вы начали ее редактировать' From 37eb7b621803eb8ed1962e9ad83c248cc4d2cddf Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 3 Jan 2011 10:57:37 +0100 Subject: [PATCH 0888/2024] Bugfix: show loading_indicator in search forms --- frontends/default/views/_field_search.html.erb | 4 ++-- frontends/default/views/_search.html.erb | 4 ++-- lib/active_scaffold/helpers/id_helpers.rb | 4 ---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/frontends/default/views/_field_search.html.erb b/frontends/default/views/_field_search.html.erb index 2c48ed8143..4691d25019 100644 --- a/frontends/default/views/_field_search.html.erb +++ b/frontends/default/views/_field_search.html.erb @@ -1,6 +1,6 @@ <% url_options = params_for(:action => :index, :escape => false, :search => nil) -%> <%= -options = {:id => search_form_id, +options = {:id => element_form_id(:action => 'search'), :class => "as_form search", :remote => true, :method => :get, @@ -29,4 +29,4 @@ form_tag url_options, options %> <%= loading_indicator_tag(:action => :search) %> </p> </form> -<%= javascript_tag("ActiveScaffold.focus_first_element_of_form('#{search_form_id}');") %> +<%= javascript_tag("ActiveScaffold.focus_first_element_of_form('#{element_form_id(:action => 'search')}');") %> diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index 7387fc9dd7..f802f7eeeb 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -1,7 +1,7 @@ <% live_search = active_scaffold_config.search.live? -%> <% url_options = params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'} -%> <%= -options = {:id => search_form_id, +options = {:id => element_form_id(:action => 'search'), :class => "as_form search", :remote => true, :method => :get} @@ -29,6 +29,6 @@ options['data-loading'] = true unless live_search $(<%= "##{search_input_id}".to_json.html_safe %>).delayedObserver(0.5, function() { $(<%= "##{search_input_id}".to_json.html_safe %>).parent().trigger("submit");}); <% end -%> -ActiveScaffold.focus_first_element_of_form('<%= search_form_id %>'); +ActiveScaffold.focus_first_element_of_form('<%= element_form_id(:action => 'search') %>'); //]]> </script> diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index 9e2d27d542..d2f3e9404b 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -38,10 +38,6 @@ def before_header_id "#{controller_id}-search-container" end - def search_form_id - "#{controller_id}-search-form" - end - def search_input_id "#{controller_id}-search-input" end From d5b1da2ef0cff9e6dcbd05330d372bf171949e79 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 3 Jan 2011 12:14:55 +0100 Subject: [PATCH 0889/2024] Bugfix: prototype npe if action_link does not have data-refresh attribute --- frontends/default/javascripts/prototype/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 9d9a4b1059..4005a535da 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -746,7 +746,7 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, { instantiate_link: function(link) { var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); - if (!this.target.readAttribute('data-refresh').blank()) l.refresh_url = this.target.readAttribute('data-refresh'); + if (this.target.hasAttribute('data-refresh') && !this.target.readAttribute('data-refresh').blank()) l.refresh_url = this.target.readAttribute('data-refresh'); if (l.position) { l.url = l.url.append_params({adapter: '_list_inline_adapter'}); From 462954530dab8bcbbc1bc067a8d2f03df6870f17 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 4 Jan 2011 10:36:03 +0100 Subject: [PATCH 0890/2024] use build instead of new for associations in new_model --- lib/active_scaffold/actions/create.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 5b091cdb72..0070c9b418 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -122,7 +122,7 @@ def new_model params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column] end - model.new + model.respond_to?(:build) ? model.build : model.new end # override this method if you want to inject data in the record (or its associated objects) before the save From 0cbe436ecf184531a2c360c20ba22b123230ff93 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 4 Jan 2011 10:53:54 +0100 Subject: [PATCH 0891/2024] Bugfix: do not user controller.merge_conditions instead use arel where() --- lib/active_scaffold/helpers/association_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/association_helpers.rb b/lib/active_scaffold/helpers/association_helpers.rb index 194297397b..5e5b8f36ad 100644 --- a/lib/active_scaffold/helpers/association_helpers.rb +++ b/lib/active_scaffold/helpers/association_helpers.rb @@ -3,11 +3,11 @@ module Helpers module AssociationHelpers # Provides a way to honor the :conditions on an association while searching the association's klass def association_options_find(association, conditions = nil) - association.klass.where(controller.send(:merge_conditions, conditions, association.options[:conditions])).all + association.klass.where(conditions).where(association.options[:conditions]).all end def association_options_count(association, conditions = nil) - association.klass.where(controller.send(:merge_conditions, conditions, association.options[:conditions])).count + association.klass.where(conditions).where(association.options[:conditions]).count end # returns options for the given association as a collection of [id, label] pairs intended for the +options_for_select+ helper. From f8eed96a7bfc94a6ec6ba63e222ca99f626abfa7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 6 Jan 2011 09:02:50 +0100 Subject: [PATCH 0892/2024] remove errors.add_to_base deprecation --- lib/active_scaffold/actions/update.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index f3383abe88..e3cecc698a 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -91,10 +91,10 @@ def update_save end rescue ActiveRecord::RecordInvalid rescue ActiveRecord::StaleObjectError - @record.errors.add_to_base as_(:version_inconsistency) + @record.errors.add(:base, as_(:version_inconsistency)) self.successful=false rescue ActiveRecord::RecordNotSaved - @record.errors.add_to_base as_(:record_not_saved) if @record.errors.empty? + @record.errors.add(:base, as_(:record_not_saved)) if @record.errors.empty? self.successful = false end end From 51f01c3b269bc1b92695fc8bd2508572d49bbbd0 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 6 Jan 2011 14:28:50 +0100 Subject: [PATCH 0893/2024] assure that correct Set class is used for inheritance --- lib/active_scaffold/data_structures/action_columns.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index d610f496d9..1adbfb3bf3 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -1,6 +1,6 @@ module ActiveScaffold::DataStructures # A set of columns. These structures can be nested for organization. - class ActionColumns < Set + class ActionColumns < ActiveScaffold::DataStructures::Set include ActiveScaffold::Configurable # this lets us refer back to the action responsible for this link, if it exists. From 0c61aa0a185cdf7ca7ae2a98b91a6eaeb1b6b3fc Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 7 Jan 2011 12:12:00 +0100 Subject: [PATCH 0894/2024] Bugfix: custom authorized methods for action_links were not called with record parameter --- lib/active_scaffold/data_structures/action_links.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 726cf5ddee..092b16258d 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -108,7 +108,7 @@ def traverse(controller, options = {}, &block) link.traverse(controller,options, &block) yield(link, nil, {:node => :finished_traversing, :first_action => first_action, :level => options[:level]}) first_action = false - elsif controller.nil? || !skip_action_link(controller, link, *(Array(options[:record]))) + elsif controller.nil? || !skip_action_link(controller, link, *(Array(options[:for]))) authorized = options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action) yield(self, link, {:authorized => authorized, :first_action => first_action, :level => options[:level]}) first_action = false From 816240d2b4335b835fa6bf5868c97d1574ff3d9b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 10 Jan 2011 13:13:56 +0100 Subject: [PATCH 0895/2024] fixed human_name deprecation --- lib/active_scaffold/config/core.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index 60d25c8cc9..b081b1c0e4 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -151,7 +151,7 @@ def _configure_sti self.columns[column].form_ui ||= :select self.columns[column].options ||= {} self.columns[column].options[:options] = self.sti_children.collect do |model_name| - [model_name.to_s.camelize.constantize.human_name, model_name.to_s.camelize] + [model_name.to_s.camelize.constantize.model_name.human, model_name.to_s.camelize] end end end @@ -163,7 +163,7 @@ def _add_sti_create_links @action_links.delete('new') self.sti_children.each do |child| new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone - new_sti_link.label = as_(:create_model, :model => child.to_s.camelize.constantize.human_name) + new_sti_link.label = as_(:create_model, :model => child.to_s.camelize.constantize.model_name.human) new_sti_link.parameters = {model.inheritance_column => child} @action_links.add(new_sti_link) end From b38463e5d5d3b621e02777158a051e23e004b2ac Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 10 Jan 2011 13:20:54 +0100 Subject: [PATCH 0896/2024] Bugfix: _add_sti_create_links --- lib/active_scaffold/config/core.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index b081b1c0e4..1a4adc34d1 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -158,14 +158,14 @@ def _configure_sti # To be called after include action modules def _add_sti_create_links - new_action_link = @action_links['new'] + new_action_link = @action_links.collection['new'] unless new_action_link.nil? - @action_links.delete('new') + @action_links.collection.delete('new') self.sti_children.each do |child| new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone new_sti_link.label = as_(:create_model, :model => child.to_s.camelize.constantize.model_name.human) new_sti_link.parameters = {model.inheritance_column => child} - @action_links.add(new_sti_link) + @action_links.collection.add(new_sti_link) end end end From 38e8a5e7007f280644417493ea4ad059ff75158c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 10 Jan 2011 14:16:22 +0100 Subject: [PATCH 0897/2024] changed localization for range in german --- lib/active_scaffold/locale/de.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index dc994bad67..f22e81a227 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -78,7 +78,7 @@ :next_year => 'Nächstes Jahr', :past => 'Letzten', :future => 'Nächsten', - :range => 'Spanne', + :range => 'Zeitraum', :seconds => 'Sekunden', :minutes => 'Minuten', :hours => 'Stunden', From f57fd754c00d74a8196545beb6f998f8e25f6999 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 12 Jan 2011 13:11:19 +0100 Subject: [PATCH 0898/2024] jquery should make ajax requests railish where necessary --- frontends/default/javascripts/jquery/active_scaffold.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 495a0bef6a..45d017d70b 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -32,10 +32,9 @@ $(document).ready(function() { if (action_link.is_disabled()) { return false; } else { - // hack: rails jquery defaults to dataType script - // but activescaffold is returning html content - // which chrome does nt like - if (action_link.position) event.data_type = 'dummy'; + // hack: jquery requires if you request for javascript that javascript + // is coming back, however rails has a different mantra + if (action_link.position) event.data_type = 'rails'; if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible'); action_link.disable(); } From 9c6c071340340b1a02e2a63596c0510386abd543 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 12 Jan 2011 14:06:53 +0100 Subject: [PATCH 0899/2024] fix column_to_native when value is nil --- lib/active_scaffold/data_structures/column.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 18ab7db664..0f14285ab0 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -278,6 +278,7 @@ def <=>(other_column) end def number_to_native(value) + return value if value.blank? || !value.is_a?(String) native = '.' # native ruby separator format = {:separator => '', :delimiter => ''}.merge! I18n.t('number.format', :default => {}) specific = case self.options[:format] From bc81fb18fa46597a34f45aa65da6e59d823abfa9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 13 Jan 2011 17:20:00 +0100 Subject: [PATCH 0900/2024] Bugfix: added nil check for number_to_native_format --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index d31a20439d..3cf604bed9 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -125,7 +125,7 @@ def i18n_number_to_native_format(value) native = '.' delimiter = I18n.t('number.format.delimiter') separator = I18n.t('number.format.separator') - + return value if value.blank? || !value.is_a?(String) unless delimiter == native && !value.include?(separator) && value !~ /\.\d{3}$/ value.gsub(/[^0-9\-#{I18n.t('number.format.separator')}]/, '').gsub(I18n.t('number.format.separator'), native) else From 5d92029d5f2e5132f3edce516ee09d5b0778ca9e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 13 Jan 2011 17:21:15 +0100 Subject: [PATCH 0901/2024] Bugfix: nested.add_link(:assoc, {:controller => 'xy'}) will actually use xy through the whole chain --- lib/active_scaffold.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 1c8f0d4185..21ffbece54 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -128,7 +128,13 @@ def links_for_associations def link_for_association(column, options = {}) begin - controller = column.polymorphic_association? ? :polymorph : active_scaffold_controller_for(column.association.klass) + controller = if column.polymorphic_association? + :polymorph + elsif options.include?(:controller) + "#{options[:controller].to_s.camelize}Controller".constantize + else + active_scaffold_controller_for(column.association.klass) + end rescue ActiveScaffold::ControllerNotFound controller = nil end From 15fe859fdf2c604e06920deb93d5fedbc4cbd0dd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 14 Jan 2011 08:40:28 +0100 Subject: [PATCH 0902/2024] Bugfix: cancel_link for inline_adapter multipart forms fixed in ajax world, in js disabled world you still will be returned to wrong controller --- frontends/default/views/_base_form.html.erb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index 9b8378c52b..d42259192d 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -14,12 +14,11 @@ cancel_options = {:class => 'as_cancel', 'data-refresh' => false} if xhr && as_action_config.multipart? # file_uploads form_remote_upload_tag url_options.merge({:iframe => true}), options else - if xhr && !as_action_config.multipart? - options[:remote] = true - cancel_options[:remote] = true - end + options[:remote] = true if xhr && !as_action_config.multipart? form_tag url_options, options -end -%> +end +cancel_options[:remote] = true if xhr #cancel link does nt have to care about multipart forms +-%> <h4><%= headline -%></h4> From 2e36f0ff9d1cd033f8e81d1019f4a7cd69be09be Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 14 Jan 2011 08:42:42 +0100 Subject: [PATCH 0903/2024] !! changed name of param parent_model to parent_scaffold in nested_links --- lib/active_scaffold.rb | 4 ++-- lib/active_scaffold/actions/nested.rb | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 21ffbece54..2839f3118f 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -142,7 +142,7 @@ def link_for_association(column, options = {}) unless controller.nil? options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column options[:parameters] ||= {} - options[:parameters].reverse_merge! :parent_model => column.active_record_class.to_s.underscore, :association => column.association.name + options[:parameters].reverse_merge! :parent_scaffold => controller_path, :association => column.association.name if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. @@ -161,7 +161,7 @@ def link_for_association(column, options = {}) def link_for_association_as_scope(scope, options = {}) options.reverse_merge! :label => scope, :position => :after, :type => :member, :controller => controller_path options[:parameters] ||= {} - options[:parameters].reverse_merge! :parent_model => active_scaffold_config.model.to_s.underscore, :named_scope => scope + options[:parameters].reverse_merge! :parent_scaffold => controller_path, :named_scope => scope ActiveScaffold::DataStructures::ActionLink.new('index', options) end diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index d3a00b9d83..6998604591 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -30,12 +30,16 @@ def nested? end def set_nested - if params[:parent_model] && ((params[:association] && params[:assoc_id]) || params[:named_scope]) + if params[:parent_scaffold] && ((params[:association] && params[:assoc_id]) || params[:named_scope]) @nested = nil - active_scaffold_session_storage[:nested] = {:parent_model => params[:parent_model].camelize.constantize, + begin + parent_scaffold = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize + active_scaffold_session_storage[:nested] = {:parent_model => parent_scaffold.active_scaffold_config.model, :name => (params[:association] || params[:named_scope]).to_sym, :parent_id => params[:assoc_id]} - params.delete_if {|key, value| [:parent_model, :association, :named_scope, :assoc_id].include? key.to_sym} + rescue ActiveScaffold::ControllerNotFound + end + params.delete_if {|key, value| [:parent_scaffold, :association, :named_scope, :assoc_id].include? key.to_sym} end end From 5b2330cd5262442e5936b6246ee44089f7e14444 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 14 Jan 2011 09:08:35 +0100 Subject: [PATCH 0904/2024] Bugfix: prev commit in _base_form printed true in form --- frontends/default/views/_base_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index d42259192d..fcf71e033a 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -11,13 +11,13 @@ options = {:onsubmit => onsubmit, 'data-loading' => true} cancel_options = {:class => 'as_cancel', 'data-refresh' => false} +cancel_options[:remote] = true if xhr #cancel link does nt have to care about multipart forms if xhr && as_action_config.multipart? # file_uploads form_remote_upload_tag url_options.merge({:iframe => true}), options else options[:remote] = true if xhr && !as_action_config.multipart? form_tag url_options, options end -cancel_options[:remote] = true if xhr #cancel link does nt have to care about multipart forms -%> <h4><%= headline -%></h4> From a3162eaef3a5e78ae3634b833e003f0439cfe5c9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 14 Jan 2011 09:16:18 +0100 Subject: [PATCH 0905/2024] add property parent_scaffold to nested_info --- lib/active_scaffold/actions/nested.rb | 6 +----- .../data_structures/nested_info.rb | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 6998604591..ff3fc56e1e 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -32,13 +32,9 @@ def nested? def set_nested if params[:parent_scaffold] && ((params[:association] && params[:assoc_id]) || params[:named_scope]) @nested = nil - begin - parent_scaffold = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize - active_scaffold_session_storage[:nested] = {:parent_model => parent_scaffold.active_scaffold_config.model, + active_scaffold_session_storage[:nested] = {:parent_scaffold => params[:parent_scaffold].to_s, :name => (params[:association] || params[:named_scope]).to_sym, :parent_id => params[:assoc_id]} - rescue ActiveScaffold::ControllerNotFound - end params.delete_if {|key, value| [:parent_scaffold, :association, :named_scope, :assoc_id].include? key.to_sym} end end diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 0be9b1df6a..42d1745030 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -5,20 +5,27 @@ def self.get(model, session_storage) nil else session_info = session_storage[:nested].clone - session_info[:association] = session_info[:parent_model].reflect_on_association(session_info[:name]) - unless session_info[:association].nil? - ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, session_info) - else - ActiveScaffold::DataStructures::NestedInfoScope.new(model, session_info) + begin + session_info[:parent_scaffold] = "#{session_info[:parent_scaffold].to_s.camelize}Controller".constantize + session_info[:parent_model] = session_info[:parent_scaffold].active_scaffold_config.model + session_info[:association] = session_info[:parent_model].reflect_on_association(session_info[:name]) + unless session_info[:association].nil? + ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, session_info) + else + ActiveScaffold::DataStructures::NestedInfoScope.new(model, session_info) + end + rescue ActiveScaffold::ControllerNotFound + nil end end end - attr_accessor :association, :child_association, :parent_model, :parent_id, :constrained_fields, :scope + attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :constrained_fields, :scope def initialize(model, session_info) @parent_model = session_info[:parent_model] @parent_id = session_info[:parent_id] + @parent_scaffold = session_info[:parent_scaffold] end def new_instance? From 7781599f7b3740de057e138525012ec74d75e9f2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 14 Jan 2011 09:23:12 +0100 Subject: [PATCH 0906/2024] parent_model param is gone, use parent_scaffold instead --- lib/active_scaffold/constraints.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 2b85c308a4..fba14216e3 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -120,10 +120,15 @@ def condition_from_association_constraint(association, value) condition = constraint_condition_for("#{table}.#{field}", value) if association.options[:polymorphic] - condition = merge_conditions( - condition, - constraint_condition_for("#{table}.#{association.name}_type", params[:parent_model].to_s) - ) + begin + parent_scaffold = "#{session_info[:parent_scaffold].to_s.camelize}Controller".constantize + condition = merge_conditions( + condition, + constraint_condition_for("#{table}.#{association.name}_type", parent_scaffold.active_scaffold_config.model_id.to_s) + ) + rescue ActiveScaffold::ControllerNotFound + nil + end end condition From 9232fa2a89ecdaa85723c2e42bdd9ab8e985c727 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 14 Jan 2011 10:08:14 +0100 Subject: [PATCH 0907/2024] action row should use same action rendering process as all the other actions --- lib/active_scaffold/actions/list.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index e5433acfc4..80d98f1fe3 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -11,7 +11,9 @@ def index # get just a single row def row - render :partial => 'row', :locals => {:record => find_if_allowed(params[:id], :read)} + Rails.logger.info("row params: #{params.inspect}") + @record = find_if_allowed(params[:id], :read) + respond_to_action(:row) end def list @@ -49,6 +51,15 @@ def list_respond_to_json def list_respond_to_yaml render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status end + + def row_respond_to_html + render :action => 'row', :locals => {:record => find_if_allowed(params[:id], :read)} + end + + def row_respond_to_js + render(:partial => 'row', :locals => {:record => find_if_allowed(params[:id], :read)}) + end + # The actual algorithm to prepare for the list view def do_list includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact @@ -153,6 +164,7 @@ def list_authorized_filter def list_formats (default_formats + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq end + alias_method :row_formats, :list_formats def action_update_formats (default_formats + active_scaffold_config.formats).uniq From 68f477220a58e367be473e50a45753a672495f76 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 14 Jan 2011 12:15:13 +0100 Subject: [PATCH 0908/2024] Bugfix: row_repond_to_html has to call partial not action --- lib/active_scaffold/actions/list.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 80d98f1fe3..deb9049664 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -53,11 +53,11 @@ def list_respond_to_yaml end def row_respond_to_html - render :action => 'row', :locals => {:record => find_if_allowed(params[:id], :read)} + render(:partial => 'row', :locals => {:record => @record}) end def row_respond_to_js - render(:partial => 'row', :locals => {:record => find_if_allowed(params[:id], :read)}) + render(:partial => 'row', :locals => {:record => @record}) end # The actual algorithm to prepare for the list view From f6b803c794e3017de0b26485cd8e50e135dd9f99 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 14 Jan 2011 12:16:40 +0100 Subject: [PATCH 0909/2024] Bugfix: refresh parent scaffold after updating nested singular assocations inline --- frontends/default/views/on_update.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 0f7db32358..922c9dfcf1 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -6,7 +6,7 @@ if controller.send :successful? page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) else updated_row = if nested? && (nested.belongs_to? || nested.has_one?) - nil + respond_to?(:render_component) ? render_component({:controller => nested.parent_scaffold.controller_path, :action => :row, :id => nested.parent_id}) : nil else render :partial => 'list_record', :locals => {:record => @record} end From a7542640fdbf703825bb8670afc3eec52eb86c9a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 14 Jan 2011 13:00:52 +0100 Subject: [PATCH 0910/2024] Bugfix: reset some more parameters when going back to main --- lib/active_scaffold/helpers/controller_helpers.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index beeba32134..7688db2735 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -33,6 +33,8 @@ def main_path_to_return parameters[:parent_id] = nil parameters[:action] = "index" parameters[:id] = nil + parameters[:associated_id] = nil + parameters[:utf8] = nil params_for(parameters) end end From 448f2fe5c4d962be913e2598850096b11552d500 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 14 Jan 2011 13:32:26 +0100 Subject: [PATCH 0911/2024] changed german localication for created_model --- lib/active_scaffold/locale/de.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index f22e81a227..b941527b2a 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -14,7 +14,7 @@ :create => 'Anlegen', :create_model => 'Lege %{model} an', :create_another => 'Weitere anlegen', - :created_model => '%{model} anlegen', + :created_model => '%{model} angelegt', :create_new => 'Neu anlegen', :customize => 'Anpassen', :delete => 'Löschen', From 067eb40ce90cf621353735c3d08a931409be1d57 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 14 Jan 2011 16:01:35 +0100 Subject: [PATCH 0912/2024] Bugfix: update parent_scaffold after creating nested single association --- frontends/default/views/on_create.js.rjs | 24 +++++++++++++++--------- lib/active_scaffold/actions/create.rb | 1 - 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index a145b88940..9cef266061 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -4,21 +4,27 @@ page << "ActiveScaffold.find_action_link('#{form_selector}').update_flash_messag if controller.send :successful? if (active_scaffold_config.create.refresh_list_after_create) page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) - elsif @insert_row + elsif nested? && (nested.belongs_to? || nested.has_one?) && respond_to?(:render_component) + updated_parent_row = render_component({:controller => nested.parent_scaffold.controller_path, :action => :row, :id => nested.parent_id}) + page << "ActiveScaffold.find_action_link('#{form_selector}').close('#{escape_javascript(updated_parent_row)}');" + page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} + elsif params[:parent_controller].nil? new_row = render :partial => 'list_record', :locals => {:record => @record} insert_at ||= :top page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}', #{{:insert_at => insert_at}.to_json});" page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} end - if (active_scaffold_config.create.persistent) - page << "ActiveScaffold.find_action_link('#{form_selector}').reload();" - else - page << "ActiveScaffold.find_action_link('#{form_selector}').close();" - end - if (active_scaffold_config.create.edit_after_create) - page << "var link = $('#{action_link_id 'edit', @record.id}');" - page << "if (link) (function() { link.action_link.open() }).defer();" + unless nested? && (nested.belongs_to? || nested.has_one?) + if (active_scaffold_config.create.persistent) + page << "ActiveScaffold.find_action_link('#{form_selector}').reload();" + else + page << "ActiveScaffold.find_action_link('#{form_selector}').close();" + end + if (active_scaffold_config.create.edit_after_create) + page << "var link = $('#{action_link_id 'edit', @record.id}');" + page << "if (link) (function() { link.action_link.open() }).defer();" + end end else page.call 'ActiveScaffold.replace', form_selector, render(:partial => 'create_form', :locals => {:xhr => true}) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 0070c9b418..eca9611b53 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -14,7 +14,6 @@ def new def create do_create - @insert_row = !(nested? && (nested.belongs_to? || nested.has_one?)) && params[:parent_controller].nil? respond_to_action(:create) end From e656667af8c20a5caec121e038f62e6521d41dd2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 14 Jan 2011 16:55:00 +0100 Subject: [PATCH 0913/2024] Bugfix: return to correct controller if cancel button is clicked and js is disabled --- lib/active_scaffold/helpers/controller_helpers.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 7688db2735..4e297816cd 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -29,6 +29,10 @@ def main_path_to_return parameters[:controller] = params[:parent_controller] parameters[:eid] = params[:parent_controller] end + if nested? + parameters[:controller] = nested.parent_scaffold.controller_path + parameters[:eid] = nil + end parameters[:parent_column] = nil parameters[:parent_id] = nil parameters[:action] = "index" From daa7d9911c5141d4bacb5d0b51d45b315acb5f57 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 17 Jan 2011 07:58:33 +0100 Subject: [PATCH 0914/2024] Bugfix: HABTM nested doesnt associate records on create (issue 68 reported by pego) --- lib/active_scaffold/actions/nested.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index ff3fc56e1e..40b4129537 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -97,14 +97,14 @@ def nested_parent_record(crud = :read) def create_association_with_parent(record) if nested? - if (nested.belongs_to? || nested.has_one?) && nested.child_association + if (nested.belongs_to? || nested.has_one? || nested.habtm?) && nested.child_association parent = nested_parent_record(:read) case nested.child_association.macro when :has_one record.send("#{nested.child_association.name}=", parent) when :belongs_to record.send("#{nested.child_association.name}=", parent) - when :has_many + when :has_many, :has_and_belongs_to_many record.send("#{nested.child_association.name}").send(:<<, parent) end unless parent.nil? end From 3dc1dc2ad929d38021ec2057c3fbd576b7162ece Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 17 Jan 2011 08:23:19 +0100 Subject: [PATCH 0915/2024] do nt use globel variables --- frontends/default/javascripts/jquery/active_scaffold.js | 5 +++-- frontends/default/javascripts/prototype/active_scaffold.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 45d017d70b..9663883ad2 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -643,8 +643,9 @@ var ActiveScaffold = { element.append(content); } } else { - if (current = $('#' + element.attr('id') + ' tr.association-record')[0]) { - this.replace(current, content); + var current = $('#' + element.attr('id') + ' tr.association-record') + if (current[0]) { + this.replace(current[0], content); } else { element.prepend(content); } diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 4005a535da..6344ac7ecd 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -521,8 +521,9 @@ var ActiveScaffold = { element.insert(content); } } else { - if (current = $$('#' + element.readAttribute('id') + ' tr.association-record')[0]) { - this.replace(current, content); + var current = $$('#' + element.readAttribute('id') + ' tr.association-record'); + if (current[0]) { + this.replace(current[0], content); } else { element.insert({top: content}); } From cc663f62fe6762046c04d9817e9b523f6137266c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 17 Jan 2011 14:25:20 +0100 Subject: [PATCH 0916/2024] Bugfix: delete action_link did not work as expected --- lib/active_scaffold/data_structures/action_links.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 092b16258d..efd72cf0ec 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -71,11 +71,9 @@ def find_duplicate(link) end def delete(val) - @set.delete_if do |item| - if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) - item.delete(val) - else - item.action == val.to_s + self.each do |link, set| + if link.action == val.to_s + set.delete_if {|item|item.action == val.to_s} end end end @@ -86,7 +84,7 @@ def each(type = nil, &block) if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) item.each(type, &block) else - yield item + yield item, @set end } end From a4542e54c2f9ec26116b995ed1abad2a69a9ba0f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 18 Jan 2011 08:35:56 +0100 Subject: [PATCH 0917/2024] Bugfix: each method supports options hash in order to support destroy without side effects --- lib/active_scaffold/data_structures/action_links.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index efd72cf0ec..c3e4ee024a 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -71,7 +71,7 @@ def find_duplicate(link) end def delete(val) - self.each do |link, set| + self.each({:include_set => true}) do |link, set| if link.action == val.to_s set.delete_if {|item|item.action == val.to_s} end @@ -79,12 +79,16 @@ def delete(val) end # iterates over the links, possibly by type - def each(type = nil, &block) + def each(options = {}, &block) @set.each {|item| if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) - item.each(type, &block) + item.each(options, &block) else - yield item, @set + if options[:include_set] + yield item, @set + else + yield item + end end } end From 44c4b8e4b5d5a8138733227729ed77082436169b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 18 Jan 2011 08:52:18 +0100 Subject: [PATCH 0918/2024] remove logger statement --- lib/active_scaffold/actions/list.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index deb9049664..31c33b7fb9 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -11,7 +11,6 @@ def index # get just a single row def row - Rails.logger.info("row params: #{params.inspect}") @record = find_if_allowed(params[:id], :read) respond_to_action(:row) end From 5e83b4ca6d5f54c2128c4cf4433ba1b405eb9ad4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 18 Jan 2011 10:04:19 +0100 Subject: [PATCH 0919/2024] added params[:return_to] which enables dev to set a return url different from current controllers one (experimental) --- .../helpers/controller_helpers.rb | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 4e297816cd..12249e592a 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -24,22 +24,26 @@ def params_for(options = {}) # Parameters to generate url to the main page (override if the ActiveScaffold is used as a component on another controllers page) def main_path_to_return - parameters = {} - if params[:parent_controller] - parameters[:controller] = params[:parent_controller] - parameters[:eid] = params[:parent_controller] + if params[:return_to] + params[:return_to] == 'referrer' ? request.referrer : params[:return_to] + else + parameters = {} + if params[:parent_controller] + parameters[:controller] = params[:parent_controller] + parameters[:eid] = params[:parent_controller] + end + if nested? + parameters[:controller] = nested.parent_scaffold.controller_path + parameters[:eid] = nil + end + parameters[:parent_column] = nil + parameters[:parent_id] = nil + parameters[:action] = "index" + parameters[:id] = nil + parameters[:associated_id] = nil + parameters[:utf8] = nil + params_for(parameters) end - if nested? - parameters[:controller] = nested.parent_scaffold.controller_path - parameters[:eid] = nil - end - parameters[:parent_column] = nil - parameters[:parent_id] = nil - parameters[:action] = "index" - parameters[:id] = nil - parameters[:associated_id] = nil - parameters[:utf8] = nil - params_for(parameters) end end end From ba074e7f828247fc3b92f318ef3f6c8893c9a49c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 18 Jan 2011 13:30:55 +0100 Subject: [PATCH 0920/2024] extract methods: render_parent, render_parent_options --- frontends/default/views/on_create.js.rjs | 15 +++++++++------ frontends/default/views/on_update.js.rjs | 4 ++-- lib/active_scaffold/helpers/controller_helpers.rb | 14 +++++++++++++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index 9cef266061..de10aeae79 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -1,21 +1,24 @@ form_selector = "#{element_form_id(:action => :create)}" - +insert_at ||= :top page << "ActiveScaffold.find_action_link('#{form_selector}').update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? if (active_scaffold_config.create.refresh_list_after_create) page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) - elsif nested? && (nested.belongs_to? || nested.has_one?) && respond_to?(:render_component) - updated_parent_row = render_component({:controller => nested.parent_scaffold.controller_path, :action => :row, :id => nested.parent_id}) - page << "ActiveScaffold.find_action_link('#{form_selector}').close('#{escape_javascript(updated_parent_row)}');" + elsif render_parent? && respond_to?(:render_component) + parent_row = render_component(render_parent_options) + if nested? + page << "ActiveScaffold.find_action_link('#{form_selector}').close('#{escape_javascript(parent_row)}');" + else + page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(parent_row)}', #{{:insert_at => insert_at}.to_json});" + end page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} elsif params[:parent_controller].nil? new_row = render :partial => 'list_record', :locals => {:record => @record} - insert_at ||= :top page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}', #{{:insert_at => insert_at}.to_json});" page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} end - unless nested? && (nested.belongs_to? || nested.has_one?) + unless render_parent? if (active_scaffold_config.create.persistent) page << "ActiveScaffold.find_action_link('#{form_selector}').reload();" else diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 922c9dfcf1..3093192ac9 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -5,8 +5,8 @@ if controller.send :successful? if (active_scaffold_config.update.refresh_list_after_update) page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) else - updated_row = if nested? && (nested.belongs_to? || nested.has_one?) - respond_to?(:render_component) ? render_component({:controller => nested.parent_scaffold.controller_path, :action => :row, :id => nested.parent_id}) : nil + updated_row = if render_parent? + respond_to?(:render_component) ? render_component(render_parent_options) : nil else render :partial => 'list_record', :locals => {:record => @record} end diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 12249e592a..e9238f0068 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Helpers module ControllerHelpers def self.included(controller) - controller.class_eval { helper_method :params_for, :main_path_to_return } + controller.class_eval { helper_method :params_for, :main_path_to_return, :render_parent?, :render_parent_options } end include ActiveScaffold::Helpers::IdHelpers @@ -45,6 +45,18 @@ def main_path_to_return params_for(parameters) end end + + def render_parent? + (nested? && (nested.belongs_to? || nested.has_one?) || params[:parent_sti]) + end + + def render_parent_options + if nested? + {:controller => nested.parent_scaffold.controller_path, :action => :row, :id => nested.parent_id} + elsif params[:parent_sti] + {:controller => params[:parent_sti], :action => :row, :id => @record.id} + end + end end end end From 3225d4d76dbc84ef4c86c5bf9e8020cd500bdf99 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 18 Jan 2011 14:45:58 +0100 Subject: [PATCH 0921/2024] find_action_link should only be called once --- frontends/default/views/on_create.js.rjs | 9 +++++---- frontends/default/views/on_update.js.rjs | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index de10aeae79..e04a28b40e 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -1,13 +1,14 @@ form_selector = "#{element_form_id(:action => :create)}" insert_at ||= :top -page << "ActiveScaffold.find_action_link('#{form_selector}').update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" +page << "var action_link = ActiveScaffold.find_action_link('#{form_selector}');" +page << "action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? if (active_scaffold_config.create.refresh_list_after_create) page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) elsif render_parent? && respond_to?(:render_component) parent_row = render_component(render_parent_options) if nested? - page << "ActiveScaffold.find_action_link('#{form_selector}').close('#{escape_javascript(parent_row)}');" + page << "action_link.close('#{escape_javascript(parent_row)}');" else page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(parent_row)}', #{{:insert_at => insert_at}.to_json});" end @@ -20,9 +21,9 @@ if controller.send :successful? unless render_parent? if (active_scaffold_config.create.persistent) - page << "ActiveScaffold.find_action_link('#{form_selector}').reload();" + page << "action_link.reload();" else - page << "ActiveScaffold.find_action_link('#{form_selector}').close();" + page << "action_link.close();" end if (active_scaffold_config.create.edit_after_create) page << "var link = $('#{action_link_id 'edit', @record.id}');" diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 3093192ac9..98611c08d1 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -1,6 +1,7 @@ form_selector = "#{element_form_id(:action => :update)}" -page << "ActiveScaffold.find_action_link('#{form_selector}').update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" +page << "var action_link = ActiveScaffold.find_action_link('#{form_selector}');" +page << "action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? if (active_scaffold_config.update.refresh_list_after_update) page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) @@ -10,7 +11,7 @@ if controller.send :successful? else render :partial => 'list_record', :locals => {:record => @record} end - page << "ActiveScaffold.find_action_link('#{form_selector}').close('#{escape_javascript(updated_row)}');" + page << "action_link.close('#{escape_javascript(updated_row)}');" page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} end else From 5c0e2b4cb69f6561a260c98c987626d3771d02f0 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 18 Jan 2011 15:03:55 +0100 Subject: [PATCH 0922/2024] create_record_row expects scaffold_id instead of tbody_id as first param --- .../default/javascripts/jquery/active_scaffold.js | 10 +++++++--- .../default/javascripts/prototype/active_scaffold.js | 9 +++++++-- frontends/default/views/add_existing.js.rjs | 2 +- frontends/default/views/on_create.js.rjs | 4 ++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 9663883ad2..f5aa9eb2e3 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -521,9 +521,9 @@ var ActiveScaffold = { $(form_element + ":first *:input[type!=hidden]:first").focus(); }, - create_record_row: function(tbody, html, options) { - if (typeof(tbody) == 'string') tbody = '#' + tbody; - tbody = $(tbody); + create_record_row: function(active_scaffold_id, html, options) { + if (typeof(active_scaffold_id) == 'string') active_scaffold_id = '#' + active_scaffold_id; + tbody = $(active_scaffold_id).find('tbody.records'); if (options.insert_at == 'top') { tbody.prepend(html); @@ -828,6 +828,10 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ scaffold_id: function() { return '#' + this.tag.closest('div.active-scaffold').attr('id'); }, + + scaffold: function() { + return this.tag.closest('div.active-scaffold'); + }, update_flash_messages: function(messages) { message_node = $(this.scaffold_id().replace(/-active-scaffold/, '-messages')); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 6344ac7ecd..686aa25629 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -408,8 +408,9 @@ var ActiveScaffold = { Form.focusFirstElement(form_element); }, - create_record_row: function(tbody, html, options) { - tbody = $(tbody); + create_record_row: function(active_scaffold_id, html, options) { + tbody = $(active_scaffold_id).down('tbody.records'); + var new_row = null; if (options.insert_at == 'top') { @@ -728,6 +729,10 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ scaffold_id: function() { return this.tag.up('div.active-scaffold').readAttribute('id'); }, + + scaffold: function() { + return this.tag.up('div.active-scaffold'); + }, update_flash_messages: function(messages) { message_node = $(this.scaffold_id().sub('-active-scaffold', '-messages')); diff --git a/frontends/default/views/add_existing.js.rjs b/frontends/default/views/add_existing.js.rjs index a0d364f50c..3a7d3b62cc 100644 --- a/frontends/default/views/add_existing.js.rjs +++ b/frontends/default/views/add_existing.js.rjs @@ -1,5 +1,5 @@ new_row = render :partial => 'list_record', :locals => {:record => @record} -page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}', #{{:insert_at => :top}.to_json});" +page << "ActiveScaffold.create_record_row('#{active_scaffold_id}','#{escape_javascript(new_row)}', #{{:insert_at => :top}.to_json});" page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} if (form_stays_open = true) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index e04a28b40e..f11298145a 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -10,12 +10,12 @@ if controller.send :successful? if nested? page << "action_link.close('#{escape_javascript(parent_row)}');" else - page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(parent_row)}', #{{:insert_at => insert_at}.to_json});" + page << "ActiveScaffold.create_record_row(action_link.scaffold(),'#{escape_javascript(parent_row)}', #{{:insert_at => insert_at}.to_json});" end page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} elsif params[:parent_controller].nil? new_row = render :partial => 'list_record', :locals => {:record => @record} - page << "ActiveScaffold.create_record_row('#{active_scaffold_tbody_id}','#{escape_javascript(new_row)}', #{{:insert_at => insert_at}.to_json});" + page << "ActiveScaffold.create_record_row(action_link.scaffold(),'#{escape_javascript(new_row)}', #{{:insert_at => insert_at}.to_json});" page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} end From e8987ae2c58ef483e78102647a9a758d073800ef Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 18 Jan 2011 15:17:53 +0100 Subject: [PATCH 0923/2024] Bugfix: check render_parent? first --- frontends/default/views/on_create.js.rjs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index f11298145a..7c85922863 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -3,16 +3,17 @@ insert_at ||= :top page << "var action_link = ActiveScaffold.find_action_link('#{form_selector}');" page << "action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? - if (active_scaffold_config.create.refresh_list_after_create) - page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) - elsif render_parent? && respond_to?(:render_component) + if render_parent? && respond_to?(:render_component) parent_row = render_component(render_parent_options) if nested? page << "action_link.close('#{escape_javascript(parent_row)}');" else page << "ActiveScaffold.create_record_row(action_link.scaffold(),'#{escape_javascript(parent_row)}', #{{:insert_at => insert_at}.to_json});" + page << "action_link.close();" end - page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} + #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} + elsif (active_scaffold_config.create.refresh_list_after_create) + page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) elsif params[:parent_controller].nil? new_row = render :partial => 'list_record', :locals => {:record => @record} page << "ActiveScaffold.create_record_row(action_link.scaffold(),'#{escape_javascript(new_row)}', #{{:insert_at => insert_at}.to_json});" From bb6da246d829d4233a527f4d581721362cb98f4e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 18 Jan 2011 16:43:59 +0100 Subject: [PATCH 0924/2024] Bugfix: do not update calculations in case of render_parent? --- frontends/default/views/on_update.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 98611c08d1..8badf514b2 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -12,7 +12,7 @@ if controller.send :successful? render :partial => 'list_record', :locals => {:record => @record} end page << "action_link.close('#{escape_javascript(updated_row)}');" - page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} + page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} && !render_parent? end else page.call 'ActiveScaffold.replace', form_selector, render(:partial => 'update_form', :locals => {:xhr => true}) From adced083e138b558c6fca592ac555b5260f1f5fa Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 18 Jan 2011 16:48:25 +0100 Subject: [PATCH 0925/2024] improved STI support (experimental) --- lib/active_scaffold.rb | 17 ++++++++++++++- lib/active_scaffold/config/core.rb | 14 ------------- .../helpers/list_column_helpers.rb | 11 +--------- lib/active_scaffold/helpers/view_helpers.rb | 21 +++++++++++++++++++ 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 2839f3118f..30fcf53f3f 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -113,7 +113,22 @@ def active_scaffold(model_id = nil, &block) active_scaffold_paths.each do |path| self.append_view_path(ActionView::ActiveScaffoldResolver.new(path)) end - self.active_scaffold_config._add_sti_create_links if self.active_scaffold_config.add_sti_create_links? + self._add_sti_create_links if self.active_scaffold_config.add_sti_create_links? + end + + # To be called after include action modules + def _add_sti_create_links + new_action_link = active_scaffold_config.action_links.collection['new'] + unless new_action_link.nil? + active_scaffold_config.action_links.collection.delete('new') + active_scaffold_config.sti_children.each do |child| + new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone + new_sti_link.label = child.to_s.camelize.constantize.model_name.human + new_sti_link.parameters = {:parent_sti => controller_path, :return_to => :referrer} + new_sti_link.controller = active_scaffold_controller_for(child.to_s.camelize.constantize).controller_path + active_scaffold_config.action_links.collection.create.add(new_sti_link) + end + end end # Create the automatic column links. Note that this has to happen when configuration is *done*, because otherwise the Nested module could be disabled. Actually, it could still be disabled later, couldn't it? diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index 1a4adc34d1..e8a94a4f92 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -156,20 +156,6 @@ def _configure_sti end end - # To be called after include action modules - def _add_sti_create_links - new_action_link = @action_links.collection['new'] - unless new_action_link.nil? - @action_links.collection.delete('new') - self.sti_children.each do |child| - new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone - new_sti_link.label = as_(:create_model, :model => child.to_s.camelize.constantize.model_name.human) - new_sti_link.parameters = {model.inheritance_column => child} - @action_links.collection.add(new_sti_link) - end - end - end - # configuration routing. # we want to route calls named like an activated action to that action's global or local Config class. # --------------------------- diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 471780248c..89db7f5d60 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -58,7 +58,7 @@ def render_list_column(text, column, record) def action_link_to_inline_form(column, record, associated) link = column.link.clone if column.polymorphic_association? - polymorphic_controller = polymorphic_controller_for_nested_link(column, record) + polymorphic_controller = controller_path_for_activerecord(record.send(column.association.name).class) return link if polymorphic_controller.nil? link.controller = polymorphic_controller end @@ -101,15 +101,6 @@ def column_link_authorized?(link, column, record, associated) end end - def polymorphic_controller_for_nested_link(column, record) - begin - controller = active_scaffold_controller_for(record.send(column.association.name).class) - controller.controller_path - rescue ActiveScaffold::ControllerNotFound - controller = nil - end - end - # There are two basic ways to clean a column's value: h() and sanitize(). The latter is useful # when the column contains *valid* html data, and you want to just disable any scripting. People # can always use field overrides to clean data one way or the other, but having this override diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 146cc9dc37..9ab11e33b9 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -34,6 +34,15 @@ def active_scaffold_controller_for(*args) ## Uncategorized ## + def controller_path_for_activerecord(klass) + begin + controller = active_scaffold_controller_for(klass) + controller.controller_path + rescue ActiveScaffold::ControllerNotFound + controller = nil + end + end + def generate_temporary_id (Time.now.to_f*1000).to_i.to_s end @@ -143,6 +152,7 @@ def action_link_url_options(link, url_options, record, options = {}) url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller] url_options.merge! link.parameters if link.parameters url_options_for_nested_link(link.column, record, link, url_options, options) if link.nested_link? + url_options_for_sti_link(link.column, record, link, url_options, options) unless record.nil? || active_scaffold_config.sti_children.nil? url_options[:_method] = link.method if !link.confirm? && link.inline? && link.method != :get url_options end @@ -211,6 +221,17 @@ def url_options_for_nested_link(column, record, link, url_options, options = {}) end end + def url_options_for_sti_link(column, record, link, url_options, options = {}) + #need to find out controller of current record type + #and set parameters + sti_controller_path = controller_path_for_activerecord(record.class) + if sti_controller_path + url_options[:controller] = sti_controller_path + url_options[:parent_sti] = controller_path + url_options[:return_to] = :referrer + end + end + def column_class(column, column_value, record) classes = [] classes << "#{column.name}-column" From f8adadaac2d291ba4d6279634643158be2b3a4b4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 18 Jan 2011 20:43:26 +0100 Subject: [PATCH 0926/2024] Bugfix: it was impossible to set cancel_link to false by config --- frontends/default/views/_create_form.html.erb | 5 +++-- frontends/default/views/_create_form_on_list.html.erb | 3 ++- frontends/default/views/_update_form.html.erb | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index 77c711b46c..058ba94dbb 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -1,7 +1,8 @@ -<% form_action ||= :create %> +<% form_action ||= :create + cancel_link = true if cancel_link.nil? %> <%= render :partial => "base_form", :locals => {:xhr => xhr ||= nil, :form_action => form_action, :method => method ||= :post, - :cancel_link => cancel_link ||= true, + :cancel_link => cancel_link, :headline => headline ||= active_scaffold_config.send(form_action).label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil)} %> diff --git a/frontends/default/views/_create_form_on_list.html.erb b/frontends/default/views/_create_form_on_list.html.erb index cbfe9bf744..96142a9704 100644 --- a/frontends/default/views/_create_form_on_list.html.erb +++ b/frontends/default/views/_create_form_on_list.html.erb @@ -1,5 +1,6 @@ +<% cancel_link = false if cancel_link.nil? %> <%= render :partial => "base_form", :locals => {:xhr => xhr ||= nil, :form_action => form_action ||= :create, :method => method ||= :post, - :cancel_link => cancel_link ||= false, + :cancel_link => cancel_link, :headline => headline ||= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil)} %> \ No newline at end of file diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index f699f7dcb7..e153409797 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -1,5 +1,6 @@ +<% cancel_link = true if cancel_link.nil? %> <%= render :partial => "base_form", :locals => {:xhr => xhr ||= nil, :form_action => form_action ||= :update, :method => method ||= :put, - :cancel_link => cancel_link ||= true, + :cancel_link => cancel_link, :headline => headline ||= @record.to_label.nil? ? active_scaffold_config.update.label : as_(:update_model, :model => clean_column_value(@record.to_label))} %> From e4a98666daf1fb924318fe1b4ef7c60f8cbdd14b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 19 Jan 2011 15:30:14 +0100 Subject: [PATCH 0927/2024] add class to div for list content --- frontends/default/views/_list_with_header.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_with_header.html.erb b/frontends/default/views/_list_with_header.html.erb index ba2a002357..4d08555bc5 100644 --- a/frontends/default/views/_list_with_header.html.erb +++ b/frontends/default/views/_list_with_header.html.erb @@ -26,7 +26,7 @@ <% end %> </tbody> </table> - <div id="<%= active_scaffold_content_id -%>"> + <div id="<%= active_scaffold_content_id-%>" class="as_content"> <%= render :partial => 'list' %> </div> </div> From b4e1543ec4db07c9c46705c969586919c8b77d90 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 19 Jan 2011 15:32:00 +0100 Subject: [PATCH 0928/2024] add support for refresh_list true in parent controller --- frontends/default/views/on_create.js.rjs | 10 ++++++--- frontends/default/views/on_update.js.rjs | 22 +++++++++++++------ .../helpers/controller_helpers.rb | 20 +++++++++++++++-- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index 7c85922863..6aa5d5f6d5 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -4,11 +4,15 @@ page << "var action_link = ActiveScaffold.find_action_link('#{form_selector}');" page << "action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? if render_parent? && respond_to?(:render_component) - parent_row = render_component(render_parent_options) + parent_rendered = render_component(render_parent_options) if nested? - page << "action_link.close('#{escape_javascript(parent_row)}');" + page << "action_link.close('#{escape_javascript(parent_rendered)}');" else - page << "ActiveScaffold.create_record_row(action_link.scaffold(),'#{escape_javascript(parent_row)}', #{{:insert_at => insert_at}.to_json});" + if render_parent_action == :row + page << "ActiveScaffold.create_record_row(action_link.scaffold(),'#{escape_javascript(parent_rendered)}', #{{:insert_at => insert_at}.to_json});" + elsif render_parent_action == :index + page << parent_rendered + end page << "action_link.close();" end #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 8badf514b2..d67a2e3ec9 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -3,16 +3,24 @@ form_selector = "#{element_form_id(:action => :update)}" page << "var action_link = ActiveScaffold.find_action_link('#{form_selector}');" page << "action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? - if (active_scaffold_config.update.refresh_list_after_update) - page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) - else - updated_row = if render_parent? - respond_to?(:render_component) ? render_component(render_parent_options) : nil + if render_parent? && respond_to?(:render_component) + parent_rendered = render_component(render_parent_options) + if nested? + page << "action_link.close('#{escape_javascript(parent_rendered)}');" else - render :partial => 'list_record', :locals => {:record => @record} + if render_parent_action == :row + page << "action_link.close('#{escape_javascript(parent_rendered)}');" + elsif render_parent_action == :index + page << parent_rendered + end end + #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} + elsif (active_scaffold_config.update.refresh_list_after_update) + page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) + else + render :partial => 'list_record', :locals => {:record => @record} page << "action_link.close('#{escape_javascript(updated_row)}');" - page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} && !render_parent? + page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} end else page.call 'ActiveScaffold.replace', form_selector, render(:partial => 'update_form', :locals => {:xhr => true}) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index e9238f0068..84c2a5001d 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Helpers module ControllerHelpers def self.included(controller) - controller.class_eval { helper_method :params_for, :main_path_to_return, :render_parent?, :render_parent_options } + controller.class_eval { helper_method :params_for, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action} end include ActiveScaffold::Helpers::IdHelpers @@ -54,9 +54,25 @@ def render_parent_options if nested? {:controller => nested.parent_scaffold.controller_path, :action => :row, :id => nested.parent_id} elsif params[:parent_sti] - {:controller => params[:parent_sti], :action => :row, :id => @record.id} + options = {:controller => params[:parent_sti], :action => render_parent_action(params[:parent_sti])} + if render_parent_action(params[:parent_sti]) == :index + options + else + options.merge({:id => @record.id}) + end end end + + def render_parent_action(controller_path = nil) + begin + @parent_action = :row + parent_controller = "#{controller_path.to_s.camelize}Controller".constantize + @parent_action = :index if action_name == 'create' && parent_controller.active_scaffold_config.actions.include?(:create) && parent_controller.active_scaffold_config.create.refresh_list_after_create == true + @parent_action = :index if action_name == 'update' && parent_controller.active_scaffold_config.actions.include?(:update) && parent_controller.active_scaffold_config.update.refresh_list_after_update == true + rescue ActiveScaffold::ControllerNotFound + end if @parent_action.nil? + @parent_action + end end end end From 964fb6cee3e14f278182521259759109b9ada35b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 19 Jan 2011 15:40:26 +0100 Subject: [PATCH 0929/2024] !! renamed refresh_list_after_create to just refresh_list --- frontends/default/views/on_create.js.rjs | 2 +- lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/config/create.rb | 8 ++++---- lib/active_scaffold/helpers/controller_helpers.rb | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index 6aa5d5f6d5..ef61685890 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -16,7 +16,7 @@ if controller.send :successful? page << "action_link.close();" end #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} - elsif (active_scaffold_config.create.refresh_list_after_create) + elsif (active_scaffold_config.create.refresh_list) page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) elsif params[:parent_controller].nil? new_row = render :partial => 'list_record', :locals => {:record => @record} diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index eca9611b53..eda650321f 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -61,7 +61,7 @@ def create_respond_to_html end def create_respond_to_js - if active_scaffold_config.create.refresh_list_after_create && successful? + if active_scaffold_config.create.refresh_list && successful? do_search if respond_to? :do_search do_list end diff --git a/lib/active_scaffold/config/create.rb b/lib/active_scaffold/config/create.rb index b02250886e..472f366c31 100644 --- a/lib/active_scaffold/config/create.rb +++ b/lib/active_scaffold/config/create.rb @@ -5,7 +5,7 @@ def initialize(*args) super self.persistent = self.class.persistent self.edit_after_create = self.class.edit_after_create - self.refresh_list_after_create = self.class.refresh_list_after_create + self.refresh_list = self.class.refresh_list end # global level configuration @@ -28,8 +28,8 @@ def self.link=(val) @@edit_after_create = false # whether we should refresh list after create or not - cattr_accessor :refresh_list_after_create - @@refresh_list_after_create = false + cattr_accessor :refresh_list + @@refresh_list = false # instance-level configuration # ---------------------------- @@ -46,6 +46,6 @@ def label(model = nil) attr_accessor :edit_after_create # whether we should refresh list after create or not - attr_accessor :refresh_list_after_create + attr_accessor :refresh_list end end diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 84c2a5001d..d7e18fe69b 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -67,7 +67,7 @@ def render_parent_action(controller_path = nil) begin @parent_action = :row parent_controller = "#{controller_path.to_s.camelize}Controller".constantize - @parent_action = :index if action_name == 'create' && parent_controller.active_scaffold_config.actions.include?(:create) && parent_controller.active_scaffold_config.create.refresh_list_after_create == true + @parent_action = :index if action_name == 'create' && parent_controller.active_scaffold_config.actions.include?(:create) && parent_controller.active_scaffold_config.create.refresh_list == true @parent_action = :index if action_name == 'update' && parent_controller.active_scaffold_config.actions.include?(:update) && parent_controller.active_scaffold_config.update.refresh_list_after_update == true rescue ActiveScaffold::ControllerNotFound end if @parent_action.nil? From d89bb2ff6a9ee27bfbd7a0f87f083a4abca5f064 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 19 Jan 2011 15:42:49 +0100 Subject: [PATCH 0930/2024] !! renamed refresh_list_after_update to refresh_list --- frontends/default/views/on_update.js.rjs | 2 +- lib/active_scaffold/actions/update.rb | 2 +- lib/active_scaffold/config/update.rb | 8 ++++---- lib/active_scaffold/helpers/controller_helpers.rb | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index d67a2e3ec9..22b0bede33 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -15,7 +15,7 @@ if controller.send :successful? end end #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} - elsif (active_scaffold_config.update.refresh_list_after_update) + elsif (active_scaffold_config.update.refresh_list) page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) else render :partial => 'list_record', :locals => {:record => @record} diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index e3cecc698a..962cebf8d3 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -49,7 +49,7 @@ def update_respond_to_html end end def update_respond_to_js - if active_scaffold_config.update.refresh_list_after_update && successful? + if active_scaffold_config.update.refresh_list && successful? do_search if respond_to? :do_search do_list end diff --git a/lib/active_scaffold/config/update.rb b/lib/active_scaffold/config/update.rb index 5b14d5f874..1178373f03 100644 --- a/lib/active_scaffold/config/update.rb +++ b/lib/active_scaffold/config/update.rb @@ -4,7 +4,7 @@ class Update < ActiveScaffold::Config::Form def initialize(*args) super self.nested_links = self.class.nested_links - self.refresh_list_after_update = self.class.refresh_list_after_update + self.refresh_list = self.class.refresh_list end # global level configuration @@ -19,8 +19,8 @@ def self.link=(val) @@link = ActiveScaffold::DataStructures::ActionLink.new('edit', :label => :edit, :type => :member, :security_method => :update_authorized?) # whether we should refresh list after update or not - cattr_accessor :refresh_list_after_update - @@refresh_list_after_update = false + cattr_accessor :refresh_list + @@refresh_list = false # instance-level configuration # ---------------------------- @@ -40,7 +40,7 @@ def hide_nested_column end # whether we should refresh list after update or not - attr_accessor :refresh_list_after_update + attr_accessor :refresh_list end end diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index d7e18fe69b..73850c48b6 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -68,7 +68,7 @@ def render_parent_action(controller_path = nil) @parent_action = :row parent_controller = "#{controller_path.to_s.camelize}Controller".constantize @parent_action = :index if action_name == 'create' && parent_controller.active_scaffold_config.actions.include?(:create) && parent_controller.active_scaffold_config.create.refresh_list == true - @parent_action = :index if action_name == 'update' && parent_controller.active_scaffold_config.actions.include?(:update) && parent_controller.active_scaffold_config.update.refresh_list_after_update == true + @parent_action = :index if action_name == 'update' && parent_controller.active_scaffold_config.actions.include?(:update) && parent_controller.active_scaffold_config.update.refresh_list == true rescue ActiveScaffold::ControllerNotFound end if @parent_action.nil? @parent_action From cf6e0fe57e9e2fbe5199c584a8096c225e8ac6cc Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 19 Jan 2011 16:11:13 +0100 Subject: [PATCH 0931/2024] Bugfix: returning to sti_parent did not work if js disabled --- lib/active_scaffold.rb | 2 +- .../helpers/controller_helpers.rb | 38 +++++++++---------- lib/active_scaffold/helpers/view_helpers.rb | 1 - 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 30fcf53f3f..964210a024 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -124,7 +124,7 @@ def _add_sti_create_links active_scaffold_config.sti_children.each do |child| new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone new_sti_link.label = child.to_s.camelize.constantize.model_name.human - new_sti_link.parameters = {:parent_sti => controller_path, :return_to => :referrer} + new_sti_link.parameters = {:parent_sti => controller_path} new_sti_link.controller = active_scaffold_controller_for(child.to_s.camelize.constantize).controller_path active_scaffold_config.action_links.collection.create.add(new_sti_link) end diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 73850c48b6..0414506936 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -24,26 +24,26 @@ def params_for(options = {}) # Parameters to generate url to the main page (override if the ActiveScaffold is used as a component on another controllers page) def main_path_to_return - if params[:return_to] - params[:return_to] == 'referrer' ? request.referrer : params[:return_to] - else - parameters = {} - if params[:parent_controller] - parameters[:controller] = params[:parent_controller] - parameters[:eid] = params[:parent_controller] - end - if nested? - parameters[:controller] = nested.parent_scaffold.controller_path - parameters[:eid] = nil - end - parameters[:parent_column] = nil - parameters[:parent_id] = nil - parameters[:action] = "index" - parameters[:id] = nil - parameters[:associated_id] = nil - parameters[:utf8] = nil - params_for(parameters) + parameters = {} + if params[:parent_controller] + parameters[:controller] = params[:parent_controller] + parameters[:eid] = params[:parent_controller] + end + if nested? + parameters[:controller] = nested.parent_scaffold.controller_path + parameters[:eid] = nil + end + if params[:parent_sti] + parameters[:controller] = params[:parent_sti] + parameters[:eid] = nil end + parameters[:parent_column] = nil + parameters[:parent_id] = nil + parameters[:action] = "index" + parameters[:id] = nil + parameters[:associated_id] = nil + parameters[:utf8] = nil + params_for(parameters) end def render_parent? diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 9ab11e33b9..9a1b785230 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -228,7 +228,6 @@ def url_options_for_sti_link(column, record, link, url_options, options = {}) if sti_controller_path url_options[:controller] = sti_controller_path url_options[:parent_sti] = controller_path - url_options[:return_to] = :referrer end end From bd3bec83173d715a7953b31a426ada546da0cdde Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 19 Jan 2011 16:37:42 +0100 Subject: [PATCH 0932/2024] Bugfix: render_field initialize new record correctly --- lib/active_scaffold/actions/core.rb | 13 ++++++++++++- lib/active_scaffold/actions/create.rb | 10 ---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 64e6e455cb..a7a81af9d6 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -11,7 +11,7 @@ def render_field @record ||= if params[:in_place_editing] active_scaffold_config.model.find params[:id] else - active_scaffold_config.model.new + new_model end column = active_scaffold_config.columns[params[:column]] if params[:in_place_editing] @@ -127,6 +127,17 @@ def conditions_from_params end conditions end + + def new_model + model = beginning_of_chain + if model.columns_hash[model.inheritance_column] + params = self.params # in new action inheritance_column must be in params + params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key + model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column] + end + model.respond_to?(:build) ? model.build : model.new + end + private def respond_to_action(action) respond_to do |type| diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index eda650321f..d1732df345 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -114,16 +114,6 @@ def do_create end end - def new_model - model = beginning_of_chain - if model.columns_hash[model.inheritance_column] - params = self.params # in new action inheritance_column must be in params - params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key - model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column] - end - model.respond_to?(:build) ? model.build : model.new - end - # override this method if you want to inject data in the record (or its associated objects) before the save def before_create_save(record); end From 0c2724bb1a7b3b40782069dc3b509311385cc122 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 20 Jan 2011 12:11:12 +0100 Subject: [PATCH 0933/2024] Bugfix: action_links find_duplicate should only compare static defined controllers --- lib/active_scaffold/data_structures/action_link.rb | 11 ++++++++++- lib/active_scaffold/data_structures/action_links.rb | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 9f80b93471..71391721ee 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -29,7 +29,16 @@ def initialize(action, options = {}) attr_accessor :action # the controller for this action link. if nil, the current controller should be assumed. - attr_accessor :controller + attr_writer :controller + + def controller + @controller = @controller.call if @controller.is_a?(Proc) + @controller + end + + def static_controller? + !(@controller.is_a?(Proc) || (@controller == :polymorph)) + end # a hash of request parameters attr_accessor :parameters diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index c3e4ee024a..90703b2e9b 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -64,7 +64,7 @@ def find_duplicate(link) collected = item.find_duplicate(link) links << collected unless collected.nil? else - links << item if item.action == link.action and item.controller == link.controller and item.parameters == link.parameters + links << item if item.action == link.action and item.static_controller? && item.controller == link.controller and item.parameters == link.parameters end end links.first From fd33ef929c7fefff5bc9fdc9aedf4ff208f94fe5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 20 Jan 2011 13:42:26 +0100 Subject: [PATCH 0934/2024] further improvements for sti support --- lib/active_scaffold.rb | 3 ++- lib/active_scaffold/config/core.rb | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 964210a024..6336398d97 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -82,6 +82,7 @@ def active_scaffold(model_id = nil, &block) @active_scaffold_custom_paths = [] self.active_scaffold_superclasses_blocks.each {|superblock| self.active_scaffold_config.configure &superblock} + self.active_scaffold_config.sti_children = nil # reset sti_children if set in parent block self.active_scaffold_config.configure &block if block_given? self.active_scaffold_config._configure_sti unless self.active_scaffold_config.sti_children.nil? self.active_scaffold_config._load_action_columns @@ -125,7 +126,7 @@ def _add_sti_create_links new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone new_sti_link.label = child.to_s.camelize.constantize.model_name.human new_sti_link.parameters = {:parent_sti => controller_path} - new_sti_link.controller = active_scaffold_controller_for(child.to_s.camelize.constantize).controller_path + new_sti_link.controller = Proc.new { active_scaffold_controller_for(child.to_s.camelize.constantize).controller_path } active_scaffold_config.action_links.collection.create.add(new_sti_link) end end diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index e8a94a4f92..a5855ed94c 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -58,6 +58,7 @@ def self.ignore_columns=(val) # lets you specify whether add a create link for each sti child cattr_accessor :sti_create_links + @@sti_create_links = true # instance-level configuration # ---------------------------- From 7d72643d6e44554b8c0459647ef31c383dde548b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 20 Jan 2011 14:16:06 +0100 Subject: [PATCH 0935/2024] readd return_to for further tests --- .../helpers/controller_helpers.rb | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 0414506936..c410fdb6da 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -24,26 +24,30 @@ def params_for(options = {}) # Parameters to generate url to the main page (override if the ActiveScaffold is used as a component on another controllers page) def main_path_to_return - parameters = {} - if params[:parent_controller] - parameters[:controller] = params[:parent_controller] - parameters[:eid] = params[:parent_controller] - end - if nested? - parameters[:controller] = nested.parent_scaffold.controller_path - parameters[:eid] = nil - end - if params[:parent_sti] - parameters[:controller] = params[:parent_sti] - parameters[:eid] = nil + if params[:return_to] + params[:return_to] + else + parameters = {} + if params[:parent_controller] + parameters[:controller] = params[:parent_controller] + parameters[:eid] = params[:parent_controller] + end + if nested? + parameters[:controller] = nested.parent_scaffold.controller_path + parameters[:eid] = nil + end + if params[:parent_sti] + parameters[:controller] = params[:parent_sti] + parameters[:eid] = nil + end + parameters[:parent_column] = nil + parameters[:parent_id] = nil + parameters[:action] = "index" + parameters[:id] = nil + parameters[:associated_id] = nil + parameters[:utf8] = nil + params_for(parameters) end - parameters[:parent_column] = nil - parameters[:parent_id] = nil - parameters[:action] = "index" - parameters[:id] = nil - parameters[:associated_id] = nil - parameters[:utf8] = nil - params_for(parameters) end def render_parent? From a229f5cdcc41d491a1cdb98b852359fcb375565f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 20 Jan 2011 14:17:27 +0100 Subject: [PATCH 0936/2024] Bugfix: do not traverse action_link group if empty --- lib/active_scaffold/data_structures/action_links.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 90703b2e9b..27c7c0cce7 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -106,10 +106,12 @@ def traverse(controller, options = {}, &block) first_action = true @set.send(traverse_method) do |link| if link.is_a?(ActiveScaffold::DataStructures::ActionLinks) - yield(link, nil, {:node => :start_traversing, :first_action => first_action, :level => options[:level]}) - link.traverse(controller,options, &block) - yield(link, nil, {:node => :finished_traversing, :first_action => first_action, :level => options[:level]}) - first_action = false + unless link.empty? + yield(link, nil, {:node => :start_traversing, :first_action => first_action, :level => options[:level]}) + link.traverse(controller,options, &block) + yield(link, nil, {:node => :finished_traversing, :first_action => first_action, :level => options[:level]}) + first_action = false + end elsif controller.nil? || !skip_action_link(controller, link, *(Array(options[:for]))) authorized = options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action) yield(self, link, {:authorized => authorized, :first_action => first_action, :level => options[:level]}) From 506d1fe9de0ece53d911abe6ddffcb9582e20778 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 20 Jan 2011 14:49:37 +0100 Subject: [PATCH 0937/2024] Bugfix: render_field for in_place_editing: init record correctly and check authorization --- lib/active_scaffold/actions/core.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index a7a81af9d6..880d7b4bb3 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -9,7 +9,8 @@ def self.included(base) end def render_field @record ||= if params[:in_place_editing] - active_scaffold_config.model.find params[:id] + register_constraints_with_action_columns(nested.constrained_fields, active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested? + find_if_allowed(params[:id], :update) else new_model end From 3527a93959d582fd43e73c439c0bf3b04870d94d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 20 Jan 2011 14:58:22 +0100 Subject: [PATCH 0938/2024] refactored render_field --- lib/active_scaffold/actions/core.rb | 33 +++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 880d7b4bb3..e8653e3e02 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -8,20 +8,10 @@ def self.included(base) base.helper_method :beginning_of_chain end def render_field - @record ||= if params[:in_place_editing] - register_constraints_with_action_columns(nested.constrained_fields, active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested? - find_if_allowed(params[:id], :update) - else - new_model - end - column = active_scaffold_config.columns[params[:column]] if params[:in_place_editing] - render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>" - elsif !column.nil? - value = column_value_from_param_value(@record, column, params[:value]) - @record.send "#{column.name}=", value - after_render_field(@record, column) - render :partial => "render_field", :collection => Array(params[:update_columns]), :content_type => 'text/javascript' + render_field_for_inplace_editing + else + render_field_for_update_columns end end @@ -30,6 +20,23 @@ def render_field def nested? false end + + def render_field_for_inplace_editing + register_constraints_with_action_columns(nested.constrained_fields, active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested? + @record = find_if_allowed(params[:id], :update) + render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>" + end + + def render_field_for_update_columns + @record = new_model + column = active_scaffold_config.columns[params[:column]] + unless column.nil? + value = column_value_from_param_value(@record, column, params[:value]) + @record.send "#{column.name}=", value + after_render_field(@record, column) + render :partial => "render_field", :collection => Array(params[:update_columns]), :content_type => 'text/javascript' + end + end # override this method if you want to do something after render_field def after_render_field(record, column); end From 712593707018ec8b7bb4c686bbf3399472aae423 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 20 Jan 2011 15:23:15 +0100 Subject: [PATCH 0939/2024] Add switch to control if assets should be copied: ACTIVE_SCAFFOLD_INSTALL_ASSETS should be defined in config/environments/xx.rb --- install_assets.rb | 83 ++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/install_assets.rb b/install_assets.rb index 4351d80e7f..47180cac8d 100755 --- a/install_assets.rb +++ b/install_assets.rb @@ -1,45 +1,46 @@ -# Workaround a problem with script/plugin and http-based repos. -# See http://dev.rubyonrails.org/ticket/8189 -Dir.chdir(Dir.getwd.sub(/vendor.*/, '')) do - -## -## Copy over asset files (javascript/css/images) from the plugin directory to public/ -## - -def copy_files(source_path, destination_path, directory, file_mask = '*.*', clean_up_destination = false) - source, destination = File.join(directory, source_path), File.join(Rails.root, destination_path) - FileUtils.mkdir_p(destination) unless File.exist?(destination) - Dir.glob('*.so') - - FileUtils.rm Dir.glob("#{destination}/*") if clean_up_destination - FileUtils.cp_r(Dir.glob("#{source}/#{file_mask}"), destination) -end - -directory = File.dirname(__FILE__) - -copy_files("/public", "/public", directory) - -available_frontends = Dir[File.join(directory, 'frontends', '*')].collect { |d| File.basename d } -[ :stylesheets, :javascripts, :images].each do |asset_type| - path = "/public/#{asset_type}/active_scaffold" - copy_files(path, path, directory) - - File.open(File.join(Rails.root, path, 'DO_NOT_EDIT'), 'w') do |f| - f.puts "Any changes made to files in sub-folders will be lost." - f.puts "See http://activescaffold.com/tutorials/faq#custom-css." - end +unless defined?(ACTIVE_SCAFFOLD_INSTALL_ASSETS) && ACTIVE_SCAFFOLD_INSTALL_ASSETS == false + # Workaround a problem with script/plugin and http-based repos. + # See http://dev.rubyonrails.org/ticket/8189 + Dir.chdir(Dir.getwd.sub(/vendor.*/, '')) do + + ## + ## Copy over asset files (javascript/css/images) from the plugin directory to public/ + ## + + def copy_files(source_path, destination_path, directory, file_mask = '*.*', clean_up_destination = false) + source, destination = File.join(directory, source_path), File.join(Rails.root, destination_path) + FileUtils.mkdir_p(destination) unless File.exist?(destination) + Dir.glob('*.so') + + FileUtils.rm Dir.glob("#{destination}/*") if clean_up_destination + FileUtils.cp_r(Dir.glob("#{source}/#{file_mask}"), destination) + end - available_frontends.each do |frontend| - if asset_type == :javascripts - file_mask = '*.js' - source = "/frontends/#{frontend}/#{asset_type}/#{ActiveScaffold.js_framework}" - else - file_mask = '*.*' - source = "/frontends/#{frontend}/#{asset_type}" + directory = File.dirname(__FILE__) + + copy_files("/public", "/public", directory) + + available_frontends = Dir[File.join(directory, 'frontends', '*')].collect { |d| File.basename d } + [ :stylesheets, :javascripts, :images].each do |asset_type| + path = "/public/#{asset_type}/active_scaffold" + copy_files(path, path, directory) + + File.open(File.join(Rails.root, path, 'DO_NOT_EDIT'), 'w') do |f| + f.puts "Any changes made to files in sub-folders will be lost." + f.puts "See http://activescaffold.com/tutorials/faq#custom-css." + end + + available_frontends.each do |frontend| + if asset_type == :javascripts + file_mask = '*.js' + source = "/frontends/#{frontend}/#{asset_type}/#{ActiveScaffold.js_framework}" + else + file_mask = '*.*' + source = "/frontends/#{frontend}/#{asset_type}" + end + destination = "/public/#{asset_type}/active_scaffold/#{frontend}" + copy_files(source, destination, directory, file_mask, true) + end end - destination = "/public/#{asset_type}/active_scaffold/#{frontend}" - copy_files(source, destination, directory, file_mask, true) end -end - end \ No newline at end of file From 71ee59e7125c8eda0ce1c848db367a4132cb05f2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 20 Jan 2011 21:42:00 +0100 Subject: [PATCH 0940/2024] if sti_children Array is empty do not delete create link --- lib/active_scaffold.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 6336398d97..955bcc64ce 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -120,7 +120,7 @@ def active_scaffold(model_id = nil, &block) # To be called after include action modules def _add_sti_create_links new_action_link = active_scaffold_config.action_links.collection['new'] - unless new_action_link.nil? + unless new_action_link.nil? || active_scaffold_config.sti_children.empty? active_scaffold_config.action_links.collection.delete('new') active_scaffold_config.sti_children.each do |child| new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone From 66cde5d60b6a63c5923bc6bd4b77d5b8cfd5358d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 20 Jan 2011 21:44:45 +0100 Subject: [PATCH 0941/2024] Bugfix for rails ticket 6306: concerning association.build for sti models --- lib/extensions/active_association_reflection.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 lib/extensions/active_association_reflection.rb diff --git a/lib/extensions/active_association_reflection.rb b/lib/extensions/active_association_reflection.rb new file mode 100644 index 0000000000..20bdffdc57 --- /dev/null +++ b/lib/extensions/active_association_reflection.rb @@ -0,0 +1,13 @@ +# Bugfix: building an sti model from an association fails +# https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6306-collection-associations-build-method-not-supported-for-sti +ActiveRecord::Reflection::AssociationReflection.class_eval do + def build_association(*opts) + col = klass.inheritance_column.to_sym + if !col.nil? && opts.first.is_a?(Hash) && (opts.first.symbolize_keys[col]) + sti_model = opts.first.delete(col) + sti_model.to_s.constantize.new(*opts) + else + klass.new(*opts) + end + end +end \ No newline at end of file From aad9c44230ec7b70b2ad070e2bfabdf299da59b6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 20 Jan 2011 21:53:59 +0100 Subject: [PATCH 0942/2024] camelize type value --- lib/extensions/active_association_reflection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extensions/active_association_reflection.rb b/lib/extensions/active_association_reflection.rb index 20bdffdc57..353b158701 100644 --- a/lib/extensions/active_association_reflection.rb +++ b/lib/extensions/active_association_reflection.rb @@ -5,7 +5,7 @@ def build_association(*opts) col = klass.inheritance_column.to_sym if !col.nil? && opts.first.is_a?(Hash) && (opts.first.symbolize_keys[col]) sti_model = opts.first.delete(col) - sti_model.to_s.constantize.new(*opts) + sti_model.to_s.camelize.constantize.new(*opts) else klass.new(*opts) end From ae31101cb3c112e215f939773726ac8d3dfa28d2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 20 Jan 2011 21:58:04 +0100 Subject: [PATCH 0943/2024] Bugfix: build correct sti model in case of building from assocation --- lib/active_scaffold/actions/core.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index e8653e3e02..fbb2cf7f33 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -139,11 +139,12 @@ def conditions_from_params def new_model model = beginning_of_chain if model.columns_hash[model.inheritance_column] + build_options = {model.inheritance_column.to_sym => active_scaffold_config.model_id} if nested? && nested.association && nested.association.collection? params = self.params # in new action inheritance_column must be in params params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column] end - model.respond_to?(:build) ? model.build : model.new + model.respond_to?(:build) ? model.build(build_options || {}) : model.new end private From 398e51fc24cd6b625cbc23d6ea6db033c69eb783 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 21 Jan 2011 08:20:42 +0100 Subject: [PATCH 0944/2024] Bugfix: updated_row was undefined --- frontends/default/views/on_update.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 22b0bede33..e3a4584e50 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -18,7 +18,7 @@ if controller.send :successful? elsif (active_scaffold_config.update.refresh_list) page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) else - render :partial => 'list_record', :locals => {:record => @record} + updated_row = render :partial => 'list_record', :locals => {:record => @record} page << "action_link.close('#{escape_javascript(updated_row)}');" page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} end From bdc9f65211b3bd2bfef7bfc7e1b267d2ea829d39 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 21 Jan 2011 11:10:51 +0100 Subject: [PATCH 0945/2024] provide function to copy assets to public dir (inspired by mojotech fork) --- init.rb | 2 +- install.rb | 3 +-- install_assets.rb | 46 ----------------------------------- lib/active_scaffold_assets.rb | 45 ++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 49 deletions(-) delete mode 100755 install_assets.rb create mode 100644 lib/active_scaffold_assets.rb diff --git a/init.rb b/init.rb index 46734751a9..5e1fe7c935 100755 --- a/init.rb +++ b/init.rb @@ -12,7 +12,7 @@ ## But at least rescue the action in production ## begin - require File.dirname(__FILE__) + '/install_assets' + ActiveScaffoldAssets.copy_to_public(File.dirname(__FILE__), {:clean_up_destination => true}) rescue raise $! unless Rails.env == 'production' end diff --git a/install.rb b/install.rb index 6aec94c5b2..5502c9022e 100644 --- a/install.rb +++ b/install.rb @@ -1,8 +1,7 @@ ## ## Install ActiveScaffold assets into /public ## - -require File.dirname(__FILE__) + '/install_assets' +ActiveScaffoldAssets.copy_to_public(File.dirname(__FILE__), {:clean_up_destination => true}) ## ## Install Counter diff --git a/install_assets.rb b/install_assets.rb deleted file mode 100755 index 47180cac8d..0000000000 --- a/install_assets.rb +++ /dev/null @@ -1,46 +0,0 @@ -unless defined?(ACTIVE_SCAFFOLD_INSTALL_ASSETS) && ACTIVE_SCAFFOLD_INSTALL_ASSETS == false - # Workaround a problem with script/plugin and http-based repos. - # See http://dev.rubyonrails.org/ticket/8189 - Dir.chdir(Dir.getwd.sub(/vendor.*/, '')) do - - ## - ## Copy over asset files (javascript/css/images) from the plugin directory to public/ - ## - - def copy_files(source_path, destination_path, directory, file_mask = '*.*', clean_up_destination = false) - source, destination = File.join(directory, source_path), File.join(Rails.root, destination_path) - FileUtils.mkdir_p(destination) unless File.exist?(destination) - Dir.glob('*.so') - - FileUtils.rm Dir.glob("#{destination}/*") if clean_up_destination - FileUtils.cp_r(Dir.glob("#{source}/#{file_mask}"), destination) - end - - directory = File.dirname(__FILE__) - - copy_files("/public", "/public", directory) - - available_frontends = Dir[File.join(directory, 'frontends', '*')].collect { |d| File.basename d } - [ :stylesheets, :javascripts, :images].each do |asset_type| - path = "/public/#{asset_type}/active_scaffold" - copy_files(path, path, directory) - - File.open(File.join(Rails.root, path, 'DO_NOT_EDIT'), 'w') do |f| - f.puts "Any changes made to files in sub-folders will be lost." - f.puts "See http://activescaffold.com/tutorials/faq#custom-css." - end - - available_frontends.each do |frontend| - if asset_type == :javascripts - file_mask = '*.js' - source = "/frontends/#{frontend}/#{asset_type}/#{ActiveScaffold.js_framework}" - else - file_mask = '*.*' - source = "/frontends/#{frontend}/#{asset_type}" - end - destination = "/public/#{asset_type}/active_scaffold/#{frontend}" - copy_files(source, destination, directory, file_mask, true) - end - end - end -end \ No newline at end of file diff --git a/lib/active_scaffold_assets.rb b/lib/active_scaffold_assets.rb new file mode 100644 index 0000000000..64675b6d2e --- /dev/null +++ b/lib/active_scaffold_assets.rb @@ -0,0 +1,45 @@ +class ActiveScaffoldAssets + + def self.copy_to_public(from, options = {}) + unless defined?(ACTIVE_SCAFFOLD_INSTALL_ASSETS) && ACTIVE_SCAFFOLD_INSTALL_ASSETS == false + copy_files("/public", "/public", from) + available_frontends = Dir[File.join(from, 'frontends', '*')].collect { |d| File.basename d } + [:stylesheets, :javascripts, :images].each do |asset_type| + copy_asset_type(from, available_frontends, asset_type, options) + end + end + end + +protected + + def self.copy_asset_type(from, available_frontends, asset_type, options = {}) + path = "/public/#{asset_type}/active_scaffold" + copy_files(path, path, from) + + File.open(File.join(Rails.root, path, 'DO_NOT_EDIT'), 'w') do |f| + f.puts "Any changes made to files in sub-folders will be lost." + f.puts "See http://activescaffold.com/tutorials/faq#custom-css." + end + + available_frontends.each do |frontend| + if asset_type == :javascripts + file_mask = '*.js' + source = "/frontends/#{frontend}/#{asset_type}/#{ActiveScaffold.js_framework}" + else + file_mask = '*.*' + source = "/frontends/#{frontend}/#{asset_type}" + end + destination = "/public/#{asset_type}/active_scaffold/#{frontend}" + copy_files(source, destination, from, file_mask, options) + end + end + + def self.copy_files(source_path, destination_path, directory, file_mask = '*.*', options = {}) + source, destination = File.join(directory, source_path), File.join(Rails.root, destination_path) + FileUtils.mkdir_p(destination) unless File.exist?(destination) + Dir.glob('*.so') + + FileUtils.rm Dir.glob("#{destination}/*") if options[:clean_up_destination] + FileUtils.cp_r(Dir.glob("#{source}/#{file_mask}"), destination) + end +end \ No newline at end of file From 7fff750fc45610dda3fe42b64784d4c79d70a157 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 21 Jan 2011 12:37:50 +0100 Subject: [PATCH 0946/2024] add refresh_list option to delete action as well --- frontends/default/views/destroy.js.rjs | 8 ++++++-- lib/active_scaffold/actions/delete.rb | 4 ++++ lib/active_scaffold/config/delete.rb | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/destroy.js.rjs b/frontends/default/views/destroy.js.rjs index 8d8c1ae6b7..485e7d3062 100644 --- a/frontends/default/views/destroy.js.rjs +++ b/frontends/default/views/destroy.js.rjs @@ -1,6 +1,10 @@ if controller.send(:successful?) - page << "ActiveScaffold.delete_record_row('#{element_row_id(:action => 'list', :id => params[:id])}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" - page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} + if (active_scaffold_config.delete.refresh_list) + page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) + else + page << "ActiveScaffold.delete_record_row('#{element_row_id(:action => 'list', :id => params[:id])}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" + page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} + end else flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) end diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 75c347c23a..d47df1370c 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -23,6 +23,10 @@ def destroy_respond_to_html end def destroy_respond_to_js + if active_scaffold_config.delete.refresh_list && successful? + do_search if respond_to? :do_search + do_list + end render(:action => 'destroy') end diff --git a/lib/active_scaffold/config/delete.rb b/lib/active_scaffold/config/delete.rb index 80438aa60c..05802a7831 100644 --- a/lib/active_scaffold/config/delete.rb +++ b/lib/active_scaffold/config/delete.rb @@ -8,6 +8,7 @@ def initialize(core_config) # start with the ActionLink defined globally @link = self.class.link.clone @action_group = self.class.action_group.clone if self.class.action_group + self.refresh_list = self.class.refresh_list end # global level configuration @@ -17,10 +18,17 @@ def initialize(core_config) cattr_accessor :link @@link = ActiveScaffold::DataStructures::ActionLink.new('destroy', :label => :delete, :type => :member, :confirm => :are_you_sure_to_delete, :method => :delete, :crud_type => :delete, :position => false, :parameters => {:destroy_action => true}, :security_method => :delete_authorized?) + # whether we should refresh list after destroy or not + cattr_accessor :refresh_list + @@refresh_list = false + # instance-level configuration # ---------------------------- # the ActionLink for this action attr_accessor :link + + # whether we should refresh list after destroy or not + attr_accessor :refresh_list end end From 12bcbd4e1bbb621fcdb29dcf33971477196e2313 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 21 Jan 2011 15:40:26 +0100 Subject: [PATCH 0947/2024] Version bump to 3.0.6 --- VERSION | 1 + 1 file changed, 1 insertion(+) create mode 100644 VERSION diff --git a/VERSION b/VERSION new file mode 100644 index 0000000000..8ffc1ad640 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +3.0.6 \ No newline at end of file From f0b6f9bd87d639445f6e6daf0131288a8030f6ad Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 21 Jan 2011 17:23:21 +0100 Subject: [PATCH 0948/2024] gemified plugin many thanks to Chris Shoemaker !! --- CHANGELOG | 27 ++++++++++ README | 28 +++++++--- Rakefile | 43 +++++++++++++-- VERSION | 1 - init.rb | 17 ++---- install.rb | 38 -------------- lib/active_scaffold.rb | 78 +++++++++++++++++++++++++++- lib/active_scaffold/config/core.rb | 2 +- lib/active_scaffold/version.rb | 9 ++++ environment.rb => lib/environment.rb | 7 +-- 10 files changed, 177 insertions(+), 73 deletions(-) delete mode 100644 VERSION delete mode 100644 install.rb create mode 100644 lib/active_scaffold/version.rb rename environment.rb => lib/environment.rb (70%) diff --git a/CHANGELOG b/CHANGELOG index 635c051fef..632837de6e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,30 @@ += 3.0.5 + +- switch from explicit requires to autoloading +- get nested action links up and running + += 3.0.4 + +- Fix a typo that made 3.0.3 unusable. + += 3.0.3 + +- Fixing 'require' ordering +- Code for nested and subgrouped action links +- bugfixes for better html generation + += 3.0.2 + +- Two bug fixes and a deprecation silencing. + += 3.0.1 + +- Fixing the requiring of files. + += 3.0.0 + +- Packaging up vhochstein's fork for Rails 3.0 as a gem. + = 1.2RC1 == FEATURES diff --git a/README b/README index 9aab254287..c0a2611778 100644 --- a/README +++ b/README @@ -29,16 +29,22 @@ Rails < 2.1: Active Scaffold 1-1-stable (no guarantees) Since Rails 2.3, render_component plugin is needed for nested and embbeded scaffolds. It works with rails-2.3 branch from ewildgoose repository: script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3 -Rails 3.0 compatible fork of activesaffold by Volker Hochstein: +== Rails 3.0 compatible fork of activesaffold by Volker Hochstein: -Since Rails 3.0 render_component is nt used for nesting, but optional for embedded scaffolds -Rails 3.0 version of render_component: -rails plugin install git://github.com/vhochstein/render_component.git +Since Rails 3.0 render_component is not used for nesting, but is optional for embedded scaffolds. +Since Rails 3.0, https://github.com/rails/verification.git is also needed. -Since Rails 3.0, the following is needed: -rails plugin install git://github.com/rails/verification.git +If you want to install as plugins under vendor/plugins, install these versions: + rails plugin install git://github.com/vhochstein/render_component.git + rails plugin install git://github.com/rails/verification.git + rails plugin install git://github.com/vhochstein/active_scaffold.git -Fork uses unobtrusive Javascript, so you are basically free to pick your javascript framework +If you want to use the gem, add to your Gemfile: + gem "active_scaffold" + +== Pick your own javascript framework + +The Rails 3.0 version uses unobtrusive Javascript, so you are free to pick your javascript framework. Out of the box Prototype or JQuery are supported: Prototype 1.7 (default js framework) @@ -46,6 +52,12 @@ rails.js in git://github.com/vhochstein/prototype-ujs.git JQuery 1.4.1 rails.js in git://github.com/vhochstein/jquery-ujs.git -uncomment last line in ...plugins/active_scaffold/environment.rb in order tu use jquery instead of prototype + +To configure the javascript framework when installed under vendor/plugins/ +uncomment last line in ...plugins/active_scaffold/environment.rb in order to use jquery instead of prototype + +To configure the javascript framework when installed as a gem: +Add a config/initializers/active_scaffold.rb containing: +ActiveScaffold.js_framework = :jquery # :prototype is the default Released under the MIT license (included) diff --git a/Rakefile b/Rakefile index 785a135289..cbc3cf7166 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,43 @@ +require 'rubygems' +require 'bundler' +begin + Bundler.setup(:default, :development) +rescue Bundler::BundlerError => e + $stderr.puts e.message + $stderr.puts "Run `bundle install` to install missing gems" + exit e.status_code +end require 'rake' require 'rake/testtask' require 'rake/packagetask' require 'rake/rdoctask' require 'find' -desc 'Default: run unit tests.' -task :default => :test +require 'jeweler' +require './lib/active_scaffold/version.rb' +Jeweler::Tasks.new do |gem| + # snip + gem.version = ActiveScaffold::Version::STRING +end + +Jeweler::Tasks.new do |gem| + # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options + gem.name = "active_scaffold" + gem.homepage = "http://github.com/vhochstein/active_scaffold" + gem.license = "MIT" + gem.summary = %Q{Rails 3 Version of activescaffold supporting prototype and jquery} + gem.description = %Q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} + gem.email = "activescaffold@googlegroups.com" + gem.authors = ["Many, see README"] + gem.add_runtime_dependency 'render_component' + gem.add_runtime_dependency 'verification' + gem.add_runtime_dependency 'rails', '~> 3.0.0' + # Include your dependencies below. Runtime dependencies are required when using your gem, + # and development dependencies are only needed for development (ie running rake tasks, tests, etc) + # gem.add_runtime_dependency 'jabber4r', '> 0.1' + # gem.add_development_dependency 'rspec', '> 1.2.3' +end +Jeweler::RubygemsDotOrgTasks.new desc 'Test ActiveScaffold.' Rake::TestTask.new(:test) do |t| @@ -16,9 +48,10 @@ end desc 'Generate documentation for ActiveScaffold.' Rake::RDocTask.new(:rdoc) do |rdoc| + version = File.exist?('VERSION') ? File.read('VERSION') : "" rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'ActiveScaffold' + rdoc.title = 'ActiveScaffold #{version}' rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('README') + rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') -end +end \ No newline at end of file diff --git a/VERSION b/VERSION deleted file mode 100644 index 8ffc1ad640..0000000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -3.0.6 \ No newline at end of file diff --git a/init.rb b/init.rb index 5e1fe7c935..7d4a1daddb 100755 --- a/init.rb +++ b/init.rb @@ -1,18 +1,9 @@ -## -## Initialize the environment -## -unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 0 - raise "This version of ActiveScaffold requires Rails 3.0 or higher. Please use an earlier version." -end +ACTIVE_SCAFFOLD_PLUGIN = true -require File.dirname(__FILE__) + '/environment' +require 'active_scaffold' -## -## Run the install assets script, too, just to make sure -## But at least rescue the action in production -## begin - ActiveScaffoldAssets.copy_to_public(File.dirname(__FILE__), {:clean_up_destination => true}) + ActiveScaffoldAssets.copy_to_public(ActiveScaffold.root, {:clean_up_destination => true}) rescue raise $! unless Rails.env == 'production' -end +end \ No newline at end of file diff --git a/install.rb b/install.rb deleted file mode 100644 index 5502c9022e..0000000000 --- a/install.rb +++ /dev/null @@ -1,38 +0,0 @@ -## -## Install ActiveScaffold assets into /public -## -ActiveScaffoldAssets.copy_to_public(File.dirname(__FILE__), {:clean_up_destination => true}) - -## -## Install Counter -## -# -# What's going on here? -# We're incrementing a web counter so we can track SVN installs of ActiveScaffold -# -# How? -# We're making a GET request to errcount.com to update a simple counter. No data is transmitted. -# -# Why? -# So we can know how many people are using ActiveScaffold and modulate our level of effort accordingly. -# Despite numerous pleas our Googly overlords still only provide us with download stats for the zip distro. -# -# *Thanks for your understanding* -# - -class ErrCounter # using errcount.com - require "net/http" - - @@ACCOUNT_ID = 341 - @@SITE_DOMAIN = 'installs.activescaffold.com' - - def self.increment - @http = Net::HTTP.new("errcount.com") - resp, data = @http.get2("/ctr/#{@@ACCOUNT_ID}.js", {'Referer' => @@SITE_DOMAIN}) - end -end - -begin - ErrCounter.increment -rescue -end diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 955bcc64ce..d30ad28311 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -1,4 +1,59 @@ +unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 0 + raise "This version of ActiveScaffold requires Rails 3.0 or higher. Please use an earlier version." +end + +begin + require 'render_component' +rescue LoadError +end +begin + require 'verification' +rescue LoadError +end + +require 'active_record_permissions' +require 'dhtml_confirm' +require 'paginator' +require 'responds_to_parent' + +require 'active_scaffold/version' + module ActiveScaffold + autoload :AttributeParams, 'active_scaffold/attribute_params' + autoload :Configurable, 'active_scaffold/configurable' + autoload :Constraints, 'active_scaffold/constraints' + autoload :Finder, 'active_scaffold/finder' + autoload :MarkedModel, 'active_scaffold/marked_model' + + def self.active_scaffold_autoload_subdir(dir, mod=self) + Dir["#{File.dirname(__FILE__)}/active_scaffold/#{dir}/*.rb"].each { |file| + basename = File.basename(file, ".rb") + mod.module_eval { + autoload basename.camelcase.to_sym, "active_scaffold/#{dir}/#{basename}" + } + } + end + + module Actions + ActiveScaffold.active_scaffold_autoload_subdir('actions', self) + end + + module Bridges + autoload :Bridge, 'active_scaffold/bridges/bridge' + end + + module Config + ActiveScaffold.active_scaffold_autoload_subdir('config', self) + end + + module DataStructures + ActiveScaffold.active_scaffold_autoload_subdir('data_structures', self) + end + + module Helpers + ActiveScaffold.active_scaffold_autoload_subdir('helpers', self) + end + class ControllerNotFound < RuntimeError; end class DependencyFailure < RuntimeError; end class MalformedConstraint < RuntimeError; end @@ -53,6 +108,10 @@ def self.js_framework @@js_framework ||= :prototype end + def self.root + File.dirname(__FILE__) + "/.." + end + module ClassMethods def active_scaffold(model_id = nil, &block) # initialize bridges here @@ -74,10 +133,10 @@ def active_scaffold(model_id = nil, &block) @active_scaffold_overrides.uniq! # Fix rails duplicating some view_paths @active_scaffold_frontends = [] if active_scaffold_config.frontend.to_sym != :default - active_scaffold_custom_frontend_path = File.join(Rails.root, 'vendor', 'plugins', ActiveScaffold::Config::Core.plugin_directory, 'frontends', active_scaffold_config.frontend.to_s , 'views') + active_scaffold_custom_frontend_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'frontends', active_scaffold_config.frontend.to_s , 'views') @active_scaffold_frontends << active_scaffold_custom_frontend_path end - active_scaffold_default_frontend_path = File.join(Rails.root, 'vendor', 'plugins', ActiveScaffold::Config::Core.plugin_directory, 'frontends', 'default' , 'views') + active_scaffold_default_frontend_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'frontends', 'default' , 'views') @active_scaffold_frontends << active_scaffold_default_frontend_path @active_scaffold_custom_paths = [] @@ -268,3 +327,18 @@ def uses_active_scaffold? end end end + +require 'environment' + +## +## Run the install assets script, too, just to make sure +## But at least rescue the action in production +## +Rails::Application.initializer("active_scaffold.install_assets") do + begin + ActiveScaffoldAssets.copy_to_public(ActiveScaffold.root, {:clean_up_destination => true}) + rescue + raise $! unless Rails.env == 'production' + end +end unless defined?(ACTIVE_SCAFFOLD_PLUGIN) && ACTIVE_SCAFFOLD_PLUGIN == true + diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index a5855ed94c..b20986b03c 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -15,7 +15,7 @@ def self.actions=(val) # configures where the ActiveScaffold plugin itself is located. there is no instance version of this. cattr_accessor :plugin_directory - @@plugin_directory = File.expand_path(__FILE__).match(/vendor\/plugins\/([^\/]*)/)[1] + @@plugin_directory = File.expand_path(__FILE__).match(%{(^.*)/lib/active_scaffold/config/core.rb})[1] # lets you specify a global ActiveScaffold frontend. cattr_accessor :frontend diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb new file mode 100644 index 0000000000..de81bf0c6b --- /dev/null +++ b/lib/active_scaffold/version.rb @@ -0,0 +1,9 @@ +module ActiveScaffold + module Version + MAJOR = 3 + MINOR = 0 + PATCH = 6 + + STRING = [MAJOR, MINOR, PATCH].compact.join('.') + end +end diff --git a/environment.rb b/lib/environment.rb similarity index 70% rename from environment.rb rename to lib/environment.rb index b8547f3f21..f1dd02cc92 100644 --- a/environment.rb +++ b/lib/environment.rb @@ -1,7 +1,5 @@ -require 'active_scaffold' - # TODO: clean up extensions. some could be organized for autoloading, and others could be removed entirely. -Dir["#{File.dirname __FILE__}/lib/extensions/*.rb"].each { |file| require file } +Dir["#{File.dirname __FILE__}/extensions/*.rb"].each { |file| require file } ActionController::Base.send(:include, ActiveScaffold) ActionController::Base.send(:include, RespondsToParent) @@ -12,6 +10,5 @@ ActiveRecord::Base.class_eval {include ActiveRecordPermissions::ModelUserAccess::Model} ActiveRecord::Base.class_eval {include ActiveRecordPermissions::Permissions} -require "#{File.dirname __FILE__}/lib/active_scaffold/bridges/bridge.rb" -I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'lib', 'active_scaffold', 'locale', '*.{rb,yml}')] +I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'active_scaffold', 'locale', '*.{rb,yml}')] #ActiveScaffold.js_framework = :jquery From bcb09f180c388080bf748add3b2866403dc610ab Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 21 Jan 2011 23:03:54 +0100 Subject: [PATCH 0949/2024] lazy load action_links in links_for_associations --- lib/active_scaffold.rb | 6 ++-- lib/active_scaffold/data_structures/column.rb | 29 ++++++++++--------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index d30ad28311..b068168179 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -196,8 +196,10 @@ def links_for_associations return unless active_scaffold_config.actions.include? :list and active_scaffold_config.actions.include? :nested active_scaffold_config.columns.each do |column| next unless column.link.nil? and column.autolink? - action_link = link_for_association(column) - column.set_link(action_link) unless action_link.nil? + #lazy load of action_link, cause it was really slowing down app in dev mode + #and might lead to trouble cause of cyclic constantization of controllers + #and might be unnecessary cause it is done before columns are configured + column.set_link(Proc.new {|col| link_for_association(col)}) end end diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 619b2781aa..b28bc62ded 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -114,22 +114,14 @@ def options @options ||= {} end - # associate an action_link with this column - attr_reader :link - - # set an action_link to nested list or inline form in this column - def autolink? - @autolink - end - - # this should not only delete any existing link but also prevent column links from being automatically added by later routines - def clear_link - @link = nil - @autolink = false + def link + @link = @link.call(self) if @link.is_a? Proc + @link end + # associate an action_link with this column def set_link(action, options = {}) - if action.is_a? ActiveScaffold::DataStructures::ActionLink + if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || (action.is_a? Proc) @link = action else options[:label] ||= self.label @@ -139,6 +131,17 @@ def set_link(action, options = {}) end end + # set an action_link to nested list or inline form in this column + def autolink? + @autolink + end + + # this should not only delete any existing link but also prevent column links from being automatically added by later routines + def clear_link + @link = nil + @autolink = false + end + # define a calculation for the column. anything that ActiveRecord::Calculations::ClassMethods#calculate accepts will do. attr_accessor :calculate From a8150b59554f1fb528f32d8404302c937eb74305 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 22 Jan 2011 20:33:33 +0100 Subject: [PATCH 0950/2024] Bugfix: gemify moved environment.rb to lib dir, generator did not know that so far (issue: 75 reported by jsurrett) --- .../active_scaffold_setup/active_scaffold_setup_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb index 28e9fdb3ea..35896ee1d4 100644 --- a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +++ b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb @@ -20,7 +20,7 @@ def install_plugins def configure_active_scaffold if js_lib == 'jquery' - gsub_file 'vendor/plugins/active_scaffold/environment.rb', /#ActiveScaffold.js_framework = :jquery/, 'ActiveScaffold.js_framework = :jquery' + gsub_file 'vendor/plugins/active_scaffold/lib/environment.rb', /#ActiveScaffold.js_framework = :jquery/, 'ActiveScaffold.js_framework = :jquery' end end From 93273eab6f1882edfea1143db03c27f0645d2600 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 24 Jan 2011 11:01:44 +0100 Subject: [PATCH 0951/2024] Bugfix: Rakefile fix copy and paste error --- Rakefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index cbc3cf7166..c59f0f6378 100644 --- a/Rakefile +++ b/Rakefile @@ -15,14 +15,11 @@ require 'find' require 'jeweler' require './lib/active_scaffold/version.rb' -Jeweler::Tasks.new do |gem| - # snip - gem.version = ActiveScaffold::Version::STRING -end Jeweler::Tasks.new do |gem| # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options gem.name = "active_scaffold" + gem.version = ActiveScaffold::Version::STRING gem.homepage = "http://github.com/vhochstein/active_scaffold" gem.license = "MIT" gem.summary = %Q{Rails 3 Version of activescaffold supporting prototype and jquery} From 6aac94e55c87957b5ec8aa8eacaee573e5875cb2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 24 Jan 2011 15:08:32 +0100 Subject: [PATCH 0952/2024] Bugfix: use VERSION CONSTANT instead of VERSION file --- Rakefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index c59f0f6378..fa67699f25 100644 --- a/Rakefile +++ b/Rakefile @@ -45,9 +45,8 @@ end desc 'Generate documentation for ActiveScaffold.' Rake::RDocTask.new(:rdoc) do |rdoc| - version = File.exist?('VERSION') ? File.read('VERSION') : "" rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'ActiveScaffold #{version}' + rdoc.title = 'ActiveScaffold #{ActiveScaffold::Version::STRING}' rdoc.options << '--line-numbers' << '--inline-source' rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') From 49a51fbcc8eb4dbf8059cd21d00ecdcda9df2098 Mon Sep 17 00:00:00 2001 From: jsurrett <jeff@surrett.org> Date: Mon, 24 Jan 2011 10:32:02 -0500 Subject: [PATCH 0953/2024] Add icons and reformat menu css for action_groups --- frontends/default/images/config.png | Bin 0 -> 714 bytes frontends/default/images/gears.png | Bin 0 -> 1741 bytes frontends/default/stylesheets/stylesheet.css | 54 ++++++++++++------ .../default/views/_action_group.html.erb | 10 ++-- 4 files changed, 41 insertions(+), 23 deletions(-) create mode 100755 frontends/default/images/config.png create mode 100644 frontends/default/images/gears.png diff --git a/frontends/default/images/config.png b/frontends/default/images/config.png new file mode 100755 index 0000000000000000000000000000000000000000..cfc2702acd7b7c84be4d84363e6845d4be5614ba GIT binary patch literal 714 zcmV;*0yX`KP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00004XF*Lt006JZ zHwB960000PbVXQnQ*UN;cVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBU!TuDShR5;6} zlkHEEVHC!nt#5tok882OJ``KFK^v>KTsd(L2%Nfb28ake(Nc)gcnjiHl06Vi5zr`8 z(3F?(m8sa))$`m0WS?l=+qJX%?3~|q&b{3f0P254(UJXrb9jGiI#k0{pbFjlDki*T zsNK65bM9bxejAF{MGV<CF)*`^$CfYXqx11Lz!cuA)=z)nUv$s7de#OQg5OEflGVes zqQTVCI5ep-s1quTFmgOu9K_H<KL)~mcocX*YVS^F&<0HUt0dX&;cD+ZTkZff?7m#` z#X`9&akaP9sSaSAeXJIMJ2TPJ1xH(~dG~s~a5x;O9-iXHXrcocb$r9o$vI{h%dl~Z zRq!fShMg(H9nHe)^JDJA2120_0)YUQS2tmxt)OXILjc2bTR3C^cBVp{-u#X&*L*&Y zU@(YWE{C<XHF!K8WHK2j6bi^>vdfg*Ucf>99P^0^-hR9&S2%@qIt{DU3aL~IrBX@O zh{xkltJMZF!Qku$_KzEIr<%^br7DT7!cwWkIkl(KYIP_Ui*UJIkjv$u`d_XSfR}Cb z{UM9R0=L_ZLZJY?UJqxoLZsE{kj-XUkQPFr5LDmuPuODtfppV3xYCS`Mgz%Y5)8w@ z@Angkj%{{2orpvt5Q#*37I1~SZ(2p|=nR#EQ|#1EP^{GPb@v#bw+~@78VP`#hFgbg zG?`3@Mxz`6VzKxVB{AfpV(m)(_QW!7K24!#B!TNn23O@VNMzIK?d?U6)DE-R43$cS wYY%A%1cIMD9`7A_#BRT>L?Qv7&&S{SUnp5P#YQSqod5s;07*qoM6N<$f_olE%m4rY literal 0 HcmV?d00001 diff --git a/frontends/default/images/gears.png b/frontends/default/images/gears.png new file mode 100644 index 0000000000000000000000000000000000000000..9857c1c52467bd5a5d6f9b63f2f6638c6a7b969d GIT binary patch literal 1741 zcmV;;1~U1HP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV0008+X+uL$Nkc;* zP;zf(X>4Tx0C)j~RL^S@K@|QrZmG~B2wH0nvUrdpNm;9CMbtL^5n^i$+aI<?kYqDS z)^0ZI?k2URh~(nYD&9ryp$Gqf9(wR(FG_`4MJV2@C}N=(E%D86Otz)!z|Ma2-Z$@k zZ+71R4RX>n^?(HA4aZWV5ov6ELTdbo0FI&wK{O>*+w4vx20?>!`FrQsdJlnHR>OPy zcd~b_n$otK2Za4V;76L-DzNVtaSB-y0*E}{p()372;bw_^6ZZ}PI-92wGS&j#91PI zKs7DSe@(bk%_Y-7gGe}(^>I=@oY#w#*Bu9GZf3^F5WP>3rn}7Ut74&?PWBFvy`A)a zPP5)V!Xd&78LdA?xQ(9mjMYElVd13a#D+Z_7&Y|xU=_C-srWU*6kiZcC!$nw*)9$7 zn6CX+@=AhmkT}X@VSsa5NKe;HZuq)~1$`#h6R+ZTR#D-3j}vF!)ZOnz+5)dI4jl{{ z44Mr{P!L4~VVJN`K!!XTF*LGrKO?IK8<Tr7btG!LbYeuYL3=jbJ-1P$-8}v%B5{;M zwFr{@LH;VQ$xr2Z`O93e*jD$Ht(%&<^58qg<(at}9@o>z<8w`3e3jI8lUGNUta*C8 zn(P`s>{pjD=7Kek#B;Fw@hxAK%$F&Q6vg9J^Xf~4by_hu-=A!MJ3Znq&n~srbFGPs zH&&aMXZ>nO`|hf|ljc?VPhR!${AbO?W8x_>CU%PFA&Hm8F7cAsOREdwU~R_;ot1_u z(ruCYB-LPGn!NQdT|ZlRy+(fw^-+`=%+gee_kY4FWHg<*4sZI8+sFJD<oAl_pC|$^ zY~aY5x@}W&?+~G7rEYVs0vEs0eekw!YomTR`~+A$s}`+NHJ>270UUORdLHO0nA4V) z%{fwsET5CQ>B?eK%uw4yQc~9?*JVo<vzb+5>2}ze(;aRcp*ceL#HUJSllrgm5wQKR zQu+C;QrUh^8rFfA`ftFz{YAidi-`aL010qNS#tmY4c7nw4c7reD4Tcy00V_dL_t(I z5nWPkXj^3zKJUFZZN9&5+T3)e+D<#HV6_>o5{0gRwmByLa6@G3kLvWtP|(3dikQOw zOeupoT&pY7>Vy%gb4#_;r81g+jCS2Rx3P3FrXNX~v`LzK^KqNp`+DD4rFh`*zVCC+ zbKZw@4q%L7)6tfD1q(+a$Cejk$NrBiZ*&14paBE=mrRo+pU>A6k0(cmM@Blydo7X4 zEkqad0MO_g^Bs&tq9a$oxVdd>K}HE8#U;gIe0-MMy=QMnhr6TcMsOziK)POCR;}Ql zW4-eT?o(-2hMV<MZ+1e9=iIH2-?3V2f2znH9=_V7QqkJa2l`Nd?`gk4r_ATVJpffa zHmfZ%!%(1Q)JUzOpd=!k;d9sOtn99-;AC^9!0hauvBvEUZh;rpXog~sT-h%%H6rLK z8=V$XkX;i%ZJ?mO)`{!cI%KsNfzR;Lt<aTbib((A$4jT?=l@JuO*VFD{DKscC+Up> zLx&<kxa*(!AlOrQccGsyghCHcFc!k|3(L|<HccB<992<3ii}O%xZ~uU&E1#YhM-|6 zsizv&DG{Ik^>FwkiNE&cGndtm<o5Bo^^%Mzl`M;8N{BZxUhl|9oWp+9Xfzv>s|gUr zf($wcV1!p_j7AAr=`*r8pZl&f?b`i(<4%=Eqmwv?lM$9S-eBhbxNlloUbSd+I=RMT zg2yaR;Mw9Yb2g(nQEipX{}jOZ)ZP~_e*5+Ql0jo<*3)?ig;QcO9j_*FT5(Iy@xFWC zpZDY6CjI!(nLS^@XVAQF$l*FX?J|+M4-5_-y?r-`2L>-=&+#+&6b`F6Lly|{*x_n7 z7>tLis;l%IYsanI+ge@plYDNed|MxFpyjltYv<E#pXLM+3)uqF>$K&A2VS}6^_~xt zMS`^yf1=jz;3%q;&*wL^cEdLO(zB0#*!lPi?=h$fYHYQdL}C^5d>+xXlviuCTw*15 zLZP--3d~Fgj>r_Y#g`)G?(R>#2vJ5{M8FzZ4f%lQvw&r#_f$FC-*@t5?xBYnN=B;y zuL2n(S!GNT&z}9Jtz%c`R8CmWV30C(4u_NA(O7H|0d3alP3GT6{q0>{uU{v)Vu&mf z_INxMCDCY9T3GyRZen8Mt*2UAT8qV^NSxdWMq(s~FgH2Mw3QBTT15#`j5L;Dfk2>_ joNl-KeR6Jz{iphG{%hOHrFy$+00000NkvXXu0mjfTyS46 literal 0 HcmV?d00001 diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 19373ea8cb..8714ad3cad 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -35,7 +35,7 @@ text-decoration: none; color: #999; } -.active-scaffold a:hover, .active-scaffold span.hover { +.active-scaffold a:hover, .active-scaffold div.hover { background-color: #ff8; } @@ -87,7 +87,7 @@ padding: 2px 5px 4px 5px; } .active-scaffold-header div.actions a, -.active-scaffold-header div.actions span { +.active-scaffold-header div.actions { float: right; font: bold 14px arial; letter-spacing: -1px; @@ -105,7 +105,7 @@ float: right; } .active-scaffold-header div.actions div.action_group li a, -.active-scaffold-header div.actions div.action_group li span { +.active-scaffold-header div.actions div.action_group li div { float: none; margin: 0 2px; } @@ -116,7 +116,7 @@ top: 14px; } .view .active-scaffold-header div.actions a, -.view .active-scaffold-header div.actions span, +.view .active-scaffold-header div.actions div, .view .active-scaffold-header div.actions div.action_group { float: left; } @@ -137,12 +137,26 @@ opacity: 0.5; .active-scaffold-header div.actions a.new, .active-scaffold-header div.actions a.new_existing, -.active-scaffold-header div.actions a.show_search { +.active-scaffold-header div.actions a.show_search, +.active-scaffold-header div.actions a.show_config_list, +.active-scaffold-header div.actions div.action_group div { padding-left: 19px; background-position: 1px 50%; background-repeat: no-repeat; } +.active-scaffold-header div.actions div.action_group div { + padding: 1px 2px 1px 19px; + background-position: 1px 50%; + background-repeat: no-repeat; + margin-left: 5px; + background-image: url(../../../images/active_scaffold/default/gears.png); /* default icon for actions or override with css */ +} + +.active-scaffold-header div.actions a.show_config_list { + background-image: url(../../../images/active_scaffold/default/config.png); +} + .active-scaffold-header div.actions a.new, .active-scaffold-header div.actions a.new_existing { background-image: url(../../../images/active_scaffold/default/add.gif); @@ -292,7 +306,7 @@ padding: 0 2px; } .active-scaffold tr.record td.actions a, -.active-scaffold tr.record td.actions span { +.active-scaffold tr.record td.actions div { font: bold 11px verdana, sans-serif; letter-spacing: -1px; padding: 2px; @@ -301,44 +315,41 @@ line-height: 16px; white-space: nowrap; } -.active-scaffold .actions .action_group span:hover { +.active-scaffold .actions .action_group div:hover { background-color: #ff8; } .active-scaffold .actions .action_group { position: relative; -text-align: right; +text-align: left; color: #0066CC; } .active-scaffold .actions .action_group ul { -border: medium none; +border: 2px solid #005CB8; list-style-type: none; margin: 0; padding: 0; position: absolute; line-height: 200%; display: none; -width: 100%; -left: -80px; +width: 150px; +right: 0px; } .active-scaffold .actions .action_group ul ul { display: none; position: absolute; top: 0; -left: -120px; } .active-scaffold .actions .action_group ul li { -background: none repeat scroll 0 0 #FFF; -border-bottom: 2px solid #005CB8; -border-left: 2px solid #005CB8; -border-right: 2px solid #005CB8; +background: none repeat scroll 0 0 #EEE; +border-bottom: 1px dashed #222; display: block; padding-bottom: 5px; position: relative; -width: 120px; +width: auto; z-index: 2; } @@ -346,6 +357,13 @@ z-index: 2; border-top: 1px solid #005CB8; } +.active-scaffold .actions .action_group ul li a { + display: block; + color: #333; + margin: 0; + padding: 3px 5px 3px 25px; +} + .active-scaffold .actions .action_group:hover ul ul, .active-scaffold .actions .action_group:hover ul ul ul { display: none; @@ -415,7 +433,7 @@ right: 0px; } .active-scaffold .active-scaffold .active-scaffold-header div.actions a, -.active-scaffold .active-scaffold .active-scaffold-header div.actions span { +.active-scaffold .active-scaffold .active-scaffold-header div.actions div { font: bold 11px verdana, sans-serif; padding: 0 2px 1px 17px; } diff --git a/frontends/default/views/_action_group.html.erb b/frontends/default/views/_action_group.html.erb index b6634f11fa..6ac6a1c3ab 100644 --- a/frontends/default/views/_action_group.html.erb +++ b/frontends/default/views/_action_group.html.erb @@ -5,11 +5,11 @@ <% if (options[:node] == :finished_traversing) -%> <%= "</ul>#{(options[:level] == 0 ? "</div>#{end_level_0_tag}": '</li>')}".html_safe %> <% elsif (options[:node] == :start_traversing) -%> - <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}<div class=\"action_group\"> #{content_tag('span', as_(parent.name))}<ul>".html_safe %> - <% else %> - <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag('span', as_(parent.name))}<ul>".html_safe %> - <% end %> + <% if options[:level] == 0 %> + <%= "#{start_level_0_tag}<div class=\"action_group\"> #{content_tag(:div, as_(parent.name), :class => (parent.name).downcase)}<ul>".html_safe %> + <% else %> + <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag(:div, as_(parent.name), :class => (parent.name).downcase)}<ul>".html_safe %> + <% end %> <% else -%> <% if options[:level] == 0 %> <%= "#{start_level_0_tag}#{h(render_group_action_link(link, url_options, options, record))}#{end_level_0_tag}".html_safe %> From 3c777cf400702ba9570b811cbf94f925326db266 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 25 Jan 2011 17:21:26 +0100 Subject: [PATCH 0954/2024] added some further nil checks --- lib/active_scaffold.rb | 3 +-- lib/active_scaffold/config/form.rb | 2 +- lib/active_scaffold/data_structures/action_links.rb | 8 +++----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index b068168179..c48dc9c108 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -163,10 +163,9 @@ def active_scaffold(model_id = nil, &block) if link = active_scaffold_config.send(mod).link rescue nil if link.is_a? Array link.each {|current| active_scaffold_config.action_links.add_to_group(current, active_scaffold_config.send(mod).action_group)} - else + elsif link.is_a? ActiveScaffold::DataStructures::ActionLink active_scaffold_config.action_links.add_to_group(link, active_scaffold_config.send(mod).action_group) end - end end end diff --git a/lib/active_scaffold/config/form.rb b/lib/active_scaffold/config/form.rb index 1b5275ef8a..0331567b59 100644 --- a/lib/active_scaffold/config/form.rb +++ b/lib/active_scaffold/config/form.rb @@ -4,7 +4,7 @@ def initialize(core_config) @core = core_config # start with the ActionLink defined globally - @link = self.class.link.clone + @link = self.class.link.clone unless self.class.link.nil? @action_group = self.class.action_group.clone if self.class.action_group # no global setting here because multipart should only be set for specific forms diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 27c7c0cce7..0a07166c86 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -36,11 +36,9 @@ def add_to_set(link) # groups are represented as a string separated by a dot # eg member.crud def add_to_group(link, group = nil) - if group - group.split('.').inject(root){|group, group_name| group.send(group_name)}.add link - else - root << link - end + add_to = root + add_to = group.split('.').inject(root){|group, group_name| group.send(group_name)} if group + add_to << link unless link.nil? end # finds an ActionLink by matching the action From e63a932f1b5234b3c26d485064a7db2fd04abbf5 Mon Sep 17 00:00:00 2001 From: jsurrett <jeff@surrett.org> Date: Tue, 25 Jan 2011 18:45:45 -0500 Subject: [PATCH 0955/2024] menu adjustments --- frontends/default/stylesheets/stylesheet.css | 1 + frontends/default/views/_action_group.html.erb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 8714ad3cad..0dfa662b1d 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -341,6 +341,7 @@ right: 0px; display: none; position: absolute; top: 0; +right: 150px; } .active-scaffold .actions .action_group ul li { diff --git a/frontends/default/views/_action_group.html.erb b/frontends/default/views/_action_group.html.erb index 6ac6a1c3ab..f84d984f67 100644 --- a/frontends/default/views/_action_group.html.erb +++ b/frontends/default/views/_action_group.html.erb @@ -6,9 +6,9 @@ <%= "</ul>#{(options[:level] == 0 ? "</div>#{end_level_0_tag}": '</li>')}".html_safe %> <% elsif (options[:node] == :start_traversing) -%> <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}<div class=\"action_group\"> #{content_tag(:div, as_(parent.name), :class => (parent.name).downcase)}<ul>".html_safe %> + <%= "#{start_level_0_tag}<div class=\"action_group\"> #{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %> <% else %> - <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag(:div, as_(parent.name), :class => (parent.name).downcase)}<ul>".html_safe %> + <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %> <% end %> <% else -%> <% if options[:level] == 0 %> From de25c9c34d6ebf4f73ad38773dee1937cb80d56a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 10:56:43 +0100 Subject: [PATCH 0956/2024] add jeweler files --- .document | 5 +++++ .gitignore | 42 ++++++++++++++++++++++++++++++++++++++++++ Gemfile | 13 +++++++++++++ Gemfile.lock | 20 ++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 .document create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/.document b/.document new file mode 100644 index 0000000000..69db7194cb --- /dev/null +++ b/.document @@ -0,0 +1,5 @@ +lib/**/*.rb +bin/* +- +features/**/*.feature +MIT-LICENSE.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..228818604e --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +# rcov generated +coverage + +# rdoc generated +rdoc + +# yard generated +doc +.yardoc + +# bundler +.bundle + +# jeweler generated +pkg + +# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore: +# +# * Create a file at ~/.gitignore +# * Include files you want ignored +# * Run: git config --global core.excludesfile ~/.gitignore +# +# After doing this, these files will be ignored in all your git projects, +# saving you from having to 'pollute' every project you touch with them +# +# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line) +# +# For MacOS: +# +#.DS_Store +# +# For TextMate +#*.tmproj +#tmtags +# +# For emacs: +#*~ +#\#* +#.\#* +# +# For vim: +#*.swp diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000000..bdb0a5f83a --- /dev/null +++ b/Gemfile @@ -0,0 +1,13 @@ +source "http://rubygems.org" +# Add dependencies required to use your gem here. +# Example: +# gem "activesupport", ">= 2.3.5" + +# Add dependencies to develop your gem here. +# Include everything needed to run rake, tests, features, etc. +group :development do + gem "shoulda", ">= 0" + gem "bundler", "~> 1.0.0" + gem "jeweler", "~> 1.5.2" + gem "rcov", ">= 0" +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000000..07df601572 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,20 @@ +GEM + remote: http://rubygems.org/ + specs: + git (1.2.5) + jeweler (1.5.2) + bundler (~> 1.0.0) + git (>= 1.2.5) + rake + rake (0.8.7) + rcov (0.9.9) + shoulda (2.11.3) + +PLATFORMS + ruby + +DEPENDENCIES + bundler (~> 1.0.0) + jeweler (~> 1.5.2) + rcov + shoulda From afec5b0b77c1d3fa9ead0affbcaa9ed854640e75 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 11:02:12 +0100 Subject: [PATCH 0957/2024] change gem name to active_scaffold_vho --- Rakefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Rakefile b/Rakefile index fa67699f25..88d230974e 100644 --- a/Rakefile +++ b/Rakefile @@ -18,7 +18,7 @@ require './lib/active_scaffold/version.rb' Jeweler::Tasks.new do |gem| # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options - gem.name = "active_scaffold" + gem.name = "active_scaffold_vho" gem.version = ActiveScaffold::Version::STRING gem.homepage = "http://github.com/vhochstein/active_scaffold" gem.license = "MIT" @@ -26,7 +26,7 @@ Jeweler::Tasks.new do |gem| gem.description = %Q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} gem.email = "activescaffold@googlegroups.com" gem.authors = ["Many, see README"] - gem.add_runtime_dependency 'render_component' + gem.add_runtime_dependency 'render_component_vho' gem.add_runtime_dependency 'verification' gem.add_runtime_dependency 'rails', '~> 3.0.0' # Include your dependencies below. Runtime dependencies are required when using your gem, From 4f49d6f509b75d63c8341b68acc1ec58f80d7627 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 11:03:36 +0100 Subject: [PATCH 0958/2024] Regenerate gemspec for version 3.0.6 --- active_scaffold_vho.gemspec | 383 ++++++++++++++++++++++++++++++++++++ 1 file changed, 383 insertions(+) create mode 100644 active_scaffold_vho.gemspec diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec new file mode 100644 index 0000000000..ae29965ed9 --- /dev/null +++ b/active_scaffold_vho.gemspec @@ -0,0 +1,383 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE DIRECTLY +# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{active_scaffold_vho} + s.version = "3.0.6" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Many, see README"] + s.date = %q{2011-01-26} + s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} + s.email = %q{activescaffold@googlegroups.com} + s.extra_rdoc_files = [ + "README" + ] + s.files = [ + ".autotest", + ".document", + "CHANGELOG", + "Gemfile", + "Gemfile.lock", + "MIT-LICENSE", + "README", + "Rakefile", + "frontends/default/images/add.gif", + "frontends/default/images/arrow_down.gif", + "frontends/default/images/arrow_up.gif", + "frontends/default/images/close.gif", + "frontends/default/images/config.png", + "frontends/default/images/cross.png", + "frontends/default/images/gears.png", + "frontends/default/images/indicator-small.gif", + "frontends/default/images/indicator.gif", + "frontends/default/images/magnifier.png", + "frontends/default/javascripts/jquery/active_scaffold.js", + "frontends/default/javascripts/jquery/jquery.editinplace.js", + "frontends/default/javascripts/prototype/active_scaffold.js", + "frontends/default/javascripts/prototype/dhtml_history.js", + "frontends/default/javascripts/prototype/form_enhancements.js", + "frontends/default/javascripts/prototype/rico_corner.js", + "frontends/default/stylesheets/stylesheet-ie.css", + "frontends/default/stylesheets/stylesheet.css", + "frontends/default/views/_action_group.html.erb", + "frontends/default/views/_add_existing_form.html.erb", + "frontends/default/views/_base_form.html.erb", + "frontends/default/views/_create_form.html.erb", + "frontends/default/views/_create_form_on_list.html.erb", + "frontends/default/views/_field_search.html.erb", + "frontends/default/views/_form.html.erb", + "frontends/default/views/_form_association.html.erb", + "frontends/default/views/_form_association_footer.html.erb", + "frontends/default/views/_form_attribute.html.erb", + "frontends/default/views/_form_hidden_attribute.html.erb", + "frontends/default/views/_form_messages.html.erb", + "frontends/default/views/_horizontal_subform.html.erb", + "frontends/default/views/_horizontal_subform_header.html.erb", + "frontends/default/views/_horizontal_subform_record.html.erb", + "frontends/default/views/_human_conditions.html.erb", + "frontends/default/views/_list.html.erb", + "frontends/default/views/_list_actions.html.erb", + "frontends/default/views/_list_calculations.html.erb", + "frontends/default/views/_list_column_headings.html.erb", + "frontends/default/views/_list_header.html.erb", + "frontends/default/views/_list_inline_adapter.html.erb", + "frontends/default/views/_list_messages.html.erb", + "frontends/default/views/_list_pagination.html.erb", + "frontends/default/views/_list_pagination_links.html.erb", + "frontends/default/views/_list_record.html.erb", + "frontends/default/views/_list_record_columns.html.erb", + "frontends/default/views/_list_with_header.html.erb", + "frontends/default/views/_messages.html.erb", + "frontends/default/views/_render_field.js.rjs", + "frontends/default/views/_row.html.erb", + "frontends/default/views/_search.html.erb", + "frontends/default/views/_search_attribute.html.erb", + "frontends/default/views/_show.html.erb", + "frontends/default/views/_show_columns.html.erb", + "frontends/default/views/_update_actions.html.erb", + "frontends/default/views/_update_form.html.erb", + "frontends/default/views/_vertical_subform.html.erb", + "frontends/default/views/_vertical_subform_record.html.erb", + "frontends/default/views/action_confirmation.html.erb", + "frontends/default/views/add_existing.js.rjs", + "frontends/default/views/add_existing_form.html.erb", + "frontends/default/views/create.html.erb", + "frontends/default/views/delete.html.erb", + "frontends/default/views/destroy.js.rjs", + "frontends/default/views/edit_associated.js.rjs", + "frontends/default/views/field_search.html.erb", + "frontends/default/views/form_messages.js.rjs", + "frontends/default/views/list.html.erb", + "frontends/default/views/list.js.rjs", + "frontends/default/views/on_action_update.js.rjs", + "frontends/default/views/on_create.js.rjs", + "frontends/default/views/on_update.js.rjs", + "frontends/default/views/search.html.erb", + "frontends/default/views/show.html.erb", + "frontends/default/views/update.html.erb", + "frontends/default/views/update_column.js.rjs", + "frontends/default/views/update_row.js.rjs", + "init.rb", + "lib/active_record_permissions.rb", + "lib/active_scaffold.rb", + "lib/active_scaffold/actions/common_search.rb", + "lib/active_scaffold/actions/core.rb", + "lib/active_scaffold/actions/create.rb", + "lib/active_scaffold/actions/delete.rb", + "lib/active_scaffold/actions/field_search.rb", + "lib/active_scaffold/actions/list.rb", + "lib/active_scaffold/actions/mark.rb", + "lib/active_scaffold/actions/nested.rb", + "lib/active_scaffold/actions/search.rb", + "lib/active_scaffold/actions/show.rb", + "lib/active_scaffold/actions/subform.rb", + "lib/active_scaffold/actions/update.rb", + "lib/active_scaffold/attribute_params.rb", + "lib/active_scaffold/bridges/ancestry/bridge.rb", + "lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb", + "lib/active_scaffold/bridges/bridge.rb", + "lib/active_scaffold/bridges/calendar_date_select/bridge.rb", + "lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb", + "lib/active_scaffold/bridges/carrierwave/bridge.rb", + "lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb", + "lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb", + "lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb", + "lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb", + "lib/active_scaffold/bridges/date_picker/bridge.rb", + "lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb", + "lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js", + "lib/active_scaffold/bridges/file_column/bridge.rb", + "lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb", + "lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb", + "lib/active_scaffold/bridges/file_column/lib/form_ui.rb", + "lib/active_scaffold/bridges/file_column/lib/list_ui.rb", + "lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb", + "lib/active_scaffold/bridges/file_column/test/mock_model.rb", + "lib/active_scaffold/bridges/file_column/test/test_helper.rb", + "lib/active_scaffold/bridges/paperclip/bridge.rb", + "lib/active_scaffold/bridges/paperclip/lib/form_ui.rb", + "lib/active_scaffold/bridges/paperclip/lib/list_ui.rb", + "lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb", + "lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb", + "lib/active_scaffold/bridges/semantic_attributes/bridge.rb", + "lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb", + "lib/active_scaffold/bridges/shared/date_bridge.rb", + "lib/active_scaffold/bridges/tiny_mce/bridge.rb", + "lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb", + "lib/active_scaffold/bridges/validation_reflection/bridge.rb", + "lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb", + "lib/active_scaffold/config/base.rb", + "lib/active_scaffold/config/core.rb", + "lib/active_scaffold/config/create.rb", + "lib/active_scaffold/config/delete.rb", + "lib/active_scaffold/config/field_search.rb", + "lib/active_scaffold/config/form.rb", + "lib/active_scaffold/config/list.rb", + "lib/active_scaffold/config/mark.rb", + "lib/active_scaffold/config/nested.rb", + "lib/active_scaffold/config/search.rb", + "lib/active_scaffold/config/show.rb", + "lib/active_scaffold/config/subform.rb", + "lib/active_scaffold/config/update.rb", + "lib/active_scaffold/configurable.rb", + "lib/active_scaffold/constraints.rb", + "lib/active_scaffold/data_structures/action_columns.rb", + "lib/active_scaffold/data_structures/action_link.rb", + "lib/active_scaffold/data_structures/action_links.rb", + "lib/active_scaffold/data_structures/actions.rb", + "lib/active_scaffold/data_structures/column.rb", + "lib/active_scaffold/data_structures/columns.rb", + "lib/active_scaffold/data_structures/error_message.rb", + "lib/active_scaffold/data_structures/nested_info.rb", + "lib/active_scaffold/data_structures/set.rb", + "lib/active_scaffold/data_structures/sorting.rb", + "lib/active_scaffold/finder.rb", + "lib/active_scaffold/helpers/association_helpers.rb", + "lib/active_scaffold/helpers/controller_helpers.rb", + "lib/active_scaffold/helpers/country_helpers.rb", + "lib/active_scaffold/helpers/form_column_helpers.rb", + "lib/active_scaffold/helpers/human_condition_helpers.rb", + "lib/active_scaffold/helpers/id_helpers.rb", + "lib/active_scaffold/helpers/list_column_helpers.rb", + "lib/active_scaffold/helpers/pagination_helpers.rb", + "lib/active_scaffold/helpers/search_column_helpers.rb", + "lib/active_scaffold/helpers/show_column_helpers.rb", + "lib/active_scaffold/helpers/view_helpers.rb", + "lib/active_scaffold/locale/de.rb", + "lib/active_scaffold/locale/en.rb", + "lib/active_scaffold/locale/es.yml", + "lib/active_scaffold/locale/fr.rb", + "lib/active_scaffold/locale/hu.yml", + "lib/active_scaffold/locale/ja.yml", + "lib/active_scaffold/locale/ru.yml", + "lib/active_scaffold/marked_model.rb", + "lib/active_scaffold/version.rb", + "lib/active_scaffold_assets.rb", + "lib/dhtml_confirm.rb", + "lib/environment.rb", + "lib/extensions/action_controller_rendering.rb", + "lib/extensions/action_view_rendering.rb", + "lib/extensions/action_view_resolver.rb", + "lib/extensions/active_association_reflection.rb", + "lib/extensions/active_record_offset.rb", + "lib/extensions/array.rb", + "lib/extensions/localize.rb", + "lib/extensions/name_option_for_datetime.rb", + "lib/extensions/nil_id_in_url_params.rb", + "lib/extensions/paginator_extensions.rb", + "lib/extensions/reverse_associations.rb", + "lib/extensions/routing_mapper.rb", + "lib/extensions/to_label.rb", + "lib/extensions/unsaved_associated.rb", + "lib/extensions/unsaved_record.rb", + "lib/extensions/usa_state.rb", + "lib/generators/active_scaffold/USAGE", + "lib/generators/active_scaffold/active_scaffold_generator.rb", + "lib/generators/active_scaffold_controller/USAGE", + "lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb", + "lib/generators/active_scaffold_controller/templates/controller.rb", + "lib/generators/active_scaffold_setup/USAGE", + "lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb", + "lib/paginator.rb", + "lib/responds_to_parent.rb", + "public/blank.html", + "shoulda_macros/macros.rb", + "test/bridges/bridge_test.rb", + "test/config/base_test.rb", + "test/config/create_test.rb", + "test/config/list_test.rb", + "test/config/show_test.rb", + "test/config/update_test.rb", + "test/const_mocker.rb", + "test/data_structures/action_columns_test.rb", + "test/data_structures/action_link_test.rb", + "test/data_structures/action_links_test.rb", + "test/data_structures/actions_test.rb", + "test/data_structures/association_column_test.rb", + "test/data_structures/column_test.rb", + "test/data_structures/columns_test.rb", + "test/data_structures/error_message_test.rb", + "test/data_structures/set_test.rb", + "test/data_structures/sorting_test.rb", + "test/data_structures/standard_column_test.rb", + "test/data_structures/virtual_column_test.rb", + "test/extensions/active_record_test.rb", + "test/extensions/array_test.rb", + "test/helpers/form_column_helpers_test.rb", + "test/helpers/list_column_helpers_test.rb", + "test/helpers/pagination_helpers_test.rb", + "test/misc/active_record_permissions_test.rb", + "test/misc/attribute_params_test.rb", + "test/misc/configurable_test.rb", + "test/misc/constraints_test.rb", + "test/misc/finder_test.rb", + "test/misc/lang_test.rb", + "test/mock_app/.gitignore", + "test/mock_app/app/controllers/application_controller.rb", + "test/mock_app/app/helpers/application_helper.rb", + "test/mock_app/config/boot.rb", + "test/mock_app/config/database.yml", + "test/mock_app/config/environment.rb", + "test/mock_app/config/environments/development.rb", + "test/mock_app/config/environments/production.rb", + "test/mock_app/config/environments/test.rb", + "test/mock_app/config/initializers/backtrace_silencers.rb", + "test/mock_app/config/initializers/inflections.rb", + "test/mock_app/config/initializers/mime_types.rb", + "test/mock_app/config/initializers/new_rails_defaults.rb", + "test/mock_app/config/initializers/session_store.rb", + "test/mock_app/config/locales/en.yml", + "test/mock_app/config/routes.rb", + "test/mock_app/db/test.sqlite3", + "test/mock_app/public/blank.html", + "test/mock_app/public/images/active_scaffold/DO_NOT_EDIT", + "test/mock_app/public/images/active_scaffold/default/add.gif", + "test/mock_app/public/images/active_scaffold/default/arrow_down.gif", + "test/mock_app/public/images/active_scaffold/default/arrow_up.gif", + "test/mock_app/public/images/active_scaffold/default/close.gif", + "test/mock_app/public/images/active_scaffold/default/cross.png", + "test/mock_app/public/images/active_scaffold/default/indicator-small.gif", + "test/mock_app/public/images/active_scaffold/default/indicator.gif", + "test/mock_app/public/images/active_scaffold/default/magnifier.png", + "test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT", + "test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js", + "test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js", + "test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js", + "test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js", + "test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT", + "test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css", + "test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css", + "test/model_stub.rb", + "test/run_all.rb", + "test/test_helper.rb", + "uninstall.rb" + ] + s.homepage = %q{http://github.com/vhochstein/active_scaffold} + s.licenses = ["MIT"] + s.require_paths = ["lib"] + s.rubygems_version = %q{1.3.7} + s.summary = %q{Rails 3 Version of activescaffold supporting prototype and jquery} + s.test_files = [ + "test/bridges/bridge_test.rb", + "test/config/base_test.rb", + "test/config/create_test.rb", + "test/config/list_test.rb", + "test/config/show_test.rb", + "test/config/update_test.rb", + "test/const_mocker.rb", + "test/data_structures/action_columns_test.rb", + "test/data_structures/action_link_test.rb", + "test/data_structures/action_links_test.rb", + "test/data_structures/actions_test.rb", + "test/data_structures/association_column_test.rb", + "test/data_structures/column_test.rb", + "test/data_structures/columns_test.rb", + "test/data_structures/error_message_test.rb", + "test/data_structures/set_test.rb", + "test/data_structures/sorting_test.rb", + "test/data_structures/standard_column_test.rb", + "test/data_structures/virtual_column_test.rb", + "test/extensions/active_record_test.rb", + "test/extensions/array_test.rb", + "test/helpers/form_column_helpers_test.rb", + "test/helpers/list_column_helpers_test.rb", + "test/helpers/pagination_helpers_test.rb", + "test/misc/active_record_permissions_test.rb", + "test/misc/attribute_params_test.rb", + "test/misc/configurable_test.rb", + "test/misc/constraints_test.rb", + "test/misc/finder_test.rb", + "test/misc/lang_test.rb", + "test/mock_app/app/controllers/application_controller.rb", + "test/mock_app/app/helpers/application_helper.rb", + "test/mock_app/config/boot.rb", + "test/mock_app/config/environment.rb", + "test/mock_app/config/environments/development.rb", + "test/mock_app/config/environments/production.rb", + "test/mock_app/config/environments/test.rb", + "test/mock_app/config/initializers/backtrace_silencers.rb", + "test/mock_app/config/initializers/inflections.rb", + "test/mock_app/config/initializers/mime_types.rb", + "test/mock_app/config/initializers/new_rails_defaults.rb", + "test/mock_app/config/initializers/session_store.rb", + "test/mock_app/config/routes.rb", + "test/model_stub.rb", + "test/run_all.rb", + "test/test_helper.rb" + ] + + if s.respond_to? :specification_version then + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + s.specification_version = 3 + + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_development_dependency(%q<shoulda>, [">= 0"]) + s.add_development_dependency(%q<bundler>, ["~> 1.0.0"]) + s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"]) + s.add_development_dependency(%q<rcov>, [">= 0"]) + s.add_runtime_dependency(%q<render_component_vho>, [">= 0"]) + s.add_runtime_dependency(%q<verification>, [">= 0"]) + s.add_runtime_dependency(%q<rails>, ["~> 3.0.0"]) + else + s.add_dependency(%q<shoulda>, [">= 0"]) + s.add_dependency(%q<bundler>, ["~> 1.0.0"]) + s.add_dependency(%q<jeweler>, ["~> 1.5.2"]) + s.add_dependency(%q<rcov>, [">= 0"]) + s.add_dependency(%q<render_component_vho>, [">= 0"]) + s.add_dependency(%q<verification>, [">= 0"]) + s.add_dependency(%q<rails>, ["~> 3.0.0"]) + end + else + s.add_dependency(%q<shoulda>, [">= 0"]) + s.add_dependency(%q<bundler>, ["~> 1.0.0"]) + s.add_dependency(%q<jeweler>, ["~> 1.5.2"]) + s.add_dependency(%q<rcov>, [">= 0"]) + s.add_dependency(%q<render_component_vho>, [">= 0"]) + s.add_dependency(%q<verification>, [">= 0"]) + s.add_dependency(%q<rails>, ["~> 3.0.0"]) + end +end + From 768b4ae224a22bf08e7bde5463f123593a4d03fd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 13:17:03 +0100 Subject: [PATCH 0959/2024] require shared/date_bridge --- lib/active_scaffold/bridges/bridge.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/bridges/bridge.rb b/lib/active_scaffold/bridges/bridge.rb index 7b85bca2ac..b249a92f64 100644 --- a/lib/active_scaffold/bridges/bridge.rb +++ b/lib/active_scaffold/bridges/bridge.rb @@ -47,6 +47,7 @@ def self.run_all end end +require File.join(File.dirname(__FILE__), 'shared', 'date_bridge.rb') Dir[File.join(File.dirname(__FILE__), "*/bridge.rb")].each{|bridge_require| require bridge_require } \ No newline at end of file From 9641dcc086158dcf30b82ddd6f2ca7f523a9627b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 13:21:14 +0100 Subject: [PATCH 0960/2024] add active_scaffold_vho file, add gem/plugin detection --- init.rb | 2 +- lib/active_scaffold.rb | 3 ++- lib/active_scaffold_vho.rb | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 lib/active_scaffold_vho.rb diff --git a/init.rb b/init.rb index 7d4a1daddb..a604755cac 100755 --- a/init.rb +++ b/init.rb @@ -1,4 +1,4 @@ -ACTIVE_SCAFFOLD_PLUGIN = true +ACTIVE_SCAFFOLD_INSTALLED = :plugin require 'active_scaffold' diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index c48dc9c108..1609a91830 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -11,6 +11,7 @@ rescue LoadError end +require 'active_scaffold_assets' require 'active_record_permissions' require 'dhtml_confirm' require 'paginator' @@ -341,5 +342,5 @@ def uses_active_scaffold? rescue raise $! unless Rails.env == 'production' end -end unless defined?(ACTIVE_SCAFFOLD_PLUGIN) && ACTIVE_SCAFFOLD_PLUGIN == true +end unless defined?(ACTIVE_SCAFFOLD_INSTALLED) && ACTIVE_SCAFFOLD_INSTALLED == :plugin diff --git a/lib/active_scaffold_vho.rb b/lib/active_scaffold_vho.rb new file mode 100644 index 0000000000..dde7ffa6f3 --- /dev/null +++ b/lib/active_scaffold_vho.rb @@ -0,0 +1,2 @@ +ACTIVE_SCAFFOLD_INSTALLED = :gem +require 'active_scaffold' \ No newline at end of file From 4eda6e12347ca9012702dffd3d9c5b7ec404ec49 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 13:23:53 +0100 Subject: [PATCH 0961/2024] Add support for gem version of active_scaffold --- .../active_scaffold_setup_generator.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb index 35896ee1d4..b64cf28b3b 100644 --- a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +++ b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb @@ -8,8 +8,10 @@ def self.source_root end def install_plugins - plugin 'verification', :git => 'git://github.com/rails/verification.git' - plugin 'render_component', :git => 'git://github.com/vhochstein/render_component.git' + unless defined?(ACTIVE_SCAFFOLD_INSTALLED) && ACTIVE_SCAFFOLD_INSTALLED == :gem + plugin 'verification', :git => 'git://github.com/rails/verification.git' + plugin 'render_component', :git => 'git://github.com/vhochstein/render_component.git' + end if js_lib == 'prototype' get "https://github.com/vhochstein/prototype-ujs/raw/master/src/rails.js", "public/javascripts/rails.js" elsif js_lib == 'jquery' @@ -19,8 +21,14 @@ def install_plugins end def configure_active_scaffold - if js_lib == 'jquery' - gsub_file 'vendor/plugins/active_scaffold/lib/environment.rb', /#ActiveScaffold.js_framework = :jquery/, 'ActiveScaffold.js_framework = :jquery' + unless defined?(ACTIVE_SCAFFOLD_INSTALLED) && ACTIVE_SCAFFOLD_INSTALLED == :gem + if js_lib == 'jquery' + gsub_file 'vendor/plugins/active_scaffold/lib/environment.rb', /#ActiveScaffold.js_framework = :jquery/, 'ActiveScaffold.js_framework = :jquery' + end + else + if js_lib == 'jquery' + create_file "config/initializers/active_scaffold.rb", "ActiveScaffold.js_framework = :jquery" + end end end From d3a2d6ccc926eafdf202cac2c9c7ee5e048fa09c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 13:26:17 +0100 Subject: [PATCH 0962/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index de81bf0c6b..06c6ead45f 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 6 + PATCH = 7 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 20b38e1d9694b77c5e54d50f1eecdd546c3c08dc Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 13:27:04 +0100 Subject: [PATCH 0963/2024] Regenerate gemspec for version 3.0.7 --- active_scaffold_vho.gemspec | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index ae29965ed9..8436398f10 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.6" + s.version = "3.0.7" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] @@ -24,6 +24,7 @@ Gem::Specification.new do |s| "MIT-LICENSE", "README", "Rakefile", + "active_scaffold_vho.gemspec", "frontends/default/images/add.gif", "frontends/default/images/arrow_down.gif", "frontends/default/images/arrow_up.gif", @@ -196,6 +197,7 @@ Gem::Specification.new do |s| "lib/active_scaffold/marked_model.rb", "lib/active_scaffold/version.rb", "lib/active_scaffold_assets.rb", + "lib/active_scaffold_vho.rb", "lib/dhtml_confirm.rb", "lib/environment.rb", "lib/extensions/action_controller_rendering.rb", From 8b7c20d6af5f8d067aa11263688b4e7fdf32652e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 16:04:38 +0100 Subject: [PATCH 0964/2024] autoload_subdir might be used by other gems --- lib/active_scaffold.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 1609a91830..3adf0e0768 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -26,8 +26,8 @@ module ActiveScaffold autoload :Finder, 'active_scaffold/finder' autoload :MarkedModel, 'active_scaffold/marked_model' - def self.active_scaffold_autoload_subdir(dir, mod=self) - Dir["#{File.dirname(__FILE__)}/active_scaffold/#{dir}/*.rb"].each { |file| + def self.autoload_subdir(dir, mod=self, root = File.dirname(__FILE__)) + Dir["#{root}/active_scaffold/#{dir}/*.rb"].each { |file| basename = File.basename(file, ".rb") mod.module_eval { autoload basename.camelcase.to_sym, "active_scaffold/#{dir}/#{basename}" @@ -36,7 +36,7 @@ def self.active_scaffold_autoload_subdir(dir, mod=self) end module Actions - ActiveScaffold.active_scaffold_autoload_subdir('actions', self) + ActiveScaffold.autoload_subdir('actions', self) end module Bridges @@ -44,15 +44,15 @@ module Bridges end module Config - ActiveScaffold.active_scaffold_autoload_subdir('config', self) + ActiveScaffold.autoload_subdir('config', self) end module DataStructures - ActiveScaffold.active_scaffold_autoload_subdir('data_structures', self) + ActiveScaffold.autoload_subdir('data_structures', self) end module Helpers - ActiveScaffold.active_scaffold_autoload_subdir('helpers', self) + ActiveScaffold.autoload_subdir('helpers', self) end class ControllerNotFound < RuntimeError; end From 074258df55d83a81064b40924c7aad7ee918172f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 16:06:11 +0100 Subject: [PATCH 0965/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 06c6ead45f..bec02727fb 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 7 + PATCH = 8 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 0c61253fd2f8f376f4d12dfd6c5c55b2ec1e4627 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 16:06:42 +0100 Subject: [PATCH 0966/2024] Regenerate gemspec for version 3.0.8 --- active_scaffold_vho.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index 8436398f10..17794d9caa 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.7" + s.version = "3.0.8" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] From 4ca65d70d78cb4b60ec2a2a7b797379b7d375763 Mon Sep 17 00:00:00 2001 From: jsurrett <jeff@surrett.org> Date: Wed, 26 Jan 2011 10:08:17 -0500 Subject: [PATCH 0967/2024] menu fine tuning: removing margins so menu hover highlights the whole menu option aligning deeper menus removing dashed line on bottom of last --- frontends/default/stylesheets/stylesheet.css | 30 +++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 0dfa662b1d..62e04c2b42 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -107,7 +107,7 @@ float: right; .active-scaffold-header div.actions div.action_group li a, .active-scaffold-header div.actions div.action_group li div { float: none; -margin: 0 2px; +margin: 0; } .active-scaffold-header div.actions .action_group ul { @@ -140,16 +140,13 @@ opacity: 0.5; .active-scaffold-header div.actions a.show_search, .active-scaffold-header div.actions a.show_config_list, .active-scaffold-header div.actions div.action_group div { -padding-left: 19px; +margin:0; +padding: 1px 5px 1px 20px; background-position: 1px 50%; background-repeat: no-repeat; } .active-scaffold-header div.actions div.action_group div { - padding: 1px 2px 1px 19px; - background-position: 1px 50%; - background-repeat: no-repeat; - margin-left: 5px; background-image: url(../../../images/active_scaffold/default/gears.png); /* default icon for actions or override with css */ } @@ -346,23 +343,31 @@ right: 150px; .active-scaffold .actions .action_group ul li { background: none repeat scroll 0 0 #EEE; -border-bottom: 1px dashed #222; +border-top: 1px dashed #222; display: block; -padding-bottom: 5px; position: relative; width: auto; z-index: 2; } -.active-scaffold .actions .action_group ul li.top { -border-top: 1px solid #005CB8; +.active-scaffold .actions .action_group ul li div { + margin: 0; + padding: 5px 5px 5px 25px; + background-position: 5px 50%; + background-repeat: no-repeat; } .active-scaffold .actions .action_group ul li a { display: block; color: #333; margin: 0; - padding: 3px 5px 3px 25px; + padding: 5px 5px 5px 25px; + background-position: 5px 50%; + background-repeat: no-repeat; +} + +.active-scaffold .actions .action_group ul li.top { +border-top: 0px solid #005CB8; } .active-scaffold .actions .action_group:hover ul ul, @@ -376,9 +381,6 @@ display: none; display: block; } - - - /* Table :: Inline Adapter ============================= */ From 051b4fc6a122ae3b95a418b24a817317eff4f74f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 20:57:39 +0100 Subject: [PATCH 0968/2024] Bugfix: do nt do_list in case of parent rendering --- lib/active_scaffold/actions/update.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 962cebf8d3..13de781c51 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -49,7 +49,7 @@ def update_respond_to_html end end def update_respond_to_js - if active_scaffold_config.update.refresh_list && successful? + if successful? && active_scaffold_config.update.refresh_list && !render_parent? do_search if respond_to? :do_search do_list end From 682217651aebb4d1a49367e8cf1f0ca32c0ec810 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 21:03:01 +0100 Subject: [PATCH 0969/2024] Bugfix: render_parent_options do a full check for nested singular associations --- lib/active_scaffold/helpers/controller_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index c410fdb6da..091015a7fd 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -55,7 +55,7 @@ def render_parent? end def render_parent_options - if nested? + if nested? && (nested.belongs_to? || nested.has_one?) {:controller => nested.parent_scaffold.controller_path, :action => :row, :id => nested.parent_id} elsif params[:parent_sti] options = {:controller => params[:parent_sti], :action => render_parent_action(params[:parent_sti])} From 835c1d305578ddbc3642e0524372b893168c7d07 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 21:05:11 +0100 Subject: [PATCH 0970/2024] sometimes render_component view helper is missing... further investigation needed --- frontends/default/views/on_update.js.rjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index e3a4584e50..5f04b87a1c 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -3,8 +3,8 @@ form_selector = "#{element_form_id(:action => :update)}" page << "var action_link = ActiveScaffold.find_action_link('#{form_selector}');" page << "action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? - if render_parent? && respond_to?(:render_component) - parent_rendered = render_component(render_parent_options) + if render_parent? && controller.respond_to?(:render_component_into_view) + parent_rendered = controller.send(:render_component_into_view, render_parent_options) if nested? page << "action_link.close('#{escape_javascript(parent_rendered)}');" else From 3a022091c053428b96e048c5d0e8092f1c985bdd Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 26 Jan 2011 21:57:08 +0100 Subject: [PATCH 0971/2024] Bugfix: check if css_class is a proc --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 9a1b785230..f0e9a33a6d 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -251,7 +251,7 @@ def column_heading_class(column, sorting) classes = [] classes << "#{column.name}-column_heading" classes << "sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column - classes << column.css_class unless column.css_class.nil? + classes << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) classes.join(' ') end From 568659104174d070510c56593c372fd3a612f1a3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 27 Jan 2011 09:48:07 +0100 Subject: [PATCH 0972/2024] Bugfix: uninitialized constant error in bridges (issue: 80 reported by korobkov) --- lib/active_scaffold/bridges/carrierwave/bridge.rb | 2 ++ lib/active_scaffold/bridges/paperclip/bridge.rb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/active_scaffold/bridges/carrierwave/bridge.rb b/lib/active_scaffold/bridges/carrierwave/bridge.rb index 84364fa70e..f746350b4d 100644 --- a/lib/active_scaffold/bridges/carrierwave/bridge.rb +++ b/lib/active_scaffold/bridges/carrierwave/bridge.rb @@ -2,6 +2,8 @@ install do require File.join(File.dirname(__FILE__), "lib/form_ui") require File.join(File.dirname(__FILE__), "lib/list_ui") + require File.join(File.dirname(__FILE__), "lib/carrierwave_bridge_helpers") + require File.join(File.dirname(__FILE__), "lib/carrierwave_bridge") ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Carrierwave::Lib::CarrierwaveBridge end end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/paperclip/bridge.rb b/lib/active_scaffold/bridges/paperclip/bridge.rb index 8c7e209064..c27af18a40 100644 --- a/lib/active_scaffold/bridges/paperclip/bridge.rb +++ b/lib/active_scaffold/bridges/paperclip/bridge.rb @@ -5,6 +5,8 @@ end require File.join(File.dirname(__FILE__), "lib/form_ui") require File.join(File.dirname(__FILE__), "lib/list_ui") + require File.join(File.dirname(__FILE__), "lib/paperclip_bridge_helpers") + require File.join(File.dirname(__FILE__), "lib/paperclip_bridge") ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Paperclip::Lib::PaperclipBridge end end \ No newline at end of file From 89fefaeac540fa1cc47a8a06602069c09b5e9d8a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 27 Jan 2011 16:33:28 +0100 Subject: [PATCH 0973/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index bec02727fb..871aef5fa8 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 8 + PATCH = 9 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 717c1b34642f75f22824f7d8bddf27c1ea2790f2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 27 Jan 2011 16:33:43 +0100 Subject: [PATCH 0974/2024] Regenerate gemspec for version 3.0.9 --- active_scaffold_vho.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index 17794d9caa..4d366f4fca 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.8" + s.version = "3.0.9" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] - s.date = %q{2011-01-26} + s.date = %q{2011-01-27} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.email = %q{activescaffold@googlegroups.com} s.extra_rdoc_files = [ From 48fd6029aabe169319344e4bee762299e7bcc392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=9A=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D0=B1=D0=BA=D0=BE=D0=B2?= <korobkov@neverbox.org> Date: Thu, 27 Jan 2011 20:54:11 +0300 Subject: [PATCH 0975/2024] Automatic recognition form_ui for :text type columns --- lib/active_scaffold/data_structures/column.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index b28bc62ded..5daaf0cb0f 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -270,6 +270,7 @@ def initialize(name, active_record_class) #:nodoc: @actions_for_association_links = self.class.actions_for_association_links.clone if @association @options = {:format => :i18n_number} if @column.try(:number?) @form_ui = :checkbox if @column and @column.type == :boolean + @form_ui = :textarea if @column and @column.type == :text @allow_add_existing = true @form_ui = self.class.association_form_ui if @association && self.class.association_form_ui From 34706786da33d7b7d990bdb526f4dc31a423c5e2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 27 Jan 2011 19:21:05 +0100 Subject: [PATCH 0976/2024] Bugfix: check if it is a nested singular assocation --- frontends/default/views/on_update.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 5f04b87a1c..d399a7a2eb 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -5,7 +5,7 @@ page << "action_link.update_flash_messages('#{escape_javascript(render(:partial if controller.send :successful? if render_parent? && controller.respond_to?(:render_component_into_view) parent_rendered = controller.send(:render_component_into_view, render_parent_options) - if nested? + if nested? && (nested.belongs_to? || nested.has_one?) page << "action_link.close('#{escape_javascript(parent_rendered)}');" else if render_parent_action == :row From dda7ab8b06f19ce8526c6a6b30021e5f5b5caf21 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 28 Jan 2011 12:12:12 +0100 Subject: [PATCH 0977/2024] Bugfix: sti edit failed if nested and parent set to refresh_list --- lib/active_scaffold/helpers/controller_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 091015a7fd..f351fd9e1c 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -60,7 +60,7 @@ def render_parent_options elsif params[:parent_sti] options = {:controller => params[:parent_sti], :action => render_parent_action(params[:parent_sti])} if render_parent_action(params[:parent_sti]) == :index - options + options.merge(params.slice(:eid)) else options.merge({:id => @record.id}) end From 229f7b8f0fe6aeac1b559b69c5fb5ab8957857d1 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 28 Jan 2011 13:06:01 +0100 Subject: [PATCH 0978/2024] Bugfix: sti create fixed in nested mode --- frontends/default/views/on_create.js.rjs | 6 +++--- lib/active_scaffold/actions/create.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index ef61685890..5fde0a8fc7 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -3,9 +3,9 @@ insert_at ||= :top page << "var action_link = ActiveScaffold.find_action_link('#{form_selector}');" page << "action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" if controller.send :successful? - if render_parent? && respond_to?(:render_component) - parent_rendered = render_component(render_parent_options) - if nested? + if render_parent? && controller.respond_to?(:render_component_into_view) + parent_rendered = controller.send(:render_component_into_view, render_parent_options) + if nested? && (nested.belongs_to? || nested.has_one?) page << "action_link.close('#{escape_javascript(parent_rendered)}');" else if render_parent_action == :row diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index d1732df345..9f6df30f9c 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -61,7 +61,7 @@ def create_respond_to_html end def create_respond_to_js - if active_scaffold_config.create.refresh_list && successful? + if successful? && active_scaffold_config.create.refresh_list && !render_parent? do_search if respond_to? :do_search do_list end From 4b0d59667037ab542a9f925ac56f805d413e2c95 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 28 Jan 2011 13:27:11 +0100 Subject: [PATCH 0979/2024] extracted method: nested_singular_association? --- frontends/default/views/on_create.js.rjs | 2 +- frontends/default/views/on_update.js.rjs | 2 +- lib/active_scaffold/helpers/controller_helpers.rb | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs index 5fde0a8fc7..73a715ecfb 100644 --- a/frontends/default/views/on_create.js.rjs +++ b/frontends/default/views/on_create.js.rjs @@ -5,7 +5,7 @@ page << "action_link.update_flash_messages('#{escape_javascript(render(:partial if controller.send :successful? if render_parent? && controller.respond_to?(:render_component_into_view) parent_rendered = controller.send(:render_component_into_view, render_parent_options) - if nested? && (nested.belongs_to? || nested.has_one?) + if nested_singular_association? page << "action_link.close('#{escape_javascript(parent_rendered)}');" else if render_parent_action == :row diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index d399a7a2eb..5460d3f073 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -5,7 +5,7 @@ page << "action_link.update_flash_messages('#{escape_javascript(render(:partial if controller.send :successful? if render_parent? && controller.respond_to?(:render_component_into_view) parent_rendered = controller.send(:render_component_into_view, render_parent_options) - if nested? && (nested.belongs_to? || nested.has_one?) + if nested_singular_association? page << "action_link.close('#{escape_javascript(parent_rendered)}');" else if render_parent_action == :row diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index f351fd9e1c..a3f5ddcea6 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Helpers module ControllerHelpers def self.included(controller) - controller.class_eval { helper_method :params_for, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action} + controller.class_eval { helper_method :params_for, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?} end include ActiveScaffold::Helpers::IdHelpers @@ -50,12 +50,16 @@ def main_path_to_return end end + def nested_singular_association? + nested? && (nested.belongs_to? || nested.has_one?) + end + def render_parent? - (nested? && (nested.belongs_to? || nested.has_one?) || params[:parent_sti]) + nested_singular_association? || params[:parent_sti] end def render_parent_options - if nested? && (nested.belongs_to? || nested.has_one?) + if nested_singular_association? {:controller => nested.parent_scaffold.controller_path, :action => :row, :id => nested.parent_id} elsif params[:parent_sti] options = {:controller => params[:parent_sti], :action => render_parent_action(params[:parent_sti])} From 5eb13f7cc730af51f9a489c740deee0cb4e88da6 Mon Sep 17 00:00:00 2001 From: jsurrett <jeff@surrett.org> Date: Fri, 28 Jan 2011 08:50:20 -0500 Subject: [PATCH 0980/2024] Fixed nested padding --- frontends/default/stylesheets/stylesheet.css | 1 - 1 file changed, 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 62e04c2b42..a40ebf9e68 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -438,7 +438,6 @@ right: 0px; .active-scaffold .active-scaffold .active-scaffold-header div.actions a, .active-scaffold .active-scaffold .active-scaffold-header div.actions div { font: bold 11px verdana, sans-serif; -padding: 0 2px 1px 17px; } .blue-theme .active-scaffold .active-scaffold-header div.actions a, From b60eeeba335a5a469d650a0398cf264feca1c618 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 28 Jan 2011 16:11:09 +0100 Subject: [PATCH 0981/2024] changed gem detection, const for plugin did nt work --- init.rb | 2 -- lib/active_scaffold.rb | 3 ++- lib/active_scaffold_vho.rb | 2 +- .../active_scaffold_setup/active_scaffold_setup_generator.rb | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/init.rb b/init.rb index a604755cac..27593a9c88 100755 --- a/init.rb +++ b/init.rb @@ -1,5 +1,3 @@ -ACTIVE_SCAFFOLD_INSTALLED = :plugin - require 'active_scaffold' begin diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 3adf0e0768..f6fb03a54a 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -336,11 +336,12 @@ def uses_active_scaffold? ## Run the install assets script, too, just to make sure ## But at least rescue the action in production ## + Rails::Application.initializer("active_scaffold.install_assets") do begin ActiveScaffoldAssets.copy_to_public(ActiveScaffold.root, {:clean_up_destination => true}) rescue raise $! unless Rails.env == 'production' end -end unless defined?(ACTIVE_SCAFFOLD_INSTALLED) && ACTIVE_SCAFFOLD_INSTALLED == :plugin +end if defined?(ACTIVE_SCAFFOLD_GEM) diff --git a/lib/active_scaffold_vho.rb b/lib/active_scaffold_vho.rb index dde7ffa6f3..73d156a604 100644 --- a/lib/active_scaffold_vho.rb +++ b/lib/active_scaffold_vho.rb @@ -1,2 +1,2 @@ -ACTIVE_SCAFFOLD_INSTALLED = :gem +ACTIVE_SCAFFOLD_GEM = true require 'active_scaffold' \ No newline at end of file diff --git a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb index b64cf28b3b..a97394d9eb 100644 --- a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +++ b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb @@ -8,7 +8,7 @@ def self.source_root end def install_plugins - unless defined?(ACTIVE_SCAFFOLD_INSTALLED) && ACTIVE_SCAFFOLD_INSTALLED == :gem + unless defined?(ACTIVE_SCAFFOLD_GEM) plugin 'verification', :git => 'git://github.com/rails/verification.git' plugin 'render_component', :git => 'git://github.com/vhochstein/render_component.git' end @@ -21,7 +21,7 @@ def install_plugins end def configure_active_scaffold - unless defined?(ACTIVE_SCAFFOLD_INSTALLED) && ACTIVE_SCAFFOLD_INSTALLED == :gem + unless defined?(ACTIVE_SCAFFOLD_GEM) if js_lib == 'jquery' gsub_file 'vendor/plugins/active_scaffold/lib/environment.rb', /#ActiveScaffold.js_framework = :jquery/, 'ActiveScaffold.js_framework = :jquery' end From 5a10726abed15aa64ac44e74adfddfd3865cc8f3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 28 Jan 2011 16:29:11 +0100 Subject: [PATCH 0982/2024] cleanup lib directory (gem best practice) --- lib/active_scaffold.rb | 7 ++- .../active_record_permissions.rb | 0 lib/{ => active_scaffold}/paginator.rb | 0 .../responds_to_parent.rb | 0 lib/dhtml_confirm.rb | 54 ------------------- lib/extensions/paginator_extensions.rb | 2 +- 6 files changed, 4 insertions(+), 59 deletions(-) rename lib/{ => active_scaffold}/active_record_permissions.rb (100%) rename lib/{ => active_scaffold}/paginator.rb (100%) rename lib/{ => active_scaffold}/responds_to_parent.rb (100%) delete mode 100644 lib/dhtml_confirm.rb diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index f6fb03a54a..b16903d0f7 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -12,10 +12,9 @@ end require 'active_scaffold_assets' -require 'active_record_permissions' -require 'dhtml_confirm' -require 'paginator' -require 'responds_to_parent' +require 'active_scaffold/active_record_permissions' +require 'active_scaffold/paginator' +require 'active_scaffold/responds_to_parent' require 'active_scaffold/version' diff --git a/lib/active_record_permissions.rb b/lib/active_scaffold/active_record_permissions.rb similarity index 100% rename from lib/active_record_permissions.rb rename to lib/active_scaffold/active_record_permissions.rb diff --git a/lib/paginator.rb b/lib/active_scaffold/paginator.rb similarity index 100% rename from lib/paginator.rb rename to lib/active_scaffold/paginator.rb diff --git a/lib/responds_to_parent.rb b/lib/active_scaffold/responds_to_parent.rb similarity index 100% rename from lib/responds_to_parent.rb rename to lib/active_scaffold/responds_to_parent.rb diff --git a/lib/dhtml_confirm.rb b/lib/dhtml_confirm.rb deleted file mode 100644 index b9a4b0d51d..0000000000 --- a/lib/dhtml_confirm.rb +++ /dev/null @@ -1,54 +0,0 @@ -# Matt Mower <matt@cominded.com> -# -# A base class for creating DHTML confirmation types. -# -# The real work is done by the onclick_function and onclick_handler methods. In -# general it should only be required to override the default onclick_handler -# method and provide the specific Javascript required to invoke the DHTML confirm -# dialog of your choice. -# -# It is up to this dialog, if the user confirms the intended action, to invoke -# the function window.gFireModalLink() to trigger the intended action of the link. -# For example, using the Modalbox library, you would use something like: -# -# Modalbox.hide( { -# afterHide: function() { -# window.gFireModalLink(); -# } } ); -# -# By default the only action recognized is :value which is used to add a -# dhtml_confirm attribute to the link <a> tag. This value is detected by the -# ActiveScaffold link and triggers the DHTML confirmation logic. -# -class DHTMLConfirm - attr_accessor :value, :message, :options - - def initialize( options = {} ) - @options = options - @value = @options.delete(:value) { |key| "yes" } - @message = @options.delete(:message) { |key| "Are you sure?" } - end - - def onclick_function( controller, link_id ) - script = <<-END -window.gFireModalLink = function() { - var link = $('#{link_id}').action_link; - link.open_action.call( link ); -}; -#{ensure_termination(onclick_handler(controller,link_id))} -return false; -END - # script = "window.gModalLink = $('#{link_id}').action_link;#{onclick_handler(controller,link_id)}return false;" - end - - def onclick_handler( controller, link_id ) - "" - end - -protected - def ensure_termination( expression ) - expression =~ /;$/ ? expression : "#{expression};" - end - -end - diff --git a/lib/extensions/paginator_extensions.rb b/lib/extensions/paginator_extensions.rb index 63ebb651ef..153030ecb2 100644 --- a/lib/extensions/paginator_extensions.rb +++ b/lib/extensions/paginator_extensions.rb @@ -1,4 +1,4 @@ -require 'paginator' +require 'active_scaffold/paginator' class Paginator From 10febd5d82358971a47952a6d8b4a69160a31929 Mon Sep 17 00:00:00 2001 From: Mike Leone <michael.leone@panopticdev.com> Date: Fri, 28 Jan 2011 15:58:00 -0500 Subject: [PATCH 0983/2024] Ensure hide/show buttons don't bring you to top of the page. return false for the toggler click callback functions so they don't bring you to the top of the page. --- frontends/default/javascripts/jquery/active_scaffold.js | 1 + frontends/default/javascripts/prototype/active_scaffold.js | 1 + 2 files changed, 2 insertions(+) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index f5aa9eb2e3..c4809e0c44 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -632,6 +632,7 @@ var ActiveScaffold = { toggler.children('a').click(function() { toggable.toggle(); $(this).html((toggable.is(':hidden')) ? options.show_label : options.hide_label); + return false; }); }, diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 686aa25629..cce54a4757 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -512,6 +512,7 @@ var ActiveScaffold = { var element = event.element(); toggable.toggle(); element.innerHTML = (toggable.style.display == 'none') ? options.show_label : options.hide_label; + return false; }); }, From 951c7958d861c76824a563b7e521a123c7ac66c0 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 29 Jan 2011 12:42:19 +0100 Subject: [PATCH 0984/2024] Bugfix: partial fix for destroy in sti mode --- frontends/default/views/destroy.js.rjs | 11 ++++++++++- lib/active_scaffold/actions/delete.rb | 2 +- lib/active_scaffold/helpers/controller_helpers.rb | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/destroy.js.rjs b/frontends/default/views/destroy.js.rjs index 485e7d3062..ebdaedcc68 100644 --- a/frontends/default/views/destroy.js.rjs +++ b/frontends/default/views/destroy.js.rjs @@ -1,5 +1,14 @@ if controller.send(:successful?) - if (active_scaffold_config.delete.refresh_list) + if render_parent? && controller.respond_to?(:render_component_into_view) + parent_rendered = controller.send(:render_component_into_view, render_parent_options) + if render_parent_action == :row + # TODO: That s not working with delete.... + page << "action_link.close('#{escape_javascript(parent_rendered)}');" + elsif render_parent_action == :index + page << parent_rendered + end + #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} + elsif (active_scaffold_config.delete.refresh_list) page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) else page << "ActiveScaffold.delete_record_row('#{element_row_id(:action => 'list', :id => params[:id])}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index d47df1370c..ae815c36ac 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -23,7 +23,7 @@ def destroy_respond_to_html end def destroy_respond_to_js - if active_scaffold_config.delete.refresh_list && successful? + if successful? && active_scaffold_config.delete.refresh_list && !render_parent? do_search if respond_to? :do_search do_list end diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index a3f5ddcea6..8f4ed4d597 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -77,6 +77,7 @@ def render_parent_action(controller_path = nil) parent_controller = "#{controller_path.to_s.camelize}Controller".constantize @parent_action = :index if action_name == 'create' && parent_controller.active_scaffold_config.actions.include?(:create) && parent_controller.active_scaffold_config.create.refresh_list == true @parent_action = :index if action_name == 'update' && parent_controller.active_scaffold_config.actions.include?(:update) && parent_controller.active_scaffold_config.update.refresh_list == true + @parent_action = :index if action_name == 'destroy' && parent_controller.active_scaffold_config.actions.include?(:delete) && parent_controller.active_scaffold_config.delete.refresh_list == true rescue ActiveScaffold::ControllerNotFound end if @parent_action.nil? @parent_action From 2d1bee01972bb824d516d7f90fa4e8b3a9ae3c5f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 29 Jan 2011 13:22:26 +0100 Subject: [PATCH 0985/2024] add method to delete an action_group --- lib/active_scaffold/data_structures/action_links.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 0a07166c86..464888c068 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -71,11 +71,21 @@ def find_duplicate(link) def delete(val) self.each({:include_set => true}) do |link, set| if link.action == val.to_s - set.delete_if {|item|item.action == val.to_s} + set.delete_if {|item| item.is_a?(ActiveScaffold::DataStructures::ActionLink) && item.action == val.to_s} end end end + def delete_group(name) + @set.each do |group| + if group.name == name + @set.delete_if {|item| item.is_a?(ActiveScaffold::DataStructures::ActionLinks) && item.name == name} + else + group.delete_group(name) + end if group.is_a?(ActiveScaffold::DataStructures::ActionLinks) + end + end + # iterates over the links, possibly by type def each(options = {}, &block) @set.each {|item| From 4301a9a4cb59109170ea18f43bb6d4b53615b003 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 31 Jan 2011 09:14:39 +0100 Subject: [PATCH 0986/2024] visualize that an record action link is disabled --- frontends/default/stylesheets/stylesheet.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index a40ebf9e68..c3d087f316 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -312,6 +312,11 @@ line-height: 16px; white-space: nowrap; } +.active-scaffold tr.record td.actions a.disabled { +color: #666; +opacity: 0.5; +} + .active-scaffold .actions .action_group div:hover { background-color: #ff8; } From f07d0fc348d73cb2691a87e818adf24f937fbfa3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 31 Jan 2011 10:05:22 +0100 Subject: [PATCH 0987/2024] bugfix: destroy working in sti mode --- frontends/default/views/destroy.js.rjs | 9 ++++++--- lib/active_scaffold/helpers/id_helpers.rb | 10 +++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/frontends/default/views/destroy.js.rjs b/frontends/default/views/destroy.js.rjs index ebdaedcc68..254f1e55b0 100644 --- a/frontends/default/views/destroy.js.rjs +++ b/frontends/default/views/destroy.js.rjs @@ -1,10 +1,13 @@ +messages_id = active_scaffold_messages_id if controller.send(:successful?) if render_parent? && controller.respond_to?(:render_component_into_view) - parent_rendered = controller.send(:render_component_into_view, render_parent_options) + render_parent_options if render_parent_action == :row # TODO: That s not working with delete.... - page << "action_link.close('#{escape_javascript(parent_rendered)}');" + page << "ActiveScaffold.delete_record_row('#{element_row_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}", :action => 'list', :id => params[:id])}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" + messages_id = active_scaffold_messages_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}") elsif render_parent_action == :index + parent_rendered = controller.send(:render_component_into_view, render_parent_options) page << parent_rendered end #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} @@ -17,4 +20,4 @@ if controller.send(:successful?) else flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) end -page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages') +page.call 'ActiveScaffold.replace_html', messages_id, render(:partial => 'messages') diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index d2f3e9404b..99c6110643 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -6,8 +6,8 @@ def id_from_controller(controller) controller.to_s.gsub("/", "__") end - def controller_id - controller_id ||= 'as_' + id_from_controller(params[:eid] || params[:parent_controller] || params[:controller]) + def controller_id(controller = (params[:eid] || params[:parent_controller] || params[:controller])) + controller_id ||= 'as_' + id_from_controller(controller) end def active_scaffold_id @@ -22,8 +22,8 @@ def active_scaffold_tbody_id "#{controller_id}-tbody" end - def active_scaffold_messages_id - "#{controller_id}-messages" + def active_scaffold_messages_id(options = {}) + "#{options[:controller_id] || controller_id}-messages" end def active_scaffold_calculations_id(column = nil) @@ -59,7 +59,7 @@ def element_row_id(options = {}) options[:action] ||= params[:action] options[:id] ||= params[:id] options[:id] ||= params[:parent_id] - clean_id "#{controller_id}-#{options[:action]}-#{options[:id]}-row" + clean_id "#{options[:controller_id] || controller_id}-#{options[:action]}-#{options[:id]}-row" end def element_cell_id(options = {}) From 7f4a576877ab0dde30dc2d1659b3e4e86000fb95 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 31 Jan 2011 10:10:33 +0100 Subject: [PATCH 0988/2024] Bugfix: prototype striping records after delete row --- frontends/default/javascripts/prototype/active_scaffold.js | 1 + 1 file changed, 1 insertion(+) diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index cce54a4757..1204c5c896 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -445,6 +445,7 @@ var ActiveScaffold = { } } row.remove(); + tbody = $(tbody); this.stripe(tbody); this.decrement_record_count(tbody.up('div.active-scaffold')); this.reload_if_empty(tbody, page_reload_url); From 7e6b00bae3dc9332be508b78ae3dcb30e6aa1fd8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 31 Jan 2011 19:19:35 +0100 Subject: [PATCH 0989/2024] Bugfix: remove default ordering if order clause is specified --- lib/active_scaffold/finder.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 3cf604bed9..496344bb5c 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -292,6 +292,7 @@ def find_page(options = {}) def append_to_query(query, options) options.assert_valid_keys :where, :select, :group, :order, :limit, :offset, :joins, :includes, :lock, :readonly, :from options.reject{|k, v| v.blank?}.inject(query) do |query, (k, v)| + query = query.except(:order) if k.to_sym == :order query.send((k.to_sym), v) end end From e59e4f983b638d7e3073a14daa7e1d10c9e1279d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 1 Feb 2011 09:03:44 +0100 Subject: [PATCH 0990/2024] Bugfix: calendar_date_select additional js and css resources have to use alias_method_chain --- .../calendar_date_select/lib/as_cds_bridge.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb index b79ef8c8d9..e91c062088 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb @@ -49,14 +49,18 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current end module ViewHelpers + def self.included(base) + base.alias_method_chain :active_scaffold_stylesheets, :calendar_date_select + base.alias_method_chain :active_scaffold_javascripts, :calendar_date_select + end # Provides stylesheets to include with +stylesheet_link_tag+ - def active_scaffold_stylesheets(frontend = :default) - super + [calendar_date_select_stylesheets] + def active_scaffold_stylesheets_with_calendar_date_select(frontend = :default) + active_scaffold_stylesheets_without_calendar_date_select + [calendar_date_select_stylesheets] end # Provides stylesheets to include with +stylesheet_link_tag+ - def active_scaffold_javascripts(frontend = :default) - super + [calendar_date_select_javascripts] + def active_scaffold_javascripts_with_calendar_date_select(frontend = :default) + active_scaffold_javascripts_without_calendar_date_select + [calendar_date_select_javascripts] end end end From 9456c30bf2849c2e8b55d2e0300cda22d55dc203 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 1 Feb 2011 09:09:04 +0100 Subject: [PATCH 0991/2024] environment.rb is in global load_path for gem... rename it to a more specific name --- lib/active_scaffold.rb | 2 +- lib/{environment.rb => active_scaffold_env.rb} | 0 .../active_scaffold_setup/active_scaffold_setup_generator.rb | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename lib/{environment.rb => active_scaffold_env.rb} (100%) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index b16903d0f7..362325a22b 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -329,7 +329,7 @@ def uses_active_scaffold? end end -require 'environment' +require 'active_scaffold_env' ## ## Run the install assets script, too, just to make sure diff --git a/lib/environment.rb b/lib/active_scaffold_env.rb similarity index 100% rename from lib/environment.rb rename to lib/active_scaffold_env.rb diff --git a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb index a97394d9eb..014bcc0451 100644 --- a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +++ b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb @@ -23,7 +23,7 @@ def install_plugins def configure_active_scaffold unless defined?(ACTIVE_SCAFFOLD_GEM) if js_lib == 'jquery' - gsub_file 'vendor/plugins/active_scaffold/lib/environment.rb', /#ActiveScaffold.js_framework = :jquery/, 'ActiveScaffold.js_framework = :jquery' + gsub_file 'vendor/plugins/active_scaffold/lib/active_scaffold_env.rb', /#ActiveScaffold.js_framework = :jquery/, 'ActiveScaffold.js_framework = :jquery' end else if js_lib == 'jquery' From ef9e5c735408ed72b2798dc59da165db1ad373b7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 1 Feb 2011 09:11:09 +0100 Subject: [PATCH 0992/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 871aef5fa8..2f5a71313d 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 9 + PATCH = 10 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From d3dd5cd45b327811de166dadac2e0393341e05fb Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 1 Feb 2011 09:12:13 +0100 Subject: [PATCH 0993/2024] Regenerate gemspec for version 3.0.10 --- active_scaffold_vho.gemspec | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index 4d366f4fca..c274da418a 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.9" + s.version = "3.0.10" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] - s.date = %q{2011-01-27} + s.date = %q{2011-02-01} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.email = %q{activescaffold@googlegroups.com} s.extra_rdoc_files = [ @@ -102,7 +102,6 @@ Gem::Specification.new do |s| "frontends/default/views/update_column.js.rjs", "frontends/default/views/update_row.js.rjs", "init.rb", - "lib/active_record_permissions.rb", "lib/active_scaffold.rb", "lib/active_scaffold/actions/common_search.rb", "lib/active_scaffold/actions/core.rb", @@ -116,6 +115,7 @@ Gem::Specification.new do |s| "lib/active_scaffold/actions/show.rb", "lib/active_scaffold/actions/subform.rb", "lib/active_scaffold/actions/update.rb", + "lib/active_scaffold/active_record_permissions.rb", "lib/active_scaffold/attribute_params.rb", "lib/active_scaffold/bridges/ancestry/bridge.rb", "lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb", @@ -195,11 +195,12 @@ Gem::Specification.new do |s| "lib/active_scaffold/locale/ja.yml", "lib/active_scaffold/locale/ru.yml", "lib/active_scaffold/marked_model.rb", + "lib/active_scaffold/paginator.rb", + "lib/active_scaffold/responds_to_parent.rb", "lib/active_scaffold/version.rb", "lib/active_scaffold_assets.rb", + "lib/active_scaffold_env.rb", "lib/active_scaffold_vho.rb", - "lib/dhtml_confirm.rb", - "lib/environment.rb", "lib/extensions/action_controller_rendering.rb", "lib/extensions/action_view_rendering.rb", "lib/extensions/action_view_resolver.rb", @@ -223,8 +224,6 @@ Gem::Specification.new do |s| "lib/generators/active_scaffold_controller/templates/controller.rb", "lib/generators/active_scaffold_setup/USAGE", "lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb", - "lib/paginator.rb", - "lib/responds_to_parent.rb", "public/blank.html", "shoulda_macros/macros.rb", "test/bridges/bridge_test.rb", From d0538de6d3b49c3116e1511b061c9fca43ce978f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 1 Feb 2011 11:52:38 +0100 Subject: [PATCH 0994/2024] remove deprecation for link_to and option popup --- lib/active_scaffold/bridges/paperclip/lib/list_ui.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb b/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb index aa71b79847..0d77026c88 100644 --- a/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +++ b/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb @@ -9,7 +9,7 @@ def active_scaffold_column_paperclip(column, record) else paperclip.original_filename end - link_to(content, paperclip.url, :popup => true) + link_to(content, paperclip.url, {'data-popup' => true, :target => '_blank'}) end end end From facac1491e7ccb7d65512aec47344ed22c11ca2f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 1 Feb 2011 19:40:07 +0100 Subject: [PATCH 0995/2024] do not use render_component call... does nt seem to be available always.. reason still unknown --- lib/active_scaffold/helpers/list_column_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 89db7f5d60..23d1da43e2 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -346,10 +346,10 @@ def column_heading_value(column, sorting, sort_direction) def render_nested_view(action_links, url_options, record) rendered = [] action_links.member.each do |link| - if link.nested_link? && link.column && @nested_auto_open[link.column.name] && @records.length <= @nested_auto_open[link.column.name] && respond_to?(:render_component) + if link.nested_link? && link.column && @nested_auto_open[link.column.name] && @records.length <= @nested_auto_open[link.column.name] && controller.respond_to?(:render_component_into_view) link_url_options = {:adapter => '_list_inline_adapter', :format => :js}.merge(action_link_url_options(link, url_options, record, options = {:reuse_eid => true})) link_id = get_action_link_id(link_url_options, record, link.column) - rendered << (render_component(link_url_options) + javascript_tag("ActiveScaffold.ActionLink.get('#{link_id}').set_opened();")) + rendered << (controller.send(:render_component_into_view, link_url_options) + javascript_tag("ActiveScaffold.ActionLink.get('#{link_id}').set_opened();")) end end rendered.join(' ').html_safe From 2a4ced2bfa7e19e9ce99e50727346ee14161900e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 2 Feb 2011 13:57:17 +0100 Subject: [PATCH 0996/2024] move extension dir into active_scaffold dir to avoid name clashes --- .../extensions/action_controller_rendering.rb | 1 + lib/{ => active_scaffold}/extensions/action_view_rendering.rb | 0 lib/{ => active_scaffold}/extensions/action_view_resolver.rb | 0 .../extensions/active_association_reflection.rb | 0 lib/{ => active_scaffold}/extensions/active_record_offset.rb | 0 lib/{ => active_scaffold}/extensions/array.rb | 0 lib/{ => active_scaffold}/extensions/localize.rb | 0 .../extensions/name_option_for_datetime.rb | 0 lib/{ => active_scaffold}/extensions/nil_id_in_url_params.rb | 0 lib/{ => active_scaffold}/extensions/paginator_extensions.rb | 0 lib/{ => active_scaffold}/extensions/reverse_associations.rb | 0 lib/{ => active_scaffold}/extensions/routing_mapper.rb | 0 lib/{ => active_scaffold}/extensions/to_label.rb | 0 lib/{ => active_scaffold}/extensions/unsaved_associated.rb | 0 lib/{ => active_scaffold}/extensions/unsaved_record.rb | 0 lib/{ => active_scaffold}/extensions/usa_state.rb | 0 lib/active_scaffold_env.rb | 2 +- 17 files changed, 2 insertions(+), 1 deletion(-) rename lib/{ => active_scaffold}/extensions/action_controller_rendering.rb (97%) rename lib/{ => active_scaffold}/extensions/action_view_rendering.rb (100%) rename lib/{ => active_scaffold}/extensions/action_view_resolver.rb (100%) rename lib/{ => active_scaffold}/extensions/active_association_reflection.rb (100%) rename lib/{ => active_scaffold}/extensions/active_record_offset.rb (100%) rename lib/{ => active_scaffold}/extensions/array.rb (100%) rename lib/{ => active_scaffold}/extensions/localize.rb (100%) rename lib/{ => active_scaffold}/extensions/name_option_for_datetime.rb (100%) rename lib/{ => active_scaffold}/extensions/nil_id_in_url_params.rb (100%) rename lib/{ => active_scaffold}/extensions/paginator_extensions.rb (100%) rename lib/{ => active_scaffold}/extensions/reverse_associations.rb (100%) rename lib/{ => active_scaffold}/extensions/routing_mapper.rb (100%) rename lib/{ => active_scaffold}/extensions/to_label.rb (100%) rename lib/{ => active_scaffold}/extensions/unsaved_associated.rb (100%) rename lib/{ => active_scaffold}/extensions/unsaved_record.rb (100%) rename lib/{ => active_scaffold}/extensions/usa_state.rb (100%) diff --git a/lib/extensions/action_controller_rendering.rb b/lib/active_scaffold/extensions/action_controller_rendering.rb similarity index 97% rename from lib/extensions/action_controller_rendering.rb rename to lib/active_scaffold/extensions/action_controller_rendering.rb index 2264ab5a1d..c8e2a4169d 100644 --- a/lib/extensions/action_controller_rendering.rb +++ b/lib/active_scaffold/extensions/action_controller_rendering.rb @@ -1,3 +1,4 @@ +puts "juhu was called" # wrap the action rendering for ActiveScaffold controllers module ActionController #:nodoc: class Base diff --git a/lib/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb similarity index 100% rename from lib/extensions/action_view_rendering.rb rename to lib/active_scaffold/extensions/action_view_rendering.rb diff --git a/lib/extensions/action_view_resolver.rb b/lib/active_scaffold/extensions/action_view_resolver.rb similarity index 100% rename from lib/extensions/action_view_resolver.rb rename to lib/active_scaffold/extensions/action_view_resolver.rb diff --git a/lib/extensions/active_association_reflection.rb b/lib/active_scaffold/extensions/active_association_reflection.rb similarity index 100% rename from lib/extensions/active_association_reflection.rb rename to lib/active_scaffold/extensions/active_association_reflection.rb diff --git a/lib/extensions/active_record_offset.rb b/lib/active_scaffold/extensions/active_record_offset.rb similarity index 100% rename from lib/extensions/active_record_offset.rb rename to lib/active_scaffold/extensions/active_record_offset.rb diff --git a/lib/extensions/array.rb b/lib/active_scaffold/extensions/array.rb similarity index 100% rename from lib/extensions/array.rb rename to lib/active_scaffold/extensions/array.rb diff --git a/lib/extensions/localize.rb b/lib/active_scaffold/extensions/localize.rb similarity index 100% rename from lib/extensions/localize.rb rename to lib/active_scaffold/extensions/localize.rb diff --git a/lib/extensions/name_option_for_datetime.rb b/lib/active_scaffold/extensions/name_option_for_datetime.rb similarity index 100% rename from lib/extensions/name_option_for_datetime.rb rename to lib/active_scaffold/extensions/name_option_for_datetime.rb diff --git a/lib/extensions/nil_id_in_url_params.rb b/lib/active_scaffold/extensions/nil_id_in_url_params.rb similarity index 100% rename from lib/extensions/nil_id_in_url_params.rb rename to lib/active_scaffold/extensions/nil_id_in_url_params.rb diff --git a/lib/extensions/paginator_extensions.rb b/lib/active_scaffold/extensions/paginator_extensions.rb similarity index 100% rename from lib/extensions/paginator_extensions.rb rename to lib/active_scaffold/extensions/paginator_extensions.rb diff --git a/lib/extensions/reverse_associations.rb b/lib/active_scaffold/extensions/reverse_associations.rb similarity index 100% rename from lib/extensions/reverse_associations.rb rename to lib/active_scaffold/extensions/reverse_associations.rb diff --git a/lib/extensions/routing_mapper.rb b/lib/active_scaffold/extensions/routing_mapper.rb similarity index 100% rename from lib/extensions/routing_mapper.rb rename to lib/active_scaffold/extensions/routing_mapper.rb diff --git a/lib/extensions/to_label.rb b/lib/active_scaffold/extensions/to_label.rb similarity index 100% rename from lib/extensions/to_label.rb rename to lib/active_scaffold/extensions/to_label.rb diff --git a/lib/extensions/unsaved_associated.rb b/lib/active_scaffold/extensions/unsaved_associated.rb similarity index 100% rename from lib/extensions/unsaved_associated.rb rename to lib/active_scaffold/extensions/unsaved_associated.rb diff --git a/lib/extensions/unsaved_record.rb b/lib/active_scaffold/extensions/unsaved_record.rb similarity index 100% rename from lib/extensions/unsaved_record.rb rename to lib/active_scaffold/extensions/unsaved_record.rb diff --git a/lib/extensions/usa_state.rb b/lib/active_scaffold/extensions/usa_state.rb similarity index 100% rename from lib/extensions/usa_state.rb rename to lib/active_scaffold/extensions/usa_state.rb diff --git a/lib/active_scaffold_env.rb b/lib/active_scaffold_env.rb index f1dd02cc92..0cbe23603e 100644 --- a/lib/active_scaffold_env.rb +++ b/lib/active_scaffold_env.rb @@ -1,5 +1,5 @@ # TODO: clean up extensions. some could be organized for autoloading, and others could be removed entirely. -Dir["#{File.dirname __FILE__}/extensions/*.rb"].each { |file| require file } +Dir["#{File.dirname __FILE__}/active_scaffold/extensions/*.rb"].each { |file| require file } ActionController::Base.send(:include, ActiveScaffold) ActionController::Base.send(:include, RespondsToParent) From edbb4f8b5455bff2df9aef2aadbe9f36f26dc65c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 2 Feb 2011 13:59:08 +0100 Subject: [PATCH 0997/2024] remove debug code --- lib/active_scaffold/extensions/action_controller_rendering.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_controller_rendering.rb b/lib/active_scaffold/extensions/action_controller_rendering.rb index c8e2a4169d..2264ab5a1d 100644 --- a/lib/active_scaffold/extensions/action_controller_rendering.rb +++ b/lib/active_scaffold/extensions/action_controller_rendering.rb @@ -1,4 +1,3 @@ -puts "juhu was called" # wrap the action rendering for ActiveScaffold controllers module ActionController #:nodoc: class Base From 91aac46328f2766195072cd93256f4b43382fbdf Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 2 Feb 2011 15:46:41 +0100 Subject: [PATCH 0998/2024] Bugfix: other partials may be called in super partial (issue 86 reported by clyfe) --- .../extensions/action_view_rendering.rb | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 87fdf7790d..1b2c25d0d4 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -38,15 +38,19 @@ module ActionView::Rendering #:nodoc: # def render_with_active_scaffold(*args, &block) if args.first == :super + last_view = @view_stack.last options = args[1] || {} options[:locals] ||= {} - options[:locals].reverse_merge!(@last_view[:locals] || {}) - if @last_view[:templates].nil? - @last_view[:templates] = lookup_context.find_all_templates(@last_view[:view], controller_path, !@last_view[:is_template]) - @last_view[:templates].shift + options[:locals].reverse_merge!(last_view[:locals] || {}) + if last_view[:templates].nil? + last_view[:templates] = lookup_context.find_all_templates(last_view[:view], controller_path, !last_view[:is_template]) + last_view[:templates].shift end - options[:template] = @last_view[:templates].shift - render_without_active_scaffold options + options[:template] = last_view[:templates].shift + @view_stack << last_view + result = render_without_active_scaffold options + @view_stack.pop + result elsif args.first.is_a?(Hash) and args.first[:active_scaffold] require 'digest/md5' options = args.first @@ -79,11 +83,17 @@ def render_with_active_scaffold(*args, &block) else options = args.first if options.is_a?(Hash) - @last_view = {:view => options[:partial], :is_template => false} if options[:partial] - @last_view = {:view => options[:template], :is_template => !!options[:template]} if @last_view.nil? && options[:template] - @last_view[:locals] = options[:locals] if !@last_view.nil? && options[:locals] + current_view = {:view => options[:partial], :is_template => false} if options[:partial] + current_view = {:view => options[:template], :is_template => !!options[:template]} if current_view.nil? && options[:template] + current_view[:locals] = options[:locals] if !current_view.nil? && options[:locals] + if current_view.present? + @view_stack ||= [] + @view_stack << current_view + end end - render_without_active_scaffold(*args, &block) + result = render_without_active_scaffold(*args, &block) + @view_stack.pop if current_view.present? + result end end alias_method_chain :render, :active_scaffold From 9fd1ded364bed64a05102cae88f6b9a49210c5dc Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 3 Feb 2011 08:17:06 +0100 Subject: [PATCH 0999/2024] CarrierWaveBridge: support for caching (experimental) --- .../bridges/carrierwave/lib/carrierwave_bridge.rb | 1 + lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb index 9b9ba34213..b27f28cc40 100644 --- a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +++ b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb @@ -25,6 +25,7 @@ def self.included(base) def configure_carrierwave_field(field) self.columns << field self.columns[field].form_ui ||= :carrierwave + self.columns[field].params.add "#{field}_cache" self.columns[field].params.add "delete_#{field}" # [:file_name, :content_type, :file_size, :updated_at].each do |f| diff --git a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb index 4f4fe26bf0..1455d91540 100644 --- a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +++ b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb @@ -22,7 +22,8 @@ def active_scaffold_input_carrierwave(column, options) content_tag(:div, ( get_column_value(@record, column) + " | " + hidden_field(:record, "delete_#{column.name}", hidden_field_options) + - content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}) + content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}) + + hidden_field(:record, "#{column.name}_cache", {:name => options[:name].gsub(/\[#{column.name}\]$/, "[#{column.name}_cache]")}) ).html_safe ) + content_tag(:div, input, :style => "display: none") ) From 4a664b6b179cf9a5573c99a10fded22dc45b0ea2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 3 Feb 2011 14:36:20 +0100 Subject: [PATCH 1000/2024] updated README --- README | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README b/README index c0a2611778..2fa98dc4a3 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ ** For all documentation see the project website: http://github.com/vhochstein/active_scaffold/wiki ** ****************************************************************************************************** -ActiveScaffold plugin by Scott Rutherford (scott@caronsoftware.com), Richard White (rrwhite@gmail.com), Lance Ivy (lance@cainlevy.net), Ed Moss, Tim Harper and Sergio Cambra (sergio@entrecables.com) +ActiveScaffold Gem/Plugin by Scott Rutherford (scott@caronsoftware.com), Richard White (rrwhite@gmail.com), Lance Ivy (lance@cainlevy.net), Ed Moss, Tim Harper and Sergio Cambra (sergio@entrecables.com) Uses DhtmlHistory by Brad Neuberg (bkn3@columbia.edu) http://codinginparadise.org @@ -40,7 +40,10 @@ If you want to install as plugins under vendor/plugins, install these versions: rails plugin install git://github.com/vhochstein/active_scaffold.git If you want to use the gem, add to your Gemfile: - gem "active_scaffold" + gem "active_scaffold_vho" + +In case you would like to use most recent commit: + gem 'active_scaffold_vho', :git => 'git://github.com/vhochstein/active_scaffold.git' == Pick your own javascript framework @@ -50,11 +53,11 @@ Out of the box Prototype or JQuery are supported: Prototype 1.7 (default js framework) rails.js in git://github.com/vhochstein/prototype-ujs.git -JQuery 1.4.1 +JQuery 1.4.1, 1.4.2 rails.js in git://github.com/vhochstein/jquery-ujs.git To configure the javascript framework when installed under vendor/plugins/ -uncomment last line in ...plugins/active_scaffold/environment.rb in order to use jquery instead of prototype +uncomment last line in ...plugins/active_scaffold/lib/active_scaffold_env.rb in order to use jquery instead of prototype To configure the javascript framework when installed as a gem: Add a config/initializers/active_scaffold.rb containing: From c1819e62e9d06ed0a15d221813403f9ebed7393a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 3 Feb 2011 16:47:37 +0100 Subject: [PATCH 1001/2024] Bugfix: show yellow background for inplace editable values again --- frontends/default/stylesheets/stylesheet.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index c3d087f316..e8fe3d49fa 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -35,7 +35,7 @@ text-decoration: none; color: #999; } -.active-scaffold a:hover, .active-scaffold div.hover { +.active-scaffold a:hover, .active-scaffold div.hover, .active-scaffold td span.hover { background-color: #ff8; } From ff240cb22d6e6639533d2f68b4d063fa8a32964d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 3 Feb 2011 17:09:46 +0100 Subject: [PATCH 1002/2024] added jquery 1.4.4 support --- README | 5 ++++- .../active_scaffold_setup_generator.rb | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README b/README index 2fa98dc4a3..ea87ab8e4c 100644 --- a/README +++ b/README @@ -54,7 +54,10 @@ Prototype 1.7 (default js framework) rails.js in git://github.com/vhochstein/prototype-ujs.git JQuery 1.4.1, 1.4.2 -rails.js in git://github.com/vhochstein/jquery-ujs.git +https://github.com/vhochstein/jquery-ujs/raw/jquery1_4_2/src/rails.js + +JQuery > 1.4.2 +https://github.com/vhochstein/jquery-ujs/raw/master/src/rails.js To configure the javascript framework when installed under vendor/plugins/ uncomment last line in ...plugins/active_scaffold/lib/active_scaffold_env.rb in order to use jquery instead of prototype diff --git a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb index 014bcc0451..3c4e48d464 100644 --- a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +++ b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb @@ -39,10 +39,10 @@ def configure_application_layout :after => "<%= javascript_include_tag :defaults %>\n" elsif js_lib == 'jquery' inject_into_file "app/views/layouts/application.html.erb", -" <%= stylesheet_link_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/ui-lightness/jquery-ui.css' %> - <%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js' %> +" <%= stylesheet_link_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/ui-lightness/jquery-ui.css' %> + <%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js' %> <%= javascript_include_tag 'rails_jquery.js' %> - <%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.js' %> + <%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js' %> <%= javascript_include_tag 'jquery-ui-timepicker-addon.js' %> <%= javascript_include_tag 'application.js' %> <%= active_scaffold_includes %>\n", From 761b6dfad3341751d45093bfabfe223067e761ef Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 3 Feb 2011 17:11:39 +0100 Subject: [PATCH 1003/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 2f5a71313d..d68cb86615 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 10 + PATCH = 11 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 9162f3b5c4c566b9019320788a1834382c91a0a4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 3 Feb 2011 17:11:49 +0100 Subject: [PATCH 1004/2024] Regenerate gemspec for version 3.0.11 --- active_scaffold_vho.gemspec | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index c274da418a..bdb92ef1ad 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.10" + s.version = "3.0.11" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] - s.date = %q{2011-02-01} + s.date = %q{2011-02-03} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.email = %q{activescaffold@googlegroups.com} s.extra_rdoc_files = [ @@ -175,6 +175,22 @@ Gem::Specification.new do |s| "lib/active_scaffold/data_structures/nested_info.rb", "lib/active_scaffold/data_structures/set.rb", "lib/active_scaffold/data_structures/sorting.rb", + "lib/active_scaffold/extensions/action_controller_rendering.rb", + "lib/active_scaffold/extensions/action_view_rendering.rb", + "lib/active_scaffold/extensions/action_view_resolver.rb", + "lib/active_scaffold/extensions/active_association_reflection.rb", + "lib/active_scaffold/extensions/active_record_offset.rb", + "lib/active_scaffold/extensions/array.rb", + "lib/active_scaffold/extensions/localize.rb", + "lib/active_scaffold/extensions/name_option_for_datetime.rb", + "lib/active_scaffold/extensions/nil_id_in_url_params.rb", + "lib/active_scaffold/extensions/paginator_extensions.rb", + "lib/active_scaffold/extensions/reverse_associations.rb", + "lib/active_scaffold/extensions/routing_mapper.rb", + "lib/active_scaffold/extensions/to_label.rb", + "lib/active_scaffold/extensions/unsaved_associated.rb", + "lib/active_scaffold/extensions/unsaved_record.rb", + "lib/active_scaffold/extensions/usa_state.rb", "lib/active_scaffold/finder.rb", "lib/active_scaffold/helpers/association_helpers.rb", "lib/active_scaffold/helpers/controller_helpers.rb", @@ -201,22 +217,6 @@ Gem::Specification.new do |s| "lib/active_scaffold_assets.rb", "lib/active_scaffold_env.rb", "lib/active_scaffold_vho.rb", - "lib/extensions/action_controller_rendering.rb", - "lib/extensions/action_view_rendering.rb", - "lib/extensions/action_view_resolver.rb", - "lib/extensions/active_association_reflection.rb", - "lib/extensions/active_record_offset.rb", - "lib/extensions/array.rb", - "lib/extensions/localize.rb", - "lib/extensions/name_option_for_datetime.rb", - "lib/extensions/nil_id_in_url_params.rb", - "lib/extensions/paginator_extensions.rb", - "lib/extensions/reverse_associations.rb", - "lib/extensions/routing_mapper.rb", - "lib/extensions/to_label.rb", - "lib/extensions/unsaved_associated.rb", - "lib/extensions/unsaved_record.rb", - "lib/extensions/usa_state.rb", "lib/generators/active_scaffold/USAGE", "lib/generators/active_scaffold/active_scaffold_generator.rb", "lib/generators/active_scaffold_controller/USAGE", From 1d14eafa382f32cfdba4594808d9f9a0ee107481 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 5 Feb 2011 12:26:14 +0100 Subject: [PATCH 1005/2024] refactored method date_bridge_now --- .../bridges/shared/date_bridge.rb | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index 774609222b..abec6868cc 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -108,12 +108,16 @@ def date_bridge_from_to(column, value) ['from', 'to'].collect { |field| condition_value_for_datetime(value[field], conversion)} end end + + def date_bridge_now + Time.zone.now + end def date_bridge_from_to_for_trend(column, value) case value['opt'] when "PAST" trend_number = [value['number'].to_i, 1].max - now = Time.zone.now + now = date_bridge_now if date_bridge_column_date?(column) from = now.beginning_of_day.ago((trend_number).send(value['unit'].downcase.singularize.to_sym)) to = now.end_of_day @@ -124,7 +128,7 @@ def date_bridge_from_to_for_trend(column, value) return from, to when "FUTURE" trend_number = [value['number'].to_i, 1].max - now = Time.zone.now + now = date_bridge_now if date_bridge_column_date?(column) from = now.beginning_of_day to = now.end_of_day.in((trend_number).send(value['unit'].downcase.singularize.to_sym)) @@ -139,21 +143,21 @@ def date_bridge_from_to_for_trend(column, value) def date_bridge_from_to_for_range(column, value) case value[:range] when 'TODAY' - return Time.zone.now.beginning_of_day, Time.zone.now.end_of_day + return date_bridge_now.beginning_of_day, date_bridge_now.end_of_day when 'YESTERDAY' - return Time.zone.now.ago(1.day).beginning_of_day, Time.zone.now.ago(1.day).end_of_day + return date_bridge_now.ago(1.day).beginning_of_day, date_bridge_now.ago(1.day).end_of_day when 'TOMMORROW' - return Time.zone.now.in(1.day).beginning_of_day, Time.zone.now.in(1.day).end_of_day + return date_bridge_now.in(1.day).beginning_of_day, date_bridge_now.in(1.day).end_of_day else range_type, range = value[:range].downcase.split('_') raise ArgumentError unless ['week', 'month', 'year'].include?(range) case range_type when 'this' - return Time.zone.now.send("beginning_of_#{range}".to_sym), Time.zone.now.send("end_of_#{range}") + return date_bridge_now.send("beginning_of_#{range}".to_sym), date_bridge_now.send("end_of_#{range}") when 'prev' - return Time.zone.now.ago(1.send(range.to_sym)).send("beginning_of_#{range}".to_sym), Time.zone.now.ago(1.send(range.to_sym)).send("end_of_#{range}".to_sym) + return date_bridge_now.ago(1.send(range.to_sym)).send("beginning_of_#{range}".to_sym), date_bridge_now.ago(1.send(range.to_sym)).send("end_of_#{range}".to_sym) when 'next' - return Time.zone.now.in(1.send(range.to_sym)).send("beginning_of_#{range}".to_sym), Time.zone.now.in(1.send(range.to_sym)).send("end_of_#{range}".to_sym) + return date_bridge_now.in(1.send(range.to_sym)).send("beginning_of_#{range}".to_sym), date_bridge_now.in(1.send(range.to_sym)).send("end_of_#{range}".to_sym) else return nil, nil end From 648facb2ede0b0ea94d36833fd8f3e8555206283 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 5 Feb 2011 12:59:10 +0100 Subject: [PATCH 1006/2024] Bugfix: date/time field_search trend select box show selected option --- lib/active_scaffold/bridges/shared/date_bridge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index abec6868cc..2b90ca4236 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -43,7 +43,7 @@ def active_scaffold_search_date_bridge_trend_tag(column, options, current_search def active_scaffold_date_bridge_trend_tag(column, options, trend_options) trend_controls = text_field_tag("#{trend_options[:name_prefix]}[#{column.name}][number]", trend_options[:number_value], :class => 'text-input', :size => 10, :autocomplete => 'off') << " " << select_tag("#{trend_options[:name_prefix]}[#{column.name}][unit]", - options_for_select(active_scaffold_search_date_bridge_trend_units(column), trend_options[:name_prefix]), + options_for_select(active_scaffold_search_date_bridge_trend_units(column), trend_options[:unit_value]), :class => 'text-input') content_tag("span", trend_controls.html_safe, :id => "#{options[:id]}_trend", :style => "display:#{trend_options[:show] ? '' : 'none'}") end From 827382f8a0188f160fd06b6364d7a60a73de40e2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Feb 2011 10:06:19 +0100 Subject: [PATCH 1007/2024] Bugfix: append_to_query npe if order is first element in hash --- lib/active_scaffold/finder.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 496344bb5c..6f75151dbb 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -292,7 +292,10 @@ def find_page(options = {}) def append_to_query(query, options) options.assert_valid_keys :where, :select, :group, :order, :limit, :offset, :joins, :includes, :lock, :readonly, :from options.reject{|k, v| v.blank?}.inject(query) do |query, (k, v)| - query = query.except(:order) if k.to_sym == :order + # default ordering of model has a higher priority than current queries ordering + # fix this by removing existing ordering from arel + # will not work if order part is first one which is iterated + query = query.except(:order) if k.to_sym == :order && query.is_a?(ActiveRecord::Relation) query.send((k.to_sym), v) end end From 6cf1e32fa5e79856fec5f4b8f7900409253ace0c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Feb 2011 16:52:31 +0100 Subject: [PATCH 1008/2024] Bugfix: update_columns working in subforms --- .../javascripts/jquery/active_scaffold.js | 25 +++++++++++++------ .../javascripts/prototype/active_scaffold.js | 22 ++++++++++------ frontends/default/views/_render_field.js.rjs | 7 ++---- lib/active_scaffold/actions/core.rb | 3 ++- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index c4809e0c44..dcc12dfcbb 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -214,7 +214,8 @@ $(document).ready(function() { var as_form = element.closest('form.as_form'); $.ajax({ url: element.attr('data-update_url'), - data: {value: element.val()}, + data: {value: element.val(), + source_id: element.attr('id')}, beforeSend: function(event) { element.nextAll('img.loading-indicator').css('visibility','visible'); $('input[type=submit]', as_form).attr('disabled', 'disabled'); @@ -653,13 +654,21 @@ var ActiveScaffold = { } }, - render_form_field: function(element, content, options) { - if (typeof(element) == 'string') element = '#' + element; - var element = $(element); - if (options.is_subform == false) { - this.replace(element.closest('dl'), content); - } else { - this.replace_html(element, content); + render_form_field: function(source, content, options) { + if (typeof(source) == 'string') source = '#' + source; + var source = $(source); + var element = source.closest('tr.association-record'); + if (element.length == 0) { + element = source.closest('ol.form'); + } + element = element.find('.' + options.field_class); + + if (element) { + if (options.is_subform == false) { + this.replace(element.closest('dl'), content); + } else { + this.replace_html(element, content); + } } }, diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 1204c5c896..0258b61cbc 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -238,7 +238,7 @@ document.observe("dom:loaded", function() { new Ajax.Request(element.readAttribute('data-update_url'), { method: 'get', - parameters: {value: element.getValue()}, + parameters: {value: element.getValue(), source_id: element.readAttribute('id')}, onLoading: function(response) { element.next('img.loading-indicator').style.visibility = 'visible'; as_form.disable(); @@ -533,12 +533,20 @@ var ActiveScaffold = { } }, - render_form_field: function(element, content, options) { - var element = $(element); - if (options.is_subform == false) { - this.replace(element.up('dl'), content); - } else { - this.replace_html(element, content); + render_form_field: function(source, content, options) { + var source = $(source); + var element = source.up('tr.association-record'); + if (typeof(element) === 'undefined') { + element = source.up('ol.form'); + } + element = element.down('.' + options.field_class); + + if (element) { + if (options.is_subform == false) { + this.replace(element.up('dl'), content); + } else { + this.replace_html(element, content); + } } }, diff --git a/frontends/default/views/_render_field.js.rjs b/frontends/default/views/_render_field.js.rjs index 8c60611db2..1957675baf 100644 --- a/frontends/default/views/_render_field.js.rjs +++ b/frontends/default/views/_render_field.js.rjs @@ -1,12 +1,9 @@ column = active_scaffold_config.columns[render_field.to_sym] -options = {:is_subform => false} +options = {:is_subform => false, :field_class => "#{column.name}-input"} if column_renders_as(column) == :subform options[:is_subform] = true - field_id = sub_form_id(:association => column.name) -else - field_id = active_scaffold_input_options(column, params[:scope])[:id] end -page.call 'ActiveScaffold.render_form_field', field_id, render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] }), options +page.call 'ActiveScaffold.render_form_field', source_id, render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] }), options render(:partial => "render_field", :collection => column.update_columns) if column.update_columns && !column.update_columns.empty? diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index fbb2cf7f33..3fd538f700 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -34,7 +34,8 @@ def render_field_for_update_columns value = column_value_from_param_value(@record, column, params[:value]) @record.send "#{column.name}=", value after_render_field(@record, column) - render :partial => "render_field", :collection => Array(params[:update_columns]), :content_type => 'text/javascript' + source_id = params.delete(:source_id) + render :partial => "render_field", :collection => Array(params[:update_columns]), :content_type => 'text/javascript', :locals => {:source_id => source_id} end end From be37ec57538e3b96778ba287aa1b3b5787292316 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 8 Feb 2011 09:24:32 +0100 Subject: [PATCH 1009/2024] move errors inside ol in vertical subform layout --- frontends/default/views/_vertical_subform.html.erb | 5 ----- frontends/default/views/_vertical_subform_record.html.erb | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/_vertical_subform.html.erb b/frontends/default/views/_vertical_subform.html.erb index eb374c1924..464c1512af 100644 --- a/frontends/default/views/_vertical_subform.html.erb +++ b/frontends/default/views/_vertical_subform.html.erb @@ -1,11 +1,6 @@ <div id="<%= sub_form_list_id(:association => column.name) %>"> <% associated.each_index do |index| %> <% @record = associated[index] -%> - <% if @record.errors.count -%> - <div class="association-record-errors" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>"> - <%= error_messages_for :record, :object_name => @record.class.human_name.downcase %> - </div> - <% end %> <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => @record == locked} %> <% end -%> </div> diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index 594a4b5738..c0d32ea9b3 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -6,6 +6,11 @@ config = active_scaffold_config_for(@record.class) -%> <ol class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> +<% if @record.errors.count -%> + <div class="association-record-errors" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>"> + <%= error_messages_for :record, :object_name => @record.class.human_name.downcase %> + </div> +<% end %> <% config.subform.columns.each :for => @record, :crud_type => crud_type, :flatten => true do |column| %> <% next unless in_subform?(column, parent_record) From 1ccceb343feae9a36081b3751be20c00c2915ae5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 9 Feb 2011 11:38:24 +0100 Subject: [PATCH 1010/2024] Bugfix: update_columns in vertical subforms fixed --- frontends/default/javascripts/jquery/active_scaffold.js | 2 +- frontends/default/javascripts/prototype/active_scaffold.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index dcc12dfcbb..8ab0379c46 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -657,7 +657,7 @@ var ActiveScaffold = { render_form_field: function(source, content, options) { if (typeof(source) == 'string') source = '#' + source; var source = $(source); - var element = source.closest('tr.association-record'); + var element = source.closest('.association-record'); if (element.length == 0) { element = source.closest('ol.form'); } diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 0258b61cbc..f9e01b71a3 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -535,7 +535,7 @@ var ActiveScaffold = { render_form_field: function(source, content, options) { var source = $(source); - var element = source.up('tr.association-record'); + var element = source.up('.association-record'); if (typeof(element) === 'undefined') { element = source.up('ol.form'); } From d5935d9e0b66c5b91e3e0ae181f81a44a2385018 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 9 Feb 2011 16:15:50 +0100 Subject: [PATCH 1011/2024] Bugfix: remove errors for subform records on delete --- frontends/default/javascripts/jquery/active_scaffold.js | 9 +++++++++ .../default/javascripts/prototype/active_scaffold.js | 8 ++++++++ .../default/views/_horizontal_subform_record.html.erb | 2 +- .../default/views/_vertical_subform_record.html.erb | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 8ab0379c46..62bd80f44d 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -563,6 +563,15 @@ var ActiveScaffold = { this.reload_if_empty(tbody, page_reload_url); }, + delete_subform_record: function(record) { + if (typeof(record) == 'string') record = '#' + record; + var errors = $(record).prev(); + if (errors.hasClass('association-record-errors')) { + this.replace_html(errors, ''); + } + this.remove(record); + }, + report_500_response: function(active_scaffold_id) { server_error = $(active_scaffold_id).find('td.messages-container p.server-error'); if (!$(server_error).is(':visible')) { diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index f9e01b71a3..0497f09d4b 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -451,6 +451,14 @@ var ActiveScaffold = { this.reload_if_empty(tbody, page_reload_url); }, + delete_subform_record: function(record) { + var errors = $(record).previous(); + if (errors.hasClassName('association-record-errors')) { + this.replace_html(errors, ''); + } + this.remove(record); + }, + report_500_response: function(active_scaffold_id) { server_error = $(active_scaffold_id).down('td.messages-container p.server-error'); if (server_error.visible()) { diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index c1d91f7b40..1bdb9ff197 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -26,7 +26,7 @@ <td class="actions"> <% if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> <% destroy_id = "#{options[:id]}-destroy" %> - <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.remove(\"#{tr_id}\"); return false;", :style=> "display: none;" %> + <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.delete_subform_record(\"#{tr_id}\"); return false;", :style=> "display: none;" %> <%= javascript_tag("ActiveScaffold.show('#{destroy_id}');") if !locked %> <% end %> <% unless @record.new_record? %> diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index aa646ec8c9..1aa55034c2 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -27,7 +27,7 @@ <li class="actions"> <% if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> <% destroy_id = "#{options[:id]}-destroy" %> - <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.remove(\"#{tr_id}\"); return false;", :style=> "display: none;" %> + <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.delete_subform_record(\"#{tr_id}\"); return false;", :style=> "display: none;" %> <%= javascript_tag("ActiveScaffold.show('#{destroy_id}');") if !locked %> <% end %> <% unless @record.new_record? %> From 0b01c2dedd63fd495f5935e2a70610c074807f60 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Thu, 10 Feb 2011 21:47:01 +0800 Subject: [PATCH 1012/2024] AS.disable_form consistency and added textarea (was missing) --- .../default/javascripts/jquery/active_scaffold.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 62bd80f44d..c4da0db090 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -218,13 +218,11 @@ $(document).ready(function() { source_id: element.attr('id')}, beforeSend: function(event) { element.nextAll('img.loading-indicator').css('visibility','visible'); - $('input[type=submit]', as_form).attr('disabled', 'disabled'); - $("input:enabled,select:enabled", as_form).attr('disabled', 'disabled'); + ActiveScaffold.disable_form(as_form) }, complete: function(event) { element.nextAll('img.loading-indicator').css('visibility','hidden'); - $('input[type=submit]', as_form).attr('disabled', ''); - $("input:disabled,select:disabled", as_form).attr('disabled', ''); + ActiveScaffold.enable_form(as_form) }, error: function (xhr, status, error) { var as_div = element.closest("div.active-scaffold"); @@ -505,7 +503,7 @@ var ActiveScaffold = { var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); if (loading_indicator) loading_indicator.css('visibility','visible'); $('input[type=submit]', as_form).attr('disabled', 'disabled'); - $("input:enabled,select:enabled", as_form).attr('disabled', 'disabled'); + $("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled'); }, enable_form: function(as_form) { @@ -514,7 +512,7 @@ var ActiveScaffold = { var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); if (loading_indicator) loading_indicator.css('visibility','hidden'); $('input[type=submit]', as_form).attr('disabled', ''); - $("input:disabled,select:disabled", as_form).attr('disabled', ''); + $("input:disabled,select:disabled,textarea:disabled", as_form).attr('disabled', ''); }, focus_first_element_of_form: function(form_element) { From 7336dbb04067c6c0d05fb70ad0eaac92015f17d6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 11 Feb 2011 10:56:34 +0100 Subject: [PATCH 1013/2024] bugfix: Heroku deploys are failing (issue 96 by MikeBlyth) --- lib/active_scaffold/bridges/date_picker/bridge.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/bridge.rb b/lib/active_scaffold/bridges/date_picker/bridge.rb index 75f2ac8b87..77f2192552 100644 --- a/lib/active_scaffold/bridges/date_picker/bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/bridge.rb @@ -8,8 +8,10 @@ if ActiveScaffold.js_framework == :jquery require File.join(directory, "lib/datepicker_bridge.rb") - FileUtils.cp(source, destination) - ActiveScaffold::Bridges::DatePickerBridge.localization(File.join(destination, 'date_picker_bridge.js')) + unless defined?(ACTIVE_SCAFFOLD_INSTALL_ASSETS) && ACTIVE_SCAFFOLD_INSTALL_ASSETS == false + FileUtils.cp(source, destination) + ActiveScaffold::Bridges::DatePickerBridge.localization(File.join(destination, 'date_picker_bridge.js')) + end else # make sure that jquery files are removed FileUtils.rm(File.join(destination, 'date_picker_bridge.js')) if File.exist?(File.join(destination, 'date_picker_bridge.js')) From 429243a4da8428804f50d541e42584d1ee559407 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 11 Feb 2011 16:18:27 +0100 Subject: [PATCH 1014/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index d68cb86615..80cad17ed3 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 11 + PATCH = 12 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 6fda33a95508df31148b16854576b67cc735342b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 11 Feb 2011 16:18:59 +0100 Subject: [PATCH 1015/2024] Regenerate gemspec for version 3.0.12 --- active_scaffold_vho.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index bdb92ef1ad..fb7fc4a6e2 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.11" + s.version = "3.0.12" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] - s.date = %q{2011-02-03} + s.date = %q{2011-02-11} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.email = %q{activescaffold@googlegroups.com} s.extra_rdoc_files = [ From c335584768208d91b909aeb5198d9be5466311a5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 12 Feb 2011 22:03:28 +0100 Subject: [PATCH 1016/2024] human conditions for field_search date range with date representation --- .../bridges/shared/date_bridge.rb | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index 2b90ca4236..c4e88aa258 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -70,7 +70,10 @@ module HumanConditionHelpers def active_scaffold_human_condition_date_bridge(column, value) case value[:opt] when 'RANGE' - "#{column.active_record_class.human_attribute_name(column.name)} = #{as_(value[:range].downcase).downcase}" + range_type, range = value[:range].downcase.split('_') + format = active_scaffold_human_condition_date_bridge_range_format(range_type, range) + from, to = controller.class.date_bridge_from_to(column, value) + "#{column.active_record_class.human_attribute_name(column.name)} = #{as_(value[:range].downcase).downcase} (#{I18n.l(from, :format => format)})" when 'PAST', 'FUTURE' "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{as_(value[:number])} #{as_(value[:unit].downcase)}" else @@ -78,6 +81,24 @@ def active_scaffold_human_condition_date_bridge(column, value) "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '- ' + I18n.l(to) : ''}" end end + + def active_scaffold_human_condition_date_bridge_range_format(range_type, range) + case range + when 'week' + first_day_of_week = I18n.translate 'active_scaffold.date_picker_options.firstDay' + if first_day_of_week == 1 + '%W %Y' + else + '%U %Y' + end + when 'month' + '%b %Y' + when 'year' + '%Y' + else + I18n.translate 'date.formats.default' + end + end end module Finder @@ -146,7 +167,7 @@ def date_bridge_from_to_for_range(column, value) return date_bridge_now.beginning_of_day, date_bridge_now.end_of_day when 'YESTERDAY' return date_bridge_now.ago(1.day).beginning_of_day, date_bridge_now.ago(1.day).end_of_day - when 'TOMMORROW' + when 'TOMORROW' return date_bridge_now.in(1.day).beginning_of_day, date_bridge_now.in(1.day).end_of_day else range_type, range = value[:range].downcase.split('_') @@ -184,8 +205,4 @@ def date_bridge_column_date?(column) ActiveScaffold::Finder.const_set('DateRanges', ["TODAY", "YESTERDAY", "TOMORROW", "THIS_WEEK", "PREV_WEEK", "NEXT_WEEK", "THIS_MONTH", "PREV_MONTH", "NEXT_MONTH", - "THIS_YEAR", "PREV_YEAR", "NEXT_YEAR"]) - - - - + "THIS_YEAR", "PREV_YEAR", "NEXT_YEAR"]) \ No newline at end of file From e0b951480ef3116cee33614f656f2df50b121d82 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 12 Feb 2011 22:10:46 +0100 Subject: [PATCH 1017/2024] human_conditions field_search date past,future with date representation --- lib/active_scaffold/bridges/shared/date_bridge.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index c4e88aa258..20a6ebd522 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -75,7 +75,8 @@ def active_scaffold_human_condition_date_bridge(column, value) from, to = controller.class.date_bridge_from_to(column, value) "#{column.active_record_class.human_attribute_name(column.name)} = #{as_(value[:range].downcase).downcase} (#{I18n.l(from, :format => format)})" when 'PAST', 'FUTURE' - "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{as_(value[:number])} #{as_(value[:unit].downcase)}" + from, to = controller.class.date_bridge_from_to(column, value) + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{as_(value[:number])} #{as_(value[:unit].downcase)} (#{I18n.l(from)} - #{I18n.l(to)})" else from, to = controller.class.date_bridge_from_to(column, value) "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '- ' + I18n.l(to) : ''}" From dc9b041cb3a41530baf07be55699bcc69804a78e Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Mon, 14 Feb 2011 12:50:52 +0200 Subject: [PATCH 1018/2024] we use cache checking to see if a file pends saving, new_record? was a stub --- .../bridges/carrierwave/lib/carrierwave_bridge_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb index 8720764cfd..f24c26822c 100644 --- a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +++ b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb @@ -15,7 +15,7 @@ def delete_#{field}=(value) return unless value # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! - self.remove_#{field}! unless new_record? + self.remove_#{field}! unless self.#{field}.cached?.present? end EOF end @@ -23,4 +23,4 @@ def delete_#{field}=(value) end end end -end \ No newline at end of file +end From 72b5b4e5dde4c7aa9c7131c629124d177ca40dd2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Feb 2011 12:21:39 +0100 Subject: [PATCH 1019/2024] Bugfix: jquery delete_subform_record (issue: 97 reported by victor-ono) --- frontends/default/javascripts/jquery/active_scaffold.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index c4da0db090..467a4c4343 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -563,7 +563,8 @@ var ActiveScaffold = { delete_subform_record: function(record) { if (typeof(record) == 'string') record = '#' + record; - var errors = $(record).prev(); + record = $(record); + var errors = record.prev(); if (errors.hasClass('association-record-errors')) { this.replace_html(errors, ''); } From 07c3bc1ce6e565b8bebc46071ec1b486d30bf4e6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Feb 2011 19:55:34 +0100 Subject: [PATCH 1020/2024] human condition date future/past just print dates without future and past part --- lib/active_scaffold/bridges/shared/date_bridge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index 20a6ebd522..92bcd40b58 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -76,7 +76,7 @@ def active_scaffold_human_condition_date_bridge(column, value) "#{column.active_record_class.human_attribute_name(column.name)} = #{as_(value[:range].downcase).downcase} (#{I18n.l(from, :format => format)})" when 'PAST', 'FUTURE' from, to = controller.class.date_bridge_from_to(column, value) - "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{as_(value[:number])} #{as_(value[:unit].downcase)} (#{I18n.l(from)} - #{I18n.l(to)})" + "#{column.active_record_class.human_attribute_name(column.name)} #{as_('BETWEEN'.downcase).downcase} #{I18n.l(from)} - #{I18n.l(to)}" else from, to = controller.class.date_bridge_from_to(column, value) "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '- ' + I18n.l(to) : ''}" From 9993b55f5e8fef61f7d012f3f1792bbfcf5403a4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Feb 2011 20:03:11 +0100 Subject: [PATCH 1021/2024] render_component is sometimes not available in views (reason still unknown) --- lib/active_scaffold/extensions/action_view_rendering.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 1b2c25d0d4..8c8e256069 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -66,8 +66,8 @@ def render_with_active_scaffold(*args, &block) id = "as_#{eid}-content" url_options = {:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params]) - if respond_to? :render_component - render_component url_options + if controller.respond_to?(:render_component_into_view) + controller.send(:render_component_into_view, url_options) else content_tag(:div, {:id => id}) do url = url_for(url_options) From 48ac1662fb06b512a01994d65eae12efcbbf844a Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Wed, 16 Feb 2011 15:34:10 +0200 Subject: [PATCH 1022/2024] refactor carrierwave bridge --- .../carrierwave/lib/carrierwave_bridge.rb | 10 ++-------- .../lib/carrierwave_bridge_helpers.rb | 14 -------------- .../bridges/carrierwave/lib/form_ui.rb | 17 +++++++++++------ 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb index b27f28cc40..4827aac634 100644 --- a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +++ b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb @@ -12,8 +12,6 @@ def initialize_with_carrierwave(model_id) self.model.uploaders.keys.each do |field| configure_carrierwave_field(field.to_sym) - # define the "delete" helper for use with active scaffold, unless it's already defined - ActiveScaffold::Bridges::Carrierwave::Lib::CarrierwaveBridgeHelpers.generate_delete_helper(self.model, field) end end @@ -24,13 +22,9 @@ def self.included(base) private def configure_carrierwave_field(field) self.columns << field - self.columns[field].form_ui ||= :carrierwave + self.columns[field].form_ui ||= :carrierwave # :TODO thumbnail self.columns[field].params.add "#{field}_cache" - self.columns[field].params.add "delete_#{field}" - -# [:file_name, :content_type, :file_size, :updated_at].each do |f| -# self.columns.exclude("#{field}_#{f}".to_sym) -# end + self.columns[field].params.add "remove_#{field}" end end end diff --git a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb index f24c26822c..b453386271 100644 --- a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +++ b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb @@ -5,20 +5,6 @@ module Lib module CarrierwaveBridgeHelpers mattr_accessor :thumbnail_style self.thumbnail_style = :thumbnail - - def self.generate_delete_helper(klass, field) - klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("delete_#{field}=") - attr_reader :delete_#{field} - - def delete_#{field}=(value) - value = (value == "true") if String === value - return unless value - - # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! - self.remove_#{field}! unless self.#{field}.cached?.present? - end - EOF - end end end end diff --git a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb index 1455d91540..881c14ba63 100644 --- a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +++ b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb @@ -12,18 +12,23 @@ def active_scaffold_input_carrierwave(column, options) js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;"; end - hidden_field_options = { - :name => options[:name].gsub(/\[#{column.name}\]$/, "[delete_#{column.name}]"), - :id => options[:id] + '_delete', - :value => "false" + remove_field_options = { + :name => options[:name].gsub(/\[#{column.name}\]$/, "[remove_#{column.name}]"), + :id => 'remove_' + options[:id], + :value => false + } + + cache_field_options = { + :name => options[:name].gsub(/\[#{column.name}\]$/, "[#{column.name}_cache]"), + :id => options[:id] + '_cache' } content_tag( :div, content_tag(:div, ( get_column_value(@record, column) + " | " + - hidden_field(:record, "delete_#{column.name}", hidden_field_options) + content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}) + - hidden_field(:record, "#{column.name}_cache", {:name => options[:name].gsub(/\[#{column.name}\]$/, "[#{column.name}_cache]")}) + hidden_field(:record, "remove_#{column.name}", remove_field_options) + + hidden_field(:record, "#{column.name}_cache", cache_field_options) ).html_safe ) + content_tag(:div, input, :style => "display: none") ) From e90a42ca8111d933ea0d230c3061b75a613551fb Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Wed, 16 Feb 2011 15:40:19 +0200 Subject: [PATCH 1023/2024] fix last commit --- lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb index 881c14ba63..6c2be1912d 100644 --- a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +++ b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb @@ -26,9 +26,9 @@ def active_scaffold_input_carrierwave(column, options) content_tag( :div, content_tag(:div, ( get_column_value(@record, column) + " | " + - content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}) + + hidden_field(:record, "#{column.name}_cache", cache_field_options) + hidden_field(:record, "remove_#{column.name}", remove_field_options) + - hidden_field(:record, "#{column.name}_cache", cache_field_options) + content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}) ).html_safe ) + content_tag(:div, input, :style => "display: none") ) From 7aa78854cd082e102b7bc7535eace3ec4109caea Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 16 Feb 2011 14:50:40 +0100 Subject: [PATCH 1024/2024] extract method: column_value_for_plural_associaton --- lib/active_scaffold/attribute_params.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index b084df866d..664f32bf36 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -110,11 +110,7 @@ def column_value_from_param_simple_value(parent_record, column, value) # it's a single id column.association.klass.find(value) if value and not value.empty? elsif column.plural_association? - # it's an array of ids - if value and not value.empty? - ids = value.select {|id| id.respond_to?(:empty?) ? !id.empty? : true} - ids.empty? ? [] : column.association.klass.find(ids) - end + column_plural_assocation_value_from_value(column, value) elsif column.column && column.column.number? && [:i18n_number, :currency].include?(column.options[:format]) self.class.i18n_number_to_native_format(value) else @@ -126,6 +122,14 @@ def column_value_from_param_simple_value(parent_record, column, value) end end + def column_plural_assocation_value_from_value(column, value) + # it's an array of ids + if value and not value.empty? + ids = value.select {|id| id.respond_to?(:empty?) ? !id.empty? : true} + ids.empty? ? [] : column.association.klass.find(ids) + end + end + def column_value_from_param_hash_value(parent_record, column, value) # this is just for backwards compatibility. we should clean this up in 2.0. if column.form_ui == :select From 2d0e041071b90998811a7625bfd72c67c341bf4c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 16 Feb 2011 14:53:52 +0100 Subject: [PATCH 1025/2024] extract method create_save --- lib/active_scaffold/actions/create.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 9f6df30f9c..944ababa61 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -103,17 +103,21 @@ def do_create create_association_with_parent(@record) register_constraints_with_action_columns(nested.constrained_fields) end - before_create_save(@record) - self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit - if successful? - @record.save! and @record.save_associated! - after_create_save(@record) - end + create_save end rescue ActiveRecord::RecordInvalid end end + def create_save + before_create_save(@record) + self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit + if successful? + @record.save! and @record.save_associated! + after_create_save(@record) + end + end + # override this method if you want to inject data in the record (or its associated objects) before the save def before_create_save(record); end From c067450b6399af9c8abba37ec8dd89d0c48be4a4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 16 Feb 2011 14:58:24 +0100 Subject: [PATCH 1026/2024] allow singular assocations with multiple selection (expermimental) --- lib/active_scaffold/helpers/form_column_helpers.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 124559b893..9386502f3f 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -107,6 +107,7 @@ def active_scaffold_input_singular_association(column, html_options) html_options.update(column.options[:html_options] || {}) options.update(column.options) + html_options[:name] = "#{html_options[:name]}[]" if (html_options[:multiple] == true && !html_options[:name].to_s.ends_with?("[]")) select(:record, method, select_options.uniq, options, html_options) end @@ -171,7 +172,9 @@ def active_scaffold_input_radio(column, html_options) # ... maybe this should be provided in a bridge? def active_scaffold_input_record_select(column, options) if column.singular_association? - active_scaffold_record_select(column, options, @record.send(column.name), false) + multiple = false + multiple = column.options[:html_options][:multiple] if column.options[:html_options] && column.options[:html_options][:multiple] + active_scaffold_record_select(column, options, @record.send(column.name), multiple) elsif column.plural_association? active_scaffold_record_select(column, options, @record.send(column.name), true) end From 1429574c6468871d58d923a92a0553afe61793ca Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 16 Feb 2011 16:34:06 +0100 Subject: [PATCH 1027/2024] dynamic parameters for action_links --- lib/active_scaffold/data_structures/action_link.rb | 4 ++++ lib/active_scaffold/helpers/view_helpers.rb | 3 +++ 2 files changed, 7 insertions(+) diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 71391721ee..e7fe8c0907 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -17,6 +17,7 @@ def initialize(action, options = {}) self.html_options = {} self.column = nil self.image = nil + self.dynamic_parameters = nil # apply quick properties options.each_pair do |k, v| @@ -43,6 +44,9 @@ def static_controller? # a hash of request parameters attr_accessor :parameters + # a block for dynamic_parameters + attr_accessor :dynamic_parameters + # the RESTful method attr_accessor :method diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index f0e9a33a6d..a566f24e8f 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -151,6 +151,9 @@ def action_link_url_options(link, url_options, record, options = {}) url_options[:controller] = link.controller if link.controller url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller] url_options.merge! link.parameters if link.parameters + @link_record = record + url_options.merge! self.instance_eval(&(link.dynamic_parameters)) if link.dynamic_parameters.is_a?(Proc) + @link_record = nil url_options_for_nested_link(link.column, record, link, url_options, options) if link.nested_link? url_options_for_sti_link(link.column, record, link, url_options, options) unless record.nil? || active_scaffold_config.sti_children.nil? url_options[:_method] = link.method if !link.confirm? && link.inline? && link.method != :get From 1a14e5033e9b3c736e106dca2fef7036e90472e0 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Thu, 17 Feb 2011 12:18:04 +0200 Subject: [PATCH 1028/2024] created cancan bridge --- lib/active_scaffold/bridges/cancan/bridge.rb | 11 +++ .../bridges/cancan/lib/cancan_bridge.rb | 81 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 lib/active_scaffold/bridges/cancan/bridge.rb create mode 100644 lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb diff --git a/lib/active_scaffold/bridges/cancan/bridge.rb b/lib/active_scaffold/bridges/cancan/bridge.rb new file mode 100644 index 0000000000..722d086e35 --- /dev/null +++ b/lib/active_scaffold/bridges/cancan/bridge.rb @@ -0,0 +1,11 @@ +ActiveScaffold::Bridges.bridge "CanCan" do + install do + require File.join(File.dirname(__FILE__), "lib", "cancan_bridge.rb") + + ActiveScaffold::Actions::Core.send :include, ActiveScaffold::CancanBridge::Core + ActiveScaffold::Actions::Nested.send :include, ActiveScaffold::CancanBridge::Core + ActionController::Base.send :include, ActiveScaffold::CancanBridge::ModelUserAccess::Controller + ActiveRecord::Base.send :include, ActiveScaffold::CancanBridge::ModelUserAccess::Model + ActiveRecord::Base.send :include, ActiveScaffold::CancanBridge::ActiveRecord + end +end diff --git a/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb b/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb new file mode 100644 index 0000000000..a63c6f9449 --- /dev/null +++ b/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb @@ -0,0 +1,81 @@ +module ActiveScaffold + module CancanBridge + + module Core + extend ActiveSupport::Concern + included do + alias_method_chain :beginning_of_chain, :cancan + end + # :TODO can this be expanded more ? + def beginning_of_chain_with_cancan + beginning_of_chain_without_cancan.accessible_by(current_ability) + end + end + + # This is a module aimed at making the current_ability available to ActiveRecord models for permissions. + module ModelUserAccess + module Controller + extend ActiveSupport::Concern + included do + prepend_before_filter :assign_current_ability_to_models + end + + # We need to give the ActiveRecord classes a handle to the current ability. We don't want to just pass the object, + # because the object may change (someone may log in or out). So we give ActiveRecord a proc that ties to the + # current_ability_method on this ApplicationController. + def assign_current_ability_to_models + ::ActiveRecord::Base.current_ability_proc = proc {send(:current_ability)} + end + end + + module Model + extend ActiveSupport::Concern + + module ClassMethods + # The proc to call that retrieves the current_ability from the ApplicationController. + attr_accessor :current_ability_proc + + # Class-level access to the current ability + def current_ability + ::ActiveRecord::Base.current_ability_proc.call if ::ActiveRecord::Base.current_ability_proc + end + end + + # Instance-level access to the current ability + def current_ability; self.class.current_ability end + end + end + + + module ActiveRecord + extend ActiveSupport::Concern + included do + extend SecurityMethods + include SecurityMethods + alias_method_chain :authorized_for?, :cancan + class << self + alias_method_chain :authorized_for?, :cancan + end + end + + module SecurityMethods + class InvalidArgument < StandardError; end + + # is usually called with :crud_type and :column, or :action + # {:crud_type=>:update, :column=>"some_colum_name"} + # {:action=>"edit"} + # to allow access cancan must allow both :crud_type and :action + # if cancan says "no", it delegates to default AS behavior + def authorized_for_with_cancan?(options = {}) + raise InvalidArgument if options[:crud_type].blank? and options[:action].blank? + crud_type_result = options[:crud_type].nil? ? true : current_ability.can?(options[:crud_type], self) + action_result = options[:action].nil? ? true : current_ability.can?(options[:action], self) + default_result = authorized_for_without_cancan?(options) + result = (crud_type_result and action_result) or default_result + return result + end + end + end + + end +end From 0a0c75c116708f0bb25cf2c148df7dce49992f39 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 17 Feb 2011 16:00:58 +0100 Subject: [PATCH 1029/2024] active_scaffold_session_storage accepts a controller id --- lib/active_scaffold.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 362325a22b..2d6586bef8 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -81,8 +81,7 @@ def active_scaffold_config_for(klass) self.class.active_scaffold_config_for(klass) end - def active_scaffold_session_storage - id = params[:eid] || params[:controller] + def active_scaffold_session_storage(id = (params[:eid] || params[:controller])) session_index = "as:#{id}" session[session_index] ||= {} session[session_index] From 631beabf872623a31302ef3d09d251684b2da78e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 18 Feb 2011 10:39:22 +0100 Subject: [PATCH 1030/2024] mark_all action get s its own respond methods --- lib/active_scaffold/actions/mark.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index e5575e5e11..0385fd34c3 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -13,10 +13,19 @@ def mark_all else do_demark_all end - do_list - respond_to_action(:list) + respond_to_action(:mark_all) end protected + + def mark_all_respond_to_html + do_list + list_respond_to_html + end + + def mark_all_respond_to_js + do_list + render :action => 'list.js' + end # We need to give the ActiveRecord classes a handle to currently marked records. We don't want to just pass the object, # because the object may change. So we give ActiveRecord a proc that ties to the @@ -46,5 +55,9 @@ def do_demark_all def mark_authorized? authorized_for?(:action => :read) end + + def mark_all_formats + (default_formats + active_scaffold_config.formats).uniq + end end end \ No newline at end of file From 010102ae664a0697d3c972112c0f12488a89e6d9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 18 Feb 2011 13:47:47 +0100 Subject: [PATCH 1031/2024] do not render whole list in case of mark_all action --- .../javascripts/jquery/active_scaffold.js | 25 +++++++++++++++++++ .../javascripts/prototype/active_scaffold.js | 24 ++++++++++++++++++ frontends/default/views/on_mark_all.js.rjs | 4 +++ lib/active_scaffold/actions/mark.rb | 2 +- 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 frontends/default/views/on_mark_all.js.rjs diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 467a4c4343..11972503bb 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -702,6 +702,31 @@ var ActiveScaffold = { ActiveScaffold.report_500_response(active_scaffold_id) } }); + }, + + // element is tbody id + mark_records: function(element, options) { + if (typeof(element) == 'string') element = '#' + element; + var element = $(element); + var mark_checkboxes = $('#' + element.attr('id') + ' > tr.record td.marked-column input[type="checkbox"]'); + mark_checkboxes.each(function (index) { + var item = $(this); + if(options.checked === true) { + item.attr('checked', 'checked'); + } else { + item.removeAttr('checked'); + } + item.attr('value', ('' + !options.checked)); + }); + if(options.include_mark_all === true) { + var mark_all_checkbox = element.prev('thead').find('th.marked-column_heading span input[type="checkbox"]'); + if(options.checked === true) { + mark_all_checkbox.attr('checked', 'checked'); + } else { + mark_all_checkbox.removeAttr('checked'); + } + mark_all_checkbox.attr('value', ('' + !options.checked)); + } } } diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 0497f09d4b..77765b12ce 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -568,7 +568,31 @@ var ActiveScaffold = { } } ); + }, + + // element is tbody id + mark_records: function(element, options) { + var element = $(element); + var mark_checkboxes = $$('#' + element.readAttribute('id') + ' > tr.record td.marked-column input[type="checkbox"]'); + mark_checkboxes.each(function(item) { + if(options.checked === true) { + item.writeAttribute({ checked: 'checked' }); + } else { + item.removeAttribute('checked'); + } + item.writeAttribute('value', ('' + !options.checked)); + }); + if(options.include_mark_all === true) { + var mark_all_checkbox = element.previous('thead').down('th.marked-column_heading span input[type="checkbox"]'); + if(options.checked === true) { + mark_all_checkbox.writeAttribute({ checked: 'checked' }); + } else { + mark_all_checkbox.removeAttribute('checked'); + } + mark_all_checkbox.writeAttribute('value', ('' + !options.checked)); + } } + } /* diff --git a/frontends/default/views/on_mark_all.js.rjs b/frontends/default/views/on_mark_all.js.rjs new file mode 100644 index 0000000000..851f29570a --- /dev/null +++ b/frontends/default/views/on_mark_all.js.rjs @@ -0,0 +1,4 @@ +options = {:checked => mark_all, + :include_mark_all => true} +page << "ActiveScaffold.mark_records('#{active_scaffold_tbody_id}', #{options.to_json});" + diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index 0385fd34c3..f1459d0e1a 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -24,7 +24,7 @@ def mark_all_respond_to_html def mark_all_respond_to_js do_list - render :action => 'list.js' + render :action => 'on_mark_all', :locals => {:mark_all => mark_all?} end # We need to give the ActiveRecord classes a handle to currently marked records. We don't want to just pass the object, From 1a989031182cba73106d657586f2b6e859723abf Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 18 Feb 2011 16:29:25 +0100 Subject: [PATCH 1032/2024] bump version number --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 80cad17ed3..05828ef615 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 12 + PATCH = 13 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From cf3b6ebfedcc8f5ddd377291adb84048ffc7940c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 18 Feb 2011 16:29:43 +0100 Subject: [PATCH 1033/2024] Regenerate gemspec for version 3.0.13 --- active_scaffold_vho.gemspec | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index fb7fc4a6e2..1282560885 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.12" + s.version = "3.0.13" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] - s.date = %q{2011-02-11} + s.date = %q{2011-02-18} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.email = %q{activescaffold@googlegroups.com} s.extra_rdoc_files = [ @@ -95,6 +95,7 @@ Gem::Specification.new do |s| "frontends/default/views/list.js.rjs", "frontends/default/views/on_action_update.js.rjs", "frontends/default/views/on_create.js.rjs", + "frontends/default/views/on_mark_all.js.rjs", "frontends/default/views/on_update.js.rjs", "frontends/default/views/search.html.erb", "frontends/default/views/show.html.erb", @@ -122,6 +123,8 @@ Gem::Specification.new do |s| "lib/active_scaffold/bridges/bridge.rb", "lib/active_scaffold/bridges/calendar_date_select/bridge.rb", "lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb", + "lib/active_scaffold/bridges/cancan/bridge.rb", + "lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb", "lib/active_scaffold/bridges/carrierwave/bridge.rb", "lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb", "lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb", From 5211e5048819f1c57677b53474d93f664c00cec8 Mon Sep 17 00:00:00 2001 From: Robert Lowe <robert@iblargz.com> Date: Sun, 20 Feb 2011 03:14:42 -0500 Subject: [PATCH 1034/2024] fixing keke/tiny_mce for activescaffold+jquery --- frontends/default/views/_form.html.erb | 4 ++-- .../default/views/_form_attribute.html.erb | 2 +- .../bridges/tiny_mce/lib/tiny_mce_bridge.rb | 22 ++++++++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index ab0befcee6..2884ab0374 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -13,11 +13,11 @@ next %> <% elsif renders_as == :subform and !override_form_field?(column) -%> <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %>" id="<%= sub_form_id(:association => column.name) %>"> - <%= render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%> + <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%> </li> <% else -%> <li class="form-element <%= 'required' if column.required? %> <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %>"> - <%= render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%> + <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%> </li> <% end -%> <% end -%> diff --git a/frontends/default/views/_form_attribute.html.erb b/frontends/default/views/_form_attribute.html.erb index ce5aa6cce3..724c9b5f16 100644 --- a/frontends/default/views/_form_attribute.html.erb +++ b/frontends/default/views/_form_attribute.html.erb @@ -4,7 +4,7 @@ <label for="<%= active_scaffold_input_options(column, scope)[:id] %>"><%= column.label %></label> </dt> <dd> - <%= active_scaffold_input_for column, scope %> + <%=raw active_scaffold_input_for column, scope %> <% if column.update_columns -%> <%= loading_indicator_tag(:action => :render_field, :id => params[:id]) %> <% end -%> diff --git a/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb b/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb index 49faf316e5..54e1e660de 100644 --- a/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +++ b/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb @@ -2,7 +2,18 @@ module ActiveScaffold module TinyMceBridge module ViewHelpers def active_scaffold_includes(*args) - tiny_mce_js = javascript_tag(%| + if ActiveScaffold.js_framework == :jquery + tiny_mce_js = javascript_tag(%| +var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; +ActiveScaffold.ActionLink.Abstract.prototype.close = function() { + $(this.adapter).find('textarea.mceEditor').each(function(index, elem) { + tinyMCE.execCommand('mceRemoveControl', false, $(elem).attr('id')); + }); + action_link_close.apply(this); +}; + |) if using_tiny_mce? + else + tiny_mce_js = javascript_tag(%| var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; ActiveScaffold.ActionLink.Abstract.prototype.close = function() { this.adapter.select('textarea.mceEditor').each(function(elem) { @@ -10,7 +21,8 @@ def active_scaffold_includes(*args) }); action_link_close.apply(this); }; - |) if using_tiny_mce? + |) if using_tiny_mce? + end super(*args) + (include_tiny_mce_if_needed || '') + (tiny_mce_js || '') end end @@ -25,7 +37,11 @@ def active_scaffold_input_text_editor(column, options) end def onsubmit - submit_js = 'tinyMCE.triggerSave();this.select("textarea.mceEditor").each(function(elem) { tinyMCE.execCommand("mceRemoveControl", false, elem.id); });' if using_tiny_mce? + if ActiveScaffold.js_framework == :jquery + submit_js = 'tinyMCE.triggerSave();$(\'textarea.mceEditor\').each(function(index, elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, $(elem).attr(\'id\')); });' if using_tiny_mce? + else + submit_js = 'tinyMCE.triggerSave();this.select(\'textarea.mceEditor\').each(function(elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, elem.id); });' if using_tiny_mce? + end [super, submit_js].compact.join ';' end end From 1d825918f4e2e7e90c75f61c365e7984297a862e Mon Sep 17 00:00:00 2001 From: Robert Lowe <robert@iblargz.com> Date: Sun, 20 Feb 2011 17:52:43 -0500 Subject: [PATCH 1035/2024] tiny patch to fix action_result for cancan bridge, action.is_a?(String).to_sym; Show works correctly now IMO --- lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb b/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb index a63c6f9449..eb0d19e91e 100644 --- a/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb +++ b/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb @@ -69,7 +69,7 @@ class InvalidArgument < StandardError; end def authorized_for_with_cancan?(options = {}) raise InvalidArgument if options[:crud_type].blank? and options[:action].blank? crud_type_result = options[:crud_type].nil? ? true : current_ability.can?(options[:crud_type], self) - action_result = options[:action].nil? ? true : current_ability.can?(options[:action], self) + action_result = options[:action].nil? ? true : current_ability.can?(options[:action].to_sym, self) default_result = authorized_for_without_cancan?(options) result = (crud_type_result and action_result) or default_result return result From c587c2a11d82be52f6dd183d03ec7e2180dc895a Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Tue, 22 Feb 2011 10:54:33 +0200 Subject: [PATCH 1036/2024] fix false positives as reported in comments https://github.com/vhochstein/active_scaffold/issues/104#issue/104/comment/793656 --- .../bridges/cancan/lib/cancan_bridge.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb b/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb index eb0d19e91e..33f777d041 100644 --- a/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb +++ b/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb @@ -68,10 +68,14 @@ class InvalidArgument < StandardError; end # if cancan says "no", it delegates to default AS behavior def authorized_for_with_cancan?(options = {}) raise InvalidArgument if options[:crud_type].blank? and options[:action].blank? - crud_type_result = options[:crud_type].nil? ? true : current_ability.can?(options[:crud_type], self) - action_result = options[:action].nil? ? true : current_ability.can?(options[:action].to_sym, self) + if current_ability.present? + crud_type_result = options[:crud_type].nil? ? true : current_ability.can?(options[:crud_type], self) + action_result = options[:action].nil? ? true : current_ability.can?(options[:action].to_sym, self) + else + crud_type_result, action_result = false, false + end default_result = authorized_for_without_cancan?(options) - result = (crud_type_result and action_result) or default_result + result = (crud_type_result && action_result) || default_result return result end end From 560869e1e5204450ed12c5c56c747a22993b3781 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 22 Feb 2011 14:02:47 +0100 Subject: [PATCH 1037/2024] avoid calling authorization for mark action configuration --- lib/active_scaffold/config/mark.rb | 2 +- lib/active_scaffold/data_structures/action_columns.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/mark.rb b/lib/active_scaffold/config/mark.rb index a443c24d65..ef3a766585 100644 --- a/lib/active_scaffold/config/mark.rb +++ b/lib/active_scaffold/config/mark.rb @@ -16,7 +16,7 @@ def add_mark_column @core.columns[:marked].form_ui = :checkbox @core.columns[:marked].inplace_edit = true @core.columns[:marked].sort = false - @core.list.columns = [:marked] + @core.list.columns.names unless @core.list.columns.include? :marked + @core.list.columns = [:marked] + @core.list.columns.names_without_auth_check unless @core.list.columns.include? :marked end end end diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index 1adbfb3bf3..caec17096b 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -38,6 +38,10 @@ def names self.collect(&:name) end + def names_without_auth_check + Array(@set) + end + protected def collect_columns From 6943c4b51e20abc61ae1d626e4adbd7b4e08f012 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 22 Feb 2011 14:57:30 +0100 Subject: [PATCH 1038/2024] do not use lowercase for search. picked from master: https://github.com/activescaffold/active_scaffold/commit/30d950ee636aff500561db67f3bc0511cbcd08de --- lib/active_scaffold/finder.rb | 12 ++++++++---- test/misc/finder_test.rb | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 6f75151dbb..78f149e48a 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -1,5 +1,9 @@ module ActiveScaffold module Finder + def self.like_operator + @@like_operator ||= ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE" + end + module ClassMethods # Takes a collection of search terms (the tokens) and creates SQL that # searches all specified ActiveScaffold columns. A row will match if each @@ -13,13 +17,13 @@ def create_conditions_for_columns(tokens, columns, text_search = :full) where_clauses = [] columns.each do |column| - where_clauses << ((column.column.nil? || column.column.text?) ? "LOWER(#{column.search_sql}) LIKE ?" : "#{column.search_sql} = ?") + where_clauses << ((column.column.nil? || column.column.text?) ? "#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?" : "#{column.search_sql} = ?") end phrase = "(#{where_clauses.join(' OR ')})" sql = ([phrase] * tokens.length).join(' AND ') tokens = tokens.collect do |value| - columns.collect {|column| (column.column.nil? || column.column.text?) ? like_pattern.sub('?', value.downcase) : column.column.type_cast(value)} + columns.collect {|column| (column.column.nil? || column.column.text?) ? like_pattern.sub('?', value) : column.column.type_cast(value)} end.flatten [sql, *tokens] @@ -52,7 +56,7 @@ def condition_for_column(column, value, text_search = :full) ["#{column.search_sql} in (?)", Array(value)] else if column.column.nil? || column.column.text? - ["LOWER(#{column.search_sql}) LIKE ?", like_pattern.sub('?', value.downcase)] + ["#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] else ["#{column.search_sql} = ?", column.column.type_cast(value)] end @@ -82,7 +86,7 @@ def condition_for_numeric(column, value) def condition_for_range(column, value, like_pattern = nil) if !value.is_a?(Hash) if column.column.nil? || column.column.text? - ["LOWER(#{column.search_sql}) LIKE ?", like_pattern.sub('?', value.downcase)] + ["#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] else ["#{column.search_sql} = ?", column.column.type_cast(value)] end diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index 3baf157663..5a75df32f1 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -33,13 +33,13 @@ def test_create_conditions_for_columns ] expected_conditions = [ - '(LOWER("model_stubs"."a") LIKE ? OR LOWER("model_stubs"."b") LIKE ?) AND (LOWER("model_stubs"."a") LIKE ? OR LOWER("model_stubs"."b") LIKE ?)', + '("model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?) AND ("model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?)', '%foo%', '%foo%', '%bar%', '%bar%' ] assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns(tokens, columns) expected_conditions = [ - '(LOWER("model_stubs"."a") LIKE ? OR LOWER("model_stubs"."b") LIKE ?)', + '("model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?)', '%foo%', '%foo%' ] assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns('foo', columns) From 69992936be77e44de4abd4e6a37b0c4b4104128f Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Tue, 22 Feb 2011 16:34:56 +0200 Subject: [PATCH 1039/2024] allow inplace editor to be inside some surrounding decorating tags --- frontends/default/javascripts/jquery/active_scaffold.js | 6 +++++- frontends/default/javascripts/prototype/active_scaffold.js | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 11972503bb..9e692f3b7e 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -140,7 +140,11 @@ $(document).ready(function() { csrf_token = $('meta[name=csrf-token]').first(), my_parent = span.parent(), column_heading = null; - + + if(!(my_parent.is('td') || my_parent.is('th'))){ + my_parent = span.parents('td').eq(0); + } + if (my_parent.is('td')) { var column_no = my_parent.prevAll('td').length; column_heading = my_parent.closest('.active-scaffold').find('th:eq(' + column_no + ')'); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 77765b12ce..14ac0b0e62 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -155,6 +155,10 @@ document.observe("dom:loaded", function() { csrf_token = $$('meta[name=csrf-token]')[0], my_parent = span.up(), column_heading = null; + + if(!(my_parent.nodeName.toLowerCase() === 'td' || my_parent.nodeName.toLowerCase() === 'th')){ + my_parent = span.up('td'); + } if (my_parent.nodeName.toLowerCase() === 'td') { var heading_selector = '.' + span.up().readAttribute('class').split(' ')[0] + '_heading'; From b803a66bcaa0ee6b8f1ce1cee838ff315d60c6d2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 23 Feb 2011 08:37:52 +0100 Subject: [PATCH 1040/2024] call new_model instead of activescafoldconfig.model.new --- frontends/default/views/_list_messages.html.erb | 2 +- lib/active_scaffold/actions/core.rb | 1 + lib/active_scaffold/actions/field_search.rb | 2 +- lib/active_scaffold/actions/list.rb | 2 +- lib/active_scaffold/actions/subform.rb | 2 +- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index bdfbbd08c6..d3a0285048 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -18,7 +18,7 @@ <% if active_scaffold_config.list.show_search_reset && @filtered -%> <% search_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :member, :position => false) action_links = ActiveScaffold::DataStructures::ActionLinks.new - record = active_scaffold_config.model.new + record = new_model record.id = 0 action_links.add(search_link) -%> <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links.member} %> diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 3fd538f700..e651c5ebe1 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -6,6 +6,7 @@ def self.included(base) end base.helper_method :nested? base.helper_method :beginning_of_chain + base.helper_method :new_model end def render_field if params[:in_place_editing] diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index 912195ec35..f1ecf67a7a 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -11,7 +11,7 @@ def self.included(base) # FieldSearch uses params[:search] and not @record because search conditions do not always pass the Model's validations. # This facilitates for example, textual searches against associations via .search_sql def show_search - @record = active_scaffold_config.model.new + @record = new_model respond_to_action(:field_search) end diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 31c33b7fb9..039d3a4272 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -18,7 +18,7 @@ def row def list do_list do_new if active_scaffold_config.list.always_show_create - @record ||= active_scaffold_config.model.new if active_scaffold_config.list.always_show_search + @record ||= new_model if active_scaffold_config.list.always_show_search @nested_auto_open = active_scaffold_config.list.nested_auto_open respond_to_action(:list) end diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index 12e2808edf..b7478f46d2 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -1,7 +1,7 @@ module ActiveScaffold::Actions module Subform def edit_associated - @parent_record = params[:id].nil? ? active_scaffold_config.model.new : find_if_allowed(params[:id], :update) + @parent_record = params[:id].nil? ? new_model : find_if_allowed(params[:id], :update) @column = active_scaffold_config.columns[params[:association]] # NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all. diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 23d1da43e2..44f6b65baf 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -275,7 +275,7 @@ def active_scaffold_inplace_edit(record, column, options = {}) def inplace_edit_control(column) if inplace_edit?(active_scaffold_config.model, column) and inplace_edit_cloning?(column) - @record = active_scaffold_config.model.new + @record = new_model column = column.clone column.options = column.options.clone column.form_ui = :select if (column.association && column.form_ui.nil?) From 0ff12965d493784e1e18831a0b4c50ee487f2821 Mon Sep 17 00:00:00 2001 From: Daniel Lepage <dlepage@solulabs.com> Date: Wed, 23 Feb 2011 14:16:36 -0500 Subject: [PATCH 1041/2024] Complete french translation --- lib/active_scaffold/locale/fr.rb | 66 +++++++++++++++++--------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb index 0205295b4e..a9dc14e78e 100644 --- a/lib/active_scaffold/locale/fr.rb +++ b/lib/active_scaffold/locale/fr.rb @@ -7,6 +7,7 @@ :are_you_sure_to_delete => 'Êtes vous sûr?', :cancel => 'Annuler', :click_to_edit => 'Cliquer pour éditer', + :click_to_reset => 'Cliquer pour ré-initialiser', :close => 'Fermer', :config_list => 'Configure', :config_list_model => 'Configure Columns for %{model}', @@ -24,6 +25,7 @@ :export => 'Exporter', :nested_for_model => '%{nested_model} pour %{parent_model}', :nested_of_model => '%{nested_model} de %{parent_model}', + :false => 'Faux', :filtered => '(Filtré)', :found => 'Trouvé', :hide => 'Cacher', @@ -50,6 +52,7 @@ :show => 'Montrer', :show_model => 'Montrer %{model}', :_to_ => ' à ', + :true => 'Vrai', :update => 'Mettre à jour', :update_model => 'Mettre à jour le(/la) %{model}', :updated_model => 'Mis à jour de %{model}', @@ -60,31 +63,34 @@ :'<' => '<', :'!=' => '!=', :between => 'Entre', - :today => 'Today', - :yesterday => 'Yesterday', - :tomorrow => 'Tommorrow', - :this_week => 'This Week', - :prev_week => 'Last Week', - :next_week => 'Next Week', - :this_month => 'This Month', - :prev_month => 'Last Month', - :next_month => 'Next Month', - :this_year => 'This Year', - :prev_year => 'Last Year', - :next_year => 'Next Year', - :past => 'Past', - :future => 'Future', - :range => 'Range', - :seconds => 'Seconds', + :contains => 'Contient', + :begins_with => 'Commençant par', + :ends_with => 'Se terminant par', + :today => "Aujourd'hui", + :yesterday => 'Hier', + :tomorrow => 'Demain', + :this_week => 'Cette Semaine', + :prev_week => 'Semaine dernière', + :next_week => 'Semaine prochaine', + :this_month => 'Ce Mois', + :prev_month => 'Mois dernier', + :next_month => 'Mois prochain', + :this_year => 'Cette Année', + :prev_year => 'Année dernière', + :next_year => 'Année prochaine', + :past => 'Passé', + :future => 'Futur', + :range => 'Intervale', + :seconds => 'Secondes', :minutes => 'Minutes', - :hours => 'Hours', - :days => 'Days', - :weeks => 'Weeks', - :months => 'Months', - :years => 'Years', - :optional_attributes => 'Further Options', - :null => 'Null', - :not_null => 'Not Null', + :hours => 'Heures', + :days => 'Jours', + :weeks => 'Semaines', + :months => 'Mois', + :years => 'Années', + :optional_attributes => 'Options additionnelles', + :null => 'Nulle', + :not_null => 'Non Nulle', :date_picker_options => { :weekHeader => 'Sm', :firstDay => 1, @@ -99,18 +105,18 @@ :errors => { :template => { :header => { - :one => "1 error prohibited this %{model} from being saved.", - :other => "%{count} errors prohibited this %{model} from being saved" + :one => "1 erreur interdit ce(tte) %{model} d'être sauvegardé.", + :other => "%{count} erreurs interdit ce(tte) %{model} d'être sauvegardé" }, - :body => "There were problems with the following fields:" + :body => "Il y avait des problèmes avec les champs suivants :" } }, # error_messages - :cant_destroy_record => "%{record} can't be destroyed", + :cant_destroy_record => "%{record} ne peut être supprimé", :internal_error => 'Erreur de la requête (code 500, Erreur interne)', :version_inconsistency => "Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer.", - :record_not_saved => 'Failed to save record cause of an unknown error', - :no_authorization_for_action => "No Authorization for action %{action}" + :record_not_saved => "Impossible d'enregistrer l'enregistrement à cause d'une erreur inconnue", + :no_authorization_for_action => "Aucune autorisation pour l'action %{action}" } } } From 0ac709dd16aafb2e91990d9ed3fa814d7c2d3140 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 24 Feb 2011 13:39:41 +0100 Subject: [PATCH 1042/2024] base_form might be used without having to define an official as action --- frontends/default/views/_base_form.html.erb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index fcf71e033a..2775d69845 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -1,21 +1,27 @@ <% url_options ||= params_for(:action => form_action) xhr = request.xhr? if xhr.nil? - as_action_config = active_scaffold_config.send(form_action) + if active_scaffold_config.actions.include? form_action + multipart ||= active_scaffold_config.send(form_action).multipart? + columns ||= active_scaffold_config.send(form_action).columns + else + multipart ||= false + columns ||= nil + end body_partial ||= 'form' %> <%= options = {:onsubmit => onsubmit, :id => element_form_id(:action => form_action), - :multipart => as_action_config.multipart?, + :multipart => multipart, :class => "as_form #{form_action.to_s}", :method => method, 'data-loading' => true} cancel_options = {:class => 'as_cancel', 'data-refresh' => false} cancel_options[:remote] = true if xhr #cancel link does nt have to care about multipart forms -if xhr && as_action_config.multipart? # file_uploads +if xhr && multipart # file_uploads form_remote_upload_tag url_options.merge({:iframe => true}), options else - options[:remote] = true if xhr && !as_action_config.multipart? + options[:remote] = true if xhr && !multipart form_tag url_options, options end -%> @@ -33,7 +39,7 @@ end <% end -%> </div> - <%= render :partial => body_partial, :locals => { :columns => as_action_config.columns } %> + <%= render :partial => body_partial, :locals => { :columns => columns } %> <p class="form-footer"> <%= submit_tag as_(form_action), :class => "submit" %> From e3b5808a3628cb5b375c0fd3faf38569587d4f1a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 28 Feb 2011 17:20:38 +0100 Subject: [PATCH 1043/2024] use column_authorized_for_update in subform on update action --- frontends/default/views/_horizontal_subform_record.html.erb | 2 +- frontends/default/views/_vertical_subform_record.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index 1388f92b9d..677aac3bff 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -1,6 +1,6 @@ <% record_column = column -%> <% readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) -%> -<% crud_type = @record.new_record? ? :create : (readonly ? :read : nil) -%> +<% crud_type = @record.new_record? ? :create : (readonly ? :read : :update) -%> <% show_actions = false -%> <% config = active_scaffold_config_for(@record.class) -%> <tr class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index c0d32ea9b3..fedcfcfe73 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -1,7 +1,7 @@ <% record_column = column readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) - crud_type = @record.new_record? ? :create : (readonly ? :read : nil) + crud_type = @record.new_record? ? :create : (readonly ? :read : :update) show_actions = false config = active_scaffold_config_for(@record.class) -%> From a70913f304972e82cbb70eda8a07f54cdaa9f554 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 1 Mar 2011 08:22:15 +0100 Subject: [PATCH 1044/2024] use crud_type :update in subforms for update action --- frontends/default/views/_horizontal_subform_record.html.erb | 2 +- frontends/default/views/_vertical_subform_record.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index 1bdb9ff197..7770cf5359 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -1,6 +1,6 @@ <% record_column = column readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) - crud_type = @record.new_record? ? :create : (readonly ? :read : nil) + crud_type = @record.new_record? ? :create : (readonly ? :read : :update) show_actions = false config = active_scaffold_config_for(@record.class) options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index 1aa55034c2..30285ddac9 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -1,7 +1,7 @@ <% record_column = column readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) - crud_type = @record.new_record? ? :create : (readonly ? :read : nil) + crud_type = @record.new_record? ? :create : (readonly ? :read : :update) show_actions = false config = active_scaffold_config_for(@record.class) options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) From 9ea9ffc59864330c1dc5b3b557f31fc827a1745b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 1 Mar 2011 08:34:33 +0100 Subject: [PATCH 1045/2024] css class FieldWithErrors renamed to field_with_errors in rails 3.0.3 --- frontends/default/stylesheets/stylesheet.css | 5 ++++- .../stylesheets/active_scaffold/default/stylesheet.css | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index e8fe3d49fa..5d9f370eae 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -793,8 +793,11 @@ padding: 2px; } .active-scaffold .fieldWithErrors input, +.active-scaffold .field_with_errors input, .active-scaffold .fieldWithErrors textarea, -.active-scaffold .fieldWithErrors select { +.active-scaffold .field_with_errors textarea, +.active-scaffold .fieldWithErrors select, +.active-scaffold .field_with_errors select { border: solid 1px #f00; } diff --git a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css index b59b6a66f0..62537e54f9 100644 --- a/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +++ b/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css @@ -662,8 +662,11 @@ padding: 2px; } .active-scaffold .fieldWithErrors input, +.active-scaffold .field_with_errors input, .active-scaffold .fieldWithErrors textarea, -.active-scaffold .fieldWithErrors select { +.active-scaffold .field_with_errors textarea, +.active-scaffold .fieldWithErrors select, +.active-scaffold .field_with_errors select { border: solid 1px #f00; } From 3c7f70918385fcd7f87bdb5ed32903f0437ec2e6 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Wed, 2 Mar 2011 16:32:37 +0200 Subject: [PATCH 1046/2024] fix carrierwave bug: "changing file on edit delets both old one and new one" this bug was introduced in my last carrierwave bridge commit (refactor) --- .../bridges/carrierwave/lib/form_ui.rb | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb index 6c2be1912d..d8ba21f3e1 100644 --- a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +++ b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb @@ -3,14 +3,8 @@ module Helpers module FormColumnHelpers def active_scaffold_input_carrierwave(column, options) options = active_scaffold_input_text_options(options) - input = file_field(:record, column.name, options) carrierwave = @record.send("#{column.name}") if carrierwave.file.present? && !carrierwave.file.empty? - if ActiveScaffold.js_framework == :jquery - js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;"; - else - js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;"; - end remove_field_options = { :name => options[:name].gsub(/\[#{column.name}\]$/, "[remove_#{column.name}]"), @@ -23,6 +17,15 @@ def active_scaffold_input_carrierwave(column, options) :id => options[:id] + '_cache' } + if ActiveScaffold.js_framework == :jquery + js_remove_file_code = "$(this).prev('input#remove_#{options[:id]}').val('true'); $(this).parent().hide().next().show(); return false;"; + js_dont_remove_file_code = "$(this).parents('div.carrierwave_controls').find('input#remove_#{options[:id]}').val('false'); return false;"; + else + js_remove_file_code = "$(this).previous('input#remove_#{options[:id]}').value='true'; $(this).up().hide().next().show(); return false;"; + js_dont_remove_file_code = "$(this).up('div.carrierwave_controls').down('input#remove_#{options[:id]}').value='false'; return false;"; + end + + input = file_field(:record, column.name, options.merge(:onchange => js_dont_remove_file_code)) content_tag( :div, content_tag(:div, ( get_column_value(@record, column) + " | " + @@ -30,10 +33,11 @@ def active_scaffold_input_carrierwave(column, options) hidden_field(:record, "remove_#{column.name}", remove_field_options) + content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}) ).html_safe - ) + content_tag(:div, input, :style => "display: none") + ) + content_tag(:div, input, :style => "display: none"), + :class => 'carrierwave_controls' ) else - input + file_field(:record, column.name, options) end end end From 660623c0a11cf3efcab78492d7be501adf0feac0 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Wed, 2 Mar 2011 16:35:10 +0200 Subject: [PATCH 1047/2024] use "assoc.build" instead of "assoc.klass.new" better wireing, helps cancan would be nice to chain upto "assoc_controller.new_model" .. --- frontends/default/views/_form_association.html.erb | 5 +++-- frontends/default/views/_horizontal_subform.html.erb | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index 8ede212341..76b7ea9437 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -2,8 +2,9 @@ parent_record = @record associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) - -associated << column.association.klass.new if column.show_blank_record? associated +if column.show_blank_record? associated + associated << column.singular_association? ? parent_record.send("build_#{column.name}".to_sym) : parent_record.send(column.name).build +end subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_record.id || 99999999999})}-div" -%> <h5><%= column.label -%></h5> diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index 89186df852..b2b2b35de2 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -1,5 +1,5 @@ <table cellpadding="0" cellspacing="0"> - <% @record = column.association.klass.new -%> + <% @record = column.singular_association? ? parent_record.send("build_#{column.name}".to_sym) : parent_record.send(column.name).build -%> <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record} %> <tbody id="<%= sub_form_list_id(:association => column.name) %>"> From 72c2f56cb99433aad30873b2b359b41ca9b49b6b Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Wed, 2 Mar 2011 17:59:29 +0200 Subject: [PATCH 1048/2024] build instead of new in edit_association --- lib/active_scaffold/actions/subform.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index b7478f46d2..370e76d0c3 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -6,7 +6,7 @@ def edit_associated # NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all. @record = @column.association.klass.find(params[:associated_id]) if params[:associated_id] - @record ||= @column.association.klass.new + @record ||= @column.singular_association? ? @parent_record.send("build_#{@column.name}".to_sym) : @parent_record.send(@column.name).build @scope = "[#{@column.name}]" @scope += (@record.new_record?) ? "[#{(Time.now.to_f*1000).to_i.to_s}]" : "[#{@record.id}]" if @column.plural_association? From d07bf32cb87705ef3e94eaee4b7b29bb20fd3989 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 3 Mar 2011 09:19:42 +0100 Subject: [PATCH 1049/2024] Revert prev commit cause failed to work with polymorphic associations --- frontends/default/views/_form_association.html.erb | 2 +- frontends/default/views/_horizontal_subform.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index 76b7ea9437..98e9f7f789 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -3,7 +3,7 @@ parent_record = @record associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) if column.show_blank_record? associated - associated << column.singular_association? ? parent_record.send("build_#{column.name}".to_sym) : parent_record.send(column.name).build + associated << column.association.klass.new end subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_record.id || 99999999999})}-div" -%> diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index b2b2b35de2..a2ab9191bf 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -1,5 +1,5 @@ <table cellpadding="0" cellspacing="0"> - <% @record = column.singular_association? ? parent_record.send("build_#{column.name}".to_sym) : parent_record.send(column.name).build -%> + <% @record = column.association.klass.new %> <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record} %> <tbody id="<%= sub_form_list_id(:association => column.name) %>"> From 1cd454a29a4af46390d467f63d1bfd8388a91333 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Thu, 3 Mar 2011 19:57:40 +0200 Subject: [PATCH 1050/2024] polymorphic able build instead of new --- frontends/default/views/_form_association.html.erb | 6 +++++- frontends/default/views/_horizontal_subform.html.erb | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index 98e9f7f789..895148d4c9 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -3,7 +3,11 @@ parent_record = @record associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) if column.show_blank_record? associated - associated << column.association.klass.new + associated << if column.singular_association? + parent_record.send("build_#{column.name}".to_sym) + else + parent_record.send(column.name).build + end end subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_record.id || 99999999999})}-div" -%> diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index a2ab9191bf..04c72a7b03 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -1,5 +1,11 @@ <table cellpadding="0" cellspacing="0"> - <% @record = column.association.klass.new %> + <% + @record = if column.singular_association? + parent_record.send("build_#{column.name}".to_sym) + else + parent_record.send(column.name).build + end + -%> <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record} %> <tbody id="<%= sub_form_list_id(:association => column.name) %>"> From 465118b087359984f08942ac1640399e67135e6d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 3 Mar 2011 21:20:40 +0100 Subject: [PATCH 1051/2024] Bugfix: habtm associations are saved altough validation failed (issue 92 reported and fixed by clyfe) --- lib/active_scaffold/actions/update.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 13de781c51..b69eaf88ef 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -75,18 +75,22 @@ def do_edit # If you want to customize this algorithm, consider using the +before_update_save+ callback def do_update do_edit - @record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record]) update_save end def update_save begin active_scaffold_config.model.transaction do + @record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record]) unless options[:no_record_param_update] before_update_save(@record) self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit if successful? @record.save! and @record.save_associated! after_update_save(@record) + else + # some associations such as habtm are saved before saved is called on parent object + # we have to revert these changes if validation fails + raise ActiveRecord::Rollback, "don't save habtm associations unless record is valid" end end rescue ActiveRecord::RecordInvalid From a3fd7f256d847863fe7a331dcde76cc3474914ee Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Fri, 4 Mar 2011 14:52:15 +0200 Subject: [PATCH 1052/2024] apply the same if-instead-ternary strategy to edit_associated just in case --- lib/active_scaffold/actions/subform.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index 370e76d0c3..b25a41d38e 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -6,7 +6,11 @@ def edit_associated # NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all. @record = @column.association.klass.find(params[:associated_id]) if params[:associated_id] - @record ||= @column.singular_association? ? @parent_record.send("build_#{@column.name}".to_sym) : @parent_record.send(@column.name).build + @record ||= if @column.singular_association? + @parent_record.send("build_#{@column.name}".to_sym) + else + @parent_record.send(@column.name).build + end @scope = "[#{@column.name}]" @scope += (@record.new_record?) ? "[#{(Time.now.to_f*1000).to_i.to_s}]" : "[#{@record.id}]" if @column.plural_association? From 3681f0fa03e82d4be0b9bb2284d6ce1e7e78dacb Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Fri, 4 Mar 2011 14:56:45 +0200 Subject: [PATCH 1053/2024] refactor edit_associated in AS do_action style to allow more granular overrides --- lib/active_scaffold/actions/subform.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index b25a41d38e..5d1f015552 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -1,6 +1,13 @@ module ActiveScaffold::Actions module Subform def edit_associated + do_edit_associated + render :action => 'edit_associated' + end + + protected + + def do_edit_associated @parent_record = params[:id].nil? ? new_model : find_if_allowed(params[:id], :update) @column = active_scaffold_config.columns[params[:association]] @@ -14,8 +21,7 @@ def edit_associated @scope = "[#{@column.name}]" @scope += (@record.new_record?) ? "[#{(Time.now.to_f*1000).to_i.to_s}]" : "[#{@record.id}]" if @column.plural_association? - - render :action => 'edit_associated' end + end end From f8dd91963c695ebd7159e02ce43da7d3e556e33a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 4 Mar 2011 22:42:48 +0100 Subject: [PATCH 1054/2024] extract method activescaffold_search_range_comparator_options --- .../helpers/search_column_helpers.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 79f1f7c6f8..588ca137ec 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -121,15 +121,20 @@ def field_search_params_range_values(column) return values[:opt], values[:from], values[:to] end - def active_scaffold_search_range(column, options) - opt_value, from_value, to_value = field_search_params_range_values(column) - - text_field_size = 10 + def active_scaffold_search_range_comparator_options(column) select_options = ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} if column.column && column.column.text? select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} - text_field_size = 15 end + select_options + end + + def active_scaffold_search_range(column, options) + opt_value, from_value, to_value = field_search_params_range_values(column) + + select_options = active_scaffold_search_range_comparator_options(column) + text_field_size = ((column.column && column.column.text?) ? 15 : 10) + from_value = controller.class.condition_value_for_numeric(column, from_value) to_value = controller.class.condition_value_for_numeric(column, to_value) from_value = format_number_value(from_value, column.options) if from_value.is_a?(Numeric) From d3ea0dbf23de96ddda845548a4ab3df68800bada Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 4 Mar 2011 22:53:33 +0100 Subject: [PATCH 1055/2024] add method action_formats --- lib/active_scaffold/actions/core.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index e651c5ebe1..0f4a6b6d30 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -152,12 +152,20 @@ def new_model private def respond_to_action(action) respond_to do |type| - send("#{action}_formats").each do |format| + action_formats.each do |format| type.send(format){ send("#{action}_respond_to_#{format}") } end end end + def action_formats + @action_formats ||= if respond_to? "#{action_name}_formats" + send("#{action_name}_formats") + else + (default_formats + active_scaffold_config.formats).uniq + end + end + def response_code_for_rescue(exception) case exception when ActiveScaffold::RecordNotAllowed From 4334aa32f5b0d6b1d26433a3ab8e9743900e7386 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 4 Mar 2011 23:09:55 +0100 Subject: [PATCH 1056/2024] active_scaffold_controller generator should also generate a helper file --- .../active_scaffold_controller_generator.rb | 1 + lib/generators/active_scaffold_controller/templates/helper.rb | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 lib/generators/active_scaffold_controller/templates/helper.rb diff --git a/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb b/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb index 232f9700cc..2a685123c4 100644 --- a/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +++ b/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb @@ -16,6 +16,7 @@ def self.source_root def create_controller_files template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb") + template 'helper.rb', File.join('app/helpers', class_path, "#{controller_file_name}_helper.rb") end hook_for :test_framework, :as => :scaffold diff --git a/lib/generators/active_scaffold_controller/templates/helper.rb b/lib/generators/active_scaffold_controller/templates/helper.rb new file mode 100644 index 0000000000..ed5759ea14 --- /dev/null +++ b/lib/generators/active_scaffold_controller/templates/helper.rb @@ -0,0 +1,2 @@ +module <%= controller_class_name %>Helper +end \ No newline at end of file From 085b341f2db6475c99574be28f441a680a01c73c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 5 Mar 2011 10:42:30 +0100 Subject: [PATCH 1057/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 05828ef615..3cee0ef9ad 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 13 + PATCH = 14 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From a0fb80effa10cbc29e739e556e9940b2e2a7c17c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 5 Mar 2011 10:42:44 +0100 Subject: [PATCH 1058/2024] Regenerate gemspec for version 3.0.14 --- active_scaffold_vho.gemspec | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index 1282560885..2783cac0f8 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.13" + s.version = "3.0.14" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] - s.date = %q{2011-02-18} + s.date = %q{2011-03-05} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.email = %q{activescaffold@googlegroups.com} s.extra_rdoc_files = [ @@ -225,6 +225,7 @@ Gem::Specification.new do |s| "lib/generators/active_scaffold_controller/USAGE", "lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb", "lib/generators/active_scaffold_controller/templates/controller.rb", + "lib/generators/active_scaffold_controller/templates/helper.rb", "lib/generators/active_scaffold_setup/USAGE", "lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb", "public/blank.html", From 61fd032e007ab7da9f8b4b367dbcb994a6ccf9e2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 5 Mar 2011 16:27:38 +0100 Subject: [PATCH 1059/2024] Bugfix: search_range values have to be set to nil for blank values --- lib/active_scaffold/helpers/search_column_helpers.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 588ca137ec..6f716cd6ce 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -118,7 +118,8 @@ def active_scaffold_search_null(column, options) def field_search_params_range_values(column) values = field_search_params[column.name] return nil if values.nil? - return values[:opt], values[:from], values[:to] + return values[:opt], (values[:from].blank? ? nil : values[:from]), (values[:to].blank? ? nil : values[:to]) + end def active_scaffold_search_range_comparator_options(column) From 958f5482533369ec16b6e9efde90bbbeb3de05e4 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 5 Mar 2011 16:34:21 +0100 Subject: [PATCH 1060/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 3cee0ef9ad..a5b92aeb47 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 14 + PATCH = 15 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 7d4b9477f42a91937507a6abcb2ed2cab312271e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 5 Mar 2011 16:39:55 +0100 Subject: [PATCH 1061/2024] Regenerate gemspec for version 3.0.15 --- active_scaffold_vho.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index 2783cac0f8..418685e3a1 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.14" + s.version = "3.0.15" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] From db23b8ed8cf70c5e84d0d5dd63159cb97860b681 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Mar 2011 10:23:06 +0100 Subject: [PATCH 1062/2024] Bugfix: inplace_edit? failed to check if user is authorized (reported by mobileMike) --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 44f6b65baf..6c4f4d9a23 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -247,7 +247,7 @@ def cache_association(value, column) def inplace_edit?(record, column) if column.inplace_edit editable = controller.send(:update_authorized?, record) if controller.respond_to?(:update_authorized?) - editable = record.authorized_for?(:action => :update, :column => column.name) if editable.nil? || editable == true + editable = record.authorized_for?(:crud_type => :update, :column => column.name) if editable.nil? || editable == true editable end end From 30e3d426e73d112c6f1c021fc7ca3255a8dd2e91 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Mar 2011 12:32:55 +0100 Subject: [PATCH 1063/2024] Bugfix: user defined select_options failed for value= false (reported by hoenth) --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 9386502f3f..ad10232317 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -136,7 +136,7 @@ def active_scaffold_checkbox_list(column, select_options, associated_ids, option end def active_scaffold_translated_option(column, text, value = nil) - value ||= text + value = text if value.nil? [(text.is_a?(Symbol) ? column.active_record_class.human_attribute_name(text) : text), value] end From b313b5a7ab449b8e64ae44b2d1993c014198a87c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Mar 2011 16:07:05 +0100 Subject: [PATCH 1064/2024] Bugfix: update was broken due to a commit three days ago (reported by MrJoy) --- lib/active_scaffold/actions/update.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index b69eaf88ef..be8a2758a6 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -78,7 +78,7 @@ def do_update update_save end - def update_save + def update_save(options = {}) begin active_scaffold_config.model.transaction do @record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record]) unless options[:no_record_param_update] From cb2304cfda9b389ece50c3e5fa34876d713b423f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Mar 2011 16:10:35 +0100 Subject: [PATCH 1065/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index a5b92aeb47..6e43c1f741 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 15 + PATCH = 16 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From b436454d52715b9bce1a80ffc2e0c93ac795757b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 7 Mar 2011 16:10:44 +0100 Subject: [PATCH 1066/2024] Regenerate gemspec for version 3.0.16 --- active_scaffold_vho.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index 418685e3a1..957a072a3a 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.15" + s.version = "3.0.16" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] - s.date = %q{2011-03-05} + s.date = %q{2011-03-07} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.email = %q{activescaffold@googlegroups.com} s.extra_rdoc_files = [ From f8d938803db720994945191bf1196366a34de0a1 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Thu, 10 Mar 2011 22:52:55 +0200 Subject: [PATCH 1067/2024] cacan bridge controller auth improvement --- lib/active_scaffold/bridges/cancan/bridge.rb | 5 +-- .../bridges/cancan/lib/cancan_bridge.rb | 32 ++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/bridges/cancan/bridge.rb b/lib/active_scaffold/bridges/cancan/bridge.rb index 722d086e35..bbae68a467 100644 --- a/lib/active_scaffold/bridges/cancan/bridge.rb +++ b/lib/active_scaffold/bridges/cancan/bridge.rb @@ -2,8 +2,9 @@ install do require File.join(File.dirname(__FILE__), "lib", "cancan_bridge.rb") - ActiveScaffold::Actions::Core.send :include, ActiveScaffold::CancanBridge::Core - ActiveScaffold::Actions::Nested.send :include, ActiveScaffold::CancanBridge::Core + ActiveScaffold::ClassMethods.send :include, ActiveScaffold::CancanBridge::ClassMethods + ActiveScaffold::Actions::Core.send :include, ActiveScaffold::CancanBridge::Actions::Core + ActiveScaffold::Actions::Nested.send :include, ActiveScaffold::CancanBridge::Actions::Core ActionController::Base.send :include, ActiveScaffold::CancanBridge::ModelUserAccess::Controller ActiveRecord::Base.send :include, ActiveScaffold::CancanBridge::ModelUserAccess::Model ActiveRecord::Base.send :include, ActiveScaffold::CancanBridge::ActiveRecord diff --git a/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb b/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb index 33f777d041..1d14717840 100644 --- a/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb +++ b/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb @@ -1,14 +1,35 @@ module ActiveScaffold module CancanBridge - module Core + # controller level authorization + # As already has callbacks to ensure authorization at controller method via "authorization_method" + # but let's include this too, just in case, no sure how performance is affected tough :TODO benchmark + module ClassMethods extend ActiveSupport::Concern included do - alias_method_chain :beginning_of_chain, :cancan + alias_method_chain :active_scaffold, :cancan end - # :TODO can this be expanded more ? - def beginning_of_chain_with_cancan - beginning_of_chain_without_cancan.accessible_by(current_ability) + + def active_scaffold_with_cancan(model_id = nil, &block) + active_scaffold_without_cancan(model_id, &block) + authorize_resource( + :class => active_scaffold_config.model, + :instance => :record + ) + end + end + + # beginning of chain integration + module Actions + module Core + extend ActiveSupport::Concern + included do + alias_method_chain :beginning_of_chain, :cancan + end + # :TODO can this be expanded more ? + def beginning_of_chain_with_cancan + beginning_of_chain_without_cancan.accessible_by(current_ability) + end end end @@ -47,6 +68,7 @@ def current_ability; self.class.current_ability end end + # plug into AS#authorized_for calls module ActiveRecord extend ActiveSupport::Concern included do From 0acc529c7a0f7ad3c653fc57cdc2386e5e689e8c Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Thu, 10 Mar 2011 22:53:43 +0200 Subject: [PATCH 1068/2024] carrierwave tiny refactor --- lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb | 2 +- lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb index d8ba21f3e1..9042f95820 100644 --- a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +++ b/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb @@ -4,7 +4,7 @@ module FormColumnHelpers def active_scaffold_input_carrierwave(column, options) options = active_scaffold_input_text_options(options) carrierwave = @record.send("#{column.name}") - if carrierwave.file.present? && !carrierwave.file.empty? + if !carrierwave.file.blank? remove_field_options = { :name => options[:name].gsub(/\[#{column.name}\]$/, "[remove_#{column.name}]"), diff --git a/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb b/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb index a6129d56d6..37f2cb2072 100644 --- a/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +++ b/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb @@ -3,7 +3,7 @@ module Helpers module ListColumnHelpers def active_scaffold_column_carrierwave(column, record) carrierwave = record.send("#{column.name}") - return nil unless carrierwave.file.present? && !carrierwave.file.empty? + return nil unless !carrierwave.file.blank? thumbnail_style = ActiveScaffold::Bridges::Carrierwave::Lib::CarrierwaveBridgeHelpers.thumbnail_style content = if carrierwave.versions.keys.include?(thumbnail_style) image_tag(carrierwave.url(thumbnail_style), :border => 0).html_safe From 758617108688a24a9e151c37820dfa25f85e17c1 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Thu, 10 Mar 2011 22:55:47 +0200 Subject: [PATCH 1069/2024] allow hash includes to columns http://guides.rubyonrails.org/active_record_querying.html#nested-associations-hash now we can do conf.column[:col].includes = {:users => {:roles, :foos}} --- lib/active_scaffold/data_structures/column.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 5daaf0cb0f..0a1beabce3 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -153,7 +153,10 @@ def calculation? # a collection of associations to pre-load when finding the records on a page attr_reader :includes def includes=(value) - @includes = value.is_a?(Array) ? value : [value] # automatically convert to an array + @includes = case value + when Array, Hash then value + else [value] # automatically convert to an array + end end # a collection of columns to load when eager loading is disabled, if it's nil all columns will be loaded From 58248a55ed2e2f8ab255b494f8cf45a3df90da1c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 12 Mar 2011 19:17:07 +0100 Subject: [PATCH 1070/2024] Bugfix: column collapsed failed in ie for field_search --- frontends/default/views/_field_search.html.erb | 2 +- frontends/default/views/_form.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_field_search.html.erb b/frontends/default/views/_field_search.html.erb index 4691d25019..dba8c5880f 100644 --- a/frontends/default/views/_field_search.html.erb +++ b/frontends/default/views/_field_search.html.erb @@ -14,7 +14,7 @@ form_tag url_options, options %> <% unless hiddens.empty? -%> <li class="sub-section"> <h5><%= as_(:optional_attributes) %></h5> - <ol id ="<%= sub_section_id(:sub_section => 'further_options') %>" class="form" 'style="display: none;"'> + <ol id ="<%= sub_section_id(:sub_section => 'further_options') %>" class="form" style="display:none;"> <% hiddens.each do |column| -%> <%= render :partial => 'search_attribute', :locals => {:column => column} %> <% end -%> diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index 2884ab0374..7ba406c79a 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -1,5 +1,5 @@ <% subsection_id ||= nil %> -<ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= 'style="display: none;"' if columns.collapsed -%>> +<ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= "style=\"display: none;\"" if columns.collapsed %>> <% columns.each :for => @record do |column| %> <% renders_as = column_renders_as(column) %> <% if renders_as == :subsection -%> From 458e7bb12697014f71c2472f6dfdf38bba1353e1 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Mar 2011 15:08:26 +0100 Subject: [PATCH 1071/2024] add option to exclude bridges from loading --- lib/active_scaffold.rb | 14 ++++++++++++++ lib/active_scaffold/bridges/bridge.rb | 8 +++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 2d6586bef8..7b9ce64f1b 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -107,6 +107,20 @@ def self.js_framework @@js_framework ||= :prototype end + # exclude bridges you do not need + # name of bridge subdir should be used to exclude it + # eg + # ActiveScaffold.exclude_bridges = [:cancan, :ancestry] + # if you are using Activescaffold as a gem add to initializer + # if you are using Activescaffold as a plugin add to active_scaffold_env.rb + def self.exclude_bridges=(bridges) + @@exclude_bridges = bridges + end + + def self.exclude_bridges + @@exclude_bridges ||= [] + end + def self.root File.dirname(__FILE__) + "/.." end diff --git a/lib/active_scaffold/bridges/bridge.rb b/lib/active_scaffold/bridges/bridge.rb index b249a92f64..78c8249294 100644 --- a/lib/active_scaffold/bridges/bridge.rb +++ b/lib/active_scaffold/bridges/bridge.rb @@ -49,5 +49,11 @@ def self.run_all require File.join(File.dirname(__FILE__), 'shared', 'date_bridge.rb') Dir[File.join(File.dirname(__FILE__), "*/bridge.rb")].each{|bridge_require| - require bridge_require + load_bridge = true + unless ActiveScaffold.exclude_bridges.empty? + match = bridge_require.match('bridges\/(.*)\/bridge.rb') + bridge_name = match[1] ? match[1] : nil + load_bridge = ActiveScaffold.exclude_bridges.exclude?(bridge_name.to_sym) if bridge_name + end + require bridge_require if load_bridge == true } \ No newline at end of file From 60d5502e284bc8149c6f4da7a9783a6c33f89605 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Mar 2011 16:14:41 +0100 Subject: [PATCH 1072/2024] do not use to_a use all instead --- frontends/default/views/_form_association.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index 895148d4c9..6bfcc8710b 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -1,6 +1,6 @@ <% parent_record = @record -associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a +associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).all associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) if column.show_blank_record? associated associated << if column.singular_association? From 1f97e53bc848883bfe14176f2530e6e5a3d9209e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Mar 2011 16:48:01 +0100 Subject: [PATCH 1073/2024] Bugfix: do not rebuild associated record if we have already build it --- frontends/default/views/_horizontal_subform.html.erb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index 04c72a7b03..75ff1999ae 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -1,9 +1,13 @@ <table cellpadding="0" cellspacing="0"> - <% - @record = if column.singular_association? - parent_record.send("build_#{column.name}".to_sym) + <% + if associated.empty? + @record = if column.singular_association? + parent_record.send("build_#{column.name}".to_sym) + else + parent_record.send(column.name).build + end else - parent_record.send(column.name).build + @record = associated.last end -%> <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record} %> From 3610d2ed10adc2611b3365a521177e2ac790b289 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Mar 2011 21:02:22 +0100 Subject: [PATCH 1074/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 6e43c1f741..012d32eb85 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 16 + PATCH = 17 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 45451d9636725a9e75c2bb9cad4f5d0edf795fa2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 14 Mar 2011 21:02:34 +0100 Subject: [PATCH 1075/2024] Regenerate gemspec for version 3.0.17 --- active_scaffold_vho.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index 957a072a3a..501aa297a1 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.16" + s.version = "3.0.17" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] - s.date = %q{2011-03-07} + s.date = %q{2011-03-14} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.email = %q{activescaffold@googlegroups.com} s.extra_rdoc_files = [ From 759ced44c691d2b218175b0d8bd33ec053dd977d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 25 Mar 2011 09:13:59 +0100 Subject: [PATCH 1076/2024] Bugfix: in_place_edit eid parameter fix (issue: 129 reported by bardbess) --- frontends/default/javascripts/jquery/active_scaffold.js | 2 +- frontends/default/javascripts/prototype/active_scaffold.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 9e692f3b7e..4b61e02289 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -168,7 +168,7 @@ $(document).ready(function() { if (span.closest('div.active-scaffold').attr('data-eid')) { if (options['params'].length > 0) { - options['params'] += ";"; + options['params'] += "&"; } options['params'] += ("eid=" + span.closest('div.active-scaffold').attr('data-eid')); } diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 14ac0b0e62..2291eddec5 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -184,7 +184,7 @@ document.observe("dom:loaded", function() { if (span.up('div.active-scaffold').readAttribute('data-eid')) { if (options['params'].length > 0) { - options['params'] += ";"; + options['params'] += "&"; } options['params'] += ("eid=" + span.up('div.active-scaffold').readAttribute('data-eid')); } From a6523cee8e5ecd0e5723f0cef4afbe3af3fa0e48 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 26 Mar 2011 22:05:05 +0100 Subject: [PATCH 1077/2024] enhancement pass record to action_link_html --- lib/active_scaffold/helpers/view_helpers.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index a566f24e8f..244fa96277 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -134,12 +134,12 @@ def skip_action_link(link, *args) def render_action_link(link, url_options, record = nil, html_options = {}) url_options = action_link_url_options(link, url_options, record) html_options = action_link_html_options(link, url_options, record, html_options) - action_link_html(link, url_options, html_options) + action_link_html(link, url_options, html_options, record) end def render_group_action_link(link, url_options, options, record = nil) if link.type == :member && !options[:authorized] - action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}) + action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}, record) else render_action_link(link, url_options, record) end @@ -198,7 +198,7 @@ def get_action_link_id(url_options, record = nil, column = nil) action_link_id(action_id, id) end - def action_link_html(link, url, html_options) + def action_link_html(link, url, html_options, record) # issue 260, use url_options[:link] if it exists. This prevents DB data from being localized. label = url.delete(:link) if url.is_a?(Hash) label ||= link.label From 2b5cab33639c5ebf6702c6ee21d82224ee6ae7c0 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 26 Mar 2011 23:17:33 +0100 Subject: [PATCH 1078/2024] extract method update_refresh_list? --- frontends/default/views/on_update.js.rjs | 2 +- lib/active_scaffold/actions/update.rb | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.rjs index 5460d3f073..15ff9022ba 100644 --- a/frontends/default/views/on_update.js.rjs +++ b/frontends/default/views/on_update.js.rjs @@ -15,7 +15,7 @@ if controller.send :successful? end end #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} - elsif (active_scaffold_config.update.refresh_list) + elsif update_refresh_list? page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) else updated_row = render :partial => 'list_record', :locals => {:record => @record} diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index be8a2758a6..ad22cc5ef9 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -5,6 +5,7 @@ def self.included(base) base.verify :method => [:post, :put], :only => :update, :redirect_to => { :action => :index } + base.helper_method :update_refresh_list? end def edit @@ -49,7 +50,7 @@ def update_respond_to_html end end def update_respond_to_js - if successful? && active_scaffold_config.update.refresh_list && !render_parent? + if successful? && update_refresh_list? && !render_parent? do_search if respond_to? :do_search do_list end @@ -125,6 +126,11 @@ def before_update_save(record); end # override this method if you want to do something after the save def after_update_save(record); end + # should we refresh whole list after update operation + def update_refresh_list? + active_scaffold_config.update.refresh_list + end + # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def update_authorized?(record = nil) From e1c18313ca775ee125d62710f4b185a06c515d4f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 26 Mar 2011 23:58:25 +0100 Subject: [PATCH 1079/2024] Bugfix: if user specifies order, apply it correctly even if order key is first one in hash --- lib/active_scaffold/finder.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 78f149e48a..77b32e3ec0 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -298,8 +298,10 @@ def append_to_query(query, options) options.reject{|k, v| v.blank?}.inject(query) do |query, (k, v)| # default ordering of model has a higher priority than current queries ordering # fix this by removing existing ordering from arel - # will not work if order part is first one which is iterated - query = query.except(:order) if k.to_sym == :order && query.is_a?(ActiveRecord::Relation) + if k.to_sym == :order + query = query.where('1=1') unless query.is_a?(ActiveRecord::Relation) + query = query.except(:order) + end query.send((k.to_sym), v) end end From 86f40d0805cf787984482dbd4ffc033b8c2ca106 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sun, 27 Mar 2011 00:07:52 +0100 Subject: [PATCH 1080/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 012d32eb85..e4792888de 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 17 + PATCH = 18 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 693e93f11106c85db8366ebd1a26b598792d7c69 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sun, 27 Mar 2011 00:08:05 +0100 Subject: [PATCH 1081/2024] Regenerate gemspec for version 3.0.18 --- active_scaffold_vho.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index 501aa297a1..fb25d94149 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.17" + s.version = "3.0.18" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] - s.date = %q{2011-03-14} + s.date = %q{2011-03-27} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.email = %q{activescaffold@googlegroups.com} s.extra_rdoc_files = [ From b67797898f1b09e26be443ca72f0e350777cee64 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 30 Mar 2011 08:53:07 +0200 Subject: [PATCH 1082/2024] bugfix: duplicate id attribute --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 244fa96277..a4f232b08a 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -190,7 +190,7 @@ def get_action_link_id(url_options, record = nil, column = nil) id = url_options[:id] || url_options[:parent_id] id = "#{column.association.name}-#{record.id}" if column && column.plural_association? if record.try(column.association.name.to_sym).present? - id = "#{column.association.name}-#{record.send(column.association.name).id}" + id = "#{column.association.name}-#{record.send(column.association.name).id}-#{record.id}" else id = "#{column.association.name}-#{record.id}" unless record.nil? end if column && column.singular_association? From 17f4c52fd263a485664de1dd9e4f927ded278dce Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 30 Mar 2011 09:20:03 +0200 Subject: [PATCH 1083/2024] W3C Validator does nt like empty id attributes --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 6c4f4d9a23..684358902e 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -316,7 +316,7 @@ def mark_column_heading all_marked = (marked_records.length >= @page.pager.count) tag_options = {:id => "#{controller_id}_mark_heading", :class => "mark_heading in_place_editor_field"} tag_options['data-ie_url'] = url_for({:controller => params_for[:controller], :action => 'mark_all', :eid => params[:eid]}) - content_tag(:span, check_box_tag(nil, !all_marked, all_marked), tag_options) + content_tag(:span, check_box_tag("#{controller_id}_mark_heading_span_input", !all_marked, all_marked), tag_options) end def render_column_heading(column, sorting, sort_direction) From 3a2dccd4f9956e02b8f1a1c2636b9a59fcc8644d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 30 Mar 2011 09:33:47 +0200 Subject: [PATCH 1084/2024] Bugfix: duplicate id attribute values for batch_destroy action_links --- lib/active_scaffold/helpers/view_helpers.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index a4f232b08a..699cc7bcc5 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -194,6 +194,7 @@ def get_action_link_id(url_options, record = nil, column = nil) else id = "#{column.association.name}-#{record.id}" unless record.nil? end if column && column.singular_association? + id = "#{id}-#{url_options[:batch_scope].downcase}" if url_options[:batch_scope] action_id = "#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}#{url_options[:action].to_s}" action_link_id(action_id, id) end From 79420a6c07bf6dcfd2c348ecb97c7a1494f6a0b6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 7 Apr 2011 21:31:00 +0200 Subject: [PATCH 1085/2024] Bugfix: search range controls define a default range option --- lib/active_scaffold/helpers/search_column_helpers.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 6f716cd6ce..6df061b242 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -132,10 +132,16 @@ def active_scaffold_search_range_comparator_options(column) def active_scaffold_search_range(column, options) opt_value, from_value, to_value = field_search_params_range_values(column) - - select_options = active_scaffold_search_range_comparator_options(column) - text_field_size = ((column.column && column.column.text?) ? 15 : 10) + select_options = active_scaffold_search_range_comparator_options(column) + if column.column && column.column.text? + text_field_size = 15 + opt_value ||= '%?%' + else + text_field_size = 10 + opt_value ||= '=' + end + from_value = controller.class.condition_value_for_numeric(column, from_value) to_value = controller.class.condition_value_for_numeric(column, to_value) from_value = format_number_value(from_value, column.options) if from_value.is_a?(Numeric) From 147383803004d82c33ac842db51617760569d567 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 8 Apr 2011 16:05:10 +0200 Subject: [PATCH 1086/2024] add support for send_form_on_update_column --- .../default/javascripts/jquery/active_scaffold.js | 13 +++++++++++-- .../javascripts/prototype/active_scaffold.js | 12 ++++++++++-- lib/active_scaffold/actions/core.rb | 8 ++++++-- lib/active_scaffold/data_structures/column.rb | 4 ++++ lib/active_scaffold/helpers/form_column_helpers.rb | 1 + 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 4b61e02289..a74b07f20c 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -216,10 +216,19 @@ $(document).ready(function() { $('input.update_form, select.update_form').live('change', function(event) { var element = $(this); var as_form = element.closest('form.as_form'); + var params = null; + + if (element.attr('data-update_send_form')) { + params = as_form.serialize(); + params += '&' + $.param({source_id: element.attr('id')}); + } else { + params = {value: element.val()}; + params.source_id = element.attr('id'); + } + $.ajax({ url: element.attr('data-update_url'), - data: {value: element.val(), - source_id: element.attr('id')}, + data: params, beforeSend: function(event) { element.nextAll('img.loading-indicator').css('visibility','visible'); ActiveScaffold.disable_form(as_form) diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 2291eddec5..18ad32a24d 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -239,10 +239,18 @@ document.observe("dom:loaded", function() { document.on('change', 'input.update_form, select.update_form', function(event) { var element = event.findElement(); var as_form = element.up('form.as_form'); - + var params = null; + + if (element.hasAttribute('data-update_send_form')) { + params = as_form.serialize(true); + } else { + params = {value: element.getValue()}; + } + params.source_id = element.readAttribute('id'); + new Ajax.Request(element.readAttribute('data-update_url'), { method: 'get', - parameters: {value: element.getValue(), source_id: element.readAttribute('id')}, + parameters: params, onLoading: function(response) { element.next('img.loading-indicator').style.visibility = 'visible'; as_form.disable(); diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 0f4a6b6d30..cf7ca24486 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -32,8 +32,12 @@ def render_field_for_update_columns @record = new_model column = active_scaffold_config.columns[params[:column]] unless column.nil? - value = column_value_from_param_value(@record, column, params[:value]) - @record.send "#{column.name}=", value + if column.send_form_on_update_column + @record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record]) + else + value = column_value_from_param_value(@record, column, params[:value]) + @record.send "#{column.name}=", value + end after_render_field(@record, column) source_id = params.delete(:source_id) render :partial => "render_field", :collection => Array(params[:update_columns]), :content_type => 'text/javascript', :locals => {:source_id => source_id} diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 0a1beabce3..9246eeea0b 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -62,6 +62,10 @@ def update_columns=(column_names) @update_columns = Array(column_names) end + # send all the form instead of only new value when this column change + cattr_accessor :send_form_on_update_column + attr_accessor :send_form_on_update_column + # sorting on a column can be configured four ways: # sort = true default, uses intelligent sorting sql default # sort = false sometimes sorting doesn't make sense diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index ad10232317..4298e0dcf0 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -86,6 +86,7 @@ def update_columns_options(column, scope, options) options[:class] = "#{options[:class]} update_form".strip options['data-update_url'] = url_for(url_params) + options['data-update_send_form'] = true if column.send_form_on_update_column end options end From fee1b1c02c98bafc8e4690da36e88170d7aa9bd4 Mon Sep 17 00:00:00 2001 From: "Ubuntu.10.10" <clyfe@ubuntu.(none)> Date: Wed, 13 Apr 2011 04:37:11 -0700 Subject: [PATCH 1087/2024] allow implicit rendering to work --- lib/active_scaffold/extensions/action_controller_rendering.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_controller_rendering.rb b/lib/active_scaffold/extensions/action_controller_rendering.rb index 2264ab5a1d..161803efa5 100644 --- a/lib/active_scaffold/extensions/action_controller_rendering.rb +++ b/lib/active_scaffold/extensions/action_controller_rendering.rb @@ -5,8 +5,9 @@ def render_with_active_scaffold(*args, &block) if self.class.uses_active_scaffold? and params[:adapter] and @rendering_adapter.nil? @rendering_adapter = true # recursion control # if we need an adapter, then we render the actual stuff to a string and insert it into the adapter template + opts = args.blank? ? Hash.new : args.first render :partial => params[:adapter][1..-1], - :locals => {:payload => render_to_string(args.first.merge(:layout => false), &block)}, + :locals => {:payload => render_to_string(opts.merge(:layout => false), &block)}, :use_full_path => true, :layout => false @rendering_adapter = nil # recursion control else @@ -18,3 +19,4 @@ def render_with_active_scaffold(*args, &block) # Rails 2.x implementation is post-initialization on :active_scaffold method end end + From ea638b98e0943f3b2c795bdf9a2ce0289ce09ce7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 15 Apr 2011 22:33:00 +0200 Subject: [PATCH 1088/2024] IPAD does not support hover, support action_groups without hover --- .../javascripts/jquery/active_scaffold.js | 25 ++++++++++++++++--- .../javascripts/prototype/active_scaffold.js | 25 ++++++++++++++++--- .../default/views/_action_group.html.erb | 8 ++++-- lib/active_scaffold.rb | 22 ++++++++++++++++ 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index a74b07f20c..1c819434ab 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -267,10 +267,27 @@ $(document).ready(function() { }); $('a[data-popup]').live('click', function(e) { - window.open($(this).attr('href')); - e.preventDefault(); - }); - + window.open($(this).attr('href')); + e.preventDefault(); + }); + + $('.hover_click').live("click", function(event) { + var element = $(this); + var ul_element = element.children('ul').first(); + if (ul_element.is(':visible')) { + element.find('ul').hide(); + } else { + ul_element.show(); + } + return false; + }); + $('.hover_click a.as_action').live('click', function(event) { + var element = $(this).closest('.hover_click'); + if (element) { + element.find('ul').hide(); + } + return true; + }); }); /* Simple Inheritance diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js index 18ad32a24d..e19b77c5d8 100644 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ b/frontends/default/javascripts/prototype/active_scaffold.js @@ -288,10 +288,27 @@ document.observe("dom:loaded", function() { return true; }); document.on("click", "a[data-popup]", function(event, element) { - if (event.stopped) return; - window.open($(element).href); - event.stop(); - }); + if (event.stopped) return; + window.open($(element).href); + event.stop(); + }); + document.on("click", ".hover_click", function(event, element) { + var ul_element = element.down('ul'); + if (ul_element.getStyle('display') === 'none') { + ul_element.style.display = 'block'; + } else { + ul_element.style.display = 'none'; + } + + return true; + }); + document.on("click", ".hover_click a.as_action", function(event, element) { + var element = element.up('.hover_click').down('ul'); + if (element) { + element.style.display = 'none'; + } + return true; + }); }); diff --git a/frontends/default/views/_action_group.html.erb b/frontends/default/views/_action_group.html.erb index f84d984f67..b0027c5192 100644 --- a/frontends/default/views/_action_group.html.erb +++ b/frontends/default/views/_action_group.html.erb @@ -5,10 +5,14 @@ <% if (options[:node] == :finished_traversing) -%> <%= "</ul>#{(options[:level] == 0 ? "</div>#{end_level_0_tag}": '</li>')}".html_safe %> <% elsif (options[:node] == :start_traversing) -%> + <% html_classes = [] + html_classes << 'hover_click' if hover_via_click? %> <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}<div class=\"action_group\"> #{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %> + <% html_classes << 'action_group' %> + <%= "#{start_level_0_tag}<div class=\"#{html_classes.join(' ')}\" #{"onclick=\"\"" if hover_via_click?}> #{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %> <% else %> - <%= "<li #{"class=\"top\"" if options[:first_action]}>#{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %> + <% html_classes << 'top' if options[:first_action] %> + <%= "<li #{"class=\"#{html_classes.join(' ')}\"" unless html_classes.empty?} #{"onclick=\"\"" if hover_via_click?}>#{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %> <% end %> <% else -%> <% if options[:level] == 0 %> diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 7b9ce64f1b..461735ac67 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -66,7 +66,11 @@ def self.included(base) base.module_eval do # TODO: these should be in actions/core before_filter :handle_user_settings + before_filter :check_input_device end + + base.helper_method :touch_device? + base.helper_method :hover_via_click? end def self.set_defaults(&block) @@ -98,6 +102,24 @@ def handle_user_settings end end end + + def check_input_device + if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod|iPad)/i] + session[:input_device_type] = 'TOUCH' + session[:hover_supported] = false + else + session[:input_device_type] = 'MOUSE' + session[:hover_supported] = true + end if session[:input_device_type].nil? + end + + def touch_device? + session[:input_device_type] == 'TOUCH' + end + + def hover_via_click? + session[:hover_supported] == false + end def self.js_framework=(framework) @@js_framework = framework From d82147137bb468f8dd2f7e45853a7e5324defc52 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 15 Apr 2011 23:40:30 +0200 Subject: [PATCH 1089/2024] add as_touch class in case of a touch device --- frontends/default/views/_list_with_header.html.erb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_list_with_header.html.erb b/frontends/default/views/_list_with_header.html.erb index 4d08555bc5..262189a27f 100644 --- a/frontends/default/views/_list_with_header.html.erb +++ b/frontends/default/views/_list_with_header.html.erb @@ -1,4 +1,4 @@ -<div id="<%= active_scaffold_id -%>" class="active-scaffold active-scaffold-<%= controller_id %> <%= "#{params[:controller]}-view" %> <%= active_scaffold_config.theme %>-theme" <%= "data-eid=#{id_from_controller(params[:eid])}" if params[:eid]%>> +<div id="<%= active_scaffold_id -%>" class="<%= as_main_div_class %>" <%= "data-eid=#{id_from_controller(params[:eid])}" if params[:eid]%>> <div class="active-scaffold-header"> <%= render :partial => 'list_header' %> </div> diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 699cc7bcc5..3134b17961 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -259,6 +259,12 @@ def column_heading_class(column, sorting) classes.join(' ') end + def as_main_div_class + classes = ["active-scaffold", "active-scaffold-#{controller_id}", "#{params[:controller]}-view", "#{active_scaffold_config.theme}-theme"] + classes << "as_touch" if touch_device? + classes.join(' ') + end + def column_empty?(column_value) empty = column_value.nil? empty ||= column_value.empty? if column_value.respond_to? :empty? From 912ad6d61259af5c2c15ffaeee2fb33d006826d3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 15 Apr 2011 23:41:53 +0200 Subject: [PATCH 1090/2024] add a touchable close image... --- frontends/default/images/close_touch.png | Bin 0 -> 422 bytes frontends/default/stylesheets/stylesheet.css | 6 ++++++ 2 files changed, 6 insertions(+) create mode 100644 frontends/default/images/close_touch.png diff --git a/frontends/default/images/close_touch.png b/frontends/default/images/close_touch.png new file mode 100644 index 0000000000000000000000000000000000000000..900228a92c8e78dc97996611f9a7dbb347e69950 GIT binary patch literal 422 zcmV;X0a^ZuP)<h;3K|Lk000e1NJLTq001BW001Hg0{{R332ZCP00001b5ch_0Itp) z=>Px#qEJj!MHX`p7jq67cM2PM2OfO_AAbNAa1;_}D-&od6lf|KYc3gVE*fty9&s-s zb2ce?J1crTB7p-bg$p{5A2EPJJ%~+6moHYIKWwXVZmx8FwQGdAbC=AOpvjY`&6~X0 zv$W!`w&Sq5=Ci-*x5M4L#_+w#^1sja#LxG{)#uOH>C@5p#?tx5)B4EO`^nk<%-a9W z=JDh7`SbYu_xt_(|NsBC_sr%1000SaNLh0L01FcU01FcV0GgZ_0001;Nkl<ZILoDz z!4iWY3`Eg1UerVEFZ9wLJG1})YaNsdGi;5OJ&3qZNCFA7qi_zG9AKirIPO5---x>I zJRqV(BL4vZ3Nub>0NIWc0zj9=EWK7SB*N^G7OR3xKkj3l#pcAvlc#ydSHJ4;E`3_4 z(!T`2*#b_Gubd|IN}<;8X2)ltE1(?E;zDqs^~xOrAqdeh<koY6_U>*0K25qlJr6!z QmH+?%07*qoM6N<$g7I{`n*aa+ literal 0 HcmV?d00001 diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 5d9f370eae..fe902925cb 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -971,3 +971,9 @@ font-size: 100%; .active-scaffold-found { float:left; } + +.as_touch a.inline-adapter-close { +width: 32px; +height: 34px; +background: url(../../../images/active_scaffold/default/close_touch.png) 0 0 no-repeat; +} \ No newline at end of file From c9cdcb040f8ddd20084595c491a6a9908d4d6876 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 15 Apr 2011 23:59:59 +0200 Subject: [PATCH 1091/2024] improve touchability for pagination --- frontends/default/stylesheets/stylesheet.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index fe902925cb..cfe586357a 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -976,4 +976,9 @@ font-size: 100%; width: 32px; height: 34px; background: url(../../../images/active_scaffold/default/close_touch.png) 0 0 no-repeat; +} + +.as_touch .as_paginate { +font-size: 20px; +padding: 3px 10px; } \ No newline at end of file From 18d13d833dc42a1705341112c2c785f6fa7129c2 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 16 Apr 2011 00:11:23 +0200 Subject: [PATCH 1092/2024] disable dhtml_history for safari it s not working anyway for current one s --- .../javascripts/prototype/dhtml_history.js | 157 +++++++++--------- 1 file changed, 80 insertions(+), 77 deletions(-) diff --git a/frontends/default/javascripts/prototype/dhtml_history.js b/frontends/default/javascripts/prototype/dhtml_history.js index 3bf6275c48..da08ba2d57 100644 --- a/frontends/default/javascripts/prototype/dhtml_history.js +++ b/frontends/default/javascripts/prototype/dhtml_history.js @@ -53,18 +53,6 @@ window.dhtmlHistory = { var that = this; - /*Set up the historyStorage object; pass in options bundle*/ - window.historyStorage.setup(options); - - /*Set up our base title if one is passed in*/ - if (options && options.baseTitle) { - if (options.baseTitle.indexOf("@@@") < 0 && historyStorage.debugMode) { - throw new Error("Programmer error: options.baseTitle must contain the replacement parameter" - + " '@@@' to be useful."); - } - this.baseTitle = options.baseTitle; - } - /*set user-agent flags*/ var UA = navigator.userAgent.toLowerCase(); var platform = navigator.platform.toLowerCase(); @@ -80,77 +68,92 @@ window.dhtmlHistory = { this.isSupported = true; } else if (vendor.indexOf("Apple Computer, Inc.") > -1) { this.isSafari = true; - this.isSupported = (platform.indexOf("mac") > -1); + //this.isSupported = (platform.indexOf("mac") > -1); + this.isSupported = false; } else if (UA.indexOf("gecko") != -1) { this.isGecko = true; this.isSupported = true; } - /*Create Safari/Opera-specific code*/ - if (this.isSafari) { - this.createSafari(); - } else if (this.isOpera) { - this.createOpera(); - } - - /*Get our initial location*/ - var initialHash = this.getCurrentLocation(); - - /*Save it as our current location*/ - this.currentLocation = initialHash; - - /*Now that we have a hash, create IE-specific code*/ - if (this.isIE) { - /*Optionally override the URL of IE's blank HTML file*/ - if (options && options.blankURL) { - var u = options.blankURL; - /*assign the value, adding the trailing ? if it's not passed in*/ - this.blankURL = (u.indexOf("?") != u.length - 1 - ? u + "?" - : u - ); - } - this.createIE(initialHash); - } - - /*Add an unload listener for the page; this is needed for FF 1.5+ because this browser caches all dynamic updates to the - page, which can break some of our logic related to testing whether this is the first instance a page has loaded or whether - it is being pulled from the cache*/ - - var unloadHandler = function() { - that.firstLoad = null; - }; - - this.addEventListener(window,'unload',unloadHandler); - - /*Determine if this is our first page load; for IE, we do this in this.iframeLoaded(), which is fired on pageload. We do it - there because we have no historyStorage at this point, which only exists after the page is finished loading in IE*/ - if (this.isIE) { - /*The iframe will get loaded on page load, and we want to ignore this fact*/ - this.ignoreLocationChange = true; - } else { - if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) { - /*This is our first page load, so ignore the location change and add our special history entry*/ - this.ignoreLocationChange = true; - this.firstLoad = true; - historyStorage.put(this.PAGELOADEDSTRING, true); - } else { - /*This isn't our first page load, so indicate that we want to pay attention to this location change*/ - this.ignoreLocationChange = false; - this.firstLoad = false; - /*For browsers other than IE, fire a history change event; on IE, the event will be thrown automatically when its - hidden iframe reloads on page load. Unfortunately, we don't have any listeners yet; indicate that we want to fire - an event when a listener is added.*/ - this.fireOnNewListener = true; - } + if (this.isSupported) { + /*Set up the historyStorage object; pass in options bundle*/ + window.historyStorage.setup(options); + + /*Set up our base title if one is passed in*/ + if (options && options.baseTitle) { + if (options.baseTitle.indexOf("@@@") < 0 && historyStorage.debugMode) { + throw new Error("Programmer error: options.baseTitle must contain the replacement parameter" + + " '@@@' to be useful."); + } + this.baseTitle = options.baseTitle; + } + + /*Create Safari/Opera-specific code*/ + if (this.isSafari && this.isSupported) { + this.createSafari(); + } else if (this.isOpera) { + this.createOpera(); + } + + /*Get our initial location*/ + var initialHash = this.getCurrentLocation(); + + /*Save it as our current location*/ + this.currentLocation = initialHash; + + /*Now that we have a hash, create IE-specific code*/ + if (this.isIE) { + /*Optionally override the URL of IE's blank HTML file*/ + if (options && options.blankURL) { + var u = options.blankURL; + /*assign the value, adding the trailing ? if it's not passed in*/ + this.blankURL = (u.indexOf("?") != u.length - 1 + ? u + "?" + : u + ); + } + this.createIE(initialHash); + } + + /*Add an unload listener for the page; this is needed for FF 1.5+ because this browser caches all dynamic updates to the + page, which can break some of our logic related to testing whether this is the first instance a page has loaded or whether + it is being pulled from the cache*/ + + var unloadHandler = function() { + that.firstLoad = null; + }; + + this.addEventListener(window,'unload',unloadHandler); + + /*Determine if this is our first page load; for IE, we do this in this.iframeLoaded(), which is fired on pageload. We do it + there because we have no historyStorage at this point, which only exists after the page is finished loading in IE*/ + if (this.isIE) { + /*The iframe will get loaded on page load, and we want to ignore this fact*/ + this.ignoreLocationChange = true; + } else if (this.isSupported) { + if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) { + /*This is our first page load, so ignore the location change and add our special history entry*/ + this.ignoreLocationChange = true; + this.firstLoad = true; + historyStorage.put(this.PAGELOADEDSTRING, true); + } else { + /*This isn't our first page load, so indicate that we want to pay attention to this location change*/ + this.ignoreLocationChange = false; + this.firstLoad = false; + /*For browsers other than IE, fire a history change event; on IE, the event will be thrown automatically when its + hidden iframe reloads on page load. Unfortunately, we don't have any listeners yet; indicate that we want to fire + an event when a listener is added.*/ + this.fireOnNewListener = true; + } + } + + /*Other browsers can use a location handler that checks at regular intervals as their primary mechanism; we use it for IE as + well to handle an important edge case; see checkLocation() for details*/ + var locationHandler = function() { + that.checkLocation(); + }; + setInterval(locationHandler, 100); } - - /*Other browsers can use a location handler that checks at regular intervals as their primary mechanism; we use it for IE as - well to handle an important edge case; see checkLocation() for details*/ - var locationHandler = function() { - that.checkLocation(); - }; - setInterval(locationHandler, 100); }, /*Public: Initialize our DHTML history. You must call this after the page is finished loading. Optionally, you can pass your listener in From 908ff6c1bedf3bd4a7aa831813db60cc91e37c57 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 16 Apr 2011 09:45:15 +0200 Subject: [PATCH 1093/2024] collection actionlinks styling --- frontends/default/stylesheets/stylesheet.css | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index cfe586357a..369042b1bc 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -99,6 +99,11 @@ background-position: 1px 50%; background-repeat: no-repeat; } +.active-scaffold-header div.actions a { +padding: 5px 5px; +margin-left: 0px; +} + .active-scaffold-header div.actions div.action_group { display: inline; float: right; @@ -112,7 +117,7 @@ margin: 0; .active-scaffold-header div.actions .action_group ul { line-height: 130%; -top: 14px; +top: 19px; } .view .active-scaffold-header div.actions a, @@ -141,8 +146,8 @@ opacity: 0.5; .active-scaffold-header div.actions a.show_config_list, .active-scaffold-header div.actions div.action_group div { margin:0; -padding: 1px 5px 1px 20px; -background-position: 1px 50%; +padding: 5px 5px 5px 25px; +background-position: 5px 50%; background-repeat: no-repeat; } From aae030ed6449a6817965e7c5c8dd1340654f231e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 16 Apr 2011 09:59:16 +0200 Subject: [PATCH 1094/2024] improve touchability for action_links in subgroups --- frontends/default/stylesheets/stylesheet.css | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 369042b1bc..62695a4963 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -986,4 +986,33 @@ background: url(../../../images/active_scaffold/default/close_touch.png) 0 0 no- .as_touch .as_paginate { font-size: 20px; padding: 3px 10px; +} + +.as_touch .active-scaffold-header div.actions a { +padding: 7px 5px; +} + +.as_touch .active-scaffold-header div.actions .action_group ul { +line-height: 130%; +top: 23px; +} + +.as_touch .active-scaffold-header div.actions a.new, +.as_touch .active-scaffold-header div.actions a.new_existing, +.as_touch .active-scaffold-header div.actions a.show_search, +.as_touch .active-scaffold-header div.actions a.show_config_list, +.as_touch .active-scaffold-header div.actions div.action_group div { +padding: 7px 5px 7px 25px; +} + +.as_touch .actions .action_group ul li div { +padding: 7px 5px 7px 25px; +} + +.as_touch .actions .action_group ul li a { +padding: 7px 5px 7px 25px; +} + +.as_touch .active-scaffold-header h2 { +padding: 4px 0px; } \ No newline at end of file From 61b1afd8ed34632f20b0885125006186d113f065 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 16 Apr 2011 10:07:28 +0200 Subject: [PATCH 1095/2024] increased line-height for tr.record in touch mode --- frontends/default/stylesheets/stylesheet.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 62695a4963..4979b1ac25 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -1015,4 +1015,8 @@ padding: 7px 5px 7px 25px; .as_touch .active-scaffold-header h2 { padding: 4px 0px; +} + +.as_touch tr.record { +line-height: 130%; } \ No newline at end of file From d95759812be0edf8a4e15ec1db8ca206454d9394 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 16 Apr 2011 10:18:47 +0200 Subject: [PATCH 1096/2024] increase th height in case of touch mode --- frontends/default/stylesheets/stylesheet.css | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 4979b1ac25..af0f0f71d3 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -1019,4 +1019,10 @@ padding: 4px 0px; .as_touch tr.record { line-height: 130%; -} \ No newline at end of file +} + +.as_touch th a, .as_touch th a:visited { +color: #fff; +padding: 5px 2px 5px 5px; +} + From ee7037c0f388a2ae31e85d2abdceb1e452d0dcdf Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 16 Apr 2011 18:44:45 +0200 Subject: [PATCH 1097/2024] german next renamed to vor --- lib/active_scaffold/locale/de.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb index b941527b2a..44812973fb 100644 --- a/lib/active_scaffold/locale/de.rb +++ b/lib/active_scaffold/locale/de.rb @@ -30,7 +30,7 @@ :hide => 'Verstecken', :live_search => 'Live-Suche', :loading => 'Lade…', - :next => 'Vorwärts', + :next => 'Vor', :no_entries => 'Keine Einträge', :no_options => 'Keine Optionen', :omit_header => 'Lasse Header weg', From 4d095964062559fa2573a708706d87f5fdb41935 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 16 Apr 2011 19:34:24 +0200 Subject: [PATCH 1098/2024] Bugfix: full_messages is nt expecting a parameter --- frontends/default/views/update_column.js.rjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/update_column.js.rjs b/frontends/default/views/update_column.js.rjs index 1d452e3bf6..6bd90fa16a 100644 --- a/frontends/default/views/update_column.js.rjs +++ b/frontends/default/views/update_column.js.rjs @@ -1,6 +1,6 @@ column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column]) unless controller.send :successful? - page.call 'alert', @record.errors.full_messages(active_scaffold_config).join("\n") + page.call 'alert', @record.errors.full_messages.join("\n") @record.reload end column = active_scaffold_config.columns[params[:column]] From b65467d057ffaa83ac1a174432975d153bf091fa Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 16 Apr 2011 19:36:32 +0200 Subject: [PATCH 1099/2024] extract method inplace_editor_field_clicked --- .../javascripts/jquery/active_scaffold.js | 129 +++++++++--------- 1 file changed, 66 insertions(+), 63 deletions(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index 1c819434ab..ff5d218655 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -128,69 +128,7 @@ $(document).ready(function() { return true; }); $('span.in_place_editor_field').live('click', function(event) { - var span = $(this); - span.data(); // jquery 1.4.2 workaround - if (typeof(span.data('editInPlace')) === 'undefined') { - var options = {show_buttons: true, - hover_class: 'hover', - element_id: 'editor_id', - ajax_data_type: "script", - update_value: 'value'}, - csrf_param = $('meta[name=csrf-param]').first(), - csrf_token = $('meta[name=csrf-token]').first(), - my_parent = span.parent(), - column_heading = null; - - if(!(my_parent.is('td') || my_parent.is('th'))){ - my_parent = span.parents('td').eq(0); - } - - if (my_parent.is('td')) { - var column_no = my_parent.prevAll('td').length; - column_heading = my_parent.closest('.active-scaffold').find('th:eq(' + column_no + ')'); - } else if (my_parent.is('th')) { - column_heading = my_parent; - } - - var render_url = column_heading.attr('data-ie_render_url'), - mode = column_heading.attr('data-ie_mode'), - record_id = span.attr('data-ie_id'); - - ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options); - - if (span.attr('data-ie_url')) { - options.url = span.attr('data-ie_url').replace(/__id__/, record_id); - } else { - options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id); - } - - if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content'); - - if (span.closest('div.active-scaffold').attr('data-eid')) { - if (options['params'].length > 0) { - options['params'] += "&"; - } - options['params'] += ("eid=" + span.closest('div.active-scaffold').attr('data-eid')); - } - - if (mode === 'clone') { - options.clone_id_suffix = record_id; - options.clone_selector = '#' + column_heading.attr('id') + ' .as_inplace_pattern'; - options.field_type = 'clone'; - } - - if (render_url) { - var plural = false; - if (column_heading.attr('data-ie_plural')) plural = true; - options.field_type = 'remote'; - options.editor_url = render_url.replace(/__id__/, record_id) - } - if (mode === 'inline_checkbox') { - ActiveScaffold.process_checkbox_inplace_edit(span.find('input:checkbox'), options); - } else { - ActiveScaffold.create_inplace_editor(span, options); - } - } + ActiveScaffold.in_place_editor_field_clicked($(this)); }); $('a.as_paginate').live('ajax:before',function(event) { var as_paginate = $(this); @@ -757,6 +695,71 @@ var ActiveScaffold = { } mark_all_checkbox.attr('value', ('' + !options.checked)); } + }, + + in_place_editor_field_clicked: function(span) { + span.data(); // jquery 1.4.2 workaround + if (typeof(span.data('editInPlace')) === 'undefined') { + var options = {show_buttons: true, + hover_class: 'hover', + element_id: 'editor_id', + ajax_data_type: "script", + update_value: 'value'}, + csrf_param = $('meta[name=csrf-param]').first(), + csrf_token = $('meta[name=csrf-token]').first(), + my_parent = span.parent(), + column_heading = null; + + if(!(my_parent.is('td') || my_parent.is('th'))){ + my_parent = span.parents('td').eq(0); + } + + if (my_parent.is('td')) { + var column_no = my_parent.prevAll('td').length; + column_heading = my_parent.closest('.active-scaffold').find('th:eq(' + column_no + ')'); + } else if (my_parent.is('th')) { + column_heading = my_parent; + } + + var render_url = column_heading.attr('data-ie_render_url'), + mode = column_heading.attr('data-ie_mode'), + record_id = span.attr('data-ie_id'); + + ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options); + + if (span.attr('data-ie_url')) { + options.url = span.attr('data-ie_url').replace(/__id__/, record_id); + } else { + options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id); + } + + if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content'); + + if (span.closest('div.active-scaffold').attr('data-eid')) { + if (options['params'].length > 0) { + options['params'] += "&"; + } + options['params'] += ("eid=" + span.closest('div.active-scaffold').attr('data-eid')); + } + + if (mode === 'clone') { + options.clone_id_suffix = record_id; + options.clone_selector = '#' + column_heading.attr('id') + ' .as_inplace_pattern'; + options.field_type = 'clone'; + } + + if (render_url) { + var plural = false; + if (column_heading.attr('data-ie_plural')) plural = true; + options.field_type = 'remote'; + options.editor_url = render_url.replace(/__id__/, record_id) + } + if (mode === 'inline_checkbox') { + ActiveScaffold.process_checkbox_inplace_edit(span.find('input:checkbox'), options); + } else { + ActiveScaffold.create_inplace_editor(span, options); + } + } } } From 8d526d77014c005f50c374ef15a9d8a02b6e45ae Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 16 Apr 2011 19:37:15 +0200 Subject: [PATCH 1100/2024] marked_column should be a little bit wider in touch mode --- frontends/default/stylesheets/stylesheet.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index af0f0f71d3..df8546132a 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -1026,3 +1026,6 @@ color: #fff; padding: 5px 2px 5px 5px; } +.as_touch tr.record td { +padding: 5px 10px; +} \ No newline at end of file From 63b81c3bf29246b3b9f39aeededdd8b6d9648f40 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 16 Apr 2011 19:54:59 +0200 Subject: [PATCH 1101/2024] collection action links for nested scaffolds should nt be smaller in touch mode --- frontends/default/stylesheets/stylesheet.css | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index df8546132a..bb2d317c9a 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -1017,6 +1017,14 @@ padding: 7px 5px 7px 25px; padding: 4px 0px; } +.as_touch .active-scaffold .active-scaffold-header div.actions a, .active-scaffold .active-scaffold .active-scaffold-header div.actions div { + font: bold 14px arial; +} + +.as_touch .active-scaffold .active-scaffold-header div.actions { + right: 15px; +} + .as_touch tr.record { line-height: 130%; } From e810a5e1cd67a5d59999b2f3cab9afea0dfb4689 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 16 Apr 2011 21:45:19 +0200 Subject: [PATCH 1102/2024] fixed some css bugs introduced by touch mode --- frontends/default/stylesheets/stylesheet.css | 39 +++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index bb2d317c9a..585ecdfeda 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -104,6 +104,10 @@ padding: 5px 5px; margin-left: 0px; } +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a { +padding: 1px 5px; +} + .active-scaffold-header div.actions div.action_group { display: inline; float: right; @@ -120,6 +124,10 @@ line-height: 130%; top: 19px; } +.active-scaffold .active-scaffold .active-scaffold-header div.actions .action_group ul { +top: 14px; +} + .view .active-scaffold-header div.actions a, .view .active-scaffold-header div.actions div, .view .active-scaffold-header div.actions div.action_group { @@ -151,6 +159,17 @@ background-position: 5px 50%; background-repeat: no-repeat; } +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.new, +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.new_existing, +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.show_search, +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.show_config_list, +.active-scaffold .active-scaffold .active-scaffold-header div.actions div.action_group > div { +margin:0; +padding: 1px 5px 1px 20px; +background-position: 1px 50%; +background-repeat: no-repeat; +} + .active-scaffold-header div.actions div.action_group div { background-image: url(../../../images/active_scaffold/default/gears.png); /* default icon for actions or override with css */ } @@ -992,11 +1011,19 @@ padding: 3px 10px; padding: 7px 5px; } +.as_touch .active-scaffold .active-scaffold-header div.actions a { +padding: 7px 5px; +} + .as_touch .active-scaffold-header div.actions .action_group ul { line-height: 130%; top: 23px; } +.as_touch .active-scaffold .active-scaffold-header div.actions .action_group ul { +top: 23px; +} + .as_touch .active-scaffold-header div.actions a.new, .as_touch .active-scaffold-header div.actions a.new_existing, .as_touch .active-scaffold-header div.actions a.show_search, @@ -1005,6 +1032,15 @@ top: 23px; padding: 7px 5px 7px 25px; } +.as_touch .active-scaffold .active-scaffold-header div.actions > a.new, +.as_touch .active-scaffold .active-scaffold-header div.actions > a.new_existing, +.as_touch .active-scaffold .active-scaffold-header div.actions > a.show_search, +.as_touch .active-scaffold .active-scaffold-header div.actions > a.show_config_list, +.as_touch .active-scaffold .active-scaffold-header div.actions div.action_group > div { +padding: 7px 5px 7px 25px; +background-position: 5px 50%; +} + .as_touch .actions .action_group ul li div { padding: 7px 5px 7px 25px; } @@ -1017,7 +1053,8 @@ padding: 7px 5px 7px 25px; padding: 4px 0px; } -.as_touch .active-scaffold .active-scaffold-header div.actions a, .active-scaffold .active-scaffold .active-scaffold-header div.actions div { +.as_touch .active-scaffold .active-scaffold-header div.actions a, +.as_touch .active-scaffold .active-scaffold-header div.actions div { font: bold 14px arial; } From 7cb8881bbede6f77dca33d5bc9524cae573c18d0 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 18 Apr 2011 15:45:30 +0200 Subject: [PATCH 1103/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index e4792888de..c2779310e6 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 18 + PATCH = 19 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From ddb1da49663b13012b713a72c1decd42acf5f2c3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 18 Apr 2011 15:45:45 +0200 Subject: [PATCH 1104/2024] Regenerate gemspec for version 3.0.19 --- active_scaffold_vho.gemspec | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index fb25d94149..6cda823864 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.18" + s.version = "3.0.19" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] - s.date = %q{2011-03-27} + s.date = %q{2011-04-18} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.email = %q{activescaffold@googlegroups.com} s.extra_rdoc_files = [ @@ -29,6 +29,7 @@ Gem::Specification.new do |s| "frontends/default/images/arrow_down.gif", "frontends/default/images/arrow_up.gif", "frontends/default/images/close.gif", + "frontends/default/images/close_touch.png", "frontends/default/images/config.png", "frontends/default/images/cross.png", "frontends/default/images/gears.png", From c763cff04a24192b6fc6460fe74692fd44eeaea5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 22 Apr 2011 15:32:49 +0200 Subject: [PATCH 1105/2024] Bugfix: fieldsearch: search_range type with column.search_sql and column.search_ui set to string (eg association searches) --- lib/active_scaffold/helpers/search_column_helpers.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 6df061b242..16d52ca726 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -122,9 +122,13 @@ def field_search_params_range_values(column) end + def active_scaffold_search_range_string?(column) + (column.column && column.column.text?) || column.search_ui == :string + end + def active_scaffold_search_range_comparator_options(column) select_options = ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} - if column.column && column.column.text? + if active_scaffold_search_range_string?(column) select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} end select_options @@ -134,7 +138,7 @@ def active_scaffold_search_range(column, options) opt_value, from_value, to_value = field_search_params_range_values(column) select_options = active_scaffold_search_range_comparator_options(column) - if column.column && column.column.text? + if active_scaffold_search_range_string?(column) text_field_size = 15 opt_value ||= '%?%' else From 97079e4881ed5d64e0b2b8d0e0be9086f9a3a2e3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 23 Apr 2011 09:17:27 +0200 Subject: [PATCH 1106/2024] Bugfix: make sure that we do not path symbolized methods to link_to --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 3134b17961..1d58300d3d 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -148,7 +148,7 @@ def render_group_action_link(link, url_options, options, record = nil) def action_link_url_options(link, url_options, record, options = {}) url_options = url_options.clone url_options[:action] = link.action - url_options[:controller] = link.controller if link.controller + url_options[:controller] = link.controller.to_s if link.controller url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller] url_options.merge! link.parameters if link.parameters @link_record = record From 4a3e2f27ed2605e02b2f9d7bd7084518e81ff263 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 23 Apr 2011 10:36:25 +0200 Subject: [PATCH 1107/2024] Bugfix: singular association inline action_links working in sti parent controllers --- lib/active_scaffold/helpers/view_helpers.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 1d58300d3d..2f0dc59aeb 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -228,10 +228,15 @@ def url_options_for_nested_link(column, record, link, url_options, options = {}) def url_options_for_sti_link(column, record, link, url_options, options = {}) #need to find out controller of current record type #and set parameters - sti_controller_path = controller_path_for_activerecord(record.class) - if sti_controller_path - url_options[:controller] = sti_controller_path - url_options[:parent_sti] = controller_path + # its quite difficult to detect an sti link + # if link.column.nil? we are sure that it is nt an singular association inline autolink + # howver that will not work if a sti parent is an singular association inline autolink + if link.column.nil? + sti_controller_path = controller_path_for_activerecord(record.class) + if sti_controller_path + url_options[:controller] = sti_controller_path + url_options[:parent_sti] = controller_path + end end end From 398ab54824a7319077c39b9fcffaf07725c40e44 Mon Sep 17 00:00:00 2001 From: robdiciuccio <rob@definitionstudio.com> Date: Thu, 28 Apr 2011 11:42:18 -0700 Subject: [PATCH 1108/2024] active_scaffold_input_plural_association helper patched for rails_xss compatiblity --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 83217d7ea4..0e7aaf6426 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -139,7 +139,7 @@ def active_scaffold_input_plural_association(column, options) html << '</ul>' html << javascript_tag("new DraggableLists('#{options[:id]}')") if column.options[:draggable_lists] - html + html.html_safe end def active_scaffold_translated_option(column, text, value = nil) From 79b737ff7e6332727592dd8590896cc78ddf6ee9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Mon, 2 May 2011 08:59:59 +0200 Subject: [PATCH 1109/2024] list: add hide_nested_column option --- lib/active_scaffold/actions/nested.rb | 2 +- lib/active_scaffold/config/list.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 40b4129537..29f88fa03e 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -19,7 +19,7 @@ def self.included(base) def nested @nested ||= ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, active_scaffold_session_storage) if !@nested.nil? && @nested.new_instance? - register_constraints_with_action_columns(@nested.constrained_fields) + register_constraints_with_action_columns(@nested.constrained_fields, active_scaffold_config.list.hide_nested_column ? [] : [:list]) active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to? end @nested diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index aeadf84a5f..d7d1d50332 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -114,6 +114,12 @@ def search_partial def always_show_create @always_show_create && @core.actions.include?(:create) end + + # if list view is nested hide nested_column + attr_writer :hide_nested_column + def hide_nested_column + @hide_nested_column.nil? ? true : @hide_nested_column + end # might be set to open nested_link automatically in view # conf.nested.add_link(:players) From ff2e52881848fbd1270aeed829c84ae6fd6d87ec Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 3 May 2011 08:43:29 +0200 Subject: [PATCH 1110/2024] raise exception if mark action is used without update action --- lib/active_scaffold/config/mark.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/config/mark.rb b/lib/active_scaffold/config/mark.rb index ef3a766585..e8a40bd89c 100644 --- a/lib/active_scaffold/config/mark.rb +++ b/lib/active_scaffold/config/mark.rb @@ -4,8 +4,12 @@ class Mark < Base def initialize(core_config) @core = core_config - @core.model.send(:include, ActiveScaffold::MarkedModel) unless @core.model.ancestors.include?(ActiveScaffold::MarkedModel) - add_mark_column + if core_config.actions.include?(:update) + @core.model.send(:include, ActiveScaffold::MarkedModel) unless @core.model.ancestors.include?(ActiveScaffold::MarkedModel) + add_mark_column + else + raise "Mark action requires update action in controller for model: #{core_config.model.to_s}" + end end protected From 8b0812d9a0699ee7d8bad5299a76873331c72209 Mon Sep 17 00:00:00 2001 From: Andrei L <adi@Andrei-Latchescus-Mac-Pro.local> Date: Mon, 9 May 2011 13:52:46 +0300 Subject: [PATCH 1111/2024] Added option to mark all to select only the current page. Configure it with config.mark.mark_all_mode = :page --- lib/active_scaffold/actions/list.rb | 49 ++++++++++++++----- lib/active_scaffold/config/mark.rb | 2 + .../helpers/list_column_helpers.rb | 9 +++- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 039d3a4272..a992ac7150 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -65,14 +65,14 @@ def do_list self.active_scaffold_includes.concat includes_for_list_columns options = { :sorting => active_scaffold_config.list.user.sorting, - :count_includes => active_scaffold_config.list.user.count_includes } + :count_includes => active_scaffold_config.list.user.count_includes } paginate = (params[:format].nil?) ? (accepts? :html, :js) : ['html', 'js'].include?(params[:format]) if paginate options.merge!({ - :per_page => active_scaffold_config.list.user.per_page, - :page => active_scaffold_config.list.user.page, - :pagination => active_scaffold_config.list.pagination - }) + :per_page => active_scaffold_config.list.user.per_page, + :page => active_scaffold_config.list.user.page, + :pagination => active_scaffold_config.list.pagination + }) end page = find_page(options); @@ -84,14 +84,39 @@ def do_list end def each_record_in_scope + _page = active_scaffold_config.list.user.page do_search if respond_to? :do_search - finder_options = { :order => "#{active_scaffold_config.model.connection.quote_table_name(active_scaffold_config.model.table_name)}.#{active_scaffold_config.model.primary_key} ASC", - :conditions => all_conditions, - :joins => joins_for_finder} - finder_options.merge! custom_finder_options - finder_options.merge! :include => (active_scaffold_includes.blank? ? nil : active_scaffold_includes) - klass = beginning_of_chain - klass.all(finder_options).each {|record| yield record} + active_scaffold_config.list.user.page = _page + if active_scaffold_config.mark.mark_all_mode == :page then + includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact + self.active_scaffold_includes.concat includes_for_list_columns + + options = { :sorting => active_scaffold_config.list.user.sorting, + :count_includes => active_scaffold_config.list.user.count_includes } + paginate = (params[:format].nil?) ? (accepts? :html, :js) : ['html', 'js'].include?(params[:format]) + if paginate + options.merge!({ + :per_page => active_scaffold_config.list.user.per_page, + :page => active_scaffold_config.list.user.page, + :pagination => active_scaffold_config.list.pagination + }) + end + + page = find_page(options); + if page.items.blank? && !page.pager.infinite? + page = page.pager.last + active_scaffold_config.list.user.page = page.number + end + page.items.each {|record| yield record} + else + finder_options = { :order => "#{active_scaffold_config.model.connection.quote_table_name(active_scaffold_config.model.table_name)}.#{active_scaffold_config.model.primary_key} ASC", + :conditions => all_conditions, + :joins => joins_for_finder} + finder_options.merge! custom_finder_options + finder_options.merge! :include => (active_scaffold_includes.blank? ? nil : active_scaffold_includes) + klass = beginning_of_chain + klass.all(finder_options).each {|record| yield record} + end end # The default security delegates to ActiveRecordPermissions. diff --git a/lib/active_scaffold/config/mark.rb b/lib/active_scaffold/config/mark.rb index e8a40bd89c..0e083395c0 100644 --- a/lib/active_scaffold/config/mark.rb +++ b/lib/active_scaffold/config/mark.rb @@ -1,6 +1,8 @@ module ActiveScaffold::Config class Mark < Base self.crud_type = :read + attr_accessor :mark_all_mode + @@mark_all_mode = :search def initialize(core_config) @core = core_config diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 684358902e..01ad606831 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -313,7 +313,14 @@ def inplace_edit_tag_attributes(column) end def mark_column_heading - all_marked = (marked_records.length >= @page.pager.count) + if active_scaffold_config.mark.mark_all_mode == :page then + all_marked = true + @page.items.each do |record| + all_marked = false if !marked_records.entries.include?(record.id) + end + else + all_marked = (marked_records.length >= @page.pager.count) + end tag_options = {:id => "#{controller_id}_mark_heading", :class => "mark_heading in_place_editor_field"} tag_options['data-ie_url'] = url_for({:controller => params_for[:controller], :action => 'mark_all', :eid => params[:eid]}) content_tag(:span, check_box_tag("#{controller_id}_mark_heading_span_input", !all_marked, all_marked), tag_options) From 986707d1df0d30c812035f94d097d42f80984bac Mon Sep 17 00:00:00 2001 From: Andrei L <adi@Andrei-Latchescus-Mac-Pro.local> Date: Mon, 9 May 2011 15:27:17 +0300 Subject: [PATCH 1112/2024] Optimized mark_all_mode code as suggested by vhochstein --- lib/active_scaffold/actions/list.rb | 43 +++++++++-------------------- lib/active_scaffold/actions/mark.rb | 14 ++++++++-- 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index a992ac7150..2990d37cbc 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -83,40 +83,23 @@ def do_list @page, @records = page, page.items end - def each_record_in_scope + def each_record_in_page _page = active_scaffold_config.list.user.page do_search if respond_to? :do_search active_scaffold_config.list.user.page = _page - if active_scaffold_config.mark.mark_all_mode == :page then - includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact - self.active_scaffold_includes.concat includes_for_list_columns - - options = { :sorting => active_scaffold_config.list.user.sorting, - :count_includes => active_scaffold_config.list.user.count_includes } - paginate = (params[:format].nil?) ? (accepts? :html, :js) : ['html', 'js'].include?(params[:format]) - if paginate - options.merge!({ - :per_page => active_scaffold_config.list.user.per_page, - :page => active_scaffold_config.list.user.page, - :pagination => active_scaffold_config.list.pagination - }) - end + do_list + @page.items.each {|record| yield record} + end - page = find_page(options); - if page.items.blank? && !page.pager.infinite? - page = page.pager.last - active_scaffold_config.list.user.page = page.number - end - page.items.each {|record| yield record} - else - finder_options = { :order => "#{active_scaffold_config.model.connection.quote_table_name(active_scaffold_config.model.table_name)}.#{active_scaffold_config.model.primary_key} ASC", - :conditions => all_conditions, - :joins => joins_for_finder} - finder_options.merge! custom_finder_options - finder_options.merge! :include => (active_scaffold_includes.blank? ? nil : active_scaffold_includes) - klass = beginning_of_chain - klass.all(finder_options).each {|record| yield record} - end + def each_record_in_scope + do_search if respond_to? :do_search + finder_options = { :order => "#{active_scaffold_config.model.connection.quote_table_name(active_scaffold_config.model.table_name)}.#{active_scaffold_config.model.primary_key} ASC", + :conditions => all_conditions, + :joins => joins_for_finder} + finder_options.merge! custom_finder_options + finder_options.merge! :include => (active_scaffold_includes.blank? ? nil : active_scaffold_includes) + klass = beginning_of_chain + klass.all(finder_options).each {|record| yield record} end # The default security delegates to ActiveRecordPermissions. diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index f1459d0e1a..a68b908aaa 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -15,7 +15,7 @@ def mark_all end respond_to_action(:mark_all) end - protected + protected def mark_all_respond_to_html do_list @@ -43,11 +43,19 @@ def mark_all? end def do_mark_all - each_record_in_scope {|record| marked_records << record.id} + if active_scaffold_config.mark.mark_all_mode == :page then + each_record_in_page {|record| marked_records << record.id} + else + each_record_in_scope {|record| marked_records << record.id} + end end def do_demark_all - each_record_in_scope {|record| marked_records.delete(record.id)} + if active_scaffold_config.mark.mark_all_mode == :page then + each_record_in_page {|record| marked_records.delete(record.id)} + else + each_record_in_scope {|record| marked_records.delete(record.id)} + end end # The default security delegates to ActiveRecordPermissions. From 39ea1199bd5030742ebcf7b5c3c5158f15bd85dc Mon Sep 17 00:00:00 2001 From: Andrei L <adi@Andrei-Latchescus-Mac-Pro.local> Date: Mon, 9 May 2011 17:10:59 +0300 Subject: [PATCH 1113/2024] configure property on class and on instance level --- lib/active_scaffold/config/mark.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/config/mark.rb b/lib/active_scaffold/config/mark.rb index 0e083395c0..241ab2c816 100644 --- a/lib/active_scaffold/config/mark.rb +++ b/lib/active_scaffold/config/mark.rb @@ -6,6 +6,7 @@ class Mark < Base def initialize(core_config) @core = core_config + @mark_all_mode = self.class.mark_all_mode if core_config.actions.include?(:update) @core.model.send(:include, ActiveScaffold::MarkedModel) unless @core.model.ancestors.include?(ActiveScaffold::MarkedModel) add_mark_column From c9cd153fd7634eb3f0d89dde9e0a884b9c09573c Mon Sep 17 00:00:00 2001 From: Andrei L <adi@Andrei-Latchescus-Mac-Pro.local> Date: Mon, 9 May 2011 18:43:24 +0300 Subject: [PATCH 1114/2024] Last fixes for mark_all_mode --- lib/active_scaffold/config/mark.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/mark.rb b/lib/active_scaffold/config/mark.rb index 241ab2c816..27a3fafc56 100644 --- a/lib/active_scaffold/config/mark.rb +++ b/lib/active_scaffold/config/mark.rb @@ -1,8 +1,10 @@ module ActiveScaffold::Config class Mark < Base self.crud_type = :read - attr_accessor :mark_all_mode + cattr_accessor :mark_all_mode @@mark_all_mode = :search + + attr_accessor :mark_all_mode def initialize(core_config) @core = core_config From dbf2106fe10ca627a06307c1075f4d121b26bc87 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 10 May 2011 10:17:14 +0200 Subject: [PATCH 1115/2024] add a short description to new mark_all_mode --- lib/active_scaffold/config/mark.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/active_scaffold/config/mark.rb b/lib/active_scaffold/config/mark.rb index 27a3fafc56..4def5d09bb 100644 --- a/lib/active_scaffold/config/mark.rb +++ b/lib/active_scaffold/config/mark.rb @@ -1,6 +1,10 @@ module ActiveScaffold::Config class Mark < Base self.crud_type = :read + + # What kind of mark all mode to use: + # * :search: de-/mark all records using current search conditions + # * :page: de-/mark all records on current page cattr_accessor :mark_all_mode @@mark_all_mode = :search From d2414d388c5d476a6ace3dda985a789ea4d2955b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 10 May 2011 11:49:24 +0200 Subject: [PATCH 1116/2024] Bugfix: jquery update_columns triggered by checkbox (issue 136 reported by clyfe) --- frontends/default/javascripts/jquery/active_scaffold.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index ff5d218655..fb560d1866 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -160,7 +160,11 @@ $(document).ready(function() { params = as_form.serialize(); params += '&' + $.param({source_id: element.attr('id')}); } else { - params = {value: element.val()}; + if (element.is("input:checkbox")) { + params = {value: element.is(":checked")}; + } else { + params = {value: element.val()}; + } params.source_id = element.attr('id'); } From 005b8fd2ff89cbd945f66a3203d077d733e6dba5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 19 May 2011 12:55:18 +0200 Subject: [PATCH 1117/2024] Bugfix: jquery highlight issue 148 reported by clyfe --- frontends/default/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js index fb560d1866..747e4d7735 100644 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ b/frontends/default/javascripts/jquery/active_scaffold.js @@ -597,7 +597,7 @@ var ActiveScaffold = { }, highlight: function(element) { - if (typeof(element) == 'string') element = '#' + element; + if (typeof(element) == 'string') element = $('#' + element); if (typeof(element.effect) == 'function') { element.effect("highlight", {}, 3000); } From 9c8a7e0c68f6d62320c8d6fd0de8560ffdebe28b Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 21 May 2011 08:59:34 +0200 Subject: [PATCH 1118/2024] display record save errors in case of action_update --- frontends/default/views/on_action_update.js.rjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/on_action_update.js.rjs b/frontends/default/views/on_action_update.js.rjs index 009e4481a9..381da8f416 100644 --- a/frontends/default/views/on_action_update.js.rjs +++ b/frontends/default/views/on_action_update.js.rjs @@ -1,8 +1,10 @@ -page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages') if controller.send :successful? + page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages') page.call 'ActiveScaffold.update_row', element_row_id(:action => :list, :id => @record.id), render(:partial => 'list_record', :locals => {:record => @record}) if @record page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} else + flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) + page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages') page.call 'ActiveScaffold.scroll_to', active_scaffold_messages_id end From 66d4f458ae872dc149f7b295461888f6fd5d5949 Mon Sep 17 00:00:00 2001 From: "Ubuntu.10.10" <clyfe@ubuntu.(none)> Date: Thu, 26 May 2011 05:06:07 -0700 Subject: [PATCH 1119/2024] refactor active_scaffold_controller_for_column to allow easy overriding --- lib/active_scaffold.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 461735ac67..9c95a51332 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -237,9 +237,9 @@ def links_for_associations end end - def link_for_association(column, options = {}) + def active_scaffold_controller_for_column(column, options = {}) begin - controller = if column.polymorphic_association? + if column.polymorphic_association? :polymorph elsif options.include?(:controller) "#{options[:controller].to_s.camelize}Controller".constantize @@ -247,8 +247,12 @@ def link_for_association(column, options = {}) active_scaffold_controller_for(column.association.klass) end rescue ActiveScaffold::ControllerNotFound - controller = nil + nil end + end + + def link_for_association(column, options = {}) + controller = active_scaffold_controller_for_column(column, options) unless controller.nil? options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column From fb2152a5e2fcbe6c9bebb6d2772561837dbc4929 Mon Sep 17 00:00:00 2001 From: Andrei L <adi@Macintosh.local> Date: Thu, 26 May 2011 19:10:17 +0300 Subject: [PATCH 1120/2024] Added option to mark all records even with mark_all_mode = :page --- frontends/default/views/on_mark_all.js.rjs | 10 +++++++++- lib/active_scaffold/actions/mark.rb | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/on_mark_all.js.rjs b/frontends/default/views/on_mark_all.js.rjs index 851f29570a..65403d4d25 100644 --- a/frontends/default/views/on_mark_all.js.rjs +++ b/frontends/default/views/on_mark_all.js.rjs @@ -1,4 +1,12 @@ options = {:checked => mark_all, :include_mark_all => true} page << "ActiveScaffold.mark_records('#{active_scaffold_tbody_id}', #{options.to_json});" - +if !@marked_records_count.nil? && @marked_records_count>0 then + if @marked_records_count < @page.pager.count then + page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, @marked_records_count.to_s + " records marked. Press <a href=\""+url_for(:action=>"mark_all",:target=>"scope")+"\">here</a> to select all #{@page.pager.count} records.".html_safe + else + page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, "All #{@page.pager.count} records marked" + end +else + page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, "" +end diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index a68b908aaa..e9c14cf55a 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -8,7 +8,7 @@ def self.included(base) end def mark_all - if mark_all? + if mark_all? || (!params[:target].nil? && params[:target] == 'scope') do_mark_all else do_demark_all @@ -43,11 +43,12 @@ def mark_all? end def do_mark_all - if active_scaffold_config.mark.mark_all_mode == :page then + if active_scaffold_config.mark.mark_all_mode == :page && (params[:target].nil? || params[:target]!='scope') then each_record_in_page {|record| marked_records << record.id} else each_record_in_scope {|record| marked_records << record.id} end + @marked_records_count = marked_records.length end def do_demark_all From 87b66e28917a2df7972d3555b83420fee0372ee1 Mon Sep 17 00:00:00 2001 From: Andrei L <adi@Macintosh.local> Date: Fri, 27 May 2011 16:17:38 +0300 Subject: [PATCH 1121/2024] Optimized and cleaned the code for the new mark all feature --- frontends/default/views/on_mark_all.js.rjs | 6 +++--- lib/active_scaffold/actions/mark.rb | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/frontends/default/views/on_mark_all.js.rjs b/frontends/default/views/on_mark_all.js.rjs index 65403d4d25..dd339166ea 100644 --- a/frontends/default/views/on_mark_all.js.rjs +++ b/frontends/default/views/on_mark_all.js.rjs @@ -1,9 +1,9 @@ options = {:checked => mark_all, :include_mark_all => true} page << "ActiveScaffold.mark_records('#{active_scaffold_tbody_id}', #{options.to_json});" -if !@marked_records_count.nil? && @marked_records_count>0 then - if @marked_records_count < @page.pager.count then - page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, @marked_records_count.to_s + " records marked. Press <a href=\""+url_for(:action=>"mark_all",:target=>"scope")+"\">here</a> to select all #{@page.pager.count} records.".html_safe +if active_scaffold_config.model.marked.length>0 then + if active_scaffold_config.model.marked.length < @page.pager.count then + page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, active_scaffold_config.model.marked.length.to_s + " records marked. Press <a href=\""+url_for(:action=>"mark_all",:mark_target=>"scope")+"\">here</a> to select all #{@page.pager.count} records.".html_safe else page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, "All #{@page.pager.count} records marked" end diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index e9c14cf55a..55ce5be1cc 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -8,7 +8,7 @@ def self.included(base) end def mark_all - if mark_all? || (!params[:target].nil? && params[:target] == 'scope') + if mark_all? || mark_all_scope_forced? do_mark_all else do_demark_all @@ -42,13 +42,16 @@ def mark_all? @mark_all ||= [true, 'true', 1, '1', 'T', 't'].include?(params[:value].class == String ? params[:value].downcase : params[:value]) end + def mark_all_scope_forced? + !params[:mark_target].nil? && params[:mark_target]=='scope' + end + def do_mark_all - if active_scaffold_config.mark.mark_all_mode == :page && (params[:target].nil? || params[:target]!='scope') then + if active_scaffold_config.mark.mark_all_mode == :page && !mark_all_scope_forced? then each_record_in_page {|record| marked_records << record.id} else each_record_in_scope {|record| marked_records << record.id} end - @marked_records_count = marked_records.length end def do_demark_all From d6964bb2b444b820cd988d87493889ce0557729e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 27 May 2011 21:33:06 +0200 Subject: [PATCH 1122/2024] reduce size of close_touch.png --- frontends/default/images/close_touch.png | Bin 422 -> 391 bytes frontends/default/stylesheets/stylesheet.css | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/images/close_touch.png b/frontends/default/images/close_touch.png index 900228a92c8e78dc97996611f9a7dbb347e69950..73b2ad63d36011f98686d95cace7631313ec745d 100644 GIT binary patch delta 190 zcmV;v073tz1BU}4iBL{Q4GJ0x0000DNk~Le0000P0000R2m=5B0KWg!T9F~se|||s zK~yNuozgK5fFKM7&}yv<I+QcG=xEaWUriJhu~dzJYWf190Q6SiQM&HdbZ(crZt_&s zs~}Py#3Ukev_n;vP{~b%yysY4WhWlC#hFA48OajTGMhpteBaHKNfN1fn2kwk6;eW% sdsC+_zk(qEn5S)zzhldf|5nZd6vBWfC3G00u>b%707*qoM6N<$f{o5fNB{r; delta 221 zcmV<303!c~1EvEZiBL{Q4GJ0x0000DNk~Le0000W0000Y2m=5B010d>&5<F~f1OE0 zK~y-)rIW!DgCGn<(KKGvL+mf~(jGgr|Nm<plnOI!jg>u!xKBs|3A3Yc4wxKZqQE%r zK;Pepy6!w6qC_J90RRd!PHF(zjuQevm&Gi-Rxu>P?2#6$f=oZ|W1Yq3#K)7TdB<13 z>hLaoTBy>$1i;w>PLQvhCiF_7GuH2B$7i7{pd8TRLU5q<${hkB2+=U))^maO?rs4- XO}aik4?bO%00000NkvXXu0mjfam8A9 diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css index 585ecdfeda..01495484c7 100644 --- a/frontends/default/stylesheets/stylesheet.css +++ b/frontends/default/stylesheets/stylesheet.css @@ -997,8 +997,8 @@ font-size: 100%; } .as_touch a.inline-adapter-close { -width: 32px; -height: 34px; +width: 25px; +height: 27px; background: url(../../../images/active_scaffold/default/close_touch.png) 0 0 no-repeat; } From 8d6fb3da8c405fa6c8562e2de02357153f6bc825 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 27 May 2011 21:41:50 +0200 Subject: [PATCH 1123/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index c2779310e6..a9cf1ec991 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 0 - PATCH = 19 + PATCH = 20 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 1919c04076660a5bccabf62f5891ca9b1aef32eb Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 27 May 2011 21:42:29 +0200 Subject: [PATCH 1124/2024] Regenerate gemspec for version 3.0.20 --- active_scaffold_vho.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index 6cda823864..58b1080235 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.19" + s.version = "3.0.20" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] - s.date = %q{2011-04-18} + s.date = %q{2011-05-27} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.email = %q{activescaffold@googlegroups.com} s.extra_rdoc_files = [ From db5209841a5b39dde1d55a0631522edc5ec4055f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 27 May 2011 22:54:12 +0200 Subject: [PATCH 1125/2024] add dependency for rails 3.1 --- Rakefile | 6 +++--- lib/active_scaffold/version.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index 88d230974e..8f02448f15 100644 --- a/Rakefile +++ b/Rakefile @@ -22,13 +22,13 @@ Jeweler::Tasks.new do |gem| gem.version = ActiveScaffold::Version::STRING gem.homepage = "http://github.com/vhochstein/active_scaffold" gem.license = "MIT" - gem.summary = %Q{Rails 3 Version of activescaffold supporting prototype and jquery} + gem.summary = %Q{Rails 3.1 Version of activescaffold supporting prototype and jquery} gem.description = %Q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} gem.email = "activescaffold@googlegroups.com" gem.authors = ["Many, see README"] gem.add_runtime_dependency 'render_component_vho' gem.add_runtime_dependency 'verification' - gem.add_runtime_dependency 'rails', '~> 3.0.0' + gem.add_runtime_dependency 'rails', '~> 3.1.0' # Include your dependencies below. Runtime dependencies are required when using your gem, # and development dependencies are only needed for development (ie running rake tasks, tests, etc) # gem.add_runtime_dependency 'jabber4r', '> 0.1' @@ -50,4 +50,4 @@ Rake::RDocTask.new(:rdoc) do |rdoc| rdoc.options << '--line-numbers' << '--inline-source' rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') -end \ No newline at end of file +end diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index a9cf1ec991..d7de511833 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -1,8 +1,8 @@ module ActiveScaffold module Version MAJOR = 3 - MINOR = 0 - PATCH = 20 + MINOR = 1 + PATCH = 0 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From eb64ff088e1de1be8bbdbf795b954ad55003cb78 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 27 May 2011 22:54:56 +0200 Subject: [PATCH 1126/2024] gemspec requiring rails 3.1 --- active_scaffold_vho.gemspec | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index 58b1080235..f46548213a 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{active_scaffold_vho} - s.version = "3.0.20" + s.version = "3.1.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Many, see README"] @@ -305,7 +305,7 @@ Gem::Specification.new do |s| s.licenses = ["MIT"] s.require_paths = ["lib"] s.rubygems_version = %q{1.3.7} - s.summary = %q{Rails 3 Version of activescaffold supporting prototype and jquery} + s.summary = %q{Rails 3.1 Version of activescaffold supporting prototype and jquery} s.test_files = [ "test/bridges/bridge_test.rb", "test/config/base_test.rb", @@ -366,7 +366,7 @@ Gem::Specification.new do |s| s.add_development_dependency(%q<rcov>, [">= 0"]) s.add_runtime_dependency(%q<render_component_vho>, [">= 0"]) s.add_runtime_dependency(%q<verification>, [">= 0"]) - s.add_runtime_dependency(%q<rails>, ["~> 3.0.0"]) + s.add_runtime_dependency(%q<rails>, ["~> 3.1.0"]) else s.add_dependency(%q<shoulda>, [">= 0"]) s.add_dependency(%q<bundler>, ["~> 1.0.0"]) @@ -374,7 +374,7 @@ Gem::Specification.new do |s| s.add_dependency(%q<rcov>, [">= 0"]) s.add_dependency(%q<render_component_vho>, [">= 0"]) s.add_dependency(%q<verification>, [">= 0"]) - s.add_dependency(%q<rails>, ["~> 3.0.0"]) + s.add_dependency(%q<rails>, ["~> 3.1.0"]) end else s.add_dependency(%q<shoulda>, [">= 0"]) @@ -383,7 +383,7 @@ Gem::Specification.new do |s| s.add_dependency(%q<rcov>, [">= 0"]) s.add_dependency(%q<render_component_vho>, [">= 0"]) s.add_dependency(%q<verification>, [">= 0"]) - s.add_dependency(%q<rails>, ["~> 3.0.0"]) + s.add_dependency(%q<rails>, ["~> 3.1.0"]) end end From 135592db881ae37845291b7ac3e84e4441893db0 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 28 May 2011 00:01:35 +0200 Subject: [PATCH 1127/2024] Bugfix: at least fix undefined method `render' for module `ActionView::Rendering' however do nt think that rendering will work... --- .../extensions/action_view_rendering.rb | 153 +++++++++--------- 1 file changed, 78 insertions(+), 75 deletions(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 8c8e256069..b9b55a0ff3 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -14,7 +14,9 @@ def find_all_templates(name, prefix = nil, partial = false) end # wrap the action rendering for ActiveScaffold views -module ActionView::Rendering #:nodoc: +module ActionView #:nodoc: + class Renderer + # # Adds two rendering options. # # ==render :super @@ -36,88 +38,89 @@ module ActionView::Rendering #:nodoc: # # Defining options[:label] lets you completely customize the list title for the embedded scaffold. # - def render_with_active_scaffold(*args, &block) - if args.first == :super - last_view = @view_stack.last - options = args[1] || {} - options[:locals] ||= {} - options[:locals].reverse_merge!(last_view[:locals] || {}) - if last_view[:templates].nil? - last_view[:templates] = lookup_context.find_all_templates(last_view[:view], controller_path, !last_view[:is_template]) - last_view[:templates].shift - end - options[:template] = last_view[:templates].shift - @view_stack << last_view - result = render_without_active_scaffold options - @view_stack.pop - result - elsif args.first.is_a?(Hash) and args.first[:active_scaffold] - require 'digest/md5' - options = args.first + def render_with_active_scaffold(*args, &block) + if args.first == :super + last_view = @view_stack.last + options = args[1] || {} + options[:locals] ||= {} + options[:locals].reverse_merge!(last_view[:locals] || {}) + if last_view[:templates].nil? + last_view[:templates] = lookup_context.find_all_templates(last_view[:view], controller_path, !last_view[:is_template]) + last_view[:templates].shift + end + options[:template] = last_view[:templates].shift + @view_stack << last_view + result = render_without_active_scaffold options + @view_stack.pop + result + elsif args.first.is_a?(Hash) and args.first[:active_scaffold] + require 'digest/md5' + options = args.first - remote_controller = options[:active_scaffold] - constraints = options[:constraints] - conditions = options[:conditions] - eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s) - session["as:#{eid}"] = {:constraints => constraints, :conditions => conditions, :list => {:label => args.first[:label]}} - options[:params] ||= {} - options[:params].merge! :eid => eid, :embedded => true - - id = "as_#{eid}-content" - url_options = {:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params]) - - if controller.respond_to?(:render_component_into_view) - controller.send(:render_component_into_view, url_options) - else - content_tag(:div, {:id => id}) do - url = url_for(url_options) - link_to(remote_controller.to_s, url, {:remote => true, :id => id}) << - if ActiveScaffold.js_framework == :prototype - javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true});") - elsif ActiveScaffold.js_framework == :jquery - javascript_tag("$('##{id}').load('#{url}');") + remote_controller = options[:active_scaffold] + constraints = options[:constraints] + conditions = options[:conditions] + eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s) + session["as:#{eid}"] = {:constraints => constraints, :conditions => conditions, :list => {:label => args.first[:label]}} + options[:params] ||= {} + options[:params].merge! :eid => eid, :embedded => true + + id = "as_#{eid}-content" + url_options = {:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params]) + + if controller.respond_to?(:render_component_into_view) + controller.send(:render_component_into_view, url_options) + else + content_tag(:div, {:id => id}) do + url = url_for(url_options) + link_to(remote_controller.to_s, url, {:remote => true, :id => id}) << + if ActiveScaffold.js_framework == :prototype + javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true});") + elsif ActiveScaffold.js_framework == :jquery + javascript_tag("$('##{id}').load('#{url}');") + end end end - end - - else - options = args.first - if options.is_a?(Hash) - current_view = {:view => options[:partial], :is_template => false} if options[:partial] - current_view = {:view => options[:template], :is_template => !!options[:template]} if current_view.nil? && options[:template] - current_view[:locals] = options[:locals] if !current_view.nil? && options[:locals] - if current_view.present? - @view_stack ||= [] - @view_stack << current_view + + else + options = args.first + if options.is_a?(Hash) + current_view = {:view => options[:partial], :is_template => false} if options[:partial] + current_view = {:view => options[:template], :is_template => !!options[:template]} if current_view.nil? && options[:template] + current_view[:locals] = options[:locals] if !current_view.nil? && options[:locals] + if current_view.present? + @view_stack ||= [] + @view_stack << current_view + end end + result = render_without_active_scaffold(*args, &block) + @view_stack.pop if current_view.present? + result end - result = render_without_active_scaffold(*args, &block) - @view_stack.pop if current_view.present? - result end - end - alias_method_chain :render, :active_scaffold - + alias_method_chain :render, :active_scaffold - def partial_pieces(partial_path) - if partial_path.include?('/') - return File.dirname(partial_path), File.basename(partial_path) - else - return controller.class.controller_path, partial_path + + def partial_pieces(partial_path) + if partial_path.include?('/') + return File.dirname(partial_path), File.basename(partial_path) + else + return controller.class.controller_path, partial_path + end end - end - - # This is the template finder logic, keep it updated with however we find stuff in rails - # currently this very similar to the logic in ActionBase::Base.render for options file - # TODO: Work with rails core team to find a better way to check for this. - def template_exists?(template_name, lookup_overrides = false) - begin - method = 'find_template' - method << '_without_active_scaffold' unless lookup_overrides - self.view_paths.send(method, template_name, @template_format) - return true - rescue ActionView::MissingTemplate => e - return false + + # This is the template finder logic, keep it updated with however we find stuff in rails + # currently this very similar to the logic in ActionBase::Base.render for options file + # TODO: Work with rails core team to find a better way to check for this. + def template_exists?(template_name, lookup_overrides = false) + begin + method = 'find_template' + method << '_without_active_scaffold' unless lookup_overrides + self.view_paths.send(method, template_name, @template_format) + return true + rescue ActionView::MissingTemplate => e + return false + end end end end From 0980077bad2525eb2013caa3f0ff581d51b98d85 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 28 May 2011 00:35:19 +0200 Subject: [PATCH 1128/2024] Bugfix: current_scoped_methods was removed in rails 3.1 --- lib/active_scaffold/data_structures/sorting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index f4724e4b9a..753f697e5f 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -9,7 +9,7 @@ def initialize(columns) end def set_default_sorting(model) - model_scope = model.send(:current_scoped_methods) + model_scope = model.send(:build_default_scope) order_clause = model_scope.arel.order_clauses.join(",") if model_scope # If an ORDER BY clause is found set default sorting according to it, else From 1269e998e34c9e83cb028441f3e3385d94ac3fad Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 28 May 2011 11:24:26 +0200 Subject: [PATCH 1129/2024] adapt ActivescaffoldResolver for rails 3.1 for partials and templates --- lib/active_scaffold/extensions/action_view_resolver.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/extensions/action_view_resolver.rb b/lib/active_scaffold/extensions/action_view_resolver.rb index 22f9d644e2..6ae8c1ce35 100644 --- a/lib/active_scaffold/extensions/action_view_resolver.rb +++ b/lib/active_scaffold/extensions/action_view_resolver.rb @@ -1,7 +1,9 @@ module ActionView class ActiveScaffoldResolver < FileSystemResolver - def build_path(name, prefix, partial, details) - super(name, '', partial, details) + # standard resolvers have a base path to views and append a controller subdirectory + # activescaffolds view path do not have a subdir, so just remove the prefix + def find_templates(name, prefix, partial, details) + super(name,'',partial, details) end end end From bf65a3bca9e1547227815e5a552b067a07561199 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 28 May 2011 11:44:15 +0200 Subject: [PATCH 1130/2024] Fix class_inheritable_attribute deprecation warning --- lib/active_scaffold/config/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/base.rb b/lib/active_scaffold/config/base.rb index 589897107b..d6e2f604f2 100644 --- a/lib/active_scaffold/config/base.rb +++ b/lib/active_scaffold/config/base.rb @@ -26,7 +26,7 @@ def crud_type; self.class.crud_type end # define a default action_group for this action # e.g. 'members.crud' - class_inheritable_accessor :action_group + class_attribute :action_group # action_group this action should belong to attr_accessor :action_group From 56a0c072762944551b1f66a7afeb0fb05981c65e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 28 May 2011 11:54:50 +0200 Subject: [PATCH 1131/2024] default js library is jquery --- lib/active_scaffold.rb | 2 +- lib/active_scaffold_env.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 9c95a51332..020bb54142 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -126,7 +126,7 @@ def self.js_framework=(framework) end def self.js_framework - @@js_framework ||= :prototype + @@js_framework ||= :jquery end # exclude bridges you do not need diff --git a/lib/active_scaffold_env.rb b/lib/active_scaffold_env.rb index 0cbe23603e..fcf4a7c48f 100644 --- a/lib/active_scaffold_env.rb +++ b/lib/active_scaffold_env.rb @@ -11,4 +11,4 @@ ActiveRecord::Base.class_eval {include ActiveRecordPermissions::Permissions} I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'active_scaffold', 'locale', '*.{rb,yml}')] -#ActiveScaffold.js_framework = :jquery +#ActiveScaffold.js_framework = :prototype From ef6c27bdcdccd1a6321044568637d5a2359daf4d Mon Sep 17 00:00:00 2001 From: Waynn Lue <WLGades@gmail.com> Date: Thu, 2 Jun 2011 00:37:02 -0700 Subject: [PATCH 1132/2024] Fix typo in README. --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index e49fdc7ba6..4a461be35e 100644 --- a/README +++ b/README @@ -35,7 +35,7 @@ Rails 2.2.*: Active Scaffold rails-2.2 Rails 2.1.*: Active Scaffold rails-2.1 Rails < 2.1: Active Scaffold 1-1-stable (no guarantees) -Since Rails 2.3, render_component plugin is needed for nested and embbeded scaffolds. It works with rails-2.3 branch from ewildgoose repository: +Since Rails 2.3, render_component plugin is needed for nested and embedded scaffolds. It works with rails-2.3 branch from ewildgoose repository: script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3 Released under the MIT license (included) From ba771a31ab77265cacddf7274d52c8ed034d273a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 2 Jun 2011 16:49:08 +0200 Subject: [PATCH 1133/2024] changed README, for rails 3.0 you have to use rails3.0 branch of this repository --- README | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README b/README index ea87ab8e4c..888bccea77 100644 --- a/README +++ b/README @@ -37,13 +37,13 @@ Since Rails 3.0, https://github.com/rails/verification.git is also needed. If you want to install as plugins under vendor/plugins, install these versions: rails plugin install git://github.com/vhochstein/render_component.git rails plugin install git://github.com/rails/verification.git - rails plugin install git://github.com/vhochstein/active_scaffold.git + rails plugin install git://github.com/vhochstein/active_scaffold.git -r 'rails-3.0' If you want to use the gem, add to your Gemfile: gem "active_scaffold_vho" -In case you would like to use most recent commit: - gem 'active_scaffold_vho', :git => 'git://github.com/vhochstein/active_scaffold.git' +In case you would like to use most recent commit with rails 3.0: + gem 'active_scaffold_vho', :git => 'git://github.com/vhochstein/active_scaffold.git, :branch => 'rails-3.0' == Pick your own javascript framework From 4802d23b1609bcf6d4356a24cbdb09a94f4e4bb6 Mon Sep 17 00:00:00 2001 From: robg <rob.golkosky@gmail.com> Date: Fri, 17 Jun 2011 08:33:09 -0700 Subject: [PATCH 1134/2024] Check against instance methods rather than class methods before generating delete helpers. --- .../bridges/paperclip/lib/paperclip_bridge_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb b/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb index 359a79544a..30124a23de 100644 --- a/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +++ b/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb @@ -7,7 +7,7 @@ module PaperclipBridgeHelpers self.thumbnail_style = :thumbnail def self.generate_delete_helper(klass, field) - klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("delete_#{field}=") + klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.instance_methods.include?("delete_#{field}=") attr_reader :delete_#{field} def delete_#{field}=(value) @@ -23,4 +23,4 @@ def delete_#{field}=(value) end end end -end \ No newline at end of file +end From 61fa48585fec8172cd083eab3ce354445246d295 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 18 Jun 2011 12:22:21 +0200 Subject: [PATCH 1135/2024] first steps to use new asset pipeline for css files --- app/assets/stylesheets/active_scaffold-ie.css | 35 + app/assets/stylesheets/active_scaffold.css | 1076 +++++++++++++++++ lib/active_scaffold.rb | 1 + lib/active_scaffold/engine.rb | 8 + 4 files changed, 1120 insertions(+) create mode 100644 app/assets/stylesheets/active_scaffold-ie.css create mode 100644 app/assets/stylesheets/active_scaffold.css create mode 100644 lib/active_scaffold/engine.rb diff --git a/app/assets/stylesheets/active_scaffold-ie.css b/app/assets/stylesheets/active_scaffold-ie.css new file mode 100644 index 0000000000..7992a64468 --- /dev/null +++ b/app/assets/stylesheets/active_scaffold-ie.css @@ -0,0 +1,35 @@ +/* IE hacks + ==================================== */ + +* html .active-scaffold-header, +.active-scaffold li.form-element, +.active-scaffold li.sub-section { +zoom: 1; +} + +* html .active-scaffold td .messages-container { +border-top: solid 1px #DAFFCD; +} + +* html .active-scaffold-header div.actions a.show_search { +background-image: none; +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../../images/active_scaffold/default/magnifier.png', sizingMethod='crop'); +} + +* html .active-scaffold .sub-form .association-record a.destroy { +background-image: none; +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../../images/active_scaffold/default/cross.png', sizingMethod='crop'); +} + +.active-scaffold-header div.actions a.disabled { +filter: alpha(opacity=50); +} + +.active-scaffold .show-view dd, +.active-scaffold li.form-element dd { +float: none; +} + +.active-scaffold li.form-element dt { +padding: 4px 0; +} diff --git a/app/assets/stylesheets/active_scaffold.css b/app/assets/stylesheets/active_scaffold.css new file mode 100644 index 0000000000..01495484c7 --- /dev/null +++ b/app/assets/stylesheets/active_scaffold.css @@ -0,0 +1,1076 @@ +/* + ActiveScaffold + (c) 2007 Richard White <rrwhite@gmail.com> + + ActiveScaffold is freely distributable under the terms of an MIT-style license. + + For details, see the ActiveScaffold web site: http://www.activescaffold.com/ +*/ + +.active-scaffold form, +.active-scaffold table, +.active-scaffold p, +.active-scaffold div, +.active-scaffold fieldset { +margin: 0; +padding: 0; +} + +.active-scaffold { +margin: 5px 0; +} + +.active-scaffold table { +width: 100%; +border-collapse: separate; +} + +.active-scaffold a, +.active-scaffold a:visited { +color: #06c; +text-decoration: none; +} + +.active-scaffold a.disabled { +color: #999; +} + +.active-scaffold a:hover, .active-scaffold div.hover, .active-scaffold td span.hover { +background-color: #ff8; +} + +.active-scaffold div.actions a img, +.active-scaffold td.actions a img { +border: none; +vertical-align: middle; +} + +.active-scaffold div.actions a.disabled img, +.active-scaffold td.actions a.disabled img { +opacity: 0.5; +} + +.active-scaffold .clear-fix { +clear: both; +} + +noscript.active-scaffold { +border-left: solid 5px #f66; +background-color: #fbb; +font-size: 11px; +font-weight: bold; +padding: 5px 20px 5px 5px; +color: #333; +} + +/* Header + ======================== */ + +.active-scaffold-header { +position: relative; +} + +.blue-theme .active-scaffold-header { +background-color: #005CB8; +} + +.active-scaffold-header h2 { +padding: 2px 0px; +margin: 0; +color: #555; +font: bold 160% arial, sans-serif; +} + +.blue-theme .active-scaffold-header h2 { +color: #fff; +padding: 2px 5px 4px 5px; +} + +.active-scaffold-header div.actions a, +.active-scaffold-header div.actions { +float: right; +font: bold 14px arial; +letter-spacing: -1px; +text-decoration: none; +padding: 1px 2px; +white-space: nowrap; +margin-left: 5px; +background-position: 1px 50%; +background-repeat: no-repeat; +} + +.active-scaffold-header div.actions a { +padding: 5px 5px; +margin-left: 0px; +} + +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a { +padding: 1px 5px; +} + +.active-scaffold-header div.actions div.action_group { +display: inline; +float: right; +} + +.active-scaffold-header div.actions div.action_group li a, +.active-scaffold-header div.actions div.action_group li div { +float: none; +margin: 0; +} + +.active-scaffold-header div.actions .action_group ul { +line-height: 130%; +top: 19px; +} + +.active-scaffold .active-scaffold .active-scaffold-header div.actions .action_group ul { +top: 14px; +} + +.view .active-scaffold-header div.actions a, +.view .active-scaffold-header div.actions div, +.view .active-scaffold-header div.actions div.action_group { +float: left; +} + +.blue-theme .active-scaffold-header div.actions a { +color: #fff; +} + +.active-scaffold-header div.actions a.disabled { +color: #666; +opacity: 0.5; +} + +.blue-theme .active-scaffold-header div.actions a.disabled { +color: #fff; +opacity: 0.5; +} + +.active-scaffold-header div.actions a.new, +.active-scaffold-header div.actions a.new_existing, +.active-scaffold-header div.actions a.show_search, +.active-scaffold-header div.actions a.show_config_list, +.active-scaffold-header div.actions div.action_group div { +margin:0; +padding: 5px 5px 5px 25px; +background-position: 5px 50%; +background-repeat: no-repeat; +} + +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.new, +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.new_existing, +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.show_search, +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.show_config_list, +.active-scaffold .active-scaffold .active-scaffold-header div.actions div.action_group > div { +margin:0; +padding: 1px 5px 1px 20px; +background-position: 1px 50%; +background-repeat: no-repeat; +} + +.active-scaffold-header div.actions div.action_group div { + background-image: url(../../../images/active_scaffold/default/gears.png); /* default icon for actions or override with css */ +} + +.active-scaffold-header div.actions a.show_config_list { + background-image: url(../../../images/active_scaffold/default/config.png); +} + +.active-scaffold-header div.actions a.new, +.active-scaffold-header div.actions a.new_existing { +background-image: url(../../../images/active_scaffold/default/add.gif); +} + +.active-scaffold-header div.actions a.show_search { +background-image: url(../../../images/active_scaffold/default/magnifier.png); +} + +.blue-theme .active-scaffold-header div.actions a:hover { +background-color: #378CDF; +} + +.active-scaffold-header div.actions a.disabled:hover { +background-color: transparent; +cursor: default; +} + +.active-scaffold-header div.actions { +position: absolute; +right: 5px; +top: 5px; +text-align: right; +} + +/* Table :: Column Headers + ============================= */ + +.active-scaffold th { +background-color: #555; +text-align: left; +} + +.active-scaffold th a, +.active-scaffold th p { +font: bold 11px arial, sans-serif; +display: block; +background-color: #555; +} + +.active-scaffold th a, .active-scaffold th a:visited { +color: #fff; +padding: 2px 2px 2px 5px; +} + +.active-scaffold th p { +color: #eee; +padding: 2px 5px; +} + +.active-scaffold th a:hover { +background-color: #000; +color: #ff8; +} + +.active-scaffold th.sorted { +background-color: #333; +} + +.active-scaffold th.sorted a { +padding-right: 18px; +} + +.active-scaffold th.asc a, +.active-scaffold th.asc a:hover { +background: #333 url(../../../images/active_scaffold/default/arrow_up.gif) right 50% no-repeat; +} + +.active-scaffold th.desc a, +.active-scaffold th.desc a:hover { +background: #333 url(../../../images/active_scaffold/default/arrow_down.gif) right 50% no-repeat; +} + +.active-scaffold th.loading a, +.active-scaffold th.loading a:hover { +background: #333 url(../../../images/active_scaffold/default/indicator-small.gif) right 50% no-repeat; +} + +.active-scaffold th .mark_heading { +margin-left: 5px; +} + +/* Table :: Record Rows + ============================= */ + +.active-scaffold tr.record { + background-color: #E6F2FF; +} +.active-scaffold tr.record td { +padding: 5px 4px; +color: #333; +font-family: Verdana, sans-serif; +font-size: 11px; +border-bottom: solid 1px #C5DBF7; +border-left: solid 1px #C5DBF7; +} + +.active-scaffold tr.record td.messages-container { +padding: 0px; +} + +.active-scaffold tr.even-record { +background-color: #fff; +} +.active-scaffold tr.even-record td { +border-left-color: #ddd; +} + +.active-scaffold tr.record td.sorted { +background-color: #B9DCFF; +border-bottom-color: #AFD0F5; +} + +.active-scaffold tr.even-record td.sorted { +background-color: #E6F2FF; +border-bottom-color: #AFD0F5; +} + +.active-scaffold tbody.records td.empty { +color: #999; +text-align: center; +} + +.active-scaffold td.numeric, +.active-scaffold-calculations td { +text-align: right; +} + +/* Table :: Actions (Edit, Delete) + ============================= */ +.active-scaffold tr.record td.actions { +border-right: solid 1px #ccc; +padding: 0; +min-width: 1%; +} + +.active-scaffold tr.record td.actions table { +float: right; +width: auto; +margin-right: 5px; +} + +.active-scaffold tr.record td.actions table td { +border: none; +text-align: right; +padding: 0 2px; +} + +.active-scaffold tr.record td.actions a, +.active-scaffold tr.record td.actions div { +font: bold 11px verdana, sans-serif; +letter-spacing: -1px; +padding: 2px; +margin: 0 2px; +line-height: 16px; +white-space: nowrap; +} + +.active-scaffold tr.record td.actions a.disabled { +color: #666; +opacity: 0.5; +} + +.active-scaffold .actions .action_group div:hover { +background-color: #ff8; +} + +.active-scaffold .actions .action_group { +position: relative; +text-align: left; +color: #0066CC; +} + +.active-scaffold .actions .action_group ul { +border: 2px solid #005CB8; +list-style-type: none; +margin: 0; +padding: 0; +position: absolute; +line-height: 200%; +display: none; +width: 150px; +right: 0px; +} + +.active-scaffold .actions .action_group ul ul { +display: none; +position: absolute; +top: 0; +right: 150px; +} + +.active-scaffold .actions .action_group ul li { +background: none repeat scroll 0 0 #EEE; +border-top: 1px dashed #222; +display: block; +position: relative; +width: auto; +z-index: 2; +} + +.active-scaffold .actions .action_group ul li div { + margin: 0; + padding: 5px 5px 5px 25px; + background-position: 5px 50%; + background-repeat: no-repeat; +} + +.active-scaffold .actions .action_group ul li a { + display: block; + color: #333; + margin: 0; + padding: 5px 5px 5px 25px; + background-position: 5px 50%; + background-repeat: no-repeat; +} + +.active-scaffold .actions .action_group ul li.top { +border-top: 0px solid #005CB8; +} + +.active-scaffold .actions .action_group:hover ul ul, +.active-scaffold .actions .action_group:hover ul ul ul { +display: none; +} + +.active-scaffold .actions .action_group:hover ul, +.active-scaffold .actions .action_group ul li:hover > ul, +.active-scaffold .actions .action_group ul ul li:hover ul { +display: block; +} + +/* Table :: Inline Adapter + ============================= */ + +.active-scaffold .view { +background-color: #DAFFCD; +padding: 4px; +border: solid 1px #7FcF00; +} + +.active-scaffold tbody.records td.inline-adapter-cell .view { +border-top: none; +} + +.active-scaffold .before-header td.inline-adapter-cell .view { +border-bottom: none; +} + +.active-scaffold a.inline-adapter-close { +float: right; +text-indent: -4000px; +width: 16px; +height: 17px; +background: url(../../../images/active_scaffold/default/close.gif) 0 0 no-repeat; +} + +/* Nested + ======================== */ + +.blue-theme .active-scaffold .active-scaffold-header, +.blue-theme .active-scaffold .active-scaffold-footer { +background-color: #1F7F00; + +background: transparent; +} + +.active-scaffold .active-scaffold .active-scaffold-header { +margin-right: 15px; +} + +.active-scaffold .active-scaffold .active-scaffold-header h2 { +font-size: 12px; +font-weight: bold; +} + +.blue-theme .active-scaffold .active-scaffold-header h2, +.active-scaffold .active-scaffold .active-scaffold-footer { +color: #444; +} + +.active-scaffold .active-scaffold .active-scaffold-header div.actions { +top: 0px; +right: 0px; +} + +.active-scaffold .active-scaffold .active-scaffold-header div.actions a, +.active-scaffold .active-scaffold .active-scaffold-header div.actions div { +font: bold 11px verdana, sans-serif; +} + +.blue-theme .active-scaffold .active-scaffold-header div.actions a, +.blue-theme .active-scaffold .active-scaffold-header div.actions a:visited { +color: #06c; +} + +.blue-theme .active-scaffold .active-scaffold-header div.actions a:hover { +background-color: #ff8; +} + +.active-scaffold .active-scaffold .view { +background-color: transparent; +padding: 0px; +border: none; +} + +.active-scaffold .active-scaffold td { +background-color: #ECFFE7; +border-bottom: solid 1px #CDF7C5; +border-left: solid 1px #CDF7C5; +} + +.active-scaffold .active-scaffold td.inline-adapter-cell { +background-color: #FFFFBB; +padding: 4px; +border: solid 1px #DDDF37; +border-top: none; +} + +.active-scaffold .active-scaffold .active-scaffold td.inline-adapter-cell { +background-color: #DAFFCD; +padding: 4px; +border: solid 1px #7FcF00; +border-top: none; +} + +.active-scaffold .active-scaffold .active-scaffold-footer { +font-size: 11px; +} + +/* Footer + ========================== */ + +.active-scaffold-calculations td { +background-color: #eee; +border-top: 2px solid #005CB8; +font: bold 12px arial, sans-serif; +} + +.active-scaffold .active-scaffold-footer { +padding: 3px 0px 2px 0px; +border-bottom: none; +font: bold 12px arial, sans-serif; +} + +.blue-theme .active-scaffold-footer { +background-color: #005CB8; +color: #ccc; +} + +.active-scaffold-footer .active-scaffold-pagination { +float: right; +white-space: nowrap; +margin-right: 5px; +} + +.blue-theme .active-scaffold-footer .active-scaffold-records { +margin-left: 5px; +} + +.active-scaffold-footer a { +text-decoration: none; +letter-spacing: 0; +padding: 0 2px; +margin: 0 -2px; +font: bold 12px arial, sans-serif; +} + +.blue-theme .active-scaffold-footer a, +.blue-theme .active-scaffold-footer a:visited { +color: #fff; +} + +.blue-theme .active-scaffold-footer a:hover { +background-color: #378CDF; +} + +.active-scaffold-footer .next { +margin-left: 0; +padding-left: 5px; +border-left: solid 1px #ccc; +} + +.active-scaffold-footer .previous { +margin-right: 0; +padding-right: 5px; +border-right: solid 1px #ccc; +} + +/* Messages + ========================= */ + +.active-scaffold .messages-container, +.active-scaffold .active-scaffold .messages-container{ +padding: 0; +margin: 0 7px; +border: none; +} + +.active-scaffold .empty-message, .active-scaffold .filtered-message { +background-color: #e8e8e8; +padding: 4px; +text-align: center; +color: #666; +} + +.active-scaffold .message { +font-size: 11px; +font-weight: bold; +padding: 5px 20px 5px 5px; +color: #333; +position: relative; +margin: 2px 7px; +line-height: 12px; +} + +.active-scaffold .message a { +position: absolute; +right: 10px; +top: 4px; +padding: 0; +font: bold 11px verdana, sans-serif; +letter-spacing: -1px; +} + +.active-scaffold .messages-container .message { +margin: 0; +} + +.active-scaffold .error-message { +border-left: solid 5px #f66; +background-color: #fbb; +} + +.active-scaffold .warning-message { +border-left: solid 5px #ff6; +background-color: #ffb; +} + +.active-scaffold .info-message { +border-left: solid 5px #66f; +background-color: #bbf; +} + +/* Error Styling + ========================== */ + +.active-scaffold .errorExplanation { +background-color: #fcc; +margin: 2px 0; +border: solid 1px #f66; +} + +.active-scaffold fieldset { +clear: both; +} + +.active-scaffold .errorExplanation h2 { +padding: 2px 5px; +color: #333; +font-size: 11px; +margin: 0; +letter-spacing: 0; +font-family: Verdana; +background-color: #f66; +} + +.active-scaffold .errorExplanation ul { +margin: 0; +padding: 0 2px 4px 25px; +list-style: disc; +} + +.active-scaffold .errorExplanation p { +font-size: 11px; +padding: 2px 5px; +font-family: Verdana; +margin: 0; +} + +.active-scaffold .errorExplanation ul li { +font: bold 11px verdana; +letter-spacing: -1px; +margin: 0; +padding: 0; +background-color: transparent; +} + +/* Loading Indicators + ============================== */ + +.active-scaffold .loading-indicator { +vertical-align: text-bottom; +width: 16px; +margin: 0; +} + +.active-scaffold .active-scaffold-header .loading-indicator { +margin-bottom: 3px; +} + +/* Show + ============================= */ + +.active-scaffold .show-view dl { +margin-left: 5px; +} + +.active-scaffold .show-view dt { +width: 12em; +float: left; +clear: left; +font: normal 11px verdana, sans-serif; +color: #555; +line-height: 16px; +} + +.active-scaffold .show-view dd { +float: left; +font: bold 14px arial; +padding-left: 5px; +margin-bottom: 5px; +} + +/* Form + ============================== */ + +.active-scaffold .submit { +font-weight: bold; +font-size: 14px; +font-family: Arial, sans-serif; +letter-spacing: 0; +margin: 0; +margin-top: 5px; +} + +.active-scaffold form p { +clear: both; +} + +.active-scaffold fieldset { +border: none; +} + +.active-scaffold h4, +.active-scaffold h5 { +padding: 2px; +margin: 0; +text-transform: none; +color: #1F7F00; +letter-spacing: -1px; +font: bold 16px arial; +} + +.active-scaffold h5 { +padding: 0; +margin: 5px 0 2px 0; +font-size: 14px; +letter-spacing: 0; +} + +.active-scaffold ol { +clear: both; +float: none; +padding: 2px; +margin-left: 5px; +list-style: none; +} + +.active-scaffold p.form-footer { +clear: both; +} + +.active-scaffold a.as_cancel, +.active-scaffold p.form-footer a { +font: bold 14px arial, sans-serif; +letter-spacing: 0; +} + +/* Form :: Fields + ============================== */ + +.active-scaffold li.form-element { +clear: both; +} + +.active-scaffold label { +font: normal 11px verdana, sans-serif; +color: #555; +} + +.active-scaffold li.form-element dt { +float: left; +width: 12em; +padding: 6px 0; +} + +.active-scaffold li.form-element dd { +float: left; +} + +.active-scaffold li.form-element dd input[type="checkbox"] { +margin-top: 6px; +} + +.active-scaffold .form dd { +margin: 0; +} + + +.active-scaffold .description { +display: inline-block; +color: #999; +font-size: 10px; +margin-left: 5px; +} + +.active-scaffold .required label { +font-weight: bold; +} + +.active-scaffold label.example { +font-size: 11px; +font-family: arial; +color: #888; +} + +.active-scaffold input.text-input, +.active-scaffold select { +font: bold 16px arial; +letter-spacing: -1px; +border: solid 1px #1F7F00; +} + +.active-scaffold input.text-input { +padding: 2px; +} + +.active-scaffold .fieldWithErrors input, +.active-scaffold .field_with_errors input, +.active-scaffold .fieldWithErrors textarea, +.active-scaffold .field_with_errors textarea, +.active-scaffold .fieldWithErrors select, +.active-scaffold .field_with_errors select { +border: solid 1px #f00; +} + +.active-scaffold select { +padding: 1px; +} + +.active-scaffold input.example { +color: #aaa; +} + +.active-scaffold select:focus, +.active-scaffold input.text-input:focus { +background-color: #ffc; +} + +.active-scaffold textarea { +font-family: Arial, sans-serif; +font-size: 12px; +padding: 1px; +border: solid 1px #1F7F00; +} + +.active-scaffold .checkbox-list { +padding-left: 0px; +} + +.active-scaffold .checkbox-list li { +padding-right: 5px; +display: inline; +} + +.active-scaffold .checkbox-list li label { +padding: 0 0 0 2px; +} + +.active-scaffold .draggable-list { +float: left; +width: 300px; +margin-right: 15px; +min-height: 30px; +max-height: 100px; +overflow: auto; +background-color: #FFFF88; +} + +.active-scaffold .draggable-list.hover { +opacity: 0.5; +} + +.active-scaffold .draggable-list.selected { +background-color: #7FCF00; +} + +.active-scaffold .draggable-list li { +display: block; +} + +.active-scaffold .draggable-list input { +display: none; +} + +/* Form :: Sub-Sections + ============================== */ + +.active-scaffold li.sub-section { +clear: left; +padding: 5px 0; +} + +/* Form :: Association Sub-Forms + ============================== */ + +.active-scaffold .sub-form { +float: left; +clear: left; +padding: 5px 0; +padding-left: 5px; +} + +.active-scaffold .sub-form h5 { +margin-left: -5px; +} + +.active-scaffold .sub-form table, +.active-scaffold .sub-form table td { +width: auto; +background: none; +} + +.active-scaffold .sub-form table th { +font: normal 10px verdana, sans-serif; +color: #555; +padding: 0 5px 0 1px; +background: none; +} + +.active-scaffold .horizontal-sub-form td dt label { +display: none; +} + +.active-scaffold .sub-form .checkbox-list { +padding: 0 2px 2px 2px; +background-color: #fff; +border: solid 1px #1F7F00; +} + +.active-scaffold .sub-form .checkbox-list label { +display: block; +} + +.active-scaffold .sub-form table td { +border: none; +background-color: transparent; +padding: 1px; +vertical-align: top; +color: #999; +} + +.active-scaffold .sub-form .actions { +vertical-align: middle; +background-color: transparent; +clear: left; +} + +.active-scaffold .sub-form .association-record a.destroy { +font-weight: bold; +display: block; +height: 16px; +padding: 0; +width: 16px; +text-indent: -4000px; +background: url(../../../images/active_scaffold/default/cross.png) 0 0 no-repeat; +} + +.active-scaffold .sub-form .locked a.destroy { +display: none; +} + +.active-scaffold .sub-form .association-record a { +font: bold 12px arial; +} + +.active-scaffold .sub-form input.text-input, +.active-scaffold .sub-form select { +letter-spacing: 0; +font: bold 12px arial; +} + +.active-scaffold .sub-form .footer-wrapper { +margin-top: 3px; +margin-right: 10px; +} + +.active-scaffold .sub-form .footer { +color: #999; +padding: 3px 5px; +} + +.active-scaffold .sub-form .footer select, +.active-scaffold .sub-form .footer input { +font-weight: bold; +font-size: 12px; +padding: 0; +} + +.active-scaffold a.visibility-toggle { +font-size: 100%; +} + +.active-scaffold-found { + float:left; +} + +.as_touch a.inline-adapter-close { +width: 25px; +height: 27px; +background: url(../../../images/active_scaffold/default/close_touch.png) 0 0 no-repeat; +} + +.as_touch .as_paginate { +font-size: 20px; +padding: 3px 10px; +} + +.as_touch .active-scaffold-header div.actions a { +padding: 7px 5px; +} + +.as_touch .active-scaffold .active-scaffold-header div.actions a { +padding: 7px 5px; +} + +.as_touch .active-scaffold-header div.actions .action_group ul { +line-height: 130%; +top: 23px; +} + +.as_touch .active-scaffold .active-scaffold-header div.actions .action_group ul { +top: 23px; +} + +.as_touch .active-scaffold-header div.actions a.new, +.as_touch .active-scaffold-header div.actions a.new_existing, +.as_touch .active-scaffold-header div.actions a.show_search, +.as_touch .active-scaffold-header div.actions a.show_config_list, +.as_touch .active-scaffold-header div.actions div.action_group div { +padding: 7px 5px 7px 25px; +} + +.as_touch .active-scaffold .active-scaffold-header div.actions > a.new, +.as_touch .active-scaffold .active-scaffold-header div.actions > a.new_existing, +.as_touch .active-scaffold .active-scaffold-header div.actions > a.show_search, +.as_touch .active-scaffold .active-scaffold-header div.actions > a.show_config_list, +.as_touch .active-scaffold .active-scaffold-header div.actions div.action_group > div { +padding: 7px 5px 7px 25px; +background-position: 5px 50%; +} + +.as_touch .actions .action_group ul li div { +padding: 7px 5px 7px 25px; +} + +.as_touch .actions .action_group ul li a { +padding: 7px 5px 7px 25px; +} + +.as_touch .active-scaffold-header h2 { +padding: 4px 0px; +} + +.as_touch .active-scaffold .active-scaffold-header div.actions a, +.as_touch .active-scaffold .active-scaffold-header div.actions div { + font: bold 14px arial; +} + +.as_touch .active-scaffold .active-scaffold-header div.actions { + right: 15px; +} + +.as_touch tr.record { +line-height: 130%; +} + +.as_touch th a, .as_touch th a:visited { +color: #fff; +padding: 5px 2px 5px 5px; +} + +.as_touch tr.record td { +padding: 5px 10px; +} \ No newline at end of file diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 020bb54142..2d894cb3c6 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -17,6 +17,7 @@ require 'active_scaffold/responds_to_parent' require 'active_scaffold/version' +require 'active_scaffold/engine' module ActiveScaffold autoload :AttributeParams, 'active_scaffold/attribute_params' diff --git a/lib/active_scaffold/engine.rb b/lib/active_scaffold/engine.rb new file mode 100644 index 0000000000..7c63cc5592 --- /dev/null +++ b/lib/active_scaffold/engine.rb @@ -0,0 +1,8 @@ +module ActiveScaffold + #do not use module Rails... cause Rails.logger will fail + # not sure if it is a must though... + #module Rails + class Engine < ::Rails::Engine + end + #end +end From 836f319dd60b2a7ddb4123ccaf3fa0c8376da08f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 18 Jun 2011 17:47:04 +0200 Subject: [PATCH 1136/2024] add javascript files to asset_pipeline however erb processing is nt working for sprocket manifest file.. :-( --- app/assets/javascripts/active_scaffold.js.erb | 11 + .../javascripts/jquery/active_scaffold.js | 1037 +++++++++++++++++ .../javascripts/jquery/jquery.editinplace.js | 743 ++++++++++++ .../javascripts/prototype/active_scaffold.js | 1028 ++++++++++++++++ .../javascripts/prototype/dhtml_history.js | 870 ++++++++++++++ .../prototype/form_enhancements.js | 117 ++ app/assets/javascripts/prototype/index.js | 0 .../javascripts/prototype/rico_corner.js | 370 ++++++ 8 files changed, 4176 insertions(+) create mode 100644 app/assets/javascripts/active_scaffold.js.erb create mode 100644 app/assets/javascripts/jquery/active_scaffold.js create mode 100644 app/assets/javascripts/jquery/jquery.editinplace.js create mode 100644 app/assets/javascripts/prototype/active_scaffold.js create mode 100644 app/assets/javascripts/prototype/dhtml_history.js create mode 100644 app/assets/javascripts/prototype/form_enhancements.js create mode 100644 app/assets/javascripts/prototype/index.js create mode 100644 app/assets/javascripts/prototype/rico_corner.js diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb new file mode 100644 index 0000000000..1bae6b4758 --- /dev/null +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -0,0 +1,11 @@ +// This is a manifest file that'll be compiled into including all the files listed below. +// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically +// be included in the compiled file accessible from http://example.com/assets/application.js +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// the compiled file. +// +<% if ActiveScaffold.js_framework == :jquery %> +//= require jquery/active_scaffold +<% else %> +//= require prototype/active_scaffold +<% end %> diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js new file mode 100644 index 0000000000..747e4d7735 --- /dev/null +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -0,0 +1,1037 @@ +$(document).ready(function() { + $('form.as_form').live('ajax:loading', function(event) { + var as_form = $(this).closest("form"); + if (as_form && as_form.attr('data-loading') == 'true') { + ActiveScaffold.disable_form(as_form); + } + return true; + }); + + $('form.as_form').live('ajax:complete', function(event) { + var as_form = $(this).closest("form"); + if (as_form && as_form.attr('data-loading') == 'true') { + ActiveScaffold.enable_form(as_form); + } + }); + $('form.as_form').live('ajax:failure', function(event) { + var as_div = $(this).closest("div.active-scaffold"); + if (as_div) { + ActiveScaffold.report_500_response(as_div) + } + }); + $('form.as_form.as_remote_upload').live('submit', function(event) { + var as_form = $(this).closest("form"); + if (as_form && as_form.attr('data-loading') == 'true') { + setTimeout("ActiveScaffold.disable_form('" + as_form.attr('id') + "')", 10); + } + return true; + }); + $('a.as_action').live('ajax:before', function(event) { + var action_link = ActiveScaffold.ActionLink.get($(this)); + if (action_link) { + if (action_link.is_disabled()) { + return false; + } else { + // hack: jquery requires if you request for javascript that javascript + // is coming back, however rails has a different mantra + if (action_link.position) event.data_type = 'rails'; + if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible'); + action_link.disable(); + } + } + return true; + }); + $('a.as_action').live('ajax:success', function(event, response) { + var action_link = ActiveScaffold.ActionLink.get($(this)); + if (action_link) { + if (action_link.position) { + action_link.insert(response); + if (action_link.hide_target) action_link.target.hide(); + } else { + action_link.enable(); + } + return true; + } + return true; + }); + $('a.as_action').live('ajax:complete', function(event) { + var action_link = ActiveScaffold.ActionLink.get($(this)); + if (action_link) { + if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden'); + } + return true; + }); + $('a.as_action').live('ajax:failure', function(event) { + var action_link = ActiveScaffold.ActionLink.get($(this)); + if (action_link) { + ActiveScaffold.report_500_response(action_link.scaffold_id()); + action_link.enable(); + } + return true; + }); + $('a.as_cancel').live('ajax:before', function(event) { + var as_cancel = $(this); + var action_link = ActiveScaffold.find_action_link(as_cancel); + + if (action_link) { + var cancel_url = as_cancel.attr('href'); + var refresh_data = as_cancel.attr('data-refresh'); + if (refresh_data === 'true' && action_link.refresh_url) { + event.data_url = action_link.refresh_url; + if (action_link.position) event.data_type = 'html' + } else if (refresh_data === 'false' || typeof(cancel_url) == 'undefined' || cancel_url.length == 0) { + action_link.close(); + return false; + } + } + return true; + }); + $('a.as_cancel').live('ajax:success', function(event, response) { + var action_link = ActiveScaffold.find_action_link($(this)); + + if (action_link) { + if (action_link.position) { + action_link.close(response); + } else { + response.evalResponse(); + } + } + return true; + }); + $('a.as_cancel').live('ajax:failure', function(event) { + var action_link = ActiveScaffold.find_action_link($(this)); + if (action_link) { + ActiveScaffold.report_500_response(action_link.scaffold_id()); + } + return true; + }); + $('a.as_sort').live('ajax:before', function(event) { + var as_sort = $(this); + var history_controller_id = as_sort.attr('data-page-history'); + if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.attr('href'), history_controller_id); + as_sort.closest('th').addClass('loading'); + return true; + }); + $('a.as_sort').live('ajax:failure', function(event) { + var as_scaffold = $(this).closest('.active-scaffold'); + ActiveScaffold.report_500_response(as_scaffold); + return true; + }); + $('span.in_place_editor_field').live('hover', function(event) { + $(this).data(); // jquery 1.4.2 workaround + if (event.type == 'mouseenter') { + if (typeof($(this).data('editInPlace')) === 'undefined') $(this).addClass("hover"); + } + if (event.type == 'mouseleave') { + if (typeof($(this).data('editInPlace')) === 'undefined') $(this).removeClass("hover"); + } + return true; + }); + $('span.in_place_editor_field').live('click', function(event) { + ActiveScaffold.in_place_editor_field_clicked($(this)); + }); + $('a.as_paginate').live('ajax:before',function(event) { + var as_paginate = $(this); + var history_controller_id = as_paginate.attr('data-page-history'); + if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.attr('href'), history_controller_id); + as_paginate.prevAll('img.loading-indicator').css('visibility','visible'); + return true; + }); + $('a.as_paginate').live('ajax:failure', function(event) { + var as_scaffold = $(this).closest('.active-scaffold'); + ActiveScaffold.report_500_response(as_scaffold); + return true; + }); + $('a.as_paginate').live('ajax:complete', function(event) { + $(this).prevAll('img.loading-indicator').css('visibility','hidden'); + return true; + }); + $('input[type=button].as_add_existing').live('ajax:before', function(event) { + var url = $(this).attr('href').replace('--ID--', $(this).prev().val()); + event.data_url = url; + return true; + }); + $('input.update_form, select.update_form').live('change', function(event) { + var element = $(this); + var as_form = element.closest('form.as_form'); + var params = null; + + if (element.attr('data-update_send_form')) { + params = as_form.serialize(); + params += '&' + $.param({source_id: element.attr('id')}); + } else { + if (element.is("input:checkbox")) { + params = {value: element.is(":checked")}; + } else { + params = {value: element.val()}; + } + params.source_id = element.attr('id'); + } + + $.ajax({ + url: element.attr('data-update_url'), + data: params, + beforeSend: function(event) { + element.nextAll('img.loading-indicator').css('visibility','visible'); + ActiveScaffold.disable_form(as_form) + }, + complete: function(event) { + element.nextAll('img.loading-indicator').css('visibility','hidden'); + ActiveScaffold.enable_form(as_form) + }, + error: function (xhr, status, error) { + var as_div = element.closest("div.active-scaffold"); + if (as_div) { + ActiveScaffold.report_500_response(as_div) + } + } + }); + return true; + }); + + $('select.as_search_range_option').live('change', function(event) { + ActiveScaffold[$(this).val() == 'BETWEEN' ? 'show' : 'hide']($(this).parent().find('.as_search_range_between')); + return true; + }); + + $('select.as_search_range_option').live('change', function(event) { + var element = $(this); + ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric')); + ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend')); + ActiveScaffold[(element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_range')); + return true; + }); + + $('select.as_update_date_operator').live('change', function(event) { + ActiveScaffold[$(this).val() == 'REPLACE' ? 'show' : 'hide']($(this).next()); + ActiveScaffold[$(this).val() == 'REPLACE' ? 'hide' : 'show']($(this).next().next()); + return true; + }); + + $('a[data-popup]').live('click', function(e) { + window.open($(this).attr('href')); + e.preventDefault(); + }); + + $('.hover_click').live("click", function(event) { + var element = $(this); + var ul_element = element.children('ul').first(); + if (ul_element.is(':visible')) { + element.find('ul').hide(); + } else { + ul_element.show(); + } + return false; + }); + $('.hover_click a.as_action').live('click', function(event) { + var element = $(this).closest('.hover_click'); + if (element) { + element.find('ul').hide(); + } + return true; + }); +}); + +/* Simple Inheritance + http://ejohn.org/blog/simple-javascript-inheritance/ +*/ +(function(){ + var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; + + // The base Class implementation (does nothing) + this.Class = function(){}; + + // Create a new Class that inherits from this class + Class.extend = function(prop) { + var _super = this.prototype; + + // Instantiate a base class (but only create the instance, + // don't run the init constructor) + initializing = true; + var prototype = new this(); + initializing = false; + + // Copy the properties over onto the new prototype + for (var name in prop) { + // Check if we're overwriting an existing function + prototype[name] = typeof prop[name] == "function" && + typeof _super[name] == "function" && fnTest.test(prop[name]) ? + (function(name, fn){ + return function() { + var tmp = this._super; + + // Add a new ._super() method that is the same method + // but on the super-class + this._super = _super[name]; + + // The method only need to be bound temporarily, so we + // remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; + + return ret; + }; + })(name, prop[name]) : + prop[name]; + } + + // The dummy class constructor + function Class() { + // All construction is actually done in the init method + if ( !initializing && this.init ) + this.init.apply(this, arguments); + } + + // Populate our constructed prototype object + Class.prototype = prototype; + + // Enforce the constructor to be what we expect + Class.constructor = Class; + + // And make this class extendable + Class.extend = arguments.callee; + + return Class; + }; +})(); + +/* + jQuery delayed observer + (c) 2007 - Maxime Haineault (max@centdessin.com) + + Special thanks to Stephen Goguen & Tane Piper. + + Slight modifications by Elliot Winkler +*/ + +if (typeof(jQuery.fn.delayedObserver) === 'undefined') { + (function() { + var delayedObserverStack = []; + var observed; + + function delayedObserverCallback(stackPos) { + observed = delayedObserverStack[stackPos]; + if (observed.timer) return; + + observed.timer = setTimeout(function(){ + observed.timer = null; + observed.callback(observed.obj.val(), observed.obj); + }, observed.delay * 1000); + + observed.oldVal = observed.obj.val(); + } + + // going by + // <http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx> + // I think these codes only work when using keyup or keydown + function isNonPrintableKey(event) { + var code = event.keyCode; + return ( + event.metaKey || + (code >= 9 && code <= 16) || (code >= 27 && code <= 40) || (code >= 91 && code <= 93) || (code >= 112 && code <= 145) + ); + } + + jQuery.fn.extend({ + delayedObserver:function(delay, callback){ + $this = $(this); + + delayedObserverStack.push({ + obj: $this, timer: null, delay: delay, + oldVal: $this.val(), callback: callback + }); + + stackPos = delayedObserverStack.length-1; + + $this.keyup(function(event) { + if (isNonPrintableKey(event)) return; + observed = delayedObserverStack[stackPos]; + if (observed.obj.val() == observed.obj.oldVal) return; + else delayedObserverCallback(stackPos); + }); + } + }); + })(); +}; + + +/* + * Simple utility methods + */ + +var ActiveScaffold = { + records_for: function(tbody_id) { + if (typeof(tbody_id) == 'string') tbody_id = '#' + tbody_id; + return $(tbody_id).children('.record'); + }, + stripe: function(tbody_id) { + var even = false; + var rows = this.records_for(tbody_id); + + rows.each(function (index, row_node) { + row = $(row_node); + if (row_node.tagName != 'SCRIPT' + && !row.hasClass("create") + && !row.hasClass("update") + && !row.hasClass("inline-adapter") + && !row.hasClass("active-scaffold-calculations")) { + + if (even) row.addClass("even-record"); + else row.removeClass("even-record"); + + even = !even; + } + }); + }, + hide_empty_message: function(tbody) { + if (this.records_for(tbody).length != 0) { + var empty_message_node = $(tbody).parent().find('tbody.messages p.empty-message') + if (empty_message_node) empty_message_node.hide(); + } + }, + reload_if_empty: function(tbody, url) { + if (this.records_for(tbody).length == 0) { + $.getScript(url); + } + }, + removeSortClasses: function(scaffold) { + if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; + scaffold = $(scaffold) + scaffold.find('td.sorted').each(function(element) { + element.removeClass("sorted"); + }); + scaffold.find('th.sorted').each(function(element) { + element.removeClass("sorted"); + element.removeClass("asc"); + element.removeClass("desc"); + }); + }, + decrement_record_count: function(scaffold) { + // decrement the last record count, firsts record count are in nested lists + if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; + scaffold = $(scaffold) + count = scaffold.find('span.active-scaffold-records').last(); + if (count) count.html(parseInt(count.html(), 10) - 1); + }, + increment_record_count: function(scaffold) { + // increment the last record count, firsts record count are in nested lists + if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; + scaffold = $(scaffold) + count = scaffold.find('span.active-scaffold-records').last(); + if (count) count.html(parseInt(count.html(), 10) + 1); + }, + update_row: function(row, html) { + var even_row = false; + var replaced = null; + if (typeof(row) == 'string') row = '#' + row; + row = $(row); + if (row.hasClass('even-record')) even_row = true; + + replaced = this.replace(row, html); + if (even_row === true) replaced.addClass('even-record'); + ActiveScaffold.highlight(replaced); + }, + + replace: function(element, html) { + if (typeof(element) == 'string') element = '#' + element; + element = $(element); + element.replaceWith(html); + if (element.attr('id')) { + element = $('#' + element.attr('id')); + } + return element; + }, + + replace_html: function(element, html) { + if (typeof(element) == 'string') element = '#' + element; + element = $(element); + element.html(html); + return element; + }, + + remove: function(element) { + if (typeof(element) == 'string') element = '#' + element; + $(element).remove(); + }, + + hide: function(element) { + if (typeof(element) == 'string') element = '#' + element; + $(element).hide(); + }, + + show: function(element) { + if (typeof(element) == 'string') element = '#' + element; + $(element).show(); + }, + + reset_form: function(element) { + if (typeof(element) == 'string') element = '#' + element; + $(element).get(0).reset(); + }, + + disable_form: function(as_form) { + if (typeof(as_form) == 'string') as_form = '#' + as_form; + as_form = $(as_form) + var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); + if (loading_indicator) loading_indicator.css('visibility','visible'); + $('input[type=submit]', as_form).attr('disabled', 'disabled'); + $("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled'); + }, + + enable_form: function(as_form) { + if (typeof(as_form) == 'string') as_form = '#' + as_form; + as_form = $(as_form) + var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); + if (loading_indicator) loading_indicator.css('visibility','hidden'); + $('input[type=submit]', as_form).attr('disabled', ''); + $("input:disabled,select:disabled,textarea:disabled", as_form).attr('disabled', ''); + }, + + focus_first_element_of_form: function(form_element) { + if (typeof(form_element) == 'string') form_element = '#' + form_element; + $(form_element + ":first *:input[type!=hidden]:first").focus(); + }, + + create_record_row: function(active_scaffold_id, html, options) { + if (typeof(active_scaffold_id) == 'string') active_scaffold_id = '#' + active_scaffold_id; + tbody = $(active_scaffold_id).find('tbody.records'); + + if (options.insert_at == 'top') { + tbody.prepend(html); + var new_row = tbody.children('tr.record:first-child'); + } else if (options.insert_at == 'bottom') { + var rows = tbody.children('tr.record, tr.inline-adapter'); + var new_row = null; + if (rows.length > 0) { + new_row = rows.last().after(html).next(); + } else { + new_row = tbody.append(html).children().last(); + } + } + this.stripe(tbody); + this.hide_empty_message(tbody); + this.increment_record_count(tbody.closest('div.active-scaffold')); + ActiveScaffold.highlight(new_row); + }, + + delete_record_row: function(row, page_reload_url) { + if (typeof(row) == 'string') row = '#' + row; + row = $(row); + var tbody = row.closest('tbody.records'); + + var current_action_node = row.find('td.actions a.disabled').first(); + if (current_action_node) { + var action_link = ActiveScaffold.ActionLink.get(current_action_node); + if (action_link) { + action_link.close_previous_adapter(); + } + } + + row.remove(); + this.stripe(tbody); + this.decrement_record_count(tbody.closest('div.active-scaffold')); + this.reload_if_empty(tbody, page_reload_url); + }, + + delete_subform_record: function(record) { + if (typeof(record) == 'string') record = '#' + record; + record = $(record); + var errors = record.prev(); + if (errors.hasClass('association-record-errors')) { + this.replace_html(errors, ''); + } + this.remove(record); + }, + + report_500_response: function(active_scaffold_id) { + server_error = $(active_scaffold_id).find('td.messages-container p.server-error'); + if (!$(server_error).is(':visible')) { + server_error.show(); + } + }, + + find_action_link: function(element) { + if (typeof(element) == 'string') element = '#' + element; + var as_adapter = $(element).closest('.as_adapter'); + return ActiveScaffold.ActionLink.get(as_adapter); + }, + + scroll_to: function(element) { + if (typeof(element) == 'string') element = '#' + element; + var form_offset = $(element).offset(), + destination = form_offset.top; + $(document).scrollTop(destination); + }, + + process_checkbox_inplace_edit: function(checkbox, options) { + var checked = checkbox.is(':checked'); + if (checked === true) options['params'] += '&value=1'; + $.ajax({ + url: options.url, + type: "POST", + data: options['params'], + dataType: options.ajax_data_type, + after: function(request){ + checkbox.attr('disabled', 'disabled'); + }, + complete: function(request){ + checkbox.attr('disabled', ''); + } + }); + }, + + read_inplace_edit_heading_attributes: function(column_heading, options) { + if (column_heading.attr('data-ie_cancel_text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.attr('data-ie_cancel_text') + "</button>"; + if (column_heading.attr('data-ie_loading_text')) options.loading_text = column_heading.attr('data-ie_loading_text'); + if (column_heading.attr('data-ie_saving_text')) options.saving_text = column_heading.attr('data-ie_saving_text'); + if (column_heading.attr('data-ie_save_text')) options.save_button = '<button class="inplace_save">' + column_heading.attr('data-ie_save_text') + "</button>"; + if (column_heading.attr('data-ie_rows')) options.textarea_rows = column_heading.attr('data-ie_rows'); + if (column_heading.attr('data-ie_cols')) options.textarea_cols = column_heading.attr('data-ie_cols'); + if (column_heading.attr('data-ie_size')) options.text_size = column_heading.attr('data-ie_size'); + }, + + create_inplace_editor: function(span, options) { + span.removeClass('hover'); + span.editInPlace(options); + span.trigger('click.editInPlace'); + }, + + highlight: function(element) { + if (typeof(element) == 'string') element = $('#' + element); + if (typeof(element.effect) == 'function') { + element.effect("highlight", {}, 3000); + } + }, + + create_visibility_toggle: function(element, options) { + if (typeof(element) == 'string') element = '#' + element; + var toggable = $(element); + var toggler = toggable.prev(); + var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label; + + toggler.append(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)'); + toggler.children('a').click(function() { + toggable.toggle(); + $(this).html((toggable.is(':hidden')) ? options.show_label : options.hide_label); + return false; + }); + }, + + create_associated_record_form: function(element, content, options) { + if (typeof(element) == 'string') element = '#' + element; + var element = $(element); + if (options.singular == false) { + if (!(options.id && $('#' + options.id).size() > 0)) { + element.append(content); + } + } else { + var current = $('#' + element.attr('id') + ' tr.association-record') + if (current[0]) { + this.replace(current[0], content); + } else { + element.prepend(content); + } + } + }, + + render_form_field: function(source, content, options) { + if (typeof(source) == 'string') source = '#' + source; + var source = $(source); + var element = source.closest('.association-record'); + if (element.length == 0) { + element = source.closest('ol.form'); + } + element = element.find('.' + options.field_class); + + if (element) { + if (options.is_subform == false) { + this.replace(element.closest('dl'), content); + } else { + this.replace_html(element, content); + } + } + }, + + sortable: function(element, controller, options, url_params) { + if (typeof(element) == 'string') element = '#' + element; + var element = $(element); + var sortable_options = {}; + if (options.update === true) { + url_params.authenticity_token = $('meta[name=csrf-param]').attr('content'); + sortable_options.update = function(event, ui) { + var url = controller + '/' + options.action + '?' + url += $(this).sortable('serialize',{key: encodeURIComponent($(this).attr('id') + '[]'), expression:/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/}); + $.post(url.append_params(url_params)); + } + } + element.sortable(sortable_options); + }, + + record_select_onselect: function(edit_associated_url, active_scaffold_id, id){ + $.ajax({ + url: edit_associated_url.split('--ID--').join(id), + error: function(xhr, textStatus, errorThrown){ + ActiveScaffold.report_500_response(active_scaffold_id) + } + }); + }, + + // element is tbody id + mark_records: function(element, options) { + if (typeof(element) == 'string') element = '#' + element; + var element = $(element); + var mark_checkboxes = $('#' + element.attr('id') + ' > tr.record td.marked-column input[type="checkbox"]'); + mark_checkboxes.each(function (index) { + var item = $(this); + if(options.checked === true) { + item.attr('checked', 'checked'); + } else { + item.removeAttr('checked'); + } + item.attr('value', ('' + !options.checked)); + }); + if(options.include_mark_all === true) { + var mark_all_checkbox = element.prev('thead').find('th.marked-column_heading span input[type="checkbox"]'); + if(options.checked === true) { + mark_all_checkbox.attr('checked', 'checked'); + } else { + mark_all_checkbox.removeAttr('checked'); + } + mark_all_checkbox.attr('value', ('' + !options.checked)); + } + }, + + in_place_editor_field_clicked: function(span) { + span.data(); // jquery 1.4.2 workaround + if (typeof(span.data('editInPlace')) === 'undefined') { + var options = {show_buttons: true, + hover_class: 'hover', + element_id: 'editor_id', + ajax_data_type: "script", + update_value: 'value'}, + csrf_param = $('meta[name=csrf-param]').first(), + csrf_token = $('meta[name=csrf-token]').first(), + my_parent = span.parent(), + column_heading = null; + + if(!(my_parent.is('td') || my_parent.is('th'))){ + my_parent = span.parents('td').eq(0); + } + + if (my_parent.is('td')) { + var column_no = my_parent.prevAll('td').length; + column_heading = my_parent.closest('.active-scaffold').find('th:eq(' + column_no + ')'); + } else if (my_parent.is('th')) { + column_heading = my_parent; + } + + var render_url = column_heading.attr('data-ie_render_url'), + mode = column_heading.attr('data-ie_mode'), + record_id = span.attr('data-ie_id'); + + ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options); + + if (span.attr('data-ie_url')) { + options.url = span.attr('data-ie_url').replace(/__id__/, record_id); + } else { + options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id); + } + + if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content'); + + if (span.closest('div.active-scaffold').attr('data-eid')) { + if (options['params'].length > 0) { + options['params'] += "&"; + } + options['params'] += ("eid=" + span.closest('div.active-scaffold').attr('data-eid')); + } + + if (mode === 'clone') { + options.clone_id_suffix = record_id; + options.clone_selector = '#' + column_heading.attr('id') + ' .as_inplace_pattern'; + options.field_type = 'clone'; + } + + if (render_url) { + var plural = false; + if (column_heading.attr('data-ie_plural')) plural = true; + options.field_type = 'remote'; + options.editor_url = render_url.replace(/__id__/, record_id) + } + if (mode === 'inline_checkbox') { + ActiveScaffold.process_checkbox_inplace_edit(span.find('input:checkbox'), options); + } else { + ActiveScaffold.create_inplace_editor(span, options); + } + } + } +} + +/* + * DHTML history tie-in + */ +function addActiveScaffoldPageToHistory(url, active_scaffold_id) { + if (typeof dhtmlHistory == 'undefined') return; // it may not be loaded + + var array = url.split('?'); + var qs = new Querystring(array[1]); + var sort = qs.get('sort') + var dir = qs.get('sort_direction') + var page = qs.get('page') + if (sort || dir || page) dhtmlHistory.add(active_scaffold_id+":"+page+":"+sort+":"+dir, url); +} + +/* + * URL modification support. Incomplete functionality. + */ +String.prototype.append_params = function(params) { + var url = this; + if (url.indexOf('?') == -1) url += '?'; + else if (url.lastIndexOf('&') != url.length) url += '&'; + + for(var key in params) { + if (key) url += (key + '=' + params[key] + '&'); + } + + // the loop leaves a comma dangling at the end of string, chop it off + url = url.substring(0, url.length-1); + return url; +}; + + +/** + * A set of links. As a set, they can be controlled such that only one is "open" at a time, etc. + */ +ActiveScaffold.Actions = new Object(); +ActiveScaffold.Actions.Abstract = Class.extend({ + init: function(links, target, loading_indicator, options) { + this.target = $(target); + this.loading_indicator = $(loading_indicator); + this.options = options; + var _this = this; + this.links = $.map(links, function(link) { + var my_link = _this.instantiate_link(link); + return my_link; + }); + }, + + instantiate_link: function(link) { + throw 'unimplemented' + } +}); + +/** + * A DataStructures::ActionLink, represented in JavaScript. + * Concerned with AJAX-enabling a link and adapting the result for insertion into the table. + */ +ActiveScaffold.ActionLink = { + get: function(element) { + if (typeof(element) == 'string') element = '#' + element; + var element = $(element); + if (element.length > 0) { + element.data(); // jquery 1.4.2 workaround + if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) { + var parent = element.closest('.actions'); + if (parent.length === 0) { + // maybe an column action_link + parent = element.parent(); + } + if (parent && parent.is('td')) { + // record action + parent = parent.closest('tr.record'); + var target = parent.find('a.as_action'); + var loading_indicator = parent.find('td.actions .loading-indicator'); + new ActiveScaffold.Actions.Record(target, parent, loading_indicator); + } else if (parent && parent.is('div')) { + //table action + new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header'), parent.find('.loading-indicator')); + } + element = $(element); + } + return element.data('action_link'); + } else { + return null; + } + } +}; +ActiveScaffold.ActionLink.Abstract = Class.extend({ + init: function(a, target, loading_indicator) { + this.tag = $(a); + this.url = this.tag.attr('href'); + this.method = this.tag.attr('data-method') || 'get'; + this.target = target; + this.loading_indicator = loading_indicator; + this.hide_target = false; + this.position = this.tag.attr('data-position'); + + this.tag.data('action_link', this); + return this; + }, + + open: function(event) { + }, + + insert: function(content) { + throw 'unimplemented' + }, + + close: function() { + this.enable(); + this.adapter.remove(); + if (this.hide_target) this.target.show(); + }, + + reload: function() { + this.close(); + this.open(); + }, + + get_new_adapter_id: function() { + var id = 'adapter_'; + var i = 0; + while ($(id + i)) i++; + return id + i; + }, + + enable: function() { + return this.tag.removeClass('disabled'); + }, + + disable: function() { + return this.tag.addClass('disabled'); + }, + + is_disabled: function() { + return this.tag.hasClass('disabled'); + }, + + scaffold_id: function() { + return '#' + this.tag.closest('div.active-scaffold').attr('id'); + }, + + scaffold: function() { + return this.tag.closest('div.active-scaffold'); + }, + + update_flash_messages: function(messages) { + message_node = $(this.scaffold_id().replace(/-active-scaffold/, '-messages')); + if (message_node) message_node.html(messages); + }, + set_adapter: function(element) { + this.adapter = element; + this.adapter.addClass('as_adapter'); + this.adapter.data('action_link', this); + } +}); + +/** + * Concrete classes for record actions + */ +ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({ + instantiate_link: function(link) { + var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); + var refresh = this.target.attr('data-refresh'); + if (refresh) l.refresh_url = refresh; + + if (l.position) { + l.url = l.url.append_params({adapter: '_list_inline_adapter'}); + l.tag.attr('href', l.url); + } + l.set = this; + return l; + } +}); + +ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ + close_previous_adapter: function() { + var _this = this; + $.each(this.set.links, function(index, item) { + if (item.url != _this.url && item.is_disabled() && item.adapter) { + item.enable(); + item.adapter.remove(); + } + }); + }, + + insert: function(content) { + this.close_previous_adapter(); + + if (this.position == 'replace') { + this.position = 'after'; + this.hide_target = true; + } + + if (this.position == 'after') { + this.target.after(content); + this.set_adapter(this.target.next()); + } + else if (this.position == 'before') { + this.target.before(content); + this.set_adapter(this.target.prev()); + } + else { + return false; + } + ActiveScaffold.highlight(this.adapter.find('td')); + }, + + close: function(refreshed_content) { + if (refreshed_content) { + ActiveScaffold.update_row(this.target, refreshed_content); + } + this._super(); + }, + + enable: function() { + var _this = this; + $.each(this.set.links, function(index, item) { + if (item.url != _this.url) return; + item.tag.removeClass('disabled'); + }); + }, + + disable: function() { + var _this = this; + $.each(this.set.links, function(index, item) { + if (item.url != _this.url) return; + item.tag.addClass('disabled'); + }); + }, + + set_opened: function() { + if (this.position == 'after') { + this.set_adapter(this.target.next()); + } + else if (this.position == 'before') { + this.set_adapter(this.target.prev()); + } + this.disable(); + } +}); + +/** + * Concrete classes for table actions + */ +ActiveScaffold.Actions.Table = ActiveScaffold.Actions.Abstract.extend({ + instantiate_link: function(link) { + var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator); + if (l.position) { + l.url = l.url.append_params({adapter: '_list_inline_adapter'}); + l.tag.attr('href', l.url); + } + return l; + } +}); + +ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({ + insert: function(content) { + if (this.position == 'top') { + this.target.prepend(content); + this.set_adapter(this.target.children().first()); + } + else { + throw 'Unknown position "' + this.position + '"' + } + ActiveScaffold.highlight(this.adapter.find('td').first().children()); + } +}); diff --git a/app/assets/javascripts/jquery/jquery.editinplace.js b/app/assets/javascripts/jquery/jquery.editinplace.js new file mode 100644 index 0000000000..9bc523a155 --- /dev/null +++ b/app/assets/javascripts/jquery/jquery.editinplace.js @@ -0,0 +1,743 @@ +/* + +A jQuery edit in place plugin + +Version 2.2.0 + +Authors: + Dave Hauenstein + Martin Häcker <spamfaenger [at] gmx [dot] de> + +Project home: + http://code.google.com/p/jquery-in-place-editor/ + +Patches with tests welcomed! For guidance see the tests at </spec/unit/spec.js>. To submit, attach them to the bug tracker. + +License: +This source file is subject to the BSD license bundled with this package. +Available online: {@link http://www.opensource.org/licenses/bsd-license.php} +If you did not receive a copy of the license, and are unable to obtain it, +learn to use a search engine. + +*/ + +(function($){ + +$.fn.editInPlace = function(options) { + + var settings = $.extend({}, $.fn.editInPlace.defaults, options); + + assertMandatorySettingsArePresent(settings); + + preloadImage(settings.saving_image); + + return this.each(function() { + var dom = $(this); + // This won't work with live queries as there is no specific element to attach this + // one way to deal with this could be to store a reference to self and then compare that in click? + if (dom.data('editInPlace')) + return; // already an editor here + dom.data('editInPlace', true); + + new InlineEditor(settings, dom).init(); + }); +}; + +/// Switch these through the dictionary argument to $(aSelector).editInPlace(overideOptions) +/// Required Options: Either url or callback, so the editor knows what to do with the edited values. +$.fn.editInPlace.defaults = { + url: "", // string: POST URL to send edited content + ajax_data_type: "html", // string: dataType (html|script) for ajax call to save updated value + bg_over: "#ffc", // string: background color of hover of unactivated editor + bg_out: "transparent", // string: background color on restore from hover + hover_class: "", // string: class added to root element during hover. Will override bg_over and bg_out + show_buttons: false, // boolean: will show the buttons: cancel or save; will automatically cancel out the onBlur functionality + save_button: '<button class="inplace_save">Save</button>', // string: image button tag to use as “Save” button + cancel_button: '<button class="inplace_cancel">Cancel</button>', // string: image button tag to use as “Cancel” button + params: "", // string: example: first_name=dave&last_name=hauenstein extra paramters sent via the post request to the server + field_type: "text", // string: "text", "textarea", or "select", or "remote", or "clone"; The type of form field that will appear on instantiation + default_text: "(Click here to add text)", // string: text to show up if the element that has this functionality is empty + use_html: false, // boolean, set to true if the editor should use jQuery.fn.html() to extract the value to show from the dom node + textarea_rows: 10, // integer: set rows attribute of textarea, if field_type is set to textarea. Use CSS if possible though + textarea_cols: 25, // integer: set cols attribute of textarea, if field_type is set to textarea. Use CSS if possible though + select_text: "Choose new value", // string: default text to show up in select box + select_options: "", // string or array: Used if field_type is set to 'select'. Can be comma delimited list of options 'textandValue,text:value', Array of options ['textAndValue', 'text:value'] or array of arrays ['textAndValue', ['text', 'value']]. The last form is especially usefull if your labels or values contain colons) + text_size: null, // integer: set cols attribute of text input, if field_type is set to text. Use CSS if possible though + editor_url: null, // for field_type: remote url to get html_code for edit_control + loading_text: 'Loading...', // shown if inplace editor is loaded from server + // Specifying callback_skip_dom_reset will disable all saving_* options + saving_text: undefined, // string: text to be used when server is saving information. Example "Saving..." + saving_image: "", // string: uses saving text specify an image location instead of text while server is saving + saving_animation_color: 'transparent', // hex color string, will be the color the pulsing animation during the save pulses to. Note: Only works if jquery-ui is loaded + clone_selector: null, // if field_type clone a selector to clone editor from + clone_id_suffix: null, // if field_type clone a suffix to create unique ids + + value_required: false, // boolean: if set to true, the element will not be saved unless a value is entered + element_id: "element_id", // string: name of parameter holding the id or the editable + update_value: "update_value", // string: name of parameter holding the updated/edited value + original_value: 'original_value', // string: name of parameter holding the updated/edited value + original_html: "original_html", // string: name of parameter holding original_html value of the editable /* DEPRECATED in 2.2.0 */ use original_value instead. + save_if_nothing_changed: false, // boolean: submit to function or server even if the user did not change anything + on_blur: "save", // string: "save" or null; what to do on blur; will be overridden if show_buttons is true + cancel: "", // string: if not empty, a jquery selector for elements that will not cause the editor to open even though they are clicked. E.g. if you have extra buttons inside editable fields + + // All callbacks will have this set to the DOM node of the editor that triggered the callback + + callback: null, // function: function to be called when editing is complete; cancels ajax submission to the url param. Prototype: function(idOfEditor, enteredText, orinalHTMLContent, settingsParams, callbacks). The function needs to return the value that should be shown in the dom. Returning undefined means cancel and will restore the dom and trigger an error. callbacks is a dictionary with two functions didStartSaving and didEndSaving() that you can use to tell the inline editor that it should start and stop any saving animations it has configured. /* DEPRECATED in 2.1.0 */ Parameter idOfEditor, use $(this).attr('id') instead + callback_skip_dom_reset: false, // boolean: set this to true if the callback should handle replacing the editor with the new value to show + success: null, // function: this function gets called if server responds with a success. Prototype: function(newEditorContentString) + error: null, // function: this function gets called if server responds with an error. Prototype: function(request) + error_sink: function(idOfEditor, errorString) { alert(errorString); }, // function: gets id of the editor and the error. Make sure the editor has an id, or it will just be undefined. If set to null, no error will be reported. /* DEPRECATED in 2.1.0 */ Parameter idOfEditor, use $(this).attr('id') instead + preinit: null, // function: this function gets called after a click on an editable element but before the editor opens. If you return false, the inline editor will not open. Prototype: function(currentDomNode). DEPRECATED in 2.2.0 use delegate shouldOpenEditInPlace call instead + postclose: null, // function: this function gets called after the inline editor has closed and all values are updated. Prototype: function(currentDomNode). DEPRECATED in 2.2.0 use delegate didCloseEditInPlace call instead + delegate: null // object: if it has methods with the name of the callbacks documented below in delegateExample these will be called. This means that you just need to impelment the callbacks you are interested in. +}; + +// Lifecycle events that the delegate can implement +// this will always be fixed to the delegate +var delegateExample = { + // called while opening the editor. + // return false to prevent editor from opening + shouldOpenEditInPlace: function(aDOMNode, aSettingsDict, triggeringEvent) {}, + // return content to show in inplace editor + willOpenEditInPlace: function(aDOMNode, aSettingsDict) {}, + didOpenEditInPlace: function(aDOMNode, aSettingsDict) {}, + + // called while closing the editor + // return false to prevent the editor from closing + shouldCloseEditInPlace: function(aDOMNode, aSettingsDict, triggeringEvent) {}, + // return value will be shown during saving + willCloseEditInPlace: function(aDOMNode, aSettingsDict) {}, + didCloseEditInPlace: function(aDOMNode, aSettingsDict) {}, + + missingCommaErrorPreventer:'' +}; + + +function InlineEditor(settings, dom) { + this.settings = settings; + this.dom = dom; + this.originalValue = null; + this.didInsertDefaultText = false; + this.shouldDelayReinit = false; +}; + +$.extend(InlineEditor.prototype, { + + init: function() { + this.setDefaultTextIfNeccessary(); + this.connectOpeningEvents(); + }, + + reinit: function() { + if (this.shouldDelayReinit) + return; + + this.triggerCallback(this.settings.postclose, /* DEPRECATED in 2.1.0 */ this.dom); + this.triggerDelegateCall('didCloseEditInPlace'); + + this.markEditorAsInactive(); + this.connectOpeningEvents(); + }, + + setDefaultTextIfNeccessary: function() { + if('' !== this.dom.html()) + return; + + this.dom.html(this.settings.default_text); + this.didInsertDefaultText = true; + }, + + connectOpeningEvents: function() { + var that = this; + this.dom + .bind('mouseenter.editInPlace', function(){ that.addHoverEffect(); }) + .bind('mouseleave.editInPlace', function(){ that.removeHoverEffect(); }) + .bind('click.editInPlace', function(anEvent){ that.openEditor(anEvent); }); + }, + + disconnectOpeningEvents: function() { + // prevent re-opening the editor when it is already open + this.dom.unbind('.editInPlace'); + }, + + addHoverEffect: function() { + if (this.settings.hover_class) + this.dom.addClass(this.settings.hover_class); + else + this.dom.css("background-color", this.settings.bg_over); + }, + + removeHoverEffect: function() { + if (this.settings.hover_class) + this.dom.removeClass(this.settings.hover_class); + else + this.dom.css("background-color", this.settings.bg_out); + }, + + openEditor: function(anEvent) { + if ( ! this.shouldOpenEditor(anEvent)) + return; + + this.workAroundFirefoxBlurBug(); + this.disconnectOpeningEvents(); + this.removeHoverEffect(); + this.removeInsertedDefaultTextIfNeccessary(); + this.saveOriginalValue(); + this.markEditorAsActive(); + this.replaceContentWithEditor(); + this.connectOpeningEventsToEditor(); + this.triggerDelegateCall('didOpenEditInPlace'); + }, + + shouldOpenEditor: function(anEvent) { + if (this.isClickedObjectCancelled(anEvent.target)) + return false; + + if (false === this.triggerCallback(this.settings.preinit, /* DEPRECATED in 2.1.0 */ this.dom)) + return false; + + if (false === this.triggerDelegateCall('shouldOpenEditInPlace', true, anEvent)) + return false; + + return true; + }, + + removeInsertedDefaultTextIfNeccessary: function() { + if ( ! this.didInsertDefaultText + || this.dom.html() !== this.settings.default_text) + return; + + this.dom.html(''); + this.didInsertDefaultText = false; + }, + + isClickedObjectCancelled: function(eventTarget) { + if ( ! this.settings.cancel) + return false; + + var eventTargetAndParents = $(eventTarget).parents().andSelf(); + var elementsMatchingCancelSelector = eventTargetAndParents.filter(this.settings.cancel); + return 0 !== elementsMatchingCancelSelector.length; + }, + + saveOriginalValue: function() { + if (this.settings.use_html) + this.originalValue = this.dom.html(); + else + this.originalValue = trim(this.dom.text()); + }, + + restoreOriginalValue: function() { + this.setClosedEditorContent(this.originalValue); + }, + + setClosedEditorContent: function(aValue) { + if (this.settings.use_html) + this.dom.html(aValue); + else + this.dom.text(aValue); + }, + + workAroundFirefoxBlurBug: function() { + if ( ! $.browser.mozilla) + return; + + // TODO: Opera seems to also have this bug.... + + // Firefox will forget to send a blur event to an input element when another one is + // created and selected programmatically. This means that if another inline editor is + // opened, existing inline editors will _not_ close if they are configured to submit when blurred. + // This is actually the first time I've written browser specific code for a browser different than IE! Wohoo! + + // Using parents() instead document as base to workaround the fact that in the unittests + // the editor is not a child of window.document but of a document fragment + this.dom.parents(':last').find('.editInPlace-active :input').blur(); + }, + + replaceContentWithEditor: function() { + var buttons_html = (this.settings.show_buttons) ? this.settings.save_button + ' ' + this.settings.cancel_button : ''; + var editorElement = this.createEditorElement(); // needs to happen before anything is replaced + /* insert the new in place form after the element they click, then empty out the original element */ + this.dom.html('<form class="inplace_form" style="display: inline; margin: 0; padding: 0;"></form>') + .find('form') + .append(editorElement) + .append(buttons_html); + }, + + createEditorElement: function() { + if (-1 === $.inArray(this.settings.field_type, ['text', 'textarea', 'select', 'remote', 'clone'])) + throw "Unknown field_type <fnord>, supported are 'text', 'textarea', 'select' and 'remote'"; + + var editor = null; + if ("select" === this.settings.field_type) + editor = this.createSelectEditor(); + else if ("text" === this.settings.field_type) + editor = $('<input type="text" ' + this.inputNameAndClass() + + ' size="' + this.settings.text_size + '" />'); + else if ("textarea" === this.settings.field_type) + editor = $('<textarea ' + this.inputNameAndClass() + + ' rows="' + this.settings.textarea_rows + '" ' + + ' cols="' + this.settings.textarea_cols + '" />'); + else if ("remote" === this.settings.field_type) + editor = this.createRemoteGeneratedEditor(); + else if ("clone" === this.settings.field_type) { + editor = this.cloneEditor(); + return editor; + } + editor.val(this.triggerDelegateCall('willOpenEditInPlace', this.originalValue)); + return editor; + }, + + createRemoteGeneratedEditor: function () { + this.dom.html(this.settings.loading_text); + return $($.ajax({ + url: this.settings.editor_url, + async: false + }).responseText); + }, + + cloneEditor: function() { + var patternNodes = this.getPatternNodes(this.settings.clone_selector); + if (patternNodes.editNode == null) { + alert('did not find any matching node for ' + this.settings.clone_selector); + return; + } + + var editorNode = patternNodes.editNode.clone(); + var clonedNodes = null; + if (editorNode.attr('id').length > 0) editorNode.attr('id', editorNode.attr('id') + this.settings.clone_id_suffix); + editorNode.attr('name', 'inplace_value'); + editorNode.addClass('editor_field'); + this.setValue(editorNode, this.originalValue); + clonedNodes = editorNode; + + if (patternNodes.additionalNodes) { + patternNodes.additionalNodes.each(function (index, node) { + var patternNode = $(node).clone(); + if (patternNode.attr('id').length > 0) { + patternNode.attr('id', patternNode.attr('id') + this.settings.clone_id_suffix); + } + clonedNodes = clonedNodes.after(patternNode); + }); + } + return clonedNodes; + }, + + getPatternNodes: function(clone_selector) { + var nodes = {editNode: null, additionalNodes: null}; + var selectedNodes = $(clone_selector); + var firstNode = selectedNodes.first(); + + if (typeof(firstNode) !== 'undefined') { + // AS inplace_edit_control_container -> we have to select all child nodes + // Workaround for ie which does not support css > selector + if (firstNode.hasClass('as_inplace_pattern')) { + selectedNodes = firstNode.children(); + } + nodes.editNode = selectedNodes.first(); + // buggy... + //nodes.additionalNodes = selectedNodes.find(':gt(0)'); + } + return nodes; + }, + + setValue: function(editField, textValue) { + var function_name = 'setValueFor' + editField.get(0).nodeName.toLowerCase(); + if (typeof(this[function_name]) == 'function') { + this[function_name](editField, textValue); + } else { + editField.val(textValue); + } + }, + + setValueForselect: function(editField, textValue) { + var option_value = editField.children("option:contains('" + textValue + "')").val(); + + if (typeof(option_value) !== 'undefined') { + editField.val(option_value); + } + }, + + inputNameAndClass: function() { + return ' name="inplace_value" class="inplace_field" '; + }, + + createSelectEditor: function() { + var editor = $('<select' + this.inputNameAndClass() + '>' + + '<option disabled="true" value="">' + this.settings.select_text + '</option>' + + '</select>'); + + var optionsArray = this.settings.select_options; + if ( ! $.isArray(optionsArray)) + optionsArray = optionsArray.split(','); + + for (var i=0; i<optionsArray.length; i++) { + + var currentTextAndValue = optionsArray[i]; + if ( ! $.isArray(currentTextAndValue)) + currentTextAndValue = currentTextAndValue.split(':'); + + var value = trim(currentTextAndValue[1] || currentTextAndValue[0]); + var text = trim(currentTextAndValue[0]); + + var selected = (value == this.originalValue) ? 'selected="selected" ' : ''; + var option = $('<option ' + selected + ' ></option>').val(value).text(text); + editor.append(option); + } + return editor; + + }, + + // REFACT: rename opening is not what it's about. Its about closing events really + connectOpeningEventsToEditor: function() { + var that = this; + function cancelEditorAction(anEvent) { + that.handleCancelEditor(anEvent); + return false; // stop event bubbling + } + function saveEditorAction(anEvent) { + that.handleSaveEditor(anEvent); + return false; // stop event bubbling + } + + var form = this.dom.find("form"); + + form.find(".inplace_field").focus().select(); + form.find(".inplace_cancel").click(cancelEditorAction); + form.find(".inplace_save").click(saveEditorAction); + + if ( ! this.settings.show_buttons) { + // TODO: Firefox has a bug where blur is not reliably called when focus is lost + // (for example by another editor appearing) + if ("save" === this.settings.on_blur) + form.find(".inplace_field").blur(saveEditorAction); + else + form.find(".inplace_field").blur(cancelEditorAction); + + // workaround for firefox bug where it won't submit on enter if no button is shown + if ($.browser.mozilla) + this.bindSubmitOnEnterInInput(); + } + + form.keyup(function(anEvent) { + // allow canceling with escape + var escape = 27; + if (escape === anEvent.which) + return cancelEditorAction(); + }); + + // workaround for webkit nightlies where they won't submit at all on enter + // REFACT: find a way to just target the nightlies + if ($.browser.safari) + this.bindSubmitOnEnterInInput(); + + + form.submit(saveEditorAction); + }, + + bindSubmitOnEnterInInput: function() { + if ('textarea' === this.settings.field_type) + return; // can't enter newlines otherwise + + var that = this; + this.dom.find(':input').keyup(function(event) { + var enter = 13; + if (enter === event.which) + return that.dom.find('form').submit(); + }); + + }, + + handleCancelEditor: function(anEvent) { + // REFACT: remove duplication between save and cancel + if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent)) + return; + + var editor = this.dom.find(':input'); + + var enteredText = editor.val(); + enteredText = this.triggerDelegateCall('willCloseEditInPlace', enteredText); + + this.restoreOriginalValue(); + if (hasContent(enteredText) + && ! this.isDisabledDefaultSelectChoice() && !editor.is('select')) + this.setClosedEditorContent(enteredText); + this.reinit(); + }, + + handleSaveEditor: function(anEvent) { + if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent)) + return; + + var editor = this.dom.find(':input:not(:button)'); + var enteredText = ''; + if (editor.length > 1) { + enteredText = jQuery.map(editor.not('input:checkbox:not(:checked)'), function(item, index) { + return $(item).val(); + }); + } else { + enteredText = editor.val(); + } + enteredText = this.triggerDelegateCall('willCloseEditInPlace', enteredText); + + if (this.isDisabledDefaultSelectChoice() + || this.isUnchangedInput(enteredText)) { + this.handleCancelEditor(anEvent); + return; + } + + if (this.didForgetRequiredText(enteredText)) { + this.handleCancelEditor(anEvent); + this.reportError("Error: You must enter a value to save this field"); + return; + } + + this.showSaving(enteredText); + + if (this.settings.callback) + this.handleSubmitToCallback(enteredText); + else + this.handleSubmitToServer(enteredText); + }, + + didForgetRequiredText: function(enteredText) { + return this.settings.value_required + && ("" === enteredText + || undefined === enteredText + || null === enteredText); + }, + + isDisabledDefaultSelectChoice: function() { + return this.dom.find('option').eq(0).is(':selected:disabled'); + }, + + isUnchangedInput: function(enteredText) { + return ! this.settings.save_if_nothing_changed + && this.originalValue === enteredText; + }, + + showSaving: function(enteredText) { + if (this.settings.callback && this.settings.callback_skip_dom_reset) + return; + + var savingMessage = enteredText; + if (hasContent(this.settings.saving_text)) + savingMessage = this.settings.saving_text; + if(hasContent(this.settings.saving_image)) + // REFACT: alt should be the configured saving message + savingMessage = $('<img />').attr('src', this.settings.saving_image).attr('alt', savingMessage); + this.dom.html(savingMessage); + }, + + handleSubmitToCallback: function(enteredText) { + // REFACT: consider to encode enteredText and originalHTML before giving it to the callback + this.enableOrDisableAnimationCallbacks(true, false); + var newHTML = this.triggerCallback(this.settings.callback, /* DEPRECATED in 2.1.0 */ this.id(), enteredText, this.originalValue, + this.settings.params, this.savingAnimationCallbacks()); + + if (this.settings.callback_skip_dom_reset) + ; // do nothing + else if (undefined === newHTML) { + // failure; put original back + this.reportError("Error: Failed to save value: " + enteredText); + this.restoreOriginalValue(); + } + else + // REFACT: use setClosedEditorContent + this.dom.html(newHTML); + + if (this.didCallNoCallbacks()) { + this.enableOrDisableAnimationCallbacks(false, false); + this.reinit(); + } + }, + + handleSubmitToServer: function(enteredText) { + var data = ''; + if (typeof(enteredText) === 'string') { + data += this.settings.update_value + '=' + encodeURIComponent(enteredText) + '&'; + } else { + for(var i = 0;i < enteredText.length; i++) { + data += this.settings.update_value + '[]=' + encodeURIComponent(enteredText[i]) + '&'; + } + } + + data += this.settings.element_id + '=' + this.dom.attr("id") + + ((this.settings.params) ? '&' + this.settings.params : '') + + '&' + this.settings.original_html + '=' + encodeURIComponent(this.originalValue) /* DEPRECATED in 2.2.0 */ + + '&' + this.settings.original_value + '=' + encodeURIComponent(this.originalValue); + + this.enableOrDisableAnimationCallbacks(true, false); + this.didStartSaving(); + var that = this; + $.ajax({ + url: that.settings.url, + type: "POST", + data: data, + dataType: that.settings.ajax_data_type, + complete: function(request){ + that.didEndSaving(); + }, + success: function(data){ + if (that.settings.ajax_data_type == 'html') { + var new_text = data || that.settings.default_text; + + /* put the newly updated info into the original element */ + // FIXME: should be affected by the preferences switch + that.dom.html(new_text); + // REFACT: remove dom parameter, already in this, not documented, should be easy to remove + // REFACT: callback should be able to override what gets put into the DOM + } + that.triggerCallback(that.settings.success,data); + }, + error: function(request) { + that.dom.html(that.originalHTML); // REFACT: what about a restorePreEditingContent() + if (that.settings.error) + // REFACT: remove dom parameter, already in this, not documented, can remove without deprecation + // REFACT: callback should be able to override what gets entered into the DOM + that.triggerCallback(that.settings.error, request); + else + that.reportError("Failed to save value: " + request.responseText || 'Unspecified Error'); + } + }); + }, + + // Utilities ......................................................... + + triggerCallback: function(aCallback /*, arguments */) { + if ( ! aCallback) + return; // callback wasn't specified after all + + var callbackArguments = Array.prototype.splice.call(arguments, 1); + return aCallback.apply(this.dom[0], callbackArguments); + }, + + /// defaultReturnValue is only used if the delegate returns undefined + triggerDelegateCall: function(aDelegateMethodName, defaultReturnValue, optionalEvent) { + // REFACT: consider to trigger equivalent callbacks automatically via a mapping table? + if ( ! this.settings.delegate + || ! $.isFunction(this.settings.delegate[aDelegateMethodName])) + return defaultReturnValue; + + var delegateReturnValue = this.settings.delegate[aDelegateMethodName](this.dom, this.settings, optionalEvent); + return (undefined === delegateReturnValue) + ? defaultReturnValue + : delegateReturnValue; + }, + + reportError: function(anErrorString) { + this.triggerCallback(this.settings.error_sink, /* DEPRECATED in 2.1.0 */ this.id(), anErrorString); + }, + + // REFACT: this method should go, callbacks should get the dom node itself as an argument + id: function() { + return this.dom.attr('id'); + }, + + markEditorAsActive: function() { + this.dom.addClass('editInPlace-active'); + }, + + markEditorAsInactive: function() { + this.dom.removeClass('editInPlace-active'); + }, + + // REFACT: consider rename, doesn't deal with animation directly + savingAnimationCallbacks: function() { + var that = this; + return { + didStartSaving: function() { that.didStartSaving(); }, + didEndSaving: function() { that.didEndSaving(); } + }; + }, + + enableOrDisableAnimationCallbacks: function(shouldEnableStart, shouldEnableEnd) { + this.didStartSaving.enabled = shouldEnableStart; + this.didEndSaving.enabled = shouldEnableEnd; + }, + + didCallNoCallbacks: function() { + return this.didStartSaving.enabled && ! this.didEndSaving.enabled; + }, + + assertCanCall: function(methodName) { + if ( ! this[methodName].enabled) + throw new Error('Cannot call ' + methodName + ' now. See documentation for details.'); + }, + + didStartSaving: function() { + this.assertCanCall('didStartSaving'); + this.shouldDelayReinit = true; + this.enableOrDisableAnimationCallbacks(false, true); + + this.startSavingAnimation(); + }, + + didEndSaving: function() { + this.assertCanCall('didEndSaving'); + this.shouldDelayReinit = false; + this.enableOrDisableAnimationCallbacks(false, false); + this.reinit(); + + this.stopSavingAnimation(); + }, + + startSavingAnimation: function() { + var that = this; + this.dom + .animate({ backgroundColor: this.settings.saving_animation_color }, 400) + .animate({ backgroundColor: 'transparent'}, 400, 'swing', function(){ + // In the tests animations are turned off - i.e they happen instantaneously. + // Hence we need to prevent this from becomming an unbounded recursion. + setTimeout(function(){ that.startSavingAnimation(); }, 10); + }); + }, + + stopSavingAnimation: function() { + this.dom + .stop(true) + .css({backgroundColor: ''}); + }, + + missingCommaErrorPreventer:'' +}); + + + +// Private helpers ....................................................... + +function assertMandatorySettingsArePresent(options) { + // one of these needs to be non falsy + if (options.url || options.callback) + return; + + throw new Error("Need to set either url: or callback: option for the inline editor to work."); +} + +/* preload the loading icon if it is configured */ +function preloadImage(anImageURL) { + if ('' === anImageURL) + return; + + var loading_image = new Image(); + loading_image.src = anImageURL; +} + +function trim(aString) { + return aString + .replace(/^\s+/, '') + .replace(/\s+$/, ''); +} + +function hasContent(something) { + if (undefined === something || null === something) + return false; + + if (0 === something.length) + return false; + + return true; +} + +})(jQuery); diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js new file mode 100644 index 0000000000..e19b77c5d8 --- /dev/null +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -0,0 +1,1028 @@ +if (typeof Prototype == 'undefined') +{ + warning = "ActiveScaffold Error: Prototype could not be found. Please make sure that your application's layout includes prototype.js (e.g. <%= javascript_include_tag :defaults %>) *before* it includes active_scaffold.js (e.g. <%= active_scaffold_includes %>)."; + alert(warning); +} +if (Prototype.Version.substring(0, 3) < '1.6') +{ + warning = "ActiveScaffold Error: Prototype version 1.6.x or higher is required. Please update prototype.js (rake rails:update:javascripts)."; + alert(warning); +} +if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFunction}); + + +document.observe("dom:loaded", function() { + document.on('ajax:create', 'form.as_form', function(event) { + var source = event.findElement(); + var as_form = event.findElement('form'); + if (source.nodeName.toUpperCase() == 'INPUT' && source.readAttribute('type') == 'button') { + // Hack: Prototype or rails.js somehow screw up event handling if someone clicks + // a button of type button such as Create Another <Association> + // as a result form is disabled but never reenabled.. + } else { + if (as_form && as_form.readAttribute('data-loading') == 'true') { + ActiveScaffold.disable_form(as_form); + } + } + return true; + }); + document.on('ajax:complete', 'form.as_form', function(event) { + var as_form = event.findElement('form'); + if (as_form && as_form.readAttribute('data-loading') == 'true') { + ActiveScaffold.enable_form(as_form); + event.stop(); + return false; + } + }); + document.on('ajax:failure', 'form.as_form', function(event) { + var as_div = event.findElement('div.active-scaffold'); + if (as_div) { + ActiveScaffold.report_500_response(as_div) + event.stop(); + return false; + } + }); + document.on('submit', 'form.as_form.as_remote_upload', function(event) { + var as_form = event.findElement('form'); + if (as_form && as_form.readAttribute('data-loading') == 'true') { + setTimeout("ActiveScaffold.disable_form('" + as_form.readAttribute('id') + "')", 10); + } + return true; + }); + document.on('ajax:before', 'a.as_action', function(event) { + var action_link = ActiveScaffold.ActionLink.get(event.findElement()); + if (action_link) { + if (action_link.is_disabled()) { + event.stop(); + } else { + if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'visible'; + action_link.disable(); + } + } + return true; + }); + document.on('ajax:success', 'a.as_action', function(event) { + var action_link = ActiveScaffold.ActionLink.get(event.findElement()); + if (action_link && event.memo && event.memo.request) { + if (action_link.position) { + action_link.insert(event.memo.request.transport.responseText); + if (action_link.hide_target) action_link.target.hide(); + } else { + //event.memo.request.evalResponse(); // (clyfe) prototype evals the response by itself checking headers, this would eval twice + action_link.enable(); + } + event.stop(); + } + return true; + }); + document.on('ajax:complete', 'a.as_action', function(event) { + var action_link = ActiveScaffold.ActionLink.get(event.findElement()); + if (action_link && action_link.loading_indicator) { + action_link.loading_indicator.style.visibility = 'hidden'; + } + return true; + }); + document.on('ajax:failure', 'a.as_action', function(event) { + var action_link = ActiveScaffold.ActionLink.get(event.findElement()); + if (action_link) { + ActiveScaffold.report_500_response(action_link.scaffold_id()); + action_link.enable(); + } + return true; + }); + document.on('ajax:before', 'a.as_cancel', function(event) { + var as_cancel = event.findElement(); + var action_link = ActiveScaffold.find_action_link(as_cancel); + + if (action_link) { + var refresh_data = as_cancel.readAttribute('data-refresh'); + if (refresh_data === 'true' && action_link.refresh_url) { + event.memo.url = action_link.refresh_url; + } else if (refresh_data === 'false' || as_cancel.readAttribute('href').blank()) { + action_link.close(); + event.stop(); + } + } + return true; + }); + document.on('ajax:success', 'a.as_cancel', function(event) { + var action_link = ActiveScaffold.find_action_link(event.findElement()); + if (action_link) { + if (action_link.position) { + action_link.close(event.memo.request.responseText); + } else { + event.memo.request.evalResponse(); + } + } + return true; + }); + document.on('ajax:failure', 'a.as_cancel', function(event) { + var action_link = ActiveScaffold.find_action_link(event.findElement()); + if (action_link) { + ActiveScaffold.report_500_response(action_link.scaffold_id()); + } + return true; + }); + document.on('ajax:before', 'a.as_sort', function(event) { + var as_sort = event.findElement(); + var history_controller_id = as_sort.readAttribute('data-page-history'); + if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.readAttribute('href'), history_controller_id); + as_sort.up('th').addClassName('loading'); + return true; + }); + document.on('ajax:failure', 'a.as_sort', function(event) { + var as_scaffold = event.findElement('.active-scaffold'); + ActiveScaffold.report_500_response(as_scaffold); + return true; + }); + document.on('mouseover', 'span.in_place_editor_field', function(event) { + event.findElement().addClassName('hover'); + }); + document.on('mouseout', 'span.in_place_editor_field', function(event) { + event.findElement().removeClassName('hover'); + }); + document.on('click', 'span.in_place_editor_field', function(event) { + var span = event.findElement('span.in_place_editor_field'); + + if (typeof(span.inplace_edit) === 'undefined') { + var options = {htmlResponse: false, + onEnterHover: null, + onLeaveHover: null, + onComplete: null, + params: '', + ajaxOptions: {method: 'post'}}, + csrf_param = $$('meta[name=csrf-param]')[0], + csrf_token = $$('meta[name=csrf-token]')[0], + my_parent = span.up(), + column_heading = null; + + if(!(my_parent.nodeName.toLowerCase() === 'td' || my_parent.nodeName.toLowerCase() === 'th')){ + my_parent = span.up('td'); + } + + if (my_parent.nodeName.toLowerCase() === 'td') { + var heading_selector = '.' + span.up().readAttribute('class').split(' ')[0] + '_heading'; + column_heading = span.up('.active-scaffold').down(heading_selector); + } else if (my_parent.nodeName.toLowerCase() === 'th') { + column_heading = my_parent; + } + + var render_url = column_heading.readAttribute('data-ie_render_url'), + mode = column_heading.readAttribute('data-ie_mode'), + record_id = span.readAttribute('data-ie_id'); + + ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options); + + if (span.readAttribute('data-ie_url')) { + options.url = span.readAttribute('data-ie_url'); + } else { + options.url = column_heading.readAttribute('data-ie_url'); + } + if (record_id) options.url = options.url.sub('__id__', record_id); + + if (csrf_param) options['params'] = csrf_param.readAttribute('content') + '=' + csrf_token.readAttribute('content'); + + if (span.up('div.active-scaffold').readAttribute('data-eid')) { + if (options['params'].length > 0) { + options['params'] += "&"; + } + options['params'] += ("eid=" + span.up('div.active-scaffold').readAttribute('data-eid')); + } + + if (mode === 'clone') { + options.nodeIdSuffix = record_id; + options.inplacePatternSelector = '#' + column_heading.readAttribute('id') + ' .as_inplace_pattern'; + options['onFormCustomization'] = new Function('element', 'form', 'element.clonePatternField();'); + } + + if (render_url) { + var plural = false; + if (column_heading.readAttribute('data-ie_plural')) plural = true; + options['onFormCustomization'] = new Function('element', 'form', 'element.setFieldFromAjax(' + "'" + render_url.sub('__id__', record_id) + "', {plural: " + plural + '});'); + } + + if (mode === 'inline_checkbox') { + ActiveScaffold.process_checkbox_inplace_edit(span.down('input[type="checkbox"]'), options); + } else { + ActiveScaffold.create_inplace_editor(span, options); + } + } + return true; + }); + document.on('ajax:before', 'a.as_paginate', function(event) { + var as_paginate = event.findElement(); + var loading_indicator = as_paginate.up().down('img.loading-indicator'); + var history_controller_id = as_paginate.readAttribute('data-page-history'); + + if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.readAttribute('href'), history_controller_id); + if (loading_indicator) loading_indicator.style.visibility = 'visible'; + return true; + }); + document.on('ajax:failure', 'a.as_paginate', function(event) { + var as_scaffold = event.findElement('.active-scaffold'); + ActiveScaffold.report_500_response(as_scaffold); + return true; + }); + document.on('ajax:complete', 'a.as_paginate', function(event) { + var as_paginate = event.findElement(); + var loading_indicator = as_paginate.up().down('img.loading-indicator'); + + if(loading_indicator) loading_indicator.style.visibility = 'hidden'; + return true; + }); + document.on('ajax:before', 'input[type=button].as_add_existing', function(event) { + var button = event.findElement(); + var url = button.readAttribute('href').sub('--ID--', button.previous().getValue()); + event.memo.url = url; + return true; + }); + document.on('change', 'input.update_form, select.update_form', function(event) { + var element = event.findElement(); + var as_form = element.up('form.as_form'); + var params = null; + + if (element.hasAttribute('data-update_send_form')) { + params = as_form.serialize(true); + } else { + params = {value: element.getValue()}; + } + params.source_id = element.readAttribute('id'); + + new Ajax.Request(element.readAttribute('data-update_url'), { + method: 'get', + parameters: params, + onLoading: function(response) { + element.next('img.loading-indicator').style.visibility = 'visible'; + as_form.disable(); + }, + onComplete: function(response) { + element.next('img.loading-indicator').style.visibility = 'hidden'; + as_form.enable(); + }, + onFailure: function(request) { + var as_div = event.findElement('div.active-scaffold'); + if (as_div) { + ActiveScaffold.report_500_response(as_div) + } + } + }); + return true; + }); + document.on('change', 'select.as_search_range_option', function(event) { + var element = event.findElement(); + Element[element.value == 'BETWEEN' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_between')); + return true; + }); + document.on('change', 'select.as_search_date_time_option', function(event) { + var element = event.findElement(); + Element[!(element.value == 'PAST' || element.value == 'FUTURE' || element.value == 'RANGE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_numeric')); + Element[(element.value == 'PAST' || element.value == 'FUTURE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_trend')); + Element[element.value == 'RANGE' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_range')); + return true; + }); + document.on('change', 'select.as_update_date_operator', function(event) { + var element = event.findElement(); + Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next()); + Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next().next()); + Element[element.value == 'REPLACE' ? 'hide' : 'show'](element.next('span')); + return true; + }); + document.on("click", "a[data-popup]", function(event, element) { + if (event.stopped) return; + window.open($(element).href); + event.stop(); + }); + document.on("click", ".hover_click", function(event, element) { + var ul_element = element.down('ul'); + if (ul_element.getStyle('display') === 'none') { + ul_element.style.display = 'block'; + } else { + ul_element.style.display = 'none'; + } + + return true; + }); + document.on("click", ".hover_click a.as_action", function(event, element) { + var element = element.up('.hover_click').down('ul'); + if (element) { + element.style.display = 'none'; + } + return true; + }); +}); + + +/* + * Simple utility methods + */ + +var ActiveScaffold = { + records_for: function(tbody_id) { + var rows = []; + var child = $(tbody_id).down('.record'); + while (child) { + rows.push(child); + child = child.next('.record'); + } + return rows; + }, + stripe: function(tbody_id) { + var even = false; + var rows = this.records_for(tbody_id); + for (var i = 0; i < rows.length; i++) { + var child = rows[i]; + //Make sure to skip rows that are create or edit rows or messages + if (child.tagName != 'SCRIPT' + && !child.hasClassName("create") + && !child.hasClassName("update") + && !child.hasClassName("inline-adapter") + && !child.hasClassName("active-scaffold-calculations")) { + + if (even) child.addClassName("even-record"); + else child.removeClassName("even-record"); + + even = !even; + } + } + }, + hide_empty_message: function(tbody) { + if (this.records_for(tbody).length != 0) { + var empty_message_nodes = $(tbody).up().select('tbody.messages p.empty-message') + empty_message_nodes.invoke('hide'); + } + }, + reload_if_empty: function(tbody, url) { + if (this.records_for(tbody).length == 0) { + new Ajax.Request(url, { + method: 'get', + asynchronous: true, + evalScripts: true + }); + } + }, + removeSortClasses: function(scaffold) { + scaffold = $(scaffold) + scaffold.select('td.sorted').each(function(element) { + element.removeClassName("sorted"); + }); + scaffold.select('th.sorted').each(function(element) { + element.removeClassName("sorted"); + element.removeClassName("asc"); + element.removeClassName("desc"); + }); + }, + decrement_record_count: function(scaffold) { + // decrement the last record count, firsts record count are in nested lists + scaffold = $(scaffold) + count = scaffold.select('span.active-scaffold-records').last(); + if (count) count.update(parseInt(count.innerHTML, 10) - 1); + }, + increment_record_count: function(scaffold) { + // increment the last record count, firsts record count are in nested lists + scaffold = $(scaffold) + count = scaffold.select('span.active-scaffold-records').last(); + if (count) count.update(parseInt(count.innerHTML, 10) + 1); + }, + update_row: function(row, html) { + row = $(row); + var new_row = this.replace(row, html) + if (row.hasClassName('even-record')) new_row.addClassName('even-record'); + new_row.highlight(); + }, + + replace: function(element, html) { + element = $(element) + Element.replace(element, html); + element = $(element.readAttribute('id')); + return element; + }, + + replace_html: function(element, html) { + element = $(element); + element.update(html); + return element; + }, + + remove: function(element) { + $(element).remove(); + }, + + hide: function(element) { + $(element).hide(); + }, + + show: function(element) { + $(element).show(); + }, + + reset_form: function(element) { + $(element).reset(); + }, + + disable_form: function(as_form) { + as_form = $(as_form) + var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator')); + if (loading_indicator) loading_indicator.style.visibility = 'visible'; + as_form.disable(); + }, + + enable_form: function(as_form) { + as_form = $(as_form) + var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator')); + if (loading_indicator) loading_indicator.style.visibility = 'hidden'; + as_form.enable(); + }, + + focus_first_element_of_form: function(form_element) { + Form.focusFirstElement(form_element); + }, + + create_record_row: function(active_scaffold_id, html, options) { + tbody = $(active_scaffold_id).down('tbody.records'); + + var new_row = null; + + if (options.insert_at == 'top') { + tbody.insert({top: html}); + new_row = tbody.firstDescendant(); + } else if (options.insert_at == 'bottom') { + var last_row = tbody.childElements().reverse().detect(function(node) { return node.hasClassName('record') || node.hasClassName('inline-adapter')}); + if (last_row) { + last_row.insert({after: html}); + } else { + tbody.insert({bottom: html}); + } + new_row = Selector.findChildElements(tbody, ['tr.record']).last(); + } + + this.stripe(tbody); + this.hide_empty_message(tbody); + this.increment_record_count(tbody.up('div.active-scaffold')); + new_row.highlight(); + }, + + delete_record_row: function(row, page_reload_url) { + row = $(row); + var tbody = row.up('tbody.records'); + + var current_action_node = row.down('td.actions a.disabled'); + + if (current_action_node) { + var action_link = ActiveScaffold.ActionLink.get(current_action_node); + if (action_link) { + action_link.close_previous_adapter(); + } + } + row.remove(); + tbody = $(tbody); + this.stripe(tbody); + this.decrement_record_count(tbody.up('div.active-scaffold')); + this.reload_if_empty(tbody, page_reload_url); + }, + + delete_subform_record: function(record) { + var errors = $(record).previous(); + if (errors.hasClassName('association-record-errors')) { + this.replace_html(errors, ''); + } + this.remove(record); + }, + + report_500_response: function(active_scaffold_id) { + server_error = $(active_scaffold_id).down('td.messages-container p.server-error'); + if (server_error.visible()) { + server_error.highlight(); + } else { + server_error.show(); + } + }, + + find_action_link: function(element) { + return ActiveScaffold.ActionLink.get($(element).up('.as_adapter')); + }, + + scroll_to: function(element) { + $(element).scrollTo(); + }, + + process_checkbox_inplace_edit: function(checkbox, options) { + var checked = checkbox.readAttribute('checked'); + // checked attribute is nt updated + if (checked !== 'checked') options['params'] += '&value=1'; + new Ajax.Request(options.url, { + method: 'post', + parameters: options['params'], + onCreate: function(response) { + checkbox.disable(); + }, + onComplete: function(response) { + checkbox.enable(); + } + }); + }, + + read_inplace_edit_heading_attributes: function(column_heading, options) { + if (column_heading.readAttribute('data-ie_cancel_text')) options.cancelText = column_heading.readAttribute('data-ie_cancel_text'); + if (column_heading.readAttribute('data-ie_loading_text')) options.loadingText = column_heading.readAttribute('data-ie_loading_text'); + if (column_heading.readAttribute('data-ie_saving_text')) options.savingText = column_heading.readAttribute('data-ie_saving_text'); + if (column_heading.readAttribute('data-ie_save_text')) options.okText = column_heading.readAttribute('data-ie_save_text'); + if (column_heading.readAttribute('data-ie_rows')) options.rows = column_heading.readAttribute('data-ie_rows'); + if (column_heading.readAttribute('data-ie_cols')) options.cols = column_heading.readAttribute('data-ie_cols'); + if (column_heading.readAttribute('data-ie_size')) options.size = column_heading.readAttribute('data-ie_size'); + }, + + create_inplace_editor: function(span, options) { + if (options['params'].length > 0) { + options['callback'] = new Function('form', 'return Form.serialize(form) + ' + "'&" + options['params'] + "';"); + } + span.removeClassName('hover'); + span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.readAttribute('id'), options.url, options) + span.inplace_edit.enterEditMode(); + }, + + create_visibility_toggle: function(element, options) { + var toggable = $(element); + var toggler = toggable.previous(); + var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label; + + toggler.insert(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)'); + toggler.firstDescendant().observe('click', function(event) { + var element = event.element(); + toggable.toggle(); + element.innerHTML = (toggable.style.display == 'none') ? options.show_label : options.hide_label; + return false; + }); + }, + + create_associated_record_form: function(element, content, options) { + var element = $(element); + if (options.singular == false) { + if (!(options.id && $(options.id))) { + element.insert(content); + } + } else { + var current = $$('#' + element.readAttribute('id') + ' tr.association-record'); + if (current[0]) { + this.replace(current[0], content); + } else { + element.insert({top: content}); + } + } + }, + + render_form_field: function(source, content, options) { + var source = $(source); + var element = source.up('.association-record'); + if (typeof(element) === 'undefined') { + element = source.up('ol.form'); + } + element = element.down('.' + options.field_class); + + if (element) { + if (options.is_subform == false) { + this.replace(element.up('dl'), content); + } else { + this.replace_html(element, content); + } + } + }, + + record_select_onselect: function(edit_associated_url, active_scaffold_id, id){ + new Ajax.Request( + edit_associated_url.sub('--ID--', id), { + asynchronous: true, + evalScripts: true, + onFailure: function(){ + ActiveScaffold.report_500_response(active_scaffold_id.to_json) + } + } + ); + }, + + // element is tbody id + mark_records: function(element, options) { + var element = $(element); + var mark_checkboxes = $$('#' + element.readAttribute('id') + ' > tr.record td.marked-column input[type="checkbox"]'); + mark_checkboxes.each(function(item) { + if(options.checked === true) { + item.writeAttribute({ checked: 'checked' }); + } else { + item.removeAttribute('checked'); + } + item.writeAttribute('value', ('' + !options.checked)); + }); + if(options.include_mark_all === true) { + var mark_all_checkbox = element.previous('thead').down('th.marked-column_heading span input[type="checkbox"]'); + if(options.checked === true) { + mark_all_checkbox.writeAttribute({ checked: 'checked' }); + } else { + mark_all_checkbox.removeAttribute('checked'); + } + mark_all_checkbox.writeAttribute('value', ('' + !options.checked)); + } + } + +} + +/* + * DHTML history tie-in + */ +function addActiveScaffoldPageToHistory(url, active_scaffold_id) { + if (typeof dhtmlHistory == 'undefined') return; // it may not be loaded + + var array = url.split('?'); + var qs = new Querystring(array[1]); + var sort = qs.get('sort') + var dir = qs.get('sort_direction') + var page = qs.get('page') + if (sort || dir || page) dhtmlHistory.add(active_scaffold_id+":"+page+":"+sort+":"+dir, url); +} + +/* + * Add-ons/Patches to Prototype + */ + +/* patch to support replacing TR/TD/TBODY in Internet Explorer, courtesy of http://dev.rubyonrails.org/ticket/4273 */ +Element.replace = function(element, html) { + element = $(element); + if (element.outerHTML) { + try { + element.outerHTML = html.stripScripts(); + } catch (e) { + var tn = element.tagName; + if(tn=='TBODY' || tn=='TR' || tn=='TD') + { + var tempDiv = document.createElement("div"); + tempDiv.innerHTML = '<table id="tempTable" style="display: none">' + html.stripScripts() + '</table>'; + element.parentNode.replaceChild(tempDiv.getElementsByTagName(tn).item(0), element); + } + else throw e; + } + } else { + var range = element.ownerDocument.createRange(); + /* patch to fix <form> replaces in Firefox. see http://dev.rubyonrails.org/ticket/8010 */ + range.selectNodeContents(element.parentNode); + element.parentNode.replaceChild(range.createContextualFragment(html.stripScripts()), element); + } + setTimeout(function() {html.evalScripts()}, 10); + return element; +}; + +/* + * URL modification support. Incomplete functionality. + */ +Object.extend(String.prototype, { + append_params: function(params) { + url = this; + if (url.indexOf('?') == -1) url += '?'; + else if (url.lastIndexOf('&') != url.length) url += '&'; + + url += $H(params).collect(function(item) { + return item.key + '=' + item.value; + }).join('&'); + + return url; + } +}); + +/* + * Prototype's implementation was throwing an error instead of false + */ +Element.Methods.Simulated = { + hasAttribute: function(element, attribute) { + var t = Element._attributeTranslations; + attribute = (t.names && t.names[attribute]) || attribute; + // Return false if we get an error here + try { + return $(element).getAttributeNode(attribute).specified; + } catch (e) { + return false; + } + } +}; + +/** + * A set of links. As a set, they can be controlled such that only one is "open" at a time, etc. + */ +ActiveScaffold.Actions = new Object(); +ActiveScaffold.Actions.Abstract = Class.create({ + initialize: function(links, target, loading_indicator, options) { + this.target = $(target); + this.loading_indicator = $(loading_indicator); + this.options = options; + this.links = links.collect(function(link) { + return this.instantiate_link(link); + }.bind(this)); + }, + + instantiate_link: function(link) { + throw 'unimplemented' + } +}); + +/** + * A DataStructures::ActionLink, represented in JavaScript. + * Concerned with AJAX-enabling a link and adapting the result for insertion into the table. + */ +ActiveScaffold.ActionLink = { + get: function(element) { + var element = $(element); + if (typeof(element.retrieve('action_link')) === 'undefined' && !element.hasClassName('as_adapter')) { + var parent = element.up('.actions'); + if (typeof(parent) === 'undefined') { + // maybe an column action_link + parent = element.up(); + } + if (parent && parent.nodeName.toUpperCase() == 'TD') { + // record action + parent = parent.up('tr.record') + new ActiveScaffold.Actions.Record(parent.select('a.as_action'), parent, parent.down('td.actions .loading-indicator')); + } else if (parent && parent.nodeName.toUpperCase() == 'DIV') { + //table action + new ActiveScaffold.Actions.Table(parent.select('a.as_action'), parent.up('div.active-scaffold').down('tbody.before-header'), parent.down('.loading-indicator')); + } + element = $(element); + } + return element.retrieve('action_link'); + } +}; + +ActiveScaffold.ActionLink.Abstract = Class.create({ + initialize: function(a, target, loading_indicator) { + this.tag = $(a); + this.url = this.tag.href; + this.method = this.tag.readAttribute('data-method') || 'get'; + this.target = target; + this.loading_indicator = loading_indicator; + this.hide_target = false; + this.position = this.tag.readAttribute('data-position'); + + this.tag.store('action_link', this); + }, + + open: function(event) { + }, + + insert: function(content) { + throw 'unimplemented' + }, + + close: function() { + this.enable(); + this.adapter.remove(); + if (this.hide_target) this.target.show(); + }, + + reload: function() { + this.close(); + this.open(); + }, + + get_new_adapter_id: function() { + var id = 'adapter_'; + var i = 0; + while ($(id + i)) i++; + return id + i; + }, + + enable: function() { + return this.tag.removeClassName('disabled'); + }, + + disable: function() { + return this.tag.addClassName('disabled'); + }, + + is_disabled: function() { + return this.tag.hasClassName('disabled'); + }, + + scaffold_id: function() { + return this.tag.up('div.active-scaffold').readAttribute('id'); + }, + + scaffold: function() { + return this.tag.up('div.active-scaffold'); + }, + + update_flash_messages: function(messages) { + message_node = $(this.scaffold_id().sub('-active-scaffold', '-messages')); + if (message_node) message_node.update(messages); + }, + + set_adapter: function(element) { + this.adapter = element; + this.adapter.addClassName('as_adapter'); + this.adapter.store('action_link', this); + } +}); + +/** + * Concrete classes for record actions + */ +ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, { + instantiate_link: function(link) { + var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); + if (this.target.hasAttribute('data-refresh') && !this.target.readAttribute('data-refresh').blank()) l.refresh_url = this.target.readAttribute('data-refresh'); + + if (l.position) { + l.url = l.url.append_params({adapter: '_list_inline_adapter'}); + l.tag.href = l.url; + } + l.set = this; + return l; + } +}); + +ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstract, { + close_previous_adapter: function() { + this.set.links.each(function(item) { + if (item.url != this.url && item.is_disabled() && item.adapter) { + item.enable(); + item.adapter.remove(); + } + }.bind(this)); + }, + + insert: function(content) { + this.close_previous_adapter(); + + if (this.position == 'replace') { + this.position = 'after'; + this.hide_target = true; + } + + if (this.position == 'after') { + this.target.insert({after:content}); + this.set_adapter(this.target.next()); + } + else if (this.position == 'before') { + this.target.insert({before:content}); + this.set_adapter(this.target.previous()); + } + else { + return false; + } + this.adapter.down('td').down().highlight(); + }, + + close: function($super, refreshed_content) { + if (refreshed_content) { + ActiveScaffold.update_row(this.target, refreshed_content); + } + $super(); + }, + + enable: function() { + this.set.links.each(function(item) { + if (item.url != this.url) return; + item.tag.removeClassName('disabled'); + }.bind(this)); + }, + + disable: function() { + this.set.links.each(function(item) { + if (item.url != this.url) return; + item.tag.addClassName('disabled'); + }.bind(this)); + }, + + set_opened: function() { + if (this.position == 'after') { + this.set_adapter(this.target.next()); + } + else if (this.position == 'before') { + this.set_adapter(this.target.previous()); + } + this.disable(); + } +}); + +/** + * Concrete classes for table actions + */ +ActiveScaffold.Actions.Table = Class.create(ActiveScaffold.Actions.Abstract, { + instantiate_link: function(link) { + var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator); + if (l.position) { + l.url = l.url.append_params({adapter: '_list_inline_adapter'}); + l.tag.href = l.url; + } + return l; + } +}); + +ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstract, { + insert: function(content) { + if (this.position == 'top') { + this.target.insert({top:content}); + this.set_adapter(this.target.immediateDescendants().first()); + } + else { + throw 'Unknown position "' + this.position + '"' + } + this.adapter.down('td').down().highlight(); + } +}); + +if (Ajax.InPlaceEditor) { +ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { + initialize: function($super, element, url, options) { + $super(element, url, options); + if (this._originalBackground == 'transparent') { + this._originalBackground = null; + } + }, + + setFieldFromAjax: function(url, options) { + var ipe = this; + $(ipe._controls.editor).remove(); + new Ajax.Request(url, { + method: 'get', + onComplete: function(response) { + ipe._form.insert({top: response.responseText}); + if (options.plural) { + ipe._form.getElements().each(function(el) { + if (el.type != "submit" && el.type != "image") { + el.name = ipe.options.paramName + '[]'; + el.className = 'editor_field'; + } + }); + } else { + var fld = ipe._form.findFirstElement(); + fld.name = ipe.options.paramName; + fld.className = 'editor_field'; + if (ipe.options.submitOnBlur) + fld.onblur = ipe._boundSubmitHandler; + ipe._controls.editor = fld; + } + } + }); + }, + + clonePatternField: function() { + var patternNodes = this.getPatternNodes(this.options.inplacePatternSelector); + if (patternNodes.editNode == null) { + alert('did not find any matching node for ' + this.options.editFieldSelector); + return; + } + + var fld = patternNodes.editNode.cloneNode(true); + if (fld.id.length > 0) fld.id += this.options.nodeIdSuffix; + fld.name = this.options.paramName; + fld.className = 'editor_field'; + this.setValue(fld, this._controls.editor.value); + if (this.options.submitOnBlur) + fld.onblur = this._boundSubmitHandler; + $(this._controls.editor).remove(); + this._controls.editor = fld; + this._form.appendChild(this._controls.editor); + + $A(patternNodes.additionalNodes).each(function(node) { + var patternNode = node.cloneNode(true); + if (patternNode.id.length > 0) { + patternNode.id = patternNode.id + this.options.nodeIdSuffix; + } + this._form.appendChild(patternNode); + }.bind(this)); + }, + + getPatternNodes: function(inplacePatternSelector) { + var nodes = {editNode: null, additionalNodes: []}; + var selectedNodes = $$(inplacePatternSelector); + var firstNode = selectedNodes.first(); + + if (typeof(firstNode) !== 'undefined') { + // AS inplace_edit_control_container -> we have to select all child nodes + // Workaround for ie which does not support css > selector + if (firstNode.className.indexOf('as_inplace_pattern') !== -1) { + selectedNodes = firstNode.childElements(); + } + nodes.editNode = selectedNodes.first(); + selectedNodes.shift(); + nodes.additionalNodes = selectedNodes; + } + return nodes; + }, + + setValue: function(editField, textValue) { + var function_name = 'setValueFor' + editField.nodeName.toLowerCase(); + if (typeof(this[function_name]) == 'function') { + this[function_name](editField, textValue); + } else { + editField.value = textValue; + } + }, + + setValueForselect: function(editField, textValue) { + var len = editField.options.length; + var i = 0; + while (i < len && editField.options[i].text != textValue) { + i++; + } + if (i < len) { + editField.value = editField.options[i].value + } + } +}); +} diff --git a/app/assets/javascripts/prototype/dhtml_history.js b/app/assets/javascripts/prototype/dhtml_history.js new file mode 100644 index 0000000000..da08ba2d57 --- /dev/null +++ b/app/assets/javascripts/prototype/dhtml_history.js @@ -0,0 +1,870 @@ +/* +Copyright (c) 2007 Brian Dillard and Brad Neuberg: +Brian Dillard | Project Lead | bdillard@pathf.com | http://blogs.pathf.com/agileajax/ +Brad Neuberg | Original Project Creator | http://codinginparadise.org + +SVN r113 from http://code.google.com/p/reallysimplehistory ++ Changes by Ed Wildgoose - MailASail ++ Changed EncodeURIComponent -> EncodeURI ++ Changed DecodeURIComponent -> DecodeURI ++ Changed 'blank.html?' -> '/blank.html?' + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files +(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +/* + dhtmlHistory: An object that provides history, history data, and bookmarking for DHTML and Ajax applications. + + dependencies: + * the historyStorage object included in this file. + +*/ +window.dhtmlHistory = { + + /*Public: User-agent booleans*/ + isIE: false, + isOpera: false, + isSafari: false, + isKonquerer: false, + isGecko: false, + isSupported: false, + + /*Public: Create the DHTML history infrastructure*/ + create: function(options) { + + /* + options - object to store initialization parameters + options.blankURL - string to override the default location of blank.html. Must end in "?" + options.debugMode - boolean that causes hidden form fields to be shown for development purposes. + options.toJSON - function to override default JSON stringifier + options.fromJSON - function to override default JSON parser + options.baseTitle - pattern for title changes; example: "Armchair DJ [@@@]" - @@@ will be replaced + */ + + var that = this; + + /*set user-agent flags*/ + var UA = navigator.userAgent.toLowerCase(); + var platform = navigator.platform.toLowerCase(); + var vendor = navigator.vendor || ""; + if (vendor === "KDE") { + this.isKonqueror = true; + this.isSupported = false; + } else if (typeof window.opera !== "undefined") { + this.isOpera = true; + this.isSupported = true; + } else if (typeof document.all !== "undefined") { + this.isIE = true; + this.isSupported = true; + } else if (vendor.indexOf("Apple Computer, Inc.") > -1) { + this.isSafari = true; + //this.isSupported = (platform.indexOf("mac") > -1); + this.isSupported = false; + } else if (UA.indexOf("gecko") != -1) { + this.isGecko = true; + this.isSupported = true; + } + + if (this.isSupported) { + /*Set up the historyStorage object; pass in options bundle*/ + window.historyStorage.setup(options); + + /*Set up our base title if one is passed in*/ + if (options && options.baseTitle) { + if (options.baseTitle.indexOf("@@@") < 0 && historyStorage.debugMode) { + throw new Error("Programmer error: options.baseTitle must contain the replacement parameter" + + " '@@@' to be useful."); + } + this.baseTitle = options.baseTitle; + } + + /*Create Safari/Opera-specific code*/ + if (this.isSafari && this.isSupported) { + this.createSafari(); + } else if (this.isOpera) { + this.createOpera(); + } + + /*Get our initial location*/ + var initialHash = this.getCurrentLocation(); + + /*Save it as our current location*/ + this.currentLocation = initialHash; + + /*Now that we have a hash, create IE-specific code*/ + if (this.isIE) { + /*Optionally override the URL of IE's blank HTML file*/ + if (options && options.blankURL) { + var u = options.blankURL; + /*assign the value, adding the trailing ? if it's not passed in*/ + this.blankURL = (u.indexOf("?") != u.length - 1 + ? u + "?" + : u + ); + } + this.createIE(initialHash); + } + + /*Add an unload listener for the page; this is needed for FF 1.5+ because this browser caches all dynamic updates to the + page, which can break some of our logic related to testing whether this is the first instance a page has loaded or whether + it is being pulled from the cache*/ + + var unloadHandler = function() { + that.firstLoad = null; + }; + + this.addEventListener(window,'unload',unloadHandler); + + /*Determine if this is our first page load; for IE, we do this in this.iframeLoaded(), which is fired on pageload. We do it + there because we have no historyStorage at this point, which only exists after the page is finished loading in IE*/ + if (this.isIE) { + /*The iframe will get loaded on page load, and we want to ignore this fact*/ + this.ignoreLocationChange = true; + } else if (this.isSupported) { + if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) { + /*This is our first page load, so ignore the location change and add our special history entry*/ + this.ignoreLocationChange = true; + this.firstLoad = true; + historyStorage.put(this.PAGELOADEDSTRING, true); + } else { + /*This isn't our first page load, so indicate that we want to pay attention to this location change*/ + this.ignoreLocationChange = false; + this.firstLoad = false; + /*For browsers other than IE, fire a history change event; on IE, the event will be thrown automatically when its + hidden iframe reloads on page load. Unfortunately, we don't have any listeners yet; indicate that we want to fire + an event when a listener is added.*/ + this.fireOnNewListener = true; + } + } + + /*Other browsers can use a location handler that checks at regular intervals as their primary mechanism; we use it for IE as + well to handle an important edge case; see checkLocation() for details*/ + var locationHandler = function() { + that.checkLocation(); + }; + setInterval(locationHandler, 100); + } + }, + + /*Public: Initialize our DHTML history. You must call this after the page is finished loading. Optionally, you can pass your listener in + here so you don't need to make a separate call to addListener*/ + initialize: function(listener) { + + /*save original document title to plug in when we hit a null-key history point*/ + this.originalTitle = document.title; + + /*IE needs to be explicitly initialized. IE doesn't autofill form data until the page is finished loading, so we have to wait*/ + if (this.isIE) { + /*If this is the first time this page has loaded*/ + if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) { + /*For IE, we do this in initialize(); for other browsers, we do it in create()*/ + this.fireOnNewListener = false; + this.firstLoad = true; + historyStorage.put(this.PAGELOADEDSTRING, true); + } + /*Else if this is a fake onload event*/ + else { + this.fireOnNewListener = true; + this.firstLoad = false; + } + } + /*optional convenience to save a separate call to addListener*/ + if (listener) { + this.addListener(listener); + } + }, + + /*Public: Adds a history change listener. Only one listener is supported at this time.*/ + addListener: function(listener) { + this.listener = listener; + /*If the page was just loaded and we should not ignore it, fire an event to our new listener now*/ + if (this.fireOnNewListener) { + this.fireHistoryEvent(this.currentLocation); + this.fireOnNewListener = false; + } + }, + + /*Public: Change the current HTML title*/ + changeTitle: function(historyData) { + var winTitle = (historyData && historyData.newTitle + /*Plug the new title into the pattern*/ + ? this.baseTitle.replace('@@@', historyData.newTitle) + /*Otherwise, if there is no new title, use the original document title. This is useful when some + history changes have title changes and some don't; we can automatically return to the original + title rather than leaving a misleading title in the title bar. The same goes for our "virgin" + (hashless) page state.*/ + : this.originalTitle + ); + /*No need to do anything if the title isn't changing*/ + if (document.title == winTitle) { + return; + } + + + /*Now change the DOM*/ + document.title = winTitle; + /*Change it in the iframe, too, for IE*/ + if (this.isIE) { + this.iframe.contentWindow.document.title = winTitle; + } + + /*If non-IE, reload the hash so the new title "sticks" in the browser history object*/ + if (!this.isIE && !this.isOpera) { + var hash = decodeURI(document.location.hash); + if (hash != "") { + var encodedHash = encodeURI(this.removeHash(hash)); + document.location.hash = encodedHash; + } else { + //document.location.hash = "#"; + } + } + }, + + /*Public: Add a history point. Parameters available: + * newLocation (required): + This will be the #hash value in the URL. Users can bookmark it. It will persist across sessions, so + your application should be able to restore itself to a specific state based on just this value. It + should be either a simple keyword for a viewstate or else a pseudo-querystring. + * historyData (optional): + This is for complex data that is relevant only to the current browsing session. It will be available + to your application until the browser is closed. If the user comes back to a bookmarked history point + during a later session, this data will no longer be available. Don't rely on it for application + re-initialization from a bookmark. + * historyData.newTitle (optional): + This will swap out the html <title> attribute with a new value. If you have set a baseTitle using the + options bundle, the value will be plugged into the baseTitle by swapping out the @@@ replacement param. + */ + add: function(newLocation, historyData) { + + var that = this; + + /*Escape the location and remove any leading hash symbols*/ + var encodedLocation = encodeURI(this.removeHash(newLocation)); + + if (this.isSafari) { + + /*Store the history data into history storage - pass in unencoded newLocation since + historyStorage does its own encoding*/ + historyStorage.put(newLocation, historyData); + + /*Save this as our current location*/ + this.currentLocation = encodedLocation; + + /*Change the browser location*/ + window.location.hash = encodedLocation; + + /*Save this to the Safari form field*/ + this.putSafariState(encodedLocation); + + this.changeTitle(historyData); + + } else { + + /*Most browsers require that we wait a certain amount of time before changing the location, such + as 200 MS; rather than forcing external callers to use window.setTimeout to account for this, + we internally handle it by putting requests in a queue.*/ + var addImpl = function() { + + /*Indicate that the current wait time is now less*/ + if (that.currentWaitTime > 0) { + that.currentWaitTime = that.currentWaitTime - that.waitTime; + } + + /*IE has a strange bug; if the encodedLocation is the same as _any_ preexisting id in the + document, then the history action gets recorded twice; throw a programmer exception if + there is an element with this ID*/ + if (document.getElementById(encodedLocation) && that.debugMode) { + var e = "Exception: History locations can not have the same value as _any_ IDs that might be in the document," + + " due to a bug in IE; please ask the developer to choose a history location that does not match any HTML" + + " IDs in this document. The following ID is already taken and cannot be a location: " + newLocation; + throw new Error(e); + } + + /*Store the history data into history storage - pass in unencoded newLocation since + historyStorage does its own encoding*/ + historyStorage.put(newLocation, historyData); + + /*Indicate to the browser to ignore this upcomming location change since we're making it programmatically*/ + that.ignoreLocationChange = true; + + /*Indicate to IE that this is an atomic location change block*/ + that.ieAtomicLocationChange = true; + + /*Save this as our current location*/ + that.currentLocation = encodedLocation; + + /*Change the browser location*/ + window.location.hash = encodedLocation; + + /*Change the hidden iframe's location if on IE*/ + if (that.isIE) { + that.iframe.src = that.blankURL + encodedLocation; + } + + /*End of atomic location change block for IE*/ + that.ieAtomicLocationChange = false; + + that.changeTitle(historyData); + + }; + + /*Now queue up this add request*/ + window.setTimeout(addImpl, this.currentWaitTime); + + /*Indicate that the next request will have to wait for awhile*/ + this.currentWaitTime = this.currentWaitTime + this.waitTime; + } + }, + + /*Public*/ + isFirstLoad: function() { + return this.firstLoad; + }, + + /*Public*/ + getVersion: function() { + return this.VERSIONNUMBER; + }, + + /*- - - - - - - - - - - -*/ + + /*Private: Constant for our own internal history event called when the page is loaded*/ + PAGELOADEDSTRING: "DhtmlHistory_pageLoaded", + + VERSIONNUMBER: "0.8", + + /* + Private: Pattern for title changes. Example: "Armchair DJ [@@@]" where @@@ will be relaced by values passed to add(); + Default is just the title itself, hence "@@@" + */ + baseTitle: "@@@", + + /*Private: Placeholder variable for the original document title; will be set in ititialize()*/ + originalTitle: null, + + /*Private: URL for the blank html file we use for IE; can be overridden via the options bundle. Otherwise it must be served + in same directory as this library*/ + blankURL: "/blank.html?", + + /*Private: Our history change listener.*/ + listener: null, + + /*Private: MS to wait between add requests - will be reset for certain browsers*/ + waitTime: 200, + + /*Private: MS before an add request can execute*/ + currentWaitTime: 0, + + /*Private: Our current hash location, without the "#" symbol.*/ + currentLocation: null, + + /*Private: Hidden iframe used to IE to detect history changes*/ + iframe: null, + + /*Private: Flags and DOM references used only by Safari*/ + safariHistoryStartPoint: null, + safariStack: null, + safariLength: null, + + /*Private: Flag used to keep checkLocation() from doing anything when it discovers location changes we've made ourselves + programmatically with the add() method. Basically, add() sets this to true. When checkLocation() discovers it's true, + it refrains from firing our listener, then resets the flag to false for next cycle. That way, our listener only gets fired on + history change events triggered by the user via back/forward buttons and manual hash changes. This flag also helps us set up + IE's special iframe-based method of handling history changes.*/ + ignoreLocationChange: null, + + /*Private: A flag that indicates that we should fire a history change event when we are ready, i.e. after we are initialized and + we have a history change listener. This is needed due to an edge case in browsers other than IE; if you leave a page entirely + then return, we must fire this as a history change event. Unfortunately, we have lost all references to listeners from earlier, + because JavaScript clears out.*/ + fireOnNewListener: null, + + /*Private: A variable that indicates whether this is the first time this page has been loaded. If you go to a web page, leave it + for another one, and then return, the page's onload listener fires again. We need a way to differentiate between the first page + load and subsequent ones. This variable works hand in hand with the pageLoaded variable we store into historyStorage.*/ + firstLoad: null, + + /*Private: A variable to handle an important edge case in IE. In IE, if a user manually types an address into their browser's + location bar, we must intercept this by calling checkLocation() at regular intervals. However, if we are programmatically + changing the location bar ourselves using the add() method, we need to ignore these changes in checkLocation(). Unfortunately, + these changes take several lines of code to complete, so for the duration of those lines of code, we set this variable to true. + That signals to checkLocation() to ignore the change-in-progress. Once we're done with our chunk of location-change code in + add(), we set this back to false. We'll do the same thing when capturing user-entered address changes in checkLocation itself.*/ + ieAtomicLocationChange: null, + + /*Private: Generic utility function for attaching events*/ + addEventListener: function(o,e,l) { + if (o.addEventListener) { + o.addEventListener(e,l,false); + } else if (o.attachEvent) { + o.attachEvent('on'+e,function() { + l(window.event); + }); + } + }, + + + /*Private: Create IE-specific DOM nodes and overrides*/ + createIE: function(initialHash) { + /*write out a hidden iframe for IE and set the amount of time to wait between add() requests*/ + this.waitTime = 400;/*IE needs longer between history updates*/ + var styles = (historyStorage.debugMode + ? 'width: 800px;height:80px;border:1px solid black;' + : historyStorage.hideStyles + ); + var iframeID = "rshHistoryFrame"; + var iframeHTML = '<iframe frameborder="0" id="' + iframeID + '" style="' + styles + '" src="' + this.blankURL + initialHash + '"></iframe>'; + document.write(iframeHTML); + this.iframe = document.getElementById(iframeID); + }, + + /*Private: Create Opera-specific DOM nodes and overrides*/ + createOpera: function() { + this.waitTime = 400;/*Opera needs longer between history updates*/ + var imgHTML = '<img src="javascript:location.href=\'javascript:dhtmlHistory.checkLocation();\';" style="' + historyStorage.hideStyles + '" />'; + document.write(imgHTML); + }, + + /*Private: Create Safari-specific DOM nodes and overrides*/ + createSafari: function() { + var formID = "rshSafariForm"; + var stackID = "rshSafariStack"; + var lengthID = "rshSafariLength"; + var formStyles = historyStorage.debugMode ? historyStorage.showStyles : historyStorage.hideStyles; + var stackStyles = (historyStorage.debugMode + ? 'width: 800px;height:80px;border:1px solid black;' + : historyStorage.hideStyles + ); + var lengthStyles = (historyStorage.debugMode + ? 'width:800px;height:20px;border:1px solid black;margin:0;padding:0;' + : historyStorage.hideStyles + ); + var safariHTML = '<form id="' + formID + '" style="' + formStyles + '">' + + '<textarea style="' + stackStyles + '" id="' + stackID + '">[]</textarea>' + + '<input type="text" style="' + lengthStyles + '" id="' + lengthID + '" value=""/>' + + '</form>'; + document.write(safariHTML); + this.safariStack = document.getElementById(stackID); + this.safariLength = document.getElementById(lengthID); + if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) { + this.safariHistoryStartPoint = history.length; + this.safariLength.value = this.safariHistoryStartPoint; + } else { + this.safariHistoryStartPoint = this.safariLength.value; + } + }, + + /*TODO: make this public again?*/ + /*Private: Get browser's current hash location; for Safari, read value from a hidden form field*/ + getCurrentLocation: function() { + var r = (this.isSafari + ? this.getSafariState() + : this.getCurrentHash() + ); + return r; + }, + + /*TODO: make this public again?*/ + /*Private: Manually parse the current url for a hash; tip of the hat to YUI*/ + getCurrentHash: function() { + var r = window.location.href; + var i = r.indexOf("#"); + return (i >= 0 + ? r.substr(i+1) + : "" + ); + }, + + /*Private: Safari method to read the history stack from a hidden form field*/ + getSafariStack: function() { + var r = this.safariStack.value; + return historyStorage.fromJSON(r); + }, + /*Private: Safari method to read from the history stack*/ + getSafariState: function() { + var stack = this.getSafariStack(); + var state = stack[history.length - this.safariHistoryStartPoint - 1]; + return state; + }, + /*Private: Safari method to write the history stack to a hidden form field*/ + putSafariState: function(newLocation) { + var stack = this.getSafariStack(); + stack[history.length - this.safariHistoryStartPoint] = newLocation; + this.safariStack.value = historyStorage.toJSON(stack); + }, + + /*Private: Notify the listener of new history changes.*/ + fireHistoryEvent: function(newHash) { + var decodedHash = decodeURI(newHash) + /*extract the value from our history storage for this hash*/ + var historyData = historyStorage.get(decodedHash); + this.changeTitle(historyData); + /*call our listener*/ + this.listener.call(null, decodedHash, historyData); + }, + + /*Private: See if the browser has changed location. This is the primary history mechanism for Firefox. For IE, we use this to + handle an important edge case: if a user manually types in a new hash value into their IE location bar and press enter, we want to + to intercept this and notify any history listener.*/ + checkLocation: function() { + + /*Ignore any location changes that we made ourselves for browsers other than IE*/ + if (!this.isIE && this.ignoreLocationChange) { + this.ignoreLocationChange = false; + return; + } + + /*If we are dealing with IE and we are in the middle of making a location change from an iframe, ignore it*/ + if (!this.isIE && this.ieAtomicLocationChange) { + return; + } + + /*Get hash location*/ + var hash = this.getCurrentLocation(); + + /*Do nothing if there's been no change*/ + if (hash == this.currentLocation) { + return; + } + + /*In IE, users manually entering locations into the browser; we do this by comparing the browser's location against the + iframe's location; if they differ, we are dealing with a manual event and need to place it inside our history, otherwise + we can return*/ + this.ieAtomicLocationChange = true; + + if (this.isIE && this.getIframeHash() != hash) { + this.iframe.src = this.blankURL + hash; + } + else if (this.isIE) { + /*the iframe is unchanged*/ + return; + } + + /*Save this new location*/ + this.currentLocation = hash; + + this.ieAtomicLocationChange = false; + + /*Notify listeners of the change*/ + this.fireHistoryEvent(hash); + }, + + /*Private: Get the current location of IE's hidden iframe.*/ + getIframeHash: function() { + var doc = this.iframe.contentWindow.document; + var hash = String(doc.location.search); + if (hash.length == 1 && hash.charAt(0) == "?") { + hash = ""; + } + else if (hash.length >= 2 && hash.charAt(0) == "?") { + hash = hash.substring(1); + } + return hash; + }, + + /*Private: Remove any leading hash that might be on a location.*/ + removeHash: function(hashValue) { + var r; + if (hashValue === null || hashValue === undefined) { + r = null; + } + else if (hashValue === "") { + r = ""; + } + else if (hashValue.length == 1 && hashValue.charAt(0) == "#") { + r = ""; + } + else if (hashValue.length > 1 && hashValue.charAt(0) == "#") { + r = hashValue.substring(1); + } + else { + r = hashValue; + } + return r; + }, + + /*Private: For IE, tell when the hidden iframe has finished loading.*/ + iframeLoaded: function(newLocation) { + /*ignore any location changes that we made ourselves*/ + if (this.ignoreLocationChange) { + this.ignoreLocationChange = false; + return; + } + + /*Get the new location*/ + var hash = String(newLocation.search); + if (hash.length == 1 && hash.charAt(0) == "?") { + hash = ""; + } + else if (hash.length >= 2 && hash.charAt(0) == "?") { + hash = hash.substring(1); + } + /*Keep the browser location bar in sync with the iframe hash*/ + window.location.hash = hash; + + /*Notify listeners of the change*/ + this.fireHistoryEvent(hash); + } + + +}; + +/* + historyStorage: An object that uses a hidden form to store history state across page loads. The mechanism for doing so relies on + the fact that browsers save the text in form data for the life of the browser session, which means the text is still there when + the user navigates back to the page. This object can be used independently of the dhtmlHistory object for caching of Ajax + session information. + + dependencies: + * json2007.js (included in a separate file) or alternate JSON methods passed in through an options bundle. +*/ +window.historyStorage = { + + /*Public: Set up our historyStorage object for use by dhtmlHistory or other objects*/ + setup: function(options) { + + /* + options - object to store initialization parameters - passed in from dhtmlHistory or directly into historyStorage + options.debugMode - boolean that causes hidden form fields to be shown for development purposes. + options.toJSON - function to override default JSON stringifier + options.fromJSON - function to override default JSON parser + */ + + /*process init parameters*/ + if (typeof options !== "undefined") { + if (options.debugMode) { + this.debugMode = options.debugMode; + } + if (options.toJSON) { + this.toJSON = options.toJSON; + } + if (options.fromJSON) { + this.fromJSON = options.fromJSON; + } + } + + /*write a hidden form and textarea into the page; we'll stow our history stack here*/ + var formID = "rshStorageForm"; + var textareaID = "rshStorageField"; + var formStyles = this.debugMode ? historyStorage.showStyles : historyStorage.hideStyles; + var textareaStyles = (historyStorage.debugMode + ? 'width: 800px;height:80px;border:1px solid black;' + : historyStorage.hideStyles + ); + var textareaHTML = '<form id="' + formID + '" style="' + formStyles + '">' + + '<textarea id="' + textareaID + '" style="' + textareaStyles + '"></textarea>' + + '</form>'; + document.write(textareaHTML); + this.storageField = document.getElementById(textareaID); + if (typeof window.opera !== "undefined") { + this.storageField.focus();/*Opera needs to focus this element before persisting values in it*/ + } + }, + + /*Public*/ + put: function(key, value) { + + var encodedKey = encodeURI(key); + + this.assertValidKey(encodedKey); + /*if we already have a value for this, remove the value before adding the new one*/ + if (this.hasKey(key)) { + this.remove(key); + } + /*store this new key*/ + this.storageHash[encodedKey] = value; + /*save and serialize the hashtable into the form*/ + this.saveHashTable(); + }, + + /*Public*/ + get: function(key) { + + var encodedKey = encodeURI(key); + + this.assertValidKey(encodedKey); + /*make sure the hash table has been loaded from the form*/ + this.loadHashTable(); + var value = this.storageHash[encodedKey]; + if (value === undefined) { + value = null; + } + return value; + }, + + /*Public*/ + remove: function(key) { + + var encodedKey = encodeURI(key); + + this.assertValidKey(encodedKey); + /*make sure the hash table has been loaded from the form*/ + this.loadHashTable(); + /*delete the value*/ + delete this.storageHash[encodedKey]; + /*serialize and save the hash table into the form*/ + this.saveHashTable(); + }, + + /*Public: Clears out all saved data.*/ + reset: function() { + this.storageField.value = ""; + this.storageHash = {}; + }, + + /*Public*/ + hasKey: function(key) { + + var encodedKey = encodeURI(key); + + this.assertValidKey(encodedKey); + /*make sure the hash table has been loaded from the form*/ + this.loadHashTable(); + return (typeof this.storageHash[encodedKey] !== "undefined"); + }, + + /*Public*/ + isValidKey: function(key) { + return (typeof key === "string"); + //TODO - should we ban hash signs and other special characters? + }, + + /*- - - - - - - - - - - -*/ + + /*Private - CSS strings utilized by both objects to hide or show behind-the-scenes DOM elements*/ + showStyles: 'border:0;margin:0;padding:0;', + hideStyles: 'left:-1000px;top:-1000px;width:1px;height:1px;border:0;position:absolute;', + + /*Private - debug mode flag*/ + debugMode: false, + + /*Private: Our hash of key name/values.*/ + storageHash: {}, + + /*Private: If true, we have loaded our hash table out of the storage form.*/ + hashLoaded: false, + + /*Private: DOM reference to our history field*/ + storageField: null, + + /*Private: Assert that a key is valid; throw an exception if it not.*/ + assertValidKey: function(key) { + var isValid = this.isValidKey(key); + if (!isValid && this.debugMode) { + throw new Error("Please provide a valid key for window.historyStorage. Invalid key = " + key + "."); + } + }, + + /*Private: Load the hash table up from the form.*/ + loadHashTable: function() { + if (!this.hashLoaded) { + var serializedHashTable = this.storageField.value; + if (serializedHashTable !== "" && serializedHashTable !== null) { + this.storageHash = this.fromJSON(serializedHashTable); + this.hashLoaded = true; + } + } + }, + /*Private: Save the hash table into the form.*/ + saveHashTable: function() { + this.loadHashTable(); + var serializedHashTable = this.toJSON(this.storageHash); + this.storageField.value = serializedHashTable; + }, + /*Private: Bridges for our JSON implementations - both rely on 2007 JSON.org library - can be overridden by options bundle*/ + toJSON: function(o) { + return o.toJSONString(); + }, + fromJSON: function(s) { + return s.parseJSON(); + } +}; + + +/*******************************************************************/ +/** QueryString Object from http://adamv.com/dev/javascript/querystring */ +/* Client-side access to querystring name=value pairs + Version 1.3 + 28 May 2008 + + License (Simplified BSD): + http://adamv.com/dev/javascript/qslicense.txt +*/ +function Querystring(qs) { // optionally pass a querystring to parse + this.params = {}; + + if (qs == null) qs = location.search.substring(1, location.search.length); + if (qs.length == 0) return; + +// Turn <plus> back to <space> +// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1 + qs = qs.replace(/\+/g, ' '); + var args = qs.split('&'); // parse out name/value pairs separated via & + +// split out each name=value pair + for (var i = 0; i < args.length; i++) { + var pair = args[i].split('='); + var name = decodeURI(pair[0]); + + var value = (pair.length==2) + ? decodeURI(pair[1]) + : name; + + this.params[name] = value; + } +} + +Querystring.prototype.get = function(key, default_) { + var value = this.params[key]; + return (value != null) ? value : default_; +} + +Querystring.prototype.contains = function(key) { + var value = this.params[key]; + return (value != null); +} + +/*******************************************************************/ +/* Added by Ed Wildgoose - MailASail */ +/* Initialise the library and add our history callback */ +/*******************************************************************/ +window.dhtmlHistory.create({ + toJSON: function(o) { + return Object.toJSON(o); + } + , fromJSON: function(s) { + return s.evalJSON(); + } + + // Enable this to assist with debugging +// , debugMode: true + + // dhtmlHistory has been modified not to need the next line + // But left in for robustness when updating dhtmlHistory + , blankURL: '/blank.html?' +}); + +/** Our callback to receive history + change events. */ +var handleHistoryChange = function(pageId, pageData) { + if (!pageData) return; + var info = pageId.split(':'); + var id = info[0]; + pageData += '&_method=get'; + new Ajax.Request(pageData, {asynchronous:true, evalScripts:true, method: 'get', onLoading:function(request){Element.show(id+'-pagination-loading-indicator');}}); +} + +window.onload = function() { + dhtmlHistory.initialize(handleHistoryChange); +}; + diff --git a/app/assets/javascripts/prototype/form_enhancements.js b/app/assets/javascripts/prototype/form_enhancements.js new file mode 100644 index 0000000000..136c2c0e8f --- /dev/null +++ b/app/assets/javascripts/prototype/form_enhancements.js @@ -0,0 +1,117 @@ + +// TODO Change to dropping the name property off the input element when in example mode +TextFieldWithExample = Class.create(); +TextFieldWithExample.prototype = { + initialize: function(inputElementId, defaultText, options) { + this.setOptions(options); + + this.input = $(inputElementId); + this.name = this.input.name; + this.defaultText = defaultText; + this.createHiddenInput(); + + if (options.focus) this.input.focus(); + this.checkAndShowExample(); + if (options.focus) { + this.input.selectionStart = 0; + this.input.selectionEnd = 0; + } + + Event.observe(this.input, "blur", this.onBlur.bindAsEventListener(this)); + Event.observe(this.input, "focus", this.onFocus.bindAsEventListener(this)); + Event.observe(this.input, "select", this.onFocus.bindAsEventListener(this)); + Event.observe(this.input, "keydown", this.onKeyPress.bindAsEventListener(this)); + Event.observe(this.input, "click", this.onClick.bindAsEventListener(this)); + }, + createHiddenInput: function() { + this.hiddenInput = document.createElement("input"); + this.hiddenInput.type = "hidden"; + this.hiddenInput.value = ""; + this.input.parentNode.appendChild(this.hiddenInput); + }, + setOptions: function(options) { + this.options = { exampleClassName: 'example' }; + Object.extend(this.options, options || {}); + }, + onKeyPress: function(event) { + if (!event) var event = window.event; + var code = (event.which) ? event.which : event.keyCode + if (this.isAlphanumeric(code)) { + this.removeExample(); + } + }, + onBlur: function(event) { + this.checkAndShowExample(); + }, + onFocus: function(event) { + this.removeExample(); + }, + onClick: function(event) { + this.removeExample(); + }, + isAlphanumeric: function(keyCode) { + return keyCode >= 40 && keyCode <= 90; + }, + checkAndShowExample: function() { + if (this.input.value == '') { + this.input.value = this.defaultText; + this.input.name = null; + this.hiddenInput.name = this.name; + Element.addClassName(this.input, this.options.exampleClassName); + } + }, + removeExample: function() { + if (this.exampleShown()) { + this.input.value = ''; + this.input.name = this.name; + this.hiddenInput.name = null; + Element.removeClassName(this.input, this.options.exampleClassName); + } + }, + exampleShown: function() { + return Element.hasClassName(this.input, this.options.exampleClassName); + } +} + +Form.disable = function(form) { + var elements = this.getElements(form); + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + try { element.blur(); } catch (e) {} + element.disabled = 'disabled'; + Element.addClassName(element, 'disabled'); + } + } +Form.enable = function(form) { + var elements = this.getElements(form); + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + element.disabled = ''; + Element.removeClassName(element, 'disabled'); + } + } + +DraggableLists = Class.create({ + initialize: function(list) { + list = $(list).addClassName('draggable-list'); + var list_selected = list.cloneNode(false).addClassName('selected'); + list_selected.id += '_seleted'; + list.select('input[type=checkbox]').each(function(item) { + var li = item.up('li'); + li.down('label').htmlFor = null; + new Draggable(li, {revert: 'failure', ghosting: true}); + if (item.checked) list_selected.insert(li.remove()); + }); + list.insert({after: list_selected}); + Droppables.add(list, {hoverclass: 'hover', containment: list_selected.id, onDrop: this.drop_to_list}); + Droppables.add(list_selected, {hoverclass: 'hover', containment: list.id, onDrop: this.drop_to_list}); + list.undoPositioned(); // undo positioned to fix dragging from elements with overflow auto + list_selected.undoPositioned(); + }, + + drop_to_list: function(draggable, droppable, event) { + droppable.insert(draggable.remove()); + draggable.setStyle({left: '0px', top: '0px'}); + draggable.down('input').checked = droppable.hasClassName('selected'); + } +}); diff --git a/app/assets/javascripts/prototype/index.js b/app/assets/javascripts/prototype/index.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/assets/javascripts/prototype/rico_corner.js b/app/assets/javascripts/prototype/rico_corner.js new file mode 100644 index 0000000000..e6541f1633 --- /dev/null +++ b/app/assets/javascripts/prototype/rico_corner.js @@ -0,0 +1,370 @@ +/** + * + * Copyright 2005 Sabre Airline Solutions + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this + * file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language governing permissions + * and limitations under the License. + **/ + + +//-------------------- rico.js +var Rico = { + Version: '1.1.0', + prototypeVersion: parseFloat(Prototype.Version.split(".")[0] + "." + Prototype.Version.split(".")[1]) +} + +//-------------------- ricoColor.js +Rico.Color = Class.create(); + +Rico.Color.prototype = { + + initialize: function(red, green, blue) { + this.rgb = { r: red, g : green, b : blue }; + }, + + blend: function(other) { + this.rgb.r = Math.floor((this.rgb.r + other.rgb.r)/2); + this.rgb.g = Math.floor((this.rgb.g + other.rgb.g)/2); + this.rgb.b = Math.floor((this.rgb.b + other.rgb.b)/2); + }, + + asRGB: function() { + return "rgb(" + this.rgb.r + "," + this.rgb.g + "," + this.rgb.b + ")"; + }, + + asHex: function() { + return "#" + this.rgb.r.toColorPart() + this.rgb.g.toColorPart() + this.rgb.b.toColorPart(); + }, + + asHSB: function() { + return Rico.Color.RGBtoHSB(this.rgb.r, this.rgb.g, this.rgb.b); + }, + + toString: function() { + return this.asHex(); + } + +}; + +Rico.Color.createFromHex = function(hexCode) { + if(hexCode.length==4) { + var shortHexCode = hexCode; + var hexCode = '#'; + for(var i=1;i<4;i++) hexCode += (shortHexCode.charAt(i) + shortHexCode.charAt(i)); + } + if ( hexCode.indexOf('#') == 0 ) + hexCode = hexCode.substring(1); + var red = hexCode.substring(0,2); + var green = hexCode.substring(2,4); + var blue = hexCode.substring(4,6); + return new Rico.Color( parseInt(red,16), parseInt(green,16), parseInt(blue,16) ); +} + +/** + * Factory method for creating a color from the background of + * an HTML element. + */ +Rico.Color.createColorFromBackground = function(elem) { + + //var actualColor = RicoUtil.getElementsComputedStyle($(elem), "backgroundColor", "background-color"); // Changed to prototype style + var actualColor = $(elem).getStyle('backgroundColor'); + + if ( actualColor == "transparent" && elem.parentNode ) + return Rico.Color.createColorFromBackground(elem.parentNode); + + if ( actualColor == null ) + return new Rico.Color(255,255,255); + + if ( actualColor.indexOf("rgb(") == 0 ) { + var colors = actualColor.substring(4, actualColor.length - 1 ); + var colorArray = colors.split(","); + return new Rico.Color( parseInt( colorArray[0] ), + parseInt( colorArray[1] ), + parseInt( colorArray[2] ) ); + + } + else if ( actualColor.indexOf("#") == 0 ) { + return Rico.Color.createFromHex(actualColor); + } + else + return new Rico.Color(255,255,255); +} + +/* next two functions changed to mootools color.js functions */ +Rico.Color.HSBtoRGB = function(hue, saturation, brightness) { + + var br = Math.round(brightness / 100 * 255); + if (this[1] == 0){ + return [br, br, br]; + } else { + var hue = this[0] % 360; + var f = hue % 60; + var p = Math.round((brightness * (100 - saturation)) / 10000 * 255); + var q = Math.round((brightness * (6000 - saturation * f)) / 600000 * 255); + var t = Math.round((brightness * (6000 - saturation * (60 - f))) / 600000 * 255); + switch(Math.floor(hue / 60)){ + case 0: return { r : br, g : t, b : p }; + case 1: return { r : q, g : br, b : p }; + case 2: return { r : p, g : br, b : t }; + case 3: return { r : p, g : q, b : br }; + case 4: return { r : t, g : p, b : br }; + case 5: return { r : br, g : p, b : q }; + } + } + return false; + } + +Rico.Color.RGBtoHSB = function(red, green, blue) { + var hue, saturation, brightness; + var max = Math.max(red, green, blue), min = Math.min(red, green, blue); + var delta = max - min; + brightness = max / 255; + saturation = (max != 0) ? delta / max : 0; + if (saturation == 0){ + hue = 0; + } else { + var rr = (max - red) / delta; + var gr = (max - green) / delta; + var br = (max - blue) / delta; + if (red == max) hue = br - gr; + else if (green == max) hue = 2 + rr - br; + else hue = 4 + gr - rr; + hue /= 6; + if (hue < 0) hue++; + } + return { h : Math.round(hue * 360), s : Math.round(saturation * 100), b : Math.round(brightness * 100)}; +} + + +//-------------------- ricoCorner.js +Rico.Corner = { + + round: function(e, options) { + var e = $(e); + this._setOptions(options); + + var color = this.options.color; + if ( this.options.color == "fromElement" ) + color = this._background(e); + + var bgColor = this.options.bgColor; + if ( this.options.bgColor == "fromParent" ) + bgColor = this._background(e.offsetParent); + + this._roundCornersImpl(e, color, bgColor); + }, + + _roundCornersImpl: function(e, color, bgColor) { + if(this.options.border) + this._renderBorder(e,bgColor); + if(this._isTopRounded()) + this._roundTopCorners(e,color,bgColor); + if(this._isBottomRounded()) + this._roundBottomCorners(e,color,bgColor); + }, + + _renderBorder: function(el,bgColor) { + var borderValue = "1px solid " + this._borderColor(bgColor); + var borderL = "border-left: " + borderValue; + var borderR = "border-right: " + borderValue; + var style = "style='" + borderL + ";" + borderR + "'"; + el.innerHTML = "<div " + style + ">" + el.innerHTML + "</div>" + }, + + _roundTopCorners: function(el, color, bgColor) { + var corner = this._createCorner(bgColor); + for(var i=0 ; i < this.options.numSlices ; i++ ) + corner.appendChild(this._createCornerSlice(color,bgColor,i,"top")); + el.style.paddingTop = 0; + el.insertBefore(corner,el.firstChild); + }, + + _roundBottomCorners: function(el, color, bgColor) { + var corner = this._createCorner(bgColor); + for(var i=(this.options.numSlices-1) ; i >= 0 ; i-- ) + corner.appendChild(this._createCornerSlice(color,bgColor,i,"bottom")); + el.style.paddingBottom = 0; + el.appendChild(corner); + }, + + _createCorner: function(bgColor) { + var corner = document.createElement("div"); + corner.style.backgroundColor = (this._isTransparent() ? "transparent" : bgColor); + return corner; + }, + + _createCornerSlice: function(color,bgColor, n, position) { + var slice = document.createElement("span"); + + var inStyle = slice.style; + inStyle.backgroundColor = color; + inStyle.display = "block"; + inStyle.height = "1px"; + inStyle.overflow = "hidden"; + inStyle.fontSize = "1px"; + + var borderColor = this._borderColor(color,bgColor); + if ( this.options.border && n == 0 ) { + inStyle.borderTopStyle = "solid"; + inStyle.borderTopWidth = "1px"; + inStyle.borderLeftWidth = "0px"; + inStyle.borderRightWidth = "0px"; + inStyle.borderBottomWidth = "0px"; + inStyle.height = "0px"; // assumes css compliant box model + inStyle.borderColor = borderColor; + } + else if(borderColor) { + inStyle.borderColor = borderColor; + inStyle.borderStyle = "solid"; + inStyle.borderWidth = "0px 1px"; + } + + if ( !this.options.compact && (n == (this.options.numSlices-1)) ) + inStyle.height = "2px"; + + this._setMargin(slice, n, position); + this._setBorder(slice, n, position); + return slice; + }, + + _setOptions: function(options) { + this.options = { + corners : "all", + color : "fromElement", + bgColor : "fromParent", + blend : true, + border : false, + compact : false + } + Object.extend(this.options, options || {}); + + this.options.numSlices = this.options.compact ? 2 : 4; + if ( this._isTransparent() ) + this.options.blend = false; + }, + + _whichSideTop: function() { + if ( this._hasString(this.options.corners, "all", "top") ) + return ""; + + if ( this.options.corners.indexOf("tl") >= 0 && this.options.corners.indexOf("tr") >= 0 ) + return ""; + + if (this.options.corners.indexOf("tl") >= 0) + return "left"; + else if (this.options.corners.indexOf("tr") >= 0) + return "right"; + return ""; + }, + + _whichSideBottom: function() { + if ( this._hasString(this.options.corners, "all", "bottom") ) + return ""; + + if ( this.options.corners.indexOf("bl")>=0 && this.options.corners.indexOf("br")>=0 ) + return ""; + + if(this.options.corners.indexOf("bl") >=0) + return "left"; + else if(this.options.corners.indexOf("br")>=0) + return "right"; + return ""; + }, + + _borderColor : function(color,bgColor) { + if ( color == "transparent" ) + return bgColor; + else if ( this.options.border ) + return this.options.border; + else if ( this.options.blend ) + return this._blend( bgColor, color ); + else + return ""; + }, + + + _setMargin: function(el, n, corners) { + var marginSize = this._marginSize(n); + var whichSide = corners == "top" ? this._whichSideTop() : this._whichSideBottom(); + + if ( whichSide == "left" ) { + el.style.marginLeft = marginSize + "px"; el.style.marginRight = "0px"; + } + else if ( whichSide == "right" ) { + el.style.marginRight = marginSize + "px"; el.style.marginLeft = "0px"; + } + else { + el.style.marginLeft = marginSize + "px"; el.style.marginRight = marginSize + "px"; + } + }, + + _setBorder: function(el,n,corners) { + var borderSize = this._borderSize(n); + var whichSide = corners == "top" ? this._whichSideTop() : this._whichSideBottom(); + if ( whichSide == "left" ) { + el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = "0px"; + } + else if ( whichSide == "right" ) { + el.style.borderRightWidth = borderSize + "px"; el.style.borderLeftWidth = "0px"; + } + else { + el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = borderSize + "px"; + } + if (this.options.border != false) + el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = borderSize + "px"; + }, + + _marginSize: function(n) { + if ( this._isTransparent() ) + return 0; + + var marginSizes = [ 5, 3, 2, 1 ]; + var blendedMarginSizes = [ 3, 2, 1, 0 ]; + var compactMarginSizes = [ 2, 1 ]; + var smBlendedMarginSizes = [ 1, 0 ]; + + if ( this.options.compact && this.options.blend ) + return smBlendedMarginSizes[n]; + else if ( this.options.compact ) + return compactMarginSizes[n]; + else if ( this.options.blend ) + return blendedMarginSizes[n]; + else + return marginSizes[n]; + }, + + _borderSize: function(n) { + var transparentBorderSizes = [ 5, 3, 2, 1 ]; + var blendedBorderSizes = [ 2, 1, 1, 1 ]; + var compactBorderSizes = [ 1, 0 ]; + var actualBorderSizes = [ 0, 2, 0, 0 ]; + + if ( this.options.compact && (this.options.blend || this._isTransparent()) ) + return 1; + else if ( this.options.compact ) + return compactBorderSizes[n]; + else if ( this.options.blend ) + return blendedBorderSizes[n]; + else if ( this.options.border ) + return actualBorderSizes[n]; + else if ( this._isTransparent() ) + return transparentBorderSizes[n]; + return 0; + }, + + _hasString: function(str) { for(var i=1 ; i<arguments.length ; i++) if (str.indexOf(arguments[i]) >= 0) return true; return false; }, + _blend: function(c1, c2) { var cc1 = Rico.Color.createFromHex(c1); cc1.blend(Rico.Color.createFromHex(c2)); return cc1; }, + _background: function(el) { try { return Rico.Color.createColorFromBackground(el).asHex(); } catch(err) { return "#ffffff"; } }, + _isTransparent: function() { return this.options.color == "transparent"; }, + _isTopRounded: function() { return this._hasString(this.options.corners, "all", "top", "tl", "tr"); }, + _isBottomRounded: function() { return this._hasString(this.options.corners, "all", "bottom", "bl", "br"); }, + _hasSingleTextChild: function(el) { return el.childNodes.length == 1 && el.childNodes[0].nodeType == 3; } +} + From d0ff07b398c5dfed568b1ca149b9e99b44e93a86 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 18 Jun 2011 23:08:54 +0200 Subject: [PATCH 1137/2024] asset pipeline for javascript files up and running --- app/assets/javascripts/active_scaffold.js.erb | 14 ++++++-------- app/assets/javascripts/prototype/index.js | 0 2 files changed, 6 insertions(+), 8 deletions(-) delete mode 100644 app/assets/javascripts/prototype/index.js diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index 1bae6b4758..fbd1b3a7aa 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -1,11 +1,9 @@ -// This is a manifest file that'll be compiled into including all the files listed below. -// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically -// be included in the compiled file accessible from http://example.com/assets/application.js -// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the -// the compiled file. -// <% if ActiveScaffold.js_framework == :jquery %> -//= require jquery/active_scaffold +<% require_asset "jquery/active_scaffold" %> +<% require_asset "jquery/jquery.editinplace" %> <% else %> -//= require prototype/active_scaffold +<% require_asset "prototype/active_scaffold" %> +<% require_asset "prototype/dhtml_history" %> +<% require_asset "prototype/form_enhancements" %> +<% require_asset "prototype/rico_corner" %> <% end %> diff --git a/app/assets/javascripts/prototype/index.js b/app/assets/javascripts/prototype/index.js deleted file mode 100644 index e69de29bb2..0000000000 From 91d04759d58d4ce988fbdf573e28b593a0922715 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 18 Jun 2011 23:14:51 +0200 Subject: [PATCH 1138/2024] remove javascript and stylesheets at old location --- .../javascripts/jquery/active_scaffold.js | 1037 ---------------- .../javascripts/jquery/jquery.editinplace.js | 743 ------------ .../javascripts/prototype/active_scaffold.js | 1028 ---------------- .../javascripts/prototype/dhtml_history.js | 870 ------------- .../prototype/form_enhancements.js | 117 -- .../javascripts/prototype/rico_corner.js | 370 ------ .../default/stylesheets/stylesheet-ie.css | 35 - frontends/default/stylesheets/stylesheet.css | 1076 ----------------- 8 files changed, 5276 deletions(-) delete mode 100644 frontends/default/javascripts/jquery/active_scaffold.js delete mode 100644 frontends/default/javascripts/jquery/jquery.editinplace.js delete mode 100644 frontends/default/javascripts/prototype/active_scaffold.js delete mode 100644 frontends/default/javascripts/prototype/dhtml_history.js delete mode 100644 frontends/default/javascripts/prototype/form_enhancements.js delete mode 100644 frontends/default/javascripts/prototype/rico_corner.js delete mode 100644 frontends/default/stylesheets/stylesheet-ie.css delete mode 100644 frontends/default/stylesheets/stylesheet.css diff --git a/frontends/default/javascripts/jquery/active_scaffold.js b/frontends/default/javascripts/jquery/active_scaffold.js deleted file mode 100644 index 747e4d7735..0000000000 --- a/frontends/default/javascripts/jquery/active_scaffold.js +++ /dev/null @@ -1,1037 +0,0 @@ -$(document).ready(function() { - $('form.as_form').live('ajax:loading', function(event) { - var as_form = $(this).closest("form"); - if (as_form && as_form.attr('data-loading') == 'true') { - ActiveScaffold.disable_form(as_form); - } - return true; - }); - - $('form.as_form').live('ajax:complete', function(event) { - var as_form = $(this).closest("form"); - if (as_form && as_form.attr('data-loading') == 'true') { - ActiveScaffold.enable_form(as_form); - } - }); - $('form.as_form').live('ajax:failure', function(event) { - var as_div = $(this).closest("div.active-scaffold"); - if (as_div) { - ActiveScaffold.report_500_response(as_div) - } - }); - $('form.as_form.as_remote_upload').live('submit', function(event) { - var as_form = $(this).closest("form"); - if (as_form && as_form.attr('data-loading') == 'true') { - setTimeout("ActiveScaffold.disable_form('" + as_form.attr('id') + "')", 10); - } - return true; - }); - $('a.as_action').live('ajax:before', function(event) { - var action_link = ActiveScaffold.ActionLink.get($(this)); - if (action_link) { - if (action_link.is_disabled()) { - return false; - } else { - // hack: jquery requires if you request for javascript that javascript - // is coming back, however rails has a different mantra - if (action_link.position) event.data_type = 'rails'; - if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible'); - action_link.disable(); - } - } - return true; - }); - $('a.as_action').live('ajax:success', function(event, response) { - var action_link = ActiveScaffold.ActionLink.get($(this)); - if (action_link) { - if (action_link.position) { - action_link.insert(response); - if (action_link.hide_target) action_link.target.hide(); - } else { - action_link.enable(); - } - return true; - } - return true; - }); - $('a.as_action').live('ajax:complete', function(event) { - var action_link = ActiveScaffold.ActionLink.get($(this)); - if (action_link) { - if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden'); - } - return true; - }); - $('a.as_action').live('ajax:failure', function(event) { - var action_link = ActiveScaffold.ActionLink.get($(this)); - if (action_link) { - ActiveScaffold.report_500_response(action_link.scaffold_id()); - action_link.enable(); - } - return true; - }); - $('a.as_cancel').live('ajax:before', function(event) { - var as_cancel = $(this); - var action_link = ActiveScaffold.find_action_link(as_cancel); - - if (action_link) { - var cancel_url = as_cancel.attr('href'); - var refresh_data = as_cancel.attr('data-refresh'); - if (refresh_data === 'true' && action_link.refresh_url) { - event.data_url = action_link.refresh_url; - if (action_link.position) event.data_type = 'html' - } else if (refresh_data === 'false' || typeof(cancel_url) == 'undefined' || cancel_url.length == 0) { - action_link.close(); - return false; - } - } - return true; - }); - $('a.as_cancel').live('ajax:success', function(event, response) { - var action_link = ActiveScaffold.find_action_link($(this)); - - if (action_link) { - if (action_link.position) { - action_link.close(response); - } else { - response.evalResponse(); - } - } - return true; - }); - $('a.as_cancel').live('ajax:failure', function(event) { - var action_link = ActiveScaffold.find_action_link($(this)); - if (action_link) { - ActiveScaffold.report_500_response(action_link.scaffold_id()); - } - return true; - }); - $('a.as_sort').live('ajax:before', function(event) { - var as_sort = $(this); - var history_controller_id = as_sort.attr('data-page-history'); - if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.attr('href'), history_controller_id); - as_sort.closest('th').addClass('loading'); - return true; - }); - $('a.as_sort').live('ajax:failure', function(event) { - var as_scaffold = $(this).closest('.active-scaffold'); - ActiveScaffold.report_500_response(as_scaffold); - return true; - }); - $('span.in_place_editor_field').live('hover', function(event) { - $(this).data(); // jquery 1.4.2 workaround - if (event.type == 'mouseenter') { - if (typeof($(this).data('editInPlace')) === 'undefined') $(this).addClass("hover"); - } - if (event.type == 'mouseleave') { - if (typeof($(this).data('editInPlace')) === 'undefined') $(this).removeClass("hover"); - } - return true; - }); - $('span.in_place_editor_field').live('click', function(event) { - ActiveScaffold.in_place_editor_field_clicked($(this)); - }); - $('a.as_paginate').live('ajax:before',function(event) { - var as_paginate = $(this); - var history_controller_id = as_paginate.attr('data-page-history'); - if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.attr('href'), history_controller_id); - as_paginate.prevAll('img.loading-indicator').css('visibility','visible'); - return true; - }); - $('a.as_paginate').live('ajax:failure', function(event) { - var as_scaffold = $(this).closest('.active-scaffold'); - ActiveScaffold.report_500_response(as_scaffold); - return true; - }); - $('a.as_paginate').live('ajax:complete', function(event) { - $(this).prevAll('img.loading-indicator').css('visibility','hidden'); - return true; - }); - $('input[type=button].as_add_existing').live('ajax:before', function(event) { - var url = $(this).attr('href').replace('--ID--', $(this).prev().val()); - event.data_url = url; - return true; - }); - $('input.update_form, select.update_form').live('change', function(event) { - var element = $(this); - var as_form = element.closest('form.as_form'); - var params = null; - - if (element.attr('data-update_send_form')) { - params = as_form.serialize(); - params += '&' + $.param({source_id: element.attr('id')}); - } else { - if (element.is("input:checkbox")) { - params = {value: element.is(":checked")}; - } else { - params = {value: element.val()}; - } - params.source_id = element.attr('id'); - } - - $.ajax({ - url: element.attr('data-update_url'), - data: params, - beforeSend: function(event) { - element.nextAll('img.loading-indicator').css('visibility','visible'); - ActiveScaffold.disable_form(as_form) - }, - complete: function(event) { - element.nextAll('img.loading-indicator').css('visibility','hidden'); - ActiveScaffold.enable_form(as_form) - }, - error: function (xhr, status, error) { - var as_div = element.closest("div.active-scaffold"); - if (as_div) { - ActiveScaffold.report_500_response(as_div) - } - } - }); - return true; - }); - - $('select.as_search_range_option').live('change', function(event) { - ActiveScaffold[$(this).val() == 'BETWEEN' ? 'show' : 'hide']($(this).parent().find('.as_search_range_between')); - return true; - }); - - $('select.as_search_range_option').live('change', function(event) { - var element = $(this); - ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric')); - ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend')); - ActiveScaffold[(element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_range')); - return true; - }); - - $('select.as_update_date_operator').live('change', function(event) { - ActiveScaffold[$(this).val() == 'REPLACE' ? 'show' : 'hide']($(this).next()); - ActiveScaffold[$(this).val() == 'REPLACE' ? 'hide' : 'show']($(this).next().next()); - return true; - }); - - $('a[data-popup]').live('click', function(e) { - window.open($(this).attr('href')); - e.preventDefault(); - }); - - $('.hover_click').live("click", function(event) { - var element = $(this); - var ul_element = element.children('ul').first(); - if (ul_element.is(':visible')) { - element.find('ul').hide(); - } else { - ul_element.show(); - } - return false; - }); - $('.hover_click a.as_action').live('click', function(event) { - var element = $(this).closest('.hover_click'); - if (element) { - element.find('ul').hide(); - } - return true; - }); -}); - -/* Simple Inheritance - http://ejohn.org/blog/simple-javascript-inheritance/ -*/ -(function(){ - var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; - - // The base Class implementation (does nothing) - this.Class = function(){}; - - // Create a new Class that inherits from this class - Class.extend = function(prop) { - var _super = this.prototype; - - // Instantiate a base class (but only create the instance, - // don't run the init constructor) - initializing = true; - var prototype = new this(); - initializing = false; - - // Copy the properties over onto the new prototype - for (var name in prop) { - // Check if we're overwriting an existing function - prototype[name] = typeof prop[name] == "function" && - typeof _super[name] == "function" && fnTest.test(prop[name]) ? - (function(name, fn){ - return function() { - var tmp = this._super; - - // Add a new ._super() method that is the same method - // but on the super-class - this._super = _super[name]; - - // The method only need to be bound temporarily, so we - // remove it when we're done executing - var ret = fn.apply(this, arguments); - this._super = tmp; - - return ret; - }; - })(name, prop[name]) : - prop[name]; - } - - // The dummy class constructor - function Class() { - // All construction is actually done in the init method - if ( !initializing && this.init ) - this.init.apply(this, arguments); - } - - // Populate our constructed prototype object - Class.prototype = prototype; - - // Enforce the constructor to be what we expect - Class.constructor = Class; - - // And make this class extendable - Class.extend = arguments.callee; - - return Class; - }; -})(); - -/* - jQuery delayed observer - (c) 2007 - Maxime Haineault (max@centdessin.com) - - Special thanks to Stephen Goguen & Tane Piper. - - Slight modifications by Elliot Winkler -*/ - -if (typeof(jQuery.fn.delayedObserver) === 'undefined') { - (function() { - var delayedObserverStack = []; - var observed; - - function delayedObserverCallback(stackPos) { - observed = delayedObserverStack[stackPos]; - if (observed.timer) return; - - observed.timer = setTimeout(function(){ - observed.timer = null; - observed.callback(observed.obj.val(), observed.obj); - }, observed.delay * 1000); - - observed.oldVal = observed.obj.val(); - } - - // going by - // <http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx> - // I think these codes only work when using keyup or keydown - function isNonPrintableKey(event) { - var code = event.keyCode; - return ( - event.metaKey || - (code >= 9 && code <= 16) || (code >= 27 && code <= 40) || (code >= 91 && code <= 93) || (code >= 112 && code <= 145) - ); - } - - jQuery.fn.extend({ - delayedObserver:function(delay, callback){ - $this = $(this); - - delayedObserverStack.push({ - obj: $this, timer: null, delay: delay, - oldVal: $this.val(), callback: callback - }); - - stackPos = delayedObserverStack.length-1; - - $this.keyup(function(event) { - if (isNonPrintableKey(event)) return; - observed = delayedObserverStack[stackPos]; - if (observed.obj.val() == observed.obj.oldVal) return; - else delayedObserverCallback(stackPos); - }); - } - }); - })(); -}; - - -/* - * Simple utility methods - */ - -var ActiveScaffold = { - records_for: function(tbody_id) { - if (typeof(tbody_id) == 'string') tbody_id = '#' + tbody_id; - return $(tbody_id).children('.record'); - }, - stripe: function(tbody_id) { - var even = false; - var rows = this.records_for(tbody_id); - - rows.each(function (index, row_node) { - row = $(row_node); - if (row_node.tagName != 'SCRIPT' - && !row.hasClass("create") - && !row.hasClass("update") - && !row.hasClass("inline-adapter") - && !row.hasClass("active-scaffold-calculations")) { - - if (even) row.addClass("even-record"); - else row.removeClass("even-record"); - - even = !even; - } - }); - }, - hide_empty_message: function(tbody) { - if (this.records_for(tbody).length != 0) { - var empty_message_node = $(tbody).parent().find('tbody.messages p.empty-message') - if (empty_message_node) empty_message_node.hide(); - } - }, - reload_if_empty: function(tbody, url) { - if (this.records_for(tbody).length == 0) { - $.getScript(url); - } - }, - removeSortClasses: function(scaffold) { - if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; - scaffold = $(scaffold) - scaffold.find('td.sorted').each(function(element) { - element.removeClass("sorted"); - }); - scaffold.find('th.sorted').each(function(element) { - element.removeClass("sorted"); - element.removeClass("asc"); - element.removeClass("desc"); - }); - }, - decrement_record_count: function(scaffold) { - // decrement the last record count, firsts record count are in nested lists - if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; - scaffold = $(scaffold) - count = scaffold.find('span.active-scaffold-records').last(); - if (count) count.html(parseInt(count.html(), 10) - 1); - }, - increment_record_count: function(scaffold) { - // increment the last record count, firsts record count are in nested lists - if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; - scaffold = $(scaffold) - count = scaffold.find('span.active-scaffold-records').last(); - if (count) count.html(parseInt(count.html(), 10) + 1); - }, - update_row: function(row, html) { - var even_row = false; - var replaced = null; - if (typeof(row) == 'string') row = '#' + row; - row = $(row); - if (row.hasClass('even-record')) even_row = true; - - replaced = this.replace(row, html); - if (even_row === true) replaced.addClass('even-record'); - ActiveScaffold.highlight(replaced); - }, - - replace: function(element, html) { - if (typeof(element) == 'string') element = '#' + element; - element = $(element); - element.replaceWith(html); - if (element.attr('id')) { - element = $('#' + element.attr('id')); - } - return element; - }, - - replace_html: function(element, html) { - if (typeof(element) == 'string') element = '#' + element; - element = $(element); - element.html(html); - return element; - }, - - remove: function(element) { - if (typeof(element) == 'string') element = '#' + element; - $(element).remove(); - }, - - hide: function(element) { - if (typeof(element) == 'string') element = '#' + element; - $(element).hide(); - }, - - show: function(element) { - if (typeof(element) == 'string') element = '#' + element; - $(element).show(); - }, - - reset_form: function(element) { - if (typeof(element) == 'string') element = '#' + element; - $(element).get(0).reset(); - }, - - disable_form: function(as_form) { - if (typeof(as_form) == 'string') as_form = '#' + as_form; - as_form = $(as_form) - var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); - if (loading_indicator) loading_indicator.css('visibility','visible'); - $('input[type=submit]', as_form).attr('disabled', 'disabled'); - $("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled'); - }, - - enable_form: function(as_form) { - if (typeof(as_form) == 'string') as_form = '#' + as_form; - as_form = $(as_form) - var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); - if (loading_indicator) loading_indicator.css('visibility','hidden'); - $('input[type=submit]', as_form).attr('disabled', ''); - $("input:disabled,select:disabled,textarea:disabled", as_form).attr('disabled', ''); - }, - - focus_first_element_of_form: function(form_element) { - if (typeof(form_element) == 'string') form_element = '#' + form_element; - $(form_element + ":first *:input[type!=hidden]:first").focus(); - }, - - create_record_row: function(active_scaffold_id, html, options) { - if (typeof(active_scaffold_id) == 'string') active_scaffold_id = '#' + active_scaffold_id; - tbody = $(active_scaffold_id).find('tbody.records'); - - if (options.insert_at == 'top') { - tbody.prepend(html); - var new_row = tbody.children('tr.record:first-child'); - } else if (options.insert_at == 'bottom') { - var rows = tbody.children('tr.record, tr.inline-adapter'); - var new_row = null; - if (rows.length > 0) { - new_row = rows.last().after(html).next(); - } else { - new_row = tbody.append(html).children().last(); - } - } - this.stripe(tbody); - this.hide_empty_message(tbody); - this.increment_record_count(tbody.closest('div.active-scaffold')); - ActiveScaffold.highlight(new_row); - }, - - delete_record_row: function(row, page_reload_url) { - if (typeof(row) == 'string') row = '#' + row; - row = $(row); - var tbody = row.closest('tbody.records'); - - var current_action_node = row.find('td.actions a.disabled').first(); - if (current_action_node) { - var action_link = ActiveScaffold.ActionLink.get(current_action_node); - if (action_link) { - action_link.close_previous_adapter(); - } - } - - row.remove(); - this.stripe(tbody); - this.decrement_record_count(tbody.closest('div.active-scaffold')); - this.reload_if_empty(tbody, page_reload_url); - }, - - delete_subform_record: function(record) { - if (typeof(record) == 'string') record = '#' + record; - record = $(record); - var errors = record.prev(); - if (errors.hasClass('association-record-errors')) { - this.replace_html(errors, ''); - } - this.remove(record); - }, - - report_500_response: function(active_scaffold_id) { - server_error = $(active_scaffold_id).find('td.messages-container p.server-error'); - if (!$(server_error).is(':visible')) { - server_error.show(); - } - }, - - find_action_link: function(element) { - if (typeof(element) == 'string') element = '#' + element; - var as_adapter = $(element).closest('.as_adapter'); - return ActiveScaffold.ActionLink.get(as_adapter); - }, - - scroll_to: function(element) { - if (typeof(element) == 'string') element = '#' + element; - var form_offset = $(element).offset(), - destination = form_offset.top; - $(document).scrollTop(destination); - }, - - process_checkbox_inplace_edit: function(checkbox, options) { - var checked = checkbox.is(':checked'); - if (checked === true) options['params'] += '&value=1'; - $.ajax({ - url: options.url, - type: "POST", - data: options['params'], - dataType: options.ajax_data_type, - after: function(request){ - checkbox.attr('disabled', 'disabled'); - }, - complete: function(request){ - checkbox.attr('disabled', ''); - } - }); - }, - - read_inplace_edit_heading_attributes: function(column_heading, options) { - if (column_heading.attr('data-ie_cancel_text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.attr('data-ie_cancel_text') + "</button>"; - if (column_heading.attr('data-ie_loading_text')) options.loading_text = column_heading.attr('data-ie_loading_text'); - if (column_heading.attr('data-ie_saving_text')) options.saving_text = column_heading.attr('data-ie_saving_text'); - if (column_heading.attr('data-ie_save_text')) options.save_button = '<button class="inplace_save">' + column_heading.attr('data-ie_save_text') + "</button>"; - if (column_heading.attr('data-ie_rows')) options.textarea_rows = column_heading.attr('data-ie_rows'); - if (column_heading.attr('data-ie_cols')) options.textarea_cols = column_heading.attr('data-ie_cols'); - if (column_heading.attr('data-ie_size')) options.text_size = column_heading.attr('data-ie_size'); - }, - - create_inplace_editor: function(span, options) { - span.removeClass('hover'); - span.editInPlace(options); - span.trigger('click.editInPlace'); - }, - - highlight: function(element) { - if (typeof(element) == 'string') element = $('#' + element); - if (typeof(element.effect) == 'function') { - element.effect("highlight", {}, 3000); - } - }, - - create_visibility_toggle: function(element, options) { - if (typeof(element) == 'string') element = '#' + element; - var toggable = $(element); - var toggler = toggable.prev(); - var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label; - - toggler.append(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)'); - toggler.children('a').click(function() { - toggable.toggle(); - $(this).html((toggable.is(':hidden')) ? options.show_label : options.hide_label); - return false; - }); - }, - - create_associated_record_form: function(element, content, options) { - if (typeof(element) == 'string') element = '#' + element; - var element = $(element); - if (options.singular == false) { - if (!(options.id && $('#' + options.id).size() > 0)) { - element.append(content); - } - } else { - var current = $('#' + element.attr('id') + ' tr.association-record') - if (current[0]) { - this.replace(current[0], content); - } else { - element.prepend(content); - } - } - }, - - render_form_field: function(source, content, options) { - if (typeof(source) == 'string') source = '#' + source; - var source = $(source); - var element = source.closest('.association-record'); - if (element.length == 0) { - element = source.closest('ol.form'); - } - element = element.find('.' + options.field_class); - - if (element) { - if (options.is_subform == false) { - this.replace(element.closest('dl'), content); - } else { - this.replace_html(element, content); - } - } - }, - - sortable: function(element, controller, options, url_params) { - if (typeof(element) == 'string') element = '#' + element; - var element = $(element); - var sortable_options = {}; - if (options.update === true) { - url_params.authenticity_token = $('meta[name=csrf-param]').attr('content'); - sortable_options.update = function(event, ui) { - var url = controller + '/' + options.action + '?' - url += $(this).sortable('serialize',{key: encodeURIComponent($(this).attr('id') + '[]'), expression:/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/}); - $.post(url.append_params(url_params)); - } - } - element.sortable(sortable_options); - }, - - record_select_onselect: function(edit_associated_url, active_scaffold_id, id){ - $.ajax({ - url: edit_associated_url.split('--ID--').join(id), - error: function(xhr, textStatus, errorThrown){ - ActiveScaffold.report_500_response(active_scaffold_id) - } - }); - }, - - // element is tbody id - mark_records: function(element, options) { - if (typeof(element) == 'string') element = '#' + element; - var element = $(element); - var mark_checkboxes = $('#' + element.attr('id') + ' > tr.record td.marked-column input[type="checkbox"]'); - mark_checkboxes.each(function (index) { - var item = $(this); - if(options.checked === true) { - item.attr('checked', 'checked'); - } else { - item.removeAttr('checked'); - } - item.attr('value', ('' + !options.checked)); - }); - if(options.include_mark_all === true) { - var mark_all_checkbox = element.prev('thead').find('th.marked-column_heading span input[type="checkbox"]'); - if(options.checked === true) { - mark_all_checkbox.attr('checked', 'checked'); - } else { - mark_all_checkbox.removeAttr('checked'); - } - mark_all_checkbox.attr('value', ('' + !options.checked)); - } - }, - - in_place_editor_field_clicked: function(span) { - span.data(); // jquery 1.4.2 workaround - if (typeof(span.data('editInPlace')) === 'undefined') { - var options = {show_buttons: true, - hover_class: 'hover', - element_id: 'editor_id', - ajax_data_type: "script", - update_value: 'value'}, - csrf_param = $('meta[name=csrf-param]').first(), - csrf_token = $('meta[name=csrf-token]').first(), - my_parent = span.parent(), - column_heading = null; - - if(!(my_parent.is('td') || my_parent.is('th'))){ - my_parent = span.parents('td').eq(0); - } - - if (my_parent.is('td')) { - var column_no = my_parent.prevAll('td').length; - column_heading = my_parent.closest('.active-scaffold').find('th:eq(' + column_no + ')'); - } else if (my_parent.is('th')) { - column_heading = my_parent; - } - - var render_url = column_heading.attr('data-ie_render_url'), - mode = column_heading.attr('data-ie_mode'), - record_id = span.attr('data-ie_id'); - - ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options); - - if (span.attr('data-ie_url')) { - options.url = span.attr('data-ie_url').replace(/__id__/, record_id); - } else { - options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id); - } - - if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content'); - - if (span.closest('div.active-scaffold').attr('data-eid')) { - if (options['params'].length > 0) { - options['params'] += "&"; - } - options['params'] += ("eid=" + span.closest('div.active-scaffold').attr('data-eid')); - } - - if (mode === 'clone') { - options.clone_id_suffix = record_id; - options.clone_selector = '#' + column_heading.attr('id') + ' .as_inplace_pattern'; - options.field_type = 'clone'; - } - - if (render_url) { - var plural = false; - if (column_heading.attr('data-ie_plural')) plural = true; - options.field_type = 'remote'; - options.editor_url = render_url.replace(/__id__/, record_id) - } - if (mode === 'inline_checkbox') { - ActiveScaffold.process_checkbox_inplace_edit(span.find('input:checkbox'), options); - } else { - ActiveScaffold.create_inplace_editor(span, options); - } - } - } -} - -/* - * DHTML history tie-in - */ -function addActiveScaffoldPageToHistory(url, active_scaffold_id) { - if (typeof dhtmlHistory == 'undefined') return; // it may not be loaded - - var array = url.split('?'); - var qs = new Querystring(array[1]); - var sort = qs.get('sort') - var dir = qs.get('sort_direction') - var page = qs.get('page') - if (sort || dir || page) dhtmlHistory.add(active_scaffold_id+":"+page+":"+sort+":"+dir, url); -} - -/* - * URL modification support. Incomplete functionality. - */ -String.prototype.append_params = function(params) { - var url = this; - if (url.indexOf('?') == -1) url += '?'; - else if (url.lastIndexOf('&') != url.length) url += '&'; - - for(var key in params) { - if (key) url += (key + '=' + params[key] + '&'); - } - - // the loop leaves a comma dangling at the end of string, chop it off - url = url.substring(0, url.length-1); - return url; -}; - - -/** - * A set of links. As a set, they can be controlled such that only one is "open" at a time, etc. - */ -ActiveScaffold.Actions = new Object(); -ActiveScaffold.Actions.Abstract = Class.extend({ - init: function(links, target, loading_indicator, options) { - this.target = $(target); - this.loading_indicator = $(loading_indicator); - this.options = options; - var _this = this; - this.links = $.map(links, function(link) { - var my_link = _this.instantiate_link(link); - return my_link; - }); - }, - - instantiate_link: function(link) { - throw 'unimplemented' - } -}); - -/** - * A DataStructures::ActionLink, represented in JavaScript. - * Concerned with AJAX-enabling a link and adapting the result for insertion into the table. - */ -ActiveScaffold.ActionLink = { - get: function(element) { - if (typeof(element) == 'string') element = '#' + element; - var element = $(element); - if (element.length > 0) { - element.data(); // jquery 1.4.2 workaround - if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) { - var parent = element.closest('.actions'); - if (parent.length === 0) { - // maybe an column action_link - parent = element.parent(); - } - if (parent && parent.is('td')) { - // record action - parent = parent.closest('tr.record'); - var target = parent.find('a.as_action'); - var loading_indicator = parent.find('td.actions .loading-indicator'); - new ActiveScaffold.Actions.Record(target, parent, loading_indicator); - } else if (parent && parent.is('div')) { - //table action - new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header'), parent.find('.loading-indicator')); - } - element = $(element); - } - return element.data('action_link'); - } else { - return null; - } - } -}; -ActiveScaffold.ActionLink.Abstract = Class.extend({ - init: function(a, target, loading_indicator) { - this.tag = $(a); - this.url = this.tag.attr('href'); - this.method = this.tag.attr('data-method') || 'get'; - this.target = target; - this.loading_indicator = loading_indicator; - this.hide_target = false; - this.position = this.tag.attr('data-position'); - - this.tag.data('action_link', this); - return this; - }, - - open: function(event) { - }, - - insert: function(content) { - throw 'unimplemented' - }, - - close: function() { - this.enable(); - this.adapter.remove(); - if (this.hide_target) this.target.show(); - }, - - reload: function() { - this.close(); - this.open(); - }, - - get_new_adapter_id: function() { - var id = 'adapter_'; - var i = 0; - while ($(id + i)) i++; - return id + i; - }, - - enable: function() { - return this.tag.removeClass('disabled'); - }, - - disable: function() { - return this.tag.addClass('disabled'); - }, - - is_disabled: function() { - return this.tag.hasClass('disabled'); - }, - - scaffold_id: function() { - return '#' + this.tag.closest('div.active-scaffold').attr('id'); - }, - - scaffold: function() { - return this.tag.closest('div.active-scaffold'); - }, - - update_flash_messages: function(messages) { - message_node = $(this.scaffold_id().replace(/-active-scaffold/, '-messages')); - if (message_node) message_node.html(messages); - }, - set_adapter: function(element) { - this.adapter = element; - this.adapter.addClass('as_adapter'); - this.adapter.data('action_link', this); - } -}); - -/** - * Concrete classes for record actions - */ -ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({ - instantiate_link: function(link) { - var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); - var refresh = this.target.attr('data-refresh'); - if (refresh) l.refresh_url = refresh; - - if (l.position) { - l.url = l.url.append_params({adapter: '_list_inline_adapter'}); - l.tag.attr('href', l.url); - } - l.set = this; - return l; - } -}); - -ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ - close_previous_adapter: function() { - var _this = this; - $.each(this.set.links, function(index, item) { - if (item.url != _this.url && item.is_disabled() && item.adapter) { - item.enable(); - item.adapter.remove(); - } - }); - }, - - insert: function(content) { - this.close_previous_adapter(); - - if (this.position == 'replace') { - this.position = 'after'; - this.hide_target = true; - } - - if (this.position == 'after') { - this.target.after(content); - this.set_adapter(this.target.next()); - } - else if (this.position == 'before') { - this.target.before(content); - this.set_adapter(this.target.prev()); - } - else { - return false; - } - ActiveScaffold.highlight(this.adapter.find('td')); - }, - - close: function(refreshed_content) { - if (refreshed_content) { - ActiveScaffold.update_row(this.target, refreshed_content); - } - this._super(); - }, - - enable: function() { - var _this = this; - $.each(this.set.links, function(index, item) { - if (item.url != _this.url) return; - item.tag.removeClass('disabled'); - }); - }, - - disable: function() { - var _this = this; - $.each(this.set.links, function(index, item) { - if (item.url != _this.url) return; - item.tag.addClass('disabled'); - }); - }, - - set_opened: function() { - if (this.position == 'after') { - this.set_adapter(this.target.next()); - } - else if (this.position == 'before') { - this.set_adapter(this.target.prev()); - } - this.disable(); - } -}); - -/** - * Concrete classes for table actions - */ -ActiveScaffold.Actions.Table = ActiveScaffold.Actions.Abstract.extend({ - instantiate_link: function(link) { - var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator); - if (l.position) { - l.url = l.url.append_params({adapter: '_list_inline_adapter'}); - l.tag.attr('href', l.url); - } - return l; - } -}); - -ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({ - insert: function(content) { - if (this.position == 'top') { - this.target.prepend(content); - this.set_adapter(this.target.children().first()); - } - else { - throw 'Unknown position "' + this.position + '"' - } - ActiveScaffold.highlight(this.adapter.find('td').first().children()); - } -}); diff --git a/frontends/default/javascripts/jquery/jquery.editinplace.js b/frontends/default/javascripts/jquery/jquery.editinplace.js deleted file mode 100644 index 9bc523a155..0000000000 --- a/frontends/default/javascripts/jquery/jquery.editinplace.js +++ /dev/null @@ -1,743 +0,0 @@ -/* - -A jQuery edit in place plugin - -Version 2.2.0 - -Authors: - Dave Hauenstein - Martin Häcker <spamfaenger [at] gmx [dot] de> - -Project home: - http://code.google.com/p/jquery-in-place-editor/ - -Patches with tests welcomed! For guidance see the tests at </spec/unit/spec.js>. To submit, attach them to the bug tracker. - -License: -This source file is subject to the BSD license bundled with this package. -Available online: {@link http://www.opensource.org/licenses/bsd-license.php} -If you did not receive a copy of the license, and are unable to obtain it, -learn to use a search engine. - -*/ - -(function($){ - -$.fn.editInPlace = function(options) { - - var settings = $.extend({}, $.fn.editInPlace.defaults, options); - - assertMandatorySettingsArePresent(settings); - - preloadImage(settings.saving_image); - - return this.each(function() { - var dom = $(this); - // This won't work with live queries as there is no specific element to attach this - // one way to deal with this could be to store a reference to self and then compare that in click? - if (dom.data('editInPlace')) - return; // already an editor here - dom.data('editInPlace', true); - - new InlineEditor(settings, dom).init(); - }); -}; - -/// Switch these through the dictionary argument to $(aSelector).editInPlace(overideOptions) -/// Required Options: Either url or callback, so the editor knows what to do with the edited values. -$.fn.editInPlace.defaults = { - url: "", // string: POST URL to send edited content - ajax_data_type: "html", // string: dataType (html|script) for ajax call to save updated value - bg_over: "#ffc", // string: background color of hover of unactivated editor - bg_out: "transparent", // string: background color on restore from hover - hover_class: "", // string: class added to root element during hover. Will override bg_over and bg_out - show_buttons: false, // boolean: will show the buttons: cancel or save; will automatically cancel out the onBlur functionality - save_button: '<button class="inplace_save">Save</button>', // string: image button tag to use as “Save” button - cancel_button: '<button class="inplace_cancel">Cancel</button>', // string: image button tag to use as “Cancel” button - params: "", // string: example: first_name=dave&last_name=hauenstein extra paramters sent via the post request to the server - field_type: "text", // string: "text", "textarea", or "select", or "remote", or "clone"; The type of form field that will appear on instantiation - default_text: "(Click here to add text)", // string: text to show up if the element that has this functionality is empty - use_html: false, // boolean, set to true if the editor should use jQuery.fn.html() to extract the value to show from the dom node - textarea_rows: 10, // integer: set rows attribute of textarea, if field_type is set to textarea. Use CSS if possible though - textarea_cols: 25, // integer: set cols attribute of textarea, if field_type is set to textarea. Use CSS if possible though - select_text: "Choose new value", // string: default text to show up in select box - select_options: "", // string or array: Used if field_type is set to 'select'. Can be comma delimited list of options 'textandValue,text:value', Array of options ['textAndValue', 'text:value'] or array of arrays ['textAndValue', ['text', 'value']]. The last form is especially usefull if your labels or values contain colons) - text_size: null, // integer: set cols attribute of text input, if field_type is set to text. Use CSS if possible though - editor_url: null, // for field_type: remote url to get html_code for edit_control - loading_text: 'Loading...', // shown if inplace editor is loaded from server - // Specifying callback_skip_dom_reset will disable all saving_* options - saving_text: undefined, // string: text to be used when server is saving information. Example "Saving..." - saving_image: "", // string: uses saving text specify an image location instead of text while server is saving - saving_animation_color: 'transparent', // hex color string, will be the color the pulsing animation during the save pulses to. Note: Only works if jquery-ui is loaded - clone_selector: null, // if field_type clone a selector to clone editor from - clone_id_suffix: null, // if field_type clone a suffix to create unique ids - - value_required: false, // boolean: if set to true, the element will not be saved unless a value is entered - element_id: "element_id", // string: name of parameter holding the id or the editable - update_value: "update_value", // string: name of parameter holding the updated/edited value - original_value: 'original_value', // string: name of parameter holding the updated/edited value - original_html: "original_html", // string: name of parameter holding original_html value of the editable /* DEPRECATED in 2.2.0 */ use original_value instead. - save_if_nothing_changed: false, // boolean: submit to function or server even if the user did not change anything - on_blur: "save", // string: "save" or null; what to do on blur; will be overridden if show_buttons is true - cancel: "", // string: if not empty, a jquery selector for elements that will not cause the editor to open even though they are clicked. E.g. if you have extra buttons inside editable fields - - // All callbacks will have this set to the DOM node of the editor that triggered the callback - - callback: null, // function: function to be called when editing is complete; cancels ajax submission to the url param. Prototype: function(idOfEditor, enteredText, orinalHTMLContent, settingsParams, callbacks). The function needs to return the value that should be shown in the dom. Returning undefined means cancel and will restore the dom and trigger an error. callbacks is a dictionary with two functions didStartSaving and didEndSaving() that you can use to tell the inline editor that it should start and stop any saving animations it has configured. /* DEPRECATED in 2.1.0 */ Parameter idOfEditor, use $(this).attr('id') instead - callback_skip_dom_reset: false, // boolean: set this to true if the callback should handle replacing the editor with the new value to show - success: null, // function: this function gets called if server responds with a success. Prototype: function(newEditorContentString) - error: null, // function: this function gets called if server responds with an error. Prototype: function(request) - error_sink: function(idOfEditor, errorString) { alert(errorString); }, // function: gets id of the editor and the error. Make sure the editor has an id, or it will just be undefined. If set to null, no error will be reported. /* DEPRECATED in 2.1.0 */ Parameter idOfEditor, use $(this).attr('id') instead - preinit: null, // function: this function gets called after a click on an editable element but before the editor opens. If you return false, the inline editor will not open. Prototype: function(currentDomNode). DEPRECATED in 2.2.0 use delegate shouldOpenEditInPlace call instead - postclose: null, // function: this function gets called after the inline editor has closed and all values are updated. Prototype: function(currentDomNode). DEPRECATED in 2.2.0 use delegate didCloseEditInPlace call instead - delegate: null // object: if it has methods with the name of the callbacks documented below in delegateExample these will be called. This means that you just need to impelment the callbacks you are interested in. -}; - -// Lifecycle events that the delegate can implement -// this will always be fixed to the delegate -var delegateExample = { - // called while opening the editor. - // return false to prevent editor from opening - shouldOpenEditInPlace: function(aDOMNode, aSettingsDict, triggeringEvent) {}, - // return content to show in inplace editor - willOpenEditInPlace: function(aDOMNode, aSettingsDict) {}, - didOpenEditInPlace: function(aDOMNode, aSettingsDict) {}, - - // called while closing the editor - // return false to prevent the editor from closing - shouldCloseEditInPlace: function(aDOMNode, aSettingsDict, triggeringEvent) {}, - // return value will be shown during saving - willCloseEditInPlace: function(aDOMNode, aSettingsDict) {}, - didCloseEditInPlace: function(aDOMNode, aSettingsDict) {}, - - missingCommaErrorPreventer:'' -}; - - -function InlineEditor(settings, dom) { - this.settings = settings; - this.dom = dom; - this.originalValue = null; - this.didInsertDefaultText = false; - this.shouldDelayReinit = false; -}; - -$.extend(InlineEditor.prototype, { - - init: function() { - this.setDefaultTextIfNeccessary(); - this.connectOpeningEvents(); - }, - - reinit: function() { - if (this.shouldDelayReinit) - return; - - this.triggerCallback(this.settings.postclose, /* DEPRECATED in 2.1.0 */ this.dom); - this.triggerDelegateCall('didCloseEditInPlace'); - - this.markEditorAsInactive(); - this.connectOpeningEvents(); - }, - - setDefaultTextIfNeccessary: function() { - if('' !== this.dom.html()) - return; - - this.dom.html(this.settings.default_text); - this.didInsertDefaultText = true; - }, - - connectOpeningEvents: function() { - var that = this; - this.dom - .bind('mouseenter.editInPlace', function(){ that.addHoverEffect(); }) - .bind('mouseleave.editInPlace', function(){ that.removeHoverEffect(); }) - .bind('click.editInPlace', function(anEvent){ that.openEditor(anEvent); }); - }, - - disconnectOpeningEvents: function() { - // prevent re-opening the editor when it is already open - this.dom.unbind('.editInPlace'); - }, - - addHoverEffect: function() { - if (this.settings.hover_class) - this.dom.addClass(this.settings.hover_class); - else - this.dom.css("background-color", this.settings.bg_over); - }, - - removeHoverEffect: function() { - if (this.settings.hover_class) - this.dom.removeClass(this.settings.hover_class); - else - this.dom.css("background-color", this.settings.bg_out); - }, - - openEditor: function(anEvent) { - if ( ! this.shouldOpenEditor(anEvent)) - return; - - this.workAroundFirefoxBlurBug(); - this.disconnectOpeningEvents(); - this.removeHoverEffect(); - this.removeInsertedDefaultTextIfNeccessary(); - this.saveOriginalValue(); - this.markEditorAsActive(); - this.replaceContentWithEditor(); - this.connectOpeningEventsToEditor(); - this.triggerDelegateCall('didOpenEditInPlace'); - }, - - shouldOpenEditor: function(anEvent) { - if (this.isClickedObjectCancelled(anEvent.target)) - return false; - - if (false === this.triggerCallback(this.settings.preinit, /* DEPRECATED in 2.1.0 */ this.dom)) - return false; - - if (false === this.triggerDelegateCall('shouldOpenEditInPlace', true, anEvent)) - return false; - - return true; - }, - - removeInsertedDefaultTextIfNeccessary: function() { - if ( ! this.didInsertDefaultText - || this.dom.html() !== this.settings.default_text) - return; - - this.dom.html(''); - this.didInsertDefaultText = false; - }, - - isClickedObjectCancelled: function(eventTarget) { - if ( ! this.settings.cancel) - return false; - - var eventTargetAndParents = $(eventTarget).parents().andSelf(); - var elementsMatchingCancelSelector = eventTargetAndParents.filter(this.settings.cancel); - return 0 !== elementsMatchingCancelSelector.length; - }, - - saveOriginalValue: function() { - if (this.settings.use_html) - this.originalValue = this.dom.html(); - else - this.originalValue = trim(this.dom.text()); - }, - - restoreOriginalValue: function() { - this.setClosedEditorContent(this.originalValue); - }, - - setClosedEditorContent: function(aValue) { - if (this.settings.use_html) - this.dom.html(aValue); - else - this.dom.text(aValue); - }, - - workAroundFirefoxBlurBug: function() { - if ( ! $.browser.mozilla) - return; - - // TODO: Opera seems to also have this bug.... - - // Firefox will forget to send a blur event to an input element when another one is - // created and selected programmatically. This means that if another inline editor is - // opened, existing inline editors will _not_ close if they are configured to submit when blurred. - // This is actually the first time I've written browser specific code for a browser different than IE! Wohoo! - - // Using parents() instead document as base to workaround the fact that in the unittests - // the editor is not a child of window.document but of a document fragment - this.dom.parents(':last').find('.editInPlace-active :input').blur(); - }, - - replaceContentWithEditor: function() { - var buttons_html = (this.settings.show_buttons) ? this.settings.save_button + ' ' + this.settings.cancel_button : ''; - var editorElement = this.createEditorElement(); // needs to happen before anything is replaced - /* insert the new in place form after the element they click, then empty out the original element */ - this.dom.html('<form class="inplace_form" style="display: inline; margin: 0; padding: 0;"></form>') - .find('form') - .append(editorElement) - .append(buttons_html); - }, - - createEditorElement: function() { - if (-1 === $.inArray(this.settings.field_type, ['text', 'textarea', 'select', 'remote', 'clone'])) - throw "Unknown field_type <fnord>, supported are 'text', 'textarea', 'select' and 'remote'"; - - var editor = null; - if ("select" === this.settings.field_type) - editor = this.createSelectEditor(); - else if ("text" === this.settings.field_type) - editor = $('<input type="text" ' + this.inputNameAndClass() - + ' size="' + this.settings.text_size + '" />'); - else if ("textarea" === this.settings.field_type) - editor = $('<textarea ' + this.inputNameAndClass() - + ' rows="' + this.settings.textarea_rows + '" ' - + ' cols="' + this.settings.textarea_cols + '" />'); - else if ("remote" === this.settings.field_type) - editor = this.createRemoteGeneratedEditor(); - else if ("clone" === this.settings.field_type) { - editor = this.cloneEditor(); - return editor; - } - editor.val(this.triggerDelegateCall('willOpenEditInPlace', this.originalValue)); - return editor; - }, - - createRemoteGeneratedEditor: function () { - this.dom.html(this.settings.loading_text); - return $($.ajax({ - url: this.settings.editor_url, - async: false - }).responseText); - }, - - cloneEditor: function() { - var patternNodes = this.getPatternNodes(this.settings.clone_selector); - if (patternNodes.editNode == null) { - alert('did not find any matching node for ' + this.settings.clone_selector); - return; - } - - var editorNode = patternNodes.editNode.clone(); - var clonedNodes = null; - if (editorNode.attr('id').length > 0) editorNode.attr('id', editorNode.attr('id') + this.settings.clone_id_suffix); - editorNode.attr('name', 'inplace_value'); - editorNode.addClass('editor_field'); - this.setValue(editorNode, this.originalValue); - clonedNodes = editorNode; - - if (patternNodes.additionalNodes) { - patternNodes.additionalNodes.each(function (index, node) { - var patternNode = $(node).clone(); - if (patternNode.attr('id').length > 0) { - patternNode.attr('id', patternNode.attr('id') + this.settings.clone_id_suffix); - } - clonedNodes = clonedNodes.after(patternNode); - }); - } - return clonedNodes; - }, - - getPatternNodes: function(clone_selector) { - var nodes = {editNode: null, additionalNodes: null}; - var selectedNodes = $(clone_selector); - var firstNode = selectedNodes.first(); - - if (typeof(firstNode) !== 'undefined') { - // AS inplace_edit_control_container -> we have to select all child nodes - // Workaround for ie which does not support css > selector - if (firstNode.hasClass('as_inplace_pattern')) { - selectedNodes = firstNode.children(); - } - nodes.editNode = selectedNodes.first(); - // buggy... - //nodes.additionalNodes = selectedNodes.find(':gt(0)'); - } - return nodes; - }, - - setValue: function(editField, textValue) { - var function_name = 'setValueFor' + editField.get(0).nodeName.toLowerCase(); - if (typeof(this[function_name]) == 'function') { - this[function_name](editField, textValue); - } else { - editField.val(textValue); - } - }, - - setValueForselect: function(editField, textValue) { - var option_value = editField.children("option:contains('" + textValue + "')").val(); - - if (typeof(option_value) !== 'undefined') { - editField.val(option_value); - } - }, - - inputNameAndClass: function() { - return ' name="inplace_value" class="inplace_field" '; - }, - - createSelectEditor: function() { - var editor = $('<select' + this.inputNameAndClass() + '>' - + '<option disabled="true" value="">' + this.settings.select_text + '</option>' - + '</select>'); - - var optionsArray = this.settings.select_options; - if ( ! $.isArray(optionsArray)) - optionsArray = optionsArray.split(','); - - for (var i=0; i<optionsArray.length; i++) { - - var currentTextAndValue = optionsArray[i]; - if ( ! $.isArray(currentTextAndValue)) - currentTextAndValue = currentTextAndValue.split(':'); - - var value = trim(currentTextAndValue[1] || currentTextAndValue[0]); - var text = trim(currentTextAndValue[0]); - - var selected = (value == this.originalValue) ? 'selected="selected" ' : ''; - var option = $('<option ' + selected + ' ></option>').val(value).text(text); - editor.append(option); - } - return editor; - - }, - - // REFACT: rename opening is not what it's about. Its about closing events really - connectOpeningEventsToEditor: function() { - var that = this; - function cancelEditorAction(anEvent) { - that.handleCancelEditor(anEvent); - return false; // stop event bubbling - } - function saveEditorAction(anEvent) { - that.handleSaveEditor(anEvent); - return false; // stop event bubbling - } - - var form = this.dom.find("form"); - - form.find(".inplace_field").focus().select(); - form.find(".inplace_cancel").click(cancelEditorAction); - form.find(".inplace_save").click(saveEditorAction); - - if ( ! this.settings.show_buttons) { - // TODO: Firefox has a bug where blur is not reliably called when focus is lost - // (for example by another editor appearing) - if ("save" === this.settings.on_blur) - form.find(".inplace_field").blur(saveEditorAction); - else - form.find(".inplace_field").blur(cancelEditorAction); - - // workaround for firefox bug where it won't submit on enter if no button is shown - if ($.browser.mozilla) - this.bindSubmitOnEnterInInput(); - } - - form.keyup(function(anEvent) { - // allow canceling with escape - var escape = 27; - if (escape === anEvent.which) - return cancelEditorAction(); - }); - - // workaround for webkit nightlies where they won't submit at all on enter - // REFACT: find a way to just target the nightlies - if ($.browser.safari) - this.bindSubmitOnEnterInInput(); - - - form.submit(saveEditorAction); - }, - - bindSubmitOnEnterInInput: function() { - if ('textarea' === this.settings.field_type) - return; // can't enter newlines otherwise - - var that = this; - this.dom.find(':input').keyup(function(event) { - var enter = 13; - if (enter === event.which) - return that.dom.find('form').submit(); - }); - - }, - - handleCancelEditor: function(anEvent) { - // REFACT: remove duplication between save and cancel - if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent)) - return; - - var editor = this.dom.find(':input'); - - var enteredText = editor.val(); - enteredText = this.triggerDelegateCall('willCloseEditInPlace', enteredText); - - this.restoreOriginalValue(); - if (hasContent(enteredText) - && ! this.isDisabledDefaultSelectChoice() && !editor.is('select')) - this.setClosedEditorContent(enteredText); - this.reinit(); - }, - - handleSaveEditor: function(anEvent) { - if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent)) - return; - - var editor = this.dom.find(':input:not(:button)'); - var enteredText = ''; - if (editor.length > 1) { - enteredText = jQuery.map(editor.not('input:checkbox:not(:checked)'), function(item, index) { - return $(item).val(); - }); - } else { - enteredText = editor.val(); - } - enteredText = this.triggerDelegateCall('willCloseEditInPlace', enteredText); - - if (this.isDisabledDefaultSelectChoice() - || this.isUnchangedInput(enteredText)) { - this.handleCancelEditor(anEvent); - return; - } - - if (this.didForgetRequiredText(enteredText)) { - this.handleCancelEditor(anEvent); - this.reportError("Error: You must enter a value to save this field"); - return; - } - - this.showSaving(enteredText); - - if (this.settings.callback) - this.handleSubmitToCallback(enteredText); - else - this.handleSubmitToServer(enteredText); - }, - - didForgetRequiredText: function(enteredText) { - return this.settings.value_required - && ("" === enteredText - || undefined === enteredText - || null === enteredText); - }, - - isDisabledDefaultSelectChoice: function() { - return this.dom.find('option').eq(0).is(':selected:disabled'); - }, - - isUnchangedInput: function(enteredText) { - return ! this.settings.save_if_nothing_changed - && this.originalValue === enteredText; - }, - - showSaving: function(enteredText) { - if (this.settings.callback && this.settings.callback_skip_dom_reset) - return; - - var savingMessage = enteredText; - if (hasContent(this.settings.saving_text)) - savingMessage = this.settings.saving_text; - if(hasContent(this.settings.saving_image)) - // REFACT: alt should be the configured saving message - savingMessage = $('<img />').attr('src', this.settings.saving_image).attr('alt', savingMessage); - this.dom.html(savingMessage); - }, - - handleSubmitToCallback: function(enteredText) { - // REFACT: consider to encode enteredText and originalHTML before giving it to the callback - this.enableOrDisableAnimationCallbacks(true, false); - var newHTML = this.triggerCallback(this.settings.callback, /* DEPRECATED in 2.1.0 */ this.id(), enteredText, this.originalValue, - this.settings.params, this.savingAnimationCallbacks()); - - if (this.settings.callback_skip_dom_reset) - ; // do nothing - else if (undefined === newHTML) { - // failure; put original back - this.reportError("Error: Failed to save value: " + enteredText); - this.restoreOriginalValue(); - } - else - // REFACT: use setClosedEditorContent - this.dom.html(newHTML); - - if (this.didCallNoCallbacks()) { - this.enableOrDisableAnimationCallbacks(false, false); - this.reinit(); - } - }, - - handleSubmitToServer: function(enteredText) { - var data = ''; - if (typeof(enteredText) === 'string') { - data += this.settings.update_value + '=' + encodeURIComponent(enteredText) + '&'; - } else { - for(var i = 0;i < enteredText.length; i++) { - data += this.settings.update_value + '[]=' + encodeURIComponent(enteredText[i]) + '&'; - } - } - - data += this.settings.element_id + '=' + this.dom.attr("id") - + ((this.settings.params) ? '&' + this.settings.params : '') - + '&' + this.settings.original_html + '=' + encodeURIComponent(this.originalValue) /* DEPRECATED in 2.2.0 */ - + '&' + this.settings.original_value + '=' + encodeURIComponent(this.originalValue); - - this.enableOrDisableAnimationCallbacks(true, false); - this.didStartSaving(); - var that = this; - $.ajax({ - url: that.settings.url, - type: "POST", - data: data, - dataType: that.settings.ajax_data_type, - complete: function(request){ - that.didEndSaving(); - }, - success: function(data){ - if (that.settings.ajax_data_type == 'html') { - var new_text = data || that.settings.default_text; - - /* put the newly updated info into the original element */ - // FIXME: should be affected by the preferences switch - that.dom.html(new_text); - // REFACT: remove dom parameter, already in this, not documented, should be easy to remove - // REFACT: callback should be able to override what gets put into the DOM - } - that.triggerCallback(that.settings.success,data); - }, - error: function(request) { - that.dom.html(that.originalHTML); // REFACT: what about a restorePreEditingContent() - if (that.settings.error) - // REFACT: remove dom parameter, already in this, not documented, can remove without deprecation - // REFACT: callback should be able to override what gets entered into the DOM - that.triggerCallback(that.settings.error, request); - else - that.reportError("Failed to save value: " + request.responseText || 'Unspecified Error'); - } - }); - }, - - // Utilities ......................................................... - - triggerCallback: function(aCallback /*, arguments */) { - if ( ! aCallback) - return; // callback wasn't specified after all - - var callbackArguments = Array.prototype.splice.call(arguments, 1); - return aCallback.apply(this.dom[0], callbackArguments); - }, - - /// defaultReturnValue is only used if the delegate returns undefined - triggerDelegateCall: function(aDelegateMethodName, defaultReturnValue, optionalEvent) { - // REFACT: consider to trigger equivalent callbacks automatically via a mapping table? - if ( ! this.settings.delegate - || ! $.isFunction(this.settings.delegate[aDelegateMethodName])) - return defaultReturnValue; - - var delegateReturnValue = this.settings.delegate[aDelegateMethodName](this.dom, this.settings, optionalEvent); - return (undefined === delegateReturnValue) - ? defaultReturnValue - : delegateReturnValue; - }, - - reportError: function(anErrorString) { - this.triggerCallback(this.settings.error_sink, /* DEPRECATED in 2.1.0 */ this.id(), anErrorString); - }, - - // REFACT: this method should go, callbacks should get the dom node itself as an argument - id: function() { - return this.dom.attr('id'); - }, - - markEditorAsActive: function() { - this.dom.addClass('editInPlace-active'); - }, - - markEditorAsInactive: function() { - this.dom.removeClass('editInPlace-active'); - }, - - // REFACT: consider rename, doesn't deal with animation directly - savingAnimationCallbacks: function() { - var that = this; - return { - didStartSaving: function() { that.didStartSaving(); }, - didEndSaving: function() { that.didEndSaving(); } - }; - }, - - enableOrDisableAnimationCallbacks: function(shouldEnableStart, shouldEnableEnd) { - this.didStartSaving.enabled = shouldEnableStart; - this.didEndSaving.enabled = shouldEnableEnd; - }, - - didCallNoCallbacks: function() { - return this.didStartSaving.enabled && ! this.didEndSaving.enabled; - }, - - assertCanCall: function(methodName) { - if ( ! this[methodName].enabled) - throw new Error('Cannot call ' + methodName + ' now. See documentation for details.'); - }, - - didStartSaving: function() { - this.assertCanCall('didStartSaving'); - this.shouldDelayReinit = true; - this.enableOrDisableAnimationCallbacks(false, true); - - this.startSavingAnimation(); - }, - - didEndSaving: function() { - this.assertCanCall('didEndSaving'); - this.shouldDelayReinit = false; - this.enableOrDisableAnimationCallbacks(false, false); - this.reinit(); - - this.stopSavingAnimation(); - }, - - startSavingAnimation: function() { - var that = this; - this.dom - .animate({ backgroundColor: this.settings.saving_animation_color }, 400) - .animate({ backgroundColor: 'transparent'}, 400, 'swing', function(){ - // In the tests animations are turned off - i.e they happen instantaneously. - // Hence we need to prevent this from becomming an unbounded recursion. - setTimeout(function(){ that.startSavingAnimation(); }, 10); - }); - }, - - stopSavingAnimation: function() { - this.dom - .stop(true) - .css({backgroundColor: ''}); - }, - - missingCommaErrorPreventer:'' -}); - - - -// Private helpers ....................................................... - -function assertMandatorySettingsArePresent(options) { - // one of these needs to be non falsy - if (options.url || options.callback) - return; - - throw new Error("Need to set either url: or callback: option for the inline editor to work."); -} - -/* preload the loading icon if it is configured */ -function preloadImage(anImageURL) { - if ('' === anImageURL) - return; - - var loading_image = new Image(); - loading_image.src = anImageURL; -} - -function trim(aString) { - return aString - .replace(/^\s+/, '') - .replace(/\s+$/, ''); -} - -function hasContent(something) { - if (undefined === something || null === something) - return false; - - if (0 === something.length) - return false; - - return true; -} - -})(jQuery); diff --git a/frontends/default/javascripts/prototype/active_scaffold.js b/frontends/default/javascripts/prototype/active_scaffold.js deleted file mode 100644 index e19b77c5d8..0000000000 --- a/frontends/default/javascripts/prototype/active_scaffold.js +++ /dev/null @@ -1,1028 +0,0 @@ -if (typeof Prototype == 'undefined') -{ - warning = "ActiveScaffold Error: Prototype could not be found. Please make sure that your application's layout includes prototype.js (e.g. <%= javascript_include_tag :defaults %>) *before* it includes active_scaffold.js (e.g. <%= active_scaffold_includes %>)."; - alert(warning); -} -if (Prototype.Version.substring(0, 3) < '1.6') -{ - warning = "ActiveScaffold Error: Prototype version 1.6.x or higher is required. Please update prototype.js (rake rails:update:javascripts)."; - alert(warning); -} -if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFunction}); - - -document.observe("dom:loaded", function() { - document.on('ajax:create', 'form.as_form', function(event) { - var source = event.findElement(); - var as_form = event.findElement('form'); - if (source.nodeName.toUpperCase() == 'INPUT' && source.readAttribute('type') == 'button') { - // Hack: Prototype or rails.js somehow screw up event handling if someone clicks - // a button of type button such as Create Another <Association> - // as a result form is disabled but never reenabled.. - } else { - if (as_form && as_form.readAttribute('data-loading') == 'true') { - ActiveScaffold.disable_form(as_form); - } - } - return true; - }); - document.on('ajax:complete', 'form.as_form', function(event) { - var as_form = event.findElement('form'); - if (as_form && as_form.readAttribute('data-loading') == 'true') { - ActiveScaffold.enable_form(as_form); - event.stop(); - return false; - } - }); - document.on('ajax:failure', 'form.as_form', function(event) { - var as_div = event.findElement('div.active-scaffold'); - if (as_div) { - ActiveScaffold.report_500_response(as_div) - event.stop(); - return false; - } - }); - document.on('submit', 'form.as_form.as_remote_upload', function(event) { - var as_form = event.findElement('form'); - if (as_form && as_form.readAttribute('data-loading') == 'true') { - setTimeout("ActiveScaffold.disable_form('" + as_form.readAttribute('id') + "')", 10); - } - return true; - }); - document.on('ajax:before', 'a.as_action', function(event) { - var action_link = ActiveScaffold.ActionLink.get(event.findElement()); - if (action_link) { - if (action_link.is_disabled()) { - event.stop(); - } else { - if (action_link.loading_indicator) action_link.loading_indicator.style.visibility = 'visible'; - action_link.disable(); - } - } - return true; - }); - document.on('ajax:success', 'a.as_action', function(event) { - var action_link = ActiveScaffold.ActionLink.get(event.findElement()); - if (action_link && event.memo && event.memo.request) { - if (action_link.position) { - action_link.insert(event.memo.request.transport.responseText); - if (action_link.hide_target) action_link.target.hide(); - } else { - //event.memo.request.evalResponse(); // (clyfe) prototype evals the response by itself checking headers, this would eval twice - action_link.enable(); - } - event.stop(); - } - return true; - }); - document.on('ajax:complete', 'a.as_action', function(event) { - var action_link = ActiveScaffold.ActionLink.get(event.findElement()); - if (action_link && action_link.loading_indicator) { - action_link.loading_indicator.style.visibility = 'hidden'; - } - return true; - }); - document.on('ajax:failure', 'a.as_action', function(event) { - var action_link = ActiveScaffold.ActionLink.get(event.findElement()); - if (action_link) { - ActiveScaffold.report_500_response(action_link.scaffold_id()); - action_link.enable(); - } - return true; - }); - document.on('ajax:before', 'a.as_cancel', function(event) { - var as_cancel = event.findElement(); - var action_link = ActiveScaffold.find_action_link(as_cancel); - - if (action_link) { - var refresh_data = as_cancel.readAttribute('data-refresh'); - if (refresh_data === 'true' && action_link.refresh_url) { - event.memo.url = action_link.refresh_url; - } else if (refresh_data === 'false' || as_cancel.readAttribute('href').blank()) { - action_link.close(); - event.stop(); - } - } - return true; - }); - document.on('ajax:success', 'a.as_cancel', function(event) { - var action_link = ActiveScaffold.find_action_link(event.findElement()); - if (action_link) { - if (action_link.position) { - action_link.close(event.memo.request.responseText); - } else { - event.memo.request.evalResponse(); - } - } - return true; - }); - document.on('ajax:failure', 'a.as_cancel', function(event) { - var action_link = ActiveScaffold.find_action_link(event.findElement()); - if (action_link) { - ActiveScaffold.report_500_response(action_link.scaffold_id()); - } - return true; - }); - document.on('ajax:before', 'a.as_sort', function(event) { - var as_sort = event.findElement(); - var history_controller_id = as_sort.readAttribute('data-page-history'); - if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.readAttribute('href'), history_controller_id); - as_sort.up('th').addClassName('loading'); - return true; - }); - document.on('ajax:failure', 'a.as_sort', function(event) { - var as_scaffold = event.findElement('.active-scaffold'); - ActiveScaffold.report_500_response(as_scaffold); - return true; - }); - document.on('mouseover', 'span.in_place_editor_field', function(event) { - event.findElement().addClassName('hover'); - }); - document.on('mouseout', 'span.in_place_editor_field', function(event) { - event.findElement().removeClassName('hover'); - }); - document.on('click', 'span.in_place_editor_field', function(event) { - var span = event.findElement('span.in_place_editor_field'); - - if (typeof(span.inplace_edit) === 'undefined') { - var options = {htmlResponse: false, - onEnterHover: null, - onLeaveHover: null, - onComplete: null, - params: '', - ajaxOptions: {method: 'post'}}, - csrf_param = $$('meta[name=csrf-param]')[0], - csrf_token = $$('meta[name=csrf-token]')[0], - my_parent = span.up(), - column_heading = null; - - if(!(my_parent.nodeName.toLowerCase() === 'td' || my_parent.nodeName.toLowerCase() === 'th')){ - my_parent = span.up('td'); - } - - if (my_parent.nodeName.toLowerCase() === 'td') { - var heading_selector = '.' + span.up().readAttribute('class').split(' ')[0] + '_heading'; - column_heading = span.up('.active-scaffold').down(heading_selector); - } else if (my_parent.nodeName.toLowerCase() === 'th') { - column_heading = my_parent; - } - - var render_url = column_heading.readAttribute('data-ie_render_url'), - mode = column_heading.readAttribute('data-ie_mode'), - record_id = span.readAttribute('data-ie_id'); - - ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options); - - if (span.readAttribute('data-ie_url')) { - options.url = span.readAttribute('data-ie_url'); - } else { - options.url = column_heading.readAttribute('data-ie_url'); - } - if (record_id) options.url = options.url.sub('__id__', record_id); - - if (csrf_param) options['params'] = csrf_param.readAttribute('content') + '=' + csrf_token.readAttribute('content'); - - if (span.up('div.active-scaffold').readAttribute('data-eid')) { - if (options['params'].length > 0) { - options['params'] += "&"; - } - options['params'] += ("eid=" + span.up('div.active-scaffold').readAttribute('data-eid')); - } - - if (mode === 'clone') { - options.nodeIdSuffix = record_id; - options.inplacePatternSelector = '#' + column_heading.readAttribute('id') + ' .as_inplace_pattern'; - options['onFormCustomization'] = new Function('element', 'form', 'element.clonePatternField();'); - } - - if (render_url) { - var plural = false; - if (column_heading.readAttribute('data-ie_plural')) plural = true; - options['onFormCustomization'] = new Function('element', 'form', 'element.setFieldFromAjax(' + "'" + render_url.sub('__id__', record_id) + "', {plural: " + plural + '});'); - } - - if (mode === 'inline_checkbox') { - ActiveScaffold.process_checkbox_inplace_edit(span.down('input[type="checkbox"]'), options); - } else { - ActiveScaffold.create_inplace_editor(span, options); - } - } - return true; - }); - document.on('ajax:before', 'a.as_paginate', function(event) { - var as_paginate = event.findElement(); - var loading_indicator = as_paginate.up().down('img.loading-indicator'); - var history_controller_id = as_paginate.readAttribute('data-page-history'); - - if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.readAttribute('href'), history_controller_id); - if (loading_indicator) loading_indicator.style.visibility = 'visible'; - return true; - }); - document.on('ajax:failure', 'a.as_paginate', function(event) { - var as_scaffold = event.findElement('.active-scaffold'); - ActiveScaffold.report_500_response(as_scaffold); - return true; - }); - document.on('ajax:complete', 'a.as_paginate', function(event) { - var as_paginate = event.findElement(); - var loading_indicator = as_paginate.up().down('img.loading-indicator'); - - if(loading_indicator) loading_indicator.style.visibility = 'hidden'; - return true; - }); - document.on('ajax:before', 'input[type=button].as_add_existing', function(event) { - var button = event.findElement(); - var url = button.readAttribute('href').sub('--ID--', button.previous().getValue()); - event.memo.url = url; - return true; - }); - document.on('change', 'input.update_form, select.update_form', function(event) { - var element = event.findElement(); - var as_form = element.up('form.as_form'); - var params = null; - - if (element.hasAttribute('data-update_send_form')) { - params = as_form.serialize(true); - } else { - params = {value: element.getValue()}; - } - params.source_id = element.readAttribute('id'); - - new Ajax.Request(element.readAttribute('data-update_url'), { - method: 'get', - parameters: params, - onLoading: function(response) { - element.next('img.loading-indicator').style.visibility = 'visible'; - as_form.disable(); - }, - onComplete: function(response) { - element.next('img.loading-indicator').style.visibility = 'hidden'; - as_form.enable(); - }, - onFailure: function(request) { - var as_div = event.findElement('div.active-scaffold'); - if (as_div) { - ActiveScaffold.report_500_response(as_div) - } - } - }); - return true; - }); - document.on('change', 'select.as_search_range_option', function(event) { - var element = event.findElement(); - Element[element.value == 'BETWEEN' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_between')); - return true; - }); - document.on('change', 'select.as_search_date_time_option', function(event) { - var element = event.findElement(); - Element[!(element.value == 'PAST' || element.value == 'FUTURE' || element.value == 'RANGE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_numeric')); - Element[(element.value == 'PAST' || element.value == 'FUTURE') ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_trend')); - Element[element.value == 'RANGE' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_range')); - return true; - }); - document.on('change', 'select.as_update_date_operator', function(event) { - var element = event.findElement(); - Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next()); - Element[element.value == 'REPLACE' ? 'show' : 'hide'](element.next().next()); - Element[element.value == 'REPLACE' ? 'hide' : 'show'](element.next('span')); - return true; - }); - document.on("click", "a[data-popup]", function(event, element) { - if (event.stopped) return; - window.open($(element).href); - event.stop(); - }); - document.on("click", ".hover_click", function(event, element) { - var ul_element = element.down('ul'); - if (ul_element.getStyle('display') === 'none') { - ul_element.style.display = 'block'; - } else { - ul_element.style.display = 'none'; - } - - return true; - }); - document.on("click", ".hover_click a.as_action", function(event, element) { - var element = element.up('.hover_click').down('ul'); - if (element) { - element.style.display = 'none'; - } - return true; - }); -}); - - -/* - * Simple utility methods - */ - -var ActiveScaffold = { - records_for: function(tbody_id) { - var rows = []; - var child = $(tbody_id).down('.record'); - while (child) { - rows.push(child); - child = child.next('.record'); - } - return rows; - }, - stripe: function(tbody_id) { - var even = false; - var rows = this.records_for(tbody_id); - for (var i = 0; i < rows.length; i++) { - var child = rows[i]; - //Make sure to skip rows that are create or edit rows or messages - if (child.tagName != 'SCRIPT' - && !child.hasClassName("create") - && !child.hasClassName("update") - && !child.hasClassName("inline-adapter") - && !child.hasClassName("active-scaffold-calculations")) { - - if (even) child.addClassName("even-record"); - else child.removeClassName("even-record"); - - even = !even; - } - } - }, - hide_empty_message: function(tbody) { - if (this.records_for(tbody).length != 0) { - var empty_message_nodes = $(tbody).up().select('tbody.messages p.empty-message') - empty_message_nodes.invoke('hide'); - } - }, - reload_if_empty: function(tbody, url) { - if (this.records_for(tbody).length == 0) { - new Ajax.Request(url, { - method: 'get', - asynchronous: true, - evalScripts: true - }); - } - }, - removeSortClasses: function(scaffold) { - scaffold = $(scaffold) - scaffold.select('td.sorted').each(function(element) { - element.removeClassName("sorted"); - }); - scaffold.select('th.sorted').each(function(element) { - element.removeClassName("sorted"); - element.removeClassName("asc"); - element.removeClassName("desc"); - }); - }, - decrement_record_count: function(scaffold) { - // decrement the last record count, firsts record count are in nested lists - scaffold = $(scaffold) - count = scaffold.select('span.active-scaffold-records').last(); - if (count) count.update(parseInt(count.innerHTML, 10) - 1); - }, - increment_record_count: function(scaffold) { - // increment the last record count, firsts record count are in nested lists - scaffold = $(scaffold) - count = scaffold.select('span.active-scaffold-records').last(); - if (count) count.update(parseInt(count.innerHTML, 10) + 1); - }, - update_row: function(row, html) { - row = $(row); - var new_row = this.replace(row, html) - if (row.hasClassName('even-record')) new_row.addClassName('even-record'); - new_row.highlight(); - }, - - replace: function(element, html) { - element = $(element) - Element.replace(element, html); - element = $(element.readAttribute('id')); - return element; - }, - - replace_html: function(element, html) { - element = $(element); - element.update(html); - return element; - }, - - remove: function(element) { - $(element).remove(); - }, - - hide: function(element) { - $(element).hide(); - }, - - show: function(element) { - $(element).show(); - }, - - reset_form: function(element) { - $(element).reset(); - }, - - disable_form: function(as_form) { - as_form = $(as_form) - var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator')); - if (loading_indicator) loading_indicator.style.visibility = 'visible'; - as_form.disable(); - }, - - enable_form: function(as_form) { - as_form = $(as_form) - var loading_indicator = $(as_form.readAttribute('id').sub('-form', '-loading-indicator')); - if (loading_indicator) loading_indicator.style.visibility = 'hidden'; - as_form.enable(); - }, - - focus_first_element_of_form: function(form_element) { - Form.focusFirstElement(form_element); - }, - - create_record_row: function(active_scaffold_id, html, options) { - tbody = $(active_scaffold_id).down('tbody.records'); - - var new_row = null; - - if (options.insert_at == 'top') { - tbody.insert({top: html}); - new_row = tbody.firstDescendant(); - } else if (options.insert_at == 'bottom') { - var last_row = tbody.childElements().reverse().detect(function(node) { return node.hasClassName('record') || node.hasClassName('inline-adapter')}); - if (last_row) { - last_row.insert({after: html}); - } else { - tbody.insert({bottom: html}); - } - new_row = Selector.findChildElements(tbody, ['tr.record']).last(); - } - - this.stripe(tbody); - this.hide_empty_message(tbody); - this.increment_record_count(tbody.up('div.active-scaffold')); - new_row.highlight(); - }, - - delete_record_row: function(row, page_reload_url) { - row = $(row); - var tbody = row.up('tbody.records'); - - var current_action_node = row.down('td.actions a.disabled'); - - if (current_action_node) { - var action_link = ActiveScaffold.ActionLink.get(current_action_node); - if (action_link) { - action_link.close_previous_adapter(); - } - } - row.remove(); - tbody = $(tbody); - this.stripe(tbody); - this.decrement_record_count(tbody.up('div.active-scaffold')); - this.reload_if_empty(tbody, page_reload_url); - }, - - delete_subform_record: function(record) { - var errors = $(record).previous(); - if (errors.hasClassName('association-record-errors')) { - this.replace_html(errors, ''); - } - this.remove(record); - }, - - report_500_response: function(active_scaffold_id) { - server_error = $(active_scaffold_id).down('td.messages-container p.server-error'); - if (server_error.visible()) { - server_error.highlight(); - } else { - server_error.show(); - } - }, - - find_action_link: function(element) { - return ActiveScaffold.ActionLink.get($(element).up('.as_adapter')); - }, - - scroll_to: function(element) { - $(element).scrollTo(); - }, - - process_checkbox_inplace_edit: function(checkbox, options) { - var checked = checkbox.readAttribute('checked'); - // checked attribute is nt updated - if (checked !== 'checked') options['params'] += '&value=1'; - new Ajax.Request(options.url, { - method: 'post', - parameters: options['params'], - onCreate: function(response) { - checkbox.disable(); - }, - onComplete: function(response) { - checkbox.enable(); - } - }); - }, - - read_inplace_edit_heading_attributes: function(column_heading, options) { - if (column_heading.readAttribute('data-ie_cancel_text')) options.cancelText = column_heading.readAttribute('data-ie_cancel_text'); - if (column_heading.readAttribute('data-ie_loading_text')) options.loadingText = column_heading.readAttribute('data-ie_loading_text'); - if (column_heading.readAttribute('data-ie_saving_text')) options.savingText = column_heading.readAttribute('data-ie_saving_text'); - if (column_heading.readAttribute('data-ie_save_text')) options.okText = column_heading.readAttribute('data-ie_save_text'); - if (column_heading.readAttribute('data-ie_rows')) options.rows = column_heading.readAttribute('data-ie_rows'); - if (column_heading.readAttribute('data-ie_cols')) options.cols = column_heading.readAttribute('data-ie_cols'); - if (column_heading.readAttribute('data-ie_size')) options.size = column_heading.readAttribute('data-ie_size'); - }, - - create_inplace_editor: function(span, options) { - if (options['params'].length > 0) { - options['callback'] = new Function('form', 'return Form.serialize(form) + ' + "'&" + options['params'] + "';"); - } - span.removeClassName('hover'); - span.inplace_edit = new ActiveScaffold.InPlaceEditor(span.readAttribute('id'), options.url, options) - span.inplace_edit.enterEditMode(); - }, - - create_visibility_toggle: function(element, options) { - var toggable = $(element); - var toggler = toggable.previous(); - var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label; - - toggler.insert(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)'); - toggler.firstDescendant().observe('click', function(event) { - var element = event.element(); - toggable.toggle(); - element.innerHTML = (toggable.style.display == 'none') ? options.show_label : options.hide_label; - return false; - }); - }, - - create_associated_record_form: function(element, content, options) { - var element = $(element); - if (options.singular == false) { - if (!(options.id && $(options.id))) { - element.insert(content); - } - } else { - var current = $$('#' + element.readAttribute('id') + ' tr.association-record'); - if (current[0]) { - this.replace(current[0], content); - } else { - element.insert({top: content}); - } - } - }, - - render_form_field: function(source, content, options) { - var source = $(source); - var element = source.up('.association-record'); - if (typeof(element) === 'undefined') { - element = source.up('ol.form'); - } - element = element.down('.' + options.field_class); - - if (element) { - if (options.is_subform == false) { - this.replace(element.up('dl'), content); - } else { - this.replace_html(element, content); - } - } - }, - - record_select_onselect: function(edit_associated_url, active_scaffold_id, id){ - new Ajax.Request( - edit_associated_url.sub('--ID--', id), { - asynchronous: true, - evalScripts: true, - onFailure: function(){ - ActiveScaffold.report_500_response(active_scaffold_id.to_json) - } - } - ); - }, - - // element is tbody id - mark_records: function(element, options) { - var element = $(element); - var mark_checkboxes = $$('#' + element.readAttribute('id') + ' > tr.record td.marked-column input[type="checkbox"]'); - mark_checkboxes.each(function(item) { - if(options.checked === true) { - item.writeAttribute({ checked: 'checked' }); - } else { - item.removeAttribute('checked'); - } - item.writeAttribute('value', ('' + !options.checked)); - }); - if(options.include_mark_all === true) { - var mark_all_checkbox = element.previous('thead').down('th.marked-column_heading span input[type="checkbox"]'); - if(options.checked === true) { - mark_all_checkbox.writeAttribute({ checked: 'checked' }); - } else { - mark_all_checkbox.removeAttribute('checked'); - } - mark_all_checkbox.writeAttribute('value', ('' + !options.checked)); - } - } - -} - -/* - * DHTML history tie-in - */ -function addActiveScaffoldPageToHistory(url, active_scaffold_id) { - if (typeof dhtmlHistory == 'undefined') return; // it may not be loaded - - var array = url.split('?'); - var qs = new Querystring(array[1]); - var sort = qs.get('sort') - var dir = qs.get('sort_direction') - var page = qs.get('page') - if (sort || dir || page) dhtmlHistory.add(active_scaffold_id+":"+page+":"+sort+":"+dir, url); -} - -/* - * Add-ons/Patches to Prototype - */ - -/* patch to support replacing TR/TD/TBODY in Internet Explorer, courtesy of http://dev.rubyonrails.org/ticket/4273 */ -Element.replace = function(element, html) { - element = $(element); - if (element.outerHTML) { - try { - element.outerHTML = html.stripScripts(); - } catch (e) { - var tn = element.tagName; - if(tn=='TBODY' || tn=='TR' || tn=='TD') - { - var tempDiv = document.createElement("div"); - tempDiv.innerHTML = '<table id="tempTable" style="display: none">' + html.stripScripts() + '</table>'; - element.parentNode.replaceChild(tempDiv.getElementsByTagName(tn).item(0), element); - } - else throw e; - } - } else { - var range = element.ownerDocument.createRange(); - /* patch to fix <form> replaces in Firefox. see http://dev.rubyonrails.org/ticket/8010 */ - range.selectNodeContents(element.parentNode); - element.parentNode.replaceChild(range.createContextualFragment(html.stripScripts()), element); - } - setTimeout(function() {html.evalScripts()}, 10); - return element; -}; - -/* - * URL modification support. Incomplete functionality. - */ -Object.extend(String.prototype, { - append_params: function(params) { - url = this; - if (url.indexOf('?') == -1) url += '?'; - else if (url.lastIndexOf('&') != url.length) url += '&'; - - url += $H(params).collect(function(item) { - return item.key + '=' + item.value; - }).join('&'); - - return url; - } -}); - -/* - * Prototype's implementation was throwing an error instead of false - */ -Element.Methods.Simulated = { - hasAttribute: function(element, attribute) { - var t = Element._attributeTranslations; - attribute = (t.names && t.names[attribute]) || attribute; - // Return false if we get an error here - try { - return $(element).getAttributeNode(attribute).specified; - } catch (e) { - return false; - } - } -}; - -/** - * A set of links. As a set, they can be controlled such that only one is "open" at a time, etc. - */ -ActiveScaffold.Actions = new Object(); -ActiveScaffold.Actions.Abstract = Class.create({ - initialize: function(links, target, loading_indicator, options) { - this.target = $(target); - this.loading_indicator = $(loading_indicator); - this.options = options; - this.links = links.collect(function(link) { - return this.instantiate_link(link); - }.bind(this)); - }, - - instantiate_link: function(link) { - throw 'unimplemented' - } -}); - -/** - * A DataStructures::ActionLink, represented in JavaScript. - * Concerned with AJAX-enabling a link and adapting the result for insertion into the table. - */ -ActiveScaffold.ActionLink = { - get: function(element) { - var element = $(element); - if (typeof(element.retrieve('action_link')) === 'undefined' && !element.hasClassName('as_adapter')) { - var parent = element.up('.actions'); - if (typeof(parent) === 'undefined') { - // maybe an column action_link - parent = element.up(); - } - if (parent && parent.nodeName.toUpperCase() == 'TD') { - // record action - parent = parent.up('tr.record') - new ActiveScaffold.Actions.Record(parent.select('a.as_action'), parent, parent.down('td.actions .loading-indicator')); - } else if (parent && parent.nodeName.toUpperCase() == 'DIV') { - //table action - new ActiveScaffold.Actions.Table(parent.select('a.as_action'), parent.up('div.active-scaffold').down('tbody.before-header'), parent.down('.loading-indicator')); - } - element = $(element); - } - return element.retrieve('action_link'); - } -}; - -ActiveScaffold.ActionLink.Abstract = Class.create({ - initialize: function(a, target, loading_indicator) { - this.tag = $(a); - this.url = this.tag.href; - this.method = this.tag.readAttribute('data-method') || 'get'; - this.target = target; - this.loading_indicator = loading_indicator; - this.hide_target = false; - this.position = this.tag.readAttribute('data-position'); - - this.tag.store('action_link', this); - }, - - open: function(event) { - }, - - insert: function(content) { - throw 'unimplemented' - }, - - close: function() { - this.enable(); - this.adapter.remove(); - if (this.hide_target) this.target.show(); - }, - - reload: function() { - this.close(); - this.open(); - }, - - get_new_adapter_id: function() { - var id = 'adapter_'; - var i = 0; - while ($(id + i)) i++; - return id + i; - }, - - enable: function() { - return this.tag.removeClassName('disabled'); - }, - - disable: function() { - return this.tag.addClassName('disabled'); - }, - - is_disabled: function() { - return this.tag.hasClassName('disabled'); - }, - - scaffold_id: function() { - return this.tag.up('div.active-scaffold').readAttribute('id'); - }, - - scaffold: function() { - return this.tag.up('div.active-scaffold'); - }, - - update_flash_messages: function(messages) { - message_node = $(this.scaffold_id().sub('-active-scaffold', '-messages')); - if (message_node) message_node.update(messages); - }, - - set_adapter: function(element) { - this.adapter = element; - this.adapter.addClassName('as_adapter'); - this.adapter.store('action_link', this); - } -}); - -/** - * Concrete classes for record actions - */ -ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, { - instantiate_link: function(link) { - var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); - if (this.target.hasAttribute('data-refresh') && !this.target.readAttribute('data-refresh').blank()) l.refresh_url = this.target.readAttribute('data-refresh'); - - if (l.position) { - l.url = l.url.append_params({adapter: '_list_inline_adapter'}); - l.tag.href = l.url; - } - l.set = this; - return l; - } -}); - -ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstract, { - close_previous_adapter: function() { - this.set.links.each(function(item) { - if (item.url != this.url && item.is_disabled() && item.adapter) { - item.enable(); - item.adapter.remove(); - } - }.bind(this)); - }, - - insert: function(content) { - this.close_previous_adapter(); - - if (this.position == 'replace') { - this.position = 'after'; - this.hide_target = true; - } - - if (this.position == 'after') { - this.target.insert({after:content}); - this.set_adapter(this.target.next()); - } - else if (this.position == 'before') { - this.target.insert({before:content}); - this.set_adapter(this.target.previous()); - } - else { - return false; - } - this.adapter.down('td').down().highlight(); - }, - - close: function($super, refreshed_content) { - if (refreshed_content) { - ActiveScaffold.update_row(this.target, refreshed_content); - } - $super(); - }, - - enable: function() { - this.set.links.each(function(item) { - if (item.url != this.url) return; - item.tag.removeClassName('disabled'); - }.bind(this)); - }, - - disable: function() { - this.set.links.each(function(item) { - if (item.url != this.url) return; - item.tag.addClassName('disabled'); - }.bind(this)); - }, - - set_opened: function() { - if (this.position == 'after') { - this.set_adapter(this.target.next()); - } - else if (this.position == 'before') { - this.set_adapter(this.target.previous()); - } - this.disable(); - } -}); - -/** - * Concrete classes for table actions - */ -ActiveScaffold.Actions.Table = Class.create(ActiveScaffold.Actions.Abstract, { - instantiate_link: function(link) { - var l = new ActiveScaffold.ActionLink.Table(link, this.target, this.loading_indicator); - if (l.position) { - l.url = l.url.append_params({adapter: '_list_inline_adapter'}); - l.tag.href = l.url; - } - return l; - } -}); - -ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstract, { - insert: function(content) { - if (this.position == 'top') { - this.target.insert({top:content}); - this.set_adapter(this.target.immediateDescendants().first()); - } - else { - throw 'Unknown position "' + this.position + '"' - } - this.adapter.down('td').down().highlight(); - } -}); - -if (Ajax.InPlaceEditor) { -ActiveScaffold.InPlaceEditor = Class.create(Ajax.InPlaceEditor, { - initialize: function($super, element, url, options) { - $super(element, url, options); - if (this._originalBackground == 'transparent') { - this._originalBackground = null; - } - }, - - setFieldFromAjax: function(url, options) { - var ipe = this; - $(ipe._controls.editor).remove(); - new Ajax.Request(url, { - method: 'get', - onComplete: function(response) { - ipe._form.insert({top: response.responseText}); - if (options.plural) { - ipe._form.getElements().each(function(el) { - if (el.type != "submit" && el.type != "image") { - el.name = ipe.options.paramName + '[]'; - el.className = 'editor_field'; - } - }); - } else { - var fld = ipe._form.findFirstElement(); - fld.name = ipe.options.paramName; - fld.className = 'editor_field'; - if (ipe.options.submitOnBlur) - fld.onblur = ipe._boundSubmitHandler; - ipe._controls.editor = fld; - } - } - }); - }, - - clonePatternField: function() { - var patternNodes = this.getPatternNodes(this.options.inplacePatternSelector); - if (patternNodes.editNode == null) { - alert('did not find any matching node for ' + this.options.editFieldSelector); - return; - } - - var fld = patternNodes.editNode.cloneNode(true); - if (fld.id.length > 0) fld.id += this.options.nodeIdSuffix; - fld.name = this.options.paramName; - fld.className = 'editor_field'; - this.setValue(fld, this._controls.editor.value); - if (this.options.submitOnBlur) - fld.onblur = this._boundSubmitHandler; - $(this._controls.editor).remove(); - this._controls.editor = fld; - this._form.appendChild(this._controls.editor); - - $A(patternNodes.additionalNodes).each(function(node) { - var patternNode = node.cloneNode(true); - if (patternNode.id.length > 0) { - patternNode.id = patternNode.id + this.options.nodeIdSuffix; - } - this._form.appendChild(patternNode); - }.bind(this)); - }, - - getPatternNodes: function(inplacePatternSelector) { - var nodes = {editNode: null, additionalNodes: []}; - var selectedNodes = $$(inplacePatternSelector); - var firstNode = selectedNodes.first(); - - if (typeof(firstNode) !== 'undefined') { - // AS inplace_edit_control_container -> we have to select all child nodes - // Workaround for ie which does not support css > selector - if (firstNode.className.indexOf('as_inplace_pattern') !== -1) { - selectedNodes = firstNode.childElements(); - } - nodes.editNode = selectedNodes.first(); - selectedNodes.shift(); - nodes.additionalNodes = selectedNodes; - } - return nodes; - }, - - setValue: function(editField, textValue) { - var function_name = 'setValueFor' + editField.nodeName.toLowerCase(); - if (typeof(this[function_name]) == 'function') { - this[function_name](editField, textValue); - } else { - editField.value = textValue; - } - }, - - setValueForselect: function(editField, textValue) { - var len = editField.options.length; - var i = 0; - while (i < len && editField.options[i].text != textValue) { - i++; - } - if (i < len) { - editField.value = editField.options[i].value - } - } -}); -} diff --git a/frontends/default/javascripts/prototype/dhtml_history.js b/frontends/default/javascripts/prototype/dhtml_history.js deleted file mode 100644 index da08ba2d57..0000000000 --- a/frontends/default/javascripts/prototype/dhtml_history.js +++ /dev/null @@ -1,870 +0,0 @@ -/* -Copyright (c) 2007 Brian Dillard and Brad Neuberg: -Brian Dillard | Project Lead | bdillard@pathf.com | http://blogs.pathf.com/agileajax/ -Brad Neuberg | Original Project Creator | http://codinginparadise.org - -SVN r113 from http://code.google.com/p/reallysimplehistory -+ Changes by Ed Wildgoose - MailASail -+ Changed EncodeURIComponent -> EncodeURI -+ Changed DecodeURIComponent -> DecodeURI -+ Changed 'blank.html?' -> '/blank.html?' - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files -(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE -FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -/* - dhtmlHistory: An object that provides history, history data, and bookmarking for DHTML and Ajax applications. - - dependencies: - * the historyStorage object included in this file. - -*/ -window.dhtmlHistory = { - - /*Public: User-agent booleans*/ - isIE: false, - isOpera: false, - isSafari: false, - isKonquerer: false, - isGecko: false, - isSupported: false, - - /*Public: Create the DHTML history infrastructure*/ - create: function(options) { - - /* - options - object to store initialization parameters - options.blankURL - string to override the default location of blank.html. Must end in "?" - options.debugMode - boolean that causes hidden form fields to be shown for development purposes. - options.toJSON - function to override default JSON stringifier - options.fromJSON - function to override default JSON parser - options.baseTitle - pattern for title changes; example: "Armchair DJ [@@@]" - @@@ will be replaced - */ - - var that = this; - - /*set user-agent flags*/ - var UA = navigator.userAgent.toLowerCase(); - var platform = navigator.platform.toLowerCase(); - var vendor = navigator.vendor || ""; - if (vendor === "KDE") { - this.isKonqueror = true; - this.isSupported = false; - } else if (typeof window.opera !== "undefined") { - this.isOpera = true; - this.isSupported = true; - } else if (typeof document.all !== "undefined") { - this.isIE = true; - this.isSupported = true; - } else if (vendor.indexOf("Apple Computer, Inc.") > -1) { - this.isSafari = true; - //this.isSupported = (platform.indexOf("mac") > -1); - this.isSupported = false; - } else if (UA.indexOf("gecko") != -1) { - this.isGecko = true; - this.isSupported = true; - } - - if (this.isSupported) { - /*Set up the historyStorage object; pass in options bundle*/ - window.historyStorage.setup(options); - - /*Set up our base title if one is passed in*/ - if (options && options.baseTitle) { - if (options.baseTitle.indexOf("@@@") < 0 && historyStorage.debugMode) { - throw new Error("Programmer error: options.baseTitle must contain the replacement parameter" - + " '@@@' to be useful."); - } - this.baseTitle = options.baseTitle; - } - - /*Create Safari/Opera-specific code*/ - if (this.isSafari && this.isSupported) { - this.createSafari(); - } else if (this.isOpera) { - this.createOpera(); - } - - /*Get our initial location*/ - var initialHash = this.getCurrentLocation(); - - /*Save it as our current location*/ - this.currentLocation = initialHash; - - /*Now that we have a hash, create IE-specific code*/ - if (this.isIE) { - /*Optionally override the URL of IE's blank HTML file*/ - if (options && options.blankURL) { - var u = options.blankURL; - /*assign the value, adding the trailing ? if it's not passed in*/ - this.blankURL = (u.indexOf("?") != u.length - 1 - ? u + "?" - : u - ); - } - this.createIE(initialHash); - } - - /*Add an unload listener for the page; this is needed for FF 1.5+ because this browser caches all dynamic updates to the - page, which can break some of our logic related to testing whether this is the first instance a page has loaded or whether - it is being pulled from the cache*/ - - var unloadHandler = function() { - that.firstLoad = null; - }; - - this.addEventListener(window,'unload',unloadHandler); - - /*Determine if this is our first page load; for IE, we do this in this.iframeLoaded(), which is fired on pageload. We do it - there because we have no historyStorage at this point, which only exists after the page is finished loading in IE*/ - if (this.isIE) { - /*The iframe will get loaded on page load, and we want to ignore this fact*/ - this.ignoreLocationChange = true; - } else if (this.isSupported) { - if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) { - /*This is our first page load, so ignore the location change and add our special history entry*/ - this.ignoreLocationChange = true; - this.firstLoad = true; - historyStorage.put(this.PAGELOADEDSTRING, true); - } else { - /*This isn't our first page load, so indicate that we want to pay attention to this location change*/ - this.ignoreLocationChange = false; - this.firstLoad = false; - /*For browsers other than IE, fire a history change event; on IE, the event will be thrown automatically when its - hidden iframe reloads on page load. Unfortunately, we don't have any listeners yet; indicate that we want to fire - an event when a listener is added.*/ - this.fireOnNewListener = true; - } - } - - /*Other browsers can use a location handler that checks at regular intervals as their primary mechanism; we use it for IE as - well to handle an important edge case; see checkLocation() for details*/ - var locationHandler = function() { - that.checkLocation(); - }; - setInterval(locationHandler, 100); - } - }, - - /*Public: Initialize our DHTML history. You must call this after the page is finished loading. Optionally, you can pass your listener in - here so you don't need to make a separate call to addListener*/ - initialize: function(listener) { - - /*save original document title to plug in when we hit a null-key history point*/ - this.originalTitle = document.title; - - /*IE needs to be explicitly initialized. IE doesn't autofill form data until the page is finished loading, so we have to wait*/ - if (this.isIE) { - /*If this is the first time this page has loaded*/ - if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) { - /*For IE, we do this in initialize(); for other browsers, we do it in create()*/ - this.fireOnNewListener = false; - this.firstLoad = true; - historyStorage.put(this.PAGELOADEDSTRING, true); - } - /*Else if this is a fake onload event*/ - else { - this.fireOnNewListener = true; - this.firstLoad = false; - } - } - /*optional convenience to save a separate call to addListener*/ - if (listener) { - this.addListener(listener); - } - }, - - /*Public: Adds a history change listener. Only one listener is supported at this time.*/ - addListener: function(listener) { - this.listener = listener; - /*If the page was just loaded and we should not ignore it, fire an event to our new listener now*/ - if (this.fireOnNewListener) { - this.fireHistoryEvent(this.currentLocation); - this.fireOnNewListener = false; - } - }, - - /*Public: Change the current HTML title*/ - changeTitle: function(historyData) { - var winTitle = (historyData && historyData.newTitle - /*Plug the new title into the pattern*/ - ? this.baseTitle.replace('@@@', historyData.newTitle) - /*Otherwise, if there is no new title, use the original document title. This is useful when some - history changes have title changes and some don't; we can automatically return to the original - title rather than leaving a misleading title in the title bar. The same goes for our "virgin" - (hashless) page state.*/ - : this.originalTitle - ); - /*No need to do anything if the title isn't changing*/ - if (document.title == winTitle) { - return; - } - - - /*Now change the DOM*/ - document.title = winTitle; - /*Change it in the iframe, too, for IE*/ - if (this.isIE) { - this.iframe.contentWindow.document.title = winTitle; - } - - /*If non-IE, reload the hash so the new title "sticks" in the browser history object*/ - if (!this.isIE && !this.isOpera) { - var hash = decodeURI(document.location.hash); - if (hash != "") { - var encodedHash = encodeURI(this.removeHash(hash)); - document.location.hash = encodedHash; - } else { - //document.location.hash = "#"; - } - } - }, - - /*Public: Add a history point. Parameters available: - * newLocation (required): - This will be the #hash value in the URL. Users can bookmark it. It will persist across sessions, so - your application should be able to restore itself to a specific state based on just this value. It - should be either a simple keyword for a viewstate or else a pseudo-querystring. - * historyData (optional): - This is for complex data that is relevant only to the current browsing session. It will be available - to your application until the browser is closed. If the user comes back to a bookmarked history point - during a later session, this data will no longer be available. Don't rely on it for application - re-initialization from a bookmark. - * historyData.newTitle (optional): - This will swap out the html <title> attribute with a new value. If you have set a baseTitle using the - options bundle, the value will be plugged into the baseTitle by swapping out the @@@ replacement param. - */ - add: function(newLocation, historyData) { - - var that = this; - - /*Escape the location and remove any leading hash symbols*/ - var encodedLocation = encodeURI(this.removeHash(newLocation)); - - if (this.isSafari) { - - /*Store the history data into history storage - pass in unencoded newLocation since - historyStorage does its own encoding*/ - historyStorage.put(newLocation, historyData); - - /*Save this as our current location*/ - this.currentLocation = encodedLocation; - - /*Change the browser location*/ - window.location.hash = encodedLocation; - - /*Save this to the Safari form field*/ - this.putSafariState(encodedLocation); - - this.changeTitle(historyData); - - } else { - - /*Most browsers require that we wait a certain amount of time before changing the location, such - as 200 MS; rather than forcing external callers to use window.setTimeout to account for this, - we internally handle it by putting requests in a queue.*/ - var addImpl = function() { - - /*Indicate that the current wait time is now less*/ - if (that.currentWaitTime > 0) { - that.currentWaitTime = that.currentWaitTime - that.waitTime; - } - - /*IE has a strange bug; if the encodedLocation is the same as _any_ preexisting id in the - document, then the history action gets recorded twice; throw a programmer exception if - there is an element with this ID*/ - if (document.getElementById(encodedLocation) && that.debugMode) { - var e = "Exception: History locations can not have the same value as _any_ IDs that might be in the document," - + " due to a bug in IE; please ask the developer to choose a history location that does not match any HTML" - + " IDs in this document. The following ID is already taken and cannot be a location: " + newLocation; - throw new Error(e); - } - - /*Store the history data into history storage - pass in unencoded newLocation since - historyStorage does its own encoding*/ - historyStorage.put(newLocation, historyData); - - /*Indicate to the browser to ignore this upcomming location change since we're making it programmatically*/ - that.ignoreLocationChange = true; - - /*Indicate to IE that this is an atomic location change block*/ - that.ieAtomicLocationChange = true; - - /*Save this as our current location*/ - that.currentLocation = encodedLocation; - - /*Change the browser location*/ - window.location.hash = encodedLocation; - - /*Change the hidden iframe's location if on IE*/ - if (that.isIE) { - that.iframe.src = that.blankURL + encodedLocation; - } - - /*End of atomic location change block for IE*/ - that.ieAtomicLocationChange = false; - - that.changeTitle(historyData); - - }; - - /*Now queue up this add request*/ - window.setTimeout(addImpl, this.currentWaitTime); - - /*Indicate that the next request will have to wait for awhile*/ - this.currentWaitTime = this.currentWaitTime + this.waitTime; - } - }, - - /*Public*/ - isFirstLoad: function() { - return this.firstLoad; - }, - - /*Public*/ - getVersion: function() { - return this.VERSIONNUMBER; - }, - - /*- - - - - - - - - - - -*/ - - /*Private: Constant for our own internal history event called when the page is loaded*/ - PAGELOADEDSTRING: "DhtmlHistory_pageLoaded", - - VERSIONNUMBER: "0.8", - - /* - Private: Pattern for title changes. Example: "Armchair DJ [@@@]" where @@@ will be relaced by values passed to add(); - Default is just the title itself, hence "@@@" - */ - baseTitle: "@@@", - - /*Private: Placeholder variable for the original document title; will be set in ititialize()*/ - originalTitle: null, - - /*Private: URL for the blank html file we use for IE; can be overridden via the options bundle. Otherwise it must be served - in same directory as this library*/ - blankURL: "/blank.html?", - - /*Private: Our history change listener.*/ - listener: null, - - /*Private: MS to wait between add requests - will be reset for certain browsers*/ - waitTime: 200, - - /*Private: MS before an add request can execute*/ - currentWaitTime: 0, - - /*Private: Our current hash location, without the "#" symbol.*/ - currentLocation: null, - - /*Private: Hidden iframe used to IE to detect history changes*/ - iframe: null, - - /*Private: Flags and DOM references used only by Safari*/ - safariHistoryStartPoint: null, - safariStack: null, - safariLength: null, - - /*Private: Flag used to keep checkLocation() from doing anything when it discovers location changes we've made ourselves - programmatically with the add() method. Basically, add() sets this to true. When checkLocation() discovers it's true, - it refrains from firing our listener, then resets the flag to false for next cycle. That way, our listener only gets fired on - history change events triggered by the user via back/forward buttons and manual hash changes. This flag also helps us set up - IE's special iframe-based method of handling history changes.*/ - ignoreLocationChange: null, - - /*Private: A flag that indicates that we should fire a history change event when we are ready, i.e. after we are initialized and - we have a history change listener. This is needed due to an edge case in browsers other than IE; if you leave a page entirely - then return, we must fire this as a history change event. Unfortunately, we have lost all references to listeners from earlier, - because JavaScript clears out.*/ - fireOnNewListener: null, - - /*Private: A variable that indicates whether this is the first time this page has been loaded. If you go to a web page, leave it - for another one, and then return, the page's onload listener fires again. We need a way to differentiate between the first page - load and subsequent ones. This variable works hand in hand with the pageLoaded variable we store into historyStorage.*/ - firstLoad: null, - - /*Private: A variable to handle an important edge case in IE. In IE, if a user manually types an address into their browser's - location bar, we must intercept this by calling checkLocation() at regular intervals. However, if we are programmatically - changing the location bar ourselves using the add() method, we need to ignore these changes in checkLocation(). Unfortunately, - these changes take several lines of code to complete, so for the duration of those lines of code, we set this variable to true. - That signals to checkLocation() to ignore the change-in-progress. Once we're done with our chunk of location-change code in - add(), we set this back to false. We'll do the same thing when capturing user-entered address changes in checkLocation itself.*/ - ieAtomicLocationChange: null, - - /*Private: Generic utility function for attaching events*/ - addEventListener: function(o,e,l) { - if (o.addEventListener) { - o.addEventListener(e,l,false); - } else if (o.attachEvent) { - o.attachEvent('on'+e,function() { - l(window.event); - }); - } - }, - - - /*Private: Create IE-specific DOM nodes and overrides*/ - createIE: function(initialHash) { - /*write out a hidden iframe for IE and set the amount of time to wait between add() requests*/ - this.waitTime = 400;/*IE needs longer between history updates*/ - var styles = (historyStorage.debugMode - ? 'width: 800px;height:80px;border:1px solid black;' - : historyStorage.hideStyles - ); - var iframeID = "rshHistoryFrame"; - var iframeHTML = '<iframe frameborder="0" id="' + iframeID + '" style="' + styles + '" src="' + this.blankURL + initialHash + '"></iframe>'; - document.write(iframeHTML); - this.iframe = document.getElementById(iframeID); - }, - - /*Private: Create Opera-specific DOM nodes and overrides*/ - createOpera: function() { - this.waitTime = 400;/*Opera needs longer between history updates*/ - var imgHTML = '<img src="javascript:location.href=\'javascript:dhtmlHistory.checkLocation();\';" style="' + historyStorage.hideStyles + '" />'; - document.write(imgHTML); - }, - - /*Private: Create Safari-specific DOM nodes and overrides*/ - createSafari: function() { - var formID = "rshSafariForm"; - var stackID = "rshSafariStack"; - var lengthID = "rshSafariLength"; - var formStyles = historyStorage.debugMode ? historyStorage.showStyles : historyStorage.hideStyles; - var stackStyles = (historyStorage.debugMode - ? 'width: 800px;height:80px;border:1px solid black;' - : historyStorage.hideStyles - ); - var lengthStyles = (historyStorage.debugMode - ? 'width:800px;height:20px;border:1px solid black;margin:0;padding:0;' - : historyStorage.hideStyles - ); - var safariHTML = '<form id="' + formID + '" style="' + formStyles + '">' - + '<textarea style="' + stackStyles + '" id="' + stackID + '">[]</textarea>' - + '<input type="text" style="' + lengthStyles + '" id="' + lengthID + '" value=""/>' - + '</form>'; - document.write(safariHTML); - this.safariStack = document.getElementById(stackID); - this.safariLength = document.getElementById(lengthID); - if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) { - this.safariHistoryStartPoint = history.length; - this.safariLength.value = this.safariHistoryStartPoint; - } else { - this.safariHistoryStartPoint = this.safariLength.value; - } - }, - - /*TODO: make this public again?*/ - /*Private: Get browser's current hash location; for Safari, read value from a hidden form field*/ - getCurrentLocation: function() { - var r = (this.isSafari - ? this.getSafariState() - : this.getCurrentHash() - ); - return r; - }, - - /*TODO: make this public again?*/ - /*Private: Manually parse the current url for a hash; tip of the hat to YUI*/ - getCurrentHash: function() { - var r = window.location.href; - var i = r.indexOf("#"); - return (i >= 0 - ? r.substr(i+1) - : "" - ); - }, - - /*Private: Safari method to read the history stack from a hidden form field*/ - getSafariStack: function() { - var r = this.safariStack.value; - return historyStorage.fromJSON(r); - }, - /*Private: Safari method to read from the history stack*/ - getSafariState: function() { - var stack = this.getSafariStack(); - var state = stack[history.length - this.safariHistoryStartPoint - 1]; - return state; - }, - /*Private: Safari method to write the history stack to a hidden form field*/ - putSafariState: function(newLocation) { - var stack = this.getSafariStack(); - stack[history.length - this.safariHistoryStartPoint] = newLocation; - this.safariStack.value = historyStorage.toJSON(stack); - }, - - /*Private: Notify the listener of new history changes.*/ - fireHistoryEvent: function(newHash) { - var decodedHash = decodeURI(newHash) - /*extract the value from our history storage for this hash*/ - var historyData = historyStorage.get(decodedHash); - this.changeTitle(historyData); - /*call our listener*/ - this.listener.call(null, decodedHash, historyData); - }, - - /*Private: See if the browser has changed location. This is the primary history mechanism for Firefox. For IE, we use this to - handle an important edge case: if a user manually types in a new hash value into their IE location bar and press enter, we want to - to intercept this and notify any history listener.*/ - checkLocation: function() { - - /*Ignore any location changes that we made ourselves for browsers other than IE*/ - if (!this.isIE && this.ignoreLocationChange) { - this.ignoreLocationChange = false; - return; - } - - /*If we are dealing with IE and we are in the middle of making a location change from an iframe, ignore it*/ - if (!this.isIE && this.ieAtomicLocationChange) { - return; - } - - /*Get hash location*/ - var hash = this.getCurrentLocation(); - - /*Do nothing if there's been no change*/ - if (hash == this.currentLocation) { - return; - } - - /*In IE, users manually entering locations into the browser; we do this by comparing the browser's location against the - iframe's location; if they differ, we are dealing with a manual event and need to place it inside our history, otherwise - we can return*/ - this.ieAtomicLocationChange = true; - - if (this.isIE && this.getIframeHash() != hash) { - this.iframe.src = this.blankURL + hash; - } - else if (this.isIE) { - /*the iframe is unchanged*/ - return; - } - - /*Save this new location*/ - this.currentLocation = hash; - - this.ieAtomicLocationChange = false; - - /*Notify listeners of the change*/ - this.fireHistoryEvent(hash); - }, - - /*Private: Get the current location of IE's hidden iframe.*/ - getIframeHash: function() { - var doc = this.iframe.contentWindow.document; - var hash = String(doc.location.search); - if (hash.length == 1 && hash.charAt(0) == "?") { - hash = ""; - } - else if (hash.length >= 2 && hash.charAt(0) == "?") { - hash = hash.substring(1); - } - return hash; - }, - - /*Private: Remove any leading hash that might be on a location.*/ - removeHash: function(hashValue) { - var r; - if (hashValue === null || hashValue === undefined) { - r = null; - } - else if (hashValue === "") { - r = ""; - } - else if (hashValue.length == 1 && hashValue.charAt(0) == "#") { - r = ""; - } - else if (hashValue.length > 1 && hashValue.charAt(0) == "#") { - r = hashValue.substring(1); - } - else { - r = hashValue; - } - return r; - }, - - /*Private: For IE, tell when the hidden iframe has finished loading.*/ - iframeLoaded: function(newLocation) { - /*ignore any location changes that we made ourselves*/ - if (this.ignoreLocationChange) { - this.ignoreLocationChange = false; - return; - } - - /*Get the new location*/ - var hash = String(newLocation.search); - if (hash.length == 1 && hash.charAt(0) == "?") { - hash = ""; - } - else if (hash.length >= 2 && hash.charAt(0) == "?") { - hash = hash.substring(1); - } - /*Keep the browser location bar in sync with the iframe hash*/ - window.location.hash = hash; - - /*Notify listeners of the change*/ - this.fireHistoryEvent(hash); - } - - -}; - -/* - historyStorage: An object that uses a hidden form to store history state across page loads. The mechanism for doing so relies on - the fact that browsers save the text in form data for the life of the browser session, which means the text is still there when - the user navigates back to the page. This object can be used independently of the dhtmlHistory object for caching of Ajax - session information. - - dependencies: - * json2007.js (included in a separate file) or alternate JSON methods passed in through an options bundle. -*/ -window.historyStorage = { - - /*Public: Set up our historyStorage object for use by dhtmlHistory or other objects*/ - setup: function(options) { - - /* - options - object to store initialization parameters - passed in from dhtmlHistory or directly into historyStorage - options.debugMode - boolean that causes hidden form fields to be shown for development purposes. - options.toJSON - function to override default JSON stringifier - options.fromJSON - function to override default JSON parser - */ - - /*process init parameters*/ - if (typeof options !== "undefined") { - if (options.debugMode) { - this.debugMode = options.debugMode; - } - if (options.toJSON) { - this.toJSON = options.toJSON; - } - if (options.fromJSON) { - this.fromJSON = options.fromJSON; - } - } - - /*write a hidden form and textarea into the page; we'll stow our history stack here*/ - var formID = "rshStorageForm"; - var textareaID = "rshStorageField"; - var formStyles = this.debugMode ? historyStorage.showStyles : historyStorage.hideStyles; - var textareaStyles = (historyStorage.debugMode - ? 'width: 800px;height:80px;border:1px solid black;' - : historyStorage.hideStyles - ); - var textareaHTML = '<form id="' + formID + '" style="' + formStyles + '">' - + '<textarea id="' + textareaID + '" style="' + textareaStyles + '"></textarea>' - + '</form>'; - document.write(textareaHTML); - this.storageField = document.getElementById(textareaID); - if (typeof window.opera !== "undefined") { - this.storageField.focus();/*Opera needs to focus this element before persisting values in it*/ - } - }, - - /*Public*/ - put: function(key, value) { - - var encodedKey = encodeURI(key); - - this.assertValidKey(encodedKey); - /*if we already have a value for this, remove the value before adding the new one*/ - if (this.hasKey(key)) { - this.remove(key); - } - /*store this new key*/ - this.storageHash[encodedKey] = value; - /*save and serialize the hashtable into the form*/ - this.saveHashTable(); - }, - - /*Public*/ - get: function(key) { - - var encodedKey = encodeURI(key); - - this.assertValidKey(encodedKey); - /*make sure the hash table has been loaded from the form*/ - this.loadHashTable(); - var value = this.storageHash[encodedKey]; - if (value === undefined) { - value = null; - } - return value; - }, - - /*Public*/ - remove: function(key) { - - var encodedKey = encodeURI(key); - - this.assertValidKey(encodedKey); - /*make sure the hash table has been loaded from the form*/ - this.loadHashTable(); - /*delete the value*/ - delete this.storageHash[encodedKey]; - /*serialize and save the hash table into the form*/ - this.saveHashTable(); - }, - - /*Public: Clears out all saved data.*/ - reset: function() { - this.storageField.value = ""; - this.storageHash = {}; - }, - - /*Public*/ - hasKey: function(key) { - - var encodedKey = encodeURI(key); - - this.assertValidKey(encodedKey); - /*make sure the hash table has been loaded from the form*/ - this.loadHashTable(); - return (typeof this.storageHash[encodedKey] !== "undefined"); - }, - - /*Public*/ - isValidKey: function(key) { - return (typeof key === "string"); - //TODO - should we ban hash signs and other special characters? - }, - - /*- - - - - - - - - - - -*/ - - /*Private - CSS strings utilized by both objects to hide or show behind-the-scenes DOM elements*/ - showStyles: 'border:0;margin:0;padding:0;', - hideStyles: 'left:-1000px;top:-1000px;width:1px;height:1px;border:0;position:absolute;', - - /*Private - debug mode flag*/ - debugMode: false, - - /*Private: Our hash of key name/values.*/ - storageHash: {}, - - /*Private: If true, we have loaded our hash table out of the storage form.*/ - hashLoaded: false, - - /*Private: DOM reference to our history field*/ - storageField: null, - - /*Private: Assert that a key is valid; throw an exception if it not.*/ - assertValidKey: function(key) { - var isValid = this.isValidKey(key); - if (!isValid && this.debugMode) { - throw new Error("Please provide a valid key for window.historyStorage. Invalid key = " + key + "."); - } - }, - - /*Private: Load the hash table up from the form.*/ - loadHashTable: function() { - if (!this.hashLoaded) { - var serializedHashTable = this.storageField.value; - if (serializedHashTable !== "" && serializedHashTable !== null) { - this.storageHash = this.fromJSON(serializedHashTable); - this.hashLoaded = true; - } - } - }, - /*Private: Save the hash table into the form.*/ - saveHashTable: function() { - this.loadHashTable(); - var serializedHashTable = this.toJSON(this.storageHash); - this.storageField.value = serializedHashTable; - }, - /*Private: Bridges for our JSON implementations - both rely on 2007 JSON.org library - can be overridden by options bundle*/ - toJSON: function(o) { - return o.toJSONString(); - }, - fromJSON: function(s) { - return s.parseJSON(); - } -}; - - -/*******************************************************************/ -/** QueryString Object from http://adamv.com/dev/javascript/querystring */ -/* Client-side access to querystring name=value pairs - Version 1.3 - 28 May 2008 - - License (Simplified BSD): - http://adamv.com/dev/javascript/qslicense.txt -*/ -function Querystring(qs) { // optionally pass a querystring to parse - this.params = {}; - - if (qs == null) qs = location.search.substring(1, location.search.length); - if (qs.length == 0) return; - -// Turn <plus> back to <space> -// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1 - qs = qs.replace(/\+/g, ' '); - var args = qs.split('&'); // parse out name/value pairs separated via & - -// split out each name=value pair - for (var i = 0; i < args.length; i++) { - var pair = args[i].split('='); - var name = decodeURI(pair[0]); - - var value = (pair.length==2) - ? decodeURI(pair[1]) - : name; - - this.params[name] = value; - } -} - -Querystring.prototype.get = function(key, default_) { - var value = this.params[key]; - return (value != null) ? value : default_; -} - -Querystring.prototype.contains = function(key) { - var value = this.params[key]; - return (value != null); -} - -/*******************************************************************/ -/* Added by Ed Wildgoose - MailASail */ -/* Initialise the library and add our history callback */ -/*******************************************************************/ -window.dhtmlHistory.create({ - toJSON: function(o) { - return Object.toJSON(o); - } - , fromJSON: function(s) { - return s.evalJSON(); - } - - // Enable this to assist with debugging -// , debugMode: true - - // dhtmlHistory has been modified not to need the next line - // But left in for robustness when updating dhtmlHistory - , blankURL: '/blank.html?' -}); - -/** Our callback to receive history - change events. */ -var handleHistoryChange = function(pageId, pageData) { - if (!pageData) return; - var info = pageId.split(':'); - var id = info[0]; - pageData += '&_method=get'; - new Ajax.Request(pageData, {asynchronous:true, evalScripts:true, method: 'get', onLoading:function(request){Element.show(id+'-pagination-loading-indicator');}}); -} - -window.onload = function() { - dhtmlHistory.initialize(handleHistoryChange); -}; - diff --git a/frontends/default/javascripts/prototype/form_enhancements.js b/frontends/default/javascripts/prototype/form_enhancements.js deleted file mode 100644 index 136c2c0e8f..0000000000 --- a/frontends/default/javascripts/prototype/form_enhancements.js +++ /dev/null @@ -1,117 +0,0 @@ - -// TODO Change to dropping the name property off the input element when in example mode -TextFieldWithExample = Class.create(); -TextFieldWithExample.prototype = { - initialize: function(inputElementId, defaultText, options) { - this.setOptions(options); - - this.input = $(inputElementId); - this.name = this.input.name; - this.defaultText = defaultText; - this.createHiddenInput(); - - if (options.focus) this.input.focus(); - this.checkAndShowExample(); - if (options.focus) { - this.input.selectionStart = 0; - this.input.selectionEnd = 0; - } - - Event.observe(this.input, "blur", this.onBlur.bindAsEventListener(this)); - Event.observe(this.input, "focus", this.onFocus.bindAsEventListener(this)); - Event.observe(this.input, "select", this.onFocus.bindAsEventListener(this)); - Event.observe(this.input, "keydown", this.onKeyPress.bindAsEventListener(this)); - Event.observe(this.input, "click", this.onClick.bindAsEventListener(this)); - }, - createHiddenInput: function() { - this.hiddenInput = document.createElement("input"); - this.hiddenInput.type = "hidden"; - this.hiddenInput.value = ""; - this.input.parentNode.appendChild(this.hiddenInput); - }, - setOptions: function(options) { - this.options = { exampleClassName: 'example' }; - Object.extend(this.options, options || {}); - }, - onKeyPress: function(event) { - if (!event) var event = window.event; - var code = (event.which) ? event.which : event.keyCode - if (this.isAlphanumeric(code)) { - this.removeExample(); - } - }, - onBlur: function(event) { - this.checkAndShowExample(); - }, - onFocus: function(event) { - this.removeExample(); - }, - onClick: function(event) { - this.removeExample(); - }, - isAlphanumeric: function(keyCode) { - return keyCode >= 40 && keyCode <= 90; - }, - checkAndShowExample: function() { - if (this.input.value == '') { - this.input.value = this.defaultText; - this.input.name = null; - this.hiddenInput.name = this.name; - Element.addClassName(this.input, this.options.exampleClassName); - } - }, - removeExample: function() { - if (this.exampleShown()) { - this.input.value = ''; - this.input.name = this.name; - this.hiddenInput.name = null; - Element.removeClassName(this.input, this.options.exampleClassName); - } - }, - exampleShown: function() { - return Element.hasClassName(this.input, this.options.exampleClassName); - } -} - -Form.disable = function(form) { - var elements = this.getElements(form); - for (var i = 0; i < elements.length; i++) { - var element = elements[i]; - try { element.blur(); } catch (e) {} - element.disabled = 'disabled'; - Element.addClassName(element, 'disabled'); - } - } -Form.enable = function(form) { - var elements = this.getElements(form); - for (var i = 0; i < elements.length; i++) { - var element = elements[i]; - element.disabled = ''; - Element.removeClassName(element, 'disabled'); - } - } - -DraggableLists = Class.create({ - initialize: function(list) { - list = $(list).addClassName('draggable-list'); - var list_selected = list.cloneNode(false).addClassName('selected'); - list_selected.id += '_seleted'; - list.select('input[type=checkbox]').each(function(item) { - var li = item.up('li'); - li.down('label').htmlFor = null; - new Draggable(li, {revert: 'failure', ghosting: true}); - if (item.checked) list_selected.insert(li.remove()); - }); - list.insert({after: list_selected}); - Droppables.add(list, {hoverclass: 'hover', containment: list_selected.id, onDrop: this.drop_to_list}); - Droppables.add(list_selected, {hoverclass: 'hover', containment: list.id, onDrop: this.drop_to_list}); - list.undoPositioned(); // undo positioned to fix dragging from elements with overflow auto - list_selected.undoPositioned(); - }, - - drop_to_list: function(draggable, droppable, event) { - droppable.insert(draggable.remove()); - draggable.setStyle({left: '0px', top: '0px'}); - draggable.down('input').checked = droppable.hasClassName('selected'); - } -}); diff --git a/frontends/default/javascripts/prototype/rico_corner.js b/frontends/default/javascripts/prototype/rico_corner.js deleted file mode 100644 index e6541f1633..0000000000 --- a/frontends/default/javascripts/prototype/rico_corner.js +++ /dev/null @@ -1,370 +0,0 @@ -/** - * - * Copyright 2005 Sabre Airline Solutions - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this - * file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. See the License for the specific language governing permissions - * and limitations under the License. - **/ - - -//-------------------- rico.js -var Rico = { - Version: '1.1.0', - prototypeVersion: parseFloat(Prototype.Version.split(".")[0] + "." + Prototype.Version.split(".")[1]) -} - -//-------------------- ricoColor.js -Rico.Color = Class.create(); - -Rico.Color.prototype = { - - initialize: function(red, green, blue) { - this.rgb = { r: red, g : green, b : blue }; - }, - - blend: function(other) { - this.rgb.r = Math.floor((this.rgb.r + other.rgb.r)/2); - this.rgb.g = Math.floor((this.rgb.g + other.rgb.g)/2); - this.rgb.b = Math.floor((this.rgb.b + other.rgb.b)/2); - }, - - asRGB: function() { - return "rgb(" + this.rgb.r + "," + this.rgb.g + "," + this.rgb.b + ")"; - }, - - asHex: function() { - return "#" + this.rgb.r.toColorPart() + this.rgb.g.toColorPart() + this.rgb.b.toColorPart(); - }, - - asHSB: function() { - return Rico.Color.RGBtoHSB(this.rgb.r, this.rgb.g, this.rgb.b); - }, - - toString: function() { - return this.asHex(); - } - -}; - -Rico.Color.createFromHex = function(hexCode) { - if(hexCode.length==4) { - var shortHexCode = hexCode; - var hexCode = '#'; - for(var i=1;i<4;i++) hexCode += (shortHexCode.charAt(i) + shortHexCode.charAt(i)); - } - if ( hexCode.indexOf('#') == 0 ) - hexCode = hexCode.substring(1); - var red = hexCode.substring(0,2); - var green = hexCode.substring(2,4); - var blue = hexCode.substring(4,6); - return new Rico.Color( parseInt(red,16), parseInt(green,16), parseInt(blue,16) ); -} - -/** - * Factory method for creating a color from the background of - * an HTML element. - */ -Rico.Color.createColorFromBackground = function(elem) { - - //var actualColor = RicoUtil.getElementsComputedStyle($(elem), "backgroundColor", "background-color"); // Changed to prototype style - var actualColor = $(elem).getStyle('backgroundColor'); - - if ( actualColor == "transparent" && elem.parentNode ) - return Rico.Color.createColorFromBackground(elem.parentNode); - - if ( actualColor == null ) - return new Rico.Color(255,255,255); - - if ( actualColor.indexOf("rgb(") == 0 ) { - var colors = actualColor.substring(4, actualColor.length - 1 ); - var colorArray = colors.split(","); - return new Rico.Color( parseInt( colorArray[0] ), - parseInt( colorArray[1] ), - parseInt( colorArray[2] ) ); - - } - else if ( actualColor.indexOf("#") == 0 ) { - return Rico.Color.createFromHex(actualColor); - } - else - return new Rico.Color(255,255,255); -} - -/* next two functions changed to mootools color.js functions */ -Rico.Color.HSBtoRGB = function(hue, saturation, brightness) { - - var br = Math.round(brightness / 100 * 255); - if (this[1] == 0){ - return [br, br, br]; - } else { - var hue = this[0] % 360; - var f = hue % 60; - var p = Math.round((brightness * (100 - saturation)) / 10000 * 255); - var q = Math.round((brightness * (6000 - saturation * f)) / 600000 * 255); - var t = Math.round((brightness * (6000 - saturation * (60 - f))) / 600000 * 255); - switch(Math.floor(hue / 60)){ - case 0: return { r : br, g : t, b : p }; - case 1: return { r : q, g : br, b : p }; - case 2: return { r : p, g : br, b : t }; - case 3: return { r : p, g : q, b : br }; - case 4: return { r : t, g : p, b : br }; - case 5: return { r : br, g : p, b : q }; - } - } - return false; - } - -Rico.Color.RGBtoHSB = function(red, green, blue) { - var hue, saturation, brightness; - var max = Math.max(red, green, blue), min = Math.min(red, green, blue); - var delta = max - min; - brightness = max / 255; - saturation = (max != 0) ? delta / max : 0; - if (saturation == 0){ - hue = 0; - } else { - var rr = (max - red) / delta; - var gr = (max - green) / delta; - var br = (max - blue) / delta; - if (red == max) hue = br - gr; - else if (green == max) hue = 2 + rr - br; - else hue = 4 + gr - rr; - hue /= 6; - if (hue < 0) hue++; - } - return { h : Math.round(hue * 360), s : Math.round(saturation * 100), b : Math.round(brightness * 100)}; -} - - -//-------------------- ricoCorner.js -Rico.Corner = { - - round: function(e, options) { - var e = $(e); - this._setOptions(options); - - var color = this.options.color; - if ( this.options.color == "fromElement" ) - color = this._background(e); - - var bgColor = this.options.bgColor; - if ( this.options.bgColor == "fromParent" ) - bgColor = this._background(e.offsetParent); - - this._roundCornersImpl(e, color, bgColor); - }, - - _roundCornersImpl: function(e, color, bgColor) { - if(this.options.border) - this._renderBorder(e,bgColor); - if(this._isTopRounded()) - this._roundTopCorners(e,color,bgColor); - if(this._isBottomRounded()) - this._roundBottomCorners(e,color,bgColor); - }, - - _renderBorder: function(el,bgColor) { - var borderValue = "1px solid " + this._borderColor(bgColor); - var borderL = "border-left: " + borderValue; - var borderR = "border-right: " + borderValue; - var style = "style='" + borderL + ";" + borderR + "'"; - el.innerHTML = "<div " + style + ">" + el.innerHTML + "</div>" - }, - - _roundTopCorners: function(el, color, bgColor) { - var corner = this._createCorner(bgColor); - for(var i=0 ; i < this.options.numSlices ; i++ ) - corner.appendChild(this._createCornerSlice(color,bgColor,i,"top")); - el.style.paddingTop = 0; - el.insertBefore(corner,el.firstChild); - }, - - _roundBottomCorners: function(el, color, bgColor) { - var corner = this._createCorner(bgColor); - for(var i=(this.options.numSlices-1) ; i >= 0 ; i-- ) - corner.appendChild(this._createCornerSlice(color,bgColor,i,"bottom")); - el.style.paddingBottom = 0; - el.appendChild(corner); - }, - - _createCorner: function(bgColor) { - var corner = document.createElement("div"); - corner.style.backgroundColor = (this._isTransparent() ? "transparent" : bgColor); - return corner; - }, - - _createCornerSlice: function(color,bgColor, n, position) { - var slice = document.createElement("span"); - - var inStyle = slice.style; - inStyle.backgroundColor = color; - inStyle.display = "block"; - inStyle.height = "1px"; - inStyle.overflow = "hidden"; - inStyle.fontSize = "1px"; - - var borderColor = this._borderColor(color,bgColor); - if ( this.options.border && n == 0 ) { - inStyle.borderTopStyle = "solid"; - inStyle.borderTopWidth = "1px"; - inStyle.borderLeftWidth = "0px"; - inStyle.borderRightWidth = "0px"; - inStyle.borderBottomWidth = "0px"; - inStyle.height = "0px"; // assumes css compliant box model - inStyle.borderColor = borderColor; - } - else if(borderColor) { - inStyle.borderColor = borderColor; - inStyle.borderStyle = "solid"; - inStyle.borderWidth = "0px 1px"; - } - - if ( !this.options.compact && (n == (this.options.numSlices-1)) ) - inStyle.height = "2px"; - - this._setMargin(slice, n, position); - this._setBorder(slice, n, position); - return slice; - }, - - _setOptions: function(options) { - this.options = { - corners : "all", - color : "fromElement", - bgColor : "fromParent", - blend : true, - border : false, - compact : false - } - Object.extend(this.options, options || {}); - - this.options.numSlices = this.options.compact ? 2 : 4; - if ( this._isTransparent() ) - this.options.blend = false; - }, - - _whichSideTop: function() { - if ( this._hasString(this.options.corners, "all", "top") ) - return ""; - - if ( this.options.corners.indexOf("tl") >= 0 && this.options.corners.indexOf("tr") >= 0 ) - return ""; - - if (this.options.corners.indexOf("tl") >= 0) - return "left"; - else if (this.options.corners.indexOf("tr") >= 0) - return "right"; - return ""; - }, - - _whichSideBottom: function() { - if ( this._hasString(this.options.corners, "all", "bottom") ) - return ""; - - if ( this.options.corners.indexOf("bl")>=0 && this.options.corners.indexOf("br")>=0 ) - return ""; - - if(this.options.corners.indexOf("bl") >=0) - return "left"; - else if(this.options.corners.indexOf("br")>=0) - return "right"; - return ""; - }, - - _borderColor : function(color,bgColor) { - if ( color == "transparent" ) - return bgColor; - else if ( this.options.border ) - return this.options.border; - else if ( this.options.blend ) - return this._blend( bgColor, color ); - else - return ""; - }, - - - _setMargin: function(el, n, corners) { - var marginSize = this._marginSize(n); - var whichSide = corners == "top" ? this._whichSideTop() : this._whichSideBottom(); - - if ( whichSide == "left" ) { - el.style.marginLeft = marginSize + "px"; el.style.marginRight = "0px"; - } - else if ( whichSide == "right" ) { - el.style.marginRight = marginSize + "px"; el.style.marginLeft = "0px"; - } - else { - el.style.marginLeft = marginSize + "px"; el.style.marginRight = marginSize + "px"; - } - }, - - _setBorder: function(el,n,corners) { - var borderSize = this._borderSize(n); - var whichSide = corners == "top" ? this._whichSideTop() : this._whichSideBottom(); - if ( whichSide == "left" ) { - el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = "0px"; - } - else if ( whichSide == "right" ) { - el.style.borderRightWidth = borderSize + "px"; el.style.borderLeftWidth = "0px"; - } - else { - el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = borderSize + "px"; - } - if (this.options.border != false) - el.style.borderLeftWidth = borderSize + "px"; el.style.borderRightWidth = borderSize + "px"; - }, - - _marginSize: function(n) { - if ( this._isTransparent() ) - return 0; - - var marginSizes = [ 5, 3, 2, 1 ]; - var blendedMarginSizes = [ 3, 2, 1, 0 ]; - var compactMarginSizes = [ 2, 1 ]; - var smBlendedMarginSizes = [ 1, 0 ]; - - if ( this.options.compact && this.options.blend ) - return smBlendedMarginSizes[n]; - else if ( this.options.compact ) - return compactMarginSizes[n]; - else if ( this.options.blend ) - return blendedMarginSizes[n]; - else - return marginSizes[n]; - }, - - _borderSize: function(n) { - var transparentBorderSizes = [ 5, 3, 2, 1 ]; - var blendedBorderSizes = [ 2, 1, 1, 1 ]; - var compactBorderSizes = [ 1, 0 ]; - var actualBorderSizes = [ 0, 2, 0, 0 ]; - - if ( this.options.compact && (this.options.blend || this._isTransparent()) ) - return 1; - else if ( this.options.compact ) - return compactBorderSizes[n]; - else if ( this.options.blend ) - return blendedBorderSizes[n]; - else if ( this.options.border ) - return actualBorderSizes[n]; - else if ( this._isTransparent() ) - return transparentBorderSizes[n]; - return 0; - }, - - _hasString: function(str) { for(var i=1 ; i<arguments.length ; i++) if (str.indexOf(arguments[i]) >= 0) return true; return false; }, - _blend: function(c1, c2) { var cc1 = Rico.Color.createFromHex(c1); cc1.blend(Rico.Color.createFromHex(c2)); return cc1; }, - _background: function(el) { try { return Rico.Color.createColorFromBackground(el).asHex(); } catch(err) { return "#ffffff"; } }, - _isTransparent: function() { return this.options.color == "transparent"; }, - _isTopRounded: function() { return this._hasString(this.options.corners, "all", "top", "tl", "tr"); }, - _isBottomRounded: function() { return this._hasString(this.options.corners, "all", "bottom", "bl", "br"); }, - _hasSingleTextChild: function(el) { return el.childNodes.length == 1 && el.childNodes[0].nodeType == 3; } -} - diff --git a/frontends/default/stylesheets/stylesheet-ie.css b/frontends/default/stylesheets/stylesheet-ie.css deleted file mode 100644 index 7992a64468..0000000000 --- a/frontends/default/stylesheets/stylesheet-ie.css +++ /dev/null @@ -1,35 +0,0 @@ -/* IE hacks - ==================================== */ - -* html .active-scaffold-header, -.active-scaffold li.form-element, -.active-scaffold li.sub-section { -zoom: 1; -} - -* html .active-scaffold td .messages-container { -border-top: solid 1px #DAFFCD; -} - -* html .active-scaffold-header div.actions a.show_search { -background-image: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../../images/active_scaffold/default/magnifier.png', sizingMethod='crop'); -} - -* html .active-scaffold .sub-form .association-record a.destroy { -background-image: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../../images/active_scaffold/default/cross.png', sizingMethod='crop'); -} - -.active-scaffold-header div.actions a.disabled { -filter: alpha(opacity=50); -} - -.active-scaffold .show-view dd, -.active-scaffold li.form-element dd { -float: none; -} - -.active-scaffold li.form-element dt { -padding: 4px 0; -} diff --git a/frontends/default/stylesheets/stylesheet.css b/frontends/default/stylesheets/stylesheet.css deleted file mode 100644 index 01495484c7..0000000000 --- a/frontends/default/stylesheets/stylesheet.css +++ /dev/null @@ -1,1076 +0,0 @@ -/* - ActiveScaffold - (c) 2007 Richard White <rrwhite@gmail.com> - - ActiveScaffold is freely distributable under the terms of an MIT-style license. - - For details, see the ActiveScaffold web site: http://www.activescaffold.com/ -*/ - -.active-scaffold form, -.active-scaffold table, -.active-scaffold p, -.active-scaffold div, -.active-scaffold fieldset { -margin: 0; -padding: 0; -} - -.active-scaffold { -margin: 5px 0; -} - -.active-scaffold table { -width: 100%; -border-collapse: separate; -} - -.active-scaffold a, -.active-scaffold a:visited { -color: #06c; -text-decoration: none; -} - -.active-scaffold a.disabled { -color: #999; -} - -.active-scaffold a:hover, .active-scaffold div.hover, .active-scaffold td span.hover { -background-color: #ff8; -} - -.active-scaffold div.actions a img, -.active-scaffold td.actions a img { -border: none; -vertical-align: middle; -} - -.active-scaffold div.actions a.disabled img, -.active-scaffold td.actions a.disabled img { -opacity: 0.5; -} - -.active-scaffold .clear-fix { -clear: both; -} - -noscript.active-scaffold { -border-left: solid 5px #f66; -background-color: #fbb; -font-size: 11px; -font-weight: bold; -padding: 5px 20px 5px 5px; -color: #333; -} - -/* Header - ======================== */ - -.active-scaffold-header { -position: relative; -} - -.blue-theme .active-scaffold-header { -background-color: #005CB8; -} - -.active-scaffold-header h2 { -padding: 2px 0px; -margin: 0; -color: #555; -font: bold 160% arial, sans-serif; -} - -.blue-theme .active-scaffold-header h2 { -color: #fff; -padding: 2px 5px 4px 5px; -} - -.active-scaffold-header div.actions a, -.active-scaffold-header div.actions { -float: right; -font: bold 14px arial; -letter-spacing: -1px; -text-decoration: none; -padding: 1px 2px; -white-space: nowrap; -margin-left: 5px; -background-position: 1px 50%; -background-repeat: no-repeat; -} - -.active-scaffold-header div.actions a { -padding: 5px 5px; -margin-left: 0px; -} - -.active-scaffold .active-scaffold .active-scaffold-header div.actions > a { -padding: 1px 5px; -} - -.active-scaffold-header div.actions div.action_group { -display: inline; -float: right; -} - -.active-scaffold-header div.actions div.action_group li a, -.active-scaffold-header div.actions div.action_group li div { -float: none; -margin: 0; -} - -.active-scaffold-header div.actions .action_group ul { -line-height: 130%; -top: 19px; -} - -.active-scaffold .active-scaffold .active-scaffold-header div.actions .action_group ul { -top: 14px; -} - -.view .active-scaffold-header div.actions a, -.view .active-scaffold-header div.actions div, -.view .active-scaffold-header div.actions div.action_group { -float: left; -} - -.blue-theme .active-scaffold-header div.actions a { -color: #fff; -} - -.active-scaffold-header div.actions a.disabled { -color: #666; -opacity: 0.5; -} - -.blue-theme .active-scaffold-header div.actions a.disabled { -color: #fff; -opacity: 0.5; -} - -.active-scaffold-header div.actions a.new, -.active-scaffold-header div.actions a.new_existing, -.active-scaffold-header div.actions a.show_search, -.active-scaffold-header div.actions a.show_config_list, -.active-scaffold-header div.actions div.action_group div { -margin:0; -padding: 5px 5px 5px 25px; -background-position: 5px 50%; -background-repeat: no-repeat; -} - -.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.new, -.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.new_existing, -.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.show_search, -.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.show_config_list, -.active-scaffold .active-scaffold .active-scaffold-header div.actions div.action_group > div { -margin:0; -padding: 1px 5px 1px 20px; -background-position: 1px 50%; -background-repeat: no-repeat; -} - -.active-scaffold-header div.actions div.action_group div { - background-image: url(../../../images/active_scaffold/default/gears.png); /* default icon for actions or override with css */ -} - -.active-scaffold-header div.actions a.show_config_list { - background-image: url(../../../images/active_scaffold/default/config.png); -} - -.active-scaffold-header div.actions a.new, -.active-scaffold-header div.actions a.new_existing { -background-image: url(../../../images/active_scaffold/default/add.gif); -} - -.active-scaffold-header div.actions a.show_search { -background-image: url(../../../images/active_scaffold/default/magnifier.png); -} - -.blue-theme .active-scaffold-header div.actions a:hover { -background-color: #378CDF; -} - -.active-scaffold-header div.actions a.disabled:hover { -background-color: transparent; -cursor: default; -} - -.active-scaffold-header div.actions { -position: absolute; -right: 5px; -top: 5px; -text-align: right; -} - -/* Table :: Column Headers - ============================= */ - -.active-scaffold th { -background-color: #555; -text-align: left; -} - -.active-scaffold th a, -.active-scaffold th p { -font: bold 11px arial, sans-serif; -display: block; -background-color: #555; -} - -.active-scaffold th a, .active-scaffold th a:visited { -color: #fff; -padding: 2px 2px 2px 5px; -} - -.active-scaffold th p { -color: #eee; -padding: 2px 5px; -} - -.active-scaffold th a:hover { -background-color: #000; -color: #ff8; -} - -.active-scaffold th.sorted { -background-color: #333; -} - -.active-scaffold th.sorted a { -padding-right: 18px; -} - -.active-scaffold th.asc a, -.active-scaffold th.asc a:hover { -background: #333 url(../../../images/active_scaffold/default/arrow_up.gif) right 50% no-repeat; -} - -.active-scaffold th.desc a, -.active-scaffold th.desc a:hover { -background: #333 url(../../../images/active_scaffold/default/arrow_down.gif) right 50% no-repeat; -} - -.active-scaffold th.loading a, -.active-scaffold th.loading a:hover { -background: #333 url(../../../images/active_scaffold/default/indicator-small.gif) right 50% no-repeat; -} - -.active-scaffold th .mark_heading { -margin-left: 5px; -} - -/* Table :: Record Rows - ============================= */ - -.active-scaffold tr.record { - background-color: #E6F2FF; -} -.active-scaffold tr.record td { -padding: 5px 4px; -color: #333; -font-family: Verdana, sans-serif; -font-size: 11px; -border-bottom: solid 1px #C5DBF7; -border-left: solid 1px #C5DBF7; -} - -.active-scaffold tr.record td.messages-container { -padding: 0px; -} - -.active-scaffold tr.even-record { -background-color: #fff; -} -.active-scaffold tr.even-record td { -border-left-color: #ddd; -} - -.active-scaffold tr.record td.sorted { -background-color: #B9DCFF; -border-bottom-color: #AFD0F5; -} - -.active-scaffold tr.even-record td.sorted { -background-color: #E6F2FF; -border-bottom-color: #AFD0F5; -} - -.active-scaffold tbody.records td.empty { -color: #999; -text-align: center; -} - -.active-scaffold td.numeric, -.active-scaffold-calculations td { -text-align: right; -} - -/* Table :: Actions (Edit, Delete) - ============================= */ -.active-scaffold tr.record td.actions { -border-right: solid 1px #ccc; -padding: 0; -min-width: 1%; -} - -.active-scaffold tr.record td.actions table { -float: right; -width: auto; -margin-right: 5px; -} - -.active-scaffold tr.record td.actions table td { -border: none; -text-align: right; -padding: 0 2px; -} - -.active-scaffold tr.record td.actions a, -.active-scaffold tr.record td.actions div { -font: bold 11px verdana, sans-serif; -letter-spacing: -1px; -padding: 2px; -margin: 0 2px; -line-height: 16px; -white-space: nowrap; -} - -.active-scaffold tr.record td.actions a.disabled { -color: #666; -opacity: 0.5; -} - -.active-scaffold .actions .action_group div:hover { -background-color: #ff8; -} - -.active-scaffold .actions .action_group { -position: relative; -text-align: left; -color: #0066CC; -} - -.active-scaffold .actions .action_group ul { -border: 2px solid #005CB8; -list-style-type: none; -margin: 0; -padding: 0; -position: absolute; -line-height: 200%; -display: none; -width: 150px; -right: 0px; -} - -.active-scaffold .actions .action_group ul ul { -display: none; -position: absolute; -top: 0; -right: 150px; -} - -.active-scaffold .actions .action_group ul li { -background: none repeat scroll 0 0 #EEE; -border-top: 1px dashed #222; -display: block; -position: relative; -width: auto; -z-index: 2; -} - -.active-scaffold .actions .action_group ul li div { - margin: 0; - padding: 5px 5px 5px 25px; - background-position: 5px 50%; - background-repeat: no-repeat; -} - -.active-scaffold .actions .action_group ul li a { - display: block; - color: #333; - margin: 0; - padding: 5px 5px 5px 25px; - background-position: 5px 50%; - background-repeat: no-repeat; -} - -.active-scaffold .actions .action_group ul li.top { -border-top: 0px solid #005CB8; -} - -.active-scaffold .actions .action_group:hover ul ul, -.active-scaffold .actions .action_group:hover ul ul ul { -display: none; -} - -.active-scaffold .actions .action_group:hover ul, -.active-scaffold .actions .action_group ul li:hover > ul, -.active-scaffold .actions .action_group ul ul li:hover ul { -display: block; -} - -/* Table :: Inline Adapter - ============================= */ - -.active-scaffold .view { -background-color: #DAFFCD; -padding: 4px; -border: solid 1px #7FcF00; -} - -.active-scaffold tbody.records td.inline-adapter-cell .view { -border-top: none; -} - -.active-scaffold .before-header td.inline-adapter-cell .view { -border-bottom: none; -} - -.active-scaffold a.inline-adapter-close { -float: right; -text-indent: -4000px; -width: 16px; -height: 17px; -background: url(../../../images/active_scaffold/default/close.gif) 0 0 no-repeat; -} - -/* Nested - ======================== */ - -.blue-theme .active-scaffold .active-scaffold-header, -.blue-theme .active-scaffold .active-scaffold-footer { -background-color: #1F7F00; - -background: transparent; -} - -.active-scaffold .active-scaffold .active-scaffold-header { -margin-right: 15px; -} - -.active-scaffold .active-scaffold .active-scaffold-header h2 { -font-size: 12px; -font-weight: bold; -} - -.blue-theme .active-scaffold .active-scaffold-header h2, -.active-scaffold .active-scaffold .active-scaffold-footer { -color: #444; -} - -.active-scaffold .active-scaffold .active-scaffold-header div.actions { -top: 0px; -right: 0px; -} - -.active-scaffold .active-scaffold .active-scaffold-header div.actions a, -.active-scaffold .active-scaffold .active-scaffold-header div.actions div { -font: bold 11px verdana, sans-serif; -} - -.blue-theme .active-scaffold .active-scaffold-header div.actions a, -.blue-theme .active-scaffold .active-scaffold-header div.actions a:visited { -color: #06c; -} - -.blue-theme .active-scaffold .active-scaffold-header div.actions a:hover { -background-color: #ff8; -} - -.active-scaffold .active-scaffold .view { -background-color: transparent; -padding: 0px; -border: none; -} - -.active-scaffold .active-scaffold td { -background-color: #ECFFE7; -border-bottom: solid 1px #CDF7C5; -border-left: solid 1px #CDF7C5; -} - -.active-scaffold .active-scaffold td.inline-adapter-cell { -background-color: #FFFFBB; -padding: 4px; -border: solid 1px #DDDF37; -border-top: none; -} - -.active-scaffold .active-scaffold .active-scaffold td.inline-adapter-cell { -background-color: #DAFFCD; -padding: 4px; -border: solid 1px #7FcF00; -border-top: none; -} - -.active-scaffold .active-scaffold .active-scaffold-footer { -font-size: 11px; -} - -/* Footer - ========================== */ - -.active-scaffold-calculations td { -background-color: #eee; -border-top: 2px solid #005CB8; -font: bold 12px arial, sans-serif; -} - -.active-scaffold .active-scaffold-footer { -padding: 3px 0px 2px 0px; -border-bottom: none; -font: bold 12px arial, sans-serif; -} - -.blue-theme .active-scaffold-footer { -background-color: #005CB8; -color: #ccc; -} - -.active-scaffold-footer .active-scaffold-pagination { -float: right; -white-space: nowrap; -margin-right: 5px; -} - -.blue-theme .active-scaffold-footer .active-scaffold-records { -margin-left: 5px; -} - -.active-scaffold-footer a { -text-decoration: none; -letter-spacing: 0; -padding: 0 2px; -margin: 0 -2px; -font: bold 12px arial, sans-serif; -} - -.blue-theme .active-scaffold-footer a, -.blue-theme .active-scaffold-footer a:visited { -color: #fff; -} - -.blue-theme .active-scaffold-footer a:hover { -background-color: #378CDF; -} - -.active-scaffold-footer .next { -margin-left: 0; -padding-left: 5px; -border-left: solid 1px #ccc; -} - -.active-scaffold-footer .previous { -margin-right: 0; -padding-right: 5px; -border-right: solid 1px #ccc; -} - -/* Messages - ========================= */ - -.active-scaffold .messages-container, -.active-scaffold .active-scaffold .messages-container{ -padding: 0; -margin: 0 7px; -border: none; -} - -.active-scaffold .empty-message, .active-scaffold .filtered-message { -background-color: #e8e8e8; -padding: 4px; -text-align: center; -color: #666; -} - -.active-scaffold .message { -font-size: 11px; -font-weight: bold; -padding: 5px 20px 5px 5px; -color: #333; -position: relative; -margin: 2px 7px; -line-height: 12px; -} - -.active-scaffold .message a { -position: absolute; -right: 10px; -top: 4px; -padding: 0; -font: bold 11px verdana, sans-serif; -letter-spacing: -1px; -} - -.active-scaffold .messages-container .message { -margin: 0; -} - -.active-scaffold .error-message { -border-left: solid 5px #f66; -background-color: #fbb; -} - -.active-scaffold .warning-message { -border-left: solid 5px #ff6; -background-color: #ffb; -} - -.active-scaffold .info-message { -border-left: solid 5px #66f; -background-color: #bbf; -} - -/* Error Styling - ========================== */ - -.active-scaffold .errorExplanation { -background-color: #fcc; -margin: 2px 0; -border: solid 1px #f66; -} - -.active-scaffold fieldset { -clear: both; -} - -.active-scaffold .errorExplanation h2 { -padding: 2px 5px; -color: #333; -font-size: 11px; -margin: 0; -letter-spacing: 0; -font-family: Verdana; -background-color: #f66; -} - -.active-scaffold .errorExplanation ul { -margin: 0; -padding: 0 2px 4px 25px; -list-style: disc; -} - -.active-scaffold .errorExplanation p { -font-size: 11px; -padding: 2px 5px; -font-family: Verdana; -margin: 0; -} - -.active-scaffold .errorExplanation ul li { -font: bold 11px verdana; -letter-spacing: -1px; -margin: 0; -padding: 0; -background-color: transparent; -} - -/* Loading Indicators - ============================== */ - -.active-scaffold .loading-indicator { -vertical-align: text-bottom; -width: 16px; -margin: 0; -} - -.active-scaffold .active-scaffold-header .loading-indicator { -margin-bottom: 3px; -} - -/* Show - ============================= */ - -.active-scaffold .show-view dl { -margin-left: 5px; -} - -.active-scaffold .show-view dt { -width: 12em; -float: left; -clear: left; -font: normal 11px verdana, sans-serif; -color: #555; -line-height: 16px; -} - -.active-scaffold .show-view dd { -float: left; -font: bold 14px arial; -padding-left: 5px; -margin-bottom: 5px; -} - -/* Form - ============================== */ - -.active-scaffold .submit { -font-weight: bold; -font-size: 14px; -font-family: Arial, sans-serif; -letter-spacing: 0; -margin: 0; -margin-top: 5px; -} - -.active-scaffold form p { -clear: both; -} - -.active-scaffold fieldset { -border: none; -} - -.active-scaffold h4, -.active-scaffold h5 { -padding: 2px; -margin: 0; -text-transform: none; -color: #1F7F00; -letter-spacing: -1px; -font: bold 16px arial; -} - -.active-scaffold h5 { -padding: 0; -margin: 5px 0 2px 0; -font-size: 14px; -letter-spacing: 0; -} - -.active-scaffold ol { -clear: both; -float: none; -padding: 2px; -margin-left: 5px; -list-style: none; -} - -.active-scaffold p.form-footer { -clear: both; -} - -.active-scaffold a.as_cancel, -.active-scaffold p.form-footer a { -font: bold 14px arial, sans-serif; -letter-spacing: 0; -} - -/* Form :: Fields - ============================== */ - -.active-scaffold li.form-element { -clear: both; -} - -.active-scaffold label { -font: normal 11px verdana, sans-serif; -color: #555; -} - -.active-scaffold li.form-element dt { -float: left; -width: 12em; -padding: 6px 0; -} - -.active-scaffold li.form-element dd { -float: left; -} - -.active-scaffold li.form-element dd input[type="checkbox"] { -margin-top: 6px; -} - -.active-scaffold .form dd { -margin: 0; -} - - -.active-scaffold .description { -display: inline-block; -color: #999; -font-size: 10px; -margin-left: 5px; -} - -.active-scaffold .required label { -font-weight: bold; -} - -.active-scaffold label.example { -font-size: 11px; -font-family: arial; -color: #888; -} - -.active-scaffold input.text-input, -.active-scaffold select { -font: bold 16px arial; -letter-spacing: -1px; -border: solid 1px #1F7F00; -} - -.active-scaffold input.text-input { -padding: 2px; -} - -.active-scaffold .fieldWithErrors input, -.active-scaffold .field_with_errors input, -.active-scaffold .fieldWithErrors textarea, -.active-scaffold .field_with_errors textarea, -.active-scaffold .fieldWithErrors select, -.active-scaffold .field_with_errors select { -border: solid 1px #f00; -} - -.active-scaffold select { -padding: 1px; -} - -.active-scaffold input.example { -color: #aaa; -} - -.active-scaffold select:focus, -.active-scaffold input.text-input:focus { -background-color: #ffc; -} - -.active-scaffold textarea { -font-family: Arial, sans-serif; -font-size: 12px; -padding: 1px; -border: solid 1px #1F7F00; -} - -.active-scaffold .checkbox-list { -padding-left: 0px; -} - -.active-scaffold .checkbox-list li { -padding-right: 5px; -display: inline; -} - -.active-scaffold .checkbox-list li label { -padding: 0 0 0 2px; -} - -.active-scaffold .draggable-list { -float: left; -width: 300px; -margin-right: 15px; -min-height: 30px; -max-height: 100px; -overflow: auto; -background-color: #FFFF88; -} - -.active-scaffold .draggable-list.hover { -opacity: 0.5; -} - -.active-scaffold .draggable-list.selected { -background-color: #7FCF00; -} - -.active-scaffold .draggable-list li { -display: block; -} - -.active-scaffold .draggable-list input { -display: none; -} - -/* Form :: Sub-Sections - ============================== */ - -.active-scaffold li.sub-section { -clear: left; -padding: 5px 0; -} - -/* Form :: Association Sub-Forms - ============================== */ - -.active-scaffold .sub-form { -float: left; -clear: left; -padding: 5px 0; -padding-left: 5px; -} - -.active-scaffold .sub-form h5 { -margin-left: -5px; -} - -.active-scaffold .sub-form table, -.active-scaffold .sub-form table td { -width: auto; -background: none; -} - -.active-scaffold .sub-form table th { -font: normal 10px verdana, sans-serif; -color: #555; -padding: 0 5px 0 1px; -background: none; -} - -.active-scaffold .horizontal-sub-form td dt label { -display: none; -} - -.active-scaffold .sub-form .checkbox-list { -padding: 0 2px 2px 2px; -background-color: #fff; -border: solid 1px #1F7F00; -} - -.active-scaffold .sub-form .checkbox-list label { -display: block; -} - -.active-scaffold .sub-form table td { -border: none; -background-color: transparent; -padding: 1px; -vertical-align: top; -color: #999; -} - -.active-scaffold .sub-form .actions { -vertical-align: middle; -background-color: transparent; -clear: left; -} - -.active-scaffold .sub-form .association-record a.destroy { -font-weight: bold; -display: block; -height: 16px; -padding: 0; -width: 16px; -text-indent: -4000px; -background: url(../../../images/active_scaffold/default/cross.png) 0 0 no-repeat; -} - -.active-scaffold .sub-form .locked a.destroy { -display: none; -} - -.active-scaffold .sub-form .association-record a { -font: bold 12px arial; -} - -.active-scaffold .sub-form input.text-input, -.active-scaffold .sub-form select { -letter-spacing: 0; -font: bold 12px arial; -} - -.active-scaffold .sub-form .footer-wrapper { -margin-top: 3px; -margin-right: 10px; -} - -.active-scaffold .sub-form .footer { -color: #999; -padding: 3px 5px; -} - -.active-scaffold .sub-form .footer select, -.active-scaffold .sub-form .footer input { -font-weight: bold; -font-size: 12px; -padding: 0; -} - -.active-scaffold a.visibility-toggle { -font-size: 100%; -} - -.active-scaffold-found { - float:left; -} - -.as_touch a.inline-adapter-close { -width: 25px; -height: 27px; -background: url(../../../images/active_scaffold/default/close_touch.png) 0 0 no-repeat; -} - -.as_touch .as_paginate { -font-size: 20px; -padding: 3px 10px; -} - -.as_touch .active-scaffold-header div.actions a { -padding: 7px 5px; -} - -.as_touch .active-scaffold .active-scaffold-header div.actions a { -padding: 7px 5px; -} - -.as_touch .active-scaffold-header div.actions .action_group ul { -line-height: 130%; -top: 23px; -} - -.as_touch .active-scaffold .active-scaffold-header div.actions .action_group ul { -top: 23px; -} - -.as_touch .active-scaffold-header div.actions a.new, -.as_touch .active-scaffold-header div.actions a.new_existing, -.as_touch .active-scaffold-header div.actions a.show_search, -.as_touch .active-scaffold-header div.actions a.show_config_list, -.as_touch .active-scaffold-header div.actions div.action_group div { -padding: 7px 5px 7px 25px; -} - -.as_touch .active-scaffold .active-scaffold-header div.actions > a.new, -.as_touch .active-scaffold .active-scaffold-header div.actions > a.new_existing, -.as_touch .active-scaffold .active-scaffold-header div.actions > a.show_search, -.as_touch .active-scaffold .active-scaffold-header div.actions > a.show_config_list, -.as_touch .active-scaffold .active-scaffold-header div.actions div.action_group > div { -padding: 7px 5px 7px 25px; -background-position: 5px 50%; -} - -.as_touch .actions .action_group ul li div { -padding: 7px 5px 7px 25px; -} - -.as_touch .actions .action_group ul li a { -padding: 7px 5px 7px 25px; -} - -.as_touch .active-scaffold-header h2 { -padding: 4px 0px; -} - -.as_touch .active-scaffold .active-scaffold-header div.actions a, -.as_touch .active-scaffold .active-scaffold-header div.actions div { - font: bold 14px arial; -} - -.as_touch .active-scaffold .active-scaffold-header div.actions { - right: 15px; -} - -.as_touch tr.record { -line-height: 130%; -} - -.as_touch th a, .as_touch th a:visited { -color: #fff; -padding: 5px 2px 5px 5px; -} - -.as_touch tr.record td { -padding: 5px 10px; -} \ No newline at end of file From da17baa4dc998c10a515ab03f1b919dc94db6ac7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 18 Jun 2011 23:44:07 +0200 Subject: [PATCH 1139/2024] use asset pipeline for images as well --- .../default => app/assets}/images/add.gif | Bin .../assets}/images/arrow_down.gif | Bin .../assets}/images/arrow_up.gif | Bin .../default => app/assets}/images/close.gif | Bin .../assets}/images/close_touch.png | Bin .../default => app/assets}/images/config.png | Bin .../default => app/assets}/images/cross.png | Bin .../default => app/assets}/images/gears.png | Bin .../assets}/images/indicator-small.gif | Bin .../assets}/images/indicator.gif | Bin .../assets}/images/magnifier.png | Bin ...e_scaffold.css => active_scaffold.css.erb} | 21 +++++++++--------- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 13 files changed, 12 insertions(+), 11 deletions(-) rename {frontends/default => app/assets}/images/add.gif (100%) rename {frontends/default => app/assets}/images/arrow_down.gif (100%) rename {frontends/default => app/assets}/images/arrow_up.gif (100%) rename {frontends/default => app/assets}/images/close.gif (100%) rename {frontends/default => app/assets}/images/close_touch.png (100%) rename {frontends/default => app/assets}/images/config.png (100%) rename {frontends/default => app/assets}/images/cross.png (100%) rename {frontends/default => app/assets}/images/gears.png (100%) rename {frontends/default => app/assets}/images/indicator-small.gif (100%) rename {frontends/default => app/assets}/images/indicator.gif (100%) rename {frontends/default => app/assets}/images/magnifier.png (100%) rename app/assets/stylesheets/{active_scaffold.css => active_scaffold.css.erb} (95%) diff --git a/frontends/default/images/add.gif b/app/assets/images/add.gif similarity index 100% rename from frontends/default/images/add.gif rename to app/assets/images/add.gif diff --git a/frontends/default/images/arrow_down.gif b/app/assets/images/arrow_down.gif similarity index 100% rename from frontends/default/images/arrow_down.gif rename to app/assets/images/arrow_down.gif diff --git a/frontends/default/images/arrow_up.gif b/app/assets/images/arrow_up.gif similarity index 100% rename from frontends/default/images/arrow_up.gif rename to app/assets/images/arrow_up.gif diff --git a/frontends/default/images/close.gif b/app/assets/images/close.gif similarity index 100% rename from frontends/default/images/close.gif rename to app/assets/images/close.gif diff --git a/frontends/default/images/close_touch.png b/app/assets/images/close_touch.png similarity index 100% rename from frontends/default/images/close_touch.png rename to app/assets/images/close_touch.png diff --git a/frontends/default/images/config.png b/app/assets/images/config.png similarity index 100% rename from frontends/default/images/config.png rename to app/assets/images/config.png diff --git a/frontends/default/images/cross.png b/app/assets/images/cross.png similarity index 100% rename from frontends/default/images/cross.png rename to app/assets/images/cross.png diff --git a/frontends/default/images/gears.png b/app/assets/images/gears.png similarity index 100% rename from frontends/default/images/gears.png rename to app/assets/images/gears.png diff --git a/frontends/default/images/indicator-small.gif b/app/assets/images/indicator-small.gif similarity index 100% rename from frontends/default/images/indicator-small.gif rename to app/assets/images/indicator-small.gif diff --git a/frontends/default/images/indicator.gif b/app/assets/images/indicator.gif similarity index 100% rename from frontends/default/images/indicator.gif rename to app/assets/images/indicator.gif diff --git a/frontends/default/images/magnifier.png b/app/assets/images/magnifier.png similarity index 100% rename from frontends/default/images/magnifier.png rename to app/assets/images/magnifier.png diff --git a/app/assets/stylesheets/active_scaffold.css b/app/assets/stylesheets/active_scaffold.css.erb similarity index 95% rename from app/assets/stylesheets/active_scaffold.css rename to app/assets/stylesheets/active_scaffold.css.erb index 01495484c7..d7c2c17709 100644 --- a/app/assets/stylesheets/active_scaffold.css +++ b/app/assets/stylesheets/active_scaffold.css.erb @@ -171,20 +171,21 @@ background-repeat: no-repeat; } .active-scaffold-header div.actions div.action_group div { - background-image: url(../../../images/active_scaffold/default/gears.png); /* default icon for actions or override with css */ + background-image: url(<%= asset_path 'gears.png' %>); /* default icon for actions or override with css */ } .active-scaffold-header div.actions a.show_config_list { - background-image: url(../../../images/active_scaffold/default/config.png); + background-image: url(<%= asset_path 'config.png' %>); } .active-scaffold-header div.actions a.new, .active-scaffold-header div.actions a.new_existing { -background-image: url(../../../images/active_scaffold/default/add.gif); +background-image: url(<%= asset_path 'add.gif' %>); } .active-scaffold-header div.actions a.show_search { -background-image: url(../../../images/active_scaffold/default/magnifier.png); + +background-image: url(<%= asset_path 'magnifier.png' %>); } .blue-theme .active-scaffold-header div.actions a:hover { @@ -243,17 +244,17 @@ padding-right: 18px; .active-scaffold th.asc a, .active-scaffold th.asc a:hover { -background: #333 url(../../../images/active_scaffold/default/arrow_up.gif) right 50% no-repeat; +background: #333 url(<%= asset_path 'arrow_up.gif' %>) right 50% no-repeat; } .active-scaffold th.desc a, .active-scaffold th.desc a:hover { -background: #333 url(../../../images/active_scaffold/default/arrow_down.gif) right 50% no-repeat; +background: #333 url(<%= asset_path 'arrow_down.gif' %>) right 50% no-repeat; } .active-scaffold th.loading a, .active-scaffold th.loading a:hover { -background: #333 url(../../../images/active_scaffold/default/indicator-small.gif) right 50% no-repeat; +background: #333 url(<%= asset_path 'indicator-small.gif' %>) right 50% no-repeat; } .active-scaffold th .mark_heading { @@ -432,7 +433,7 @@ float: right; text-indent: -4000px; width: 16px; height: 17px; -background: url(../../../images/active_scaffold/default/close.gif) 0 0 no-repeat; +background: url(<%= asset_path 'close.gif' %>) 0 0 no-repeat; } /* Nested @@ -954,7 +955,7 @@ height: 16px; padding: 0; width: 16px; text-indent: -4000px; -background: url(../../../images/active_scaffold/default/cross.png) 0 0 no-repeat; +background: url(<%= asset_path 'cross.png' %>) 0 0 no-repeat; } .active-scaffold .sub-form .locked a.destroy { @@ -999,7 +1000,7 @@ font-size: 100%; .as_touch a.inline-adapter-close { width: 25px; height: 27px; -background: url(../../../images/active_scaffold/default/close_touch.png) 0 0 no-repeat; +background: url(<%= asset_path 'close_touch.png' %>) 0 0 no-repeat; } .as_touch .as_paginate { diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 2f0dc59aeb..e2a04f1761 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -114,7 +114,7 @@ def active_scaffold_includes(*args) # a general-use loading indicator (the "stuff is happening, please wait" feedback) def loading_indicator_tag(options) - image_tag "/images/active_scaffold/default/indicator.gif", :style => "visibility:hidden;", :id => loading_indicator_id(options), :alt => "loading indicator", :class => "loading-indicator" + image_tag "indicator.gif", :style => "visibility:hidden;", :id => loading_indicator_id(options), :alt => "loading indicator", :class => "loading-indicator" end # Creates a javascript-based link that toggles the visibility of some element on the page. From 0cc27633c5682bfa891b6c801371e85222a308ca Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sun, 19 Jun 2011 00:08:41 +0200 Subject: [PATCH 1140/2024] template_exists? deactivated for rails 3.1 so far which means override_subform_partial cannot be found --- .../extensions/action_view_rendering.rb | 22 ------------------- .../helpers/form_column_helpers.rb | 4 ++-- lib/active_scaffold/helpers/view_helpers.rb | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index b9b55a0ff3..fd1f877556 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -100,27 +100,5 @@ def render_with_active_scaffold(*args, &block) end alias_method_chain :render, :active_scaffold - - def partial_pieces(partial_path) - if partial_path.include?('/') - return File.dirname(partial_path), File.basename(partial_path) - else - return controller.class.controller_path, partial_path - end - end - - # This is the template finder logic, keep it updated with however we find stuff in rails - # currently this very similar to the logic in ActionBase::Base.render for options file - # TODO: Work with rails core team to find a better way to check for this. - def template_exists?(template_name, lookup_overrides = false) - begin - method = 'find_template' - method << '_without_active_scaffold' unless lookup_overrides - self.view_paths.send(method, template_name, @template_format) - return true - rescue ActionView::MissingTemplate => e - return false - end - end end end diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 4298e0dcf0..f96a5ec368 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -245,7 +245,7 @@ def onsubmit # add functionality for overriding subform partials from association class path def override_subform_partial?(column, subform_partial) path, partial_name = partial_pieces(override_subform_partial(column, subform_partial)) - template_exists?(partial_name, path, true) + template_exists?(partial_name, path) end def override_subform_partial(column, subform_partial) @@ -254,7 +254,7 @@ def override_subform_partial(column, subform_partial) def override_form_field_partial?(column) path, partial_name = partial_pieces(override_form_field_partial(column)) - template_exists?(partial_name, path, true) + template_exists?(partial_name, path) end # the naming convention for overriding form fields with partials diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index e2a04f1761..bfe8a14dff 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -43,6 +43,28 @@ def controller_path_for_activerecord(klass) end end + def partial_pieces(partial_path) + if partial_path.include?('/') + return File.dirname(partial_path), File.basename(partial_path) + else + return controller.class.controller_path, partial_path + end + end + + # This is the template finder logic, keep it updated with however we find stuff in rails + # currently this very similar to the logic in ActionBase::Base.render for options file + # TODO: Work with rails core team to find a better way to check for this. + # Not working so far for rais 3.1 + def template_exists?(template_name, path) + begin + method = 'find_template' + #self.view_paths.send(method, template_name) + return false + rescue ActionView::MissingTemplate => e + return false + end + end + def generate_temporary_id (Time.now.to_f*1000).to_i.to_s end From ca6dd59f268f7373a9d58bf717a75d745ddb3f66 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 24 Jun 2011 19:09:59 +0200 Subject: [PATCH 1141/2024] fix set_sorting by order_clause in case it s not a string --- lib/active_scaffold/data_structures/sorting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 753f697e5f..d205fd1028 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -128,7 +128,7 @@ def default_sorting? def set_sorting_from_order_clause(order_clause, model_table_name = nil) clear - order_clause.split(',').each do |criterion| + order_clause.to_s.split(',').each do |criterion| unless criterion.blank? order_parts = extract_order_parts(criterion) add(order_parts[:column_name], order_parts[:direction]) unless different_table?(model_table_name, order_parts[:table_name]) From 999dc3f72751568b9863d463528219f8c6f10bf9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 24 Jun 2011 19:14:06 +0200 Subject: [PATCH 1142/2024] Bugfix: call html_safe in action_link_html --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index bfe8a14dff..c3fbc26a30 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -231,7 +231,7 @@ def action_link_html(link, url, html_options, record) html = link_to(image_tag(link.image[:name] , :size => link.image[:size], :alt => label), url, html_options) end # if url is nil we would like to generate an anchor without href attribute - url.nil? ? html.sub(/href=".*?"/, '') : html + url.nil? ? html.sub(/href=".*?"/, '').html_safe : html.html_safe end def url_options_for_nested_link(column, record, link, url_options, options = {}) From d769881efb468c28f319d14a8cc9fe62eb92bab9 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 24 Jun 2011 19:16:09 +0200 Subject: [PATCH 1143/2024] update master -> rails-3.1 --- README | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README b/README index 888bccea77..c027d72480 100644 --- a/README +++ b/README @@ -20,7 +20,8 @@ http://code.google.com/p/recordselect/ Please note the following list of Active Scaffold branches and Rails versions. Master will not work with Rails < 2.2 -Active Scaffold master currently supports rails-2.3.5, but incompatible changes can be introduced, if you want an stable version, use rails-2.3 +Active Scaffold master currently supports rails-3.1, but incompatible changes can be introduced, if you want an stable version, use rails-2.3 +Rails 3.0.*: Active Scaffold rails-3.0 Rails 2.3.*: Active Scaffold rails-2.3 Rails 2.2.*: Active Scaffold rails-2.2 Rails 2.1.*: Active Scaffold rails-2.1 @@ -42,8 +43,8 @@ If you want to install as plugins under vendor/plugins, install these versions: If you want to use the gem, add to your Gemfile: gem "active_scaffold_vho" -In case you would like to use most recent commit with rails 3.0: - gem 'active_scaffold_vho', :git => 'git://github.com/vhochstein/active_scaffold.git, :branch => 'rails-3.0' +In case you would like to use most recent commit: + gem 'active_scaffold_vho', :git => 'git://github.com/vhochstein/active_scaffold.git', :branch => 'rails-3.0' == Pick your own javascript framework @@ -66,4 +67,8 @@ To configure the javascript framework when installed as a gem: Add a config/initializers/active_scaffold.rb containing: ActiveScaffold.js_framework = :jquery # :prototype is the default +== Rails 3.1 compatible fork of activesaffold by Volker Hochstein: +under construction + + Released under the MIT license (included) From a033d3a46a7ac3431796378ba1e19c31f2d83f43 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 24 Jun 2011 21:19:18 +0200 Subject: [PATCH 1144/2024] country_helper moved to bridge (issue 159 reported by ssinghi) --- lib/active_scaffold/bridges/country_helper/bridge.rb | 9 +++++++++ .../country_helper/lib/country_helper_bridge.rb} | 8 +++++++- lib/active_scaffold/helpers/view_helpers.rb | 1 - 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 lib/active_scaffold/bridges/country_helper/bridge.rb rename lib/active_scaffold/{helpers/country_helpers.rb => bridges/country_helper/lib/country_helper_bridge.rb} (98%) diff --git a/lib/active_scaffold/bridges/country_helper/bridge.rb b/lib/active_scaffold/bridges/country_helper/bridge.rb new file mode 100644 index 0000000000..644e8f897a --- /dev/null +++ b/lib/active_scaffold/bridges/country_helper/bridge.rb @@ -0,0 +1,9 @@ +ActiveScaffold::Bridges.bridge "CountryHelper" do + install do + require File.join(File.dirname(__FILE__), "lib/country_helper_bridge.rb") + end + + install? do + true + end +end diff --git a/lib/active_scaffold/helpers/country_helpers.rb b/lib/active_scaffold/bridges/country_helper/lib/country_helper_bridge.rb similarity index 98% rename from lib/active_scaffold/helpers/country_helpers.rb rename to lib/active_scaffold/bridges/country_helper/lib/country_helper_bridge.rb index fd46de1f15..1e452127fd 100644 --- a/lib/active_scaffold/helpers/country_helpers.rb +++ b/lib/active_scaffold/bridges/country_helper/lib/country_helper_bridge.rb @@ -1,5 +1,5 @@ module ActiveScaffold - module Helpers + module CountryHelperBridge module CountryHelpers # Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags. def country_select(object, method, priority_countries = nil, options = {}, html_options = {}) @@ -350,3 +350,9 @@ def active_scaffold_search_usa_state(column, options) end end end + +ActionView::Base.class_eval do + include ActiveScaffold::CountryHelperBridge::CountryHelpers + include ActiveScaffold::CountryHelperBridge::FormColumnHelpers + include ActiveScaffold::CountryHelperBridge::SearchColumnHelpers +end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index c3fbc26a30..6655f1a2a9 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -10,7 +10,6 @@ module ViewHelpers include ActiveScaffold::Helpers::ShowColumnHelpers include ActiveScaffold::Helpers::FormColumnHelpers include ActiveScaffold::Helpers::SearchColumnHelpers - include ActiveScaffold::Helpers::CountryHelpers include ActiveScaffold::Helpers::HumanConditionHelpers ## From 9e35aa00cd46d6203e09da78243bf089ba97461d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Fri, 24 Jun 2011 22:05:55 +0200 Subject: [PATCH 1145/2024] replace with new button (issue 130 reported by jsurrett) --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 6655f1a2a9..41255275d0 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -323,7 +323,7 @@ def column_show_add_existing(column) end def column_show_add_new(column, associated, record) - value = column.plural_association? || (column.singular_association? and not associated.empty?) + value = (column.plural_association? && !column.readonly_association?) || (column.singular_association? and not associated.empty?) value = false unless record.class.authorized_for?(:crud_type => :create) value end From 97abdcdc449a17c83dd1872725b3809181114b0f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 30 Jun 2011 20:17:37 +0200 Subject: [PATCH 1146/2024] !!!list_column override add column parameter !!! all list column helper overrides should have same method signature --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 01ad606831..42e306084f 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -10,7 +10,7 @@ def get_column_value(record, column) # we only pass the record as the argument. we previously also passed the formatted_value, # but mike perham pointed out that prohibited the usage of overrides to improve on the # performance of our default formatting. see issue #138. - send(column_override(column), record) + send(column_override(column), column, record) # second, check if the dev has specified a valid list_ui for this column elsif column.list_ui and override_column_ui?(column.list_ui) send(override_column_ui(column.list_ui), column, record) From 0de3b285511d1ee459f5e87af6098f67925942d8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 2 Jul 2011 13:22:09 +0200 Subject: [PATCH 1147/2024] add date_picker_bridge js file to asset pipeline --- app/assets/javascripts/active_scaffold.js.erb | 1 + .../jquery/date_picker_bridge.js.erb | 2 + .../bridges/date_picker/bridge.rb | 5 +- .../date_picker/lib/datepicker_bridge.rb | 135 +++++++++++------- 4 files changed, 88 insertions(+), 55 deletions(-) rename lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js => app/assets/javascripts/jquery/date_picker_bridge.js.erb (91%) diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index fbd1b3a7aa..1b777cb124 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -1,6 +1,7 @@ <% if ActiveScaffold.js_framework == :jquery %> <% require_asset "jquery/active_scaffold" %> <% require_asset "jquery/jquery.editinplace" %> +<% require_asset "jquery/date_picker_bridge" %> <% else %> <% require_asset "prototype/active_scaffold" %> <% require_asset "prototype/dhtml_history" %> diff --git a/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js b/app/assets/javascripts/jquery/date_picker_bridge.js.erb similarity index 91% rename from lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js rename to app/assets/javascripts/jquery/date_picker_bridge.js.erb index 6a4b864b73..5ed5b5aef0 100644 --- a/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +++ b/app/assets/javascripts/jquery/date_picker_bridge.js.erb @@ -1,3 +1,5 @@ +<%= ActiveScaffold::Bridges::DatePickerBridge.localization %> + $(document).ready(function() { $('input.date_picker').live('focus', function(event) { var date_picker = $(this); diff --git a/lib/active_scaffold/bridges/date_picker/bridge.rb b/lib/active_scaffold/bridges/date_picker/bridge.rb index 77f2192552..705a43e166 100644 --- a/lib/active_scaffold/bridges/date_picker/bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/bridge.rb @@ -1,5 +1,3 @@ - - ActiveScaffold::Bridges.bridge "DatePicker" do install do directory = File.dirname(__FILE__) @@ -10,13 +8,14 @@ require File.join(directory, "lib/datepicker_bridge.rb") unless defined?(ACTIVE_SCAFFOLD_INSTALL_ASSETS) && ACTIVE_SCAFFOLD_INSTALL_ASSETS == false FileUtils.cp(source, destination) - ActiveScaffold::Bridges::DatePickerBridge.localization(File.join(destination, 'date_picker_bridge.js')) + #ActiveScaffold::Bridges::DatePickerBridge.localization(File.join(destination, 'date_picker_bridge.js')) end else # make sure that jquery files are removed FileUtils.rm(File.join(destination, 'date_picker_bridge.js')) if File.exist?(File.join(destination, 'date_picker_bridge.js')) end end + install? do true diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index c08ae8b144..d6c3886585 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -48,76 +48,107 @@ module DatePickerBridge '%S' => 'ss' } - def self.localization(js_file) - localization = "jQuery(function($){ + def self.localization + "jQuery(function($){ if (typeof($.datepicker) === 'object') { - $.datepicker.regional['#{I18n.locale}'] = #{date_options.to_json}; + #{date_options_for_locales} $.datepicker.setDefaults($.datepicker.regional['#{I18n.locale}']); } if (typeof($.timepicker) === 'object') { - $.timepicker.regional['#{I18n.locale}'] = #{datetime_options.to_json}; + #{datetime_options_for_locales} $.timepicker.setDefaults($.timepicker.regional['#{I18n.locale}']); } });\n" - prepend_js_file(js_file, localization) end - - def self.date_options - date_options = I18n.translate! 'date' - date_picker_options = { :closeText => as_(:close), - :prevText => as_(:previous), - :nextText => as_(:next), - :currentText => as_(:today), - :monthNames => date_options[:month_names][1, (date_options[:month_names].length - 1)], - :monthNamesShort => date_options[:abbr_month_names][1, (date_options[:abbr_month_names].length - 1)], - :dayNames => date_options[:day_names], - :dayNamesShort => date_options[:abbr_day_names], - :dayNamesMin => date_options[:abbr_day_names], - :changeYear => true, - :changeMonth => true, - } + def self.date_options_for_locales + I18n.available_locales.collect do |locale| + locale_date_options = date_options(locale) + if locale_date_options + "$.datepicker.regional['#{locale}'] = #{locale_date_options.to_json};" + else + nil + end + end.compact.join('') + end + + def self.date_options(locale) begin - as_date_picker_options = I18n.translate! 'active_scaffold.date_picker_options' - date_picker_options.merge!(as_date_picker_options) if as_date_picker_options.is_a? Hash + date_options = I18n.translate! 'date', :locale => locale + date_picker_options = { :closeText => as_(:close), + :prevText => as_(:previous), + :nextText => as_(:next), + :currentText => as_(:today), + :monthNames => date_options[:month_names][1, (date_options[:month_names].length - 1)], + :monthNamesShort => date_options[:abbr_month_names][1, (date_options[:abbr_month_names].length - 1)], + :dayNames => date_options[:day_names], + :dayNamesShort => date_options[:abbr_day_names], + :dayNamesMin => date_options[:abbr_day_names], + :changeYear => true, + :changeMonth => true, + } + + begin + as_date_picker_options = I18n.translate! 'active_scaffold.date_picker_options' + date_picker_options.merge!(as_date_picker_options) if as_date_picker_options.is_a? Hash + rescue + Rails.logger.warn "ActiveScaffold: Missing date picker localization for your locale: #{locale}" + end + + js_format = self.to_datepicker_format(date_options[:formats][:default]) + date_picker_options[:dateFormat] = js_format unless js_format.nil? + date_picker_options rescue - Rails.logger.warn "ActiveScaffold: Missing date picker localization for your locale: #{I18n.locale}" + if locale == I18n.locale + raise + else + nil + end end + end - js_format = self.to_datepicker_format(date_options[:formats][:default]) - date_picker_options[:dateFormat] = js_format unless js_format.nil? - date_picker_options + def self.datetime_options_for_locales + I18n.available_locales.collect do |locale| + locale_datetime_options = datetime_options(locale) + if locale_datetime_options + "$.timepicker.regional['#{locale}'] = #{locale_datetime_options.to_json};" + else + nil + end + end.compact.join('') end - def self.datetime_options - rails_time_format = I18n.translate! 'time.formats.default' - datetime_options = I18n.translate! 'datetime.prompts' - datetime_picker_options = {:ampm => false, - :hourText => datetime_options[:hour], - :minuteText => datetime_options[:minute], - :secondText => datetime_options[:second], - } - + def self.datetime_options(locale) begin - as_datetime_picker_options = I18n.translate! 'active_scaffold.datetime_picker_options' - datetime_picker_options.merge!(as_datetime_picker_options) if as_datetime_picker_options.is_a? Hash + rails_time_format = I18n.translate! 'time.formats.default', :locale => locale + datetime_options = I18n.translate! 'datetime.prompts', :locale => locale + datetime_picker_options = {:ampm => false, + :hourText => datetime_options[:hour], + :minuteText => datetime_options[:minute], + :secondText => datetime_options[:second], + } + + begin + as_datetime_picker_options = I18n.translate! 'active_scaffold.datetime_picker_options' + datetime_picker_options.merge!(as_datetime_picker_options) if as_datetime_picker_options.is_a? Hash + rescue + Rails.logger.warn "ActiveScaffold: Missing datetime picker localization for your locale: #{locale}" + end + + date_format, time_format = self.split_datetime_format(self.to_datepicker_format(rails_time_format)) + datetime_picker_options[:dateFormat] = date_format unless date_format.nil? + unless time_format.nil? + datetime_picker_options[:timeFormat] = time_format + datetime_picker_options[:ampm] = true if rails_time_format.include?('%I') + end + datetime_picker_options rescue - Rails.logger.warn "ActiveScaffold: Missing datetime picker localization for your locale: #{I18n.locale}" - end - - date_format, time_format = self.split_datetime_format(self.to_datepicker_format(rails_time_format)) - datetime_picker_options[:dateFormat] = date_format unless date_format.nil? - unless time_format.nil? - datetime_picker_options[:timeFormat] = time_format - datetime_picker_options[:ampm] = true if rails_time_format.include?('%I') + if locale == I18n.locale + raise + else + nil + end end - datetime_picker_options - end - - def self.prepend_js_file(js_file, prepend) - content = File.binread(js_file) - content.gsub!(/\A/, prepend) - File.open(js_file, 'wb') { |file| file.write(content) } end def self.to_datepicker_format(rails_format) From 879cd0544ea63377a48b4b03d291f42ff2d08faa Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 2 Jul 2011 13:23:54 +0200 Subject: [PATCH 1148/2024] remove old copy js file code for date_picker bridge --- lib/active_scaffold/bridges/date_picker/bridge.rb | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/bridge.rb b/lib/active_scaffold/bridges/date_picker/bridge.rb index 705a43e166..3743451aa4 100644 --- a/lib/active_scaffold/bridges/date_picker/bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/bridge.rb @@ -1,19 +1,5 @@ ActiveScaffold::Bridges.bridge "DatePicker" do install do - directory = File.dirname(__FILE__) - source = File.join(directory, "public/javascripts/date_picker_bridge.js") - destination = File.join(Rails.root, "public/javascripts/active_scaffold/default/") - - if ActiveScaffold.js_framework == :jquery - require File.join(directory, "lib/datepicker_bridge.rb") - unless defined?(ACTIVE_SCAFFOLD_INSTALL_ASSETS) && ACTIVE_SCAFFOLD_INSTALL_ASSETS == false - FileUtils.cp(source, destination) - #ActiveScaffold::Bridges::DatePickerBridge.localization(File.join(destination, 'date_picker_bridge.js')) - end - else - # make sure that jquery files are removed - FileUtils.rm(File.join(destination, 'date_picker_bridge.js')) if File.exist?(File.join(destination, 'date_picker_bridge.js')) - end end From 6b1c9386339eba59b3b10c272bbe62140f8f3ba8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 2 Jul 2011 13:29:06 +0200 Subject: [PATCH 1149/2024] remove code to copy activescaffold assets --- init.rb | 8 +------ lib/active_scaffold.rb | 16 +------------ lib/active_scaffold_assets.rb | 45 ----------------------------------- 3 files changed, 2 insertions(+), 67 deletions(-) delete mode 100644 lib/active_scaffold_assets.rb diff --git a/init.rb b/init.rb index 27593a9c88..6e1b45a648 100755 --- a/init.rb +++ b/init.rb @@ -1,7 +1 @@ -require 'active_scaffold' - -begin - ActiveScaffoldAssets.copy_to_public(ActiveScaffold.root, {:clean_up_destination => true}) -rescue - raise $! unless Rails.env == 'production' -end \ No newline at end of file +require 'active_scaffold' \ No newline at end of file diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 2d894cb3c6..884c0e7d3c 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -369,18 +369,4 @@ def uses_active_scaffold? end end -require 'active_scaffold_env' - -## -## Run the install assets script, too, just to make sure -## But at least rescue the action in production -## - -Rails::Application.initializer("active_scaffold.install_assets") do - begin - ActiveScaffoldAssets.copy_to_public(ActiveScaffold.root, {:clean_up_destination => true}) - rescue - raise $! unless Rails.env == 'production' - end -end if defined?(ACTIVE_SCAFFOLD_GEM) - +require 'active_scaffold_env' \ No newline at end of file diff --git a/lib/active_scaffold_assets.rb b/lib/active_scaffold_assets.rb deleted file mode 100644 index 64675b6d2e..0000000000 --- a/lib/active_scaffold_assets.rb +++ /dev/null @@ -1,45 +0,0 @@ -class ActiveScaffoldAssets - - def self.copy_to_public(from, options = {}) - unless defined?(ACTIVE_SCAFFOLD_INSTALL_ASSETS) && ACTIVE_SCAFFOLD_INSTALL_ASSETS == false - copy_files("/public", "/public", from) - available_frontends = Dir[File.join(from, 'frontends', '*')].collect { |d| File.basename d } - [:stylesheets, :javascripts, :images].each do |asset_type| - copy_asset_type(from, available_frontends, asset_type, options) - end - end - end - -protected - - def self.copy_asset_type(from, available_frontends, asset_type, options = {}) - path = "/public/#{asset_type}/active_scaffold" - copy_files(path, path, from) - - File.open(File.join(Rails.root, path, 'DO_NOT_EDIT'), 'w') do |f| - f.puts "Any changes made to files in sub-folders will be lost." - f.puts "See http://activescaffold.com/tutorials/faq#custom-css." - end - - available_frontends.each do |frontend| - if asset_type == :javascripts - file_mask = '*.js' - source = "/frontends/#{frontend}/#{asset_type}/#{ActiveScaffold.js_framework}" - else - file_mask = '*.*' - source = "/frontends/#{frontend}/#{asset_type}" - end - destination = "/public/#{asset_type}/active_scaffold/#{frontend}" - copy_files(source, destination, from, file_mask, options) - end - end - - def self.copy_files(source_path, destination_path, directory, file_mask = '*.*', options = {}) - source, destination = File.join(directory, source_path), File.join(Rails.root, destination_path) - FileUtils.mkdir_p(destination) unless File.exist?(destination) - Dir.glob('*.so') - - FileUtils.rm Dir.glob("#{destination}/*") if options[:clean_up_destination] - FileUtils.cp_r(Dir.glob("#{source}/#{file_mask}"), destination) - end -end \ No newline at end of file From 4762664a39c87e2d1da5f46262fa9f89ca2390fe Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 2 Jul 2011 13:35:20 +0200 Subject: [PATCH 1150/2024] remove require statements fo actvescaffold_assets --- active_scaffold_vho.gemspec | 1 - lib/active_scaffold.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec index f46548213a..ba8ac86297 100644 --- a/active_scaffold_vho.gemspec +++ b/active_scaffold_vho.gemspec @@ -218,7 +218,6 @@ Gem::Specification.new do |s| "lib/active_scaffold/paginator.rb", "lib/active_scaffold/responds_to_parent.rb", "lib/active_scaffold/version.rb", - "lib/active_scaffold_assets.rb", "lib/active_scaffold_env.rb", "lib/active_scaffold_vho.rb", "lib/generators/active_scaffold/USAGE", diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 884c0e7d3c..32669ba843 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -11,7 +11,6 @@ rescue LoadError end -require 'active_scaffold_assets' require 'active_scaffold/active_record_permissions' require 'active_scaffold/paginator' require 'active_scaffold/responds_to_parent' From 6d3a6af1ec1ccfdfa66295f3249a2b43e7f3d756 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 2 Jul 2011 13:42:04 +0200 Subject: [PATCH 1151/2024] Bugfix: readd require for date_picker_bridge file --- lib/active_scaffold/bridges/date_picker/bridge.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/bridges/date_picker/bridge.rb b/lib/active_scaffold/bridges/date_picker/bridge.rb index 3743451aa4..f1282d2b88 100644 --- a/lib/active_scaffold/bridges/date_picker/bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/bridge.rb @@ -1,5 +1,6 @@ ActiveScaffold::Bridges.bridge "DatePicker" do install do + require File.join(File.dirname(__FILE__), "lib/datepicker_bridge.rb") if ActiveScaffold.js_framework == :jquery end From 6f2797f7dd7ee6c818a44b3e27c5d4679eb47d29 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 2 Jul 2011 14:40:35 +0200 Subject: [PATCH 1152/2024] Bugfix: add additional html_safe call to prefend escaping --- lib/active_scaffold/extensions/action_controller_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_controller_rendering.rb b/lib/active_scaffold/extensions/action_controller_rendering.rb index 161803efa5..e48bdffec8 100644 --- a/lib/active_scaffold/extensions/action_controller_rendering.rb +++ b/lib/active_scaffold/extensions/action_controller_rendering.rb @@ -7,7 +7,7 @@ def render_with_active_scaffold(*args, &block) # if we need an adapter, then we render the actual stuff to a string and insert it into the adapter template opts = args.blank? ? Hash.new : args.first render :partial => params[:adapter][1..-1], - :locals => {:payload => render_to_string(opts.merge(:layout => false), &block)}, + :locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe}, :use_full_path => true, :layout => false @rendering_adapter = nil # recursion control else From 7acdc6b1c7f379fa3ad5fd5cbfdf18995a92ac23 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 2 Jul 2011 14:41:13 +0200 Subject: [PATCH 1153/2024] Bugfix: jquery 1.6 does not work with dataType rails instead use dataType text --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 747e4d7735..e238057700 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -34,7 +34,7 @@ $(document).ready(function() { } else { // hack: jquery requires if you request for javascript that javascript // is coming back, however rails has a different mantra - if (action_link.position) event.data_type = 'rails'; + if (action_link.position) event.data_type = 'text'; if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible'); action_link.disable(); } From 5a8ed31fd101422755124b12818af36a22c02129 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Tue, 5 Jul 2011 21:49:31 +0200 Subject: [PATCH 1154/2024] improved jquery version detection to support inline action links --- app/assets/javascripts/jquery/active_scaffold.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index e238057700..58d3534e03 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -34,7 +34,13 @@ $(document).ready(function() { } else { // hack: jquery requires if you request for javascript that javascript // is coming back, however rails has a different mantra - if (action_link.position) event.data_type = 'text'; + if (action_link.position) { + if (parseFloat($.fn.jquery) >= 1.5) { + event.data_type = 'text'; + } else { + event.data_type = 'rails'; + } + } if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible'); action_link.disable(); } From 8bb6786bf34cfc07ffcb62ff4eb473eecce3b0f7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 09:56:14 +0200 Subject: [PATCH 1155/2024] Bugfix: ignore_columns settings are not considered for search_columns (issue 168 by eriko) --- lib/active_scaffold/config/search.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/search.rb b/lib/active_scaffold/config/search.rb index 999c3584f8..216c372a4e 100644 --- a/lib/active_scaffold/config/search.rb +++ b/lib/active_scaffold/config/search.rb @@ -42,7 +42,7 @@ def self.live? def columns # we want to delay initializing to the @core.columns set for as long as possible. Too soon and .search_sql will not be available to .searchable? unless @columns - self.columns = @core.columns.collect{|c| c.name if c.searchable? and c.column and c.column.text?}.compact + self.columns = @core.columns.collect{|c| c.name if @core.columns._inheritable.include?(c.name) and c.searchable? and c.column and c.column.text?}.compact end @columns end From ee547c6d904cffd8b25f47a98a2bd9be3361c12e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 13:03:32 +0200 Subject: [PATCH 1156/2024] jquery ujs triggers ajax:error event instead of ajax:failure --- app/assets/javascripts/jquery/active_scaffold.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 58d3534e03..bfc39c229f 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -13,7 +13,7 @@ $(document).ready(function() { ActiveScaffold.enable_form(as_form); } }); - $('form.as_form').live('ajax:failure', function(event) { + $('form.as_form').live('ajax:error', function(event, xhr, status, error) { var as_div = $(this).closest("div.active-scaffold"); if (as_div) { ActiveScaffold.report_500_response(as_div) @@ -67,7 +67,7 @@ $(document).ready(function() { } return true; }); - $('a.as_action').live('ajax:failure', function(event) { + $('a.as_action').live('ajax:error', function(event, xhr, status, error) { var action_link = ActiveScaffold.ActionLink.get($(this)); if (action_link) { ActiveScaffold.report_500_response(action_link.scaffold_id()); @@ -104,7 +104,7 @@ $(document).ready(function() { } return true; }); - $('a.as_cancel').live('ajax:failure', function(event) { + $('a.as_cancel').live('ajax:error', function(event, xhr, status, error) { var action_link = ActiveScaffold.find_action_link($(this)); if (action_link) { ActiveScaffold.report_500_response(action_link.scaffold_id()); @@ -118,7 +118,7 @@ $(document).ready(function() { as_sort.closest('th').addClass('loading'); return true; }); - $('a.as_sort').live('ajax:failure', function(event) { + $('a.as_sort').live('ajax:error', function(event, xhr, status, error) { var as_scaffold = $(this).closest('.active-scaffold'); ActiveScaffold.report_500_response(as_scaffold); return true; @@ -143,7 +143,7 @@ $(document).ready(function() { as_paginate.prevAll('img.loading-indicator').css('visibility','visible'); return true; }); - $('a.as_paginate').live('ajax:failure', function(event) { + $('a.as_paginate').live('ajax:error', function(event, xhr, status, error) { var as_scaffold = $(this).closest('.active-scaffold'); ActiveScaffold.report_500_response(as_scaffold); return true; From 3e6c07d5fb97f8bb1b68fad601b9e6e86255b1f6 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 13:46:56 +0200 Subject: [PATCH 1157/2024] on_create rjs was removed in rails 3.1 use erb for the moment --- frontends/default/views/on_create.js.erb | 45 ++++++++++++++++++++++++ frontends/default/views/on_create.js.rjs | 41 --------------------- 2 files changed, 45 insertions(+), 41 deletions(-) create mode 100644 frontends/default/views/on_create.js.erb delete mode 100644 frontends/default/views/on_create.js.rjs diff --git a/frontends/default/views/on_create.js.erb b/frontends/default/views/on_create.js.erb new file mode 100644 index 0000000000..dcd94f484f --- /dev/null +++ b/frontends/default/views/on_create.js.erb @@ -0,0 +1,45 @@ +try { +<% form_selector = "#{element_form_id(:action => :create)}" +insert_at ||= :top %> +var action_link = ActiveScaffold.find_action_link('<%= form_selector%>'); +action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages').strip)%>'); +<% if controller.send :successful? %> + <% if render_parent? && controller.respond_to?(:render_component_into_view) %> + <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> + <% if nested_singular_association? %> + action_link.close('<%= escape_javascript(parent_rendered)%>'); + <% else %> + <% if render_parent_action == :row %> + ActiveScaffold.create_record_row(action_link.scaffold(),'<%= escape_javascript(parent_rendered)%>', <%= {:insert_at => insert_at}.to_json.html_safe %>); + <% elsif render_parent_action == :index %> + <%= escape_javascript(parent_rendered) %> + <% end %> + action_link.close(); + <% end %> + <%#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> + <% elsif (active_scaffold_config.create.refresh_list) %> + ActiveScaffold.replace_html(<%= active_scaffold_content_id%>, <%= escape_javascript(render(:partial => 'list', :layout => false)) %>); + <% elsif params[:parent_controller].nil? %> + <% new_row = render :partial => 'list_record', :locals => {:record => @record} %> + ActiveScaffold.create_record_row(action_link.scaffold(),'<%=escape_javascript(new_row)%>', <%={:insert_at => insert_at}.to_json.html_safe%>); + <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> + ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); + <% end %> + <% end %> + + <% unless render_parent? %> + <% if (active_scaffold_config.create.persistent) %> + action_link.reload(); + <% else %> + action_link.close(); + <% end %> + <% if (active_scaffold_config.create.edit_after_create) %> + var link = $('<%=action_link_id 'edit', @record.id%>'); + if (link) (function() { link.action_link.open() }).defer(); + <% end %> + <% end %> +<% else %> + ActiveScaffold.replace('<%=form_selector%>','<%=escape_javascript(render(:partial => 'create_form', :locals => {:xhr => true}))%>'); + ActiveScaffold.scroll_to('<%=form_selector%>'); +<% end %> +} catch (e) { alert('RJS error:\n\n' + e.toString());} \ No newline at end of file diff --git a/frontends/default/views/on_create.js.rjs b/frontends/default/views/on_create.js.rjs deleted file mode 100644 index 73a715ecfb..0000000000 --- a/frontends/default/views/on_create.js.rjs +++ /dev/null @@ -1,41 +0,0 @@ -form_selector = "#{element_form_id(:action => :create)}" -insert_at ||= :top -page << "var action_link = ActiveScaffold.find_action_link('#{form_selector}');" -page << "action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" -if controller.send :successful? - if render_parent? && controller.respond_to?(:render_component_into_view) - parent_rendered = controller.send(:render_component_into_view, render_parent_options) - if nested_singular_association? - page << "action_link.close('#{escape_javascript(parent_rendered)}');" - else - if render_parent_action == :row - page << "ActiveScaffold.create_record_row(action_link.scaffold(),'#{escape_javascript(parent_rendered)}', #{{:insert_at => insert_at}.to_json});" - elsif render_parent_action == :index - page << parent_rendered - end - page << "action_link.close();" - end - #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} - elsif (active_scaffold_config.create.refresh_list) - page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) - elsif params[:parent_controller].nil? - new_row = render :partial => 'list_record', :locals => {:record => @record} - page << "ActiveScaffold.create_record_row(action_link.scaffold(),'#{escape_javascript(new_row)}', #{{:insert_at => insert_at}.to_json});" - page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} - end - - unless render_parent? - if (active_scaffold_config.create.persistent) - page << "action_link.reload();" - else - page << "action_link.close();" - end - if (active_scaffold_config.create.edit_after_create) - page << "var link = $('#{action_link_id 'edit', @record.id}');" - page << "if (link) (function() { link.action_link.open() }).defer();" - end - end -else - page.call 'ActiveScaffold.replace', form_selector, render(:partial => 'create_form', :locals => {:xhr => true}) - page.call 'ActiveScaffold.scroll_to', form_selector -end From 9d8564c3f04b361db8db65f25eb68e203b2932dc Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 13:50:34 +0200 Subject: [PATCH 1158/2024] on_update.js.rjs renamed to js.erb --- frontends/default/views/{on_update.js.rjs => on_update.js.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frontends/default/views/{on_update.js.rjs => on_update.js.erb} (100%) diff --git a/frontends/default/views/on_update.js.rjs b/frontends/default/views/on_update.js.erb similarity index 100% rename from frontends/default/views/on_update.js.rjs rename to frontends/default/views/on_update.js.erb From e10206684c780ecd55e8106aa210bd74620e1bf3 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:00:59 +0200 Subject: [PATCH 1159/2024] changed code to erb syntax --- frontends/default/views/on_update.js.erb | 59 +++++++++++++----------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/frontends/default/views/on_update.js.erb b/frontends/default/views/on_update.js.erb index 15ff9022ba..cc48b13c44 100644 --- a/frontends/default/views/on_update.js.erb +++ b/frontends/default/views/on_update.js.erb @@ -1,28 +1,31 @@ -form_selector = "#{element_form_id(:action => :update)}" - -page << "var action_link = ActiveScaffold.find_action_link('#{form_selector}');" -page << "action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');" -if controller.send :successful? - if render_parent? && controller.respond_to?(:render_component_into_view) - parent_rendered = controller.send(:render_component_into_view, render_parent_options) - if nested_singular_association? - page << "action_link.close('#{escape_javascript(parent_rendered)}');" - else - if render_parent_action == :row - page << "action_link.close('#{escape_javascript(parent_rendered)}');" - elsif render_parent_action == :index - page << parent_rendered - end - end - #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} - elsif update_refresh_list? - page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) - else - updated_row = render :partial => 'list_record', :locals => {:record => @record} - page << "action_link.close('#{escape_javascript(updated_row)}');" - page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} - end -else - page.call 'ActiveScaffold.replace', form_selector, render(:partial => 'update_form', :locals => {:xhr => true}) - page.call 'ActiveScaffold.scroll_to', form_selector -end +try { +<% form_selector = "#{element_form_id(:action => :update)}" %> +var action_link = ActiveScaffold.find_action_link('<%= form_selector%>'); +action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages').strip)%>'); +<% if controller.send :successful? %> + <% if render_parent? && controller.respond_to?(:render_component_into_view) %> + <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> + <% if nested_singular_association? %> + action_link.close('<%= escape_javascript(parent_rendered)%>'); + <% else %> + <% if render_parent_action == :row %> + action_link.close('<%= escape_javascript(parent_rendered)%>'); + <% elsif render_parent_action == :index %> + <%= escape_javascript(parent_rendered) %> + <% end %> + <% end %> + <%#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> + <% elsif update_refresh_list? %> + ActiveScaffold.replace_html(<%= active_scaffold_content_id%>, <%= escape_javascript(render(:partial => 'list', :layout => false)) %>); + <% else %> + <% updated_row = render :partial => 'list_record', :locals => {:record => @record}%> + action_link.close('<%= escape_javascript(updated_row)%>'); + <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> + ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); + <% end %> + <% end %> +<% else %> + ActiveScaffold.replace('<%=form_selector%>','<%=escape_javascript(render(:partial => 'update_form', :locals => {:xhr => true}))%>'); + ActiveScaffold.scroll_to('<%=form_selector%>'); +<% end %> +} catch (e) { alert('RJS error:\n\n' + e.toString());} From 070e29ded21ad457400dfcfdb0e778bb4bd6ef2f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:05:26 +0200 Subject: [PATCH 1160/2024] renamed update_column rjs to erb --- .../default/views/{update_column.js.rjs => update_column.js.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frontends/default/views/{update_column.js.rjs => update_column.js.erb} (100%) diff --git a/frontends/default/views/update_column.js.rjs b/frontends/default/views/update_column.js.erb similarity index 100% rename from frontends/default/views/update_column.js.rjs rename to frontends/default/views/update_column.js.erb From 874a5ba6a39ee83fea745896415f706371f5ff28 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:12:20 +0200 Subject: [PATCH 1161/2024] changed syntax to erb --- frontends/default/views/update_column.js.erb | 29 +++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/frontends/default/views/update_column.js.erb b/frontends/default/views/update_column.js.erb index 6bd90fa16a..77a08a8c82 100644 --- a/frontends/default/views/update_column.js.erb +++ b/frontends/default/views/update_column.js.erb @@ -1,13 +1,16 @@ -column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column]) -unless controller.send :successful? - page.call 'alert', @record.errors.full_messages.join("\n") - @record.reload -end -column = active_scaffold_config.columns[params[:column]] -if column.inplace_edit - page.call 'ActiveScaffold.replace_html', column_span_id, format_inplace_edit_column(@record, column) -else - formatted_value = get_column_value(@record, column) - page.call 'ActiveScaffold.replace_html', column_span_id, formatted_value -end -page.call 'ActiveScaffold.replace_html', active_scaffold_calculations_id(column), render_column_calculation(column) if column.calculation? +<% column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column])%> +<% unless controller.send :successful?%> + alert('<%= escape_javascript(@record.errors.full_messages.join("\n"))%>'); + <% @record.reload%> +<% end%> +<% column = active_scaffold_config.columns[params[:column]]%> +<% if column.inplace_edit%> + ActiveScaffold.replace_html('<%=column_span_id%>','<%=escape_javascript(format_inplace_edit_column(@record, column))%>'); +<% else%> + <% formatted_value = get_column_value(@record, column)%> + ActiveScaffold.replace_html('<%=column_span_id%>','<%=escape_javascript(formatted_value)%>'); +<% end%> +<% if column.calculation?%> + ActiveScaffold.replace_html('<%=active_scaffold_calculations_id(column)%>', '<%=escape_javascript(render_column_calculation(column))%>'); +<% end%> + From b4e0a4be688a0f0c05dc443b65f26f9e4c45d0d5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:13:16 +0200 Subject: [PATCH 1162/2024] update_row renamed to erb suffix --- frontends/default/views/{update_row.js.rjs => update_row.js.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frontends/default/views/{update_row.js.rjs => update_row.js.erb} (100%) diff --git a/frontends/default/views/update_row.js.rjs b/frontends/default/views/update_row.js.erb similarity index 100% rename from frontends/default/views/update_row.js.rjs rename to frontends/default/views/update_row.js.erb From 8b69ba70392d412086ba5ee1e548088ae1d7ad07 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:17:40 +0200 Subject: [PATCH 1163/2024] changed to erb syntax --- frontends/default/views/update_row.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/update_row.js.erb b/frontends/default/views/update_row.js.erb index ac654a92ba..177d86f7b3 100644 --- a/frontends/default/views/update_row.js.erb +++ b/frontends/default/views/update_row.js.erb @@ -1 +1 @@ -page.call 'ActiveScaffold.update_row', element_row_id(:action => 'list', :id => @record.id), render(:partial => 'list_record', :locals => {:record => @record}) +ActiveScaffold.update_row('<%=element_row_id(:action => 'list', :id => @record.id)%>','<%=escape_javascript(render(:partial => 'list_record', :locals => {:record => @record}))%>'); \ No newline at end of file From 7358841a8e183760593fc907b9646cbe7e1bf685 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:18:24 +0200 Subject: [PATCH 1164/2024] renamed to erb suffix --- .../default/views/{_render_field.js.rjs => _render_field.js.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frontends/default/views/{_render_field.js.rjs => _render_field.js.erb} (100%) diff --git a/frontends/default/views/_render_field.js.rjs b/frontends/default/views/_render_field.js.erb similarity index 100% rename from frontends/default/views/_render_field.js.rjs rename to frontends/default/views/_render_field.js.erb From 33095de336424f0fbc0382c4cf8ee6773fa2250f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:25:01 +0200 Subject: [PATCH 1165/2024] change syntax to erb --- frontends/default/views/_render_field.js.erb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/frontends/default/views/_render_field.js.erb b/frontends/default/views/_render_field.js.erb index 1957675baf..d86f02ac38 100644 --- a/frontends/default/views/_render_field.js.erb +++ b/frontends/default/views/_render_field.js.erb @@ -1,10 +1,13 @@ -column = active_scaffold_config.columns[render_field.to_sym] -options = {:is_subform => false, :field_class => "#{column.name}-input"} -if column_renders_as(column) == :subform - options[:is_subform] = true -end -page.call 'ActiveScaffold.render_form_field', source_id, render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] }), options -render(:partial => "render_field", :collection => column.update_columns) if column.update_columns && !column.update_columns.empty? +<%column = active_scaffold_config.columns[render_field.to_sym] + options = {:is_subform => false, :field_class => "#{column.name}-input"} + if column_renders_as(column) == :subform + options[:is_subform] = true + end %> + +ActiveScaffold.render_form_field('<%source_id%>','<%=escape_javascript(render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] }))%>', options.to_json.html_safe); +<%if column.update_columns && !column.update_columns.empty?%> + <%= render(:partial => "render_field", :collection => column.update_columns)%> +<%end%> From a3c0709f1250bfd7636f2749e7851d4e7451042a Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:36:12 +0200 Subject: [PATCH 1166/2024] add_existing to erb --- frontends/default/views/add_existing.js.erb | 20 ++++++++++++++++++++ frontends/default/views/add_existing.js.rjs | 17 ----------------- 2 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 frontends/default/views/add_existing.js.erb delete mode 100644 frontends/default/views/add_existing.js.rjs diff --git a/frontends/default/views/add_existing.js.erb b/frontends/default/views/add_existing.js.erb new file mode 100644 index 0000000000..9f25e32a75 --- /dev/null +++ b/frontends/default/views/add_existing.js.erb @@ -0,0 +1,20 @@ +<% new_row = render :partial => 'list_record', :locals => {:record => @record}%> +ActiveScaffold.create_record_row('#{active_scaffold_id}','#{escape_javascript(new_row)}', #{{:insert_at => :top}.to_json.html_safe}); +<%%> +<% if active_scaffold_config.list.columns.any? {|c| c.calculation?} %> + ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); +<%end%> +<%%> +<% if(form_stays_open == true)%> + <%# why not just re-render the form? that wouldn't utilize a possible do_new override which sets default values.%> + ActiveScaffold.reset_form('<%element_form_id%>'); + ActiveScaffold.replace_html('<%element_messages_id(:action => :add_existing)%>', '<%=escape_javascript(render(:partial => 'form_messages'))%>'); + <%# have to delay the focus, because there's no "firstElement" in prototype until at least one element is not disabled%> + <%if ActiveScaffold.js_framework == :prototype%> + page.delay 0.1 do + page << "ActiveScaffold.focus_first_element_of_form('#{element_form_id}');" + end + <%end%> +<%else%> + ActiveScaffold.find_action_link('<%element_form_id(:action => :new_existing)%>').close(); +<%end%> diff --git a/frontends/default/views/add_existing.js.rjs b/frontends/default/views/add_existing.js.rjs deleted file mode 100644 index 3a7d3b62cc..0000000000 --- a/frontends/default/views/add_existing.js.rjs +++ /dev/null @@ -1,17 +0,0 @@ -new_row = render :partial => 'list_record', :locals => {:record => @record} -page << "ActiveScaffold.create_record_row('#{active_scaffold_id}','#{escape_javascript(new_row)}', #{{:insert_at => :top}.to_json});" -page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} - -if (form_stays_open = true) - # why not just re-render the form? that wouldn't utilize a possible do_new override which sets default values. - page.call 'ActiveScaffold.reset_form', element_form_id - page.call 'ActiveScaffold.replace_html', element_messages_id(:action => :add_existing), render(:partial => 'form_messages') - # have to delay the focus, because there's no "firstElement" in prototype until at least one element is not disabled - if ActiveScaffold.js_framework == :prototype - page.delay 0.1 do - page << "ActiveScaffold.focus_first_element_of_form('#{element_form_id}');" - end - end -else - page << "ActiveScaffold.find_action_link('#{element_form_id(:action => :new_existing)}').close();" -end \ No newline at end of file From 5b5b8520d8455a36abbbbb29bdf127a3fda5c44e Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:36:49 +0200 Subject: [PATCH 1167/2024] renamed to erb suffix --- frontends/default/views/{destroy.js.rjs => destroy.js.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frontends/default/views/{destroy.js.rjs => destroy.js.erb} (100%) diff --git a/frontends/default/views/destroy.js.rjs b/frontends/default/views/destroy.js.erb similarity index 100% rename from frontends/default/views/destroy.js.rjs rename to frontends/default/views/destroy.js.erb From d955fb107f86e03c5629bbe303d29e3e77de6983 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:51:30 +0200 Subject: [PATCH 1168/2024] changed syntax to erb --- frontends/default/views/destroy.js.erb | 47 +++++++++++++------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/frontends/default/views/destroy.js.erb b/frontends/default/views/destroy.js.erb index 254f1e55b0..d2c043b556 100644 --- a/frontends/default/views/destroy.js.erb +++ b/frontends/default/views/destroy.js.erb @@ -1,23 +1,24 @@ -messages_id = active_scaffold_messages_id -if controller.send(:successful?) - if render_parent? && controller.respond_to?(:render_component_into_view) - render_parent_options - if render_parent_action == :row - # TODO: That s not working with delete.... - page << "ActiveScaffold.delete_record_row('#{element_row_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}", :action => 'list', :id => params[:id])}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" - messages_id = active_scaffold_messages_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}") - elsif render_parent_action == :index - parent_rendered = controller.send(:render_component_into_view, render_parent_options) - page << parent_rendered - end - #page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} - elsif (active_scaffold_config.delete.refresh_list) - page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) - else - page << "ActiveScaffold.delete_record_row('#{element_row_id(:action => 'list', :id => params[:id])}','#{url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))}');" - page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} - end -else - flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) -end -page.call 'ActiveScaffold.replace_html', messages_id, render(:partial => 'messages') +<%messages_id = active_scaffold_messages_id%> +<%if controller.send(:successful?)%> + <%if render_parent? && controller.respond_to?(:render_component_into_view)%> + <%render_parent_options%> + <%if render_parent_action == :row%> + <%# TODO: That s not working with delete....%> + ActiveScaffold.delete_record_row('<%=element_row_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}", :action => 'list', :id => params[:id])%>', '<%=url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))%>'); + <%messages_id = active_scaffold_messages_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}")%> + <%elsif render_parent_action == :index%> + <%= escape_javascript(controller.send(:render_component_into_view, render_parent_options))%> + <%end%> + <%#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> + <%elsif (active_scaffold_config.delete.refresh_list)%> + ActiveScaffold.replace('<%=active_scaffold_content_id%>', '<%=escape_javascript(render(:partial => 'list', :layout => false))%>'); + <%else%> + ActiveScaffold.delete_record_row('<%=element_row_id(:action => 'list', :id => params[:id])%>', '<%=url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))%>'); + <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> + ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); + <% end %> + <%end%> +<%else%> + <%flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br)%> +<%end%> +ActiveScaffold.replace_html('<%=messages_id%>', '<%=escape_javascript(render(:partial => 'messages'))%>'); \ No newline at end of file From 8aae968e8f80b721331b7ddb23cea9303b1c9fdf Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:51:45 +0200 Subject: [PATCH 1169/2024] fixed some erb syntax errors --- frontends/default/views/on_update.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/on_update.js.erb b/frontends/default/views/on_update.js.erb index cc48b13c44..67f878b0ca 100644 --- a/frontends/default/views/on_update.js.erb +++ b/frontends/default/views/on_update.js.erb @@ -16,7 +16,7 @@ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'mess <% end %> <%#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> <% elsif update_refresh_list? %> - ActiveScaffold.replace_html(<%= active_scaffold_content_id%>, <%= escape_javascript(render(:partial => 'list', :layout => false)) %>); + ActiveScaffold.replace_html('<%= active_scaffold_content_id%>', '<%= escape_javascript(render(:partial => 'list', :layout => false))%>'); <% else %> <% updated_row = render :partial => 'list_record', :locals => {:record => @record}%> action_link.close('<%= escape_javascript(updated_row)%>'); From e119893bfdf041c9ee60323b9c7d65dea253f44f Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:52:45 +0200 Subject: [PATCH 1170/2024] renamed suffix to erb --- frontends/default/views/{list.js.rjs => list.js.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frontends/default/views/{list.js.rjs => list.js.erb} (100%) diff --git a/frontends/default/views/list.js.rjs b/frontends/default/views/list.js.erb similarity index 100% rename from frontends/default/views/list.js.rjs rename to frontends/default/views/list.js.erb From 72d04c37db8a142e8c78f1c41ccac3caced8bbc5 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:55:10 +0200 Subject: [PATCH 1171/2024] changed syntax to erb --- frontends/default/views/list.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/list.js.erb b/frontends/default/views/list.js.erb index d98c799e87..4c76e4a8f5 100644 --- a/frontends/default/views/list.js.erb +++ b/frontends/default/views/list.js.erb @@ -1 +1 @@ -page.call 'ActiveScaffold.replace_html', active_scaffold_content_id, render(:partial => 'list', :layout => false) +ActiveScaffold.replace_html('<%=active_scaffold_content_id%>','<%=escape_javascript(render(:partial => 'list', :layout => false))%>'); \ No newline at end of file From b187bd8648149f7f7465404dbf39fd3324719821 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 14:55:49 +0200 Subject: [PATCH 1172/2024] renamed to erb suffix --- .../views/{on_action_update.js.rjs => on_action_update.js.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frontends/default/views/{on_action_update.js.rjs => on_action_update.js.erb} (100%) diff --git a/frontends/default/views/on_action_update.js.rjs b/frontends/default/views/on_action_update.js.erb similarity index 100% rename from frontends/default/views/on_action_update.js.rjs rename to frontends/default/views/on_action_update.js.erb From 0d525a0d9aca9b16b01d738d1ec126602ba38c37 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 15:13:50 +0200 Subject: [PATCH 1173/2024] changed syntax to erb --- .../default/views/on_action_update.js.erb | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/frontends/default/views/on_action_update.js.erb b/frontends/default/views/on_action_update.js.erb index 381da8f416..544d954c94 100644 --- a/frontends/default/views/on_action_update.js.erb +++ b/frontends/default/views/on_action_update.js.erb @@ -1,10 +1,13 @@ -if controller.send :successful? - page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages') - page.call 'ActiveScaffold.update_row', element_row_id(:action => :list, :id => @record.id), render(:partial => 'list_record', :locals => {:record => @record}) if @record - page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?} -else - flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) - page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, render(:partial => 'messages') - page.call 'ActiveScaffold.scroll_to', active_scaffold_messages_id -end - +<%if controller.send :successful?%> + ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>','<%=escape_javascript(render(:partial => 'messages'))%>'); + <%if @record%> + ActiveScaffold.update_row('<%=element_row_id(:action => :list, :id => @record.id)%>','<%=escape_javascript(render(:partial => 'list_record', :locals => {:record => @record}))%>'); + <%end%> + <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> + ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); + <% end %> +<%else%> + <%flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br)%> + ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>','<%=escape_javascript(render(:partial => 'messages'))%>'); + ActiveScaffold.scroll_to('<%=active_scaffold_messages_id%>'); +<%end%> \ No newline at end of file From 673af34d4025bd97bad051b21cff11ecedc546bf Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 15:14:28 +0200 Subject: [PATCH 1174/2024] changed suffix to erb --- .../default/views/{form_messages.js.rjs => form_messages.js.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frontends/default/views/{form_messages.js.rjs => form_messages.js.erb} (100%) diff --git a/frontends/default/views/form_messages.js.rjs b/frontends/default/views/form_messages.js.erb similarity index 100% rename from frontends/default/views/form_messages.js.rjs rename to frontends/default/views/form_messages.js.erb From 065411cd26a90db042274c4993e92c594017d774 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 15:16:15 +0200 Subject: [PATCH 1175/2024] changed syntax to erb --- frontends/default/views/form_messages.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/form_messages.js.erb b/frontends/default/views/form_messages.js.erb index 85478db21a..a865405e74 100644 --- a/frontends/default/views/form_messages.js.erb +++ b/frontends/default/views/form_messages.js.erb @@ -1 +1 @@ -page.replace_html element_messages_id, :partial => 'form_messages' \ No newline at end of file +ActiveScaffold.replace_html('<%=element_messages_id%>','<%=escape_javascript(render(:partial => 'form_messages'))%>'); \ No newline at end of file From 1f17862e083b00707e82f6bffec2bce5186f2467 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 15:16:54 +0200 Subject: [PATCH 1176/2024] changed suffix to erb --- .../default/views/{on_mark_all.js.rjs => on_mark_all.js.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frontends/default/views/{on_mark_all.js.rjs => on_mark_all.js.erb} (100%) diff --git a/frontends/default/views/on_mark_all.js.rjs b/frontends/default/views/on_mark_all.js.erb similarity index 100% rename from frontends/default/views/on_mark_all.js.rjs rename to frontends/default/views/on_mark_all.js.erb From 610ae50abcc619498f0bb1006a120eb5283090c8 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 15:29:30 +0200 Subject: [PATCH 1177/2024] changed syntax to erb --- frontends/default/views/on_mark_all.js.erb | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/frontends/default/views/on_mark_all.js.erb b/frontends/default/views/on_mark_all.js.erb index dd339166ea..f4e05b69eb 100644 --- a/frontends/default/views/on_mark_all.js.erb +++ b/frontends/default/views/on_mark_all.js.erb @@ -1,12 +1,12 @@ -options = {:checked => mark_all, - :include_mark_all => true} -page << "ActiveScaffold.mark_records('#{active_scaffold_tbody_id}', #{options.to_json});" -if active_scaffold_config.model.marked.length>0 then - if active_scaffold_config.model.marked.length < @page.pager.count then - page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, active_scaffold_config.model.marked.length.to_s + " records marked. Press <a href=\""+url_for(:action=>"mark_all",:mark_target=>"scope")+"\">here</a> to select all #{@page.pager.count} records.".html_safe - else - page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, "All #{@page.pager.count} records marked" - end -else - page.call 'ActiveScaffold.replace_html', active_scaffold_messages_id, "" -end +<%options = {:checked => mark_all, + :include_mark_all => true}%> +ActiveScaffold.mark_records('<%=active_scaffold_tbody_id%>',<%=options.to_json.html_safe%>); +<%if active_scaffold_config.model.marked.length>0 then %> + <%if active_scaffold_config.model.marked.length < @page.pager.count then%> + ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>','<%="#{active_scaffold_config.model.marked.length.to_s} records marked. Press <a href=\"#{url_for(:action=>"mark_all",:mark_target=>"scope")}\">here</a> to select all #{@page.pager.count} records.".html_safe%>'); + <%else%> + ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>','<%="All #{@page.pager.count} records marked".html_safe%>'); + <%end%> +<%else%> + ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>',''); +<%end%> From 562673ac7e575bf181a8a1a0ce5726e97642f3ae Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 15:30:46 +0200 Subject: [PATCH 1178/2024] renamed suffix to erb --- .../views/{edit_associated.js.rjs => edit_associated.js.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frontends/default/views/{edit_associated.js.rjs => edit_associated.js.erb} (100%) diff --git a/frontends/default/views/edit_associated.js.rjs b/frontends/default/views/edit_associated.js.erb similarity index 100% rename from frontends/default/views/edit_associated.js.rjs rename to frontends/default/views/edit_associated.js.erb From 4de22417b47d1502147adab06aab47dbee9fac93 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 9 Jul 2011 15:33:59 +0200 Subject: [PATCH 1179/2024] changed syntax to erb --- frontends/default/views/edit_associated.js.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/edit_associated.js.erb b/frontends/default/views/edit_associated.js.erb index 1afaba9998..57af838574 100644 --- a/frontends/default/views/edit_associated.js.erb +++ b/frontends/default/views/edit_associated.js.erb @@ -1,3 +1,4 @@ +<% associated_form = render :partial => "#{subform_partial_for_column(@column)}_record", :locals => {:scope => @scope, :parent_record => @parent_record, :column => @column, :locked => @record.new_record? && @column.singular_association?} options = {:singular => false} if @column.singular_association? @@ -7,5 +8,5 @@ else column = active_scaffold_config_for(@record.class).columns[@record.class.primary_key] options[:id] = active_scaffold_input_options(column, @scope)[:id] end -end -page.call 'ActiveScaffold.create_associated_record_form', sub_form_list_id(:association => @column.name), associated_form, options +end %> +ActiveScaffold.create_associated_record_form('<%=sub_form_list_id(:association => @column.name)%>','<%=escape_javascript(associated_form)%>', options.to_json.html_safe); From b67d5fe20b8255204c6623ea6b9aeaa29a79e594 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 14 Jul 2011 16:06:56 +0200 Subject: [PATCH 1180/2024] experimental: add js trigger as_action_success --- app/assets/javascripts/jquery/active_scaffold.js | 5 +++-- lib/active_scaffold/helpers/view_helpers.rb | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index bfc39c229f..816060b3f6 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -56,7 +56,7 @@ $(document).ready(function() { } else { action_link.enable(); } - return true; + $(this).trigger('as:action_success', action_link); } return true; }); @@ -869,7 +869,8 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ this.loading_indicator = loading_indicator; this.hide_target = false; this.position = this.tag.attr('data-position'); - + this.action = this.tag.attr('data-action'); + this.tag.data('action_link', this); return this; }, diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 41255275d0..b81d43c622 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -191,6 +191,7 @@ def action_link_html_options(link, url_options, record, html_options) html_options['data-confirm'] = link.confirm(record.try(:to_label)) if link.confirm? html_options['data-position'] = link.position if link.position and link.inline? html_options[:class] += ' as_action' if link.inline? + html_options['data-action'] = link.action if link.inline? if link.popup? html_options['data-popup'] = true html_options[:target] = '_blank' From fd82640ddc5f800d0dd5a0e7640cf752de99402d Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 16 Jul 2011 22:16:00 +0200 Subject: [PATCH 1181/2024] avoid record not found exception for human conditions --- lib/active_scaffold/helpers/human_condition_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/human_condition_helpers.rb b/lib/active_scaffold/helpers/human_condition_helpers.rb index 7ab504dda3..b226e4c9a0 100644 --- a/lib/active_scaffold/helpers/human_condition_helpers.rb +++ b/lib/active_scaffold/helpers/human_condition_helpers.rb @@ -26,7 +26,7 @@ def active_scaffold_human_condition_for(column) when :select, :multi_select, :record_select associated = value associated = [associated].compact unless associated.is_a? Array - associated = column.association.klass.find(associated.map(&:to_i)).collect(&:to_label) if column.association + associated = column.association.klass.where(["id in (?)", associated.map(&:to_i)]).collect(&:to_label) if column.association "#{column.active_record_class.human_attribute_name(column.name)} = #{associated.join(', ')}" when :boolean, :checkbox label = column.column.type_cast(value) ? as_(:true) : as_(:false) From da1d2f5bbda66baa99a14fbc609b490bb04c0283 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 23 Jul 2011 17:08:01 +0200 Subject: [PATCH 1182/2024] Bugfix: iterate_model_associations wrong child_association (issue 170 reported by nakedmoon) --- lib/active_scaffold/data_structures/nested_info.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 42d1745030..4545edf67c 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -102,7 +102,7 @@ def iterate_model_associations(model) model.reflect_on_all_associations.each do |current| if !current.belongs_to? && association.primary_key_name == current.association_foreign_key constrained_fields << current.name.to_sym - @child_association = current + @child_association = current if current.klass == @parent_model end if association.primary_key_name == current.primary_key_name # show columns for has_many and has_one child associationes From 773174d9f14852b14adc29d75e99c7e5444c8908 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 23 Jul 2011 17:57:42 +0200 Subject: [PATCH 1183/2024] primary_key_name is deprecated in rails 3.1 --- .../lib/validation_reflection_bridge.rb | 2 +- lib/active_scaffold/data_structures/column.rb | 2 +- lib/active_scaffold/data_structures/nested_info.rb | 6 +++--- lib/active_scaffold/extensions/reverse_associations.rb | 6 +++--- lib/active_scaffold/helpers/association_helpers.rb | 2 +- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- lib/active_scaffold/helpers/search_column_helpers.rb | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb b/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb index 777ddcdb38..a54db9fdbe 100644 --- a/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +++ b/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb @@ -7,7 +7,7 @@ def self.included(base) def initialize_with_validation_reflection(name, active_record_class) initialize_without_validation_reflection(name, active_record_class) column_names = [name] - column_names << @association.primary_key_name if @association + column_names << @association.foreign_key if @association self.required = column_names.any? do |column_name| active_record_class.reflect_on_validations_for(column_name.to_sym).any? do |val| val.macro == :validates_presence_of or (val.macro == :validates_inclusion_of and not val.options[:allow_nil] and not val.options[:allow_blank]) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 9246eeea0b..f3432f9d3a 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -295,7 +295,7 @@ def initialize(name, active_record_class) #:nodoc: # just the field (not table.field) def field_name return nil if virtual? - column ? @active_record_class.connection.quote_column_name(column.name) : association.primary_key_name + column ? @active_record_class.connection.quote_column_name(column.name) : association.foreign_key end def <=>(other_column) diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 4545edf67c..72279f8fca 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -98,13 +98,13 @@ def default_sorting def iterate_model_associations(model) @constrained_fields = [] - @constrained_fields << association.primary_key_name.to_sym unless association.belongs_to? + @constrained_fields << association.foreign_key.to_sym unless association.belongs_to? model.reflect_on_all_associations.each do |current| - if !current.belongs_to? && association.primary_key_name == current.association_foreign_key + if !current.belongs_to? && association.foreign_key == current.association_foreign_key constrained_fields << current.name.to_sym @child_association = current if current.klass == @parent_model end - if association.primary_key_name == current.primary_key_name + if association.foreign_key == current.foreign_key # show columns for has_many and has_one child associationes constrained_fields << current.name.to_sym if current.belongs_to? @child_association = current diff --git a/lib/active_scaffold/extensions/reverse_associations.rb b/lib/active_scaffold/extensions/reverse_associations.rb index d17e119bb2..8675d56de1 100644 --- a/lib/active_scaffold/extensions/reverse_associations.rb +++ b/lib/active_scaffold/extensions/reverse_associations.rb @@ -20,7 +20,7 @@ def reverse def reverse_matches_for(klass) reverse_matches = [] - # stage 1 filter: collect associations that point back to this model and use the same primary_key_name + # stage 1 filter: collect associations that point back to this model and use the same foreign_key klass.reflect_on_all_associations.each do |assoc| if self.options[:through] # only iterate has_many :through associations @@ -40,9 +40,9 @@ def reverse_matches_for(klass) when 1 next - # otherwise, match them based on the primary_key_name + # otherwise, match them based on the foreign_key when 0 - next unless assoc.primary_key_name.to_sym == self.primary_key_name.to_sym + next unless assoc.foreign_key.to_sym == self.foreign_key.to_sym end end diff --git a/lib/active_scaffold/helpers/association_helpers.rb b/lib/active_scaffold/helpers/association_helpers.rb index 5e5b8f36ad..99ae97b520 100644 --- a/lib/active_scaffold/helpers/association_helpers.rb +++ b/lib/active_scaffold/helpers/association_helpers.rb @@ -29,7 +29,7 @@ def options_for_association_conditions(association) case association.macro when :has_one, :has_many # Find only orphaned objects - "#{association.primary_key_name} IS NULL" + "#{association.foreign_key} IS NULL" when :belongs_to, :has_and_belongs_to_many # Find all nil diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index f96a5ec368..f83e88f7d6 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -190,7 +190,7 @@ def active_scaffold_record_select(column, options, value, multiple) # if the opposite association is a :belongs_to (in that case association in this class must be has_one or has_many) # then only show records that have not been associated yet if [:has_one, :has_many].include?(column.association.macro) - params.merge!({column.association.primary_key_name => ''}) + params.merge!({column.association.foreign_key => ''}) end record_select_options = {:controller => remote_controller, :id => options[:id]} diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 16d52ca726..1cdb4c987d 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -74,7 +74,7 @@ def active_scaffold_search_select(column, html_options) associated = html_options.delete :value if column.association associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil? - method = column.association.macro == :belongs_to ? column.association.primary_key_name : column.name + method = column.association.macro == :belongs_to ? column.association.foreign_key : column.name select_options = options_for_association(column.association, true) else method = column.name From d7724c94d77ac1ceee4523661232e764584f6631 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 18 Apr 2011 13:08:28 +0200 Subject: [PATCH 1184/2024] merge latest changes from rails 2.3 branches (cherry picked from commit c00245805482ea20ca4f835af61c0998f7bb5e54) --- lib/active_scaffold/config/list.rb | 8 +++++++ .../helpers/form_column_helpers.rb | 12 ++++++---- .../helpers/list_column_helpers.rb | 16 ++++++++----- .../helpers/search_column_helpers.rb | 24 +++++++++++++++---- .../helpers/show_column_helpers.rb | 12 ++++++---- lib/active_scaffold/helpers/view_helpers.rb | 12 ++++++++-- 6 files changed, 64 insertions(+), 20 deletions(-) diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index d7d1d50332..e185833c48 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -16,6 +16,7 @@ def initialize(core_config) # inherit from global scope @empty_field_text = self.class.empty_field_text + @association_join_text = self.class.association_join_text @pagination = self.class.pagination @show_search_reset = true end @@ -34,6 +35,10 @@ def initialize(core_config) cattr_accessor :empty_field_text @@empty_field_text = '-' + # what string to use to join records from plural associations + cattr_accessor :association_join_text + @@association_join_text = ', ' + # What kind of pagination to use: # * true: The usual pagination # * :infinite: Treat the source as having an infinite number of pages (i.e. don't count the records; useful for large tables where counting is slow and we don't really care anyway) @@ -67,6 +72,9 @@ def columns # what string to use when a field is empty attr_accessor :empty_field_text + # what string to use to join records from plural associations + attr_accessor :association_join_text + # show a link to reset the search next to filtered message attr_accessor :show_search_reset diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index f83e88f7d6..f3f92ea553 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -262,13 +262,17 @@ def override_form_field_partial(column) "#{column.name}_form_column" end - def override_form_field?(column) - respond_to?(override_form_field(column)) + def override_form_field(column) + method_with_class = override_form_field_name(column, true) + return method_with_class if respond_to?(method_with_class) + method = override_form_field_name(column) + method if respond_to?(method) end + alias_method :override_form_field?, :override_form_field # the naming convention for overriding form fields with helpers - def override_form_field(column) - "#{column.name}_form_column" + def override_form_field_name(column, class_prefix = false) + "#{clean_class_name(column.active_record_class.name) + '_' if class_prefix}#{clean_column_name(column.name)}_form_column" end def override_input?(form_ui) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 42e306084f..16967386c7 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -86,7 +86,7 @@ def configure_column_link(link, associated, actions) def column_link_authorized?(link, column, record, associated) if column.association - associated_for_authorized = if associated.nil? || (associated.respond_to?(:empty?) && associated.empty?) + associated_for_authorized = if associated.nil? || (associated.respond_to?(:blank?) && associated.blank?) column.association.klass elsif [:has_many, :has_and_belongs_to_many].include? column.association.macro associated.first @@ -136,13 +136,17 @@ def active_scaffold_column_checkbox(column, record) check_box(:record, column.name, options) end - def column_override(column) - "#{column.name.to_s.gsub('?', '')}_column" # parse out any question marks (see issue 227) + def column_override_name(column, class_prefix = false) + "#{clean_class_name(column.active_record_class.name) + '_' if class_prefix}#{clean_column_name(column.name)}_column" end - def column_override?(column) - respond_to?(column_override(column)) + def column_override(column) + method_with_class = column_override_name(column, true) + return method_with_class if respond_to?(method_with_class) + method = column_override_name(column) + method if respond_to?(method) end + alias_method :column_override?, :column_override def override_column_ui?(list_ui) respond_to?(override_column_ui(list_ui)) @@ -208,7 +212,7 @@ def format_association_value(value, column, size) if column.associated_limit == 0 size if column.associated_number? else - joined_associated = format_value(firsts.join(', ')) + joined_associated = format_value(firsts.join(active_scaffold_config.list.association_join_text)) joined_associated << " (#{size})" if column.associated_number? and column.associated_limit and value.size > column.associated_limit joined_associated end diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 1cdb4c987d..9e5f3cf92e 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -126,11 +126,23 @@ def active_scaffold_search_range_string?(column) (column.column && column.column.text?) || column.search_ui == :string end + def include_null_comparators?(column) + return column.options[:null_comparators] if column.options.has_key? :null_comparators + if column.association + column.association.macro != :belongs_to || active_scaffold_config.columns[column.association.primary_key_name].column.try(:null) + else + column.column.try(:null) + end + end + def active_scaffold_search_range_comparator_options(column) select_options = ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} if active_scaffold_search_range_string?(column) select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} end + if include_null_comparators? column + select_options += ActiveScaffold::Finder::NullComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} + end select_options end @@ -211,13 +223,17 @@ def active_scaffold_search_time(column, options) ## Search column override signatures ## - def override_search_field?(column) - respond_to?(override_search_field(column)) + def override_search_field(column) + method_with_class = override_search_field_name(column, true) + return method_with_class if respond_to?(method_with_class) + method = override_search_field_name(column) + method if respond_to?(method) end + alias_method :override_search_field?, :override_search_field # the naming convention for overriding form fields with helpers - def override_search_field(column) - "#{column.name}_search_column" + def override_search_field_name(column, class_prefix = false) + "#{clean_class_name(column.active_record_class.name) + '_' if class_prefix}#{clean_column_name(column.name)}_search_column" end def override_search?(search_ui) diff --git a/lib/active_scaffold/helpers/show_column_helpers.rb b/lib/active_scaffold/helpers/show_column_helpers.rb index a330e63c68..3c86065990 100644 --- a/lib/active_scaffold/helpers/show_column_helpers.rb +++ b/lib/active_scaffold/helpers/show_column_helpers.rb @@ -25,13 +25,17 @@ def active_scaffold_show_text(column, record) simple_format(clean_column_value(record.send(column.name))) end - def show_column_override(column) - "#{column.name.to_s.gsub('?', '')}_show_column" # parse out any question marks (see issue 227) + def show_column_override_name(column, class_prefix = false) + "#{clean_class_name(column.active_record_class.name) + '_' if class_prefix}#{clean_column_name(column.name)}_show_column" end - def show_column_override?(column) - respond_to?(show_column_override(column)) + def show_column_override(column) + method_with_class = show_column_override_name(column, true) + return method_with_class if respond_to?(method_with_class) + method = show_column_override_name(column) + method if respond_to?(method) end + alias_method :show_column_override?, :show_column_override def override_show_column_ui?(list_ui) respond_to?(override_show_column_ui(list_ui)) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index b81d43c622..4f3081aceb 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -294,7 +294,7 @@ def as_main_div_class def column_empty?(column_value) empty = column_value.nil? - empty ||= column_value.empty? if column_value.respond_to? :empty? + empty ||= column_value.blank? if column_value.respond_to? :blank? empty ||= [' ', active_scaffold_config.list.empty_field_text].include? column_value if String === column_value return empty end @@ -328,7 +328,15 @@ def column_show_add_new(column, associated, record) value = false unless record.class.authorized_for?(:crud_type => :create) value end - + + def clean_column_name(name) + name.to_s.gsub('?', '') + end + + def clean_class_name(name) + name.underscore.gsub('/', '_') + end + def active_scaffold_error_messages_for(*params) options = params.extract_options!.symbolize_keys options.reverse_merge!(:container_tag => :div, :list_type => :ul) From 295cb9746acb6478545e7e9e685597620713cf71 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 18 Apr 2011 13:17:46 +0200 Subject: [PATCH 1185/2024] move record select to a bridge --- .../bridges/record_select/bridge.rb | 5 ++ .../record_select/lib/record_select_bridge.rb | 82 +++++++++++++++++++ .../helpers/form_column_helpers.rb | 35 -------- .../helpers/search_column_helpers.rb | 21 ----- 4 files changed, 87 insertions(+), 56 deletions(-) create mode 100644 lib/active_scaffold/bridges/record_select/bridge.rb create mode 100644 lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb diff --git a/lib/active_scaffold/bridges/record_select/bridge.rb b/lib/active_scaffold/bridges/record_select/bridge.rb new file mode 100644 index 0000000000..8c2d4d31ba --- /dev/null +++ b/lib/active_scaffold/bridges/record_select/bridge.rb @@ -0,0 +1,5 @@ +ActiveScaffold::Bridges.bridge "RecordSelect" do + install do + require File.join(File.dirname(__FILE__), "lib/record_select_bridge.rb") + end +end diff --git a/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb b/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb new file mode 100644 index 0000000000..d941f08f95 --- /dev/null +++ b/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb @@ -0,0 +1,82 @@ +module ActiveScaffold + module RecordSelectBridge + def self.included(base) + base.class_eval do + include FormColumnHelpers + include SearchColumnHelpers + include ViewHelpers + end + end + + module ViewHelpers + def self.included(base) + base.alias_method_chain :active_scaffold_includes, :record_select + end + + def active_scaffold_includes_with_record_select(*args) + active_scaffold_includes_without_record_select(*args) + record_select_includes + end + end + + module FormColumnHelpers + # requires RecordSelect plugin to be installed and configured. + def active_scaffold_input_record_select(column, options) + if column.singular_association? + multiple = false + multiple = column.options[:html_options][:multiple] if column.options[:html_options] && column.options[:html_options][:multiple] + active_scaffold_record_select(column, options, @record.send(column.name), multiple) + elsif column.plural_association? + active_scaffold_record_select(column, options, @record.send(column.name), true) + end + end + + def active_scaffold_record_select(column, options, value, multiple) + unless column.association + raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)." + end + remote_controller = active_scaffold_controller_for(column.association.klass).controller_path + + # if the opposite association is a :belongs_to (in that case association in this class must be has_one or has_many) + # then only show records that have not been associated yet + if [:has_one, :has_many].include?(column.association.macro) + params.merge!({column.association.primary_key_name => ''}) + end + + record_select_options = {:controller => remote_controller, :id => options[:id]} + record_select_options.merge!(active_scaffold_input_text_options) + record_select_options.merge!(column.options) + + if multiple + record_multi_select_field(options[:name], value || [], record_select_options) + else + record_select_field(options[:name], value || column.association.klass.new, record_select_options) + end + end + end + + module SearchColumnHelpers + def active_scaffold_search_record_select(column, options) + value = field_search_record_select_value(column) + active_scaffold_record_select(column, options, value, column.options[:multiple]) + end + + def field_search_record_select_value(column) + begin + value = field_search_params[column.name] + unless value.blank? + if column.options[:multiple] + column.association.klass.find value.collect!(&:to_i) + else + column.association.klass.find(value.to_i) + end + end + rescue Exception => e + logger.error Time.now.to_s + "Sorry, we are not that smart yet. Attempted to restore search values to search fields but instead got -- #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" + raise e + end + end + end + end +end + +ActionView::Base.class_eval { include ActiveScaffold::RecordSelectBridge } diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index f3f92ea553..bdf6731117 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -169,41 +169,6 @@ def active_scaffold_input_radio(column, html_options) end.html_safe end - # requires RecordSelect plugin to be installed and configured. - # ... maybe this should be provided in a bridge? - def active_scaffold_input_record_select(column, options) - if column.singular_association? - multiple = false - multiple = column.options[:html_options][:multiple] if column.options[:html_options] && column.options[:html_options][:multiple] - active_scaffold_record_select(column, options, @record.send(column.name), multiple) - elsif column.plural_association? - active_scaffold_record_select(column, options, @record.send(column.name), true) - end - end - - def active_scaffold_record_select(column, options, value, multiple) - unless column.association - raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)." - end - remote_controller = active_scaffold_controller_for(column.association.klass).controller_path - - # if the opposite association is a :belongs_to (in that case association in this class must be has_one or has_many) - # then only show records that have not been associated yet - if [:has_one, :has_many].include?(column.association.macro) - params.merge!({column.association.foreign_key => ''}) - end - - record_select_options = {:controller => remote_controller, :id => options[:id]} - record_select_options.merge!(active_scaffold_input_text_options) - record_select_options.merge!(column.options) - - if multiple - record_multi_select_field(options[:name], value || [], record_select_options) - else - record_select_field(options[:name], value || column.association.klass.new, record_select_options) - end - end - def active_scaffold_input_checkbox(column, options) check_box(:record, column.name, options) end diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 9e5f3cf92e..e0cbd32dc2 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -177,27 +177,6 @@ def active_scaffold_search_range(column, options) alias_method :active_scaffold_search_float, :active_scaffold_search_range alias_method :active_scaffold_search_string, :active_scaffold_search_range - def active_scaffold_search_record_select(column, options) - value = field_search_record_select_value(column) - active_scaffold_record_select(column, options, value, column.options[:multiple]) - end - - def field_search_record_select_value(column) - begin - value = field_search_params[column.name] - unless value.blank? - if column.options[:multiple] - column.association.klass.find value.collect!(&:to_i) - else - column.association.klass.find(value.to_i) - end - end - rescue Exception => e - logger.error Time.now.to_s + "Sorry, we are not that smart yet. Attempted to restore search values to search fields but instead got -- #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}" - raise e - end - end - def field_search_datetime_value(value) DateTime.new(value[:year].to_i, value[:month].to_i, value[:day].to_i, value[:hour].to_i, value[:minute].to_i, value[:second].to_i) unless value.nil? || value[:year].blank? end From 33a134dcfc017502dbcc13b4852c6f0681121cc4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 4 May 2011 12:51:01 +0200 Subject: [PATCH 1186/2024] different classes in subform footer buttons for singular associations (cherry picked from commit f336344e1a7d0bc415084c734e83b515808c61e8) --- .../default/views/_form_association_footer.html.erb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index 7a8071278d..9cd237e95c 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -17,9 +17,15 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as <div class="footer-wrapper"> <div class="footer"> <% if show_add_new -%> - <% add_label = column.plural_association? ? as_(:create_another, :model => column.association.klass.model_name.human) : as_(:replace_with_new) + <% if column.plural_association? + add_label = as_(:create_another, :model => column.association.klass.model_name.human) + add_class = 'as_create_another' + else + add_label = as_(:replace_with_new) + add_class = 'as_replace_with_new' + end create_another_id = "#{sub_form_id(:association => column.name)}-create-another" %> - <%= tag(:input, {:id => create_another_id, :type => 'button', :value => add_label, :href => add_new_url.html_safe, 'data-remote' => true, :style=> "display: none;"}) %> + <%= tag(:input, {:id => create_another_id, :type => 'button', :value => add_label, :href => add_new_url.html_safe, 'data-remote' => true, :class => add_class, :style=> "display: none;"}) %> <%= javascript_tag("ActiveScaffold.show('#{create_another_id}');") %> <% end -%> @@ -32,7 +38,7 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as <% select_options = options_for_select(options_for_association(column.association)) add_existing_id = "#{sub_form_id(:association => column.name)}-add-existing" %> <%= select_tag 'associated_id', '<option value="">'.html_safe + as_(:_select_) + '</option>'.html_safe + select_options %> - <%= tag(:input, {:id => add_existing_id, :type => 'button', :value => as_(:add_existing), :href => edit_associated_url.html_safe, 'data-remote' => true, :class=> 'as_add_existing', :style => "display: none;"}) %> + <%= tag(:input, {:id => add_existing_id, :type => 'button', :value => as_(:add_existing), :href => edit_associated_url.html_safe, 'data-remote' => true, :class=> column.plural_association? ? 'as_add_existing' : 'as_replace_existing', :style => "display: none;"}) %> <%= javascript_tag("ActiveScaffold.show('#{add_existing_id}');") %> <% end -%> <% end -%> From 7725b507f264241121ec5a85c600212ea2771e11 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 4 May 2011 14:32:04 +0200 Subject: [PATCH 1187/2024] update spanish translation (cherry picked from commit 315c22540cbc380ff1bdfd05d99745263c4a613e) --- lib/active_scaffold/locale/es.yml | 64 +++++++++++++++---------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index 339f1ea1f7..85dbbd9484 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -8,8 +8,8 @@ es: click_to_edit: 'Pulsa para editar' click_to_reset: 'Pulsa para restaurar' close: 'Cerrar' - config_list: 'Configure' - config_list_model: 'Configure Columns for %{model}' + config_list: 'Configurar' + config_list_model: 'Configurar columnas de %{model}' create: 'Crear' create_model: 'Crear %{model}' create_another: 'Crear Otro %{model}' @@ -31,7 +31,7 @@ es: live_search: 'Buscar en Vivo' loading: 'Cargando…' nested_for_model: '%{nested_model} de %{parent_model}' - nested_of_model: '%{nested_model} of %{parent_model}' + nested_of_model: '%{nested_model} de %{parent_model}' next: 'Siguiente' no_entries: 'Sin entradas' no_options: 'sin opciones' @@ -67,31 +67,31 @@ es: contains: 'Contiene' begins_with: 'Empieza con' ends_with: 'Termina con' - today: 'Today' - yesterday: 'Yesterday' - tomorrow: 'Tommorrow' - this_week: 'This Week' - prev_week: 'Last Week' - next_week: 'Next Week' - this_month: 'This Month' - prev_month: 'Last Month' - next_month: 'Next Month' - this_year: 'This Year' - prev_year: 'Last Year' - next_year: 'Next Year' - past: 'Past' - future: 'Future' - range: 'Range' - seconds: 'Seconds' - minutes: 'Minutes' - hours: 'Hours' - days: 'Days' - weeks: 'Weeks' - months: 'Months' - years: 'Years' - optional_attributes: 'Further Options' - null: 'Null' - not_null: 'Not Null' + today: 'Hoy' + yesterday: 'Ayer' + tomorrow: 'Mañana' + this_week: 'Esta semana' + prev_week: 'Semana pasada' + next_week: 'Próxima semana' + this_month: 'Este mes' + prev_month: 'Mes pasado' + next_month: 'Próximo mes' + this_year: 'Este año' + prev_year: 'Año pasado' + next_year: 'Próximo año' + past: 'Pasado' + future: 'Futuro' + range: 'Rango' + seconds: 'Segundos' + minutes: 'Minutos' + hours: 'Horas' + days: 'Días' + weeks: 'Semanas' + months: 'Meses' + years: 'Años' + optional_attributes: 'Más opciones' + null: 'Nulo' + not_null: 'No Nulo' date_picker_options: weekHeader: 'Sm' firstDay: 1 @@ -104,12 +104,12 @@ es: errors: template: header: - one: "1 error prohibited this %{model} from being saved." - other: "%{count} errors prohibited this %{model} from being saved" - body: "There were problems with the following fields:" + one: "No se pudo guardar debido a un error." + other: "No se pudo guardar debido a %{count} errores." + body: "Hubo problemas con los siguientes campos:" # error_messages cant_destroy_record: "No se pudo borrar %{record}" internal_error: 'Petición fallida (código 500, error interno)' version_inconsistency: 'Inconsistencia de versiones - este registro se ha modificado después de que empezó a editarlo.' - no_authorization_for_action: "No Authorization for action %{action}" + no_authorization_for_action: "No dispone de autorización para la acción %{action}" From 8db793f9c14ac2d2ed60c538ee3836835999a087 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 5 May 2011 11:02:57 +0200 Subject: [PATCH 1188/2024] fix edit_associated for singular associations (cherry picked from commit 62c90dc34a2920129e65bf3fb6cd6d480854d7e0) --- app/assets/javascripts/jquery/active_scaffold.js | 4 ++-- app/assets/javascripts/prototype/active_scaffold.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 816060b3f6..c3748fb3a9 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -152,7 +152,7 @@ $(document).ready(function() { $(this).prevAll('img.loading-indicator').css('visibility','hidden'); return true; }); - $('input[type=button].as_add_existing').live('ajax:before', function(event) { + $('input[type=button].as_add_existing, input[type=button].as_replace_existing').live('ajax:before', function(event) { var url = $(this).attr('href').replace('--ID--', $(this).prev().val()); event.data_url = url; return true; @@ -631,7 +631,7 @@ var ActiveScaffold = { element.append(content); } } else { - var current = $('#' + element.attr('id') + ' tr.association-record') + var current = $('#' + element.attr('id') + ' .association-record') if (current[0]) { this.replace(current[0], content); } else { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index e19b77c5d8..e7b01dbdd7 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -230,7 +230,7 @@ document.observe("dom:loaded", function() { if(loading_indicator) loading_indicator.style.visibility = 'hidden'; return true; }); - document.on('ajax:before', 'input[type=button].as_add_existing', function(event) { + document.on('ajax:before', 'input[type=button].as_add_existing, input[type=button].as_replace_existing', function(event) { var button = event.findElement(); var url = button.readAttribute('href').sub('--ID--', button.previous().getValue()); event.memo.url = url; @@ -561,7 +561,7 @@ var ActiveScaffold = { element.insert(content); } } else { - var current = $$('#' + element.readAttribute('id') + ' tr.association-record'); + var current = $$('#' + element.readAttribute('id') + ' .association-record'); if (current[0]) { this.replace(current[0], content); } else { From 610775e9a163faebd3afb9cf4b7f2542c37666c4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 16 May 2011 14:27:33 +0200 Subject: [PATCH 1189/2024] fix edit_associated action (cherry picked from commit 34d2a1cd03b85284309379c0988b58059aff4388) --- lib/active_scaffold/actions/subform.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index 5d1f015552..df6708e7eb 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -2,7 +2,7 @@ module ActiveScaffold::Actions module Subform def edit_associated do_edit_associated - render :action => 'edit_associated' + render :action => 'edit_associated.js' end protected From b03c5da0e3caee35200eae13dd05aefc4d51fb53 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 15 Jun 2011 13:56:06 +0200 Subject: [PATCH 1190/2024] fix shoulda macros (cherry picked from commit 41669f2f8b06b3297697318e76467692b27769f4) --- shoulda_macros/macros.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shoulda_macros/macros.rb b/shoulda_macros/macros.rb index bb810e1dc0..fdc5031881 100644 --- a/shoulda_macros/macros.rb +++ b/shoulda_macros/macros.rb @@ -26,7 +26,7 @@ def self.should_not_include_columns_in(action, *columns) def self.should_render_as_form_ui(column_name, form_ui) should "render column #{column_name} as #{form_ui} form_ui", :before => lambda{ @rendered_columns = [] - ActionView::Base.any_instance.expects(:"active_scaffold_input_#{form_ui}").at_least_once.with {|column, options| + @controller.view_context_class.any_instance.expects(:"active_scaffold_input_#{form_ui}").at_least_once.with {|column, options| @rendered_columns << column.name true } @@ -60,7 +60,7 @@ def self.should_render_as_form_partial_override(column_name) def self.should_render_as_form_hidden(column_name) should "render column #{column_name} as form hidden", :before => lambda{ @rendered_columns = [] - ActionView::Base.any_instance.expects(:"hidden_field").at_least_once.with {|object, method, options| + @controller.view_context_class.any_instance.expects(:"hidden_field").at_least_once.with {|object, method, options| @rendered_columns << method true } @@ -73,7 +73,7 @@ def self.should_render_as_form_hidden(column_name) def self.should_render_as_list_ui(column_name, list_ui) should "render column #{column_name} as #{list_ui} list_ui", :before => lambda{ @rendered_columns = [] - ActionView::Base.any_instance.expects(:"active_scaffold_column_#{list_ui}").at_least_once.with {|column, options| + @controller.view_context_class.any_instance.expects(:"active_scaffold_column_#{list_ui}").at_least_once.with {|column, options| @rendered_columns << column.name true } @@ -102,7 +102,7 @@ def self.should_render_as_inplace_edit(column_name) @column = @controller.active_scaffold_config.columns[column_name] @rendered_columns = [] method = @column.list_ui == :checkbox ? :format_column_checkbox : :active_scaffold_inplace_edit - ActionView::Base.any_instance.expects(method).at_least_once.with {|model, column, options| + @controller.view_context_class.any_instance.expects(method).at_least_once.with {|model, column, options| @rendered_columns << column.name true } From 45c0577a556a56b937d77fa64cf89c5857b83ddb Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 16 Jun 2011 14:40:44 +0200 Subject: [PATCH 1191/2024] fix jquery datepicker bridge with non english localization (cherry picked from commit a2ed92c61506e76b34efe935aadc9eb8077fe7fa) --- .../bridges/date_picker/lib/datepicker_bridge.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb index d6c3886585..634cd0b4c5 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb @@ -26,6 +26,15 @@ def initialize_with_date_picker(model_id) alias_method_chain :initialize, :date_picker end +ActiveRecord::ConnectionAdapters::Column.class_eval do + class << self + def fallback_string_to_date_with_date_picker(string) + Date.strptime(string, I18n.t('date.formats.default')) rescue fallback_string_to_date_without_date_picker(string) + end + alias_method_chain :fallback_string_to_date, :date_picker + end +end + module ActiveScaffold module Bridges From d007d12b68cd262449d7bd8ce3dfb8a422e3a0ba Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 16 Jun 2011 14:41:26 +0200 Subject: [PATCH 1192/2024] simplify render field (use column.update_columns instead of setting them in the request) (cherry picked from commit 9d7be9b961eb08068b3f795f8cf11c23d02e6a9e) --- lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index cf7ca24486..219bbf0ce2 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -40,7 +40,7 @@ def render_field_for_update_columns end after_render_field(@record, column) source_id = params.delete(:source_id) - render :partial => "render_field", :collection => Array(params[:update_columns]), :content_type => 'text/javascript', :locals => {:source_id => source_id} + render :partial => "render_field", :collection => column.update_columns, :content_type => 'text/javascript', :locals => {:source_id => source_id} end end diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index bdf6731117..f89be57d52 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -79,7 +79,7 @@ def active_scaffold_input_options(column, scope = nil, options = {}) def update_columns_options(column, scope, options) if column.update_columns form_action = params[:action] == 'edit' ? :update : :create - url_params = {:action => 'render_field', :id => params[:id], :column => column.name, :update_columns => column.update_columns} + url_params = {:action => 'render_field', :id => params[:id], :column => column.name} url_params[:eid] = params[:eid] if params[:eid] url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope url_params[:scope] = params[:scope] if scope From 21704dcd3b8f7232f29d898c18278225a572ca67 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 21 Jun 2011 12:19:20 +0200 Subject: [PATCH 1193/2024] allow to set number format for virtual columns (cherry picked from commit b4eb4fef27d34dc2f768db0dffdb08901e1c363d) --- lib/active_scaffold/attribute_params.rb | 2 +- lib/active_scaffold/data_structures/column.rb | 9 ++++++++- lib/active_scaffold/helpers/form_column_helpers.rb | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 664f32bf36..a0c778cb3f 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -111,7 +111,7 @@ def column_value_from_param_simple_value(parent_record, column, value) column.association.klass.find(value) if value and not value.empty? elsif column.plural_association? column_plural_assocation_value_from_value(column, value) - elsif column.column && column.column.number? && [:i18n_number, :currency].include?(column.options[:format]) + elsif column.column && column.number? && [:i18n_number, :currency].include?(column.options[:format]) self.class.i18n_number_to_native_format(value) else # convert empty strings into nil. this works better with 'null => true' columns (and validations), diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index f3432f9d3a..756b85a26f 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -248,6 +248,11 @@ def readonly_association? def virtual? column.nil? && association.nil? end + + attr_writer :number + def number? + @number + end # this is so that array.delete and array.include?, etc., will work by column name def ==(other) #:nodoc: @@ -275,7 +280,9 @@ def initialize(name, active_record_class) #:nodoc: @associated_number = self.class.associated_number @show_blank_record = self.class.show_blank_record @actions_for_association_links = self.class.actions_for_association_links.clone if @association - @options = {:format => :i18n_number} if @column.try(:number?) + + self.number = @column.try(:number?) + @options = {:format => :i18n_number} if self.number? @form_ui = :checkbox if @column and @column.type == :boolean @form_ui = :textarea if @column and @column.type == :text @allow_add_existing = true diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index f89be57d52..5baa85b7f1 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -31,6 +31,7 @@ def active_scaffold_render_input(column, options) raise "Unknown form_ui `#{column.form_ui}' for column `#{column.name}'" end elsif column.virtual? + options[:value] = format_number_value(@record.send(column.name), column.options) if column.number? active_scaffold_input_virtual(column, options) else # regular model attribute column @@ -47,7 +48,7 @@ def active_scaffold_render_input(column, options) options[:size] ||= ActionView::Helpers::InstanceTag::DEFAULT_FIELD_OPTIONS["size"] end options[:include_blank] = true if column.column.null and [:date, :datetime, :time].include?(column.column.type) - options[:value] = format_number_value(@record.send(column.name), column.options) if column.column.number? + options[:value] = format_number_value(@record.send(column.name), column.options) if column.number? text_field(:record, column.name, options.merge(column.options)) end end From 23fc38fed88d95bdd4061e02593b42298f84790c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 21 Jun 2011 12:45:46 +0200 Subject: [PATCH 1194/2024] use to_a instead of all, when there are some errors and saving fails, new associated records are removed (cherry picked from commit 369f391ec9e585aa278fad97a715b45fbef910a8) --- frontends/default/views/_form_association.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index 6bfcc8710b..895148d4c9 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -1,6 +1,6 @@ <% parent_record = @record -associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).all +associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) if column.show_blank_record? associated associated << if column.singular_association? From 667f81dd695e87f66942ad62bc16369b98c527dc Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 21 Jun 2011 13:09:09 +0200 Subject: [PATCH 1195/2024] allow to remove last record when show_blank_record is disabled, last record is new record when saving fails (cherry picked from commit 69e4555534490f2119026d428cf1e2d8c5eb7588) --- frontends/default/views/_form_association.html.erb | 4 ++-- frontends/default/views/_horizontal_subform.html.erb | 2 +- frontends/default/views/_vertical_subform.html.erb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index 895148d4c9..0ad5f7dbdf 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -2,7 +2,7 @@ parent_record = @record associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) -if column.show_blank_record? associated +if show_blank_record = column.show_blank_record?(associated) associated << if column.singular_association? parent_record.send("build_#{column.name}".to_sym) else @@ -13,7 +13,7 @@ subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_reco -%> <h5><%= column.label -%></h5> <div id ="<%= subform_div_id %>" <%= 'style="display: none;"'.html_safe if column.collapsed -%>> -<%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated} %> +<%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record} %> </div> <%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%> <% @record = parent_record -%> diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index 75ff1999ae..8907053019 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -22,7 +22,7 @@ </td> </tr> <% end %> - <%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => @record.new_record? && @record == associated.last} %> + <%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> <% end -%> </tbody> </table> diff --git a/frontends/default/views/_vertical_subform.html.erb b/frontends/default/views/_vertical_subform.html.erb index 130de78a2a..5b3bc15eca 100644 --- a/frontends/default/views/_vertical_subform.html.erb +++ b/frontends/default/views/_vertical_subform.html.erb @@ -6,7 +6,7 @@ <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> </div> <% end %> - <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => @record.new_record? && @record == associated.last} %> + <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> <% end -%> </div> <%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%> From d0caf9871661828d9def208200610971fec7f9a5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 21 Jun 2011 15:41:12 +0200 Subject: [PATCH 1196/2024] fix render field for subforms and simplify overriding render_field view --- frontends/default/views/_render_field.js.erb | 4 ++-- frontends/default/views/render_field.js.erb | 1 + lib/active_scaffold/actions/core.rb | 11 +++++++++-- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 frontends/default/views/render_field.js.erb diff --git a/frontends/default/views/_render_field.js.erb b/frontends/default/views/_render_field.js.erb index d86f02ac38..bf81c40aa8 100644 --- a/frontends/default/views/_render_field.js.erb +++ b/frontends/default/views/_render_field.js.erb @@ -4,9 +4,9 @@ options[:is_subform] = true end %> -ActiveScaffold.render_form_field('<%source_id%>','<%=escape_javascript(render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] }))%>', options.to_json.html_safe); +ActiveScaffold.render_form_field('<%source_id%>','<%=escape_javascript(render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope }))%>', options.to_json.html_safe); <%if column.update_columns && !column.update_columns.empty?%> - <%= render(:partial => "render_field", :collection => column.update_columns)%> + <%= render(:partial => "render_field", :collection => column.update_columns, :locals => {:source_id => source_id, :scope => scope})%> <%end%> diff --git a/frontends/default/views/render_field.js.erb b/frontends/default/views/render_field.js.erb new file mode 100644 index 0000000000..7f912ba13d --- /dev/null +++ b/frontends/default/views/render_field.js.erb @@ -0,0 +1 @@ +<%= render :partial => "render_field", :collection => columns, :locals => {:source_id => source_id, :scope => scope} %> diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 219bbf0ce2..5d02580623 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -33,14 +33,21 @@ def render_field_for_update_columns column = active_scaffold_config.columns[params[:column]] unless column.nil? if column.send_form_on_update_column - @record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record]) + hash = if params[:scope] + hash = params[:scope].gsub('[','').split(']').inject(params[:record]) do |hash, index| + hash[index] + end + else + params[:record] + end + @record = update_record_from_params(@record, active_scaffold_config.update.columns, hash) else value = column_value_from_param_value(@record, column, params[:value]) @record.send "#{column.name}=", value end after_render_field(@record, column) source_id = params.delete(:source_id) - render :partial => "render_field", :collection => column.update_columns, :content_type => 'text/javascript', :locals => {:source_id => source_id} + render :locals => {:source_id => source_id, :columns => column.update_columns, :scope => params[:scope]} end end diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 5baa85b7f1..07f76b7339 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -83,7 +83,7 @@ def update_columns_options(column, scope, options) url_params = {:action => 'render_field', :id => params[:id], :column => column.name} url_params[:eid] = params[:eid] if params[:eid] url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope - url_params[:scope] = params[:scope] if scope + url_params[:scope] = scope if scope options[:class] = "#{options[:class]} update_form".strip options['data-update_url'] = url_for(url_params) From 0a24308cbba305f75d27f3f44dfc8bf547fa3e49 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 21 Jun 2011 16:59:45 +0200 Subject: [PATCH 1197/2024] only update first matching field in render_form_field, as in prototype (cherry picked from commit 35710257cfb28176b74b24dd7568bea85543254a) --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index c3748fb3a9..ef7c29bee7 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -647,7 +647,7 @@ var ActiveScaffold = { if (element.length == 0) { element = source.closest('ol.form'); } - element = element.find('.' + options.field_class); + element = element.find('.' + options.field_class + ":first"); if (element) { if (options.is_subform == false) { From 98486d4eb86312e8e7c09f4d21f28a209ed0bc7f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 22 Jun 2011 11:04:26 +0200 Subject: [PATCH 1198/2024] missing semicolon (cherry picked from commit 4e5c90b79f5257ec990603f083071304eedbd952) --- app/assets/javascripts/jquery/active_scaffold.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index ef7c29bee7..9e3a08784c 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -179,16 +179,16 @@ $(document).ready(function() { data: params, beforeSend: function(event) { element.nextAll('img.loading-indicator').css('visibility','visible'); - ActiveScaffold.disable_form(as_form) + ActiveScaffold.disable_form(as_form); }, complete: function(event) { element.nextAll('img.loading-indicator').css('visibility','hidden'); - ActiveScaffold.enable_form(as_form) + ActiveScaffold.enable_form(as_form); }, error: function (xhr, status, error) { var as_div = element.closest("div.active-scaffold"); if (as_div) { - ActiveScaffold.report_500_response(as_div) + ActiveScaffold.report_500_response(as_div); } } }); From 307bafec7d51ef2cc2fd51b8a2a9a4adfa836572 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 28 Jun 2011 10:06:13 +0200 Subject: [PATCH 1199/2024] fix update subforms when a column changes --- frontends/default/views/_form.html.erb | 2 +- frontends/default/views/_render_field.js.erb | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index 7ba406c79a..a75f15e796 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -12,7 +12,7 @@ <% elsif column.readonly_association? next %> <% elsif renders_as == :subform and !override_form_field?(column) -%> - <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %>" id="<%= sub_form_id(:association => column.name) %>"> + <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %> <%=column.name%>-sub-form" id="<%= sub_form_id(:association => column.name) %>"> <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%> </li> <% else -%> diff --git a/frontends/default/views/_render_field.js.erb b/frontends/default/views/_render_field.js.erb index bf81c40aa8..b791b90b65 100644 --- a/frontends/default/views/_render_field.js.erb +++ b/frontends/default/views/_render_field.js.erb @@ -1,8 +1,11 @@ -<%column = active_scaffold_config.columns[render_field.to_sym] - options = {:is_subform => false, :field_class => "#{column.name}-input"} +<% + column = active_scaffold_config.columns[render_field.to_sym] if column_renders_as(column) == :subform - options[:is_subform] = true - end %> + options = {:is_subform => true, :field_class => "#{column.name}-sub-form"} + else + options = {:is_subform => false, :field_class => "#{column.name}-input"} + end +-%> ActiveScaffold.render_form_field('<%source_id%>','<%=escape_javascript(render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope }))%>', options.to_json.html_safe); <%if column.update_columns && !column.update_columns.empty?%> From 9fb6dc38ef7c558e327b88a73360d393c839b675 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 22 Jul 2011 14:31:06 +0200 Subject: [PATCH 1200/2024] fix update columns for record_select form_ui (cherry picked from commit fc4cf7e319a7c3ff0b51b1fa24ec9adc0112662a) --- .../javascripts/jquery/active_scaffold.js | 69 ++++++++++--------- .../javascripts/prototype/active_scaffold.js | 61 ++++++++-------- .../record_select/lib/record_select_bridge.rb | 5 ++ 3 files changed, 72 insertions(+), 63 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 9e3a08784c..3ccf51f282 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -158,40 +158,9 @@ $(document).ready(function() { return true; }); $('input.update_form, select.update_form').live('change', function(event) { - var element = $(this); - var as_form = element.closest('form.as_form'); - var params = null; - - if (element.attr('data-update_send_form')) { - params = as_form.serialize(); - params += '&' + $.param({source_id: element.attr('id')}); - } else { - if (element.is("input:checkbox")) { - params = {value: element.is(":checked")}; - } else { - params = {value: element.val()}; - } - params.source_id = element.attr('id'); - } - - $.ajax({ - url: element.attr('data-update_url'), - data: params, - beforeSend: function(event) { - element.nextAll('img.loading-indicator').css('visibility','visible'); - ActiveScaffold.disable_form(as_form); - }, - complete: function(event) { - element.nextAll('img.loading-indicator').css('visibility','hidden'); - ActiveScaffold.enable_form(as_form); - }, - error: function (xhr, status, error) { - var as_div = element.closest("div.active-scaffold"); - if (as_div) { - ActiveScaffold.report_500_response(as_div); - } - } - }); + var element = $(this); + var value = element.is("input:checkbox") ? element.is(":checked") : element.val(); + ActiveScaffold.update_column(element, element.attr('data-update_url'), element.attr('data-update_send_form'), element.attr('id'), value); return true; }); @@ -770,6 +739,38 @@ var ActiveScaffold = { ActiveScaffold.create_inplace_editor(span, options); } } + }, + + update_column: function(element, url, send_form, source_id, val) { + var as_form = element.closest('form.as_form'); + var params = null; + + if (send_form) { + params = as_form.serialize(); + params += '&' + $.param({"source_id": source_id}); + } else { + params = {value: val}; + params.source_id = source_id; + } + + $.ajax({ + url: url, + data: params, + beforeSend: function(event) { + element.nextAll('img.loading-indicator').css('visibility','visible'); + ActiveScaffold.disable_form(as_form); + }, + complete: function(event) { + element.nextAll('img.loading-indicator').css('visibility','hidden'); + ActiveScaffold.enable_form(as_form); + }, + error: function (xhr, status, error) { + var as_div = element.closest("div.active-scaffold"); + if (as_div) { + ActiveScaffold.report_500_response(as_div); + } + } + }); } } diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index e7b01dbdd7..5ce84ade25 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -238,34 +238,7 @@ document.observe("dom:loaded", function() { }); document.on('change', 'input.update_form, select.update_form', function(event) { var element = event.findElement(); - var as_form = element.up('form.as_form'); - var params = null; - - if (element.hasAttribute('data-update_send_form')) { - params = as_form.serialize(true); - } else { - params = {value: element.getValue()}; - } - params.source_id = element.readAttribute('id'); - - new Ajax.Request(element.readAttribute('data-update_url'), { - method: 'get', - parameters: params, - onLoading: function(response) { - element.next('img.loading-indicator').style.visibility = 'visible'; - as_form.disable(); - }, - onComplete: function(response) { - element.next('img.loading-indicator').style.visibility = 'hidden'; - as_form.enable(); - }, - onFailure: function(request) { - var as_div = event.findElement('div.active-scaffold'); - if (as_div) { - ActiveScaffold.report_500_response(as_div) - } - } - }); + ActiveScaffold.update_column(element, element.readAttribute('data-update_url'), element.hasAttribute('data-update_send_form'), element.readAttribute('id'), element.getValue()); return true; }); document.on('change', 'select.as_search_range_option', function(event) { @@ -620,8 +593,38 @@ var ActiveScaffold = { } mark_all_checkbox.writeAttribute('value', ('' + !options.checked)); } - } + }, + update_column: function(element, url, send_form, source_id, val) { + var as_form = element.up('form.as_form'); + var params = null; + + if (send_form) { + params = as_form.serialize(true); + } else { + params = {value: val}; + } + params.source_id = source_id; + + new Ajax.Request(url, { + method: 'get', + parameters: params, + onLoading: function(response) { + element.next('img.loading-indicator').style.visibility = 'visible'; + as_form.disable(); + }, + onComplete: function(response) { + element.next('img.loading-indicator').style.visibility = 'hidden'; + as_form.enable(); + }, + onFailure: function(request) { + var as_div = event.findElement('div.active-scaffold'); + if (as_div) { + ActiveScaffold.report_500_response(as_div) + } + } + }); + } } /* diff --git a/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb b/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb index d941f08f95..02fbc2f90a 100644 --- a/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb +++ b/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb @@ -45,6 +45,11 @@ def active_scaffold_record_select(column, options, value, multiple) record_select_options = {:controller => remote_controller, :id => options[:id]} record_select_options.merge!(active_scaffold_input_text_options) record_select_options.merge!(column.options) + if column.update_columns + record_select_options[:onchange] = %|function(id, label) { + ActiveScaffold.update_column($("##{options[:id]}"), "#{options['data-update_url']}", #{options['data-update_send_form'].to_json}, "#{options[:id]}", id); + }| + end if multiple record_multi_select_field(options[:name], value || [], record_select_options) From 2efd30686211a590e53b7b782e84a295b97a0782 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 26 Jul 2011 12:54:01 +0200 Subject: [PATCH 1201/2024] don't set onchange for render_field on search forms (cherry picked from commit 228b6beefcc36de22f42dcf096d257d46a617833) --- .../bridges/record_select/lib/record_select_bridge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb b/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb index 02fbc2f90a..f51d6c80c3 100644 --- a/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb +++ b/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb @@ -45,7 +45,7 @@ def active_scaffold_record_select(column, options, value, multiple) record_select_options = {:controller => remote_controller, :id => options[:id]} record_select_options.merge!(active_scaffold_input_text_options) record_select_options.merge!(column.options) - if column.update_columns + if options['data-update_url'] record_select_options[:onchange] = %|function(id, label) { ActiveScaffold.update_column($("##{options[:id]}"), "#{options['data-update_url']}", #{options['data-update_send_form'].to_json}, "#{options[:id]}", id); }| From d3c8c1e7425229e95d58ac3df0604d9fb02685c8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 26 Jul 2011 12:54:23 +0200 Subject: [PATCH 1202/2024] fix null comparators on range search ui (cherry picked from commit 4a795443baa37de1724dc090031fce3d95439cb2) --- lib/active_scaffold/finder.rb | 2 ++ lib/active_scaffold/helpers/search_column_helpers.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 77b32e3ec0..b31feb124c 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -90,6 +90,8 @@ def condition_for_range(column, value, like_pattern = nil) else ["#{column.search_sql} = ?", column.column.type_cast(value)] end + elsif ActiveScaffold::Finder::NullComparators.include?(value[:opt]) + condition_for_null_type(column, value[:opt], like_pattern) elsif value[:from].blank? nil elsif ActiveScaffold::Finder::StringComparators.values.include?(value[:opt]) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index e0cbd32dc2..b4bf245bb4 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -141,7 +141,7 @@ def active_scaffold_search_range_comparator_options(column) select_options.unshift *ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} end if include_null_comparators? column - select_options += ActiveScaffold::Finder::NullComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]} + select_options += ActiveScaffold::Finder::NullComparators.collect {|comp| [as_(comp), comp]} end select_options end From 2034d445ec96d15692a5116e1d6dbff8f2165bdf Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 26 Jul 2011 13:07:09 +0200 Subject: [PATCH 1203/2024] add span to set styles for search range ui (cherry picked from commit 9da6d85e7ebe6ccfa97b3e0578fa27cd960bf68a) --- lib/active_scaffold/helpers/search_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index b4bf245bb4..aa822af09d 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -170,7 +170,7 @@ def active_scaffold_search_range(column, options) html << ' ' << content_tag(:span, (' - ' + text_field_tag("#{options[:name]}[to]", to_value, active_scaffold_input_text_options(:id => "#{options[:id]}_to", :size => text_field_size))).html_safe, :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => "display:#{(opt_value == 'BETWEEN') ? '' : 'none'}") - html + content_tag :span, html, :class => 'search_range' end alias_method :active_scaffold_search_integer, :active_scaffold_search_range alias_method :active_scaffold_search_decimal, :active_scaffold_search_range From e0d276cce624cceb67f7be1f9fb8fcaf8dd86e2b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 26 Jul 2011 13:16:12 +0200 Subject: [PATCH 1204/2024] fix error message on finder (cherry picked from commit dc802eceed9f6a2a89297a008c256334b86a5193) --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index b31feb124c..65c5d8fb32 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -66,7 +66,7 @@ def condition_for_column(column, value, text_search = :full) end end rescue Exception => e - logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column :#{column.name}, search_ui = #{search_ui} in #{@controller.class}" + logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column :#{column.name}, search_ui = #{search_ui} in #{self.name}" raise e end end From a63a75a5ef8d3bf8d8dd814f3cd6f2f04a515cea Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 26 Jul 2011 14:55:02 +0200 Subject: [PATCH 1205/2024] fix custom action formats (config.list.formats, config.create.formats, ...) (cherry picked from commit 9eef2ce7503ca85173f679ae399e9d158a87dad9) --- lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/actions/list.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 5d02580623..30ceee5f99 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -170,7 +170,7 @@ def respond_to_action(action) end def action_formats - @action_formats ||= if respond_to? "#{action_name}_formats" + @action_formats ||= if respond_to? "#{action_name}_formats", true send("#{action_name}_formats") else (default_formats + active_scaffold_config.formats).uniq diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 2990d37cbc..f50f144a6e 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -171,6 +171,7 @@ def list_authorized_filter def list_formats (default_formats + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq end + alias_method :index_formats, :list_formats alias_method :row_formats, :list_formats def action_update_formats From 49c363d46f3a4097dd0466fb29a52fc5f9b1c403 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 2 Aug 2011 10:20:56 +0200 Subject: [PATCH 1206/2024] allow to override crud_type in process_action_link_action (cherry picked from commit 105d76b616d1e537ab11cb44350cde9b2e5cfa90) --- lib/active_scaffold/actions/list.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index f50f144a6e..2c6267a5ee 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -115,14 +115,15 @@ def list_authorized? # self.successful = true # flash[:info] = 'Player fired' # end - def process_action_link_action(render_action = :action_update) + def process_action_link_action(render_action = :action_update, crud_type = nil) if request.get? # someone has disabled javascript, we have to show confirmation form first @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0 respond_to_action(:action_confirmation) else if params[:id] && params[:id] && params[:id].to_i > 0 - @record = find_if_allowed(params[:id], (request.post? || request.put?) ? :update : :delete) + crud_type ||= (request.post? || request.put?) ? :update : :delete + @record = find_if_allowed(params[:id], crud_type) unless @record.nil? yield @record else From 791d68df112188e02434b6486c5f89b6fe704787 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 2 Aug 2011 13:17:11 +0200 Subject: [PATCH 1207/2024] fix authorization checks in horizontal subform (cherry picked from commit dcda8f7250e0d81dd1fa4daba9350b0a8ebeb9e4) --- frontends/default/views/_horizontal_subform_header.html.erb | 2 +- frontends/default/views/_horizontal_subform_record.html.erb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_horizontal_subform_header.html.erb b/frontends/default/views/_horizontal_subform_header.html.erb index 240d0d3bbe..5c77304fbc 100644 --- a/frontends/default/views/_horizontal_subform_header.html.erb +++ b/frontends/default/views/_horizontal_subform_header.html.erb @@ -1,7 +1,7 @@ <thead> <tr> <% - active_scaffold_config_for(@record.class).subform.columns.each :for => @record, :flatten => true do |column| + active_scaffold_config_for(@record.class).subform.columns.each :for => @record.class, :flatten => true do |column| next unless in_subform?(column, parent_record) and column_renders_as(column) != :hidden -%> <th<%= ' class="required"' if column.required? %>><label><%= column.label %></label></th> diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index 7770cf5359..f01de46709 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -1,4 +1,5 @@ -<% record_column = column +<% + record_column = column readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) crud_type = @record.new_record? ? :create : (readonly ? :read : :update) show_actions = false @@ -15,7 +16,7 @@ column.form_ui ||= :select if column.association -%> <td> - <% unless readonly and not @record.new_record? -%> + <% unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) -%> <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%> <% else -%> <p><%= get_column_value(@record, column) -%></p> From 39a820c6968dab53624114a9e78d709108de309f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 18 Apr 2011 11:42:23 +0200 Subject: [PATCH 1208/2024] overriding options_for_association_conditions works for add existing now (cherry picked from commit d86950b469d9e2e92c283ee7da0e95ae04b15118) --- frontends/default/views/_form_association_footer.html.erb | 3 ++- lib/active_scaffold/helpers/view_helpers.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index 9cd237e95c..c95596dd3c 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -4,9 +4,10 @@ begin rescue ActiveScaffold::ControllerNotFound remote_controller = nil end +@record = parent_record show_add_existing = column_show_add_existing(column) -show_add_new = column_show_add_new(column, associated, @record) +show_add_new = column_show_add_new(column, associated) return unless show_add_new or show_add_existing diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 4f3081aceb..cf85770d41 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -323,9 +323,9 @@ def column_show_add_existing(column) (column.allow_add_existing and options_for_association_count(column.association) > 0) end - def column_show_add_new(column, associated, record) + def column_show_add_new(column, associated) value = (column.plural_association? && !column.readonly_association?) || (column.singular_association? and not associated.empty?) - value = false unless record.class.authorized_for?(:crud_type => :create) + value = false unless column.association.klass.authorized_for?(:crud_type => :create) value end From d3fe7bd3474f4b2f51a0583f71d55890480dd45f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 2 Aug 2011 12:38:49 +0200 Subject: [PATCH 1209/2024] add record to column_show_add_new arguments, it could be useful when method is overrided (cherry picked from commit c2551609e0564a504f242c3a8d2da6c882931666) --- frontends/default/views/_form_association_footer.html.erb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index c95596dd3c..c1eaa81e2d 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -7,7 +7,7 @@ end @record = parent_record show_add_existing = column_show_add_existing(column) -show_add_new = column_show_add_new(column, associated) +show_add_new = column_show_add_new(column, associated, @record) return unless show_add_new or show_add_existing diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index cf85770d41..988cefc9b3 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -323,7 +323,7 @@ def column_show_add_existing(column) (column.allow_add_existing and options_for_association_count(column.association) > 0) end - def column_show_add_new(column, associated) + def column_show_add_new(column, associated, record) value = (column.plural_association? && !column.readonly_association?) || (column.singular_association? and not associated.empty?) value = false unless column.association.klass.authorized_for?(:crud_type => :create) value From 020430a5611827af4e81a04ebd4c902d1e30099e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 2 Aug 2011 14:01:06 +0200 Subject: [PATCH 1210/2024] add show_unauthorized_columns to show value for unauthorized columns instead of skip them (cherry picked from commit d6cf7d8b618d5fb1df6b71f384eaeadef72c9919) --- frontends/default/views/_base_form.html.erb | 2 +- frontends/default/views/_form.html.erb | 10 ++++++---- frontends/default/views/_form_attribute.html.erb | 6 ++++++ lib/active_scaffold/config/form.rb | 6 ++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index 2775d69845..4019a55187 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -39,7 +39,7 @@ end <% end -%> </div> - <%= render :partial => body_partial, :locals => { :columns => columns } %> + <%= render :partial => body_partial, :locals => { :columns => columns, :form_action => form_action } %> <p class="form-footer"> <%= submit_tag as_(form_action), :class => "submit" %> diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index a75f15e796..6e89fd06b2 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -1,23 +1,25 @@ <% subsection_id ||= nil %> +<% show_unauthorized_columns = active_scaffold_config.send(form_action).show_unauthorized_columns %> <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= "style=\"display: none;\"" if columns.collapsed %>> - <% columns.each :for => @record do |column| %> + <% columns.each :for => @record, :crud_type => (:read if show_unauthorized_columns) do |column| %> + <% authorized = show_unauthorized_columns ? @record.authorized_for?(:crud_type => form_action, :column => column.name) : true %> <% renders_as = column_renders_as(column) %> <% if renders_as == :subsection -%> <% subsection_id = sub_section_id(:sub_section => column.label) %> <li class="sub-section"> <h5><%= column.label %></h5> - <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id} %> + <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id, :form_action => form_action } %> <%= link_to_visibility_toggle(subsection_id, {:default_visible => !column.collapsed}) -%> </li> <% elsif column.readonly_association? next %> - <% elsif renders_as == :subform and !override_form_field?(column) -%> + <% elsif renders_as == :subform and !override_form_field?(column) and authorized -%> <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %> <%=column.name%>-sub-form" id="<%= sub_form_id(:association => column.name) %>"> <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%> </li> <% else -%> <li class="form-element <%= 'required' if column.required? %> <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %>"> - <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%> + <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column, :authorized => authorized } -%> </li> <% end -%> <% end -%> diff --git a/frontends/default/views/_form_attribute.html.erb b/frontends/default/views/_form_attribute.html.erb index 724c9b5f16..7a8c5ec541 100644 --- a/frontends/default/views/_form_attribute.html.erb +++ b/frontends/default/views/_form_attribute.html.erb @@ -1,10 +1,16 @@ <% scope ||= nil %> +<% authorized = true unless local_assigns.has_key? :authorized %> <dl> <dt> <label for="<%= active_scaffold_input_options(column, scope)[:id] %>"><%= column.label %></label> </dt> <dd> + <% if authorized %> <%=raw active_scaffold_input_for column, scope %> + <% else %> + <%= get_column_value(@record, column) %> + <%= hidden_field :record, column.association ? column.association.primary_key_name : column.name, active_scaffold_input_options(column, scope) -%> + <% end %> <% if column.update_columns -%> <%= loading_indicator_tag(:action => :render_field, :id => params[:id]) %> <% end -%> diff --git a/lib/active_scaffold/config/form.rb b/lib/active_scaffold/config/form.rb index 0331567b59..d4579d6cf7 100644 --- a/lib/active_scaffold/config/form.rb +++ b/lib/active_scaffold/config/form.rb @@ -6,6 +6,7 @@ def initialize(core_config) # start with the ActionLink defined globally @link = self.class.link.clone unless self.class.link.nil? @action_group = self.class.action_group.clone if self.class.action_group + @show_unauthorized_columns = self.class.show_unauthorized_columns # no global setting here because multipart should only be set for specific forms @multipart = false @@ -13,10 +14,15 @@ def initialize(core_config) # global level configuration # -------------------------- + # show value of unauthorized columns instead of skip them + class_inheritable_accessor :show_unauthorized_columns # instance-level configuration # ---------------------------- + # show value of unauthorized columns instead of skip them + attr_accessor :show_unauthorized_columns + # the ActionLink for this action attr_accessor :link From c9f02f855603d9b22527e89b10e1ce1b91168545 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 3 Aug 2011 10:44:57 +0200 Subject: [PATCH 1211/2024] simplify last commit (cherry picked from commit 067a315357a224630cd17351e8f9cd8fb3db2f14) --- frontends/default/views/_form.html.erb | 2 +- frontends/default/views/_form_attribute.html.erb | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index 6e89fd06b2..514878356a 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -19,7 +19,7 @@ </li> <% else -%> <li class="form-element <%= 'required' if column.required? %> <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %>"> - <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column, :authorized => authorized } -%> + <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column, :only_value => !authorized } -%> </li> <% end -%> <% end -%> diff --git a/frontends/default/views/_form_attribute.html.erb b/frontends/default/views/_form_attribute.html.erb index 7a8c5ec541..a0a427b1bb 100644 --- a/frontends/default/views/_form_attribute.html.erb +++ b/frontends/default/views/_form_attribute.html.erb @@ -1,11 +1,10 @@ <% scope ||= nil %> -<% authorized = true unless local_assigns.has_key? :authorized %> <dl> <dt> <label for="<%= active_scaffold_input_options(column, scope)[:id] %>"><%= column.label %></label> </dt> <dd> - <% if authorized %> + <% unless local_assigns[:only_value] %> <%=raw active_scaffold_input_for column, scope %> <% else %> <%= get_column_value(@record, column) %> @@ -18,4 +17,4 @@ <span class="description"><%= column.description %></span> <% end -%> </dd> -</dl> \ No newline at end of file +</dl> From 509bddfb2837906a7aa8d6eddbce8a2c08fe1208 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 3 Aug 2011 10:57:39 +0200 Subject: [PATCH 1212/2024] update doc about versions (cherry picked from commit 961d5c07ab87ddc009f21e9c1e9265e91b6a438e) --- README | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/README b/README index c027d72480..3c4adc1b0b 100644 --- a/README +++ b/README @@ -18,33 +18,31 @@ http://code.google.com/p/recordselect/ == Version Information -Please note the following list of Active Scaffold branches and Rails versions. Master will not work with Rails < 2.2 +Please note the following list of Active Scaffold branches and Rails versions. Master will not work with Rails < 3.1 -Active Scaffold master currently supports rails-3.1, but incompatible changes can be introduced, if you want an stable version, use rails-2.3 +Active Scaffold master currently supports rails-3.1, but incompatible changes can be introduced, if you want an stable version, use rails-3.0 Rails 3.0.*: Active Scaffold rails-3.0 -Rails 2.3.*: Active Scaffold rails-2.3 +Rails 2.3.*: Active Scaffold rails-2.3 and v2.4 Rails 2.2.*: Active Scaffold rails-2.2 Rails 2.1.*: Active Scaffold rails-2.1 Rails < 2.1: Active Scaffold 1-1-stable (no guarantees) -Since Rails 2.3, render_component plugin is needed for nested and embbeded scaffolds. It works with rails-2.3 branch from ewildgoose repository: +Since Rails 2.3, render_component plugin is needed for nested and embedded scaffolds. It works with rails-2.3 branch from ewildgoose repository: script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3 -== Rails 3.0 compatible fork of activesaffold by Volker Hochstein: - Since Rails 3.0 render_component is not used for nesting, but is optional for embedded scaffolds. Since Rails 3.0, https://github.com/rails/verification.git is also needed. If you want to install as plugins under vendor/plugins, install these versions: rails plugin install git://github.com/vhochstein/render_component.git rails plugin install git://github.com/rails/verification.git - rails plugin install git://github.com/vhochstein/active_scaffold.git -r 'rails-3.0' + rails plugin install git://github.com/activescaffold/active_scaffold.git -r 'rails-3.0' If you want to use the gem, add to your Gemfile: gem "active_scaffold_vho" In case you would like to use most recent commit: - gem 'active_scaffold_vho', :git => 'git://github.com/vhochstein/active_scaffold.git', :branch => 'rails-3.0' + gem 'active_scaffold_vho', :git => 'git://github.com/active_scaffold/active_scaffold.git', :branch => 'rails-3.0' == Pick your own javascript framework @@ -67,7 +65,7 @@ To configure the javascript framework when installed as a gem: Add a config/initializers/active_scaffold.rb containing: ActiveScaffold.js_framework = :jquery # :prototype is the default -== Rails 3.1 compatible fork of activesaffold by Volker Hochstein: +== Rails 3.1 compatible branch: under construction From 22c7c43aa1b2f7866a825807e9e5a63a25cab0a1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 3 Aug 2011 11:34:22 +0200 Subject: [PATCH 1213/2024] change locale ruby files to yaml (cherry picked from commit 1a6db12df027bc7f41efb5ea88f9d983b5df248f) --- lib/active_scaffold/locale/de.rb | 120 ----------------------------- lib/active_scaffold/locale/de.yml | 111 +++++++++++++++++++++++++++ lib/active_scaffold/locale/en.rb | 119 ----------------------------- lib/active_scaffold/locale/en.yml | 115 ++++++++++++++++++++++++++++ lib/active_scaffold/locale/fr.rb | 122 ------------------------------ lib/active_scaffold/locale/fr.yml | 118 +++++++++++++++++++++++++++++ 6 files changed, 344 insertions(+), 361 deletions(-) delete mode 100644 lib/active_scaffold/locale/de.rb create mode 100644 lib/active_scaffold/locale/de.yml delete mode 100644 lib/active_scaffold/locale/en.rb create mode 100644 lib/active_scaffold/locale/en.yml delete mode 100644 lib/active_scaffold/locale/fr.rb create mode 100644 lib/active_scaffold/locale/fr.yml diff --git a/lib/active_scaffold/locale/de.rb b/lib/active_scaffold/locale/de.rb deleted file mode 100644 index 44812973fb..0000000000 --- a/lib/active_scaffold/locale/de.rb +++ /dev/null @@ -1,120 +0,0 @@ -{ - :'de' => { - :active_scaffold => { - :add => 'Hinzufügen', - :add_existing => 'Existierenden Eintrag hinzufügen', - :add_existing_model => 'Existierende %{model} hinzufügen', - :are_you_sure_to_delete => 'Sind Sie sicher?', - :cancel => 'Abbrechen', - :click_to_edit => 'Zum Editieren anklicken', - :click_to_reset => 'Reset', - :close => 'Schliessen', - :config_list => 'Konfigurieren', - :config_list_model => 'Konfiguriere Spalten für %{model}', - :create => 'Anlegen', - :create_model => 'Lege %{model} an', - :create_another => 'Weitere anlegen', - :created_model => '%{model} angelegt', - :create_new => 'Neu anlegen', - :customize => 'Anpassen', - :delete => 'Löschen', - :deleted_model => '%{model} gelöscht', - :delimiter => 'Trennzeichen', - :download => 'Download', - :edit => 'Bearbeiten', - :export => 'Exportieren', - :nested_for_model => '%{nested_model} für %{parent_model}', - :nested_of_model => '%{nested_model} von %{parent_model}', - :filtered => '(Gefiltert)', - :found => 'Gefunden', - :hide => 'Verstecken', - :live_search => 'Live-Suche', - :loading => 'Lade…', - :next => 'Vor', - :no_entries => 'Keine Einträge', - :no_options => 'Keine Optionen', - :omit_header => 'Lasse Header weg', - :options => 'Optionen', - :pdf => 'PDF', - :previous => 'Zurück', - :print => 'Drucken', - :refresh => 'Neu laden', - :remove => 'Entfernen', - :remove_file => 'Entferne oder Ersetze Datei', - :replace_with_new => 'Mit Neuer ersetzen', - :revisions_for_model => 'Revisionen für %{model}', - :reset => 'Zurücksetzen', - :saving => 'Speichern…', - :search => 'Suche', - :search_terms => 'Suchbegriffe', - :_select_ => '- Auswählen -', - :show => 'Anzeigen', - :show_model => 'Zeige %{model} an', - :_to_ => ' zu ', - :update => 'Speichern', - :update_model => 'Editiere %{model}', - :updated_model => '%{model} aktualisiert', - :'=' => '=', - :'>=' => '>=', - :'<=' => '<=', - :'>' => '>', - :'<' => '<', - :'!=' => '!=', - :between => 'Zwischen', - :contains => 'Enthält', - :begins_with => 'Beginnt', - :ends_with => 'Ended', - :today => 'Heute', - :yesterday => 'Gestern', - :tomorrow => 'Morgen', - :this_week => 'Diese Woche', - :prev_week => 'Letzte Woche', - :next_week => 'Nächste Woche', - :this_month => 'Diesen Monat', - :prev_month => 'Letzten Monat', - :next_month => 'Nächsten Monat', - :this_year => 'Dieses Jahr', - :prev_year => 'Letztes Jahr', - :next_year => 'Nächstes Jahr', - :past => 'Letzten', - :future => 'Nächsten', - :range => 'Zeitraum', - :seconds => 'Sekunden', - :minutes => 'Minuten', - :hours => 'Stunden', - :days => 'Tage', - :weeks => 'Wochen', - :months => 'Monate', - :years => 'Jahre', - :optional_attributes => 'Weitere', - :null => 'Null', - :not_null => 'Nicht Null', - :date_picker_options => { - :weekHeader => 'Wo', - :firstDay => 1, - :isRTL => false, - :showMonthAfterYear => false - }, - :datetime_picker_options => { - :timeText => 'Uhrzeit', - :currentText => 'Jetzt', - :closeText => 'Schließen' - }, - :errors => { - :template => { - :header => { - :one => "Konnte %{model} nicht speichern: ein Fehler.", - :other => "Konnte %{model} nicht speichern: %{count} Fehler." - }, - :body => "Bitte überprüfen Sie die folgenden Felder:" - } - }, - # error_messages - :cant_destroy_record => "%{record} kann nicht gelöscht werden", - :internal_error => 'Fehler bei der Verarbeitung (code 500, Interner Fehler)', - :version_inconsistency => 'Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben.', - :record_not_saved => 'Eintrag kann nicht gespeichert werden. Ursache unbekannt.', - :no_authorization_for_action => "Keine Berechtigung für Aktion %{action}" - } - } -} diff --git a/lib/active_scaffold/locale/de.yml b/lib/active_scaffold/locale/de.yml new file mode 100644 index 0000000000..f174545dfe --- /dev/null +++ b/lib/active_scaffold/locale/de.yml @@ -0,0 +1,111 @@ +de: + active_scaffold: + add: 'Hinzufügen' + add_existing: 'Existierenden Eintrag hinzufügen' + add_existing_model: 'Existierende %{model} hinzufügen' + are_you_sure_to_delete: 'Sind Sie sicher?' + cancel: 'Abbrechen' + click_to_edit: 'Zum Editieren anklicken' + click_to_reset: 'Reset' + close: 'Schliessen' + config_list: 'Konfigurieren' + config_list_model: 'Konfiguriere Spalten für %{model}' + create: 'Anlegen' + create_model: 'Lege %{model} an' + create_another: 'Weitere anlegen' + created_model: '%{model} angelegt' + create_new: 'Neu anlegen' + customize: 'Anpassen' + delete: 'Löschen' + deleted_model: '%{model} gelöscht' + delimiter: 'Trennzeichen' + download: 'Download' + edit: 'Bearbeiten' + export: 'Exportieren' + nested_for_model: '%{nested_model} für %{parent_model}' + nested_of_model: '%{nested_model} von %{parent_model}' + filtered: '(Gefiltert)' + found: 'Gefunden' + hide: 'Verstecken' + live_search: 'Live-Suche' + loading: 'Lade…' + next: 'Vor' + no_entries: 'Keine Einträge' + no_options: 'Keine Optionen' + omit_header: 'Lasse Header weg' + options: 'Optionen' + pdf: 'PDF' + previous: 'Zurück' + print: 'Drucken' + refresh: 'Neu laden' + remove: 'Entfernen' + remove_file: 'Entferne oder Ersetze Datei' + replace_with_new: 'Mit Neuer ersetzen' + revisions_for_model: 'Revisionen für %{model}' + reset: 'Zurücksetzen' + saving: 'Speichern…' + search: 'Suche' + search_terms: 'Suchbegriffe' + _select_: '- Auswählen -' + show: 'Anzeigen' + show_model: 'Zeige %{model} an' + _to_ : ' zu ' + update: 'Speichern' + update_model: 'Editiere %{model}' + updated_model: '%{model} aktualisiert' + '=': '=' + '>=': '>=' + '<=': '<=' + '>': '>' + '<': '<' + '!=': '!=' + between: 'Zwischen' + contains: 'Enthält' + begins_with: 'Beginnt' + ends_with: 'Ended' + today: 'Heute' + yesterday: 'Gestern' + tomorrow: 'Morgen' + this_week: 'Diese Woche' + prev_week: 'Letzte Woche' + next_week: 'Nächste Woche' + this_month: 'Diesen Monat' + prev_month: 'Letzten Monat' + next_month: 'Nächsten Monat' + this_year: 'Dieses Jahr' + prev_year: 'Letztes Jahr' + next_year: 'Nächstes Jahr' + past: 'Letzten', + future: 'Nächsten' + range: 'Zeitraum' + seconds: 'Sekunden' + minutes: 'Minuten' + hours: 'Stunden' + days: 'Tage' + weeks: 'Wochen' + months: 'Monate' + years: 'Jahre' + optional_attributes: 'Weitere' + null: 'Null' + not_null: 'Nicht Null' + date_picker_options: + weekHeader: 'Wo' + firstDay: 1 + isRTL: false + showMonthAfterYear: false + datetime_picker_options: + timeText: 'Uhrzeit' + currentText: 'Jetzt' + closeText: 'Schließen' + errors: + template: + header: + one: "Konnte %{model} nicht speichern: ein Fehler." + other: "Konnte %{model} nicht speichern: %{count} Fehler." + body: "Bitte überprüfen Sie die folgenden Felder:" + # error_messages + cant_destroy_record: "%{record} kann nicht gelöscht werden" + internal_error: 'Fehler bei der Verarbeitung (code 500, Interner Fehler)' + version_inconsistency: 'Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben.' + record_not_saved: 'Eintrag kann nicht gespeichert werden. Ursache unbekannt.' + no_authorization_for_action: "Keine Berechtigung für Aktion %{action}" diff --git a/lib/active_scaffold/locale/en.rb b/lib/active_scaffold/locale/en.rb deleted file mode 100644 index 61fe874d23..0000000000 --- a/lib/active_scaffold/locale/en.rb +++ /dev/null @@ -1,119 +0,0 @@ -{ - :'en' => { - :active_scaffold => { - :add => 'Add', - :add_existing => 'Add Existing', - :add_existing_model => 'Add Existing %{model}', - :are_you_sure_to_delete => 'Are you sure you want to delete %{label}?', - :cancel => 'Cancel', - :click_to_edit => 'Click to edit', - :click_to_reset => 'Click to reset', - :close => 'Close', - :config_list => 'Configure', - :config_list_model => 'Configure Columns for %{model}', - :create => 'Create', - :create_model => 'Create %{model}', - :create_another => 'Create Another %{model}', - :created_model => 'Created %{model}', - :create_new => 'Create New', - :customize => 'Customize', - :delete => 'Delete', - :deleted_model => 'Deleted %{model}', - :delimiter => 'Delimiter', - :download => 'Download', - :edit => 'Edit', - :export => 'Export', - :nested_for_model => '%{nested_model} for %{parent_model}', - :nested_of_model => '%{nested_model} of %{parent_model}', - :false => 'False', - :filtered => '(Filtered)', - :found => 'Found', - :hide => 'Hide', - :live_search => 'Live Search', - :loading => 'Loading…', - :next => 'Next', - :no_entries => 'No Entries', - :no_options => 'no options', - :omit_header => 'Omit Header', - :options => 'Options', - :pdf => 'PDF', - :previous => 'Previous', - :print => 'Print', - :refresh => 'Refresh', - :remove => 'Remove', - :remove_file => 'Remove or Replace file', - :replace_with_new => 'Replace With New', - :revisions_for_model => 'Revisions for %{model}', - :reset => 'Reset', - :saving => 'Saving…', - :search => 'Search', - :search_terms => 'Search Terms', - :_select_ => '- select -', - :show => 'Show', - :show_model => 'Show %{model}', - :_to_ => ' to ', - :true => 'True', - :update => 'Update', - :update_model => 'Update %{model}', - :updated_model => 'Updated %{model}', - :'=' => '=', - :'>=' => '>=', - :'<=' => '<=', - :'>' => '>', - :'<' => '<', - :'!=' => '!=', - :between => 'Between', - :contains => 'Contains', - :begins_with => 'Begins with', - :ends_with => 'Ends with', - :today => 'Today', - :yesterday => 'Yesterday', - :tomorrow => 'Tommorrow', - :this_week => 'This Week', - :prev_week => 'Last Week', - :next_week => 'Next Week', - :this_month => 'This Month', - :prev_month => 'Last Month', - :next_month => 'Next Month', - :this_year => 'This Year', - :prev_year => 'Last Year', - :next_year => 'Next Year', - :past => 'Past', - :future => 'Future', - :range => 'Range', - :seconds => 'Seconds', - :minutes => 'Minutes', - :hours => 'Hours', - :days => 'Days', - :weeks => 'Weeks', - :months => 'Months', - :years => 'Years', - :optional_attributes => 'Further Options', - :null => 'Null', - :not_null => 'Not Null', - :date_picker_options => { - :weekHeader => 'Wk', - :firstDay => 0, - :isRTL => false, - :showMonthAfterYear => false - }, - :datetime_picker_options => { - }, - :errors => { - :template => { - :header => { - :one => "1 error prohibited this %{model} from being saved.", - :other => "%{count} errors prohibited this %{model} from being saved" - }, - :body => "There were problems with the following fields:" - } - }, - # error_messages - :cant_destroy_record => "%{record} can't be destroyed", - :internal_error => 'Request Failed (code 500, Internal Error)', - :version_inconsistency => 'Version inconsistency - this record has been modified since you started editing it.', - :record_not_saved => 'Failed to save record cause of an unknown error', - :no_authorization_for_action => "No Authorization for action %{action}" - } - } -} diff --git a/lib/active_scaffold/locale/en.yml b/lib/active_scaffold/locale/en.yml new file mode 100644 index 0000000000..98bc2399a8 --- /dev/null +++ b/lib/active_scaffold/locale/en.yml @@ -0,0 +1,115 @@ +en: + active_scaffold: + add: 'Add' + add_existing: 'Add Existing' + add_existing_model: 'Add Existing %{model}' + are_you_sure_to_delete: 'Are you sure you want to delete %{label}?' + cancel: 'Cancel' + click_to_edit: 'Click to edit' + click_to_reset: 'Click to reset' + close: 'Close' + config_list: 'Configure' + config_list_model: 'Configure Columns for %{model}' + create: 'Create' + create_model: 'Create %{model}' + create_another: 'Create Another %{model}' + created_model: 'Created %{model}' + create_new: 'Create New' + customize: 'Customize' + delete: 'Delete' + deleted_model: 'Deleted %{model}' + delimiter: 'Delimiter' + download: 'Download' + edit: 'Edit' + export: 'Export' + nested_for_model: '%{nested_model} for %{parent_model}' + nested_of_model: '%{nested_model} of %{parent_model}' + 'false': 'False' + filtered: '(Filtered)' + found: 'Found' + hide: 'Hide' + live_search: 'Live Search' + loading: 'Loading…' + next: 'Next' + no_entries: 'No Entries' + no_options: 'no options' + omit_header: 'Omit Header' + options: 'Options' + pdf: 'PDF' + previous: 'Previous' + print: 'Print' + refresh: 'Refresh' + remove: 'Remove' + remove_file: 'Remove or Replace file' + replace_with_new: 'Replace With New' + revisions_for_model: 'Revisions for %{model}' + reset: 'Reset' + saving: 'Saving…' + search: 'Search' + search_terms: 'Search Terms' + _select_: '- select -' + show: 'Show' + show_model: 'Show %{model}' + _to_ : ' to ' + 'true': 'True' + update: 'Update' + update_model: 'Update %{model}' + updated_model: 'Updated %{model}' + '=': '=' + '>=': '>=' + '<=': '<=' + '>': '>' + '<': '<' + '!=': '!=' + between: 'Between' + contains: 'Contains' + begins_with: 'Begins with' + ends_with: 'Ends with' + today: 'Today' + yesterday: 'Yesterday' + tomorrow: 'Tommorrow' + this_week: 'This Week' + prev_week: 'Last Week' + next_week: 'Next Week' + this_month: 'This Month' + prev_month: 'Last Month' + next_month: 'Next Month' + this_year: 'This Year' + prev_year: 'Last Year' + next_year: 'Next Year' + past: 'Past', + future: 'Future' + range: 'Range' + seconds: 'Seconds' + minutes: 'Minutes' + hours: 'Hours' + days: 'Days' + weeks: 'Weeks' + months: 'Months' + years: 'Years' + optional_attributes: 'Further Options' + null: 'Null' + not_null: 'Not Null' + date_picker_options: + weekHeader: 'Wk' + firstDay: 0 + isRTL: false + showMonthAfterYear: false + + datetime_picker_options: + + errors: + template: + header: + one: "1 error prohibited this %{model} from being saved." + other: "%{count} errors prohibited this %{model} from being saved" + + body: "There were problems with the following fields:" + + + # error_messages + cant_destroy_record: "%{record} can't be destroyed" + internal_error: 'Request Failed (code 500, Internal Error)' + version_inconsistency: 'Version inconsistency - this record has been modified since you started editing it.' + record_not_saved: 'Failed to save record cause of an unknown error' + no_authorization_for_action: "No Authorization for action %{action}" diff --git a/lib/active_scaffold/locale/fr.rb b/lib/active_scaffold/locale/fr.rb deleted file mode 100644 index a9dc14e78e..0000000000 --- a/lib/active_scaffold/locale/fr.rb +++ /dev/null @@ -1,122 +0,0 @@ -{ - :'fr' => { - :active_scaffold => { - :add => 'Ajouter', - :add_existing => 'Ajouter un(e) existant(e)', - :add_existing_model => 'Ajouter un(e) %{model} existant(e)', - :are_you_sure_to_delete => 'Êtes vous sûr?', - :cancel => 'Annuler', - :click_to_edit => 'Cliquer pour éditer', - :click_to_reset => 'Cliquer pour ré-initialiser', - :close => 'Fermer', - :config_list => 'Configure', - :config_list_model => 'Configure Columns for %{model}', - :create => 'Créer', - :create_model => 'Créer %{model}', - :create_another => 'Créer un autre', - :created_model => '%{model} créé', - :create_new => 'Créer un nouveau', - :customize => 'Personnaliser', - :delete => 'Supprimer', - :deleted_model => 'Suppression de %{model}', - :delimiter => 'Délimiteur', - :download => 'Télécharger', - :edit => 'Éditer', - :export => 'Exporter', - :nested_for_model => '%{nested_model} pour %{parent_model}', - :nested_of_model => '%{nested_model} de %{parent_model}', - :false => 'Faux', - :filtered => '(Filtré)', - :found => 'Trouvé', - :hide => 'Cacher', - :live_search => 'Recherche en temps réel', - :loading => 'Chargement…', - :next => 'Suivant', - :no_entries => "Pas d'entrée", - :no_options => "pas d'option", - :omit_header => 'Omettre les en-têtes', - :options => 'Options', - :pdf => 'PDF', - :previous => 'Précédent', - :print => 'Imprimer', - :refresh => 'Rafraîchir', - :remove => 'Supprimer', - :remove_file => 'Supprimer et remplacer le fichier', - :replace_with_new => 'Remplacer avec le nouveau', - :revisions_for_model => 'Révision pour %{model}', - :reset => 'Annuler', - :saving => 'Sauvegarder…', - :search => 'Rechercher', - :search_terms => 'Recherche de termes', - :_select_ => '- sélectionner -', - :show => 'Montrer', - :show_model => 'Montrer %{model}', - :_to_ => ' à ', - :true => 'Vrai', - :update => 'Mettre à jour', - :update_model => 'Mettre à jour le(/la) %{model}', - :updated_model => 'Mis à jour de %{model}', - :'=' => '=', - :'>=' => '>=', - :'<=' => '<=', - :'>' => '>', - :'<' => '<', - :'!=' => '!=', - :between => 'Entre', - :contains => 'Contient', - :begins_with => 'Commençant par', - :ends_with => 'Se terminant par', - :today => "Aujourd'hui", - :yesterday => 'Hier', - :tomorrow => 'Demain', - :this_week => 'Cette Semaine', - :prev_week => 'Semaine dernière', - :next_week => 'Semaine prochaine', - :this_month => 'Ce Mois', - :prev_month => 'Mois dernier', - :next_month => 'Mois prochain', - :this_year => 'Cette Année', - :prev_year => 'Année dernière', - :next_year => 'Année prochaine', - :past => 'Passé', - :future => 'Futur', - :range => 'Intervale', - :seconds => 'Secondes', - :minutes => 'Minutes', - :hours => 'Heures', - :days => 'Jours', - :weeks => 'Semaines', - :months => 'Mois', - :years => 'Années', - :optional_attributes => 'Options additionnelles', - :null => 'Nulle', - :not_null => 'Non Nulle', - :date_picker_options => { - :weekHeader => 'Sm', - :firstDay => 1, - :isRTL => false, - :showMonthAfterYear => false, - }, - :datetime_picker_options => { - :timeText => 'Heure', - :currentText => 'Maintenant', - :closeText => 'Fermer' - }, - :errors => { - :template => { - :header => { - :one => "1 erreur interdit ce(tte) %{model} d'être sauvegardé.", - :other => "%{count} erreurs interdit ce(tte) %{model} d'être sauvegardé" - }, - :body => "Il y avait des problèmes avec les champs suivants :" - } - }, - # error_messages - :cant_destroy_record => "%{record} ne peut être supprimé", - :internal_error => 'Erreur de la requête (code 500, Erreur interne)', - :version_inconsistency => "Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer.", - :record_not_saved => "Impossible d'enregistrer l'enregistrement à cause d'une erreur inconnue", - :no_authorization_for_action => "Aucune autorisation pour l'action %{action}" - } - } -} diff --git a/lib/active_scaffold/locale/fr.yml b/lib/active_scaffold/locale/fr.yml new file mode 100644 index 0000000000..bd3b9b8b85 --- /dev/null +++ b/lib/active_scaffold/locale/fr.yml @@ -0,0 +1,118 @@ +fr: + active_scaffold: + add: 'Ajouter' + add_existing: 'Ajouter un(e) existant(e)' + add_existing_model: 'Ajouter un(e) %{model} existant(e)' + are_you_sure_to_delete: 'Êtes vous sûr?' + cancel: 'Annuler' + click_to_edit: 'Cliquer pour éditer' + click_to_reset: 'Cliquer pour ré-initialiser' + close: 'Fermer' + config_list: 'Configure' + config_list_model: 'Configure Columns for %{model}' + create: 'Créer' + create_model: 'Créer %{model}' + create_another: 'Créer un autre' + created_model: '%{model} créé' + create_new: 'Créer un nouveau' + customize: 'Personnaliser' + delete: 'Supprimer' + deleted_model: 'Suppression de %{model}' + delimiter: 'Délimiteur' + download: 'Télécharger' + edit: 'Éditer' + export: 'Exporter' + nested_for_model: '%{nested_model} pour %{parent_model}' + nested_of_model: '%{nested_model} de %{parent_model}' + 'false': 'Faux' + filtered: '(Filtré)' + found: 'Trouvé' + hide: 'Cacher' + live_search: 'Recherche en temps réel' + loading: 'Chargement…' + next: 'Suivant' + no_entries: "Pas d'entrée" + no_options: "pas d'option" + omit_header: 'Omettre les en-têtes' + options: 'Options' + pdf: 'PDF' + previous: 'Précédent' + print: 'Imprimer' + refresh: 'Rafraîchir' + remove: 'Supprimer' + remove_file: 'Supprimer et remplacer le fichier' + replace_with_new: 'Remplacer avec le nouveau' + revisions_for_model: 'Révision pour %{model}' + reset: 'Annuler' + saving: 'Sauvegarder…' + search: 'Rechercher' + search_terms: 'Recherche de termes' + _select_: '- sélectionner -' + show: 'Montrer' + show_model: 'Montrer %{model}' + _to_ : ' à ' + 'true': 'Vrai' + update: 'Mettre à jour' + update_model: 'Mettre à jour le(/la) %{model}' + updated_model: 'Mis à jour de %{model}' + '=': '=' + '>=': '>=' + '<=': '<=' + '>': '>' + '<': '<' + '!=': '!=' + between: 'Entre' + contains: 'Contient' + begins_with: 'Commençant par' + ends_with: 'Se terminant par' + today: "Aujourd'hui" + yesterday: 'Hier' + tomorrow: 'Demain' + this_week: 'Cette Semaine' + prev_week: 'Semaine dernière' + next_week: 'Semaine prochaine' + this_month: 'Ce Mois' + prev_month: 'Mois dernier' + next_month: 'Mois prochain' + this_year: 'Cette Année' + prev_year: 'Année dernière' + next_year: 'Année prochaine' + past: 'Passé', + future: 'Futur' + range: 'Intervale' + seconds: 'Secondes' + minutes: 'Minutes' + hours: 'Heures' + days: 'Jours' + weeks: 'Semaines' + months: 'Mois' + years: 'Années' + optional_attributes: 'Options additionnelles' + null: 'Nulle' + not_null: 'Non Nulle' + date_picker_options: + weekHeader: 'Sm' + firstDay: 1 + isRTL: false + showMonthAfterYear: false + + datetime_picker_options: + timeText: 'Heure' + currentText: 'Maintenant' + closeText: 'Fermer' + + errors: + template: + header: + one: "1 erreur interdit ce(tte) %{model} d'être sauvegardé." + other: "%{count} erreurs interdit ce(tte) %{model} d'être sauvegardé" + + body: "Il y avait des problèmes avec les champs suivants :" + + + # error_messages + cant_destroy_record: "%{record} ne peut être supprimé" + internal_error: 'Erreur de la requête (code 500, Erreur interne)' + version_inconsistency: "Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer." + record_not_saved: "Impossible d'enregistrer l'enregistrement à cause d'une erreur inconnue" + no_authorization_for_action: "Aucune autorisation pour l'action %{action}" From a0aed766997823a8e3477f584ac23be7c76ecf95 Mon Sep 17 00:00:00 2001 From: Clark Li <clark.zhe.li@gmail.com> Date: Sun, 7 Aug 2011 01:57:22 -0400 Subject: [PATCH 1214/2024] I think the comma is not supposed to be here. --- lib/active_scaffold/locale/de.yml | 2 +- lib/active_scaffold/locale/en.yml | 2 +- lib/active_scaffold/locale/fr.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/locale/de.yml b/lib/active_scaffold/locale/de.yml index f174545dfe..f727bfa84e 100644 --- a/lib/active_scaffold/locale/de.yml +++ b/lib/active_scaffold/locale/de.yml @@ -75,7 +75,7 @@ de: this_year: 'Dieses Jahr' prev_year: 'Letztes Jahr' next_year: 'Nächstes Jahr' - past: 'Letzten', + past: 'Letzten' future: 'Nächsten' range: 'Zeitraum' seconds: 'Sekunden' diff --git a/lib/active_scaffold/locale/en.yml b/lib/active_scaffold/locale/en.yml index 98bc2399a8..8e52600323 100644 --- a/lib/active_scaffold/locale/en.yml +++ b/lib/active_scaffold/locale/en.yml @@ -77,7 +77,7 @@ en: this_year: 'This Year' prev_year: 'Last Year' next_year: 'Next Year' - past: 'Past', + past: 'Past' future: 'Future' range: 'Range' seconds: 'Seconds' diff --git a/lib/active_scaffold/locale/fr.yml b/lib/active_scaffold/locale/fr.yml index bd3b9b8b85..9d016fa2ae 100644 --- a/lib/active_scaffold/locale/fr.yml +++ b/lib/active_scaffold/locale/fr.yml @@ -77,7 +77,7 @@ fr: this_year: 'Cette Année' prev_year: 'Année dernière' next_year: 'Année prochaine' - past: 'Passé', + past: 'Passé' future: 'Futur' range: 'Intervale' seconds: 'Secondes' From 455426982473ff4975df98c521b54c21285ae5b1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 8 Aug 2011 15:00:52 +0200 Subject: [PATCH 1215/2024] don't add description when is blank (cherry picked from commit 04e7c3d8110e727cf2ff131453ae675bcbdcbb64) --- app/assets/stylesheets/active_scaffold.css.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/stylesheets/active_scaffold.css.erb b/app/assets/stylesheets/active_scaffold.css.erb index 3a1d89819b..0ca21b3b98 100644 --- a/app/assets/stylesheets/active_scaffold.css.erb +++ b/app/assets/stylesheets/active_scaffold.css.erb @@ -791,6 +791,7 @@ padding: 6px 0; float: left; } +.active-scaffold li.form-element dd p, .active-scaffold li.form-element dd input[type="checkbox"] { margin-top: 6px; } From d9f02f0d39740b5f0f4bcece77363c07fec60225 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Sat, 20 Aug 2011 00:52:04 +0200 Subject: [PATCH 1216/2024] prepare active_scaffold gem --- Gemfile | 1 - Gemfile.lock | 7 - README | 3 +- Rakefile | 28 +-- active_scaffold.gemspec | 31 +++ active_scaffold_vho.gemspec | 388 ------------------------------------ init.rb | 3 + install.rb | 3 + lib/active_scaffold_env.rb | 1 - lib/active_scaffold_vho.rb | 2 - 10 files changed, 41 insertions(+), 426 deletions(-) create mode 100644 active_scaffold.gemspec delete mode 100644 active_scaffold_vho.gemspec create mode 100644 install.rb delete mode 100644 lib/active_scaffold_vho.rb diff --git a/Gemfile b/Gemfile index bdb0a5f83a..b5ca9e515a 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,5 @@ source "http://rubygems.org" group :development do gem "shoulda", ">= 0" gem "bundler", "~> 1.0.0" - gem "jeweler", "~> 1.5.2" gem "rcov", ">= 0" end diff --git a/Gemfile.lock b/Gemfile.lock index 07df601572..9cf16fcd74 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,12 +1,6 @@ GEM remote: http://rubygems.org/ specs: - git (1.2.5) - jeweler (1.5.2) - bundler (~> 1.0.0) - git (>= 1.2.5) - rake - rake (0.8.7) rcov (0.9.9) shoulda (2.11.3) @@ -15,6 +9,5 @@ PLATFORMS DEPENDENCIES bundler (~> 1.0.0) - jeweler (~> 1.5.2) rcov shoulda diff --git a/README b/README index 3c4adc1b0b..abb957eb36 100644 --- a/README +++ b/README @@ -59,7 +59,8 @@ JQuery > 1.4.2 https://github.com/vhochstein/jquery-ujs/raw/master/src/rails.js To configure the javascript framework when installed under vendor/plugins/ -uncomment last line in ...plugins/active_scaffold/lib/active_scaffold_env.rb in order to use jquery instead of prototype +uncomment last line in config/initializers/active_scaffold.rb in order to use jquery instead of prototype. +That file is created when you install ActiveScaffold as a plugin. To configure the javascript framework when installed as a gem: Add a config/initializers/active_scaffold.rb containing: diff --git a/Rakefile b/Rakefile index 8f02448f15..257d2085dd 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,4 @@ -require 'rubygems' +require 'rake' require 'bundler' begin Bundler.setup(:default, :development) @@ -7,35 +7,11 @@ rescue Bundler::BundlerError => e $stderr.puts "Run `bundle install` to install missing gems" exit e.status_code end -require 'rake' +Bundler::GemHelper.install_tasks require 'rake/testtask' -require 'rake/packagetask' require 'rake/rdoctask' require 'find' -require 'jeweler' -require './lib/active_scaffold/version.rb' - -Jeweler::Tasks.new do |gem| - # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options - gem.name = "active_scaffold_vho" - gem.version = ActiveScaffold::Version::STRING - gem.homepage = "http://github.com/vhochstein/active_scaffold" - gem.license = "MIT" - gem.summary = %Q{Rails 3.1 Version of activescaffold supporting prototype and jquery} - gem.description = %Q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} - gem.email = "activescaffold@googlegroups.com" - gem.authors = ["Many, see README"] - gem.add_runtime_dependency 'render_component_vho' - gem.add_runtime_dependency 'verification' - gem.add_runtime_dependency 'rails', '~> 3.1.0' - # Include your dependencies below. Runtime dependencies are required when using your gem, - # and development dependencies are only needed for development (ie running rake tasks, tests, etc) - # gem.add_runtime_dependency 'jabber4r', '> 0.1' - # gem.add_development_dependency 'rspec', '> 1.2.3' -end -Jeweler::RubygemsDotOrgTasks.new - desc 'Test ActiveScaffold.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec new file mode 100644 index 0000000000..70bc394cc6 --- /dev/null +++ b/active_scaffold.gemspec @@ -0,0 +1,31 @@ +# -*- encoding: utf-8 -*- +$LOAD_PATH.unshift File.expand_path('../lib', __FILE__) +require 'active_scaffold/version' + +Gem::Specification.new do |s| + s.name = %q{active_scaffold} + s.version = ActiveScaffold::Version::STRING + s.platform = Gem::Platform::RUBY + s.email = %q{activescaffold@googlegroups.com} + s.authors = ["Many, see README"] + s.homepage = %q{http://active_scaffold.com} + s.summary = %q{Rails 3.1 Version of activescaffold supporting prototype and jquery} + s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} + s.require_paths = ["lib"] + s.files = Dir["{frontends,lib,public,shoulda_macros}/**/*"] + %w[MIT-LICENSE CHANGELOG README] + s.extra_rdoc_files = [ + "README" + ] + s.licenses = ["MIT"] + s.test_files = Dir["test/**/*"] + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + + s.add_development_dependency(%q<shoulda>, [">= 0"]) + s.add_development_dependency(%q<bundler>, ["~> 1.0.0"]) + s.add_development_dependency(%q<rcov>, [">= 0"]) + s.add_runtime_dependency(%q<render_component_vho>, [">= 0"]) + s.add_runtime_dependency(%q<verification>, [">= 0"]) + s.add_runtime_dependency(%q<rails>, ["~> 3.0.0"]) +end + diff --git a/active_scaffold_vho.gemspec b/active_scaffold_vho.gemspec deleted file mode 100644 index ba8ac86297..0000000000 --- a/active_scaffold_vho.gemspec +++ /dev/null @@ -1,388 +0,0 @@ -# Generated by jeweler -# DO NOT EDIT THIS FILE DIRECTLY -# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' -# -*- encoding: utf-8 -*- - -Gem::Specification.new do |s| - s.name = %q{active_scaffold_vho} - s.version = "3.1.0" - - s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= - s.authors = ["Many, see README"] - s.date = %q{2011-05-27} - s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} - s.email = %q{activescaffold@googlegroups.com} - s.extra_rdoc_files = [ - "README" - ] - s.files = [ - ".autotest", - ".document", - "CHANGELOG", - "Gemfile", - "Gemfile.lock", - "MIT-LICENSE", - "README", - "Rakefile", - "active_scaffold_vho.gemspec", - "frontends/default/images/add.gif", - "frontends/default/images/arrow_down.gif", - "frontends/default/images/arrow_up.gif", - "frontends/default/images/close.gif", - "frontends/default/images/close_touch.png", - "frontends/default/images/config.png", - "frontends/default/images/cross.png", - "frontends/default/images/gears.png", - "frontends/default/images/indicator-small.gif", - "frontends/default/images/indicator.gif", - "frontends/default/images/magnifier.png", - "frontends/default/javascripts/jquery/active_scaffold.js", - "frontends/default/javascripts/jquery/jquery.editinplace.js", - "frontends/default/javascripts/prototype/active_scaffold.js", - "frontends/default/javascripts/prototype/dhtml_history.js", - "frontends/default/javascripts/prototype/form_enhancements.js", - "frontends/default/javascripts/prototype/rico_corner.js", - "frontends/default/stylesheets/stylesheet-ie.css", - "frontends/default/stylesheets/stylesheet.css", - "frontends/default/views/_action_group.html.erb", - "frontends/default/views/_add_existing_form.html.erb", - "frontends/default/views/_base_form.html.erb", - "frontends/default/views/_create_form.html.erb", - "frontends/default/views/_create_form_on_list.html.erb", - "frontends/default/views/_field_search.html.erb", - "frontends/default/views/_form.html.erb", - "frontends/default/views/_form_association.html.erb", - "frontends/default/views/_form_association_footer.html.erb", - "frontends/default/views/_form_attribute.html.erb", - "frontends/default/views/_form_hidden_attribute.html.erb", - "frontends/default/views/_form_messages.html.erb", - "frontends/default/views/_horizontal_subform.html.erb", - "frontends/default/views/_horizontal_subform_header.html.erb", - "frontends/default/views/_horizontal_subform_record.html.erb", - "frontends/default/views/_human_conditions.html.erb", - "frontends/default/views/_list.html.erb", - "frontends/default/views/_list_actions.html.erb", - "frontends/default/views/_list_calculations.html.erb", - "frontends/default/views/_list_column_headings.html.erb", - "frontends/default/views/_list_header.html.erb", - "frontends/default/views/_list_inline_adapter.html.erb", - "frontends/default/views/_list_messages.html.erb", - "frontends/default/views/_list_pagination.html.erb", - "frontends/default/views/_list_pagination_links.html.erb", - "frontends/default/views/_list_record.html.erb", - "frontends/default/views/_list_record_columns.html.erb", - "frontends/default/views/_list_with_header.html.erb", - "frontends/default/views/_messages.html.erb", - "frontends/default/views/_render_field.js.rjs", - "frontends/default/views/_row.html.erb", - "frontends/default/views/_search.html.erb", - "frontends/default/views/_search_attribute.html.erb", - "frontends/default/views/_show.html.erb", - "frontends/default/views/_show_columns.html.erb", - "frontends/default/views/_update_actions.html.erb", - "frontends/default/views/_update_form.html.erb", - "frontends/default/views/_vertical_subform.html.erb", - "frontends/default/views/_vertical_subform_record.html.erb", - "frontends/default/views/action_confirmation.html.erb", - "frontends/default/views/add_existing.js.rjs", - "frontends/default/views/add_existing_form.html.erb", - "frontends/default/views/create.html.erb", - "frontends/default/views/delete.html.erb", - "frontends/default/views/destroy.js.rjs", - "frontends/default/views/edit_associated.js.rjs", - "frontends/default/views/field_search.html.erb", - "frontends/default/views/form_messages.js.rjs", - "frontends/default/views/list.html.erb", - "frontends/default/views/list.js.rjs", - "frontends/default/views/on_action_update.js.rjs", - "frontends/default/views/on_create.js.rjs", - "frontends/default/views/on_mark_all.js.rjs", - "frontends/default/views/on_update.js.rjs", - "frontends/default/views/search.html.erb", - "frontends/default/views/show.html.erb", - "frontends/default/views/update.html.erb", - "frontends/default/views/update_column.js.rjs", - "frontends/default/views/update_row.js.rjs", - "init.rb", - "lib/active_scaffold.rb", - "lib/active_scaffold/actions/common_search.rb", - "lib/active_scaffold/actions/core.rb", - "lib/active_scaffold/actions/create.rb", - "lib/active_scaffold/actions/delete.rb", - "lib/active_scaffold/actions/field_search.rb", - "lib/active_scaffold/actions/list.rb", - "lib/active_scaffold/actions/mark.rb", - "lib/active_scaffold/actions/nested.rb", - "lib/active_scaffold/actions/search.rb", - "lib/active_scaffold/actions/show.rb", - "lib/active_scaffold/actions/subform.rb", - "lib/active_scaffold/actions/update.rb", - "lib/active_scaffold/active_record_permissions.rb", - "lib/active_scaffold/attribute_params.rb", - "lib/active_scaffold/bridges/ancestry/bridge.rb", - "lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb", - "lib/active_scaffold/bridges/bridge.rb", - "lib/active_scaffold/bridges/calendar_date_select/bridge.rb", - "lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb", - "lib/active_scaffold/bridges/cancan/bridge.rb", - "lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb", - "lib/active_scaffold/bridges/carrierwave/bridge.rb", - "lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb", - "lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb", - "lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb", - "lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb", - "lib/active_scaffold/bridges/date_picker/bridge.rb", - "lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb", - "lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js", - "lib/active_scaffold/bridges/file_column/bridge.rb", - "lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb", - "lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb", - "lib/active_scaffold/bridges/file_column/lib/form_ui.rb", - "lib/active_scaffold/bridges/file_column/lib/list_ui.rb", - "lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb", - "lib/active_scaffold/bridges/file_column/test/mock_model.rb", - "lib/active_scaffold/bridges/file_column/test/test_helper.rb", - "lib/active_scaffold/bridges/paperclip/bridge.rb", - "lib/active_scaffold/bridges/paperclip/lib/form_ui.rb", - "lib/active_scaffold/bridges/paperclip/lib/list_ui.rb", - "lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb", - "lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb", - "lib/active_scaffold/bridges/semantic_attributes/bridge.rb", - "lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb", - "lib/active_scaffold/bridges/shared/date_bridge.rb", - "lib/active_scaffold/bridges/tiny_mce/bridge.rb", - "lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb", - "lib/active_scaffold/bridges/validation_reflection/bridge.rb", - "lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb", - "lib/active_scaffold/config/base.rb", - "lib/active_scaffold/config/core.rb", - "lib/active_scaffold/config/create.rb", - "lib/active_scaffold/config/delete.rb", - "lib/active_scaffold/config/field_search.rb", - "lib/active_scaffold/config/form.rb", - "lib/active_scaffold/config/list.rb", - "lib/active_scaffold/config/mark.rb", - "lib/active_scaffold/config/nested.rb", - "lib/active_scaffold/config/search.rb", - "lib/active_scaffold/config/show.rb", - "lib/active_scaffold/config/subform.rb", - "lib/active_scaffold/config/update.rb", - "lib/active_scaffold/configurable.rb", - "lib/active_scaffold/constraints.rb", - "lib/active_scaffold/data_structures/action_columns.rb", - "lib/active_scaffold/data_structures/action_link.rb", - "lib/active_scaffold/data_structures/action_links.rb", - "lib/active_scaffold/data_structures/actions.rb", - "lib/active_scaffold/data_structures/column.rb", - "lib/active_scaffold/data_structures/columns.rb", - "lib/active_scaffold/data_structures/error_message.rb", - "lib/active_scaffold/data_structures/nested_info.rb", - "lib/active_scaffold/data_structures/set.rb", - "lib/active_scaffold/data_structures/sorting.rb", - "lib/active_scaffold/extensions/action_controller_rendering.rb", - "lib/active_scaffold/extensions/action_view_rendering.rb", - "lib/active_scaffold/extensions/action_view_resolver.rb", - "lib/active_scaffold/extensions/active_association_reflection.rb", - "lib/active_scaffold/extensions/active_record_offset.rb", - "lib/active_scaffold/extensions/array.rb", - "lib/active_scaffold/extensions/localize.rb", - "lib/active_scaffold/extensions/name_option_for_datetime.rb", - "lib/active_scaffold/extensions/nil_id_in_url_params.rb", - "lib/active_scaffold/extensions/paginator_extensions.rb", - "lib/active_scaffold/extensions/reverse_associations.rb", - "lib/active_scaffold/extensions/routing_mapper.rb", - "lib/active_scaffold/extensions/to_label.rb", - "lib/active_scaffold/extensions/unsaved_associated.rb", - "lib/active_scaffold/extensions/unsaved_record.rb", - "lib/active_scaffold/extensions/usa_state.rb", - "lib/active_scaffold/finder.rb", - "lib/active_scaffold/helpers/association_helpers.rb", - "lib/active_scaffold/helpers/controller_helpers.rb", - "lib/active_scaffold/helpers/country_helpers.rb", - "lib/active_scaffold/helpers/form_column_helpers.rb", - "lib/active_scaffold/helpers/human_condition_helpers.rb", - "lib/active_scaffold/helpers/id_helpers.rb", - "lib/active_scaffold/helpers/list_column_helpers.rb", - "lib/active_scaffold/helpers/pagination_helpers.rb", - "lib/active_scaffold/helpers/search_column_helpers.rb", - "lib/active_scaffold/helpers/show_column_helpers.rb", - "lib/active_scaffold/helpers/view_helpers.rb", - "lib/active_scaffold/locale/de.rb", - "lib/active_scaffold/locale/en.rb", - "lib/active_scaffold/locale/es.yml", - "lib/active_scaffold/locale/fr.rb", - "lib/active_scaffold/locale/hu.yml", - "lib/active_scaffold/locale/ja.yml", - "lib/active_scaffold/locale/ru.yml", - "lib/active_scaffold/marked_model.rb", - "lib/active_scaffold/paginator.rb", - "lib/active_scaffold/responds_to_parent.rb", - "lib/active_scaffold/version.rb", - "lib/active_scaffold_env.rb", - "lib/active_scaffold_vho.rb", - "lib/generators/active_scaffold/USAGE", - "lib/generators/active_scaffold/active_scaffold_generator.rb", - "lib/generators/active_scaffold_controller/USAGE", - "lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb", - "lib/generators/active_scaffold_controller/templates/controller.rb", - "lib/generators/active_scaffold_controller/templates/helper.rb", - "lib/generators/active_scaffold_setup/USAGE", - "lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb", - "public/blank.html", - "shoulda_macros/macros.rb", - "test/bridges/bridge_test.rb", - "test/config/base_test.rb", - "test/config/create_test.rb", - "test/config/list_test.rb", - "test/config/show_test.rb", - "test/config/update_test.rb", - "test/const_mocker.rb", - "test/data_structures/action_columns_test.rb", - "test/data_structures/action_link_test.rb", - "test/data_structures/action_links_test.rb", - "test/data_structures/actions_test.rb", - "test/data_structures/association_column_test.rb", - "test/data_structures/column_test.rb", - "test/data_structures/columns_test.rb", - "test/data_structures/error_message_test.rb", - "test/data_structures/set_test.rb", - "test/data_structures/sorting_test.rb", - "test/data_structures/standard_column_test.rb", - "test/data_structures/virtual_column_test.rb", - "test/extensions/active_record_test.rb", - "test/extensions/array_test.rb", - "test/helpers/form_column_helpers_test.rb", - "test/helpers/list_column_helpers_test.rb", - "test/helpers/pagination_helpers_test.rb", - "test/misc/active_record_permissions_test.rb", - "test/misc/attribute_params_test.rb", - "test/misc/configurable_test.rb", - "test/misc/constraints_test.rb", - "test/misc/finder_test.rb", - "test/misc/lang_test.rb", - "test/mock_app/.gitignore", - "test/mock_app/app/controllers/application_controller.rb", - "test/mock_app/app/helpers/application_helper.rb", - "test/mock_app/config/boot.rb", - "test/mock_app/config/database.yml", - "test/mock_app/config/environment.rb", - "test/mock_app/config/environments/development.rb", - "test/mock_app/config/environments/production.rb", - "test/mock_app/config/environments/test.rb", - "test/mock_app/config/initializers/backtrace_silencers.rb", - "test/mock_app/config/initializers/inflections.rb", - "test/mock_app/config/initializers/mime_types.rb", - "test/mock_app/config/initializers/new_rails_defaults.rb", - "test/mock_app/config/initializers/session_store.rb", - "test/mock_app/config/locales/en.yml", - "test/mock_app/config/routes.rb", - "test/mock_app/db/test.sqlite3", - "test/mock_app/public/blank.html", - "test/mock_app/public/images/active_scaffold/DO_NOT_EDIT", - "test/mock_app/public/images/active_scaffold/default/add.gif", - "test/mock_app/public/images/active_scaffold/default/arrow_down.gif", - "test/mock_app/public/images/active_scaffold/default/arrow_up.gif", - "test/mock_app/public/images/active_scaffold/default/close.gif", - "test/mock_app/public/images/active_scaffold/default/cross.png", - "test/mock_app/public/images/active_scaffold/default/indicator-small.gif", - "test/mock_app/public/images/active_scaffold/default/indicator.gif", - "test/mock_app/public/images/active_scaffold/default/magnifier.png", - "test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT", - "test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js", - "test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js", - "test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js", - "test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js", - "test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT", - "test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css", - "test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css", - "test/model_stub.rb", - "test/run_all.rb", - "test/test_helper.rb", - "uninstall.rb" - ] - s.homepage = %q{http://github.com/vhochstein/active_scaffold} - s.licenses = ["MIT"] - s.require_paths = ["lib"] - s.rubygems_version = %q{1.3.7} - s.summary = %q{Rails 3.1 Version of activescaffold supporting prototype and jquery} - s.test_files = [ - "test/bridges/bridge_test.rb", - "test/config/base_test.rb", - "test/config/create_test.rb", - "test/config/list_test.rb", - "test/config/show_test.rb", - "test/config/update_test.rb", - "test/const_mocker.rb", - "test/data_structures/action_columns_test.rb", - "test/data_structures/action_link_test.rb", - "test/data_structures/action_links_test.rb", - "test/data_structures/actions_test.rb", - "test/data_structures/association_column_test.rb", - "test/data_structures/column_test.rb", - "test/data_structures/columns_test.rb", - "test/data_structures/error_message_test.rb", - "test/data_structures/set_test.rb", - "test/data_structures/sorting_test.rb", - "test/data_structures/standard_column_test.rb", - "test/data_structures/virtual_column_test.rb", - "test/extensions/active_record_test.rb", - "test/extensions/array_test.rb", - "test/helpers/form_column_helpers_test.rb", - "test/helpers/list_column_helpers_test.rb", - "test/helpers/pagination_helpers_test.rb", - "test/misc/active_record_permissions_test.rb", - "test/misc/attribute_params_test.rb", - "test/misc/configurable_test.rb", - "test/misc/constraints_test.rb", - "test/misc/finder_test.rb", - "test/misc/lang_test.rb", - "test/mock_app/app/controllers/application_controller.rb", - "test/mock_app/app/helpers/application_helper.rb", - "test/mock_app/config/boot.rb", - "test/mock_app/config/environment.rb", - "test/mock_app/config/environments/development.rb", - "test/mock_app/config/environments/production.rb", - "test/mock_app/config/environments/test.rb", - "test/mock_app/config/initializers/backtrace_silencers.rb", - "test/mock_app/config/initializers/inflections.rb", - "test/mock_app/config/initializers/mime_types.rb", - "test/mock_app/config/initializers/new_rails_defaults.rb", - "test/mock_app/config/initializers/session_store.rb", - "test/mock_app/config/routes.rb", - "test/model_stub.rb", - "test/run_all.rb", - "test/test_helper.rb" - ] - - if s.respond_to? :specification_version then - current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION - s.specification_version = 3 - - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_development_dependency(%q<shoulda>, [">= 0"]) - s.add_development_dependency(%q<bundler>, ["~> 1.0.0"]) - s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"]) - s.add_development_dependency(%q<rcov>, [">= 0"]) - s.add_runtime_dependency(%q<render_component_vho>, [">= 0"]) - s.add_runtime_dependency(%q<verification>, [">= 0"]) - s.add_runtime_dependency(%q<rails>, ["~> 3.1.0"]) - else - s.add_dependency(%q<shoulda>, [">= 0"]) - s.add_dependency(%q<bundler>, ["~> 1.0.0"]) - s.add_dependency(%q<jeweler>, ["~> 1.5.2"]) - s.add_dependency(%q<rcov>, [">= 0"]) - s.add_dependency(%q<render_component_vho>, [">= 0"]) - s.add_dependency(%q<verification>, [">= 0"]) - s.add_dependency(%q<rails>, ["~> 3.1.0"]) - end - else - s.add_dependency(%q<shoulda>, [">= 0"]) - s.add_dependency(%q<bundler>, ["~> 1.0.0"]) - s.add_dependency(%q<jeweler>, ["~> 1.5.2"]) - s.add_dependency(%q<rcov>, [">= 0"]) - s.add_dependency(%q<render_component_vho>, [">= 0"]) - s.add_dependency(%q<verification>, [">= 0"]) - s.add_dependency(%q<rails>, ["~> 3.1.0"]) - end -end - diff --git a/init.rb b/init.rb index 2c4004c8e3..dfc70336b2 100755 --- a/init.rb +++ b/init.rb @@ -1 +1,4 @@ +ACTIVE_SCAFFOLD_PLUGIN = true require 'active_scaffold' +ActiveSupport.run_load_hooks(:active_scaffold, ActiveScaffold) + diff --git a/install.rb b/install.rb new file mode 100644 index 0000000000..ea29c8b9a1 --- /dev/null +++ b/install.rb @@ -0,0 +1,3 @@ +File.open(File.expand_path('../../../../config/initializers/active_scaffold.rb', __FILE__), 'w') do |f| + f << "#ActiveSupport.on_load(:active_scaffold) { self.js_framework = :jquery }\n" +end diff --git a/lib/active_scaffold_env.rb b/lib/active_scaffold_env.rb index fcf4a7c48f..ea0fc2a2b3 100644 --- a/lib/active_scaffold_env.rb +++ b/lib/active_scaffold_env.rb @@ -11,4 +11,3 @@ ActiveRecord::Base.class_eval {include ActiveRecordPermissions::Permissions} I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'active_scaffold', 'locale', '*.{rb,yml}')] -#ActiveScaffold.js_framework = :prototype diff --git a/lib/active_scaffold_vho.rb b/lib/active_scaffold_vho.rb deleted file mode 100644 index 73d156a604..0000000000 --- a/lib/active_scaffold_vho.rb +++ /dev/null @@ -1,2 +0,0 @@ -ACTIVE_SCAFFOLD_GEM = true -require 'active_scaffold' \ No newline at end of file From 3513a3d20099b736f669d18f00d9b4b7dbea0de5 Mon Sep 17 00:00:00 2001 From: Wes Gamble <weyus@att.net> Date: Mon, 22 Aug 2011 18:02:29 -0500 Subject: [PATCH 1217/2024] Fixed gem commands. --- README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index abb957eb36..9962fa293d 100644 --- a/README +++ b/README @@ -39,10 +39,10 @@ If you want to install as plugins under vendor/plugins, install these versions: rails plugin install git://github.com/activescaffold/active_scaffold.git -r 'rails-3.0' If you want to use the gem, add to your Gemfile: - gem "active_scaffold_vho" + gem "active_scaffold" In case you would like to use most recent commit: - gem 'active_scaffold_vho', :git => 'git://github.com/active_scaffold/active_scaffold.git', :branch => 'rails-3.0' + gem 'active_scaffold', :git => 'git://github.com/activescaffold/active_scaffold.git', :branch => 'rails-3.0' == Pick your own javascript framework From 75bdb1b31bdd8c16d2bfa09ab0d3e5401b2ec486 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 24 Aug 2011 14:24:37 +0200 Subject: [PATCH 1218/2024] Add dragonfly bridge (cherry picked from commit a0e4cafd875d38660284528706732b10fe787c66) --- .../bridges/dragonfly/bridge.rb | 9 +++++ .../bridges/dragonfly/lib/dragonfly_bridge.rb | 36 +++++++++++++++++++ .../dragonfly/lib/dragonfly_bridge_helpers.rb | 12 +++++++ .../bridges/dragonfly/lib/form_ui.rb | 27 ++++++++++++++ .../bridges/dragonfly/lib/list_ui.rb | 16 +++++++++ 5 files changed, 100 insertions(+) create mode 100644 lib/active_scaffold/bridges/dragonfly/bridge.rb create mode 100644 lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb create mode 100644 lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb create mode 100644 lib/active_scaffold/bridges/dragonfly/lib/form_ui.rb create mode 100644 lib/active_scaffold/bridges/dragonfly/lib/list_ui.rb diff --git a/lib/active_scaffold/bridges/dragonfly/bridge.rb b/lib/active_scaffold/bridges/dragonfly/bridge.rb new file mode 100644 index 0000000000..0a22b9167c --- /dev/null +++ b/lib/active_scaffold/bridges/dragonfly/bridge.rb @@ -0,0 +1,9 @@ +ActiveScaffold::Bridges.bridge "Dragonfly" do + install do + require File.join(File.dirname(__FILE__), "lib/form_ui") + require File.join(File.dirname(__FILE__), "lib/list_ui") + require File.join(File.dirname(__FILE__), "lib/dragonfly_bridge_helpers") + require File.join(File.dirname(__FILE__), "lib/dragonfly_bridge") + ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Dragonfly::Lib::DragonflyBridge + end +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb b/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb new file mode 100644 index 0000000000..e85502b451 --- /dev/null +++ b/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb @@ -0,0 +1,36 @@ +module ActiveScaffold + module Bridges + module Dragonfly + module Lib + module DragonflyBridge + def initialize_with_dragonfly(model_id) + initialize_without_dragonfly(model_id) + return unless self.model.respond_to?(:dragonfly_attachment_classes) && self.model.dragonfly_attachment_classes.present? + + self.update.multipart = true + self.create.multipart = true + + self.model.dragonfly_attachment_classes.each do |attachment| + configure_dragonfly_field(attachment.attribute) + end + end + + def self.included(base) + base.alias_method_chain :initialize, :dragonfly + end + + private + def configure_dragonfly_field(field) + self.columns << field + self.columns[field].form_ui ||= :dragonfly + self.columns[field].params.add "remove_#{field}" + + [:name, :uid].each do |f| + self.columns.exclude("#{field}_#{f}".to_sym) + end + end + end + end + end + end +end diff --git a/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb b/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb new file mode 100644 index 0000000000..c7446d2fea --- /dev/null +++ b/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb @@ -0,0 +1,12 @@ +module ActiveScaffold + module Bridges + module Dragonfly + module Lib + module DragonflyBridgeHelpers + mattr_accessor :thumbnail_style + self.thumbnail_style = 'x30>' + end + end + end + end +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/dragonfly/lib/form_ui.rb b/lib/active_scaffold/bridges/dragonfly/lib/form_ui.rb new file mode 100644 index 0000000000..c709db31a0 --- /dev/null +++ b/lib/active_scaffold/bridges/dragonfly/lib/form_ui.rb @@ -0,0 +1,27 @@ +module ActiveScaffold + module Helpers + module FormColumnHelpers + def active_scaffold_input_dragonfly(column, options) + options = active_scaffold_input_text_options(options) + input = file_field(:record, column.name, options) + dragonfly = @record.send("#{column.name}") + if dragonfly.present? + if ActiveScaffold.js_framework == :jquery + js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;"; + else + js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;"; + end + + content = active_scaffold_column_dragonfly(column, @record) + content_tag(:div, + content + " | " + + hidden_field(:record, "remove_#{column.name}", :value => "false") + + content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}) + ) + content_tag(:div, input, :style => "display: none") + else + input + end + end + end + end +end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/dragonfly/lib/list_ui.rb b/lib/active_scaffold/bridges/dragonfly/lib/list_ui.rb new file mode 100644 index 0000000000..fdfbb068ee --- /dev/null +++ b/lib/active_scaffold/bridges/dragonfly/lib/list_ui.rb @@ -0,0 +1,16 @@ +module ActiveScaffold + module Helpers + module ListColumnHelpers + def active_scaffold_column_dragonfly(column, record) + attachment = record.send("#{column.name}") + return nil unless attachment.present? + content = if attachment.image? + image_tag(attachment.thumb(column.options[:thumb] || ActiveScaffold::Bridges::Dragonfly::Lib::DragonflyBridgeHelpers.thumbnail_style).url, :border => 0) + else + attachment.name + end + link_to(content, attachment.remote_url, {'data-popup' => true, :target => '_blank'}) + end + end + end +end \ No newline at end of file From c2bceec57f32f7301496dba05aa38939d58ea89e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 26 Aug 2011 10:40:38 +0200 Subject: [PATCH 1219/2024] fix setup generator (cherry picked from commit ef537d258f143ea5badf91c18ac629942b241519) --- .../active_scaffold_setup_generator.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb index 3c4e48d464..20dab19236 100644 --- a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +++ b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb @@ -8,7 +8,7 @@ def self.source_root end def install_plugins - unless defined?(ACTIVE_SCAFFOLD_GEM) + if defined?(ACTIVE_SCAFFOLD_PLUGIN) plugin 'verification', :git => 'git://github.com/rails/verification.git' plugin 'render_component', :git => 'git://github.com/vhochstein/render_component.git' end @@ -21,15 +21,13 @@ def install_plugins end def configure_active_scaffold - unless defined?(ACTIVE_SCAFFOLD_GEM) - if js_lib == 'jquery' - gsub_file 'vendor/plugins/active_scaffold/lib/active_scaffold_env.rb', /#ActiveScaffold.js_framework = :jquery/, 'ActiveScaffold.js_framework = :jquery' - end + return unless js_lib == 'jquery' + if defined?(ACTIVE_SCAFFOLD_PLUGIN) + content = "ActiveSupport.on_load(:active_scaffold) { self.js_framework = :jquery }" else - if js_lib == 'jquery' - create_file "config/initializers/active_scaffold.rb", "ActiveScaffold.js_framework = :jquery" - end + content = "ActiveScaffold.js_framework = :jquery" end + create_file "config/initializers/active_scaffold.rb", content end def configure_application_layout From b0ac4543e42e08276a701a1b3af1fd8a89499fb4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 29 Aug 2011 09:42:48 +0200 Subject: [PATCH 1220/2024] fix homepage in gemspec --- active_scaffold.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index 70bc394cc6..f985290a3d 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -8,7 +8,7 @@ Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.email = %q{activescaffold@googlegroups.com} s.authors = ["Many, see README"] - s.homepage = %q{http://active_scaffold.com} + s.homepage = %q{http://activescaffold.com} s.summary = %q{Rails 3.1 Version of activescaffold supporting prototype and jquery} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.require_paths = ["lib"] From 928d2fb201aa6196d2271b824620187e3deff866 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Aug 2011 09:40:42 +0200 Subject: [PATCH 1221/2024] fix update columns when create and update columns are different (cherry picked from commit 34e6de4b85e9ac711bf8190dbe6e1372e13d3f39) --- lib/active_scaffold/actions/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index bc8f60b727..d878671572 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -40,7 +40,7 @@ def render_field_for_update_columns else params[:record] end - @record = update_record_from_params(@record, active_scaffold_config.update.columns, hash) + @record = update_record_from_params(@record, active_scaffold_config.send(params[:id] ? :update : :create).columns, hash) else value = column_value_from_param_value(@record, column, params[:value]) @record.send "#{column.name}=", value From 732713747104df18c0c0cb03014cdaf19fe3fab4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Aug 2011 10:55:49 +0200 Subject: [PATCH 1222/2024] avoid circular references in update columns --- frontends/default/views/_render_field.js.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontends/default/views/_render_field.js.erb b/frontends/default/views/_render_field.js.erb index b791b90b65..44033015c7 100644 --- a/frontends/default/views/_render_field.js.erb +++ b/frontends/default/views/_render_field.js.erb @@ -1,5 +1,8 @@ <% column = active_scaffold_config.columns[render_field.to_sym] + @rendered ||= Set.new + return if @rendered.include? column.name + @rendered << column.name if column_renders_as(column) == :subform options = {:is_subform => true, :field_class => "#{column.name}-sub-form"} else From 55f0c7f2e8e234a9090dc2fbbc95356210b3653c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Aug 2011 13:08:39 +0200 Subject: [PATCH 1223/2024] It could be useful to have db values when update columns sending full form (cherry picked from commit 3d09bc884ab98cc633f44fb388b033deb3fab9d3) --- lib/active_scaffold/actions/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index d878671572..e69fa67112 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -29,8 +29,8 @@ def render_field_for_inplace_editing end def render_field_for_update_columns - @record = new_model column = active_scaffold_config.columns[params[:column]] + @record = params[:id] && column.send_form_on_update_column ? find_if_allowed(params[:id], :update) : new_model unless column.nil? if column.send_form_on_update_column hash = if params[:scope] From 41624ceb0f11ef0b4cf43ce974dac9c030bd11bc Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 31 Aug 2011 13:37:30 +0200 Subject: [PATCH 1224/2024] keep html classes set by AS in record select bridge (cherry picked from commit 982d167e7b66166442eae9d4825a5e305cfc905e) --- .../bridges/record_select/lib/record_select_bridge.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb b/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb index f51d6c80c3..17b0a13b0e 100644 --- a/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb +++ b/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb @@ -42,8 +42,11 @@ def active_scaffold_record_select(column, options, value, multiple) params.merge!({column.association.primary_key_name => ''}) end - record_select_options = {:controller => remote_controller, :id => options[:id]} - record_select_options.merge!(active_scaffold_input_text_options) + record_select_options = active_scaffold_input_text_options( + :controller => remote_controller, + :id => options[:id], + :class => options[:class] + ) record_select_options.merge!(column.options) if options['data-update_url'] record_select_options[:onchange] = %|function(id, label) { From 603a2b6177c5f3077ba4b06ea8d3027ec6ae7eb4 Mon Sep 17 00:00:00 2001 From: Liehann Loots <liehannl@gmail.com> Date: Wed, 31 Aug 2011 19:06:23 +0200 Subject: [PATCH 1225/2024] association_options_find honours :includes. association_options_find now honours the association :include. --- lib/active_scaffold/helpers/association_helpers.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/association_helpers.rb b/lib/active_scaffold/helpers/association_helpers.rb index 99ae97b520..753de6ea80 100644 --- a/lib/active_scaffold/helpers/association_helpers.rb +++ b/lib/active_scaffold/helpers/association_helpers.rb @@ -3,7 +3,9 @@ module Helpers module AssociationHelpers # Provides a way to honor the :conditions on an association while searching the association's klass def association_options_find(association, conditions = nil) - association.klass.where(conditions).where(association.options[:conditions]).all + relation = association.klass.where(conditions).where(association.options[:conditions]) + relation = relation.includes(association.options[:include]) if association.options[:include] + relation.all end def association_options_count(association, conditions = nil) From 9e2e11a3d221b92e7f98a4866cf6602ae5d15eaa Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 2 Sep 2011 15:08:00 +0200 Subject: [PATCH 1226/2024] Fix rendering horizontal subform with hidden fields (cherry picked from commit 4d4e99be0c327af8f46e6c37e1fbe243fc0cbec8) --- app/assets/stylesheets/active_scaffold.css.erb | 4 ++++ frontends/default/views/_horizontal_subform_header.html.erb | 5 +++-- frontends/default/views/_horizontal_subform_record.html.erb | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/active_scaffold.css.erb b/app/assets/stylesheets/active_scaffold.css.erb index 0ca21b3b98..94667ad297 100644 --- a/app/assets/stylesheets/active_scaffold.css.erb +++ b/app/assets/stylesheets/active_scaffold.css.erb @@ -265,6 +265,10 @@ background: #333 url(<%= asset_path 'indicator-small.gif' %>) right 50% no-repea margin-left: 5px; } +.active-scaffold th.hidden, .active-scaffold td.hidden { +display: none; +} + /* Table :: Record Rows ============================= */ diff --git a/frontends/default/views/_horizontal_subform_header.html.erb b/frontends/default/views/_horizontal_subform_header.html.erb index 5c77304fbc..c39a00fbca 100644 --- a/frontends/default/views/_horizontal_subform_header.html.erb +++ b/frontends/default/views/_horizontal_subform_header.html.erb @@ -2,9 +2,10 @@ <tr> <% active_scaffold_config_for(@record.class).subform.columns.each :for => @record.class, :flatten => true do |column| - next unless in_subform?(column, parent_record) and column_renders_as(column) != :hidden + hidden = column_renders_as(column) == :hidden + next unless in_subform?(column, parent_record) -%> - <th<%= ' class="required"' if column.required? %>><label><%= column.label %></label></th> + <th class="<%= "#{'required' if column.required?} #{'hidden' if hidden}" %>"><label><%= column.label unless hidden %></label></th> <% end -%> </tr> </thead> diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index f01de46709..7067b7cee9 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -15,7 +15,7 @@ column = column.clone column.form_ui ||= :select if column.association -%> - <td> + <td<%= ' class="hidden"'.html_safe if column_renders_as(column) == :hidden %>> <% unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) -%> <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%> <% else -%> From 97dd37df9758465682fb15fb79eeeb03513ca3a0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 5 Sep 2011 12:17:00 +0200 Subject: [PATCH 1227/2024] add errors to record select (cherry picked from commit eb10d5f2745f38aff05e070d6f6b2d56a2a24c6a) --- .../bridges/record_select/lib/record_select_bridge.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb b/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb index 17b0a13b0e..3e1a1e6b27 100644 --- a/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb +++ b/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb @@ -54,11 +54,13 @@ def active_scaffold_record_select(column, options, value, multiple) }| end - if multiple + html = if multiple record_multi_select_field(options[:name], value || [], record_select_options) else record_select_field(options[:name], value || column.association.klass.new, record_select_options) end + html = self.class.field_error_proc.call(html, self) if @record.errors[column.name].any? + html end end From 08c883aa764b7f41282dd9c857c5a87dfcc8eea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D0=B5=D0=B4=D0=BE=D1=80=D0=BE=D0=B2=20=D0=A1=D0=B5?= =?UTF-8?q?=D1=80=D0=B3=D0=B5=D0=B9?= <fedorov@ek.apress.ru> Date: Mon, 5 Sep 2011 18:15:31 +0600 Subject: [PATCH 1228/2024] Fix link display if it has a authorized_for_action? method in model --- frontends/default/views/_action_group.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_action_group.html.erb b/frontends/default/views/_action_group.html.erb index b0027c5192..4d2e455015 100644 --- a/frontends/default/views/_action_group.html.erb +++ b/frontends/default/views/_action_group.html.erb @@ -16,7 +16,7 @@ <% end %> <% else -%> <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}#{h(render_group_action_link(link, url_options, options, record))}#{end_level_0_tag}".html_safe %> + <%= "#{start_level_0_tag}#{render_group_action_link(link, url_options, options, record)}#{end_level_0_tag}".html_safe %> <% else %> <%= content_tag('li', render_group_action_link(link, url_options, options, record), options[:first_action] ? {:class => 'top'}: {}) %> <% end %> From 161f340f7447ff2bfe824ededaa9980b565a284b Mon Sep 17 00:00:00 2001 From: Brian Miller <brimil01@gmail.com> Date: Mon, 12 Sep 2011 16:56:24 -0700 Subject: [PATCH 1229/2024] Updated rails version to 3.1.0 --- active_scaffold.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index f985290a3d..4006811c7f 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -26,6 +26,6 @@ Gem::Specification.new do |s| s.add_development_dependency(%q<rcov>, [">= 0"]) s.add_runtime_dependency(%q<render_component_vho>, [">= 0"]) s.add_runtime_dependency(%q<verification>, [">= 0"]) - s.add_runtime_dependency(%q<rails>, ["~> 3.0.0"]) + s.add_runtime_dependency(%q<rails>, ["~> 3.1.0"]) end From d5cdf8f986f46b6ab5063bb6f25aaead4ebecd0b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 13 Sep 2011 11:53:52 +0200 Subject: [PATCH 1230/2024] fix Rakefile for 3.1 --- Gemfile | 2 ++ Gemfile.lock | 4 ++++ Rakefile | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index b5ca9e515a..b7bdfa5964 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,8 @@ source "http://rubygems.org" # Add dependencies to develop your gem here. # Include everything needed to run rake, tests, features, etc. group :development do + gem "rake" + gem "rdoc" gem "shoulda", ">= 0" gem "bundler", "~> 1.0.0" gem "rcov", ">= 0" diff --git a/Gemfile.lock b/Gemfile.lock index 9cf16fcd74..5f9ea8a271 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,9 @@ GEM remote: http://rubygems.org/ specs: + rake (0.9.2) rcov (0.9.9) + rdoc (3.9.4) shoulda (2.11.3) PLATFORMS @@ -9,5 +11,7 @@ PLATFORMS DEPENDENCIES bundler (~> 1.0.0) + rake rcov + rdoc shoulda diff --git a/Rakefile b/Rakefile index 257d2085dd..7b65523a85 100644 --- a/Rakefile +++ b/Rakefile @@ -9,7 +9,7 @@ rescue Bundler::BundlerError => e end Bundler::GemHelper.install_tasks require 'rake/testtask' -require 'rake/rdoctask' +require 'rdoc/task' require 'find' desc 'Test ActiveScaffold.' From dbfe3664ec8ab545bfa91ce31c346752df73301a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 13 Sep 2011 12:14:09 +0200 Subject: [PATCH 1231/2024] remove verify, using REST is not needed to verify request method --- active_scaffold.gemspec | 1 - lib/active_scaffold/actions/create.rb | 3 --- lib/active_scaffold/actions/nested.rb | 3 --- lib/active_scaffold/actions/update.rb | 3 --- 4 files changed, 10 deletions(-) diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index 4006811c7f..042bce3995 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -25,7 +25,6 @@ Gem::Specification.new do |s| s.add_development_dependency(%q<bundler>, ["~> 1.0.0"]) s.add_development_dependency(%q<rcov>, [">= 0"]) s.add_runtime_dependency(%q<render_component_vho>, [">= 0"]) - s.add_runtime_dependency(%q<verification>, [">= 0"]) s.add_runtime_dependency(%q<rails>, ["~> 3.1.0"]) end diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 432a83afd7..c3a0349e0f 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -2,9 +2,6 @@ module ActiveScaffold::Actions module Create def self.included(base) base.before_filter :create_authorized_filter, :only => [:new, :create] - base.verify :method => :post, - :only => :create, - :redirect_to => { :action => :index } end def new diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 29f88fa03e..83cecda5e5 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -123,9 +123,6 @@ module ChildMethods def self.included(base) super - base.verify :method => :post, - :only => :add_existing, - :redirect_to => { :action => :index } end def new_existing diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index ad22cc5ef9..f2f5000fc2 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -2,9 +2,6 @@ module ActiveScaffold::Actions module Update def self.included(base) base.before_filter :update_authorized_filter, :only => [:edit, :update] - base.verify :method => [:post, :put], - :only => :update, - :redirect_to => { :action => :index } base.helper_method :update_refresh_list? end From 6b20d1a7725c59f2eece7be73066dcb20af2e640 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 13 Sep 2011 17:54:55 +0200 Subject: [PATCH 1232/2024] update asset pipeline --- active_scaffold.gemspec | 2 +- app/assets/javascripts/active_scaffold.js.erb | 3 + .../jquery/date_picker_bridge.js.erb | 4 +- .../stylesheets/active_scaffold.css.erb | 2 + app/assets/stylesheets/jquery-ui.css | 568 ++++++++++++++++++ lib/active_scaffold.rb | 6 +- lib/active_scaffold/bridge.rb | 57 ++ lib/active_scaffold/bridges.rb | 5 + lib/active_scaffold/bridges/bridge.rb | 59 -- lib/active_scaffold/bridges/date_picker.rb | 23 + .../bridges/date_picker/bridge.rb | 10 - .../bridges/date_picker/ext.rb | 54 ++ .../{lib/datepicker_bridge.rb => helper.rb} | 93 +-- .../active_scaffold_setup_generator.rb | 3 +- 14 files changed, 726 insertions(+), 163 deletions(-) create mode 100644 app/assets/stylesheets/jquery-ui.css create mode 100644 lib/active_scaffold/bridge.rb create mode 100644 lib/active_scaffold/bridges.rb delete mode 100644 lib/active_scaffold/bridges/bridge.rb create mode 100644 lib/active_scaffold/bridges/date_picker.rb delete mode 100644 lib/active_scaffold/bridges/date_picker/bridge.rb create mode 100644 lib/active_scaffold/bridges/date_picker/ext.rb rename lib/active_scaffold/bridges/date_picker/{lib/datepicker_bridge.rb => helper.rb} (68%) diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index 042bce3995..c43a90576f 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |s| s.add_development_dependency(%q<shoulda>, [">= 0"]) s.add_development_dependency(%q<bundler>, ["~> 1.0.0"]) s.add_development_dependency(%q<rcov>, [">= 0"]) - s.add_runtime_dependency(%q<render_component_vho>, [">= 0"]) + #s.add_runtime_dependency(%q<render_component_vho>, [">= 0"]) s.add_runtime_dependency(%q<rails>, ["~> 3.1.0"]) end diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index 1b777cb124..4aad7dcbcd 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -1,8 +1,11 @@ <% if ActiveScaffold.js_framework == :jquery %> +<% require_asset "jquery-ui" %> <% require_asset "jquery/active_scaffold" %> <% require_asset "jquery/jquery.editinplace" %> <% require_asset "jquery/date_picker_bridge" %> <% else %> +<% require_asset "effects" %> +<% require_asset "controls" %> <% require_asset "prototype/active_scaffold" %> <% require_asset "prototype/dhtml_history" %> <% require_asset "prototype/form_enhancements" %> diff --git a/app/assets/javascripts/jquery/date_picker_bridge.js.erb b/app/assets/javascripts/jquery/date_picker_bridge.js.erb index 5ed5b5aef0..4831bedc0c 100644 --- a/app/assets/javascripts/jquery/date_picker_bridge.js.erb +++ b/app/assets/javascripts/jquery/date_picker_bridge.js.erb @@ -1,4 +1,4 @@ -<%= ActiveScaffold::Bridges::DatePickerBridge.localization %> +<%= ActiveScaffold::Bridge[:date_picker].localization %> $(document).ready(function() { $('input.date_picker').live('focus', function(event) { @@ -21,4 +21,4 @@ $(document).ready(function() { } return true; }); -}); \ No newline at end of file +}); diff --git a/app/assets/stylesheets/active_scaffold.css.erb b/app/assets/stylesheets/active_scaffold.css.erb index 94667ad297..78f0aea865 100644 --- a/app/assets/stylesheets/active_scaffold.css.erb +++ b/app/assets/stylesheets/active_scaffold.css.erb @@ -1,3 +1,4 @@ +<%= require_asset "jquery-ui" %> /* ActiveScaffold (c) 2007 Richard White <rrwhite@gmail.com> @@ -5,6 +6,7 @@ ActiveScaffold is freely distributable under the terms of an MIT-style license. For details, see the ActiveScaffold web site: http://www.activescaffold.com/ + */ .active-scaffold form, diff --git a/app/assets/stylesheets/jquery-ui.css b/app/assets/stylesheets/jquery-ui.css new file mode 100644 index 0000000000..fe31070575 --- /dev/null +++ b/app/assets/stylesheets/jquery-ui.css @@ -0,0 +1,568 @@ +/* + * jQuery UI CSS Framework 1.8.14 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Theming/API + */ + +/* Layout helpers +----------------------------------*/ +.ui-helper-hidden { display: none; } +.ui-helper-hidden-accessible { position: absolute !important; clip: rect(1px 1px 1px 1px); clip: rect(1px,1px,1px,1px); } +.ui-helper-reset { margin: 0; padding: 0; border: 0; outline: 0; line-height: 1.3; text-decoration: none; font-size: 100%; list-style: none; } +.ui-helper-clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; } +.ui-helper-clearfix { display: inline-block; } +/* required comment for clearfix to work in Opera \*/ +* html .ui-helper-clearfix { height:1%; } +.ui-helper-clearfix { display:block; } +/* end clearfix */ +.ui-helper-zfix { width: 100%; height: 100%; top: 0; left: 0; position: absolute; opacity: 0; filter:Alpha(Opacity=0); } + + +/* Interaction Cues +----------------------------------*/ +.ui-state-disabled { cursor: default !important; } + + +/* Icons +----------------------------------*/ + +/* states and images */ +.ui-icon { display: block; text-indent: -99999px; overflow: hidden; background-repeat: no-repeat; } + + +/* Misc visuals +----------------------------------*/ + +/* Overlays */ +.ui-widget-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } + + +/* + * jQuery UI CSS Framework 1.8.14 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Theming/API + * + * To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Trebuchet%20MS,%20Tahoma,%20Verdana,%20Arial,%20sans-serif&fwDefault=bold&fsDefault=1.1em&cornerRadius=4px&bgColorHeader=f6a828&bgTextureHeader=12_gloss_wave.png&bgImgOpacityHeader=35&borderColorHeader=e78f08&fcHeader=ffffff&iconColorHeader=ffffff&bgColorContent=eeeeee&bgTextureContent=03_highlight_soft.png&bgImgOpacityContent=100&borderColorContent=dddddd&fcContent=333333&iconColorContent=222222&bgColorDefault=f6f6f6&bgTextureDefault=02_glass.png&bgImgOpacityDefault=100&borderColorDefault=cccccc&fcDefault=1c94c4&iconColorDefault=ef8c08&bgColorHover=fdf5ce&bgTextureHover=02_glass.png&bgImgOpacityHover=100&borderColorHover=fbcb09&fcHover=c77405&iconColorHover=ef8c08&bgColorActive=ffffff&bgTextureActive=02_glass.png&bgImgOpacityActive=65&borderColorActive=fbd850&fcActive=eb8f00&iconColorActive=ef8c08&bgColorHighlight=ffe45c&bgTextureHighlight=03_highlight_soft.png&bgImgOpacityHighlight=75&borderColorHighlight=fed22f&fcHighlight=363636&iconColorHighlight=228ef1&bgColorError=b81900&bgTextureError=08_diagonals_thick.png&bgImgOpacityError=18&borderColorError=cd0a0a&fcError=ffffff&iconColorError=ffd27a&bgColorOverlay=666666&bgTextureOverlay=08_diagonals_thick.png&bgImgOpacityOverlay=20&opacityOverlay=50&bgColorShadow=000000&bgTextureShadow=01_flat.png&bgImgOpacityShadow=10&opacityShadow=20&thicknessShadow=5px&offsetTopShadow=-5px&offsetLeftShadow=-5px&cornerRadiusShadow=5px + */ + + +/* Component containers +----------------------------------*/ +.ui-widget { font-family: Trebuchet MS, Tahoma, Verdana, Arial, sans-serif; font-size: 1.1em; } +.ui-widget .ui-widget { font-size: 1em; } +.ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Trebuchet MS, Tahoma, Verdana, Arial, sans-serif; font-size: 1em; } +.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee url(images/ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x; color: #333333; } +.ui-widget-content a { color: #333333; } +.ui-widget-header { border: 1px solid #e78f08; background: #f6a828 url(images/ui-bg_gloss-wave_35_f6a828_500x100.png) 50% 50% repeat-x; color: #ffffff; font-weight: bold; } +.ui-widget-header a { color: #ffffff; } + +/* Interaction states +----------------------------------*/ +.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 url(images/ui-bg_glass_100_f6f6f6_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #1c94c4; } +.ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #1c94c4; text-decoration: none; } +.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #fbcb09; background: #fdf5ce url(images/ui-bg_glass_100_fdf5ce_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #c77405; } +.ui-state-hover a, .ui-state-hover a:hover { color: #c77405; text-decoration: none; } +.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #fbd850; background: #ffffff url(images/ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #eb8f00; } +.ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #eb8f00; text-decoration: none; } +.ui-widget :active { outline: none; } + +/* Interaction Cues +----------------------------------*/ +.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fed22f; background: #ffe45c url(images/ui-bg_highlight-soft_75_ffe45c_1x100.png) 50% top repeat-x; color: #363636; } +.ui-state-highlight a, .ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a { color: #363636; } +.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 url(images/ui-bg_diagonals-thick_18_b81900_40x40.png) 50% 50% repeat; color: #ffffff; } +.ui-state-error a, .ui-widget-content .ui-state-error a, .ui-widget-header .ui-state-error a { color: #ffffff; } +.ui-state-error-text, .ui-widget-content .ui-state-error-text, .ui-widget-header .ui-state-error-text { color: #ffffff; } +.ui-priority-primary, .ui-widget-content .ui-priority-primary, .ui-widget-header .ui-priority-primary { font-weight: bold; } +.ui-priority-secondary, .ui-widget-content .ui-priority-secondary, .ui-widget-header .ui-priority-secondary { opacity: .7; filter:Alpha(Opacity=70); font-weight: normal; } +.ui-state-disabled, .ui-widget-content .ui-state-disabled, .ui-widget-header .ui-state-disabled { opacity: .35; filter:Alpha(Opacity=35); background-image: none; } + +/* Icons +----------------------------------*/ + +/* states and images */ +.ui-icon { width: 16px; height: 16px; background-image: url(images/ui-icons_222222_256x240.png); } +.ui-widget-content .ui-icon {background-image: url(images/ui-icons_222222_256x240.png); } +.ui-widget-header .ui-icon {background-image: url(images/ui-icons_ffffff_256x240.png); } +.ui-state-default .ui-icon { background-image: url(images/ui-icons_ef8c08_256x240.png); } +.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(images/ui-icons_ef8c08_256x240.png); } +.ui-state-active .ui-icon {background-image: url(images/ui-icons_ef8c08_256x240.png); } +.ui-state-highlight .ui-icon {background-image: url(images/ui-icons_228ef1_256x240.png); } +.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(images/ui-icons_ffd27a_256x240.png); } + +/* positioning */ +.ui-icon-carat-1-n { background-position: 0 0; } +.ui-icon-carat-1-ne { background-position: -16px 0; } +.ui-icon-carat-1-e { background-position: -32px 0; } +.ui-icon-carat-1-se { background-position: -48px 0; } +.ui-icon-carat-1-s { background-position: -64px 0; } +.ui-icon-carat-1-sw { background-position: -80px 0; } +.ui-icon-carat-1-w { background-position: -96px 0; } +.ui-icon-carat-1-nw { background-position: -112px 0; } +.ui-icon-carat-2-n-s { background-position: -128px 0; } +.ui-icon-carat-2-e-w { background-position: -144px 0; } +.ui-icon-triangle-1-n { background-position: 0 -16px; } +.ui-icon-triangle-1-ne { background-position: -16px -16px; } +.ui-icon-triangle-1-e { background-position: -32px -16px; } +.ui-icon-triangle-1-se { background-position: -48px -16px; } +.ui-icon-triangle-1-s { background-position: -64px -16px; } +.ui-icon-triangle-1-sw { background-position: -80px -16px; } +.ui-icon-triangle-1-w { background-position: -96px -16px; } +.ui-icon-triangle-1-nw { background-position: -112px -16px; } +.ui-icon-triangle-2-n-s { background-position: -128px -16px; } +.ui-icon-triangle-2-e-w { background-position: -144px -16px; } +.ui-icon-arrow-1-n { background-position: 0 -32px; } +.ui-icon-arrow-1-ne { background-position: -16px -32px; } +.ui-icon-arrow-1-e { background-position: -32px -32px; } +.ui-icon-arrow-1-se { background-position: -48px -32px; } +.ui-icon-arrow-1-s { background-position: -64px -32px; } +.ui-icon-arrow-1-sw { background-position: -80px -32px; } +.ui-icon-arrow-1-w { background-position: -96px -32px; } +.ui-icon-arrow-1-nw { background-position: -112px -32px; } +.ui-icon-arrow-2-n-s { background-position: -128px -32px; } +.ui-icon-arrow-2-ne-sw { background-position: -144px -32px; } +.ui-icon-arrow-2-e-w { background-position: -160px -32px; } +.ui-icon-arrow-2-se-nw { background-position: -176px -32px; } +.ui-icon-arrowstop-1-n { background-position: -192px -32px; } +.ui-icon-arrowstop-1-e { background-position: -208px -32px; } +.ui-icon-arrowstop-1-s { background-position: -224px -32px; } +.ui-icon-arrowstop-1-w { background-position: -240px -32px; } +.ui-icon-arrowthick-1-n { background-position: 0 -48px; } +.ui-icon-arrowthick-1-ne { background-position: -16px -48px; } +.ui-icon-arrowthick-1-e { background-position: -32px -48px; } +.ui-icon-arrowthick-1-se { background-position: -48px -48px; } +.ui-icon-arrowthick-1-s { background-position: -64px -48px; } +.ui-icon-arrowthick-1-sw { background-position: -80px -48px; } +.ui-icon-arrowthick-1-w { background-position: -96px -48px; } +.ui-icon-arrowthick-1-nw { background-position: -112px -48px; } +.ui-icon-arrowthick-2-n-s { background-position: -128px -48px; } +.ui-icon-arrowthick-2-ne-sw { background-position: -144px -48px; } +.ui-icon-arrowthick-2-e-w { background-position: -160px -48px; } +.ui-icon-arrowthick-2-se-nw { background-position: -176px -48px; } +.ui-icon-arrowthickstop-1-n { background-position: -192px -48px; } +.ui-icon-arrowthickstop-1-e { background-position: -208px -48px; } +.ui-icon-arrowthickstop-1-s { background-position: -224px -48px; } +.ui-icon-arrowthickstop-1-w { background-position: -240px -48px; } +.ui-icon-arrowreturnthick-1-w { background-position: 0 -64px; } +.ui-icon-arrowreturnthick-1-n { background-position: -16px -64px; } +.ui-icon-arrowreturnthick-1-e { background-position: -32px -64px; } +.ui-icon-arrowreturnthick-1-s { background-position: -48px -64px; } +.ui-icon-arrowreturn-1-w { background-position: -64px -64px; } +.ui-icon-arrowreturn-1-n { background-position: -80px -64px; } +.ui-icon-arrowreturn-1-e { background-position: -96px -64px; } +.ui-icon-arrowreturn-1-s { background-position: -112px -64px; } +.ui-icon-arrowrefresh-1-w { background-position: -128px -64px; } +.ui-icon-arrowrefresh-1-n { background-position: -144px -64px; } +.ui-icon-arrowrefresh-1-e { background-position: -160px -64px; } +.ui-icon-arrowrefresh-1-s { background-position: -176px -64px; } +.ui-icon-arrow-4 { background-position: 0 -80px; } +.ui-icon-arrow-4-diag { background-position: -16px -80px; } +.ui-icon-extlink { background-position: -32px -80px; } +.ui-icon-newwin { background-position: -48px -80px; } +.ui-icon-refresh { background-position: -64px -80px; } +.ui-icon-shuffle { background-position: -80px -80px; } +.ui-icon-transfer-e-w { background-position: -96px -80px; } +.ui-icon-transferthick-e-w { background-position: -112px -80px; } +.ui-icon-folder-collapsed { background-position: 0 -96px; } +.ui-icon-folder-open { background-position: -16px -96px; } +.ui-icon-document { background-position: -32px -96px; } +.ui-icon-document-b { background-position: -48px -96px; } +.ui-icon-note { background-position: -64px -96px; } +.ui-icon-mail-closed { background-position: -80px -96px; } +.ui-icon-mail-open { background-position: -96px -96px; } +.ui-icon-suitcase { background-position: -112px -96px; } +.ui-icon-comment { background-position: -128px -96px; } +.ui-icon-person { background-position: -144px -96px; } +.ui-icon-print { background-position: -160px -96px; } +.ui-icon-trash { background-position: -176px -96px; } +.ui-icon-locked { background-position: -192px -96px; } +.ui-icon-unlocked { background-position: -208px -96px; } +.ui-icon-bookmark { background-position: -224px -96px; } +.ui-icon-tag { background-position: -240px -96px; } +.ui-icon-home { background-position: 0 -112px; } +.ui-icon-flag { background-position: -16px -112px; } +.ui-icon-calendar { background-position: -32px -112px; } +.ui-icon-cart { background-position: -48px -112px; } +.ui-icon-pencil { background-position: -64px -112px; } +.ui-icon-clock { background-position: -80px -112px; } +.ui-icon-disk { background-position: -96px -112px; } +.ui-icon-calculator { background-position: -112px -112px; } +.ui-icon-zoomin { background-position: -128px -112px; } +.ui-icon-zoomout { background-position: -144px -112px; } +.ui-icon-search { background-position: -160px -112px; } +.ui-icon-wrench { background-position: -176px -112px; } +.ui-icon-gear { background-position: -192px -112px; } +.ui-icon-heart { background-position: -208px -112px; } +.ui-icon-star { background-position: -224px -112px; } +.ui-icon-link { background-position: -240px -112px; } +.ui-icon-cancel { background-position: 0 -128px; } +.ui-icon-plus { background-position: -16px -128px; } +.ui-icon-plusthick { background-position: -32px -128px; } +.ui-icon-minus { background-position: -48px -128px; } +.ui-icon-minusthick { background-position: -64px -128px; } +.ui-icon-close { background-position: -80px -128px; } +.ui-icon-closethick { background-position: -96px -128px; } +.ui-icon-key { background-position: -112px -128px; } +.ui-icon-lightbulb { background-position: -128px -128px; } +.ui-icon-scissors { background-position: -144px -128px; } +.ui-icon-clipboard { background-position: -160px -128px; } +.ui-icon-copy { background-position: -176px -128px; } +.ui-icon-contact { background-position: -192px -128px; } +.ui-icon-image { background-position: -208px -128px; } +.ui-icon-video { background-position: -224px -128px; } +.ui-icon-script { background-position: -240px -128px; } +.ui-icon-alert { background-position: 0 -144px; } +.ui-icon-info { background-position: -16px -144px; } +.ui-icon-notice { background-position: -32px -144px; } +.ui-icon-help { background-position: -48px -144px; } +.ui-icon-check { background-position: -64px -144px; } +.ui-icon-bullet { background-position: -80px -144px; } +.ui-icon-radio-off { background-position: -96px -144px; } +.ui-icon-radio-on { background-position: -112px -144px; } +.ui-icon-pin-w { background-position: -128px -144px; } +.ui-icon-pin-s { background-position: -144px -144px; } +.ui-icon-play { background-position: 0 -160px; } +.ui-icon-pause { background-position: -16px -160px; } +.ui-icon-seek-next { background-position: -32px -160px; } +.ui-icon-seek-prev { background-position: -48px -160px; } +.ui-icon-seek-end { background-position: -64px -160px; } +.ui-icon-seek-start { background-position: -80px -160px; } +/* ui-icon-seek-first is deprecated, use ui-icon-seek-start instead */ +.ui-icon-seek-first { background-position: -80px -160px; } +.ui-icon-stop { background-position: -96px -160px; } +.ui-icon-eject { background-position: -112px -160px; } +.ui-icon-volume-off { background-position: -128px -160px; } +.ui-icon-volume-on { background-position: -144px -160px; } +.ui-icon-power { background-position: 0 -176px; } +.ui-icon-signal-diag { background-position: -16px -176px; } +.ui-icon-signal { background-position: -32px -176px; } +.ui-icon-battery-0 { background-position: -48px -176px; } +.ui-icon-battery-1 { background-position: -64px -176px; } +.ui-icon-battery-2 { background-position: -80px -176px; } +.ui-icon-battery-3 { background-position: -96px -176px; } +.ui-icon-circle-plus { background-position: 0 -192px; } +.ui-icon-circle-minus { background-position: -16px -192px; } +.ui-icon-circle-close { background-position: -32px -192px; } +.ui-icon-circle-triangle-e { background-position: -48px -192px; } +.ui-icon-circle-triangle-s { background-position: -64px -192px; } +.ui-icon-circle-triangle-w { background-position: -80px -192px; } +.ui-icon-circle-triangle-n { background-position: -96px -192px; } +.ui-icon-circle-arrow-e { background-position: -112px -192px; } +.ui-icon-circle-arrow-s { background-position: -128px -192px; } +.ui-icon-circle-arrow-w { background-position: -144px -192px; } +.ui-icon-circle-arrow-n { background-position: -160px -192px; } +.ui-icon-circle-zoomin { background-position: -176px -192px; } +.ui-icon-circle-zoomout { background-position: -192px -192px; } +.ui-icon-circle-check { background-position: -208px -192px; } +.ui-icon-circlesmall-plus { background-position: 0 -208px; } +.ui-icon-circlesmall-minus { background-position: -16px -208px; } +.ui-icon-circlesmall-close { background-position: -32px -208px; } +.ui-icon-squaresmall-plus { background-position: -48px -208px; } +.ui-icon-squaresmall-minus { background-position: -64px -208px; } +.ui-icon-squaresmall-close { background-position: -80px -208px; } +.ui-icon-grip-dotted-vertical { background-position: 0 -224px; } +.ui-icon-grip-dotted-horizontal { background-position: -16px -224px; } +.ui-icon-grip-solid-vertical { background-position: -32px -224px; } +.ui-icon-grip-solid-horizontal { background-position: -48px -224px; } +.ui-icon-gripsmall-diagonal-se { background-position: -64px -224px; } +.ui-icon-grip-diagonal-se { background-position: -80px -224px; } + + +/* Misc visuals +----------------------------------*/ + +/* Corner radius */ +.ui-corner-all, .ui-corner-top, .ui-corner-left, .ui-corner-tl { -moz-border-radius-topleft: 4px; -webkit-border-top-left-radius: 4px; -khtml-border-top-left-radius: 4px; border-top-left-radius: 4px; } +.ui-corner-all, .ui-corner-top, .ui-corner-right, .ui-corner-tr { -moz-border-radius-topright: 4px; -webkit-border-top-right-radius: 4px; -khtml-border-top-right-radius: 4px; border-top-right-radius: 4px; } +.ui-corner-all, .ui-corner-bottom, .ui-corner-left, .ui-corner-bl { -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; -khtml-border-bottom-left-radius: 4px; border-bottom-left-radius: 4px; } +.ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br { -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; -khtml-border-bottom-right-radius: 4px; border-bottom-right-radius: 4px; } + +/* Overlays */ +.ui-widget-overlay { background: #666666 url(images/ui-bg_diagonals-thick_20_666666_40x40.png) 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); } +.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 url(images/ui-bg_flat_10_000000_40x100.png) 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }/* + * jQuery UI Resizable 1.8.14 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Resizable#theming + */ +.ui-resizable { position: relative;} +.ui-resizable-handle { position: absolute;font-size: 0.1px;z-index: 99999; display: block; } +.ui-resizable-disabled .ui-resizable-handle, .ui-resizable-autohide .ui-resizable-handle { display: none; } +.ui-resizable-n { cursor: n-resize; height: 7px; width: 100%; top: -5px; left: 0; } +.ui-resizable-s { cursor: s-resize; height: 7px; width: 100%; bottom: -5px; left: 0; } +.ui-resizable-e { cursor: e-resize; width: 7px; right: -5px; top: 0; height: 100%; } +.ui-resizable-w { cursor: w-resize; width: 7px; left: -5px; top: 0; height: 100%; } +.ui-resizable-se { cursor: se-resize; width: 12px; height: 12px; right: 1px; bottom: 1px; } +.ui-resizable-sw { cursor: sw-resize; width: 9px; height: 9px; left: -5px; bottom: -5px; } +.ui-resizable-nw { cursor: nw-resize; width: 9px; height: 9px; left: -5px; top: -5px; } +.ui-resizable-ne { cursor: ne-resize; width: 9px; height: 9px; right: -5px; top: -5px;}/* + * jQuery UI Selectable 1.8.14 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Selectable#theming + */ +.ui-selectable-helper { position: absolute; z-index: 100; border:1px dotted black; } +/* + * jQuery UI Accordion 1.8.14 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Accordion#theming + */ +/* IE/Win - Fix animation bug - #4615 */ +.ui-accordion { width: 100%; } +.ui-accordion .ui-accordion-header { cursor: pointer; position: relative; margin-top: 1px; zoom: 1; } +.ui-accordion .ui-accordion-li-fix { display: inline; } +.ui-accordion .ui-accordion-header-active { border-bottom: 0 !important; } +.ui-accordion .ui-accordion-header a { display: block; font-size: 1em; padding: .5em .5em .5em .7em; } +.ui-accordion-icons .ui-accordion-header a { padding-left: 2.2em; } +.ui-accordion .ui-accordion-header .ui-icon { position: absolute; left: .5em; top: 50%; margin-top: -8px; } +.ui-accordion .ui-accordion-content { padding: 1em 2.2em; border-top: 0; margin-top: -2px; position: relative; top: 1px; margin-bottom: 2px; overflow: auto; display: none; zoom: 1; } +.ui-accordion .ui-accordion-content-active { display: block; } +/* + * jQuery UI Autocomplete 1.8.14 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Autocomplete#theming + */ +.ui-autocomplete { position: absolute; cursor: default; } + +/* workarounds */ +* html .ui-autocomplete { width:1px; } /* without this, the menu expands to 100% in IE6 */ + +/* + * jQuery UI Menu 1.8.14 + * + * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Menu#theming + */ +.ui-menu { + list-style:none; + padding: 2px; + margin: 0; + display:block; + float: left; +} +.ui-menu .ui-menu { + margin-top: -3px; +} +.ui-menu .ui-menu-item { + margin:0; + padding: 0; + zoom: 1; + float: left; + clear: left; + width: 100%; +} +.ui-menu .ui-menu-item a { + text-decoration:none; + display:block; + padding:.2em .4em; + line-height:1.5; + zoom:1; +} +.ui-menu .ui-menu-item a.ui-state-hover, +.ui-menu .ui-menu-item a.ui-state-active { + font-weight: normal; + margin: -1px; +} +/* + * jQuery UI Button 1.8.14 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Button#theming + */ +.ui-button { display: inline-block; position: relative; padding: 0; margin-right: .1em; text-decoration: none !important; cursor: pointer; text-align: center; zoom: 1; overflow: visible; } /* the overflow property removes extra width in IE */ +.ui-button-icon-only { width: 2.2em; } /* to make room for the icon, a width needs to be set here */ +button.ui-button-icon-only { width: 2.4em; } /* button elements seem to need a little more width */ +.ui-button-icons-only { width: 3.4em; } +button.ui-button-icons-only { width: 3.7em; } + +/*button text element */ +.ui-button .ui-button-text { display: block; line-height: 1.4; } +.ui-button-text-only .ui-button-text { padding: .4em 1em; } +.ui-button-icon-only .ui-button-text, .ui-button-icons-only .ui-button-text { padding: .4em; text-indent: -9999999px; } +.ui-button-text-icon-primary .ui-button-text, .ui-button-text-icons .ui-button-text { padding: .4em 1em .4em 2.1em; } +.ui-button-text-icon-secondary .ui-button-text, .ui-button-text-icons .ui-button-text { padding: .4em 2.1em .4em 1em; } +.ui-button-text-icons .ui-button-text { padding-left: 2.1em; padding-right: 2.1em; } +/* no icon support for input elements, provide padding by default */ +input.ui-button { padding: .4em 1em; } + +/*button icon element(s) */ +.ui-button-icon-only .ui-icon, .ui-button-text-icon-primary .ui-icon, .ui-button-text-icon-secondary .ui-icon, .ui-button-text-icons .ui-icon, .ui-button-icons-only .ui-icon { position: absolute; top: 50%; margin-top: -8px; } +.ui-button-icon-only .ui-icon { left: 50%; margin-left: -8px; } +.ui-button-text-icon-primary .ui-button-icon-primary, .ui-button-text-icons .ui-button-icon-primary, .ui-button-icons-only .ui-button-icon-primary { left: .5em; } +.ui-button-text-icon-secondary .ui-button-icon-secondary, .ui-button-text-icons .ui-button-icon-secondary, .ui-button-icons-only .ui-button-icon-secondary { right: .5em; } +.ui-button-text-icons .ui-button-icon-secondary, .ui-button-icons-only .ui-button-icon-secondary { right: .5em; } + +/*button sets*/ +.ui-buttonset { margin-right: 7px; } +.ui-buttonset .ui-button { margin-left: 0; margin-right: -.3em; } + +/* workarounds */ +button.ui-button::-moz-focus-inner { border: 0; padding: 0; } /* reset extra padding in Firefox */ +/* + * jQuery UI Dialog 1.8.14 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Dialog#theming + */ +.ui-dialog { position: absolute; padding: .2em; width: 300px; overflow: hidden; } +.ui-dialog .ui-dialog-titlebar { padding: .4em 1em; position: relative; } +.ui-dialog .ui-dialog-title { float: left; margin: .1em 16px .1em 0; } +.ui-dialog .ui-dialog-titlebar-close { position: absolute; right: .3em; top: 50%; width: 19px; margin: -10px 0 0 0; padding: 1px; height: 18px; } +.ui-dialog .ui-dialog-titlebar-close span { display: block; margin: 1px; } +.ui-dialog .ui-dialog-titlebar-close:hover, .ui-dialog .ui-dialog-titlebar-close:focus { padding: 0; } +.ui-dialog .ui-dialog-content { position: relative; border: 0; padding: .5em 1em; background: none; overflow: auto; zoom: 1; } +.ui-dialog .ui-dialog-buttonpane { text-align: left; border-width: 1px 0 0 0; background-image: none; margin: .5em 0 0 0; padding: .3em 1em .5em .4em; } +.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset { float: right; } +.ui-dialog .ui-dialog-buttonpane button { margin: .5em .4em .5em 0; cursor: pointer; } +.ui-dialog .ui-resizable-se { width: 14px; height: 14px; right: 3px; bottom: 3px; } +.ui-draggable .ui-dialog-titlebar { cursor: move; } +/* + * jQuery UI Slider 1.8.14 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Slider#theming + */ +.ui-slider { position: relative; text-align: left; } +.ui-slider .ui-slider-handle { position: absolute; z-index: 2; width: 1.2em; height: 1.2em; cursor: default; } +.ui-slider .ui-slider-range { position: absolute; z-index: 1; font-size: .7em; display: block; border: 0; background-position: 0 0; } + +.ui-slider-horizontal { height: .8em; } +.ui-slider-horizontal .ui-slider-handle { top: -.3em; margin-left: -.6em; } +.ui-slider-horizontal .ui-slider-range { top: 0; height: 100%; } +.ui-slider-horizontal .ui-slider-range-min { left: 0; } +.ui-slider-horizontal .ui-slider-range-max { right: 0; } + +.ui-slider-vertical { width: .8em; height: 100px; } +.ui-slider-vertical .ui-slider-handle { left: -.3em; margin-left: 0; margin-bottom: -.6em; } +.ui-slider-vertical .ui-slider-range { left: 0; width: 100%; } +.ui-slider-vertical .ui-slider-range-min { bottom: 0; } +.ui-slider-vertical .ui-slider-range-max { top: 0; }/* + * jQuery UI Tabs 1.8.14 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Tabs#theming + */ +.ui-tabs { position: relative; padding: .2em; zoom: 1; } /* position: relative prevents IE scroll bug (element with position: relative inside container with overflow: auto appear as "fixed") */ +.ui-tabs .ui-tabs-nav { margin: 0; padding: .2em .2em 0; } +.ui-tabs .ui-tabs-nav li { list-style: none; float: left; position: relative; top: 1px; margin: 0 .2em 1px 0; border-bottom: 0 !important; padding: 0; white-space: nowrap; } +.ui-tabs .ui-tabs-nav li a { float: left; padding: .5em 1em; text-decoration: none; } +.ui-tabs .ui-tabs-nav li.ui-tabs-selected { margin-bottom: 0; padding-bottom: 1px; } +.ui-tabs .ui-tabs-nav li.ui-tabs-selected a, .ui-tabs .ui-tabs-nav li.ui-state-disabled a, .ui-tabs .ui-tabs-nav li.ui-state-processing a { cursor: text; } +.ui-tabs .ui-tabs-nav li a, .ui-tabs.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-selected a { cursor: pointer; } /* first selector in group seems obsolete, but required to overcome bug in Opera applying cursor: text overall if defined elsewhere... */ +.ui-tabs .ui-tabs-panel { display: block; border-width: 0; padding: 1em 1.4em; background: none; } +.ui-tabs .ui-tabs-hide { display: none !important; } +/* + * jQuery UI Datepicker 1.8.14 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Datepicker#theming + */ +.ui-datepicker { width: 17em; padding: .2em .2em 0; display: none; } +.ui-datepicker .ui-datepicker-header { position:relative; padding:.2em 0; } +.ui-datepicker .ui-datepicker-prev, .ui-datepicker .ui-datepicker-next { position:absolute; top: 2px; width: 1.8em; height: 1.8em; } +.ui-datepicker .ui-datepicker-prev-hover, .ui-datepicker .ui-datepicker-next-hover { top: 1px; } +.ui-datepicker .ui-datepicker-prev { left:2px; } +.ui-datepicker .ui-datepicker-next { right:2px; } +.ui-datepicker .ui-datepicker-prev-hover { left:1px; } +.ui-datepicker .ui-datepicker-next-hover { right:1px; } +.ui-datepicker .ui-datepicker-prev span, .ui-datepicker .ui-datepicker-next span { display: block; position: absolute; left: 50%; margin-left: -8px; top: 50%; margin-top: -8px; } +.ui-datepicker .ui-datepicker-title { margin: 0 2.3em; line-height: 1.8em; text-align: center; } +.ui-datepicker .ui-datepicker-title select { font-size:1em; margin:1px 0; } +.ui-datepicker select.ui-datepicker-month-year {width: 100%;} +.ui-datepicker select.ui-datepicker-month, +.ui-datepicker select.ui-datepicker-year { width: 49%;} +.ui-datepicker table {width: 100%; font-size: .9em; border-collapse: collapse; margin:0 0 .4em; } +.ui-datepicker th { padding: .7em .3em; text-align: center; font-weight: bold; border: 0; } +.ui-datepicker td { border: 0; padding: 1px; } +.ui-datepicker td span, .ui-datepicker td a { display: block; padding: .2em; text-align: right; text-decoration: none; } +.ui-datepicker .ui-datepicker-buttonpane { background-image: none; margin: .7em 0 0 0; padding:0 .2em; border-left: 0; border-right: 0; border-bottom: 0; } +.ui-datepicker .ui-datepicker-buttonpane button { float: right; margin: .5em .2em .4em; cursor: pointer; padding: .2em .6em .3em .6em; width:auto; overflow:visible; } +.ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current { float:left; } + +/* with multiple calendars */ +.ui-datepicker.ui-datepicker-multi { width:auto; } +.ui-datepicker-multi .ui-datepicker-group { float:left; } +.ui-datepicker-multi .ui-datepicker-group table { width:95%; margin:0 auto .4em; } +.ui-datepicker-multi-2 .ui-datepicker-group { width:50%; } +.ui-datepicker-multi-3 .ui-datepicker-group { width:33.3%; } +.ui-datepicker-multi-4 .ui-datepicker-group { width:25%; } +.ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header { border-left-width:0; } +.ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header { border-left-width:0; } +.ui-datepicker-multi .ui-datepicker-buttonpane { clear:left; } +.ui-datepicker-row-break { clear:both; width:100%; font-size:0em; } + +/* RTL support */ +.ui-datepicker-rtl { direction: rtl; } +.ui-datepicker-rtl .ui-datepicker-prev { right: 2px; left: auto; } +.ui-datepicker-rtl .ui-datepicker-next { left: 2px; right: auto; } +.ui-datepicker-rtl .ui-datepicker-prev:hover { right: 1px; left: auto; } +.ui-datepicker-rtl .ui-datepicker-next:hover { left: 1px; right: auto; } +.ui-datepicker-rtl .ui-datepicker-buttonpane { clear:right; } +.ui-datepicker-rtl .ui-datepicker-buttonpane button { float: left; } +.ui-datepicker-rtl .ui-datepicker-buttonpane button.ui-datepicker-current { float:right; } +.ui-datepicker-rtl .ui-datepicker-group { float:right; } +.ui-datepicker-rtl .ui-datepicker-group-last .ui-datepicker-header { border-right-width:0; border-left-width:1px; } +.ui-datepicker-rtl .ui-datepicker-group-middle .ui-datepicker-header { border-right-width:0; border-left-width:1px; } + +/* IE6 IFRAME FIX (taken from datepicker 1.5.3 */ +.ui-datepicker-cover { + display: none; /*sorry for IE5*/ + display/**/: block; /*sorry for IE5*/ + position: absolute; /*must have*/ + z-index: -1; /*must have*/ + filter: mask(); /*must have*/ + top: -4px; /*must have*/ + left: -4px; /*must have*/ + width: 200px; /*must have*/ + height: 200px; /*must have*/ +}/* + * jQuery UI Progressbar 1.8.14 + * + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license + * + * http://docs.jquery.com/UI/Progressbar#theming + */ +.ui-progressbar { height:2em; text-align: left; } +.ui-progressbar .ui-progressbar-value {margin: -1px; height:100%; } \ No newline at end of file diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 9b19ceff3b..ad69caa2bb 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -24,6 +24,8 @@ module ActiveScaffold autoload :Constraints, 'active_scaffold/constraints' autoload :Finder, 'active_scaffold/finder' autoload :MarkedModel, 'active_scaffold/marked_model' + autoload :Bridge, 'active_scaffold/bridge' + autoload :Bridges, 'active_scaffold/bridges' def self.autoload_subdir(dir, mod=self, root = File.dirname(__FILE__)) Dir["#{root}/active_scaffold/#{dir}/*.rb"].each { |file| @@ -38,10 +40,6 @@ module Actions ActiveScaffold.autoload_subdir('actions', self) end - module Bridges - autoload :Bridge, 'active_scaffold/bridges/bridge' - end - module Config ActiveScaffold.autoload_subdir('config', self) end diff --git a/lib/active_scaffold/bridge.rb b/lib/active_scaffold/bridge.rb new file mode 100644 index 0000000000..9c7e877550 --- /dev/null +++ b/lib/active_scaffold/bridge.rb @@ -0,0 +1,57 @@ +module ActiveScaffold + class Bridge + attr_accessor :name + cattr_accessor :bridges + cattr_accessor :bridges_run + self.bridges = {} + + def self.register(file) + match = file.match(/(active_scaffold\/bridges\/(.*))\.rb\Z/) + self.bridges[match[2].to_sym] = match[1] if match + end + + def self.load(bridge_name) + bridge = self.bridges[bridge_name.to_sym] + if bridge.is_a? String + if ActiveScaffold.exclude_bridges.exclude? bridge_name.to_sym + bridge = bridge.camelize.constantize + self.bridges[bridge_name.to_sym] = bridge + else + self.bridges.delete bridge_name + bridge = nil + end + end + bridge + end + class << self + alias_method :[], :load + end + + def self.run_all + return false if self.bridges_run + self.bridges.keys.each{|bridge_name| + bridge = self[bridge_name] + bridge.run if bridge + } + self.bridges_run = true + end + + def self.install + raise(RunTimeError, "install not defined for bridge #{name}") + end + + # by convention and default, use the bridge name as the required constant for installation + def self.install? + Object.const_defined? name.demodulize + end + + def self.run + install if install? + end + end +end + +require File.join(File.dirname(__FILE__), 'bridges/shared/date_bridge.rb') +(Dir[File.join(File.dirname(__FILE__), "bridges/*.rb")] - [__FILE__]).each{|bridge_require| + ActiveScaffold::Bridge.register bridge_require +} diff --git a/lib/active_scaffold/bridges.rb b/lib/active_scaffold/bridges.rb new file mode 100644 index 0000000000..64389893a0 --- /dev/null +++ b/lib/active_scaffold/bridges.rb @@ -0,0 +1,5 @@ +module ActiveScaffold + module Bridges + ActiveScaffold.autoload_subdir('bridges', self) + end +end diff --git a/lib/active_scaffold/bridges/bridge.rb b/lib/active_scaffold/bridges/bridge.rb deleted file mode 100644 index 78c8249294..0000000000 --- a/lib/active_scaffold/bridges/bridge.rb +++ /dev/null @@ -1,59 +0,0 @@ -module ActiveScaffold - module Bridges - def self.bridge(name, &block) - ActiveScaffold::Bridges::Bridge.new(name, &block) - end - - class Bridge - attr_accessor :name - cattr_accessor :bridges - cattr_accessor :bridges_run - self.bridges = [] - - def initialize(name, &block) - self.name = name - @install = nil - # by convention and default, use the bridge name as the required constant for installation - @install_if = lambda { Object.const_defined?(name) } - self.instance_eval(&block) - - ActiveScaffold::Bridges::Bridge.bridges << self - end - - # Set the install block - def install(&block) - @install = block - end - - # Set the install_if block (to check to see whether or not to install the block) - def install?(&block) - @install_if = block - end - - - def run - raise(ArgumentError, "install and install? not defined for bridge #{name}" ) unless @install && @install_if - @install.call if @install_if.call - end - - def self.run_all - return false if self.bridges_run - ActiveScaffold::Bridges::Bridge.bridges.each{|bridge| - bridge.run - } - self.bridges_run=true - end - end - end -end - -require File.join(File.dirname(__FILE__), 'shared', 'date_bridge.rb') -Dir[File.join(File.dirname(__FILE__), "*/bridge.rb")].each{|bridge_require| - load_bridge = true - unless ActiveScaffold.exclude_bridges.empty? - match = bridge_require.match('bridges\/(.*)\/bridge.rb') - bridge_name = match[1] ? match[1] : nil - load_bridge = ActiveScaffold.exclude_bridges.exclude?(bridge_name.to_sym) if bridge_name - end - require bridge_require if load_bridge == true -} \ No newline at end of file diff --git a/lib/active_scaffold/bridges/date_picker.rb b/lib/active_scaffold/bridges/date_picker.rb new file mode 100644 index 0000000000..39697a7995 --- /dev/null +++ b/lib/active_scaffold/bridges/date_picker.rb @@ -0,0 +1,23 @@ +module ActiveScaffold::Bridges + class DatePicker < ActiveScaffold::Bridge + autoload :Helper, 'active_scaffold/bridges/date_picker/helper' + def self.install + require File.join(File.dirname(__FILE__), "ext.rb") + end + def self.install? + ActiveScaffold.js_framework == :jquery + end + def self.localization + "jQuery(function($){ + if (typeof($.datepicker) === 'object') { + #{Helper.date_options_for_locales} + $.datepicker.setDefaults($.datepicker.regional['#{::I18n.locale}']); + } + if (typeof($.timepicker) === 'object') { + #{Helper.datetime_options_for_locales} + $.timepicker.setDefaults($.timepicker.regional['#{::I18n.locale}']); + } +});\n" + end + end +end diff --git a/lib/active_scaffold/bridges/date_picker/bridge.rb b/lib/active_scaffold/bridges/date_picker/bridge.rb deleted file mode 100644 index f1282d2b88..0000000000 --- a/lib/active_scaffold/bridges/date_picker/bridge.rb +++ /dev/null @@ -1,10 +0,0 @@ -ActiveScaffold::Bridges.bridge "DatePicker" do - install do - require File.join(File.dirname(__FILE__), "lib/datepicker_bridge.rb") if ActiveScaffold.js_framework == :jquery - end - - - install? do - true - end -end diff --git a/lib/active_scaffold/bridges/date_picker/ext.rb b/lib/active_scaffold/bridges/date_picker/ext.rb new file mode 100644 index 0000000000..7f2e0af646 --- /dev/null +++ b/lib/active_scaffold/bridges/date_picker/ext.rb @@ -0,0 +1,54 @@ +class File #:nodoc: + + unless File.respond_to?(:binread) + def self.binread(file) + File.open(file, 'rb') { |f| f.read } + end + end + +end + +ActiveScaffold::Config::Core.class_eval do + def initialize_with_date_picker(model_id) + initialize_without_date_picker(model_id) + + date_picker_fields = self.model.columns.collect{|c| {:name => c.name.to_sym, :type => c.type} if [:date, :datetime].include?(c.type) }.compact + # check to see if file column was used on the model + return if date_picker_fields.empty? + + # automatically set the forum_ui to a file column + date_picker_fields.each{|field| + col_config = self.columns[field[:name]] + col_config.form_ui = (field[:type] == :date ? :date_picker : :datetime_picker) + } + end + + alias_method_chain :initialize, :date_picker +end + +ActiveRecord::ConnectionAdapters::Column.class_eval do + class << self + def fallback_string_to_date_with_date_picker(string) + Date.strptime(string, I18n.t('date.formats.default')) rescue fallback_string_to_date_without_date_picker(string) + end + alias_method_chain :fallback_string_to_date, :date_picker + end +end + +ActionView::Base.class_eval do + include ActiveScaffold::Bridges::Shared::DateBridge::SearchColumnHelpers + alias_method :active_scaffold_search_date_picker, :active_scaffold_search_date_bridge + alias_method :active_scaffold_search_datetime_picker, :active_scaffold_search_date_bridge + include ActiveScaffold::Bridges::Shared::DateBridge::HumanConditionHelpers + alias_method :active_scaffold_human_condition_date_picker, :active_scaffold_human_condition_date_bridge + alias_method :active_scaffold_human_condition_datetime_picker, :active_scaffold_human_condition_date_bridge + include ActiveScaffold::Bridges::DatePicker::Helper::SearchColumnHelpers + include ActiveScaffold::Bridges::DatePicker::Helper::FormColumnHelpers + alias_method :active_scaffold_input_datetime_picker, :active_scaffold_input_date_picker + include ActiveScaffold::Bridges::DatePicker::Helper::DatepickerColumnHelpers +end +ActiveScaffold::Finder::ClassMethods.module_eval do + include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods + alias_method :condition_for_date_picker_type, :condition_for_date_bridge_type + alias_method :condition_for_datetime_picker_type, :condition_for_date_picker_type +end diff --git a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb b/lib/active_scaffold/bridges/date_picker/helper.rb similarity index 68% rename from lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb rename to lib/active_scaffold/bridges/date_picker/helper.rb index 634cd0b4c5..8564b7b3a5 100644 --- a/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -1,44 +1,6 @@ -class File #:nodoc: - - unless File.respond_to?(:binread) - def self.binread(file) - File.open(file, 'rb') { |f| f.read } - end - end - -end - -ActiveScaffold::Config::Core.class_eval do - def initialize_with_date_picker(model_id) - initialize_without_date_picker(model_id) - - date_picker_fields = self.model.columns.collect{|c| {:name => c.name.to_sym, :type => c.type} if [:date, :datetime].include?(c.type) }.compact - # check to see if file column was used on the model - return if date_picker_fields.empty? - - # automatically set the forum_ui to a file column - date_picker_fields.each{|field| - col_config = self.columns[field[:name]] - col_config.form_ui = (field[:type] == :date ? :date_picker : :datetime_picker) - } - end - - alias_method_chain :initialize, :date_picker -end - -ActiveRecord::ConnectionAdapters::Column.class_eval do - class << self - def fallback_string_to_date_with_date_picker(string) - Date.strptime(string, I18n.t('date.formats.default')) rescue fallback_string_to_date_without_date_picker(string) - end - alias_method_chain :fallback_string_to_date, :date_picker - end -end - - -module ActiveScaffold - module Bridges - module DatePickerBridge +module ActiveScaffold::Bridges + class DatePicker + module Helper DATE_FORMAT_CONVERSION = { '%a' => 'D', '%A' => 'DD', @@ -57,19 +19,6 @@ module DatePickerBridge '%S' => 'ss' } - def self.localization - "jQuery(function($){ - if (typeof($.datepicker) === 'object') { - #{date_options_for_locales} - $.datepicker.setDefaults($.datepicker.regional['#{I18n.locale}']); - } - if (typeof($.timepicker) === 'object') { - #{datetime_options_for_locales} - $.timepicker.setDefaults($.timepicker.regional['#{I18n.locale}']); - } -});\n" - end - def self.date_options_for_locales I18n.available_locales.collect do |locale| locale_date_options = date_options(locale) @@ -108,11 +57,7 @@ def self.date_options(locale) date_picker_options[:dateFormat] = js_format unless js_format.nil? date_picker_options rescue - if locale == I18n.locale - raise - else - nil - end + raise if locale == I18n.locale end end @@ -152,18 +97,14 @@ def self.datetime_options(locale) end datetime_picker_options rescue - if locale == I18n.locale - raise - else - nil - end + raise if locale == I18n.locale end end def self.to_datepicker_format(rails_format) return nil if rails_format.nil? if rails_format =~ /%[cUWwxXZz]/ - Rails.logger.warn("AS DatePickerBridge: Can t convert rails date format: #{rails_format} to jquery datepicker format. Options %c, %U, %W, %w, %x %X, %z, %Z are not supported by datepicker]") + Rails.logger.warn("AS DatePicker::Helper: Can t convert rails date format: #{rails_format} to jquery datepicker format. Options %c, %U, %W, %w, %x %X, %z, %Z are not supported by datepicker]") nil else js_format = rails_format.dup @@ -191,11 +132,11 @@ def self.split_datetime_format(datetime_format) module DatepickerColumnHelpers def datepicker_split_datetime_format(datetime_format) - ActiveScaffold::Bridges::DatePickerBridge.split_datetime_format(datetime_format) + ActiveScaffold::Bridges::DatePicker::Helper.split_datetime_format(datetime_format) end def to_datepicker_format(rails_format) - ActiveScaffold::Bridges::DatePickerBridge.to_datepicker_format(rails_format) + ActiveScaffold::Bridges::DatePicker::Helper.to_datepicker_format(rails_format) end def datepicker_format_options(column, format, options) @@ -245,21 +186,3 @@ def active_scaffold_input_date_picker(column, options) end end end - -ActionView::Base.class_eval do - include ActiveScaffold::Bridges::Shared::DateBridge::SearchColumnHelpers - alias_method :active_scaffold_search_date_picker, :active_scaffold_search_date_bridge - alias_method :active_scaffold_search_datetime_picker, :active_scaffold_search_date_bridge - include ActiveScaffold::Bridges::Shared::DateBridge::HumanConditionHelpers - alias_method :active_scaffold_human_condition_date_picker, :active_scaffold_human_condition_date_bridge - alias_method :active_scaffold_human_condition_datetime_picker, :active_scaffold_human_condition_date_bridge - include ActiveScaffold::Bridges::DatePickerBridge::SearchColumnHelpers - include ActiveScaffold::Bridges::DatePickerBridge::FormColumnHelpers - alias_method :active_scaffold_input_datetime_picker, :active_scaffold_input_date_picker - include ActiveScaffold::Bridges::DatePickerBridge::DatepickerColumnHelpers -end -ActiveScaffold::Finder::ClassMethods.module_eval do - include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods - alias_method :condition_for_date_picker_type, :condition_for_date_bridge_type - alias_method :condition_for_datetime_picker_type, :condition_for_date_picker_type -end diff --git a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb index 20dab19236..69e2ac2ae3 100644 --- a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +++ b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb @@ -9,7 +9,6 @@ def self.source_root def install_plugins if defined?(ACTIVE_SCAFFOLD_PLUGIN) - plugin 'verification', :git => 'git://github.com/rails/verification.git' plugin 'render_component', :git => 'git://github.com/vhochstein/render_component.git' end if js_lib == 'prototype' @@ -56,4 +55,4 @@ def configure_application_layout end end end -end \ No newline at end of file +end From fcd71e138181b592c58272665648bcf480fd2eb3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 13 Sep 2011 18:14:43 +0200 Subject: [PATCH 1233/2024] fix render :super and render :active_scaffold --- .../extensions/action_view_rendering.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index fd1f877556..eb11ea6533 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -14,8 +14,8 @@ def find_all_templates(name, prefix = nil, partial = false) end # wrap the action rendering for ActiveScaffold views -module ActionView #:nodoc: - class Renderer +module ActionView::Helpers #:nodoc: + module RenderingHelper # # Adds two rendering options. # @@ -40,7 +40,7 @@ class Renderer # def render_with_active_scaffold(*args, &block) if args.first == :super - last_view = @view_stack.last + last_view = @_view_stack.last options = args[1] || {} options[:locals] ||= {} options[:locals].reverse_merge!(last_view[:locals] || {}) @@ -49,11 +49,11 @@ def render_with_active_scaffold(*args, &block) last_view[:templates].shift end options[:template] = last_view[:templates].shift - @view_stack << last_view + @_view_stack << last_view result = render_without_active_scaffold options - @view_stack.pop + @_view_stack.pop result - elsif args.first.is_a?(Hash) and args.first[:active_scaffold] + elsif args.first.is_a? Hash and args.first[:active_scaffold] require 'digest/md5' options = args.first @@ -89,12 +89,12 @@ def render_with_active_scaffold(*args, &block) current_view = {:view => options[:template], :is_template => !!options[:template]} if current_view.nil? && options[:template] current_view[:locals] = options[:locals] if !current_view.nil? && options[:locals] if current_view.present? - @view_stack ||= [] - @view_stack << current_view + @_view_stack ||= [] + @_view_stack << current_view end end result = render_without_active_scaffold(*args, &block) - @view_stack.pop if current_view.present? + @_view_stack.pop if current_view.present? result end end From bb7023b46b5ccccb5816078c6d47bacaf4483184 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Sep 2011 10:58:43 +0200 Subject: [PATCH 1234/2024] update bridges structure --- .../jquery/date_picker_bridge.js.erb | 2 +- lib/active_scaffold.rb | 3 +- lib/active_scaffold/bridge.rb | 57 ------------------ lib/active_scaffold/bridges.rb | 40 +++++++++++++ lib/active_scaffold/bridges/ancestry.rb | 5 ++ .../ancestry/{lib => }/ancestry_bridge.rb | 0 .../bridges/ancestry/bridge.rb | 5 -- .../bridge.rb => calendar_date_select.rb} | 8 +-- .../{lib => }/as_cds_bridge.rb | 0 .../bridges/{cancan/bridge.rb => cancan.rb} | 9 ++- .../bridges/cancan/{lib => }/cancan_bridge.rb | 0 lib/active_scaffold/bridges/carrierwave.rb | 12 ++++ .../bridges/carrierwave/bridge.rb | 9 --- .../bridges/carrierwave/carrierwave_bridge.rb | 31 ++++++++++ .../carrierwave/carrierwave_bridge_helpers.rb | 10 ++++ .../bridges/carrierwave/{lib => }/form_ui.rb | 0 .../carrierwave/lib/carrierwave_bridge.rb | 33 ----------- .../lib/carrierwave_bridge_helpers.rb | 12 ---- .../bridges/carrierwave/{lib => }/list_ui.rb | 2 +- lib/active_scaffold/bridges/country_helper.rb | 9 +++ .../bridges/country_helper/bridge.rb | 9 --- .../{lib => }/country_helper_bridge.rb | 0 lib/active_scaffold/bridges/date_picker.rb | 2 +- lib/active_scaffold/bridges/dragonfly.rb | 9 +++ .../bridges/dragonfly/bridge.rb | 9 --- .../bridges/dragonfly/dragonfly_bridge.rb | 34 +++++++++++ .../dragonfly/dragonfly_bridge_helpers.rb | 10 ++++ .../bridges/dragonfly/{lib => }/form_ui.rb | 0 .../bridges/dragonfly/lib/dragonfly_bridge.rb | 36 ----------- .../dragonfly/lib/dragonfly_bridge_helpers.rb | 12 ---- .../bridges/dragonfly/{lib => }/list_ui.rb | 4 +- lib/active_scaffold/bridges/file_column.rb | 11 ++++ .../{lib => }/as_file_column_bridge.rb | 4 +- .../bridges/file_column/bridge.rb | 11 ---- .../file_column/file_column_helpers.rb | 57 ++++++++++++++++++ .../bridges/file_column/{lib => }/form_ui.rb | 0 .../file_column/lib/file_column_helpers.rb | 59 ------------------- .../bridges/file_column/{lib => }/list_ui.rb | 0 lib/active_scaffold/bridges/paperclip.rb | 12 ++++ .../bridges/paperclip/bridge.rb | 12 ---- .../bridges/paperclip/{lib => }/form_ui.rb | 0 .../bridges/paperclip/lib/paperclip_bridge.rb | 38 ------------ .../paperclip/lib/paperclip_bridge_helpers.rb | 26 -------- .../bridges/paperclip/{lib => }/list_ui.rb | 6 +- .../bridges/paperclip/paperclip_bridge.rb | 36 +++++++++++ .../paperclip/paperclip_bridge_helpers.rb | 24 ++++++++ lib/active_scaffold/bridges/record_select.rb | 5 ++ .../bridges/record_select/bridge.rb | 5 -- .../{lib => }/record_select_bridge.rb | 0 .../bridges/semantic_attributes.rb | 5 ++ .../bridges/semantic_attributes/bridge.rb | 5 -- .../{lib => }/semantic_attributes_bridge.rb | 0 lib/active_scaffold/bridges/tiny_mce.rb | 5 ++ .../bridges/tiny_mce/bridge.rb | 5 -- .../tiny_mce/{lib => }/tiny_mce_bridge.rb | 0 .../bridges/validation_reflection.rb | 9 +++ .../bridges/validation_reflection/bridge.rb | 9 --- .../{lib => }/validation_reflection_bridge.rb | 0 lib/active_scaffold/data_structures/bridge.rb | 16 +++++ 59 files changed, 361 insertions(+), 371 deletions(-) delete mode 100644 lib/active_scaffold/bridge.rb create mode 100644 lib/active_scaffold/bridges/ancestry.rb rename lib/active_scaffold/bridges/ancestry/{lib => }/ancestry_bridge.rb (100%) delete mode 100644 lib/active_scaffold/bridges/ancestry/bridge.rb rename lib/active_scaffold/bridges/{calendar_date_select/bridge.rb => calendar_date_select.rb} (74%) rename lib/active_scaffold/bridges/calendar_date_select/{lib => }/as_cds_bridge.rb (100%) rename lib/active_scaffold/bridges/{cancan/bridge.rb => cancan.rb} (70%) rename lib/active_scaffold/bridges/cancan/{lib => }/cancan_bridge.rb (100%) create mode 100644 lib/active_scaffold/bridges/carrierwave.rb delete mode 100644 lib/active_scaffold/bridges/carrierwave/bridge.rb create mode 100644 lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb create mode 100644 lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb rename lib/active_scaffold/bridges/carrierwave/{lib => }/form_ui.rb (100%) delete mode 100644 lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb delete mode 100644 lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb rename lib/active_scaffold/bridges/carrierwave/{lib => }/list_ui.rb (93%) create mode 100644 lib/active_scaffold/bridges/country_helper.rb delete mode 100644 lib/active_scaffold/bridges/country_helper/bridge.rb rename lib/active_scaffold/bridges/country_helper/{lib => }/country_helper_bridge.rb (100%) create mode 100644 lib/active_scaffold/bridges/dragonfly.rb delete mode 100644 lib/active_scaffold/bridges/dragonfly/bridge.rb create mode 100644 lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb create mode 100644 lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb rename lib/active_scaffold/bridges/dragonfly/{lib => }/form_ui.rb (100%) delete mode 100644 lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb delete mode 100644 lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb rename lib/active_scaffold/bridges/dragonfly/{lib => }/list_ui.rb (82%) create mode 100644 lib/active_scaffold/bridges/file_column.rb rename lib/active_scaffold/bridges/file_column/{lib => }/as_file_column_bridge.rb (88%) delete mode 100644 lib/active_scaffold/bridges/file_column/bridge.rb create mode 100644 lib/active_scaffold/bridges/file_column/file_column_helpers.rb rename lib/active_scaffold/bridges/file_column/{lib => }/form_ui.rb (100%) delete mode 100644 lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb rename lib/active_scaffold/bridges/file_column/{lib => }/list_ui.rb (100%) create mode 100644 lib/active_scaffold/bridges/paperclip.rb delete mode 100644 lib/active_scaffold/bridges/paperclip/bridge.rb rename lib/active_scaffold/bridges/paperclip/{lib => }/form_ui.rb (100%) delete mode 100644 lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb delete mode 100644 lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb rename lib/active_scaffold/bridges/paperclip/{lib => }/list_ui.rb (79%) create mode 100644 lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb create mode 100644 lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb create mode 100644 lib/active_scaffold/bridges/record_select.rb delete mode 100644 lib/active_scaffold/bridges/record_select/bridge.rb rename lib/active_scaffold/bridges/record_select/{lib => }/record_select_bridge.rb (100%) create mode 100644 lib/active_scaffold/bridges/semantic_attributes.rb delete mode 100644 lib/active_scaffold/bridges/semantic_attributes/bridge.rb rename lib/active_scaffold/bridges/semantic_attributes/{lib => }/semantic_attributes_bridge.rb (100%) create mode 100644 lib/active_scaffold/bridges/tiny_mce.rb delete mode 100644 lib/active_scaffold/bridges/tiny_mce/bridge.rb rename lib/active_scaffold/bridges/tiny_mce/{lib => }/tiny_mce_bridge.rb (100%) create mode 100644 lib/active_scaffold/bridges/validation_reflection.rb delete mode 100644 lib/active_scaffold/bridges/validation_reflection/bridge.rb rename lib/active_scaffold/bridges/validation_reflection/{lib => }/validation_reflection_bridge.rb (100%) create mode 100644 lib/active_scaffold/data_structures/bridge.rb diff --git a/app/assets/javascripts/jquery/date_picker_bridge.js.erb b/app/assets/javascripts/jquery/date_picker_bridge.js.erb index 4831bedc0c..121a2041d8 100644 --- a/app/assets/javascripts/jquery/date_picker_bridge.js.erb +++ b/app/assets/javascripts/jquery/date_picker_bridge.js.erb @@ -1,4 +1,4 @@ -<%= ActiveScaffold::Bridge[:date_picker].localization %> +<%= ActiveScaffold::Bridges[:date_picker].localization %> $(document).ready(function() { $('input.date_picker').live('focus', function(event) { diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index ad69caa2bb..2bd49b82d0 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -24,7 +24,6 @@ module ActiveScaffold autoload :Constraints, 'active_scaffold/constraints' autoload :Finder, 'active_scaffold/finder' autoload :MarkedModel, 'active_scaffold/marked_model' - autoload :Bridge, 'active_scaffold/bridge' autoload :Bridges, 'active_scaffold/bridges' def self.autoload_subdir(dir, mod=self, root = File.dirname(__FILE__)) @@ -148,7 +147,7 @@ def self.root module ClassMethods def active_scaffold(model_id = nil, &block) # initialize bridges here - ActiveScaffold::Bridges::Bridge.run_all + ActiveScaffold::Bridges.run_all # converts Foo::BarController to 'bar' and FooBarsController to 'foo_bar' and AddressController to 'address' model_id = self.to_s.split('::').last.sub(/Controller$/, '').pluralize.singularize.underscore unless model_id diff --git a/lib/active_scaffold/bridge.rb b/lib/active_scaffold/bridge.rb deleted file mode 100644 index 9c7e877550..0000000000 --- a/lib/active_scaffold/bridge.rb +++ /dev/null @@ -1,57 +0,0 @@ -module ActiveScaffold - class Bridge - attr_accessor :name - cattr_accessor :bridges - cattr_accessor :bridges_run - self.bridges = {} - - def self.register(file) - match = file.match(/(active_scaffold\/bridges\/(.*))\.rb\Z/) - self.bridges[match[2].to_sym] = match[1] if match - end - - def self.load(bridge_name) - bridge = self.bridges[bridge_name.to_sym] - if bridge.is_a? String - if ActiveScaffold.exclude_bridges.exclude? bridge_name.to_sym - bridge = bridge.camelize.constantize - self.bridges[bridge_name.to_sym] = bridge - else - self.bridges.delete bridge_name - bridge = nil - end - end - bridge - end - class << self - alias_method :[], :load - end - - def self.run_all - return false if self.bridges_run - self.bridges.keys.each{|bridge_name| - bridge = self[bridge_name] - bridge.run if bridge - } - self.bridges_run = true - end - - def self.install - raise(RunTimeError, "install not defined for bridge #{name}") - end - - # by convention and default, use the bridge name as the required constant for installation - def self.install? - Object.const_defined? name.demodulize - end - - def self.run - install if install? - end - end -end - -require File.join(File.dirname(__FILE__), 'bridges/shared/date_bridge.rb') -(Dir[File.join(File.dirname(__FILE__), "bridges/*.rb")] - [__FILE__]).each{|bridge_require| - ActiveScaffold::Bridge.register bridge_require -} diff --git a/lib/active_scaffold/bridges.rb b/lib/active_scaffold/bridges.rb index 64389893a0..6f8433b9be 100644 --- a/lib/active_scaffold/bridges.rb +++ b/lib/active_scaffold/bridges.rb @@ -1,5 +1,45 @@ module ActiveScaffold module Bridges ActiveScaffold.autoload_subdir('bridges', self) + + mattr_accessor :bridges + mattr_accessor :bridges_run + self.bridges = {} + + def self.register(file) + match = file.match(/(active_scaffold\/bridges\/(.*))\.rb\Z/) + self.bridges[match[2].to_sym] = match[1] if match + end + + def self.load(bridge_name) + bridge = self.bridges[bridge_name.to_sym] + if bridge.is_a? String + if ActiveScaffold.exclude_bridges.exclude? bridge_name.to_sym + bridge = bridge.camelize.constantize + self.bridges[bridge_name.to_sym] = bridge + else + self.bridges.delete bridge_name + bridge = nil + end + end + bridge + end + class << self + alias_method :[], :load + end + + def self.run_all + return false if self.bridges_run + self.bridges.keys.each{|bridge_name| + bridge = self[bridge_name] + bridge.run if bridge + } + self.bridges_run = true + end end end + +require File.join(File.dirname(__FILE__), 'bridges/shared/date_bridge.rb') +(Dir[File.join(File.dirname(__FILE__), "bridges/*.rb")] - [__FILE__]).each{|bridge_require| + ActiveScaffold::Bridges.register bridge_require +} diff --git a/lib/active_scaffold/bridges/ancestry.rb b/lib/active_scaffold/bridges/ancestry.rb new file mode 100644 index 0000000000..965195f576 --- /dev/null +++ b/lib/active_scaffold/bridges/ancestry.rb @@ -0,0 +1,5 @@ +class ActiveScaffold::Bridges::Ancestry < ActiveScaffold::DataStructures::Bridge + def self.install + require File.join(File.dirname(__FILE__), "ancestry/ancestry_bridge.rb") + end +end diff --git a/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb b/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb similarity index 100% rename from lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb rename to lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb diff --git a/lib/active_scaffold/bridges/ancestry/bridge.rb b/lib/active_scaffold/bridges/ancestry/bridge.rb deleted file mode 100644 index 364d974d27..0000000000 --- a/lib/active_scaffold/bridges/ancestry/bridge.rb +++ /dev/null @@ -1,5 +0,0 @@ -ActiveScaffold::Bridges.bridge "Ancestry" do - install do - require File.join(File.dirname(__FILE__), "lib/ancestry_bridge.rb") - end -end diff --git a/lib/active_scaffold/bridges/calendar_date_select/bridge.rb b/lib/active_scaffold/bridges/calendar_date_select.rb similarity index 74% rename from lib/active_scaffold/bridges/calendar_date_select/bridge.rb rename to lib/active_scaffold/bridges/calendar_date_select.rb index de4946ae61..719cf6d4b2 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select.rb @@ -1,5 +1,5 @@ -ActiveScaffold::Bridges.bridge "CalendarDateSelect" do - install do +class ActiveScaffold::Bridges::CalendarDateSelect < ActiveScaffold::DataStructures::Bridge + def self.install # check to see if the old bridge was installed. If so, warn them # we can detect this by checking to see if the bridge was installed before calling this code @@ -7,10 +7,10 @@ raise RuntimeError, "We've detected that you have active_scaffold_calendar_date_select_bridge installed. This plugin has been moved to core. Please remove active_scaffold_calendar_date_select_bridge to prevent any conflicts" end - require File.join(File.dirname(__FILE__), "lib/as_cds_bridge.rb") + require File.join(File.dirname(__FILE__), "calendar_date_select/as_cds_bridge.rb") end - install? do + def self.install? Object.const_defined?(name) && ActiveScaffold.js_framework == :prototype end end diff --git a/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb similarity index 100% rename from lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb rename to lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb diff --git a/lib/active_scaffold/bridges/cancan/bridge.rb b/lib/active_scaffold/bridges/cancan.rb similarity index 70% rename from lib/active_scaffold/bridges/cancan/bridge.rb rename to lib/active_scaffold/bridges/cancan.rb index bbae68a467..1ea56132c4 100644 --- a/lib/active_scaffold/bridges/cancan/bridge.rb +++ b/lib/active_scaffold/bridges/cancan.rb @@ -1,6 +1,6 @@ -ActiveScaffold::Bridges.bridge "CanCan" do - install do - require File.join(File.dirname(__FILE__), "lib", "cancan_bridge.rb") +class ActiveScaffold::Bridges::Cancan < ActiveScaffold::DataStructures::Bridge + def self.install + require File.join(File.dirname(__FILE__), "cancan", "cancan_bridge.rb") ActiveScaffold::ClassMethods.send :include, ActiveScaffold::CancanBridge::ClassMethods ActiveScaffold::Actions::Core.send :include, ActiveScaffold::CancanBridge::Actions::Core @@ -9,4 +9,7 @@ ActiveRecord::Base.send :include, ActiveScaffold::CancanBridge::ModelUserAccess::Model ActiveRecord::Base.send :include, ActiveScaffold::CancanBridge::ActiveRecord end + def self.install? + Object.const_defined? 'CanCan' + end end diff --git a/lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb b/lib/active_scaffold/bridges/cancan/cancan_bridge.rb similarity index 100% rename from lib/active_scaffold/bridges/cancan/lib/cancan_bridge.rb rename to lib/active_scaffold/bridges/cancan/cancan_bridge.rb diff --git a/lib/active_scaffold/bridges/carrierwave.rb b/lib/active_scaffold/bridges/carrierwave.rb new file mode 100644 index 0000000000..f6c6c4117e --- /dev/null +++ b/lib/active_scaffold/bridges/carrierwave.rb @@ -0,0 +1,12 @@ +class ActiveScaffold::Bridges::Carrierwave < ActiveScaffold::DataStructures::Bridge + def self.install + require File.join(File.dirname(__FILE__), "carrierwave/form_ui") + require File.join(File.dirname(__FILE__), "carrierwave/list_ui") + require File.join(File.dirname(__FILE__), "carrierwave/carrierwave_bridge_helpers") + require File.join(File.dirname(__FILE__), "carrierwave/carrierwave_bridge") + ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Carrierwave::CarrierwaveBridge + end + def self.install? + Object.const_defined? 'CarrierWave' + end +end diff --git a/lib/active_scaffold/bridges/carrierwave/bridge.rb b/lib/active_scaffold/bridges/carrierwave/bridge.rb deleted file mode 100644 index f746350b4d..0000000000 --- a/lib/active_scaffold/bridges/carrierwave/bridge.rb +++ /dev/null @@ -1,9 +0,0 @@ -ActiveScaffold::Bridges.bridge "CarrierWave" do - install do - require File.join(File.dirname(__FILE__), "lib/form_ui") - require File.join(File.dirname(__FILE__), "lib/list_ui") - require File.join(File.dirname(__FILE__), "lib/carrierwave_bridge_helpers") - require File.join(File.dirname(__FILE__), "lib/carrierwave_bridge") - ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Carrierwave::Lib::CarrierwaveBridge - end -end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb b/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb new file mode 100644 index 0000000000..8fe7f8d322 --- /dev/null +++ b/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb @@ -0,0 +1,31 @@ +module ActiveScaffold + module Bridges + module Carrierwave + module CarrierwaveBridge + def initialize_with_carrierwave(model_id) + initialize_without_carrierwave(model_id) + return unless self.model.respond_to?(:uploaders) && self.model.uploaders.present? + + self.update.multipart = true + self.create.multipart = true + + self.model.uploaders.keys.each do |field| + configure_carrierwave_field(field.to_sym) + end + end + + def self.included(base) + base.alias_method_chain :initialize, :carrierwave + end + + private + def configure_carrierwave_field(field) + self.columns << field + self.columns[field].form_ui ||= :carrierwave # :TODO thumbnail + self.columns[field].params.add "#{field}_cache" + self.columns[field].params.add "remove_#{field}" + end + end + end + end +end diff --git a/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb b/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb new file mode 100644 index 0000000000..a56c38ffc8 --- /dev/null +++ b/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb @@ -0,0 +1,10 @@ +module ActiveScaffold + module Bridges + module Carrierwave + module CarrierwaveBridgeHelpers + mattr_accessor :thumbnail_style + self.thumbnail_style = :thumbnail + end + end + end +end diff --git a/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb b/lib/active_scaffold/bridges/carrierwave/form_ui.rb similarity index 100% rename from lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb rename to lib/active_scaffold/bridges/carrierwave/form_ui.rb diff --git a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb deleted file mode 100644 index 4827aac634..0000000000 --- a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +++ /dev/null @@ -1,33 +0,0 @@ -module ActiveScaffold - module Bridges - module Carrierwave - module Lib - module CarrierwaveBridge - def initialize_with_carrierwave(model_id) - initialize_without_carrierwave(model_id) - return unless self.model.respond_to?(:uploaders) && self.model.uploaders.present? - - self.update.multipart = true - self.create.multipart = true - - self.model.uploaders.keys.each do |field| - configure_carrierwave_field(field.to_sym) - end - end - - def self.included(base) - base.alias_method_chain :initialize, :carrierwave - end - - private - def configure_carrierwave_field(field) - self.columns << field - self.columns[field].form_ui ||= :carrierwave # :TODO thumbnail - self.columns[field].params.add "#{field}_cache" - self.columns[field].params.add "remove_#{field}" - end - end - end - end - end -end diff --git a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb b/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb deleted file mode 100644 index b453386271..0000000000 --- a/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +++ /dev/null @@ -1,12 +0,0 @@ -module ActiveScaffold - module Bridges - module Carrierwave - module Lib - module CarrierwaveBridgeHelpers - mattr_accessor :thumbnail_style - self.thumbnail_style = :thumbnail - end - end - end - end -end diff --git a/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb b/lib/active_scaffold/bridges/carrierwave/list_ui.rb similarity index 93% rename from lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb rename to lib/active_scaffold/bridges/carrierwave/list_ui.rb index 37f2cb2072..f9079710cd 100644 --- a/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +++ b/lib/active_scaffold/bridges/carrierwave/list_ui.rb @@ -4,7 +4,7 @@ module ListColumnHelpers def active_scaffold_column_carrierwave(column, record) carrierwave = record.send("#{column.name}") return nil unless !carrierwave.file.blank? - thumbnail_style = ActiveScaffold::Bridges::Carrierwave::Lib::CarrierwaveBridgeHelpers.thumbnail_style + thumbnail_style = ActiveScaffold::Bridges::Carrierwave::CarrierwaveBridgeHelpers.thumbnail_style content = if carrierwave.versions.keys.include?(thumbnail_style) image_tag(carrierwave.url(thumbnail_style), :border => 0).html_safe else diff --git a/lib/active_scaffold/bridges/country_helper.rb b/lib/active_scaffold/bridges/country_helper.rb new file mode 100644 index 0000000000..0263910cc3 --- /dev/null +++ b/lib/active_scaffold/bridges/country_helper.rb @@ -0,0 +1,9 @@ +class ActiveScaffold::Bridges::CountryHelper < ActiveScaffold::DataStructures::Bridge + def self.install + require File.join(File.dirname(__FILE__), "country_helper/country_helper_bridge.rb") + end + + def self.install? + true + end +end diff --git a/lib/active_scaffold/bridges/country_helper/bridge.rb b/lib/active_scaffold/bridges/country_helper/bridge.rb deleted file mode 100644 index 644e8f897a..0000000000 --- a/lib/active_scaffold/bridges/country_helper/bridge.rb +++ /dev/null @@ -1,9 +0,0 @@ -ActiveScaffold::Bridges.bridge "CountryHelper" do - install do - require File.join(File.dirname(__FILE__), "lib/country_helper_bridge.rb") - end - - install? do - true - end -end diff --git a/lib/active_scaffold/bridges/country_helper/lib/country_helper_bridge.rb b/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb similarity index 100% rename from lib/active_scaffold/bridges/country_helper/lib/country_helper_bridge.rb rename to lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb diff --git a/lib/active_scaffold/bridges/date_picker.rb b/lib/active_scaffold/bridges/date_picker.rb index 39697a7995..5b1c26f564 100644 --- a/lib/active_scaffold/bridges/date_picker.rb +++ b/lib/active_scaffold/bridges/date_picker.rb @@ -1,5 +1,5 @@ module ActiveScaffold::Bridges - class DatePicker < ActiveScaffold::Bridge + class DatePicker < ActiveScaffold::DataStructures::Bridge autoload :Helper, 'active_scaffold/bridges/date_picker/helper' def self.install require File.join(File.dirname(__FILE__), "ext.rb") diff --git a/lib/active_scaffold/bridges/dragonfly.rb b/lib/active_scaffold/bridges/dragonfly.rb new file mode 100644 index 0000000000..2ae7ef410a --- /dev/null +++ b/lib/active_scaffold/bridges/dragonfly.rb @@ -0,0 +1,9 @@ +class ActiveScaffold::Bridges::Dragonfly < ActiveScaffold::DataStructures::Bridge + def self.install + require File.join(File.dirname(__FILE__), "dragonfly/form_ui") + require File.join(File.dirname(__FILE__), "dragonfly/list_ui") + require File.join(File.dirname(__FILE__), "dragonfly/dragonfly_bridge_helpers") + require File.join(File.dirname(__FILE__), "dragonfly/dragonfly_bridge") + ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Dragonfly::DragonflyBridge + end +end diff --git a/lib/active_scaffold/bridges/dragonfly/bridge.rb b/lib/active_scaffold/bridges/dragonfly/bridge.rb deleted file mode 100644 index 0a22b9167c..0000000000 --- a/lib/active_scaffold/bridges/dragonfly/bridge.rb +++ /dev/null @@ -1,9 +0,0 @@ -ActiveScaffold::Bridges.bridge "Dragonfly" do - install do - require File.join(File.dirname(__FILE__), "lib/form_ui") - require File.join(File.dirname(__FILE__), "lib/list_ui") - require File.join(File.dirname(__FILE__), "lib/dragonfly_bridge_helpers") - require File.join(File.dirname(__FILE__), "lib/dragonfly_bridge") - ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Dragonfly::Lib::DragonflyBridge - end -end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb b/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb new file mode 100644 index 0000000000..67bd39b64a --- /dev/null +++ b/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb @@ -0,0 +1,34 @@ +module ActiveScaffold + module Bridges + module Dragonfly + module DragonflyBridge + def initialize_with_dragonfly(model_id) + initialize_without_dragonfly(model_id) + return unless self.model.respond_to?(:dragonfly_attachment_classes) && self.model.dragonfly_attachment_classes.present? + + self.update.multipart = true + self.create.multipart = true + + self.model.dragonfly_attachment_classes.each do |attachment| + configure_dragonfly_field(attachment.attribute) + end + end + + def self.included(base) + base.alias_method_chain :initialize, :dragonfly + end + + private + def configure_dragonfly_field(field) + self.columns << field + self.columns[field].form_ui ||= :dragonfly + self.columns[field].params.add "remove_#{field}" + + [:name, :uid].each do |f| + self.columns.exclude("#{field}_#{f}".to_sym) + end + end + end + end + end +end diff --git a/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb b/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb new file mode 100644 index 0000000000..f01bc5ad29 --- /dev/null +++ b/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb @@ -0,0 +1,10 @@ +module ActiveScaffold + module Bridges + module Dragonfly + module DragonflyBridgeHelpers + mattr_accessor :thumbnail_style + self.thumbnail_style = 'x30>' + end + end + end +end diff --git a/lib/active_scaffold/bridges/dragonfly/lib/form_ui.rb b/lib/active_scaffold/bridges/dragonfly/form_ui.rb similarity index 100% rename from lib/active_scaffold/bridges/dragonfly/lib/form_ui.rb rename to lib/active_scaffold/bridges/dragonfly/form_ui.rb diff --git a/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb b/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb deleted file mode 100644 index e85502b451..0000000000 --- a/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge.rb +++ /dev/null @@ -1,36 +0,0 @@ -module ActiveScaffold - module Bridges - module Dragonfly - module Lib - module DragonflyBridge - def initialize_with_dragonfly(model_id) - initialize_without_dragonfly(model_id) - return unless self.model.respond_to?(:dragonfly_attachment_classes) && self.model.dragonfly_attachment_classes.present? - - self.update.multipart = true - self.create.multipart = true - - self.model.dragonfly_attachment_classes.each do |attachment| - configure_dragonfly_field(attachment.attribute) - end - end - - def self.included(base) - base.alias_method_chain :initialize, :dragonfly - end - - private - def configure_dragonfly_field(field) - self.columns << field - self.columns[field].form_ui ||= :dragonfly - self.columns[field].params.add "remove_#{field}" - - [:name, :uid].each do |f| - self.columns.exclude("#{field}_#{f}".to_sym) - end - end - end - end - end - end -end diff --git a/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb b/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb deleted file mode 100644 index c7446d2fea..0000000000 --- a/lib/active_scaffold/bridges/dragonfly/lib/dragonfly_bridge_helpers.rb +++ /dev/null @@ -1,12 +0,0 @@ -module ActiveScaffold - module Bridges - module Dragonfly - module Lib - module DragonflyBridgeHelpers - mattr_accessor :thumbnail_style - self.thumbnail_style = 'x30>' - end - end - end - end -end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/dragonfly/lib/list_ui.rb b/lib/active_scaffold/bridges/dragonfly/list_ui.rb similarity index 82% rename from lib/active_scaffold/bridges/dragonfly/lib/list_ui.rb rename to lib/active_scaffold/bridges/dragonfly/list_ui.rb index fdfbb068ee..d8e49b30f8 100644 --- a/lib/active_scaffold/bridges/dragonfly/lib/list_ui.rb +++ b/lib/active_scaffold/bridges/dragonfly/list_ui.rb @@ -5,7 +5,7 @@ def active_scaffold_column_dragonfly(column, record) attachment = record.send("#{column.name}") return nil unless attachment.present? content = if attachment.image? - image_tag(attachment.thumb(column.options[:thumb] || ActiveScaffold::Bridges::Dragonfly::Lib::DragonflyBridgeHelpers.thumbnail_style).url, :border => 0) + image_tag(attachment.thumb(column.options[:thumb] || ActiveScaffold::Bridges::Dragonfly::DragonflyBridgeHelpers.thumbnail_style).url, :border => 0) else attachment.name end @@ -13,4 +13,4 @@ def active_scaffold_column_dragonfly(column, record) end end end -end \ No newline at end of file +end diff --git a/lib/active_scaffold/bridges/file_column.rb b/lib/active_scaffold/bridges/file_column.rb new file mode 100644 index 0000000000..25b92fdddc --- /dev/null +++ b/lib/active_scaffold/bridges/file_column.rb @@ -0,0 +1,11 @@ +class ActiveScaffold::Bridges::FileColumn < ActiveScaffold::DataStructures::Bridge + def self.install + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_file_column") + raise RuntimeError, "We've detected that you have active_scaffold_file_column_bridge installed. This plugin has been moved to core. Please remove active_scaffold_file_column_bridge to prevent any conflicts" + end + require File.join(File.dirname(__FILE__), "file_column/as_file_column_bridge") + require File.join(File.dirname(__FILE__), "file_column/form_ui") + require File.join(File.dirname(__FILE__), "file_column/list_ui") + require File.join(File.dirname(__FILE__), "file_column/file_column_helpers") + end +end diff --git a/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb b/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb similarity index 88% rename from lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb rename to lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb index 472b32c371..9fec882bc5 100644 --- a/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +++ b/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb @@ -8,9 +8,9 @@ class Core < Base def initialize_with_file_column(model_id) initialize_without_file_column(model_id) - return unless ActiveScaffold::Bridges::Paperclip::Lib::FileColumnHelpers.klass_has_file_column_fields?(self.model) + return unless ActiveScaffold::Bridges::FileColumn::FileColumnHelpers.klass_has_file_column_fields?(self.model) - self.model.send :extend, ActiveScaffold::Bridges::Paperclip::Lib::FileColumnHelpers + self.model.send :extend, ActiveScaffold::Bridges::FileColumn::FileColumnHelpers # include the "delete" helpers for use with active scaffold, unless they are already included self.model.generate_delete_helpers diff --git a/lib/active_scaffold/bridges/file_column/bridge.rb b/lib/active_scaffold/bridges/file_column/bridge.rb deleted file mode 100644 index ab517a4a9e..0000000000 --- a/lib/active_scaffold/bridges/file_column/bridge.rb +++ /dev/null @@ -1,11 +0,0 @@ -ActiveScaffold::Bridges.bridge "FileColumn" do - install do - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_file_column") - raise RuntimeError, "We've detected that you have active_scaffold_file_column_bridge installed. This plugin has been moved to core. Please remove active_scaffold_file_column_bridge to prevent any conflicts" - end - require File.join(File.dirname(__FILE__), "lib/as_file_column_bridge") - require File.join(File.dirname(__FILE__), "lib/form_ui") - require File.join(File.dirname(__FILE__), "lib/list_ui") - require File.join(File.dirname(__FILE__), "lib/file_column_helpers") - end -end diff --git a/lib/active_scaffold/bridges/file_column/file_column_helpers.rb b/lib/active_scaffold/bridges/file_column/file_column_helpers.rb new file mode 100644 index 0000000000..3ede053c67 --- /dev/null +++ b/lib/active_scaffold/bridges/file_column/file_column_helpers.rb @@ -0,0 +1,57 @@ +module ActiveScaffold + module Bridges + module FileColumn + module FileColumnHelpers + class << self + def file_column_fields(klass) + klass.instance_methods.grep(/_just_uploaded\?$/).collect{|m| m[0..-16].to_sym } + end + + def generate_delete_helpers(klass) + file_column_fields(klass).each { |field| + klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("#{field}_with_delete=") + attr_reader :delete_#{field} + + def delete_#{field}=(value) + value = (value=="true") if String===value + return unless value + + # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! + self.#{field} = nil unless self.#{field}_just_uploaded? + end + EOF + } + end + + def klass_has_file_column_fields?(klass) + true unless file_column_fields(klass).empty? + end + end + + def file_column_fields + @file_column_fields||=FileColumnHelpers.file_column_fields(self) + end + + def options_for_file_column_field(field) + self.allocate.send("#{field}_options") + end + + def field_has_image_version?(field, version="thumb") + begin + # the only way to get to the options of a particular field is to use the instance method + options = options_for_file_column_field(field) + versions = options[:magick][:versions] + raise unless versions.stringify_keys[version] + true + rescue + false + end + end + + def generate_delete_helpers + FileColumnHelpers.generate_delete_helpers(self) + end + end + end + end +end diff --git a/lib/active_scaffold/bridges/file_column/lib/form_ui.rb b/lib/active_scaffold/bridges/file_column/form_ui.rb similarity index 100% rename from lib/active_scaffold/bridges/file_column/lib/form_ui.rb rename to lib/active_scaffold/bridges/file_column/form_ui.rb diff --git a/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb b/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb deleted file mode 100644 index 9aa607417a..0000000000 --- a/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +++ /dev/null @@ -1,59 +0,0 @@ -module ActiveScaffold - module Bridges - module Paperclip - module Lib - module FileColumnHelpers - class << self - def file_column_fields(klass) - klass.instance_methods.grep(/_just_uploaded\?$/).collect{|m| m[0..-16].to_sym } - end - - def generate_delete_helpers(klass) - file_column_fields(klass).each { |field| - klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("#{field}_with_delete=") - attr_reader :delete_#{field} - - def delete_#{field}=(value) - value = (value=="true") if String===value - return unless value - - # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! - self.#{field} = nil unless self.#{field}_just_uploaded? - end - EOF - } - end - - def klass_has_file_column_fields?(klass) - true unless file_column_fields(klass).empty? - end - end - - def file_column_fields - @file_column_fields||=FileColumnHelpers.file_column_fields(self) - end - - def options_for_file_column_field(field) - self.allocate.send("#{field}_options") - end - - def field_has_image_version?(field, version="thumb") - begin - # the only way to get to the options of a particular field is to use the instance method - options = options_for_file_column_field(field) - versions = options[:magick][:versions] - raise unless versions.stringify_keys[version] - true - rescue - false - end - end - - def generate_delete_helpers - FileColumnHelpers.generate_delete_helpers(self) - end - end - end - end - end -end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/file_column/lib/list_ui.rb b/lib/active_scaffold/bridges/file_column/list_ui.rb similarity index 100% rename from lib/active_scaffold/bridges/file_column/lib/list_ui.rb rename to lib/active_scaffold/bridges/file_column/list_ui.rb diff --git a/lib/active_scaffold/bridges/paperclip.rb b/lib/active_scaffold/bridges/paperclip.rb new file mode 100644 index 0000000000..de8a61aed1 --- /dev/null +++ b/lib/active_scaffold/bridges/paperclip.rb @@ -0,0 +1,12 @@ +class ActiveScaffold::Bridges::Paperclip < ActiveScaffold::DataStructures::Bridge + def self.install + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip") + raise RuntimeError, "We've detected that you have active_scaffold_paperclip_bridge installed. This plugin has been moved to core. Please remove active_scaffold_paperclip_bridge to prevent any conflicts" + end + require File.join(File.dirname(__FILE__), "paperclip/form_ui") + require File.join(File.dirname(__FILE__), "paperclip/list_ui") + require File.join(File.dirname(__FILE__), "paperclip/paperclip_bridge_helpers") + require File.join(File.dirname(__FILE__), "paperclip/paperclip_bridge") + ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Paperclip::PaperclipBridge + end +end diff --git a/lib/active_scaffold/bridges/paperclip/bridge.rb b/lib/active_scaffold/bridges/paperclip/bridge.rb deleted file mode 100644 index c27af18a40..0000000000 --- a/lib/active_scaffold/bridges/paperclip/bridge.rb +++ /dev/null @@ -1,12 +0,0 @@ -ActiveScaffold::Bridges.bridge "Paperclip" do - install do - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip") - raise RuntimeError, "We've detected that you have active_scaffold_paperclip_bridge installed. This plugin has been moved to core. Please remove active_scaffold_paperclip_bridge to prevent any conflicts" - end - require File.join(File.dirname(__FILE__), "lib/form_ui") - require File.join(File.dirname(__FILE__), "lib/list_ui") - require File.join(File.dirname(__FILE__), "lib/paperclip_bridge_helpers") - require File.join(File.dirname(__FILE__), "lib/paperclip_bridge") - ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Paperclip::Lib::PaperclipBridge - end -end \ No newline at end of file diff --git a/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb b/lib/active_scaffold/bridges/paperclip/form_ui.rb similarity index 100% rename from lib/active_scaffold/bridges/paperclip/lib/form_ui.rb rename to lib/active_scaffold/bridges/paperclip/form_ui.rb diff --git a/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb b/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb deleted file mode 100644 index daf98a33f7..0000000000 --- a/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +++ /dev/null @@ -1,38 +0,0 @@ -module ActiveScaffold - module Bridges - module Paperclip - module Lib - module PaperclipBridge - def initialize_with_paperclip(model_id) - initialize_without_paperclip(model_id) - return unless self.model.respond_to?(:attachment_definitions) && !self.model.attachment_definitions.nil? - - self.update.multipart = true - self.create.multipart = true - - self.model.attachment_definitions.keys.each do |field| - configure_paperclip_field(field.to_sym) - # define the "delete" helper for use with active scaffold, unless it's already defined - ActiveScaffold::Bridges::Paperclip::Lib::PaperclipBridgeHelpers.generate_delete_helper(self.model, field) - end - end - - def self.included(base) - base.alias_method_chain :initialize, :paperclip - end - - private - def configure_paperclip_field(field) - self.columns << field - self.columns[field].form_ui ||= :paperclip - self.columns[field].params.add "delete_#{field}" - - [:file_name, :content_type, :file_size, :updated_at].each do |f| - self.columns.exclude("#{field}_#{f}".to_sym) - end - end - end - end - end - end -end diff --git a/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb b/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb deleted file mode 100644 index 30124a23de..0000000000 --- a/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +++ /dev/null @@ -1,26 +0,0 @@ -module ActiveScaffold - module Bridges - module Paperclip - module Lib - module PaperclipBridgeHelpers - mattr_accessor :thumbnail_style - self.thumbnail_style = :thumbnail - - def self.generate_delete_helper(klass, field) - klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.instance_methods.include?("delete_#{field}=") - attr_reader :delete_#{field} - - def delete_#{field}=(value) - value = (value == "true") if String === value - return unless value - - # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! - self.#{field} = nil unless self.#{field}.dirty? - end - EOF - end - end - end - end - end -end diff --git a/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb b/lib/active_scaffold/bridges/paperclip/list_ui.rb similarity index 79% rename from lib/active_scaffold/bridges/paperclip/lib/list_ui.rb rename to lib/active_scaffold/bridges/paperclip/list_ui.rb index 0d77026c88..bce065610b 100644 --- a/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +++ b/lib/active_scaffold/bridges/paperclip/list_ui.rb @@ -4,8 +4,8 @@ module ListColumnHelpers def active_scaffold_column_paperclip(column, record) paperclip = record.send("#{column.name}") return nil unless paperclip.file? - content = if paperclip.styles.include?(ActiveScaffold::Bridges::Paperclip::Lib::PaperclipBridgeHelpers.thumbnail_style) - image_tag(paperclip.url(ActiveScaffold::Bridges::Paperclip::Lib::PaperclipBridgeHelpers.thumbnail_style), :border => 0) + content = if paperclip.styles.include?(ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.thumbnail_style) + image_tag(paperclip.url(ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.thumbnail_style), :border => 0) else paperclip.original_filename end @@ -13,4 +13,4 @@ def active_scaffold_column_paperclip(column, record) end end end -end \ No newline at end of file +end diff --git a/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb b/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb new file mode 100644 index 0000000000..951e266308 --- /dev/null +++ b/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb @@ -0,0 +1,36 @@ +module ActiveScaffold + module Bridges + module Paperclip + module PaperclipBridge + def initialize_with_paperclip(model_id) + initialize_without_paperclip(model_id) + return unless self.model.respond_to?(:attachment_definitions) && !self.model.attachment_definitions.nil? + + self.update.multipart = true + self.create.multipart = true + + self.model.attachment_definitions.keys.each do |field| + configure_paperclip_field(field.to_sym) + # define the "delete" helper for use with active scaffold, unless it's already defined + ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.generate_delete_helper(self.model, field) + end + end + + def self.included(base) + base.alias_method_chain :initialize, :paperclip + end + + private + def configure_paperclip_field(field) + self.columns << field + self.columns[field].form_ui ||= :paperclip + self.columns[field].params.add "delete_#{field}" + + [:file_name, :content_type, :file_size, :updated_at].each do |f| + self.columns.exclude("#{field}_#{f}".to_sym) + end + end + end + end + end +end diff --git a/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb b/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb new file mode 100644 index 0000000000..fc5e9d2a6d --- /dev/null +++ b/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb @@ -0,0 +1,24 @@ +module ActiveScaffold + module Bridges + module Paperclip + module PaperclipBridgeHelpers + mattr_accessor :thumbnail_style + self.thumbnail_style = :thumbnail + + def self.generate_delete_helper(klass, field) + klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.instance_methods.include?("delete_#{field}=") + attr_reader :delete_#{field} + + def delete_#{field}=(value) + value = (value == "true") if String === value + return unless value + + # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! + self.#{field} = nil unless self.#{field}.dirty? + end + EOF + end + end + end + end +end diff --git a/lib/active_scaffold/bridges/record_select.rb b/lib/active_scaffold/bridges/record_select.rb new file mode 100644 index 0000000000..3200e0fdd0 --- /dev/null +++ b/lib/active_scaffold/bridges/record_select.rb @@ -0,0 +1,5 @@ +class ActiveScaffold::Bridges::RecordSelect < ActiveScaffold::DataStructures::Bridge + def self.install + require File.join(File.dirname(__FILE__), "record_select/record_select_bridge.rb") + end +end diff --git a/lib/active_scaffold/bridges/record_select/bridge.rb b/lib/active_scaffold/bridges/record_select/bridge.rb deleted file mode 100644 index 8c2d4d31ba..0000000000 --- a/lib/active_scaffold/bridges/record_select/bridge.rb +++ /dev/null @@ -1,5 +0,0 @@ -ActiveScaffold::Bridges.bridge "RecordSelect" do - install do - require File.join(File.dirname(__FILE__), "lib/record_select_bridge.rb") - end -end diff --git a/lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb b/lib/active_scaffold/bridges/record_select/record_select_bridge.rb similarity index 100% rename from lib/active_scaffold/bridges/record_select/lib/record_select_bridge.rb rename to lib/active_scaffold/bridges/record_select/record_select_bridge.rb diff --git a/lib/active_scaffold/bridges/semantic_attributes.rb b/lib/active_scaffold/bridges/semantic_attributes.rb new file mode 100644 index 0000000000..3b9b5a5371 --- /dev/null +++ b/lib/active_scaffold/bridges/semantic_attributes.rb @@ -0,0 +1,5 @@ +class ActiveScaffold::Bridges::SemanticAttributes < ActiveScaffold::DataStructures::Bridge + def self.install + require File.join(File.dirname(__FILE__), "semantic_attributes/semantic_attributes_bridge.rb") + end +end diff --git a/lib/active_scaffold/bridges/semantic_attributes/bridge.rb b/lib/active_scaffold/bridges/semantic_attributes/bridge.rb deleted file mode 100644 index 7c51235f1b..0000000000 --- a/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +++ /dev/null @@ -1,5 +0,0 @@ -ActiveScaffold::Bridges.bridge "SemanticAttributes" do - install do - require File.join(File.dirname(__FILE__), "lib/semantic_attributes_bridge.rb") - end -end diff --git a/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb b/lib/active_scaffold/bridges/semantic_attributes/semantic_attributes_bridge.rb similarity index 100% rename from lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb rename to lib/active_scaffold/bridges/semantic_attributes/semantic_attributes_bridge.rb diff --git a/lib/active_scaffold/bridges/tiny_mce.rb b/lib/active_scaffold/bridges/tiny_mce.rb new file mode 100644 index 0000000000..ad0a390aab --- /dev/null +++ b/lib/active_scaffold/bridges/tiny_mce.rb @@ -0,0 +1,5 @@ +class ActiveScaffold::Bridges::TinyMCE < ActiveScaffold::DataStructures::Bridge + def self.install + require File.join(File.dirname(__FILE__), "tiny_mce/tiny_mce_bridge.rb") + end +end diff --git a/lib/active_scaffold/bridges/tiny_mce/bridge.rb b/lib/active_scaffold/bridges/tiny_mce/bridge.rb deleted file mode 100644 index dd4abcaa01..0000000000 --- a/lib/active_scaffold/bridges/tiny_mce/bridge.rb +++ /dev/null @@ -1,5 +0,0 @@ -ActiveScaffold::Bridges.bridge "TinyMCE" do - install do - require File.join(File.dirname(__FILE__), "lib/tiny_mce_bridge.rb") - end -end diff --git a/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb b/lib/active_scaffold/bridges/tiny_mce/tiny_mce_bridge.rb similarity index 100% rename from lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb rename to lib/active_scaffold/bridges/tiny_mce/tiny_mce_bridge.rb diff --git a/lib/active_scaffold/bridges/validation_reflection.rb b/lib/active_scaffold/bridges/validation_reflection.rb new file mode 100644 index 0000000000..227d28b3bc --- /dev/null +++ b/lib/active_scaffold/bridges/validation_reflection.rb @@ -0,0 +1,9 @@ +class ActiveScaffold::Bridges::ValidationReflection < ActiveScaffold::DataStructures::Bridge + def self.install + require File.join(File.dirname(__FILE__), "validation_reflection/validation_reflection_bridge.rb") + ActiveScaffold::DataStructures::Column.class_eval { include ActiveScaffold::ValidationReflectionBridge } + end + def self.install? + ActiveRecord::Base.respond_to? :reflect_on_validations_for + end +end diff --git a/lib/active_scaffold/bridges/validation_reflection/bridge.rb b/lib/active_scaffold/bridges/validation_reflection/bridge.rb deleted file mode 100644 index 04089f25fa..0000000000 --- a/lib/active_scaffold/bridges/validation_reflection/bridge.rb +++ /dev/null @@ -1,9 +0,0 @@ -ActiveScaffold::Bridges.bridge "ValidationReflection" do - install do - require File.join(File.dirname(__FILE__), "lib/validation_reflection_bridge.rb") - ActiveScaffold::DataStructures::Column.class_eval { include ActiveScaffold::ValidationReflectionBridge } - end - install? do - ActiveRecord::Base.respond_to? :reflect_on_validations_for - end -end diff --git a/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb b/lib/active_scaffold/bridges/validation_reflection/validation_reflection_bridge.rb similarity index 100% rename from lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb rename to lib/active_scaffold/bridges/validation_reflection/validation_reflection_bridge.rb diff --git a/lib/active_scaffold/data_structures/bridge.rb b/lib/active_scaffold/data_structures/bridge.rb new file mode 100644 index 0000000000..f2a33e3ee0 --- /dev/null +++ b/lib/active_scaffold/data_structures/bridge.rb @@ -0,0 +1,16 @@ +module ActiveScaffold::DataStructures + class Bridge + def self.install + raise(RunTimeError, "install not defined for bridge #{name}") + end + + # by convention and default, use the bridge name as the required constant for installation + def self.install? + Object.const_defined? name.demodulize + end + + def self.run + install if install? + end + end +end From 93b0dad44a187549354afbc65be5518d89d52d1f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Sep 2011 11:26:13 +0200 Subject: [PATCH 1235/2024] update class and modules bridges --- lib/active_scaffold/bridges.rb | 4 +- .../bridges/ancestry/ancestry_bridge.rb | 6 +- .../calendar_date_select/as_cds_bridge.rb | 8 +- lib/active_scaffold/bridges/cancan.rb | 12 +- .../bridges/cancan/cancan_bridge.rb | 4 +- .../bridges/carrierwave/carrierwave_bridge.rb | 2 +- .../carrierwave/carrierwave_bridge_helpers.rb | 2 +- .../country_helper/country_helper_bridge.rb | 10 +- .../bridges/dragonfly/dragonfly_bridge.rb | 2 +- .../dragonfly/dragonfly_bridge_helpers.rb | 2 +- .../file_column/file_column_helpers.rb | 110 +++++++++--------- .../bridges/paperclip/paperclip_bridge.rb | 2 +- .../paperclip/paperclip_bridge_helpers.rb | 2 +- lib/active_scaffold/bridges/record_select.rb | 2 +- .../{record_select_bridge.rb => helpers.rb} | 6 +- .../bridges/semantic_attributes.rb | 2 +- ...emantic_attributes_bridge.rb => column.rb} | 6 +- lib/active_scaffold/bridges/tiny_mce.rb | 4 +- .../{tiny_mce_bridge.rb => helpers.rb} | 6 +- .../bridges/validation_reflection.rb | 9 -- .../validation_reflection_bridge.rb | 19 --- lib/active_scaffold/data_structures/column.rb | 6 +- 22 files changed, 102 insertions(+), 124 deletions(-) rename lib/active_scaffold/bridges/record_select/{record_select_bridge.rb => helpers.rb} (96%) rename lib/active_scaffold/bridges/semantic_attributes/{semantic_attributes_bridge.rb => column.rb} (84%) rename lib/active_scaffold/bridges/tiny_mce/{tiny_mce_bridge.rb => helpers.rb} (94%) delete mode 100644 lib/active_scaffold/bridges/validation_reflection.rb delete mode 100644 lib/active_scaffold/bridges/validation_reflection/validation_reflection_bridge.rb diff --git a/lib/active_scaffold/bridges.rb b/lib/active_scaffold/bridges.rb index 6f8433b9be..ba8e643b76 100644 --- a/lib/active_scaffold/bridges.rb +++ b/lib/active_scaffold/bridges.rb @@ -1,6 +1,9 @@ module ActiveScaffold module Bridges ActiveScaffold.autoload_subdir('bridges', self) + module Shared + autoload :DateBridge, 'active_scaffold/bridges/shared/date_bridge' + end mattr_accessor :bridges mattr_accessor :bridges_run @@ -39,7 +42,6 @@ def self.run_all end end -require File.join(File.dirname(__FILE__), 'bridges/shared/date_bridge.rb') (Dir[File.join(File.dirname(__FILE__), "bridges/*.rb")] - [__FILE__]).each{|bridge_require| ActiveScaffold::Bridges.register bridge_require } diff --git a/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb b/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb index f1bb9c76b5..0b321d365c 100644 --- a/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +++ b/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb @@ -14,8 +14,8 @@ def initialize_with_ancestry(model_id) alias_method_chain :initialize, :ancestry end -module ActiveScaffold - module AncestryBridge +module ActiveScaffold::Bridges + class Ancestry module FormColumnHelpers def active_scaffold_input_ancestry(column, options) select_options = [] @@ -35,5 +35,5 @@ def active_scaffold_input_ancestry(column, options) end ActionView::Base.class_eval do - include ActiveScaffold::AncestryBridge::FormColumnHelpers + include ActiveScaffold::Bridges::Ancestry::FormColumnHelpers end diff --git a/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb index e91c062088..0065aa7591 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb @@ -22,7 +22,7 @@ def initialize_with_calendar_date_select(model_id) module ActiveScaffold module Bridges - module CalendarDateSelectBridge + class CalendarDateSelect # Helpers that assist with the rendering of a Form Column module FormColumnHelpers def active_scaffold_input_calendar_date_select(column, options) @@ -68,13 +68,13 @@ def active_scaffold_javascripts_with_calendar_date_select(frontend = :default) end ActionView::Base.class_eval do - include ActiveScaffold::Bridges::CalendarDateSelectBridge::FormColumnHelpers + include ActiveScaffold::Bridges::CalendarDateSelect::FormColumnHelpers include ActiveScaffold::Bridges::Shared::DateBridge::SearchColumnHelpers alias_method :active_scaffold_search_calendar_date_select, :active_scaffold_search_date_bridge include ActiveScaffold::Bridges::Shared::DateBridge::HumanConditionHelpers alias_method :active_scaffold_human_condition_calendar_date_select, :active_scaffold_human_condition_date_bridge - include ActiveScaffold::Bridges::CalendarDateSelectBridge::SearchColumnHelpers - include ActiveScaffold::Bridges::CalendarDateSelectBridge::ViewHelpers + include ActiveScaffold::Bridges::CalendarDateSelect::SearchColumnHelpers + include ActiveScaffold::Bridges::CalendarDateSelect::ViewHelpers end ActiveScaffold::Finder::ClassMethods.module_eval do diff --git a/lib/active_scaffold/bridges/cancan.rb b/lib/active_scaffold/bridges/cancan.rb index 1ea56132c4..761820eb80 100644 --- a/lib/active_scaffold/bridges/cancan.rb +++ b/lib/active_scaffold/bridges/cancan.rb @@ -2,12 +2,12 @@ class ActiveScaffold::Bridges::Cancan < ActiveScaffold::DataStructures::Bridge def self.install require File.join(File.dirname(__FILE__), "cancan", "cancan_bridge.rb") - ActiveScaffold::ClassMethods.send :include, ActiveScaffold::CancanBridge::ClassMethods - ActiveScaffold::Actions::Core.send :include, ActiveScaffold::CancanBridge::Actions::Core - ActiveScaffold::Actions::Nested.send :include, ActiveScaffold::CancanBridge::Actions::Core - ActionController::Base.send :include, ActiveScaffold::CancanBridge::ModelUserAccess::Controller - ActiveRecord::Base.send :include, ActiveScaffold::CancanBridge::ModelUserAccess::Model - ActiveRecord::Base.send :include, ActiveScaffold::CancanBridge::ActiveRecord + ActiveScaffold::ClassMethods.send :include, ActiveScaffold::Bridges::Cancan::ClassMethods + ActiveScaffold::Actions::Core.send :include, ActiveScaffold::Bridges::Cancan::Actions::Core + ActiveScaffold::Actions::Nested.send :include, ActiveScaffold::Bridges::Cancan::Actions::Core + ActionController::Base.send :include, ActiveScaffold::Bridges::Cancan::ModelUserAccess::Controller + ActiveRecord::Base.send :include, ActiveScaffold::Bridges::Cancan::ModelUserAccess::Model + ActiveRecord::Base.send :include, ActiveScaffold::Bridges::Cancan::ActiveRecord end def self.install? Object.const_defined? 'CanCan' diff --git a/lib/active_scaffold/bridges/cancan/cancan_bridge.rb b/lib/active_scaffold/bridges/cancan/cancan_bridge.rb index 1d14717840..ed94e88234 100644 --- a/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +++ b/lib/active_scaffold/bridges/cancan/cancan_bridge.rb @@ -1,5 +1,5 @@ -module ActiveScaffold - module CancanBridge +module ActiveScaffold::Bridges + class Cancan # controller level authorization # As already has callbacks to ensure authorization at controller method via "authorization_method" diff --git a/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb b/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb index 8fe7f8d322..f426f173ca 100644 --- a/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +++ b/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb @@ -1,6 +1,6 @@ module ActiveScaffold module Bridges - module Carrierwave + class Carrierwave module CarrierwaveBridge def initialize_with_carrierwave(model_id) initialize_without_carrierwave(model_id) diff --git a/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb b/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb index a56c38ffc8..02a4d9e55f 100644 --- a/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb +++ b/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb @@ -1,6 +1,6 @@ module ActiveScaffold module Bridges - module Carrierwave + class Carrierwave module CarrierwaveBridgeHelpers mattr_accessor :thumbnail_style self.thumbnail_style = :thumbnail diff --git a/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb b/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb index 1e452127fd..2c9c38e442 100644 --- a/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +++ b/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb @@ -1,5 +1,5 @@ -module ActiveScaffold - module CountryHelperBridge +module ActiveScaffold::Bridges + class CountryHelper module CountryHelpers # Return select and option tags for the given object and method, using country_options_for_select to generate the list of option tags. def country_select(object, method, priority_countries = nil, options = {}, html_options = {}) @@ -352,7 +352,7 @@ def active_scaffold_search_usa_state(column, options) end ActionView::Base.class_eval do - include ActiveScaffold::CountryHelperBridge::CountryHelpers - include ActiveScaffold::CountryHelperBridge::FormColumnHelpers - include ActiveScaffold::CountryHelperBridge::SearchColumnHelpers + include ActiveScaffold::Bridges::CountryHelper::CountryHelpers + include ActiveScaffold::Bridges::CountryHelper::FormColumnHelpers + include ActiveScaffold::Bridges::CountryHelper::SearchColumnHelpers end diff --git a/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb b/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb index 67bd39b64a..523cdb79a8 100644 --- a/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +++ b/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb @@ -1,6 +1,6 @@ module ActiveScaffold module Bridges - module Dragonfly + class Dragonfly module DragonflyBridge def initialize_with_dragonfly(model_id) initialize_without_dragonfly(model_id) diff --git a/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb b/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb index f01bc5ad29..504c57b361 100644 --- a/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb +++ b/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb @@ -1,6 +1,6 @@ module ActiveScaffold module Bridges - module Dragonfly + class Dragonfly module DragonflyBridgeHelpers mattr_accessor :thumbnail_style self.thumbnail_style = 'x30>' diff --git a/lib/active_scaffold/bridges/file_column/file_column_helpers.rb b/lib/active_scaffold/bridges/file_column/file_column_helpers.rb index 3ede053c67..5a235f544b 100644 --- a/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +++ b/lib/active_scaffold/bridges/file_column/file_column_helpers.rb @@ -1,57 +1,57 @@ module ActiveScaffold - module Bridges - module FileColumn - module FileColumnHelpers - class << self - def file_column_fields(klass) - klass.instance_methods.grep(/_just_uploaded\?$/).collect{|m| m[0..-16].to_sym } - end - - def generate_delete_helpers(klass) - file_column_fields(klass).each { |field| - klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("#{field}_with_delete=") - attr_reader :delete_#{field} - - def delete_#{field}=(value) - value = (value=="true") if String===value - return unless value - - # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! - self.#{field} = nil unless self.#{field}_just_uploaded? - end - EOF - } - end - - def klass_has_file_column_fields?(klass) - true unless file_column_fields(klass).empty? - end - end - - def file_column_fields - @file_column_fields||=FileColumnHelpers.file_column_fields(self) - end - - def options_for_file_column_field(field) - self.allocate.send("#{field}_options") - end - - def field_has_image_version?(field, version="thumb") - begin - # the only way to get to the options of a particular field is to use the instance method - options = options_for_file_column_field(field) - versions = options[:magick][:versions] - raise unless versions.stringify_keys[version] - true - rescue - false - end - end - - def generate_delete_helpers - FileColumnHelpers.generate_delete_helpers(self) - end - end - end - end + module Bridges + class FileColumn + module FileColumnHelpers + class << self + def file_column_fields(klass) + klass.instance_methods.grep(/_just_uploaded\?$/).collect{|m| m[0..-16].to_sym } + end + + def generate_delete_helpers(klass) + file_column_fields(klass).each { |field| + klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("#{field}_with_delete=") + attr_reader :delete_#{field} + + def delete_#{field}=(value) + value = (value=="true") if String===value + return unless value + + # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! + self.#{field} = nil unless self.#{field}_just_uploaded? + end + EOF + } + end + + def klass_has_file_column_fields?(klass) + true unless file_column_fields(klass).empty? + end + end + + def file_column_fields + @file_column_fields||=FileColumnHelpers.file_column_fields(self) + end + + def options_for_file_column_field(field) + self.allocate.send("#{field}_options") + end + + def field_has_image_version?(field, version="thumb") + begin + # the only way to get to the options of a particular field is to use the instance method + options = options_for_file_column_field(field) + versions = options[:magick][:versions] + raise unless versions.stringify_keys[version] + true + rescue + false + end + end + + def generate_delete_helpers + FileColumnHelpers.generate_delete_helpers(self) + end + end + end + end end diff --git a/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb b/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb index 951e266308..c19dcb6702 100644 --- a/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +++ b/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb @@ -1,6 +1,6 @@ module ActiveScaffold module Bridges - module Paperclip + class Paperclip module PaperclipBridge def initialize_with_paperclip(model_id) initialize_without_paperclip(model_id) diff --git a/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb b/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb index fc5e9d2a6d..c1706c11fb 100644 --- a/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +++ b/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb @@ -1,6 +1,6 @@ module ActiveScaffold module Bridges - module Paperclip + class Paperclip module PaperclipBridgeHelpers mattr_accessor :thumbnail_style self.thumbnail_style = :thumbnail diff --git a/lib/active_scaffold/bridges/record_select.rb b/lib/active_scaffold/bridges/record_select.rb index 3200e0fdd0..fb153fa8be 100644 --- a/lib/active_scaffold/bridges/record_select.rb +++ b/lib/active_scaffold/bridges/record_select.rb @@ -1,5 +1,5 @@ class ActiveScaffold::Bridges::RecordSelect < ActiveScaffold::DataStructures::Bridge def self.install - require File.join(File.dirname(__FILE__), "record_select/record_select_bridge.rb") + require File.join(File.dirname(__FILE__), "record_select/helpers.rb") end end diff --git a/lib/active_scaffold/bridges/record_select/record_select_bridge.rb b/lib/active_scaffold/bridges/record_select/helpers.rb similarity index 96% rename from lib/active_scaffold/bridges/record_select/record_select_bridge.rb rename to lib/active_scaffold/bridges/record_select/helpers.rb index 3e1a1e6b27..7b6553e757 100644 --- a/lib/active_scaffold/bridges/record_select/record_select_bridge.rb +++ b/lib/active_scaffold/bridges/record_select/helpers.rb @@ -1,5 +1,5 @@ -module ActiveScaffold - module RecordSelectBridge +class ActiveScaffold::Bridges::RecordSelect + module Helpers def self.included(base) base.class_eval do include FormColumnHelpers @@ -89,4 +89,4 @@ def field_search_record_select_value(column) end end -ActionView::Base.class_eval { include ActiveScaffold::RecordSelectBridge } +ActionView::Base.class_eval { include ActiveScaffold::Bridges::RecordSelect::Helpers } diff --git a/lib/active_scaffold/bridges/semantic_attributes.rb b/lib/active_scaffold/bridges/semantic_attributes.rb index 3b9b5a5371..2adbead537 100644 --- a/lib/active_scaffold/bridges/semantic_attributes.rb +++ b/lib/active_scaffold/bridges/semantic_attributes.rb @@ -1,5 +1,5 @@ class ActiveScaffold::Bridges::SemanticAttributes < ActiveScaffold::DataStructures::Bridge def self.install - require File.join(File.dirname(__FILE__), "semantic_attributes/semantic_attributes_bridge.rb") + require File.join(File.dirname(__FILE__), "semantic_attributes/column.rb") end end diff --git a/lib/active_scaffold/bridges/semantic_attributes/semantic_attributes_bridge.rb b/lib/active_scaffold/bridges/semantic_attributes/column.rb similarity index 84% rename from lib/active_scaffold/bridges/semantic_attributes/semantic_attributes_bridge.rb rename to lib/active_scaffold/bridges/semantic_attributes/column.rb index b953e038b8..0863da8656 100644 --- a/lib/active_scaffold/bridges/semantic_attributes/semantic_attributes_bridge.rb +++ b/lib/active_scaffold/bridges/semantic_attributes/column.rb @@ -1,5 +1,5 @@ -module ActiveScaffold - module SemanticAttributesBridge +class ActiveScaffold::Bridges::SemanticAttributes + module Column def self.included(base) base.class_eval { alias_method_chain :initialize, :semantic_attributes } end @@ -16,5 +16,5 @@ def initialize_with_semantic_attributes(name, active_record_class) end end ActiveScaffold::DataStructures::Column.class_eval do - include ActiveScaffold::SemanticAttributesBridge + include ActiveScaffold::Bridges::SemanticAttributes::Column end diff --git a/lib/active_scaffold/bridges/tiny_mce.rb b/lib/active_scaffold/bridges/tiny_mce.rb index ad0a390aab..0349f9560f 100644 --- a/lib/active_scaffold/bridges/tiny_mce.rb +++ b/lib/active_scaffold/bridges/tiny_mce.rb @@ -1,5 +1,5 @@ -class ActiveScaffold::Bridges::TinyMCE < ActiveScaffold::DataStructures::Bridge +class ActiveScaffold::Bridges::TinyMce < ActiveScaffold::DataStructures::Bridge def self.install - require File.join(File.dirname(__FILE__), "tiny_mce/tiny_mce_bridge.rb") + require File.join(File.dirname(__FILE__), "tiny_mce/helpers.rb") end end diff --git a/lib/active_scaffold/bridges/tiny_mce/tiny_mce_bridge.rb b/lib/active_scaffold/bridges/tiny_mce/helpers.rb similarity index 94% rename from lib/active_scaffold/bridges/tiny_mce/tiny_mce_bridge.rb rename to lib/active_scaffold/bridges/tiny_mce/helpers.rb index 380ff35a96..ce2a09c925 100644 --- a/lib/active_scaffold/bridges/tiny_mce/tiny_mce_bridge.rb +++ b/lib/active_scaffold/bridges/tiny_mce/helpers.rb @@ -1,5 +1,5 @@ -module ActiveScaffold - module TinyMceBridge +class ActiveScaffold::Bridges::TinyMce + module Helpers def self.included(base) base.class_eval do include FormColumnHelpers @@ -66,4 +66,4 @@ def self.included(base) end end -ActionView::Base.class_eval { include ActiveScaffold::TinyMceBridge } +ActionView::Base.class_eval { include ActiveScaffold::Bridges::TinyMce::Helpers } diff --git a/lib/active_scaffold/bridges/validation_reflection.rb b/lib/active_scaffold/bridges/validation_reflection.rb deleted file mode 100644 index 227d28b3bc..0000000000 --- a/lib/active_scaffold/bridges/validation_reflection.rb +++ /dev/null @@ -1,9 +0,0 @@ -class ActiveScaffold::Bridges::ValidationReflection < ActiveScaffold::DataStructures::Bridge - def self.install - require File.join(File.dirname(__FILE__), "validation_reflection/validation_reflection_bridge.rb") - ActiveScaffold::DataStructures::Column.class_eval { include ActiveScaffold::ValidationReflectionBridge } - end - def self.install? - ActiveRecord::Base.respond_to? :reflect_on_validations_for - end -end diff --git a/lib/active_scaffold/bridges/validation_reflection/validation_reflection_bridge.rb b/lib/active_scaffold/bridges/validation_reflection/validation_reflection_bridge.rb deleted file mode 100644 index 69d26c013b..0000000000 --- a/lib/active_scaffold/bridges/validation_reflection/validation_reflection_bridge.rb +++ /dev/null @@ -1,19 +0,0 @@ -module ActiveScaffold - module ValidationReflectionBridge - def self.included(base) - base.class_eval { alias_method_chain :initialize, :validation_reflection } - end - - def initialize_with_validation_reflection(name, active_record_class) - initialize_without_validation_reflection(name, active_record_class) - column_names = [name] - column_names << @association.foreign_key if @association - self.required = column_names.any? do |column_name| - active_record_class.reflect_on_validations_for(column_name.to_sym).any? do |val| - val.macro == :validates_presence_of or (val.macro == :validates_inclusion_of and not val.options[:allow_nil] and not val.options[:allow_blank]) - end - end - end - end -end - diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 515192ce07..d7f125b606 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -298,7 +298,11 @@ def initialize(name, active_record_class) #:nodoc: # default all the configurable variables self.css_class = '' - self.required = active_record_class.validators_on(self.name).map(&:class).include? ActiveModel::Validations::PresenceValidator + self.required = active_record_class.validators_on(self.name).any? do |val| + ActiveModel::Validations::PresenceValidator === val or ( + ActiveModel::Validations::InclusionValidator === val and not val.options[:allow_nil] and not val.options[:allow_blank] + ) + end self.sort = true self.search_sql = true From cbfda5743902a3faf236458548449a19379bd22c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Sep 2011 13:01:01 +0200 Subject: [PATCH 1236/2024] edit_after_create was generalized in action_after_create --- frontends/default/views/on_create.js.erb | 6 +++--- lib/active_scaffold/bridges/calendar_date_select.rb | 2 +- lib/active_scaffold/bridges/date_picker.rb | 2 +- lib/active_scaffold/config/create.rb | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/frontends/default/views/on_create.js.erb b/frontends/default/views/on_create.js.erb index dcd94f484f..ba33be0bcf 100644 --- a/frontends/default/views/on_create.js.erb +++ b/frontends/default/views/on_create.js.erb @@ -33,8 +33,8 @@ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'mess <% else %> action_link.close(); <% end %> - <% if (active_scaffold_config.create.edit_after_create) %> - var link = $('<%=action_link_id 'edit', @record.id%>'); + <% if (active_scaffold_config.create.action_after_create) %> + var link = $('<%=action_link_id active_scaffold_config.create.action_after_create, @record.id%>'); if (link) (function() { link.action_link.open() }).defer(); <% end %> <% end %> @@ -42,4 +42,4 @@ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'mess ActiveScaffold.replace('<%=form_selector%>','<%=escape_javascript(render(:partial => 'create_form', :locals => {:xhr => true}))%>'); ActiveScaffold.scroll_to('<%=form_selector%>'); <% end %> -} catch (e) { alert('RJS error:\n\n' + e.toString());} \ No newline at end of file +} catch (e) { alert('RJS error:\n\n' + e.toString());} diff --git a/lib/active_scaffold/bridges/calendar_date_select.rb b/lib/active_scaffold/bridges/calendar_date_select.rb index 719cf6d4b2..36be8e92ea 100644 --- a/lib/active_scaffold/bridges/calendar_date_select.rb +++ b/lib/active_scaffold/bridges/calendar_date_select.rb @@ -11,6 +11,6 @@ def self.install end def self.install? - Object.const_defined?(name) && ActiveScaffold.js_framework == :prototype + super && ActiveScaffold.js_framework == :prototype end end diff --git a/lib/active_scaffold/bridges/date_picker.rb b/lib/active_scaffold/bridges/date_picker.rb index 5b1c26f564..54a871c11e 100644 --- a/lib/active_scaffold/bridges/date_picker.rb +++ b/lib/active_scaffold/bridges/date_picker.rb @@ -2,7 +2,7 @@ module ActiveScaffold::Bridges class DatePicker < ActiveScaffold::DataStructures::Bridge autoload :Helper, 'active_scaffold/bridges/date_picker/helper' def self.install - require File.join(File.dirname(__FILE__), "ext.rb") + require File.join(File.dirname(__FILE__), "date_picker/ext.rb") end def self.install? ActiveScaffold.js_framework == :jquery diff --git a/lib/active_scaffold/config/create.rb b/lib/active_scaffold/config/create.rb index 2dc3a3813a..18336e19bd 100644 --- a/lib/active_scaffold/config/create.rb +++ b/lib/active_scaffold/config/create.rb @@ -5,7 +5,7 @@ def initialize(core_config) super @label = :create_model self.persistent = self.class.persistent - self.edit_after_create = self.class.edit_after_create + self.action_after_create = self.class.action_after_create self.refresh_list = self.class.refresh_list end @@ -44,7 +44,7 @@ def label(model = nil) attr_accessor :persistent # whether the form stays open after a create or not - attr_accessor :edit_after_create + attr_accessor :action_after_create # whether we should refresh list after create or not attr_accessor :refresh_list From 25adf804e912bab5ac8d0022bc38d0fd2dbc15f8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Sep 2011 13:31:59 +0200 Subject: [PATCH 1237/2024] cleanup old method from rails 2.3 --- lib/active_scaffold/helpers/form_column_helpers.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index cf76f7a712..26dd59ce5b 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -43,7 +43,6 @@ def active_scaffold_render_input(column, options) # for textual fields we pass different options text_types = [:text, :string, :integer, :float, :decimal, :date, :time, :datetime] options = active_scaffold_input_text_options(options) if text_types.include?(column.column.type) - options = active_scaffold_input_date_options(column, options) if date_types.include?(column.column.type) if column.column.type == :string && options[:maxlength].blank? options[:maxlength] = column.column.limit options[:size] ||= ActionView::Helpers::InstanceTag::DEFAULT_FIELD_OPTIONS["size"] @@ -67,13 +66,6 @@ def active_scaffold_input_text_options(options = {}) options end - # the standard active scaffold options used for date, datetime and time inputs - def active_scaffold_input_date_options(column, options = {}) - options[:include_blank] = true if column.column.null - options[:prefix] = options[:name].gsub("[#{column.name}]", '') - options - end - # the standard active scaffold options used for class, name and scope def active_scaffold_input_options(column, scope = nil, options = {}) name = scope ? "record#{scope}[#{column.name}]" : "record[#{column.name}]" From 84d656a814f6a533396308325252ecd3b12d1787 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Sep 2011 13:57:53 +0200 Subject: [PATCH 1238/2024] fix some bits broken on merging --- lib/active_scaffold/actions/list.rb | 2 +- lib/active_scaffold/finder.rb | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index d1e0330614..53446b212d 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -60,7 +60,7 @@ def row_respond_to_js end # The actual algorithm to prepare for the list view - def do_list + def set_includes_for_list_columns includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact self.active_scaffold_includes.concat includes_for_list_columns end diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 6d7935a43a..52c78590bd 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -261,7 +261,7 @@ def finder_options(options = {}) finder_options = { :order => options[:sorting].try(:clause), :where => search_conditions, :joins => joins_for_finder, - :includes => options[:count_includes]} + :includes => full_includes} finder_options.merge! custom_finder_options finder_options @@ -270,9 +270,9 @@ def finder_options(options = {}) # Returns a hash with options to count records, rejecting select and order options # See finder_options for valid options def count_options(find_options = {}, count_includes = nil) - count_includes ||= find_options[:include] unless find_options[:conditions].nil? + count_includes ||= find_options[:includes] unless find_options[:conditions].nil? options = find_options.reject{|k,v| [:select, :order].include? k} - options[:include] = count_includes + options[:includes] = count_includes options end @@ -287,25 +287,26 @@ def find_page(options = {}) klass = beginning_of_chain # NOTE: we must use :include in the count query, because some conditions may reference other tables - count_query = append_to_query(klass, finder_options.reject{|k, v| [:select, :order].include?(k)}) - count = count_query.count unless options[:pagination] == :infinite + if options[:pagination] && options[:pagination] != :infinite + count_query = append_to_query(klass, count_options(find_options, options[:count_includes])) + count = count_query.count unless options[:pagination] == :infinite + end # Converts count to an integer if ActiveRecord returned an OrderedHash # that happens when find_options contains a :group key count = count.length if count.is_a? ActiveSupport::OrderedHash - finder_options.merge! :includes => full_includes # we build the paginator differently for method- and sql-based sorting if options[:sorting] and options[:sorting].sorts_by_method? pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| - sorted_collection = sort_collection_by_column(append_to_query(klass, finder_options).all, *options[:sorting].first) + sorted_collection = sort_collection_by_column(append_to_query(klass, find_options).all, *options[:sorting].first) sorted_collection = sorted_collection.slice(offset, per_page) if options[:pagination] sorted_collection end else pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| - finder_options.merge!(:offset => offset, :limit => per_page) if options[:pagination] - append_to_query(klass, finder_options).all + find_options.merge!(:offset => offset, :limit => per_page) if options[:pagination] + append_to_query(klass, find_options).all end end pager.page(options[:page]) From 972a7eaeedb8a0a5c9ad3ed5eb129a188826327a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Sep 2011 15:12:31 +0200 Subject: [PATCH 1239/2024] simplify template lookup and fix it for rails 3.1 --- lib/active_scaffold.rb | 21 +++++-------------- .../extensions/action_view_rendering.rb | 15 +++++++------ .../extensions/action_view_resolver.rb | 9 -------- 3 files changed, 12 insertions(+), 33 deletions(-) delete mode 100644 lib/active_scaffold/extensions/action_view_resolver.rb diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 2bd49b82d0..8211bb404b 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -157,12 +157,6 @@ def active_scaffold(model_id = nil, &block) @active_scaffold_config_block = block self.links_for_associations - @active_scaffold_overrides = [] - ActionController::Base.view_paths.each do |dir| - active_scaffold_overrides_dir = File.join(dir.to_s,"active_scaffold_overrides") - @active_scaffold_overrides << active_scaffold_overrides_dir if File.exists?(active_scaffold_overrides_dir) - end - @active_scaffold_overrides.uniq! # Fix rails duplicating some view_paths @active_scaffold_frontends = [] if active_scaffold_config.frontend.to_sym != :default active_scaffold_custom_frontend_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'frontends', active_scaffold_config.frontend.to_s , 'views') @@ -201,12 +195,14 @@ def active_scaffold(model_id = nil, &block) end end end - active_scaffold_paths.each do |path| - self.append_view_path(ActionView::ActiveScaffoldResolver.new(path)) - end + self.append_view_path active_scaffold_paths self._add_sti_create_links if self.active_scaffold_config.add_sti_create_links? end + def parent_prefixes + @parent_prefixes ||= super << 'active_scaffold_overrides' << '' + end + # To be called after include action modules def _add_sti_create_links new_action_link = active_scaffold_config.action_links.collection['new'] @@ -282,17 +278,10 @@ def add_active_scaffold_path(path) @active_scaffold_custom_paths << path end - def add_active_scaffold_override_path(path) - @active_scaffold_paths = nil # Force active_scaffold_paths to rebuild - @active_scaffold_overrides.unshift path - end - def active_scaffold_paths return @active_scaffold_paths unless @active_scaffold_paths.nil? - #@active_scaffold_paths = ActionView::PathSet.new @active_scaffold_paths = [] - @active_scaffold_paths.concat @active_scaffold_overrides unless @active_scaffold_overrides.nil? @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil? @active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil? @active_scaffold_paths diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index eb11ea6533..554ba9e69f 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -1,13 +1,12 @@ module ActionView class LookupContext module ViewPaths - def find_all_templates(name, prefix = nil, partial = false) - templates = [] - @view_paths.each do |resolver| - template = resolver.find_all(*args_for_lookup(name, prefix, partial)).first - templates << template unless template.nil? - end - templates + def find_all_templates(name, partial = false, locals = {}) + prefixes.collect do |prefix| + view_paths.collect do |resolver| + resolver.find_all(*args_for_lookup(name, prefix, partial, locals)) + end + end.flatten! end end end @@ -45,7 +44,7 @@ def render_with_active_scaffold(*args, &block) options[:locals] ||= {} options[:locals].reverse_merge!(last_view[:locals] || {}) if last_view[:templates].nil? - last_view[:templates] = lookup_context.find_all_templates(last_view[:view], controller_path, !last_view[:is_template]) + last_view[:templates] = lookup_context.find_all_templates(last_view[:view], !last_view[:is_template], options[:locals]) last_view[:templates].shift end options[:template] = last_view[:templates].shift diff --git a/lib/active_scaffold/extensions/action_view_resolver.rb b/lib/active_scaffold/extensions/action_view_resolver.rb deleted file mode 100644 index 6ae8c1ce35..0000000000 --- a/lib/active_scaffold/extensions/action_view_resolver.rb +++ /dev/null @@ -1,9 +0,0 @@ -module ActionView - class ActiveScaffoldResolver < FileSystemResolver - # standard resolvers have a base path to views and append a controller subdirectory - # activescaffolds view path do not have a subdir, so just remove the prefix - def find_templates(name, prefix, partial, details) - super(name,'',partial, details) - end - end -end From dc42577a9cb29b1ef45bd4d6ee059572d31a27c1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Sep 2011 15:15:11 +0200 Subject: [PATCH 1240/2024] don't break backwards compatibility --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index d15896ac45..4e4839f9af 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -10,7 +10,7 @@ def get_column_value(record, column) # we only pass the record as the argument. we previously also passed the formatted_value, # but mike perham pointed out that prohibited the usage of overrides to improve on the # performance of our default formatting. see issue #138. - send(column_override(column), column, record) + send(column_override(column), record) # second, check if the dev has specified a valid list_ui for this column elsif column.list_ui and override_column_ui?(column.list_ui) send(override_column_ui(column.list_ui), column, record) From 77f40f8379db39aab967932223ed03998637ae7e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Sep 2011 15:51:44 +0200 Subject: [PATCH 1241/2024] cache_association for singular associations has no point, once is retrieved it will be cached --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 4e4839f9af..4f2924c22d 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -153,7 +153,7 @@ def format_column_value(record, column, value = nil) value ||= record.send(column.name) unless record.nil? if value && column.association # cache association size before calling column_empty? associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association - cache_association(value, column) + cache_association(value, column) if column.plural_association? end if column.association.nil? or column_empty?(value) if column.form_ui == :select && column.options[:options] From 59201b2879c303f4989b720a2654b31cc8102b90 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Sep 2011 16:00:09 +0200 Subject: [PATCH 1242/2024] implement partial overrides --- .../helpers/form_column_helpers.rb | 6 ++---- lib/active_scaffold/helpers/view_helpers.rb | 20 ++----------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 26dd59ce5b..5f047c07a1 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -209,8 +209,7 @@ def onsubmit # add functionality for overriding subform partials from association class path def override_subform_partial?(column, subform_partial) - path, partial_name = partial_pieces(override_subform_partial(column, subform_partial)) - template_exists?(partial_name, path) + template_exists?(override_subform_partial(column, subform_partial), true) end def override_subform_partial(column, subform_partial) @@ -218,8 +217,7 @@ def override_subform_partial(column, subform_partial) end def override_form_field_partial?(column) - path, partial_name = partial_pieces(override_form_field_partial(column)) - template_exists?(partial_name, path) + template_exists?(override_form_field_partial(column), true) end # the naming convention for overriding form fields with helpers diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 988cefc9b3..a824a83983 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -42,26 +42,10 @@ def controller_path_for_activerecord(klass) end end - def partial_pieces(partial_path) - if partial_path.include?('/') - return File.dirname(partial_path), File.basename(partial_path) - else - return controller.class.controller_path, partial_path - end - end - # This is the template finder logic, keep it updated with however we find stuff in rails # currently this very similar to the logic in ActionBase::Base.render for options file - # TODO: Work with rails core team to find a better way to check for this. - # Not working so far for rais 3.1 - def template_exists?(template_name, path) - begin - method = 'find_template' - #self.view_paths.send(method, template_name) - return false - rescue ActionView::MissingTemplate => e - return false - end + def template_exists?(template_name, partial = false) + lookup_context.exists? template_name, '', partial end def generate_temporary_id From 61ef4f31903d7c6e170ad7e8cf71dcbb92b9cce1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Sep 2011 16:04:17 +0200 Subject: [PATCH 1243/2024] fix create label --- lib/active_scaffold/config/create.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/active_scaffold/config/create.rb b/lib/active_scaffold/config/create.rb index 18336e19bd..c32117f08b 100644 --- a/lib/active_scaffold/config/create.rb +++ b/lib/active_scaffold/config/create.rb @@ -32,14 +32,6 @@ def self.link=(val) cattr_accessor :refresh_list @@refresh_list = false - # instance-level configuration - # ---------------------------- - # the label= method already exists in the Form base class - def label(model = nil) - model ||= @core.label(:count => 1) - @label ? as_(@label) : as_(:create_model, :model => model) - end - # whether the form stays open after a create or not attr_accessor :persistent From 481cf01b3d3939c22b2b09ee212350f083f694bf Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Sep 2011 18:03:13 +0200 Subject: [PATCH 1244/2024] automatic bridges assets --- app/assets/javascripts/active_scaffold.js.erb | 1 + .../stylesheets/active_scaffold.css.erb | 4 +- lib/active_scaffold/bridges.rb | 18 ++++- .../bridges/calendar_date_select.rb | 8 ++ .../calendar_date_select/as_cds_bridge.rb | 16 ---- .../bridges/record_select/helpers.rb | 11 --- lib/active_scaffold/data_structures/bridge.rb | 6 ++ lib/active_scaffold/helpers/view_helpers.rb | 33 -------- lib/bridges/dependent_protect/bridge.rb | 10 --- .../lib/dependent_protect_bridge.rb | 11 --- lib/bridges/paperclip/bridge.rb | 13 --- lib/bridges/paperclip/lib/form_ui.rb | 20 ----- lib/bridges/paperclip/lib/list_ui.rb | 16 ---- lib/bridges/paperclip/lib/paperclip_bridge.rb | 32 -------- .../paperclip/lib/paperclip_bridge_helpers.rb | 18 ----- lib/bridges/record_select/bridge.rb | 5 -- .../record_select/lib/record_select_bridge.rb | 79 ------------------- lib/bridges/unobtrusive_date_picker/bridge.rb | 9 --- .../unobtrusive_date_picker/lib/form_ui.rb | 14 ---- .../lib/unobtrusive_date_picker_bridge.rb | 15 ---- .../lib/view_helpers.rb | 16 ---- 21 files changed, 34 insertions(+), 321 deletions(-) delete mode 100644 lib/bridges/dependent_protect/bridge.rb delete mode 100644 lib/bridges/dependent_protect/lib/dependent_protect_bridge.rb delete mode 100644 lib/bridges/paperclip/bridge.rb delete mode 100644 lib/bridges/paperclip/lib/form_ui.rb delete mode 100644 lib/bridges/paperclip/lib/list_ui.rb delete mode 100644 lib/bridges/paperclip/lib/paperclip_bridge.rb delete mode 100644 lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb delete mode 100644 lib/bridges/record_select/bridge.rb delete mode 100644 lib/bridges/record_select/lib/record_select_bridge.rb delete mode 100644 lib/bridges/unobtrusive_date_picker/bridge.rb delete mode 100644 lib/bridges/unobtrusive_date_picker/lib/form_ui.rb delete mode 100644 lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb delete mode 100644 lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index 4aad7dcbcd..f3f75113ab 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -11,3 +11,4 @@ <% require_asset "prototype/form_enhancements" %> <% require_asset "prototype/rico_corner" %> <% end %> +<% ActiveScaffold::Bridges.all_javascripts.each {|js| require_asset js} %> diff --git a/app/assets/stylesheets/active_scaffold.css.erb b/app/assets/stylesheets/active_scaffold.css.erb index 78f0aea865..347a276368 100644 --- a/app/assets/stylesheets/active_scaffold.css.erb +++ b/app/assets/stylesheets/active_scaffold.css.erb @@ -1,4 +1,4 @@ -<%= require_asset "jquery-ui" %> +<% require_asset "jquery-ui" %> /* ActiveScaffold (c) 2007 Richard White <rrwhite@gmail.com> @@ -1093,3 +1093,5 @@ padding: 5px 2px 5px 5px; .as_touch tr.record td { padding: 5px 10px; } + +<% ActiveScaffold::Bridges.all_stylesheets.each {|css| require_asset css} %> diff --git a/lib/active_scaffold/bridges.rb b/lib/active_scaffold/bridges.rb index ba8e643b76..9895d73c81 100644 --- a/lib/active_scaffold/bridges.rb +++ b/lib/active_scaffold/bridges.rb @@ -33,12 +33,26 @@ class << self def self.run_all return false if self.bridges_run - self.bridges.keys.each{|bridge_name| + self.bridges.keys.each do |bridge_name| bridge = self[bridge_name] bridge.run if bridge - } + end self.bridges_run = true end + + def self.all_stylesheets + self.bridges.keys.collect do |bridge_name| + bridge = self[bridge_name] + bridge.stylesheets if bridge and bridge.install? + end.compact.flatten + end + + def self.all_javascripts + self.bridges.keys.collect do |bridge_name| + bridge = self[bridge_name] + bridge.javascripts if bridge and bridge.install? + end.compact.flatten + end end end diff --git a/lib/active_scaffold/bridges/calendar_date_select.rb b/lib/active_scaffold/bridges/calendar_date_select.rb index 36be8e92ea..0849c90ac7 100644 --- a/lib/active_scaffold/bridges/calendar_date_select.rb +++ b/lib/active_scaffold/bridges/calendar_date_select.rb @@ -13,4 +13,12 @@ def self.install def self.install? super && ActiveScaffold.js_framework == :prototype end + + def self.stylesheets + calendar_date_select_stylesheets + end + + def self.javascripts + calendar_date_select_javascripts + end end diff --git a/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb index 0065aa7591..2568613cff 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb @@ -47,22 +47,6 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current :style => "display:#{(options[:show].nil? || options[:show]) ? '' : 'none'}"}) end end - - module ViewHelpers - def self.included(base) - base.alias_method_chain :active_scaffold_stylesheets, :calendar_date_select - base.alias_method_chain :active_scaffold_javascripts, :calendar_date_select - end - # Provides stylesheets to include with +stylesheet_link_tag+ - def active_scaffold_stylesheets_with_calendar_date_select(frontend = :default) - active_scaffold_stylesheets_without_calendar_date_select + [calendar_date_select_stylesheets] - end - - # Provides stylesheets to include with +stylesheet_link_tag+ - def active_scaffold_javascripts_with_calendar_date_select(frontend = :default) - active_scaffold_javascripts_without_calendar_date_select + [calendar_date_select_javascripts] - end - end end end end diff --git a/lib/active_scaffold/bridges/record_select/helpers.rb b/lib/active_scaffold/bridges/record_select/helpers.rb index 7b6553e757..fc67fd91b2 100644 --- a/lib/active_scaffold/bridges/record_select/helpers.rb +++ b/lib/active_scaffold/bridges/record_select/helpers.rb @@ -4,17 +4,6 @@ def self.included(base) base.class_eval do include FormColumnHelpers include SearchColumnHelpers - include ViewHelpers - end - end - - module ViewHelpers - def self.included(base) - base.alias_method_chain :active_scaffold_includes, :record_select - end - - def active_scaffold_includes_with_record_select(*args) - active_scaffold_includes_without_record_select(*args) + record_select_includes end end diff --git a/lib/active_scaffold/data_structures/bridge.rb b/lib/active_scaffold/data_structures/bridge.rb index f2a33e3ee0..97890bc064 100644 --- a/lib/active_scaffold/data_structures/bridge.rb +++ b/lib/active_scaffold/data_structures/bridge.rb @@ -12,5 +12,11 @@ def self.install? def self.run install if install? end + + def self.stylesheets + end + + def self.javascripts + end end end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index a824a83983..b209eb8968 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -84,39 +84,6 @@ def form_remote_upload_tag(url_for_options = {}, options = {}) (output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>").html_safe end - # Provides list of javascripts to include with +javascript_include_tag+ - # You can use this with your javascripts like - # <%= javascript_include_tag :defaults, 'your_own_cool_script', active_scaffold_javascripts, :cache => true %> - def active_scaffold_javascripts(frontend = :default) - ActiveScaffold::Config::Core.javascripts(frontend).collect do |name| - ActiveScaffold::Config::Core.asset_path(name, frontend) - end - end - - # Provides stylesheets to include with +stylesheet_link_tag+ - def active_scaffold_stylesheets(frontend = :default) - [ActiveScaffold::Config::Core.asset_path("stylesheet.css", frontend)] - end - - # Provides stylesheets for IE to include with +stylesheet_link_tag+ - def active_scaffold_ie_stylesheets(frontend = :default) - [ActiveScaffold::Config::Core.asset_path("stylesheet-ie.css", frontend)] - end - - # easy way to include ActiveScaffold assets - def active_scaffold_includes(*args) - frontend = args.first.is_a?(Symbol) ? args.shift : :default - options = args.first.is_a?(Hash) ? args.shift : {} - js = javascript_include_tag(*active_scaffold_javascripts(frontend).push(options)) - - css = stylesheet_link_tag(*active_scaffold_stylesheets(frontend).push(options)) - options[:cache] += '_ie' if options[:cache].is_a? String - options[:concat] += '_ie' if options[:concat].is_a? String - ie_css = stylesheet_link_tag(*active_scaffold_ie_stylesheets(frontend).push(options)) - - js + "\n" + css + "\n<!--[if IE]>".html_safe + ie_css + "<![endif]-->\n".html_safe - end - # a general-use loading indicator (the "stuff is happening, please wait" feedback) def loading_indicator_tag(options) image_tag "indicator.gif", :style => "visibility:hidden;", :id => loading_indicator_id(options), :alt => "loading indicator", :class => "loading-indicator" diff --git a/lib/bridges/dependent_protect/bridge.rb b/lib/bridges/dependent_protect/bridge.rb deleted file mode 100644 index 3ed3ba4693..0000000000 --- a/lib/bridges/dependent_protect/bridge.rb +++ /dev/null @@ -1,10 +0,0 @@ -ActiveScaffold.bridge "DependentProtect" do - install do - # check to see if the old bridge was installed. If so, warn them - # we can detect this by checking to see if the bridge was installed before calling this code - if ActiveRecord::Base.instance_methods.include?("authorized_for_delete?") - raise RuntimeError, "We've detected that you have active_scaffold_dependent_protect installed. This plugin has been moved to core. Please remove active_scaffold_dependent_protect to prevent any conflicts" - end - require File.join(File.dirname(__FILE__), "lib/dependent_protect_bridge.rb") - end -end diff --git a/lib/bridges/dependent_protect/lib/dependent_protect_bridge.rb b/lib/bridges/dependent_protect/lib/dependent_protect_bridge.rb deleted file mode 100644 index 3db3e2890a..0000000000 --- a/lib/bridges/dependent_protect/lib/dependent_protect_bridge.rb +++ /dev/null @@ -1,11 +0,0 @@ -module DependentProtectSecurity - def self.included(base) - base.class_inheritable_accessor :dependent_associations - end - protected - def authorized_for_delete? - self.class.dependent_associations ||= self.class.reflect_on_all_associations.select {|assoc| assoc.options[:dependent] == :protect} - self.class.dependent_associations.all? {|assoc| self.send(assoc.name).blank?} - end -end -ActiveRecord::Base.class_eval { include DependentProtectSecurity } diff --git a/lib/bridges/paperclip/bridge.rb b/lib/bridges/paperclip/bridge.rb deleted file mode 100644 index bdf507be7f..0000000000 --- a/lib/bridges/paperclip/bridge.rb +++ /dev/null @@ -1,13 +0,0 @@ -require File.join(File.dirname(__FILE__), "lib/paperclip_bridge_helpers") -ActiveScaffold.bridge "Paperclip" do - install do - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip") - raise RuntimeError, "We've detected that you have active_scaffold_paperclip_bridge installed. This plugin has been moved to core. Please remove active_scaffold_paperclip_bridge to prevent any conflicts" - end - - require File.join(File.dirname(__FILE__), "lib/paperclip_bridge") - require File.join(File.dirname(__FILE__), "lib/form_ui") - require File.join(File.dirname(__FILE__), "lib/list_ui") - ActiveScaffold::Config::Core.send :include, ActiveScaffold::PaperclipBridge - end -end \ No newline at end of file diff --git a/lib/bridges/paperclip/lib/form_ui.rb b/lib/bridges/paperclip/lib/form_ui.rb deleted file mode 100644 index 025f1b694b..0000000000 --- a/lib/bridges/paperclip/lib/form_ui.rb +++ /dev/null @@ -1,20 +0,0 @@ -module ActiveScaffold - module Helpers - module FormColumnHelpers - def active_scaffold_input_paperclip(column, options) - input = file_field(:record, column.name, options) - paperclip = @record.send("#{column.name}") - if paperclip.file? - content = active_scaffold_column_paperclip(column, @record) - content_tag(:div, - content + " | " + - link_to_function(as_(:remove_file), "$(this).next().value='true'; $(this).up().hide().next().show()") + - hidden_field(:record, "delete_#{column.name}", :value => "false") - ) + content_tag(:div, input, :style => "display: none") - else - input - end - end - end - end -end \ No newline at end of file diff --git a/lib/bridges/paperclip/lib/list_ui.rb b/lib/bridges/paperclip/lib/list_ui.rb deleted file mode 100644 index c06a351b53..0000000000 --- a/lib/bridges/paperclip/lib/list_ui.rb +++ /dev/null @@ -1,16 +0,0 @@ -module ActiveScaffold - module Helpers - module ListColumnHelpers - def active_scaffold_column_paperclip(column, record) - paperclip = record.send("#{column.name}") - return nil unless paperclip.file? - content = if paperclip.styles.include?(PaperclipBridgeHelpers.thumbnail_style) - image_tag(paperclip.url(PaperclipBridgeHelpers.thumbnail_style), :border => 0) - else - paperclip.original_filename - end - link_to(content, paperclip.url, :popup => true) - end - end - end -end \ No newline at end of file diff --git a/lib/bridges/paperclip/lib/paperclip_bridge.rb b/lib/bridges/paperclip/lib/paperclip_bridge.rb deleted file mode 100644 index 38ac1bc188..0000000000 --- a/lib/bridges/paperclip/lib/paperclip_bridge.rb +++ /dev/null @@ -1,32 +0,0 @@ -module ActiveScaffold - module PaperclipBridge - def initialize_with_paperclip(model_id) - initialize_without_paperclip(model_id) - return if self.model.attachment_definitions.nil? - - self.update.multipart = true - self.create.multipart = true - - self.model.attachment_definitions.keys.each do |field| - configure_paperclip_field(field.to_sym) - # define the "delete" helper for use with active scaffold, unless it's already defined - PaperclipBridgeHelpers.generate_delete_helper(self.model, field) - end - end - - def self.included(base) - base.alias_method_chain :initialize, :paperclip - end - - private - def configure_paperclip_field(field) - self.columns << field - self.columns[field].form_ui ||= :paperclip - self.columns[field].params.add "delete_#{field}" - - [:file_name, :content_type, :file_size, :updated_at].each do |f| - self.columns.exclude("#{field}_#{f}".to_sym) - end - end - end -end diff --git a/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb b/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb deleted file mode 100644 index 3dcb49dd3d..0000000000 --- a/lib/bridges/paperclip/lib/paperclip_bridge_helpers.rb +++ /dev/null @@ -1,18 +0,0 @@ -module PaperclipBridgeHelpers - mattr_accessor :thumbnail_style - self.thumbnail_style = :thumbnail - - def self.generate_delete_helper(klass, field) - klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("delete_#{field}=") - attr_reader :delete_#{field} - - def delete_#{field}=(value) - value = (value == "true") if String === value - return unless value - - # passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file! - self.#{field} = nil unless self.#{field}.dirty? - end - EOF - end -end \ No newline at end of file diff --git a/lib/bridges/record_select/bridge.rb b/lib/bridges/record_select/bridge.rb deleted file mode 100644 index f3ccb37ec7..0000000000 --- a/lib/bridges/record_select/bridge.rb +++ /dev/null @@ -1,5 +0,0 @@ -ActiveScaffold.bridge "RecordSelect" do - install do - require File.join(File.dirname(__FILE__), "lib/record_select_bridge.rb") - end -end diff --git a/lib/bridges/record_select/lib/record_select_bridge.rb b/lib/bridges/record_select/lib/record_select_bridge.rb deleted file mode 100644 index db5fef2b5b..0000000000 --- a/lib/bridges/record_select/lib/record_select_bridge.rb +++ /dev/null @@ -1,79 +0,0 @@ -module ActiveScaffold - module RecordSelectBridge - def self.included(base) - base.class_eval do - include FormColumnHelpers - include SearchColumnHelpers - include ViewHelpers - end - end - - module ViewHelpers - def self.included(base) - base.alias_method_chain :active_scaffold_includes, :record_select - end - - def active_scaffold_includes_with_record_select(*args) - active_scaffold_includes_without_record_select(*args) + record_select_includes - end - end - - module FormColumnHelpers - # requires RecordSelect plugin to be installed and configured. - def active_scaffold_input_record_select(column, options) - if column.singular_association? - active_scaffold_record_select(column, options, @record.send(column.name), false) - elsif column.plural_association? - active_scaffold_record_select(column, options, @record.send(column.name), true) - end - end - - def active_scaffold_record_select(column, options, value, multiple) - unless column.association - raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)." - end - remote_controller = active_scaffold_controller_for(column.association.klass).controller_path - - # if the opposite association is a :belongs_to (in that case association in this class must be has_one or has_many) - # then only show records that have not been associated yet - if [:has_one, :has_many].include?(column.association.macro) - params.merge!({column.association.primary_key_name => ''}) - end - - record_select_options = {:controller => remote_controller, :id => options[:id]} - record_select_options.merge!(options) - record_select_options.merge!(active_scaffold_input_text_options) - record_select_options.merge!(column.options) - record_select_options[:onchange] = "function(id, label) { this.value = id; #{record_select_options[:onchange]} }" if record_select_options[:onchange] - - if multiple - record_multi_select_field(options[:name], value || [], record_select_options) - else - record_select_field(options[:name], value || column.association.klass.new, record_select_options) - end - end - end - - module SearchColumnHelpers - def active_scaffold_search_record_select(column, options) - begin - value = field_search_params[column.name] - value = unless value.blank? - if column.options[:multiple] - column.association.klass.find value.collect!(&:to_i) - else - column.association.klass.find(value.to_i) - end - end - rescue Exception => e - logger.error Time.now.to_s + "Sorry, we are not that smart yet. Attempted to restore search values to search fields but instead got -- #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" - raise e - end - - active_scaffold_record_select(column, options, value, column.options[:multiple]) - end - end - end -end - -ActionView::Base.class_eval { include ActiveScaffold::RecordSelectBridge } diff --git a/lib/bridges/unobtrusive_date_picker/bridge.rb b/lib/bridges/unobtrusive_date_picker/bridge.rb deleted file mode 100644 index 878b762211..0000000000 --- a/lib/bridges/unobtrusive_date_picker/bridge.rb +++ /dev/null @@ -1,9 +0,0 @@ -ActiveScaffold.bridge "UnobtrusiveDatePicker" do - install do - require File.join(File.dirname(__FILE__), "lib/unobtrusive_date_picker_bridge.rb") - require File.join(File.dirname(__FILE__), "lib/form_ui.rb") - require File.join(File.dirname(__FILE__), "lib/view_helpers.rb") - ActiveScaffold::Config::Core.send :include, ActiveScaffold::UnobtrusiveDatePickerBridge - ActiveScaffold::Helpers::ViewHelpers.send :include, ActiveScaffold::UnobtrusiveDatePickerHelpers - end -end diff --git a/lib/bridges/unobtrusive_date_picker/lib/form_ui.rb b/lib/bridges/unobtrusive_date_picker/lib/form_ui.rb deleted file mode 100644 index 26c5df971a..0000000000 --- a/lib/bridges/unobtrusive_date_picker/lib/form_ui.rb +++ /dev/null @@ -1,14 +0,0 @@ -module ActiveScaffold - module Helpers - module FormColumnHelpers - def active_scaffold_input_datepicker(column, options) - method = "date#{'time' if column.column.type == :datetime}_select" - options[:include_blank] = true if column.column and column.column.null and [:date, :datetime, :time].include?(column.column.type) - html_options = options.update(column.options).delete(:html_options) || {} - options = active_scaffold_input_date_options(column, options) - args = [:record, column.name, options, html_options] - self.send(method, *args) + date_picker(*args) - end - end - end -end diff --git a/lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb b/lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb deleted file mode 100644 index 69624ed237..0000000000 --- a/lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge.rb +++ /dev/null @@ -1,15 +0,0 @@ -module ActiveScaffold - module UnobtrusiveDatePickerBridge - def initialize_with_unobtrusive_date_picker(model_id) - initialize_without_unobtrusive_date_picker(model_id) - date_fields = self.model.columns.select {|c| [:date, :datetime].include?(c.type) } - - # automatically set the forum_ui to a file column - date_fields.each {|field| self.columns[field.name.to_sym].form_ui = :datepicker} - end - - def self.included(base) - base.alias_method_chain :initialize, :unobtrusive_date_picker - end - end -end diff --git a/lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb b/lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb deleted file mode 100644 index 981144227a..0000000000 --- a/lib/bridges/unobtrusive_date_picker/lib/view_helpers.rb +++ /dev/null @@ -1,16 +0,0 @@ -module ActiveScaffold - module UnobtrusiveDatePickerHelpers - def self.included(base) - base.alias_method_chain :active_scaffold_stylesheets, :date_picker - base.alias_method_chain :active_scaffold_javascripts, :date_picker - end - - def active_scaffold_stylesheets_with_date_picker(frontend = :default) - active_scaffold_stylesheets_without_date_picker(frontend) + unobtrusive_datepicker_stylesheets - end - - def active_scaffold_javascripts_with_date_picker(frontend = :default) - active_scaffold_javascripts_without_date_picker(frontend) + unobtrusive_datepicker_javascripts - end - end -end From bf2fc4e3316d0fb0012c3434b93969239eedea56 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 15 Sep 2011 11:18:48 +0200 Subject: [PATCH 1245/2024] support to ActiveScaffold plugins add their stylesheets and javascripts --- app/assets/javascripts/active_scaffold.js.erb | 1 + app/assets/stylesheets/active_scaffold.css.erb | 3 ++- lib/active_scaffold.rb | 11 ++++++----- lib/active_scaffold/bridges/record_select.rb | 7 +++++++ lib/active_scaffold/engine.rb | 8 ++------ 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index f3f75113ab..4065869e55 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -11,4 +11,5 @@ <% require_asset "prototype/form_enhancements" %> <% require_asset "prototype/rico_corner" %> <% end %> +<% ActiveScaffold.javascripts.each {|js| require_asset js} %> <% ActiveScaffold::Bridges.all_javascripts.each {|js| require_asset js} %> diff --git a/app/assets/stylesheets/active_scaffold.css.erb b/app/assets/stylesheets/active_scaffold.css.erb index 347a276368..a46bf71241 100644 --- a/app/assets/stylesheets/active_scaffold.css.erb +++ b/app/assets/stylesheets/active_scaffold.css.erb @@ -1,4 +1,3 @@ -<% require_asset "jquery-ui" %> /* ActiveScaffold (c) 2007 Richard White <rrwhite@gmail.com> @@ -1094,4 +1093,6 @@ padding: 5px 2px 5px 5px; padding: 5px 10px; } +<% require_asset "jquery-ui" %> +<% ActiveScaffold.stylesheets.each {|css| require_asset css} %> <% ActiveScaffold::Bridges.all_stylesheets.each {|css| require_asset css} %> diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 8211bb404b..e4f17e5322 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -6,17 +6,13 @@ require 'render_component' rescue LoadError end -begin - require 'verification' -rescue LoadError -end require 'active_scaffold/active_record_permissions' require 'active_scaffold/paginator' require 'active_scaffold/responds_to_parent' require 'active_scaffold/version' -require 'active_scaffold/engine' +require 'active_scaffold/engine' unless defined? ACTIVE_SCAFFOLD_PLUGIN module ActiveScaffold autoload :AttributeParams, 'active_scaffold/attribute_params' @@ -26,6 +22,11 @@ module ActiveScaffold autoload :MarkedModel, 'active_scaffold/marked_model' autoload :Bridges, 'active_scaffold/bridges' + mattr_accessor :stylesheets + self.stylesheets = [] + mattr_accessor :javascripts + self.javascripts = [] + def self.autoload_subdir(dir, mod=self, root = File.dirname(__FILE__)) Dir["#{root}/active_scaffold/#{dir}/*.rb"].each { |file| basename = File.basename(file, ".rb") diff --git a/lib/active_scaffold/bridges/record_select.rb b/lib/active_scaffold/bridges/record_select.rb index fb153fa8be..352bdb774a 100644 --- a/lib/active_scaffold/bridges/record_select.rb +++ b/lib/active_scaffold/bridges/record_select.rb @@ -1,5 +1,12 @@ class ActiveScaffold::Bridges::RecordSelect < ActiveScaffold::DataStructures::Bridge def self.install + RecordSelect::Config.js_framework = ActiveScaffold.js_framework require File.join(File.dirname(__FILE__), "record_select/helpers.rb") end + def self.stylesheets + 'record_select' + end + def self.javascripts + 'record_select' + end end diff --git a/lib/active_scaffold/engine.rb b/lib/active_scaffold/engine.rb index 7c63cc5592..9910f48a5c 100644 --- a/lib/active_scaffold/engine.rb +++ b/lib/active_scaffold/engine.rb @@ -1,8 +1,4 @@ module ActiveScaffold - #do not use module Rails... cause Rails.logger will fail - # not sure if it is a must though... - #module Rails - class Engine < ::Rails::Engine - end - #end + class Engine < ::Rails::Engine + end end From 8444b4bc6f6abfbbca46b2711b8fb487f5016217 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 15 Sep 2011 11:21:53 +0200 Subject: [PATCH 1246/2024] fix record select js framework --- lib/active_scaffold/bridges/record_select.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/record_select.rb b/lib/active_scaffold/bridges/record_select.rb index 352bdb774a..f9d5ad0687 100644 --- a/lib/active_scaffold/bridges/record_select.rb +++ b/lib/active_scaffold/bridges/record_select.rb @@ -1,6 +1,5 @@ class ActiveScaffold::Bridges::RecordSelect < ActiveScaffold::DataStructures::Bridge def self.install - RecordSelect::Config.js_framework = ActiveScaffold.js_framework require File.join(File.dirname(__FILE__), "record_select/helpers.rb") end def self.stylesheets @@ -10,3 +9,4 @@ def self.javascripts 'record_select' end end +RecordSelect::Config.js_framework = ActiveScaffold.js_framework From 8fd49e7ef89a21c5515e0c19b5d7d6a783806517 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 15 Sep 2011 11:54:01 +0200 Subject: [PATCH 1247/2024] autodetect js framework --- app/assets/javascripts/active_scaffold.js.erb | 5 +++-- install.rb | 3 --- lib/active_scaffold.rb | 6 +++++- lib/active_scaffold/bridges/record_select.rb | 1 - 4 files changed, 8 insertions(+), 7 deletions(-) delete mode 100644 install.rb diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index 4065869e55..93caa4e8a5 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -1,9 +1,10 @@ -<% if ActiveScaffold.js_framework == :jquery %> +<% case ActiveScaffold.js_framework %> +<% when :jquery %> <% require_asset "jquery-ui" %> <% require_asset "jquery/active_scaffold" %> <% require_asset "jquery/jquery.editinplace" %> <% require_asset "jquery/date_picker_bridge" %> -<% else %> +<% when :prototype %> <% require_asset "effects" %> <% require_asset "controls" %> <% require_asset "prototype/active_scaffold" %> diff --git a/install.rb b/install.rb deleted file mode 100644 index ea29c8b9a1..0000000000 --- a/install.rb +++ /dev/null @@ -1,3 +0,0 @@ -File.open(File.expand_path('../../../../config/initializers/active_scaffold.rb', __FILE__), 'w') do |f| - f << "#ActiveSupport.on_load(:active_scaffold) { self.js_framework = :jquery }\n" -end diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index e4f17e5322..e879bc93e0 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -124,7 +124,11 @@ def self.js_framework=(framework) end def self.js_framework - @@js_framework ||= :jquery + @@js_framework ||= if defined? Jquery + :jquery + elsif defined? PrototypeRails + :prototype + end end # exclude bridges you do not need diff --git a/lib/active_scaffold/bridges/record_select.rb b/lib/active_scaffold/bridges/record_select.rb index f9d5ad0687..717d47597c 100644 --- a/lib/active_scaffold/bridges/record_select.rb +++ b/lib/active_scaffold/bridges/record_select.rb @@ -9,4 +9,3 @@ def self.javascripts 'record_select' end end -RecordSelect::Config.js_framework = ActiveScaffold.js_framework From 15923c956f32f968585a51a5ec6318d2842d952f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 15 Sep 2011 12:12:56 +0200 Subject: [PATCH 1248/2024] add time format for datetime picker --- .../bridges/date_picker/helper.rb | 46 +++++++++---------- lib/active_scaffold/locale/de.yml | 3 ++ lib/active_scaffold/locale/en.yml | 3 ++ lib/active_scaffold/locale/es.yml | 3 ++ lib/active_scaffold/locale/fr.yml | 3 ++ lib/active_scaffold/locale/hu.yml | 3 ++ lib/active_scaffold/locale/ja.yml | 3 ++ lib/active_scaffold/locale/ru.yml | 3 ++ 8 files changed, 44 insertions(+), 23 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index 8564b7b3a5..4a2edaf316 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -2,21 +2,22 @@ module ActiveScaffold::Bridges class DatePicker module Helper DATE_FORMAT_CONVERSION = { - '%a' => 'D', - '%A' => 'DD', - '%b' => 'M', - '$B' => 'MM', - '%d' => 'dd', - '%e' => 'd', - '%j' => 'oo', - '%m' => 'mm', - '%y' => 'y', - '%Y' => 'yy', - '%H' => 'hh', # options ampm => false - '%I' => 'hh', # options ampm => true - '%M' => 'mm', - '%p' => 'tt', - '%S' => 'ss' + /%a/ => 'D', + /%A/ => 'DD', + /%b/ => 'M', + /%B/ => 'MM', + /%d/ => 'dd', + /%e/ => 'd', + /%j/ => 'oo', + /%m/ => 'mm', + /%y/ => 'y', + /%Y/ => 'yy', + /%H/ => 'hh', # options ampm => false + /%I/ => 'hh', # options ampm => true + /%M/ => 'mm', + /%p/ => 'tt', + /%S/ => 'ss', + /%[cUWwxXZz]/ => '' } def self.date_options_for_locales @@ -74,7 +75,7 @@ def self.datetime_options_for_locales def self.datetime_options(locale) begin - rails_time_format = I18n.translate! 'time.formats.default', :locale => locale + rails_time_format = I18n.translate! 'time.formats.picker', :locale => locale datetime_options = I18n.translate! 'datetime.prompts', :locale => locale datetime_picker_options = {:ampm => false, :hourText => datetime_options[:hour], @@ -104,15 +105,14 @@ def self.datetime_options(locale) def self.to_datepicker_format(rails_format) return nil if rails_format.nil? if rails_format =~ /%[cUWwxXZz]/ - Rails.logger.warn("AS DatePicker::Helper: Can t convert rails date format: #{rails_format} to jquery datepicker format. Options %c, %U, %W, %w, %x %X, %z, %Z are not supported by datepicker]") + Rails.logger.warn("AS DatePicker::Helper: rails date format #{rails_format} includes options which can't be converted to jquery datepicker format. Options %c, %U, %W, %w, %x %X, %z, %Z are not supported by datepicker and will be removed") nil - else - js_format = rails_format.dup - DATE_FORMAT_CONVERSION.each do |key, value| - js_format.gsub!(Regexp.new("#{key}"), value) - end - js_format end + js_format = rails_format.dup + DATE_FORMAT_CONVERSION.each do |key, value| + js_format.gsub!(key, value) + end + js_format end def self.split_datetime_format(datetime_format) diff --git a/lib/active_scaffold/locale/de.yml b/lib/active_scaffold/locale/de.yml index f727bfa84e..5e750318c0 100644 --- a/lib/active_scaffold/locale/de.yml +++ b/lib/active_scaffold/locale/de.yml @@ -1,4 +1,7 @@ de: + time: + formats: + picker: "%a, %d %b %Y %H:%M:%S" active_scaffold: add: 'Hinzufügen' add_existing: 'Existierenden Eintrag hinzufügen' diff --git a/lib/active_scaffold/locale/en.yml b/lib/active_scaffold/locale/en.yml index 8e52600323..06259c41ec 100644 --- a/lib/active_scaffold/locale/en.yml +++ b/lib/active_scaffold/locale/en.yml @@ -1,4 +1,7 @@ en: + time: + formats: + picker: "%a, %d %b %Y %H:%M:%S" active_scaffold: add: 'Add' add_existing: 'Add Existing' diff --git a/lib/active_scaffold/locale/es.yml b/lib/active_scaffold/locale/es.yml index 1d53082475..0f3c83729c 100644 --- a/lib/active_scaffold/locale/es.yml +++ b/lib/active_scaffold/locale/es.yml @@ -1,4 +1,7 @@ es: + time: + formats: + picker: "%a, %d %b %Y %H:%M:%S" active_scaffold: add: 'Añadir' add_existing: 'Añadir Existente' diff --git a/lib/active_scaffold/locale/fr.yml b/lib/active_scaffold/locale/fr.yml index 9d016fa2ae..59ad66069f 100644 --- a/lib/active_scaffold/locale/fr.yml +++ b/lib/active_scaffold/locale/fr.yml @@ -1,4 +1,7 @@ fr: + time: + formats: + picker: "%a, %d %b %Y %H:%M:%S" active_scaffold: add: 'Ajouter' add_existing: 'Ajouter un(e) existant(e)' diff --git a/lib/active_scaffold/locale/hu.yml b/lib/active_scaffold/locale/hu.yml index 680fd8163b..9e742fe9a7 100644 --- a/lib/active_scaffold/locale/hu.yml +++ b/lib/active_scaffold/locale/hu.yml @@ -1,4 +1,7 @@ hu: + time: + formats: + picker: "%a, %d %b %Y %H:%M:%S" active_scaffold: add: 'Hozzáadás' add_existing: 'Meglevő hozzáadása' diff --git a/lib/active_scaffold/locale/ja.yml b/lib/active_scaffold/locale/ja.yml index a24b664cc0..add34059b0 100644 --- a/lib/active_scaffold/locale/ja.yml +++ b/lib/active_scaffold/locale/ja.yml @@ -1,4 +1,7 @@ ja: + time: + formats: + picker: "%a, %d %b %Y %H:%M:%S" active_scaffold: add: '追加' add_existing: '既存のものを追加' diff --git a/lib/active_scaffold/locale/ru.yml b/lib/active_scaffold/locale/ru.yml index 8952f1c7a6..ee3b2c4c20 100644 --- a/lib/active_scaffold/locale/ru.yml +++ b/lib/active_scaffold/locale/ru.yml @@ -1,4 +1,7 @@ ru: + time: + formats: + picker: "%a, %d %b %Y %H:%M:%S" active_scaffold: add: 'Добавить запись' add_existing: 'Добавить существующую запись' From 12ece86cebb47fe4a9ac0127fa325191274071cd Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 15 Sep 2011 12:13:11 +0200 Subject: [PATCH 1249/2024] Remove active_scaffold_setup generator, it isn't needed anymore There is no layout or locale modification, no configuration of js framework because it's autodetected from gems and no plugin installation (verification isn't used, render_component isn't needed because it will use JS if it's missing) --- lib/generators/active_scaffold_setup/USAGE | 10 ---- .../active_scaffold_setup_generator.rb | 58 ------------------- 2 files changed, 68 deletions(-) delete mode 100644 lib/generators/active_scaffold_setup/USAGE delete mode 100644 lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb diff --git a/lib/generators/active_scaffold_setup/USAGE b/lib/generators/active_scaffold_setup/USAGE deleted file mode 100644 index f256e54c3e..0000000000 --- a/lib/generators/active_scaffold_setup/USAGE +++ /dev/null @@ -1,10 +0,0 @@ -Description: - Setup a new Rails 3 Application with active_scaffold. - Pass 'jquery' in case you would like to use it instead of prototype - - This installs required plugins and configures active_scaffold to use - specified js lib and application layout file to include all required - assets - -Example: - `rails generate active_scaffold_setup jquery` \ No newline at end of file diff --git a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb b/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb deleted file mode 100644 index 69e2ac2ae3..0000000000 --- a/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +++ /dev/null @@ -1,58 +0,0 @@ -module Rails - module Generators - class ActiveScaffoldSetupGenerator < Rails::Generators::Base #metagenerator - argument :js_lib, :type => :string, :default => 'prototype', :desc => 'js_lib for activescaffold (prototype|jquery)' - - def self.source_root - @source_root ||= File.join(File.dirname(__FILE__), 'templates') - end - - def install_plugins - if defined?(ACTIVE_SCAFFOLD_PLUGIN) - plugin 'render_component', :git => 'git://github.com/vhochstein/render_component.git' - end - if js_lib == 'prototype' - get "https://github.com/vhochstein/prototype-ujs/raw/master/src/rails.js", "public/javascripts/rails.js" - elsif js_lib == 'jquery' - get "https://github.com/vhochstein/jquery-ujs/raw/master/src/rails.js", "public/javascripts/rails_jquery.js" - get "https://github.com/vhochstein/jQuery-Timepicker-Addon/raw/master/jquery-ui-timepicker-addon.js", "public/javascripts/jquery-ui-timepicker-addon.js" - end - end - - def configure_active_scaffold - return unless js_lib == 'jquery' - if defined?(ACTIVE_SCAFFOLD_PLUGIN) - content = "ActiveSupport.on_load(:active_scaffold) { self.js_framework = :jquery }" - else - content = "ActiveScaffold.js_framework = :jquery" - end - create_file "config/initializers/active_scaffold.rb", content - end - - def configure_application_layout - if js_lib == 'prototype' - inject_into_file "app/views/layouts/application.html.erb", - " <%= active_scaffold_includes %>\n", - :after => "<%= javascript_include_tag :defaults %>\n" - elsif js_lib == 'jquery' - inject_into_file "app/views/layouts/application.html.erb", -" <%= stylesheet_link_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/ui-lightness/jquery-ui.css' %> - <%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js' %> - <%= javascript_include_tag 'rails_jquery.js' %> - <%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js' %> - <%= javascript_include_tag 'jquery-ui-timepicker-addon.js' %> - <%= javascript_include_tag 'application.js' %> - <%= active_scaffold_includes %>\n", - :after => "<%= javascript_include_tag :defaults %>\n" - - inject_into_file "config/locales/en.yml", -" time: - formats: - default: \"%a, %d %b %Y %H:%M:%S\"", - :after => "hello: \"Hello world\"\n" - gsub_file 'app/views/layouts/application.html.erb', /<%= javascript_include_tag :defaults/, '<%# javascript_include_tag :defaults' - end - end - end - end -end From 1e5618664f427814efe4ea6cfce38a8b4a882b62 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 15 Sep 2011 12:17:51 +0200 Subject: [PATCH 1250/2024] move locale files to config/locales --- {lib/active_scaffold/locale => config/locales}/de.yml | 0 {lib/active_scaffold/locale => config/locales}/en.yml | 0 {lib/active_scaffold/locale => config/locales}/es.yml | 0 {lib/active_scaffold/locale => config/locales}/fr.yml | 0 {lib/active_scaffold/locale => config/locales}/hu.yml | 0 {lib/active_scaffold/locale => config/locales}/ja.yml | 0 {lib/active_scaffold/locale => config/locales}/ru.yml | 0 lib/active_scaffold_env.rb | 2 -- 8 files changed, 2 deletions(-) rename {lib/active_scaffold/locale => config/locales}/de.yml (100%) rename {lib/active_scaffold/locale => config/locales}/en.yml (100%) rename {lib/active_scaffold/locale => config/locales}/es.yml (100%) rename {lib/active_scaffold/locale => config/locales}/fr.yml (100%) rename {lib/active_scaffold/locale => config/locales}/hu.yml (100%) rename {lib/active_scaffold/locale => config/locales}/ja.yml (100%) rename {lib/active_scaffold/locale => config/locales}/ru.yml (100%) diff --git a/lib/active_scaffold/locale/de.yml b/config/locales/de.yml similarity index 100% rename from lib/active_scaffold/locale/de.yml rename to config/locales/de.yml diff --git a/lib/active_scaffold/locale/en.yml b/config/locales/en.yml similarity index 100% rename from lib/active_scaffold/locale/en.yml rename to config/locales/en.yml diff --git a/lib/active_scaffold/locale/es.yml b/config/locales/es.yml similarity index 100% rename from lib/active_scaffold/locale/es.yml rename to config/locales/es.yml diff --git a/lib/active_scaffold/locale/fr.yml b/config/locales/fr.yml similarity index 100% rename from lib/active_scaffold/locale/fr.yml rename to config/locales/fr.yml diff --git a/lib/active_scaffold/locale/hu.yml b/config/locales/hu.yml similarity index 100% rename from lib/active_scaffold/locale/hu.yml rename to config/locales/hu.yml diff --git a/lib/active_scaffold/locale/ja.yml b/config/locales/ja.yml similarity index 100% rename from lib/active_scaffold/locale/ja.yml rename to config/locales/ja.yml diff --git a/lib/active_scaffold/locale/ru.yml b/config/locales/ru.yml similarity index 100% rename from lib/active_scaffold/locale/ru.yml rename to config/locales/ru.yml diff --git a/lib/active_scaffold_env.rb b/lib/active_scaffold_env.rb index ea0fc2a2b3..f9345d9676 100644 --- a/lib/active_scaffold_env.rb +++ b/lib/active_scaffold_env.rb @@ -9,5 +9,3 @@ ActionController::Base.class_eval {include ActiveRecordPermissions::ModelUserAccess::Controller} ActiveRecord::Base.class_eval {include ActiveRecordPermissions::ModelUserAccess::Model} ActiveRecord::Base.class_eval {include ActiveRecordPermissions::Permissions} - -I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'active_scaffold', 'locale', '*.{rb,yml}')] From 10c0544102e6f7e90ae462bcfa187b0ef0d1bab4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 16 Sep 2011 11:56:45 +0200 Subject: [PATCH 1251/2024] add app to gem --- active_scaffold.gemspec | 2 +- lib/active_scaffold.rb | 4 ++-- lib/active_scaffold/version.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index c43a90576f..1cd5003aa9 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |s| s.summary = %q{Rails 3.1 Version of activescaffold supporting prototype and jquery} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.require_paths = ["lib"] - s.files = Dir["{frontends,lib,public,shoulda_macros}/**/*"] + %w[MIT-LICENSE CHANGELOG README] + s.files = Dir["{app,frontends,lib,public,shoulda_macros}/**/*"] + %w[MIT-LICENSE CHANGELOG README] s.extra_rdoc_files = [ "README" ] diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index e879bc93e0..18ec82998c 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -1,5 +1,5 @@ -unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 0 - raise "This version of ActiveScaffold requires Rails 3.0 or higher. Please use an earlier version." +unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 1 + raise "This version of ActiveScaffold requires Rails 3.1 or higher. Please use an earlier version." end begin diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index d7de511833..114797cb96 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 0 + PATCH = 1 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From c82ab8a6fccf593247890901d469cc2b4043d093 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 16 Sep 2011 12:17:55 +0200 Subject: [PATCH 1252/2024] add config to gem --- active_scaffold.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index 1cd5003aa9..c366475355 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |s| s.summary = %q{Rails 3.1 Version of activescaffold supporting prototype and jquery} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.require_paths = ["lib"] - s.files = Dir["{app,frontends,lib,public,shoulda_macros}/**/*"] + %w[MIT-LICENSE CHANGELOG README] + s.files = Dir["{app,config,frontends,lib,public,shoulda_macros}/**/*"] + %w[MIT-LICENSE CHANGELOG README] s.extra_rdoc_files = [ "README" ] From 4c40c8d115ef06fdf456d7a2e3a37a4c0e0f5232 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 16 Sep 2011 12:21:04 +0200 Subject: [PATCH 1253/2024] bump --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 114797cb96..c2c8cbcf20 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 1 + PATCH = 2 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From c2d974ed504e69f555dfa07c422c4095f8be3d9b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 16 Sep 2011 15:35:29 +0200 Subject: [PATCH 1254/2024] pass block in build_association --- .../active_association_reflection.rb | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/extensions/active_association_reflection.rb b/lib/active_scaffold/extensions/active_association_reflection.rb index 353b158701..06192b5516 100644 --- a/lib/active_scaffold/extensions/active_association_reflection.rb +++ b/lib/active_scaffold/extensions/active_association_reflection.rb @@ -1,13 +1,22 @@ # Bugfix: building an sti model from an association fails # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6306-collection-associations-build-method-not-supported-for-sti +# https://github.com/rails/rails/issues/815 +# https://github.com/rails/rails/pull/1686 ActiveRecord::Reflection::AssociationReflection.class_eval do - def build_association(*opts) - col = klass.inheritance_column.to_sym - if !col.nil? && opts.first.is_a?(Hash) && (opts.first.symbolize_keys[col]) - sti_model = opts.first.delete(col) - sti_model.to_s.camelize.constantize.new(*opts) + def klass_with_sti(*opts) + sti_col = klass.inheritance_column + if (h = opts.first).is_a? Hash and (passed_type = ( h[sti_col] || h[sti_col.to_sym] )) and (new_klass = active_record.send(:compute_type, passed_type)) < klass + new_klass else - klass.new(*opts) + klass end end -end \ No newline at end of file + def build_association(*opts, &block) + self.original_build_association_called = true + klass_with_sti(*opts).new(*opts, &block) + end + def create_association(*opts, &block) + self.original_build_association_called = true + klass_with_sti(*opts).create(*opts, &block) + end +end From 908433d68c2e35f14bcb0f2ef4a065d033eee4e2 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 16 Sep 2011 17:30:30 +0200 Subject: [PATCH 1255/2024] fix inline action links --- app/assets/javascripts/jquery/active_scaffold.js | 9 --------- .../extensions/action_controller_rendering.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 9 +++++---- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 3ccf51f282..bb8882de72 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -32,15 +32,6 @@ $(document).ready(function() { if (action_link.is_disabled()) { return false; } else { - // hack: jquery requires if you request for javascript that javascript - // is coming back, however rails has a different mantra - if (action_link.position) { - if (parseFloat($.fn.jquery) >= 1.5) { - event.data_type = 'text'; - } else { - event.data_type = 'rails'; - } - } if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','visible'); action_link.disable(); } diff --git a/lib/active_scaffold/extensions/action_controller_rendering.rb b/lib/active_scaffold/extensions/action_controller_rendering.rb index e48bdffec8..1ddda2f52b 100644 --- a/lib/active_scaffold/extensions/action_controller_rendering.rb +++ b/lib/active_scaffold/extensions/action_controller_rendering.rb @@ -8,7 +8,7 @@ def render_with_active_scaffold(*args, &block) opts = args.blank? ? Hash.new : args.first render :partial => params[:adapter][1..-1], :locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe}, - :use_full_path => true, :layout => false + :use_full_path => true, :layout => false, :content_type => :html @rendering_adapter = nil # recursion control else render_without_active_scaffold(*args, &block) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index b209eb8968..158e95bbe8 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -139,12 +139,13 @@ def action_link_html_options(link, url_options, record, html_options) # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails html_options[:method] = link.method if link.method != :get - html_options['data-confirm'] = link.confirm(record.try(:to_label)) if link.confirm? - html_options['data-position'] = link.position if link.position and link.inline? html_options[:class] += ' as_action' if link.inline? - html_options['data-action'] = link.action if link.inline? + html_options[:data] = {} + html_options[:data][:confirm] = link.confirm(record.try(:to_label)) if link.confirm? + html_options[:data][:position] = link.position if link.position and link.inline? + html_options[:data][:action] = link.action if link.inline? if link.popup? - html_options['data-popup'] = true + html_options[:data][:popup] = true html_options[:target] = '_blank' end html_options[:id] = link_id From 59dcb90a7bf09e4b30f34dc39059373748619355 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 16 Sep 2011 17:36:21 +0200 Subject: [PATCH 1256/2024] fix search view --- frontends/default/views/search.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/search.html.erb b/frontends/default/views/search.html.erb index 45a80962f9..5c126f67aa 100644 --- a/frontends/default/views/search.html.erb +++ b/frontends/default/views/search.html.erb @@ -1,5 +1,5 @@ <div class="active-scaffold"> - <div class="search-view <%= controller_class %> view"> + <div class="search-view <%= "#{params[:controller]}-view" %> view"> <%= render :partial => 'search' -%> </div> </div> From 0ce03559d49f007c588d7fad201a96b27a1fb2d2 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 19 Sep 2011 16:08:24 +0200 Subject: [PATCH 1257/2024] fix cancan bridge --- lib/active_scaffold/bridges/cancan.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/cancan.rb b/lib/active_scaffold/bridges/cancan.rb index 761820eb80..37c7536560 100644 --- a/lib/active_scaffold/bridges/cancan.rb +++ b/lib/active_scaffold/bridges/cancan.rb @@ -6,8 +6,8 @@ def self.install ActiveScaffold::Actions::Core.send :include, ActiveScaffold::Bridges::Cancan::Actions::Core ActiveScaffold::Actions::Nested.send :include, ActiveScaffold::Bridges::Cancan::Actions::Core ActionController::Base.send :include, ActiveScaffold::Bridges::Cancan::ModelUserAccess::Controller - ActiveRecord::Base.send :include, ActiveScaffold::Bridges::Cancan::ModelUserAccess::Model - ActiveRecord::Base.send :include, ActiveScaffold::Bridges::Cancan::ActiveRecord + ::ActiveRecord::Base.send :include, ActiveScaffold::Bridges::Cancan::ModelUserAccess::Model + ::ActiveRecord::Base.send :include, ActiveScaffold::Bridges::Cancan::ActiveRecord end def self.install? Object.const_defined? 'CanCan' From 5c4ae3b25238eaed5f3313ab2ac0dea395b4c8cb Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 20 Sep 2011 14:00:22 +0200 Subject: [PATCH 1258/2024] Don't modifiy model_id, it should be possible to use with pluralized models like TradableTerms --- lib/active_scaffold/config/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index b20986b03c..3ba7417545 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -107,7 +107,7 @@ def label(options={}) def initialize(model_id) # model_id is the only absolutely required configuration value. it is also not publicly accessible. - @model_id = model_id.to_s.pluralize.singularize + @model_id = model_id # inherit the actions list directly from the global level @actions = self.class.actions.clone From c712ea7879cf891625c4830f2696832c9493104c Mon Sep 17 00:00:00 2001 From: Brian Miller <BRIMIL01@gmail.com> Date: Fri, 23 Sep 2011 14:14:26 -0700 Subject: [PATCH 1259/2024] Replaced deprecated class_inheritable_attribute with class_attribute --- lib/active_scaffold/config/form.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/form.rb b/lib/active_scaffold/config/form.rb index 865b3ff8b2..abc07be2ca 100644 --- a/lib/active_scaffold/config/form.rb +++ b/lib/active_scaffold/config/form.rb @@ -14,7 +14,7 @@ def initialize(core_config) # global level configuration # -------------------------- # show value of unauthorized columns instead of skip them - class_inheritable_accessor :show_unauthorized_columns + class_attribute :show_unauthorized_columns # instance-level configuration # ---------------------------- From d0a2a7ddff9fe4a8abd8bcb27fd6b891952c7e73 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 26 Sep 2011 16:05:56 +0200 Subject: [PATCH 1260/2024] fix :select for singular associations --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 5f047c07a1..9ec1b03473 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -104,7 +104,7 @@ def active_scaffold_input_singular_association(column, html_options) method = column.name #html_options[:name] += '[id]' - options = {:include_blank => as_(:_select_)} + options = {:selected => associated.try(:id), :include_blank => as_(:_select_)} html_options.update(column.options[:html_options] || {}) options.update(column.options) From bdf910b7dff2b4567f569df809d1f6e11ec0f772 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 26 Sep 2011 16:29:14 +0200 Subject: [PATCH 1261/2024] images for jquery ui theme, and put jquery styles in vendor --- .../ui-bg_diagonals-thick_18_b81900_40x40.png | Bin 0 -> 260 bytes .../ui-bg_diagonals-thick_20_666666_40x40.png | Bin 0 -> 251 bytes .../images/ui-bg_flat_10_000000_40x100.png | Bin 0 -> 178 bytes .../images/ui-bg_glass_100_f6f6f6_1x400.png | Bin 0 -> 104 bytes .../images/ui-bg_glass_100_fdf5ce_1x400.png | Bin 0 -> 125 bytes .../images/ui-bg_glass_65_ffffff_1x400.png | Bin 0 -> 105 bytes .../ui-bg_gloss-wave_35_f6a828_500x100.png | Bin 0 -> 3762 bytes .../ui-bg_highlight-soft_100_eeeeee_1x100.png | Bin 0 -> 90 bytes .../ui-bg_highlight-soft_75_ffe45c_1x100.png | Bin 0 -> 129 bytes .../assets/images/ui-icons_222222_256x240.png | Bin 0 -> 4369 bytes .../assets/images/ui-icons_228ef1_256x240.png | Bin 0 -> 4369 bytes .../assets/images/ui-icons_ef8c08_256x240.png | Bin 0 -> 4369 bytes .../assets/images/ui-icons_ffd27a_256x240.png | Bin 0 -> 5355 bytes .../assets/images/ui-icons_ffffff_256x240.png | Bin 0 -> 4369 bytes .../assets/stylesheets/jquery-ui.css | 36 +++++++++--------- 15 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 vendor/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png create mode 100644 vendor/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png create mode 100644 vendor/assets/images/ui-bg_flat_10_000000_40x100.png create mode 100644 vendor/assets/images/ui-bg_glass_100_f6f6f6_1x400.png create mode 100644 vendor/assets/images/ui-bg_glass_100_fdf5ce_1x400.png create mode 100644 vendor/assets/images/ui-bg_glass_65_ffffff_1x400.png create mode 100644 vendor/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png create mode 100644 vendor/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png create mode 100644 vendor/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png create mode 100644 vendor/assets/images/ui-icons_222222_256x240.png create mode 100644 vendor/assets/images/ui-icons_228ef1_256x240.png create mode 100644 vendor/assets/images/ui-icons_ef8c08_256x240.png create mode 100644 vendor/assets/images/ui-icons_ffd27a_256x240.png create mode 100644 vendor/assets/images/ui-icons_ffffff_256x240.png rename {app => vendor}/assets/stylesheets/jquery-ui.css (94%) diff --git a/vendor/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png b/vendor/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png new file mode 100644 index 0000000000000000000000000000000000000000..954e22dbd99e8c6dd7091335599abf2d10bf8003 GIT binary patch literal 260 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1|)m_?Z^dEr#)R9Ln2z=UU%d=WFXS=@V?HT z#xG*`>Yvsgk=}99w^d^D^d*@m74oMo<%#FcopJf?u00-~YVKV2wzrI*_R6;UORMea zBFVSEnN~eiVA6V&z`E)YLz5Aok^D)In}Yn=OzDpgR5Wv0XfT8pOkmV{sKAJ-PO9#T zZK}IXj&Q-V!U)!LcB_3K<j6=ku*!%uXjy#leKdQ?`ZvP&RiaPVOzxQ$`O)`M(6sLS yN%J;Y?DO0<r7?ff#!c6LsA*2U`f2*?C%gsKpMo6zvorv`#o+1c=d#Wzp$Py>0&C*{ literal 0 HcmV?d00001 diff --git a/vendor/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png b/vendor/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png new file mode 100644 index 0000000000000000000000000000000000000000..64ece5707d91a6edf9fad4bfcce0c4dbcafcf58d GIT binary patch literal 251 zcmV<X00jSuP)<h;3K|Lk000e1NJLTq001Ze001Zm1^@s6jQ+T70002ONkl<ZScUD^ zT?&IR7(~(AY#^)6!n1<<Vj)fQYm^M-n@5r1C}@~h2;ohZ7-N3vC*J$+J$LlEJIhL0 z?fU|%;UEDj;@||T;sBg74hkR1O4$<++XU{$LE{Z7;GhCj!9fA2go6yIhJysCh=UWT ziUV-UI2ia*&y+p!utUI|$6*(^`>bvPcjKS|RKP(6sDcCAB(_QB%0978a<$Ah$!b|E zwn;|HO0i8cQ<lay$(1s&O|n)t8rvkbvR?jjlN@>j@~)s!ajF0S002ovPDHLkV1oEp BYH0uf literal 0 HcmV?d00001 diff --git a/vendor/assets/images/ui-bg_flat_10_000000_40x100.png b/vendor/assets/images/ui-bg_flat_10_000000_40x100.png new file mode 100644 index 0000000000000000000000000000000000000000..abdc01082bf3534eafecc5819d28c9574d44ea89 GIT binary patch literal 178 zcmeAS@N?(olHy`uVBq!ia0vp^8bF-F!3HG1q!d*FsY*{5$B>N1x91EQ4=4yQY-ImG zFPf9b{J;c_6SHRK%WcbN_hZpM=(Ry;4Rxv2@@2Y=$K57eF$X$=!PC{xWt~$(69B)$ BI)4BF literal 0 HcmV?d00001 diff --git a/vendor/assets/images/ui-bg_glass_100_f6f6f6_1x400.png b/vendor/assets/images/ui-bg_glass_100_f6f6f6_1x400.png new file mode 100644 index 0000000000000000000000000000000000000000..9b383f4d2eab09c0f2a739d6b232c32934bc620b GIT binary patch literal 104 zcmeAS@N?(olHy`uVBq!ia0vp^j6gJjgAK^akKnour1U*q978O6-yYw{%b*}|_(02F z@qbE9)0CJMo;*v*PWv`Vh2h6EmG8IS-Cm{3U~`<YvxSSFU3)<QP%DF{tDnm{r-UW| Dvd<uf literal 0 HcmV?d00001 diff --git a/vendor/assets/images/ui-bg_glass_100_fdf5ce_1x400.png b/vendor/assets/images/ui-bg_glass_100_fdf5ce_1x400.png new file mode 100644 index 0000000000000000000000000000000000000000..a23baad25b1d1ff36e17361eab24271f2e9b7326 GIT binary patch literal 125 zcmeAS@N?(olHy`uVBq!ia0vp^j6gJjgAK^akKnouq+C2*978O6lYjjF{IFh)jg74> zFlmZ}YMcJY=eo?o%*@I?2`NblNeMudl#t?<YIry`QK*OGr~otD9plAEGz`5G6d9zp Wa55e{GUW=;JO)o!KbLh*2~7a@&m@!p literal 0 HcmV?d00001 diff --git a/vendor/assets/images/ui-bg_glass_65_ffffff_1x400.png b/vendor/assets/images/ui-bg_glass_65_ffffff_1x400.png new file mode 100644 index 0000000000000000000000000000000000000000..42ccba269b6e91bef12ad0fa18be651b5ef0ee68 GIT binary patch literal 105 zcmeAS@N?(olHy`uVBq!ia0vp^j6gJjgAK^akKnouqzpV=978O6-=0?FV^9z|eBtf= z|7WztIJ;WT>{+tN>ySr~=F{k$>;_x^_y?afmf9pRKH0)6?eSP?3s5hEr>mdKI;Vst E0O<Z9>;M1& literal 0 HcmV?d00001 diff --git a/vendor/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png b/vendor/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png new file mode 100644 index 0000000000000000000000000000000000000000..39d5824d6af5456f1e89fc7847ea3599ea5fd815 GIT binary patch literal 3762 zcmb_eYgiKKwx-=Q?P<E4nMM;$eWu2m#PU%`&Ae^LOv^6gctJ3vM8!lUG!aCxQ#0eJ zq?xIqDJi9<fFp>di0+w!yaC|_1uvA>yaxz|iX3eB<LqajpXblFzRUBi^{w~$)_UKp zpDz0D*=4#5008Vc>v#HR0ASmSVIKMS&kf`CSAV4g0DJLgPkRO79xj%J<(hH6`bTGj zrr^$JeiHJI?;s&<5pRw-^kj}=E;X0OX+pgz+f5GVt0NQv_gbu0>-8J+F$O>HpW?Lx z+YFO`CV&6VV9fsEwG#js0_-|v*!ujZ*M=jfo457?0Do-z<^}+8bI+qk+W~+$zz%Z& z;L7&@&ns`l8Ofh*Wd<Cp_>U0pO%RP^?Xa_h7I}7K#}4Xt`s%-(m-enaPWX<H>$O&- zX~a1aOzn?!r?5wJVBNPJ_o8-(9Fz<_c1LYGxUl(E+Wdx?wkNHH2T%eWq9Kz00h#RB zYKI~=a<9_QqC^n<>hyWlS66waWgyAP#t&TfTWP=Sxa)ukRY%j7WH}(@r=B^W_;b&M zRzPYsb*j^Kou%%`K6VP+dKtR@x~qEHq4rXMxoX-gcSf&->lMY%TMXF!Gw_A)(tp6} z2A%kN3twbr%KyUrrmw24V3d%wzK<-q(M;MTr41}un`P!!xejADEv_CJ{CTif907B& zEP`pDJIZHVgnmxh$EZnBOUxz~Ap+ZzKbFmg39_n-)$wY!Q@i~5aGmHbN7&*gk<HNQ z!$-sS))5(#?qPW$1C^3#;cFvQMWTd)d(I_4awE^ZjGC%XcnSGez>q9zWgV|2(Zhxl zoDqJp&MxW(qX#C@oF8L)*r$RdSjVFSc$%z?*9%YoZ6sOZ!vtxXtBM<*r82<p7}?1@ zveQI&tiNm{;57jipQbO}b?9l*l4nGAT4Y=-w()@*#J1?%2{)nY^{|NO=xM)s?jR6< ziJ!fSOOPs*$8->vyC}_Eiz1PJ2L$bttko`=+fH{Ne@G#lMDxkKt_y)O(J5&Ak)w-I znm!vzYX3$kLDG$hOp-KJg~7}M;73BFWA{!a61fe?NJkjR_}Xw+*`O0=AGg7&dU<kQ zA;d%-zM*iwS2t8Y)Gu@JK&A)fV=HHvbW`6mV+EZrtJSauApMCndBS~F>A`A?9`whW zM{fkFf`G`P^9j*|-q9KLvS<191z9a^mK3Lss}W8O=sZ}N$V4Fh*SWF5NbZQ>p{0>$ z0pe}d$*s!y<I6P@1-n$GE>*R&NSXbjmld6{4Y;O89MuDTK0Hn0C?QdL9z1qGegXs! z7$MIGkPkwdHF2os-Z-e85B?5An>yc|m<}>!Iirg%H-<NQ%ws0uIi51-a5phDmp{k5 zD(zjPC;t}@{w)+0&{l~FS*>%F11XY{{>@kgL>a#6fM9JzBE&an&F>eWh|b0^kJ<?n zs=7WyuX=fIhvAjTTX`c}HUH)bTTI;OJGlyB{(NK&G;Htmn6^?c?TaAsOV}uBUtAa> zNBM5*nCa~(xwn~rG~<cfPp*ub4V(WF)lGbJpS(|MvAA83yV}}9bfbt(>>GSG9mz3h z9F~64y}giIrz^lfl|_5HpUsG}?Wpr*&f?bS=|9biqivN)-a~u>uK<{Lfcng{663QL zLXzO@*N5)q4C=j6E8nC+P%lEwI#~0wkt;M4Y8!+DYzN2rBuYao1*HRIa^NC9nFeep z+ns5$X9Bh48S-`ss!k&!J#Ddd=j1O-9}?`v(B|<M1@-U18t+Js;ZNHIk3$u$U;Eyu z3exyGipUQbO;S|Bzp(hX{&!NB@oq*gb}e^)68}5#!kH$BhK<@5!ubu^XDa&d1C#@| z3yY}&(~QVLCVdv){)I_ECxKsIlmW8LZ!;=rtk4ZaX!xm*=*Z(|P+Uqf*Rg<I!Tau& z85{4>>R7wD97BV;nK~quUHx^mj^G6K2GZ1*uSN?iLm!7vHB7_1^TGbKhmnK+K`GYA zocp2=on8LxJH^`7^1ch0ft(MTU$vJB!R@gQ^R`qoX>(=iY#u++3K>oqSpG={?#YVw zp3m99FXk^~<6#X9X1oKYXEH%8t2btG65(u0zF-J)^>8dj0Evc+9_Bd^Y)k9AfW~FV z%iDV(ClS6)TC7eVzh{ml;p4cx8)$TV&qhRWp+dqiw>i32?1;5d>HLrNj=^OdJ<}L) zWxqw8aFI<~_TkMDQHS?`z+KQ?+{ASoy%}RBu6i9?BXbh%OEx1OuZ}?n(VjrT(!B1; zQ!#WA0NBx=^6rJrFVsDCuT4)OTG<Ikaz*O8tFTZ)QL^`qbYu)jq*kTD>zZ3$Z4Yqz z&c9+7%g!%zxtv#p2fhHbo98KBwfE<e9Z<Yr%uRWj-5Hd3hTYY<&ve`je8y8RV)knu zYCT0K`*JrRv<nx%jAf>&Y(&2#=}qEEU`ECEjlCp=X^_tIoMx>%kBT5k)^c=zyV5w3 zc>DLKY6%=y0igWi9B@4hB}bR6K|+jYBt+}i6Ld|b`*s62c6Ge?zGYvdW)=p90~$Ad zxGB>c<3Dy~hPJ#vNXierOl41xBn_0L<5NhK6JO-LvtS&Z{xjGKfIC6*9%*?tv*?+! zv;Q{?mHN2b|3DEJO}R9w11ZT5QVC(H0u|0n9cVK_@2r%C<)OnZ(3aS0Ux^6G$ja*< z9R~o~9XjhPL)w@vYi6r;H$tR>wW`0-Z&Qed`X0LZY9-~mfso!@dt?5Q;@|K6$mAB& z$J41&y)<{N;QATPeU}BC{lM_<D4HZA)B)i-;gJ1pwusq$h>@-LlQ2hjX;}6~qdglT zGm%qJm*F^in=w*?j;@C_P<fNuR>CMnXK5Fd^wXV**pZOdS1KbSJsC~s#R;tmXIMb` zHB>sx<rNDl@4+*>Qg&E5Yf@}d#~Z9D4R{}ZpLm7S=bY0x#k<=H?=R+=W$=Bm2aU*n z)qgD*0#4>GGlHhQ`bx#k=Njc;+9D@{F5`xI^tMkBf{XIzwB=b9KbuuLF7jMTR~Mwt zN#!)9J4&^V@JRe9Y!b2!;$rCLPWZfG`C;Qz`u~TJdCzv->e`=R8uHX_2{Fp&pWJ*h z#A60&bY(j(^P@t_`_pktBV7{tFVoeNWlNA|zgNr&DMjJ_!k2%2s2~F@la$M6k%hWi z7}}hoDuoaN7?lchVk@4DunpEIS$72&uuF&F;&4uhC$L)6IzHHUryR9emzpxwsRXmj zfc}pI#oRCB7Y1;t=*58Gsv7x3PGuW^spn6V&dWf#?*TQ0(|*rr=EeE1o~y1<q=XbB zH7M1n6!fSD?pm#tnQqCt>wyQi%)e*oX6iX@$m0F1R<jp2X5!4xYkF7J+;bthC|!^_ zfGt{`v`5@+vH^moN%0^eXsq^fv|D%^4d2~y%?^q=-Nv+wR>tKUT0vgg!8^fWhYLqS zF@EOpFld7>f^kprb~YwMq=^<<pan6S!*H@g7t}eQJLhuWeLGTkT2P+Ck3!Te1lk%) zt9TCz)oC3>e|gw?QFyf8ck|ZC^>)3c`b$^C>jCB4Fne_1e$Cqt=4Ud#K~~8Nfa91W zwk17&D?X?4FRzR+5qCiIqPf0};K4$tW$}l~A?u_E=JSe;*f_DO>r{z=U4_<)dY)M! z7O#mizC+GN&#;)k)vkBU<tXnqP_^|-tGmZcT8Dlxt6Pn?`uypBX@1fVrNePVd#ALp zF4$80+@AG;7xl5W_sE^yNYES$<C6}`Zb1&JCZx~nYEbc%r#1d%Mn0pgS$5QlwG(ot z!Za{>S@fZesb{v?YuFlCPRjsT5bxB4@+sqdq}xvvBhTngZ(N1LUCS-ei=5sgE-Tbc z7HK+A_O23MP@sUoc?I?*ZB|F)&%us|2<oRU<$~ApQ%f%RU*aE`VmGrB<J4ieMCirV zP_~OQ;txr2WBgPQtAbapRV&BoULc}?@}z*gAAJEFNo(?(iOCZhqe)W78eZ*UvaN@7 zhKKGvt0!}(rjB;qc0K^%h|5n7(;vc+uHx|Dg@=F~<I;s3VT_=D#he%5p2SoOly<_w z*HKrz@ej3W?Y+xd+RJZ;9WZCGEGI{ETYg8h6;=d~Oi`<7@VfdE&iUPi>O$#G7V$6z zq>G%6!cu7OEf+_#^A=23Hd6Db9-yK*NQ#<PGnv3oz%Gl*Ib##q`dB%MvY>S+kjJI7 zhLiLz{>zKKtHH>H;B-cALzj`>@+-~?X2aP7ypf9WMf8q0m)wS!Nkf+&R&&zEjFOUx zlq^>v#VAq}=)?dKRMe+010g9O;qAiaTA4dV+==mw%i3Re)DwZ$Wd5CK1m4Ivy&&Ef zO8W!SpcgA>zfTGAE!{IPJMhdZ`T4{K#7ndDT8K2&*jf=J8O>H*iDJ}ZK}z|$C3U62 z$nZhk4v$QIYzMaV+0`B8S!=9RSYzi*QG#tp>ZY|lY_`}A-zI7)(tV$B9G-tC#zt8m z<!M@MT<43;wMNmuo-kSmPm5UQboY7uH(`#(7slpt#=BnL_;t>re~pD7oIFkmIAM=s zw+Iili%nSC?yks)t~q4lTlZW(#5^yUV@+^KvIuQzZDO^*TBz!<CtQh2rfO<z=TS{H zzIH*$V56H0{EnCR^XrG!ZG7AjD4r}Q(t2l9(P&QU6M<44;NxCby12gE#~t-zco3A+ rQq8KZ5e*fKEaO{0Ke0s~Qmy6Xh5m%FO!wV}CE%>j#nX%*uiW|{x9q0w literal 0 HcmV?d00001 diff --git a/vendor/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png b/vendor/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png new file mode 100644 index 0000000000000000000000000000000000000000..f1273672d253263b7564e9e21d69d7d9d0b337d9 GIT binary patch literal 90 zcmeAS@N?(olHy`uVBq!ia0vp^j6j^i!3HGVb)pi0l%l7LV~E7m<R2d&AFo$qV`FPm oboulDzr6KyA+fs7hb{~ZQx+&qVC9&67pR!Q)78&qol`;+0H8b=ng9R* literal 0 HcmV?d00001 diff --git a/vendor/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png b/vendor/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png new file mode 100644 index 0000000000000000000000000000000000000000..359397acffdd84bd102f0e8a951c9d744f278db5 GIT binary patch literal 129 zcmeAS@N?(olHy`uVBq!ia0vp^j6j^i!3HGVb)pi0l!vE_V~E7mtNjN#8yp0f)nD%C z{k^&2ZZH4W#qke67#j$%IepV*`yn{#P|600IVRJjChwXe(ssyZ>xPQ=F85a&M@g_{ d|GeK{$Y5lo%PMu^>wln`44$rjF6*2UngE4^EGqy2 literal 0 HcmV?d00001 diff --git a/vendor/assets/images/ui-icons_222222_256x240.png b/vendor/assets/images/ui-icons_222222_256x240.png new file mode 100644 index 0000000000000000000000000000000000000000..b273ff111d219c9b9a8b96d57683d0075fb7871a GIT binary patch literal 4369 zcmd^?`8O2)_s3^phOrG}UnfiUEn8(9QW1?MNkxXVDEpFin2{xWrLx5kBC;k~Gm<qS zlCjL7i8RK}U~J#s@6Y%1S9~7lb?$xLU+y{go_o*h`AV=spXY*!!T<mOmxZ~R9RL9Q zdj+hrf&W^P#f9C!Zpp^V{;aID?ElVL?Rdohw{Ucz9r_YL7=D6<&8F>PmYTG^FX}c% zl<zAi(m>GE{DS1Q;~I7<vD)$Yj(fd>-6ze&TN@+F-xsI6sd%SwK#*O5K|pDRZqEy< zJg0Nd8F@!OxqElm`~U#piM22@u@8B<<ecI*S<egUH7}csd8!)jLBD2s`p(8v&--KE z71^q9MglFywkSt_5FCr2F%o&UR(5j7-O>moyKE%ct`B(jysxK+1m?G)UyIFs1t0}L zemGR&?jGaM1YQblj?v&@0iXS#fi-VbR9zLEnHLP?xQ|=%Ihrc7^yPWR!tW$yH!zrw z#I2}_!JnT^(qk)VgJr`NGdPtT^dmQIZc%=6nTAyJDXk+^3}wUOilJuwq>s=T_!9V) zr1)DT6VQ2~rgd@!Jlrte3}}m~j}juCS`J4(d-5+e-3@EzzTJNCE2z)w(kJ90z*QE) zBtnV@4mM>jTrZZ*$01SnGov0&=A-JrX5Ge%Pce1Vj}=5YQqBD^W@n4KmFxxpFK`uH zP;(xKV+6VJ2|g+?_Lct7`uElL<&jzGS8Gfva2+=8A@#V+xsAj9|Dkg)vL5yhX@~B= zN2KZSAUD%QH`x>H+@Ou(D1~Pyv#0nc&$!1kI?IO01yw3jD0@80qvc?T*Nr8?-%rC8 z@5$|WY?Hqp`ixmEkzeJTz_`_<!oE0dsO`po1=$i_1k<Um_}caMZcrpqA*x-}Rw(fX z3Qyh8;-4^Fe)UICI@ayzmyV?48GbR;1*s>wsSRi1%Zivd`#+T{Aib6-rf$}M8sz6v zb6ERbr-SniO2wbOv!M4)nb}6UVzoVZEh5kQWh_5x4rYy3<sHrHJLqL+DcLT5`t$L@ z5_J8#H;PWO1GW@oId1Y>c!871NeaM(_p=4(kbS6U#x<*k8Wg^KHs2ttCz<+pBxQ$Z zQMv;kVm5_fF_vH`Mzrq$Y&6u?j6~f<juy`C^I0O`4mfXK0lrRY*VoeJX&k$9aL;Hl zlp63sf~-1z_419)A8^j|LeQSmK&T8R7nA=Ki3^H;YaeL&hF6>tIV0Yg)Nw7JysIN_ z-_n*K_v1c&D}-1{NbBwS2h#m1y0a5RiEcYil+58$8IDh49bPnzE7R8In6P%V{2IZU z7#clr=V4<zT-gP2u}DD>yyrRe@oXNqbqo^^LvlLE?%8XaI&N(Np90-psU}7kqmbWk zZ;YBwJNnNs<m6GqjV2(cCX2e+#tSOgIGm~J&Djknhy!e`&p)NTq>$~d!mx9oMGyT( znaBoj0d}gpQ^aRr?6nW)$4god*`@Uh2e+YpS@0(Mw{|z|6ko3NbTvDiCu3YO+)egL z>uW(^ahKFj>iJ-JF!^KhKQyPTznJa;xyHYwxJgr16&Wid_9)-%*mEwo{B_|M9t@S1 zf@T@q?b2Qgl!~_(Roe;fdK)y|XG0;ls;ZbT)w-aOVttk#daQcY7$cpY496H*`m@+L zeP#$&yRbBjFWv}B)|5-1v=(66M_;V1SWv6MHnO}}1=vby&9l+gaP?|pXwp0AFDe#L z&MRJ^*qX6wgxhA_`*o=LGZ>G_NTX%AKHPz4bO^R72ZYK}ale3lffDgM8H!Wrw{B7A z{?c_|dh2J*y<H{`M3l!HEtOc{;H{lJx}(C|*lvPQ+RAcV`>8b04c37OmqUw;#;G<* z@nz@dV`;7&^$)e!B}cd5tl<nF(??uM#|`*5pIKe!DEUl5-&9M=s_3Yn@-P(czyPQ~ zTU3I3bk%z<*w;9V(oQvt^2H`kBAW;=2oA<L1<qVIK(Z{Hk@5&E&_2mS+|}+?g@FBu zK+e=OWg<)e?RO;llNw00>0{g(Q>5_7H^@bEJi7;fQ4B$NGZerH#Ae1#8WDTH`iB&) zC6Et3BYY#mcJxh&)b2C^{aLq~psFN)Q1SucCaBaBUr%5PYX{~-q{KGEh)*;n;?75k z=hq%i^I}rd;z-#YyI`8-OfMpWz5kgJE3<X7ptj0dmPk5UrEf%nVD%<Giiw4wVh!K0 zFjy-VAnpOFJIDm=jqqahP0Wam<9qv4UMIazx8J<YJz>I!3ean6=UZi!BxG7i(YBk? z02HM7wS0)Wni{dWbQMRtd-A)_Az!t>F;IwWf~!*)-Az4}yryNkz&9)w>ElA80Oc`6 zHo#9H!Y3*Qx9n@Jn)!w6G^hb;e_n8zpIyXCN`JFkPc)^Q?2MsLNFhMgrcZI-<#1ne zjH;KFf?4eAT9<t<iUSC5BsF-<$q+H@@j%Yk>mQZ}ZfHLGA#d%s;SZK4p0FwZT2S^{ zQ2BG1xJsbK6?yrHTjJi|5C0u=!|r!?*4FL%y%3q#(d+e>b_2I9!*iI!30}42Ia0bq zUf`Z?LGSEvtz8s``Tg5o_CP(FbR0X$FlE0yCnB7su<mcL>DPmI2=yOg^*2#cY9o`X z;NY-3VBHZjnVcGS){GZ98{e+l<X|f4%S*+x526SE1mJ%6M<Nt*!}czEQf{?H1U0br z^Y7cXNxH@=Ve^#j3H@BPU>q~O$u6pEcgd0CrnIsWffN1MbCZDH<7c^hv+Z0Ucf0{w zSzi^qKuUHD9Dgp0EAGg@@$zr32dQx>N=ws`MESEsmzgT2&L;?MSTo&ky&!-JR3g~1 zPGTt515X)wr+Bx(G9lWd;@Y3^Vl}50Wb&6-Tiy;HPS0drF`rC}qYq22K4)G#AoD0X zYw$E+Bz@Zr^50MAwu@$?%f9$r4WHH?*2|67&FXFhXBrVFGmg)6?h3^-1?t;UzH0*I zNVf9wQLNLnG2@q>6CGm>&y|lC`iCFfYd}9i%+xkl^5oBJ?<;aneCfcHqJh7Yl5uLS z9Fx-(kMdcNyZejXh22N{mCw_rX1O!cOE&3>e(ZH81PR95wQC37En4O{w;{3q9n1<A zPC{;HRD3#A!@Lk)+k!~onQ0|-U%#uGd$&L?ZhNC&R)V(mb`NhUqrYysoMQ;Z)sq!y zW_WwV!+jO*nGT8-Hx_JVmFK^=>t&;p)D%&Z%Nw$gSPa!nz8Slh7=ko2am)XARwOWw zpsz0~K!s{(dM$NB=(A=kkp>T(*yU6<_dwIx>cH4+LWl282hXa6-EUq>R3t?G2623< z*RwTN%-fgBmD{fu*ejNn)1@KG?Sg<bw3hQ~jCP9_dLp#J9Fi#nX3wGv<cLwQ;8x0` zA<%pA%E0S;<5FJhw8e#?n&IA5g19Fv!v7YC%Gxqd<x1=+hht1t>*8z3hYtkQJQjB6 zQ|x>wA=o$=O)+nLmgTXW3<g>_6diA;b4EY{*i<HxX2Q~PA|R-tJ=V1~4KO3h7H~CG ztNFL#J=a@4Q5K7Ogvj-+3N_IJUjc}x34}a7@bDE3!)Kj4s7ME<v)`yP${V~G_J@6l zp{&i)CGxx1)X`lnwc}#g;g<(rA1#7Ez8@J}tuMD3bB{Wifbe~LWT0zYNjgb_qn|+G z2TCDZw1rV|wPx@~-H8<4^MGxfR0aLq+_k+{JT<mckxWLsw*J%G%YH0>*R%6dO2EMg z@6g?M3rpbnfB@hOdUeb9<OD{Zt&T^7p>6=~I?OIA3@BWAGmTwiQ{x5Cqq<8c10L!P zd@Qk^BseTX%$Q7^s}5n%HB|)gKx}H$d8Sb$bBnq9-AglT2dGR2(+I;_fL|R4p$odJ zllfb0NqI)7=^z~qAm1V{(PkpxXsQ#4*NH9yYZ`Vf@)?#ueGgtCmGGY|9U#v|hRdg- zQ%0#cGIfXCd{Y)JB~qykO;KPvHu|5Ck&(Hn%DF~cct@}j+87xhs2ew;fLm5#2+mb| z8{9e*YI(u|gt|{x1G+U=DA3y)9s2w7@cvQ($ZJIA)x$e~5_3L<r=v~@?aZ+642@!3 z&nTpp8p^rR@IEsq`uhzfD&i>KFV~ASci8W}jF&VeJoPDUy(BB>ExJpck;%;!`0AAo zAcHgcnT8%OX&UW_n|%{2B|<6Wp2MMGvd5`T2KKv;ltt_~H+w00x6+SlAD`{K4!9zx z*1?EpQ%Lwiik){3n{-+YNrT;fH_niD_Ng9|58@m8RsKFVF!6pk@qxa{BH-&8tsim0 zdAQ(GyC^9ane7_KW*#^vMIoeQdpJqmPp%%px3GIftbwESu#+vPyI*YTuJ6+4`z{s? zpkv~0x4c_PFH`-tqafw5)>4AuQ78SkZ!$8}INLK;Egr;2tS18hEO5=t;QDmZ-qu?I zG+=DN`nR72Xto{{bJp||`k}-2G;5#xg8E~xgz22)^_Z;=K|4@(E&5J)SY2of=olcw z5)@L)_Ntcm!*5nEy0M9v0`S33;pO4T<mv%0Rx6?c2H~TA%zOO^T2$@D<Cut3{ae}| zAT@Uzc>N;>4(Z+<j5j2DQ*r;U|6a;YfP1jST$I3mSn3aNn!?<=B-XkzG?hQH;@bu% zmFYDDgbC%Wt{6LBrs%88L}deF9pse}dmIp4lmp@Tir9q)JKESa=h>19p_0>u#e-vE zXCU(6gAvu~I7Cw(xd%0e59MNLw^U37ZDbsBrj%eDCexw8a3G`nTcXVNL6{B7Hj@i& zbVB{;ApEtHk76q08DJ48dSxd$C(;$K6=FpU<~l9pVoT9arW^Vu{%Bcn4`eIpkOVC| z$)AKYG_`ypM{0@BUb3^9lqi_c?ONH|4UJMJWDowMVjacycX7}9g={O7swOB+{;+?; zjBo!9?+nd)ie#x5IbFW-zBOo0c4q@9wGVt5;pNt`=-~Zgcw#*`m($6ibxtZ`H=e=} zF#GZ~5$%AUn};8U#tRem0J(JTR}<qii}wxmUzVwVIg2$uE2;GN{hhT&GE1i;_fi(_ z9KKXP)ds1Q)XnUhr?uXO-HbKE%5f%+-C>d4vR(dgK2ML~lZsPhayJ2h1%sD4FVst| zKF)+@`iNzLRjg4=K8@**0=5cE>%?FDc({I^+g9USk<8$&^qD~@%W0i4b|yMG*p4`N zh}I!ltTRI8Ex$+@V{02Br%xq#O?UlhO{r8WsaZnZCZq0MK9%AXU%MDLT;3=0A9(BV z9VxxxJd7jo$hw3q;3o?yBLmA=azBUrd9>-<_ANs0n3?-Ic*6&ytb@H~?0E(*d>T5n z-HiH2jsDf6uWhID%#n>SzOqrFCPDfUcu5QPd?<(=w6pv1BE#nsxS{n!UnC9qAha1< z;3cpZ9A-e$+Y)%b;w@!!YRA9p%Kf9IHGGg^{+p`mh;q8i7}&e@V3EQaMsItEMS&=X plT@$;k0WcB_jb;cn%_Idz4HO$QU*abf4}+wi?e96N>fbq{{i|W0@(ln literal 0 HcmV?d00001 diff --git a/vendor/assets/images/ui-icons_228ef1_256x240.png b/vendor/assets/images/ui-icons_228ef1_256x240.png new file mode 100644 index 0000000000000000000000000000000000000000..a641a371afa0fbb08ba599dc7ddf14b9bfc3c84f GIT binary patch literal 4369 zcmd^?`8O2)_s3^phOrG}UnfiUEn8(9QW1?MNkxXVDEpFin2{xWrLx5kBC;k~Gm<qS zlCjL7i8RK}U~J#s@6Y%1S9~7lb?$xLU+y{go_o*h`AV=spXY*!!T<mOmxZ~R9RL9Q zdj+hrf&W^P#f9C!Zpp^V{;X{3=KszyL1xbWEgT(ahrR?5hM!<zvuS&nr6z6fi@J>w z<@?HsG!Qg3zaV+-xQ3ldtad!U<6iGz_enGH*2akP_r)o1D&8p^5M)<i5Kvm7+w+1d z&*|KAM&6N6?%o|XKL7xDVlB)}>_c8IIj6Wy*7HJo&CBLuo~nj>(63pZzO(Vv^ZuB3 zMYigjkwA;FEy|G}1jpiMj6|NTm7Uyiw=@FDE*nX<>jR!W@9XIyf%$Fd*J5*D0Z0Lm z9}ZQxyT|x5ftNy?V>EbJz-K>bV9gs9RaXUP<^=;e?&Fqxj;6{ieR-a-@H<J_4GiWZ zaVu(K@aJcf^w<j8VA*iR3{E8n{m4z5Ta=$%rXkgQO6v#}L)oynVyGEE=_51-z65?H zDgGA81aw}gX`NgF4>ycA1KMKhql8GOmcx<Hp8QKqcf*>wZ?_-(3hMK^^a*(gaFvBH ziIC!fgH4$W*NbKIaY&T?%&13``KbD@S-0`xQ%v3TV+B!;RC7O!+1a9QCA$H@3tR;k z)SSoR7(s4)f{zM}eWgFN{(ZH5d1O}l)f$ruT!)Q&NImXyZsTzOf9TwctcSfr+M)aJ z5otO+$jvm-P4)ykH)x|cO5xeb>?!`qGw$(>&axqLL6yoB${vsMXgL_-bz@2J_tS92 zdvZG-+vKl@K4Vr(<X8D7Fm5%eurE#<YP<1YLAHb!!E~xCzIMI68x%=Yh-w$L6-vB; z!c#Z2_$LgPU;Po3j&(cwr6cKhhF=VILF!3vYQvfMvLYtV{!ir!NUtS|shjnm2Kl+v z9M*o<>EL{WQt@Z+Ea-hxX0}nTSZxnpi^#Kn8Ox8FgIS|hc}KJQ4tm*HO16ui{(O9} z1YN)GjiQt6fGq`Cj+^`zUf?8hk^(T{{cOQGWFP98am}is28A!5%{R#ENv8fCN!j69 zl<vTXm`x#Aj3pR~5$!tw8x6HJBT;veqlI((e3l5f1J0XQfUi^9^|f?)8pp02+%sAX zr3QSEAghjFy?kTy2b}Y~5VYqs5GsSo#pFLl;)0^z+6P*`;T5Mu&WLv=bzI9Q@9K!# zx3ne5{kTux3L#b!(t3OTfpmY0?(76nqT7xWC3Cn`hU1f1hZjxb%CxmPCafJTzecbo zhDHzEdDz$vS9U>MEK(2z?|BY=Je$XD9mB-Kkem*(d-j^9j$2#6r$Dz?s)-TCDCGCs z8>6Pvj{Y+YIeFA@qY22V$)awy@q!9A4rgk5b9TcC;s9Ig^G|6nDP+5=Fzg&?(L=vc zCbGd>fSu~@6!94td+o#d@sid<c4_^>!EI<?7QBi6t=$bf#g{8RUCj>X$rx7*cawe6 z`dScJ+$HssdOjE)O#Ybs56vm-FQ$7yuJJD^Zqk%hMaIgAJ<2yb_MFQte_i;62ScT$ zpjifYyR_E=rQ+>H)pmlr-Udzg*-!|ssw(D7wJvC+Sf8bb9;;q8#z?0p!!bsd{wy|5 zpBaMHE-Ve>i#LLjHRaMLtp%9&(HCng7Sw96jVv!#0k%?F^K7&=T)mnYn)D9(i;4x5 z^NJTJwq~pv;kH@#ejTd*48~(J(r6j34|m`h9fEDj0im)~+%I5XphWymhT;_Zty|Q& zzjPg#-ufAHZ<omf5#{klOC=UKcxxw*?x^rKwwoZ7wz3@8eku)ggLNRn<<KIdajH#H zeA)T=Seh$G{X;Ew$<Zx1YdFKl^buFmaRdI%XI9raN<LH2H`S7|Dmv<?JPd_9FaRph z7M0*0UG<&|_BGC;v{TKZe6h)s$R@%If`c(mfiu?)kSq&lq&xx(v`_L7ceQ&}Az*(Z zkTW$+naI+A`yGk?qy`dg`WSb{6e&FN4RX;O&+frr6hjc+3<Yokv6*p`M#SE){vkzc z3FL#%2;YdX9eq<GwL48ff7Y!gs4B@Hlzc$A2`aV3*Atk++JX5HDY4Bk;uB4Yxbu<X z`L&1ByqMIqI8t`UE|_LH(~F2;?|){*%50r1sI9V=C6bO-=^K$CSiOmlVqzhvSi?6g z4AzPTh<iZl4l)6IBfJ=W6EkAt_}>1M*Gccw?Kf|8Pnhtb0`!{N`Bqsa37J+>wC$!e z00k+2Egzz;rbcWoUB%Jvp8W1}$XD%e3>4y;;OZ1ccT-O#uW6Ys@C}Pa`nZrNKzR(2 z4e%3)@QI4SE&E!lW`5y14QhbepBG%_XBV-O(%<aX6HVzRJ7ee*QV3AB=~LWyIoy{V zqv~a)U>5tj)@9#|;sC-MNev!zGDHk}JdpGC`iJF#8=8-P$Xoku_=Dw%Cv3{U7L>gf zRQ?<$t`cZ*MP5GQmbmx#!+*!zu>0MewRO9GFGS{b^m_fJ-N0?j@EqoFf>$khj+E|@ z7r3We&^tR^YZrxKe*d<YJy4G(9mh^GOxZ8bi3n#Ytos{m`t{%)Lj8wW{Y{jV+Q_6T zI5_MMSa-xsCZ~p-HRDCj#<#0BIhacN@>22agXqCO0l44&kqCv{u)T|(lv`~PK@DvE z{QI_TlCH5z*gR!>LO)k67{^R+vWx24U2^2ODXpwT;6y+6+$5m)_*w4WY&#do9dCeE z)>p+Ykdhq($DhmMiaYXey!@N%L26uz($aJ!QT{B^Wu}U$^9e#5)=c+XF9@Ill?ZmM zlNgHiz*9!vDc&uxOo;ZVxb`Q!Sk0*gnfxWzmbZh4(=%CD%qP?0=);n$&zaW_$UKV9 z8axdcN#AyZ{P)wj?V{P}vM)YY!>6@}^>U+iv$`9>nMTCPjN>z%yF&3yf%>+T@0vh4 zlC8Xa6zeo?%=o3}M8{aebLHcO{^1Ar8qiM=Gquf?Jo)q5`-+?sUpg?QXyEUpWSm+n z$K-UyqkI<R?*3wTVfWE~<@2<uS?-MVl1;jzAA8*iL4xsi?b?BNi<UXgZAh$t2eX2O zlaSjP6`u~(FfWAHwjdICW?Bi|*YB$4-Yt-e+urDxm7s0C-NReT=&xHY=NLk9^<)K_ z8Qvc8a9@Rcrh{U|jRjj-<@xXJdfDhCHAU3q@`fxV7DF|YZ^rH=h9J#M-17gO6$#8E z=<ACLP@x){UQ68&`mEVXq`?Cxb~%;JJ<xQvIxsey(BZq&!Lur1_nVgz6$w$lK^&jz z^=yq5^Y*23<@W0Z_KKzDbZLlkyC5J9t>wHLquru~o(OF)hhz$Y*|X>ZIbswnxRvr~ z2=rdOGVuD|xRlpAZE<0!X1F(%Anpl^@V^D3vbM}qxe|NI;TTiZy7(IM;R69RkA>a& z6gwYE2sREzQ_LHmWqB+ogMk(fMaSFeoDq-!HkFB_nXt5+2ncFuk9BQL1I&oB1zZi) zYW{6_&-Ip1l*OVRA##1ILQS;5R{-K^0wGTiJbVSi@LA^$D$;@J>^G{6@&+%4{b3(s zC~LEHiTv(0b#zxt?YJ0r_~pUZM~mQ(??(n#>&tD%+@nq=Abj5*8R!~Ul1`G~=qFJ4 zfl|m8ZDCYgtr`4LcOpgiJYX9qRY5;DcWti~PmS$VB$E-Zt^f4)vLDOe_3XTq5^ylW zJ9PKm!V-8sAOJXnUfuFNIf0R9tK-pNs2hO04zr620}5B(Ok>yB)Of-3sP59qfQNbm zA4{w!2@cB;GbR(~szVrbO%(w=5S!X`o@o@x++wbN_tMPT0V<QhG{UeJ;8({%=z{L* zWd0UgQl1fNI!H$Y$hXK#w3!Gvn(74Nb)t*FnucAAe1;`Z--B03CHyB#2gq}g;qs~I zlu;^<Ox+<j-;_m5iBxJsQxuqvjs7QOWMpota<0)9-Vv;XHb%w=>c)*I;Fgsbf^*g0 z2Di?HTApwKq3+YwfNsqd3iP%{hyK1iyuVZc@*0tO_3+N0#GFsz>8MjeJ2UJ%L!%hi zGYYAthH`E+ywA*u{(eJ=ia3h*%k?779rk-K<0VZAPkl;TFUbmei|$fqWO8!_zIvqt z$ly$VrlH46nnpX~X5Yk0iBJl;=WuA4>~X4-f&K0yWf42h&0b30t@NYX$7egQ1Fp!a zbui-D6cWCWV&|R1CY@G8(qOmWjWeX3eX7UggZPGimA}soOuQdXe4uZ#2>5zN>qlI0 z9xk}lE=tNpX1m6*nFr2EQ3xs79!^sCldDJYE$m(qYv3q7>}1R7?iZW7>$~*%zKaC| z=$N?ME$>#+%T&MZC`dW1wUl6Z)JgyCn~V%K&i0H|iwE%$>xsZW3tTfZxIUe<xAj&4 z4Hz4+{_ST0nym-LoHhM~e(110&D!U_p#In^VLIn{J!Y#z&<>Pci@p;cRu|d=ItIwF z1clVHy{hH?@SD|(Zfqi^0DQ1hczHN7xq85h)rzQqLHMX2^IkuK7FB!kI40s$|CY7~ zNX^{_UjN8}L%Med;|+=4RNTMozn8KT;2tb77bUPCmioh+rZBfIiM6f_P34cQ__o1G zWqQp3VL~~pE5?qODf%iiQQ3f42YF@09tQ*$<v=*TB6gv{jy879dA6iNsN{5E@!(k4 z8HhaiU_^B~4$+iH?m^ArL%A5*Efo_%8ySb3DJ2+($#iHi9LOmDmMF7*5N3n2&E!HG zolrkI2!HM5qnOHg23Q1&UfD^`iFCzlg;)`TxlRkY*i!V9>4v_EKUx;t1KCPCBtgqg z@+Tn;O)a0uky_%jm+WjNB?=~VyH>V#L!*=l*@OS6SVyt_UEH&NA=?V2stHPyKkVNy z<J*73J43UcB3bH1PM2@IZw;E0-Pr(2?E_y%c)4{fI(WYro>&jg<#cjros){#ji)dK z%)We0L_478=HZ8-@xnwsKrWs8)x`MB;(Y`Cmu2c-&SH(vN-F(*e`l?c%+l$|y_AJJ zhcDGnwLvN+bu;_sX|1<mH)GAPa-4}{cUWY%Y?nWr&(mZ0q~a8r+)V&r!Qf@i3-wZ~ zk29f}K4Mv56>AiePh<L{fUUyPI`J1j9<HC~w$=DnBr|v`eP$5Ka$0AMorz8kwj<6R zqIF0X>x@u&%P$hf*xE+O=~D?_(_KGWQ!158YL-y9$*6mmPo;Rp*Dl5lm-mVM2i`h- zM@nxv590_tvMwPD_{l=b$iOm|+|S{D9&P%zeT$GgX6Akl-tfUF>tL@Ld!B&{pN39t zH>3Vhqkr}2Yul+jb7UiouWVGPNsxX7Ueba+9|~dz?d*QM$ng0DZfO0`7fAy?2yMm| zcnRzUhZ&IcwgjH9cuU!w+VStYa{p*)4IgBf|E8)sqMYtB2KH_}SfsFq(c9i(Q6S3U oBo%DI<H*|Oy`A%<=J$?q?|gu`ltGZq->*Kv;w;*%(i9W@e{{5C=l}o! literal 0 HcmV?d00001 diff --git a/vendor/assets/images/ui-icons_ef8c08_256x240.png b/vendor/assets/images/ui-icons_ef8c08_256x240.png new file mode 100644 index 0000000000000000000000000000000000000000..85e63e9f604ce042d59eb06a8428eeb7cb7896c9 GIT binary patch literal 4369 zcmd^?`8O2)_s3^phOrG}UnfiUEn8(9QW1?MNkxXVDEpFin2{xWrLx5kBC;k~Gm<qS zlCjL7i8RK}U~J#s@6Y%1S9~7lb?$xLU+y{go_o*h`AV=spXY*!!T<mOmxZ~R9RL9Q zdj+hrf&W^P#f9C!Zpp^V{wzI}^MB`Dm+sH{TR1w<4t)tA3_robX4CdCOHJC|7j+vW z%J-EMX&`87enIluaSc0_SnYUx$GzUc?vrNXt&I`o?~7C3RJ>C-Ajq!3AfU8Dx90^_ zp3}MKjJzYC+`T(&egFXQ#9Ek{*oVAaa!zrZtmlRFnwQPRJXH<%pkK2*eP`pT=lwD7 zifq+4BY_rUTa+U|2#&?i7>PVvD?7R4ZfOLPT{e<z*9Sa%-q+JZ0`uF@uf^uR0+0eA zKOCxXcaQOB0xyL&$7t}dfX{x=z?wHIs;&yo%nJr`+{Z2X98Hy3`tm$u;dhd<8yL(- z;#Sne;Lpz{>9G~G!Ls3s8JtQE`jMM9w<tfkOhc;ql-3a{hO%LC#ZWVT(nn|vd<pzY zQv5BF3Fy2~(>l2V9&Q+K2DHW0M+uQmEr%nYJ^7cK?uIpU-)=wn71ZZ-=@ar0;3^AY z5+TI{2b(e%t{2PZ<B%x(nNg1>^HKF*vu@+Xr<l6w#|okxspftdv$I9rN_GQ)7q|*8 zs5y_rF@oIq1RoU``$~Uk{rhVB^2n_8t2HJSxDFflkb2zZ+{WSl|IoP?Sr2=Mv_tpb zBhqwukeg|uo9qd8ZqP<?l)|%<*;D+JXWZi%on=Ghf-03Mlsz8h(Q+`v>&BAc@2BC4 z_vCgww#i=)ea5Vo$glEEVBBg_VPBj!)OO>)f@}#dg6ULOeC>LBHz<;*5Y;YfE0lNx zg{N+4@lO~ozxpF69qV@VOGnc248Iuag4C1T)P^(hWkpP!{h!JekX}m^Q#b2B4f1oT zIjsGz)4}-$rQ*-tS<w5Y%xt4vvDzNI7LjNDGL|1T2eU@2@{VTp9rUuZlx!D2{rUJ{ z3A%pW8$~DC0b2^P95?wbyueB1Bn4o?``LnX$Uf9F<C;}N4GLdAn{SZSlT7_PlCs0I zDBXb%F`GiL7)vk|BieTWHX3ScMxyQ_M+@in`79A|2b?#r0AHuH>uc%qG>%<4xM#E& zN)7lRK~^2VdiloY4>;#}A!yHOAXEmEi^+eA#05pawGXs>!z)gSoDuI#>bRCq-qjJe zZ)r=A`*EMX6+)~er1kdv1L^)0-PsAEM7JF$O6G8>496$24lkO<m1%2pOjtWwevM#F z42>SR^RTfUuIz%iSfn5b-t!##cs7sQI);gdAvqmn_v|%I9k;fCPl0Z)R1+hNQONJN zH%3jT9sOq*a`LF*MiY=zlSSQZ;{_FL9M07A=In+O!~wR}=bzGEQpk2!Vc0p)qKAH? zOk{(%06W#)DdICQ_S%Q@<0Y+!?9%#$gWJ%)EO-<BTe}-}iZ54sx|$u%lQFIs?k4-B z^|c_dxJ&9M^?WcqnEWyMADUCvUrhIaT;pF-+@vY1ij0*Jdz5c>>^YZP{<`oB4~9xh zL9-0*c4@B#O2ylYs_g`Ky$zb~v!M`NRaMNFYF*Gsu|7)=JyyMHjFC=HhGUE@{aI|B zJ~ITXU052%7jFb5Ys#fhS_?4kqc7H0EU49B8(Chg0&JzU=Gka#xOz1)H0d4m7ZnRA z=M^tdY|U6T!fmte{W?_r8H~qdq|q{5AMU_2It1I4143n~xL?4&K#BOB48<w*Teqll zf9X0fz4bHZ-Y$~|BFf{9mP#ye@YYTq-BICfY&StDZDl#G{Ztz02J1kC%b`U^<5ZiZ z__Fi!u{2kX`iENVlA~L2)^LW8=_9VB;|Bbj&#bO<lzgV3Z>l9_Rdm!(c^C?JU;tF0 zEh@o1y6Qa_>}#AwX{VY+`C^kNkxhgb1P5cB0%xupAXyg9NO=SnXrJUE?rQg{Lcsn+ zAZKctGLfbK_B#^&Nev|0^fB&?DN=ak8|0!np524LD25=s84BP8Vl(3=jflNp{X>e@ z637Ri5xx;&JNl+XYImA|{;XR~P*svYDEWYJ6I5!6uO~2twFC1ZQevB7#3z~(apxn& z^J@>Mc`>PJair{yT`<jZrWX;x-v7*qmDxI3P+Mg!OC%kw(l;VOuzC|8#l%8Tv4(G0 z7_1cw5ch!89b^LbMtCv$CT7IO@xA>iuan-V+i%|Ho-pA<1?V-k^R2Q<5;Co%XxmL` z018t4T0TTwO^w)Gx{9OSJ^9_|kgwX`7%0Rw!PO~@?xvnfUehvN;2Rc;^l>3kfbtk3 z8{j7p;S&{uTlTe9&HTc38q@%_KQFk<&n{vmrN7y&Cz{etcE->rq!6HL)2F!aa=0%! zM%Bwo!7TQ5t;@a_#Q}sjk{UebWQZ8{cp&HN^$*JfH#8spkhk{R@CVBiPuP@yEhu{} zsQfuhTqV%rioATpEphMfhyRYbVfVW`YwLFXUWm-===J(byMf!5;W^CV1g~2194Xx) zFK|z{pm%n-)-DRe{Qhk(d!QaoI*y%Wn6h7<6A{i*Sob&B^y|Spg!&J$`kN>zwUJ3x zaB$ciu<nSNOim3uYsQP5jc-?Naxj(j<)z};2hoFn0&u_kBM}O@VS5)nDYx1pf*RQR z`S)$xBwb^buzAY%gnq7CFpintWEa)7yX44mQ(9Sxz=?kBxk*6p@w42$*>*0FJKg}T ztgnh)ASF8njz5>h6?f#{c=<QigVeYbrKRaeqWoE+%S;th=M#iBteNh&UJyV9DiQ2h zCovT3fv1eTQ@mSXnGo$!aqUldv6@p0GWkoaEpG=8r)RRRm`|p~(T62hpEIu=ka-lH zHFz2@lD_Q*`R}K5+eNd{WnX-*hEHn`>*Yr4W_34$GmVIo8OLWjcZK4a0`+Yv-!*}9 zBwKm;DAsA(nDI-`iH@;`=gP+m{lgFLHK3m$W@?)&dGhDA_Z2xOzI0$p(ZJtH$vCxE zj>+kYNBJzs-TlSx!tSH}%I9fQv)mc!C7X0bKlZv4f&}C3+O-4k7A<p}+mKlQ4rT=l zCn2{pDn1>mVO|KYZ9ydP%(N1^uisV8y;~p`x4qFXD?!_OyN9=w(O<V*&M}1I>d6W; zGrT?G;l2v@Ob5k^8w<9w%Jbjb^|H}PYKo}I<qcU#EQV?(-;CW$3_+TixaI#lD-xJT z(AO6gph7h?y_UKm^jWi&NP`DX>~bobd!XrTbzp2Zp~H8lgJ)I3?l&(bDiWf8gE&6b z>)9GB=Iu-6%I((+>=jGP>CzD8c0oWITFZGgM!Q7|JrUYq4#^Y(vuDu-a>OWDa4Y4} z5a_*lW#IL_aVf8L+Ty}c&2VojLEIA-;eQK6Wo?<KawYbZ!!f3+b@4Ui!v_Lt9t*qk zDRw@T5NsTbrkFQA%ko%G1_Lb|ijKF_IU^teY$_8;Ght~t5fIeS9_!kg2AC0L3%DAp z)%@G=p6e~2D2qisLge~Zg_>xAuK>i;1VWx3c=!s2;j_*iRHOsb*>6-C<qcj8`@=rO zP}XMY68YV0>gcYP+Ho=L@XLd*j~2ln-;WHg)|cCixksH$K={5rGSD@yB%LI|(NCc8 z1Er8H+QO)~S~K{g?nH|2dB8SKs)BxQ?%G}}o*LV!NG2m*TmR|pWj~g`>)ClJCE#F$ zcj)fBg(dKOKmc$Cy}IRlasngIR>z~kP&WW~9cC951{AKmnZ~ZMsqup6QQf7J0T1;C zK9*Qd5*(HxW=tl|RfjO>nkoW#AU3t>JkuzWxy4-l?xmTv15_r1X@p@dz^{&j&;{Mq z$^0$0q&y?kbdZh)kZ+NfXfqLTG}Q^j>qHlUH4VEK`3y^-z6Y<6O88Hf4v^;}!{t-a zDWg;znYu%6zA1~A5~<XNrYJBS8~snn$jIDO<y@mJydzi%ZH$Z$)QuZaz%45=1m~)~ z4Q`zYwLIYfLfxmU0o|G_6zFY@4*h+3cz>w?<TWDm>fxO~i8-Ib(^02{c4pXjhDI^2 zXB1LP4dvWuc%PXQ{r!d#6>${rm+M8EJM8yf#!H$Kp8AxwUXm5`7Tu-J$mHe<eDz8P zkinV!Ohb>CG>vw|&Ay415}_1w&*9K8+2d3v1N+@a$|820o4u60Tj@u&kI!~q2V9X; z>tMvQDI|O$#m+m2O**ZHq`_{#8)ry6`&5s~2k{O4Du16Fn0P;&_(0!e5%Bel){nU0 zJX~<8U6hoI%yx}qGY_1Tq7YKDJ)ETOCs&W)TiCrK*1%DE*vXdD-7hwE*LUgjeHRM` z&@pkhTi>m#Kc+QIK+2Ybn9-sFVKNHyIgfob4H_77yYh))Rq$7Pw|+aD6&yZ|ki9 z8Zb6s{oBt1G+PgfIcxd}{m@~1nzhe;LH)5;!gS8@ddyabpdBc?7JVl?tS+<#bPSMT z2@0uYdsWN(;Ww)n-PlA-0r+62@bYkEa`k{0s})fJgYZ#5=DmIdEvok7aZJRi{w-|} zkea&<y#A2`hji}_#v2m7skndFe=lVxz&%)EE=piOEcJ&sO<`_b5^G%<n#vzp@oj^X z%JiB6!h~{GSBxDmQ}k74qOt+84)V%~Jq`#i%7JivMeIU@9c}EI^K40lP|4}S;=!@7 zGZ1<3!HDW~9HJ?Y+=H6KhjKBrTPh}kHZl%5Q%W!nlj+c4IFM2PEm3CsAj}43o5_VX zI-!1a5dPZ9M=_Q046q0ky|R;>6X}ZA3b7&vbDb7)v8CuI(+zzSf3z&P2eOrPNP?D~ z<WE8xnp!@QBele5FWK2lN)$}!cCBpfhDIq9vIqZBv5sQ<ySQilLber3RTGpZf7ria z#<%~5cZOy?MY7b3oG#yZ-x@S0yR!k5+6TUj@N(-|bnt#LJh2{}%jx9MIwuve8&6>f zn0@)0h;~5F&BG5v<AsTOfLuEFtBLWM#rp>OFU!=woW&ZSl~nrs{?1w>nWfW_dnpTd z4qvLDYJ*ft>Sp%M(^_xCZpNBn<v0_^?y$&i*)D%LpQp$0NyRBLxtjpMg2Bt27wV-} zA7?@{eZ;cBD%L0_pT_h@0b7Nob>c66JX}A|ZL9IENM`U>`ph7d<+RQiI}@E8Y)70s zMC*_&))}GlmR}@{v9*nm)29-=rn`Q$rc^4G)GVQHlTr6BpGxtHuU(8AF7Ffh54?5w zj+EYT9>x)PWL-iQ@RNm<k%46_xu3)RJlgba`xYU0%*_29yy1gU*1=vg_B;a@J`J7P zZbtp1M*r&3*S1r6=Ez1EU)iWolOX*FyrcztJ`}_b+S&bhk>T?R+|c@=FOmj)5Za6_ z@DkVy4l^L>Z3#SI@s_eVwd3D)<^Ivq8a~J{|4mhOL^<7M4D8){ut;GIqqn`oqCk|x pNh;Wa$C0(mdpqYz&F>xK-uVD=DT5%Jzh8ZT#aXmjr70%*{{RacS`YvL literal 0 HcmV?d00001 diff --git a/vendor/assets/images/ui-icons_ffd27a_256x240.png b/vendor/assets/images/ui-icons_ffd27a_256x240.png new file mode 100644 index 0000000000000000000000000000000000000000..d9dc50933653200e041d37aa53a93d62c47bb989 GIT binary patch literal 5355 zcmd^@=Q|sY*Ty4}Sg|)zYE|u`wI#ONCH9`xQd?|dtD4`|Xi-Y3(V{JCM%0KEvu0{j zl!{rKU!T9@IoEmdx!;}pesy2xxv`-(H6;fn005wVsH0&50FeAcz#cj1AJrO$`TP@q zjP;S4m*Wxte|8O5wD8ZkVW5ejDS(Ymij>^ABkr|0FVYv`?#RJ_hw><~sOjk5vKEvy z5lxUuis^dVKZ29ffVDSAR5z5RRet&^bXCMpq=W!7N}aRc)p{)!YN>cfWqEjv>s$c< zj1CVqRFNSCf9$AS2#xfReqHN|ypqd2&c~<;(b+G8;cx{p8|l`q@tW<cn<D8IKkPCf z^T&j4s!`6nu0vnaT>u?v0vl;yk=hk&VJihX@&PDB{&_<H)bv@7df%jFU(-6r{wnO% z%J|fpi4r~IBlh7MtzSHF)8mVb0b+rUJDZ4LbLdH7;G(IfnD+kCX{Ow^%C>5G{<GOC z*Oaoe9U7h}YrfrI?IZzo^OLm?M(*s4*0~$zSH>6r5TgEE90QXSXzJ$k7t*j~wA5oM ze-x+x)m}Fr#3amKua`}N?FOd}d=5kAeNpYKuWQ_jx(Rg^LvraqaXVx+tu__XL;vnc zhH<=7;@RGIj=3ZhObxAS3K+Hw&-a@~O^Z7;9k|T!ci<nHIV+2(f4*N!R<ol*XCc=5 z(YiuTjYDU24wjlSlPkg>MP#bNRkr{|+}@|{ePlb67nbk6Vb|plUN_e`FIx6F%pP9F z_4(x@TEyd~PM_Qi4^d*PW__x=R#4?8QKoq*V4boD!HW*4PHGn}v%%Q=Iib0TDE1SR z=_>9tJl_~ZSAJ)QH~O0P_V0AeneHH1Vc0dBKS`XrTN>eQ?iO6QCh$6VRfUf+mt+)$ zU8mm|rZw%|KpjFM%kLXLKnJ*6qxnSL7>*n5kW_wG68%d#5gjgzgte1A^kk*;TTXXh z-|fX0&N}yiT7X=vDbGLv_eU<;S5W<gNg+6ITxm-cfzOJo_Qi`)<I=l_ml^60)NPsg z8O+7rsMZhj(~M7zvpN?*|1M^rS){QhGI`U_j`H@K9JOup>zZC-qG~B!6x78>*K^G_ zo!-9R2)GJTx06+(bCVTqYm=e)FgM=6I8ZyqZpKWLG1(2XU@iC{_WB&J-obLzhmtMn z3POep2zS)WpN;d5taq5l?@WYUFB^4h6(pH8lQV(kmd8@>0<5CiMA(-ERxCfs5KWOz z78>)WG!_$mZcl?C+4S}kV=o`F5%C7Jk0l&9XbjqY+<0dNtD@MS@x<L(p$s@TdYL?7 z@t^FGSi;xnrD??k>08So$L<V&|09<TE%i_4_`#>%T(~A8@8W5|YA1dy=Vz75=E`T% zzVDcM1?Z@qJ*nF8bTYH|ERX-ocPU{E7Y?f7?~TeJ|1z?AqGJV%U2pvT;=WW|+EmfE zUrXd@u0{KZUvr$W*fY@Ro--jl!l_df?ukKbN}zhMaS5Iv{l+2qECf*MqpavU9pc3~ z!v&&c#%d0SGj^P+D!`pG4Wv5wwfz#+M6x{?Ns`pTDuJ194n`z$ouBuxuBT}glEKDa zjhdN`Sn6X{)&5vqm(7-V5%x`17`<zQ6TrM1J;7(RCL?%A#`1f@^9Vk%dD&}D+K9ed zp-jynJ2-W;L(l#PG_GRjGfdQ#wQ^>4!^x(Lf^=+HH#xK_qNN&1W!$W)TDMFA&2)t4 z5%1Il85`{McIiyEUksKpME5j8Rat3~N2aUz2k<w$9^u=-tIm4)uQ=!lZ>Mby5!Hl& z3}F4`&BD3k{r;e;Jh?t&D$?kIT*Ma=7)e;H#nN{Xc<J^A^PFEDueQZt#hW+lj=}i% z7uyycs;kSb8yi}`#PD>EP7~YJ0JmzpLT}ztw%5)EYIbeDBKOM{I!K}muBfF8wCzm0 z(#7wAteiqB2k-7Lbj6V+Pug6rw<?uj-ivIi9N?$|o^{YKZX(mBSZ5N2zXtTz7anwr z>Jb|2Y^#!w2~VCna=R@pa)JD<FyA@p0jvY^p-yw7m6R3wr4f*kw|61>Hg!;>tad4R z`R^NM?6(t>OGfOmF^0~#C7plmlZ50vOX-;~%JkxApoLa>o4RHf0r0C;0wSd_#-8mF zxTpUrZ4}NiDaWCx;-&ORR%>MwwSZS;M|k0}|8C_@gANvRnt^uH*|5zEN8dTUv>-x1 zt^&~y(5-Ml+jfBIR-!EpfY?cOc42PR)zneOShI(+KsS?+9dz=(H2N`GO5G$4o)3E8 z_UF2Dw43>r;Fe|Bd+_P*hv^U$M4Ak08w|$=!<8XYz<zVvN!rxulWv5-yDq<qJOV-s zW>Zb3Sl-QjjWH9VjK-MEklM>N#e3$!1N9OXFH?ebg&K+F7*ZhqMc}eDGVg+#Q_s;e zb>Zw)R#xmc8eTPJ^gK!X>svx-;&-cWm&M^_KY0yXBN`_`mRKESW1i+RQYopw>7Bj( z$AH6IoJE8!o=D$d<vOAl@YRyi<f7ddWRn=W$7MB5Cw(Xl7tkYEPXCa?RVf5|EAbwi zH~!mV->EM=yXeKz{lmIPoD%jhBU&Ypr`Xk*rmF(o$K<eO?70N(oqeT*?-R@qm6x7c z8)w8G2i#FLNAHXExg&d*-X38i@!C=-NH};_G{RDq?fuZf%mavOlA%?9liKI2g|OP$ zmKf$9;*vjv*L>O(k&hK3uU<WhD1z4){fChJPochWWHlv&`=cVbYxT%4L9yk0d1><N z2CA0w^IqSQxE#5UyFeJ1DY=Q!ZXZn|BTy?>Yb+#ncTdoE6e72h#uI#F1UY~S{aSXI z*B$~5-D;qmX&0-2Ph6up>A-#)#lcl6xQt0F(s6CDOxhe$#E`=#Q-zf3$lb~n5WjE< zS$fc4Im7rfGTi#f$xdpJXYm+#L8B=DKzE{u<8o}j)YR5K45|+n4bp14WC&~<)C={9 zr8{Pfe7ZX8>hI3Kj+g$aq<T*>30D*jWn%MFDcVk+R#0~>ej}dSYu1@P+a5lzT2|}x z)Wk48hN5hvE|W7J26{DC^oW83vcqDU+JOcaeg;U;*<r}==E&S4KPbRqS{sr*uquxY z(B!ucZW;j`I!$v7<1<(YT4pIad<-4ulN4?|<k~-e-Mh4A3oe;AmsQE}cA7A<A>c&@ z(9E6v#10u)ijEdTRlYqZq=p(aofwmIbkS>6Yv|ry*WQKn4RbmN?{QG|qRkOT5)vIO z2cxEcM(j+Z=SR}2gF`xy-h{ar+A3@9RX%dVYu;H1wgc~E7ZB5sGFh<M_}5aFa?r8& zs+4AG|6Ds9wR8HtK4A-vF|XOGw{Yl88`iSIS3VILFuRj=xFADi{&fZVo@rEeg>zIO zlosi@omAz&O7iDjn&p{$r4gtIGC%CI{vMH`%ITwGaY4no8tn~{D$|P=o@aH(l^dM= zO6&JfsFuwH6yNVLI2Res;A#quH~hQ9uGE!cOrh`NJ=3oOf@XRsaN}O17C0V8CCG1W zWVh(?+;?xGcFo)1?EVID8UDMd{8p~COkPf!wz^qQ=II^^QnyQgQw|HoGCnDbU`L=N zT@0BM;)ecS5NAQO`3;r5D3PJcd(4RzZ^qYK{dEa=CFMtjh0p3&ZIqYC*dV(?pd3|c zeYQ+&`MmDrlK!pb1a?ab@{FNA9T4YWd4J~vg~?AG@3_OB=w7*$)82V?<1QHUJY!3r zFdz8308a)OLPg%|+Pyyk9g0Zk>J`W*G^PnGNsaCkebliz&v;fB_8mg1Y|(!fT<Y(d z-+-L7zDg^3(`rQoL-L)dPm8l}af{|AMCD;d2Lk|lhrY@?2ghp8Qz@u&`Fk%Ky#-vx zR(ENL%U6bngO;3f+)KNPXzuf$$d=o=>S+|U47=MTve`AbG|A$8<zcEHT`0Q!V55n5 z9myAmL?gJ<Wquy;UI1_-78Zh&k^=9YI)x=m`SPt85mqA*X2_Org}B1~8^=r2T`q$W zTM`VFtouSI`jBKdN_MGyoVuBv{r29q<I)!^;sVDbV>&6G%PZ9jmnDoqW)?lq{1nX* z(h3X639tAt2L+vuKC|$S*;N%lLt$-~8k|BYU4EJSfJd;4>!VL++w<@3DyI8b?APLS zHFh0K)>S1Bgm^-l{!0j>Z@RVI-vx~AQ+*yDFPc)+KPQ6DLx+j5Q5OFz@>Gtbe+l3a zMx_wezJIfcTgYCzs!~#+@wLgP&mvc9@wszF$?SxRbZ;=$D@b}tfe2jdDhY9a+AUX1 z7X^ezc+B`3lcZwrEP$n?q;4rR+M^bw;v7*w!|yo85lF8n_NZg+*(2o<nS8z}IO2%% zf#{t&gbwK&sCtwoPzT&Qz)c@#CK)m4Y_yV$j)1uIU(}BJQYgn{9eKJCpnvl*!C+xN zzSVc7OD|=|qV-f5=$`-d!L^T)g7|Gm&t}LIdPlU@wO$wv^P*no0^6bSU670$-&fL- zJDK!otq)-^IWm2;pp-AIc9Kf_s-$_8W!$6APGFqTm(!0?v9-5JHTNi)>cMsSP{}|} z{<*&J6k1C1*se>q=u1j12FdhrFrC)$DmpbagCqP;XUuD7>${@1<w8oW436kktmNUA zPhIK)D@GtSTXz9#uBv=;!>2n{w3rAzc@5U5k^#gfx4r_r^)jL&k@#8d++CFfJ$^1^ ziGE%W5JcA{?EI`b1HE=Ed^^v^Zi(ZzK49kvKBCS47iBula_f|eu*PE+%*x$33eKXN z{SC<^=K0S*=@VvzzxV{{3MqeGn>E<Vv8UmYdk8k?i4^_h9uJ5;y#^+zd=j}0z^KGz z!{0!75?c`U?JrN=E}yEc<!Z<sT$B15jW|7ajer^BkTre>!;cU6$436*GHB(Vytz9T z@K;ilRXvK;mP)~F%KXiPqz$tsO52_-#{*f}<zJ5G_bS&x@yFdR2vYZWLy5TlDqM&A z+uY<^#shKYcETQSN`7FWE!)ev!QxpAfX&>JxNzB)CnP%CL6P70n{~aV3$R-~mm3H$ zPX@~Ec>S1mhv~C32H<)O4_-DtXGn+*?Xy^B9*q46=<MmyYyo5aXB$c?Lm##YH<?76 z1EiufN%xTDQRhs`hU;6=4RUUiw<(0fH$}Df#F~lkNcX4|#I5QxI=LP*lJf`=UjtvB zcH7?;M?bAZ!yqz!_7A|slphU$fcJBJXxS*(&eb9#qRwpq)YEn~^or_c4U{%*CUbYu zSz}JsV@Q=l+0}Q;gA(C!dZB`qT=<dq`0z(Yg~Opg?q>DyRd<!N*ZN<Nq%lOLZ#muW z6tuu_Rd0t;TaWzMdDotXTr2xCU8aQcP@TSG4{SS{&3?@LjWzFe<3vtJ>^@l-5-|nB zgq@$`CrzcSt6JVM%10upc+8wm#V%_uhIGJXziQbH@P@L&Z!-6$9*@r4Q}o^+ykK}Z zPU-GDuI4E~`UTu{4hD__Pe}J(gr3}<{J>|2ps;Kqy+5ONPP>=8duZ_uvEtyQX^|?p z{QGwhqHC<8q`*zR)$sR5!?y=@w*jtyxvg5qwYBd2p{a|x4(LK}1N~K>*GgCluJyRj z9#6y;S#kwd{%7vcc736i+_UJw`6b(;!{^-oB%VubN}js@*<scq`$_s;u2elS$aLh` zNo%TQmzP2$RXy><hm%u{ux_Sk06vi0W1j9}HN1Omy5e9+Ra<Tc`IKMNGvx2upFK>h zT+Wd&%u1>y90a1Js|%?e`qkPgFB%?OPk~66!&Ej%TTG4y#>==JS_ASg?O0_%yx8YJ zdbE$`8a7QMb3--Qtc4B<n3qe{slqg8p(e+D1OmKm8FUIl`TObt*PlFKFS5gy)@A(K zO`7&zDuxE#SAfG$ND-tT%<qW5MMZnXxMX{g$jZ*|6xff<ZCLDJsM=nYK6-r8jJFnJ zi55(_Kku-m0eBk+-`KpTd6u75$&jp80>&bNB^%HMMnmGRA;s+5K0n>(5<sf(V*8j` z=d0U%UAS<bjiIO{gWcBfwavN^2{AI=rMO-1gBvo=xVxQskGu+=dMXQW?=Q(zu(C8w zKR9BWk1TGz9uLHvP@aTZ*1b$?-IUhrOOe(1My60*{cLvpIE~mEy%<hE+{To|jINdx zYbzp?A|TC9^a)cy<L*S_z9lz;XKOk=!hr9yM*Lp21Zor<#==b#!@Xw7v~cBHqy!t| z5#U>$ARC(5>2?s92i;OW*y@$|B)=wvU{gmVEKy+Ntqf|LJl(N;Gh$5sLx?W*{DDud za^#t7PTIgECPY<ls!}n4<|p_Rv9-{O(CUrD#YMrrX7OIjxWu0lAM=B~vXH>z@$dTC zES%%GL=%knK2EEx<l9RNR_9-fssb;nULHO?c|2XY3>)71-u}Mx!<_?Zc@w<-?-K(P zl1=l^2UG8!129uqv)Q1nQg!OR-#sF8za}M%pY$nz=(93qXJ;=WKaE7+K4;k?;5UN? z2|2fb9khESqM7CrYOVK=3R7yo6Gf>DSo-&9#V^&rM3A&E`=7l^xTqigK0mz)%4}_< zu(nsc7?<<~3$DKO;9Y_2cV@u*GO#|eIkHhcUf-Qad?BJ<&HfH%Z<d|rMn<%B$jNO# z)}zBbuF_jS1D8%n5;sM(9iFMx+AK64k?&mq)Q={={dfKMscG2!L1US;loZ4<uy<jz zG^wC^VoTxl;voL*NH{ao6_D<z8M~^@f>kF1{~5VJ+=OeUQzoz}z&>%<POMK}RoEA- zPyi?|>EOZuMM8-@S^}-suIl4(xeFsuB5<s)u9IyL&?`HhM^_mQU@xj5z=tz;nBq0< Yc}f7RcoVYzf4|I!nuZ!RYL2o017zKHzW@LL literal 0 HcmV?d00001 diff --git a/vendor/assets/images/ui-icons_ffffff_256x240.png b/vendor/assets/images/ui-icons_ffffff_256x240.png new file mode 100644 index 0000000000000000000000000000000000000000..42f8f992c727ddaa617da224a522e463df690387 GIT binary patch literal 4369 zcmd^?`8O2)_s3^p#%>t<I$5%B*(%$RifAlJDl()+*_W)tj4atJl`V!4ku}Mhk*o=k zjAh1XB8{;#7~8k^`}6($6`#j>oqJ#RmwV2==ic*rz7lOw=eaq=H~;_ux21)-Jpcgw zdj+hrf&W^f<%Qk9Zpqf#;q3n5{{POY;f!wmTR1An9(4&I0z1LNX50QSTV2M%4|y9c z#{ZQIVJKu~aY5?ZaZP*GIGqGs=e@q6o|EPhZB3CC?@LnORK8O@z{{<0KtSn5?#~OW zy=L;x8T&*%xqElS;s5~Pjk7d2bqIaA<dW(>)xZbovnZd7eX17WNxx=w`p(8vulwUZ zl{so}MuRNJx5!8S5G;$o2?BApPHt+)!^#*Ww`?rcVE}mcyuY`X2o|uVUyI9o1t11O zemGWR?;aD#0$vJhiPhv~0iXS#iLq!>Qd<?G%nJo^-p4Na9!-~9`SCtu5pb5a9~>$` zU{}<|Vb9Md>$4TMbL7C3GP#r;4Wc$}Z;^j;n}yc!E3d;<jpV}POQ7Zg#E;Ne*b?}a zl*C&E6VP>`wry$!JkmJP0%(tIh!!TET8=<Gd-5-}J&kJ?em(xME6C65GA9%uz*QFf z6kM7Y1~y|ZTrZI;z#@<ilrhg{i!qH~v+ffmr<i&f#|opJs22Wc^RvZ0%JzeR7uZT} zs0FX%F}(c5BtI1x_sU>+{rhUi^60G0t2HJSxXv-*DgC(HrJd8`|Dp3NvL5yg>xAvU zho|fEA~w^-HrW&H-JwkqNX2I-bEXBR&Uhp+y2^)1h1IIlNCzC!v-Mz@&z&VPz+cl1 z=f&f6Y*U~C`ixm4Sy1hl$hg(4%Dy;bq~k7d1<@K&%%NLT`L+A)-QXyKVswX?op90( zB#yeFEih@c{OXU8Oq~1CFI_38GXmns3(`;W(i+bslovCx4u7gvK>DrGOug*?G|1nz z_OR}|ZYS3pq-p?rS7G0qa`TM}r5XqDT4cV>%Qyk#9ES}`jc+Ww|DcbZrF6UG>CeXp zOVIV}K1e#z9@tu#?X)Ri=?zXMB`X3G-_I7FL-Zq`nbfWtX_EO1*!+U6pJW-_k&+vk zMd}THh}{(Ch_wPk(PI4vVB_KT76kGxVytLxpWg}&bHw`a3G#QzxV@ICNax&@hk3<_ zBh`Tq66G{-tCw$V{(y0v7l!tp20~@gdFX<t2yAf7TZbU4H+&N0D2hZ^a_6-I(yp$A zLu-4Y{Ez$etx!T0KE1E^ABgv-=`PL?WxCx2K`NJ9btEB~b!5>jzFbF#bJE7i>T4ux zQdrF3org^wFcnw$#bQMv@SfN3$Fuo7HnB_`2ZGB{ZqGr>%xP;2_!Q{=N-ZhU1c~^5 zdt=OO#wmcpkXJyCG?{{&n=R{Sn=Ytg;<09CH)l7TA&wkt{Q;>RrA2Ia6-QixEPLrU z%0)N$3Nh0?U825&<F9?WK3>v($Sz}0G_(!v&xSSAzje4{rup+^W@^}ByqOb95$<wN z+FlC*OS+|hQqPCLLP#G|{-Gsx{l!c#$SvU|*<FUbs>E0sbwK*%#GP}!6`%*Z@L;&C z3^dE&>5%bWAXmP<sMdk^(BGixJsS?iR#(S<snG+CmKd<~(&IF$#~B&)6d2mrDuBh- z`7=YP#+9XUV(~_Bik5uFl#L+MA?9LT<$`)GritanD!@)!d!CK9hHX$6M-ksae^D`j z3O<QKrMApfW9&BT-mgQopCLGOW;!j??cokAvs0*DB`{2miv0!b50XsS$yAy~y>*X1 z_m}Pivs*u7@9i>qA!58fDCwj^M<1P(u^m;urVdlM@>aIf+E3-d9<VM%qyk!OJVCWh zPAES=A4hZJY<Q^6E;Y6VV~t?=nmyu9K5i(m`ONw{XX$4$>ZW>fc4cS7w5O3sCmKKn z+94A?VyfSBb9{}rEbCIYtXORJBCv__fnZ>?a}edaA%bP$jI?J^q0UKO!mduA8U!3b z0CJ_Js}NWQZoebapVUHP%pPOUm?1<)zd<fq;MhF{ievF2n_&PhASNq*%9zmiH6XNj zEs=Ea8SWPuzGGlUp!TE-8qB)a23IEsfKm?dH$i1qxCT5^L?@^KA}zidPI#gv8Gk-X zqM+_@h7X;V9#72a+y&FDD1Goq_JL={tjxBl!n$f3IRf!$mA(-L;%G4SRZ1!Xm1z2f zhjX-H01}>%`hzUM-Y6g1z|@@3G_kio?S0bcbjQuxJd>vU$Uyz(4*peEDSVc-G;O;% z9Y97%Tq}TRsH+oN%2u(oyC=W<9`e@&m;i;jC%L;sP(9RBDQnth3;ZMEQNFH3GEf0c zU<3RF!hNG-vCDooYFS^nPlFnv4(ElI1=vNcr42TF^u<zpNG@plq%<5<WA+sLT^{=- z*SKa`IfTWbzHQm>q67f{MoN>{f&>xA91r4pz5Zc&@P^i-9||`98v$Si!U@}ouZ88W zg;YL=OQ;4}UQtkpyd~lD{qWy0H|lwJXKmenz#E=*9kt$YX*X!wDk7ITlIUGWnj>a7 z<_GQR752@J)Y(U)ncu(d<qS5Uh{rKg3^Vr2bD|>Iit7P}oBq8x$FP85)&Nsw<#rOW z8U_x(1J)Zgm(8tZXU%+(yYcO+Z7#ZszPwa2`ygiMPayX9KondtFMRK!7x`9uWN;(f zfWW?8yOdj;GA3We0YAW92gWipn(d>zcbA+vZ_21B<GE0ey*BZvJpq=xH`~tz@gx|c zR1DNG3&a$spo!;l*pkkI8!!LndXN^Ms=PE4MNl|PaHUi;bw5F9BU%~$>xF?-pfcW` zbqY<k8GOpfKgG8NmJQVzlhFBu6R$nBAX~7++WL0raE6k7#bPQwo<1VA`kZ;~fW)ih zqRHEcmh$T`EO<YY*CCdJD*xhpHDX3*L_aS^FT1A+oMlXy$~;c#+7(V<3O2N-e%AuZ z6YUffqFHBX<0db?COgL)pQ{`%3Wzwk*NA!or_{An@fOVM>??6ie(6M)p@6@WQ?Tl7 zoKrKEj|x~2yZehhMLkFRRnOC>XL&L+N;m0B{_OQ9gzzTYb!!Jct=bk?_hIpY9rOwY zMnr69R(?8EN52qR+k!~qnCYc-KmV&*d$&NY?t5cjR)V+ncMor=puTRoo?{5dH;@!* z<~RrV!+ljAN+;Qx2LraY&JWnz^|sYbZjP+Y;|pC#DuHUH+>F~x3PqTkx)=OAE0X9( z(AO6gp~AH^{nq+n)LHYDD8mQN?DDFcd!U&d4PaajzSD1~lXq3p{x=^vItrq3gD^4O z=hYS`?&C-0&KuAV>Jv}T?ba0IafL$~+bZ}p$9lwyyx=-uPN`Hpvv<)Ia>OWHa4+N4 z6zscrW$^XA32E<j+Ty}+?MPo5Uc!qbGT;`7%Gx?l<xc9YfT7LQ>Jw^7hYtkRJr{Q8 zQ|*1pp_q6Mno|D6EX!kgSv0h0I3~ef_l%$<u(@0`-IS&EL||}ZN1R(*I)Ea^7I-yG zyXCjhJ-1uF(Uyz)_^9=*N_DY9KS79>DTFjL`0y16n%^dGNQn;2V82mqoIi9i{15vu zLq&(BTl9CInUjZlTIa>^!!HlMK3W8Sd_Ow0+E8IT?h$=55$^Z)$WYIuig=O;Lp_1Q z4wOT;XbWQ!>Mh`pdXuSo=K<ST=}P*!xodlEIBHy%5{U$VZS$wEkNsG|u2<Kk)WCyL zzTvy?7M8&Cfq_5@YIV!+<Rn^wt)5qtp<xK_KFldD3M^WAGlN-UQ|ANEBYVoG0w3xR zek`?_!aFWQ%$ZEAn=XFHElm{gKzw@Bh0-LNwZ&Zh?yZ%*15_b_Y4{Osz^~4Oum!!< zse&!G<a}e~Ot7vdkbjYnU^^LjG~ETn>Bba;wT!wK`Hf1Ueh04*%D7Kfj*#b~BNfvz zsbf?uiMm5-xhaQ|7Om2OrYbU>ngUM9%F5nU<65IFyu(`yZ;Vb1)=wCd!L2K?c$ezE z4IbS|^?Z>)eEp}ZfjwF)Waw?pPJ?{~*g%;e<TX6&>fxO~Nx7dQGLWZ)cPQ*T!((W- zGm2?tM)K}7oG<0Xz<`ltWjxvE<$AH!4*R{A2~uYGr@m!vm*j+e#CE9^*}Oc#uihB| z5;#kMY2^8mrr80%*+02bDx6B{Jsch(d7kQGV7~iGTgFZBu$Pf`tNf`B2{|t7fGhIq zos0xF#l$bfxOtcGDd*MDbdKBaCKxg<zBS_t!TiI&D&FS>CEbr8JTNd_1bjWC{Ubgk z9~)9;A1&=FyIt$l!VBXfD~6VCk0fjO%QwLJ7k00RH*%I8cCqF542VzP^;`OU-_?=< zbV}OoQE)HqV`|)X5+WbgSxGWH>t+7-O;(l~Z+FJJ)sygu^+eF01#Suj+pnAcw!s>p z$-xF}c>7t9X6H$^V9hvT5H{jKv+=zzWHA0pgw8e5fZpm9vIphVq3%S4*N3%&jsY^Q zK%sSPuj=?d{ATs0o0y6#0w3%YT^@-_sTuTUwI(Q{;l3KjeAbVk#Wmi%PDxm`zoqQ~ z((<-}*FSP%5gt7uI3t1&75ne{@1^bpdW1;MMGNkSr~UAuDbB4+VQi|x(gdO^zin_) zncfs2hj8xdiiy)@vVkfkItLKvsGtJh<Ah+N9r4Fk#4j}3)5fp4%$8OPm!2*v85$2i z15p4UjH=DV!<+L-y~sIS7&k+wwQ@3eBlD0ewG{0*l>rTb0T~tFl4Q3J!flauS==b& z6B<Vc5wD$nmC_i`0E<AeD?2H<QEoWxP-{X6_i15QJF-Cv-N-NLN9%$|5L;=d6lmF5 z;UuK7x%Cq%N?T&~lD+MeWZ|S<_sZ68ShNa0XXqal>m<Ivi+wgAY*(pVJxOj3;P^Mp z{Py4Q&hV_4XtqYN^W_`w+k)rhb~b?0`@olx-tL`?jy^9&Cf7sqxSSo^=A<Kc6UYof z^DkeMP>!g%dDvlCf(St$kVofvH90|9yl-gmvRvcKS&Ye9DdoTK@2m}iSvC{3m%4E0 z@TJD7c1V?!URM7+t?f3)%{X(6JXg~A9TvGQyX6n(^Yt0NX;>vDPcr~mICPooLWA_` z<1A>FuXr|C)dtDr*PQt%Xs5WePWUB&gBj$zZ#BIY%?jDdpbSA-PV0`dGf^oa_Jp}Z zlrGV7oe`#B^+nPIQ`ZDJeJas=ru#=*YL#+n?Go}f33>1GsZ{TTy2bdBihj}mz*mp! zOzn%{WgLM=*CpiuKUs*GnHa{B$2siJqfNi|Z;|rH%stM*8b26kAMCYY&NHwPGtlYn z7UVx_^sgR$Z8x27foS63FCP<b7NQ@4m$W&a4+pb@c6L8rWcYppH@1D~kD>t|gtcG_ zy#@C|!VQV~TY}G5e57qp?F4jRxqq~@h6^?-cvD>ySwVLl2m7=gERtEn>Fw_@ND%pO oiVC*mbz<%I+0K1Z`+LWvZ$3~$+A!Gm?^hpSc@||}WrmLVKLvuzv;Y7A literal 0 HcmV?d00001 diff --git a/app/assets/stylesheets/jquery-ui.css b/vendor/assets/stylesheets/jquery-ui.css similarity index 94% rename from app/assets/stylesheets/jquery-ui.css rename to vendor/assets/stylesheets/jquery-ui.css index fe31070575..77c68d3637 100644 --- a/app/assets/stylesheets/jquery-ui.css +++ b/vendor/assets/stylesheets/jquery-ui.css @@ -59,26 +59,26 @@ .ui-widget { font-family: Trebuchet MS, Tahoma, Verdana, Arial, sans-serif; font-size: 1.1em; } .ui-widget .ui-widget { font-size: 1em; } .ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Trebuchet MS, Tahoma, Verdana, Arial, sans-serif; font-size: 1em; } -.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee url(images/ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x; color: #333333; } +.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee url(ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x; color: #333333; } .ui-widget-content a { color: #333333; } -.ui-widget-header { border: 1px solid #e78f08; background: #f6a828 url(images/ui-bg_gloss-wave_35_f6a828_500x100.png) 50% 50% repeat-x; color: #ffffff; font-weight: bold; } +.ui-widget-header { border: 1px solid #e78f08; background: #f6a828 url(ui-bg_gloss-wave_35_f6a828_500x100.png) 50% 50% repeat-x; color: #ffffff; font-weight: bold; } .ui-widget-header a { color: #ffffff; } /* Interaction states ----------------------------------*/ -.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 url(images/ui-bg_glass_100_f6f6f6_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #1c94c4; } +.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 url(ui-bg_glass_100_f6f6f6_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #1c94c4; } .ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #1c94c4; text-decoration: none; } -.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #fbcb09; background: #fdf5ce url(images/ui-bg_glass_100_fdf5ce_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #c77405; } +.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #fbcb09; background: #fdf5ce url(ui-bg_glass_100_fdf5ce_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #c77405; } .ui-state-hover a, .ui-state-hover a:hover { color: #c77405; text-decoration: none; } -.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #fbd850; background: #ffffff url(images/ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #eb8f00; } +.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #fbd850; background: #ffffff url(ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #eb8f00; } .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #eb8f00; text-decoration: none; } .ui-widget :active { outline: none; } /* Interaction Cues ----------------------------------*/ -.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fed22f; background: #ffe45c url(images/ui-bg_highlight-soft_75_ffe45c_1x100.png) 50% top repeat-x; color: #363636; } +.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fed22f; background: #ffe45c url(ui-bg_highlight-soft_75_ffe45c_1x100.png) 50% top repeat-x; color: #363636; } .ui-state-highlight a, .ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a { color: #363636; } -.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 url(images/ui-bg_diagonals-thick_18_b81900_40x40.png) 50% 50% repeat; color: #ffffff; } +.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 url(ui-bg_diagonals-thick_18_b81900_40x40.png) 50% 50% repeat; color: #ffffff; } .ui-state-error a, .ui-widget-content .ui-state-error a, .ui-widget-header .ui-state-error a { color: #ffffff; } .ui-state-error-text, .ui-widget-content .ui-state-error-text, .ui-widget-header .ui-state-error-text { color: #ffffff; } .ui-priority-primary, .ui-widget-content .ui-priority-primary, .ui-widget-header .ui-priority-primary { font-weight: bold; } @@ -89,14 +89,14 @@ ----------------------------------*/ /* states and images */ -.ui-icon { width: 16px; height: 16px; background-image: url(images/ui-icons_222222_256x240.png); } -.ui-widget-content .ui-icon {background-image: url(images/ui-icons_222222_256x240.png); } -.ui-widget-header .ui-icon {background-image: url(images/ui-icons_ffffff_256x240.png); } -.ui-state-default .ui-icon { background-image: url(images/ui-icons_ef8c08_256x240.png); } -.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(images/ui-icons_ef8c08_256x240.png); } -.ui-state-active .ui-icon {background-image: url(images/ui-icons_ef8c08_256x240.png); } -.ui-state-highlight .ui-icon {background-image: url(images/ui-icons_228ef1_256x240.png); } -.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(images/ui-icons_ffd27a_256x240.png); } +.ui-icon { width: 16px; height: 16px; background-image: url(ui-icons_222222_256x240.png); } +.ui-widget-content .ui-icon {background-image: url(ui-icons_222222_256x240.png); } +.ui-widget-header .ui-icon {background-image: url(ui-icons_ffffff_256x240.png); } +.ui-state-default .ui-icon { background-image: url(ui-icons_ef8c08_256x240.png); } +.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(ui-icons_ef8c08_256x240.png); } +.ui-state-active .ui-icon {background-image: url(ui-icons_ef8c08_256x240.png); } +.ui-state-highlight .ui-icon {background-image: url(ui-icons_228ef1_256x240.png); } +.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(ui-icons_ffd27a_256x240.png); } /* positioning */ .ui-icon-carat-1-n { background-position: 0 0; } @@ -286,8 +286,8 @@ .ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br { -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; -khtml-border-bottom-right-radius: 4px; border-bottom-right-radius: 4px; } /* Overlays */ -.ui-widget-overlay { background: #666666 url(images/ui-bg_diagonals-thick_20_666666_40x40.png) 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); } -.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 url(images/ui-bg_flat_10_000000_40x100.png) 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }/* +.ui-widget-overlay { background: #666666 url(ui-bg_diagonals-thick_20_666666_40x40.png) 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); } +.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 url(ui-bg_flat_10_000000_40x100.png) 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }/* * jQuery UI Resizable 1.8.14 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) @@ -565,4 +565,4 @@ button.ui-button::-moz-focus-inner { border: 0; padding: 0; } /* reset extra pad * http://docs.jquery.com/UI/Progressbar#theming */ .ui-progressbar { height:2em; text-align: left; } -.ui-progressbar .ui-progressbar-value {margin: -1px; height:100%; } \ No newline at end of file +.ui-progressbar .ui-progressbar-value {margin: -1px; height:100%; } From 5391f1f4ab8a71ca4c010107e970266bff5a09b1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 27 Sep 2011 11:29:57 +0200 Subject: [PATCH 1262/2024] fix create another and add existing --- app/assets/javascripts/jquery/active_scaffold.js | 11 +++++++---- app/assets/javascripts/prototype/active_scaffold.js | 2 +- .../default/views/_form_association_footer.html.erb | 4 ++-- frontends/default/views/edit_associated.js.erb | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index bb8882de72..26232757cf 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -143,10 +143,13 @@ $(document).ready(function() { $(this).prevAll('img.loading-indicator').css('visibility','hidden'); return true; }); - $('input[type=button].as_add_existing, input[type=button].as_replace_existing').live('ajax:before', function(event) { - var url = $(this).attr('href').replace('--ID--', $(this).prev().val()); - event.data_url = url; - return true; + $('a.as_add_existing, a.as_replace_existing').live('ajax:before', function(event) { + var id = $(this).prev().val(); + if (id) { + if (!$(this).data('href')) $(this).data('href', $(this).attr('href')); + $(this).attr('href', $(this).data('href').replace('--ID--', id)); + return true; + } else return false; }); $('input.update_form, select.update_form').live('change', function(event) { var element = $(this); diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 5ce84ade25..4872e16f0d 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -230,7 +230,7 @@ document.observe("dom:loaded", function() { if(loading_indicator) loading_indicator.style.visibility = 'hidden'; return true; }); - document.on('ajax:before', 'input[type=button].as_add_existing, input[type=button].as_replace_existing', function(event) { + document.on('ajax:before', 'a.as_add_existing, a.as_replace_existing', function(event) { var button = event.findElement(); var url = button.readAttribute('href').sub('--ID--', button.previous().getValue()); event.memo.url = url; diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index c1eaa81e2d..9057bc2a79 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -26,7 +26,7 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as add_class = 'as_replace_with_new' end create_another_id = "#{sub_form_id(:association => column.name)}-create-another" %> - <%= tag(:input, {:id => create_another_id, :type => 'button', :value => add_label, :href => add_new_url.html_safe, 'data-remote' => true, :class => add_class, :style=> "display: none;"}) %> + <%= link_to add_label, add_new_url, :id => create_another_id, :remote => true, :class => add_class, :style=> "display: none;" %> <%= javascript_tag("ActiveScaffold.show('#{create_another_id}');") %> <% end -%> @@ -39,7 +39,7 @@ add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :as <% select_options = options_for_select(options_for_association(column.association)) add_existing_id = "#{sub_form_id(:association => column.name)}-add-existing" %> <%= select_tag 'associated_id', '<option value="">'.html_safe + as_(:_select_) + '</option>'.html_safe + select_options %> - <%= tag(:input, {:id => add_existing_id, :type => 'button', :value => as_(:add_existing), :href => edit_associated_url.html_safe, 'data-remote' => true, :class=> column.plural_association? ? 'as_add_existing' : 'as_replace_existing', :style => "display: none;"}) %> + <%= link_to as_(:add_existing), edit_associated_url, :id => add_existing_id, :remote => true, :class=> column.plural_association? ? 'as_add_existing' : 'as_replace_existing', :style => "display: none;" %> <%= javascript_tag("ActiveScaffold.show('#{add_existing_id}');") %> <% end -%> <% end -%> diff --git a/frontends/default/views/edit_associated.js.erb b/frontends/default/views/edit_associated.js.erb index 57af838574..94547a95fb 100644 --- a/frontends/default/views/edit_associated.js.erb +++ b/frontends/default/views/edit_associated.js.erb @@ -9,4 +9,4 @@ else options[:id] = active_scaffold_input_options(column, @scope)[:id] end end %> -ActiveScaffold.create_associated_record_form('<%=sub_form_list_id(:association => @column.name)%>','<%=escape_javascript(associated_form)%>', options.to_json.html_safe); +ActiveScaffold.create_associated_record_form('<%=sub_form_list_id(:association => @column.name)%>','<%=escape_javascript(associated_form)%>', <%= options.to_json.html_safe %>); From 09b1d2fa9cd2fdc7a576e213e07869b569977afe Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 28 Sep 2011 13:22:49 +0200 Subject: [PATCH 1263/2024] fix duplicated in embedded rendering --- .../extensions/action_view_rendering.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 554ba9e69f..784920ab58 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -64,16 +64,18 @@ def render_with_active_scaffold(*args, &block) options[:params] ||= {} options[:params].merge! :eid => eid, :embedded => true - id = "as_#{eid}-content" + id = "as_#{eid}-embedded" url_options = {:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params]) if controller.respond_to?(:render_component_into_view) controller.send(:render_component_into_view, url_options) else - content_tag(:div, {:id => id}) do + content_tag(:div, :id => id, :class => 'active-scaffold-component') do url = url_for(url_options) - link_to(remote_controller.to_s, url, {:remote => true, :id => id}) << - if ActiveScaffold.js_framework == :prototype + content_tag(:div, :class => 'active-scaffold-header') do + content_tag :h2, link_to(args.first[:label] || active_scaffold_config_for(remote_controller.to_s.singularize).list.label, url, :remote => true) + end << + if ActiveScaffold.js_framework == :prototype javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true});") elsif ActiveScaffold.js_framework == :jquery javascript_tag("$('##{id}').load('#{url}');") From 42f4b5e13d296923b005863e426859154288c7d8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 28 Sep 2011 14:26:38 +0200 Subject: [PATCH 1264/2024] fix calling render :super in view which is non partial --- .../extensions/action_view_rendering.rb | 67 ++++++++++--------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 784920ab58..d2ac44b8f9 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -15,42 +15,42 @@ def find_all_templates(name, partial = false, locals = {}) # wrap the action rendering for ActiveScaffold views module ActionView::Helpers #:nodoc: module RenderingHelper - # - # Adds two rendering options. - # - # ==render :super - # - # This syntax skips all template overrides and goes directly to the provided ActiveScaffold templates. - # Useful if you want to wrap an existing template. Just call super! - # - # ==render :active_scaffold => #{controller.to_s}, options = {}+ - # - # Lets you embed an ActiveScaffold by referencing the controller where it's configured. - # - # You may specify options[:constraints] for the embedded scaffold. These constraints have three effects: - # * the scaffold's only displays records matching the constraint - # * all new records created will be assigned the constrained values - # * constrained columns will be hidden (they're pretty boring at this point) - # - # You may also specify options[:conditions] for the embedded scaffold. These only do 1/3 of what - # constraints do (they only limit search results). Any format accepted by ActiveRecord::Base.find is valid. - # - # Defining options[:label] lets you completely customize the list title for the embedded scaffold. - # + # + # Adds two rendering options. + # + # ==render :super + # + # This syntax skips all template overrides and goes directly to the provided ActiveScaffold templates. + # Useful if you want to wrap an existing template. Just call super! + # + # ==render :active_scaffold => #{controller.to_s}, options = {}+ + # + # Lets you embed an ActiveScaffold by referencing the controller where it's configured. + # + # You may specify options[:constraints] for the embedded scaffold. These constraints have three effects: + # * the scaffold's only displays records matching the constraint + # * all new records created will be assigned the constrained values + # * constrained columns will be hidden (they're pretty boring at this point) + # + # You may also specify options[:conditions] for the embedded scaffold. These only do 1/3 of what + # constraints do (they only limit search results). Any format accepted by ActiveRecord::Base.find is valid. + # + # Defining options[:label] lets you completely customize the list title for the embedded scaffold. + # def render_with_active_scaffold(*args, &block) if args.first == :super - last_view = @_view_stack.last + last_view = view_stack.last || {:view => instance_variable_get(:@virtual_path).split('/').last} options = args[1] || {} options[:locals] ||= {} options[:locals].reverse_merge!(last_view[:locals] || {}) if last_view[:templates].nil? - last_view[:templates] = lookup_context.find_all_templates(last_view[:view], !last_view[:is_template], options[:locals]) + last_view[:templates] = lookup_context.find_all_templates(last_view[:view], last_view[:partial], options[:locals]) last_view[:templates].shift end options[:template] = last_view[:templates].shift - @_view_stack << last_view + view_stack << last_view result = render_without_active_scaffold options - @_view_stack.pop + view_stack.pop result elsif args.first.is_a? Hash and args.first[:active_scaffold] require 'digest/md5' @@ -86,20 +86,21 @@ def render_with_active_scaffold(*args, &block) else options = args.first if options.is_a?(Hash) - current_view = {:view => options[:partial], :is_template => false} if options[:partial] - current_view = {:view => options[:template], :is_template => !!options[:template]} if current_view.nil? && options[:template] + current_view = {:view => options[:partial], :partial => true} if options[:partial] + current_view = {:view => options[:template], :partial => false} if current_view.nil? && options[:template] current_view[:locals] = options[:locals] if !current_view.nil? && options[:locals] - if current_view.present? - @_view_stack ||= [] - @_view_stack << current_view - end + view_stack << current_view if current_view.present? end result = render_without_active_scaffold(*args, &block) - @_view_stack.pop if current_view.present? + view_stack.pop if current_view.present? result end end alias_method_chain :render, :active_scaffold + + def view_stack + @_view_stack ||= [] + end end end From 60bb1ffeb99e7d3b6b99ffb117a48a527afe2c51 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 28 Sep 2011 14:53:56 +0200 Subject: [PATCH 1265/2024] fix for ruby 1.9 --- lib/active_scaffold/extensions/action_view_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index d2ac44b8f9..c7bfb7f901 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -4,7 +4,7 @@ module ViewPaths def find_all_templates(name, partial = false, locals = {}) prefixes.collect do |prefix| view_paths.collect do |resolver| - resolver.find_all(*args_for_lookup(name, prefix, partial, locals)) + resolver.find_all(*args_for_lookup(name, [prefix], partial, locals)) end end.flatten! end From 600409f169959c96646be73f9bfc096080d6d03a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 29 Sep 2011 11:34:45 +0200 Subject: [PATCH 1266/2024] another fix for ruby 1.9 --- lib/active_scaffold/extensions/action_view_rendering.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index c7bfb7f901..46ad4c4ce4 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -4,7 +4,9 @@ module ViewPaths def find_all_templates(name, partial = false, locals = {}) prefixes.collect do |prefix| view_paths.collect do |resolver| - resolver.find_all(*args_for_lookup(name, [prefix], partial, locals)) + temp_args = *args_for_lookup(name, [prefix], partial, locals) + temp_args[1] = temp_args[1][0] + resolver.find_all(*temp_args) end end.flatten! end From ca05e17548c4ac620600d699249b06cf24531de7 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Thu, 29 Sep 2011 03:54:25 -0700 Subject: [PATCH 1267/2024] Improved wireing of the child record with the parent in subforms --- .../default/views/_form_association.html.erb | 15 +++++++++++---- lib/active_scaffold/actions/subform.rb | 14 ++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index 0ad5f7dbdf..b1a9040860 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -3,11 +3,18 @@ parent_record = @record associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) if show_blank_record = column.show_blank_record?(associated) - associated << if column.singular_association? - parent_record.send("build_#{column.name}".to_sym) - else - parent_record.send(column.name).build + child = column.singular_association? ? parent_record.send(:"build_#{column.name}") : parent_record.send(column.name).build + reflection = parent_record.class.reflect_on_association(column.name) + if reflection && reflection.reverse && parent_record.new_record? + reverse_macro = child.class.reflect_on_association(reflection.reverse).macro + if [:has_one, :belongs_to].include?(reverse_macro) # singular + child.send(:"#{reflection.reverse}=", parent_record) + # TODO: Might want to extend with this branch in the future + # else # plural + # child.send(:"#{reflection.reverse}") << parent_record + end end + associated << child end subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_record.id || 99999999999})}-div" -%> diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index df6708e7eb..04eb209845 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -13,10 +13,16 @@ def do_edit_associated # NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all. @record = @column.association.klass.find(params[:associated_id]) if params[:associated_id] - @record ||= if @column.singular_association? - @parent_record.send("build_#{@column.name}".to_sym) - else - @parent_record.send(@column.name).build + @record ||= @column.singular_association? ? @parent_record.send("build_#{@column.name}".to_sym) : @parent_record.send(@column.name).build + reflection = @parent_record.class.reflect_on_association(@column.name) + if reflection && reflection.reverse && @parent_record.new_record? + reverse_macro = @record.class.reflect_on_association(reflection.reverse).macro + if [:has_one, :belongs_to].include?(reverse_macro) # singular + @record.send(:"#{reflection.reverse}=", @parent_record) + # TODO: Might want to extend with this branch in the future + # else # plural + # @record.send(:"#{reflection.reverse}") << @parent_record + end end @scope = "[#{@column.name}]" From 9308782cb1864e96b30bac6ea32a7f1fce2834f5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 29 Sep 2011 13:49:13 +0200 Subject: [PATCH 1268/2024] fix cache associations --- lib/active_scaffold/actions/update.rb | 2 +- .../extensions/cache_association.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 lib/active_scaffold/extensions/cache_association.rb diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index f2f5000fc2..a3c94ec0cc 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -32,7 +32,7 @@ def edit_respond_to_html def edit_respond_to_js render(:partial => 'update_form') end - def update_respond_to_html + def update_respond_to_html if params[:iframe]=='true' # was this an iframe post ? responds_to_parent do render :action => 'on_update.js', :layout => false diff --git a/lib/active_scaffold/extensions/cache_association.rb b/lib/active_scaffold/extensions/cache_association.rb new file mode 100644 index 0000000000..c88a58815c --- /dev/null +++ b/lib/active_scaffold/extensions/cache_association.rb @@ -0,0 +1,19 @@ +module ActiveRecord + class Relation + def target=(records) + debugger + @loaded = true + @records = records + puts loaded?.inspect + puts self.object_id + @records + end + end +end +module ActiveRecord + module Associations + class CollectionProxy + delegate :target=, :to => :@association + end + end +end From 19bf77bf81c09d0d8f06f1927885a4166a6577ba Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 29 Sep 2011 14:00:41 +0200 Subject: [PATCH 1269/2024] reload row when nested scaffold is closed --- app/assets/javascripts/jquery/active_scaffold.js | 7 ++----- lib/active_scaffold/actions/list.rb | 9 ++++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 26232757cf..8c3342caee 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -72,11 +72,7 @@ $(document).ready(function() { if (action_link) { var cancel_url = as_cancel.attr('href'); - var refresh_data = as_cancel.attr('data-refresh'); - if (refresh_data === 'true' && action_link.refresh_url) { - event.data_url = action_link.refresh_url; - if (action_link.position) event.data_type = 'html' - } else if (refresh_data === 'false' || typeof(cancel_url) == 'undefined' || cancel_url.length == 0) { + if (typeof(cancel_url) == 'undefined' || cancel_url.length == 0) { action_link.close(); return false; } @@ -923,6 +919,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ this.adapter = element; this.adapter.addClass('as_adapter'); this.adapter.data('action_link', this); + if (this.refresh_url) $('.as_cancel[data-refresh=true]', this.adapter).attr('href', this.refresh_url); } }); diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 53446b212d..869e64a2d9 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -55,10 +55,6 @@ def row_respond_to_html render(:partial => 'row', :locals => {:record => @record}) end - def row_respond_to_js - render(:partial => 'row', :locals => {:record => @record}) - end - # The actual algorithm to prepare for the list view def set_includes_for_list_columns includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact @@ -178,7 +174,10 @@ def list_formats (default_formats + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq end alias_method :index_formats, :list_formats - alias_method :row_formats, :list_formats + + def row_formats + ([:html] + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq + end def action_update_formats (default_formats + active_scaffold_config.formats).uniq From 59da3ce2143c07700829d649cc72e39c5ee180a9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 29 Sep 2011 14:53:03 +0200 Subject: [PATCH 1270/2024] dry last commit --- .../default/views/_form_association.html.erb | 13 +------------ lib/active_scaffold/actions/subform.rb | 12 +----------- .../helpers/controller_helpers.rb | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index b1a9040860..65e191950f 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -3,18 +3,7 @@ parent_record = @record associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) if show_blank_record = column.show_blank_record?(associated) - child = column.singular_association? ? parent_record.send(:"build_#{column.name}") : parent_record.send(column.name).build - reflection = parent_record.class.reflect_on_association(column.name) - if reflection && reflection.reverse && parent_record.new_record? - reverse_macro = child.class.reflect_on_association(reflection.reverse).macro - if [:has_one, :belongs_to].include?(reverse_macro) # singular - child.send(:"#{reflection.reverse}=", parent_record) - # TODO: Might want to extend with this branch in the future - # else # plural - # child.send(:"#{reflection.reverse}") << parent_record - end - end - associated << child + associated << build_associated(column, parent_record) end subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_record.id || 99999999999})}-div" -%> diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index 04eb209845..268b40600e 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -13,17 +13,7 @@ def do_edit_associated # NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all. @record = @column.association.klass.find(params[:associated_id]) if params[:associated_id] - @record ||= @column.singular_association? ? @parent_record.send("build_#{@column.name}".to_sym) : @parent_record.send(@column.name).build - reflection = @parent_record.class.reflect_on_association(@column.name) - if reflection && reflection.reverse && @parent_record.new_record? - reverse_macro = @record.class.reflect_on_association(reflection.reverse).macro - if [:has_one, :belongs_to].include?(reverse_macro) # singular - @record.send(:"#{reflection.reverse}=", @parent_record) - # TODO: Might want to extend with this branch in the future - # else # plural - # @record.send(:"#{reflection.reverse}") << @parent_record - end - end + @record ||= build_associated(@column, @parent_record) @scope = "[#{@column.name}]" @scope += (@record.new_record?) ? "[#{(Time.now.to_f*1000).to_i.to_s}]" : "[#{@record.id}]" if @column.plural_association? diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 8f4ed4d597..043f587499 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Helpers module ControllerHelpers def self.included(controller) - controller.class_eval { helper_method :params_for, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?} + controller.class_eval { helper_method :params_for, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated} end include ActiveScaffold::Helpers::IdHelpers @@ -82,6 +82,20 @@ def render_parent_action(controller_path = nil) end if @parent_action.nil? @parent_action end + + def build_associated(column, parent_record) + child = column.singular_association? ? parent_record.send(:"build_#{column.name}") : parent_record.send(column.name).build + if parent_record.new_record? && (reflection = parent_record.class.reflect_on_association(column.name)).try(:reverse) + reverse_macro = child.class.reflect_on_association(reflection.reverse).macro + if [:has_one, :belongs_to].include?(reverse_macro) # singular + child.send(:"#{reflection.reverse}=", parent_record) + # TODO: Might want to extend with this branch in the future + # else # plural + # child.send(:"#{reflection.reverse}") << parent_record + end + end + child + end end end end From 99d994108e36247a3cca67dc65649830d5f7e9f1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 29 Sep 2011 17:54:20 +0200 Subject: [PATCH 1271/2024] fix row view with calculations --- frontends/default/views/_row.html.erb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/frontends/default/views/_row.html.erb b/frontends/default/views/_row.html.erb index 3044d61143..b31788bc75 100644 --- a/frontends/default/views/_row.html.erb +++ b/frontends/default/views/_row.html.erb @@ -1,12 +1,6 @@ <%= render :partial => 'list_record', :locals => {:record => record}%> -<% if active_scaffold_config.list.columns.any? {|c| c.calculation?} %> -<script type="text/javascript"> -//<![CDATA[ - <%= update_page do |page| - page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') - end %> -//]]> -</script> -<% end %> +<%= javascript_tag do %> +ActiveScaffold.replace('<%= active_scaffold_calculations_id %>', '<%= escape_javascript render(:partial => 'list_calculations') %>'); +<% end if active_scaffold_config.list.columns.any? {|c| c.calculation?} %> From 70fa886a198dad546f43f88575b5c974307fd375 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 30 Sep 2011 14:03:32 +0200 Subject: [PATCH 1272/2024] fix a search helper --- frontends/default/views/_horizontal_subform.html.erb | 8 ++++---- .../default/views/_horizontal_subform_header.html.erb | 2 +- lib/active_scaffold/helpers/search_column_helpers.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index 8907053019..8d4f9c2695 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -1,16 +1,16 @@ <table cellpadding="0" cellspacing="0"> <% - if associated.empty? - @record = if column.singular_association? + record = if associated.empty? + if column.singular_association? parent_record.send("build_#{column.name}".to_sym) else parent_record.send(column.name).build end else - @record = associated.last + associated.last end -%> - <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record} %> + <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record, :record => record} %> <tbody id="<%= sub_form_list_id(:association => column.name) %>"> <% associated.each_index do |index| %> diff --git a/frontends/default/views/_horizontal_subform_header.html.erb b/frontends/default/views/_horizontal_subform_header.html.erb index c39a00fbca..40e8b3090b 100644 --- a/frontends/default/views/_horizontal_subform_header.html.erb +++ b/frontends/default/views/_horizontal_subform_header.html.erb @@ -1,7 +1,7 @@ <thead> <tr> <% - active_scaffold_config_for(@record.class).subform.columns.each :for => @record.class, :flatten => true do |column| + active_scaffold_config_for(record.class).subform.columns.each :for => record.class, :flatten => true do |column| hidden = column_renders_as(column) == :hidden next unless in_subform?(column, parent_record) -%> diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 35095b3241..5c6f8d6481 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -88,7 +88,7 @@ def active_scaffold_search_select(column, html_options) else options[:include_blank] ||= as_(:_select_) end - select(:record, method, options_for_select, options, html_options) + select(:record, method, select_options, options, html_options) end def active_scaffold_search_text(column, options) From 8ae9cdb28e9fd358d159df11c8b82b4d426fdcfe Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 30 Sep 2011 14:41:27 +0200 Subject: [PATCH 1273/2024] fix render :super with locals --- lib/active_scaffold/extensions/action_view_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 46ad4c4ce4..12e31451bf 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -46,7 +46,7 @@ def render_with_active_scaffold(*args, &block) options[:locals] ||= {} options[:locals].reverse_merge!(last_view[:locals] || {}) if last_view[:templates].nil? - last_view[:templates] = lookup_context.find_all_templates(last_view[:view], last_view[:partial], options[:locals]) + last_view[:templates] = lookup_context.find_all_templates(last_view[:view], last_view[:partial], options[:locals].keys) last_view[:templates].shift end options[:template] = last_view[:templates].shift From 3a57995b496ef3be1fe45621d226b5db121f049e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 30 Sep 2011 14:55:10 +0200 Subject: [PATCH 1274/2024] Fix overriding render_field Don't use locals in controller, because we can't recover them if render :super is used --- frontends/default/views/render_field.js.erb | 2 +- lib/active_scaffold/actions/core.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/render_field.js.erb b/frontends/default/views/render_field.js.erb index 7f912ba13d..d892da8f8a 100644 --- a/frontends/default/views/render_field.js.erb +++ b/frontends/default/views/render_field.js.erb @@ -1 +1 @@ -<%= render :partial => "render_field", :collection => columns, :locals => {:source_id => source_id, :scope => scope} %> +<%= render :partial => "render_field", :collection => @columns, :locals => {:source_id => @source_id, :scope => @scope} %> diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index e69fa67112..9bcdec8f3c 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -46,8 +46,10 @@ def render_field_for_update_columns @record.send "#{column.name}=", value end after_render_field(@record, column) - source_id = params.delete(:source_id) - render :locals => {:source_id => source_id, :columns => column.update_columns, :scope => params[:scope]} + + @source_id = params.delete(:source_id) + @columns = column.update_columns + @scope = params[:scope] end end From 857af52a6c7926795914e3ae7c5a074dac20bbd1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 30 Sep 2011 17:31:23 +0200 Subject: [PATCH 1275/2024] fix reenabling fields on update column (jquery) --- app/assets/javascripts/jquery/active_scaffold.js | 4 ++-- lib/active_scaffold/attribute_params.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 8c3342caee..a00ff64833 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -440,7 +440,7 @@ var ActiveScaffold = { var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); if (loading_indicator) loading_indicator.css('visibility','visible'); $('input[type=submit]', as_form).attr('disabled', 'disabled'); - $("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled'); + as_form[0].disabled_fields = $("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled'); }, enable_form: function(as_form) { @@ -449,7 +449,7 @@ var ActiveScaffold = { var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); if (loading_indicator) loading_indicator.css('visibility','hidden'); $('input[type=submit]', as_form).attr('disabled', ''); - $("input:disabled,select:disabled,textarea:disabled", as_form).attr('disabled', ''); + as_form[0].disabled_fields.removeAttr("disabled"); }, focus_first_element_of_form: function(form_element) { diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index d35bb6cf4d..d617d96dd0 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -71,7 +71,7 @@ def update_record_from_params(parent_record, columns, attributes) next unless [:has_one, :has_many].include?(a.macro) and not (a.options[:through] || a.options[:finder_sql]) next unless association_proxy = parent_record.send(a.name) - raise ActiveScaffold::ReverseAssociationRequired, "Association #{a.name}: In order to support :has_one and :has_many where the parent record is new and the child record(s) validate the presence of the parent, ActiveScaffold requires the reverse association (the belongs_to)." unless a.reverse + raise ActiveScaffold::ReverseAssociationRequired, "Association #{a.name} in class #{parent_record.class.name}: In order to support :has_one and :has_many where the parent record is new and the child record(s) validate the presence of the parent, ActiveScaffold requires the reverse association (the belongs_to)." unless a.reverse association_proxy = [association_proxy] if a.macro == :has_one association_proxy.each { |record| record.send("#{a.reverse}=", parent_record) } From fe7555c632d3d72d49fb3149dc500d95c9bfda6d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 30 Sep 2011 18:02:58 +0200 Subject: [PATCH 1276/2024] fix search in associations --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 52c78590bd..00c5fd0e35 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -270,7 +270,7 @@ def finder_options(options = {}) # Returns a hash with options to count records, rejecting select and order options # See finder_options for valid options def count_options(find_options = {}, count_includes = nil) - count_includes ||= find_options[:includes] unless find_options[:conditions].nil? + count_includes ||= find_options[:includes] unless find_options[:where].nil? options = find_options.reject{|k,v| [:select, :order].include? k} options[:includes] = count_includes options From a0099b3da32c4ad0d7aefc6f2eeaa5a2ac5398c8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 30 Sep 2011 18:03:17 +0200 Subject: [PATCH 1277/2024] fix disabling and reenabling search form --- app/assets/javascripts/jquery/active_scaffold.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index a00ff64833..3e468f6507 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -1,5 +1,5 @@ $(document).ready(function() { - $('form.as_form').live('ajax:loading', function(event) { + $('form.as_form').live('ajax:beforeSend', function(event) { var as_form = $(this).closest("form"); if (as_form && as_form.attr('data-loading') == 'true') { ActiveScaffold.disable_form(as_form); @@ -448,8 +448,8 @@ var ActiveScaffold = { as_form = $(as_form) var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); if (loading_indicator) loading_indicator.css('visibility','hidden'); - $('input[type=submit]', as_form).attr('disabled', ''); - as_form[0].disabled_fields.removeAttr("disabled"); + $('input[type=submit]', as_form).removeAttr('disabled'); + as_form[0].disabled_fields.removeAttr('disabled'); }, focus_first_element_of_form: function(form_element) { @@ -540,7 +540,7 @@ var ActiveScaffold = { checkbox.attr('disabled', 'disabled'); }, complete: function(request){ - checkbox.attr('disabled', ''); + checkbox.removeAttr('disabled'); } }); }, From 882bf02fed20c319f53ed39951bc480b2c94af6a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 30 Sep 2011 18:07:19 +0200 Subject: [PATCH 1278/2024] click_to_reset security method call at instance level (must be called at class level) --- frontends/default/views/_list_messages.html.erb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index d3a0285048..61656f2da8 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -18,10 +18,8 @@ <% if active_scaffold_config.list.show_search_reset && @filtered -%> <% search_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :member, :position => false) action_links = ActiveScaffold::DataStructures::ActionLinks.new - record = new_model - record.id = 0 action_links.add(search_link) -%> - <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links.member} %> + <%= render :partial => 'list_actions', :locals => {:record => active_scaffold_config.model, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links.member} %> <% else %> <td class='actions'><%= '<p class="empty-message"> </p>'.html_safe if @page.items.empty? %></td> <% end -%> From 56a4ba251c75bd191070484741ad069d16a15629 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 3 Oct 2011 13:39:18 +0200 Subject: [PATCH 1279/2024] fix render field --- frontends/default/views/_render_field.js.erb | 2 +- frontends/default/views/_render_fields.js.rjs | 11 ----------- lib/active_scaffold/actions/core.rb | 2 +- 3 files changed, 2 insertions(+), 13 deletions(-) delete mode 100644 frontends/default/views/_render_fields.js.rjs diff --git a/frontends/default/views/_render_field.js.erb b/frontends/default/views/_render_field.js.erb index 44033015c7..d0f939a862 100644 --- a/frontends/default/views/_render_field.js.erb +++ b/frontends/default/views/_render_field.js.erb @@ -10,7 +10,7 @@ end -%> -ActiveScaffold.render_form_field('<%source_id%>','<%=escape_javascript(render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope }))%>', options.to_json.html_safe); +ActiveScaffold.render_form_field('<%= source_id %>','<%= escape_javascript(render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope })) %>', <%= options.to_json.html_safe %>); <%if column.update_columns && !column.update_columns.empty?%> <%= render(:partial => "render_field", :collection => column.update_columns, :locals => {:source_id => source_id, :scope => scope})%> <%end%> diff --git a/frontends/default/views/_render_fields.js.rjs b/frontends/default/views/_render_fields.js.rjs deleted file mode 100644 index 884a6ae3e1..0000000000 --- a/frontends/default/views/_render_fields.js.rjs +++ /dev/null @@ -1,11 +0,0 @@ -render_fields.each do |column_name| - column = active_scaffold_config.columns[column_name.to_sym] - if column_renders_as(column) == :subform - field_id = sub_form_id(:association => column.name) - page[field_id].replace_html :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } - else - field_id = active_scaffold_input_options(column, params[:scope])[:id] - page[field_id].up('dl').replace :partial => form_partial_for_column(column), :locals => { :column => column, :scope => params[:scope] } - end - page << render(:partial => 'render_fields.js', :object => Array(column.update_column)) if column.update_column -end diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 9bcdec8f3c..bafce2bb4a 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -45,11 +45,11 @@ def render_field_for_update_columns value = column_value_from_param_value(@record, column, params[:value]) @record.send "#{column.name}=", value end - after_render_field(@record, column) @source_id = params.delete(:source_id) @columns = column.update_columns @scope = params[:scope] + after_render_field(@record, column) end end From 86dcff95869881d0024d304dc317e48e39a5269d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 4 Oct 2011 10:29:13 +0200 Subject: [PATCH 1280/2024] fix previous commit, it broke loading_indicator_tag --- frontends/default/views/_list_actions.html.erb | 2 +- frontends/default/views/_list_messages.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb index 019938eed9..53b1e38d11 100644 --- a/frontends/default/views/_list_actions.html.erb +++ b/frontends/default/views/_list_actions.html.erb @@ -6,7 +6,7 @@ <%= render :partial => 'action_group', :locals => {:action_links => action_links || active_scaffold_config.action_links.member, :url_options => url_options, :record => record, - :traverse_options => {:for => record}, + :traverse_options => {:for => record.persisted? ? record : record.class}, :start_level_0_tag => '<td>', :end_level_0_tag => '</td>'} %> </tr> diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index 61656f2da8..1daab81615 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -19,7 +19,7 @@ <% search_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :member, :position => false) action_links = ActiveScaffold::DataStructures::ActionLinks.new action_links.add(search_link) -%> - <%= render :partial => 'list_actions', :locals => {:record => active_scaffold_config.model, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links.member} %> + <%= render :partial => 'list_actions', :locals => {:record => new_model, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links.member} %> <% else %> <td class='actions'><%= '<p class="empty-message"> </p>'.html_safe if @page.items.empty? %></td> <% end -%> From 3f3fcdcb001ecbfa02689f530b7a596e40179135 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 4 Oct 2011 14:15:02 +0200 Subject: [PATCH 1281/2024] add css_class to column groups --- frontends/default/views/_form.html.erb | 2 +- lib/active_scaffold/data_structures/action_columns.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index 514878356a..d9699c8192 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -6,7 +6,7 @@ <% renders_as = column_renders_as(column) %> <% if renders_as == :subsection -%> <% subsection_id = sub_section_id(:sub_section => column.label) %> - <li class="sub-section"> + <li class="sub-section <%= column.css_class %>"> <h5><%= column.label %></h5> <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id, :form_action => form_action } %> <%= link_to_visibility_toggle(subsection_id, {:default_visible => !column.collapsed}) -%> diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index caec17096b..e3fc836ec4 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -12,6 +12,9 @@ class ActionColumns < ActiveScaffold::DataStructures::Set def label as_(@label) if @label end + def css_class + @label.to_s.underscore + end # Whether this column set is collapsed by default in contexts where collapsing is supported attr_accessor :collapsed From 85310b219e783b6654f81365605a55b6d2ee50cb Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 4 Oct 2011 16:55:38 +0200 Subject: [PATCH 1282/2024] use inverse_of feature --- lib/active_scaffold/attribute_params.rb | 14 ++++-------- .../extensions/reverse_associations.rb | 22 ++++++++++--------- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index d617d96dd0..4602daf254 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -157,22 +157,16 @@ def find_or_create_for_params(params, parent_column, parent_record) # modifying the current object of a singular association pk_val = params[pk] if current and current.is_a? ActiveRecord::Base and current.id.to_s == pk_val - return current + current # modifying one of the current objects in a plural association elsif current and current.respond_to?(:any?) and current.any? {|o| o.id.to_s == pk_val} - return current.detect {|o| o.id.to_s == pk_val} + current.detect {|o| o.id.to_s == pk_val} # attaching an existing but not-current object else - return klass.find(pk_val) + klass.find(pk_val) end else - if klass.authorized_for?(:crud_type => :create) - if parent_column.singular_association? - return parent_record.send("build_#{parent_column.name}") - else - return parent_record.send(parent_column.name).build - end - end + build_associated(parent_column, parent_record) if klass.authorized_for?(:crud_type => :create) end end # Determines whether the given attributes hash is "empty". diff --git a/lib/active_scaffold/extensions/reverse_associations.rb b/lib/active_scaffold/extensions/reverse_associations.rb index 8675d56de1..bade4f10cc 100644 --- a/lib/active_scaffold/extensions/reverse_associations.rb +++ b/lib/active_scaffold/extensions/reverse_associations.rb @@ -1,23 +1,25 @@ module ActiveRecord module Reflection class AssociationReflection #:nodoc: - def reverse_for?(klass) - reverse_matches_for(klass).empty? ? false : true + def inverse_for?(klass) + inverse_class = inverse_of.try(:active_record) + inverse_class.present? && (inverse_class == klass || klass < inverse_class) end attr_writer :reverse def reverse - if @reverse.nil? and not self.options[:polymorphic] - reverse_matches = reverse_matches_for(self.class_name.constantize) rescue nil - # grab first association, or make a wild guess - @reverse = reverse_matches.blank? ? false : reverse_matches.first.name - end - @reverse + @reverse ||= inverse_of.try(:name) end + def inverse_of_with_autodetect + inverse_of_without_autodetect || autodetect_inverse + end + alias_method_chain :inverse_of, :autodetect + protected - def reverse_matches_for(klass) + def autodetect_inverse + return nil if options[:polymorphic] reverse_matches = [] # stage 1 filter: collect associations that point back to this model and use the same foreign_key @@ -54,7 +56,7 @@ def reverse_matches_for(klass) self.active_record.to_s.underscore.include? assoc.name.to_s.pluralize.singularize end if reverse_matches.length > 1 - reverse_matches + reverse_matches.first end end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 158e95bbe8..399e58754f 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -70,7 +70,7 @@ def in_subform?(column, parent_record) return false if column.polymorphic_association? # A column shouldn't be in the subform if it's the reverse association to the parent - return false if column.association.reverse_for?(parent_record.class) + return false if column.association.inverse_for?(parent_record.class) return true end From 9c537c62b23dd2fd4d255f419edf669706aa50f9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 5 Oct 2011 09:26:06 +0200 Subject: [PATCH 1283/2024] remove wiring associations, :inverse_of should be used when it's needed --- .../helpers/controller_helpers.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 043f587499..2430d28fc0 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -83,18 +83,12 @@ def render_parent_action(controller_path = nil) @parent_action end - def build_associated(column, parent_record) - child = column.singular_association? ? parent_record.send(:"build_#{column.name}") : parent_record.send(column.name).build - if parent_record.new_record? && (reflection = parent_record.class.reflect_on_association(column.name)).try(:reverse) - reverse_macro = child.class.reflect_on_association(reflection.reverse).macro - if [:has_one, :belongs_to].include?(reverse_macro) # singular - child.send(:"#{reflection.reverse}=", parent_record) - # TODO: Might want to extend with this branch in the future - # else # plural - # child.send(:"#{reflection.reverse}") << parent_record - end + def build_associated(column, record) + if column.singular_association? + record.send(:"build_#{column.name}") + else + record.send(column.name).build end - child end end end From 74c7ef41c2621045d5d2389851e3dd6584afbb76 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 5 Oct 2011 12:54:53 +0200 Subject: [PATCH 1284/2024] fix i18n number for virtual columns --- lib/active_scaffold/attribute_params.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 4602daf254..be98f3cd5c 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -106,7 +106,7 @@ def column_value_from_param_simple_value(parent_record, column, value) column.association.klass.find(value) if value and not value.empty? elsif column.plural_association? column_plural_assocation_value_from_value(column, value) - elsif column.column && column.number? && [:i18n_number, :currency].include?(column.options[:format]) + elsif column.number? && [:i18n_number, :currency].include?(column.options[:format]) self.class.i18n_number_to_native_format(value) else # convert empty strings into nil. this works better with 'null => true' columns (and validations), From f9fd980cb1a5be7ac64799c0b787fd117d3b7f3d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 5 Oct 2011 12:58:47 +0200 Subject: [PATCH 1285/2024] remove debug code --- lib/active_scaffold/extensions/cache_association.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/active_scaffold/extensions/cache_association.rb b/lib/active_scaffold/extensions/cache_association.rb index c88a58815c..80568df025 100644 --- a/lib/active_scaffold/extensions/cache_association.rb +++ b/lib/active_scaffold/extensions/cache_association.rb @@ -1,11 +1,8 @@ module ActiveRecord class Relation def target=(records) - debugger @loaded = true @records = records - puts loaded?.inspect - puts self.object_id @records end end From bf7e09b4e25c776e26108c4fc56185855d4236c5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 5 Oct 2011 13:34:20 +0200 Subject: [PATCH 1286/2024] allow to pass a column instead of symbol to render partial It's needed to update a parent column from a child record (in a subform) --- frontends/default/views/_render_field.js.erb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_render_field.js.erb b/frontends/default/views/_render_field.js.erb index d0f939a862..705d4f38af 100644 --- a/frontends/default/views/_render_field.js.erb +++ b/frontends/default/views/_render_field.js.erb @@ -1,5 +1,9 @@ <% - column = active_scaffold_config.columns[render_field.to_sym] + column = if render_field.is_a? ActiveScaffold::DataStructures::Column + render_field + else + active_scaffold_config.columns[render_field.to_sym] unless render_field.is_a? ActiveScaffold::DataStructures::Column + end @rendered ||= Set.new return if @rendered.include? column.name @rendered << column.name From add1595078a560fd7b02f1639dd979093e4560cb Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 5 Oct 2011 13:50:12 +0200 Subject: [PATCH 1287/2024] fix update columns in a subform inside an update form --- lib/active_scaffold/actions/core.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index bafce2bb4a..cfa982772f 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -30,18 +30,19 @@ def render_field_for_inplace_editing def render_field_for_update_columns column = active_scaffold_config.columns[params[:column]] - @record = params[:id] && column.send_form_on_update_column ? find_if_allowed(params[:id], :update) : new_model unless column.nil? if column.send_form_on_update_column hash = if params[:scope] - hash = params[:scope].gsub('[','').split(']').inject(params[:record]) do |hash, index| + params[:scope].gsub('[','').split(']').inject(params[:record]) do |hash, index| hash[index] end else params[:record] end + @record = hash[:id] ? find_if_allowed(hash[:id], :update) : new_model @record = update_record_from_params(@record, active_scaffold_config.send(params[:id] ? :update : :create).columns, hash) else + @record = new_model value = column_value_from_param_value(@record, column, params[:value]) @record.send "#{column.name}=", value end From 0fd661cd780b65f4b9dd1ca0be7ab7b4b2eb59e4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 5 Oct 2011 14:04:48 +0200 Subject: [PATCH 1288/2024] use subform.columns on rendering a field with scope --- lib/active_scaffold/actions/core.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index cfa982772f..d4131aa054 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -31,6 +31,10 @@ def render_field_for_inplace_editing def render_field_for_update_columns column = active_scaffold_config.columns[params[:column]] unless column.nil? + @source_id = params.delete(:source_id) + @columns = column.update_columns + @scope = params[:scope] + if column.send_form_on_update_column hash = if params[:scope] params[:scope].gsub('[','').split(']').inject(params[:record]) do |hash, index| @@ -40,16 +44,13 @@ def render_field_for_update_columns params[:record] end @record = hash[:id] ? find_if_allowed(hash[:id], :update) : new_model - @record = update_record_from_params(@record, active_scaffold_config.send(params[:id] ? :update : :create).columns, hash) + @record = update_record_from_params(@record, active_scaffold_config.send(@scope ? :subform : (params[:id] ? :update : :create)).columns, hash) else @record = new_model value = column_value_from_param_value(@record, column, params[:value]) @record.send "#{column.name}=", value end - @source_id = params.delete(:source_id) - @columns = column.update_columns - @scope = params[:scope] after_render_field(@record, column) end end From 801719cc0723b83bde84512a22e305294f149499 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 5 Oct 2011 16:53:46 +0200 Subject: [PATCH 1289/2024] render field was failing with subgroups, because they add ol.form elements --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- lib/active_scaffold/actions/core.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 3e468f6507..aec4f06a23 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -604,7 +604,7 @@ var ActiveScaffold = { var source = $(source); var element = source.closest('.association-record'); if (element.length == 0) { - element = source.closest('ol.form'); + element = source.closest('form > ol.form'); } element = element.find('.' + options.field_class + ":first"); diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index d4131aa054..46f85192b9 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -36,8 +36,8 @@ def render_field_for_update_columns @scope = params[:scope] if column.send_form_on_update_column - hash = if params[:scope] - params[:scope].gsub('[','').split(']').inject(params[:record]) do |hash, index| + hash = if @scope + @scope.gsub('[','').split(']').inject(params[:record]) do |hash, index| hash[index] end else From 433c933c09243aea7616c0d21b58b86cb96652b4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 6 Oct 2011 10:24:14 +0200 Subject: [PATCH 1290/2024] add horizontal subform footer, so apps can add a tfooter --- frontends/default/views/_horizontal_subform.html.erb | 3 +++ frontends/default/views/_horizontal_subform_footer.html.erb | 0 frontends/default/views/_render_field.js.erb | 3 --- 3 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 frontends/default/views/_horizontal_subform_footer.html.erb diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index 8d4f9c2695..a136bc671b 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -25,5 +25,8 @@ <%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> <% end -%> </tbody> + <tfooter> + <%= render :partial => 'horizontal_subform_footer', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column} %> + </tfooter> </table> <%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%> diff --git a/frontends/default/views/_horizontal_subform_footer.html.erb b/frontends/default/views/_horizontal_subform_footer.html.erb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frontends/default/views/_render_field.js.erb b/frontends/default/views/_render_field.js.erb index 705d4f38af..0225bf7868 100644 --- a/frontends/default/views/_render_field.js.erb +++ b/frontends/default/views/_render_field.js.erb @@ -18,6 +18,3 @@ ActiveScaffold.render_form_field('<%= source_id %>','<%= escape_javascript(rende <%if column.update_columns && !column.update_columns.empty?%> <%= render(:partial => "render_field", :collection => column.update_columns, :locals => {:source_id => source_id, :scope => scope})%> <%end%> - - - From d8f1f6920ff700bbcd2281dbe43f4843106eb9c2 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 6 Oct 2011 10:54:06 +0200 Subject: [PATCH 1291/2024] method to dry converting scope for use in id attributes --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- lib/active_scaffold/helpers/id_helpers.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 9ec1b03473..82a63510e2 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -72,7 +72,7 @@ def active_scaffold_input_options(column, scope = nil, options = {}) # Fix for keeping unique IDs in subform id_control = "record_#{column.name}_#{[params[:eid], params[:id]].compact.join '_'}" - id_control += scope.gsub(/(\[|\])/, '_').gsub('__', '_').gsub(/_$/, '') if scope + id_control += scope_id(scope) if scope { :name => name, :class => "#{column.name}-input", :id => id_control}.merge(options) end diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index d76beacdfd..e2d9234a8a 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -111,6 +111,10 @@ def element_messages_id(options = {}) def action_iframe_id(options) "#{controller_id}-#{options[:action]}-#{options[:id]}-iframe" end + + def scope_id(scope) + scope.gsub(/(\[|\])/, '_').gsub('__', '_').gsub(/_$/, '') + end private From 88fbea946441bb6dde80d9d2325ea1a7277878f6 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 6 Oct 2011 11:09:10 +0200 Subject: [PATCH 1292/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index c2c8cbcf20..c1bec8b176 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 2 + PATCH = 3 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 2e84c7ea35a974975bd558bcc09615900e229ede Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 6 Oct 2011 11:50:22 +0200 Subject: [PATCH 1293/2024] allow to use update_columns for rendering plural associations --- .../helpers/form_column_helpers.rb | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 82a63510e2..a3545a43f6 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -115,25 +115,26 @@ def active_scaffold_input_singular_association(column, html_options) def active_scaffold_input_plural_association(column, options) associated_options = @record.send(column.association.name).collect {|r| [r.to_label, r.id]} select_options = associated_options | options_for_association(column.association) - return content_tag(:span, as_(:no_options), :id => options[:id]) if select_options.empty? + return content_tag(:span, as_(:no_options), :class => options[:class], :id => options[:id]) if select_options.empty? active_scaffold_checkbox_list(column, select_options, associated_options.collect {|a| a[1]}, options) end def active_scaffold_checkbox_list(column, select_options, associated_ids, options) - html = "<ul class=\"checkbox-list\" id=\"#{options[:id]}\">" - - select_options.each_with_index do |option, i| - label, id = option - this_id = "#{options[:id]}_#{i}_id" - html << content_tag(:li) do - check_box_tag("#{options[:name]}[]", id, associated_ids.include?(id), :id => this_id) << - content_tag(:label, h(label), :for => this_id) + html = content_tag :ul, :class => "#{options[:class]} checkbox-list", :id => options[:id] do + content = "".html_safe + select_options.each_with_index do |option, i| + label, id = option + this_id = "#{options[:id]}_#{i}_id" + content << content_tag(:li) do + check_box_tag("#{options[:name]}[]", id, associated_ids.include?(id), :id => this_id) << + content_tag(:label, h(label), :for => this_id) + end end + content end - html << '</ul>' html << javascript_tag("new DraggableLists('#{options[:id]}')") if column.options[:draggable_lists] - html.html_safe + html end def active_scaffold_translated_option(column, text, value = nil) From 0fd3f7f604c9ce69285e918840c4a8e8de1f1fbb Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 6 Oct 2011 12:39:51 +0200 Subject: [PATCH 1294/2024] send value when a checkbox calls update column in jquery, as it's done in prototype. record select with update column works with prototype too --- app/assets/javascripts/jquery/active_scaffold.js | 3 ++- app/assets/javascripts/prototype/active_scaffold.js | 2 ++ lib/active_scaffold/bridges/record_select/helpers.rb | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index aec4f06a23..eb0e392b43 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -149,7 +149,7 @@ $(document).ready(function() { }); $('input.update_form, select.update_form').live('change', function(event) { var element = $(this); - var value = element.is("input:checkbox") ? element.is(":checked") : element.val(); + var value = element.is("input:checkbox:not(:checked)") ? null : element.val(); ActiveScaffold.update_column(element, element.attr('data-update_url'), element.attr('data-update_send_form'), element.attr('id'), value); return true; }); @@ -732,6 +732,7 @@ var ActiveScaffold = { }, update_column: function(element, url, send_form, source_id, val) { + if (!element) element = $('#' + source_id); var as_form = element.closest('form.as_form'); var params = null; diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 4872e16f0d..52ceb9041c 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -596,6 +596,8 @@ var ActiveScaffold = { }, update_column: function(element, url, send_form, source_id, val) { + if (!element) element = $(source_id); + var as_form = element.up('form.as_form'); var params = null; diff --git a/lib/active_scaffold/bridges/record_select/helpers.rb b/lib/active_scaffold/bridges/record_select/helpers.rb index fc67fd91b2..35c94cd517 100644 --- a/lib/active_scaffold/bridges/record_select/helpers.rb +++ b/lib/active_scaffold/bridges/record_select/helpers.rb @@ -39,7 +39,7 @@ def active_scaffold_record_select(column, options, value, multiple) record_select_options.merge!(column.options) if options['data-update_url'] record_select_options[:onchange] = %|function(id, label) { - ActiveScaffold.update_column($("##{options[:id]}"), "#{options['data-update_url']}", #{options['data-update_send_form'].to_json}, "#{options[:id]}", id); + ActiveScaffold.update_column(null, "#{options['data-update_url']}", #{options['data-update_send_form'].to_json}, "#{options[:id]}", id); }| end From 75acdb1635684f4d33c924ca515bf39e14046d01 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 6 Oct 2011 12:54:58 +0200 Subject: [PATCH 1295/2024] call render field only when a record is selected, not with change event --- lib/active_scaffold/bridges/record_select/helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/record_select/helpers.rb b/lib/active_scaffold/bridges/record_select/helpers.rb index 35c94cd517..ed5abb0fab 100644 --- a/lib/active_scaffold/bridges/record_select/helpers.rb +++ b/lib/active_scaffold/bridges/record_select/helpers.rb @@ -34,7 +34,7 @@ def active_scaffold_record_select(column, options, value, multiple) record_select_options = active_scaffold_input_text_options( :controller => remote_controller, :id => options[:id], - :class => options[:class] + :class => options[:class].gsub(/update_form/, '') ) record_select_options.merge!(column.options) if options['data-update_url'] From 54d934762fd28476b2ba93a33ebb667416a1da71 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 6 Oct 2011 17:03:04 +0200 Subject: [PATCH 1296/2024] include vendor in gem --- active_scaffold.gemspec | 2 +- lib/active_scaffold/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index c366475355..a2e5a2cc5a 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |s| s.summary = %q{Rails 3.1 Version of activescaffold supporting prototype and jquery} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.require_paths = ["lib"] - s.files = Dir["{app,config,frontends,lib,public,shoulda_macros}/**/*"] + %w[MIT-LICENSE CHANGELOG README] + s.files = Dir["{app,config,frontends,lib,public,shoulda_macros,vendor}/**/*"] + %w[MIT-LICENSE CHANGELOG README] s.extra_rdoc_files = [ "README" ] diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index c1bec8b176..063d566928 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 3 + PATCH = 4 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 2f2f2ca665055cce91a637b9d69ff390002b4994 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 6 Oct 2011 20:13:13 +0200 Subject: [PATCH 1297/2024] fix time conversion for other languages --- lib/active_scaffold/finder.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 00c5fd0e35..a2bf7beb68 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -108,11 +108,18 @@ def condition_for_range(column, value, like_pattern = nil) def condition_value_for_datetime(value, conversion = :to_time) if value.is_a? Hash - Time.zone.local(*[:year, :month, :day, :hour, :minute, :second].collect {|part| value[field][part].to_i}) rescue nil + Time.zone.local(*[:year, :month, :day, :hour, :minute, :second].collect {|part| value[part].to_i}) rescue nil elsif value.respond_to?(:strftime) value.send(conversion) + elsif conversion == :to_date + Date.strptime(value, I18n.t('date.formats.default')) rescue nil else - Time.zone.parse(value).in_time_zone.send(conversion) rescue nil + parts = Date._parse(value) + time_parts = [[:hour, '%H'], [:min, '%M'], [:sec, '%S']].collect {|part, format_part| format_part if parts[part].present?}.compact + format = "#{I18n.t('date.formats.default')} #{time_parts.join(':')} #{'%z' if parts[:offset].present?}" + time = DateTime.strptime(value, format) + time = Time.zone.local_to_utc(time) unless parts[:offset] + time.in_time_zone.send(conversion) rescue nil end unless value.nil? || value.blank? end From 7f088d119bd2f7ae25d8ab155f433e51ec53c1dd Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 7 Oct 2011 10:57:21 +0200 Subject: [PATCH 1298/2024] fix nested link for singular associations and some code cleaning --- lib/active_scaffold.rb | 2 +- lib/active_scaffold/actions/nested.rb | 8 ++++++-- lib/active_scaffold/config/nested.rb | 1 + .../data_structures/action_link.rb | 8 ++++---- .../helpers/list_column_helpers.rb | 15 +++++++++------ lib/active_scaffold/helpers/view_helpers.rb | 2 +- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 18ec82998c..d31813e257 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -266,7 +266,7 @@ def link_for_association(column, options = {}) column.actions_for_association_links.delete :new unless actions.include? :create column.actions_for_association_links.delete :edit unless actions.include? :update column.actions_for_association_links.delete :show unless actions.include? :show - ActiveScaffold::DataStructures::ActionLink.new(:none, options.merge({:crud_type => nil, :html_options => {:class => column.name}})) + ActiveScaffold::DataStructures::ActionLink.new(nil, options.merge(:html_options => {:class => column.name})) end end end diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 83cecda5e5..c786066413 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -82,8 +82,12 @@ def include_habtm_actions end def beginning_of_chain - if nested? && nested.association && nested.association.collection? - nested.parent_scope.send(nested.association.name) + if nested? && nested.association && !nested.association.belongs_to? + if nested.association.collection? + nested.parent_scope.send(nested.association.name) + elsif nested.child_association.belongs_to? + active_scaffold_config.model.where(nested.child_association.foreign_key => nested.parent_scope) + end elsif nested? && nested.scope nested.parent_scope.send(nested.scope) else diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index d41ade8896..c116c136b5 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -24,6 +24,7 @@ def add_link(attribute, options = {}) unless column.nil? || column.association.nil? options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) action_link = @core.link_for_association(column, options) + action_link.action ||= :index @core.action_links.add_to_group(action_link, action_group) unless action_link.nil? else diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 9f40f80131..756f8b38fb 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -3,15 +3,15 @@ class ActionLink # provides a quick way to set any property of the object from a hash def initialize(action, options = {}) # set defaults - self.action = action.to_s + self.action = action self.label = action self.confirm = false self.type = :collection self.inline = true self.method = :get - self.crud_type = :delete if [:destroy].include?(action.to_sym) - self.crud_type = :create if [:create, :new].include?(action.to_sym) - self.crud_type = :update if [:edit, :update].include?(action.to_sym) + self.crud_type = :delete if [:destroy].include?(action.try(:to_sym)) + self.crud_type = :create if [:create, :new].include?(action.try(:to_sym)) + self.crud_type = :update if [:edit, :update].include?(action.try(:to_sym)) self.crud_type ||= :read self.parameters = {} self.html_options = {} diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 4f2924c22d..f9eb7d04a7 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -34,13 +34,14 @@ def render_list_column(text, column, record) if column.link link = column.link associated = record.send(column.association.name) if column.association - url_options = params_for(:action => nil, :id => record.id, :link => text) + url_options = params_for(:action => nil, :id => record.id) # setup automatic link if column.autolink? && column.singular_association? # link to inline form - link = action_link_to_inline_form(column, record, associated) - return text if link.crud_type.nil? - url_options[:link] = as_(:create_new) if link.crud_type == :create + link = action_link_to_inline_form(column, record, associated, text) + return text if link.nil? + else + url_options[:link] = text end if column_link_authorized?(link, column, record, associated) @@ -55,8 +56,9 @@ def render_list_column(text, column, record) end # setup the action link to inline form - def action_link_to_inline_form(column, record, associated) + def action_link_to_inline_form(column, record, associated, text) link = column.link.clone + link.label = text if column.polymorphic_association? polymorphic_controller = controller_path_for_activerecord(record.send(column.association.name).class) return link if polymorphic_controller.nil? @@ -70,6 +72,7 @@ def configure_column_link(link, associated, actions) if actions.include?(:new) link.action = 'new' link.crud_type = :create + link.label = as_(:create_new) end elsif actions.include?(:edit) link.action = 'edit' @@ -81,7 +84,7 @@ def configure_column_link(link, associated, actions) link.action = 'index' link.crud_type = :read end - link + link if link.action.present? end def column_link_authorized?(link, column, record, associated) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 399e58754f..f17c1a958f 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -134,7 +134,7 @@ def action_link_url_options(link, url_options, record, options = {}) def action_link_html_options(link, url_options, record, html_options) link_id = get_action_link_id(url_options, record, link.column) - html_options.reverse_merge! link.html_options.merge(:class => link.action) + html_options.reverse_merge! link.html_options.merge(:class => link.action.to_s) # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails html_options[:method] = link.method if link.method != :get From da126afef3d59bb0b1e8cbefb6af9186e0146275 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 7 Oct 2011 18:16:56 +0200 Subject: [PATCH 1299/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 063d566928..fbf6a1b1af 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 4 + PATCH = 5 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 1cf4aefe793f1cdbbd4803fdd11880342586e06f Mon Sep 17 00:00:00 2001 From: "eric.beland@nemoves.com" <eric.beland@nemoves.com> Date: Wed, 12 Oct 2011 15:50:07 -0400 Subject: [PATCH 1300/2024] File column bridge tweaks --- .../bridges/file_column/form_ui.rb | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/lib/active_scaffold/bridges/file_column/form_ui.rb b/lib/active_scaffold/bridges/file_column/form_ui.rb index b2d84598d0..669731c22b 100644 --- a/lib/active_scaffold/bridges/file_column/form_ui.rb +++ b/lib/active_scaffold/bridges/file_column/form_ui.rb @@ -3,35 +3,32 @@ module Helpers # Helpers that assist with the rendering of a Form Column module FormColumnHelpers def active_scaffold_input_file_column(column, options) - if @record.send(column.name) - # we already have a value? display the form for deletion. + if @record.send(column.name) + # we already have a value? display the form for deletion. if ActiveScaffold.js_framework == :jquery - js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;"; + remove_file_js = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;"; else - js_remove_file_code = "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show(); return false;"; + remove_file_js = "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show(); return false;"; + end + + hidden_options = options.dup + hidden_options[:id] += '_delete' + hidden_options[:name].sub!("[#{column.name}]", "[delete_#{column.name}]") + hidden_options[:value] = 'false' + custom_hidden_field_tag = hidden_field(:record, column.name, hidden_options) + + content_tag(:div) do + content_tag(:div) do + content = get_column_value(@record, column) + " #{custom_hidden_field_tag} | " + content += content_tag(:a, as_(:remove_file), {:href => '#', :onclick => remove_file_js}) + content += content_tag(:div, file_column_field("record", column.name, options), :style => "display: none") + end end - content_tag( - :div, - content_tag( - :div, - get_column_value(@record, column) + " " + - custom_hidden_field_tag + - " | " + - content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code}), - {} - ) + - content_tag( - :div, - file_column_field("record", column.name, options), - :style => "display: none" - ), - {} - ) - else - # no, just display the file_column_field - file_column_field("record", column.name, options) - end - end + else + file_column_field("record", column.name, options) + end + end + end end end From b82a0ae523d9be73878ac49b59545396554c80d3 Mon Sep 17 00:00:00 2001 From: "eric.beland@nemoves.com" <eric.beland@nemoves.com> Date: Wed, 12 Oct 2011 16:22:27 -0400 Subject: [PATCH 1301/2024] fix for html escaping problem --- lib/active_scaffold/bridges/file_column/form_ui.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/file_column/form_ui.rb b/lib/active_scaffold/bridges/file_column/form_ui.rb index 669731c22b..81e6783b29 100644 --- a/lib/active_scaffold/bridges/file_column/form_ui.rb +++ b/lib/active_scaffold/bridges/file_column/form_ui.rb @@ -19,7 +19,7 @@ def active_scaffold_input_file_column(column, options) content_tag(:div) do content_tag(:div) do - content = get_column_value(@record, column) + " #{custom_hidden_field_tag} | " + content = get_column_value(@record, column) + " #{custom_hidden_field_tag} | ".html_safe content += content_tag(:a, as_(:remove_file), {:href => '#', :onclick => remove_file_js}) content += content_tag(:div, file_column_field("record", column.name, options), :style => "display: none") end From b2433eb88d5450881e1f8ab4e1d2b7cd65e141ab Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 19 Oct 2011 15:41:32 +0200 Subject: [PATCH 1302/2024] fix show label --- lib/active_scaffold/config/base.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/base.rb b/lib/active_scaffold/config/base.rb index 4947dd9b31..8deac89134 100644 --- a/lib/active_scaffold/config/base.rb +++ b/lib/active_scaffold/config/base.rb @@ -26,7 +26,8 @@ def crud_type=(val) def crud_type; self.class.crud_type end def label(model = nil) - as_(@label, :model => model || @core.label(:count => 1)) + model ||= @core.label(:count => 1) + @label.nil? ? model : as_(@label, :model => model) end # the user property gets set to the instantiation of the local UserSettings class during the automatic instantiation of this class. From cd89d324313489f84e1c71f26e3f2f2b1e3f243a Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Sun, 2 Oct 2011 09:21:32 -0700 Subject: [PATCH 1303/2024] build is an alias for new https://github.com/rails/rails/blob/24ade58875da9e7ae80aa0640f3374a80b202202/activerecord/lib/active_record/relation.rb#L87https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation.rb#L87 (cherry picked from commit f9709aa2761e587efb0899bf70c9ba671c9cacc3) --- lib/active_scaffold/actions/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 46f85192b9..26312c395a 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -165,7 +165,7 @@ def new_model params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column] end - model.respond_to?(:build) ? model.build(build_options || {}) : model.new + model.new(build_options || {}) end private From c4235cff950fa997126266de299e74e933d1e89a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 19 Oct 2011 15:55:26 +0200 Subject: [PATCH 1304/2024] fix sanitized html in messages displayed in on_create and on_update --- frontends/default/views/on_create.js.erb | 2 +- frontends/default/views/on_update.js.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/on_create.js.erb b/frontends/default/views/on_create.js.erb index ba33be0bcf..a8ceabb6ab 100644 --- a/frontends/default/views/on_create.js.erb +++ b/frontends/default/views/on_create.js.erb @@ -2,7 +2,7 @@ try { <% form_selector = "#{element_form_id(:action => :create)}" insert_at ||= :top %> var action_link = ActiveScaffold.find_action_link('<%= form_selector%>'); -action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages').strip)%>'); +action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages'))%>'); <% if controller.send :successful? %> <% if render_parent? && controller.respond_to?(:render_component_into_view) %> <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> diff --git a/frontends/default/views/on_update.js.erb b/frontends/default/views/on_update.js.erb index 67f878b0ca..444c43ff44 100644 --- a/frontends/default/views/on_update.js.erb +++ b/frontends/default/views/on_update.js.erb @@ -1,7 +1,7 @@ try { <% form_selector = "#{element_form_id(:action => :update)}" %> var action_link = ActiveScaffold.find_action_link('<%= form_selector%>'); -action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages').strip)%>'); +action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages'))%>'); <% if controller.send :successful? %> <% if render_parent? && controller.respond_to?(:render_component_into_view) %> <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> From 2326f7843b22e3fd65da45affd751fd6e6268909 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 19 Oct 2011 15:57:01 +0200 Subject: [PATCH 1305/2024] display all records allowed to read in the header; input will be rendered only for records allowed to create/update --- frontends/default/views/_horizontal_subform_header.html.erb | 2 +- frontends/default/views/_horizontal_subform_record.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_horizontal_subform_header.html.erb b/frontends/default/views/_horizontal_subform_header.html.erb index 40e8b3090b..eedab39455 100644 --- a/frontends/default/views/_horizontal_subform_header.html.erb +++ b/frontends/default/views/_horizontal_subform_header.html.erb @@ -1,7 +1,7 @@ <thead> <tr> <% - active_scaffold_config_for(record.class).subform.columns.each :for => record.class, :flatten => true do |column| + active_scaffold_config_for(record.class).subform.columns.each :for => record.class, :crud_type => :read, :flatten => true do |column| hidden = column_renders_as(column) == :hidden next unless in_subform?(column, parent_record) -%> diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index 7067b7cee9..9b3d4ba40a 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -8,7 +8,7 @@ tr_id = "association-#{options[:id]}" %> <tr id="<%= tr_id %>" class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> -<% config.subform.columns.each :for => @record.class, :crud_type => crud_type, :flatten => true do |column| %> +<% config.subform.columns.each :for => @record.class, :crud_type => :read, :flatten => true do |column| %> <% next unless in_subform?(column, parent_record) show_actions = true From 4bb4ea6d62e6e0407e9ba9b30ed77dbfdf155fa0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 20 Oct 2011 13:25:57 +0200 Subject: [PATCH 1306/2024] draggable lists for jquery, fix issue #79 --- app/assets/javascripts/active_scaffold.js.erb | 1 + .../javascripts/jquery/active_scaffold.js | 4 +++ .../javascripts/jquery/draggable_lists.js | 27 +++++++++++++++++++ .../javascripts/prototype/active_scaffold.js | 4 +++ .../stylesheets/active_scaffold.css.erb | 4 +++ .../helpers/form_column_helpers.rb | 2 +- 6 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/jquery/draggable_lists.js diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index 93caa4e8a5..ae23dfd018 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -4,6 +4,7 @@ <% require_asset "jquery/active_scaffold" %> <% require_asset "jquery/jquery.editinplace" %> <% require_asset "jquery/date_picker_bridge" %> +<% require_asset "jquery/draggable_lists" %> <% when :prototype %> <% require_asset "effects" %> <% require_asset "controls" %> diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index eb0e392b43..fc9d38c95c 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -762,6 +762,10 @@ var ActiveScaffold = { } } }); + }, + + draggable_lists: function(element) { + $('#' + element).draggable_lists(); } } diff --git a/app/assets/javascripts/jquery/draggable_lists.js b/app/assets/javascripts/jquery/draggable_lists.js new file mode 100644 index 0000000000..0fd09047a2 --- /dev/null +++ b/app/assets/javascripts/jquery/draggable_lists.js @@ -0,0 +1,27 @@ +jQuery.fn.draggable_lists = function() { + this.addClass('draggable-list'); + var list_selected = $(this.get(0).cloneNode(false)).addClass('selected'); + list_selected.attr('id', list_selected.attr('id') + '_selected').insertAfter(this); + this.find('input:checkbox').each(function(index, item) { + var li = $(item).closest('li').addClass('draggable-item'); + li.children('label').removeAttr('for'); + if ($(item).is(':checked')) li.appendTo(list_selected); + li.draggable({appendTo: 'body', helper: 'clone'}); + }); + $([this, list_selected]).droppable({ + hoverClass: 'hover', + accept: function(draggable) { + var parent_id = draggable.parent().attr('id'), id = $(this).attr('id'), + requested_id = $(this).hasClass('selected') ? id.replace('_selected', '') : id + '_selected'; + return parent_id == requested_id; + }, + drop: function(event, ui) { + $(this).append(ui.draggable); + var input = $('input:checkbox', ui.draggable); + if ($(this).hasClass('selected')) input.attr('checked', 'checked'); + else input.removeAttr('checked'); + ui.draggable.css({left: '0px', top: '0px'}); + } + }); + return this; +}; diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 52ceb9041c..eaa12a599f 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -626,6 +626,10 @@ var ActiveScaffold = { } } }); + }, + + draggable_lists: function(element) { + new DraggableLists(element); } } diff --git a/app/assets/stylesheets/active_scaffold.css.erb b/app/assets/stylesheets/active_scaffold.css.erb index a46bf71241..d66dfb1aa5 100644 --- a/app/assets/stylesheets/active_scaffold.css.erb +++ b/app/assets/stylesheets/active_scaffold.css.erb @@ -898,6 +898,10 @@ background-color: #7FCF00; display: block; } +li.draggable-item { + list-style: none; +} +li.draggable-item input, .active-scaffold .draggable-list input { display: none; } diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index a3545a43f6..4e816657e5 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -133,7 +133,7 @@ def active_scaffold_checkbox_list(column, select_options, associated_ids, option end content end - html << javascript_tag("new DraggableLists('#{options[:id]}')") if column.options[:draggable_lists] + html << javascript_tag("ActiveScaffold.draggable_lists('#{options[:id]}')") if column.options[:draggable_lists] html end From d22b3ac72a78936b6dd3335ddc9bb93754784954 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 20 Oct 2011 13:27:09 +0200 Subject: [PATCH 1307/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index fbf6a1b1af..e62e6a7c05 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 5 + PATCH = 6 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 004e0ebefdd1aa60a0d3b187d2e954bf2b4d6284 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 21 Oct 2011 09:40:24 +0200 Subject: [PATCH 1308/2024] fix on create --- frontends/default/views/on_create.js.erb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/on_create.js.erb b/frontends/default/views/on_create.js.erb index a8ceabb6ab..92dce8b406 100644 --- a/frontends/default/views/on_create.js.erb +++ b/frontends/default/views/on_create.js.erb @@ -16,9 +16,11 @@ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'mess <% end %> action_link.close(); <% end %> - <%#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> + <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> + ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); + <% end %> <% elsif (active_scaffold_config.create.refresh_list) %> - ActiveScaffold.replace_html(<%= active_scaffold_content_id%>, <%= escape_javascript(render(:partial => 'list', :layout => false)) %>); + ActiveScaffold.replace_html('<%= active_scaffold_content_id%>', '<%= escape_javascript(render(:partial => 'list', :layout => false)) %>'); <% elsif params[:parent_controller].nil? %> <% new_row = render :partial => 'list_record', :locals => {:record => @record} %> ActiveScaffold.create_record_row(action_link.scaffold(),'<%=escape_javascript(new_row)%>', <%={:insert_at => insert_at}.to_json.html_safe%>); From 1d4f0da634aa28a1e020a132c9279bc365b2ab98 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 21 Oct 2011 10:51:30 +0200 Subject: [PATCH 1309/2024] support a generic calculation formatter when column.calculate is a proc --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index f17c1a958f..d0df16a77e 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -265,7 +265,7 @@ def column_calculation(column) def render_column_calculation(column) calculation = column_calculation(column) - override_formatter = "render_#{column.name}_#{column.calculate}" + override_formatter = "render_#{column.name}_#{column.calculate.is_a?(Proc) ? :calculate : column.calculate}" calculation = send(override_formatter, calculation) if respond_to? override_formatter "#{"#{as_(column.calculate)}: " unless column.calculate.is_a? Proc}#{format_column_value nil, column, calculation}" From 98b50f0b9755b933e955ade54c184f75ab8e3ee1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 27 Oct 2011 14:40:36 +0200 Subject: [PATCH 1310/2024] Remove errors in horizontal subforms when row is removed Remove associated rows in horizontal subforms when row is removed, so you can override _horizontal_subform_record and add some associated rows below main one --- app/assets/javascripts/jquery/active_scaffold.js | 8 +++++++- app/assets/javascripts/prototype/active_scaffold.js | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index fc9d38c95c..098196984e 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -503,9 +503,15 @@ var ActiveScaffold = { record = $(record); var errors = record.prev(); if (errors.hasClass('association-record-errors')) { - this.replace_html(errors, ''); + this.remove(errors); } + var associated = $(record).next(); this.remove(record); + while (associated.hasClass('associated-record')) { + record = associated; + associated = $(record).next(); + this.remove(record); + } }, report_500_response: function(active_scaffold_id) { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index eaa12a599f..29c481a237 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -456,9 +456,15 @@ var ActiveScaffold = { delete_subform_record: function(record) { var errors = $(record).previous(); if (errors.hasClassName('association-record-errors')) { - this.replace_html(errors, ''); + this.remove(errors); } + var associated = $(record).next(); this.remove(record); + while (associated && associated.hasClassName('associated-record')) { + record = associated; + associated = $(record).next(); + this.remove(record); + } }, report_500_response: function(active_scaffold_id) { From 15675c9ae1e0ad5eb897f063ad8dec2a4a6520ea Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 27 Oct 2011 15:08:12 +0200 Subject: [PATCH 1311/2024] prepare next version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index e62e6a7c05..dbb43b5521 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 6 + PATCH = 7 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 513fc75d8bc31f98f34cd8dca6a654f366058d97 Mon Sep 17 00:00:00 2001 From: Andrey Korobkov <korobkov@fryxell.info> Date: Thu, 27 Oct 2011 18:16:34 +0400 Subject: [PATCH 1312/2024] updating russian locale --- config/locales/ru.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/config/locales/ru.yml b/config/locales/ru.yml index ee3b2c4c20..d783f87739 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -84,8 +84,8 @@ ru: this_year: 'В этом году' prev_year: 'В прошлом году' next_year: 'В следующем году' - past: 'Прошлое' - future: 'Будущее' + past: 'Прошедшие' + future: 'Будущие' range: 'Интервал' seconds: 'секунд' minutes: 'минут' @@ -102,10 +102,9 @@ ru: firstDay: 1 isRTL: false showMonthAfterYear: false + datetime_picker_options: - timeText: 'Время' - currentText: 'Сегодня' - closeText: 'Закрыть' + errors: template: header: @@ -117,6 +116,8 @@ ru: # error_messages cant_destroy_record: 'Запись %{record} не может быть удалена' - failed_to_save_record: 'Запись не может быть сохранена из-за неизвестной ошибки' internal_error: '500 Внутренняя ошибка сервера' version_inconsistency: 'Эта запись была обновлена с того момента, как вы начали ее редактировать' + record_not_saved: 'Запись не может быть сохранена из-за неизвестной ошибки' + no_authorization_for_action: 'Нет прав на выполнение действия "%{action}"' + From 3c7b4986629fd95f1bd52d41327a7446f0c30818 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 28 Oct 2011 11:27:19 +0200 Subject: [PATCH 1313/2024] remove unneeded render call in update_column action --- frontends/default/views/update_column.js.erb | 6 +++--- lib/active_scaffold/actions/update.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/update_column.js.erb b/frontends/default/views/update_column.js.erb index 77a08a8c82..cf1af853e3 100644 --- a/frontends/default/views/update_column.js.erb +++ b/frontends/default/views/update_column.js.erb @@ -1,14 +1,14 @@ -<% column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column])%> +<% @column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column]) %> <% unless controller.send :successful?%> alert('<%= escape_javascript(@record.errors.full_messages.join("\n"))%>'); <% @record.reload%> <% end%> <% column = active_scaffold_config.columns[params[:column]]%> <% if column.inplace_edit%> - ActiveScaffold.replace_html('<%=column_span_id%>','<%=escape_javascript(format_inplace_edit_column(@record, column))%>'); + ActiveScaffold.replace_html('<%=@column_span_id%>','<%=escape_javascript(format_inplace_edit_column(@record, column))%>'); <% else%> <% formatted_value = get_column_value(@record, column)%> - ActiveScaffold.replace_html('<%=column_span_id%>','<%=escape_javascript(formatted_value)%>'); + ActiveScaffold.replace_html('<%=@column_span_id%>','<%=escape_javascript(formatted_value)%>'); <% end%> <% if column.calculation?%> ActiveScaffold.replace_html('<%=active_scaffold_calculations_id(column)%>', '<%=escape_javascript(render_column_calculation(column))%>'); diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index a3c94ec0cc..5fcd71fdcd 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -18,7 +18,7 @@ def update # for inline (inlist) editing def update_column do_update_column - render :action => 'update_column', :locals => {:column_span_id => params[:editor_id] || params[:editorId]} + @column_span_id = params[:editor_id] || params[:editorId] end protected From df58e0c0b431567a5065d4b1c541e4066f42c375 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 28 Oct 2011 13:07:20 +0200 Subject: [PATCH 1314/2024] undo setting @record in inplace_edit_control --- lib/active_scaffold/helpers/list_column_helpers.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index f9eb7d04a7..a9129fd54a 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -275,11 +275,13 @@ def active_scaffold_inplace_edit(record, column, options = {}) def inplace_edit_control(column) if inplace_edit?(active_scaffold_config.model, column) and inplace_edit_cloning?(column) - @record = new_model + old_record, @record = @record, new_model column = column.clone column.options = column.options.clone column.form_ui = :select if (column.association && column.form_ui.nil?) - content_tag(:div, active_scaffold_input_for(column), {:style => "display:none;", :class => inplace_edit_control_css_class}) + content_tag(:div, active_scaffold_input_for(column), :style => "display:none;", :class => inplace_edit_control_css_class).tap do + @record = old_record + end end end From 55981839072920c48a6449e36bafea7ab2aac556 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 28 Oct 2011 13:17:41 +0200 Subject: [PATCH 1315/2024] undo setting @record with always_show_search/create --- frontends/default/views/_list_with_header.html.erb | 4 ++++ lib/active_scaffold/actions/list.rb | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_list_with_header.html.erb b/frontends/default/views/_list_with_header.html.erb index 262189a27f..2278906468 100644 --- a/frontends/default/views/_list_with_header.html.erb +++ b/frontends/default/views/_list_with_header.html.erb @@ -5,6 +5,7 @@ <table cellpadding="0" cellspacing="0"> <tbody class="before-header" id="<%= before_header_id -%>"> <% if active_scaffold_config.list.always_show_search %> + <% old_record, @record = @record, new_model %> <tr> <td> <div class="active-scaffold show_search-view <%= "#{params[:controller]}-view" %> view"> @@ -12,10 +13,12 @@ </div> </td> </tr> + <% @record = old_record %> <% else %> <tr><td></td></tr> <% end %> <% if !nested? && active_scaffold_config.list.always_show_create %> + <% old_record, @record = @record, new_model %> <tr> <td> <div class="active-scaffold create-view <%= "#{params[:controller]}-view" %> view"> @@ -23,6 +26,7 @@ </div> </td> </tr> + <% @record = old_record %> <% end %> </tbody> </table> diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 869e64a2d9..20ec757c2c 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -17,8 +17,6 @@ def row def list do_list - do_new if active_scaffold_config.list.always_show_create - @record ||= new_model if active_scaffold_config.list.always_show_search @nested_auto_open = active_scaffold_config.list.nested_auto_open respond_to_action(:list) end From 8cc8b1cc6258f6ddf2bd6319f5d01539b0168c5b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 8 Nov 2011 12:15:32 +0100 Subject: [PATCH 1316/2024] add timepicker addon for jquery --- app/assets/javascripts/active_scaffold.js.erb | 1 + .../javascripts/jquery-ui-timepicker-addon.js | 1276 +++++++++++++++++ 2 files changed, 1277 insertions(+) create mode 100644 vendor/assets/javascripts/jquery-ui-timepicker-addon.js diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index ae23dfd018..e51401d90a 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -1,6 +1,7 @@ <% case ActiveScaffold.js_framework %> <% when :jquery %> <% require_asset "jquery-ui" %> +<% require_asset "jquery-ui-timepicker-addon" %> <% require_asset "jquery/active_scaffold" %> <% require_asset "jquery/jquery.editinplace" %> <% require_asset "jquery/date_picker_bridge" %> diff --git a/vendor/assets/javascripts/jquery-ui-timepicker-addon.js b/vendor/assets/javascripts/jquery-ui-timepicker-addon.js new file mode 100644 index 0000000000..d72c481d5e --- /dev/null +++ b/vendor/assets/javascripts/jquery-ui-timepicker-addon.js @@ -0,0 +1,1276 @@ +/* +* jQuery timepicker addon +* By: Trent Richardson [http://trentrichardson.com] +* Version 0.9.7 +* Last Modified: 10/02/2011 +* +* Copyright 2011 Trent Richardson +* Dual licensed under the MIT and GPL licenses. +* http://trentrichardson.com/Impromptu/GPL-LICENSE.txt +* http://trentrichardson.com/Impromptu/MIT-LICENSE.txt +* +* HERES THE CSS: +* .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; } +* .ui-timepicker-div dl { text-align: left; } +* .ui-timepicker-div dl dt { height: 25px; } +* .ui-timepicker-div dl dd { margin: -25px 10px 10px 65px; } +* .ui-timepicker-div td { font-size: 90%; } +* .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; } +*/ + +(function($) { + +$.extend($.ui, { timepicker: { version: "0.9.7" } }); + +/* Time picker manager. + Use the singleton instance of this class, $.timepicker, to interact with the time picker. + Settings for (groups of) time pickers are maintained in an instance object, + allowing multiple different settings on the same page. */ + +function Timepicker() { + this.regional = []; // Available regional settings, indexed by language code + this.regional[''] = { // Default regional settings + currentText: 'Now', + closeText: 'Done', + ampm: false, + amNames: ['AM', 'A'], + pmNames: ['PM', 'P'], + timeFormat: 'hh:mm tt', + timeSuffix: '', + timeOnlyTitle: 'Choose Time', + timeText: 'Time', + hourText: 'Hour', + minuteText: 'Minute', + secondText: 'Second', + millisecText: 'Millisecond', + timezoneText: 'Time Zone' + }; + this._defaults = { // Global defaults for all the datetime picker instances + showButtonPanel: true, + timeOnly: false, + showHour: true, + showMinute: true, + showSecond: false, + showMillisec: false, + showTimezone: false, + showTime: true, + stepHour: 0.05, + stepMinute: 0.05, + stepSecond: 0.05, + stepMillisec: 0.5, + hour: 0, + minute: 0, + second: 0, + millisec: 0, + timezone: '+0000', + hourMin: 0, + minuteMin: 0, + secondMin: 0, + millisecMin: 0, + hourMax: 23, + minuteMax: 59, + secondMax: 59, + millisecMax: 999, + minDateTime: null, + maxDateTime: null, + onSelect: null, + hourGrid: 0, + minuteGrid: 0, + secondGrid: 0, + millisecGrid: 0, + alwaysSetTime: true, + separator: ' ', + altFieldTimeOnly: true, + showTimepicker: true, + timezoneIso8609: false, + timezoneList: null + }; + $.extend(this._defaults, this.regional['']); +} + +$.extend(Timepicker.prototype, { + $input: null, + $altInput: null, + $timeObj: null, + inst: null, + hour_slider: null, + minute_slider: null, + second_slider: null, + millisec_slider: null, + timezone_select: null, + hour: 0, + minute: 0, + second: 0, + millisec: 0, + timezone: '+0000', + hourMinOriginal: null, + minuteMinOriginal: null, + secondMinOriginal: null, + millisecMinOriginal: null, + hourMaxOriginal: null, + minuteMaxOriginal: null, + secondMaxOriginal: null, + millisecMaxOriginal: null, + ampm: '', + formattedDate: '', + formattedTime: '', + formattedDateTime: '', + timezoneList: null, + + /* Override the default settings for all instances of the time picker. + @param settings object - the new settings to use as defaults (anonymous object) + @return the manager object */ + setDefaults: function(settings) { + extendRemove(this._defaults, settings || {}); + return this; + }, + + //######################################################################## + // Create a new Timepicker instance + //######################################################################## + _newInst: function($input, o) { + var tp_inst = new Timepicker(), + inlineSettings = {}; + + for (var attrName in this._defaults) { + var attrValue = $input.attr('time:' + attrName); + if (attrValue) { + try { + inlineSettings[attrName] = eval(attrValue); + } catch (err) { + inlineSettings[attrName] = attrValue; + } + } + } + tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, { + beforeShow: function(input, dp_inst) { + if ($.isFunction(o.beforeShow)) + o.beforeShow(input, dp_inst, tp_inst); + }, + onChangeMonthYear: function(year, month, dp_inst) { + // Update the time as well : this prevents the time from disappearing from the $input field. + tp_inst._updateDateTime(dp_inst); + if ($.isFunction(o.onChangeMonthYear)) + o.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst); + }, + onClose: function(dateText, dp_inst) { + if (tp_inst.timeDefined === true && $input.val() != '') + tp_inst._updateDateTime(dp_inst); + if ($.isFunction(o.onClose)) + o.onClose.call($input[0], dateText, dp_inst, tp_inst); + }, + timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); + }); + tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { return val.toUpperCase() }); + tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { return val.toUpperCase() }); + + if (tp_inst._defaults.timezoneList === null) { + var timezoneList = []; + for (var i = -11; i <= 12; i++) + timezoneList.push((i >= 0 ? '+' : '-') + ('0' + Math.abs(i).toString()).slice(-2) + '00'); + if (tp_inst._defaults.timezoneIso8609) + timezoneList = $.map(timezoneList, function(val) { + return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3)); + }); + tp_inst._defaults.timezoneList = timezoneList; + } + + tp_inst.hour = tp_inst._defaults.hour; + tp_inst.minute = tp_inst._defaults.minute; + tp_inst.second = tp_inst._defaults.second; + tp_inst.millisec = tp_inst._defaults.millisec; + tp_inst.ampm = ''; + tp_inst.$input = $input; + + if (o.altField) + tp_inst.$altInput = $(o.altField) + .css({ cursor: 'pointer' }) + .focus(function(){ $input.trigger("focus"); }); + + if(tp_inst._defaults.minDate==0 || tp_inst._defaults.minDateTime==0) + { + tp_inst._defaults.minDate=new Date(); + } + if(tp_inst._defaults.maxDate==0 || tp_inst._defaults.maxDateTime==0) + { + tp_inst._defaults.maxDate=new Date(); + } + + // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime.. + if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) + tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime()); + if(tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date) + tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime()); + if(tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date) + tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime()); + if(tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) + tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime()); + return tp_inst; + }, + + //######################################################################## + // add our sliders to the calendar + //######################################################################## + _addTimePicker: function(dp_inst) { + var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? + this.$input.val() + ' ' + this.$altInput.val() : + this.$input.val(); + + this.timeDefined = this._parseTime(currDT); + this._limitMinMaxDateTime(dp_inst, false); + this._injectTimePicker(); + }, + + //######################################################################## + // parse the time string from input value or _setTime + //######################################################################## + _parseTime: function(timeString, withDate) { + var regstr = this._defaults.timeFormat.toString() + .replace(/h{1,2}/ig, '(\\d?\\d)') + .replace(/m{1,2}/ig, '(\\d?\\d)') + .replace(/s{1,2}/ig, '(\\d?\\d)') + .replace(/l{1}/ig, '(\\d?\\d?\\d)') + .replace(/t{1,2}/ig, this._getPatternAmpm()) + .replace(/z{1}/ig, '(z|[-+]\\d\\d:?\\d\\d)?') + .replace(/\s/g, '\\s?') + this._defaults.timeSuffix + '$', + order = this._getFormatPositions(), + ampm = '', + treg; + + if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]); + + if (withDate || !this._defaults.timeOnly) { + // the time should come after x number of characters and a space. + // x = at least the length of text specified by the date format + var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat'); + // escape special regex characters in the seperator + var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); + regstr = '.{' + dp_dateFormat.length + ',}' + this._defaults.separator.replace(specials, "\\$&") + regstr; + } + + treg = timeString.match(new RegExp(regstr, 'i')); + + if (treg) { + if (order.t !== -1) { + if (treg[order.t] === undefined || treg[order.t].length === 0) { + ampm = ''; + this.ampm = ''; + } else { + ampm = $.inArray(treg[order.t].toUpperCase(), this.amNames) !== -1 ? 'AM' : 'PM'; + this.ampm = this._defaults[ampm == 'AM' ? 'amNames' : 'pmNames'][0]; + } + } + + if (order.h !== -1) { + if (ampm == 'AM' && treg[order.h] == '12') + this.hour = 0; // 12am = 0 hour + else if (ampm == 'PM' && treg[order.h] != '12') + this.hour = (parseFloat(treg[order.h]) + 12).toFixed(0); // 12pm = 12 hour, any other pm = hour + 12 + else this.hour = Number(treg[order.h]); + } + + if (order.m !== -1) this.minute = Number(treg[order.m]); + if (order.s !== -1) this.second = Number(treg[order.s]); + if (order.l !== -1) this.millisec = Number(treg[order.l]); + if (order.z !== -1 && treg[order.z] !== undefined) { + var tz = treg[order.z].toUpperCase(); + switch (tz.length) { + case 1: // Z + tz = this._defaults.timezoneIso8609 ? 'Z' : '+0000'; + break; + case 5: // +hhmm + if (this._defaults.timezoneIso8609) + tz = tz.substring(1) == '0000' + ? 'Z' + : tz.substring(0, 3) + ':' + tz.substring(3); + break; + case 6: // +hh:mm + if (!this._defaults.timezoneIso8609) + tz = tz == 'Z' || tz.substring(1) == '00:00' + ? '+0000' + : tz.replace(/:/, ''); + else if (tz.substring(1) == '00:00') + tz = 'Z'; + break; + } + this.timezone = tz; + } + + return true; + + } + return false; + }, + + //######################################################################## + // pattern for standard and localized AM/PM markers + //######################################################################## + _getPatternAmpm: function() { + var markers = []; + o = this._defaults; + if (o.amNames) + $.merge(markers, o.amNames); + if (o.pmNames) + $.merge(markers, o.pmNames); + markers = $.map(markers, function(val) { return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&') }); + return '(' + markers.join('|') + ')?'; + }, + + //######################################################################## + // figure out position of time elements.. cause js cant do named captures + //######################################################################## + _getFormatPositions: function() { + var finds = this._defaults.timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z)/g), + orders = { h: -1, m: -1, s: -1, l: -1, t: -1, z: -1 }; + + if (finds) + for (var i = 0; i < finds.length; i++) + if (orders[finds[i].toString().charAt(0)] == -1) + orders[finds[i].toString().charAt(0)] = i + 1; + + return orders; + }, + + //######################################################################## + // generate and inject html for timepicker into ui datepicker + //######################################################################## + _injectTimePicker: function() { + var $dp = this.inst.dpDiv, + o = this._defaults, + tp_inst = this, + // Added by Peter Medeiros: + // - Figure out what the hour/minute/second max should be based on the step values. + // - Example: if stepMinute is 15, then minMax is 45. + hourMax = (o.hourMax - ((o.hourMax - o.hourMin) % o.stepHour)).toFixed(0), + minMax = (o.minuteMax - ((o.minuteMax - o.minuteMin) % o.stepMinute)).toFixed(0), + secMax = (o.secondMax - ((o.secondMax - o.secondMin) % o.stepSecond)).toFixed(0), + millisecMax = (o.millisecMax - ((o.millisecMax - o.millisecMin) % o.stepMillisec)).toFixed(0), + dp_id = this.inst.id.toString().replace(/([^A-Za-z0-9_])/g, ''); + + // Prevent displaying twice + //if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0) { + if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0 && o.showTimepicker) { + var noDisplay = ' style="display:none;"', + html = '<div class="ui-timepicker-div" id="ui-timepicker-div-' + dp_id + '"><dl>' + + '<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_' + dp_id + '"' + + ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' + + '<dd class="ui_tpicker_time" id="ui_tpicker_time_' + dp_id + '"' + + ((o.showTime) ? '' : noDisplay) + '></dd>' + + '<dt class="ui_tpicker_hour_label" id="ui_tpicker_hour_label_' + dp_id + '"' + + ((o.showHour) ? '' : noDisplay) + '>' + o.hourText + '</dt>', + hourGridSize = 0, + minuteGridSize = 0, + secondGridSize = 0, + millisecGridSize = 0, + size; + + // Hours + if (o.showHour && o.hourGrid > 0) { + html += '<dd class="ui_tpicker_hour">' + + '<div id="ui_tpicker_hour_' + dp_id + '"' + ((o.showHour) ? '' : noDisplay) + '></div>' + + '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>'; + + for (var h = o.hourMin; h <= hourMax; h += parseInt(o.hourGrid,10)) { + hourGridSize++; + var tmph = (o.ampm && h > 12) ? h-12 : h; + if (tmph < 10) tmph = '0' + tmph; + if (o.ampm) { + if (h == 0) tmph = 12 +'a'; + else if (h < 12) tmph += 'a'; + else tmph += 'p'; + } + html += '<td>' + tmph + '</td>'; + } + + html += '</tr></table></div>' + + '</dd>'; + } else html += '<dd class="ui_tpicker_hour" id="ui_tpicker_hour_' + dp_id + '"' + + ((o.showHour) ? '' : noDisplay) + '></dd>'; + + html += '<dt class="ui_tpicker_minute_label" id="ui_tpicker_minute_label_' + dp_id + '"' + + ((o.showMinute) ? '' : noDisplay) + '>' + o.minuteText + '</dt>'; + + // Minutes + if (o.showMinute && o.minuteGrid > 0) { + html += '<dd class="ui_tpicker_minute ui_tpicker_minute_' + o.minuteGrid + '">' + + '<div id="ui_tpicker_minute_' + dp_id + '"' + + ((o.showMinute) ? '' : noDisplay) + '></div>' + + '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>'; + + for (var m = o.minuteMin; m <= minMax; m += parseInt(o.minuteGrid,10)) { + minuteGridSize++; + html += '<td>' + ((m < 10) ? '0' : '') + m + '</td>'; + } + + html += '</tr></table></div>' + + '</dd>'; + } else html += '<dd class="ui_tpicker_minute" id="ui_tpicker_minute_' + dp_id + '"' + + ((o.showMinute) ? '' : noDisplay) + '></dd>'; + + // Seconds + html += '<dt class="ui_tpicker_second_label" id="ui_tpicker_second_label_' + dp_id + '"' + + ((o.showSecond) ? '' : noDisplay) + '>' + o.secondText + '</dt>'; + + if (o.showSecond && o.secondGrid > 0) { + html += '<dd class="ui_tpicker_second ui_tpicker_second_' + o.secondGrid + '">' + + '<div id="ui_tpicker_second_' + dp_id + '"' + + ((o.showSecond) ? '' : noDisplay) + '></div>' + + '<div style="padding-left: 1px"><table><tr>'; + + for (var s = o.secondMin; s <= secMax; s += parseInt(o.secondGrid,10)) { + secondGridSize++; + html += '<td>' + ((s < 10) ? '0' : '') + s + '</td>'; + } + + html += '</tr></table></div>' + + '</dd>'; + } else html += '<dd class="ui_tpicker_second" id="ui_tpicker_second_' + dp_id + '"' + + ((o.showSecond) ? '' : noDisplay) + '></dd>'; + + // Milliseconds + html += '<dt class="ui_tpicker_millisec_label" id="ui_tpicker_millisec_label_' + dp_id + '"' + + ((o.showMillisec) ? '' : noDisplay) + '>' + o.millisecText + '</dt>'; + + if (o.showMillisec && o.millisecGrid > 0) { + html += '<dd class="ui_tpicker_millisec ui_tpicker_millisec_' + o.millisecGrid + '">' + + '<div id="ui_tpicker_millisec_' + dp_id + '"' + + ((o.showMillisec) ? '' : noDisplay) + '></div>' + + '<div style="padding-left: 1px"><table><tr>'; + + for (var l = o.millisecMin; l <= millisecMax; l += parseInt(o.millisecGrid,10)) { + millisecGridSize++; + html += '<td>' + ((l < 10) ? '0' : '') + s + '</td>'; + } + + html += '</tr></table></div>' + + '</dd>'; + } else html += '<dd class="ui_tpicker_millisec" id="ui_tpicker_millisec_' + dp_id + '"' + + ((o.showMillisec) ? '' : noDisplay) + '></dd>'; + + // Timezone + html += '<dt class="ui_tpicker_timezone_label" id="ui_tpicker_timezone_label_' + dp_id + '"' + + ((o.showTimezone) ? '' : noDisplay) + '>' + o.timezoneText + '</dt>'; + html += '<dd class="ui_tpicker_timezone" id="ui_tpicker_timezone_' + dp_id + '"' + + ((o.showTimezone) ? '' : noDisplay) + '></dd>'; + + html += '</dl></div>'; + $tp = $(html); + + // if we only want time picker... + if (o.timeOnly === true) { + $tp.prepend( + '<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' + + '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' + + '</div>'); + $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide(); + } + + this.hour_slider = $tp.find('#ui_tpicker_hour_'+ dp_id).slider({ + orientation: "horizontal", + value: this.hour, + min: o.hourMin, + max: hourMax, + step: o.stepHour, + slide: function(event, ui) { + tp_inst.hour_slider.slider( "option", "value", ui.value); + tp_inst._onTimeChange(); + } + }); + + // Updated by Peter Medeiros: + // - Pass in Event and UI instance into slide function + this.minute_slider = $tp.find('#ui_tpicker_minute_'+ dp_id).slider({ + orientation: "horizontal", + value: this.minute, + min: o.minuteMin, + max: minMax, + step: o.stepMinute, + slide: function(event, ui) { + // update the global minute slider instance value with the current slider value + tp_inst.minute_slider.slider( "option", "value", ui.value); + tp_inst._onTimeChange(); + } + }); + + this.second_slider = $tp.find('#ui_tpicker_second_'+ dp_id).slider({ + orientation: "horizontal", + value: this.second, + min: o.secondMin, + max: secMax, + step: o.stepSecond, + slide: function(event, ui) { + tp_inst.second_slider.slider( "option", "value", ui.value); + tp_inst._onTimeChange(); + } + }); + + this.millisec_slider = $tp.find('#ui_tpicker_millisec_'+ dp_id).slider({ + orientation: "horizontal", + value: this.millisec, + min: o.millisecMin, + max: millisecMax, + step: o.stepMillisec, + slide: function(event, ui) { + tp_inst.millisec_slider.slider( "option", "value", ui.value); + tp_inst._onTimeChange(); + } + }); + + this.timezone_select = $tp.find('#ui_tpicker_timezone_'+ dp_id).append('<select></select>').find("select"); + $.fn.append.apply(this.timezone_select, + $.map(o.timezoneList, function(val, idx) { + return $("<option />") + .val(typeof val == "object" ? val.value : val) + .text(typeof val == "object" ? val.label : val); + }) + ); + this.timezone_select.val((typeof this.timezone != "undefined" && this.timezone != null && this.timezone != "") ? this.timezone : o.timezone); + this.timezone_select.change(function() { + tp_inst._onTimeChange(); + }); + + // Add grid functionality + if (o.showHour && o.hourGrid > 0) { + size = 100 * hourGridSize * o.hourGrid / (hourMax - o.hourMin); + + $tp.find(".ui_tpicker_hour table").css({ + width: size + "%", + marginLeft: (size / (-2 * hourGridSize)) + "%", + borderCollapse: 'collapse' + }).find("td").each( function(index) { + $(this).click(function() { + var h = $(this).html(); + if(o.ampm) { + var ap = h.substring(2).toLowerCase(), + aph = parseInt(h.substring(0,2), 10); + if (ap == 'a') { + if (aph == 12) h = 0; + else h = aph; + } else if (aph == 12) h = 12; + else h = aph + 12; + } + tp_inst.hour_slider.slider("option", "value", h); + tp_inst._onTimeChange(); + tp_inst._onSelectHandler(); + }).css({ + cursor: 'pointer', + width: (100 / hourGridSize) + '%', + textAlign: 'center', + overflow: 'hidden' + }); + }); + } + + if (o.showMinute && o.minuteGrid > 0) { + size = 100 * minuteGridSize * o.minuteGrid / (minMax - o.minuteMin); + $tp.find(".ui_tpicker_minute table").css({ + width: size + "%", + marginLeft: (size / (-2 * minuteGridSize)) + "%", + borderCollapse: 'collapse' + }).find("td").each(function(index) { + $(this).click(function() { + tp_inst.minute_slider.slider("option", "value", $(this).html()); + tp_inst._onTimeChange(); + tp_inst._onSelectHandler(); + }).css({ + cursor: 'pointer', + width: (100 / minuteGridSize) + '%', + textAlign: 'center', + overflow: 'hidden' + }); + }); + } + + if (o.showSecond && o.secondGrid > 0) { + $tp.find(".ui_tpicker_second table").css({ + width: size + "%", + marginLeft: (size / (-2 * secondGridSize)) + "%", + borderCollapse: 'collapse' + }).find("td").each(function(index) { + $(this).click(function() { + tp_inst.second_slider.slider("option", "value", $(this).html()); + tp_inst._onTimeChange(); + tp_inst._onSelectHandler(); + }).css({ + cursor: 'pointer', + width: (100 / secondGridSize) + '%', + textAlign: 'center', + overflow: 'hidden' + }); + }); + } + + if (o.showMillisec && o.millisecGrid > 0) { + $tp.find(".ui_tpicker_millisec table").css({ + width: size + "%", + marginLeft: (size / (-2 * millisecGridSize)) + "%", + borderCollapse: 'collapse' + }).find("td").each(function(index) { + $(this).click(function() { + tp_inst.millisec_slider.slider("option", "value", $(this).html()); + tp_inst._onTimeChange(); + tp_inst._onSelectHandler(); + }).css({ + cursor: 'pointer', + width: (100 / millisecGridSize) + '%', + textAlign: 'center', + overflow: 'hidden' + }); + }); + } + + var $buttonPanel = $dp.find('.ui-datepicker-buttonpane'); + if ($buttonPanel.length) $buttonPanel.before($tp); + else $dp.append($tp); + + this.$timeObj = $tp.find('#ui_tpicker_time_'+ dp_id); + + if (this.inst !== null) { + var timeDefined = this.timeDefined; + this._onTimeChange(); + this.timeDefined = timeDefined; + } + + //Emulate datepicker onSelect behavior. Call on slidestop. + var onSelectDelegate = function() { + tp_inst._onSelectHandler(); + }; + this.hour_slider.bind('slidestop',onSelectDelegate); + this.minute_slider.bind('slidestop',onSelectDelegate); + this.second_slider.bind('slidestop',onSelectDelegate); + this.millisec_slider.bind('slidestop',onSelectDelegate); + } + }, + + //######################################################################## + // This function tries to limit the ability to go outside the + // min/max date range + //######################################################################## + _limitMinMaxDateTime: function(dp_inst, adjustSliders){ + var o = this._defaults, + dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay); + + if(!this._defaults.showTimepicker) return; // No time so nothing to check here + + if($.datepicker._get(dp_inst, 'minDateTime') !== null && $.datepicker._get(dp_inst, 'minDateTime') !== undefined && dp_date){ + var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'), + minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0); + + if(this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null || this.millisecMinOriginal === null){ + this.hourMinOriginal = o.hourMin; + this.minuteMinOriginal = o.minuteMin; + this.secondMinOriginal = o.secondMin; + this.millisecMinOriginal = o.millisecMin; + } + + if(dp_inst.settings.timeOnly || minDateTimeDate.getTime() == dp_date.getTime()) { + this._defaults.hourMin = minDateTime.getHours(); + if (this.hour <= this._defaults.hourMin) { + this.hour = this._defaults.hourMin; + this._defaults.minuteMin = minDateTime.getMinutes(); + if (this.minute <= this._defaults.minuteMin) { + this.minute = this._defaults.minuteMin; + this._defaults.secondMin = minDateTime.getSeconds(); + } else if (this.second <= this._defaults.secondMin){ + this.second = this._defaults.secondMin; + this._defaults.millisecMin = minDateTime.getMilliseconds(); + } else { + if(this.millisec < this._defaults.millisecMin) + this.millisec = this._defaults.millisecMin; + this._defaults.millisecMin = this.millisecMinOriginal; + } + } else { + this._defaults.minuteMin = this.minuteMinOriginal; + this._defaults.secondMin = this.secondMinOriginal; + this._defaults.millisecMin = this.millisecMinOriginal; + } + }else{ + this._defaults.hourMin = this.hourMinOriginal; + this._defaults.minuteMin = this.minuteMinOriginal; + this._defaults.secondMin = this.secondMinOriginal; + this._defaults.millisecMin = this.millisecMinOriginal; + } + } + + if($.datepicker._get(dp_inst, 'maxDateTime') !== null && $.datepicker._get(dp_inst, 'maxDateTime') !== undefined && dp_date){ + var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'), + maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0); + + if(this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null){ + this.hourMaxOriginal = o.hourMax; + this.minuteMaxOriginal = o.minuteMax; + this.secondMaxOriginal = o.secondMax; + this.millisecMaxOriginal = o.millisecMax; + } + + if(dp_inst.settings.timeOnly || maxDateTimeDate.getTime() == dp_date.getTime()){ + this._defaults.hourMax = maxDateTime.getHours(); + if (this.hour >= this._defaults.hourMax) { + this.hour = this._defaults.hourMax; + this._defaults.minuteMax = maxDateTime.getMinutes(); + if (this.minute >= this._defaults.minuteMax) { + this.minute = this._defaults.minuteMax; + this._defaults.secondMax = maxDateTime.getSeconds(); + } else if (this.second >= this._defaults.secondMax) { + this.second = this._defaults.secondMax; + this._defaults.millisecMax = maxDateTime.getMilliseconds(); + } else { + if(this.millisec > this._defaults.millisecMax) this.millisec = this._defaults.millisecMax; + this._defaults.millisecMax = this.millisecMaxOriginal; + } + } else { + this._defaults.minuteMax = this.minuteMaxOriginal; + this._defaults.secondMax = this.secondMaxOriginal; + this._defaults.millisecMax = this.millisecMaxOriginal; + } + }else{ + this._defaults.hourMax = this.hourMaxOriginal; + this._defaults.minuteMax = this.minuteMaxOriginal; + this._defaults.secondMax = this.secondMaxOriginal; + this._defaults.millisecMax = this.millisecMaxOriginal; + } + } + + if(adjustSliders !== undefined && adjustSliders === true){ + var hourMax = (this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)).toFixed(0), + minMax = (this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)).toFixed(0), + secMax = (this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)).toFixed(0), + millisecMax = (this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)).toFixed(0); + + if(this.hour_slider) + this.hour_slider.slider("option", { min: this._defaults.hourMin, max: hourMax }).slider('value', this.hour); + if(this.minute_slider) + this.minute_slider.slider("option", { min: this._defaults.minuteMin, max: minMax }).slider('value', this.minute); + if(this.second_slider) + this.second_slider.slider("option", { min: this._defaults.secondMin, max: secMax }).slider('value', this.second); + if(this.millisec_slider) + this.millisec_slider.slider("option", { min: this._defaults.millisecMin, max: millisecMax }).slider('value', this.millisec); + } + + }, + + + //######################################################################## + // when a slider moves, set the internal time... + // on time change is also called when the time is updated in the text field + //######################################################################## + _onTimeChange: function() { + var hour = (this.hour_slider) ? this.hour_slider.slider('value') : false, + minute = (this.minute_slider) ? this.minute_slider.slider('value') : false, + second = (this.second_slider) ? this.second_slider.slider('value') : false, + millisec = (this.millisec_slider) ? this.millisec_slider.slider('value') : false, + timezone = (this.timezone_select) ? this.timezone_select.val() : false, + o = this._defaults; + + if (typeof(hour) == 'object') hour = false; + if (typeof(minute) == 'object') minute = false; + if (typeof(second) == 'object') second = false; + if (typeof(millisec) == 'object') millisec = false; + if (typeof(timezone) == 'object') timezone = false; + + if (hour !== false) hour = parseInt(hour,10); + if (minute !== false) minute = parseInt(minute,10); + if (second !== false) second = parseInt(second,10); + if (millisec !== false) millisec = parseInt(millisec,10); + + var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0]; + + // If the update was done in the input field, the input field should not be updated. + // If the update was done using the sliders, update the input field. + var hasChanged = (hour != this.hour || minute != this.minute + || second != this.second || millisec != this.millisec + || (this.ampm.length > 0 + && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) + || timezone != this.timezone); + + if (hasChanged) { + + if (hour !== false)this.hour = hour; + if (minute !== false) this.minute = minute; + if (second !== false) this.second = second; + if (millisec !== false) this.millisec = millisec; + if (timezone !== false) this.timezone = timezone; + + if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]); + + this._limitMinMaxDateTime(this.inst, true); + } + if (o.ampm) this.ampm = ampm; + + this._formatTime(); + if (this.$timeObj) this.$timeObj.text(this.formattedTime + o.timeSuffix); + this.timeDefined = true; + if (hasChanged) this._updateDateTime(); + }, + + //######################################################################## + // call custom onSelect. + // bind to sliders slidestop, and grid click. + //######################################################################## + _onSelectHandler: function() { + var onSelect = this._defaults.onSelect; + var inputEl = this.$input ? this.$input[0] : null; + if (onSelect && inputEl) { + onSelect.apply(inputEl, [this.formattedDateTime, this]); + } + }, + + //######################################################################## + // format the time all pretty... + //######################################################################## + _formatTime: function(time, format, ampm) { + if (ampm == undefined) ampm = this._defaults.ampm; + time = time || { hour: this.hour, minute: this.minute, second: this.second, millisec: this.millisec, ampm: this.ampm, timezone: this.timezone }; + var tmptime = (format || this._defaults.timeFormat).toString(); + + var hour = parseInt(time.hour, 10); + if (ampm) { + if (!$.inArray(time.ampm.toUpperCase(), this.amNames) !== -1) + hour = hour % 12; + if (hour === 0) + hour = 12; + } + tmptime = tmptime.replace(/(?:hh?|mm?|ss?|[tT]{1,2}|[lz])/g, function(match) { + switch (match.toLowerCase()) { + case 'hh': return ('0' + hour).slice(-2); + case 'h': return hour; + case 'mm': return ('0' + time.minute).slice(-2); + case 'm': return time.minute; + case 'ss': return ('0' + time.second).slice(-2); + case 's': return time.second; + case 'l': return ('00' + time.millisec).slice(-3); + case 'z': return time.timezone; + case 't': case 'tt': + if (ampm) { + var _ampm = time.ampm; + if (match.length == 1) + _ampm = _ampm.charAt(0); + return match.charAt(0) == 'T' ? _ampm.toUpperCase() : _ampm.toLowerCase(); + } + return ''; + } + }); + + if (arguments.length) return tmptime; + else this.formattedTime = tmptime; + }, + + //######################################################################## + // update our input with the new date time.. + //######################################################################## + _updateDateTime: function(dp_inst) { + dp_inst = this.inst || dp_inst, + dt = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay), + dateFmt = $.datepicker._get(dp_inst, 'dateFormat'), + formatCfg = $.datepicker._getFormatConfig(dp_inst), + timeAvailable = dt !== null && this.timeDefined; + this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg); + var formattedDateTime = this.formattedDate; + if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0)) + return; + + if (this._defaults.timeOnly === true) { + formattedDateTime = this.formattedTime; + } else if (this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) { + formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix; + } + + this.formattedDateTime = formattedDateTime; + + if(!this._defaults.showTimepicker) { + this.$input.val(this.formattedDate); + } else if (this.$altInput && this._defaults.altFieldTimeOnly === true) { + this.$altInput.val(this.formattedTime); + this.$input.val(this.formattedDate); + } else if(this.$altInput) { + this.$altInput.val(formattedDateTime); + this.$input.val(formattedDateTime); + } else { + this.$input.val(formattedDateTime); + } + + this.$input.trigger("change"); + } + +}); + +$.fn.extend({ + //######################################################################## + // shorthand just to use timepicker.. + //######################################################################## + timepicker: function(o) { + o = o || {}; + var tmp_args = arguments; + + if (typeof o == 'object') tmp_args[0] = $.extend(o, { timeOnly: true }); + + return $(this).each(function() { + $.fn.datetimepicker.apply($(this), tmp_args); + }); + }, + + //######################################################################## + // extend timepicker to datepicker + //######################################################################## + datetimepicker: function(o) { + o = o || {}; + var $input = this, + tmp_args = arguments; + + if (typeof(o) == 'string'){ + if(o == 'getDate') + return $.fn.datepicker.apply($(this[0]), tmp_args); + else + return this.each(function() { + var $t = $(this); + $t.datepicker.apply($t, tmp_args); + }); + } + else + return this.each(function() { + var $t = $(this); + $t.datepicker($.timepicker._newInst($t, o)._defaults); + }); + } +}); + +//######################################################################## +// the bad hack :/ override datepicker so it doesnt close on select +// inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378 +//######################################################################## +$.datepicker._base_selectDate = $.datepicker._selectDate; +$.datepicker._selectDate = function (id, dateStr) { + var inst = this._getInst($(id)[0]), + tp_inst = this._get(inst, 'timepicker'); + + if (tp_inst) { + tp_inst._limitMinMaxDateTime(inst, true); + inst.inline = inst.stay_open = true; + //This way the onSelect handler called from calendarpicker get the full dateTime + this._base_selectDate(id, dateStr); + inst.inline = inst.stay_open = false; + this._notifyChange(inst); + this._updateDatepicker(inst); + } + else this._base_selectDate(id, dateStr); +}; + +//############################################################################################# +// second bad hack :/ override datepicker so it triggers an event when changing the input field +// and does not redraw the datepicker on every selectDate event +//############################################################################################# +$.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker; +$.datepicker._updateDatepicker = function(inst) { + + // don't popup the datepicker if there is another instance already opened + var input = inst.input[0]; + if($.datepicker._curInst && + $.datepicker._curInst != inst && + $.datepicker._datepickerShowing && + $.datepicker._lastInput != input) { + return; + } + + if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) { + + this._base_updateDatepicker(inst); + + // Reload the time control when changing something in the input text field. + var tp_inst = this._get(inst, 'timepicker'); + if(tp_inst) tp_inst._addTimePicker(inst); + } +}; + +//####################################################################################### +// third bad hack :/ override datepicker so it allows spaces and colon in the input field +//####################################################################################### +$.datepicker._base_doKeyPress = $.datepicker._doKeyPress; +$.datepicker._doKeyPress = function(event) { + var inst = $.datepicker._getInst(event.target), + tp_inst = $.datepicker._get(inst, 'timepicker'); + + if (tp_inst) { + if ($.datepicker._get(inst, 'constrainInput')) { + var ampm = tp_inst._defaults.ampm, + dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')), + datetimeChars = tp_inst._defaults.timeFormat.toString() + .replace(/[hms]/g, '') + .replace(/TT/g, ampm ? 'APM' : '') + .replace(/Tt/g, ampm ? 'AaPpMm' : '') + .replace(/tT/g, ampm ? 'AaPpMm' : '') + .replace(/T/g, ampm ? 'AP' : '') + .replace(/tt/g, ampm ? 'apm' : '') + .replace(/t/g, ampm ? 'ap' : '') + + " " + + tp_inst._defaults.separator + + tp_inst._defaults.timeSuffix + + (tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') + + (tp_inst._defaults.amNames.join('')) + + (tp_inst._defaults.pmNames.join('')) + + dateChars, + chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode); + return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1); + } + } + + return $.datepicker._base_doKeyPress(event); +}; + +//####################################################################################### +// Override key up event to sync manual input changes. +//####################################################################################### +$.datepicker._base_doKeyUp = $.datepicker._doKeyUp; +$.datepicker._doKeyUp = function (event) { + var inst = $.datepicker._getInst(event.target), + tp_inst = $.datepicker._get(inst, 'timepicker'); + + if (tp_inst) { + if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) { + try { + $.datepicker._updateDatepicker(inst); + } + catch (err) { + $.datepicker.log(err); + } + } + } + + return $.datepicker._base_doKeyUp(event); +}; + +//####################################################################################### +// override "Today" button to also grab the time. +//####################################################################################### +$.datepicker._base_gotoToday = $.datepicker._gotoToday; +$.datepicker._gotoToday = function(id) { + var inst = this._getInst($(id)[0]), + $dp = inst.dpDiv; + this._base_gotoToday(id); + var now = new Date(); + var tp_inst = this._get(inst, 'timepicker'); + if (tp_inst._defaults.showTimezone && tp_inst.timezone_select) { + var tzoffset = now.getTimezoneOffset(); // If +0100, returns -60 + var tzsign = tzoffset > 0 ? '-' : '+'; + tzoffset = Math.abs(tzoffset); + var tzmin = tzoffset % 60 + tzoffset = tzsign + ('0' + (tzoffset - tzmin) / 60).slice(-2) + ('0' + tzmin).slice(-2); + if (tp_inst._defaults.timezoneIso8609) + tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3); + tp_inst.timezone_select.val(tzoffset); + } + this._setTime(inst, now); + $( '.ui-datepicker-today', $dp).click(); +}; + +//####################################################################################### +// Disable & enable the Time in the datetimepicker +//####################################################################################### +$.datepicker._disableTimepickerDatepicker = function(target, date, withDate) { + var inst = this._getInst(target), + tp_inst = this._get(inst, 'timepicker'); + $(target).datepicker('getDate'); // Init selected[Year|Month|Day] + if (tp_inst) { + tp_inst._defaults.showTimepicker = false; + tp_inst._updateDateTime(inst); + } +}; + +$.datepicker._enableTimepickerDatepicker = function(target, date, withDate) { + var inst = this._getInst(target), + tp_inst = this._get(inst, 'timepicker'); + $(target).datepicker('getDate'); // Init selected[Year|Month|Day] + if (tp_inst) { + tp_inst._defaults.showTimepicker = true; + tp_inst._addTimePicker(inst); // Could be disabled on page load + tp_inst._updateDateTime(inst); + } +}; + +//####################################################################################### +// Create our own set time function +//####################################################################################### +$.datepicker._setTime = function(inst, date) { + var tp_inst = this._get(inst, 'timepicker'); + if (tp_inst) { + var defaults = tp_inst._defaults, + // calling _setTime with no date sets time to defaults + hour = date ? date.getHours() : defaults.hour, + minute = date ? date.getMinutes() : defaults.minute, + second = date ? date.getSeconds() : defaults.second, + millisec = date ? date.getMilliseconds() : defaults.millisec; + + //check if within min/max times.. + if ((hour < defaults.hourMin || hour > defaults.hourMax) || (minute < defaults.minuteMin || minute > defaults.minuteMax) || (second < defaults.secondMin || second > defaults.secondMax) || (millisec < defaults.millisecMin || millisec > defaults.millisecMax)) { + hour = defaults.hourMin; + minute = defaults.minuteMin; + second = defaults.secondMin; + millisec = defaults.millisecMin; + } + + tp_inst.hour = hour; + tp_inst.minute = minute; + tp_inst.second = second; + tp_inst.millisec = millisec; + + if (tp_inst.hour_slider) tp_inst.hour_slider.slider('value', hour); + if (tp_inst.minute_slider) tp_inst.minute_slider.slider('value', minute); + if (tp_inst.second_slider) tp_inst.second_slider.slider('value', second); + if (tp_inst.millisec_slider) tp_inst.millisec_slider.slider('value', millisec); + + tp_inst._onTimeChange(); + tp_inst._updateDateTime(inst); + } +}; + +//####################################################################################### +// Create new public method to set only time, callable as $().datepicker('setTime', date) +//####################################################################################### +$.datepicker._setTimeDatepicker = function(target, date, withDate) { + var inst = this._getInst(target), + tp_inst = this._get(inst, 'timepicker'); + + if (tp_inst) { + this._setDateFromField(inst); + var tp_date; + if (date) { + if (typeof date == "string") { + tp_inst._parseTime(date, withDate); + tp_date = new Date(); + tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec); + } + else tp_date = new Date(date.getTime()); + if (tp_date.toString() == 'Invalid Date') tp_date = undefined; + this._setTime(inst, tp_date); + } + } + +}; + +//####################################################################################### +// override setDate() to allow setting time too within Date object +//####################################################################################### +$.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker; +$.datepicker._setDateDatepicker = function(target, date) { + var inst = this._getInst(target), + tp_date = (date instanceof Date) ? new Date(date.getTime()) : date; + + this._updateDatepicker(inst); + this._base_setDateDatepicker.apply(this, arguments); + this._setTimeDatepicker(target, tp_date, true); +}; + +//####################################################################################### +// override getDate() to allow getting time too within Date object +//####################################################################################### +$.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker; +$.datepicker._getDateDatepicker = function(target, noDefault) { + var inst = this._getInst(target), + tp_inst = this._get(inst, 'timepicker'); + + if (tp_inst) { + this._setDateFromField(inst, noDefault); + var date = this._getDate(inst); + if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec); + return date; + } + return this._base_getDateDatepicker(target, noDefault); +}; + +//####################################################################################### +// override parseDate() because UI 1.8.14 throws an error about "Extra characters" +// An option in datapicker to ignore extra format characters would be nicer. +//####################################################################################### +$.datepicker._base_parseDate = $.datepicker.parseDate; +$.datepicker.parseDate = function(format, value, settings) { + var date; + try { + date = this._base_parseDate(format, value, settings); + } catch (err) { + // Hack! The error message ends with a colon, a space, and + // the "extra" characters. We rely on that instead of + // attempting to perfectly reproduce the parsing algorithm. + date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings); + } + return date; +}; + +//####################################################################################### +// override formatDate to set date with time to the input +//####################################################################################### +$.datepicker._base_formatDate=$.datepicker._formatDate; +$.datepicker._formatDate = function(inst, day, month, year){ + var tp_inst = this._get(inst, 'timepicker'); + if(tp_inst) + { + if(day) + var b = this._base_formatDate(inst, day, month, year); + tp_inst._updateDateTime(); + return tp_inst.$input.val(); + } + return this._base_formatDate(inst); +} + +//####################################################################################### +// override options setter to add time to maxDate(Time) and minDate(Time). MaxDate +//####################################################################################### +$.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker; +$.datepicker._optionDatepicker = function(target, name, value) { + var inst = this._getInst(target), + tp_inst = this._get(inst, 'timepicker'); + if (tp_inst) { + var min,max,onselect; + if (typeof name == 'string') { // if min/max was set with the string + if (name==='minDate' || name==='minDateTime' ) + min = value; + else if (name==='maxDate' || name==='maxDateTime') + max = value; + else if (name==='onSelect') + onselect=value; + } else if (typeof name == 'object') { //if min/max was set with the JSON + if(name.minDate) + min = name.minDate; + else if (name.minDateTime) + min = name.minDateTime; + else if (name.maxDate) + max = name.maxDate; + else if (name.maxDateTime) + max = name.maxDateTime; + } + if(min){ //if min was set + if(min==0) + min=new Date(); + else + min= new Date(min); + + tp_inst._defaults.minDate = min; + tp_inst._defaults.minDateTime = min; + } else if (max){ //if max was set + if(max==0) + max=new Date(); + else + max= new Date(max); + tp_inst._defaults.maxDate = max; + tp_inst._defaults.maxDateTime = max; + } + else if (onselect) + tp_inst._defaults.onSelect=onselect; + } + this._base_optionDatepicker(target, name, value); +}; + +//####################################################################################### +// jQuery extend now ignores nulls! +//####################################################################################### +function extendRemove(target, props) { + $.extend(target, props); + for (var name in props) + if (props[name] === null || props[name] === undefined) + target[name] = props[name]; + return target; +} + +$.timepicker = new Timepicker(); // singleton instance +$.timepicker.version = "0.9.7"; + +})(jQuery); + From 75ad8124c85ed6683ba3f64c15be43ff4aaf853d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 8 Nov 2011 13:04:45 +0100 Subject: [PATCH 1317/2024] fix access to @record in in_subform? helper method for subform header, it could be needed for overriding --- frontends/default/views/_horizontal_subform.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index a136bc671b..32945c91e4 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -1,6 +1,6 @@ <table cellpadding="0" cellspacing="0"> <% - record = if associated.empty? + @record = if associated.empty? if column.singular_association? parent_record.send("build_#{column.name}".to_sym) else @@ -10,7 +10,7 @@ associated.last end -%> - <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record, :record => record} %> + <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record, :record => @record} %> <tbody id="<%= sub_form_list_id(:association => column.name) %>"> <% associated.each_index do |index| %> From fec48d5c4efb7985a612d51d04917789300d02b8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 9 Nov 2011 13:47:24 +0100 Subject: [PATCH 1318/2024] fix html tag --- frontends/default/views/_horizontal_subform.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index 32945c91e4..a5f5304ef8 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -25,8 +25,8 @@ <%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> <% end -%> </tbody> - <tfooter> + <tfoot> <%= render :partial => 'horizontal_subform_footer', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column} %> - </tfooter> + </tfoot> </table> <%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%> From d1e7b3adab7d47a81e30c6ddb2e506e51365a920 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 9 Nov 2011 17:44:26 +0100 Subject: [PATCH 1319/2024] add support for record_select_autocomplete --- .../bridges/record_select/helpers.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/active_scaffold/bridges/record_select/helpers.rb b/lib/active_scaffold/bridges/record_select/helpers.rb index ed5abb0fab..c18700b723 100644 --- a/lib/active_scaffold/bridges/record_select/helpers.rb +++ b/lib/active_scaffold/bridges/record_select/helpers.rb @@ -16,6 +16,8 @@ def active_scaffold_input_record_select(column, options) active_scaffold_record_select(column, options, @record.send(column.name), multiple) elsif column.plural_association? active_scaffold_record_select(column, options, @record.send(column.name), true) + else + active_scaffold_record_select_autocomplete(column, options) end end @@ -51,6 +53,23 @@ def active_scaffold_record_select(column, options, value, multiple) html = self.class.field_error_proc.call(html, self) if @record.errors[column.name].any? html end + + def active_scaffold_record_select_autocomplete(column, options) + record_select_options = active_scaffold_input_text_options( + :controller => active_scaffold_controller_for(@record.class).controller_path, + :id => options[:id], + :class => options[:class].gsub(/update_form/, '') + ) + if options['data-update_url'] + record_select_options[:onchange] = %|function(id, label) { + ActiveScaffold.update_column(null, "#{options['data-update_url']}", #{options['data-update_send_form'].to_json}, "#{options[:id]}", id); + }| + end + + html = record_select_autocomplete(options[:name], @record, record_select_options) + html = self.class.field_error_proc.call(html, self) if @record.errors[column.name].any? + html + end end module SearchColumnHelpers From 036f29a5b5957f4537c07981497fdc263b6e9b25 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 9 Nov 2011 18:00:21 +0100 Subject: [PATCH 1320/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index dbb43b5521..844c46917d 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 7 + PATCH = 8 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 00612fe5e8691e762353260e5275b45c6fc8ee04 Mon Sep 17 00:00:00 2001 From: Claas Abert <=> Date: Thu, 10 Nov 2011 01:16:17 +0100 Subject: [PATCH 1321/2024] Fix tinymce bridge --- .../javascripts/jquery/active_scaffold.js | 19 +++++++++++++++++++ lib/active_scaffold/bridges/tiny_mce.rb | 4 ++++ .../bridges/tiny_mce/helpers.rb | 12 ++++++------ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 098196984e..83fad7a1da 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -67,6 +67,24 @@ $(document).ready(function() { return true; }); $('a.as_cancel').live('ajax:before', function(event) { + /* implementation from vhochstein, solves tiny_mce issue */ + var as_cancel = $(this); + var action_link = ActiveScaffold.find_action_link(as_cancel); + + if (action_link) { + var cancel_url = as_cancel.attr('href'); + var refresh_data = as_cancel.attr('data-refresh'); + if (refresh_data === 'true' && action_link.refresh_url) { + event.data_url = action_link.refresh_url; + if (action_link.position) event.data_type = 'html' + } else if (refresh_data === 'false' || typeof(cancel_url) == 'undefined' || cancel_url.length == 0) { + action_link.close(); + return false; + } + } + return true; + + /* var as_cancel = $(this); var action_link = ActiveScaffold.find_action_link(as_cancel); @@ -78,6 +96,7 @@ $(document).ready(function() { } } return true; + */ }); $('a.as_cancel').live('ajax:success', function(event, response) { var action_link = ActiveScaffold.find_action_link($(this)); diff --git a/lib/active_scaffold/bridges/tiny_mce.rb b/lib/active_scaffold/bridges/tiny_mce.rb index 0349f9560f..026189eac8 100644 --- a/lib/active_scaffold/bridges/tiny_mce.rb +++ b/lib/active_scaffold/bridges/tiny_mce.rb @@ -2,4 +2,8 @@ class ActiveScaffold::Bridges::TinyMce < ActiveScaffold::DataStructures::Bridge def self.install require File.join(File.dirname(__FILE__), "tiny_mce/helpers.rb") end + + def self.install? + true # TODO check if tinymce-rails ist installed + end end diff --git a/lib/active_scaffold/bridges/tiny_mce/helpers.rb b/lib/active_scaffold/bridges/tiny_mce/helpers.rb index ce2a09c925..430c8e1cdc 100644 --- a/lib/active_scaffold/bridges/tiny_mce/helpers.rb +++ b/lib/active_scaffold/bridges/tiny_mce/helpers.rb @@ -19,7 +19,7 @@ def active_scaffold_includes(*args) }); action_link_close.apply(this); }; - |) if using_tiny_mce? + |) #if using_tiny_mce? TODO check if tiny mce is included else tiny_mce_js = javascript_tag(%| var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; @@ -29,7 +29,7 @@ def active_scaffold_includes(*args) }); action_link_close.apply(this); }; - |) if using_tiny_mce? + |) #if using_tiny_mce? TODO check if tiny mce is included end super(*args) + (include_tiny_mce_if_needed || '') + (tiny_mce_js || '') end @@ -48,13 +48,13 @@ def active_scaffold_input_text_editor(column, options) html.join "\n" end - def onsubmit + def onsubmit_with_tiny_mce if ActiveScaffold.js_framework == :jquery - submit_js = 'tinyMCE.triggerSave();$(\'textarea.mceEditor\').each(function(index, elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, $(elem).attr(\'id\')); });' if using_tiny_mce? + submit_js = 'tinyMCE.triggerSave();$(\'textarea.mceEditor\').each(function(index, elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, $(elem).attr(\'id\')); });' #if using_tiny_mce? TODO check if tine mce is included else - submit_js = 'tinyMCE.triggerSave();this.select(\'textarea.mceEditor\').each(function(elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, elem.id); });' if using_tiny_mce? + submit_js = 'tinyMCE.triggerSave();this.select(\'textarea.mceEditor\').each(function(elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, elem.id); });' #if using_tiny_mce? TODO check if tiny mce is included end - [super, submit_js].compact.join ';' + [onsubmit_without_tiny_mce, submit_js].compact.join ';' end end From e6adca70f9060962af4ffb0d170eaf16a3e13fff Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 14 Nov 2011 09:48:49 +0100 Subject: [PATCH 1322/2024] remove clean_column_value from views, is not needed and it was escaping twice in update view. fix issue #88 --- frontends/default/views/_show.html.erb | 2 +- frontends/default/views/_update_form.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_show.html.erb b/frontends/default/views/_show.html.erb index 4fb506e382..8a28421b95 100644 --- a/frontends/default/views/_show.html.erb +++ b/frontends/default/views/_show.html.erb @@ -1,4 +1,4 @@ -<h4><%= active_scaffold_config.show.label(@record.to_label.nil? ? nil : clean_column_value(@record.to_label)) %></h4> +<h4><%= active_scaffold_config.show.label(@record.to_label.nil? ? nil : @record.to_label) %></h4> <%= render :partial => 'show_columns', :locals => {:columns => active_scaffold_config.show.columns} -%> diff --git a/frontends/default/views/_update_form.html.erb b/frontends/default/views/_update_form.html.erb index e153409797..9ec9c320f1 100644 --- a/frontends/default/views/_update_form.html.erb +++ b/frontends/default/views/_update_form.html.erb @@ -3,4 +3,4 @@ :form_action => form_action ||= :update, :method => method ||= :put, :cancel_link => cancel_link, - :headline => headline ||= @record.to_label.nil? ? active_scaffold_config.update.label : as_(:update_model, :model => clean_column_value(@record.to_label))} %> + :headline => headline ||= @record.to_label.nil? ? active_scaffold_config.update.label : as_(:update_model, :model => @record.to_label)} %> From c2dec6c96518bbe7bb3eadef1b54fb219a8cbed8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 14 Nov 2011 09:52:36 +0100 Subject: [PATCH 1323/2024] truncate string before escaping, it could break a html entity --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index a9129fd54a..05cf1e2a79 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -119,7 +119,7 @@ def clean_column_value(v) ## Overrides ## def active_scaffold_column_text(column, record) - truncate(clean_column_value(record.send(column.name)), :length => column.options[:truncate] || 50) + clean_column_value(truncate(record.send(column.name), :length => column.options[:truncate] || 50)) end def active_scaffold_column_checkbox(column, record) From b8bddb9fca461d3e8e0fd140601c9b47fa36ecf1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 14 Nov 2011 10:17:34 +0100 Subject: [PATCH 1324/2024] fix escaping in associations --- lib/active_scaffold/helpers/list_column_helpers.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 05cf1e2a79..236948b7c2 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -190,25 +190,25 @@ def format_number_value(value, options = {}) end def format_association_value(value, column, size) - case column.association.macro + format_value case column.association.macro when :has_one, :belongs_to if column.polymorphic_association? - format_value("#{value.class.model_name.human}: #{value.to_label}") + "#{value.class.model_name.human}: #{value.to_label}" else - format_value(value.to_label) + value.to_label end when :has_many, :has_and_belongs_to_many if column.associated_limit.nil? - firsts = value.collect { |v| clean_column_value(v.to_label) } + firsts = value.collect { |v| v.to_label } else firsts = value.first(column.associated_limit) - firsts.collect! { |v| clean_column_value(v.to_label) } + firsts.collect! { |v| v.to_label } firsts[column.associated_limit] = '…' if value.size > column.associated_limit end if column.associated_limit == 0 size if column.associated_number? else - joined_associated = format_value(firsts.join(active_scaffold_config.list.association_join_text)) + joined_associated = firsts.join('&') joined_associated << " (#{size})" if column.associated_number? and column.associated_limit and value.size > column.associated_limit joined_associated end From c547b613323aebf4611e48d2f4b6e0e47c972e0c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 14 Nov 2011 10:18:41 +0100 Subject: [PATCH 1325/2024] remove code for debugging --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 236948b7c2..e213d1f882 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -208,7 +208,7 @@ def format_association_value(value, column, size) if column.associated_limit == 0 size if column.associated_number? else - joined_associated = firsts.join('&') + joined_associated = firsts.join(active_scaffold_config.list.association_join_text) joined_associated << " (#{size})" if column.associated_number? and column.associated_limit and value.size > column.associated_limit joined_associated end From c55f4207718bf91122a0724a97ed50935acead27 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 14 Nov 2011 13:15:57 +0100 Subject: [PATCH 1326/2024] remove format_inplace_edit_column and use get_column_value, it's possible now that code for rendering list is simpler --- frontends/default/views/update_column.js.erb | 2 +- lib/active_scaffold/helpers/list_column_helpers.rb | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/frontends/default/views/update_column.js.erb b/frontends/default/views/update_column.js.erb index cf1af853e3..a3b9f902d1 100644 --- a/frontends/default/views/update_column.js.erb +++ b/frontends/default/views/update_column.js.erb @@ -5,7 +5,7 @@ <% end%> <% column = active_scaffold_config.columns[params[:column]]%> <% if column.inplace_edit%> - ActiveScaffold.replace_html('<%=@column_span_id%>','<%=escape_javascript(format_inplace_edit_column(@record, column))%>'); + ActiveScaffold.replace_html('<%=@column_span_id%>','<%=escape_javascript(get_column_value(@record, column))%>'); <% else%> <% formatted_value = get_column_value(@record, column)%> ActiveScaffold.replace_html('<%=@column_span_id%>','<%=escape_javascript(formatted_value)%>'); diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index e213d1f882..b264c29808 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -256,14 +256,6 @@ def inplace_edit_cloning?(column) column.inplace_edit != :ajax and (override_form_field?(column) or column.form_ui or (column.column and override_input?(column.column.type))) end - def format_inplace_edit_column(record,column) - if column.list_ui == :checkbox - active_scaffold_column_checkbox(column, record) - else - format_column_value(record, column) - end - end - def active_scaffold_inplace_edit(record, column, options = {}) formatted_column = options[:formatted_column] || format_column_value(record, column) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} From 7857659accd24b43370dd5799752b2b3f325fa33 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 14 Nov 2011 13:27:09 +0100 Subject: [PATCH 1327/2024] enable update_columns for textareas --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 098196984e..14c2ef44ed 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -147,7 +147,7 @@ $(document).ready(function() { return true; } else return false; }); - $('input.update_form, select.update_form').live('change', function(event) { + $('input.update_form, textarea.update_form, select.update_form').live('change', function(event) { var element = $(this); var value = element.is("input:checkbox:not(:checked)") ? null : element.val(); ActiveScaffold.update_column(element, element.attr('data-update_url'), element.attr('data-update_send_form'), element.attr('id'), value); From 42c85ac53b58283f1600f45987a526a2d6c7dd7c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 14 Nov 2011 17:53:21 +0100 Subject: [PATCH 1328/2024] update for more unobtrusive record_select --- .../javascripts/jquery/active_scaffold.js | 5 ++++ .../javascripts/prototype/active_scaffold.js | 7 +++++- .../bridges/record_select/helpers.rb | 23 ++++--------------- lib/active_scaffold/version.rb | 2 +- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 14c2ef44ed..c899e7c9a6 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -153,6 +153,11 @@ $(document).ready(function() { ActiveScaffold.update_column(element, element.attr('data-update_url'), element.attr('data-update_send_form'), element.attr('id'), value); return true; }); + $('input.recordselect.update_form').live('recordselect:change', function(event, id, label) { + var element = $(this); + ActiveScaffold.update_column(element, element.attr('data-update_url'), element.attr('data-update_send_form'), element.attr('id'), id); + return true; + }); $('select.as_search_range_option').live('change', function(event) { ActiveScaffold[$(this).val() == 'BETWEEN' ? 'show' : 'hide']($(this).parent().find('.as_search_range_between')); diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 29c481a237..46409361ef 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -236,11 +236,16 @@ document.observe("dom:loaded", function() { event.memo.url = url; return true; }); - document.on('change', 'input.update_form, select.update_form', function(event) { + document.on('change', 'input.update_form, textarea.update_form, select.update_form', function(event) { var element = event.findElement(); ActiveScaffold.update_column(element, element.readAttribute('data-update_url'), element.hasAttribute('data-update_send_form'), element.readAttribute('id'), element.getValue()); return true; }); + document.on('recordselect:change', 'input.recordselect.update_form', function(event) { + var element = event.findElement(); + ActiveScaffold.update_column(element, element.readAttribute('data-update_url'), element.hasAttribute('data-update_send_form'), element.readAttribute('id'), element.memo.id); + return true; + }); document.on('change', 'select.as_search_range_option', function(event) { var element = event.findElement(); Element[element.value == 'BETWEEN' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_between')); diff --git a/lib/active_scaffold/bridges/record_select/helpers.rb b/lib/active_scaffold/bridges/record_select/helpers.rb index c18700b723..ac3b1a4381 100644 --- a/lib/active_scaffold/bridges/record_select/helpers.rb +++ b/lib/active_scaffold/bridges/record_select/helpers.rb @@ -33,17 +33,10 @@ def active_scaffold_record_select(column, options, value, multiple) params.merge!({column.association.primary_key_name => ''}) end - record_select_options = active_scaffold_input_text_options( - :controller => remote_controller, - :id => options[:id], - :class => options[:class].gsub(/update_form/, '') + record_select_options = active_scaffold_input_text_options(options).merge( + :controller => remote_controller ) record_select_options.merge!(column.options) - if options['data-update_url'] - record_select_options[:onchange] = %|function(id, label) { - ActiveScaffold.update_column(null, "#{options['data-update_url']}", #{options['data-update_send_form'].to_json}, "#{options[:id]}", id); - }| - end html = if multiple record_multi_select_field(options[:name], value || [], record_select_options) @@ -55,17 +48,9 @@ def active_scaffold_record_select(column, options, value, multiple) end def active_scaffold_record_select_autocomplete(column, options) - record_select_options = active_scaffold_input_text_options( - :controller => active_scaffold_controller_for(@record.class).controller_path, - :id => options[:id], - :class => options[:class].gsub(/update_form/, '') + record_select_options = active_scaffold_input_text_options(options).merge( + :controller => remote_controller ) - if options['data-update_url'] - record_select_options[:onchange] = %|function(id, label) { - ActiveScaffold.update_column(null, "#{options['data-update_url']}", #{options['data-update_send_form'].to_json}, "#{options[:id]}", id); - }| - end - html = record_select_autocomplete(options[:name], @record, record_select_options) html = self.class.field_error_proc.call(html, self) if @record.errors[column.name].any? html diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 844c46917d..1bc28e5e49 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 8 + PATCH = 9 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From df24d4a336281b986e99546512174101c1fda66b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 16 Nov 2011 17:51:37 +0100 Subject: [PATCH 1329/2024] support proc in i18n. Fix #89 --- .../bridges/date_picker/helper.rb | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index 4a2edaf316..a74c78a1eb 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -33,29 +33,25 @@ def self.date_options_for_locales def self.date_options(locale) begin - date_options = I18n.translate! 'date', :locale => locale date_picker_options = { :closeText => as_(:close), :prevText => as_(:previous), :nextText => as_(:next), :currentText => as_(:today), - :monthNames => date_options[:month_names][1, (date_options[:month_names].length - 1)], - :monthNamesShort => date_options[:abbr_month_names][1, (date_options[:abbr_month_names].length - 1)], - :dayNames => date_options[:day_names], - :dayNamesShort => date_options[:abbr_day_names], - :dayNamesMin => date_options[:abbr_day_names], + :monthNames => I18n.translate!('date.month_names', :locale => locale)[1..-1], + :monthNamesShort => I18n.translate!('date.abbr_month_names', :locale => locale)[1..-1], + :dayNames => I18n.translate!('date.day_names', :locale => locale), + :dayNamesShort => I18n.translate!('date.abbr_day_names', :locale => locale), + :dayNamesMin => I18n.translate!('date.abbr_day_names', :locale => locale), :changeYear => true, :changeMonth => true, } - begin - as_date_picker_options = I18n.translate! 'active_scaffold.date_picker_options' - date_picker_options.merge!(as_date_picker_options) if as_date_picker_options.is_a? Hash - rescue - Rails.logger.warn "ActiveScaffold: Missing date picker localization for your locale: #{locale}" - end + as_date_picker_options = I18n.translate! :date_picker_options, :scope => :active_scaffold, :locale => locale, :default => '' + date_picker_options.merge!(as_date_picker_options) if as_date_picker_options.is_a? Hash + Rails.logger.warn "ActiveScaffold: Missing date picker localization for your locale: #{locale}" if as_date_picker_options.blank? - js_format = self.to_datepicker_format(date_options[:formats][:default]) - date_picker_options[:dateFormat] = js_format unless js_format.nil? + js_format = self.to_datepicker_format(I18n.translate!('date.formats.default', :locale => locale, :default => '')) + date_picker_options[:dateFormat] = js_format unless js_format.blank? date_picker_options rescue raise if locale == I18n.locale @@ -76,19 +72,15 @@ def self.datetime_options_for_locales def self.datetime_options(locale) begin rails_time_format = I18n.translate! 'time.formats.picker', :locale => locale - datetime_options = I18n.translate! 'datetime.prompts', :locale => locale datetime_picker_options = {:ampm => false, - :hourText => datetime_options[:hour], - :minuteText => datetime_options[:minute], - :secondText => datetime_options[:second], + :hourText => I18n.translate!('datetime.prompts.hour', :locale => locale), + :minuteText => I18n.translate!('datetime.prompts.minute', :locale => locale), + :secondText => I18n.translate!('datetime.prompts.second', :locale => locale) } - begin - as_datetime_picker_options = I18n.translate! 'active_scaffold.datetime_picker_options' - datetime_picker_options.merge!(as_datetime_picker_options) if as_datetime_picker_options.is_a? Hash - rescue - Rails.logger.warn "ActiveScaffold: Missing datetime picker localization for your locale: #{locale}" - end + as_datetime_picker_options = I18n.translate! :datetime_picker_options, :scope => :active_scaffold, :locale => locale, :default => '' + datetime_picker_options.merge!(as_datetime_picker_options) if as_datetime_picker_options.is_a? Hash + Rails.logger.warn "ActiveScaffold: Missing datetime picker localization for your locale: #{locale}" if as_datetime_picker_options.blank? date_format, time_format = self.split_datetime_format(self.to_datepicker_format(rails_time_format)) datetime_picker_options[:dateFormat] = date_format unless date_format.nil? From cd338e0310f40e4147104d4a36b66ce2a5814776 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 17 Nov 2011 09:26:09 +0100 Subject: [PATCH 1330/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 1bc28e5e49..c3df7ea21e 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 9 + PATCH = 10 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 403a882d3061d514dc989bdb8e471776d23d98de Mon Sep 17 00:00:00 2001 From: Claas Abert <=> Date: Sun, 20 Nov 2011 13:30:40 +0100 Subject: [PATCH 1331/2024] Fixing TinyMCE bridge, cleanup --- .../javascripts/jquery/active_scaffold.js | 15 --------- .../javascripts/jquery/tiny_mce_bridge.js | 7 ++++ .../javascripts/prototype/tiny_mce_bridge.js | 7 ++++ lib/active_scaffold/bridges/tiny_mce.rb | 10 +++++- .../bridges/tiny_mce/helpers.rb | 32 ++----------------- 5 files changed, 25 insertions(+), 46 deletions(-) create mode 100644 app/assets/javascripts/jquery/tiny_mce_bridge.js create mode 100644 app/assets/javascripts/prototype/tiny_mce_bridge.js diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 7a4ac26767..e776841424 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -67,7 +67,6 @@ $(document).ready(function() { return true; }); $('a.as_cancel').live('ajax:before', function(event) { - /* implementation from vhochstein, solves tiny_mce issue */ var as_cancel = $(this); var action_link = ActiveScaffold.find_action_link(as_cancel); @@ -83,20 +82,6 @@ $(document).ready(function() { } } return true; - - /* - var as_cancel = $(this); - var action_link = ActiveScaffold.find_action_link(as_cancel); - - if (action_link) { - var cancel_url = as_cancel.attr('href'); - if (typeof(cancel_url) == 'undefined' || cancel_url.length == 0) { - action_link.close(); - return false; - } - } - return true; - */ }); $('a.as_cancel').live('ajax:success', function(event, response) { var action_link = ActiveScaffold.find_action_link($(this)); diff --git a/app/assets/javascripts/jquery/tiny_mce_bridge.js b/app/assets/javascripts/jquery/tiny_mce_bridge.js new file mode 100644 index 0000000000..d6508c30e6 --- /dev/null +++ b/app/assets/javascripts/jquery/tiny_mce_bridge.js @@ -0,0 +1,7 @@ +var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; +ActiveScaffold.ActionLink.Abstract.prototype.close = function() { + $(this.adapter).find('textarea.mceEditor').each(function(index, elem) { + tinyMCE.execCommand('mceRemoveControl', false, $(elem).attr('id')); + }); + action_link_close.apply(this); +}; diff --git a/app/assets/javascripts/prototype/tiny_mce_bridge.js b/app/assets/javascripts/prototype/tiny_mce_bridge.js new file mode 100644 index 0000000000..ce1f2f9cbc --- /dev/null +++ b/app/assets/javascripts/prototype/tiny_mce_bridge.js @@ -0,0 +1,7 @@ +var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; +ActiveScaffold.ActionLink.Abstract.prototype.close = function() { + this.adapter.select('textarea.mceEditor').each(function(elem) { + tinyMCE.execCommand('mceRemoveControl', false, elem.id); + }); + action_link_close.apply(this); +}; diff --git a/lib/active_scaffold/bridges/tiny_mce.rb b/lib/active_scaffold/bridges/tiny_mce.rb index 026189eac8..b744234ed7 100644 --- a/lib/active_scaffold/bridges/tiny_mce.rb +++ b/lib/active_scaffold/bridges/tiny_mce.rb @@ -4,6 +4,14 @@ def self.install end def self.install? - true # TODO check if tinymce-rails ist installed + Object.const_defined? "TinyMCE" + end + + def self.javascripts + if ActiveScaffold.js_framework == :jquery + ['tinymce-jquery', 'jquery/tiny_mce_bridge'] + else + ['tinymce', 'prototype/tiny_mce_bridge'] + end end end diff --git a/lib/active_scaffold/bridges/tiny_mce/helpers.rb b/lib/active_scaffold/bridges/tiny_mce/helpers.rb index 430c8e1cdc..c81d5c0324 100644 --- a/lib/active_scaffold/bridges/tiny_mce/helpers.rb +++ b/lib/active_scaffold/bridges/tiny_mce/helpers.rb @@ -4,34 +4,6 @@ def self.included(base) base.class_eval do include FormColumnHelpers include SearchColumnHelpers - include ViewHelpers - end - end - - module ViewHelpers - def active_scaffold_includes(*args) - if ActiveScaffold.js_framework == :jquery - tiny_mce_js = javascript_tag(%| -var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; -ActiveScaffold.ActionLink.Abstract.prototype.close = function() { - $(this.adapter).find('textarea.mceEditor').each(function(index, elem) { - tinyMCE.execCommand('mceRemoveControl', false, $(elem).attr('id')); - }); - action_link_close.apply(this); -}; - |) #if using_tiny_mce? TODO check if tiny mce is included - else - tiny_mce_js = javascript_tag(%| -var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; -ActiveScaffold.ActionLink.Abstract.prototype.close = function() { - this.adapter.select('textarea.mceEditor').each(function(elem) { - tinyMCE.execCommand('mceRemoveControl', false, elem.id); - }); - action_link_close.apply(this); -}; - |) #if using_tiny_mce? TODO check if tiny mce is included - end - super(*args) + (include_tiny_mce_if_needed || '') + (tiny_mce_js || '') end end @@ -50,9 +22,9 @@ def active_scaffold_input_text_editor(column, options) def onsubmit_with_tiny_mce if ActiveScaffold.js_framework == :jquery - submit_js = 'tinyMCE.triggerSave();$(\'textarea.mceEditor\').each(function(index, elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, $(elem).attr(\'id\')); });' #if using_tiny_mce? TODO check if tine mce is included + submit_js = 'if (tinyMCE) {tinyMCE.triggerSave();$(\'textarea.mceEditor\').each(function(index, elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, $(elem).attr(\'id\')); });}' else - submit_js = 'tinyMCE.triggerSave();this.select(\'textarea.mceEditor\').each(function(elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, elem.id); });' #if using_tiny_mce? TODO check if tiny mce is included + submit_js = 'if (tinyMCE) {tinyMCE.triggerSave();this.select(\'textarea.mceEditor\').each(function(elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, elem.id); });}' end [onsubmit_without_tiny_mce, submit_js].compact.join ';' end From 38e609bf02394466128ada85c4a82ced00b34bec Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Thu, 27 Oct 2011 19:19:00 +0200 Subject: [PATCH 1332/2024] Bugfix: build is nt always just an alias of new (cherry picked from commit 0ff2d7f56810896af417f21f55095d9337a35c10) --- lib/active_scaffold/actions/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 26312c395a..46f85192b9 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -165,7 +165,7 @@ def new_model params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column] end - model.new(build_options || {}) + model.respond_to?(:build) ? model.build(build_options || {}) : model.new end private From fca9a8ba489281a89b3f6280f59cadcba21cc171 Mon Sep 17 00:00:00 2001 From: Claas Abert <=> Date: Tue, 22 Nov 2011 11:02:36 +0100 Subject: [PATCH 1333/2024] TinyMCE bridge, update as_cancel event --- app/assets/javascripts/jquery/active_scaffold.js | 7 ++----- lib/active_scaffold/bridges/tiny_mce/helpers.rb | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index e776841424..cd4b1d9436 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -68,15 +68,12 @@ $(document).ready(function() { }); $('a.as_cancel').live('ajax:before', function(event) { var as_cancel = $(this); - var action_link = ActiveScaffold.find_action_link(as_cancel); + var action_link = ActiveScaffold.find_action_link(as_cancel); if (action_link) { var cancel_url = as_cancel.attr('href'); var refresh_data = as_cancel.attr('data-refresh'); - if (refresh_data === 'true' && action_link.refresh_url) { - event.data_url = action_link.refresh_url; - if (action_link.position) event.data_type = 'html' - } else if (refresh_data === 'false' || typeof(cancel_url) == 'undefined' || cancel_url.length == 0) { + if (refresh_data !== 'true' || !cancel_url) { action_link.close(); return false; } diff --git a/lib/active_scaffold/bridges/tiny_mce/helpers.rb b/lib/active_scaffold/bridges/tiny_mce/helpers.rb index c81d5c0324..22eb3716cd 100644 --- a/lib/active_scaffold/bridges/tiny_mce/helpers.rb +++ b/lib/active_scaffold/bridges/tiny_mce/helpers.rb @@ -22,9 +22,9 @@ def active_scaffold_input_text_editor(column, options) def onsubmit_with_tiny_mce if ActiveScaffold.js_framework == :jquery - submit_js = 'if (tinyMCE) {tinyMCE.triggerSave();$(\'textarea.mceEditor\').each(function(index, elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, $(elem).attr(\'id\')); });}' + submit_js = 'tinyMCE.triggerSave();$(\'textarea.mceEditor\').each(function(index, elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, $(elem).attr(\'id\')); });' else - submit_js = 'if (tinyMCE) {tinyMCE.triggerSave();this.select(\'textarea.mceEditor\').each(function(elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, elem.id); });}' + submit_js = 'tinyMCE.triggerSave();this.select(\'textarea.mceEditor\').each(function(elem) { tinyMCE.execCommand(\'mceRemoveControl\', false, elem.id); });' end [onsubmit_without_tiny_mce, submit_js].compact.join ';' end From 002e5caba15069f04c6ba16f2630f2570015b7f2 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 22 Nov 2011 18:23:06 +0100 Subject: [PATCH 1334/2024] fix overriding list.html breaks rendering list.js. It fixes #93 --- frontends/default/views/mark.js.rjs | 6 ------ .../default/views/{list.js.erb => refresh_list.js.erb} | 0 lib/active_scaffold/actions/list.rb | 2 +- 3 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 frontends/default/views/mark.js.rjs rename frontends/default/views/{list.js.erb => refresh_list.js.erb} (100%) diff --git a/frontends/default/views/mark.js.rjs b/frontends/default/views/mark.js.rjs deleted file mode 100644 index d5bc8718c0..0000000000 --- a/frontends/default/views/mark.js.rjs +++ /dev/null @@ -1,6 +0,0 @@ -if params[:id] - # FIXME: It isn't right when there are filtered records by a search - page << "$('#{active_scaffold_id}').down('.mark_record').checked = #{@mark ? true : false};" -else - page << "$$('##{active_scaffold_tbody_id} > tr > td > .mark_record').each(function(checkbox) { checkbox.checked = #{@mark ? true : false};});" -end diff --git a/frontends/default/views/list.js.erb b/frontends/default/views/refresh_list.js.erb similarity index 100% rename from frontends/default/views/list.js.erb rename to frontends/default/views/refresh_list.js.erb diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 20ec757c2c..47956ac7c4 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -36,7 +36,7 @@ def list_respond_to_js params.delete(:embedded) render(:partial => 'list_with_header') else - render :action => 'list.js' + render :action => 'refresh_list.js' end end def list_respond_to_xml From fca072d419bf6a78b3c8ca88a419c5a3d3475f54 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 22 Nov 2011 18:27:13 +0100 Subject: [PATCH 1335/2024] bump to 3.1.11 --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index c3df7ea21e..d4847d3103 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 10 + PATCH = 11 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 75abf52219da6015e76a9bd9115f80134a384d69 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 29 Nov 2011 09:58:25 +0100 Subject: [PATCH 1336/2024] Fix add existing on singular association which is reverse of a plural association --- lib/active_scaffold/attribute_params.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index be98f3cd5c..d9cb5a91e0 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -85,6 +85,7 @@ def manage_nested_record_from_params(parent_record, column, attributes) record = find_or_create_for_params(attributes, column, parent_record) if record record_columns = active_scaffold_config_for(column.association.klass).subform.columns + record_columns.constraint_columns = [column.association.reverse] update_record_from_params(record, record_columns, attributes) record.unsaved = true end From 09f17ece779c3442d9040d6597b6cadc12693e1e Mon Sep 17 00:00:00 2001 From: Rami Grossman <ramigg@gmail.com> Date: Wed, 30 Nov 2011 11:36:20 +0200 Subject: [PATCH 1337/2024] Hardcoded LIKE operator should be replaced with a calculated one according to database type --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index a2bf7beb68..34541a65ad 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -96,7 +96,7 @@ def condition_for_range(column, value, like_pattern = nil) elsif value[:from].blank? nil elsif ActiveScaffold::Finder::StringComparators.values.include?(value[:opt]) - ["#{column.search_sql} LIKE ?", value[:opt].sub('?', value[:from])] + ["#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?", value[:opt].sub('?', value[:from])] elsif value[:opt] == 'BETWEEN' ["#{column.search_sql} BETWEEN ? AND ?", value[:from], value[:to]] elsif ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) From 365a8f39d5410f6782f552ca66ba10b8d72973d5 Mon Sep 17 00:00:00 2001 From: Atastor <michaelp@portzblitz.de> Date: Wed, 7 Dec 2011 11:21:44 +0100 Subject: [PATCH 1338/2024] Correction of a spelling error and fix for date time-picker in german. --- config/locales/de.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index 5e750318c0..cfeffb1036 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1,7 +1,7 @@ de: time: formats: - picker: "%a, %d %b %Y %H:%M:%S" + picker: "%d.%m.%Y %H:%M" active_scaffold: add: 'Hinzufügen' add_existing: 'Existierenden Eintrag hinzufügen' @@ -65,7 +65,7 @@ de: between: 'Zwischen' contains: 'Enthält' begins_with: 'Beginnt' - ends_with: 'Ended' + ends_with: 'Endet' today: 'Heute' yesterday: 'Gestern' tomorrow: 'Morgen' From f29cc2fcfcbeb84365c71b2fe841a0f0bb781066 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 12 Dec 2011 10:36:46 +0100 Subject: [PATCH 1339/2024] fix german locale (by Atastor) Fixes #110 --- config/locales/de.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index 5e750318c0..b88b0d3a06 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -65,7 +65,7 @@ de: between: 'Zwischen' contains: 'Enthält' begins_with: 'Beginnt' - ends_with: 'Ended' + ends_with: 'Endet' today: 'Heute' yesterday: 'Gestern' tomorrow: 'Morgen' From 400b3f3bb37c1457faf8db142e07e3da4c290e48 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 12 Dec 2011 12:00:12 +0100 Subject: [PATCH 1340/2024] update gem dependencies --- Gemfile.lock | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5f9ea8a271..c47f6cba3e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,9 +1,11 @@ GEM remote: http://rubygems.org/ specs: - rake (0.9.2) + json (1.6.3) + rake (0.9.2.2) rcov (0.9.9) - rdoc (3.9.4) + rdoc (3.11) + json (~> 1.4) shoulda (2.11.3) PLATFORMS From 943b26216c09201578f98b811bf4610316dc0ccd Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 12 Dec 2011 14:39:58 +0100 Subject: [PATCH 1341/2024] set successful when saving fails with a RecordInvalid exception, and display exception message --- lib/active_scaffold/actions/create.rb | 2 ++ lib/active_scaffold/actions/update.rb | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index c3a0349e0f..eea51255db 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -103,6 +103,8 @@ def do_create create_save end rescue ActiveRecord::RecordInvalid + flash[:error] = $!.message + self.successful = false end end diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 5fcd71fdcd..2871214886 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -92,9 +92,11 @@ def update_save(options = {}) end end rescue ActiveRecord::RecordInvalid + flash[:error] = $!.message + self.successful = false rescue ActiveRecord::StaleObjectError @record.errors.add(:base, as_(:version_inconsistency)) - self.successful=false + self.successful = false rescue ActiveRecord::RecordNotSaved @record.errors.add(:base, as_(:record_not_saved)) if @record.errors.empty? self.successful = false From 3f83b28da14654acbd9e62535902a61b25149e5d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 13 Dec 2011 11:55:45 +0100 Subject: [PATCH 1342/2024] fix cancel url for views of nested scaffolds (fix #104) --- lib/active_scaffold/data_structures/nested_info.rb | 12 ++++++++++++ lib/active_scaffold/helpers/controller_helpers.rb | 5 +---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 72279f8fca..8af2f09e17 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -28,6 +28,10 @@ def initialize(model, session_info) @parent_scaffold = session_info[:parent_scaffold] end + def to_params + {:parent_scaffold => parent_scaffold.controller_path} + end + def new_instance? result = @new_instance.nil? @new_instance = false @@ -94,6 +98,10 @@ def default_sorting association.options[:order] end + def to_params + super.merge(:association => @association.name, :assoc_id => parent_id) + end + protected def iterate_model_associations(model) @@ -119,5 +127,9 @@ def initialize(model, session_info) @scope = session_info[:name] @constrained_fields = [] end + + def to_params + super.merge(:named_scope => @scope) + end end end diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 2430d28fc0..a9b5569593 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -32,10 +32,7 @@ def main_path_to_return parameters[:controller] = params[:parent_controller] parameters[:eid] = params[:parent_controller] end - if nested? - parameters[:controller] = nested.parent_scaffold.controller_path - parameters[:eid] = nil - end + parameters.merge! nested.to_params if nested? if params[:parent_sti] parameters[:controller] = params[:parent_sti] parameters[:eid] = nil From 701de8d6a3e3b93448ecaf8bf5aa778aaecaaec4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 15 Dec 2011 12:16:18 +0100 Subject: [PATCH 1343/2024] fix enum in field search --- lib/active_scaffold/helpers/search_column_helpers.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 5c6f8d6481..d2b257ddae 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -78,7 +78,9 @@ def active_scaffold_search_select(column, html_options) select_options = options_for_association(column.association, true) else method = column.name - select_options = Array(column.options[:options]) + select_options = column.options[:options].collect do |text, value| + active_scaffold_translated_option(column, text, value) + end end options = { :selected => associated }.merge! column.options From 53a17785192ad1baa074fc09414a7a752790f963 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 19 Dec 2011 10:07:23 +0100 Subject: [PATCH 1344/2024] Fix add existing, fixes #106 --- frontends/default/views/add_existing.js.erb | 30 ++++++++++----------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/frontends/default/views/add_existing.js.erb b/frontends/default/views/add_existing.js.erb index 9f25e32a75..aa3aaed60f 100644 --- a/frontends/default/views/add_existing.js.erb +++ b/frontends/default/views/add_existing.js.erb @@ -1,20 +1,18 @@ -<% new_row = render :partial => 'list_record', :locals => {:record => @record}%> -ActiveScaffold.create_record_row('#{active_scaffold_id}','#{escape_javascript(new_row)}', #{{:insert_at => :top}.to_json.html_safe}); -<%%> +<% new_row = render :partial => 'list_record', :locals => {:record => @record} %> +ActiveScaffold.create_record_row('<%= active_scaffold_id %>', '<%= escape_javascript(new_row) %>', <%= {:insert_at => :top}.to_json.html_safe %>); + <% if active_scaffold_config.list.columns.any? {|c| c.calculation?} %> - ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); + ActiveScaffold.replace('<%= active_scaffold_calculations_id %>', '<%= escape_javascript(render(:partial => 'list_calculations')) %>'); <%end%> -<%%> -<% if(form_stays_open == true)%> + +<% if form_stays_open ||= true %> <%# why not just re-render the form? that wouldn't utilize a possible do_new override which sets default values.%> - ActiveScaffold.reset_form('<%element_form_id%>'); - ActiveScaffold.replace_html('<%element_messages_id(:action => :add_existing)%>', '<%=escape_javascript(render(:partial => 'form_messages'))%>'); + ActiveScaffold.reset_form('<%= element_form_id %>'); + ActiveScaffold.replace_html('<%= element_messages_id(:action => :add_existing) %>', '<%= escape_javascript(render(:partial => 'form_messages')) %>'); <%# have to delay the focus, because there's no "firstElement" in prototype until at least one element is not disabled%> - <%if ActiveScaffold.js_framework == :prototype%> - page.delay 0.1 do - page << "ActiveScaffold.focus_first_element_of_form('#{element_form_id}');" - end - <%end%> -<%else%> - ActiveScaffold.find_action_link('<%element_form_id(:action => :new_existing)%>').close(); -<%end%> + <% if ActiveScaffold.js_framework == :prototype %> + ActiveScaffold.focus_first_element_of_form.defer('<%= element_form_id %>'); + <% end %> +<% else %> + ActiveScaffold.find_action_link('<%= element_form_id(:action => :new_existing) %>').close(); +<% end %> From baa9851b460cb1739134c2b20ff221297f091a5d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 19 Dec 2011 12:59:23 +0100 Subject: [PATCH 1345/2024] fix recordselect with update_form, it wasn't working after typing to search --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index cd4b1d9436..9e8c04ed83 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -148,7 +148,7 @@ $(document).ready(function() { return true; } else return false; }); - $('input.update_form, textarea.update_form, select.update_form').live('change', function(event) { + $('input.update_form:not(.recordselect), textarea.update_form, select.update_form').live('change', function(event) { var element = $(this); var value = element.is("input:checkbox:not(:checked)") ? null : element.val(); ActiveScaffold.update_column(element, element.attr('data-update_url'), element.attr('data-update_send_form'), element.attr('id'), value); From a40fb2ab537792b8232a627048da3f650d5e84f6 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 19 Dec 2011 13:01:00 +0100 Subject: [PATCH 1346/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index d4847d3103..893941d7d7 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 11 + PATCH = 12 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 5631e4ea8105f4cbda315d91338f06991d75bf81 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 21 Dec 2011 12:01:47 +0100 Subject: [PATCH 1347/2024] fix record_select_autocomplete --- lib/active_scaffold/bridges/record_select/helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/record_select/helpers.rb b/lib/active_scaffold/bridges/record_select/helpers.rb index ac3b1a4381..39eaf78b1b 100644 --- a/lib/active_scaffold/bridges/record_select/helpers.rb +++ b/lib/active_scaffold/bridges/record_select/helpers.rb @@ -49,7 +49,7 @@ def active_scaffold_record_select(column, options, value, multiple) def active_scaffold_record_select_autocomplete(column, options) record_select_options = active_scaffold_input_text_options(options).merge( - :controller => remote_controller + :controller => active_scaffold_controller_for(@record.class).controller_path ) html = record_select_autocomplete(options[:name], @record, record_select_options) html = self.class.field_error_proc.call(html, self) if @record.errors[column.name].any? From b79e35fc5c617de347ff48ea201023533b57248b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 21 Dec 2011 12:02:12 +0100 Subject: [PATCH 1348/2024] fix klass_with_sti for models without inheritance_column --- lib/active_scaffold/extensions/active_association_reflection.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/active_association_reflection.rb b/lib/active_scaffold/extensions/active_association_reflection.rb index 06192b5516..d3265e4f28 100644 --- a/lib/active_scaffold/extensions/active_association_reflection.rb +++ b/lib/active_scaffold/extensions/active_association_reflection.rb @@ -5,7 +5,7 @@ ActiveRecord::Reflection::AssociationReflection.class_eval do def klass_with_sti(*opts) sti_col = klass.inheritance_column - if (h = opts.first).is_a? Hash and (passed_type = ( h[sti_col] || h[sti_col.to_sym] )) and (new_klass = active_record.send(:compute_type, passed_type)) < klass + if sti_col and (h = opts.first).is_a? Hash and (passed_type = ( h[sti_col] || h[sti_col.to_sym] )) and (new_klass = active_record.send(:compute_type, passed_type)) < klass new_klass else klass From 7ece16b812891b155818ba466c4490b631bccffb Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 21 Dec 2011 12:02:29 +0100 Subject: [PATCH 1349/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 893941d7d7..88afe5763b 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 12 + PATCH = 13 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From c2380071424210e6704fc278c677ae340caf8311 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 28 Dec 2011 14:13:53 +0100 Subject: [PATCH 1350/2024] fix child_association nested info --- lib/active_scaffold/data_structures/nested_info.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 8af2f09e17..e803722705 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -115,7 +115,7 @@ def iterate_model_associations(model) if association.foreign_key == current.foreign_key # show columns for has_many and has_one child associationes constrained_fields << current.name.to_sym if current.belongs_to? - @child_association = current + @child_association = current if current.klass == @parent_model end end end From e73f9bae65966f3c076de6faaba6a03a0c32cef6 Mon Sep 17 00:00:00 2001 From: r-stu31 <r.stu3.1@googlemail.com> Date: Sat, 7 Jan 2012 01:15:25 +0100 Subject: [PATCH 1351/2024] After closing a form, scroll to the modified record. --- app/assets/javascripts/jquery/active_scaffold.js | 1 + app/assets/javascripts/prototype/active_scaffold.js | 1 + 2 files changed, 2 insertions(+) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 9e8c04ed83..27bdfe62dc 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -894,6 +894,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ this.enable(); this.adapter.remove(); if (this.hide_target) this.target.show(); + ActiveScaffold.scroll_to(this.target); }, reload: function() { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 46409361ef..bd41c7aae3 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -791,6 +791,7 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ this.enable(); this.adapter.remove(); if (this.hide_target) this.target.show(); + ActiveScaffold.scroll_to(this.target); }, reload: function() { From 474b460379cc87ae31e9b993db0c8d0e04f8c2f7 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 4 Jan 2012 18:58:27 +0100 Subject: [PATCH 1352/2024] Bugfix: do not use try cause it s throwing exceptions (cherry picked from commit 0093ef7306f4a1c542bba6390cbb12213a0a83c6) --- lib/active_scaffold/data_structures/action_links.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 464888c068..3dac351799 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -173,7 +173,7 @@ def #{name} protected def skip_action_link(controller, link, *args) - (!link.ignore_method.nil? and controller.try(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args)) + (!link.ignore_method.nil? && controller.respond_to?(link.ignore_method) && controller.send(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args)) end # called during clone or dup. makes the clone/dup deeper. diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index d0df16a77e..107623eb26 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -100,7 +100,7 @@ def link_to_visibility_toggle(id, options = {}) end def skip_action_link(link, *args) - (!link.ignore_method.nil? and controller.try(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args)) + (!link.ignore_method.nil? && controller.respond_to?(link.ignore_method) && controller.send(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args)) end def render_action_link(link, url_options, record = nil, html_options = {}) From 67299d07eb43b38098c5d07b55dd89a76a1d978c Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Sat, 31 Dec 2011 10:55:17 +0100 Subject: [PATCH 1353/2024] Bugfix: delete action should listen to ignore_action method as well (cherry picked from commit 2279b0902a5638c9316ecd9cae82694b8c825599) --- lib/active_scaffold/config/delete.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/delete.rb b/lib/active_scaffold/config/delete.rb index a1dac67c1f..2625f26078 100644 --- a/lib/active_scaffold/config/delete.rb +++ b/lib/active_scaffold/config/delete.rb @@ -15,7 +15,7 @@ def initialize(core_config) # the ActionLink for this action cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('destroy', :label => :delete, :type => :member, :confirm => :are_you_sure_to_delete, :method => :delete, :crud_type => :delete, :position => false, :parameters => {:destroy_action => true}, :security_method => :delete_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('destroy', :label => :delete, :type => :member, :confirm => :are_you_sure_to_delete, :method => :delete, :crud_type => :delete, :position => false, :parameters => {:destroy_action => true}, :security_method => :delete_authorized?, :ignore_method => :delete_ignore?) # whether we should refresh list after destroy or not cattr_accessor :refresh_list From 6c436db895f5b37763f7930034f3ddd7f5209d4c Mon Sep 17 00:00:00 2001 From: Craig Walker <github@softcraft.ca> Date: Tue, 10 Jan 2012 20:20:57 +0000 Subject: [PATCH 1354/2024] Prevented conflicts with the $ variable for jQuery --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- app/assets/javascripts/jquery/date_picker_bridge.js.erb | 2 +- app/assets/javascripts/jquery/draggable_lists.js | 4 ++++ app/assets/javascripts/jquery/tiny_mce_bridge.js | 5 +++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 9e8c04ed83..28be6f72fa 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -1,4 +1,4 @@ -$(document).ready(function() { +jQuery(document).ready(function($) { $('form.as_form').live('ajax:beforeSend', function(event) { var as_form = $(this).closest("form"); if (as_form && as_form.attr('data-loading') == 'true') { diff --git a/app/assets/javascripts/jquery/date_picker_bridge.js.erb b/app/assets/javascripts/jquery/date_picker_bridge.js.erb index 121a2041d8..bb30c530f8 100644 --- a/app/assets/javascripts/jquery/date_picker_bridge.js.erb +++ b/app/assets/javascripts/jquery/date_picker_bridge.js.erb @@ -1,6 +1,6 @@ <%= ActiveScaffold::Bridges[:date_picker].localization %> -$(document).ready(function() { +jQuery(document).ready(function($) { $('input.date_picker').live('focus', function(event) { var date_picker = $(this); if (typeof(date_picker.datepicker) == 'function') { diff --git a/app/assets/javascripts/jquery/draggable_lists.js b/app/assets/javascripts/jquery/draggable_lists.js index 0fd09047a2..b7c2018b00 100644 --- a/app/assets/javascripts/jquery/draggable_lists.js +++ b/app/assets/javascripts/jquery/draggable_lists.js @@ -1,3 +1,5 @@ +(function($){ + jQuery.fn.draggable_lists = function() { this.addClass('draggable-list'); var list_selected = $(this.get(0).cloneNode(false)).addClass('selected'); @@ -25,3 +27,5 @@ jQuery.fn.draggable_lists = function() { }); return this; }; + +})(jQuery); \ No newline at end of file diff --git a/app/assets/javascripts/jquery/tiny_mce_bridge.js b/app/assets/javascripts/jquery/tiny_mce_bridge.js index d6508c30e6..5ae4bad902 100644 --- a/app/assets/javascripts/jquery/tiny_mce_bridge.js +++ b/app/assets/javascripts/jquery/tiny_mce_bridge.js @@ -1,7 +1,12 @@ var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; + +(function($){ + ActiveScaffold.ActionLink.Abstract.prototype.close = function() { $(this.adapter).find('textarea.mceEditor').each(function(index, elem) { tinyMCE.execCommand('mceRemoveControl', false, $(elem).attr('id')); }); action_link_close.apply(this); }; + +})(jQuery); \ No newline at end of file From bf090b75eefce238eb8cd8e8a9c6865303bb14fe Mon Sep 17 00:00:00 2001 From: Craig Walker <github@softcraft.ca> Date: Tue, 10 Jan 2012 21:04:59 +0000 Subject: [PATCH 1355/2024] More jQuery conflict resolution --- app/assets/javascripts/jquery/active_scaffold.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 28be6f72fa..1d9f7c38c7 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -266,6 +266,9 @@ jQuery(document).ready(function($) { }; })(); + +(function($){ + /* jQuery delayed observer (c) 2007 - Maxime Haineault (max@centdessin.com) @@ -1051,3 +1054,5 @@ ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({ ActiveScaffold.highlight(this.adapter.find('td').first().children()); } }); + +})(jQuery); \ No newline at end of file From 38b0e36ee08025d381747bf809cabd691ea0b973 Mon Sep 17 00:00:00 2001 From: Craig Walker <github@softcraft.ca> Date: Tue, 10 Jan 2012 21:18:45 +0000 Subject: [PATCH 1356/2024] Switched jQuery function wrapper with jQuery instance variable calls --- .../javascripts/jquery/active_scaffold.js | 269 +++++++++--------- .../jquery/date_picker_bridge.js.erb | 10 +- .../javascripts/jquery/draggable_lists.js | 22 +- .../javascripts/jquery/tiny_mce_bridge.js | 9 +- 4 files changed, 148 insertions(+), 162 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 1d9f7c38c7..4674160ba2 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -1,33 +1,33 @@ -jQuery(document).ready(function($) { - $('form.as_form').live('ajax:beforeSend', function(event) { - var as_form = $(this).closest("form"); +jQuery(document).ready(function() { + jQuery('form.as_form').live('ajax:beforeSend', function(event) { + var as_form = jQuery(this).closest("form"); if (as_form && as_form.attr('data-loading') == 'true') { ActiveScaffold.disable_form(as_form); } return true; }); - $('form.as_form').live('ajax:complete', function(event) { - var as_form = $(this).closest("form"); + jQuery('form.as_form').live('ajax:complete', function(event) { + var as_form = jQuery(this).closest("form"); if (as_form && as_form.attr('data-loading') == 'true') { ActiveScaffold.enable_form(as_form); } }); - $('form.as_form').live('ajax:error', function(event, xhr, status, error) { - var as_div = $(this).closest("div.active-scaffold"); + jQuery('form.as_form').live('ajax:error', function(event, xhr, status, error) { + var as_div = jQuery(this).closest("div.active-scaffold"); if (as_div) { ActiveScaffold.report_500_response(as_div) } }); - $('form.as_form.as_remote_upload').live('submit', function(event) { - var as_form = $(this).closest("form"); + jQuery('form.as_form.as_remote_upload').live('submit', function(event) { + var as_form = jQuery(this).closest("form"); if (as_form && as_form.attr('data-loading') == 'true') { setTimeout("ActiveScaffold.disable_form('" + as_form.attr('id') + "')", 10); } return true; }); - $('a.as_action').live('ajax:before', function(event) { - var action_link = ActiveScaffold.ActionLink.get($(this)); + jQuery('a.as_action').live('ajax:before', function(event) { + var action_link = ActiveScaffold.ActionLink.get(jQuery(this)); if (action_link) { if (action_link.is_disabled()) { return false; @@ -38,8 +38,8 @@ jQuery(document).ready(function($) { } return true; }); - $('a.as_action').live('ajax:success', function(event, response) { - var action_link = ActiveScaffold.ActionLink.get($(this)); + jQuery('a.as_action').live('ajax:success', function(event, response) { + var action_link = ActiveScaffold.ActionLink.get(jQuery(this)); if (action_link) { if (action_link.position) { action_link.insert(response); @@ -47,27 +47,27 @@ jQuery(document).ready(function($) { } else { action_link.enable(); } - $(this).trigger('as:action_success', action_link); + jQuery(this).trigger('as:action_success', action_link); } return true; }); - $('a.as_action').live('ajax:complete', function(event) { - var action_link = ActiveScaffold.ActionLink.get($(this)); + jQuery('a.as_action').live('ajax:complete', function(event) { + var action_link = ActiveScaffold.ActionLink.get(jQuery(this)); if (action_link) { if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden'); } return true; }); - $('a.as_action').live('ajax:error', function(event, xhr, status, error) { - var action_link = ActiveScaffold.ActionLink.get($(this)); + jQuery('a.as_action').live('ajax:error', function(event, xhr, status, error) { + var action_link = ActiveScaffold.ActionLink.get(jQuery(this)); if (action_link) { ActiveScaffold.report_500_response(action_link.scaffold_id()); action_link.enable(); } return true; }); - $('a.as_cancel').live('ajax:before', function(event) { - var as_cancel = $(this); + jQuery('a.as_cancel').live('ajax:before', function(event) { + var as_cancel = jQuery(this); var action_link = ActiveScaffold.find_action_link(as_cancel); if (action_link) { @@ -80,8 +80,8 @@ jQuery(document).ready(function($) { } return true; }); - $('a.as_cancel').live('ajax:success', function(event, response) { - var action_link = ActiveScaffold.find_action_link($(this)); + jQuery('a.as_cancel').live('ajax:success', function(event, response) { + var action_link = ActiveScaffold.find_action_link(jQuery(this)); if (action_link) { if (action_link.position) { @@ -92,100 +92,100 @@ jQuery(document).ready(function($) { } return true; }); - $('a.as_cancel').live('ajax:error', function(event, xhr, status, error) { - var action_link = ActiveScaffold.find_action_link($(this)); + jQuery('a.as_cancel').live('ajax:error', function(event, xhr, status, error) { + var action_link = ActiveScaffold.find_action_link(jQuery(this)); if (action_link) { ActiveScaffold.report_500_response(action_link.scaffold_id()); } return true; }); - $('a.as_sort').live('ajax:before', function(event) { - var as_sort = $(this); + jQuery('a.as_sort').live('ajax:before', function(event) { + var as_sort = jQuery(this); var history_controller_id = as_sort.attr('data-page-history'); if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.attr('href'), history_controller_id); as_sort.closest('th').addClass('loading'); return true; }); - $('a.as_sort').live('ajax:error', function(event, xhr, status, error) { - var as_scaffold = $(this).closest('.active-scaffold'); + jQuery('a.as_sort').live('ajax:error', function(event, xhr, status, error) { + var as_scaffold = jQuery(this).closest('.active-scaffold'); ActiveScaffold.report_500_response(as_scaffold); return true; }); - $('span.in_place_editor_field').live('hover', function(event) { - $(this).data(); // jquery 1.4.2 workaround + jQuery('span.in_place_editor_field').live('hover', function(event) { + jQuery(this).data(); // jquery 1.4.2 workaround if (event.type == 'mouseenter') { - if (typeof($(this).data('editInPlace')) === 'undefined') $(this).addClass("hover"); + if (typeof(jQuery(this).data('editInPlace')) === 'undefined') jQuery(this).addClass("hover"); } if (event.type == 'mouseleave') { - if (typeof($(this).data('editInPlace')) === 'undefined') $(this).removeClass("hover"); + if (typeof(jQuery(this).data('editInPlace')) === 'undefined') jQuery(this).removeClass("hover"); } return true; }); - $('span.in_place_editor_field').live('click', function(event) { - ActiveScaffold.in_place_editor_field_clicked($(this)); + jQuery('span.in_place_editor_field').live('click', function(event) { + ActiveScaffold.in_place_editor_field_clicked(jQuery(this)); }); - $('a.as_paginate').live('ajax:before',function(event) { - var as_paginate = $(this); + jQuery('a.as_paginate').live('ajax:before',function(event) { + var as_paginate = jQuery(this); var history_controller_id = as_paginate.attr('data-page-history'); if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.attr('href'), history_controller_id); as_paginate.prevAll('img.loading-indicator').css('visibility','visible'); return true; }); - $('a.as_paginate').live('ajax:error', function(event, xhr, status, error) { - var as_scaffold = $(this).closest('.active-scaffold'); + jQuery('a.as_paginate').live('ajax:error', function(event, xhr, status, error) { + var as_scaffold = jQuery(this).closest('.active-scaffold'); ActiveScaffold.report_500_response(as_scaffold); return true; }); - $('a.as_paginate').live('ajax:complete', function(event) { - $(this).prevAll('img.loading-indicator').css('visibility','hidden'); + jQuery('a.as_paginate').live('ajax:complete', function(event) { + jQuery(this).prevAll('img.loading-indicator').css('visibility','hidden'); return true; }); - $('a.as_add_existing, a.as_replace_existing').live('ajax:before', function(event) { - var id = $(this).prev().val(); + jQuery('a.as_add_existing, a.as_replace_existing').live('ajax:before', function(event) { + var id = jQuery(this).prev().val(); if (id) { - if (!$(this).data('href')) $(this).data('href', $(this).attr('href')); - $(this).attr('href', $(this).data('href').replace('--ID--', id)); + if (!jQuery(this).data('href')) jQuery(this).data('href', jQuery(this).attr('href')); + jQuery(this).attr('href', jQuery(this).data('href').replace('--ID--', id)); return true; } else return false; }); - $('input.update_form:not(.recordselect), textarea.update_form, select.update_form').live('change', function(event) { - var element = $(this); + jQuery('input.update_form:not(.recordselect), textarea.update_form, select.update_form').live('change', function(event) { + var element = jQuery(this); var value = element.is("input:checkbox:not(:checked)") ? null : element.val(); ActiveScaffold.update_column(element, element.attr('data-update_url'), element.attr('data-update_send_form'), element.attr('id'), value); return true; }); - $('input.recordselect.update_form').live('recordselect:change', function(event, id, label) { - var element = $(this); + jQuery('input.recordselect.update_form').live('recordselect:change', function(event, id, label) { + var element = jQuery(this); ActiveScaffold.update_column(element, element.attr('data-update_url'), element.attr('data-update_send_form'), element.attr('id'), id); return true; }); - $('select.as_search_range_option').live('change', function(event) { - ActiveScaffold[$(this).val() == 'BETWEEN' ? 'show' : 'hide']($(this).parent().find('.as_search_range_between')); + jQuery('select.as_search_range_option').live('change', function(event) { + ActiveScaffold[jQuery(this).val() == 'BETWEEN' ? 'show' : 'hide'](jQuery(this).parent().find('.as_search_range_between')); return true; }); - $('select.as_search_range_option').live('change', function(event) { - var element = $(this); + jQuery('select.as_search_range_option').live('change', function(event) { + var element = jQuery(this); ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric')); ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend')); ActiveScaffold[(element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_range')); return true; }); - $('select.as_update_date_operator').live('change', function(event) { - ActiveScaffold[$(this).val() == 'REPLACE' ? 'show' : 'hide']($(this).next()); - ActiveScaffold[$(this).val() == 'REPLACE' ? 'hide' : 'show']($(this).next().next()); + jQuery('select.as_update_date_operator').live('change', function(event) { + ActiveScaffold[jQuery(this).val() == 'REPLACE' ? 'show' : 'hide'](jQuery(this).next()); + ActiveScaffold[jQuery(this).val() == 'REPLACE' ? 'hide' : 'show'](jQuery(this).next().next()); return true; }); - $('a[data-popup]').live('click', function(e) { - window.open($(this).attr('href')); + jQuery('a[data-popup]').live('click', function(e) { + window.open(jQuery(this).attr('href')); e.preventDefault(); }); - $('.hover_click').live("click", function(event) { - var element = $(this); + jQuery('.hover_click').live("click", function(event) { + var element = jQuery(this); var ul_element = element.children('ul').first(); if (ul_element.is(':visible')) { element.find('ul').hide(); @@ -194,8 +194,8 @@ jQuery(document).ready(function($) { } return false; }); - $('.hover_click a.as_action').live('click', function(event) { - var element = $(this).closest('.hover_click'); + jQuery('.hover_click a.as_action').live('click', function(event) { + var element = jQuery(this).closest('.hover_click'); if (element) { element.find('ul').hide(); } @@ -266,9 +266,6 @@ jQuery(document).ready(function($) { }; })(); - -(function($){ - /* jQuery delayed observer (c) 2007 - Maxime Haineault (max@centdessin.com) @@ -308,16 +305,16 @@ if (typeof(jQuery.fn.delayedObserver) === 'undefined') { jQuery.fn.extend({ delayedObserver:function(delay, callback){ - $this = $(this); + jQuerythis = jQuery(this); delayedObserverStack.push({ - obj: $this, timer: null, delay: delay, - oldVal: $this.val(), callback: callback + obj: jQuerythis, timer: null, delay: delay, + oldVal: jQuerythis.val(), callback: callback }); stackPos = delayedObserverStack.length-1; - $this.keyup(function(event) { + jQuerythis.keyup(function(event) { if (isNonPrintableKey(event)) return; observed = delayedObserverStack[stackPos]; if (observed.obj.val() == observed.obj.oldVal) return; @@ -336,14 +333,14 @@ if (typeof(jQuery.fn.delayedObserver) === 'undefined') { var ActiveScaffold = { records_for: function(tbody_id) { if (typeof(tbody_id) == 'string') tbody_id = '#' + tbody_id; - return $(tbody_id).children('.record'); + return jQuery(tbody_id).children('.record'); }, stripe: function(tbody_id) { var even = false; var rows = this.records_for(tbody_id); rows.each(function (index, row_node) { - row = $(row_node); + row = jQuery(row_node); if (row_node.tagName != 'SCRIPT' && !row.hasClass("create") && !row.hasClass("update") @@ -359,18 +356,18 @@ var ActiveScaffold = { }, hide_empty_message: function(tbody) { if (this.records_for(tbody).length != 0) { - var empty_message_node = $(tbody).parent().find('tbody.messages p.empty-message') + var empty_message_node = jQuery(tbody).parent().find('tbody.messages p.empty-message') if (empty_message_node) empty_message_node.hide(); } }, reload_if_empty: function(tbody, url) { if (this.records_for(tbody).length == 0) { - $.getScript(url); + jQuery.getScript(url); } }, removeSortClasses: function(scaffold) { if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; - scaffold = $(scaffold) + scaffold = jQuery(scaffold) scaffold.find('td.sorted').each(function(element) { element.removeClass("sorted"); }); @@ -383,14 +380,14 @@ var ActiveScaffold = { decrement_record_count: function(scaffold) { // decrement the last record count, firsts record count are in nested lists if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; - scaffold = $(scaffold) + scaffold = jQuery(scaffold) count = scaffold.find('span.active-scaffold-records').last(); if (count) count.html(parseInt(count.html(), 10) - 1); }, increment_record_count: function(scaffold) { // increment the last record count, firsts record count are in nested lists if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; - scaffold = $(scaffold) + scaffold = jQuery(scaffold) count = scaffold.find('span.active-scaffold-records').last(); if (count) count.html(parseInt(count.html(), 10) + 1); }, @@ -398,7 +395,7 @@ var ActiveScaffold = { var even_row = false; var replaced = null; if (typeof(row) == 'string') row = '#' + row; - row = $(row); + row = jQuery(row); if (row.hasClass('even-record')) even_row = true; replaced = this.replace(row, html); @@ -408,67 +405,67 @@ var ActiveScaffold = { replace: function(element, html) { if (typeof(element) == 'string') element = '#' + element; - element = $(element); + element = jQuery(element); element.replaceWith(html); if (element.attr('id')) { - element = $('#' + element.attr('id')); + element = jQuery('#' + element.attr('id')); } return element; }, replace_html: function(element, html) { if (typeof(element) == 'string') element = '#' + element; - element = $(element); + element = jQuery(element); element.html(html); return element; }, remove: function(element) { if (typeof(element) == 'string') element = '#' + element; - $(element).remove(); + jQuery(element).remove(); }, hide: function(element) { if (typeof(element) == 'string') element = '#' + element; - $(element).hide(); + jQuery(element).hide(); }, show: function(element) { if (typeof(element) == 'string') element = '#' + element; - $(element).show(); + jQuery(element).show(); }, reset_form: function(element) { if (typeof(element) == 'string') element = '#' + element; - $(element).get(0).reset(); + jQuery(element).get(0).reset(); }, disable_form: function(as_form) { if (typeof(as_form) == 'string') as_form = '#' + as_form; - as_form = $(as_form) - var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); + as_form = jQuery(as_form) + var loading_indicator = jQuery('#' + as_form.attr('id').replace(/-formjQuery/, '-loading-indicator')); if (loading_indicator) loading_indicator.css('visibility','visible'); - $('input[type=submit]', as_form).attr('disabled', 'disabled'); - as_form[0].disabled_fields = $("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled'); + jQuery('input[type=submit]', as_form).attr('disabled', 'disabled'); + as_form[0].disabled_fields = jQuery("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled'); }, enable_form: function(as_form) { if (typeof(as_form) == 'string') as_form = '#' + as_form; - as_form = $(as_form) - var loading_indicator = $('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); + as_form = jQuery(as_form) + var loading_indicator = jQuery('#' + as_form.attr('id').replace(/-formjQuery/, '-loading-indicator')); if (loading_indicator) loading_indicator.css('visibility','hidden'); - $('input[type=submit]', as_form).removeAttr('disabled'); + jQuery('input[type=submit]', as_form).removeAttr('disabled'); as_form[0].disabled_fields.removeAttr('disabled'); }, focus_first_element_of_form: function(form_element) { if (typeof(form_element) == 'string') form_element = '#' + form_element; - $(form_element + ":first *:input[type!=hidden]:first").focus(); + jQuery(form_element + ":first *:input[type!=hidden]:first").focus(); }, create_record_row: function(active_scaffold_id, html, options) { if (typeof(active_scaffold_id) == 'string') active_scaffold_id = '#' + active_scaffold_id; - tbody = $(active_scaffold_id).find('tbody.records'); + tbody = jQuery(active_scaffold_id).find('tbody.records'); if (options.insert_at == 'top') { tbody.prepend(html); @@ -490,7 +487,7 @@ var ActiveScaffold = { delete_record_row: function(row, page_reload_url) { if (typeof(row) == 'string') row = '#' + row; - row = $(row); + row = jQuery(row); var tbody = row.closest('tbody.records'); var current_action_node = row.find('td.actions a.disabled').first(); @@ -509,44 +506,44 @@ var ActiveScaffold = { delete_subform_record: function(record) { if (typeof(record) == 'string') record = '#' + record; - record = $(record); + record = jQuery(record); var errors = record.prev(); if (errors.hasClass('association-record-errors')) { this.remove(errors); } - var associated = $(record).next(); + var associated = jQuery(record).next(); this.remove(record); while (associated.hasClass('associated-record')) { record = associated; - associated = $(record).next(); + associated = jQuery(record).next(); this.remove(record); } }, report_500_response: function(active_scaffold_id) { - server_error = $(active_scaffold_id).find('td.messages-container p.server-error'); - if (!$(server_error).is(':visible')) { + server_error = jQuery(active_scaffold_id).find('td.messages-container p.server-error'); + if (!jQuery(server_error).is(':visible')) { server_error.show(); } }, find_action_link: function(element) { if (typeof(element) == 'string') element = '#' + element; - var as_adapter = $(element).closest('.as_adapter'); + var as_adapter = jQuery(element).closest('.as_adapter'); return ActiveScaffold.ActionLink.get(as_adapter); }, scroll_to: function(element) { if (typeof(element) == 'string') element = '#' + element; - var form_offset = $(element).offset(), + var form_offset = jQuery(element).offset(), destination = form_offset.top; - $(document).scrollTop(destination); + jQuery(document).scrollTop(destination); }, process_checkbox_inplace_edit: function(checkbox, options) { var checked = checkbox.is(':checked'); if (checked === true) options['params'] += '&value=1'; - $.ajax({ + jQuery.ajax({ url: options.url, type: "POST", data: options['params'], @@ -577,7 +574,7 @@ var ActiveScaffold = { }, highlight: function(element) { - if (typeof(element) == 'string') element = $('#' + element); + if (typeof(element) == 'string') element = jQuery('#' + element); if (typeof(element.effect) == 'function') { element.effect("highlight", {}, 3000); } @@ -585,27 +582,27 @@ var ActiveScaffold = { create_visibility_toggle: function(element, options) { if (typeof(element) == 'string') element = '#' + element; - var toggable = $(element); + var toggable = jQuery(element); var toggler = toggable.prev(); var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label; toggler.append(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)'); toggler.children('a').click(function() { toggable.toggle(); - $(this).html((toggable.is(':hidden')) ? options.show_label : options.hide_label); + jQuery(this).html((toggable.is(':hidden')) ? options.show_label : options.hide_label); return false; }); }, create_associated_record_form: function(element, content, options) { if (typeof(element) == 'string') element = '#' + element; - var element = $(element); + var element = jQuery(element); if (options.singular == false) { - if (!(options.id && $('#' + options.id).size() > 0)) { + if (!(options.id && jQuery('#' + options.id).size() > 0)) { element.append(content); } } else { - var current = $('#' + element.attr('id') + ' .association-record') + var current = jQuery('#' + element.attr('id') + ' .association-record') if (current[0]) { this.replace(current[0], content); } else { @@ -616,7 +613,7 @@ var ActiveScaffold = { render_form_field: function(source, content, options) { if (typeof(source) == 'string') source = '#' + source; - var source = $(source); + var source = jQuery(source); var element = source.closest('.association-record'); if (element.length == 0) { element = source.closest('form > ol.form'); @@ -634,21 +631,21 @@ var ActiveScaffold = { sortable: function(element, controller, options, url_params) { if (typeof(element) == 'string') element = '#' + element; - var element = $(element); + var element = jQuery(element); var sortable_options = {}; if (options.update === true) { - url_params.authenticity_token = $('meta[name=csrf-param]').attr('content'); + url_params.authenticity_token = jQuery('meta[name=csrf-param]').attr('content'); sortable_options.update = function(event, ui) { var url = controller + '/' + options.action + '?' - url += $(this).sortable('serialize',{key: encodeURIComponent($(this).attr('id') + '[]'), expression:/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/}); - $.post(url.append_params(url_params)); + url += jQuery(this).sortable('serialize',{key: encodeURIComponent(jQuery(this).attr('id') + '[]'), expression:/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-rowjQuery/}); + jQuery.post(url.append_params(url_params)); } } element.sortable(sortable_options); }, record_select_onselect: function(edit_associated_url, active_scaffold_id, id){ - $.ajax({ + jQuery.ajax({ url: edit_associated_url.split('--ID--').join(id), error: function(xhr, textStatus, errorThrown){ ActiveScaffold.report_500_response(active_scaffold_id) @@ -659,10 +656,10 @@ var ActiveScaffold = { // element is tbody id mark_records: function(element, options) { if (typeof(element) == 'string') element = '#' + element; - var element = $(element); - var mark_checkboxes = $('#' + element.attr('id') + ' > tr.record td.marked-column input[type="checkbox"]'); + var element = jQuery(element); + var mark_checkboxes = jQuery('#' + element.attr('id') + ' > tr.record td.marked-column input[type="checkbox"]'); mark_checkboxes.each(function (index) { - var item = $(this); + var item = jQuery(this); if(options.checked === true) { item.attr('checked', 'checked'); } else { @@ -689,8 +686,8 @@ var ActiveScaffold = { element_id: 'editor_id', ajax_data_type: "script", update_value: 'value'}, - csrf_param = $('meta[name=csrf-param]').first(), - csrf_token = $('meta[name=csrf-token]').first(), + csrf_param = jQuery('meta[name=csrf-param]').first(), + csrf_token = jQuery('meta[name=csrf-token]').first(), my_parent = span.parent(), column_heading = null; @@ -747,19 +744,19 @@ var ActiveScaffold = { }, update_column: function(element, url, send_form, source_id, val) { - if (!element) element = $('#' + source_id); + if (!element) element = jQuery('#' + source_id); var as_form = element.closest('form.as_form'); var params = null; if (send_form) { params = as_form.serialize(); - params += '&' + $.param({"source_id": source_id}); + params += '&' + jQuery.param({"source_id": source_id}); } else { params = {value: val}; params.source_id = source_id; } - $.ajax({ + jQuery.ajax({ url: url, data: params, beforeSend: function(event) { @@ -780,7 +777,7 @@ var ActiveScaffold = { }, draggable_lists: function(element) { - $('#' + element).draggable_lists(); + jQuery('#' + element).draggable_lists(); } } @@ -822,11 +819,11 @@ String.prototype.append_params = function(params) { ActiveScaffold.Actions = new Object(); ActiveScaffold.Actions.Abstract = Class.extend({ init: function(links, target, loading_indicator, options) { - this.target = $(target); - this.loading_indicator = $(loading_indicator); + this.target = jQuery(target); + this.loading_indicator = jQuery(loading_indicator); this.options = options; var _this = this; - this.links = $.map(links, function(link) { + this.links = jQuery.map(links, function(link) { var my_link = _this.instantiate_link(link); return my_link; }); @@ -844,7 +841,7 @@ ActiveScaffold.Actions.Abstract = Class.extend({ ActiveScaffold.ActionLink = { get: function(element) { if (typeof(element) == 'string') element = '#' + element; - var element = $(element); + var element = jQuery(element); if (element.length > 0) { element.data(); // jquery 1.4.2 workaround if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) { @@ -863,7 +860,7 @@ ActiveScaffold.ActionLink = { //table action new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header'), parent.find('.loading-indicator')); } - element = $(element); + element = jQuery(element); } return element.data('action_link'); } else { @@ -873,7 +870,7 @@ ActiveScaffold.ActionLink = { }; ActiveScaffold.ActionLink.Abstract = Class.extend({ init: function(a, target, loading_indicator) { - this.tag = $(a); + this.tag = jQuery(a); this.url = this.tag.attr('href'); this.method = this.tag.attr('data-method') || 'get'; this.target = target; @@ -907,7 +904,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ get_new_adapter_id: function() { var id = 'adapter_'; var i = 0; - while ($(id + i)) i++; + while (jQuery(id + i)) i++; return id + i; }, @@ -932,14 +929,14 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ }, update_flash_messages: function(messages) { - message_node = $(this.scaffold_id().replace(/-active-scaffold/, '-messages')); + message_node = jQuery(this.scaffold_id().replace(/-active-scaffold/, '-messages')); if (message_node) message_node.html(messages); }, set_adapter: function(element) { this.adapter = element; this.adapter.addClass('as_adapter'); this.adapter.data('action_link', this); - if (this.refresh_url) $('.as_cancel[data-refresh=true]', this.adapter).attr('href', this.refresh_url); + if (this.refresh_url) jQuery('.as_cancel[data-refresh=true]', this.adapter).attr('href', this.refresh_url); } }); @@ -964,7 +961,7 @@ ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ close_previous_adapter: function() { var _this = this; - $.each(this.set.links, function(index, item) { + jQuery.each(this.set.links, function(index, item) { if (item.url != _this.url && item.is_disabled() && item.adapter) { item.enable(); item.adapter.remove(); @@ -1003,7 +1000,7 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ enable: function() { var _this = this; - $.each(this.set.links, function(index, item) { + jQuery.each(this.set.links, function(index, item) { if (item.url != _this.url) return; item.tag.removeClass('disabled'); }); @@ -1011,7 +1008,7 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ disable: function() { var _this = this; - $.each(this.set.links, function(index, item) { + jQuery.each(this.set.links, function(index, item) { if (item.url != _this.url) return; item.tag.addClass('disabled'); }); @@ -1054,5 +1051,3 @@ ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({ ActiveScaffold.highlight(this.adapter.find('td').first().children()); } }); - -})(jQuery); \ No newline at end of file diff --git a/app/assets/javascripts/jquery/date_picker_bridge.js.erb b/app/assets/javascripts/jquery/date_picker_bridge.js.erb index bb30c530f8..c56a45529a 100644 --- a/app/assets/javascripts/jquery/date_picker_bridge.js.erb +++ b/app/assets/javascripts/jquery/date_picker_bridge.js.erb @@ -1,8 +1,8 @@ <%= ActiveScaffold::Bridges[:date_picker].localization %> -jQuery(document).ready(function($) { - $('input.date_picker').live('focus', function(event) { - var date_picker = $(this); +jQuery(document).ready(function() { + jQuery('input.date_picker').live('focus', function(event) { + var date_picker = jQuery(this); if (typeof(date_picker.datepicker) == 'function') { if (!date_picker.hasClass('hasDatepicker')) { date_picker.datepicker(); @@ -11,8 +11,8 @@ jQuery(document).ready(function($) { } return true; }); - $('input.datetime_picker').live('focus', function(event) { - var date_picker = $(this); + jQuery('input.datetime_picker').live('focus', function(event) { + var date_picker = jQuery(this); if (typeof(date_picker.datetimepicker) == 'function') { if (!date_picker.hasClass('hasDatepicker')) { date_picker.datetimepicker(); diff --git a/app/assets/javascripts/jquery/draggable_lists.js b/app/assets/javascripts/jquery/draggable_lists.js index b7c2018b00..c03baa8eee 100644 --- a/app/assets/javascripts/jquery/draggable_lists.js +++ b/app/assets/javascripts/jquery/draggable_lists.js @@ -1,31 +1,27 @@ -(function($){ - jQuery.fn.draggable_lists = function() { this.addClass('draggable-list'); - var list_selected = $(this.get(0).cloneNode(false)).addClass('selected'); + var list_selected = jQuery(this.get(0).cloneNode(false)).addClass('selected'); list_selected.attr('id', list_selected.attr('id') + '_selected').insertAfter(this); this.find('input:checkbox').each(function(index, item) { - var li = $(item).closest('li').addClass('draggable-item'); + var li = jQuery(item).closest('li').addClass('draggable-item'); li.children('label').removeAttr('for'); - if ($(item).is(':checked')) li.appendTo(list_selected); + if (jQuery(item).is(':checked')) li.appendTo(list_selected); li.draggable({appendTo: 'body', helper: 'clone'}); }); - $([this, list_selected]).droppable({ + jQuery([this, list_selected]).droppable({ hoverClass: 'hover', accept: function(draggable) { - var parent_id = draggable.parent().attr('id'), id = $(this).attr('id'), - requested_id = $(this).hasClass('selected') ? id.replace('_selected', '') : id + '_selected'; + var parent_id = draggable.parent().attr('id'), id = jQuery(this).attr('id'), + requested_id = jQuery(this).hasClass('selected') ? id.replace('_selected', '') : id + '_selected'; return parent_id == requested_id; }, drop: function(event, ui) { - $(this).append(ui.draggable); - var input = $('input:checkbox', ui.draggable); - if ($(this).hasClass('selected')) input.attr('checked', 'checked'); + jQuery(this).append(ui.draggable); + var input = jQuery('input:checkbox', ui.draggable); + if (jQuery(this).hasClass('selected')) input.attr('checked', 'checked'); else input.removeAttr('checked'); ui.draggable.css({left: '0px', top: '0px'}); } }); return this; }; - -})(jQuery); \ No newline at end of file diff --git a/app/assets/javascripts/jquery/tiny_mce_bridge.js b/app/assets/javascripts/jquery/tiny_mce_bridge.js index 5ae4bad902..b6e9e812ac 100644 --- a/app/assets/javascripts/jquery/tiny_mce_bridge.js +++ b/app/assets/javascripts/jquery/tiny_mce_bridge.js @@ -1,12 +1,7 @@ var action_link_close = ActiveScaffold.ActionLink.Abstract.prototype.close; - -(function($){ - ActiveScaffold.ActionLink.Abstract.prototype.close = function() { - $(this.adapter).find('textarea.mceEditor').each(function(index, elem) { - tinyMCE.execCommand('mceRemoveControl', false, $(elem).attr('id')); + jQuery(this.adapter).find('textarea.mceEditor').each(function(index, elem) { + tinyMCE.execCommand('mceRemoveControl', false, jQuery(elem).attr('id')); }); action_link_close.apply(this); }; - -})(jQuery); \ No newline at end of file From c648357d5f48f5f864df565a26dead14608d92f4 Mon Sep 17 00:00:00 2001 From: Craig Walker <github@softcraft.ca> Date: Tue, 10 Jan 2012 21:31:00 +0000 Subject: [PATCH 1357/2024] More jQuery conflict resolution --- frontends/default/views/_search.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index f802f7eeeb..f95c448afc 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -25,9 +25,9 @@ options['data-loading'] = true unless live_search $(element).next().click(); }); <% elsif live_search && ActiveScaffold.js_framework == :jquery %> - $(<%= "##{search_input_id}".to_json.html_safe %>).next().hide(); - $(<%= "##{search_input_id}".to_json.html_safe %>).delayedObserver(0.5, function() { - $(<%= "##{search_input_id}".to_json.html_safe %>).parent().trigger("submit");}); + jQuery(<%= "##{search_input_id}".to_json.html_safe %>).next().hide(); + jQuery(<%= "##{search_input_id}".to_json.html_safe %>).delayedObserver(0.5, function() { + jQuery(<%= "##{search_input_id}".to_json.html_safe %>).parent().trigger("submit");}); <% end -%> ActiveScaffold.focus_first_element_of_form('<%= element_form_id(:action => 'search') %>'); //]]> From b5e6d3a96320f78a81a4af0f368d757e6d955eda Mon Sep 17 00:00:00 2001 From: Craig Walker <github@softcraft.ca> Date: Tue, 10 Jan 2012 22:31:20 +0000 Subject: [PATCH 1358/2024] Fixed search-and-replace to account for $ in regexes --- .../javascripts/jquery/active_scaffold.js | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 4674160ba2..389d886bb1 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -112,7 +112,7 @@ jQuery(document).ready(function() { return true; }); jQuery('span.in_place_editor_field').live('hover', function(event) { - jQuery(this).data(); // jquery 1.4.2 workaround + jQuery(this).data(); // $ 1.4.2 workaround if (event.type == 'mouseenter') { if (typeof(jQuery(this).data('editInPlace')) === 'undefined') jQuery(this).addClass("hover"); } @@ -267,7 +267,7 @@ jQuery(document).ready(function() { })(); /* - jQuery delayed observer + $ delayed observer (c) 2007 - Maxime Haineault (max@centdessin.com) Special thanks to Stephen Goguen & Tane Piper. @@ -275,7 +275,7 @@ jQuery(document).ready(function() { Slight modifications by Elliot Winkler */ -if (typeof(jQuery.fn.delayedObserver) === 'undefined') { +if (typeof($.fn.delayedObserver) === 'undefined') { (function() { var delayedObserverStack = []; var observed; @@ -303,18 +303,18 @@ if (typeof(jQuery.fn.delayedObserver) === 'undefined') { ); } - jQuery.fn.extend({ + $.fn.extend({ delayedObserver:function(delay, callback){ - jQuerythis = jQuery(this); + $this = jQuery(this); delayedObserverStack.push({ - obj: jQuerythis, timer: null, delay: delay, - oldVal: jQuerythis.val(), callback: callback + obj: $this, timer: null, delay: delay, + oldVal: $this.val(), callback: callback }); stackPos = delayedObserverStack.length-1; - jQuerythis.keyup(function(event) { + $this.keyup(function(event) { if (isNonPrintableKey(event)) return; observed = delayedObserverStack[stackPos]; if (observed.obj.val() == observed.obj.oldVal) return; @@ -362,7 +362,7 @@ var ActiveScaffold = { }, reload_if_empty: function(tbody, url) { if (this.records_for(tbody).length == 0) { - jQuery.getScript(url); + $.getScript(url); } }, removeSortClasses: function(scaffold) { @@ -443,7 +443,7 @@ var ActiveScaffold = { disable_form: function(as_form) { if (typeof(as_form) == 'string') as_form = '#' + as_form; as_form = jQuery(as_form) - var loading_indicator = jQuery('#' + as_form.attr('id').replace(/-formjQuery/, '-loading-indicator')); + var loading_indicator = jQuery('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); if (loading_indicator) loading_indicator.css('visibility','visible'); jQuery('input[type=submit]', as_form).attr('disabled', 'disabled'); as_form[0].disabled_fields = jQuery("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled'); @@ -452,7 +452,7 @@ var ActiveScaffold = { enable_form: function(as_form) { if (typeof(as_form) == 'string') as_form = '#' + as_form; as_form = jQuery(as_form) - var loading_indicator = jQuery('#' + as_form.attr('id').replace(/-formjQuery/, '-loading-indicator')); + var loading_indicator = jQuery('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); if (loading_indicator) loading_indicator.css('visibility','hidden'); jQuery('input[type=submit]', as_form).removeAttr('disabled'); as_form[0].disabled_fields.removeAttr('disabled'); @@ -543,7 +543,7 @@ var ActiveScaffold = { process_checkbox_inplace_edit: function(checkbox, options) { var checked = checkbox.is(':checked'); if (checked === true) options['params'] += '&value=1'; - jQuery.ajax({ + $.ajax({ url: options.url, type: "POST", data: options['params'], @@ -637,15 +637,15 @@ var ActiveScaffold = { url_params.authenticity_token = jQuery('meta[name=csrf-param]').attr('content'); sortable_options.update = function(event, ui) { var url = controller + '/' + options.action + '?' - url += jQuery(this).sortable('serialize',{key: encodeURIComponent(jQuery(this).attr('id') + '[]'), expression:/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-rowjQuery/}); - jQuery.post(url.append_params(url_params)); + url += jQuery(this).sortable('serialize',{key: encodeURIComponent(jQuery(this).attr('id') + '[]'), expression:/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/}); + $.post(url.append_params(url_params)); } } element.sortable(sortable_options); }, record_select_onselect: function(edit_associated_url, active_scaffold_id, id){ - jQuery.ajax({ + $.ajax({ url: edit_associated_url.split('--ID--').join(id), error: function(xhr, textStatus, errorThrown){ ActiveScaffold.report_500_response(active_scaffold_id) @@ -679,7 +679,7 @@ var ActiveScaffold = { }, in_place_editor_field_clicked: function(span) { - span.data(); // jquery 1.4.2 workaround + span.data(); // $ 1.4.2 workaround if (typeof(span.data('editInPlace')) === 'undefined') { var options = {show_buttons: true, hover_class: 'hover', @@ -750,13 +750,13 @@ var ActiveScaffold = { if (send_form) { params = as_form.serialize(); - params += '&' + jQuery.param({"source_id": source_id}); + params += '&' + $.param({"source_id": source_id}); } else { params = {value: val}; params.source_id = source_id; } - jQuery.ajax({ + $.ajax({ url: url, data: params, beforeSend: function(event) { @@ -823,7 +823,7 @@ ActiveScaffold.Actions.Abstract = Class.extend({ this.loading_indicator = jQuery(loading_indicator); this.options = options; var _this = this; - this.links = jQuery.map(links, function(link) { + this.links = $.map(links, function(link) { var my_link = _this.instantiate_link(link); return my_link; }); @@ -843,7 +843,7 @@ ActiveScaffold.ActionLink = { if (typeof(element) == 'string') element = '#' + element; var element = jQuery(element); if (element.length > 0) { - element.data(); // jquery 1.4.2 workaround + element.data(); // $ 1.4.2 workaround if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) { var parent = element.closest('.actions'); if (parent.length === 0) { @@ -961,7 +961,7 @@ ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ close_previous_adapter: function() { var _this = this; - jQuery.each(this.set.links, function(index, item) { + $.each(this.set.links, function(index, item) { if (item.url != _this.url && item.is_disabled() && item.adapter) { item.enable(); item.adapter.remove(); @@ -1000,7 +1000,7 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ enable: function() { var _this = this; - jQuery.each(this.set.links, function(index, item) { + $.each(this.set.links, function(index, item) { if (item.url != _this.url) return; item.tag.removeClass('disabled'); }); @@ -1008,7 +1008,7 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ disable: function() { var _this = this; - jQuery.each(this.set.links, function(index, item) { + $.each(this.set.links, function(index, item) { if (item.url != _this.url) return; item.tag.addClass('disabled'); }); From 6bfd1ec5de2b29d264ee092bcf0889bf0064ed1b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 11 Jan 2012 13:34:03 +0100 Subject: [PATCH 1359/2024] fix class name for namespaced controllers --- frontends/default/views/_list_inline_adapter.html.erb | 2 +- frontends/default/views/_list_with_header.html.erb | 4 ++-- frontends/default/views/add_existing_form.html.erb | 2 +- frontends/default/views/create.html.erb | 2 +- frontends/default/views/search.html.erb | 2 +- frontends/default/views/show.html.erb | 2 +- frontends/default/views/update.html.erb | 2 +- lib/active_scaffold/data_structures/nested_info.rb | 8 ++++++++ lib/active_scaffold/helpers/view_helpers.rb | 2 +- 9 files changed, 17 insertions(+), 9 deletions(-) diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index 67109a02b0..477f71c9bb 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -1,7 +1,7 @@ <%# nested_id, allows us to remove a nested scaffold programmatically %> <tr class="inline-adapter" id="<%= element_row_id :action => :nested %>"> <td colspan="99" class="inline-adapter-cell"> - <div class="<%= "#{params[:action]}-view" if params[:action] %> <%= "#{params[:associations] ? params[:associations] : params[:controller]}-view" %> view"> + <div class="<%= "#{params[:action]}-view" if params[:action] %> <%= "#{nested? ? nested.name : id_from_controller(params[:controller])}-view" %> view"> <%= link_to(as_(:close), '', :class => 'inline-adapter-close as_cancel', :remote => true, :title => as_(:close), 'data-refresh' => (action_name == 'index' ? true : false)) -%> <%= payload -%> </div> diff --git a/frontends/default/views/_list_with_header.html.erb b/frontends/default/views/_list_with_header.html.erb index 2278906468..eb8d3faaa0 100644 --- a/frontends/default/views/_list_with_header.html.erb +++ b/frontends/default/views/_list_with_header.html.erb @@ -8,7 +8,7 @@ <% old_record, @record = @record, new_model %> <tr> <td> - <div class="active-scaffold show_search-view <%= "#{params[:controller]}-view" %> view"> + <div class="active-scaffold show_search-view <%= "#{id_from_controller params[:controller]}-view" %> view"> <%= render :partial => active_scaffold_config.list.search_partial %> </div> </td> @@ -21,7 +21,7 @@ <% old_record, @record = @record, new_model %> <tr> <td> - <div class="active-scaffold create-view <%= "#{params[:controller]}-view" %> view"> + <div class="active-scaffold create-view <%= "#{id_from_controller params[:controller]}-view" %> view"> <%= render :partial => 'create_form_on_list' %> </div> </td> diff --git a/frontends/default/views/add_existing_form.html.erb b/frontends/default/views/add_existing_form.html.erb index 49570161a9..f75446c2d1 100644 --- a/frontends/default/views/add_existing_form.html.erb +++ b/frontends/default/views/add_existing_form.html.erb @@ -1,5 +1,5 @@ <div class="active-scaffold"> - <div class="create-view <%= "#{params[:controller]}-view" %> view"> + <div class="create-view <%= "#{id_from_controller params[:controller]}-view" %> view"> <%= render :partial => 'add_existing_form' -%> </div> </div> \ No newline at end of file diff --git a/frontends/default/views/create.html.erb b/frontends/default/views/create.html.erb index 4647991dcd..1bcb00c78b 100644 --- a/frontends/default/views/create.html.erb +++ b/frontends/default/views/create.html.erb @@ -1,5 +1,5 @@ <div class="active-scaffold"> - <div class="create-view <%= "#{params[:controller]}-view" %> view"> + <div class="create-view <%= "#{id_from_controller params[:controller]}-view" %> view"> <%= render :partial => 'create_form' -%> </div> </div> \ No newline at end of file diff --git a/frontends/default/views/search.html.erb b/frontends/default/views/search.html.erb index 5c126f67aa..873d0da377 100644 --- a/frontends/default/views/search.html.erb +++ b/frontends/default/views/search.html.erb @@ -1,5 +1,5 @@ <div class="active-scaffold"> - <div class="search-view <%= "#{params[:controller]}-view" %> view"> + <div class="search-view <%= "#{id_from_controller params[:controller]}-view" %> view"> <%= render :partial => 'search' -%> </div> </div> diff --git a/frontends/default/views/show.html.erb b/frontends/default/views/show.html.erb index 0b36a919b7..3382a7b722 100644 --- a/frontends/default/views/show.html.erb +++ b/frontends/default/views/show.html.erb @@ -1,5 +1,5 @@ <div class="active-scaffold"> - <div class="show-view <%= "#{params[:controller]}-view" %> view"> + <div class="show-view <%= "#{id_from_controller params[:controller]}-view" %> view"> <%= render :partial => 'show' -%> </div> </div> \ No newline at end of file diff --git a/frontends/default/views/update.html.erb b/frontends/default/views/update.html.erb index d8e3da1821..3909b937e3 100644 --- a/frontends/default/views/update.html.erb +++ b/frontends/default/views/update.html.erb @@ -1,5 +1,5 @@ <div class="active-scaffold"> - <div class="update-view <%= "#{params[:controller]}-view" %> view"> + <div class="update-view <%= "#{id_from_controller params[:controller]}-view" %> view"> <% if active_scaffold_config.update.nested_links and active_scaffold_config.action_links.member.empty? -%> <%= render :partial => 'update_actions', :locals => {:record => @record, :url_options => params_for(:action => :list, :id => @record.id)} %> <% end -%> diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index e803722705..5b71e81e3c 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -70,6 +70,10 @@ def initialize(model, session_info) iterate_model_associations(model) end + def name + self.association.name + end + def habtm? association.macro == :has_and_belongs_to_many end @@ -131,5 +135,9 @@ def initialize(model, session_info) def to_params super.merge(:named_scope => @scope) end + + def name + self.scope + end end end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 107623eb26..b538abc075 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -239,7 +239,7 @@ def column_heading_class(column, sorting) end def as_main_div_class - classes = ["active-scaffold", "active-scaffold-#{controller_id}", "#{params[:controller]}-view", "#{active_scaffold_config.theme}-theme"] + classes = ["active-scaffold", "active-scaffold-#{controller_id}", "#{id_from_controller params[:controller]}-view", "#{active_scaffold_config.theme}-theme"] classes << "as_touch" if touch_device? classes.join(' ') end From 81a0db7cd2be4405ee097e59fde3dd5efb4ae66b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 12 Jan 2012 14:30:13 +0100 Subject: [PATCH 1360/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 88afe5763b..cae7dadbbb 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 13 + PATCH = 14 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 14391a946e26c96adbadba0e8ee2c17f42318c3f Mon Sep 17 00:00:00 2001 From: r-stu31 <r.stu3.1@googlemail.com> Date: Sat, 14 Jan 2012 18:32:24 +0100 Subject: [PATCH 1361/2024] Add a configuration option for JavaScript features: ActiveScaffold.js_config. Make the scroll_on_close feature configurable. --- app/assets/javascripts/active_scaffold.js.erb | 1 + app/assets/javascripts/jquery/active_scaffold.js | 2 +- app/assets/javascripts/prototype/active_scaffold.js | 2 +- lib/active_scaffold.rb | 9 +++++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index e51401d90a..832e679f6e 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -14,5 +14,6 @@ <% require_asset "prototype/form_enhancements" %> <% require_asset "prototype/rico_corner" %> <% end %> +ActiveScaffold.config = <%= ActiveScaffold.js_config.to_json %>; <% ActiveScaffold.javascripts.each {|js| require_asset js} %> <% ActiveScaffold::Bridges.all_javascripts.each {|js| require_asset js} %> diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 27bdfe62dc..9a690e13b8 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -894,7 +894,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ this.enable(); this.adapter.remove(); if (this.hide_target) this.target.show(); - ActiveScaffold.scroll_to(this.target); + if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target); }, reload: function() { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index bd41c7aae3..f8e79aa8a6 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -791,7 +791,7 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ this.enable(); this.adapter.remove(); if (this.hide_target) this.target.show(); - ActiveScaffold.scroll_to(this.target); + if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target); }, reload: function() { diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index d31813e257..f2edbc27ff 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -13,6 +13,7 @@ require 'active_scaffold/version' require 'active_scaffold/engine' unless defined? ACTIVE_SCAFFOLD_PLUGIN +require 'json' # for js_config module ActiveScaffold autoload :AttributeParams, 'active_scaffold/attribute_params' @@ -131,6 +132,14 @@ def self.js_framework end end + def self.js_config=(config) + @@js_config = config + end + + def self.js_config + @@js_config ||= {:scroll_on_close => true} + end + # exclude bridges you do not need # name of bridge subdir should be used to exclude it # eg From d02cda4c3e58f30b447b49286d6f49fadc33a189 Mon Sep 17 00:00:00 2001 From: Kevin Whitaker <kevin.whitaker.tx@gmail.com> Date: Tue, 17 Jan 2012 11:44:28 -0600 Subject: [PATCH 1362/2024] Replacing $ with jQuery --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 389d886bb1..337c7f2aa0 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -823,7 +823,7 @@ ActiveScaffold.Actions.Abstract = Class.extend({ this.loading_indicator = jQuery(loading_indicator); this.options = options; var _this = this; - this.links = $.map(links, function(link) { + this.links = jQuery.map(links, function(link) { var my_link = _this.instantiate_link(link); return my_link; }); From 2cb1da3f3615822778401a1cd038631b299bb05b Mon Sep 17 00:00:00 2001 From: Kevin Whitaker <kevin.whitaker.tx@gmail.com> Date: Tue, 17 Jan 2012 17:19:45 -0600 Subject: [PATCH 1363/2024] Making search render HTML safe --- lib/active_scaffold/actions/search.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index 83488d0336..44bdb67775 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -17,7 +17,7 @@ def search_respond_to_html render(:action => "search") end def search_respond_to_js - render(:partial => "search") + render(:partial => "search").html_safe end def do_search query = search_params.to_s.strip rescue '' From 38493c376d07824699a3b7dacedc9e14374ee811 Mon Sep 17 00:00:00 2001 From: Kevin Whitaker <kevin.whitaker.tx@gmail.com> Date: Tue, 17 Jan 2012 17:25:19 -0600 Subject: [PATCH 1364/2024] forgot a bang --- lib/active_scaffold/actions/search.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index 44bdb67775..9d70af2fc5 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -17,7 +17,7 @@ def search_respond_to_html render(:action => "search") end def search_respond_to_js - render(:partial => "search").html_safe + render(:partial => "search").html_safe! end def do_search query = search_params.to_s.strip rescue '' From ca738028233a3e86e0292805be07c702946d2101 Mon Sep 17 00:00:00 2001 From: Kevin Whitaker <kevin.whitaker.tx@gmail.com> Date: Tue, 17 Jan 2012 17:31:13 -0600 Subject: [PATCH 1365/2024] failed experiment --- lib/active_scaffold/actions/search.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index 9d70af2fc5..83488d0336 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -17,7 +17,7 @@ def search_respond_to_html render(:action => "search") end def search_respond_to_js - render(:partial => "search").html_safe! + render(:partial => "search") end def do_search query = search_params.to_s.strip rescue '' From 49696f66dd4b3faa51421f7cd67159584b04b9de Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 18 Jan 2012 16:14:49 +0100 Subject: [PATCH 1366/2024] remove eid from nested links to avoid cookie overflows --- .../default/views/_field_search.html.erb | 2 +- .../views/_form_association_footer.html.erb | 4 +- .../default/views/_list_messages.html.erb | 2 +- frontends/default/views/_list_record.html.erb | 2 +- frontends/default/views/_search.html.erb | 2 +- frontends/default/views/destroy.js.erb | 6 +-- lib/active_scaffold/actions/nested.rb | 16 +++--- .../data_structures/nested_info.rb | 49 +++++++++---------- .../helpers/controller_helpers.rb | 4 +- .../helpers/list_column_helpers.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 4 -- 11 files changed, 41 insertions(+), 52 deletions(-) diff --git a/frontends/default/views/_field_search.html.erb b/frontends/default/views/_field_search.html.erb index dba8c5880f..d4223d1947 100644 --- a/frontends/default/views/_field_search.html.erb +++ b/frontends/default/views/_field_search.html.erb @@ -1,4 +1,4 @@ -<% url_options = params_for(:action => :index, :escape => false, :search => nil) -%> +<% url_options = params_for(:action => :index, :search => nil) -%> <%= options = {:id => element_form_id(:action => 'search'), :class => "as_form search", diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index 9057bc2a79..f1bef8030a 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -11,8 +11,8 @@ show_add_new = column_show_add_new(column, associated, @record) return unless show_add_new or show_add_existing -edit_associated_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :associated_id => '--ID--', :escape => false, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_existing -add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :escape => false, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_new +edit_associated_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :associated_id => '--ID--', :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_existing +add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_new -%> <div class="footer-wrapper"> diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index 1daab81615..a44989272a 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -19,7 +19,7 @@ <% search_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :member, :position => false) action_links = ActiveScaffold::DataStructures::ActionLinks.new action_links.add(search_link) -%> - <%= render :partial => 'list_actions', :locals => {:record => new_model, :url_options => params_for(:escape => false, :search => ''), :action_links => action_links.member} %> + <%= render :partial => 'list_actions', :locals => {:record => new_model, :url_options => params_for(:search => ''), :action_links => action_links.member} %> <% else %> <td class='actions'><%= '<p class="empty-message"> </p>'.html_safe if @page.items.empty? %></td> <% end -%> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index cf4ef59b6b..3455e94361 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -7,7 +7,7 @@ url_options = params_for(:action => :list, :id => record.id) action_links ||= active_scaffold_config.action_links.member -%> -<tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get, :escape => false)).html_safe %>"> +<tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get)).html_safe %>"> <%= render :partial => 'list_record_columns', :locals => {:record => record, :columns => columns} %> <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options, :action_links => action_links} unless action_links.empty? %> <%= render_nested_view(action_links, url_options, record) unless @nested_auto_open.nil? %> diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index f802f7eeeb..0dd7ad59c4 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -1,5 +1,5 @@ <% live_search = active_scaffold_config.search.live? -%> -<% url_options = params_for(:action => :index, :escape => false).delete_if{|k,v| k == 'search'} -%> +<% url_options = params_for(:action => :index).delete_if{|k,v| k == 'search'} -%> <%= options = {:id => element_form_id(:action => 'search'), :class => "as_form search", diff --git a/frontends/default/views/destroy.js.erb b/frontends/default/views/destroy.js.erb index d2c043b556..329627e816 100644 --- a/frontends/default/views/destroy.js.erb +++ b/frontends/default/views/destroy.js.erb @@ -4,7 +4,7 @@ <%render_parent_options%> <%if render_parent_action == :row%> <%# TODO: That s not working with delete....%> - ActiveScaffold.delete_record_row('<%=element_row_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}", :action => 'list', :id => params[:id])%>', '<%=url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))%>'); + ActiveScaffold.delete_record_row('<%=element_row_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}", :action => 'list', :id => params[:id])%>', '<%=url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max))%>'); <%messages_id = active_scaffold_messages_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}")%> <%elsif render_parent_action == :index%> <%= escape_javascript(controller.send(:render_component_into_view, render_parent_options))%> @@ -13,7 +13,7 @@ <%elsif (active_scaffold_config.delete.refresh_list)%> ActiveScaffold.replace('<%=active_scaffold_content_id%>', '<%=escape_javascript(render(:partial => 'list', :layout => false))%>'); <%else%> - ActiveScaffold.delete_record_row('<%=element_row_id(:action => 'list', :id => params[:id])%>', '<%=url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max, :escape => false))%>'); + ActiveScaffold.delete_record_row('<%=element_row_id(:action => 'list', :id => params[:id])%>', '<%=url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max))%>'); <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); <% end %> @@ -21,4 +21,4 @@ <%else%> <%flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br)%> <%end%> -ActiveScaffold.replace_html('<%=messages_id%>', '<%=escape_javascript(render(:partial => 'messages'))%>'); \ No newline at end of file +ActiveScaffold.replace_html('<%=messages_id%>', '<%=escape_javascript(render(:partial => 'messages'))%>'); diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index c786066413..36f323220a 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -17,11 +17,6 @@ def self.included(base) protected def nested - @nested ||= ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, active_scaffold_session_storage) - if !@nested.nil? && @nested.new_instance? - register_constraints_with_action_columns(@nested.constrained_fields, active_scaffold_config.list.hide_nested_column ? [] : [:list]) - active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to? - end @nested end @@ -31,11 +26,12 @@ def nested? def set_nested if params[:parent_scaffold] && ((params[:association] && params[:assoc_id]) || params[:named_scope]) - @nested = nil - active_scaffold_session_storage[:nested] = {:parent_scaffold => params[:parent_scaffold].to_s, - :name => (params[:association] || params[:named_scope]).to_sym, - :parent_id => params[:assoc_id]} - params.delete_if {|key, value| [:parent_scaffold, :association, :named_scope, :assoc_id].include? key.to_sym} + @nested = ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, params) + unless @nested.nil? + register_constraints_with_action_columns(@nested.constrained_fields, active_scaffold_config.list.hide_nested_column ? [] : [:list]) + active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to? + end + #params.delete_if {|key, value| [:parent_scaffold, :association, :named_scope, :assoc_id].include? key.to_sym} end end diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 5b71e81e3c..63c2e96cd5 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -1,31 +1,28 @@ module ActiveScaffold::DataStructures class NestedInfo - def self.get(model, session_storage) - if session_storage[:nested].nil? - nil - else - session_info = session_storage[:nested].clone - begin - session_info[:parent_scaffold] = "#{session_info[:parent_scaffold].to_s.camelize}Controller".constantize - session_info[:parent_model] = session_info[:parent_scaffold].active_scaffold_config.model - session_info[:association] = session_info[:parent_model].reflect_on_association(session_info[:name]) - unless session_info[:association].nil? - ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, session_info) - else - ActiveScaffold::DataStructures::NestedInfoScope.new(model, session_info) - end - rescue ActiveScaffold::ControllerNotFound - nil + def self.get(model, params) + nested_info = {} + begin + nested_info[:name] = (params[:association] || params[:named_scope]).to_sym + nested_info[:parent_scaffold] = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize + nested_info[:parent_model] = nested_info[:parent_scaffold].active_scaffold_config.model + nested_info[:parent_id] = params[:assoc_id] + unless nested_info[:association].nil? + ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, nested_info) + else + ActiveScaffold::DataStructures::NestedInfoScope.new(model, nested_info) end + rescue ActiveScaffold::ControllerNotFound + nil end end attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :constrained_fields, :scope - def initialize(model, session_info) - @parent_model = session_info[:parent_model] - @parent_id = session_info[:parent_id] - @parent_scaffold = session_info[:parent_scaffold] + def initialize(model, nested_info) + @parent_model = nested_info[:parent_model] + @parent_id = nested_info[:parent_id] + @parent_scaffold = nested_info[:parent_scaffold] end def to_params @@ -64,9 +61,9 @@ def sorted? end class NestedInfoAssociation < NestedInfo - def initialize(model, session_info) - super(model, session_info) - @association = session_info[:association] + def initialize(model, nested_info) + super(model, nested_info) + @association = parent_model.reflect_on_association(nested_info[:name]) iterate_model_associations(model) end @@ -126,9 +123,9 @@ def iterate_model_associations(model) end class NestedInfoScope < NestedInfo - def initialize(model, session_info) - super(model, session_info) - @scope = session_info[:name] + def initialize(model, nested_info) + super(model, nested_info) + @scope = nested_info[:name] @constrained_fields = [] end diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index a9b5569593..e12c947184 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -30,12 +30,12 @@ def main_path_to_return parameters = {} if params[:parent_controller] parameters[:controller] = params[:parent_controller] - parameters[:eid] = params[:parent_controller] + #parameters[:eid] = params[:parent_controller] end parameters.merge! nested.to_params if nested? if params[:parent_sti] parameters[:controller] = params[:parent_sti] - parameters[:eid] = nil + #parameters[:eid] = nil end parameters[:parent_column] = nil parameters[:parent_id] = nil diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index b264c29808..58f95d13b0 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -297,7 +297,7 @@ def inplace_edit_tag_attributes(column) elsif inplace_edit_cloning?(column) tag_options['data-ie_mode'] = :clone elsif column.inplace_edit == :ajax - url = url_for(:controller => params_for[:controller], :action => 'render_field', :id => '__id__', :column => column.name, :update_column => column.name, :in_place_editing => true, :escape => false) + url = url_for(:controller => params_for[:controller], :action => 'render_field', :id => '__id__', :column => column.name, :update_column => column.name, :in_place_editing => true) plural = column.plural_association? && !override_form_field?(column) && [:select, :record_select].include?(column.form_ui) tag_options['data-ie_render_url'] = url tag_options['data-ie_mode'] = :ajax diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index b538abc075..8f03d00705 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -190,12 +190,8 @@ def url_options_for_nested_link(column, record, link, url_options, options = {}) if column && column.association url_options[:assoc_id] = url_options.delete(:id) url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present? - link.eid = "#{controller_id.from(3)}_#{record.id}_#{column.association.name}" unless options.has_key?(:reuse_eid) - url_options[:eid] = link.eid elsif link.parameters && link.parameters[:named_scope] url_options[:assoc_id] = url_options.delete(:id) - link.eid = "#{controller_id.from(3)}_#{record.id}_#{link.parameters[:named_scope]}" unless options.has_key?(:reuse_eid) - url_options[:eid] = link.eid end end From e9e22d745ebe7d6553fbe2d1ec4a5f26a0f7d668 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 18 Jan 2012 17:13:28 +0100 Subject: [PATCH 1367/2024] nested routes for nested scaffolds --- lib/active_scaffold/data_structures/nested_info.rb | 2 +- lib/active_scaffold/extensions/routing_mapper.rb | 14 ++++++++++++++ lib/active_scaffold/helpers/view_helpers.rb | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 63c2e96cd5..e6c55da15f 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -6,7 +6,7 @@ def self.get(model, params) nested_info[:name] = (params[:association] || params[:named_scope]).to_sym nested_info[:parent_scaffold] = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize nested_info[:parent_model] = nested_info[:parent_scaffold].active_scaffold_config.model - nested_info[:parent_id] = params[:assoc_id] + nested_info[:parent_id] = params[nested_info[:parent_model].name.foreign_key] unless nested_info[:association].nil? ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, nested_info) else diff --git a/lib/active_scaffold/extensions/routing_mapper.rb b/lib/active_scaffold/extensions/routing_mapper.rb index c027385a91..d3877ab1b9 100644 --- a/lib/active_scaffold/extensions/routing_mapper.rb +++ b/lib/active_scaffold/extensions/routing_mapper.rb @@ -28,6 +28,20 @@ def as_association_routes ActionDispatch::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each {|name, type| send(type, name)} end end + + def as_nested_resources(*resources) + options = resources.extract_options! + resources.each do |resource| + resources(resource, options.merge(:parent_scaffold => merge_module_scope(@scope[:module], parent_resource.plural), :association => resource)) { yield if block_given? } + end + end + + def as_scoped_routes(*scopes) + options = scopes.extract_options! + scopes.each do |scope| + resources(scope, options.merge(:parent_scaffold => merge_module_scope(@scope[:module], parent_resource.plural), :named_scope => scope, :controller => parent_resource.plural)) { yield if block_given? } + end + end end end end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 8f03d00705..1fc0cc9606 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -188,10 +188,10 @@ def action_link_html(link, url, html_options, record) def url_options_for_nested_link(column, record, link, url_options, options = {}) if column && column.association - url_options[:assoc_id] = url_options.delete(:id) + url_options[column.association.active_record.name.foreign_key.to_sym] = url_options.delete(:id) url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present? elsif link.parameters && link.parameters[:named_scope] - url_options[:assoc_id] = url_options.delete(:id) + url_options[active_scaffold_config.model.name.foreign_key.to_sym] = url_options.delete(:id) end end From 03e21acebff7a2289ed320044784c5c6853c9869 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 18 Jan 2012 17:14:29 +0100 Subject: [PATCH 1368/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index cae7dadbbb..292972ab2d 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 14 + PATCH = 15 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From b791d367a20ccef76127df5232ab3a44a21e967d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 20 Jan 2012 11:10:08 +0100 Subject: [PATCH 1369/2024] fix nested action, fixes #116 --- lib/active_scaffold/actions/nested.rb | 2 +- lib/active_scaffold/data_structures/nested_info.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 36f323220a..9a9f073b89 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -25,7 +25,7 @@ def nested? end def set_nested - if params[:parent_scaffold] && ((params[:association] && params[:assoc_id]) || params[:named_scope]) + if params[:parent_scaffold] && (params[:association] || params[:named_scope]) @nested = ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, params) unless @nested.nil? register_constraints_with_action_columns(@nested.constrained_fields, active_scaffold_config.list.hide_nested_column ? [] : [:list]) diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index e6c55da15f..6f12dd89df 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -7,10 +7,12 @@ def self.get(model, params) nested_info[:parent_scaffold] = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize nested_info[:parent_model] = nested_info[:parent_scaffold].active_scaffold_config.model nested_info[:parent_id] = params[nested_info[:parent_model].name.foreign_key] - unless nested_info[:association].nil? - ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, nested_info) - else - ActiveScaffold::DataStructures::NestedInfoScope.new(model, nested_info) + if nested_info[:parent_id] + unless nested_info[:association].nil? + ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, nested_info) + else + ActiveScaffold::DataStructures::NestedInfoScope.new(model, nested_info) + end end rescue ActiveScaffold::ControllerNotFound nil From 7529b2bafc9ea7e23955c8c23ced81a15e326030 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 20 Jan 2012 11:21:50 +0100 Subject: [PATCH 1370/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 292972ab2d..5800539fd6 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 15 + PATCH = 16 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From a830a0b6cb03a5e8cc560696e7bc066bae18f9d4 Mon Sep 17 00:00:00 2001 From: Nick Rogers <nick@Nicks-MacBook-Air.local> Date: Fri, 20 Jan 2012 09:15:26 -0500 Subject: [PATCH 1371/2024] Fix exception when trying to render an inline scaffold from a namespaced controller (e.g., render :active_scaffold => 'admin/scaffolds/admins') when using AJAX to insert the rendered scaffold instead of render_component. --- lib/active_scaffold/extensions/action_view_rendering.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 12e31451bf..2588946bd9 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -74,8 +74,11 @@ def render_with_active_scaffold(*args, &block) else content_tag(:div, :id => id, :class => 'active-scaffold-component') do url = url_for(url_options) + # parse the ActiveRecord model name from the controller path, which + # might be a namespaced controller (e.g., 'admin/admins') + model = remote_controller.to_s.sub(/.*\//, '').singularize content_tag(:div, :class => 'active-scaffold-header') do - content_tag :h2, link_to(args.first[:label] || active_scaffold_config_for(remote_controller.to_s.singularize).list.label, url, :remote => true) + content_tag :h2, link_to(args.first[:label] || active_scaffold_config_for(model).list.label, url, :remote => true) end << if ActiveScaffold.js_framework == :prototype javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true});") From 3b38df82a4a0af93b9b70f86f9672a5bb0922176 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 24 Jan 2012 09:39:59 +0100 Subject: [PATCH 1372/2024] fix date_picker search --- lib/active_scaffold/bridges/date_picker/helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index a74c78a1eb..d6aa61d733 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -150,7 +150,7 @@ def datepicker_format_options(column, format, options) module SearchColumnHelpers def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) if current_search.is_a? Hash - value = controller.class.condition_value_for_datetime(current_search[name], column.form_ui == :date_picker ? :to_date : :to_time) + value = controller.class.condition_value_for_datetime(current_search[name], column.search_ui == :date_picker ? :to_date : :to_time) else value = current_search end From 26f9bc9af8732a6c0e01425b66a258d698d4d97d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 24 Jan 2012 09:53:31 +0100 Subject: [PATCH 1373/2024] fix nested and constraints --- lib/active_scaffold/actions/nested.rb | 3 +-- lib/active_scaffold/data_structures/nested_info.rb | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 9a9f073b89..6418b2d1b2 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -28,10 +28,9 @@ def set_nested if params[:parent_scaffold] && (params[:association] || params[:named_scope]) @nested = ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, params) unless @nested.nil? - register_constraints_with_action_columns(@nested.constrained_fields, active_scaffold_config.list.hide_nested_column ? [] : [:list]) active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to? + register_constraints_with_action_columns(@nested.constrained_fields, active_scaffold_config.list.hide_nested_column ? [] : [:list]) end - #params.delete_if {|key, value| [:parent_scaffold, :association, :named_scope, :assoc_id].include? key.to_sym} end end diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 6f12dd89df..cea9adf867 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -8,7 +8,7 @@ def self.get(model, params) nested_info[:parent_model] = nested_info[:parent_scaffold].active_scaffold_config.model nested_info[:parent_id] = params[nested_info[:parent_model].name.foreign_key] if nested_info[:parent_id] - unless nested_info[:association].nil? + unless params[:association].nil? ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, nested_info) else ActiveScaffold::DataStructures::NestedInfoScope.new(model, nested_info) @@ -108,7 +108,7 @@ def to_params protected def iterate_model_associations(model) - @constrained_fields = [] + @constrained_fields = [] @constrained_fields << association.foreign_key.to_sym unless association.belongs_to? model.reflect_on_all_associations.each do |current| if !current.belongs_to? && association.foreign_key == current.association_foreign_key From 16751ae1416a629cf9f0cb13ecfdae759d3ed05c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 24 Jan 2012 10:03:43 +0100 Subject: [PATCH 1374/2024] translate greater, less and so on to spanish --- config/locales/es.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/locales/es.yml b/config/locales/es.yml index 0f3c83729c..4bac577ad9 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -60,12 +60,12 @@ es: update: 'Actualizar' update_model: 'Actualizar %{model}' updated_model: '%{model} actualizado' - '=': '=' - '>=': '>=' - '<=': '<=' - '>': '>' - '<': '<' - '!=': '!=' + '=': 'Igual' + '>=': 'Mayor o igual' + '<=': 'Menor o igual' + '>': 'Mayor' + '<': 'Menor' + '!=': 'Distinto' between: 'Entre' is_null: 'Es nulo' is_not_null: 'No es nulo' From ad73ab39b5f4c92cdad49060c0beb5b021a3b079 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 24 Jan 2012 10:28:35 +0100 Subject: [PATCH 1375/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 5800539fd6..3570ab1de6 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 16 + PATCH = 17 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From d4516e89d997f8def69017d0a23ab2b0f0a1e8cd Mon Sep 17 00:00:00 2001 From: "Dr. Michael Portz" <michael.portz@wamms.org> Date: Wed, 25 Jan 2012 09:47:03 +0100 Subject: [PATCH 1376/2024] Fixing enum in field search for multi_select, too --- lib/active_scaffold/helpers/search_column_helpers.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index d2b257ddae..abaaaa3acc 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -63,7 +63,9 @@ def active_scaffold_search_multi_select(column, options) if column.association select_options = options_for_association(column.association, false) else - select_options = Array(column.options[:options]) + select_options = column.options[:options].collect do |text, value| + active_scaffold_translated_option(column, text, value) + end end return as_(:no_options) if select_options.empty? From 6fab70de417ea6611981bd51578cd6ce27c24984 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 25 Jan 2012 11:07:58 +0100 Subject: [PATCH 1377/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 3570ab1de6..7fff8ea904 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 17 + PATCH = 18 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 69b400c4c817338a039a419e7f45e2fd958c6c58 Mon Sep 17 00:00:00 2001 From: CFI Web Dev <webdev@centerforinquiry.net> Date: Wed, 25 Jan 2012 15:07:34 -0500 Subject: [PATCH 1378/2024] allow passing of options to TinyMCE form fields via the column options tinymce hash --- lib/active_scaffold/bridges/tiny_mce/helpers.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/tiny_mce/helpers.rb b/lib/active_scaffold/bridges/tiny_mce/helpers.rb index 22eb3716cd..4ab7195a62 100644 --- a/lib/active_scaffold/bridges/tiny_mce/helpers.rb +++ b/lib/active_scaffold/bridges/tiny_mce/helpers.rb @@ -14,9 +14,14 @@ def self.included(base) def active_scaffold_input_text_editor(column, options) options[:class] = "#{options[:class]} mceEditor #{column.options[:class]}".strip + + settings = column.options[:tinymce] || { theme: 'simple' } + settings = settings.to_s.gsub(/:(.+?)\=\>/, '\1:') + settings = "tinyMCE.settings = #{settings};" + html = [] html << send(override_input(:textarea), column, options) - html << javascript_tag("tinyMCE.execCommand('mceAddControl', false, '#{options[:id]}');") if request.xhr? || params[:iframe] + html << javascript_tag(settings + "tinyMCE.execCommand('mceAddControl', false, '#{options[:id]}');") if request.xhr? || params[:iframe] html.join "\n" end From 6b399dae8ec56f8ab7b57b29dbe9e032622be13f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 26 Jan 2012 09:49:24 +0100 Subject: [PATCH 1379/2024] fix setting nested label affects non nested model --- lib/active_scaffold.rb | 3 ++- lib/active_scaffold/actions/nested.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index f2edbc27ff..73e9c2ed17 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -84,7 +84,8 @@ def active_scaffold_config_for(klass) self.class.active_scaffold_config_for(klass) end - def active_scaffold_session_storage(id = (params[:eid] || params[:controller])) + def active_scaffold_session_storage(id = nil) + id ||= params[:eid] || "#{params[:controller]}#{"_#{nested.parent_id}" if nested?}" session_index = "as:#{id}" session[session_index] ||= {} session[session_index] diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 6418b2d1b2..0d47b26b39 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -5,8 +5,8 @@ module Nested def self.included(base) super base.module_eval do - before_filter :register_constraints_with_action_columns - before_filter :set_nested + #before_filter :register_constraints_with_action_columns + prepend_before_filter :set_nested before_filter :configure_nested include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? {|a| a.macro == :has_and_belongs_to_many} end From fcc0802b80e6e5079a93195a0f2aba63d9ad1854 Mon Sep 17 00:00:00 2001 From: CFI Web Dev <webdev@centerforinquiry.net> Date: Thu, 26 Jan 2012 10:43:37 -0500 Subject: [PATCH 1380/2024] better handling of default options --- lib/active_scaffold/bridges/tiny_mce/helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/tiny_mce/helpers.rb b/lib/active_scaffold/bridges/tiny_mce/helpers.rb index 4ab7195a62..0301c8c557 100644 --- a/lib/active_scaffold/bridges/tiny_mce/helpers.rb +++ b/lib/active_scaffold/bridges/tiny_mce/helpers.rb @@ -15,7 +15,7 @@ def self.included(base) def active_scaffold_input_text_editor(column, options) options[:class] = "#{options[:class]} mceEditor #{column.options[:class]}".strip - settings = column.options[:tinymce] || { theme: 'simple' } + settings = { :theme => 'simple' }.merge(column.options[:tinymce] || {}) settings = settings.to_s.gsub(/:(.+?)\=\>/, '\1:') settings = "tinyMCE.settings = #{settings};" From 6287854748c4dd36b66f40a91323d2bc6140a7b8 Mon Sep 17 00:00:00 2001 From: Ville Lautanala <lautis@gmail.com> Date: Fri, 27 Jan 2012 13:48:34 +0200 Subject: [PATCH 1381/2024] Put images in separate dir to avoid collisions --- .../images/{ => active_scaffold}/add.gif | Bin .../{ => active_scaffold}/arrow_down.gif | Bin .../images/{ => active_scaffold}/arrow_up.gif | Bin .../images/{ => active_scaffold}/close.gif | Bin .../{ => active_scaffold}/close_touch.png | Bin .../images/{ => active_scaffold}/config.png | Bin .../images/{ => active_scaffold}/cross.png | Bin .../images/{ => active_scaffold}/gears.png | Bin .../{ => active_scaffold}/indicator-small.gif | Bin .../{ => active_scaffold}/indicator.gif | Bin .../{ => active_scaffold}/magnifier.png | Bin .../stylesheets/active_scaffold.css.erb | 20 +++++++++--------- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 13 files changed, 11 insertions(+), 11 deletions(-) rename app/assets/images/{ => active_scaffold}/add.gif (100%) rename app/assets/images/{ => active_scaffold}/arrow_down.gif (100%) rename app/assets/images/{ => active_scaffold}/arrow_up.gif (100%) rename app/assets/images/{ => active_scaffold}/close.gif (100%) rename app/assets/images/{ => active_scaffold}/close_touch.png (100%) rename app/assets/images/{ => active_scaffold}/config.png (100%) rename app/assets/images/{ => active_scaffold}/cross.png (100%) rename app/assets/images/{ => active_scaffold}/gears.png (100%) rename app/assets/images/{ => active_scaffold}/indicator-small.gif (100%) rename app/assets/images/{ => active_scaffold}/indicator.gif (100%) rename app/assets/images/{ => active_scaffold}/magnifier.png (100%) diff --git a/app/assets/images/add.gif b/app/assets/images/active_scaffold/add.gif similarity index 100% rename from app/assets/images/add.gif rename to app/assets/images/active_scaffold/add.gif diff --git a/app/assets/images/arrow_down.gif b/app/assets/images/active_scaffold/arrow_down.gif similarity index 100% rename from app/assets/images/arrow_down.gif rename to app/assets/images/active_scaffold/arrow_down.gif diff --git a/app/assets/images/arrow_up.gif b/app/assets/images/active_scaffold/arrow_up.gif similarity index 100% rename from app/assets/images/arrow_up.gif rename to app/assets/images/active_scaffold/arrow_up.gif diff --git a/app/assets/images/close.gif b/app/assets/images/active_scaffold/close.gif similarity index 100% rename from app/assets/images/close.gif rename to app/assets/images/active_scaffold/close.gif diff --git a/app/assets/images/close_touch.png b/app/assets/images/active_scaffold/close_touch.png similarity index 100% rename from app/assets/images/close_touch.png rename to app/assets/images/active_scaffold/close_touch.png diff --git a/app/assets/images/config.png b/app/assets/images/active_scaffold/config.png similarity index 100% rename from app/assets/images/config.png rename to app/assets/images/active_scaffold/config.png diff --git a/app/assets/images/cross.png b/app/assets/images/active_scaffold/cross.png similarity index 100% rename from app/assets/images/cross.png rename to app/assets/images/active_scaffold/cross.png diff --git a/app/assets/images/gears.png b/app/assets/images/active_scaffold/gears.png similarity index 100% rename from app/assets/images/gears.png rename to app/assets/images/active_scaffold/gears.png diff --git a/app/assets/images/indicator-small.gif b/app/assets/images/active_scaffold/indicator-small.gif similarity index 100% rename from app/assets/images/indicator-small.gif rename to app/assets/images/active_scaffold/indicator-small.gif diff --git a/app/assets/images/indicator.gif b/app/assets/images/active_scaffold/indicator.gif similarity index 100% rename from app/assets/images/indicator.gif rename to app/assets/images/active_scaffold/indicator.gif diff --git a/app/assets/images/magnifier.png b/app/assets/images/active_scaffold/magnifier.png similarity index 100% rename from app/assets/images/magnifier.png rename to app/assets/images/active_scaffold/magnifier.png diff --git a/app/assets/stylesheets/active_scaffold.css.erb b/app/assets/stylesheets/active_scaffold.css.erb index d66dfb1aa5..123f3a0c61 100644 --- a/app/assets/stylesheets/active_scaffold.css.erb +++ b/app/assets/stylesheets/active_scaffold.css.erb @@ -176,21 +176,21 @@ background-repeat: no-repeat; } .active-scaffold-header div.actions div.action_group div { - background-image: url(<%= asset_path 'gears.png' %>); /* default icon for actions or override with css */ + background-image: url(<%= asset_path 'active_scaffold/gears.png' %>); /* default icon for actions or override with css */ } .active-scaffold-header div.actions a.show_config_list { - background-image: url(<%= asset_path 'config.png' %>); + background-image: url(<%= asset_path 'active_scaffold/config.png' %>); } .active-scaffold-header div.actions a.new, .active-scaffold-header div.actions a.new_existing { -background-image: url(<%= asset_path 'add.gif' %>); +background-image: url(<%= asset_path 'active_scaffold/add.gif' %>); } .active-scaffold-header div.actions a.show_search { -background-image: url(<%= asset_path 'magnifier.png' %>); +background-image: url(<%= asset_path 'active_scaffold/magnifier.png' %>); } .blue-theme .active-scaffold-header div.actions a:hover { @@ -249,17 +249,17 @@ padding-right: 18px; .active-scaffold th.asc a, .active-scaffold th.asc a:hover { -background: #333 url(<%= asset_path 'arrow_up.gif' %>) right 50% no-repeat; +background: #333 url(<%= asset_path 'active_scaffold/arrow_up.gif' %>) right 50% no-repeat; } .active-scaffold th.desc a, .active-scaffold th.desc a:hover { -background: #333 url(<%= asset_path 'arrow_down.gif' %>) right 50% no-repeat; +background: #333 url(<%= asset_path 'active_scaffold/arrow_down.gif' %>) right 50% no-repeat; } .active-scaffold th.loading a, .active-scaffold th.loading a:hover { -background: #333 url(<%= asset_path 'indicator-small.gif' %>) right 50% no-repeat; +background: #333 url(<%= asset_path 'active_scaffold/indicator-small.gif' %>) right 50% no-repeat; } .active-scaffold th .mark_heading { @@ -442,7 +442,7 @@ float: right; text-indent: -4000px; width: 16px; height: 17px; -background: url(<%= asset_path 'close.gif' %>) 0 0 no-repeat; +background: url(<%= asset_path 'active_scaffold/close.gif' %>) 0 0 no-repeat; } /* Nested @@ -976,7 +976,7 @@ height: 16px; padding: 0; width: 16px; text-indent: -4000px; -background: url(<%= asset_path 'cross.png' %>) 0 0 no-repeat; +background: url(<%= asset_path 'active_scaffold/cross.png' %>) 0 0 no-repeat; } .active-scaffold .sub-form .locked a.destroy { @@ -1021,7 +1021,7 @@ font-size: 100%; .as_touch a.inline-adapter-close { width: 25px; height: 27px; -background: url(<%= asset_path 'close_touch.png' %>) 0 0 no-repeat; +background: url(<%= asset_path 'active_scaffold/close_touch.png' %>) 0 0 no-repeat; } .as_touch .as_paginate { diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 1fc0cc9606..e59acefc47 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -86,7 +86,7 @@ def form_remote_upload_tag(url_for_options = {}, options = {}) # a general-use loading indicator (the "stuff is happening, please wait" feedback) def loading_indicator_tag(options) - image_tag "indicator.gif", :style => "visibility:hidden;", :id => loading_indicator_id(options), :alt => "loading indicator", :class => "loading-indicator" + image_tag "active_scaffold/indicator.gif", :style => "visibility:hidden;", :id => loading_indicator_id(options), :alt => "loading indicator", :class => "loading-indicator" end # Creates a javascript-based link that toggles the visibility of some element on the page. From fb7fffbe82ee16715aaedbec7e57c3b94a147402 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 27 Jan 2012 17:34:13 +0100 Subject: [PATCH 1382/2024] add variables for colors --- .../stylesheets/active_scaffold.css.erb | 299 ++++++++++-------- app/assets/stylesheets/blue-theme.css | 74 +++++ 2 files changed, 233 insertions(+), 140 deletions(-) create mode 100644 app/assets/stylesheets/blue-theme.css diff --git a/app/assets/stylesheets/active_scaffold.css.erb b/app/assets/stylesheets/active_scaffold.css.erb index 123f3a0c61..b107b615b3 100644 --- a/app/assets/stylesheets/active_scaffold.css.erb +++ b/app/assets/stylesheets/active_scaffold.css.erb @@ -7,6 +7,82 @@ For details, see the ActiveScaffold web site: http://www.activescaffold.com/ */ +<% + @disabled_color ||= '#999' + @actions_disabled_color ||= '#666' + @link_color ||= '#06c' + @hover_bg ||= '#ff8' + @header_color ||= '#555' + + @column_header_bg ||= @header_color + @column_header_link_color ||= '#fff' + @column_header_link_hover_bg ||= '#000' + @column_header_link_hover_color ||= '#ff8' + @column_header_color ||= '#eee' + @column_header_sorted_bg ||= '#333' + + @column_bg ||= '#E6F2FF' + @column_even_bg ||= '#fff' + @column_color ||= '#333' + @column_empty_color ||= '#999' + @column_border_color ||= '#C5DBF7' + @column_even_border_color ||= '#ddd' + @column_actions_border_color ||= '#ccc' + + @column_sorted_bg ||= '#B9DCFF' + @column_sorted_border_color ||= '#AFD0F5' + @column_even_sorted_bg ||= '#E6F2FF' + @column_even_sorted_border_color ||= '#AFD0F5' + + @calculations_bg ||= '#eee' + @calculations_border_color ||= '#005CB8' + + @action_group_color ||= '#0066CC' + @action_group_hover_bg ||= '#ff8' + @action_group_border_color ||= '#005CB8' + @action_group_items_bg ||= '#EEE' + @action_group_items_border_color ||= '#222' + @action_group_link_color ||= @column_color + + @nested_bg ||= '#DAFFCD' + @nested_border_color ||= '#7FCF00' + @nested_footer_color ||= '#444' + @nested_column_bg ||= '#ECFFE7' + @nested_column_border_color ||= @column_border_color + + @second_nested_bg ||= '#FFFFBB' + @second_nested_border_color ||= '#DDDF37' + + @third_nested_bg ||= @nested_bg + @third_nested_border_color ||= @nested_border_color + + @pagination_border_color ||= '#ccc' + @msg_color ||= '#333' + @msg_error_bg ||= '#fbb' + @msg_error_border_color ||= '#f66' + @msg_warning_bg ||= '#ffb' + @msg_warning_border_color ||= '#ff6' + @msg_info_bg ||= '#bbf' + @msg_info_border_color ||= '#66f' + @msg_filtered_bg ||= '#e8e8e8' + @msg_filtered_color ||= '#666' + + @form_title_color ||= '#1F7F00' + @label_color ||= @header_color + @description_color ||= '#999' + @placeholder_color ||= '#aaa' + @input_border_color ||= @form_title_color + @input_error_border_color ||= '#f00' + @input_focus_bg ||= '#ffc' + + @draggable_list_bg ||= '#FFFF88' + @draggable_list_selected_bg ||= '#7FCF00' + @checkbox_list_bg ||= '#fff' + + @subform_color ||= '#999' + @subform_header_color ||= @header_color + @subform_footer_color ||= @subform_color +%> .active-scaffold form, .active-scaffold table, @@ -28,16 +104,16 @@ border-collapse: separate; .active-scaffold a, .active-scaffold a:visited { -color: #06c; +color: <%= @link_color %>; text-decoration: none; } .active-scaffold a.disabled { -color: #999; +color: <%= @disabled_color %>; } .active-scaffold a:hover, .active-scaffold div.hover, .active-scaffold td span.hover { -background-color: #ff8; +background-color: <%= @hover_bg %>; } .active-scaffold div.actions a img, @@ -56,12 +132,12 @@ clear: both; } noscript.active-scaffold { -border-left: solid 5px #f66; -background-color: #fbb; +border-left: solid 5px <%= @msg_error_border_color %>; +background-color: <%= @msg_error_bg %>; font-size: 11px; font-weight: bold; padding: 5px 20px 5px 5px; -color: #333; +color: <%= @column_color %>; } .active-scaffold .mark_record_column { @@ -75,22 +151,13 @@ color: #333; position: relative; } -.blue-theme .active-scaffold-header { -background-color: #005CB8; -} - .active-scaffold-header h2 { padding: 2px 0px; margin: 0; -color: #555; +color: <%= @header_color %>; font: bold 160% arial, sans-serif; } -.blue-theme .active-scaffold-header h2 { -color: #fff; -padding: 2px 5px 4px 5px; -} - .active-scaffold-header div.actions a, .active-scaffold-header div.actions { float: right; @@ -139,17 +206,8 @@ top: 14px; float: left; } -.blue-theme .active-scaffold-header div.actions a { -color: #fff; -} - .active-scaffold-header div.actions a.disabled { -color: #666; -opacity: 0.5; -} - -.blue-theme .active-scaffold-header div.actions a.disabled { -color: #fff; +color: <%= @actions_disabled_color %>; opacity: 0.5; } @@ -193,10 +251,6 @@ background-image: url(<%= asset_path 'active_scaffold/add.gif' %>); background-image: url(<%= asset_path 'active_scaffold/magnifier.png' %>); } -.blue-theme .active-scaffold-header div.actions a:hover { -background-color: #378CDF; -} - .active-scaffold-header div.actions a.disabled:hover { background-color: transparent; cursor: default; @@ -213,7 +267,7 @@ text-align: right; ============================= */ .active-scaffold th { -background-color: #555; +background-color: <%= @column_header_bg %>; text-align: left; } @@ -221,26 +275,26 @@ text-align: left; .active-scaffold th p { font: bold 11px arial, sans-serif; display: block; -background-color: #555; +background-color: <%= @column_header_bg %>; } .active-scaffold th a, .active-scaffold th a:visited { -color: #fff; +color: <%= @column_header_link_color %>; padding: 2px 2px 2px 5px; } .active-scaffold th p { -color: #eee; +color: <%= @column_header_color %>; padding: 2px 5px; } .active-scaffold th a:hover { -background-color: #000; -color: #ff8; +background-color: <%= @column_header_link_hover_bg %>; +color: <%= @column_header_link_hover_color %>; } .active-scaffold th.sorted { -background-color: #333; +background-color: <%= @column_header_sorted_bg %>; } .active-scaffold th.sorted a { @@ -249,17 +303,17 @@ padding-right: 18px; .active-scaffold th.asc a, .active-scaffold th.asc a:hover { -background: #333 url(<%= asset_path 'active_scaffold/arrow_up.gif' %>) right 50% no-repeat; +background: <%= @column_header_sorted_bg %> url(<%= asset_path 'active_scaffold/arrow_up.gif' %>) right 50% no-repeat; } .active-scaffold th.desc a, .active-scaffold th.desc a:hover { -background: #333 url(<%= asset_path 'active_scaffold/arrow_down.gif' %>) right 50% no-repeat; +background: <%= @column_header_sorted_bg %> url(<%= asset_path 'active_scaffold/arrow_down.gif' %>) right 50% no-repeat; } .active-scaffold th.loading a, .active-scaffold th.loading a:hover { -background: #333 url(<%= asset_path 'active_scaffold/indicator-small.gif' %>) right 50% no-repeat; +background: <%= @column_header_sorted_bg %> url(<%= asset_path 'active_scaffold/indicator-small.gif' %>) right 50% no-repeat; } .active-scaffold th .mark_heading { @@ -274,15 +328,15 @@ display: none; ============================= */ .active-scaffold tr.record { - background-color: #E6F2FF; + background-color: <%= @column_bg %>; } .active-scaffold tr.record td { padding: 5px 4px; -color: #333; +color: <%= @column_color %>; font-family: Verdana, sans-serif; font-size: 11px; -border-bottom: solid 1px #C5DBF7; -border-left: solid 1px #C5DBF7; +border: solid 1px <%= @column_border_color %>; +border-width: 0 0 1px 1px; } .active-scaffold tr.record td.messages-container { @@ -290,24 +344,24 @@ padding: 0px; } .active-scaffold tr.even-record { -background-color: #fff; +background-color: <%= @column_even_bg %>; } .active-scaffold tr.even-record td { -border-left-color: #ddd; +border-left-color: <%= @column_even_border_color %>; } .active-scaffold tr.record td.sorted { -background-color: #B9DCFF; -border-bottom-color: #AFD0F5; +background-color: <%= @column_sorted_bg %>; +border-bottom-color: <%= @column_sorted_border_color %>; } .active-scaffold tr.even-record td.sorted { -background-color: #E6F2FF; -border-bottom-color: #AFD0F5; +background-color: <%= @column_even_sorted_bg %>; +border-bottom-color: <%= @column_even_sorted_border_color %>; } .active-scaffold tbody.records td.empty { -color: #999; +color: <%= @column_empty_color %>; text-align: center; } @@ -319,7 +373,7 @@ text-align: right; /* Table :: Actions (Edit, Delete) ============================= */ .active-scaffold tr.record td.actions { -border-right: solid 1px #ccc; +border-right: solid 1px <%= @column_actions_border_color %>; padding: 0; min-width: 1%; } @@ -347,22 +401,22 @@ white-space: nowrap; } .active-scaffold tr.record td.actions a.disabled { -color: #666; +color: <%= @actions_disabled_color %>; opacity: 0.5; } .active-scaffold .actions .action_group div:hover { -background-color: #ff8; +background-color: <%= @action_group_hover_bg %>; } .active-scaffold .actions .action_group { position: relative; text-align: left; -color: #0066CC; +color: <%= @action_group_color %>; } .active-scaffold .actions .action_group ul { -border: 2px solid #005CB8; +border: 2px solid <%= @action_group_border_color %>; list-style-type: none; margin: 0; padding: 0; @@ -381,8 +435,8 @@ right: 150px; } .active-scaffold .actions .action_group ul li { -background: none repeat scroll 0 0 #EEE; -border-top: 1px dashed #222; +background: none repeat scroll 0 0 <%= @action_group_items_bg %>; +border-top: 1px dashed <%= @action_group_items_border_color %>; display: block; position: relative; width: auto; @@ -398,7 +452,7 @@ z-index: 2; .active-scaffold .actions .action_group ul li a { display: block; - color: #333; + color: <%= @action_group_link_color %>; margin: 0; padding: 5px 5px 5px 25px; background-position: 5px 50%; @@ -406,7 +460,7 @@ z-index: 2; } .active-scaffold .actions .action_group ul li.top { -border-top: 0px solid #005CB8; +border-top-width: 0px; } .active-scaffold .actions .action_group:hover ul ul, @@ -424,9 +478,9 @@ display: block; ============================= */ .active-scaffold .view { -background-color: #DAFFCD; +background-color: <%= @nested_bg %>; padding: 4px; -border: solid 1px #7FcF00; +border: solid 1px <%= @nested_border_color %>; } .active-scaffold tbody.records td.inline-adapter-cell .view { @@ -448,13 +502,6 @@ background: url(<%= asset_path 'active_scaffold/close.gif' %>) 0 0 no-repeat; /* Nested ======================== */ -.blue-theme .active-scaffold .active-scaffold-header, -.blue-theme .active-scaffold .active-scaffold-footer { -background-color: #1F7F00; - -background: transparent; -} - .active-scaffold .active-scaffold .active-scaffold-header { margin-right: 25px; } @@ -464,9 +511,8 @@ font-size: 12px; font-weight: bold; } -.blue-theme .active-scaffold .active-scaffold-header h2, .active-scaffold .active-scaffold .active-scaffold-footer { -color: #444; +color: <%= @nested_footer_color %>; } .active-scaffold .active-scaffold .active-scaffold-header div.actions { @@ -479,15 +525,6 @@ right: 0px; font: bold 11px verdana, sans-serif; } -.blue-theme .active-scaffold .active-scaffold-header div.actions a, -.blue-theme .active-scaffold .active-scaffold-header div.actions a:visited { -color: #06c; -} - -.blue-theme .active-scaffold .active-scaffold-header div.actions a:hover { -background-color: #ff8; -} - .active-scaffold .active-scaffold .view { background-color: transparent; padding: 0px; @@ -495,22 +532,22 @@ border: none; } .active-scaffold .active-scaffold td { -background-color: #ECFFE7; -border-bottom: solid 1px #CDF7C5; -border-left: solid 1px #CDF7C5; +background-color: <%= @nested_column_bg %>; +border-bottom: solid 1px <%= @nested_column_border_color %>; +border-left: solid 1px <%= @nested_column_border_color %>; } .active-scaffold .active-scaffold td.inline-adapter-cell { -background-color: #FFFFBB; +background-color: <%= @second_nested_bg %>; padding: 4px; -border: solid 1px #DDDF37; +border: solid 1px <%= @second_nested_border_color %>; border-top: none; } .active-scaffold .active-scaffold .active-scaffold td.inline-adapter-cell { -background-color: #DAFFCD; +background-color: <%= @third_nested_bg %>; padding: 4px; -border: solid 1px #7FcF00; +border: solid 1px <%= @third_nested_border_color %>; border-top: none; } @@ -522,8 +559,8 @@ font-size: 11px; ========================== */ .active-scaffold-calculations td { -background-color: #eee; -border-top: 2px solid #005CB8; +background-color: <%= @calculations_bg %>; +border-top: 2px solid <%= @calculations_border_color %>; font: bold 12px arial, sans-serif; } @@ -533,21 +570,12 @@ border-bottom: none; font: bold 12px arial, sans-serif; } -.blue-theme .active-scaffold-footer { -background-color: #005CB8; -color: #ccc; -} - .active-scaffold-footer .active-scaffold-pagination { float: right; white-space: nowrap; margin-right: 5px; } -.blue-theme .active-scaffold-footer .active-scaffold-records { -margin-left: 5px; -} - .active-scaffold-footer a { text-decoration: none; letter-spacing: 0; @@ -556,25 +584,16 @@ margin: 0 -2px; font: bold 12px arial, sans-serif; } -.blue-theme .active-scaffold-footer a, -.blue-theme .active-scaffold-footer a:visited { -color: #fff; -} - -.blue-theme .active-scaffold-footer a:hover { -background-color: #378CDF; -} - .active-scaffold-footer .next { margin-left: 0; padding-left: 5px; -border-left: solid 1px #ccc; +border-left: solid 1px <%= @pagination_border_color %>; } .active-scaffold-footer .previous { margin-right: 0; padding-right: 5px; -border-right: solid 1px #ccc; +border-right: solid 1px <%= @pagination_border_color %>; } /* Messages @@ -588,17 +607,17 @@ border: none; } .active-scaffold .empty-message, .active-scaffold .filtered-message { -background-color: #e8e8e8; +background-color: <%= @msg_filtered_bg %>; padding: 4px; text-align: center; -color: #666; +color: <%= @msg_filtered_color %>; } .active-scaffold .message { font-size: 11px; font-weight: bold; padding: 5px 20px 5px 5px; -color: #333; +color: <%= @msg_color %>; position: relative; margin: 2px 7px; line-height: 12px; @@ -618,27 +637,27 @@ margin: 0; } .active-scaffold .error-message { -border-left: solid 5px #f66; -background-color: #fbb; +border-left: solid 5px <%= @msg_error_border_color %>; +background-color: <%= @msg_error_bg %>; } .active-scaffold .warning-message { -border-left: solid 5px #ff6; -background-color: #ffb; +border-left: solid 5px <%= @msg_warning_border_color %>; +background-color: <%= @msg_warning_bg %>; } .active-scaffold .info-message { -border-left: solid 5px #66f; -background-color: #bbf; +border-left: solid 5px <%= @msg_info_border_color %>; +background-color: <%= @msg_info_bg %>; } /* Error Styling ========================== */ .active-scaffold .errorExplanation { -background-color: #fcc; +background-color: <%= @msg_error_bg %>; margin: 2px 0; -border: solid 1px #f66; +border: solid 1px <%= @msg_error_border_color %>; } .active-scaffold fieldset { @@ -647,12 +666,12 @@ clear: both; .active-scaffold .errorExplanation h2 { padding: 2px 5px; -color: #333; +color: <%= @msg_color %>; font-size: 11px; margin: 0; letter-spacing: 0; font-family: Verdana; -background-color: #f66; +background-color: <%= @msg_error_border_color %>; } .active-scaffold .errorExplanation ul { @@ -704,7 +723,7 @@ width: 12em; float: left; clear: left; font: normal 11px verdana, sans-serif; -color: #555; +color: <%= @label_color %>; line-height: 16px; } @@ -744,7 +763,7 @@ border: none; padding: 2px; margin: 0; text-transform: none; -color: #1F7F00; +color: <%= @form_title_color %>; letter-spacing: -1px; font: bold 16px arial; } @@ -783,7 +802,7 @@ clear: both; .active-scaffold label { font: normal 11px verdana, sans-serif; -color: #555; +color: <%= @label_color %>; } .active-scaffold li.form-element dt { @@ -808,7 +827,7 @@ margin: 0; .active-scaffold .description { display: inline-block; -color: #999; +color: <%= @description_color %>; font-size: 10px; margin-left: 5px; } @@ -820,14 +839,14 @@ font-weight: bold; .active-scaffold label.example { font-size: 11px; font-family: arial; -color: #888; +color: <%= @placeholder_color %>; } .active-scaffold input.text-input, .active-scaffold select { font: bold 16px arial; letter-spacing: -1px; -border: solid 1px #1F7F00; +border: solid 1px <%= @input_border_color %>; } .active-scaffold input.text-input { @@ -840,7 +859,7 @@ padding: 2px; .active-scaffold .field_with_errors textarea, .active-scaffold .fieldWithErrors select, .active-scaffold .field_with_errors select { -border: solid 1px #f00; +border: solid 1px <%= @input_error_border_color %>; } .active-scaffold select { @@ -848,19 +867,19 @@ padding: 1px; } .active-scaffold input.example { -color: #aaa; +color: <%= @placeholder_color %>; } .active-scaffold select:focus, .active-scaffold input.text-input:focus { -background-color: #ffc; +background-color: <%= @input_focus_bg %>; } .active-scaffold textarea { font-family: Arial, sans-serif; font-size: 12px; padding: 1px; -border: solid 1px #1F7F00; +border: solid 1px <%= @input_border_color %>; } .active-scaffold .checkbox-list { @@ -883,7 +902,7 @@ margin-right: 15px; min-height: 30px; max-height: 100px; overflow: auto; -background-color: #FFFF88; +background-color: <%= @draggable_list_bg %>; } .active-scaffold .draggable-list.hover { @@ -891,7 +910,7 @@ opacity: 0.5; } .active-scaffold .draggable-list.selected { -background-color: #7FCF00; +background-color: <%= @draggable_list_selected_bg %>; } .active-scaffold .draggable-list li { @@ -936,7 +955,7 @@ background: none; .active-scaffold .sub-form table th { font: normal 10px verdana, sans-serif; -color: #555; +color: <%= @subform_header_color %>; padding: 0 5px 0 1px; background: none; } @@ -947,8 +966,8 @@ display: none; .active-scaffold .sub-form .checkbox-list { padding: 0 2px 2px 2px; -background-color: #fff; -border: solid 1px #1F7F00; +background-color: <%= @checkbox_list_bg %>; +border: solid 1px <%= @input_border_color %>; } .active-scaffold .sub-form .checkbox-list label { @@ -960,7 +979,7 @@ border: none; background-color: transparent; padding: 1px; vertical-align: top; -color: #999; +color: <%= @subform_color %>; } .active-scaffold .sub-form .actions { @@ -999,7 +1018,7 @@ margin-right: 10px; } .active-scaffold .sub-form .footer { -color: #999; +color: <%= @subform_footer_color %>; padding: 3px 5px; } @@ -1089,7 +1108,7 @@ line-height: 130%; } .as_touch th a, .as_touch th a:visited { -color: #fff; +color: <%= @column_header_link_color %>; padding: 5px 2px 5px 5px; } diff --git a/app/assets/stylesheets/blue-theme.css b/app/assets/stylesheets/blue-theme.css new file mode 100644 index 0000000000..2c65c58c2a --- /dev/null +++ b/app/assets/stylesheets/blue-theme.css @@ -0,0 +1,74 @@ +/* + ActiveScaffold Blue Theme + (c) 2007 Richard White <rrwhite@gmail.com> + + ActiveScaffold is freely distributable under the terms of an MIT-style license. + + For details, see the ActiveScaffold web site: http://www.activescaffold.com/ + +*/ + +/* Header + ======================== */ + +.blue-theme .active-scaffold-header { +background-color: #005CB8; +} + +.blue-theme .active-scaffold-header h2 { +color: #fff; +padding: 2px 5px 4px 5px; +} + +.blue-theme .active-scaffold-header div.actions a { +color: #fff; +} + +.blue-theme .active-scaffold-header div.actions a.disabled { +color: #fff; +opacity: 0.5; +} + +.blue-theme .active-scaffold-header div.actions a:hover { +background-color: #378CDF; +} + +.blue-theme .active-scaffold .active-scaffold-header, +.blue-theme .active-scaffold .active-scaffold-footer { +background-color: #1F7F00; +background: transparent; +} + +.blue-theme .active-scaffold .active-scaffold-header h2 { +color: #444; +} + +.blue-theme .active-scaffold .active-scaffold-header div.actions a, +.blue-theme .active-scaffold .active-scaffold-header div.actions a:visited { +color: #06c; +} + +.blue-theme .active-scaffold .active-scaffold-header div.actions a:hover { +background-color: #ff8; +} + +/* Footer + ========================== */ + +.blue-theme .active-scaffold-footer { +background-color: #005CB8; +color: #ccc; +} + +.blue-theme .active-scaffold-footer .active-scaffold-records { +margin-left: 5px; +} + +.blue-theme .active-scaffold-footer a, +.blue-theme .active-scaffold-footer a:visited { +color: #fff; +} + +.blue-theme .active-scaffold-footer a:hover { +background-color: #378CDF; +} From 463b420050d2ee0d05c526afd0a80308b4373edc Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 27 Jan 2012 17:34:33 +0100 Subject: [PATCH 1383/2024] fix nested for polymorphic associations --- lib/active_scaffold/data_structures/nested_info.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index cea9adf867..eba23c0e4a 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -117,8 +117,12 @@ def iterate_model_associations(model) end if association.foreign_key == current.foreign_key # show columns for has_many and has_one child associationes - constrained_fields << current.name.to_sym if current.belongs_to? - @child_association = current if current.klass == @parent_model + constrained_fields << current.name.to_sym if current.belongs_to? + if association.options[:as] and current.options[:polymorphic] + @child_association = current if association.options[:as].to_sym == current.name + else + @child_association = current if current.klass == @parent_model + end end end end From 1fb6598311db7807b665b356f7113a3b386394df Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 27 Jan 2012 17:38:21 +0100 Subject: [PATCH 1384/2024] It works with rails 3.2! --- active_scaffold.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index a2e5a2cc5a..63d331821d 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -25,6 +25,6 @@ Gem::Specification.new do |s| s.add_development_dependency(%q<bundler>, ["~> 1.0.0"]) s.add_development_dependency(%q<rcov>, [">= 0"]) #s.add_runtime_dependency(%q<render_component_vho>, [">= 0"]) - s.add_runtime_dependency(%q<rails>, ["~> 3.1.0"]) + s.add_runtime_dependency(%q<rails>, [">= 3.1.3"]) end From 10271205e8a819d67386c10b76b161170ccc26da Mon Sep 17 00:00:00 2001 From: Nick Rogers <nick@Nicks-MacBook-Air.local> Date: Sat, 28 Jan 2012 16:55:52 -0500 Subject: [PATCH 1385/2024] Fix jquery javascript asset to play nicely with prototype when utilizing "jQuery.noConflict()". Be consistent with using jQuery instead of $. --- .../javascripts/jquery/active_scaffold.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index fc5dbfc712..fae704bff7 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -275,7 +275,7 @@ jQuery(document).ready(function() { Slight modifications by Elliot Winkler */ -if (typeof($.fn.delayedObserver) === 'undefined') { +if (typeof(jQuery.fn.delayedObserver) === 'undefined') { (function() { var delayedObserverStack = []; var observed; @@ -303,7 +303,7 @@ if (typeof($.fn.delayedObserver) === 'undefined') { ); } - $.fn.extend({ + jQuery.fn.extend({ delayedObserver:function(delay, callback){ $this = jQuery(this); @@ -362,7 +362,7 @@ var ActiveScaffold = { }, reload_if_empty: function(tbody, url) { if (this.records_for(tbody).length == 0) { - $.getScript(url); + jQuery.getScript(url); } }, removeSortClasses: function(scaffold) { @@ -543,7 +543,7 @@ var ActiveScaffold = { process_checkbox_inplace_edit: function(checkbox, options) { var checked = checkbox.is(':checked'); if (checked === true) options['params'] += '&value=1'; - $.ajax({ + jQuery.ajax({ url: options.url, type: "POST", data: options['params'], @@ -638,14 +638,14 @@ var ActiveScaffold = { sortable_options.update = function(event, ui) { var url = controller + '/' + options.action + '?' url += jQuery(this).sortable('serialize',{key: encodeURIComponent(jQuery(this).attr('id') + '[]'), expression:/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/}); - $.post(url.append_params(url_params)); + jQuery.post(url.append_params(url_params)); } } element.sortable(sortable_options); }, record_select_onselect: function(edit_associated_url, active_scaffold_id, id){ - $.ajax({ + jQuery.ajax({ url: edit_associated_url.split('--ID--').join(id), error: function(xhr, textStatus, errorThrown){ ActiveScaffold.report_500_response(active_scaffold_id) @@ -750,13 +750,13 @@ var ActiveScaffold = { if (send_form) { params = as_form.serialize(); - params += '&' + $.param({"source_id": source_id}); + params += '&' + jQuery.param({"source_id": source_id}); } else { params = {value: val}; params.source_id = source_id; } - $.ajax({ + jQuery.ajax({ url: url, data: params, beforeSend: function(event) { @@ -962,7 +962,7 @@ ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ close_previous_adapter: function() { var _this = this; - $.each(this.set.links, function(index, item) { + jQuery.each(this.set.links, function(index, item) { if (item.url != _this.url && item.is_disabled() && item.adapter) { item.enable(); item.adapter.remove(); @@ -1001,7 +1001,7 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ enable: function() { var _this = this; - $.each(this.set.links, function(index, item) { + jQuery.each(this.set.links, function(index, item) { if (item.url != _this.url) return; item.tag.removeClass('disabled'); }); @@ -1009,7 +1009,7 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ disable: function() { var _this = this; - $.each(this.set.links, function(index, item) { + jQuery.each(this.set.links, function(index, item) { if (item.url != _this.url) return; item.tag.addClass('disabled'); }); From aa138a3bff76d9065450124337e65cb3b190b42d Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@entrecables.com> Date: Mon, 30 Jan 2012 13:45:47 +0100 Subject: [PATCH 1386/2024] Update lib/active_scaffold/extensions/active_association_reflection.rb --- .../extensions/active_association_reflection.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/extensions/active_association_reflection.rb b/lib/active_scaffold/extensions/active_association_reflection.rb index d3265e4f28..561ed60e58 100644 --- a/lib/active_scaffold/extensions/active_association_reflection.rb +++ b/lib/active_scaffold/extensions/active_association_reflection.rb @@ -12,11 +12,11 @@ def klass_with_sti(*opts) end end def build_association(*opts, &block) - self.original_build_association_called = true + @original_build_association_called = true # FIXME: remove when 3.1 support is dropped klass_with_sti(*opts).new(*opts, &block) end def create_association(*opts, &block) - self.original_build_association_called = true + @original_build_association_called = true # FIXME: remove when 3.1 support is dropped klass_with_sti(*opts).create(*opts, &block) end end From 2977d43765335c231e74b6d38c14c9c8763d3910 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@entrecables.com> Date: Mon, 30 Jan 2012 13:55:11 +0100 Subject: [PATCH 1387/2024] Fix for rails 3.2, closes #127 --- lib/active_scaffold/extensions/action_view_rendering.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 2588946bd9..f8ed18c81a 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -4,7 +4,11 @@ module ViewPaths def find_all_templates(name, partial = false, locals = {}) prefixes.collect do |prefix| view_paths.collect do |resolver| - temp_args = *args_for_lookup(name, [prefix], partial, locals) + if Rails.version < '3.2.0' + temp_args = *args_for_lookup(name, [prefix], partial, locals) + else + temp_args = *args_for_lookup(name, [prefix], partial, locals, {}) + end temp_args[1] = temp_args[1][0] resolver.find_all(*temp_args) end From 18b96da6eae91f015c7476d775dd0c79a33b3fa6 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@entrecables.com> Date: Mon, 30 Jan 2012 13:55:47 +0100 Subject: [PATCH 1388/2024] Fixme comment --- lib/active_scaffold/extensions/action_view_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index f8ed18c81a..f5ef6fb9dd 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -4,7 +4,7 @@ module ViewPaths def find_all_templates(name, partial = false, locals = {}) prefixes.collect do |prefix| view_paths.collect do |resolver| - if Rails.version < '3.2.0' + if Rails.version < '3.2.0' # FIXME: remove when rails 3.1 support is dropped temp_args = *args_for_lookup(name, [prefix], partial, locals) else temp_args = *args_for_lookup(name, [prefix], partial, locals, {}) From 93e518a0953f4e7c6321a4b086b685b51f3b720b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 31 Jan 2012 11:11:22 +0100 Subject: [PATCH 1389/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 7fff8ea904..7be60bc898 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 18 + PATCH = 19 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From d43c332fcfaace9cea4a6d4685514ec9752cb0c7 Mon Sep 17 00:00:00 2001 From: clst <cs@apl.li> Date: Tue, 31 Jan 2012 13:43:48 +0100 Subject: [PATCH 1390/2024] fixed a typo in the German translation --- config/locales/de.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index cfeffb1036..42c51d5e5f 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -10,7 +10,7 @@ de: cancel: 'Abbrechen' click_to_edit: 'Zum Editieren anklicken' click_to_reset: 'Reset' - close: 'Schliessen' + close: 'Schließen' config_list: 'Konfigurieren' config_list_model: 'Konfiguriere Spalten für %{model}' create: 'Anlegen' From 686f43c1fbd76224be9b32505ecde6d553a0d26d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 1 Feb 2012 14:19:58 +0100 Subject: [PATCH 1391/2024] put colors in a new asset file, and support sass variables to override the color scheme --- .../stylesheets/active_scaffold.css.erb | 1116 +---------------- .../stylesheets/active_scaffold_colors.css | 244 ++++ .../stylesheets/active_scaffold_colors.scss | 391 ++++++ .../active_scaffold_default.css.erb | 47 + .../stylesheets/active_scaffold_layout.css | 912 ++++++++++++++ 5 files changed, 1597 insertions(+), 1113 deletions(-) create mode 100644 app/assets/stylesheets/active_scaffold_colors.css create mode 100644 app/assets/stylesheets/active_scaffold_colors.scss create mode 100644 app/assets/stylesheets/active_scaffold_default.css.erb create mode 100644 app/assets/stylesheets/active_scaffold_layout.css diff --git a/app/assets/stylesheets/active_scaffold.css.erb b/app/assets/stylesheets/active_scaffold.css.erb index b107b615b3..2c8a167a85 100644 --- a/app/assets/stylesheets/active_scaffold.css.erb +++ b/app/assets/stylesheets/active_scaffold.css.erb @@ -5,1117 +5,7 @@ ActiveScaffold is freely distributable under the terms of an MIT-style license. For details, see the ActiveScaffold web site: http://www.activescaffold.com/ - + *= require active_scaffold_layout + *= require active_scaffold_default */ -<% - @disabled_color ||= '#999' - @actions_disabled_color ||= '#666' - @link_color ||= '#06c' - @hover_bg ||= '#ff8' - @header_color ||= '#555' - - @column_header_bg ||= @header_color - @column_header_link_color ||= '#fff' - @column_header_link_hover_bg ||= '#000' - @column_header_link_hover_color ||= '#ff8' - @column_header_color ||= '#eee' - @column_header_sorted_bg ||= '#333' - - @column_bg ||= '#E6F2FF' - @column_even_bg ||= '#fff' - @column_color ||= '#333' - @column_empty_color ||= '#999' - @column_border_color ||= '#C5DBF7' - @column_even_border_color ||= '#ddd' - @column_actions_border_color ||= '#ccc' - - @column_sorted_bg ||= '#B9DCFF' - @column_sorted_border_color ||= '#AFD0F5' - @column_even_sorted_bg ||= '#E6F2FF' - @column_even_sorted_border_color ||= '#AFD0F5' - - @calculations_bg ||= '#eee' - @calculations_border_color ||= '#005CB8' - - @action_group_color ||= '#0066CC' - @action_group_hover_bg ||= '#ff8' - @action_group_border_color ||= '#005CB8' - @action_group_items_bg ||= '#EEE' - @action_group_items_border_color ||= '#222' - @action_group_link_color ||= @column_color - - @nested_bg ||= '#DAFFCD' - @nested_border_color ||= '#7FCF00' - @nested_footer_color ||= '#444' - @nested_column_bg ||= '#ECFFE7' - @nested_column_border_color ||= @column_border_color - - @second_nested_bg ||= '#FFFFBB' - @second_nested_border_color ||= '#DDDF37' - - @third_nested_bg ||= @nested_bg - @third_nested_border_color ||= @nested_border_color - - @pagination_border_color ||= '#ccc' - @msg_color ||= '#333' - @msg_error_bg ||= '#fbb' - @msg_error_border_color ||= '#f66' - @msg_warning_bg ||= '#ffb' - @msg_warning_border_color ||= '#ff6' - @msg_info_bg ||= '#bbf' - @msg_info_border_color ||= '#66f' - @msg_filtered_bg ||= '#e8e8e8' - @msg_filtered_color ||= '#666' - - @form_title_color ||= '#1F7F00' - @label_color ||= @header_color - @description_color ||= '#999' - @placeholder_color ||= '#aaa' - @input_border_color ||= @form_title_color - @input_error_border_color ||= '#f00' - @input_focus_bg ||= '#ffc' - - @draggable_list_bg ||= '#FFFF88' - @draggable_list_selected_bg ||= '#7FCF00' - @checkbox_list_bg ||= '#fff' - - @subform_color ||= '#999' - @subform_header_color ||= @header_color - @subform_footer_color ||= @subform_color -%> - -.active-scaffold form, -.active-scaffold table, -.active-scaffold p, -.active-scaffold div, -.active-scaffold fieldset { -margin: 0; -padding: 0; -} - -.active-scaffold { -margin: 5px 0; -} - -.active-scaffold table { -width: 100%; -border-collapse: separate; -} - -.active-scaffold a, -.active-scaffold a:visited { -color: <%= @link_color %>; -text-decoration: none; -} - -.active-scaffold a.disabled { -color: <%= @disabled_color %>; -} - -.active-scaffold a:hover, .active-scaffold div.hover, .active-scaffold td span.hover { -background-color: <%= @hover_bg %>; -} - -.active-scaffold div.actions a img, -.active-scaffold td.actions a img { -border: none; -vertical-align: middle; -} - -.active-scaffold div.actions a.disabled img, -.active-scaffold td.actions a.disabled img { -opacity: 0.5; -} - -.active-scaffold .clear-fix { -clear: both; -} - -noscript.active-scaffold { -border-left: solid 5px <%= @msg_error_border_color %>; -background-color: <%= @msg_error_bg %>; -font-size: 11px; -font-weight: bold; -padding: 5px 20px 5px 5px; -color: <%= @column_color %>; -} - -.active-scaffold .mark_record_column { - width: 1px; -} - -/* Header - ======================== */ - -.active-scaffold-header { -position: relative; -} - -.active-scaffold-header h2 { -padding: 2px 0px; -margin: 0; -color: <%= @header_color %>; -font: bold 160% arial, sans-serif; -} - -.active-scaffold-header div.actions a, -.active-scaffold-header div.actions { -float: right; -font: bold 14px arial; -letter-spacing: -1px; -text-decoration: none; -padding: 1px 2px; -white-space: nowrap; -margin-left: 5px; -background-position: 1px 50%; -background-repeat: no-repeat; -} - -.active-scaffold-header div.actions a { -padding: 5px 5px; -margin-left: 0px; -} - -.active-scaffold .active-scaffold .active-scaffold-header div.actions > a { -padding: 1px 5px; -} - -.active-scaffold-header div.actions div.action_group { -display: inline; -float: right; -} - -.active-scaffold-header div.actions div.action_group li a, -.active-scaffold-header div.actions div.action_group li div { -float: none; -margin: 0; -} - -.active-scaffold-header div.actions .action_group ul { -line-height: 130%; -top: 19px; -} - -.active-scaffold .active-scaffold .active-scaffold-header div.actions .action_group ul { -top: 14px; -} - -.view .active-scaffold-header div.actions a, -.view .active-scaffold-header div.actions div, -.view .active-scaffold-header div.actions div.action_group { -float: left; -} - -.active-scaffold-header div.actions a.disabled { -color: <%= @actions_disabled_color %>; -opacity: 0.5; -} - -.active-scaffold-header div.actions a.new, -.active-scaffold-header div.actions a.new_existing, -.active-scaffold-header div.actions a.show_search, -.active-scaffold-header div.actions a.show_config_list, -.active-scaffold-header div.actions div.action_group div { -margin:0; -padding: 5px 5px 5px 25px; -background-position: 5px 50%; -background-repeat: no-repeat; -} - -.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.new, -.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.new_existing, -.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.show_search, -.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.show_config_list, -.active-scaffold .active-scaffold .active-scaffold-header div.actions div.action_group > div { -margin:0; -padding: 1px 5px 1px 20px; -background-position: 1px 50%; -background-repeat: no-repeat; -} - -.active-scaffold-header div.actions div.action_group div { - background-image: url(<%= asset_path 'active_scaffold/gears.png' %>); /* default icon for actions or override with css */ -} - -.active-scaffold-header div.actions a.show_config_list { - background-image: url(<%= asset_path 'active_scaffold/config.png' %>); -} - -.active-scaffold-header div.actions a.new, -.active-scaffold-header div.actions a.new_existing { -background-image: url(<%= asset_path 'active_scaffold/add.gif' %>); -} - -.active-scaffold-header div.actions a.show_search { - -background-image: url(<%= asset_path 'active_scaffold/magnifier.png' %>); -} - -.active-scaffold-header div.actions a.disabled:hover { -background-color: transparent; -cursor: default; -} - -.active-scaffold-header div.actions { -position: absolute; -right: 5px; -top: 5px; -text-align: right; -} - -/* Table :: Column Headers - ============================= */ - -.active-scaffold th { -background-color: <%= @column_header_bg %>; -text-align: left; -} - -.active-scaffold th a, -.active-scaffold th p { -font: bold 11px arial, sans-serif; -display: block; -background-color: <%= @column_header_bg %>; -} - -.active-scaffold th a, .active-scaffold th a:visited { -color: <%= @column_header_link_color %>; -padding: 2px 2px 2px 5px; -} - -.active-scaffold th p { -color: <%= @column_header_color %>; -padding: 2px 5px; -} - -.active-scaffold th a:hover { -background-color: <%= @column_header_link_hover_bg %>; -color: <%= @column_header_link_hover_color %>; -} - -.active-scaffold th.sorted { -background-color: <%= @column_header_sorted_bg %>; -} - -.active-scaffold th.sorted a { -padding-right: 18px; -} - -.active-scaffold th.asc a, -.active-scaffold th.asc a:hover { -background: <%= @column_header_sorted_bg %> url(<%= asset_path 'active_scaffold/arrow_up.gif' %>) right 50% no-repeat; -} - -.active-scaffold th.desc a, -.active-scaffold th.desc a:hover { -background: <%= @column_header_sorted_bg %> url(<%= asset_path 'active_scaffold/arrow_down.gif' %>) right 50% no-repeat; -} - -.active-scaffold th.loading a, -.active-scaffold th.loading a:hover { -background: <%= @column_header_sorted_bg %> url(<%= asset_path 'active_scaffold/indicator-small.gif' %>) right 50% no-repeat; -} - -.active-scaffold th .mark_heading { -margin-left: 5px; -} - -.active-scaffold th.hidden, .active-scaffold td.hidden { -display: none; -} - -/* Table :: Record Rows - ============================= */ - -.active-scaffold tr.record { - background-color: <%= @column_bg %>; -} -.active-scaffold tr.record td { -padding: 5px 4px; -color: <%= @column_color %>; -font-family: Verdana, sans-serif; -font-size: 11px; -border: solid 1px <%= @column_border_color %>; -border-width: 0 0 1px 1px; -} - -.active-scaffold tr.record td.messages-container { -padding: 0px; -} - -.active-scaffold tr.even-record { -background-color: <%= @column_even_bg %>; -} -.active-scaffold tr.even-record td { -border-left-color: <%= @column_even_border_color %>; -} - -.active-scaffold tr.record td.sorted { -background-color: <%= @column_sorted_bg %>; -border-bottom-color: <%= @column_sorted_border_color %>; -} - -.active-scaffold tr.even-record td.sorted { -background-color: <%= @column_even_sorted_bg %>; -border-bottom-color: <%= @column_even_sorted_border_color %>; -} - -.active-scaffold tbody.records td.empty { -color: <%= @column_empty_color %>; -text-align: center; -} - -.active-scaffold td.numeric, -.active-scaffold-calculations td { -text-align: right; -} - -/* Table :: Actions (Edit, Delete) - ============================= */ -.active-scaffold tr.record td.actions { -border-right: solid 1px <%= @column_actions_border_color %>; -padding: 0; -min-width: 1%; -} - -.active-scaffold tr.record td.actions table { -float: right; -width: auto; -margin-right: 5px; -} - -.active-scaffold tr.record td.actions table td { -border: none; -text-align: right; -padding: 0 2px; -} - -.active-scaffold tr.record td.actions a, -.active-scaffold tr.record td.actions div { -font: bold 11px verdana, sans-serif; -letter-spacing: -1px; -padding: 2px; -margin: 0 2px; -line-height: 16px; -white-space: nowrap; -} - -.active-scaffold tr.record td.actions a.disabled { -color: <%= @actions_disabled_color %>; -opacity: 0.5; -} - -.active-scaffold .actions .action_group div:hover { -background-color: <%= @action_group_hover_bg %>; -} - -.active-scaffold .actions .action_group { -position: relative; -text-align: left; -color: <%= @action_group_color %>; -} - -.active-scaffold .actions .action_group ul { -border: 2px solid <%= @action_group_border_color %>; -list-style-type: none; -margin: 0; -padding: 0; -position: absolute; -line-height: 200%; -display: none; -width: 150px; -right: 0px; -} - -.active-scaffold .actions .action_group ul ul { -display: none; -position: absolute; -top: 0; -right: 150px; -} - -.active-scaffold .actions .action_group ul li { -background: none repeat scroll 0 0 <%= @action_group_items_bg %>; -border-top: 1px dashed <%= @action_group_items_border_color %>; -display: block; -position: relative; -width: auto; -z-index: 2; -} - -.active-scaffold .actions .action_group ul li div { - margin: 0; - padding: 5px 5px 5px 25px; - background-position: 5px 50%; - background-repeat: no-repeat; -} - -.active-scaffold .actions .action_group ul li a { - display: block; - color: <%= @action_group_link_color %>; - margin: 0; - padding: 5px 5px 5px 25px; - background-position: 5px 50%; - background-repeat: no-repeat; -} - -.active-scaffold .actions .action_group ul li.top { -border-top-width: 0px; -} - -.active-scaffold .actions .action_group:hover ul ul, -.active-scaffold .actions .action_group:hover ul ul ul { -display: none; -} - -.active-scaffold .actions .action_group:hover ul, -.active-scaffold .actions .action_group ul li:hover > ul, -.active-scaffold .actions .action_group ul ul li:hover ul { -display: block; -} - -/* Table :: Inline Adapter - ============================= */ - -.active-scaffold .view { -background-color: <%= @nested_bg %>; -padding: 4px; -border: solid 1px <%= @nested_border_color %>; -} - -.active-scaffold tbody.records td.inline-adapter-cell .view { -border-top: none; -} - -.active-scaffold .before-header td.inline-adapter-cell .view { -border-bottom: none; -} - -.active-scaffold a.inline-adapter-close { -float: right; -text-indent: -4000px; -width: 16px; -height: 17px; -background: url(<%= asset_path 'active_scaffold/close.gif' %>) 0 0 no-repeat; -} - -/* Nested - ======================== */ - -.active-scaffold .active-scaffold .active-scaffold-header { -margin-right: 25px; -} - -.active-scaffold .active-scaffold .active-scaffold-header h2 { -font-size: 12px; -font-weight: bold; -} - -.active-scaffold .active-scaffold .active-scaffold-footer { -color: <%= @nested_footer_color %>; -} - -.active-scaffold .active-scaffold .active-scaffold-header div.actions { -top: 0px; -right: 0px; -} - -.active-scaffold .active-scaffold .active-scaffold-header div.actions a, -.active-scaffold .active-scaffold .active-scaffold-header div.actions div { -font: bold 11px verdana, sans-serif; -} - -.active-scaffold .active-scaffold .view { -background-color: transparent; -padding: 0px; -border: none; -} - -.active-scaffold .active-scaffold td { -background-color: <%= @nested_column_bg %>; -border-bottom: solid 1px <%= @nested_column_border_color %>; -border-left: solid 1px <%= @nested_column_border_color %>; -} - -.active-scaffold .active-scaffold td.inline-adapter-cell { -background-color: <%= @second_nested_bg %>; -padding: 4px; -border: solid 1px <%= @second_nested_border_color %>; -border-top: none; -} - -.active-scaffold .active-scaffold .active-scaffold td.inline-adapter-cell { -background-color: <%= @third_nested_bg %>; -padding: 4px; -border: solid 1px <%= @third_nested_border_color %>; -border-top: none; -} - -.active-scaffold .active-scaffold .active-scaffold-footer { -font-size: 11px; -} - -/* Footer - ========================== */ - -.active-scaffold-calculations td { -background-color: <%= @calculations_bg %>; -border-top: 2px solid <%= @calculations_border_color %>; -font: bold 12px arial, sans-serif; -} - -.active-scaffold .active-scaffold-footer { -padding: 3px 0px 2px 0px; -border-bottom: none; -font: bold 12px arial, sans-serif; -} - -.active-scaffold-footer .active-scaffold-pagination { -float: right; -white-space: nowrap; -margin-right: 5px; -} - -.active-scaffold-footer a { -text-decoration: none; -letter-spacing: 0; -padding: 0 2px; -margin: 0 -2px; -font: bold 12px arial, sans-serif; -} - -.active-scaffold-footer .next { -margin-left: 0; -padding-left: 5px; -border-left: solid 1px <%= @pagination_border_color %>; -} - -.active-scaffold-footer .previous { -margin-right: 0; -padding-right: 5px; -border-right: solid 1px <%= @pagination_border_color %>; -} - -/* Messages - ========================= */ - -.active-scaffold .messages-container, -.active-scaffold .active-scaffold .messages-container{ -padding: 0; -margin: 0 7px; -border: none; -} - -.active-scaffold .empty-message, .active-scaffold .filtered-message { -background-color: <%= @msg_filtered_bg %>; -padding: 4px; -text-align: center; -color: <%= @msg_filtered_color %>; -} - -.active-scaffold .message { -font-size: 11px; -font-weight: bold; -padding: 5px 20px 5px 5px; -color: <%= @msg_color %>; -position: relative; -margin: 2px 7px; -line-height: 12px; -} - -.active-scaffold .message a { -position: absolute; -right: 10px; -top: 4px; -padding: 0; -font: bold 11px verdana, sans-serif; -letter-spacing: -1px; -} - -.active-scaffold .messages-container .message { -margin: 0; -} - -.active-scaffold .error-message { -border-left: solid 5px <%= @msg_error_border_color %>; -background-color: <%= @msg_error_bg %>; -} - -.active-scaffold .warning-message { -border-left: solid 5px <%= @msg_warning_border_color %>; -background-color: <%= @msg_warning_bg %>; -} - -.active-scaffold .info-message { -border-left: solid 5px <%= @msg_info_border_color %>; -background-color: <%= @msg_info_bg %>; -} - -/* Error Styling - ========================== */ - -.active-scaffold .errorExplanation { -background-color: <%= @msg_error_bg %>; -margin: 2px 0; -border: solid 1px <%= @msg_error_border_color %>; -} - -.active-scaffold fieldset { -clear: both; -} - -.active-scaffold .errorExplanation h2 { -padding: 2px 5px; -color: <%= @msg_color %>; -font-size: 11px; -margin: 0; -letter-spacing: 0; -font-family: Verdana; -background-color: <%= @msg_error_border_color %>; -} - -.active-scaffold .errorExplanation ul { -margin: 0; -padding: 0 2px 4px 25px; -list-style: disc; -} - -.active-scaffold .errorExplanation p { -font-size: 11px; -padding: 2px 5px; -font-family: Verdana; -margin: 0; -} - -.active-scaffold .errorExplanation ul li { -font: bold 11px verdana; -letter-spacing: -1px; -margin: 0; -padding: 0; -background-color: transparent; -} - -/* Loading Indicators - ============================== */ - -.active-scaffold .loading-indicator { -vertical-align: text-bottom; -width: 16px; -margin: 0; -} - -.active-scaffold .active-scaffold-header .loading-indicator { -margin-top: 3px; -} - -/* Show - ============================= */ - -.active-scaffold .show-view dl { -margin-left: 5px; -} -.active-scaffold .show-view dl dl { -margin-left: 0px; -} - -.active-scaffold .show-view dt { -width: 12em; -float: left; -clear: left; -font: normal 11px verdana, sans-serif; -color: <%= @label_color %>; -line-height: 16px; -} - -.active-scaffold .show-view dd { -float: left; -font: bold 14px arial; -padding-left: 5px; -margin-bottom: 5px; -} - -/* Form - ============================== */ - -.active-scaffold dl { -margin: 0; -} - -.active-scaffold .submit { -font-weight: bold; -font-size: 14px; -font-family: Arial, sans-serif; -letter-spacing: 0; -margin: 0; -margin-top: 5px; -} - -.active-scaffold form p { -clear: both; -} - -.active-scaffold fieldset { -border: none; -} - -.active-scaffold h4, -.active-scaffold h5 { -padding: 2px; -margin: 0; -text-transform: none; -color: <%= @form_title_color %>; -letter-spacing: -1px; -font: bold 16px arial; -} - -.active-scaffold h5 { -padding: 0; -margin: 5px 0 2px 0; -font-size: 14px; -letter-spacing: 0; -} - -.active-scaffold ol { -clear: both; -float: none; -padding: 2px; -margin-left: 5px; -list-style: none; -} - -.active-scaffold p.form-footer { -clear: both; -} - -.active-scaffold a.as_cancel, -.active-scaffold p.form-footer a { -font: bold 14px arial, sans-serif; -letter-spacing: 0; -} - -/* Form :: Fields - ============================== */ - -.active-scaffold li.form-element { -clear: both; -} - -.active-scaffold label { -font: normal 11px verdana, sans-serif; -color: <%= @label_color %>; -} - -.active-scaffold li.form-element dt { -float: left; -width: 12em; -padding: 6px 0; -} - -.active-scaffold li.form-element dd { -float: left; -} - -.active-scaffold li.form-element dd p, -.active-scaffold li.form-element dd input[type="checkbox"] { -margin-top: 6px; -} - -.active-scaffold .form dd { -margin: 0; -} - - -.active-scaffold .description { -display: inline-block; -color: <%= @description_color %>; -font-size: 10px; -margin-left: 5px; -} - -.active-scaffold .required label { -font-weight: bold; -} - -.active-scaffold label.example { -font-size: 11px; -font-family: arial; -color: <%= @placeholder_color %>; -} - -.active-scaffold input.text-input, -.active-scaffold select { -font: bold 16px arial; -letter-spacing: -1px; -border: solid 1px <%= @input_border_color %>; -} - -.active-scaffold input.text-input { -padding: 2px; -} - -.active-scaffold .fieldWithErrors input, -.active-scaffold .field_with_errors input, -.active-scaffold .fieldWithErrors textarea, -.active-scaffold .field_with_errors textarea, -.active-scaffold .fieldWithErrors select, -.active-scaffold .field_with_errors select { -border: solid 1px <%= @input_error_border_color %>; -} - -.active-scaffold select { -padding: 1px; -} - -.active-scaffold input.example { -color: <%= @placeholder_color %>; -} - -.active-scaffold select:focus, -.active-scaffold input.text-input:focus { -background-color: <%= @input_focus_bg %>; -} - -.active-scaffold textarea { -font-family: Arial, sans-serif; -font-size: 12px; -padding: 1px; -border: solid 1px <%= @input_border_color %>; -} - -.active-scaffold .checkbox-list { -padding-left: 0px; -} - -.active-scaffold .checkbox-list li { -padding-right: 5px; -display: inline; -} - -.active-scaffold .checkbox-list li label { -padding: 0 0 0 2px; -} - -.active-scaffold .draggable-list { -float: left; -width: 300px; -margin-right: 15px; -min-height: 30px; -max-height: 100px; -overflow: auto; -background-color: <%= @draggable_list_bg %>; -} - -.active-scaffold .draggable-list.hover { -opacity: 0.5; -} - -.active-scaffold .draggable-list.selected { -background-color: <%= @draggable_list_selected_bg %>; -} - -.active-scaffold .draggable-list li { -display: block; -} - -li.draggable-item { - list-style: none; -} -li.draggable-item input, -.active-scaffold .draggable-list input { -display: none; -} - -/* Form :: Sub-Sections - ============================== */ - -.active-scaffold li.sub-section { -clear: left; -padding: 5px 0; -} - -/* Form :: Association Sub-Forms - ============================== */ - -.active-scaffold .sub-form { -float: left; -clear: left; -padding: 5px 0; -padding-left: 5px; -} - -.active-scaffold .sub-form h5 { -margin-left: -5px; -} - -.active-scaffold .sub-form table, -.active-scaffold .sub-form table td { -width: auto; -background: none; -} - -.active-scaffold .sub-form table th { -font: normal 10px verdana, sans-serif; -color: <%= @subform_header_color %>; -padding: 0 5px 0 1px; -background: none; -} - -.active-scaffold .horizontal-sub-form td dt label { -display: none; -} - -.active-scaffold .sub-form .checkbox-list { -padding: 0 2px 2px 2px; -background-color: <%= @checkbox_list_bg %>; -border: solid 1px <%= @input_border_color %>; -} - -.active-scaffold .sub-form .checkbox-list label { -display: block; -} - -.active-scaffold .sub-form table td { -border: none; -background-color: transparent; -padding: 1px; -vertical-align: top; -color: <%= @subform_color %>; -} - -.active-scaffold .sub-form .actions { -vertical-align: middle; -background-color: transparent; -clear: left; -} - -.active-scaffold .sub-form .association-record a.destroy { -font-weight: bold; -display: block; -height: 16px; -padding: 0; -width: 16px; -text-indent: -4000px; -background: url(<%= asset_path 'active_scaffold/cross.png' %>) 0 0 no-repeat; -} - -.active-scaffold .sub-form .locked a.destroy { -display: none; -} - -.active-scaffold .sub-form .association-record a { -font: bold 12px arial; -} - -.active-scaffold .sub-form input.text-input, -.active-scaffold .sub-form select { -letter-spacing: 0; -font: bold 12px arial; -} - -.active-scaffold .sub-form .footer-wrapper { -margin-top: 3px; -margin-right: 10px; -} - -.active-scaffold .sub-form .footer { -color: <%= @subform_footer_color %>; -padding: 3px 5px; -} - -.active-scaffold .sub-form .footer select, -.active-scaffold .sub-form .footer input { -font-weight: bold; -font-size: 12px; -padding: 0; -} - -.active-scaffold a.visibility-toggle { -font-size: 100%; -} - -.active-scaffold-found { - float:left; -} - -.as_touch a.inline-adapter-close { -width: 25px; -height: 27px; -background: url(<%= asset_path 'active_scaffold/close_touch.png' %>) 0 0 no-repeat; -} - -.as_touch .as_paginate { -font-size: 20px; -padding: 3px 10px; -} - -.as_touch .active-scaffold-header div.actions a { -padding: 7px 5px; -} - -.as_touch .active-scaffold .active-scaffold-header div.actions a { -padding: 7px 5px; -} - -.as_touch .active-scaffold-header div.actions .action_group ul { -line-height: 130%; -top: 23px; -} - -.as_touch .active-scaffold .active-scaffold-header div.actions .action_group ul { -top: 23px; -} - -.as_touch .active-scaffold-header div.actions a.new, -.as_touch .active-scaffold-header div.actions a.new_existing, -.as_touch .active-scaffold-header div.actions a.show_search, -.as_touch .active-scaffold-header div.actions a.show_config_list, -.as_touch .active-scaffold-header div.actions div.action_group div { -padding: 7px 5px 7px 25px; -} - -.as_touch .active-scaffold .active-scaffold-header div.actions > a.new, -.as_touch .active-scaffold .active-scaffold-header div.actions > a.new_existing, -.as_touch .active-scaffold .active-scaffold-header div.actions > a.show_search, -.as_touch .active-scaffold .active-scaffold-header div.actions > a.show_config_list, -.as_touch .active-scaffold .active-scaffold-header div.actions div.action_group > div { -padding: 7px 5px 7px 25px; -background-position: 5px 50%; -} - -.as_touch .actions .action_group ul li div { -padding: 7px 5px 7px 25px; -} - -.as_touch .actions .action_group ul li a { -padding: 7px 5px 7px 25px; -} - -.as_touch .active-scaffold-header h2 { -padding: 4px 0px; -} - -.as_touch .active-scaffold .active-scaffold-header div.actions a, -.as_touch .active-scaffold .active-scaffold-header div.actions div { - font: bold 14px arial; -} - -.as_touch .active-scaffold .active-scaffold-header div.actions { - right: 15px; -} - -.as_touch tr.record { -line-height: 130%; -} - -.as_touch th a, .as_touch th a:visited { -color: <%= @column_header_link_color %>; -padding: 5px 2px 5px 5px; -} - -.as_touch tr.record td { -padding: 5px 10px; -} - -<% require_asset "jquery-ui" %> -<% ActiveScaffold.stylesheets.each {|css| require_asset css} %> -<% ActiveScaffold::Bridges.all_stylesheets.each {|css| require_asset css} %> +@import 'active_scaffold_colors<%= '.css' unless defined? Sass %>'; diff --git a/app/assets/stylesheets/active_scaffold_colors.css b/app/assets/stylesheets/active_scaffold_colors.css new file mode 100644 index 0000000000..faacf2f805 --- /dev/null +++ b/app/assets/stylesheets/active_scaffold_colors.css @@ -0,0 +1,244 @@ +/* + ActiveScaffold + (c) 2007 Richard White <rrwhite@gmail.com> + + ActiveScaffold is freely distributable under the terms of an MIT-style license. + + For details, see the ActiveScaffold web site: http://www.activescaffold.com/ + +*/ +.active-scaffold a.disabled { + color: #999999; } + +.active-scaffold a:hover, .active-scaffold div.hover, .active-scaffold td span.hover { + background-color: #ffff88; } + +noscript.active-scaffold { + border-color: #ff6666; + background-color: #ffbbbb; + color: #333333; } + +/* Header + ======================== */ +.active-scaffold-header h2 { + color: #555555; } + +.active-scaffold-header div.actions a.disabled { + color: #666666; } + +/* Table :: Column Headers + ============================= */ +.active-scaffold th { + background-color: #555555; } + +.active-scaffold th a, +.active-scaffold th p { + background-color: #555555; } + +.active-scaffold th a, .active-scaffold th a:visited { + color: white; } + +.active-scaffold th p { + color: #eeeeee; } + +.active-scaffold th a:hover { + background-color: black; + color: #ffff88; } + +.active-scaffold th.sorted { + background-color: #333333; } + +.active-scaffold th.asc a, +.active-scaffold th.asc a:hover, +.active-scaffold th.desc a, +.active-scaffold th.desc a:hover, +.active-scaffold th.loading a, +.active-scaffold th.loading a:hover { + background-color: #333333; } + +/* Table :: Record Rows + ============================= */ +.active-scaffold tr.record { + background-color: #e6f2ff; } + +.active-scaffold tr.record td { + color: #333333; + border-color: #c5dbf7; } + +.active-scaffold tr.even-record { + background-color: white; } + +.active-scaffold tr.even-record td { + border-left-color: #dddddd; } + +.active-scaffold tr.record td.sorted { + background-color: #b9dcff; + border-bottom-color: #afd0f5; } + +.active-scaffold tr.even-record td.sorted { + background-color: #e6f2ff; + border-bottom-color: #afd0f5; } + +.active-scaffold tbody.records td.empty { + color: #999999; } + +/* Table :: Actions (Edit, Delete) + ============================= */ +.active-scaffold tr.record td.actions { + border-color: #cccccc; } + +.active-scaffold tr.record td.actions a.disabled { + color: #666666; } + +.active-scaffold .actions .action_group div:hover { + background-color: #ffff88; } + +.active-scaffold .actions .action_group { + color: #0066cc; } + +.active-scaffold .actions .action_group ul { + border-color: #005cb8; } + +.active-scaffold .actions .action_group ul li { + background-color: #eeeeee; + border-color: #222222; } + +.active-scaffold .actions .action_group ul li a { + color: #333333; } + +/* Table :: Inline Adapter + ============================= */ +.active-scaffold .view { + background-color: #daffcd; + border-color: #7fcf00; } + +/* Nested + ======================== */ +.active-scaffold .active-scaffold .active-scaffold-footer { + color: #444444; } + +.active-scaffold .active-scaffold td { + background-color: #ecffe7; + border-color: #c5dbf7; } + +.active-scaffold .active-scaffold td.inline-adapter-cell { + background-color: #ffffbb; + border-color: #dddf37; } + +.active-scaffold .active-scaffold .active-scaffold td.inline-adapter-cell { + background-color: #daffcd; + border-color: #7fcf00; } + +/* Footer + ========================== */ +.active-scaffold-calculations td { + background-color: #eeeeee; + border-color: #005cb8; } + +.active-scaffold-footer .next { + border-color: #cccccc; } + +.active-scaffold-footer .previous { + border-color: #cccccc; } + +/* Messages + ========================= */ +.active-scaffold .empty-message, .active-scaffold .filtered-message { + background-color: #e8e8e8; + color: #666666; } + +.active-scaffold .message { + color: #333333; } + +.active-scaffold .error-message { + border-color: #ff6666; + background-color: #ffbbbb; } + +.active-scaffold .warning-message { + border-color: #ffff66; + background-color: #ffffbb; } + +.active-scaffold .info-message { + border-color: #6666ff; + background-color: #bbbbff; } + +/* Error Styling + ========================== */ +.active-scaffold .errorExplanation { + background-color: #ffbbbb; + border-color: #ff6666; } + +.active-scaffold .errorExplanation h2 { + color: #333333; + background-color: #ff6666; } + +/* Show + ============================= */ +.active-scaffold .show-view dt { + color: #555555; } + +/* Form + ============================== */ +.active-scaffold h4, +.active-scaffold h5 { + color: #1f7f00; } + +/* Form :: Fields + ============================== */ +.active-scaffold label { + color: #555555; } + +.active-scaffold .description { + color: #999999; } + +.active-scaffold label.example { + color: #aaaaaa; } + +.active-scaffold input.text-input, +.active-scaffold select { + border-color: #1f7f00; } + +.active-scaffold .fieldWithErrors input, +.active-scaffold .field_with_errors input, +.active-scaffold .fieldWithErrors textarea, +.active-scaffold .field_with_errors textarea, +.active-scaffold .fieldWithErrors select, +.active-scaffold .field_with_errors select { + border-color: red; } + +.active-scaffold input.example { + color: #aaaaaa; } + +.active-scaffold select:focus, +.active-scaffold input.text-input:focus { + background-color: #ffffcc; } + +.active-scaffold textarea { + border-color: #1f7f00; } + +.active-scaffold .draggable-list { + background-color: #ffff88; } + +.active-scaffold .draggable-list.selected { + background-color: #7fcf00; } + +/* Form :: Association Sub-Forms + ============================== */ +.active-scaffold .sub-form table th { + color: #555555; } + +.active-scaffold .sub-form .checkbox-list { + background-color: white; + border-color: #1f7f00; } + +.active-scaffold .sub-form .checkbox-list label { + display: block; } + +.active-scaffold .sub-form table td { + color: #999999; } + +.active-scaffold .sub-form .footer { + color: #999999; } + +.as_touch th a, .as_touch th a:visited { + color: white; } diff --git a/app/assets/stylesheets/active_scaffold_colors.scss b/app/assets/stylesheets/active_scaffold_colors.scss new file mode 100644 index 0000000000..168c6f0303 --- /dev/null +++ b/app/assets/stylesheets/active_scaffold_colors.scss @@ -0,0 +1,391 @@ +/* + ActiveScaffold + (c) 2007 Richard White <rrwhite@gmail.com> + + ActiveScaffold is freely distributable under the terms of an MIT-style license. + + For details, see the ActiveScaffold web site: http://www.activescaffold.com/ + +*/ + +$disabled_color: #999 !default; +$actions_disabled_color: #666 !default; +$link_color: #06c !default; +$hover_bg: #ff8 !default; +$header_color: #555 !default; + +$column_header_bg: $header_color !default; +$column_header_link_color: #fff !default; +$column_header_link_hover_bg: #000 !default; +$column_header_link_hover_color: #ff8 !default; +$column_header_color: #eee !default; +$column_header_sorted_bg: #333 !default; + +$column_bg: #E6F2FF !default; +$column_even_bg: #fff !default; +$column_color: #333 !default; +$column_empty_color: #999 !default; +$column_border_color: #C5DBF7 !default; +$column_even_border_color: #ddd !default; +$column_actions_border_color: #ccc !default; + +$column_sorted_bg: #B9DCFF !default; +$column_sorted_border_color: #AFD0F5 !default; +$column_even_sorted_bg: #E6F2FF !default; +$column_even_sorted_border_color: #AFD0F5 !default; + +$calculations_bg: #eee !default; +$calculations_border_color: #005CB8 !default; + +$action_group_color: #0066CC !default; +$action_group_hover_bg: #ff8 !default; +$action_group_border_color: #005CB8 !default; +$action_group_items_bg: #EEE !default; +$action_group_items_border_color: #222 !default; +$action_group_link_color: $column_color !default; + +$nested_bg: #DAFFCD !default; +$nested_border_color: #7FCF00 !default; +$nested_footer_color: #444 !default; +$nested_column_bg: #ECFFE7 !default; +$nested_column_border_color: $column_border_color !default; + +$second_nested_bg: #FFFFBB !default; +$second_nested_border_color: #DDDF37 !default; + +$third_nested_bg: $nested_bg !default; +$third_nested_border_color: $nested_border_color !default; + +$pagination_border_color: #ccc !default; +$msg_color: #333 !default; +$msg_error_bg: #fbb !default; +$msg_error_border_color: #f66 !default; +$msg_warning_bg: #ffb !default; +$msg_warning_border_color: #ff6 !default; +$msg_info_bg: #bbf !default; +$msg_info_border_color: #66f !default; +$msg_filtered_bg: #e8e8e8 !default; +$msg_filtered_color: #666 !default; + +$form_title_color: #1F7F00 !default; +$label_color: $header_color !default; +$description_color: #999 !default; +$placeholder_color: #aaa !default; +$input_border_color: $form_title_color !default; +$input_error_border_color: #f00 !default; +$input_focus_bg: #ffc !default; + +$draggable_list_bg: #FFFF88 !default; +$draggable_list_selected_bg: #7FCF00 !default; +$checkbox_list_bg: #fff !default; + +$subform_color: #999 !default; +$subform_header_color: $header_color !default; +$subform_footer_color: $subform_color !default; + +.active-scaffold a.disabled { +color: $disabled_color; +} + +.active-scaffold a:hover, .active-scaffold div.hover, .active-scaffold td span.hover { +background-color: $hover_bg; +} + +noscript.active-scaffold { +border-color: $msg_error_border_color; +background-color: $msg_error_bg; +color: $column_color; +} + +/* Header + ======================== */ + +.active-scaffold-header h2 { +color: $header_color; +} + +.active-scaffold-header div.actions a.disabled { +color: $actions_disabled_color; +} + +/* Table :: Column Headers + ============================= */ + +.active-scaffold th { +background-color: $column_header_bg; +} + +.active-scaffold th a, +.active-scaffold th p { +background-color: $column_header_bg; +} + +.active-scaffold th a, .active-scaffold th a:visited { +color: $column_header_link_color; +} + +.active-scaffold th p { +color: $column_header_color; +} + +.active-scaffold th a:hover { +background-color: $column_header_link_hover_bg; +color: $column_header_link_hover_color; +} + +.active-scaffold th.sorted { +background-color: $column_header_sorted_bg; +} + +.active-scaffold th.asc a, +.active-scaffold th.asc a:hover, +.active-scaffold th.desc a, +.active-scaffold th.desc a:hover, +.active-scaffold th.loading a, +.active-scaffold th.loading a:hover { + background-color: $column_header_sorted_bg; +} + +/* Table :: Record Rows + ============================= */ + +.active-scaffold tr.record { + background-color: $column_bg; +} +.active-scaffold tr.record td { +color: $column_color; +border-color: $column_border_color; +} + +.active-scaffold tr.even-record { +background-color: $column_even_bg; +} +.active-scaffold tr.even-record td { +border-left-color: $column_even_border_color; +} + +.active-scaffold tr.record td.sorted { +background-color: $column_sorted_bg; +border-bottom-color: $column_sorted_border_color; +} + +.active-scaffold tr.even-record td.sorted { +background-color: $column_even_sorted_bg; +border-bottom-color: $column_even_sorted_border_color; +} + +.active-scaffold tbody.records td.empty { +color: $column_empty_color; +} + +/* Table :: Actions (Edit, Delete) + ============================= */ +.active-scaffold tr.record td.actions { +border-color: $column_actions_border_color; +} + +.active-scaffold tr.record td.actions a.disabled { +color: $actions_disabled_color; +} + +.active-scaffold .actions .action_group div:hover { +background-color: $action_group_hover_bg; +} + +.active-scaffold .actions .action_group { +color: $action_group_color; +} + +.active-scaffold .actions .action_group ul { +border-color: $action_group_border_color; +} + +.active-scaffold .actions .action_group ul li { +background-color: $action_group_items_bg; +border-color: $action_group_items_border_color; +} + +.active-scaffold .actions .action_group ul li a { + color: $action_group_link_color; +} + +/* Table :: Inline Adapter + ============================= */ + +.active-scaffold .view { +background-color: $nested_bg; +border-color: $nested_border_color; +} + +/* Nested + ======================== */ + +.active-scaffold .active-scaffold .active-scaffold-footer { +color: $nested_footer_color; +} + +.active-scaffold .active-scaffold td { +background-color: $nested_column_bg; +border-color: $nested_column_border_color; +} + +.active-scaffold .active-scaffold td.inline-adapter-cell { +background-color: $second_nested_bg; +border-color: $second_nested_border_color; +} + +.active-scaffold .active-scaffold .active-scaffold td.inline-adapter-cell { +background-color: $third_nested_bg; +border-color: $third_nested_border_color; +} + +/* Footer + ========================== */ + +.active-scaffold-calculations td { +background-color: $calculations_bg; +border-color: $calculations_border_color; +} + +.active-scaffold-footer .next { +border-color: $pagination_border_color; +} + +.active-scaffold-footer .previous { +border-color: $pagination_border_color; +} + +/* Messages + ========================= */ + + +.active-scaffold .empty-message, .active-scaffold .filtered-message { +background-color: $msg_filtered_bg; +color: $msg_filtered_color; +} + +.active-scaffold .message { +color: $msg_color; +} + +.active-scaffold .error-message { +border-color: $msg_error_border_color; +background-color: $msg_error_bg; +} + +.active-scaffold .warning-message { +border-color: $msg_warning_border_color; +background-color: $msg_warning_bg; +} + +.active-scaffold .info-message { +border-color: $msg_info_border_color; +background-color: $msg_info_bg; +} + +/* Error Styling + ========================== */ + +.active-scaffold .errorExplanation { +background-color: $msg_error_bg; +border-color: $msg_error_border_color; +} + +.active-scaffold .errorExplanation h2 { +color: $msg_color; +background-color: $msg_error_border_color; +} + +/* Show + ============================= */ + +.active-scaffold .show-view dt { +color: $label_color; +} + +/* Form + ============================== */ + +.active-scaffold h4, +.active-scaffold h5 { +color: $form_title_color; +} + +/* Form :: Fields + ============================== */ + +.active-scaffold label { +color: $label_color; +} + +.active-scaffold .description { +color: $description_color; +} + +.active-scaffold label.example { +color: $placeholder_color; +} + +.active-scaffold input.text-input, +.active-scaffold select { +border-color: $input_border_color; +} + +.active-scaffold .fieldWithErrors input, +.active-scaffold .field_with_errors input, +.active-scaffold .fieldWithErrors textarea, +.active-scaffold .field_with_errors textarea, +.active-scaffold .fieldWithErrors select, +.active-scaffold .field_with_errors select { +border-color: $input_error_border_color; +} + +.active-scaffold input.example { +color: $placeholder_color; +} + +.active-scaffold select:focus, +.active-scaffold input.text-input:focus { +background-color: $input_focus_bg; +} + +.active-scaffold textarea { +border-color: $input_border_color; +} + +.active-scaffold .draggable-list { +background-color: $draggable_list_bg; +} + +.active-scaffold .draggable-list.selected { +background-color: $draggable_list_selected_bg; +} + + +/* Form :: Association Sub-Forms + ============================== */ + +.active-scaffold .sub-form table th { +color: $subform_header_color; +} + +.active-scaffold .sub-form .checkbox-list { +background-color: $checkbox_list_bg; +border-color: $input_border_color; +} + +.active-scaffold .sub-form .checkbox-list label { +display: block; +} + +.active-scaffold .sub-form table td { +color: $subform_color; +} + +.active-scaffold .sub-form .footer { +color: $subform_footer_color; +} + +.as_touch th a, .as_touch th a:visited { +color: $column_header_link_color; +} diff --git a/app/assets/stylesheets/active_scaffold_default.css.erb b/app/assets/stylesheets/active_scaffold_default.css.erb new file mode 100644 index 0000000000..b94995f151 --- /dev/null +++ b/app/assets/stylesheets/active_scaffold_default.css.erb @@ -0,0 +1,47 @@ +.active-scaffold-header div.actions div.action_group div { + background-image: url(<%= asset_path 'active_scaffold/gears.png' %>); /* default icon for actions or override with css */ +} + +.active-scaffold-header div.actions a.show_config_list { + background-image: url(<%= asset_path 'active_scaffold/config.png' %>); +} + +.active-scaffold-header div.actions a.new, +.active-scaffold-header div.actions a.new_existing { +background-image: url(<%= asset_path 'active_scaffold/add.gif' %>); +} + +.active-scaffold-header div.actions a.show_search { +background-image: url(<%= asset_path 'active_scaffold/magnifier.png' %>); +} + +.active-scaffold th.asc a, +.active-scaffold th.asc a:hover { +background-image: url(<%= asset_path 'active_scaffold/arrow_up.gif' %>); +} + +.active-scaffold th.desc a, +.active-scaffold th.desc a:hover { +background-image: url(<%= asset_path 'active_scaffold/arrow_down.gif' %>); +} + +.active-scaffold th.loading a, +.active-scaffold th.loading a:hover { +background-image: url(<%= asset_path 'active_scaffold/indicator-small.gif' %>); +} + +.active-scaffold a.inline-adapter-close { +background-image: url(<%= asset_path 'active_scaffold/close.gif' %>); +} + +.active-scaffold .sub-form .association-record a.destroy { +background-image: url(<%= asset_path 'active_scaffold/cross.png' %>); +} + +.as_touch a.inline-adapter-close { +background-image: url(<%= asset_path 'active_scaffold/close_touch.png' %>); +} + +<% require_asset "jquery-ui" %> +<% ActiveScaffold.stylesheets.each {|css| require_asset css} %> +<% ActiveScaffold::Bridges.all_stylesheets.each {|css| require_asset css} %> diff --git a/app/assets/stylesheets/active_scaffold_layout.css b/app/assets/stylesheets/active_scaffold_layout.css new file mode 100644 index 0000000000..4a5b8b4fcd --- /dev/null +++ b/app/assets/stylesheets/active_scaffold_layout.css @@ -0,0 +1,912 @@ +.active-scaffold form, +.active-scaffold table, +.active-scaffold p, +.active-scaffold div, +.active-scaffold fieldset { +margin: 0; +padding: 0; +} + +.active-scaffold { +margin: 5px 0; +} + +.active-scaffold table { +width: 100%; +border-collapse: separate; +} + +.active-scaffold a, +.active-scaffold a:visited { +text-decoration: none; +} + +.active-scaffold div.actions a img, +.active-scaffold td.actions a img { +border: none; +vertical-align: middle; +} + +.active-scaffold div.actions a.disabled img, +.active-scaffold td.actions a.disabled img { +opacity: 0.5; +} + +.active-scaffold .clear-fix { +clear: both; +} + +noscript.active-scaffold { +border-left: solid 5px; +font-size: 11px; +font-weight: bold; +padding: 5px 20px 5px 5px; +} + +.active-scaffold .mark_record_column { + width: 1px; +} + +/* Header + ======================== */ + +.active-scaffold-header { +position: relative; +} + +.active-scaffold-header h2 { +padding: 2px 0px; +margin: 0; +font: bold 160% arial, sans-serif; +} + +.active-scaffold-header div.actions a, +.active-scaffold-header div.actions { +float: right; +font: bold 14px arial; +letter-spacing: -1px; +text-decoration: none; +padding: 1px 2px; +white-space: nowrap; +margin-left: 5px; +background-position: 1px 50%; +background-repeat: no-repeat; +} + +.active-scaffold-header div.actions a { +padding: 5px 5px; +margin-left: 0px; +} + +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a { +padding: 1px 5px; +} + +.active-scaffold-header div.actions div.action_group { +display: inline; +float: right; +} + +.active-scaffold-header div.actions div.action_group li a, +.active-scaffold-header div.actions div.action_group li div { +float: none; +margin: 0; +} + +.active-scaffold-header div.actions .action_group ul { +line-height: 130%; +top: 19px; +} + +.active-scaffold .active-scaffold .active-scaffold-header div.actions .action_group ul { +top: 14px; +} + +.view .active-scaffold-header div.actions a, +.view .active-scaffold-header div.actions div, +.view .active-scaffold-header div.actions div.action_group { +float: left; +} + +.active-scaffold-header div.actions a.disabled { +opacity: 0.5; +} + +.active-scaffold-header div.actions a.new, +.active-scaffold-header div.actions a.new_existing, +.active-scaffold-header div.actions a.show_search, +.active-scaffold-header div.actions a.show_config_list, +.active-scaffold-header div.actions div.action_group div { +margin:0; +padding: 5px 5px 5px 25px; +background-position: 5px 50%; +background-repeat: no-repeat; +} + +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.new, +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.new_existing, +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.show_search, +.active-scaffold .active-scaffold .active-scaffold-header div.actions > a.show_config_list, +.active-scaffold .active-scaffold .active-scaffold-header div.actions div.action_group > div { +margin:0; +padding: 1px 5px 1px 20px; +background-position: 1px 50%; +background-repeat: no-repeat; +} + +.active-scaffold-header div.actions a.disabled:hover { +background-color: transparent; +cursor: default; +} + +.active-scaffold-header div.actions { +position: absolute; +right: 5px; +top: 5px; +text-align: right; +} + +/* Table :: Column Headers + ============================= */ + +.active-scaffold th { +text-align: left; +} + +.active-scaffold th a, +.active-scaffold th p { +font: bold 11px arial, sans-serif; +display: block; +} + +.active-scaffold th a, .active-scaffold th a:visited { +padding: 2px 2px 2px 5px; +} + +.active-scaffold th p { +padding: 2px 5px; +} + +.active-scaffold th.sorted a { +padding-right: 18px; +} + +.active-scaffold th.asc a, +.active-scaffold th.asc a:hover, +.active-scaffold th.desc a, +.active-scaffold th.desc a:hover, +.active-scaffold th.loading a, +.active-scaffold th.loading a:hover { + background: right 50% no-repeat; +} + +.active-scaffold th .mark_heading { +margin-left: 5px; +} + +.active-scaffold th.hidden, .active-scaffold td.hidden { +display: none; +} + +/* Table :: Record Rows + ============================= */ + +.active-scaffold tr.record td { +padding: 5px 4px; +font-family: Verdana, sans-serif; +font-size: 11px; +border: solid 1px; +border-width: 0 0 1px 1px; +} + +.active-scaffold tr.record td.messages-container { +padding: 0px; +} + +.active-scaffold tbody.records td.empty { +text-align: center; +} + +.active-scaffold td.numeric, +.active-scaffold-calculations td { +text-align: right; +} + +/* Table :: Actions (Edit, Delete) + ============================= */ +.active-scaffold tr.record td.actions { +border-right: solid 1px; +padding: 0; +min-width: 1%; +} + +.active-scaffold tr.record td.actions table { +float: right; +width: auto; +margin-right: 5px; +} + +.active-scaffold tr.record td.actions table td { +border: none; +text-align: right; +padding: 0 2px; +} + +.active-scaffold tr.record td.actions a, +.active-scaffold tr.record td.actions div { +font: bold 11px verdana, sans-serif; +letter-spacing: -1px; +padding: 2px; +margin: 0 2px; +line-height: 16px; +white-space: nowrap; +} + +.active-scaffold tr.record td.actions a.disabled { +opacity: 0.5; +} + +.active-scaffold .actions .action_group { +position: relative; +text-align: left; +} + +.active-scaffold .actions .action_group ul { +border: 2px solid; +list-style-type: none; +margin: 0; +padding: 0; +position: absolute; +line-height: 200%; +display: none; +width: 150px; +right: 0px; +} + +.active-scaffold .actions .action_group ul ul { +display: none; +position: absolute; +top: 0; +right: 150px; +} + +.active-scaffold .actions .action_group ul li { +background: none repeat scroll 0 0; +border-top: 1px dashed; +display: block; +position: relative; +width: auto; +z-index: 2; +} + +.active-scaffold .actions .action_group ul li div { + margin: 0; + padding: 5px 5px 5px 25px; + background-position: 5px 50%; + background-repeat: no-repeat; +} + +.active-scaffold .actions .action_group ul li a { + display: block; + margin: 0; + padding: 5px 5px 5px 25px; + background-position: 5px 50%; + background-repeat: no-repeat; +} + +.active-scaffold .actions .action_group ul li.top { +border-top-width: 0px; +} + +.active-scaffold .actions .action_group:hover ul ul, +.active-scaffold .actions .action_group:hover ul ul ul { +display: none; +} + +.active-scaffold .actions .action_group:hover ul, +.active-scaffold .actions .action_group ul li:hover > ul, +.active-scaffold .actions .action_group ul ul li:hover ul { +display: block; +} + +/* Table :: Inline Adapter + ============================= */ + +.active-scaffold .view { +padding: 4px; +border: solid 1px; +} + +.active-scaffold tbody.records td.inline-adapter-cell .view { +border-top: none; +} + +.active-scaffold .before-header td.inline-adapter-cell .view { +border-bottom: none; +} + +.active-scaffold a.inline-adapter-close { +float: right; +text-indent: -4000px; +width: 16px; +height: 17px; +background: 0 0 no-repeat; +} + +/* Nested + ======================== */ + +.active-scaffold .active-scaffold .active-scaffold-header { +margin-right: 25px; +} + +.active-scaffold .active-scaffold .active-scaffold-header h2 { +font-size: 12px; +font-weight: bold; +} + + +.active-scaffold .active-scaffold .active-scaffold-header div.actions { +top: 0px; +right: 0px; +} + +.active-scaffold .active-scaffold .active-scaffold-header div.actions a, +.active-scaffold .active-scaffold .active-scaffold-header div.actions div { +font: bold 11px verdana, sans-serif; +} + +.active-scaffold .active-scaffold .view { +background-color: transparent; +padding: 0px; +border: none; +} + +.active-scaffold .active-scaffold td { +border-bottom: solid 1px; +border-left: solid 1px; +} + +.active-scaffold .active-scaffold td.inline-adapter-cell { +padding: 4px; +border: solid 1px; +border-top: none; +} + +.active-scaffold .active-scaffold .active-scaffold td.inline-adapter-cell { +padding: 4px; +border: solid 1px; +border-top: none; +} + +.active-scaffold .active-scaffold .active-scaffold-footer { +font-size: 11px; +} + +/* Footer + ========================== */ + +.active-scaffold-calculations td { +border-top: 2px solid; +font: bold 12px arial, sans-serif; +} + +.active-scaffold .active-scaffold-footer { +padding: 3px 0px 2px 0px; +border-bottom: none; +font: bold 12px arial, sans-serif; +} + +.active-scaffold-footer .active-scaffold-pagination { +float: right; +white-space: nowrap; +margin-right: 5px; +} + +.active-scaffold-footer a { +text-decoration: none; +letter-spacing: 0; +padding: 0 2px; +margin: 0 -2px; +font: bold 12px arial, sans-serif; +} + +.active-scaffold-footer .next { +margin-left: 0; +padding-left: 5px; +border-left: solid 1px; +} + +.active-scaffold-footer .previous { +margin-right: 0; +padding-right: 5px; +border-right: solid 1px; +} + +/* Messages + ========================= */ + +.active-scaffold .messages-container, +.active-scaffold .active-scaffold .messages-container{ +padding: 0; +margin: 0 7px; +border: none; +} + +.active-scaffold .empty-message, .active-scaffold .filtered-message { +padding: 4px; +text-align: center; +} + +.active-scaffold .message { +font-size: 11px; +font-weight: bold; +padding: 5px 20px 5px 5px; +position: relative; +margin: 2px 7px; +line-height: 12px; +} + +.active-scaffold .message a { +position: absolute; +right: 10px; +top: 4px; +padding: 0; +font: bold 11px verdana, sans-serif; +letter-spacing: -1px; +} + +.active-scaffold .messages-container .message { +margin: 0; +} + +.active-scaffold .error-message { +border-left: solid 5px; +} + +.active-scaffold .warning-message { +border-left: solid 5px; +} + +.active-scaffold .info-message { +border-left: solid 5px; +} + +/* Error Styling + ========================== */ + +.active-scaffold .errorExplanation { +border: solid 1px; +} + +.active-scaffold fieldset { +clear: both; +} + +.active-scaffold .errorExplanation h2 { +padding: 2px 5px; +font-size: 11px; +margin: 0; +letter-spacing: 0; +font-family: Verdana; +} + +.active-scaffold .errorExplanation ul { +margin: 0; +padding: 0 2px 4px 25px; +list-style: disc; +} + +.active-scaffold .errorExplanation p { +font-size: 11px; +padding: 2px 5px; +font-family: Verdana; +margin: 0; +} + +.active-scaffold .errorExplanation ul li { +font: bold 11px verdana; +letter-spacing: -1px; +margin: 0; +padding: 0; +background-color: transparent; +} + +/* Loading Indicators + ============================== */ + +.active-scaffold .loading-indicator { +vertical-align: text-bottom; +width: 16px; +margin: 0; +} + +.active-scaffold .active-scaffold-header .loading-indicator { +margin-top: 3px; +} + +/* Show + ============================= */ + +.active-scaffold .show-view dl { +margin-left: 5px; +} +.active-scaffold .show-view dl dl { +margin-left: 0px; +} + +.active-scaffold .show-view dt { +width: 12em; +float: left; +clear: left; +font: normal 11px verdana, sans-serif; +line-height: 16px; +} + +.active-scaffold .show-view dd { +float: left; +font: bold 14px arial; +padding-left: 5px; +margin-bottom: 5px; +} + +/* Form + ============================== */ + +.active-scaffold dl { +margin: 0; +} + +.active-scaffold .submit { +font-weight: bold; +font-size: 14px; +font-family: Arial, sans-serif; +letter-spacing: 0; +margin: 0; +margin-top: 5px; +} + +.active-scaffold form p { +clear: both; +} + +.active-scaffold fieldset { +border: none; +} + +.active-scaffold h4, +.active-scaffold h5 { +padding: 2px; +margin: 0; +text-transform: none; +letter-spacing: -1px; +font: bold 16px arial; +} + +.active-scaffold h5 { +padding: 0; +margin: 5px 0 2px 0; +font-size: 14px; +letter-spacing: 0; +} + +.active-scaffold ol { +clear: both; +float: none; +padding: 2px; +margin-left: 5px; +list-style: none; +} + +.active-scaffold p.form-footer { +clear: both; +} + +.active-scaffold a.as_cancel, +.active-scaffold p.form-footer a { +font: bold 14px arial, sans-serif; +letter-spacing: 0; +} + +/* Form :: Fields + ============================== */ + +.active-scaffold li.form-element { +clear: both; +} + +.active-scaffold label { +font: normal 11px verdana, sans-serif; +} + +.active-scaffold li.form-element dt { +float: left; +width: 12em; +padding: 6px 0; +} + +.active-scaffold li.form-element dd { +float: left; +} + +.active-scaffold li.form-element dd p, +.active-scaffold li.form-element dd input[type="checkbox"] { +margin-top: 6px; +} + +.active-scaffold .form dd { +margin: 0; +} + + +.active-scaffold .description { +display: inline-block; +font-size: 10px; +margin-left: 5px; +} + +.active-scaffold .required label { +font-weight: bold; +} + +.active-scaffold label.example { +font-size: 11px; +font-family: arial; +} + +.active-scaffold input.text-input, +.active-scaffold select { +font: bold 16px arial; +letter-spacing: -1px; +border: solid 1px; +} + +.active-scaffold input.text-input { +padding: 2px; +} + +.active-scaffold .fieldWithErrors input, +.active-scaffold .field_with_errors input, +.active-scaffold .fieldWithErrors textarea, +.active-scaffold .field_with_errors textarea, +.active-scaffold .fieldWithErrors select, +.active-scaffold .field_with_errors select { +border: solid 1px; +} + +.active-scaffold select { +padding: 1px; +} + + +.active-scaffold textarea { +font-family: Arial, sans-serif; +font-size: 12px; +padding: 1px; +border: solid 1px; +} + +.active-scaffold .checkbox-list { +padding-left: 0px; +} + +.active-scaffold .checkbox-list li { +padding-right: 5px; +display: inline; +} + +.active-scaffold .checkbox-list li label { +padding: 0 0 0 2px; +} + +.active-scaffold .draggable-list { +float: left; +width: 300px; +margin-right: 15px; +min-height: 30px; +max-height: 100px; +overflow: auto; +} + +.active-scaffold .draggable-list.hover { +opacity: 0.5; +} + + +.active-scaffold .draggable-list li { +display: block; +} + +li.draggable-item { + list-style: none; +} +li.draggable-item input, +.active-scaffold .draggable-list input { +display: none; +} + +/* Form :: Sub-Sections + ============================== */ + +.active-scaffold li.sub-section { +clear: left; +padding: 5px 0; +} + +/* Form :: Association Sub-Forms + ============================== */ + +.active-scaffold .sub-form { +float: left; +clear: left; +padding: 5px 0; +padding-left: 5px; +} + +.active-scaffold .sub-form h5 { +margin-left: -5px; +} + +.active-scaffold .sub-form table, +.active-scaffold .sub-form table td { +width: auto; +background: none; +} + +.active-scaffold .sub-form table th { +font: normal 10px verdana, sans-serif; +padding: 0 5px 0 1px; +background: none; +} + +.active-scaffold .horizontal-sub-form td dt label { +display: none; +} + +.active-scaffold .sub-form .checkbox-list { +padding: 0 2px 2px 2px; +border: solid 1px; +} + +.active-scaffold .sub-form .checkbox-list label { +display: block; +} + +.active-scaffold .sub-form table td { +border: none; +background-color: transparent; +padding: 1px; +vertical-align: top; +} + +.active-scaffold .sub-form .actions { +vertical-align: middle; +background-color: transparent; +clear: left; +} + +.active-scaffold .sub-form .association-record a.destroy { +font-weight: bold; +display: block; +height: 16px; +padding: 0; +width: 16px; +text-indent: -4000px; +background: 0 0 no-repeat; +} + +.active-scaffold .sub-form .locked a.destroy { +display: none; +} + +.active-scaffold .sub-form .association-record a { +font: bold 12px arial; +} + +.active-scaffold .sub-form input.text-input, +.active-scaffold .sub-form select { +letter-spacing: 0; +font: bold 12px arial; +} + +.active-scaffold .sub-form .footer-wrapper { +margin-top: 3px; +margin-right: 10px; +} + +.active-scaffold .sub-form .footer { +padding: 3px 5px; +} + +.active-scaffold .sub-form .footer select, +.active-scaffold .sub-form .footer input { +font-weight: bold; +font-size: 12px; +padding: 0; +} + +.active-scaffold a.visibility-toggle { +font-size: 100%; +} + +.active-scaffold-found { + float:left; +} + +.as_touch a.inline-adapter-close { +width: 25px; +height: 27px; +background: 0 0 no-repeat; +} + +.as_touch .as_paginate { +font-size: 20px; +padding: 3px 10px; +} + +.as_touch .active-scaffold-header div.actions a { +padding: 7px 5px; +} + +.as_touch .active-scaffold .active-scaffold-header div.actions a { +padding: 7px 5px; +} + +.as_touch .active-scaffold-header div.actions .action_group ul { +line-height: 130%; +top: 23px; +} + +.as_touch .active-scaffold .active-scaffold-header div.actions .action_group ul { +top: 23px; +} + +.as_touch .active-scaffold-header div.actions a.new, +.as_touch .active-scaffold-header div.actions a.new_existing, +.as_touch .active-scaffold-header div.actions a.show_search, +.as_touch .active-scaffold-header div.actions a.show_config_list, +.as_touch .active-scaffold-header div.actions div.action_group div { +padding: 7px 5px 7px 25px; +} + +.as_touch .active-scaffold .active-scaffold-header div.actions > a.new, +.as_touch .active-scaffold .active-scaffold-header div.actions > a.new_existing, +.as_touch .active-scaffold .active-scaffold-header div.actions > a.show_search, +.as_touch .active-scaffold .active-scaffold-header div.actions > a.show_config_list, +.as_touch .active-scaffold .active-scaffold-header div.actions div.action_group > div { +padding: 7px 5px 7px 25px; +background-position: 5px 50%; +} + +.as_touch .actions .action_group ul li div { +padding: 7px 5px 7px 25px; +} + +.as_touch .actions .action_group ul li a { +padding: 7px 5px 7px 25px; +} + +.as_touch .active-scaffold-header h2 { +padding: 4px 0px; +} + +.as_touch .active-scaffold .active-scaffold-header div.actions a, +.as_touch .active-scaffold .active-scaffold-header div.actions div { + font: bold 14px arial; +} + +.as_touch .active-scaffold .active-scaffold-header div.actions { + right: 15px; +} + +.as_touch tr.record { +line-height: 130%; +} + +.as_touch th a, .as_touch th a:visited { +padding: 5px 2px 5px 5px; +} + +.as_touch tr.record td { +padding: 5px 10px; +} From e97bc0329bf2423fd2d049e47453a82be7b7ad1b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 2 Feb 2012 09:54:22 +0100 Subject: [PATCH 1392/2024] ignore sass cache --- .gitignore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 228818604e..c918d37478 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,9 @@ doc # jeweler generated pkg +# sass generated +.sass-cache + # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore: # # * Create a file at ~/.gitignore @@ -39,4 +42,7 @@ pkg #.\#* # # For vim: -#*.swp +*.swp +# +# For kdevelop: +*.kdev4 From 2f1cc3bfa3b0083eadd5236dfe86a48f819b3c3c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 2 Feb 2012 09:54:35 +0100 Subject: [PATCH 1393/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 7be60bc898..881c6cf344 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 1 - PATCH = 19 + PATCH = 20 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 28f2ffc0b9b591ade29b11f434a46e5965613e08 Mon Sep 17 00:00:00 2001 From: Nick Rogers <ncrogers@gmail.com> Date: Wed, 1 Feb 2012 23:18:05 -0500 Subject: [PATCH 1394/2024] Fix AJAX method of inline scaffold rendering when using jQuery for active_scaffold in conjunction with prototype library. --- lib/active_scaffold/extensions/action_view_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index f5ef6fb9dd..528b097281 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -87,7 +87,7 @@ def render_with_active_scaffold(*args, &block) if ActiveScaffold.js_framework == :prototype javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true});") elsif ActiveScaffold.js_framework == :jquery - javascript_tag("$('##{id}').load('#{url}');") + javascript_tag("jQuery('##{id}').load('#{url}');") end end end From a1c75fcaaabf34a7165b57c13d86aafa1cbf98d5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 6 Feb 2012 12:55:41 +0100 Subject: [PATCH 1395/2024] fijar ancho columna --- app/assets/stylesheets/active_scaffold_colors.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/stylesheets/active_scaffold_colors.scss b/app/assets/stylesheets/active_scaffold_colors.scss index 168c6f0303..273cd0e448 100644 --- a/app/assets/stylesheets/active_scaffold_colors.scss +++ b/app/assets/stylesheets/active_scaffold_colors.scss @@ -83,6 +83,10 @@ $subform_color: #999 !default; $subform_header_color: $header_color !default; $subform_footer_color: $subform_color !default; +.active-scaffold a, .active-scaffold a:visited { +color: $link_color; +} + .active-scaffold a.disabled { color: $disabled_color; } From 6eeb64eb564ce031bfe8be441f726413fe9bac2a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 6 Feb 2012 13:23:25 +0100 Subject: [PATCH 1396/2024] force to use sass, it should fix file not found problems on precompilation --- .../stylesheets/active_scaffold.css.erb | 2 +- .../stylesheets/active_scaffold_colors.css | 244 ------------------ 2 files changed, 1 insertion(+), 245 deletions(-) delete mode 100644 app/assets/stylesheets/active_scaffold_colors.css diff --git a/app/assets/stylesheets/active_scaffold.css.erb b/app/assets/stylesheets/active_scaffold.css.erb index 2c8a167a85..e3b598d019 100644 --- a/app/assets/stylesheets/active_scaffold.css.erb +++ b/app/assets/stylesheets/active_scaffold.css.erb @@ -8,4 +8,4 @@ *= require active_scaffold_layout *= require active_scaffold_default */ -@import 'active_scaffold_colors<%= '.css' unless defined? Sass %>'; +@import 'active_scaffold_colors'; diff --git a/app/assets/stylesheets/active_scaffold_colors.css b/app/assets/stylesheets/active_scaffold_colors.css deleted file mode 100644 index faacf2f805..0000000000 --- a/app/assets/stylesheets/active_scaffold_colors.css +++ /dev/null @@ -1,244 +0,0 @@ -/* - ActiveScaffold - (c) 2007 Richard White <rrwhite@gmail.com> - - ActiveScaffold is freely distributable under the terms of an MIT-style license. - - For details, see the ActiveScaffold web site: http://www.activescaffold.com/ - -*/ -.active-scaffold a.disabled { - color: #999999; } - -.active-scaffold a:hover, .active-scaffold div.hover, .active-scaffold td span.hover { - background-color: #ffff88; } - -noscript.active-scaffold { - border-color: #ff6666; - background-color: #ffbbbb; - color: #333333; } - -/* Header - ======================== */ -.active-scaffold-header h2 { - color: #555555; } - -.active-scaffold-header div.actions a.disabled { - color: #666666; } - -/* Table :: Column Headers - ============================= */ -.active-scaffold th { - background-color: #555555; } - -.active-scaffold th a, -.active-scaffold th p { - background-color: #555555; } - -.active-scaffold th a, .active-scaffold th a:visited { - color: white; } - -.active-scaffold th p { - color: #eeeeee; } - -.active-scaffold th a:hover { - background-color: black; - color: #ffff88; } - -.active-scaffold th.sorted { - background-color: #333333; } - -.active-scaffold th.asc a, -.active-scaffold th.asc a:hover, -.active-scaffold th.desc a, -.active-scaffold th.desc a:hover, -.active-scaffold th.loading a, -.active-scaffold th.loading a:hover { - background-color: #333333; } - -/* Table :: Record Rows - ============================= */ -.active-scaffold tr.record { - background-color: #e6f2ff; } - -.active-scaffold tr.record td { - color: #333333; - border-color: #c5dbf7; } - -.active-scaffold tr.even-record { - background-color: white; } - -.active-scaffold tr.even-record td { - border-left-color: #dddddd; } - -.active-scaffold tr.record td.sorted { - background-color: #b9dcff; - border-bottom-color: #afd0f5; } - -.active-scaffold tr.even-record td.sorted { - background-color: #e6f2ff; - border-bottom-color: #afd0f5; } - -.active-scaffold tbody.records td.empty { - color: #999999; } - -/* Table :: Actions (Edit, Delete) - ============================= */ -.active-scaffold tr.record td.actions { - border-color: #cccccc; } - -.active-scaffold tr.record td.actions a.disabled { - color: #666666; } - -.active-scaffold .actions .action_group div:hover { - background-color: #ffff88; } - -.active-scaffold .actions .action_group { - color: #0066cc; } - -.active-scaffold .actions .action_group ul { - border-color: #005cb8; } - -.active-scaffold .actions .action_group ul li { - background-color: #eeeeee; - border-color: #222222; } - -.active-scaffold .actions .action_group ul li a { - color: #333333; } - -/* Table :: Inline Adapter - ============================= */ -.active-scaffold .view { - background-color: #daffcd; - border-color: #7fcf00; } - -/* Nested - ======================== */ -.active-scaffold .active-scaffold .active-scaffold-footer { - color: #444444; } - -.active-scaffold .active-scaffold td { - background-color: #ecffe7; - border-color: #c5dbf7; } - -.active-scaffold .active-scaffold td.inline-adapter-cell { - background-color: #ffffbb; - border-color: #dddf37; } - -.active-scaffold .active-scaffold .active-scaffold td.inline-adapter-cell { - background-color: #daffcd; - border-color: #7fcf00; } - -/* Footer - ========================== */ -.active-scaffold-calculations td { - background-color: #eeeeee; - border-color: #005cb8; } - -.active-scaffold-footer .next { - border-color: #cccccc; } - -.active-scaffold-footer .previous { - border-color: #cccccc; } - -/* Messages - ========================= */ -.active-scaffold .empty-message, .active-scaffold .filtered-message { - background-color: #e8e8e8; - color: #666666; } - -.active-scaffold .message { - color: #333333; } - -.active-scaffold .error-message { - border-color: #ff6666; - background-color: #ffbbbb; } - -.active-scaffold .warning-message { - border-color: #ffff66; - background-color: #ffffbb; } - -.active-scaffold .info-message { - border-color: #6666ff; - background-color: #bbbbff; } - -/* Error Styling - ========================== */ -.active-scaffold .errorExplanation { - background-color: #ffbbbb; - border-color: #ff6666; } - -.active-scaffold .errorExplanation h2 { - color: #333333; - background-color: #ff6666; } - -/* Show - ============================= */ -.active-scaffold .show-view dt { - color: #555555; } - -/* Form - ============================== */ -.active-scaffold h4, -.active-scaffold h5 { - color: #1f7f00; } - -/* Form :: Fields - ============================== */ -.active-scaffold label { - color: #555555; } - -.active-scaffold .description { - color: #999999; } - -.active-scaffold label.example { - color: #aaaaaa; } - -.active-scaffold input.text-input, -.active-scaffold select { - border-color: #1f7f00; } - -.active-scaffold .fieldWithErrors input, -.active-scaffold .field_with_errors input, -.active-scaffold .fieldWithErrors textarea, -.active-scaffold .field_with_errors textarea, -.active-scaffold .fieldWithErrors select, -.active-scaffold .field_with_errors select { - border-color: red; } - -.active-scaffold input.example { - color: #aaaaaa; } - -.active-scaffold select:focus, -.active-scaffold input.text-input:focus { - background-color: #ffffcc; } - -.active-scaffold textarea { - border-color: #1f7f00; } - -.active-scaffold .draggable-list { - background-color: #ffff88; } - -.active-scaffold .draggable-list.selected { - background-color: #7fcf00; } - -/* Form :: Association Sub-Forms - ============================== */ -.active-scaffold .sub-form table th { - color: #555555; } - -.active-scaffold .sub-form .checkbox-list { - background-color: white; - border-color: #1f7f00; } - -.active-scaffold .sub-form .checkbox-list label { - display: block; } - -.active-scaffold .sub-form table td { - color: #999999; } - -.active-scaffold .sub-form .footer { - color: #999999; } - -.as_touch th a, .as_touch th a:visited { - color: white; } From bd42453e3d9e3d32115afa8fca25b88b3fbe0415 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 6 Feb 2012 13:31:32 +0100 Subject: [PATCH 1397/2024] rename files and use scss for images too --- .../stylesheets/active_scaffold.css.erb | 5 +- ...s.scss => active_scaffold_colors.css.scss} | 0 .../active_scaffold_default.css.erb | 47 ------------------- .../active_scaffold_images.css.scss | 43 +++++++++++++++++ 4 files changed, 47 insertions(+), 48 deletions(-) rename app/assets/stylesheets/{active_scaffold_colors.scss => active_scaffold_colors.css.scss} (100%) delete mode 100644 app/assets/stylesheets/active_scaffold_default.css.erb create mode 100644 app/assets/stylesheets/active_scaffold_images.css.scss diff --git a/app/assets/stylesheets/active_scaffold.css.erb b/app/assets/stylesheets/active_scaffold.css.erb index e3b598d019..b6a1a39dd2 100644 --- a/app/assets/stylesheets/active_scaffold.css.erb +++ b/app/assets/stylesheets/active_scaffold.css.erb @@ -6,6 +6,9 @@ For details, see the ActiveScaffold web site: http://www.activescaffold.com/ *= require active_scaffold_layout - *= require active_scaffold_default + *= require active_scaffold_images */ @import 'active_scaffold_colors'; +<% require_asset "jquery-ui" %> +<% ActiveScaffold.stylesheets.each {|css| require_asset css} %> +<% ActiveScaffold::Bridges.all_stylesheets.each {|css| require_asset css} %> diff --git a/app/assets/stylesheets/active_scaffold_colors.scss b/app/assets/stylesheets/active_scaffold_colors.css.scss similarity index 100% rename from app/assets/stylesheets/active_scaffold_colors.scss rename to app/assets/stylesheets/active_scaffold_colors.css.scss diff --git a/app/assets/stylesheets/active_scaffold_default.css.erb b/app/assets/stylesheets/active_scaffold_default.css.erb deleted file mode 100644 index b94995f151..0000000000 --- a/app/assets/stylesheets/active_scaffold_default.css.erb +++ /dev/null @@ -1,47 +0,0 @@ -.active-scaffold-header div.actions div.action_group div { - background-image: url(<%= asset_path 'active_scaffold/gears.png' %>); /* default icon for actions or override with css */ -} - -.active-scaffold-header div.actions a.show_config_list { - background-image: url(<%= asset_path 'active_scaffold/config.png' %>); -} - -.active-scaffold-header div.actions a.new, -.active-scaffold-header div.actions a.new_existing { -background-image: url(<%= asset_path 'active_scaffold/add.gif' %>); -} - -.active-scaffold-header div.actions a.show_search { -background-image: url(<%= asset_path 'active_scaffold/magnifier.png' %>); -} - -.active-scaffold th.asc a, -.active-scaffold th.asc a:hover { -background-image: url(<%= asset_path 'active_scaffold/arrow_up.gif' %>); -} - -.active-scaffold th.desc a, -.active-scaffold th.desc a:hover { -background-image: url(<%= asset_path 'active_scaffold/arrow_down.gif' %>); -} - -.active-scaffold th.loading a, -.active-scaffold th.loading a:hover { -background-image: url(<%= asset_path 'active_scaffold/indicator-small.gif' %>); -} - -.active-scaffold a.inline-adapter-close { -background-image: url(<%= asset_path 'active_scaffold/close.gif' %>); -} - -.active-scaffold .sub-form .association-record a.destroy { -background-image: url(<%= asset_path 'active_scaffold/cross.png' %>); -} - -.as_touch a.inline-adapter-close { -background-image: url(<%= asset_path 'active_scaffold/close_touch.png' %>); -} - -<% require_asset "jquery-ui" %> -<% ActiveScaffold.stylesheets.each {|css| require_asset css} %> -<% ActiveScaffold::Bridges.all_stylesheets.each {|css| require_asset css} %> diff --git a/app/assets/stylesheets/active_scaffold_images.css.scss b/app/assets/stylesheets/active_scaffold_images.css.scss new file mode 100644 index 0000000000..ec20d4f9c0 --- /dev/null +++ b/app/assets/stylesheets/active_scaffold_images.css.scss @@ -0,0 +1,43 @@ +.active-scaffold-header div.actions div.action_group div { + background-image: image-url('active_scaffold/gears.png'); /* default icon for actions or override with css */ +} + +.active-scaffold-header div.actions a.show_config_list { + background-image: image-url('active_scaffold/config.png'); +} + +.active-scaffold-header div.actions a.new, +.active-scaffold-header div.actions a.new_existing { +background-image: image-url('active_scaffold/add.gif'); +} + +.active-scaffold-header div.actions a.show_search { +background-image: image-url('active_scaffold/magnifier.png'); +} + +.active-scaffold th.asc a, +.active-scaffold th.asc a:hover { +background-image: image-url('active_scaffold/arrow_up.gif'); +} + +.active-scaffold th.desc a, +.active-scaffold th.desc a:hover { +background-image: image-url('active_scaffold/arrow_down.gif'); +} + +.active-scaffold th.loading a, +.active-scaffold th.loading a:hover { +background-image: image-url('active_scaffold/indicator-small.gif'); +} + +.active-scaffold a.inline-adapter-close { +background-image: image-url('active_scaffold/close.gif'); +} + +.active-scaffold .sub-form .association-record a.destroy { +background-image: image-url('active_scaffold/cross.png'); +} + +.as_touch a.inline-adapter-close { +background-image: image-url('active_scaffold/close_touch.png'); +} From 1662ca93d10b377335cb0737fd12ff69234fd266 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 6 Feb 2012 14:05:34 +0100 Subject: [PATCH 1398/2024] use git to build gem, avoids adding backup files --- active_scaffold.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index 63d331821d..db8fd8d78e 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -12,12 +12,12 @@ Gem::Specification.new do |s| s.summary = %q{Rails 3.1 Version of activescaffold supporting prototype and jquery} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.require_paths = ["lib"] - s.files = Dir["{app,config,frontends,lib,public,shoulda_macros,vendor}/**/*"] + %w[MIT-LICENSE CHANGELOG README] + s.files = `git ls-files {app,config,frontends,lib,public,shoulda_macros,vendor}`.split("\n") + %w[MIT-LICENSE CHANGELOG README] s.extra_rdoc_files = [ "README" ] s.licenses = ["MIT"] - s.test_files = Dir["test/**/*"] + s.test_files = `git ls-files test`.split("\n") s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= From 634033040ec2f5b18f8ce0579e0095d3450afb99 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 6 Feb 2012 14:08:24 +0100 Subject: [PATCH 1399/2024] prepare next version --- lib/active_scaffold/version.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 881c6cf344..2ed42ea0b1 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -1,8 +1,8 @@ module ActiveScaffold module Version MAJOR = 3 - MINOR = 1 - PATCH = 20 + MINOR = 2 + PATCH = 0 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 9d41fa9c3ef941f78e828b6c548b693537b09fe5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 6 Feb 2012 14:46:20 +0100 Subject: [PATCH 1400/2024] fix constraints for embedded scaffolds, fixes #135 --- lib/active_scaffold/actions/core.rb | 1 + lib/active_scaffold/actions/nested.rb | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 46f85192b9..53aff90bdc 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -2,6 +2,7 @@ module ActiveScaffold::Actions module Core def self.included(base) base.class_eval do + before_filter :register_constraints_with_action_columns after_filter :clear_flashes end base.helper_method :nested? diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 0d47b26b39..f7fe9e68a8 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -5,7 +5,6 @@ module Nested def self.included(base) super base.module_eval do - #before_filter :register_constraints_with_action_columns prepend_before_filter :set_nested before_filter :configure_nested include ActiveScaffold::Actions::Nested::ChildMethods if active_scaffold_config.model.reflect_on_all_associations.any? {|a| a.macro == :has_and_belongs_to_many} From 18d665ddebd3b5ca09d967adab1e45c51b01bf97 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 7 Feb 2012 09:48:30 +0100 Subject: [PATCH 1401/2024] fix @import --- .../{active_scaffold.css.erb => active_scaffold.css.scss.erb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/assets/stylesheets/{active_scaffold.css.erb => active_scaffold.css.scss.erb} (100%) diff --git a/app/assets/stylesheets/active_scaffold.css.erb b/app/assets/stylesheets/active_scaffold.css.scss.erb similarity index 100% rename from app/assets/stylesheets/active_scaffold.css.erb rename to app/assets/stylesheets/active_scaffold.css.scss.erb From d7ca8758e270d225f6b7f634e2e79d750d530297 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 7 Feb 2012 10:18:11 +0100 Subject: [PATCH 1402/2024] fix working with require and @import --- ..._scaffold.css.scss.erb => active_scaffold.css.scss} | 10 +++++----- .../stylesheets/active_scaffold_extensions.css.erb | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) rename app/assets/stylesheets/{active_scaffold.css.scss.erb => active_scaffold.css.scss} (51%) create mode 100644 app/assets/stylesheets/active_scaffold_extensions.css.erb diff --git a/app/assets/stylesheets/active_scaffold.css.scss.erb b/app/assets/stylesheets/active_scaffold.css.scss similarity index 51% rename from app/assets/stylesheets/active_scaffold.css.scss.erb rename to app/assets/stylesheets/active_scaffold.css.scss index b6a1a39dd2..805a845703 100644 --- a/app/assets/stylesheets/active_scaffold.css.scss.erb +++ b/app/assets/stylesheets/active_scaffold.css.scss @@ -5,10 +5,10 @@ ActiveScaffold is freely distributable under the terms of an MIT-style license. For details, see the ActiveScaffold web site: http://www.activescaffold.com/ - *= require active_scaffold_layout - *= require active_scaffold_images */ + +@import 'active_scaffold_layout'; +@import 'active_scaffold_images'; +@import 'jquery-ui'; +@import 'active_scaffold_extensions'; @import 'active_scaffold_colors'; -<% require_asset "jquery-ui" %> -<% ActiveScaffold.stylesheets.each {|css| require_asset css} %> -<% ActiveScaffold::Bridges.all_stylesheets.each {|css| require_asset css} %> diff --git a/app/assets/stylesheets/active_scaffold_extensions.css.erb b/app/assets/stylesheets/active_scaffold_extensions.css.erb new file mode 100644 index 0000000000..b42b27de46 --- /dev/null +++ b/app/assets/stylesheets/active_scaffold_extensions.css.erb @@ -0,0 +1,2 @@ +<% ActiveScaffold.stylesheets.each {|css| require_asset css} %> +<% ActiveScaffold::Bridges.all_stylesheets.each {|css| require_asset css} %> From 6eeafaf67ba7ae8ea49065692b6124c9b1b6e794 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 14 Feb 2012 18:20:49 +0100 Subject: [PATCH 1403/2024] add send_form_selector option --- app/assets/javascripts/jquery/active_scaffold.js | 5 ++++- app/assets/javascripts/prototype/active_scaffold.js | 5 ++++- lib/active_scaffold/helpers/form_column_helpers.rb | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index fae704bff7..6f58a02ef5 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -749,7 +749,10 @@ var ActiveScaffold = { var params = null; if (send_form) { - params = as_form.serialize(); + var selector; + if (selector = element.data('update_send_form_selector')) + params = as_form.find(selector).serialize(); + else params = as_form.serialize(); params += '&' + jQuery.param({"source_id": source_id}); } else { params = {value: val}; diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index f8e79aa8a6..af8c945184 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -613,7 +613,10 @@ var ActiveScaffold = { var params = null; if (send_form) { - params = as_form.serialize(true); + var selector; + if (selector = element.readAttribute('data-update_send_form_selector')) + params = Form.serializeElements(as_form.getElementsBySelector(selector), true); + else params = as_form.serialize(true); } else { params = {value: val}; } diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 4e816657e5..7f997b715a 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -88,6 +88,7 @@ def update_columns_options(column, scope, options) options[:class] = "#{options[:class]} update_form".strip options['data-update_url'] = url_for(url_params) options['data-update_send_form'] = true if column.send_form_on_update_column + options['data-update_send_form_selector'] = column.options[:send_form_selector] if column.options[:send_form_selector] end options end From 5891e531f0749a9ceda0ce3f61200ab2af54ac8c Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Wed, 15 Feb 2012 07:11:23 -0800 Subject: [PATCH 1404/2024] as action aliases closes #138 --- .../bridges/cancan/cancan_bridge.rb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/active_scaffold/bridges/cancan/cancan_bridge.rb b/lib/active_scaffold/bridges/cancan/cancan_bridge.rb index ed94e88234..4737108ccc 100644 --- a/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +++ b/lib/active_scaffold/bridges/cancan/cancan_bridge.rb @@ -1,3 +1,23 @@ +# Allow users to easily define aliases for AS actions. +# Ability#as_action_aliases should be called by the user in his ability class +# +# class Ability < CanCan::Ability +# def initialize(user) +# as_action_aliases +# end +# end +# +module CanCan + module Ability + def as_action_aliases + alias_action :list, :row, :show_search, :render_field, :to => :read + alias_action :update_column, :add_association, :edit_associated, + :edit_associated, :new_existing, :add_existing, :to => :update + alias_action :delete, :destroy_existing, :to => :destroy + end + end +end + module ActiveScaffold::Bridges class Cancan From 89510ded462f56591c32dd4add5b3246a5be8180 Mon Sep 17 00:00:00 2001 From: Andrey Korobkov <korobkov@fryxell.info> Date: Sat, 18 Feb 2012 14:36:12 +0400 Subject: [PATCH 1405/2024] GIFs converted to PNGs, except animated. Fixes #25 --- app/assets/images/active_scaffold/add.gif | Bin 986 -> 0 bytes app/assets/images/active_scaffold/add.png | Bin 0 -> 679 bytes app/assets/images/active_scaffold/arrow_down.gif | Bin 853 -> 0 bytes app/assets/images/active_scaffold/arrow_down.png | Bin 0 -> 171 bytes app/assets/images/active_scaffold/arrow_up.gif | Bin 851 -> 0 bytes app/assets/images/active_scaffold/arrow_up.png | Bin 0 -> 172 bytes app/assets/images/active_scaffold/close.gif | Bin 960 -> 0 bytes app/assets/images/active_scaffold/close.png | Bin 0 -> 444 bytes .../stylesheets/active_scaffold_images.css.scss | 8 ++++---- 9 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 app/assets/images/active_scaffold/add.gif create mode 100644 app/assets/images/active_scaffold/add.png delete mode 100644 app/assets/images/active_scaffold/arrow_down.gif create mode 100644 app/assets/images/active_scaffold/arrow_down.png delete mode 100644 app/assets/images/active_scaffold/arrow_up.gif create mode 100644 app/assets/images/active_scaffold/arrow_up.png delete mode 100644 app/assets/images/active_scaffold/close.gif create mode 100644 app/assets/images/active_scaffold/close.png diff --git a/app/assets/images/active_scaffold/add.gif b/app/assets/images/active_scaffold/add.gif deleted file mode 100644 index 51e6a2d53a13122a3e85de3bb56c22fee79de313..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 986 zcmZ?wbhEHb6krfw_|CxKz`$VLYU0>q>eOfM)NSR`ZROr$@7`zU(QD`4>)=1bA!v$s z$W))Oxh}D@Lz3qQC(I2?nje<3Ff46hWcsS0lvN>FE5kEaM`f>!%-s^62SO3~+arp% zMHO$0F5D4Sv@^P3Z(P~#_>$FWWoy#QHz(I_$gJL(T(dj1W^Y=>p4^%pnKe7I>UQMh zA4sY=kX(HztMX`8?SYKi<9Usnb6d9-v~Mfx-c{PMx4d&lMbF-<iTmm%?W=7#Q_^~} zvh`$j%h`&~gB5)TYdTKUb)K)8c%**vzJ@9L8@o?8^qy(%z0@@Ac*~@-?bA=UPCL^w z{Y=~RGo6z!cTT<BG383<)GJ-nu6E71*fr<I#Q8U;%)dEx@wv%M&re-?Vd|3GvsPW1 zz4FSOb@!L7yT5ef?d6+pF4+u3x0Y@JvhS|ge0SxxTPwHTUA^W0>g{*e?YgsW+k<s` zA8p<9Wb2U^`%gbRbnfNJE3eOAe|PE5#~Tkm-TD9jKQO3A!C(sk#h)yU3=EYFIv|IE z@&p6Nc81R!G9DWi9JF!Ix^SYf-~pd*(Tg*Qmz$0pl+Jy3;N>J%pE(LbT%SCWpL0!C z30bC5csPmaplay`7s)1eegO&NYbFvIF1`{f_90jHC@{55RT5yiR1tjC{p|7zixWSJ z92RsMyHq)>J*n6#&cu}KFj45RE9*KLJBy146BJlY^qo2$%sS{ilaa-JjX>~}!)&~= t#}YgOJ~(n3`v=U)a60DH&@3pz@o*DsI|DN>tCd4Qg5$IE%*;#-)&TDaA-Mnm diff --git a/app/assets/images/active_scaffold/add.png b/app/assets/images/active_scaffold/add.png new file mode 100644 index 0000000000000000000000000000000000000000..2dd22829a973073ef452453a0a96df011eaa7256 GIT binary patch literal 679 zcmV;Y0$BZtP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00004b3#c}2nYxW zd<bNS00009a7bBm000ie000ie0hKEb8vp<TNl8ROR5*>Ll1oTbVHk#=GdiO)>WmJP zb}>Z_FD1DsBC(LbMYYWY7h&YCT1X_(mD)tustZ9`xQd{nO;$5uqY@@UpyHxLoAJ`1 zjyjj4Gdgq5oWGUFL}%r@{Jxj>d-(qswkavu;%WCi5sn5?wFK$L46dDgu%&m?@R9qD zuxIa}d}kGAV-|5O&fKz({xLVJ%L;Av&!waR55KmGs^V%&a}P2uk21UBL(vp$CL6it zJ@k#b7@P3$vgxg~Dd4gDw%C_nNoigcJu@z%ktm8#Nl#BhAc$!(Dy)_K_}ztnF35|f zHxhthEg;pLMv<d}@3UR3D62%36|Nk*#l-`ygknJgp;`K8dN^8kf{;3|QyT!DxbKR> z+%kTJM_7;-kfSo8<)Cizd8SZe5hC&;e`PN<Wi_0C)gS;;0RoXl_8TosE_sP-F>V~W zzu{q@)xQRy#o352=%Lban3-_*I)R!{i6~1f#buNfWvk!PB@!AE0wtlM6Ie`H_=1yU zrezX}259MRCgPWAKl@I<3}BE9?6ws!HRr`{v9A+cKiwt`c?Kx36d{xtQbNU^ld<8l zmJk>;iM`e$J`aE6{iRMxCjiKj91M*0P+d|---HuYQ)zKFA`$=slOcuLl2bSbJ248g z9=xGQ%^hci!;#JL@;au&UVK3>Let2%7n5%-<jc@UhR6TVck}1wBCY8{M}t_5`Khfq zMxJdK2$&8`;Tm*f!h-8+Z}KYtuXFA7VqW&6YARN94j(RmO6uK~{sCks`Q&bjxbpx2 N002ovPDHLkV1fllD%=17 literal 0 HcmV?d00001 diff --git a/app/assets/images/active_scaffold/arrow_down.gif b/app/assets/images/active_scaffold/arrow_down.gif deleted file mode 100644 index bcda8697b6ac9701b40499855afe5fc32a7f899e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 853 zcmZ?wbhEHb6kuRy_|CvkRaI42SJ&9sxN6m^U%!6+{rmSn7%+^2(GVB`A)xq^g^>Z6 z6?8y;1?33_4kHGB76FG12?rV2h16sM4m2EYXXD}tSTRBINQbaySk8-pMQ*)fwskC? P3XeT{8T{lpI2fz}7^o(6 diff --git a/app/assets/images/active_scaffold/arrow_down.png b/app/assets/images/active_scaffold/arrow_down.png new file mode 100644 index 0000000000000000000000000000000000000000..641047c2775f1afe269fd24c49872ba9c954e5db GIT binary patch literal 171 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~p!3HE570x;VDVAa<&kznEsNqQI0P;BtJR*x3 z82FBWFymBhK53w!ucwP+h{V*nXAHRx81Og;w%)nb%r5WlZo*NnC34Fub8FXsHijM5 zXDv6*QgJ!5LsrE*sC06O%Inbg6H@Oe-u@{3$#S34%%A#p>1oj)8TrM#)-}Fu;Q$)U N;OXk;vd$@?2>^7zGTZ<F literal 0 HcmV?d00001 diff --git a/app/assets/images/active_scaffold/arrow_up.gif b/app/assets/images/active_scaffold/arrow_up.gif deleted file mode 100644 index b5e3399e44967d6a029de64dd19ea9a653cc1c31..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 851 zcmZ?wbhEHb6kuRy_|CvkRaI42SJ&9sxN6m^U%!6+{rmSn7%+^2(GVB`A)xq^g^>Z6 z6?8y;1?33_4g&^$4jGPw1qYj%*aajS1Rgdpv2hvX%n(@A*dZ(%wWlLc`FOt&KbwHV Nrj(NmY|Kmy)&Qp2Bz6D* diff --git a/app/assets/images/active_scaffold/arrow_up.png b/app/assets/images/active_scaffold/arrow_up.png new file mode 100644 index 0000000000000000000000000000000000000000..acf046aa00aea79a6ce83b24ec462437e2a52e90 GIT binary patch literal 172 zcmeAS@N?(olHy`uVBq!ia0vp^0zk~p!3HE570x;VDVAa<&kznEsNqQI0P;BtJR*x3 z82FBWFymBhK53w!pQnpsh{V*XeFr%Y81OKEeQ`z7^RvXBZpRhtofi7exfA@1k6HMb z#Jsyv9=lfge6n%6G%4ryq;pF7KNGD#spq?g6^ZX;P*9pM^X>FWcDH$X7j~}<?MU?p Pn#|zo>gTe~DWM4fjnXy# literal 0 HcmV?d00001 diff --git a/app/assets/images/active_scaffold/close.gif b/app/assets/images/active_scaffold/close.gif deleted file mode 100644 index aa1b988cc99c95e9badcbd6ff2210ef7f990b310..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 960 zcmZ?wbhEHb6krf!_|Cu}R?IJ6%qLmSC0)rbSIZ<{&mdMHB9yKzoS`j}p(T;6Cz+!s zm9H;XsIOFPrdesNU1g)x$gJ7QZPhPt*x+Q_;p;J7KWx5z&g!DPbtSc1vs-o+Pd_tt z!O6+X&(7X+bMux*>$g4Lu=CmG{jatkzPtO_hrK61?LYtR$ocO_u0B71<K^XxKaO4c zdF=A96IXwqy!r3Ut^a4AeSG}o=jR{4zyJRG`~Uy{45MH)1ZWllIv|rld4YjrDMR86 z2FDEx90e334p;;>IyScpDC?d0pv1z&$YPXrN5bJChX6a9h=k{+Ck@Oj&eLKdAEbCq zWDQy|L7=gvYoeaxA(g<zhufqy3l?3mENbGBGR}w)_%&%syOgQjgflBQHLyw<rCix@ zU`hs~sHw@Ho{L*oaR~`#-OI7uqIG&5XTrWzZl@L|2Ifz%?q(lw<P?`su#xcDVZh2~ SAhh1$;Es)t#X6ap7_0%<wVQVU diff --git a/app/assets/images/active_scaffold/close.png b/app/assets/images/active_scaffold/close.png new file mode 100644 index 0000000000000000000000000000000000000000..caf633a8c9b76497892b9e005bc9f653ca4bfdd4 GIT binary patch literal 444 zcmV;t0Ym<YP)<h;3K|Lk000e1NJLTq000mG000pP0ssI2Tg|(Z00003b3#c}2nYz< z;ZNWI000SaNLh0L01m_e01m_fl`9S#0004BNkl<ZD3N2l_5bYq&!1j@_`rY{FflU9 zh>3Bqv9o;r{=H;c-`(erSeWo>`2G8TsFPcEKm^P4w{NaJxW~qSpMmWM9u5D#@vPdr zE6~Q7<=_AR|Nk>EG5uv^`iDmY3)|1{U;cjm@dK|ruzCiKzb)hZ&aBH^Y~0LD%uC{S z@65W4ZWS8;-M2S3N-pIt9Zx<yuu*ck_TmBo4dt6sc4b|OHp%$=@6Vrqe~LFG5OC7d z4-YqAS;4}@!p_2R@Xn6wFD??$pedmrVvz9l*O#xqzBsG-m@C*5&@drr2@4ZT=bnlQ z2O1z;0)Aj%U^sGb&(bq97#JArRXjv_BnW75pQa0E$1HNiG>(aZfq{wfKc)mOz{1MH z!otk*`xgg(b-%y!3h;0X@$s?9h>C?cxa>cF>fe8S_HYQWr}+en@Cz{B`hS*zf#Lhl mpa1^jO?=EO?5wN|3=9CbT7!uE>|aO#0000<MNUMnLSTa8YSV83 literal 0 HcmV?d00001 diff --git a/app/assets/stylesheets/active_scaffold_images.css.scss b/app/assets/stylesheets/active_scaffold_images.css.scss index ec20d4f9c0..67e8bb4958 100644 --- a/app/assets/stylesheets/active_scaffold_images.css.scss +++ b/app/assets/stylesheets/active_scaffold_images.css.scss @@ -8,7 +8,7 @@ .active-scaffold-header div.actions a.new, .active-scaffold-header div.actions a.new_existing { -background-image: image-url('active_scaffold/add.gif'); +background-image: image-url('active_scaffold/add.png'); } .active-scaffold-header div.actions a.show_search { @@ -17,12 +17,12 @@ background-image: image-url('active_scaffold/magnifier.png'); .active-scaffold th.asc a, .active-scaffold th.asc a:hover { -background-image: image-url('active_scaffold/arrow_up.gif'); +background-image: image-url('active_scaffold/arrow_up.png'); } .active-scaffold th.desc a, .active-scaffold th.desc a:hover { -background-image: image-url('active_scaffold/arrow_down.gif'); +background-image: image-url('active_scaffold/arrow_down.png'); } .active-scaffold th.loading a, @@ -31,7 +31,7 @@ background-image: image-url('active_scaffold/indicator-small.gif'); } .active-scaffold a.inline-adapter-close { -background-image: image-url('active_scaffold/close.gif'); +background-image: image-url('active_scaffold/close.png'); } .active-scaffold .sub-form .association-record a.destroy { From 5256e1e1d2c1014691c08d30a864208e799277f7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 22 Feb 2012 12:15:37 +0100 Subject: [PATCH 1406/2024] minor change --- lib/active_scaffold.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 73e9c2ed17..df0bb1992f 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -271,8 +271,8 @@ def link_for_association(column, options = {}) ActiveScaffold::DataStructures::ActionLink.new('index', options) #unless column.through_association? else - actions = [:create, :update, :show] actions = controller.active_scaffold_config.actions unless controller == :polymorph + actions ||= [:create, :update, :show] column.actions_for_association_links.delete :new unless actions.include? :create column.actions_for_association_links.delete :edit unless actions.include? :update column.actions_for_association_links.delete :show unless actions.include? :show From eec5640f200185d33ecacc26d230b1e4c8b1e124 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 22 Feb 2012 15:50:44 +0100 Subject: [PATCH 1407/2024] bitfields bridge --- lib/active_scaffold/bridges/bitfields.rb | 6 +++ .../bridges/bitfields/bitfields_bridge.rb | 37 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 lib/active_scaffold/bridges/bitfields.rb create mode 100644 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb diff --git a/lib/active_scaffold/bridges/bitfields.rb b/lib/active_scaffold/bridges/bitfields.rb new file mode 100644 index 0000000000..51fd4f045c --- /dev/null +++ b/lib/active_scaffold/bridges/bitfields.rb @@ -0,0 +1,6 @@ +class ActiveScaffold::Bridges::Bitfields < ActiveScaffold::DataStructures::Bridge + def self.install + require File.join(File.dirname(__FILE__), "bitfields/bitfields_bridge") + ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Bitfields::BitfieldsBridge + end +end diff --git a/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb b/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb new file mode 100644 index 0000000000..64676f4d8d --- /dev/null +++ b/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb @@ -0,0 +1,37 @@ +module ActiveScaffold + module Bridges + class Bitfields + module BitfieldsBridge + def initialize_with_bitfields(model_id) + initialize_without_bitfields(model_id) + return unless self.model.respond_to?(:bitfields) and self.model.bitfields.present? + + self.model.bitfields.each do |column_name, options| + self.columns << options.keys + options.each do |column, value| + self.columns[column].form_ui = :checkbox + self.columns[column].weight = 1000 + value.to_s(2).size + end + end + end + + def _load_action_columns_with_bitfields + self.model.bitfields.each do |column_name, options| + columns = options.keys.sort_by { |column| self.columns[column].weight } + [:create, :update, :show, :subform].each do |action| + self.send(action).columns.add_subgroup(column_name) { |group| group.add *columns } + end + end if self.model.respond_to?(:bitfields) and self.model.bitfields.present? + + _load_action_columns_without_bitfields + end + + + def self.included(base) + base.alias_method_chain :initialize, :bitfields + base.alias_method_chain :_load_action_columns, :bitfields + end + end + end + end +end From ab2dae8cc7da5957720bf911d0a66785056fc70e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 22 Feb 2012 16:10:39 +0100 Subject: [PATCH 1408/2024] add filters for loading new png icons in IE6 --- app/assets/stylesheets/active_scaffold-ie.css | 35 ------------ .../stylesheets/active_scaffold-ie.css.scss | 54 +++++++++++++++++++ 2 files changed, 54 insertions(+), 35 deletions(-) delete mode 100644 app/assets/stylesheets/active_scaffold-ie.css create mode 100644 app/assets/stylesheets/active_scaffold-ie.css.scss diff --git a/app/assets/stylesheets/active_scaffold-ie.css b/app/assets/stylesheets/active_scaffold-ie.css deleted file mode 100644 index 7992a64468..0000000000 --- a/app/assets/stylesheets/active_scaffold-ie.css +++ /dev/null @@ -1,35 +0,0 @@ -/* IE hacks - ==================================== */ - -* html .active-scaffold-header, -.active-scaffold li.form-element, -.active-scaffold li.sub-section { -zoom: 1; -} - -* html .active-scaffold td .messages-container { -border-top: solid 1px #DAFFCD; -} - -* html .active-scaffold-header div.actions a.show_search { -background-image: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../../images/active_scaffold/default/magnifier.png', sizingMethod='crop'); -} - -* html .active-scaffold .sub-form .association-record a.destroy { -background-image: none; -filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../../images/active_scaffold/default/cross.png', sizingMethod='crop'); -} - -.active-scaffold-header div.actions a.disabled { -filter: alpha(opacity=50); -} - -.active-scaffold .show-view dd, -.active-scaffold li.form-element dd { -float: none; -} - -.active-scaffold li.form-element dt { -padding: 4px 0; -} diff --git a/app/assets/stylesheets/active_scaffold-ie.css.scss b/app/assets/stylesheets/active_scaffold-ie.css.scss new file mode 100644 index 0000000000..753b33ab27 --- /dev/null +++ b/app/assets/stylesheets/active_scaffold-ie.css.scss @@ -0,0 +1,54 @@ +/* IE hacks + ==================================== */ + +* html .active-scaffold-header, +.active-scaffold li.form-element, +.active-scaffold li.sub-section { +zoom: 1; +} + +* html .active-scaffold td .messages-container { +border-top: solid 1px #DAFFCD; +} + +* html .active-scaffold-header div.actions a.show_search { +background-image: none; +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='#{image_path('active_scaffold/magnifier.png')}', sizingMethod='crop'); +} + +* html .active-scaffold .sub-form .association-record a.destroy { +background-image: none; +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='#{image_path('active_scaffold/cross.png')}', sizingMethod='crop'); +} +* html .active-scaffold-header div.actions a.new, +* html .active-scaffold-header div.actions a.new_existing { +background-image: none; +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='#{image_path('active_scaffold/add.png')}', sizingMethod='crop'); +} +* html .active-scaffold-header th.asc a, +* html .active-scaffold-header th.asc a:hover { +background-image: none; +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='#{image_path('active_scaffold/arrow_up.png')}', sizingMethod='crop'); +} +* html .active-scaffold-header th.desc a, +* html .active-scaffold-header th.desc a:hover { +background-image: none; +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='#{image_path('active_scaffold/arrow_down.png')}', sizingMethod='crop'); +} +* html .active-scaffold-header a.inline-adapter-close { +background-image: none; +filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='#{image_path('active_scaffold/close.png')}', sizingMethod='crop'); +} + +.active-scaffold-header div.actions a.disabled { +filter: alpha(opacity=50); +} + +.active-scaffold .show-view dd, +.active-scaffold li.form-element dd { +float: none; +} + +.active-scaffold li.form-element dt { +padding: 4px 0; +} From 0d6048b0dfe85d5e9a25417b907c5d39c78eb6b9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 23 Feb 2012 17:06:57 +0100 Subject: [PATCH 1409/2024] clean styles --- app/assets/stylesheets/active_scaffold_images.css.scss | 9 +++------ app/assets/stylesheets/active_scaffold_layout.css | 5 +---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/app/assets/stylesheets/active_scaffold_images.css.scss b/app/assets/stylesheets/active_scaffold_images.css.scss index 67e8bb4958..0ecf5fc96c 100644 --- a/app/assets/stylesheets/active_scaffold_images.css.scss +++ b/app/assets/stylesheets/active_scaffold_images.css.scss @@ -15,18 +15,15 @@ background-image: image-url('active_scaffold/add.png'); background-image: image-url('active_scaffold/magnifier.png'); } -.active-scaffold th.asc a, -.active-scaffold th.asc a:hover { +.active-scaffold th.asc a { background-image: image-url('active_scaffold/arrow_up.png'); } -.active-scaffold th.desc a, -.active-scaffold th.desc a:hover { +.active-scaffold th.desc a { background-image: image-url('active_scaffold/arrow_down.png'); } -.active-scaffold th.loading a, -.active-scaffold th.loading a:hover { +.active-scaffold th.loading a { background-image: image-url('active_scaffold/indicator-small.gif'); } diff --git a/app/assets/stylesheets/active_scaffold_layout.css b/app/assets/stylesheets/active_scaffold_layout.css index 4a5b8b4fcd..973f030064 100644 --- a/app/assets/stylesheets/active_scaffold_layout.css +++ b/app/assets/stylesheets/active_scaffold_layout.css @@ -172,11 +172,8 @@ padding-right: 18px; } .active-scaffold th.asc a, -.active-scaffold th.asc a:hover, .active-scaffold th.desc a, -.active-scaffold th.desc a:hover, -.active-scaffold th.loading a, -.active-scaffold th.loading a:hover { +.active-scaffold th.loading a { background: right 50% no-repeat; } From 6cb0fbc59db5c24f2490c5e6594f6c9444a73173 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 28 Feb 2012 17:06:34 +0100 Subject: [PATCH 1410/2024] fix reset search --- frontends/default/views/_field_search.html.erb | 2 +- frontends/default/views/_search.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_field_search.html.erb b/frontends/default/views/_field_search.html.erb index d4223d1947..674fca40ef 100644 --- a/frontends/default/views/_field_search.html.erb +++ b/frontends/default/views/_field_search.html.erb @@ -25,7 +25,7 @@ form_tag url_options, options %> </ol> <p class="form-footer"> <%= submit_tag as_(:search), :class => "submit" %> - <%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel', :remote => true %> + <%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel', :remote => true, :data => {:refresh => true} %> <%= loading_indicator_tag(:action => :search) %> </p> </form> diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index 489339702f..4563fbc7a5 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -9,7 +9,7 @@ options['data-loading'] = true unless live_search form_tag url_options, options %> <%= text_field_tag :search, search_params, :class => 'text-input', :id => search_input_id, :size => 50, :autocomplete => :off %> <%= submit_tag as_(:search), :class => "submit" %> - <%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel', :remote => true %> + <%= link_to as_(:reset), url_for(url_options.merge(:search => '')), :class => 'as_cancel', :remote => true, :data => {:refresh => true} %> <%= loading_indicator_tag(:action => :search) %> </form> From 86348552c09a64db00e3b5375562c5e4664ebdde Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 28 Feb 2012 17:19:35 +0100 Subject: [PATCH 1411/2024] primary_key_name doesn't exist in 3.2 --- frontends/default/views/_form_attribute.html.erb | 2 +- lib/active_scaffold/bridges/record_select/helpers.rb | 2 +- lib/active_scaffold/helpers/search_column_helpers.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_form_attribute.html.erb b/frontends/default/views/_form_attribute.html.erb index b550557a3a..1c26eda766 100644 --- a/frontends/default/views/_form_attribute.html.erb +++ b/frontends/default/views/_form_attribute.html.erb @@ -8,7 +8,7 @@ <%=raw active_scaffold_input_for column, scope %> <% else %> <%= get_column_value(@record, column) %> - <%= hidden_field :record, column.association ? column.association.primary_key_name : column.name, active_scaffold_input_options(column, scope) -%> + <%= hidden_field :record, column.association ? column.association.foreign_key : column.name, active_scaffold_input_options(column, scope) -%> <% end %> <% if column.update_columns -%> <%= loading_indicator_tag(:action => :render_field, :id => params[:id]) %> diff --git a/lib/active_scaffold/bridges/record_select/helpers.rb b/lib/active_scaffold/bridges/record_select/helpers.rb index 39eaf78b1b..795734110b 100644 --- a/lib/active_scaffold/bridges/record_select/helpers.rb +++ b/lib/active_scaffold/bridges/record_select/helpers.rb @@ -30,7 +30,7 @@ def active_scaffold_record_select(column, options, value, multiple) # if the opposite association is a :belongs_to (in that case association in this class must be has_one or has_many) # then only show records that have not been associated yet if [:has_one, :has_many].include?(column.association.macro) - params.merge!({column.association.primary_key_name => ''}) + params.merge!({column.association.foreign_key => ''}) end record_select_options = active_scaffold_input_text_options(options).merge( diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index abaaaa3acc..756e5d0a6e 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -133,7 +133,7 @@ def active_scaffold_search_range_string?(column) def include_null_comparators?(column) return column.options[:null_comparators] if column.options.has_key? :null_comparators if column.association - column.association.macro != :belongs_to || active_scaffold_config.columns[column.association.primary_key_name].column.try(:null) + column.association.macro != :belongs_to || active_scaffold_config.columns[column.association.foreign_key].column.try(:null) else column.column.try(:null) end @@ -153,7 +153,7 @@ def active_scaffold_search_range_comparator_options(column) def include_null_comparators?(column) return column.options[:null_comparators] if column.options.has_key? :null_comparators if column.association - column.association.macro != :belongs_to || active_scaffold_config.columns[column.association.primary_key_name].column.try(:null) + column.association.macro != :belongs_to || active_scaffold_config.columns[column.association.foreign_key].column.try(:null) else column.column.try(:null) end From f5931395ab3b9ecb1cecb757b3831b8fb56babc1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 28 Feb 2012 17:39:12 +0100 Subject: [PATCH 1412/2024] clean html for date search --- .../bridges/calendar_date_select/as_cds_bridge.rb | 2 +- lib/active_scaffold/bridges/date_picker/helper.rb | 2 +- lib/active_scaffold/bridges/shared/date_bridge.rb | 8 ++++---- lib/active_scaffold/helpers/search_column_helpers.rb | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb index 2568613cff..329c927927 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb @@ -44,7 +44,7 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current :class => 'text-input', :id => "#{options[:id]}_#{name}", :time => column_datetime?(column) ? true : false, - :style => "display:#{(options[:show].nil? || options[:show]) ? '' : 'none'}"}) + :style => (options[:show].nil? || options[:show]) ? nil : "display: none"}) end end end diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index d6aa61d733..e9240215f9 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -157,7 +157,7 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current options = column.options.merge(options).except!(:include_blank, :discard_time, :discard_date, :value) options = active_scaffold_input_text_options(options.merge(column.options)) options[:class] << " #{column.search_ui.to_s}" - options[:style] = "display:#{(options[:show].nil? || options[:show]) ? '' : 'none'}" + options[:style] = (options[:show].nil? || options[:show]) ? nil : "display: none" format = options.delete(:format) || :default datepicker_format_options(column, format, options) text_field_tag("#{options[:name]}[#{name}]", value ? l(value, :format => format) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index 92bcd40b58..90fd33e297 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -28,8 +28,8 @@ def active_scaffold_search_date_bridge_numeric_tag(column, options, current_sear numeric_controls = "" << active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'from') << content_tag(:span, (" - " + active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'to')).html_safe, - :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => "display:#{current_search['opt'] == 'BETWEEN' ? '' : 'none'}") - content_tag("span", numeric_controls.html_safe, :id => "#{options[:id]}_numeric", :style => "display:#{ActiveScaffold::Finder::NumericComparators.include?(current_search['opt']) ? '' : 'none'}") + :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => current_search['opt'] == 'BETWEEN' ? nil : "display: none") + content_tag("span", numeric_controls.html_safe, :id => "#{options[:id]}_numeric", :style => ActiveScaffold::Finder::NumericComparators.include?(current_search['opt']) ? nil : "display: none") end def active_scaffold_search_date_bridge_trend_tag(column, options, current_search) @@ -45,7 +45,7 @@ def active_scaffold_date_bridge_trend_tag(column, options, trend_options) select_tag("#{trend_options[:name_prefix]}[#{column.name}][unit]", options_for_select(active_scaffold_search_date_bridge_trend_units(column), trend_options[:unit_value]), :class => 'text-input') - content_tag("span", trend_controls.html_safe, :id => "#{options[:id]}_trend", :style => "display:#{trend_options[:show] ? '' : 'none'}") + content_tag("span", trend_controls.html_safe, :id => "#{options[:id]}_trend", :style => trend_options[:show] ? nil : "display: none") end def active_scaffold_search_date_bridge_trend_units(column) @@ -58,7 +58,7 @@ def active_scaffold_search_date_bridge_range_tag(column, options, current_search range_controls = select_tag("search[#{column.name}][range]", options_for_select( ActiveScaffold::Finder::DateRanges.collect{|range| [as_(range.downcase.to_sym), range]}, current_search["range"]), :class => 'text-input') - content_tag("span", range_controls.html_safe, :id => "#{options[:id]}_range", :style => "display:#{(current_search['opt'] == 'RANGE') ? '' : 'none'}") + content_tag("span", range_controls.html_safe, :id => "#{options[:id]}_range", :style => (current_search['opt'] == 'RANGE') ? nil : "display: none") end def column_datetime?(column) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 756e5d0a6e..8ca4168a15 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -182,7 +182,7 @@ def active_scaffold_search_range(column, options) html << ' ' << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(:id => options[:id], :size => text_field_size)) html << ' ' << content_tag(:span, (' - ' + text_field_tag("#{options[:name]}[to]", to_value, active_scaffold_input_text_options(:id => "#{options[:id]}_to", :size => text_field_size))).html_safe, - :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => "display:#{(opt_value == 'BETWEEN') ? '' : 'none'}") + :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => (opt_value == 'BETWEEN') ? nil : "display: none") content_tag :span, html, :class => 'search_range' end alias_method :active_scaffold_search_integer, :active_scaffold_search_range From dd0c412bfc0332d23f93dbaf5ac465953a637232 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 6 Mar 2012 10:15:41 +0100 Subject: [PATCH 1413/2024] update readme --- README | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/README b/README index 9962fa293d..f3dd4de695 100644 --- a/README +++ b/README @@ -18,9 +18,16 @@ http://code.google.com/p/recordselect/ == Version Information -Please note the following list of Active Scaffold branches and Rails versions. Master will not work with Rails < 3.1 +If you want to use the gem, add to your Gemfile: + gem "active_scaffold" + +In case you would like to use most recent commit: + gem 'active_scaffold', :git => 'git://github.com/activescaffold/active_scaffold.git' + +3.1.* and 3.2.* versions works with rails 3.1 and 3.2, 3.0.* versions with rails 3.0. +To use previous rails versions you will have to install the right branch as a plugin. -Active Scaffold master currently supports rails-3.1, but incompatible changes can be introduced, if you want an stable version, use rails-3.0 +Active Scaffold master currently supports rails 3.1 and rails 3.2, you can use following branches for previous rails versions: Rails 3.0.*: Active Scaffold rails-3.0 Rails 2.3.*: Active Scaffold rails-2.3 and v2.4 Rails 2.2.*: Active Scaffold rails-2.2 @@ -31,19 +38,13 @@ Since Rails 2.3, render_component plugin is needed for nested and embedded scaff script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3 Since Rails 3.0 render_component is not used for nesting, but is optional for embedded scaffolds. -Since Rails 3.0, https://github.com/rails/verification.git is also needed. +For Rails 3.0, https://github.com/rails/verification.git is also needed, not in rails 3.1 or higher. If you want to install as plugins under vendor/plugins, install these versions: rails plugin install git://github.com/vhochstein/render_component.git rails plugin install git://github.com/rails/verification.git rails plugin install git://github.com/activescaffold/active_scaffold.git -r 'rails-3.0' -If you want to use the gem, add to your Gemfile: - gem "active_scaffold" - -In case you would like to use most recent commit: - gem 'active_scaffold', :git => 'git://github.com/activescaffold/active_scaffold.git', :branch => 'rails-3.0' - == Pick your own javascript framework The Rails 3.0 version uses unobtrusive Javascript, so you are free to pick your javascript framework. @@ -66,8 +67,4 @@ To configure the javascript framework when installed as a gem: Add a config/initializers/active_scaffold.rb containing: ActiveScaffold.js_framework = :jquery # :prototype is the default -== Rails 3.1 compatible branch: -under construction - - Released under the MIT license (included) From a778bdb31fcdb7e2ff94f05aa1e279e66ac99c17 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 6 Mar 2012 12:27:14 +0100 Subject: [PATCH 1414/2024] cleanup order code --- lib/active_scaffold/finder.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 34541a65ad..aaac9b1ed7 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -265,7 +265,7 @@ def finder_options(options = {}) full_includes = (active_scaffold_includes.blank? ? nil : active_scaffold_includes) # create a general-use options array that's compatible with Rails finders - finder_options = { :order => options[:sorting].try(:clause), + finder_options = { :reorder => options[:sorting].try(:clause), :where => search_conditions, :joins => joins_for_finder, :includes => full_includes} @@ -278,7 +278,7 @@ def finder_options(options = {}) # See finder_options for valid options def count_options(find_options = {}, count_includes = nil) count_includes ||= find_options[:includes] unless find_options[:where].nil? - options = find_options.reject{|k,v| [:select, :order].include? k} + options = find_options.reject{|k,v| [:select, :reorder].include? k} options[:includes] = count_includes options end @@ -320,14 +320,8 @@ def find_page(options = {}) end def append_to_query(query, options) - options.assert_valid_keys :where, :select, :group, :order, :limit, :offset, :joins, :includes, :lock, :readonly, :from + options.assert_valid_keys :where, :select, :group, :reorder, :limit, :offset, :joins, :includes, :lock, :readonly, :from options.reject{|k, v| v.blank?}.inject(query) do |query, (k, v)| - # default ordering of model has a higher priority than current queries ordering - # fix this by removing existing ordering from arel - if k.to_sym == :order - query = query.where('1=1') unless query.is_a?(ActiveRecord::Relation) - query = query.except(:order) - end query.send((k.to_sym), v) end end From 7cdd35ce6c02b9eeab3b61a360f7b66cbe84aebe Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 6 Mar 2012 12:27:34 +0100 Subject: [PATCH 1415/2024] fix rails 3.2 deprecations --- lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/actions/list.rb | 2 +- lib/active_scaffold/actions/subform.rb | 2 +- lib/active_scaffold/actions/update.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index eea51255db..197438d579 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -34,7 +34,7 @@ def new_respond_to_js def create_respond_to_html if params[:iframe]=='true' # was this an iframe post ? responds_to_parent do - render :action => 'on_create.js', :layout => false + render :action => 'on_create', :format => [:js], :layout => false end else if successful? diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 47956ac7c4..14171058e1 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -36,7 +36,7 @@ def list_respond_to_js params.delete(:embedded) render(:partial => 'list_with_header') else - render :action => 'refresh_list.js' + render :action => 'refresh_list', :format => [:js] end end def list_respond_to_xml diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index 268b40600e..7364299df9 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -2,7 +2,7 @@ module ActiveScaffold::Actions module Subform def edit_associated do_edit_associated - render :action => 'edit_associated.js' + render :action => 'edit_associated', :format => [:js] end protected diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 2871214886..732d477682 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -35,7 +35,7 @@ def edit_respond_to_js def update_respond_to_html if params[:iframe]=='true' # was this an iframe post ? responds_to_parent do - render :action => 'on_update.js', :layout => false + render :action => 'on_update', :format => [:js], :layout => false end else # just a regular post if successful? From cc11f74e6ee2853bd0137ce6cb9fe1b7a8a761c7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 6 Mar 2012 12:33:41 +0100 Subject: [PATCH 1416/2024] fix set column sorting to sort in multiple columns --- lib/active_scaffold/data_structures/sorting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index dfcf5a5552..1038e3a196 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -95,7 +95,7 @@ def clause sql = sort_column.sort[:sql] next if sql.nil? or sql.empty? - order << "#{sql} #{sort_direction}" + order << Array(sql).map {|column| "#{column} #{sort_direction}"}.join(', ') end order.join(', ') unless order.empty? From fd5d0e816b6052ea7883fc8cb0a51996a9d72c0d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 6 Mar 2012 12:55:18 +0100 Subject: [PATCH 1417/2024] set colspan to list columns number, fix problem with table-layout: fixed in css --- frontends/default/views/_list_inline_adapter.html.erb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index 477f71c9bb..f9954bb387 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -1,6 +1,13 @@ +<% + column_count = if nested? + active_scaffold_config_for(nested.parent_model).list.columns.count + 1 + else + active_scaffold_config.list.columns.count + 1 + end +%> <%# nested_id, allows us to remove a nested scaffold programmatically %> <tr class="inline-adapter" id="<%= element_row_id :action => :nested %>"> - <td colspan="99" class="inline-adapter-cell"> + <td colspan="<%= column_count %>" class="inline-adapter-cell"> <div class="<%= "#{params[:action]}-view" if params[:action] %> <%= "#{nested? ? nested.name : id_from_controller(params[:controller])}-view" %> view"> <%= link_to(as_(:close), '', :class => 'inline-adapter-close as_cancel', :remote => true, :title => as_(:close), 'data-refresh' => (action_name == 'index' ? true : false)) -%> <%= payload -%> From 1844a67ddb2d0ca6769f6b0432d200968d08e96d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 6 Mar 2012 13:19:55 +0100 Subject: [PATCH 1418/2024] register_constraints_with_action_columns is not needed as a filter, it's called in nested and update --- lib/active_scaffold/actions/core.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 53aff90bdc..46f85192b9 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -2,7 +2,6 @@ module ActiveScaffold::Actions module Core def self.included(base) base.class_eval do - before_filter :register_constraints_with_action_columns after_filter :clear_flashes end base.helper_method :nested? From 99996330a0e87e440d741403c31b03c0abe18194 Mon Sep 17 00:00:00 2001 From: vhochstein <v.hochstein@highstone.de> Date: Wed, 8 Feb 2012 18:45:04 +0100 Subject: [PATCH 1419/2024] Performance: do not rebuild sorting everytime column_class is called --- lib/active_scaffold/config/list.rb | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 62a9becd32..4988ee7f84 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -142,6 +142,11 @@ def hide_nested_column attr_accessor :nested_auto_open class UserSettings < UserSettings + def initialize(conf, storage, params) + super(conf,storage,params) + @sorting = nil + end + # This label has alread been localized. def label @session[:label] ? @session[:label] : @conf.label @@ -173,17 +178,20 @@ def default_sorting end def sorting - # we want to store as little as possible in the session, but we want to return a Sorting data structure. so we recreate it each page load based on session data. - @session['sort'] = [@params['sort'], @params['sort_direction']] if @params['sort'] and @params['sort_direction'] - @session['sort'] = nil if @params['sort_direction'] == 'reset' - - if @session['sort'] - sorting = @conf.sorting.clone - sorting.set(*@session['sort']) - return sorting - else - return default_sorting + if @sorting.nil? + # we want to store as little as possible in the session, but we want to return a Sorting data structure. so we recreate it each page load based on session data. + @session['sort'] = [@params['sort'], @params['sort_direction']] if @params['sort'] and @params['sort_direction'] + @session['sort'] = nil if @params['sort_direction'] == 'reset' + + if @session['sort'] + sorting = @conf.sorting.clone + sorting.set(*@session['sort']) + @sorting = sorting + else + @sorting = default_sorting + end end + @sorting end def count_includes From ad6986d866a94d6d888f763d9886329041b34aa4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 6 Mar 2012 17:38:01 +0100 Subject: [PATCH 1420/2024] remove vhochstein wiki reference, our doc is on our wiki --- README | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README b/README index f3dd4de695..4abe558b79 100644 --- a/README +++ b/README @@ -1,7 +1,3 @@ -****************************************************************************************************** -** For all documentation see the project website: http://github.com/vhochstein/active_scaffold/wiki ** -****************************************************************************************************** - ActiveScaffold Gem/Plugin by Scott Rutherford (scott@caronsoftware.com), Richard White (rrwhite@gmail.com), Lance Ivy (lance@cainlevy.net), Ed Moss, Tim Harper and Sergio Cambra (sergio@entrecables.com) Uses DhtmlHistory by Brad Neuberg (bkn3@columbia.edu) From d0991f33348f545ace1da15a62c7c5bfd78c3263 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <nicolae_claudius@yahoo.com> Date: Thu, 8 Mar 2012 02:07:25 -0800 Subject: [PATCH 1421/2024] Per model list_row_class configuration --- frontends/default/views/_list_record.html.erb | 3 +-- lib/active_scaffold/helpers/view_helpers.rb | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 3455e94361..0618e5bf59 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -1,8 +1,7 @@ <% record = list_record if list_record # compat with render :partial :collection columns ||= list_columns -tr_class = cycle("", "even-record") -tr_class += " #{list_row_class(record)}" if respond_to? :list_row_class +tr_class = cycle("", "even-record") + ' ' + list_row_class(record) url_options = params_for(:action => :list, :id => record.id) action_links ||= active_scaffold_config.action_links.member -%> diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index e59acefc47..5f17906cc9 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -210,6 +210,11 @@ def url_options_for_sti_link(column, record, link, url_options, options = {}) end end + def list_row_class(record) + class_override_helper = :"#{clean_class_name(record.class.name)}_list_row_class" + respond_to?(class_override_helper) ? send(class_override_helper, record) : '' + end + def column_class(column, column_value, record) classes = [] classes << "#{column.name}-column" From b1a541eea0b57f8fb645c8d7be4bb1b8ca68b1b1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 9 Mar 2012 10:37:50 +0100 Subject: [PATCH 1422/2024] fix render field for existing records, it wasn't loading the record --- lib/active_scaffold/actions/core.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 46f85192b9..f84e5ac525 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -36,15 +36,17 @@ def render_field_for_update_columns @scope = params[:scope] if column.send_form_on_update_column - hash = if @scope - @scope.gsub('[','').split(']').inject(params[:record]) do |hash, index| + if @scope + hash = @scope.gsub('[','').split(']').inject(params[:record]) do |hash, index| hash[index] end + id = hash[:id] else - params[:record] + hash = params[:record] + id = params[:id] end - @record = hash[:id] ? find_if_allowed(hash[:id], :update) : new_model - @record = update_record_from_params(@record, active_scaffold_config.send(@scope ? :subform : (params[:id] ? :update : :create)).columns, hash) + @record = id ? find_if_allowed(id, :update) : new_model + @record = update_record_from_params(@record, active_scaffold_config.send(@scope ? :subform : (id ? :update : :create)).columns, hash) else @record = new_model value = column_value_from_param_value(@record, column, params[:value]) From 3401322504979e46e4e414e17e40810e033276b0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 9 Mar 2012 10:38:18 +0100 Subject: [PATCH 1423/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 2ed42ea0b1..7fb7346d90 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 0 + PATCH = 1 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 76bb16c3644f68a77fd0716b9da4cff129b34116 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 12 Mar 2012 13:38:09 +0100 Subject: [PATCH 1424/2024] fix colspan for edit in nested scaffolds, it fixes #148 --- frontends/default/views/_list_inline_adapter.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index f9954bb387..1990cf9d02 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -1,5 +1,5 @@ <% - column_count = if nested? + column_count = if nested? and action_name == 'index' active_scaffold_config_for(nested.parent_model).list.columns.count + 1 else active_scaffold_config.list.columns.count + 1 From 5675a858b14aaddf42d15e11ff1a379c4243180a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Mar 2012 09:20:07 +0100 Subject: [PATCH 1425/2024] fix previous commit, it's :formats, not :format --- lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/actions/list.rb | 2 +- lib/active_scaffold/actions/subform.rb | 2 +- lib/active_scaffold/actions/update.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 197438d579..5340e3e32b 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -34,7 +34,7 @@ def new_respond_to_js def create_respond_to_html if params[:iframe]=='true' # was this an iframe post ? responds_to_parent do - render :action => 'on_create', :format => [:js], :layout => false + render :action => 'on_create', :formats => [:js], :layout => false end else if successful? diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 14171058e1..188094a828 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -36,7 +36,7 @@ def list_respond_to_js params.delete(:embedded) render(:partial => 'list_with_header') else - render :action => 'refresh_list', :format => [:js] + render :action => 'refresh_list', :formats => [:js] end end def list_respond_to_xml diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index 7364299df9..e0151c061c 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -2,7 +2,7 @@ module ActiveScaffold::Actions module Subform def edit_associated do_edit_associated - render :action => 'edit_associated', :format => [:js] + render :action => 'edit_associated', :formats => [:js] end protected diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 732d477682..dc48663279 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -35,7 +35,7 @@ def edit_respond_to_js def update_respond_to_html if params[:iframe]=='true' # was this an iframe post ? responds_to_parent do - render :action => 'on_update', :format => [:js], :layout => false + render :action => 'on_update', :formats => [:js], :layout => false end else # just a regular post if successful? From 254cc2a0e51a58ca0bbc75a0e415b50d1ea164de Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 15 Mar 2012 13:15:27 +0100 Subject: [PATCH 1426/2024] don't delete associated records if column is not in the hash, try to fix #144 --- frontends/default/views/_form_association.html.erb | 2 ++ lib/active_scaffold/attribute_params.rb | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index 65e191950f..ee60ccda1b 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -9,6 +9,8 @@ subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_reco -%> <h5><%= column.label -%></h5> <div id ="<%= subform_div_id %>" <%= 'style="display: none;"'.html_safe if column.collapsed -%>> +<%# HACK to be able to delete all associated records %> +<%= hidden_field_tag "#{active_scaffold_input_options(column)[:name]}[0]", '' if column.plural_association? %> <%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record} %> </div> <%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%> diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index d9cb5a91e0..3144b9f152 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -60,9 +60,6 @@ def update_record_from_params(parent_record, columns, attributes) # we avoid assigning a value that already exists because otherwise has_one associations will break (AR bug in has_one_association.rb#replace) parent_record.send("#{column.name}=", value) unless parent_record.send(column.name) == value - - elsif column.plural_association? - parent_record.send("#{column.name}=", []) end end @@ -139,7 +136,8 @@ def column_value_from_param_hash_value(parent_record, column, value) elsif column.singular_association? manage_nested_record_from_params(parent_record, column, value) elsif column.plural_association? - value.collect {|key_value_pair| manage_nested_record_from_params(parent_record, column, key_value_pair[1])}.compact + # HACK to be able to delete all associated records, hash will include "0" => "" + value.collect {|key, value| manage_nested_record_from_params(parent_record, column, value) unless value == ""}.compact else value end From 08dcd3aaddd53c9069e94c1d2994417e925b7b02 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 15 Mar 2012 14:09:54 +0100 Subject: [PATCH 1427/2024] prepare 3.2.2 --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 7fb7346d90..6c45ebfe64 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 1 + PATCH = 2 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From ee77509e80ade05f648b0e89e4d9b2909aab0949 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <claudius.nicolae@gmail.com> Date: Sat, 17 Mar 2012 04:15:14 -0700 Subject: [PATCH 1428/2024] refactor --- frontends/default/views/_horizontal_subform.html.erb | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index a5f5304ef8..646bd21412 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -1,15 +1,5 @@ <table cellpadding="0" cellspacing="0"> - <% - @record = if associated.empty? - if column.singular_association? - parent_record.send("build_#{column.name}".to_sym) - else - parent_record.send(column.name).build - end - else - associated.last - end - -%> + <% @record = associated.empty? ? build_associated(column, parent_record) : associated.last -%> <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record, :record => @record} %> <tbody id="<%= sub_form_list_id(:association => column.name) %>"> From 706e42a7ab9d42f8ed822fab0481544f21b99d42 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <claudius.nicolae@gmail.com> Date: Sat, 17 Mar 2012 04:22:59 -0700 Subject: [PATCH 1429/2024] refactor and update vertical subform authorization as per 2326f7843b22e3fd65da45affd751fd6e6268909 and 791d68df112188e02434b6486c5f89b6fe704787 --- .../views/_horizontal_subform_record.html.erb | 23 +++++++++++-------- .../views/_vertical_subform_record.html.erb | 11 ++++++--- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index 9b3d4ba40a..578eb54701 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -1,12 +1,12 @@ <% - record_column = column - readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) - crud_type = @record.new_record? ? :create : (readonly ? :read : :update) - show_actions = false - config = active_scaffold_config_for(@record.class) - options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) - tr_id = "association-#{options[:id]}" -%> + record_column = column + readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) + crud_type = @record.new_record? ? :create : (readonly ? :read : :update) + show_actions = false + config = active_scaffold_config_for(@record.class) + options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) + tr_id = "association-#{options[:id]}" +-%> <tr id="<%= tr_id %>" class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> <% config.subform.columns.each :for => @record.class, :crud_type => :read, :flatten => true do |column| %> <% @@ -14,8 +14,13 @@ show_actions = true column = column.clone column.form_ui ||= :select if column.association + + col_class = [] + col_class << 'required' if column.required? + col_class << column.css_class unless column.css_class.nil? + col_class = 'hidden' if column_renders_as(column) == :hidden -%> - <td<%= ' class="hidden"'.html_safe if column_renders_as(column) == :hidden %>> + <td class="<%= col_class.join(' ') %>"> <% unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) -%> <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%> <% else -%> diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index 30285ddac9..7965b3cf6a 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -8,15 +8,20 @@ tr_id = "association-#{options[:id]}" -%> <ol id="<%= tr_id %>" class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> -<% config.subform.columns.each :for => @record, :crud_type => crud_type, :flatten => true do |column| %> +<% config.subform.columns.each :for => @record.class, :crud_type => :read, :flatten => true do |column| %> <% next unless in_subform?(column, parent_record) show_actions = true column = column.clone column.form_ui ||= :select if column.association + + col_class = ['form-element'] + col_class << 'required' if column.required? + col_class << column.css_class unless column.css_class.nil? + col_class << 'hidden' if column_renders_as(column) == :hidden -%> - <li class="form-element <%= 'required' if column.required? %> <%= column.css_class unless column.css_class.nil? %>"> - <% unless readonly -%> + <li class="<%= col_class.join(' ') %>"> + <% unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) -%> <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%> <% else -%> <p><%= get_column_value(@record, column) -%></p> From 7ee46714996b8d8e47fab040d8cdf390c9dfd1ec Mon Sep 17 00:00:00 2001 From: Nick Rogers <ncrogers@gmail.com> Date: Sat, 24 Mar 2012 18:56:35 -0400 Subject: [PATCH 1430/2024] Fix issue where show, mark, and other actions were validating the record and its associations, which resulted in unnecessary SQL queries and object instantiation. --- lib/active_scaffold/actions/core.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index f84e5ac525..ac2a6eaca1 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -108,16 +108,16 @@ def response_object @response_object = successful? ? (@record || @records) : @record.errors end - # Success is the existence of certain variables and the absence of errors (when applicable). - # Success can also be defined. + # Success is the existence of one or more model objects. Most actions + # circumvent this method by setting @success directly. def successful? if @successful.nil? - @records or (@record and @record.errors.count == 0 and @record.no_errors_in_associated?) + @record || @records else @successful end end - + def successful=(val) @successful = (val) ? true : false end From ffaafa2e9caae589eed879775eb536b499e31b1c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 28 Mar 2012 11:55:19 +0200 Subject: [PATCH 1431/2024] String.join doesn't exist --- frontends/default/views/_horizontal_subform_record.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index 578eb54701..ddad5019d7 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -18,7 +18,7 @@ col_class = [] col_class << 'required' if column.required? col_class << column.css_class unless column.css_class.nil? - col_class = 'hidden' if column_renders_as(column) == :hidden + col_class << 'hidden' if column_renders_as(column) == :hidden -%> <td class="<%= col_class.join(' ') %>"> <% unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) -%> From 9d65d039bb3787a0475d0749da4839d41973af13 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 28 Mar 2012 12:27:04 +0200 Subject: [PATCH 1432/2024] update docs about javascript frameworks --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 4abe558b79..3bb4a2c94f 100644 --- a/README +++ b/README @@ -44,7 +44,7 @@ If you want to install as plugins under vendor/plugins, install these versions: == Pick your own javascript framework The Rails 3.0 version uses unobtrusive Javascript, so you are free to pick your javascript framework. -Out of the box Prototype or JQuery are supported: +Out of the box Prototype or JQuery are supported for rails 3.1 and later. For rails 3.0 pick a JS file: Prototype 1.7 (default js framework) rails.js in git://github.com/vhochstein/prototype-ujs.git From 739cc6e1e8b50c34d66bac802a8ef433115afa46 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 30 Mar 2012 12:37:15 +0200 Subject: [PATCH 1433/2024] fix embedded scaffolds with constraints --- lib/active_scaffold/actions/core.rb | 4 ++++ lib/active_scaffold/actions/list.rb | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index f84e5ac525..213beb0b0d 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -2,6 +2,7 @@ module ActiveScaffold::Actions module Core def self.included(base) base.class_eval do + before_filter :register_constraints_with_action_columns, :if => :embedded? after_filter :clear_flashes end base.helper_method :nested? @@ -17,6 +18,9 @@ def render_field end protected + def embedded? + @embedded ||= params.delete(:embedded) + end def nested? false diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 188094a828..2249f08031 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -23,7 +23,7 @@ def list protected def list_respond_to_html - if params.delete(:embedded) + if embedded? render :action => 'list', :layout => false else render :action => 'list' @@ -32,8 +32,7 @@ def list_respond_to_html def list_respond_to_js if params[:adapter] render(:partial => 'list_with_header') - elsif params[:embedded] - params.delete(:embedded) + elsif embedded? render(:partial => 'list_with_header') else render :action => 'refresh_list', :formats => [:js] From 3f7fc838759a843561e9c6610750c1046f80f3e5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 30 Mar 2012 12:37:27 +0200 Subject: [PATCH 1434/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 6c45ebfe64..8f93661764 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 2 + PATCH = 3 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From f9523bd518e2f175550b31f43b4be3cee4380d24 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 30 Mar 2012 15:26:31 +0200 Subject: [PATCH 1435/2024] fix calendar date select view helpers --- .../bridges/calendar_date_select/as_cds_bridge.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb index 329c927927..bfa20e1954 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb @@ -58,7 +58,6 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current include ActiveScaffold::Bridges::Shared::DateBridge::HumanConditionHelpers alias_method :active_scaffold_human_condition_calendar_date_select, :active_scaffold_human_condition_date_bridge include ActiveScaffold::Bridges::CalendarDateSelect::SearchColumnHelpers - include ActiveScaffold::Bridges::CalendarDateSelect::ViewHelpers end ActiveScaffold::Finder::ClassMethods.module_eval do From 7b3f6135992da58ac9fe1496131e5fd518ce3f76 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 2 Apr 2012 11:55:51 +0200 Subject: [PATCH 1436/2024] fix update column for checkbox columns with true as default value --- lib/active_scaffold/actions/update.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index dc48663279..831813db81 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -107,7 +107,13 @@ def do_update_column @record = active_scaffold_config.model.find(params[:id]) if @record.authorized_for?(:crud_type => :update, :column => params[:column]) column = active_scaffold_config.columns[params[:column].to_sym] - params[:value] ||= @record.column_for_attribute(params[:column]).default unless @record.column_for_attribute(params[:column]).nil? || @record.column_for_attribute(params[:column]).null + unless @record.column_for_attribute(params[:column]).nil? || @record.column_for_attribute(params[:column]).null + if @record.column_for_attribute(params[:column]).default == true + params[:value] ||= false + else + params[:value] ||= @record.column_for_attribute(params[:column]).default + end + end unless column.nil? params[:value] = column_value_from_param_value(@record, column, params[:value]) params[:value] = [] if params[:value].nil? && column.form_ui && column.plural_association? From 5d3dd1d76cb32c128727ef9b882538dd78fce8fd Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 2 Apr 2012 12:03:19 +0200 Subject: [PATCH 1437/2024] fix loading subgroup collapsed --- frontends/default/views/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index d9699c8192..9de5a55747 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -1,6 +1,6 @@ <% subsection_id ||= nil %> <% show_unauthorized_columns = active_scaffold_config.send(form_action).show_unauthorized_columns %> -<ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= "style=\"display: none;\"" if columns.collapsed %>> +<ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= "style=\"display: none;\"".html_safe if columns.collapsed %>> <% columns.each :for => @record, :crud_type => (:read if show_unauthorized_columns) do |column| %> <% authorized = show_unauthorized_columns ? @record.authorized_for?(:crud_type => form_action, :column => column.name) : true %> <% renders_as = column_renders_as(column) %> From 5e7ae63af9a43c474e9ffc00cb2b67433bd6c02c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 2 Apr 2012 13:13:03 +0200 Subject: [PATCH 1438/2024] fix loading inline action links in a new window --- lib/active_scaffold/extensions/action_controller_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_controller_rendering.rb b/lib/active_scaffold/extensions/action_controller_rendering.rb index 1ddda2f52b..60e16994c2 100644 --- a/lib/active_scaffold/extensions/action_controller_rendering.rb +++ b/lib/active_scaffold/extensions/action_controller_rendering.rb @@ -2,7 +2,7 @@ module ActionController #:nodoc: class Base def render_with_active_scaffold(*args, &block) - if self.class.uses_active_scaffold? and params[:adapter] and @rendering_adapter.nil? + if self.class.uses_active_scaffold? and params[:adapter] and @rendering_adapter.nil? and request.xhr? @rendering_adapter = true # recursion control # if we need an adapter, then we render the actual stuff to a string and insert it into the adapter template opts = args.blank? ? Hash.new : args.first From 25851fad34b103349786a8bccfb581df22732163 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 10 Apr 2012 11:31:48 +0200 Subject: [PATCH 1439/2024] fix nested scaffolds open from an embedded scaffold --- lib/active_scaffold/helpers/controller_helpers.rb | 4 ++-- lib/active_scaffold/helpers/view_helpers.rb | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index e12c947184..c9e9d04ce9 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -30,12 +30,12 @@ def main_path_to_return parameters = {} if params[:parent_controller] parameters[:controller] = params[:parent_controller] - #parameters[:eid] = params[:parent_controller] + #parameters[:eid] = params[:parent_controller] # not neeeded anymore? end parameters.merge! nested.to_params if nested? if params[:parent_sti] parameters[:controller] = params[:parent_sti] - #parameters[:eid] = nil + #parameters[:eid] = nil # not neeeded anymore? end parameters[:parent_column] = nil parameters[:parent_id] = nil diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 5f17906cc9..2aaa41ad25 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -190,8 +190,10 @@ def url_options_for_nested_link(column, record, link, url_options, options = {}) if column && column.association url_options[column.association.active_record.name.foreign_key.to_sym] = url_options.delete(:id) url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present? + url_options[:eid] = nil # needed for nested scaffolds open from an embedded scaffold elsif link.parameters && link.parameters[:named_scope] url_options[active_scaffold_config.model.name.foreign_key.to_sym] = url_options.delete(:id) + url_options[:eid] = nil # needed for nested scaffolds open from an embedded scaffold end end From 31319c76c51852ad971cc899c91e2d49279fe66c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 11 Apr 2012 09:46:35 +0200 Subject: [PATCH 1440/2024] update jquery.inplaceedit.js to last version --- .../javascripts/jquery/jquery.editinplace.js | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/app/assets/javascripts/jquery/jquery.editinplace.js b/app/assets/javascripts/jquery/jquery.editinplace.js index 9bc523a155..6e4af64d6c 100644 --- a/app/assets/javascripts/jquery/jquery.editinplace.js +++ b/app/assets/javascripts/jquery/jquery.editinplace.js @@ -11,7 +11,7 @@ Authors: Project home: http://code.google.com/p/jquery-in-place-editor/ -Patches with tests welcomed! For guidance see the tests at </spec/unit/spec.js>. To submit, attach them to the bug tracker. +Patches with tests welcomed! For guidance see the tests </spec/unit/>. To submit, attach them to the bug tracker. License: This source file is subject to the BSD license bundled with this package. @@ -19,6 +19,7 @@ Available online: {@link http://www.opensource.org/licenses/bsd-license.php} If you did not receive a copy of the license, and are unable to obtain it, learn to use a search engine. +Rev: 161 */ (function($){ @@ -26,9 +27,7 @@ learn to use a search engine. $.fn.editInPlace = function(options) { var settings = $.extend({}, $.fn.editInPlace.defaults, options); - assertMandatorySettingsArePresent(settings); - preloadImage(settings.saving_image); return this.each(function() { @@ -57,7 +56,7 @@ $.fn.editInPlace.defaults = { params: "", // string: example: first_name=dave&last_name=hauenstein extra paramters sent via the post request to the server field_type: "text", // string: "text", "textarea", or "select", or "remote", or "clone"; The type of form field that will appear on instantiation default_text: "(Click here to add text)", // string: text to show up if the element that has this functionality is empty - use_html: false, // boolean, set to true if the editor should use jQuery.fn.html() to extract the value to show from the dom node + use_html: false, // boolean, set to true if the editor should use jQuery.fn.html() to extract the value to show from the dom node (keep in mind that IE will uppercase all tags, so use with caution) textarea_rows: 10, // integer: set rows attribute of textarea, if field_type is set to textarea. Use CSS if possible though textarea_cols: 25, // integer: set cols attribute of textarea, if field_type is set to textarea. Use CSS if possible though select_text: "Choose new value", // string: default text to show up in select box @@ -179,14 +178,15 @@ $.extend(InlineEditor.prototype, { if ( ! this.shouldOpenEditor(anEvent)) return; - this.workAroundFirefoxBlurBug(); this.disconnectOpeningEvents(); this.removeHoverEffect(); this.removeInsertedDefaultTextIfNeccessary(); this.saveOriginalValue(); this.markEditorAsActive(); this.replaceContentWithEditor(); - this.connectOpeningEventsToEditor(); + this.setInitialValue(); + this.workAroundMissingBlurBug(); + this.connectClosingEventsToEditor(); this.triggerDelegateCall('didOpenEditInPlace'); }, @@ -239,20 +239,16 @@ $.extend(InlineEditor.prototype, { this.dom.text(aValue); }, - workAroundFirefoxBlurBug: function() { - if ( ! $.browser.mozilla) - return; - - // TODO: Opera seems to also have this bug.... - - // Firefox will forget to send a blur event to an input element when another one is - // created and selected programmatically. This means that if another inline editor is - // opened, existing inline editors will _not_ close if they are configured to submit when blurred. - // This is actually the first time I've written browser specific code for a browser different than IE! Wohoo! + workAroundMissingBlurBug: function() { + // Strangely, all browser will forget to send a blur event to an input element + // when another one is created and selected programmatically. (at least under some circumstances). + // This means that if another inline editor is opened, existing inline editors will _not_ close + // if they are configured to submit when blurred. // Using parents() instead document as base to workaround the fact that in the unittests // the editor is not a child of window.document but of a document fragment - this.dom.parents(':last').find('.editInPlace-active :input').blur(); + var ourInput = this.dom.find(':input'); + this.dom.parents(':last').find('.editInPlace-active :input').not(ourInput).blur(); }, replaceContentWithEditor: function() { @@ -285,10 +281,20 @@ $.extend(InlineEditor.prototype, { editor = this.cloneEditor(); return editor; } - editor.val(this.triggerDelegateCall('willOpenEditInPlace', this.originalValue)); return editor; }, + setInitialValue: function() { + var initialValue = this.triggerDelegateCall('willOpenEditInPlace', this.originalValue); + var editor = this.dom.find(':input'); + editor.val(initialValue); + + // Workaround for select fields which don't contain the original value. + // Somehow the browsers don't like to select the instructional choice (disabled) in that case + if (editor.val() !== initialValue) + editor.val(''); // selects instructional choice + }, + createRemoteGeneratedEditor: function () { this.dom.html(this.settings.loading_text); return $($.ajax({ @@ -373,7 +379,6 @@ $.extend(InlineEditor.prototype, { optionsArray = optionsArray.split(','); for (var i=0; i<optionsArray.length; i++) { - var currentTextAndValue = optionsArray[i]; if ( ! $.isArray(currentTextAndValue)) currentTextAndValue = currentTextAndValue.split(':'); @@ -381,16 +386,14 @@ $.extend(InlineEditor.prototype, { var value = trim(currentTextAndValue[1] || currentTextAndValue[0]); var text = trim(currentTextAndValue[0]); - var selected = (value == this.originalValue) ? 'selected="selected" ' : ''; - var option = $('<option ' + selected + ' ></option>').val(value).text(text); + var option = $('<option>').val(value).text(text); editor.append(option); } + return editor; - }, - // REFACT: rename opening is not what it's about. Its about closing events really - connectOpeningEventsToEditor: function() { + connectClosingEventsToEditor: function() { var that = this; function cancelEditorAction(anEvent) { that.handleCancelEditor(anEvent); @@ -415,8 +418,8 @@ $.extend(InlineEditor.prototype, { else form.find(".inplace_field").blur(cancelEditorAction); - // workaround for firefox bug where it won't submit on enter if no button is shown - if ($.browser.mozilla) + // workaround for msie & firefox bug where it won't submit on enter if no button is shown + if ($.browser.mozilla || $.browser.msie) this.bindSubmitOnEnterInInput(); } @@ -460,9 +463,6 @@ $.extend(InlineEditor.prototype, { enteredText = this.triggerDelegateCall('willCloseEditInPlace', enteredText); this.restoreOriginalValue(); - if (hasContent(enteredText) - && ! this.isDisabledDefaultSelectChoice() && !editor.is('select')) - this.setClosedEditorContent(enteredText); this.reinit(); }, @@ -609,7 +609,7 @@ $.extend(InlineEditor.prototype, { if ( ! aCallback) return; // callback wasn't specified after all - var callbackArguments = Array.prototype.splice.call(arguments, 1); + var callbackArguments = Array.prototype.slice.call(arguments, 1); return aCallback.apply(this.dom[0], callbackArguments); }, From d939b1d40cff5cb82f28ec84433ccd2d61506edc Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 16 Apr 2012 11:17:31 +0200 Subject: [PATCH 1441/2024] it's possible to sort using a function, in that case ActiveScaffold can't get the column --- lib/active_scaffold/data_structures/sorting.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 1038e3a196..35fd96b5e1 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -32,9 +32,8 @@ def add(column_name, direction = nil) direction ||= 'ASC' direction = direction.to_s.upcase column = get_column(column_name) - raise ArgumentError, "Could not find column #{column_name}" if column.nil? raise ArgumentError, "Sorting direction unknown" unless [:ASC, :DESC].include? direction.to_sym - @clauses << [column, direction.untaint] if column.sortable? + @clauses << [column, direction.untaint] if column and column.sortable? raise ArgumentError, "Can't mix :method- and :sql-based sorting" if mixed_sorting? end From bda9b37a9bb44d899fd5c2e690e2cd264f92ccf9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 16 Apr 2012 16:49:39 +0200 Subject: [PATCH 1442/2024] remove constrained fields from params in nested links, fixes double nested scaffolds --- lib/active_scaffold/helpers/view_helpers.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 2aaa41ad25..99b628a700 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -195,6 +195,7 @@ def url_options_for_nested_link(column, record, link, url_options, options = {}) url_options[active_scaffold_config.model.name.foreign_key.to_sym] = url_options.delete(:id) url_options[:eid] = nil # needed for nested scaffolds open from an embedded scaffold end + nested.constrained_fields.each { |field| url_options.delete field } if nested? end def url_options_for_sti_link(column, record, link, url_options, options = {}) From bcfaea09d9f9532edda60a73d56d2e9f04591bca Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 16 Apr 2012 16:54:30 +0200 Subject: [PATCH 1443/2024] bump version --- CHANGELOG | 11 +++++++++++ lib/active_scaffold/version.rb | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 71613ef036..b93c47df9e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,14 @@ += 3.2.4 +- don't break on custom SQL sorting (e.g. sorting with functions) +- fix cancel inplace edit with jquery +- fix nested scaffolds inside nested and embedded scaffolds +- fix collapsed subgroups +- fix inplace edit for checkboxes columns with true as default value +- fix calendar date select bridge + += 3.0.6 .. 3.2.3 +- many changes + = 3.0.5 - switch from explicit requires to autoloading diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 8f93661764..7e7f7bab61 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 3 + PATCH = 4 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 1f460042012211d2c2363a23c87cb3f7359f08a7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 27 Apr 2012 11:47:09 +0200 Subject: [PATCH 1444/2024] Fix #159, use label from core config when is set and there is no STI children --- CHANGELOG | 1 + frontends/default/views/_create_form.html.erb | 2 +- frontends/default/views/_create_form_on_list.html.erb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b93c47df9e..565dc2a066 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ = 3.2.4 +- use core config label when is set and STI is not used - don't break on custom SQL sorting (e.g. sorting with functions) - fix cancel inplace edit with jquery - fix nested scaffolds inside nested and embedded scaffolds diff --git a/frontends/default/views/_create_form.html.erb b/frontends/default/views/_create_form.html.erb index 058ba94dbb..9bfaf10615 100644 --- a/frontends/default/views/_create_form.html.erb +++ b/frontends/default/views/_create_form.html.erb @@ -4,5 +4,5 @@ :form_action => form_action, :method => method ||= :post, :cancel_link => cancel_link, - :headline => headline ||= active_scaffold_config.send(form_action).label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil)} %> + :headline => headline ||= active_scaffold_config.send(form_action).label(active_scaffold_config.add_sti_create_links? ? @record.class.model_name.human(:count => 1) : nil)} %> diff --git a/frontends/default/views/_create_form_on_list.html.erb b/frontends/default/views/_create_form_on_list.html.erb index 96142a9704..7a735f0841 100644 --- a/frontends/default/views/_create_form_on_list.html.erb +++ b/frontends/default/views/_create_form_on_list.html.erb @@ -3,4 +3,4 @@ :form_action => form_action ||= :create, :method => method ||= :post, :cancel_link => cancel_link, - :headline => headline ||= active_scaffold_config.create.label(active_scaffold_config.sti_create_links ? @record.class.model_name.human(:count => 1) : nil)} %> \ No newline at end of file + :headline => headline ||= active_scaffold_config.create.label(active_scaffold_config.add_sti_create_links? ? @record.class.model_name.human(:count => 1) : nil)} %> \ No newline at end of file From 610f92cde168f7c65761992c7783d068ac74a3b7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 27 Apr 2012 11:53:03 +0200 Subject: [PATCH 1445/2024] Fix #158, add subgroup for bitfields columns only for used actions --- CHANGELOG | 1 + lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 565dc2a066..251d269535 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ = 3.2.4 +- fix bitfields bridge when some actions are not used - use core config label when is set and STI is not used - don't break on custom SQL sorting (e.g. sorting with functions) - fix cancel inplace edit with jquery diff --git a/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb b/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb index 64676f4d8d..984cc7c074 100644 --- a/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +++ b/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb @@ -19,7 +19,7 @@ def _load_action_columns_with_bitfields self.model.bitfields.each do |column_name, options| columns = options.keys.sort_by { |column| self.columns[column].weight } [:create, :update, :show, :subform].each do |action| - self.send(action).columns.add_subgroup(column_name) { |group| group.add *columns } + self.send(action).columns.add_subgroup(column_name) { |group| group.add *columns } if self.actions.included? action end end if self.model.respond_to?(:bitfields) and self.model.bitfields.present? From 1d687c358275c7fd500b6accdade4a021ab0c866 Mon Sep 17 00:00:00 2001 From: Nick Rogers <ncrogers@gmail.com> Date: Tue, 1 May 2012 12:29:49 -0400 Subject: [PATCH 1446/2024] Fix bug where the contents of a datetime_picker textarea form field of an existing record was not correctly localized to the local timezone due to a bug/regression in rails core. Automatically set the format of a datetime_picker column to :picker instead of :default, because if the "time.formats.default" translation is changed from the default value, the text field's value is set to something that is not correctly recognized by the controller when editing and saving an existing record. --- lib/active_scaffold/bridges/date_picker/ext.rb | 2 +- lib/active_scaffold/bridges/date_picker/helper.rb | 4 ++-- lib/active_scaffold/finder.rb | 8 +++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/ext.rb b/lib/active_scaffold/bridges/date_picker/ext.rb index 7f2e0af646..74e698cf18 100644 --- a/lib/active_scaffold/bridges/date_picker/ext.rb +++ b/lib/active_scaffold/bridges/date_picker/ext.rb @@ -16,7 +16,7 @@ def initialize_with_date_picker(model_id) # check to see if file column was used on the model return if date_picker_fields.empty? - # automatically set the forum_ui to a file column + # automatically set the forum_ui to a date_picker or datetime_picker date_picker_fields.each{|field| col_config = self.columns[field[:name]] col_config.form_ui = (field[:type] == :date ? :date_picker : :datetime_picker) diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index e9240215f9..1fcf97b41d 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -158,7 +158,7 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current options = active_scaffold_input_text_options(options.merge(column.options)) options[:class] << " #{column.search_ui.to_s}" options[:style] = (options[:show].nil? || options[:show]) ? nil : "display: none" - format = options.delete(:format) || :default + format = options.delete(:format) || column.form_ui == :date_picker ? :default : :picker datepicker_format_options(column, format, options) text_field_tag("#{options[:name]}[#{name}]", value ? l(value, :format => format) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) end @@ -169,7 +169,7 @@ def active_scaffold_input_date_picker(column, options) options = active_scaffold_input_text_options(options.merge(column.options)) options[:class] << " #{column.form_ui.to_s}" value = controller.class.condition_value_for_datetime(@record.send(column.name), column.form_ui == :date_picker ? :to_date : :to_time) - format = options.delete(:format) || :default + format = options.delete(:format) || column.form_ui == :date_picker ? :default : :picker datepicker_format_options(column, format, options) options[:value] = (value ? l(value, :format => format) : nil) text_field(:record, column.name, options) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index aaac9b1ed7..3b53fa52fd 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -110,7 +110,13 @@ def condition_value_for_datetime(value, conversion = :to_time) if value.is_a? Hash Time.zone.local(*[:year, :month, :day, :hour, :minute, :second].collect {|part| value[part].to_i}) rescue nil elsif value.respond_to?(:strftime) - value.send(conversion) + if conversion == :to_time + # Explicitly get the localtime, because TimeWithZone#to_time in rails 3.2.3 returns UTC. + # https://github.com/rails/rails/pull/2453 + value.to_time.localtime + else + value.send(conversion) + end elsif conversion == :to_date Date.strptime(value, I18n.t('date.formats.default')) rescue nil else From 5af6ac0c8ed4e6c9fca729b5eece392e56655370 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 1 May 2012 21:29:11 +0200 Subject: [PATCH 1447/2024] Localtime doesn't use Time.zone, which is set in application.rb (config.time_zone) or can be changed to user's timezone with a before filter for example, so in_time_zone should be used instead of localtime. --- lib/active_scaffold/finder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 3b53fa52fd..3c2840ac69 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -111,9 +111,9 @@ def condition_value_for_datetime(value, conversion = :to_time) Time.zone.local(*[:year, :month, :day, :hour, :minute, :second].collect {|part| value[part].to_i}) rescue nil elsif value.respond_to?(:strftime) if conversion == :to_time - # Explicitly get the localtime, because TimeWithZone#to_time in rails 3.2.3 returns UTC. + # Explicitly get the current zone, because TimeWithZone#to_time in rails 3.2.3 returns UTC. # https://github.com/rails/rails/pull/2453 - value.to_time.localtime + value.to_time.in_time_zone else value.send(conversion) end From 2ff9bd9fde9b444f5172fd2b84cc4d1b269b5e9a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 2 May 2012 14:25:57 +0200 Subject: [PATCH 1448/2024] add outer window option for page links --- CHANGELOG | 3 ++ .../views/_list_pagination_links.html.erb | 2 +- lib/active_scaffold/config/list.rb | 28 +++++++++++-- .../helpers/pagination_helpers.rb | 39 ++++++++++--------- 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 251d269535..40da33f6ba 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,7 @@ = 3.2.4 +- add outer window for pagination links +- workaround rails 3.2.3 bug in TimeWithZone#to_time +- fix date picker format for datetime fields - fix bitfields bridge when some actions are not used - use core config label when is set and STI is not used - don't break on custom SQL sorting (e.g. sorting with functions) diff --git a/frontends/default/views/_list_pagination_links.html.erb b/frontends/default/views/_list_pagination_links.html.erb index 119a0a99fc..d936e97399 100644 --- a/frontends/default/views/_list_pagination_links.html.erb +++ b/frontends/default/views/_list_pagination_links.html.erb @@ -4,6 +4,6 @@ <%= loading_indicator_tag :action => :pagination %> <%= link_to as_(:previous), url_options.merge(:page => current_page.number - 1), options.merge(:class => "as_paginate previous") if current_page.prev? %> - <%= pagination_ajax_links current_page, url_options, options, active_scaffold_config.list.page_links_window %> + <%= pagination_ajax_links current_page, url_options, options, active_scaffold_config.list.page_links_inner_window, active_scaffold_config.list.page_links_outer_window %> <%= link_to as_(:next), url_options.merge(:page => current_page.number + 1), options.merge(:class => "as_paginate next") if current_page.next? %> <% end -%> diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 4988ee7f84..567c044ce4 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -7,7 +7,8 @@ def initialize(core_config) # inherit from global scope # full configuration path is: defaults => global table => local table @per_page = self.class.per_page - @page_links_window = self.class.page_links_window + @page_links_inner_window = self.class.page_links_inner_window + @page_links_outer_window = self.class.page_links_outer_window # originates here @sorting = ActiveScaffold::DataStructures::Sorting.new(@core.columns) @@ -28,8 +29,19 @@ def initialize(core_config) @@per_page = 15 # how many page links around current page to show - cattr_accessor :page_links_window - @@page_links_window = 2 + cattr_accessor :page_links_inner_window + @@page_links_inner_window = 2 + + # how many page links around first and last page to show + cattr_accessor :page_links_outer_window + @@page_links_outer_window = 0 + + class << self + def page_links_window=(value) + ActiveSupport::Deprecation.warn("Use page_links_inner_window", caller(1)) + self.page_links_inner_window = value + end + end # what string to use when a field is empty cattr_accessor :empty_field_text @@ -64,7 +76,15 @@ def columns attr_accessor :per_page # how many page links around current page to show - attr_accessor :page_links_window + attr_accessor :page_links_inner_window + + # how many page links around current page to show + attr_accessor :page_links_outer_window + + def page_links_window=(value) + ActiveSupport::Deprecation.warn("Use page_links_inner_window", caller(1)) + self.page_links_inner_window = value + end # What kind of pagination to use: # * true: The usual pagination diff --git a/lib/active_scaffold/helpers/pagination_helpers.rb b/lib/active_scaffold/helpers/pagination_helpers.rb index 4df2e5bd42..ef4eab0fdd 100644 --- a/lib/active_scaffold/helpers/pagination_helpers.rb +++ b/lib/active_scaffold/helpers/pagination_helpers.rb @@ -5,9 +5,9 @@ def pagination_ajax_link(page_number, url_options, options) link_to page_number, url_options.merge(:page => page_number), options.merge(:class => "as_paginate") end - def pagination_ajax_links(current_page, url_options, options, window_size) - start_number = current_page.number - window_size - end_number = current_page.number + window_size + def pagination_ajax_links(current_page, url_options, options, inner_window, outer_window) + start_number = current_page.number - inner_window + end_number = current_page.number + inner_window start_number = 1 if start_number <= 0 if current_page.pager.infinite? offsets = [20, 100] @@ -16,23 +16,24 @@ def pagination_ajax_links(current_page, url_options, options, window_size) end html = [] - unless start_number == 1 - last_page = 1 - html << pagination_ajax_link(last_page, url_options, options) - if current_page.pager.infinite? - offsets.reverse.each do |offset| - page = current_page.number - offset - if page < start_number && page > 1 - html << '..' if page > last_page + 1 - html << pagination_ajax_link(page, params) - last_page = page - end + last_page = 1 + last_page.upto(last_page + outer_window) do |num| + html << pagination_ajax_link(num, url_options, options) + last_page = num + end + if current_page.pager.infinite? + offsets.reverse.each do |offset| + page = current_page.number - offset + if page < start_number && page > last_page + html << '..' if page > last_page + 1 + html << pagination_ajax_link(page, params) + last_page = page end end - html << ".." if start_number > last_page + 1 end + html << ".." if start_number > last_page + 1 - start_number.upto(end_number) do |num| + [start_number, last_page + 1].max.upto(end_number) do |num| if current_page.number == num html << content_tag(:span, num.to_s, {:class => "as_paginate current"}) else @@ -45,8 +46,10 @@ def pagination_ajax_links(current_page, url_options, options, window_size) html << '..' << pagination_ajax_link(current_page.number + offset, url_options, options) end else - html << ".." unless end_number >= current_page.pager.last.number - 1 - html << pagination_ajax_link(current_page.pager.last.number, url_options, options) unless end_number == current_page.pager.last.number + html << ".." unless end_number >= current_page.pager.last.number - outer_window - 1 + [end_number + 1, current_page.pager.last.number - outer_window].max.upto(current_page.pager.last.number) do |num| + html << pagination_ajax_link(num, url_options, options) + end end html.join(' ').html_safe end From c8236f22e88f974669d27d0590c3da4bb571b943 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 2 May 2012 14:42:46 +0200 Subject: [PATCH 1449/2024] bump version to 3.2.5 --- CHANGELOG | 4 +++- lib/active_scaffold/version.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 40da33f6ba..b67fce00f2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,11 @@ -= 3.2.4 += 3.2.5 - add outer window for pagination links - workaround rails 3.2.3 bug in TimeWithZone#to_time - fix date picker format for datetime fields - fix bitfields bridge when some actions are not used - use core config label when is set and STI is not used + += 3.2.4 - don't break on custom SQL sorting (e.g. sorting with functions) - fix cancel inplace edit with jquery - fix nested scaffolds inside nested and embedded scaffolds diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 7e7f7bab61..340a1eba05 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 4 + PATCH = 5 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From fc803381046400ce5f0ff6541853493ba4795179 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 3 May 2012 13:13:45 +0200 Subject: [PATCH 1450/2024] allow to override some human condition strings in i18n --- config/locales/en.yml | 7 +++++-- frontends/default/views/_human_conditions.html.erb | 2 +- lib/active_scaffold/extensions/localize.rb | 2 +- lib/active_scaffold/helpers/human_condition_helpers.rb | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 06259c41ec..64b8248e98 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -100,6 +100,10 @@ en: showMonthAfterYear: false datetime_picker_options: + + human_conditions: + boolean: "%{column} = %{value}" + association: "%{column} = %{value}" errors: template: @@ -109,8 +113,7 @@ en: body: "There were problems with the following fields:" - - # error_messages + # error_messages cant_destroy_record: "%{record} can't be destroyed" internal_error: 'Request Failed (code 500, Internal Error)' version_inconsistency: 'Version inconsistency - this record has been modified since you started editing it.' diff --git a/frontends/default/views/_human_conditions.html.erb b/frontends/default/views/_human_conditions.html.erb index b1a09cd9ef..4bb8ae63db 100644 --- a/frontends/default/views/_human_conditions.html.erb +++ b/frontends/default/views/_human_conditions.html.erb @@ -1 +1 @@ -<%= columns.collect {|column| active_scaffold_human_condition_for(column)}.compact.join(I18n.t('support.array.two_words_connector')) %> \ No newline at end of file +<%= columns.collect {|column| active_scaffold_human_condition_for(column)}.compact.to_sentence %> \ No newline at end of file diff --git a/lib/active_scaffold/extensions/localize.rb b/lib/active_scaffold/extensions/localize.rb index 671a4633ea..01b6001881 100644 --- a/lib/active_scaffold/extensions/localize.rb +++ b/lib/active_scaffold/extensions/localize.rb @@ -1,7 +1,7 @@ class Object def as_(key, options = {}) unless key.blank? - text = I18n.translate "#{key}", {:scope => [:active_scaffold], :default => key.is_a?(String) ? key : key.to_s.titleize}.merge(options) + text = I18n.translate "#{key}", {:scope => [:active_scaffold, *options.delete(:scope)], :default => key.is_a?(String) ? key : key.to_s.titleize}.merge(options) # text = nil if text.include?('translation missing:') end text ||= key diff --git a/lib/active_scaffold/helpers/human_condition_helpers.rb b/lib/active_scaffold/helpers/human_condition_helpers.rb index b226e4c9a0..49f600b929 100644 --- a/lib/active_scaffold/helpers/human_condition_helpers.rb +++ b/lib/active_scaffold/helpers/human_condition_helpers.rb @@ -27,10 +27,10 @@ def active_scaffold_human_condition_for(column) associated = value associated = [associated].compact unless associated.is_a? Array associated = column.association.klass.where(["id in (?)", associated.map(&:to_i)]).collect(&:to_label) if column.association - "#{column.active_record_class.human_attribute_name(column.name)} = #{associated.join(', ')}" + as_(:association, :scope => :human_conditions, :column => column.active_record_class.human_attribute_name(column.name), :value => associated.join(', ')) when :boolean, :checkbox label = column.column.type_cast(value) ? as_(:true) : as_(:false) - "#{column.active_record_class.human_attribute_name(column.name)} = #{label}" + as_(:boolean, :scope => :human_conditions, :column => column.active_record_class.human_attribute_name(column.name), :value => label) when :null "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value.to_sym)}" end From 93b5755790ef2a1952074a1115d0899acdd36bbd Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 3 May 2012 13:13:52 +0200 Subject: [PATCH 1451/2024] update locales --- config/locales/de.yml | 5 ++++ config/locales/es.yml | 6 +++-- config/locales/fr.yml | 4 ++++ config/locales/hu.yml | 50 ++++++++++++++++++++++++++++++++++++++-- config/locales/ja.yml | 53 ++++++++++++++++++++++++++++++++++++++++--- config/locales/ru.yml | 8 +++++-- 6 files changed, 117 insertions(+), 9 deletions(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index 42c51d5e5f..e50fd6cb7b 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -27,6 +27,7 @@ de: export: 'Exportieren' nested_for_model: '%{nested_model} für %{parent_model}' nested_of_model: '%{nested_model} von %{parent_model}' + 'false': 'False' filtered: '(Gefiltert)' found: 'Gefunden' hide: 'Verstecken' @@ -53,6 +54,7 @@ de: show: 'Anzeigen' show_model: 'Zeige %{model} an' _to_ : ' zu ' + 'true': 'True' update: 'Speichern' update_model: 'Editiere %{model}' updated_model: '%{model} aktualisiert' @@ -100,6 +102,9 @@ de: timeText: 'Uhrzeit' currentText: 'Jetzt' closeText: 'Schließen' + human_conditions: + boolean: "%{column} = %{value}" + association: "%{column} = %{value}" errors: template: header: diff --git a/config/locales/es.yml b/config/locales/es.yml index 4bac577ad9..5d55f40d9a 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -67,8 +67,6 @@ es: '<': 'Menor' '!=': 'Distinto' between: 'Entre' - is_null: 'Es nulo' - is_not_null: 'No es nulo' contains: 'Contiene' begins_with: 'Empieza con' ends_with: 'Termina con' @@ -106,6 +104,9 @@ es: timeText: 'Hora' currentText: 'Ahora' closeText: 'Cerrar' + human_conditions: + boolean: "%{column} = %{value}" + association: "%{column} = %{value}" errors: template: header: @@ -117,4 +118,5 @@ es: cant_destroy_record: "No se pudo borrar %{record}" internal_error: 'Petición fallida (código 500, error interno)' version_inconsistency: 'Inconsistencia de versiones - este registro se ha modificado después de que empezó a editarlo.' + record_not_saved: 'Fallo guardando el registro debido a un error desconocido' no_authorization_for_action: "No dispone de autorización para la acción %{action}" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 59ad66069f..e163900c0b 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -104,6 +104,10 @@ fr: currentText: 'Maintenant' closeText: 'Fermer' + human_conditions: + boolean: "%{column} = %{value}" + association: "%{column} = %{value}" + errors: template: header: diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 9e742fe9a7..24ac3f6c7a 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -11,6 +11,8 @@ hu: click_to_edit: 'Kattints a szerkesztéshez' click_to_reset: 'Kattints az alapállapothoz' close: 'Bezárás' + config_list: 'Configure' + config_list_model: 'Configure Columns for %{model}' create: 'Létrehozás' create_model: '%{model} létrehozása' create_another: 'Mégegy hozzáadása' @@ -25,6 +27,7 @@ hu: export: 'Exportálás' nested_for_model: '%{nested_model} / %{parent_model}' nested_of_model: '%{nested_model} of %{parent_model}' + 'false': 'False' filtered: '(Szűrt)' found: 'Találat' hide: 'Elrejtés' @@ -51,6 +54,7 @@ hu: show: 'Mutatás' show_model: '%{model} mutatása' _to_ : ' – ' + 'true': 'True' update: 'Modosítás' update_model: '%{model} modosítása' updated_model: '%{model} módosítva' @@ -61,12 +65,54 @@ hu: '<': '<' '!=': '!=' between: 'Között' - is_null: 'Is null' - is_not_null: 'Is not null' contains: 'Contains' begins_with: 'Begins with' ends_with: 'Ends with' + today: 'Today' + yesterday: 'Yesterday' + tomorrow: 'Tommorrow' + this_week: 'This Week' + prev_week: 'Last Week' + next_week: 'Next Week' + this_month: 'This Month' + prev_month: 'Last Month' + next_month: 'Next Month' + this_year: 'This Year' + prev_year: 'Last Year' + next_year: 'Next Year' + past: 'Past' + future: 'Future' + range: 'Range' + seconds: 'Seconds' + minutes: 'Minutes' + hours: 'Hours' + days: 'Days' + weeks: 'Weeks' + months: 'Months' + years: 'Years' + optional_attributes: 'Further Options' + null: 'Null' + not_null: 'Not Null' + date_picker_options: + weekHeader: 'Wk' + firstDay: 0 + isRTL: false + showMonthAfterYear: false + + datetime_picker_options: + human_conditions: + boolean: "%{column} = %{value}" + association: "%{column} = %{value}" + + errors: + template: + header: + one: "1 error prohibited this %{model} from being saved." + other: "%{count} errors prohibited this %{model} from being saved" + + body: "There were problems with the following fields:" + # error_messages cant_destroy_record: "nem törölhető: %{record}" internal_error: 'A lekérés sikertelen (code 500, Internal Error)' diff --git a/config/locales/ja.yml b/config/locales/ja.yml index add34059b0..da3cb742b5 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -9,7 +9,10 @@ ja: are_you_sure_to_delete: '本当によいですか?' cancel: 'キャンセル' click_to_edit: 'クリックして編集' + click_to_reset: 'Click to reset' close: '閉じる' + config_list: 'Configure' + config_list_model: 'Configure Columns for %{model}' create: '作成' create_model: '%{model}を作成' create_another: '別のものを作成' @@ -24,6 +27,7 @@ ja: export: 'Export' # needed? nested_for_model: '%{parent_model}の%{nested_model}' nested_of_model: '%{nested_model} of %{parent_model}' + 'false': 'False' filtered: '(フィルタ中)' found: '個ありました' hide: '隠す' @@ -50,6 +54,7 @@ ja: show: '表示' show_model: '%{model}を表示' _to_ : ' to ' # needed? + 'true': 'True' update: '更新' update_model: '%{model}を更新' updated_model: '%{model}を更新しました' @@ -60,12 +65,54 @@ ja: '<': '<' '!=': '!=' between: 'Between' # needed? - is_null: 'Is null' - is_not_null: 'Is not null' contains: 'Contains' begins_with: 'Begins with' ends_with: 'Ends with' - + today: 'Today' + yesterday: 'Yesterday' + tomorrow: 'Tommorrow' + this_week: 'This Week' + prev_week: 'Last Week' + next_week: 'Next Week' + this_month: 'This Month' + prev_month: 'Last Month' + next_month: 'Next Month' + this_year: 'This Year' + prev_year: 'Last Year' + next_year: 'Next Year' + past: 'Past' + future: 'Future' + range: 'Range' + seconds: 'Seconds' + minutes: 'Minutes' + hours: 'Hours' + days: 'Days' + weeks: 'Weeks' + months: 'Months' + years: 'Years' + optional_attributes: 'Further Options' + null: 'Null' + not_null: 'Not Null' + date_picker_options: + weekHeader: 'Wk' + firstDay: 0 + isRTL: false + showMonthAfterYear: false + + datetime_picker_options: + + human_conditions: + boolean: "%{column} = %{value}" + association: "%{column} = %{value}" + + errors: + template: + header: + one: "1 error prohibited this %{model} from being saved." + other: "%{count} errors prohibited this %{model} from being saved" + + body: "There were problems with the following fields:" + # error_messages cant_destroy_record: "%{record}を削除で来ません" internal_error: 'リクエストが失敗しました(コード500: 内部エラー)' diff --git a/config/locales/ru.yml b/config/locales/ru.yml index d783f87739..2c851e4141 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -27,7 +27,7 @@ ru: export: 'Экспорт' nested_for_model: '%{parent_model} / %{nested_model}' nested_of_model: '%{nested_model} @ %{parent_model}' - false: 'Нет' + 'false': 'Нет' filtered: '(Найденное)' found: one: 'запись' @@ -58,7 +58,7 @@ ru: show: 'Показать' show_model: '%{model}: показать запись' _to_ : ' to ' - true: 'Да' + 'true': 'Да' update: 'Обновить запись' update_model: '%{model}: обновить запись' updated_model: '%{model}: запись обновлена' @@ -104,6 +104,10 @@ ru: showMonthAfterYear: false datetime_picker_options: + + human_conditions: + boolean: "%{column} = %{value}" + association: "%{column} = %{value}" errors: template: From c4c043546a1421e0b33bc8aaa3125f10d41b3419 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 3 May 2012 13:46:48 +0200 Subject: [PATCH 1452/2024] translate select values for non-association columns in human conditions --- CHANGELOG | 3 +++ lib/active_scaffold/helpers/human_condition_helpers.rb | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index b67fce00f2..82e606ccf6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ += 3.2.6 (not released) +- allow to override some human condition strings in i18n, and translate select values for non-association columns + = 3.2.5 - add outer window for pagination links - workaround rails 3.2.3 bug in TimeWithZone#to_time diff --git a/lib/active_scaffold/helpers/human_condition_helpers.rb b/lib/active_scaffold/helpers/human_condition_helpers.rb index 49f600b929..67f48c4a51 100644 --- a/lib/active_scaffold/helpers/human_condition_helpers.rb +++ b/lib/active_scaffold/helpers/human_condition_helpers.rb @@ -26,7 +26,15 @@ def active_scaffold_human_condition_for(column) when :select, :multi_select, :record_select associated = value associated = [associated].compact unless associated.is_a? Array - associated = column.association.klass.where(["id in (?)", associated.map(&:to_i)]).collect(&:to_label) if column.association + if column.association + associated = column.association.klass.where(:id => associated.map(&:to_i)).collect(&:to_label) + elsif column.options[:options] + associated = associated.collect do |value| + text, val = column.options[:options].find {|text, val| (val.nil? ? text : val).to_s == value.to_s} + value = active_scaffold_translated_option(column, text, val).first if text + value + end + end as_(:association, :scope => :human_conditions, :column => column.active_record_class.human_attribute_name(column.name), :value => associated.join(', ')) when :boolean, :checkbox label = column.column.type_cast(value) ? as_(:true) : as_(:false) From 376a36d72360c7abfe6133e5b541d380fd9e60f5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 3 May 2012 14:13:18 +0200 Subject: [PATCH 1453/2024] Fix #161, reorder requires an array for some adapters which require extra processing for DISTINCT calls --- CHANGELOG | 3 ++- lib/active_scaffold/data_structures/sorting.rb | 2 +- test/data_structures/sorting_test.rb | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 82e606ccf6..180d78d366 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ -= 3.2.6 (not released) += 3.2.6 +- fix ordering with DISTINCT call - allow to override some human condition strings in i18n, and translate select values for non-association columns = 3.2.5 diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 35fd96b5e1..6b17cc5e5f 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -97,7 +97,7 @@ def clause order << Array(sql).map {|column| "#{column} #{sort_direction}"}.join(', ') end - order.join(', ') unless order.empty? + order unless order.empty? end protected diff --git a/test/data_structures/sorting_test.rb b/test/data_structures/sorting_test.rb index 9d622a44f0..37a096da81 100644 --- a/test/data_structures/sorting_test.rb +++ b/test/data_structures/sorting_test.rb @@ -100,7 +100,7 @@ def test_build_order_clause @sorting << [:a, 'desc'] @sorting << [:b, 'asc'] - assert_equal '"model_stubs"."a" DESC, "model_stubs"."b" ASC', @sorting.clause + assert_equal '"model_stubs"."a" DESC, "model_stubs"."b" ASC', @sorting.clause.join(', ') end def test_set_default_sorting_with_simple_default_scope From 2ad08e26d814d290e86aa60f2abf3c44e2291120 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 3 May 2012 14:13:37 +0200 Subject: [PATCH 1454/2024] bump version to 3.2.6 --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 340a1eba05..b275d2089d 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 5 + PATCH = 6 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 9f247296290529811bd0cde453fb8d453e842524 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 4 May 2012 16:45:50 +0200 Subject: [PATCH 1455/2024] restore missing update.persistent feature, fixes #162 --- CHANGELOG | 3 ++ frontends/default/views/on_update.js.erb | 36 +++++++++++++----------- lib/active_scaffold/actions/list.rb | 4 +-- lib/active_scaffold/actions/update.rb | 9 ++++-- lib/active_scaffold/config/update.rb | 7 +++++ 5 files changed, 36 insertions(+), 23 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 180d78d366..38150b6bc4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ += 3.2.7 (not released) +- restore missing update.persistent feature + = 3.2.6 - fix ordering with DISTINCT call - allow to override some human condition strings in i18n, and translate select values for non-association columns diff --git a/frontends/default/views/on_update.js.erb b/frontends/default/views/on_update.js.erb index 444c43ff44..644593547a 100644 --- a/frontends/default/views/on_update.js.erb +++ b/frontends/default/views/on_update.js.erb @@ -3,25 +3,27 @@ try { var action_link = ActiveScaffold.find_action_link('<%= form_selector%>'); action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages'))%>'); <% if controller.send :successful? %> - <% if render_parent? && controller.respond_to?(:render_component_into_view) %> - <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> - <% if nested_singular_association? %> - action_link.close('<%= escape_javascript(parent_rendered)%>'); - <% else %> - <% if render_parent_action == :row %> + <% if !active_scaffold_config.update.persistent %> + <% if render_parent? && controller.respond_to?(:render_component_into_view) %> + <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> + <% if nested_singular_association? %> action_link.close('<%= escape_javascript(parent_rendered)%>'); - <% elsif render_parent_action == :index %> - <%= escape_javascript(parent_rendered) %> + <% else %> + <% if render_parent_action == :row %> + action_link.close('<%= escape_javascript(parent_rendered)%>'); + <% elsif render_parent_action == :index %> + <%= escape_javascript(parent_rendered) %> + <% end %> + <% end %> + <%#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> + <% elsif update_refresh_list? %> + ActiveScaffold.replace_html('<%= active_scaffold_content_id%>', '<%= escape_javascript(render(:partial => 'list', :layout => false))%>'); + <% else %> + <% updated_row = render :partial => 'list_record', :locals => {:record => @record}%> + action_link.close('<%= escape_javascript(updated_row)%>'); + <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> + ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); <% end %> - <% end %> - <%#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> - <% elsif update_refresh_list? %> - ActiveScaffold.replace_html('<%= active_scaffold_content_id%>', '<%= escape_javascript(render(:partial => 'list', :layout => false))%>'); - <% else %> - <% updated_row = render :partial => 'list_record', :locals => {:record => @record}%> - action_link.close('<%= escape_javascript(updated_row)%>'); - <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> - ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); <% end %> <% end %> <% else %> diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 2249f08031..91ff2674e2 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -30,9 +30,7 @@ def list_respond_to_html end end def list_respond_to_js - if params[:adapter] - render(:partial => 'list_with_header') - elsif embedded? + if params[:adapter] || embedded? render(:partial => 'list_with_header') else render :action => 'refresh_list', :formats => [:js] diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 831813db81..fbb8ef21d7 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -47,9 +47,12 @@ def update_respond_to_html end end def update_respond_to_js - if successful? && update_refresh_list? && !render_parent? - do_search if respond_to? :do_search - do_list + if successful? + if update_refresh_list? && !render_parent? + do_search if respond_to? :do_search + do_list + end + flash.now[:info] = as_(:updated_model, :model => @record.to_label) if active_scaffold_config.update.persistent end render :action => 'on_update' end diff --git a/lib/active_scaffold/config/update.rb b/lib/active_scaffold/config/update.rb index 3bc9ec8143..1f4c415167 100644 --- a/lib/active_scaffold/config/update.rb +++ b/lib/active_scaffold/config/update.rb @@ -18,6 +18,10 @@ def self.link=(val) end @@link = ActiveScaffold::DataStructures::ActionLink.new('edit', :label => :edit, :type => :member, :security_method => :update_authorized?) + # whether the form stays open after an update or not + cattr_accessor :persistent + @@persistent = false + # whether we should refresh list after update or not cattr_accessor :refresh_list @@refresh_list = false @@ -28,6 +32,9 @@ def self.link=(val) attr_accessor :nested_links cattr_accessor :nested_links @@nested_links = false + + # whether the form stays open after an update or not + attr_accessor :persistent attr_writer :hide_nested_column def hide_nested_column From a77444886e0dc2ace4425fa546985fb9f219062e Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 7 May 2012 11:30:42 -1000 Subject: [PATCH 1456/2024] add new record in first active_scaffold, not in all nested scaffolds. Clean some code --- app/assets/javascripts/jquery/active_scaffold.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 6f58a02ef5..f9ee2fb52e 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -356,8 +356,7 @@ var ActiveScaffold = { }, hide_empty_message: function(tbody) { if (this.records_for(tbody).length != 0) { - var empty_message_node = jQuery(tbody).parent().find('tbody.messages p.empty-message') - if (empty_message_node) empty_message_node.hide(); + jQuery(tbody).parent().find('tbody.messages p.empty-message').hide(); } }, reload_if_empty: function(tbody, url) { @@ -380,14 +379,14 @@ var ActiveScaffold = { decrement_record_count: function(scaffold) { // decrement the last record count, firsts record count are in nested lists if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; - scaffold = jQuery(scaffold) + scaffold = jQuery(scaffold); count = scaffold.find('span.active-scaffold-records').last(); if (count) count.html(parseInt(count.html(), 10) - 1); }, increment_record_count: function(scaffold) { // increment the last record count, firsts record count are in nested lists if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; - scaffold = jQuery(scaffold) + scaffold = jQuery(scaffold); count = scaffold.find('span.active-scaffold-records').last(); if (count) count.html(parseInt(count.html(), 10) + 1); }, @@ -465,7 +464,7 @@ var ActiveScaffold = { create_record_row: function(active_scaffold_id, html, options) { if (typeof(active_scaffold_id) == 'string') active_scaffold_id = '#' + active_scaffold_id; - tbody = jQuery(active_scaffold_id).find('tbody.records'); + tbody = jQuery(active_scaffold_id).find('tbody.records').first(); if (options.insert_at == 'top') { tbody.prepend(html); @@ -618,7 +617,7 @@ var ActiveScaffold = { if (element.length == 0) { element = source.closest('form > ol.form'); } - element = element.find('.' + options.field_class + ":first"); + element = element.find('.' + options.field_class).first(); if (element) { if (options.is_subform == false) { @@ -861,7 +860,7 @@ ActiveScaffold.ActionLink = { new ActiveScaffold.Actions.Record(target, parent, loading_indicator); } else if (parent && parent.is('div')) { //table action - new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header'), parent.find('.loading-indicator')); + new ActiveScaffold.Actions.Table(parent.find('a.as_action'), parent.closest('div.active-scaffold').find('tbody.before-header').first(), parent.find('.loading-indicator').first()); } element = jQuery(element); } From 5c31e1f75ebd7b74e0b641812dd42d2027877041 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 7 May 2012 15:38:56 -1000 Subject: [PATCH 1457/2024] fix persistent create --- CHANGELOG | 2 ++ app/assets/javascripts/jquery/active_scaffold.js | 13 +++++++------ app/assets/javascripts/prototype/active_scaffold.js | 13 +++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 38150b6bc4..edaca54153 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ = 3.2.7 (not released) - restore missing update.persistent feature +- fix create.persistent +- add new record in first scaffold, not in all nested scaffolds = 3.2.6 - fix ordering with DISTINCT call diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index f9ee2fb52e..201dd862d7 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -886,6 +886,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ }, open: function(event) { + this.tag.click(); }, insert: function(content) { @@ -899,11 +900,6 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target); }, - reload: function() { - this.close(); - this.open(); - }, - get_new_adapter_id: function() { var id = 'adapter_'; var i = 0; @@ -1052,5 +1048,10 @@ ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({ throw 'Unknown position "' + this.position + '"' } ActiveScaffold.highlight(this.adapter.find('td').first().children()); - } + }, + + reload: function() { + this.close(); + this.open(); + }, }); diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index af8c945184..de17d75b47 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -784,6 +784,7 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ }, open: function(event) { + this.tag.click(); }, insert: function(content) { @@ -797,11 +798,6 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target); }, - reload: function() { - this.close(); - this.open(); - }, - get_new_adapter_id: function() { var id = 'adapter_'; var i = 0; @@ -946,7 +942,12 @@ ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstrac throw 'Unknown position "' + this.position + '"' } this.adapter.down('td').down().highlight(); - } + }, + + reload: function() { + this.close(); + this.open(); + }, }); if (Ajax.InPlaceEditor) { From 524f33ce7b6775df5a495c56e5233f81d6166148 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 7 May 2012 16:40:20 -1000 Subject: [PATCH 1458/2024] fix deleting all in habtm with select_ui --- CHANGELOG | 1 + lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index edaca54153..19a3211678 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ - restore missing update.persistent feature - fix create.persistent - add new record in first scaffold, not in all nested scaffolds +- fix deleting all in habtm with select_ui = 3.2.6 - fix ordering with DISTINCT call diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 7f997b715a..8fc7a4e54b 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -123,7 +123,7 @@ def active_scaffold_input_plural_association(column, options) def active_scaffold_checkbox_list(column, select_options, associated_ids, options) html = content_tag :ul, :class => "#{options[:class]} checkbox-list", :id => options[:id] do - content = "".html_safe + content = hidden_field_tag("#{options[:name]}[]", '') select_options.each_with_index do |option, i| label, id = option this_id = "#{options[:id]}_#{i}_id" From 76c1eb1588a5c3e7fc6a32c61353374613f028c8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 8 May 2012 10:39:21 +0200 Subject: [PATCH 1459/2024] bump to 3.2.7 --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index b275d2089d..82ef1b00a0 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 6 + PATCH = 7 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 6269a8fd0c55a0a7364796d957b4272f3aead7bd Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 8 May 2012 08:42:48 -1000 Subject: [PATCH 1460/2024] add deprecation for update_column, update_columns should be used instead --- CHANGELOG | 5 ++++- lib/active_scaffold/data_structures/column.rb | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 19a3211678..dc40277290 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,7 @@ -= 3.2.7 (not released) += 3.2.8 (not released) +- add deprecation for update_column, update_columns should be used instead + += 3.2.7 - restore missing update.persistent feature - fix create.persistent - add new record in first scaffold, not in all nested scaffolds diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index d7f125b606..401e76edb0 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -67,7 +67,10 @@ def update_columns=(column_names) attr_accessor :send_form_on_update_column # column to be updated in a form when this column changes - attr_accessor :update_column + def update_column=(column_name) + ActiveSupport::Deprecation.warn "Use update_columns= instead of update_column=" + self.update_columns = column_name + end # send all the form instead of only new value when this column change cattr_accessor :send_form_on_update_column From f9e4fdf12641b1d8c2344a9773c8e3cde2d56bb0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 8 May 2012 10:32:24 -1000 Subject: [PATCH 1461/2024] fix constraints with hide_nested_column disabled in list and embedded scaffolds which are nested too --- CHANGELOG | 1 + lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/actions/create.rb | 4 ++-- lib/active_scaffold/actions/nested.rb | 3 ++- lib/active_scaffold/actions/update.rb | 2 +- lib/active_scaffold/constraints.rb | 16 ++++------------ .../data_structures/nested_info.rb | 11 ++++++----- 7 files changed, 17 insertions(+), 22 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index dc40277290..564e3ff2a8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ = 3.2.8 (not released) - add deprecation for update_column, update_columns should be used instead +- fix constraints with hide_nested_column disabled in list and embedded scaffolds which are nested too = 3.2.7 - restore missing update.persistent feature diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 368b07283b..fd1eb9447c 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -27,7 +27,7 @@ def nested? end def render_field_for_inplace_editing - register_constraints_with_action_columns(nested.constrained_fields, active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested? + register_constraints_with_action_columns(active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested? @record = find_if_allowed(params[:id], :update) render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>" end diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 5340e3e32b..5d35c1ab46 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -84,7 +84,7 @@ def do_new apply_constraints_to_record(@record) if nested? create_association_with_parent(@record) - register_constraints_with_action_columns(nested.constrained_fields) + register_constraints_with_action_columns end @record end @@ -98,7 +98,7 @@ def do_create apply_constraints_to_record(@record, :allow_autosave => true) if nested? create_association_with_parent(@record) - register_constraints_with_action_columns(nested.constrained_fields) + register_constraints_with_action_columns end create_save end diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index f7fe9e68a8..178d34c0cf 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -27,8 +27,9 @@ def set_nested if params[:parent_scaffold] && (params[:association] || params[:named_scope]) @nested = ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, params) unless @nested.nil? + active_scaffold_constraints.merge! @nested.constraints active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to? - register_constraints_with_action_columns(@nested.constrained_fields, active_scaffold_config.list.hide_nested_column ? [] : [:list]) + register_constraints_with_action_columns end end end diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index fbb8ef21d7..c93397ab62 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -68,7 +68,7 @@ def update_respond_to_yaml # A simple method to find and prepare a record for editing # May be overridden to customize the record (set default values, etc.) def do_edit - register_constraints_with_action_columns(nested.constrained_fields, active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested? + register_constraints_with_action_columns(active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested? @record = find_if_allowed(params[:id], :update) end diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index fba14216e3..487dbe259e 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -8,23 +8,15 @@ def active_scaffold_constraints @active_scaffold_constraints ||= active_scaffold_session_storage[:constraints] || {} end - def set_active_scaffold_constraints - associations_by_params = {} - active_scaffold_config.model.reflect_on_all_associations.each do |association| - associations_by_params[association.klass.name.foreign_key] = association.name unless association.options[:polymorphic] - end - params.each do |key, value| - active_scaffold_constraints[associations_by_params[key]] = value if associations_by_params.include? key - end - end - # For each enabled action, adds the constrained columns to the ActionColumns object (if it exists). # This lets the ActionColumns object skip constrained columns. # # If the constraint value is a Hash, then we assume the constraint is a multi-level association constraint (the reverse of a has_many :through) and we do NOT register the constraint column. - def register_constraints_with_action_columns(association_constrained_fields = [], exclude_actions = []) + def register_constraints_with_action_columns(exclude_actions = []) +Rails.logger.debug "CONSTRAINTS: "+active_scaffold_constraints.inspect constrained_fields = active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect{|k| k.to_sym} - constrained_fields = constrained_fields | association_constrained_fields +Rails.logger.debug "CONSTRAINTS: "+constrained_fields.inspect + exclude_actions << :list unless active_scaffold_config.list.hide_nested_column if self.class.uses_active_scaffold? # we actually want to do this whether constrained_fields exist or not, so that we can reset the array when they don't active_scaffold_config.actions.each do |action_name| diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index eba23c0e4a..918742f711 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -19,7 +19,7 @@ def self.get(model, params) end end - attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :constrained_fields, :scope + attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :constrained_fields, :constraints, :scope def initialize(model, nested_info) @parent_model = nested_info[:parent_model] @@ -108,16 +108,16 @@ def to_params protected def iterate_model_associations(model) - @constrained_fields = [] - @constrained_fields << association.foreign_key.to_sym unless association.belongs_to? + @constraints = {} + @constraints[association.foreign_key.to_sym] = parent_id unless association.belongs_to? model.reflect_on_all_associations.each do |current| if !current.belongs_to? && association.foreign_key == current.association_foreign_key - constrained_fields << current.name.to_sym + constraints[current.name.to_sym] = parent_id @child_association = current if current.klass == @parent_model end if association.foreign_key == current.foreign_key # show columns for has_many and has_one child associationes - constrained_fields << current.name.to_sym if current.belongs_to? + constraints[current.name.to_sym] = parent_id if current.belongs_to? if association.options[:as] and current.options[:polymorphic] @child_association = current if association.options[:as].to_sym == current.name else @@ -125,6 +125,7 @@ def iterate_model_associations(model) end end end + @constrained_fields = @constraints.keys end end From 991a89144b6ae8f3bdab3b4071ca7b1dab012cc0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 8 May 2012 13:07:36 -1000 Subject: [PATCH 1462/2024] fix setting a hash in column.includes, cannot be concated in finder --- CHANGELOG | 1 + lib/active_scaffold/data_structures/column.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 564e3ff2a8..e27864991a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ = 3.2.8 (not released) - add deprecation for update_column, update_columns should be used instead - fix constraints with hide_nested_column disabled in list and embedded scaffolds which are nested too +- fix setting a hash as includes, cannot be concat in finder = 3.2.7 - restore missing update.persistent feature diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 401e76edb0..9d362c77e9 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -168,7 +168,7 @@ def calculation? attr_reader :includes def includes=(value) @includes = case value - when Array, Hash then value + when Array then value else [value] # automatically convert to an array end end From ccd2c3e1112bce246631a050afa316eb8a4124a9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 8 May 2012 13:09:22 -1000 Subject: [PATCH 1463/2024] add option to scroll on close only if element is not visible in viewport --- CHANGELOG | 1 + app/assets/javascripts/jquery/active_scaffold.js | 12 +++++++++--- app/assets/javascripts/prototype/active_scaffold.js | 9 ++++++++- lib/active_scaffold.rb | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e27864991a..7e285cbc0f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ - add deprecation for update_column, update_columns should be used instead - fix constraints with hide_nested_column disabled in list and embedded scaffolds which are nested too - fix setting a hash as includes, cannot be concat in finder +- add option to scroll on close only if element is not visible in viewport (default now) = 3.2.7 - restore missing update.persistent feature diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 201dd862d7..704c8f3991 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -534,9 +534,15 @@ var ActiveScaffold = { scroll_to: function(element) { if (typeof(element) == 'string') element = '#' + element; - var form_offset = jQuery(element).offset(), - destination = form_offset.top; - jQuery(document).scrollTop(destination); + var form_offset = jQuery(element).offset().top; + if (ActiveScaffold.config.scroll_on_close == 'checkInViewport') { + var docViewTop = jQuery(window).scrollTop(), + docViewBottom = docViewTop + jQuery(window).height(); + // If it's in viewport , don't scroll; + if (form_offset + jQuery(element).height() <= docViewBottom && form_offset >= docViewTop) return; + } + + jQuery(document).scrollTop(form_offset); }, process_checkbox_inplace_edit: function(checkbox, options) { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index de17d75b47..b1b1fc2b9b 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -485,7 +485,14 @@ var ActiveScaffold = { return ActiveScaffold.ActionLink.get($(element).up('.as_adapter')); }, - scroll_to: function(element) { + scroll_to: function(element, checkInView) { + var form_offset = $(element).viewportOffset().top; + if (ActiveScaffold.config.scroll_on_close == 'checkInViewport') { + var docViewTop = document.viewport.getScrollOffsets().top, + docViewBottom = docViewTop + document.viewport.getHeight(); + // If it's in viewport , don't scroll; + if (form_offset + $(element).getHeight() <= docViewBottom && form_offset >= docViewTop) return; + } $(element).scrollTo(); }, diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index df0bb1992f..ae2ae3d64c 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -138,7 +138,7 @@ def self.js_config=(config) end def self.js_config - @@js_config ||= {:scroll_on_close => true} + @@js_config ||= {:scroll_on_close => :checkInViewport} end # exclude bridges you do not need From 869b0f32afbeb8e3dc8ed77b8e98b75447c4a34a Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 8 May 2012 13:20:11 -1000 Subject: [PATCH 1464/2024] remove debugging --- lib/active_scaffold/constraints.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 487dbe259e..5b16c42cca 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -13,9 +13,7 @@ def active_scaffold_constraints # # If the constraint value is a Hash, then we assume the constraint is a multi-level association constraint (the reverse of a has_many :through) and we do NOT register the constraint column. def register_constraints_with_action_columns(exclude_actions = []) -Rails.logger.debug "CONSTRAINTS: "+active_scaffold_constraints.inspect constrained_fields = active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect{|k| k.to_sym} -Rails.logger.debug "CONSTRAINTS: "+constrained_fields.inspect exclude_actions << :list unless active_scaffold_config.list.hide_nested_column if self.class.uses_active_scaffold? # we actually want to do this whether constrained_fields exist or not, so that we can reset the array when they don't From 8423b0a390b2c2d56588adcf27b9679825ad799f Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 8 May 2012 14:48:53 -1000 Subject: [PATCH 1465/2024] allow to override submit text in base_form --- frontends/default/views/_base_form.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index 4019a55187..7edb3cc1ba 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -7,6 +7,7 @@ multipart ||= false columns ||= nil end + submit_text ||= form_action body_partial ||= 'form' %> <%= options = {:onsubmit => onsubmit, @@ -42,7 +43,7 @@ end <%= render :partial => body_partial, :locals => { :columns => columns, :form_action => form_action } %> <p class="form-footer"> - <%= submit_tag as_(form_action), :class => "submit" %> + <%= submit_tag as_(submit_text), :class => "submit" %> <%= link_to(as_(:cancel), main_path_to_return, cancel_options) if cancel_link %> <%= loading_indicator_tag(:action => form_action, :id => params[:id]) %> </p> From 54e0ee5e34539b2cc9c2ce1e2fc27124e9331256 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 9 May 2012 10:58:19 -1000 Subject: [PATCH 1466/2024] fix checkInViewport when row is updated, check must be done before updating --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- app/assets/javascripts/prototype/active_scaffold.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 704c8f3991..dc8704e808 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -997,10 +997,10 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ }, close: function(refreshed_content) { + this._super(); if (refreshed_content) { ActiveScaffold.update_row(this.target, refreshed_content); } - this._super(); }, enable: function() { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index b1b1fc2b9b..5f762a13b6 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -894,10 +894,10 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra }, close: function($super, refreshed_content) { + $super(); if (refreshed_content) { ActiveScaffold.update_row(this.target, refreshed_content); } - $super(); }, enable: function() { From f733e45185b774c469fa669f95355edab998c027 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 9 May 2012 12:19:53 -1000 Subject: [PATCH 1467/2024] cleanup some actions code --- lib/active_scaffold/actions/create.rb | 8 ++------ lib/active_scaffold/actions/delete.rb | 5 +---- lib/active_scaffold/actions/list.rb | 5 +++++ lib/active_scaffold/actions/mark.rb | 3 +-- lib/active_scaffold/actions/update.rb | 5 +---- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 5d35c1ab46..0e2973d984 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -48,8 +48,7 @@ def create_respond_to_html end else if !nested? && active_scaffold_config.actions.include?(:list) && active_scaffold_config.list.always_show_create - do_list - render(:action => 'list') + list else render(:action => 'create') end @@ -58,10 +57,7 @@ def create_respond_to_html end def create_respond_to_js - if successful? && active_scaffold_config.create.refresh_list && !render_parent? - do_search if respond_to? :do_search - do_list - end + do_refresh_list if successful? && active_scaffold_config.create.refresh_list && !render_parent? render :action => 'on_create' end diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 7114d86ad9..ee8082b202 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -23,10 +23,7 @@ def destroy_respond_to_html end def destroy_respond_to_js - if successful? && active_scaffold_config.delete.refresh_list && !render_parent? - do_search if respond_to? :do_search - do_list - end + do_refresh_list if successful? && active_scaffold_config.delete.refresh_list && !render_parent? render(:action => 'destroy') end diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 91ff2674e2..6c19091519 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -78,6 +78,11 @@ def do_list end @page, @records = page, page.items end + + def do_refresh_list + do_search if respond_to? :do_search + do_list + end def each_record_in_page _page = active_scaffold_config.list.user.page diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index 5eaf5229a6..7d73fa4d5f 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -13,17 +13,16 @@ def mark_all else do_unmark end + do_list respond_to_action(:mark_all) end protected def mark_all_respond_to_html - do_list list_respond_to_html end def mark_all_respond_to_js - do_list render :action => 'on_mark_all', :locals => {:mark_all => mark_all?} end diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index c93397ab62..cab6333292 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -48,10 +48,7 @@ def update_respond_to_html end def update_respond_to_js if successful? - if update_refresh_list? && !render_parent? - do_search if respond_to? :do_search - do_list - end + do_refresh_list if update_refresh_list? && !render_parent? flash.now[:info] = as_(:updated_model, :model => @record.to_label) if active_scaffold_config.update.persistent end render :action => 'on_update' From 64abbd4a898626b6a5b15671dd28e1d554a44a05 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 9 May 2012 16:22:08 -1000 Subject: [PATCH 1468/2024] improve support in process_action_link_action for refresh list in collection actions and close form in action links with position --- .../javascripts/jquery/active_scaffold.js | 7 ++-- .../javascripts/prototype/active_scaffold.js | 7 ++-- frontends/default/views/_refresh_list.js.erb | 1 + .../default/views/on_action_update.js.erb | 35 ++++++++++++------- frontends/default/views/refresh_list.js.erb | 3 +- lib/active_scaffold/actions/list.rb | 20 +++++------ lib/active_scaffold/finder.rb | 4 +-- 7 files changed, 44 insertions(+), 33 deletions(-) create mode 100644 frontends/default/views/_refresh_list.js.erb diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index dc8704e808..13b1d486ab 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -532,10 +532,11 @@ var ActiveScaffold = { return ActiveScaffold.ActionLink.get(as_adapter); }, - scroll_to: function(element) { + scroll_to: function(element, checkInViewport) { + if (typeof checkInViewport == 'undefined') checkInViewport = true; if (typeof(element) == 'string') element = '#' + element; var form_offset = jQuery(element).offset().top; - if (ActiveScaffold.config.scroll_on_close == 'checkInViewport') { + if (checkInViewport) { var docViewTop = jQuery(window).scrollTop(), docViewBottom = docViewTop + jQuery(window).height(); // If it's in viewport , don't scroll; @@ -903,7 +904,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ this.enable(); this.adapter.remove(); if (this.hide_target) this.target.show(); - if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target); + if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target, ActiveScaffold.config.scroll_on_close == 'checkInViewport'); }, get_new_adapter_id: function() { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 5f762a13b6..7c16ec6a3f 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -485,9 +485,10 @@ var ActiveScaffold = { return ActiveScaffold.ActionLink.get($(element).up('.as_adapter')); }, - scroll_to: function(element, checkInView) { + scroll_to: function(element, checkInViewport) { + if (typeof checkInViewport == 'undefined') checkInViewport = true; var form_offset = $(element).viewportOffset().top; - if (ActiveScaffold.config.scroll_on_close == 'checkInViewport') { + if (checkInViewport) { var docViewTop = document.viewport.getScrollOffsets().top, docViewBottom = docViewTop + document.viewport.getHeight(); // If it's in viewport , don't scroll; @@ -802,7 +803,7 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ this.enable(); this.adapter.remove(); if (this.hide_target) this.target.show(); - if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target); + if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target, ActiveScaffold.config.scroll_on_close == 'checkInViewport'); }, get_new_adapter_id: function() { diff --git a/frontends/default/views/_refresh_list.js.erb b/frontends/default/views/_refresh_list.js.erb new file mode 100644 index 0000000000..4c76e4a8f5 --- /dev/null +++ b/frontends/default/views/_refresh_list.js.erb @@ -0,0 +1 @@ +ActiveScaffold.replace_html('<%=active_scaffold_content_id%>','<%=escape_javascript(render(:partial => 'list', :layout => false))%>'); \ No newline at end of file diff --git a/frontends/default/views/on_action_update.js.erb b/frontends/default/views/on_action_update.js.erb index 544d954c94..32b76c7db7 100644 --- a/frontends/default/views/on_action_update.js.erb +++ b/frontends/default/views/on_action_update.js.erb @@ -1,13 +1,24 @@ -<%if controller.send :successful?%> - ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>','<%=escape_javascript(render(:partial => 'messages'))%>'); - <%if @record%> - ActiveScaffold.update_row('<%=element_row_id(:action => :list, :id => @record.id)%>','<%=escape_javascript(render(:partial => 'list_record', :locals => {:record => @record}))%>'); - <%end%> - <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> - ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); +<% if controller.send :successful? %> + <% if @record %> + ActiveScaffold.replace_html('<%= active_scaffold_messages_id %>','<%= escape_javascript(render(:partial => 'messages')) %>'); + var row = '<%= escape_javascript(render(:partial => 'list_record', :locals => {:record => @record})) %>'; + <% if @action_link.nil? || @action_link.position %> + ActiveScaffold.find_action_link('<%= element_row_id(:action => :list, :id => @record.id) %>').close(row); + <% else %> + ActiveScaffold.update_row('<%= element_row_id(:action => :list, :id => @record.id) %>', row); + ActiveScaffold.scroll_to('<%= element_row_id(:action => :list, :id => @record.id) %>', true); <% end %> -<%else%> - <%flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br)%> - ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>','<%=escape_javascript(render(:partial => 'messages'))%>'); - ActiveScaffold.scroll_to('<%=active_scaffold_messages_id%>'); -<%end%> \ No newline at end of file + <% if active_scaffold_config.list.columns.any? {|c| c.calculation?} %> + ActiveScaffold.replace('<%= active_scaffold_calculations_id %>', '<%= escape_javascript(render(:partial => 'list_calculations')) %>'); + <% end %> + <% else %> + <% if @action_link.nil? || @action_link.position %> + ActiveScaffold.find_action_link('<%= element_row_id(:action => action_name) %>').close(); + <% end %> + <%= render :partial => 'refresh_list' %> + <% end %> +<% else %> + <% flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) %> + ActiveScaffold.replace_html('<%= active_scaffold_messages_id %>','<%= escape_javascript(render(:partial => 'messages')) %>'); + ActiveScaffold.scroll_to('<%= active_scaffold_messages_id %>', true); +<% end %> diff --git a/frontends/default/views/refresh_list.js.erb b/frontends/default/views/refresh_list.js.erb index 4c76e4a8f5..c5855d99a7 100644 --- a/frontends/default/views/refresh_list.js.erb +++ b/frontends/default/views/refresh_list.js.erb @@ -1 +1,2 @@ -ActiveScaffold.replace_html('<%=active_scaffold_content_id%>','<%=escape_javascript(render(:partial => 'list', :layout => false))%>'); \ No newline at end of file +<% ActiveSupport::Deprecation.warn "You should use render :partial => 'refresh_list' instead of render :action => 'refresh_list'" %> +<%= render :partial => 'refresh_list' %> diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 6c19091519..07dc84093d 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -16,7 +16,11 @@ def row end def list - do_list + if %w(index list).include? action_name + do_list + else + do_refresh_list + end @nested_auto_open = active_scaffold_config.list.nested_auto_open respond_to_action(:list) end @@ -33,7 +37,7 @@ def list_respond_to_js if params[:adapter] || embedded? render(:partial => 'list_with_header') else - render :action => 'refresh_list', :formats => [:js] + render :partial => 'refresh_list', :formats => [:js] end end def list_respond_to_xml @@ -94,13 +98,7 @@ def each_record_in_page def each_record_in_scope do_search if respond_to? :do_search - finder_options = { :order => "#{active_scaffold_config.model.connection.quote_table_name(active_scaffold_config.model.table_name)}.#{active_scaffold_config.model.primary_key} ASC", - :conditions => all_conditions, - :joins => joins_for_finder} - finder_options.merge! custom_finder_options - finder_options.merge! :include => (active_scaffold_includes.blank? ? nil : active_scaffold_includes) - klass = beginning_of_chain - klass.all(finder_options).each {|record| yield record} + append_to_query(beginning_of_chain, finder_options).all.each {|record| yield record} end # The default security delegates to ActiveRecordPermissions. @@ -122,6 +120,7 @@ def process_action_link_action(render_action = :action_update, crud_type = nil) @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0 respond_to_action(:action_confirmation) else + @action_link = active_scaffold_config.action_links[action_name] if params[:id] && params[:id] && params[:id].to_i > 0 crud_type ||= (request.post? || request.put?) ? :update : :delete @record = find_if_allowed(params[:id], crud_type) @@ -144,12 +143,11 @@ def action_confirmation_respond_to_html(confirm_action = action_name.to_sym) end def action_update_respond_to_html - do_search if respond_to? :do_search - do_list redirect_to :action => 'index' end def action_update_respond_to_js + do_refresh_list unless @record.present? render(:action => 'on_action_update') end diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 3c2840ac69..789829b73e 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -265,8 +265,6 @@ def find_if_allowed(id, crud_type, klass = beginning_of_chain) # * :per_page # * :page def finder_options(options = {}) - options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination, :select - search_conditions = all_conditions full_includes = (active_scaffold_includes.blank? ? nil : active_scaffold_includes) @@ -291,8 +289,8 @@ def count_options(find_options = {}, count_includes = nil) # returns a Paginator::Page (not from ActiveRecord::Paginator) for the given parameters # See finder_options for valid options - # TODO: this should reside on the model, not the controller def find_page(options = {}) + options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination options[:per_page] ||= 999999999 options[:page] ||= 1 From 0cdfbc13a49d33f428aa73a9c2d929d02173c518 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 10 May 2012 06:00:20 +0200 Subject: [PATCH 1469/2024] call action_respond_to_format only if it's defined, in other case default render behavior will be used --- lib/active_scaffold/actions/core.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index fd1eb9447c..6103d023f1 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -178,7 +178,11 @@ def new_model def respond_to_action(action) respond_to do |type| action_formats.each do |format| - type.send(format){ send("#{action}_respond_to_#{format}") } + type.send(format) do + if respond_to?(method_name = "#{action}_respond_to_#{format}") + send(method_name) + end + end end end end From 1ff87f4908a64b1683ea8c577a01b982b54f98bd Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 10 May 2012 10:35:39 -1000 Subject: [PATCH 1470/2024] add some partials to dry js views --- .../javascripts/jquery/active_scaffold.js | 4 +- .../javascripts/prototype/active_scaffold.js | 3 +- .../default/views/_list_calculations.html.erb | 2 +- frontends/default/views/_refresh_list.js.erb | 2 +- frontends/default/views/_row.html.erb | 4 +- frontends/default/views/_search.html.erb | 4 +- .../default/views/_update_calculations.js.erb | 4 ++ .../default/views/_update_messages.js.erb | 2 + frontends/default/views/add_existing.js.erb | 8 +--- frontends/default/views/destroy.js.erb | 44 +++++++++---------- .../default/views/on_action_update.js.erb | 12 +++-- frontends/default/views/on_create.js.erb | 22 ++++------ frontends/default/views/on_update.js.erb | 32 ++++++-------- frontends/default/views/update_column.js.erb | 25 +++++------ .../helpers/controller_helpers.rb | 22 +++++++--- lib/active_scaffold/helpers/id_helpers.rb | 4 +- 16 files changed, 96 insertions(+), 98 deletions(-) create mode 100644 frontends/default/views/_update_calculations.js.erb create mode 100644 frontends/default/views/_update_messages.js.erb diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 13b1d486ab..d8787d925d 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -528,8 +528,8 @@ var ActiveScaffold = { find_action_link: function(element) { if (typeof(element) == 'string') element = '#' + element; - var as_adapter = jQuery(element).closest('.as_adapter'); - return ActiveScaffold.ActionLink.get(as_adapter); + element = jQuery(element); + return ActiveScaffold.ActionLink.get(element.is('a') ? element : element.closest('.as_adapter')); }, scroll_to: function(element, checkInViewport) { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 7c16ec6a3f..1383729a2b 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -482,7 +482,8 @@ var ActiveScaffold = { }, find_action_link: function(element) { - return ActiveScaffold.ActionLink.get($(element).up('.as_adapter')); + element = $(element); + return ActiveScaffold.ActionLink.get(element.match('a') ? element : element.up('.as_adapter')); }, scroll_to: function(element, checkInViewport) { diff --git a/frontends/default/views/_list_calculations.html.erb b/frontends/default/views/_list_calculations.html.erb index 7afbcb67c8..d0491c1cc0 100644 --- a/frontends/default/views/_list_calculations.html.erb +++ b/frontends/default/views/_list_calculations.html.erb @@ -2,7 +2,7 @@ columns ||= list_columns -%> <tr id="<%= active_scaffold_calculations_id %>" class="active-scaffold-calculations"> <% columns.each do |column| -%> - <td <%= "id=#{active_scaffold_calculations_id(column)}" if column.calculation? %>> + <td <%= "id=#{active_scaffold_calculations_id(:column => column)}" if column.calculation? %>> <% if column.calculation? -%> <%= render_column_calculation(column) %> <% else -%> diff --git a/frontends/default/views/_refresh_list.js.erb b/frontends/default/views/_refresh_list.js.erb index 4c76e4a8f5..d79ec9783f 100644 --- a/frontends/default/views/_refresh_list.js.erb +++ b/frontends/default/views/_refresh_list.js.erb @@ -1 +1 @@ -ActiveScaffold.replace_html('<%=active_scaffold_content_id%>','<%=escape_javascript(render(:partial => 'list', :layout => false))%>'); \ No newline at end of file +ActiveScaffold.replace_html('<%= active_scaffold_content_id %>', '<%= escape_javascript(render(:partial => 'list', :layout => false)) %>'); diff --git a/frontends/default/views/_row.html.erb b/frontends/default/views/_row.html.erb index b31788bc75..33d0f4e0de 100644 --- a/frontends/default/views/_row.html.erb +++ b/frontends/default/views/_row.html.erb @@ -1,6 +1,6 @@ <%= render :partial => 'list_record', :locals => {:record => record}%> <%= javascript_tag do %> -ActiveScaffold.replace('<%= active_scaffold_calculations_id %>', '<%= escape_javascript render(:partial => 'list_calculations') %>'); -<% end if active_scaffold_config.list.columns.any? {|c| c.calculation?} %> + <%= render :partial => 'update_calculations', :formats => [:js] %> +<% end %> diff --git a/frontends/default/views/_search.html.erb b/frontends/default/views/_search.html.erb index 4563fbc7a5..67fae54167 100644 --- a/frontends/default/views/_search.html.erb +++ b/frontends/default/views/_search.html.erb @@ -17,13 +17,13 @@ options['data-loading'] = true unless live_search //<![CDATA[ <% if ActiveScaffold.js_framework == :prototype %> new TextFieldWithExample('<%= search_input_id %>', '<%= as_(live_search ? :live_search : :search_terms) %>', {focus: true}); -<% end -%> -<% if live_search && ActiveScaffold.js_framework == :prototype -%> +<% if live_search -%> $(<%= search_input_id.to_json.html_safe %>).next().hide(); new Form.Element.DelayedObserver('<%= search_input_id %>', 0.5, function(element, value) { if (!$(element.id)) return false; // because the element may have been destroyed $(element).next().click(); }); +<% end -%> <% elsif live_search && ActiveScaffold.js_framework == :jquery %> jQuery(<%= "##{search_input_id}".to_json.html_safe %>).next().hide(); jQuery(<%= "##{search_input_id}".to_json.html_safe %>).delayedObserver(0.5, function() { diff --git a/frontends/default/views/_update_calculations.js.erb b/frontends/default/views/_update_calculations.js.erb new file mode 100644 index 0000000000..32347d8282 --- /dev/null +++ b/frontends/default/views/_update_calculations.js.erb @@ -0,0 +1,4 @@ +<% calculations_id ||= active_scaffold_calculations_id -%> +<% if active_scaffold_config.list.columns.any? {|c| c.calculation?} %> + ActiveScaffold.replace('<%= calculations_id %>', '<%= escape_javascript(render(:partial => 'list_calculations')) %>'); +<% end %> diff --git a/frontends/default/views/_update_messages.js.erb b/frontends/default/views/_update_messages.js.erb new file mode 100644 index 0000000000..3800667202 --- /dev/null +++ b/frontends/default/views/_update_messages.js.erb @@ -0,0 +1,2 @@ +<% messages_id ||= active_scaffold_messages_id -%> +ActiveScaffold.replace_html('<%= messages_id %>', '<%= escape_javascript(render(:partial => 'messages')) %>'); diff --git a/frontends/default/views/add_existing.js.erb b/frontends/default/views/add_existing.js.erb index aa3aaed60f..a26167d307 100644 --- a/frontends/default/views/add_existing.js.erb +++ b/frontends/default/views/add_existing.js.erb @@ -1,18 +1,14 @@ <% new_row = render :partial => 'list_record', :locals => {:record => @record} %> ActiveScaffold.create_record_row('<%= active_scaffold_id %>', '<%= escape_javascript(new_row) %>', <%= {:insert_at => :top}.to_json.html_safe %>); -<% if active_scaffold_config.list.columns.any? {|c| c.calculation?} %> - ActiveScaffold.replace('<%= active_scaffold_calculations_id %>', '<%= escape_javascript(render(:partial => 'list_calculations')) %>'); -<%end%> +<%= render :partial => 'update_calculations' %> <% if form_stays_open ||= true %> <%# why not just re-render the form? that wouldn't utilize a possible do_new override which sets default values.%> ActiveScaffold.reset_form('<%= element_form_id %>'); ActiveScaffold.replace_html('<%= element_messages_id(:action => :add_existing) %>', '<%= escape_javascript(render(:partial => 'form_messages')) %>'); <%# have to delay the focus, because there's no "firstElement" in prototype until at least one element is not disabled%> - <% if ActiveScaffold.js_framework == :prototype %> - ActiveScaffold.focus_first_element_of_form.defer('<%= element_form_id %>'); - <% end %> + ActiveScaffold.focus_first_element_of_form<%= '.defer' if ActiveScaffold.js_framework == :prototype %>('<%= element_form_id %>'); <% else %> ActiveScaffold.find_action_link('<%= element_form_id(:action => :new_existing) %>').close(); <% end %> diff --git a/frontends/default/views/destroy.js.erb b/frontends/default/views/destroy.js.erb index 329627e816..cba90a1bf2 100644 --- a/frontends/default/views/destroy.js.erb +++ b/frontends/default/views/destroy.js.erb @@ -1,24 +1,22 @@ -<%messages_id = active_scaffold_messages_id%> -<%if controller.send(:successful?)%> - <%if render_parent? && controller.respond_to?(:render_component_into_view)%> - <%render_parent_options%> - <%if render_parent_action == :row%> - <%# TODO: That s not working with delete....%> - ActiveScaffold.delete_record_row('<%=element_row_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}", :action => 'list', :id => params[:id])%>', '<%=url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max))%>'); - <%messages_id = active_scaffold_messages_id(:controller_id => "as_#{id_from_controller(params[:eid] || params[:parent_sti])}")%> - <%elsif render_parent_action == :index%> - <%= escape_javascript(controller.send(:render_component_into_view, render_parent_options))%> - <%end%> - <%#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> - <%elsif (active_scaffold_config.delete.refresh_list)%> - ActiveScaffold.replace('<%=active_scaffold_content_id%>', '<%=escape_javascript(render(:partial => 'list', :layout => false))%>'); - <%else%> - ActiveScaffold.delete_record_row('<%=element_row_id(:action => 'list', :id => params[:id])%>', '<%=url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max))%>'); - <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> - ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); +<% messages_id = active_scaffold_messages_id %> +<% if controller.send(:successful?) %> + <% if render_parent? && controller.respond_to?(:render_component_into_view) %> + <% if render_parent_action == :row %> + <%# TODO: That s not working with delete.... %> + <% current_id = controller_id(params[:eid] || params[:parent_sti]) -%> + ActiveScaffold.delete_record_row('<%= element_row_id(:controller_id => current_id, :action => 'list', :id => params[:id]) %>', '<%= url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max)) %>'); + <% messages_id = active_scaffold_messages_id(:controller_id => current_id) %> + <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => current_id)} %> + <% elsif render_parent_action == :index %> + <%= escape_javascript(controller.send(:render_component_into_view, render_parent_options)) %> <% end %> - <%end%> -<%else%> - <%flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br)%> -<%end%> -ActiveScaffold.replace_html('<%=messages_id%>', '<%=escape_javascript(render(:partial => 'messages'))%>'); + <% elsif (active_scaffold_config.delete.refresh_list) %> + <%= render :partial => 'refresh_list' %> + <% else %> + ActiveScaffold.delete_record_row('<%= element_row_id(:action => 'list', :id => params[:id]) %>', '<%= url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max)) %>'); + <%= render :partial => 'update_calculations' %> + <% end %> +<% else %> + <% flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) %> +<% end %> +<%= render :partial => 'update_messages', :locals => {:messages_id => messages_id} %> diff --git a/frontends/default/views/on_action_update.js.erb b/frontends/default/views/on_action_update.js.erb index 32b76c7db7..95ffd5c6f6 100644 --- a/frontends/default/views/on_action_update.js.erb +++ b/frontends/default/views/on_action_update.js.erb @@ -1,16 +1,14 @@ <% if controller.send :successful? %> <% if @record %> - ActiveScaffold.replace_html('<%= active_scaffold_messages_id %>','<%= escape_javascript(render(:partial => 'messages')) %>'); - var row = '<%= escape_javascript(render(:partial => 'list_record', :locals => {:record => @record})) %>'; + <%= render :partial => 'update_messages' %> + <% row = escape_javascript(render(:partial => 'list_record', :locals => {:record => @record})) -%> <% if @action_link.nil? || @action_link.position %> - ActiveScaffold.find_action_link('<%= element_row_id(:action => :list, :id => @record.id) %>').close(row); + ActiveScaffold.find_action_link('<%= element_row_id(:action => :list, :id => @record.id) %>').close('<%= row %>'); <% else %> - ActiveScaffold.update_row('<%= element_row_id(:action => :list, :id => @record.id) %>', row); + ActiveScaffold.update_row('<%= element_row_id(:action => :list, :id => @record.id) %>', '<%= row %>'); ActiveScaffold.scroll_to('<%= element_row_id(:action => :list, :id => @record.id) %>', true); <% end %> - <% if active_scaffold_config.list.columns.any? {|c| c.calculation?} %> - ActiveScaffold.replace('<%= active_scaffold_calculations_id %>', '<%= escape_javascript(render(:partial => 'list_calculations')) %>'); - <% end %> + <%= render :partial => 'update_calculations' %> <% else %> <% if @action_link.nil? || @action_link.position %> ActiveScaffold.find_action_link('<%= element_row_id(:action => action_name) %>').close(); diff --git a/frontends/default/views/on_create.js.erb b/frontends/default/views/on_create.js.erb index 92dce8b406..4c1309a6f5 100644 --- a/frontends/default/views/on_create.js.erb +++ b/frontends/default/views/on_create.js.erb @@ -10,23 +10,19 @@ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'mess action_link.close('<%= escape_javascript(parent_rendered)%>'); <% else %> <% if render_parent_action == :row %> - ActiveScaffold.create_record_row(action_link.scaffold(),'<%= escape_javascript(parent_rendered)%>', <%= {:insert_at => insert_at}.to_json.html_safe %>); + ActiveScaffold.create_record_row(action_link.scaffold(),'<%= escape_javascript(parent_rendered) %>', <%= {:insert_at => insert_at}.to_json.html_safe %>); <% elsif render_parent_action == :index %> <%= escape_javascript(parent_rendered) %> <% end %> action_link.close(); <% end %> - <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> - ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); - <% end %> + <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)} unless render_parent_action == :index %> <% elsif (active_scaffold_config.create.refresh_list) %> - ActiveScaffold.replace_html('<%= active_scaffold_content_id%>', '<%= escape_javascript(render(:partial => 'list', :layout => false)) %>'); + <%= render :partial => 'refresh_list' %> <% elsif params[:parent_controller].nil? %> <% new_row = render :partial => 'list_record', :locals => {:record => @record} %> - ActiveScaffold.create_record_row(action_link.scaffold(),'<%=escape_javascript(new_row)%>', <%={:insert_at => insert_at}.to_json.html_safe%>); - <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> - ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); - <% end %> + ActiveScaffold.create_record_row(action_link.scaffold(),'<%= escape_javascript(new_row) %>', <%= {:insert_at => insert_at}.to_json.html_safe %>); + <%= render :partial => 'update_calculations' %> <% end %> <% unless render_parent? %> @@ -36,12 +32,12 @@ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'mess action_link.close(); <% end %> <% if (active_scaffold_config.create.action_after_create) %> - var link = $('<%=action_link_id active_scaffold_config.create.action_after_create, @record.id%>'); - if (link) (function() { link.action_link.open() }).defer(); + var link = ActiveScaffold.find_action_link('<%= action_link_id active_scaffold_config.create.action_after_create, @record.id %>'); + if (link) (function() { link.open() })<%= '.defer' if ActiveScaffold.js_framework == :prototype %>(); <% end %> <% end %> <% else %> - ActiveScaffold.replace('<%=form_selector%>','<%=escape_javascript(render(:partial => 'create_form', :locals => {:xhr => true}))%>'); - ActiveScaffold.scroll_to('<%=form_selector%>'); + ActiveScaffold.replace('<%= form_selector %>','<%= escape_javascript(render(:partial => 'create_form', :locals => {:xhr => true})) %>'); + ActiveScaffold.scroll_to('<%= form_selector %>', true); <% end %> } catch (e) { alert('RJS error:\n\n' + e.toString());} diff --git a/frontends/default/views/on_update.js.erb b/frontends/default/views/on_update.js.erb index 644593547a..af12ef90e5 100644 --- a/frontends/default/views/on_update.js.erb +++ b/frontends/default/views/on_update.js.erb @@ -1,33 +1,27 @@ try { <% form_selector = "#{element_form_id(:action => :update)}" %> -var action_link = ActiveScaffold.find_action_link('<%= form_selector%>'); -action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages'))%>'); +var action_link = ActiveScaffold.find_action_link('<%= form_selector %>'); +action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'messages')) %>'); <% if controller.send :successful? %> <% if !active_scaffold_config.update.persistent %> <% if render_parent? && controller.respond_to?(:render_component_into_view) %> <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> - <% if nested_singular_association? %> - action_link.close('<%= escape_javascript(parent_rendered)%>'); - <% else %> - <% if render_parent_action == :row %> - action_link.close('<%= escape_javascript(parent_rendered)%>'); - <% elsif render_parent_action == :index %> - <%= escape_javascript(parent_rendered) %> - <% end %> + <% if nested_singular_association? || render_parent_action == :row %> + action_link.close('<%= escape_javascript(parent_rendered) %>'); + <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)} %> + <% elsif render_parent_action == :index %> + <%= escape_javascript(parent_rendered) %> <% end %> - <%#page.call 'ActiveScaffold.replace', active_scaffold_calculations_id, render(:partial => 'list_calculations') if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> <% elsif update_refresh_list? %> - ActiveScaffold.replace_html('<%= active_scaffold_content_id%>', '<%= escape_javascript(render(:partial => 'list', :layout => false))%>'); + <%= render :partial => 'refresh_list' %> <% else %> - <% updated_row = render :partial => 'list_record', :locals => {:record => @record}%> - action_link.close('<%= escape_javascript(updated_row)%>'); - <% if active_scaffold_config.list.columns.any? {|c| c.calculation?}%> - ActiveScaffold.replace('<%=active_scaffold_calculations_id%>', '<%=escape_javascript(render(:partial => 'list_calculations'))%>'); - <% end %> + <% updated_row = render :partial => 'list_record', :locals => {:record => @record} %> + action_link.close('<%= escape_javascript(updated_row) %>'); + <%= render :partial => 'update_calculations' %> <% end %> <% end %> <% else %> - ActiveScaffold.replace('<%=form_selector%>','<%=escape_javascript(render(:partial => 'update_form', :locals => {:xhr => true}))%>'); - ActiveScaffold.scroll_to('<%=form_selector%>'); + ActiveScaffold.replace('<%= form_selector %>', '<%= escape_javascript(render(:partial => 'update_form', :locals => {:xhr => true})) %>'); + ActiveScaffold.scroll_to('<%= form_selector %>', true); <% end %> } catch (e) { alert('RJS error:\n\n' + e.toString());} diff --git a/frontends/default/views/update_column.js.erb b/frontends/default/views/update_column.js.erb index a3b9f902d1..33e35c990e 100644 --- a/frontends/default/views/update_column.js.erb +++ b/frontends/default/views/update_column.js.erb @@ -1,16 +1,15 @@ <% @column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column]) %> -<% unless controller.send :successful?%> - alert('<%= escape_javascript(@record.errors.full_messages.join("\n"))%>'); - <% @record.reload%> -<% end%> -<% column = active_scaffold_config.columns[params[:column]]%> +<% unless controller.send :successful? %> + alert('<%= escape_javascript(@record.errors.full_messages.join("\n")) %>'); + <% @record.reload %> +<% end %> +<% column = active_scaffold_config.columns[params[:column]] %> <% if column.inplace_edit%> - ActiveScaffold.replace_html('<%=@column_span_id%>','<%=escape_javascript(get_column_value(@record, column))%>'); -<% else%> + ActiveScaffold.replace_html('<%= @column_span_id %>','<%= escape_javascript(get_column_value(@record, column)) %>'); +<% else %> <% formatted_value = get_column_value(@record, column)%> - ActiveScaffold.replace_html('<%=@column_span_id%>','<%=escape_javascript(formatted_value)%>'); -<% end%> -<% if column.calculation?%> - ActiveScaffold.replace_html('<%=active_scaffold_calculations_id(column)%>', '<%=escape_javascript(render_column_calculation(column))%>'); -<% end%> - + ActiveScaffold.replace_html('<%= @column_span_id %>','<%= escape_javascript(formatted_value) %>'); +<% end %> +<% if column.calculation? %> + ActiveScaffold.replace_html('<%= active_scaffold_calculations_id(:column => column) %>', '<%= escape_javascript(render_column_calculation(column)) %>'); +<% end %> diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index c9e9d04ce9..361758755a 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -59,7 +59,7 @@ def render_parent_options if nested_singular_association? {:controller => nested.parent_scaffold.controller_path, :action => :row, :id => nested.parent_id} elsif params[:parent_sti] - options = {:controller => params[:parent_sti], :action => render_parent_action(params[:parent_sti])} + options = {:controller => params[:parent_sti], :action => render_parent_action} if render_parent_action(params[:parent_sti]) == :index options.merge(params.slice(:eid)) else @@ -68,17 +68,27 @@ def render_parent_options end end - def render_parent_action(controller_path = nil) + def render_parent_action begin @parent_action = :row - parent_controller = "#{controller_path.to_s.camelize}Controller".constantize - @parent_action = :index if action_name == 'create' && parent_controller.active_scaffold_config.actions.include?(:create) && parent_controller.active_scaffold_config.create.refresh_list == true - @parent_action = :index if action_name == 'update' && parent_controller.active_scaffold_config.actions.include?(:update) && parent_controller.active_scaffold_config.update.refresh_list == true - @parent_action = :index if action_name == 'destroy' && parent_controller.active_scaffold_config.actions.include?(:delete) && parent_controller.active_scaffold_config.delete.refresh_list == true + if params[:parent_sti] + parent_controller = "#{params[:parent_sti].to_s.camelize}Controller".constantize + @parent_action = :index if action_name == 'create' && parent_controller.active_scaffold_config.actions.include?(:create) && parent_controller.active_scaffold_config.create.refresh_list == true + @parent_action = :index if action_name == 'update' && parent_controller.active_scaffold_config.actions.include?(:update) && parent_controller.active_scaffold_config.update.refresh_list == true + @parent_action = :index if action_name == 'destroy' && parent_controller.active_scaffold_config.actions.include?(:delete) && parent_controller.active_scaffold_config.delete.refresh_list == true + end rescue ActiveScaffold::ControllerNotFound end if @parent_action.nil? @parent_action end + + def render_parent_controller + if nested_singular_association? + nested.parent_scaffold.controller_path + else + params[:parent_sti] + end + end def build_associated(column, record) if column.singular_association? diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index e2d9234a8a..8811a9a4a3 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -26,8 +26,8 @@ def active_scaffold_messages_id(options = {}) "#{options[:controller_id] || controller_id}-messages" end - def active_scaffold_calculations_id(column = nil) - "#{controller_id}-calculations#{'-' + column.name.to_s if column}" + def active_scaffold_calculations_id(options = {}) + "#{options[:controller_id] || controller_id}-calculations#{'-' + options[:column].name.to_s if options[:column]}" end def empty_message_id From a32023371c5fe80f57902897f756ffc8556df25e Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 10 May 2012 22:50:57 +0200 Subject: [PATCH 1471/2024] add some more defaults to base_form partial --- frontends/default/views/_base_form.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index 7edb3cc1ba..75aa117786 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -7,6 +7,8 @@ multipart ||= false columns ||= nil end + method ||= :post + cancel_link = true if cancel_link.nil? submit_text ||= form_action body_partial ||= 'form' %> <%= From 6c233837440c583309c9e347f16d4897e626e64e Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 10 May 2012 23:31:50 +0200 Subject: [PATCH 1472/2024] fix create and edit singular associations without render_component --- CHANGELOG | 1 + .../javascripts/jquery/active_scaffold.js | 7 +++-- .../javascripts/prototype/active_scaffold.js | 15 ++++++----- frontends/default/views/on_create.js.erb | 27 ++++++++++++------- frontends/default/views/on_update.js.erb | 21 ++++++++++----- frontends/default/views/row.js.erb | 1 + lib/active_scaffold/actions/list.rb | 2 +- 7 files changed, 48 insertions(+), 26 deletions(-) create mode 100644 frontends/default/views/row.js.erb diff --git a/CHANGELOG b/CHANGELOG index 7e285cbc0f..0d6234dde0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ - fix constraints with hide_nested_column disabled in list and embedded scaffolds which are nested too - fix setting a hash as includes, cannot be concat in finder - add option to scroll on close only if element is not visible in viewport (default now) +- fix create and edit singular associations without render_component = 3.2.7 - restore missing update.persistent feature diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index d8787d925d..5a27f0e753 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -361,9 +361,12 @@ var ActiveScaffold = { }, reload_if_empty: function(tbody, url) { if (this.records_for(tbody).length == 0) { - jQuery.getScript(url); + this.reload(url); } }, + reload: function(url) { + jQuery.getScript(url); + }, removeSortClasses: function(scaffold) { if (typeof(scaffold) == 'string') scaffold = '#' + scaffold; scaffold = jQuery(scaffold) @@ -529,7 +532,7 @@ var ActiveScaffold = { find_action_link: function(element) { if (typeof(element) == 'string') element = '#' + element; element = jQuery(element); - return ActiveScaffold.ActionLink.get(element.is('a') ? element : element.closest('.as_adapter')); + return ActiveScaffold.ActionLink.get(element.is('.actions a') ? element : element.closest('.as_adapter')); }, scroll_to: function(element, checkInViewport) { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 1383729a2b..2c7b1a3c89 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -331,13 +331,16 @@ var ActiveScaffold = { }, reload_if_empty: function(tbody, url) { if (this.records_for(tbody).length == 0) { - new Ajax.Request(url, { - method: 'get', - asynchronous: true, - evalScripts: true - }); + this.reload(url); } }, + reload: function(url) { + new Ajax.Request(url, { + method: 'get', + asynchronous: true, + evalScripts: true + }); + }, removeSortClasses: function(scaffold) { scaffold = $(scaffold) scaffold.select('td.sorted').each(function(element) { @@ -483,7 +486,7 @@ var ActiveScaffold = { find_action_link: function(element) { element = $(element); - return ActiveScaffold.ActionLink.get(element.match('a') ? element : element.up('.as_adapter')); + return ActiveScaffold.ActionLink.get(element.match('.actions a') ? element : element.up('.as_adapter')); }, scroll_to: function(element, checkInViewport) { diff --git a/frontends/default/views/on_create.js.erb b/frontends/default/views/on_create.js.erb index 4c1309a6f5..e30918670f 100644 --- a/frontends/default/views/on_create.js.erb +++ b/frontends/default/views/on_create.js.erb @@ -4,19 +4,26 @@ insert_at ||= :top %> var action_link = ActiveScaffold.find_action_link('<%= form_selector%>'); action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages'))%>'); <% if controller.send :successful? %> - <% if render_parent? && controller.respond_to?(:render_component_into_view) %> - <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> - <% if nested_singular_association? %> - action_link.close('<%= escape_javascript(parent_rendered)%>'); + <% if render_parent? %> + <% if controller.respond_to?(:render_component_into_view) %> + <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> + <% if nested_singular_association? %> + action_link.close('<%= escape_javascript(parent_rendered)%>'); + <% else %> + <% if render_parent_action == :row %> + ActiveScaffold.create_record_row(action_link.scaffold(),'<%= escape_javascript(parent_rendered) %>', <%= {:insert_at => insert_at}.to_json.html_safe %>); + <% elsif render_parent_action == :index %> + <%= escape_javascript(parent_rendered) %> + <% end %> + action_link.close(); + <% end %> + <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)} unless render_parent_action == :index %> <% else %> - <% if render_parent_action == :row %> - ActiveScaffold.create_record_row(action_link.scaffold(),'<%= escape_javascript(parent_rendered) %>', <%= {:insert_at => insert_at}.to_json.html_safe %>); - <% elsif render_parent_action == :index %> - <%= escape_javascript(parent_rendered) %> + <% if nested_singular_association? || render_parent_action == :row %> + action_link.close(); <% end %> - action_link.close(); + ActiveScaffold.reload('<%= url_for render_parent_options %>'); <% end %> - <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)} unless render_parent_action == :index %> <% elsif (active_scaffold_config.create.refresh_list) %> <%= render :partial => 'refresh_list' %> <% elsif params[:parent_controller].nil? %> diff --git a/frontends/default/views/on_update.js.erb b/frontends/default/views/on_update.js.erb index af12ef90e5..8a52c09076 100644 --- a/frontends/default/views/on_update.js.erb +++ b/frontends/default/views/on_update.js.erb @@ -4,13 +4,20 @@ var action_link = ActiveScaffold.find_action_link('<%= form_selector %>'); action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'messages')) %>'); <% if controller.send :successful? %> <% if !active_scaffold_config.update.persistent %> - <% if render_parent? && controller.respond_to?(:render_component_into_view) %> - <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> - <% if nested_singular_association? || render_parent_action == :row %> - action_link.close('<%= escape_javascript(parent_rendered) %>'); - <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)} %> - <% elsif render_parent_action == :index %> - <%= escape_javascript(parent_rendered) %> + <% if render_parent? %> + <% if controller.respond_to?(:render_component_into_view) %> + <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> + <% if nested_singular_association? || render_parent_action == :row %> + action_link.close('<%= escape_javascript(parent_rendered) %>'); + <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)} %> + <% elsif render_parent_action == :index %> + <%= escape_javascript(parent_rendered) %> + <% end %> + <% else %> + <% if nested_singular_association? || render_parent_action == :row %> + action_link.close(); + <% end %> + ActiveScaffold.reload('<%= url_for render_parent_options %>'); <% end %> <% elsif update_refresh_list? %> <%= render :partial => 'refresh_list' %> diff --git a/frontends/default/views/row.js.erb b/frontends/default/views/row.js.erb new file mode 100644 index 0000000000..a346641218 --- /dev/null +++ b/frontends/default/views/row.js.erb @@ -0,0 +1 @@ +ActiveScaffold.update_row('<%= element_row_id(:action => :list) %>', '<%= escape_javascript render(:partial => 'row', :locals => {:record => @record}) %>'); diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 07dc84093d..f66bcf8a13 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -174,7 +174,7 @@ def list_formats alias_method :index_formats, :list_formats def row_formats - ([:html] + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq + ([:html, :js] + active_scaffold_config.formats + active_scaffold_config.list.formats).uniq end def action_update_formats From 7af0e5eb6a1ccebf446d80653233b725546c7c73 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 10 May 2012 23:39:31 +0200 Subject: [PATCH 1473/2024] try to fix delete in sti controllers without render_component --- frontends/default/views/destroy.js.erb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontends/default/views/destroy.js.erb b/frontends/default/views/destroy.js.erb index cba90a1bf2..6a8503509b 100644 --- a/frontends/default/views/destroy.js.erb +++ b/frontends/default/views/destroy.js.erb @@ -1,6 +1,6 @@ <% messages_id = active_scaffold_messages_id %> <% if controller.send(:successful?) %> - <% if render_parent? && controller.respond_to?(:render_component_into_view) %> + <% if render_parent? %> <% if render_parent_action == :row %> <%# TODO: That s not working with delete.... %> <% current_id = controller_id(params[:eid] || params[:parent_sti]) -%> @@ -8,7 +8,11 @@ <% messages_id = active_scaffold_messages_id(:controller_id => current_id) %> <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => current_id)} %> <% elsif render_parent_action == :index %> - <%= escape_javascript(controller.send(:render_component_into_view, render_parent_options)) %> + <% if controller.respond_to?(:render_component_into_view) %> + <%= escape_javascript(controller.send(:render_component_into_view, render_parent_options)) %> + <% else %> + ActiveScaffold.reload('<%= url_for render_parent_options %>'); + <% end %> <% end %> <% elsif (active_scaffold_config.delete.refresh_list) %> <%= render :partial => 'refresh_list' %> From bd86a864597f2a7ae6a59b059de83719eb1dd880 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 11 May 2012 00:39:16 +0200 Subject: [PATCH 1474/2024] messages go across all table, use unobtrusive js to close messages --- CHANGELOG | 1 + .../javascripts/jquery/active_scaffold.js | 5 ++++ .../javascripts/prototype/active_scaffold.js | 4 ++++ .../stylesheets/active_scaffold_layout.css | 11 ++++++++- .../default/views/_list_messages.html.erb | 23 ++++++++----------- frontends/default/views/_messages.html.erb | 2 +- lib/active_scaffold/config/list.rb | 8 +++++++ 7 files changed, 39 insertions(+), 15 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 0d6234dde0..b42a19539a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ - fix setting a hash as includes, cannot be concat in finder - add option to scroll on close only if element is not visible in viewport (default now) - fix create and edit singular associations without render_component +- messages go across all table = 3.2.7 - restore missing update.persistent feature diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 5a27f0e753..782a5cc589 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -201,6 +201,11 @@ jQuery(document).ready(function() { } return true; }); + + jQuery('.message a.close').live('click', function(e) { + ActiveScaffold.hide(jQuery(this).closest('.message')); + e.preventDefault(); + }); }); /* Simple Inheritance diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 2c7b1a3c89..91af2c8dd6 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -287,6 +287,10 @@ document.observe("dom:loaded", function() { } return true; }); + document.on('click', '.messages a.close', function(event, element) { + ActiveScaffold.hide(element.up('.message')); + event.stop(); + }); }); diff --git a/app/assets/stylesheets/active_scaffold_layout.css b/app/assets/stylesheets/active_scaffold_layout.css index 973f030064..450f590bf1 100644 --- a/app/assets/stylesheets/active_scaffold_layout.css +++ b/app/assets/stylesheets/active_scaffold_layout.css @@ -433,6 +433,7 @@ border: none; .active-scaffold .empty-message, .active-scaffold .filtered-message { padding: 4px; text-align: center; +position: relative; } .active-scaffold .message { @@ -444,7 +445,15 @@ margin: 2px 7px; line-height: 12px; } -.active-scaffold .message a { +.active-scaffold .filtered-message .reset { +position: absolute; +display: inline; +right: 10px; +top: 4px; +padding: 0; +} + +.active-scaffold .message a.close { position: absolute; right: 10px; top: 4px; diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index a44989272a..eb7b9a85a1 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -1,29 +1,26 @@ <tbody class="messages"> <tr class="record even-record"> - <td colspan="<%= columns.length -%>" class="messages-container"> + <td colspan="<%= columns.length + 1 -%>" class="messages-container"> <p class="error-message message server-error" style="display:none;"> <%= as_(:internal_error).html_safe %> - <a href="#" onclick="ActiveScaffold.hide(this.parentNode); return false;" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a> + <a href="#" class="close" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a> </p> <div id="<%= active_scaffold_messages_id -%>"> <%= render :partial => 'messages' %> </div> - <p class="filtered-message" <%= ' style="display:none;" '.html_safe unless @filtered %>> + <div class="filtered-message" <%= ' style="display:none;" '.html_safe unless @filtered %>> <%= @filtered.is_a?(Array) ? render(:partial => 'human_conditions', :locals => {:columns => @filtered}) : as_(active_scaffold_config.list.filtered_message) %> - </p> + <% if active_scaffold_config.list.show_search_reset && @filtered -%> + <div class="reset"> + <%= loading_indicator_tag(:action => :record, :id => nil) %> + <%= render_action_link(active_scaffold_config.list.reset_link, params_for(:search => '')) %> + </div> + <% end -%> + </div> <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" '.html_safe unless @page.items.empty? %>> <%= as_(active_scaffold_config.list.no_entries_message) %> </p> </td> - <% if active_scaffold_config.list.show_search_reset && @filtered -%> - <% search_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :member, :position => false) - action_links = ActiveScaffold::DataStructures::ActionLinks.new - action_links.add(search_link) -%> - <%= render :partial => 'list_actions', :locals => {:record => new_model, :url_options => params_for(:search => ''), :action_links => action_links.member} %> - <% else %> - <td class='actions'><%= '<p class="empty-message"> </p>'.html_safe if @page.items.empty? %></td> - <% end -%> - </tr> </tbody> diff --git a/frontends/default/views/_messages.html.erb b/frontends/default/views/_messages.html.erb index 4d87e191f4..8b21e1c117 100644 --- a/frontends/default/views/_messages.html.erb +++ b/frontends/default/views/_messages.html.erb @@ -3,7 +3,7 @@ <div class="<%= "#{name}-message message" %>"> <%= h flash[name] %> <% if request.xhr? %> - <a href="#" onclick="ActiveScaffold.remove(this.parentNode); return false;" title="<%= as_(:close) %>"><%= as_(:close) %></a> + <a href="#" class="close" title="<%= as_(:close) %>"><%= as_(:close) %></a> <% end %> </div> <% end %> diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 567c044ce4..ba1e249afb 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -19,6 +19,7 @@ def initialize(core_config) @association_join_text = self.class.association_join_text @pagination = self.class.pagination @show_search_reset = true + @reset_link = self.class.reset_link.clone @mark_records = self.class.mark_records end @@ -61,6 +62,10 @@ def page_links_window=(value) # Add a checkbox in front of each record to mark them and use them with a batch action later cattr_accessor :mark_records + # the ActionLink to reset search + cattr_accessor :reset_link + @@reset_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :collection, :position => false) + # instance-level configuration # ---------------------------- @@ -101,6 +106,9 @@ def page_links_window=(value) # show a link to reset the search next to filtered message attr_accessor :show_search_reset + # the ActionLink to reset search + attr_reader :reset_link + # Add a checkbox in front of each record to mark them and use them with a batch action later attr_accessor :mark_records From 0ad0aee4bad245bf100a9d8058957831885ccee5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 11 May 2012 08:32:41 -1000 Subject: [PATCH 1475/2024] add column_attributes method to add attributes to cells in list, and DRY override helpers code --- .../views/_list_record_columns.html.erb | 4 +- .../helpers/form_column_helpers.rb | 30 +++++-------- .../helpers/list_column_helpers.rb | 29 +++++-------- .../helpers/search_column_helpers.rb | 42 +++++++------------ .../helpers/show_column_helpers.rb | 29 ++++--------- lib/active_scaffold/helpers/view_helpers.rb | 20 ++++++++- 6 files changed, 65 insertions(+), 89 deletions(-) diff --git a/frontends/default/views/_list_record_columns.html.erb b/frontends/default/views/_list_record_columns.html.erb index 7a18c31cfb..40244aa689 100644 --- a/frontends/default/views/_list_record_columns.html.erb +++ b/frontends/default/views/_list_record_columns.html.erb @@ -2,7 +2,7 @@ <% authorized = record.authorized_for?(:crud_type => :read, :column => column.name) -%> <% column_value = authorized ? get_column_value(record, column) : active_scaffold_config.list.empty_field_text -%> - <td class="<%= column_class(column, column_value, record) %>" > + <%= content_tag :td, column_attributes(column, record).merge(:class => column_class(column, column_value, record)) do %> <%= authorized ? render_list_column(column_value, column, record) : column_value %> - </td> + <% end %> <% end -%> diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 8fc7a4e54b..645ae3ae16 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -15,11 +15,11 @@ def active_scaffold_input_for(column, scope = nil, options = {}) def active_scaffold_render_input(column, options) begin # first, check if the dev has created an override for this specific field - if override_form_field?(column) - send(override_form_field(column), @record, options) + if (method = override_form_field(column)) + send(method, @record, options) # second, check if the dev has specified a valid form_ui for this column - elsif column.form_ui and override_input?(column.form_ui) - send(override_input(column.form_ui), column, options) + elsif column.form_ui and (method = override_input(column.form_ui)) + send(method, column, options) # fallback: we get to make the decision else if column.association @@ -36,8 +36,8 @@ def active_scaffold_render_input(column, options) else # regular model attribute column # if we (or someone else) have created a custom render option for the column type, use that - if override_input?(column.column.type) - send(override_input(column.column.type), column, options) + if (method = override_input(column.column.type)) + send(method, column, options) # final ultimate fallback: use rails' generic input method else # for textual fields we pass different options @@ -229,26 +229,16 @@ def override_form_field_partial(column) end def override_form_field(column) - method_with_class = override_form_field_name(column, true) - return method_with_class if respond_to?(method_with_class) - method = override_form_field_name(column) - method if respond_to?(method) + override_helper column, 'form_column' end alias_method :override_form_field?, :override_form_field - # the naming convention for overriding form fields with helpers - def override_form_field_name(column, class_prefix = false) - "#{clean_class_name(column.active_record_class.name) + '_' if class_prefix}#{clean_column_name(column.name)}_form_column" - end - - def override_input?(form_ui) - respond_to?(override_input(form_ui)) - end - # the naming convention for overriding form input types with helpers def override_input(form_ui) - "active_scaffold_input_#{form_ui}" + method = "active_scaffold_input_#{form_ui}" + method if respond_to? method end + alias_method :override_input?, :override_input def form_partial_for_column(column, renders_as = nil) renders_as ||= column_renders_as(column) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 58f95d13b0..4091e244f2 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -6,16 +6,16 @@ module ListColumnHelpers def get_column_value(record, column) begin # check for an override helper - value = if column_override? column + value = if (method = column_override(column)) # we only pass the record as the argument. we previously also passed the formatted_value, # but mike perham pointed out that prohibited the usage of overrides to improve on the # performance of our default formatting. see issue #138. - send(column_override(column), record) + send(method, record) # second, check if the dev has specified a valid list_ui for this column - elsif column.list_ui and override_column_ui?(column.list_ui) - send(override_column_ui(column.list_ui), column, record) - elsif column.column and override_column_ui?(column.column.type) - send(override_column_ui(column.column.type), column, record) + elsif column.list_ui and (method = override_column_ui(column.list_ui)) + send(method, column, record) + elsif column.column and (method = override_column_ui(column.column.type)) + send(method, column, record) else format_column_value(record, column) end @@ -128,26 +128,17 @@ def active_scaffold_column_checkbox(column, record) check_box(:record, column.name, options) end - def column_override_name(column, class_prefix = false) - "#{clean_class_name(column.active_record_class.name) + '_' if class_prefix}#{clean_column_name(column.name)}_column" - end - def column_override(column) - method_with_class = column_override_name(column, true) - return method_with_class if respond_to?(method_with_class) - method = column_override_name(column) - method if respond_to?(method) + override_helper column, 'column' end alias_method :column_override?, :column_override - def override_column_ui?(list_ui) - respond_to?(override_column_ui(list_ui)) - end - # the naming convention for overriding column types with helpers def override_column_ui(list_ui) - "active_scaffold_column_#{list_ui}" + method = "active_scaffold_column_#{list_ui}" + method if respond_to? method end + alias_method :override_column_ui?, :override_column_ui ## ## Formatting diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 8ca4168a15..62e5ec49a0 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -8,20 +8,20 @@ def active_scaffold_search_for(column) options = active_scaffold_search_options(column) # first, check if the dev has created an override for this specific field for search - if override_search_field?(column) - send(override_search_field(column), @record, options) + if (method = override_search_field(column)) + send(method, @record, options) # second, check if the dev has specified a valid search_ui for this column, using specific ui for searches - elsif column.search_ui and override_search?(column.search_ui) - send(override_search(column.search_ui), column, options) + elsif column.search_ui and (method = override_search(column.search_ui)) + send(method, column, options) # third, check if the dev has specified a valid search_ui for this column, using generic ui for forms - elsif column.search_ui and override_input?(column.search_ui) - send(override_input(column.search_ui), column, options) + elsif column.search_ui and (method = override_input(column.search_ui)) + send(method, column, options) # fourth, check if the dev has created an override for this specific field - elsif override_form_field?(column) - send(override_form_field(column), @record, options) + elsif (method = override_form_field(column)) + send(method, @record, options) # fallback: we get to make the decision else @@ -30,11 +30,11 @@ def active_scaffold_search_for(column) else # regular model attribute column # if we (or someone else) have created a custom render option for the column type, use that - if override_search?(column.column.type) - send(override_search(column.column.type), column, options) + if (method = override_search(column.column.type)) + send(method, column, options) # if we (or someone else) have created a custom render option for the column type, use that - elsif override_input?(column.column.type) - send(override_input(column.column.type), column, options) + elsif (method = override_input(column.column.type)) + send(method, column, options) # final ultimate fallback: use rails' generic input method else # for textual fields we pass different options @@ -216,25 +216,13 @@ def active_scaffold_search_time(column, options) ## def override_search_field(column) - method_with_class = override_search_field_name(column, true) - return method_with_class if respond_to?(method_with_class) - method = override_search_field_name(column) - method if respond_to?(method) - end - alias_method :override_search_field?, :override_search_field - - # the naming convention for overriding form fields with helpers - def override_search_field_name(column, class_prefix = false) - "#{clean_class_name(column.active_record_class.name) + '_' if class_prefix}#{clean_column_name(column.name)}_search_column" - end - - def override_search?(search_ui) - respond_to?(override_search(search_ui)) + override_helper column, 'search_column' end # the naming convention for overriding search input types with helpers def override_search(form_ui) - "active_scaffold_search_#{form_ui}" + method = "active_scaffold_search_#{form_ui}" + method if respond_to? method end def visibles_and_hiddens(search_config) diff --git a/lib/active_scaffold/helpers/show_column_helpers.rb b/lib/active_scaffold/helpers/show_column_helpers.rb index 3c86065990..376cb150a9 100644 --- a/lib/active_scaffold/helpers/show_column_helpers.rb +++ b/lib/active_scaffold/helpers/show_column_helpers.rb @@ -4,17 +4,17 @@ module Helpers module ShowColumnHelpers def show_column_value(record, column) # check for an override helper - if show_column_override? column + if (method = show_column_override(column)) # we only pass the record as the argument. we previously also passed the formatted_value, # but mike perham pointed out that prohibited the usage of overrides to improve on the # performance of our default formatting. see issue #138. - send(show_column_override(column), record) + send(method, record) # second, check if the dev has specified a valid list_ui for this column - elsif column.list_ui and override_show_column_ui?(column.list_ui) - send(override_show_column_ui(column.list_ui), column, record) + elsif column.list_ui and (method = override_show_column_ui(column.list_ui)) + send(method, column, record) else - if column.column and override_show_column_ui?(column.column.type) - send(override_show_column_ui(column.column.type), column, record) + if column.column and (method = override_show_column_ui(column.column.type)) + send(method, column, record) else get_column_value(record, column) end @@ -25,25 +25,14 @@ def active_scaffold_show_text(column, record) simple_format(clean_column_value(record.send(column.name))) end - def show_column_override_name(column, class_prefix = false) - "#{clean_class_name(column.active_record_class.name) + '_' if class_prefix}#{clean_column_name(column.name)}_show_column" - end - def show_column_override(column) - method_with_class = show_column_override_name(column, true) - return method_with_class if respond_to?(method_with_class) - method = show_column_override_name(column) - method if respond_to?(method) - end - alias_method :show_column_override?, :show_column_override - - def override_show_column_ui?(list_ui) - respond_to?(override_show_column_ui(list_ui)) + override_helper column, 'show_column' end # the naming convention for overriding show types with helpers def override_show_column_ui(list_ui) - "active_scaffold_show_#{list_ui}" + method = "active_scaffold_show_#{list_ui}" + method if respond_to? method end end end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 99b628a700..ef95280567 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -217,7 +217,13 @@ def list_row_class(record) class_override_helper = :"#{clean_class_name(record.class.name)}_list_row_class" respond_to?(class_override_helper) ? send(class_override_helper, record) : '' end - + + def column_attributes(column, record) + method = override_helper column, 'column_attributes' + return send(class_override_helper, record) if method + {} + end + def column_class(column, column_value, record) classes = [] classes << "#{column.name}-column" @@ -293,6 +299,18 @@ def clean_class_name(name) name.underscore.gsub('/', '_') end + # the naming convention for overriding with helpers + def override_helper_name(column, suffix, class_prefix = false) + "#{clean_class_name(column.active_record_class.name) + '_' if class_prefix}#{clean_column_name(column.name)}_#{suffix}" + end + + def override_helper(column, suffix) + method_with_class = override_helper_name(column, suffix, true) + return method_with_class if respond_to?(method_with_class) + method = override_helper_name(column, suffix) + method if respond_to?(method) + end + def active_scaffold_error_messages_for(*params) options = params.extract_options!.symbolize_keys options.reverse_merge!(:container_tag => :div, :list_type => :ul) From b93526eff249dfdc188d264914e60bc2f6a3f9e8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 11 May 2012 11:51:00 -1000 Subject: [PATCH 1476/2024] display readonly associations in forms --- CHANGELOG | 1 + frontends/default/views/_form.html.erb | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b42a19539a..24b05835e6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ - add option to scroll on close only if element is not visible in viewport (default now) - fix create and edit singular associations without render_component - messages go across all table +- display readonly associations in forms, it was ready to display them but it was skipping them = 3.2.7 - restore missing update.persistent feature diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index 9de5a55747..e452729b37 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -11,8 +11,6 @@ <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id, :form_action => form_action } %> <%= link_to_visibility_toggle(subsection_id, {:default_visible => !column.collapsed}) -%> </li> - <% elsif column.readonly_association? - next %> <% elsif renders_as == :subform and !override_form_field?(column) and authorized -%> <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %> <%=column.name%>-sub-form" id="<%= sub_form_id(:association => column.name) %>"> <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%> From 659ec1766c0d863b992a05e1dbab2cfabcb38433 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 11 May 2012 15:01:57 -1000 Subject: [PATCH 1477/2024] fix inplace edit with form overrides --- app/assets/javascripts/jquery/jquery.editinplace.js | 7 +++---- frontends/default/views/update_column.js.erb | 4 ++-- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/jquery/jquery.editinplace.js b/app/assets/javascripts/jquery/jquery.editinplace.js index 6e4af64d6c..9042b91f6a 100644 --- a/app/assets/javascripts/jquery/jquery.editinplace.js +++ b/app/assets/javascripts/jquery/jquery.editinplace.js @@ -312,7 +312,7 @@ $.extend(InlineEditor.prototype, { var editorNode = patternNodes.editNode.clone(); var clonedNodes = null; - if (editorNode.attr('id').length > 0) editorNode.attr('id', editorNode.attr('id') + this.settings.clone_id_suffix); + if (editorNode.attr('id')) editorNode.attr('id', editorNode.attr('id') + this.settings.clone_id_suffix); editorNode.attr('name', 'inplace_value'); editorNode.addClass('editor_field'); this.setValue(editorNode, this.originalValue); @@ -321,7 +321,7 @@ $.extend(InlineEditor.prototype, { if (patternNodes.additionalNodes) { patternNodes.additionalNodes.each(function (index, node) { var patternNode = $(node).clone(); - if (patternNode.attr('id').length > 0) { + if (patternNode.attr('id')) { patternNode.attr('id', patternNode.attr('id') + this.settings.clone_id_suffix); } clonedNodes = clonedNodes.after(patternNode); @@ -342,8 +342,7 @@ $.extend(InlineEditor.prototype, { selectedNodes = firstNode.children(); } nodes.editNode = selectedNodes.first(); - // buggy... - //nodes.additionalNodes = selectedNodes.find(':gt(0)'); + nodes.additionalNodes = selectedNodes.slice(1); } return nodes; }, diff --git a/frontends/default/views/update_column.js.erb b/frontends/default/views/update_column.js.erb index 33e35c990e..23f880c333 100644 --- a/frontends/default/views/update_column.js.erb +++ b/frontends/default/views/update_column.js.erb @@ -4,10 +4,10 @@ <% @record.reload %> <% end %> <% column = active_scaffold_config.columns[params[:column]] %> +<% formatted_value = get_column_value(@record, column)%> <% if column.inplace_edit%> - ActiveScaffold.replace_html('<%= @column_span_id %>','<%= escape_javascript(get_column_value(@record, column)) %>'); + ActiveScaffold.replace_html('<%= @column_span_id %>','<%= escape_javascript(formatted_value) %>'); <% else %> - <% formatted_value = get_column_value(@record, column)%> ActiveScaffold.replace_html('<%= @column_span_id %>','<%= escape_javascript(formatted_value) %>'); <% end %> <% if column.calculation? %> diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 4091e244f2..7ed2d6963b 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -262,7 +262,7 @@ def inplace_edit_control(column) column = column.clone column.options = column.options.clone column.form_ui = :select if (column.association && column.form_ui.nil?) - content_tag(:div, active_scaffold_input_for(column), :style => "display:none;", :class => inplace_edit_control_css_class).tap do + content_tag(:div, active_scaffold_input_for(column).html_safe, :style => "display:none;", :class => inplace_edit_control_css_class).tap do @record = old_record end end From 4593fe7596439eed8d3c6498f37ea23b5a29e731 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 11 May 2012 15:56:08 -1000 Subject: [PATCH 1478/2024] fix for ajax and radiobuttons inplace editors --- app/assets/javascripts/jquery/jquery.editinplace.js | 3 ++- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/jquery/jquery.editinplace.js b/app/assets/javascripts/jquery/jquery.editinplace.js index 9042b91f6a..f48fa87cbf 100644 --- a/app/assets/javascripts/jquery/jquery.editinplace.js +++ b/app/assets/javascripts/jquery/jquery.editinplace.js @@ -285,6 +285,7 @@ $.extend(InlineEditor.prototype, { }, setInitialValue: function() { + if (this.settings.field_type == 'remote') return; // remote generated editor doesn't need initial value var initialValue = this.triggerDelegateCall('willOpenEditInPlace', this.originalValue); var editor = this.dom.find(':input'); editor.val(initialValue); @@ -472,7 +473,7 @@ $.extend(InlineEditor.prototype, { var editor = this.dom.find(':input:not(:button)'); var enteredText = ''; if (editor.length > 1) { - enteredText = jQuery.map(editor.not('input:checkbox:not(:checked)'), function(item, index) { + enteredText = jQuery.map(editor.not('input:checkbox:not(:checked)').not('input:radio:not(:checked)'), function(item, index) { return $(item).val(); }); } else { diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 7ed2d6963b..4091e244f2 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -262,7 +262,7 @@ def inplace_edit_control(column) column = column.clone column.options = column.options.clone column.form_ui = :select if (column.association && column.form_ui.nil?) - content_tag(:div, active_scaffold_input_for(column).html_safe, :style => "display:none;", :class => inplace_edit_control_css_class).tap do + content_tag(:div, active_scaffold_input_for(column), :style => "display:none;", :class => inplace_edit_control_css_class).tap do @record = old_record end end From d7e67c37cc008f9f1148fbf0b4f04b557e952d22 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 11 May 2012 16:22:37 -1000 Subject: [PATCH 1479/2024] inplace editor: remove unchecked checkboxes and radiobuttons before testing length --- CHANGELOG | 1 + app/assets/javascripts/jquery/active_scaffold.js | 1 + app/assets/javascripts/jquery/jquery.editinplace.js | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 24b05835e6..b5a4393f08 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ - fix create and edit singular associations without render_component - messages go across all table - display readonly associations in forms, it was ready to display them but it was skipping them +- Some fixes for inplace editors (cloning form overrides, ajax and radiobuttons) = 3.2.7 - restore missing update.persistent feature diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 782a5cc589..2c9ef20cd6 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -694,6 +694,7 @@ var ActiveScaffold = { in_place_editor_field_clicked: function(span) { span.data(); // $ 1.4.2 workaround + // test editor is open if (typeof(span.data('editInPlace')) === 'undefined') { var options = {show_buttons: true, hover_class: 'hover', diff --git a/app/assets/javascripts/jquery/jquery.editinplace.js b/app/assets/javascripts/jquery/jquery.editinplace.js index f48fa87cbf..833fd3a575 100644 --- a/app/assets/javascripts/jquery/jquery.editinplace.js +++ b/app/assets/javascripts/jquery/jquery.editinplace.js @@ -470,10 +470,10 @@ $.extend(InlineEditor.prototype, { if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent)) return; - var editor = this.dom.find(':input:not(:button)'); + var editor = this.dom.find(':input:not(:button)').not('input:checkbox:not(:checked)').not('input:radio:not(:checked)'); var enteredText = ''; if (editor.length > 1) { - enteredText = jQuery.map(editor.not('input:checkbox:not(:checked)').not('input:radio:not(:checked)'), function(item, index) { + enteredText = jQuery.map(editor, function(item, index) { return $(item).val(); }); } else { From 2ab1aadd1806893ed02d9499cc4a41f6ded2a747 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 11 May 2012 18:45:09 -1000 Subject: [PATCH 1480/2024] add handle for inplace edit --- CHANGELOG | 2 +- .../javascripts/jquery/active_scaffold.js | 30 ++++++++++++++----- .../javascripts/prototype/active_scaffold.js | 20 +++++++++---- .../stylesheets/active_scaffold_layout.css | 6 ++++ frontends/default/views/update_column.js.erb | 6 ++-- .../helpers/list_column_helpers.rb | 1 + lib/active_scaffold/helpers/view_helpers.rb | 1 + 7 files changed, 49 insertions(+), 17 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b5a4393f08..4dd3071795 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,7 +6,7 @@ - fix create and edit singular associations without render_component - messages go across all table - display readonly associations in forms, it was ready to display them but it was skipping them -- Some fixes for inplace editors (cloning form overrides, ajax and radiobuttons) +- Some fixes for inplace editors (cloning form overrides, ajax and radiobuttons). Add handlers for empty columns = 3.2.7 - restore missing update.persistent feature diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 2c9ef20cd6..c3d3299bd5 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -111,18 +111,23 @@ jQuery(document).ready(function() { ActiveScaffold.report_500_response(as_scaffold); return true; }); - jQuery('span.in_place_editor_field').live('hover', function(event) { - jQuery(this).data(); // $ 1.4.2 workaround + jQuery('td.in_place_editor_field').live('hover', function(event) { + var td = jQuery(this), span = td.find('span.in_place_editor_field'); + span.data(); // $ 1.4.2 workaround if (event.type == 'mouseenter') { - if (typeof(jQuery(this).data('editInPlace')) === 'undefined') jQuery(this).addClass("hover"); + if (td.hasClass('empty') || typeof(span.data('editInPlace')) === 'undefined') td.find('span').addClass("hover"); } if (event.type == 'mouseleave') { - if (typeof(jQuery(this).data('editInPlace')) === 'undefined') jQuery(this).removeClass("hover"); + if (td.hasClass('empty') || typeof(span.data('editInPlace')) === 'undefined') td.find('span').removeClass("hover"); } return true; }); - jQuery('span.in_place_editor_field').live('click', function(event) { - ActiveScaffold.in_place_editor_field_clicked(jQuery(this)); + jQuery('td.in_place_editor_field').live('click', function(event) { + var span = jQuery(this).find('span.in_place_editor_field'); + span.data('addEmptyOnCancel', jQuery(this).hasClass('empty')); + jQuery(this).removeClass('empty'); + if (span.data('editInPlace')) span.trigger('click.editInPlace'); + else ActiveScaffold.in_place_editor_field_clicked(span); }); jQuery('a.as_paginate').live('ajax:before',function(event) { var as_paginate = jQuery(this); @@ -431,6 +436,12 @@ var ActiveScaffold = { if (typeof(element) == 'string') element = '#' + element; jQuery(element).remove(); }, + + update_inplace_edit: function(element, value, empty) { + if (typeof(element) == 'string') element = '#' + element; + this.replace_html(jQuery(element), value); + if (empty) jQuery(element).closest('td').addClass('empty'); + }, hide: function(element) { if (typeof(element) == 'string') element = '#' + element; @@ -700,6 +711,11 @@ var ActiveScaffold = { hover_class: 'hover', element_id: 'editor_id', ajax_data_type: "script", + delegate: { + willCloseEditInPlace: function(span, options, enteredText) { + if (span.data('addEmptyOnCancel')) span.closest('td').addClass('empty'); + } + }, update_value: 'value'}, csrf_param = jQuery('meta[name=csrf-param]').first(), csrf_token = jQuery('meta[name=csrf-token]').first(), @@ -707,7 +723,7 @@ var ActiveScaffold = { column_heading = null; if(!(my_parent.is('td') || my_parent.is('th'))){ - my_parent = span.parents('td').eq(0); + my_parent = span.parents('td').eq(0); } if (my_parent.is('td')) { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 91af2c8dd6..36323f2274 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -135,14 +135,16 @@ document.observe("dom:loaded", function() { ActiveScaffold.report_500_response(as_scaffold); return true; }); - document.on('mouseover', 'span.in_place_editor_field', function(event) { - event.findElement().addClassName('hover'); + document.on('mouseover', 'td.in_place_editor_field', function(event) { + event.findElement('td.in_place_editor_field').select('span').invoke('addClassName', 'hover'); }); - document.on('mouseout', 'span.in_place_editor_field', function(event) { - event.findElement().removeClassName('hover'); + document.on('mouseout', 'td.in_place_editor_field', function(event) { + event.findElement('td.in_place_editor_field').select('span').invoke('removeClassName', 'hover'); }); - document.on('click', 'span.in_place_editor_field', function(event) { - var span = event.findElement('span.in_place_editor_field'); + document.on('click', 'td.in_place_editor_field', function(event) { + var td = event.findElement('td.in_place_editor_field'), + span = td.down('span.in_place_editor_field'); + td.removeClassName('empty'); if (typeof(span.inplace_edit) === 'undefined') { var options = {htmlResponse: false, @@ -150,6 +152,7 @@ document.observe("dom:loaded", function() { onLeaveHover: null, onComplete: null, params: '', + externalControl: td.down('.handle'), ajaxOptions: {method: 'post'}}, csrf_param = $$('meta[name=csrf-param]')[0], csrf_token = $$('meta[name=csrf-token]')[0], @@ -392,6 +395,11 @@ var ActiveScaffold = { $(element).remove(); }, + update_inplace_edit: function(element, value, empty) { + this.replace_html(element, value); + if (empty) $(element).up('td').addClassName('empty'); + }, + hide: function(element) { $(element).hide(); }, diff --git a/app/assets/stylesheets/active_scaffold_layout.css b/app/assets/stylesheets/active_scaffold_layout.css index 450f590bf1..7cd019f6b5 100644 --- a/app/assets/stylesheets/active_scaffold_layout.css +++ b/app/assets/stylesheets/active_scaffold_layout.css @@ -203,6 +203,12 @@ padding: 0px; .active-scaffold tbody.records td.empty { text-align: center; } +.active-scaffold tbody.records td.in_place_editor_field .handle { +display:none; +} +.active-scaffold tbody.records td.in_place_editor_field.empty .handle { +display:inline; +} .active-scaffold td.numeric, .active-scaffold-calculations td { diff --git a/frontends/default/views/update_column.js.erb b/frontends/default/views/update_column.js.erb index 23f880c333..5305eef641 100644 --- a/frontends/default/views/update_column.js.erb +++ b/frontends/default/views/update_column.js.erb @@ -4,9 +4,9 @@ <% @record.reload %> <% end %> <% column = active_scaffold_config.columns[params[:column]] %> -<% formatted_value = get_column_value(@record, column)%> -<% if column.inplace_edit%> - ActiveScaffold.replace_html('<%= @column_span_id %>','<%= escape_javascript(formatted_value) %>'); +<% formatted_value = get_column_value(@record, column) %> +<% if column.inplace_edit %> + ActiveScaffold.update_inplace_edit('<%= @column_span_id %>','<%= escape_javascript(formatted_value) %>', <%= column_empty?(formatted_value).to_json %>); <% else %> ActiveScaffold.replace_html('<%= @column_span_id %>','<%= escape_javascript(formatted_value) %>'); <% end %> diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 4091e244f2..e0f31a6e8a 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -253,6 +253,7 @@ def active_scaffold_inplace_edit(record, column, options = {}) tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field", :title => as_(:click_to_edit), 'data-ie_id' => record.id.to_s} + content_tag(:span, as_(:click_to_edit), :class => 'handle') << content_tag(:span, formatted_column, tag_options) end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index ef95280567..0468fc6276 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -237,6 +237,7 @@ def column_class(column, column_value, record) classes << 'empty' if column_empty? column_value classes << 'sorted' if active_scaffold_config.list.user.sorting.sorts_on?(column) classes << 'numeric' if column.column and [:decimal, :float, :integer].include?(column.column.type) + classes << 'in_place_editor_field' if inplace_edit?(record, column) classes.join(' ').rstrip end From 21abf5bcb57f8cbeab8ac22b9ca4f2853d955b59 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 11 May 2012 18:56:57 -1000 Subject: [PATCH 1481/2024] fix typo --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 0468fc6276..fe923c3ce4 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -220,7 +220,7 @@ def list_row_class(record) def column_attributes(column, record) method = override_helper column, 'column_attributes' - return send(class_override_helper, record) if method + return send(method, record) if method {} end From cbd06b27a10edb5f915483a67597837801b19385 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 14 May 2012 12:56:11 -1000 Subject: [PATCH 1482/2024] add wrap tag option --- lib/active_scaffold/config/list.rb | 10 ++++++++++ lib/active_scaffold/helpers/list_column_helpers.rb | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index ba1e249afb..a739216c71 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -21,6 +21,7 @@ def initialize(core_config) @show_search_reset = true @reset_link = self.class.reset_link.clone @mark_records = self.class.mark_records + @wrap_tag = self.class.wrap_tag end # global level configuration @@ -66,6 +67,11 @@ def page_links_window=(value) cattr_accessor :reset_link @@reset_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :collection, :position => false) + # wrap normal cells (not inplace editable columns or with link) with a tag + # it allows for more css styling + cattr_accessor :wrap_tag + @@wrap_tag = nil + # instance-level configuration # ---------------------------- @@ -169,6 +175,10 @@ def hide_nested_column # will open nested players view if there are 2 or less records in parent attr_accessor :nested_auto_open + # wrap normal cells (not inplace editable columns or with link) with a tag + # it allows for more css styling + attr_accessor :wrap_tag + class UserSettings < UserSettings def initialize(conf, storage, params) super(conf,storage,params) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index e0f31a6e8a..db24b5dcf7 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -49,8 +49,11 @@ def render_list_column(text, column, record) else "<a class='disabled'>#{text}</a>".html_safe end + elsif inplace_edit?(record, column) + active_scaffold_inplace_edit(record, column, {:formatted_column => text}) + elsif active_scaffold_config.list.wrap_tag + content_tag active_scaffold_config.list.wrap_tag, text else - text = active_scaffold_inplace_edit(record, column, {:formatted_column => text}) if inplace_edit?(record, column) text end end From 99307155490209bb980e7d3b647df2c6d6363a0f Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 14 May 2012 14:32:53 -1000 Subject: [PATCH 1483/2024] change dependency on bundler --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index b7bdfa5964..ac5bfbfb5a 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,6 @@ group :development do gem "rake" gem "rdoc" gem "shoulda", ">= 0" - gem "bundler", "~> 1.0.0" + gem "bundler", ">= 1.0.0" gem "rcov", ">= 0" end From 02143df858459b875b8e1fc81c5ea59a8b25b09c Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 15 May 2012 14:27:36 -1000 Subject: [PATCH 1484/2024] add as:element_updated event so form customization can be reloaded --- app/assets/javascripts/jquery/active_scaffold.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index c3d3299bd5..de0ab85f86 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -422,6 +422,7 @@ var ActiveScaffold = { if (element.attr('id')) { element = jQuery('#' + element.attr('id')); } + element.trigger('as:element_updated'); return element; }, @@ -429,6 +430,7 @@ var ActiveScaffold = { if (typeof(element) == 'string') element = '#' + element; element = jQuery(element); element.html(html); + element.trigger('as:element_updated'); return element; }, From 9b581dfeebddce08ca360e609779e190078ba637 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 15 May 2012 15:42:11 -1000 Subject: [PATCH 1485/2024] add support for create multiple items (in active_scaffold_batch plugin) --- frontends/default/views/_base_form.html.erb | 14 +++++--------- frontends/default/views/_form.html.erb | 13 ++++++++----- frontends/default/views/_form_messages.html.erb | 6 +++--- lib/active_scaffold/actions/create.rb | 5 +++-- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index 75aa117786..fe69483797 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -1,4 +1,6 @@ -<% url_options ||= params_for(:action => form_action) +<% scope ||= nil + footer_extension ||= nil + url_options ||= params_for(:action => form_action) xhr = request.xhr? if xhr.nil? if active_scaffold_config.actions.include? form_action multipart ||= active_scaffold_config.send(form_action).multipart? @@ -32,22 +34,16 @@ end <h4><%= headline -%></h4> <div id="<%= element_messages_id(:action => form_action) %>" class="messages-container"> -<% if request.xhr? -%> - <% records = @error_records || Array(@record) - records.each do |record| %> - <%= active_scaffold_error_messages_for record, :object_name => "#{record.class.model_name.human.downcase}#{record.new_record? ? '' : ": #{record.to_label}"}" %> - <% end %> -<% else -%> <%= render :partial => 'form_messages' %> -<% end -%> </div> - <%= render :partial => body_partial, :locals => { :columns => columns, :form_action => form_action } %> + <%= render :partial => body_partial, :locals => { :columns => columns, :form_action => form_action, :scope => scope } %> <p class="form-footer"> <%= submit_tag as_(submit_text), :class => "submit" %> <%= link_to(as_(:cancel), main_path_to_return, cancel_options) if cancel_link %> <%= loading_indicator_tag(:action => form_action, :id => params[:id]) %> + <%= render :partial => footer_extension, :locals => { :form_action => form_action } if footer_extension %> </p> </form> diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index e452729b37..04b86b2f36 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -1,5 +1,8 @@ -<% subsection_id ||= nil %> -<% show_unauthorized_columns = active_scaffold_config.send(form_action).show_unauthorized_columns %> +<% + scope ||= nil + subsection_id ||= nil + show_unauthorized_columns = active_scaffold_config.send(form_action).show_unauthorized_columns +%> <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= "style=\"display: none;\"".html_safe if columns.collapsed %>> <% columns.each :for => @record, :crud_type => (:read if show_unauthorized_columns) do |column| %> <% authorized = show_unauthorized_columns ? @record.authorized_for?(:crud_type => form_action, :column => column.name) : true %> @@ -8,16 +11,16 @@ <% subsection_id = sub_section_id(:sub_section => column.label) %> <li class="sub-section <%= column.css_class %>"> <h5><%= column.label %></h5> - <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id, :form_action => form_action } %> + <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id, :form_action => form_action, :scope => scope } %> <%= link_to_visibility_toggle(subsection_id, {:default_visible => !column.collapsed}) -%> </li> <% elsif renders_as == :subform and !override_form_field?(column) and authorized -%> <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %> <%=column.name%>-sub-form" id="<%= sub_form_id(:association => column.name) %>"> - <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column } -%> + <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column, :scope => scope } -%> </li> <% else -%> <li class="form-element <%= 'required' if column.required? %> <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %>"> - <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column, :only_value => !authorized } -%> + <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column, :only_value => !authorized, :scope => scope } -%> </li> <% end -%> <% end -%> diff --git a/frontends/default/views/_form_messages.html.erb b/frontends/default/views/_form_messages.html.erb index 5095dd03cd..d0c07ab620 100644 --- a/frontends/default/views/_form_messages.html.erb +++ b/frontends/default/views/_form_messages.html.erb @@ -1,5 +1,5 @@ -<%= render :partial => 'messages' %> +<%= render :partial => 'messages' unless request.xhr? %> <% unless @record.nil? %> - <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> -<% end %> \ No newline at end of file + <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> +<% end %> diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 0e2973d984..6ccb2dd1de 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -87,10 +87,11 @@ def do_new # A somewhat complex method to actually create a new record. The complexity is from support for subforms and associated records. # If you want to customize this behavior, consider using the +before_create_save+ and +after_create_save+ callbacks. - def do_create + def do_create(hash = nil) + hash ||= params[:record] begin active_scaffold_config.model.transaction do - @record = update_record_from_params(new_model, active_scaffold_config.create.columns, params[:record]) + @record = update_record_from_params(new_model, active_scaffold_config.create.columns, hash) apply_constraints_to_record(@record, :allow_autosave => true) if nested? create_association_with_parent(@record) From 3df09c581f25b6ea2142bd6f986f325f0a3b9e82 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 16 May 2012 10:26:22 -1000 Subject: [PATCH 1486/2024] use time.formats.picker to parse datetime if jquery is used, fixes #163 --- lib/active_scaffold/finder.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 789829b73e..68541f1f34 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -121,11 +121,17 @@ def condition_value_for_datetime(value, conversion = :to_time) Date.strptime(value, I18n.t('date.formats.default')) rescue nil else parts = Date._parse(value) - time_parts = [[:hour, '%H'], [:min, '%M'], [:sec, '%S']].collect {|part, format_part| format_part if parts[part].present?}.compact - format = "#{I18n.t('date.formats.default')} #{time_parts.join(':')} #{'%z' if parts[:offset].present?}" + format = I18n.translate 'time.formats.picker', :default => '' if ActiveScaffold.js_framework == :jquery + if format.blank? + time_parts = [[:hour, '%H'], [:min, '%M'], [:sec, '%S']].collect {|part, format_part| format_part if parts[part].present?}.compact + format = "#{I18n.t('date.formats.default')} #{time_parts.join(':')} #{'%z' if parts[:offset].present?}" + else + format += ' %z' if parts[:offset].present? && format !~ /%z/i + end time = DateTime.strptime(value, format) - time = Time.zone.local_to_utc(time) unless parts[:offset] - time.in_time_zone.send(conversion) rescue nil + time = Time.zone.local_to_utc(time).in_time_zone unless parts[:offset] + time = time.send(conversion) unless conversion == :to_time + time end unless value.nil? || value.blank? end From 38348352f2522e93f7eae16cd98cabb971a3d706 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 16 May 2012 10:29:31 -1000 Subject: [PATCH 1487/2024] update changelog --- CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 4dd3071795..5d1ee5191b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,9 @@ - messages go across all table - display readonly associations in forms, it was ready to display them but it was skipping them - Some fixes for inplace editors (cloning form overrides, ajax and radiobuttons). Add handlers for empty columns +- add wrap_tag to list so cells content can be wrapped in a tag for better styling +- fix date picker parsing for datetime fields when jquery is used +- add as:element_updated js event when replace or replace_html is called = 3.2.7 - restore missing update.persistent feature From 3c632ef0f5020f9a27af2d0caca7c9a38db672aa Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 16 May 2012 11:09:51 -1000 Subject: [PATCH 1488/2024] add cleafix to ol.form --- app/assets/stylesheets/active_scaffold_layout.css | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/assets/stylesheets/active_scaffold_layout.css b/app/assets/stylesheets/active_scaffold_layout.css index 7cd019f6b5..1c1ae8f408 100644 --- a/app/assets/stylesheets/active_scaffold_layout.css +++ b/app/assets/stylesheets/active_scaffold_layout.css @@ -609,6 +609,14 @@ padding: 2px; margin-left: 5px; list-style: none; } +.active-scaffold ol:after { +content: '.'; +visibility: hidden; +line-height: 0; +height: 0; +display: block; +clear: both; +} .active-scaffold p.form-footer { clear: both; From 9d1803c0a27278bc81e3a2ed001563235e01ae20 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 16 May 2012 13:27:27 -1000 Subject: [PATCH 1489/2024] rescue all active record errors, so database exceptions are displayed as errors --- CHANGELOG | 1 + lib/active_scaffold/actions/create.rb | 4 ++-- lib/active_scaffold/actions/update.rb | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5d1ee5191b..4e418dd97d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ - add wrap_tag to list so cells content can be wrapped in a tag for better styling - fix date picker parsing for datetime fields when jquery is used - add as:element_updated js event when replace or replace_html is called +- rescue database exceptions so you get error messages for it insted of error 500, for example in case you forgot to check uniqueness for a unique index = 3.2.7 - restore missing update.persistent feature diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 6ccb2dd1de..3784a9fab5 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -99,8 +99,8 @@ def do_create(hash = nil) end create_save end - rescue ActiveRecord::RecordInvalid - flash[:error] = $!.message + rescue ActiveRecord::ActiveRecordError => ex + flash[:error] = ex.message self.successful = false end end diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index cab6333292..499f2c2c59 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -91,15 +91,15 @@ def update_save(options = {}) raise ActiveRecord::Rollback, "don't save habtm associations unless record is valid" end end - rescue ActiveRecord::RecordInvalid - flash[:error] = $!.message - self.successful = false rescue ActiveRecord::StaleObjectError @record.errors.add(:base, as_(:version_inconsistency)) self.successful = false rescue ActiveRecord::RecordNotSaved @record.errors.add(:base, as_(:record_not_saved)) if @record.errors.empty? self.successful = false + rescue ActiveRecord::ActiveRecordError => ex + flash[:error] = ex.message + self.successful = false end end From 180a2a0a38f4503c21655e580c6c2a61e259cd73 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 17 May 2012 11:20:20 -1000 Subject: [PATCH 1490/2024] make global some options and move duplicated lines to base and form classes --- lib/active_scaffold/config/base.rb | 1 + lib/active_scaffold/config/create.rb | 16 ++-------------- lib/active_scaffold/config/delete.rb | 3 +-- lib/active_scaffold/config/field_search.rb | 11 ++++++++--- lib/active_scaffold/config/form.rb | 17 ++++++++++++++++- lib/active_scaffold/config/list.rb | 19 +++++++++++++++++-- lib/active_scaffold/config/nested.rb | 3 +-- lib/active_scaffold/config/search.rb | 6 +++--- lib/active_scaffold/config/show.rb | 1 - lib/active_scaffold/config/update.rb | 15 --------------- 10 files changed, 49 insertions(+), 43 deletions(-) diff --git a/lib/active_scaffold/config/base.rb b/lib/active_scaffold/config/base.rb index 8deac89134..1d5a90f1ad 100644 --- a/lib/active_scaffold/config/base.rb +++ b/lib/active_scaffold/config/base.rb @@ -5,6 +5,7 @@ class Base def initialize(core_config) @core = core_config + @action_group = self.class.action_group.clone if self.class.action_group end def self.inherited(subclass) diff --git a/lib/active_scaffold/config/create.rb b/lib/active_scaffold/config/create.rb index c32117f08b..50234317a3 100644 --- a/lib/active_scaffold/config/create.rb +++ b/lib/active_scaffold/config/create.rb @@ -4,9 +4,7 @@ class Create < ActiveScaffold::Config::Form def initialize(core_config) super @label = :create_model - self.persistent = self.class.persistent self.action_after_create = self.class.action_after_create - self.refresh_list = self.class.refresh_list end # global level configuration @@ -20,25 +18,15 @@ def self.link=(val) end @@link = ActiveScaffold::DataStructures::ActionLink.new('new', :label => :create_new, :type => :collection, :security_method => :create_authorized?, :ignore_method => :create_ignore?) - # whether the form stays open after a create or not - cattr_accessor :persistent - @@persistent = false - # whether update form is opened after a create or not cattr_accessor :action_after_create @@action_after_create = nil - # whether we should refresh list after create or not - cattr_accessor :refresh_list - @@refresh_list = false - - # whether the form stays open after a create or not - attr_accessor :persistent + # instance-level configuration + # ---------------------------- # whether the form stays open after a create or not attr_accessor :action_after_create - # whether we should refresh list after create or not - attr_accessor :refresh_list end end diff --git a/lib/active_scaffold/config/delete.rb b/lib/active_scaffold/config/delete.rb index 2625f26078..355d252b58 100644 --- a/lib/active_scaffold/config/delete.rb +++ b/lib/active_scaffold/config/delete.rb @@ -6,8 +6,7 @@ def initialize(core_config) super # start with the ActionLink defined globally @link = self.class.link.clone - @action_group = self.class.action_group.clone if self.class.action_group - self.refresh_list = self.class.refresh_list + @refresh_list = self.class.refresh_list end # global level configuration diff --git a/lib/active_scaffold/config/field_search.rb b/lib/active_scaffold/config/field_search.rb index da6ea56423..df8e116ae6 100644 --- a/lib/active_scaffold/config/field_search.rb +++ b/lib/active_scaffold/config/field_search.rb @@ -5,10 +5,10 @@ class FieldSearch < Base def initialize(core_config) super @text_search = self.class.text_search + @human_conditions = self.class.human_conditions # start with the ActionLink defined globally @link = self.class.link.clone - @action_group = self.class.action_group.clone if self.class.action_group end @@ -27,6 +27,11 @@ def initialize(core_config) cattr_accessor :text_search @@text_search = :full + # human conditions + # instead of just filtered you may show the user a humanized search condition statment + cattr_accessor :human_conditions + @@human_conditions = false + # instance-level configuration # ---------------------------- @@ -54,8 +59,8 @@ def columns attr_accessor :link # rarely searched columns may be placed in a hidden subgroup - def optional_columns=(optionals) - @optional_columns= Array(optionals) + def optional_columns=(optionals) + @optional_columns = Array(optionals) end def optional_columns diff --git a/lib/active_scaffold/config/form.rb b/lib/active_scaffold/config/form.rb index abc07be2ca..c88f875004 100644 --- a/lib/active_scaffold/config/form.rb +++ b/lib/active_scaffold/config/form.rb @@ -4,8 +4,9 @@ def initialize(core_config) super # start with the ActionLink defined globally @link = self.class.link.clone unless self.class.link.nil? - @action_group = self.class.action_group.clone if self.class.action_group @show_unauthorized_columns = self.class.show_unauthorized_columns + @refresh_list = self.class.refresh_list + @persistent = self.class.persistent # no global setting here because multipart should only be set for specific forms @multipart = false @@ -16,6 +17,14 @@ def initialize(core_config) # show value of unauthorized columns instead of skip them class_attribute :show_unauthorized_columns + # whether the form stays open after an update or not + cattr_accessor :persistent + @@persistent = false + + # whether we should refresh list after update or not + cattr_accessor :refresh_list + @@refresh_list = false + # instance-level configuration # ---------------------------- @@ -28,6 +37,12 @@ def initialize(core_config) # the label for this Form action. used for the header. attr_writer :label + # whether the form stays open after a create or not + attr_accessor :persistent + + # whether we should refresh list after create or not + attr_accessor :refresh_list + # provides access to the list of columns specifically meant for the Form to use def columns unless @columns # lazy evaluation diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index a739216c71..aa63938550 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -18,10 +18,12 @@ def initialize(core_config) @empty_field_text = self.class.empty_field_text @association_join_text = self.class.association_join_text @pagination = self.class.pagination - @show_search_reset = true + @show_search_reset = self.class.show_search_reset @reset_link = self.class.reset_link.clone @mark_records = self.class.mark_records @wrap_tag = self.class.wrap_tag + @always_show_search = self.class.always_show_search + @always_show_create = self.class.always_show_create end # global level configuration @@ -62,9 +64,14 @@ def page_links_window=(value) # Add a checkbox in front of each record to mark them and use them with a batch action later cattr_accessor :mark_records + @@mark_records = false + + # show a link to reset the search next to filtered message + cattr_accessor :show_search_reset + @@show_search_reset = true # the ActionLink to reset search - cattr_accessor :reset_link + cattr_reader :reset_link @@reset_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :collection, :position => false) # wrap normal cells (not inplace editable columns or with link) with a tag @@ -72,6 +79,14 @@ def page_links_window=(value) cattr_accessor :wrap_tag @@wrap_tag = nil + # Show search form in the list header instead of display the link + cattr_accessor :always_show_search + @@always_show_search = false + + # Show create form in the list header instead of display the link + cattr_accessor :always_show_create + @@always_show_create = false + # instance-level configuration # ---------------------------- diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index c116c136b5..6eb5f4702f 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -5,8 +5,7 @@ class Nested < Base def initialize(core_config) super @label = :add_existing_model - self.shallow_delete = self.class.shallow_delete - @action_group = self.class.action_group.clone if self.class.action_group + @shallow_delete = self.class.shallow_delete end # global level configuration diff --git a/lib/active_scaffold/config/search.rb b/lib/active_scaffold/config/search.rb index 5cb810ae9f..b31979750e 100644 --- a/lib/active_scaffold/config/search.rb +++ b/lib/active_scaffold/config/search.rb @@ -10,7 +10,6 @@ def initialize(core_config) # start with the ActionLink defined globally @link = self.class.link.clone - @action_group = self.class.action_group.clone if self.class.action_group end @@ -35,6 +34,9 @@ def self.live? @@live end + cattr_accessor :split_terms + @@split_terms = " " + # instance-level configuration # ---------------------------- @@ -57,8 +59,6 @@ def columns # Default is :full attr_accessor :text_search - @@split_terms = " " - cattr_accessor :split_terms attr_accessor :split_terms # the ActionLink for this action diff --git a/lib/active_scaffold/config/show.rb b/lib/active_scaffold/config/show.rb index 2f4e78342e..e25d19ef87 100644 --- a/lib/active_scaffold/config/show.rb +++ b/lib/active_scaffold/config/show.rb @@ -6,7 +6,6 @@ def initialize(core_config) super # start with the ActionLink defined globally @link = self.class.link.clone - @action_group = self.class.action_group.clone if self.class.action_group end # global level configuration diff --git a/lib/active_scaffold/config/update.rb b/lib/active_scaffold/config/update.rb index 1f4c415167..10b241929b 100644 --- a/lib/active_scaffold/config/update.rb +++ b/lib/active_scaffold/config/update.rb @@ -4,7 +4,6 @@ class Update < ActiveScaffold::Config::Form def initialize(core_config) super self.nested_links = self.class.nested_links - self.refresh_list = self.class.refresh_list end # global level configuration @@ -18,14 +17,6 @@ def self.link=(val) end @@link = ActiveScaffold::DataStructures::ActionLink.new('edit', :label => :edit, :type => :member, :security_method => :update_authorized?) - # whether the form stays open after an update or not - cattr_accessor :persistent - @@persistent = false - - # whether we should refresh list after update or not - cattr_accessor :refresh_list - @@refresh_list = false - # instance-level configuration # ---------------------------- @@ -33,16 +24,10 @@ def self.link=(val) cattr_accessor :nested_links @@nested_links = false - # whether the form stays open after an update or not - attr_accessor :persistent - attr_writer :hide_nested_column def hide_nested_column @hide_nested_column.nil? ? true : @hide_nested_column end - - # whether we should refresh list after update or not - attr_accessor :refresh_list end end From e108acd130a27db19062db8c3c4e3ea048e73c91 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 18 May 2012 01:27:45 +0200 Subject: [PATCH 1491/2024] add class attribute for displayed unauthorized columns in forms, so they get same styling --- CHANGELOG | 1 + frontends/default/views/_form_attribute.html.erb | 9 ++++++--- .../default/views/_horizontal_subform_record.html.erb | 2 +- .../default/views/_vertical_subform_record.html.erb | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4e418dd97d..7808ac400c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ - fix date picker parsing for datetime fields when jquery is used - add as:element_updated js event when replace or replace_html is called - rescue database exceptions so you get error messages for it insted of error 500, for example in case you forgot to check uniqueness for a unique index +- add class attribute for displayed unauthorized columns in forms, so they get same styling = 3.2.7 - restore missing update.persistent feature diff --git a/frontends/default/views/_form_attribute.html.erb b/frontends/default/views/_form_attribute.html.erb index 1c26eda766..ca5511b67f 100644 --- a/frontends/default/views/_form_attribute.html.erb +++ b/frontends/default/views/_form_attribute.html.erb @@ -1,13 +1,16 @@ -<% scope ||= nil %> +<% + scope ||= nil + column_options = active_scaffold_input_options(column, scope) +%> <dl> <dt> - <label for="<%= active_scaffold_input_options(column, scope)[:id] %>"><%= column.label %></label> + <label for="<%= column_options[:id] %>"><%= column.label %></label> </dt> <dd> <% unless local_assigns[:only_value] %> <%=raw active_scaffold_input_for column, scope %> <% else %> - <%= get_column_value(@record, column) %> + <%= content_tag :span, get_column_value(@record, column), options.except(:name) %> <%= hidden_field :record, column.association ? column.association.foreign_key : column.name, active_scaffold_input_options(column, scope) -%> <% end %> <% if column.update_columns -%> diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index ddad5019d7..707c82e01c 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -24,7 +24,7 @@ <% unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) -%> <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%> <% else -%> - <p><%= get_column_value(@record, column) -%></p> + <p class="<%= column.name %>-input"><%= get_column_value(@record, column) -%></p> <% end -%> </td> <% end -%> diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index 7965b3cf6a..80b9e09a7f 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -24,7 +24,7 @@ <% unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) -%> <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%> <% else -%> - <p><%= get_column_value(@record, column) -%></p> + <p class="<%= column.name %>-input"><%= get_column_value(@record, column) -%></p> <% end -%> </li> <% end -%> From e6e25e66849b86261b70da0f2546b0506ed19a73 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 18 May 2012 01:28:10 +0200 Subject: [PATCH 1492/2024] bump version to 3.2.8 --- Gemfile.lock | 2 +- lib/active_scaffold/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index c47f6cba3e..951cbaee42 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,7 +12,7 @@ PLATFORMS ruby DEPENDENCIES - bundler (~> 1.0.0) + bundler (>= 1.0.0) rake rcov rdoc diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 82ef1b00a0..41ce7164b7 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 7 + PATCH = 8 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 694e344538c68d2091fcfa71d153d5c1ff603eb4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 18 May 2012 17:03:18 -1000 Subject: [PATCH 1493/2024] remove some duplicated conditions with constraints, and clean conditions code removeing sanitize_sql calls, where method provides them --- CHANGELOG | 5 ++- lib/active_scaffold/actions/core.rb | 11 ++---- lib/active_scaffold/actions/field_search.rb | 14 +++---- lib/active_scaffold/actions/nested.rb | 2 +- lib/active_scaffold/actions/search.rb | 2 +- .../active_record_permissions.rb | 1 + lib/active_scaffold/constraints.rb | 35 ++++++----------- lib/active_scaffold/finder.rb | 39 +++++++++---------- lib/active_scaffold_env.rb | 1 - 9 files changed, 46 insertions(+), 64 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7808ac400c..de46a963b5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,7 @@ -= 3.2.8 (not released) += 3.2.9 (not released) +- remove some duplicated conditions with constraints + += 3.2.8 - add deprecation for update_column, update_columns should be used instead - fix constraints with hide_nested_column disabled in list and embedded scaffolds which are nested too - fix setting a hash as includes, cannot be concat in finder diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 6103d023f1..f036f42f70 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -151,14 +151,11 @@ def beginning_of_chain # Builds search conditions by search params for column names. This allows urls like "contacts/list?company_id=5". def conditions_from_params - conditions = nil + conditions = {} params.reject {|key, value| [:controller, :action, :id, :page, :sort, :sort_direction].include?(key.to_sym)}.each do |key, value| - next unless active_scaffold_config.model.column_names.include?(key) - if value.is_a?(Array) - conditions = merge_conditions(conditions, ["#{active_scaffold_config.model.table_name}.#{key.to_s} in (?)", value]) - else - conditions = merge_conditions(conditions, ["#{active_scaffold_config.model.table_name}.#{key.to_s} = ?", value]) - end + next unless active_scaffold_config.model.columns_hash[key.to_s] + next if active_scaffold_constraints[key.to_sym] + conditions[key] = value end conditions end diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index 636b79b034..e725f8626d 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -43,23 +43,19 @@ def field_search_respond_to_js def do_search unless search_params.blank? + filtered_columns = [] text_search = active_scaffold_config.field_search.text_search - search_conditions = [] - human_condition_columns = [] if active_scaffold_config.field_search.human_conditions columns = active_scaffold_config.field_search.columns search_params.each do |key, value| next unless columns.include? key search_condition = self.class.condition_for_column(active_scaffold_config.columns[key], value, text_search) unless search_condition.blank? - search_conditions << search_condition - human_condition_columns << active_scaffold_config.columns[key] unless human_condition_columns.nil? + self.active_scaffold_conditions << search_condition + filtered_columns << active_scaffold_config.columns[key] end end - self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, *search_conditions) - if search_conditions.blank? - @filtered = false - else - @filtered = human_condition_columns.nil? ? true : human_condition_columns + unless filtered_columns.blank? + @filtered = active_scaffold_config.field_search.human_conditions ? filtered_columns : true end includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 178d34c0cf..1ed0ed682f 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -86,7 +86,7 @@ def beginning_of_chain elsif nested? && nested.scope nested.parent_scope.send(nested.scope) else - active_scaffold_config.model + super end end diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index 83488d0336..ac069128c1 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -26,8 +26,8 @@ def do_search text_search = active_scaffold_config.search.text_search query = query.split(active_scaffold_config.search.split_terms) if active_scaffold_config.search.split_terms search_conditions = self.class.create_conditions_for_columns(query, columns, text_search) - self.active_scaffold_conditions = merge_conditions(self.active_scaffold_conditions, search_conditions) @filtered = !search_conditions.blank? + self.active_scaffold_conditions.concat search_conditions if @filtered includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact self.active_scaffold_includes.concat includes_for_search_columns diff --git a/lib/active_scaffold/active_record_permissions.rb b/lib/active_scaffold/active_record_permissions.rb index e8610453ae..d092ce1783 100644 --- a/lib/active_scaffold/active_record_permissions.rb +++ b/lib/active_scaffold/active_record_permissions.rb @@ -41,6 +41,7 @@ def assign_current_user_to_models module Model def self.included(base) base.extend ClassMethods + base.send :include, ActiveRecordPermissions::Permissions end module ClassMethods diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 5b16c42cca..9501b998c3 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -34,10 +34,11 @@ def register_constraints_with_action_columns(exclude_actions = []) # All of this work is primarily to support nested scaffolds in a manner generally useful for other # embedded scaffolds. def conditions_from_constraints - conditions = nil + hash_conditions = {} + conditions = [hash_conditions] active_scaffold_constraints.each do |k, v| column = active_scaffold_config.columns[k] - constraint_condition = if column + if column # Assume this is a multi-level association constraint. # example: # data model: Park -> Den -> Bear @@ -47,8 +48,8 @@ def conditions_from_constraints field = far_association.klass.primary_key table = far_association.table_name - active_scaffold_includes.concat([{k => v.keys.first}]) # e.g. {:den => :park} - constraint_condition_for("#{table}.#{field}", v.values.first) + active_scaffold_includes.concat([{k => far_association.name}]) # e.g. {:den => :park} + hash_conditions.merge!("#{table}.#{field}" => v.values.first) # association column constraint elsif column.association @@ -57,23 +58,20 @@ def conditions_from_constraints else active_scaffold_includes.concat column.includes end - condition_from_association_constraint(column.association, v) + hash_conditions.merge!(condition_from_association_constraint(column.association, v)) # regular column constraints - elsif column.searchable? + elsif column.searchable? && params[column.name] != v active_scaffold_includes.concat column.includes - constraint_condition_for(column.search_sql, v) + conditions << ["#{column.search_sql} = ?", v] end # unknown-to-activescaffold-but-real-database-column constraint - elsif active_scaffold_config.model.column_names.include? k.to_s - constraint_condition_for(k.to_s, v) + elsif active_scaffold_config.model.columns_hash[k.to_s] && params[column.name] != v + hash_conditions.merge!(k => v) else raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, k), caller end - - conditions = merge_conditions(conditions, constraint_condition) end - conditions end @@ -108,14 +106,11 @@ def condition_from_association_constraint(association, value) value = association.klass.find(value).send(association.options[:primary_key]) end - condition = constraint_condition_for("#{table}.#{field}", value) + condition = {"#{table}.#{field}" => value} if association.options[:polymorphic] begin parent_scaffold = "#{session_info[:parent_scaffold].to_s.camelize}Controller".constantize - condition = merge_conditions( - condition, - constraint_condition_for("#{table}.#{association.name}_type", parent_scaffold.active_scaffold_config.model_id.to_s) - ) + condition["#{table}.#{association.name}_type"] = parent_scaffold.active_scaffold_config.model_id.to_s rescue ActiveScaffold::ControllerNotFound nil end @@ -164,11 +159,5 @@ def apply_constraints_to_record(record, options = {}) end end end - - private - - def constraint_condition_for(sql, value) - value.nil? ? "#{sql} IS NULL" : ["#{sql} = ?", value] - end end end diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 68541f1f34..c7b7787d97 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -19,14 +19,13 @@ def create_conditions_for_columns(tokens, columns, text_search = :full) columns.each do |column| where_clauses << ((column.column.nil? || column.column.text?) ? "#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?" : "#{column.search_sql} = ?") end - phrase = "(#{where_clauses.join(' OR ')})" + phrase = where_clauses.join(' OR ') - sql = ([phrase] * tokens.length).join(' AND ') - tokens = tokens.collect do |value| - columns.collect {|column| (column.column.nil? || column.column.text?) ? like_pattern.sub('?', value) : column.column.type_cast(value)} - end.flatten - - [sql, *tokens] + tokens.collect do |value| + columns.inject([phrase]) do |condition, column| + condition.push((column.column.nil? || column.column.text?) ? like_pattern.sub('?', value) : column.column.type_cast(value)) + end + end end # Generates an SQL condition for the given ActiveScaffold column based on @@ -247,13 +246,13 @@ def active_scaffold_habtm_joins end def all_conditions - merge_conditions( + [ active_scaffold_conditions, # from the search modules conditions_for_collection, # from the dev conditions_from_params, # from the parameters (e.g. /users/list?first_name=Fred) conditions_from_constraints, # from any constraints (embedded scaffolds) active_scaffold_session_storage[:conditions] # embedding conditions (weaker constraints) - ) + ] end # returns a single record (the given id) but only if it's allowed for the specified action. @@ -264,8 +263,6 @@ def find_if_allowed(id, crud_type, klass = beginning_of_chain) raise ActiveScaffold::RecordNotAllowed, "#{klass} with id = #{id}" unless record.authorized_for?(:crud_type => crud_type.to_sym) return record end - - # returns a hash with options to find records # valid options may include: # * :sorting - a Sorting DataStructure (basically an array of hashes of field => direction, e.g. [{:field1 => 'asc'}, {:field2 => 'desc'}]). please note that multi-column sorting has some limitations: if any column in a multi-field sort uses method-based sorting, it will be ignored. method sorting only works for single-column sorting. # * :per_page @@ -276,10 +273,10 @@ def finder_options(options = {}) # create a general-use options array that's compatible with Rails finders finder_options = { :reorder => options[:sorting].try(:clause), - :where => search_conditions, + :conditions => search_conditions, :joins => joins_for_finder, :includes => full_includes} - + finder_options.merge! custom_finder_options finder_options end @@ -330,7 +327,8 @@ def find_page(options = {}) end def append_to_query(query, options) - options.assert_valid_keys :where, :select, :group, :reorder, :limit, :offset, :joins, :includes, :lock, :readonly, :from + options.assert_valid_keys :where, :select, :group, :reorder, :limit, :offset, :joins, :includes, :lock, :readonly, :from, :conditions + query = apply_conditions(query, *options.delete(:conditions)) if options[:conditions] options.reject{|k, v| v.blank?}.inject(query) do |query, (k, v)| query.send((k.to_sym), v) end @@ -347,15 +345,14 @@ def joins_for_finder end + active_scaffold_habtm_joins end - def merge_conditions(*conditions) - segments = [] - conditions.each do |condition| - unless condition.blank? - sql = active_scaffold_config.model.send(:sanitize_sql, condition) - segments << sql unless sql.blank? + def apply_conditions(query, *conditions) + conditions.reject(&:blank?).inject(query) do |query, condition| + if condition.is_a?(Array) && !condition.first.is_a?(String) # multiple conditions + apply_conditions(query, *condition) + else + query.where(condition) end end - "(#{segments.join(') AND (')})" unless segments.empty? end # TODO: this should reside on the column, not the controller diff --git a/lib/active_scaffold_env.rb b/lib/active_scaffold_env.rb index f9345d9676..9610141ece 100644 --- a/lib/active_scaffold_env.rb +++ b/lib/active_scaffold_env.rb @@ -8,4 +8,3 @@ ActionController::Base.class_eval {include ActiveRecordPermissions::ModelUserAccess::Controller} ActiveRecord::Base.class_eval {include ActiveRecordPermissions::ModelUserAccess::Model} -ActiveRecord::Base.class_eval {include ActiveRecordPermissions::Permissions} From 46d597cd413e01beb3497da1a2261c42a96c52da Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 21 May 2012 09:04:37 -1000 Subject: [PATCH 1494/2024] sort and search must be set explictly for tableless models --- lib/active_scaffold/data_structures/column.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 9d362c77e9..b80bb4d1a0 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -317,7 +317,7 @@ def initialize(name, active_record_class) #:nodoc: # just the field (not table.field) def field_name return nil if virtual? - column ? @active_record_class.connection.quote_column_name(column.name) : association.foreign_key + @field_name ||= column ? @active_record_class.connection.quote_column_name(column.name) : association.foreign_key end def <=>(other_column) @@ -356,7 +356,7 @@ def initialize_sort self.sort = {:method => "#{self.name}.to_s"} elsif self.plural_association? self.sort = {:method => "#{self.name}.join(',')"} - else + elsif @active_record_class.connection self.sort = {:sql => self.field} end end @@ -365,11 +365,9 @@ def initialize_sort def initialize_search_sql self.search_sql = unless self.virtual? if association.nil? - self.field.to_s + self.field.to_s unless @active_record_class.connection.nil? elsif !self.polymorphic_association? - [association.klass.table_name, association.klass.primary_key].collect! do |str| - association.klass.connection.quote_column_name str - end.join('.') + [association.klass.quoted_table_name, association.klass.quoted_primary_key].join('.') unless association.klass.connection.nil? end end end @@ -379,7 +377,7 @@ def initialize_search_sql # the table.field name for this column, if applicable def field - @field ||= [@active_record_class.connection.quote_table_name(@table), field_name].join('.') + @field ||= [@active_record_class.quoted_table_name, field_name].join('.') end def estimate_weight From 487893f9a62e0d08185846310ed87133d3e9b5f1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 22 May 2012 02:02:47 +0200 Subject: [PATCH 1495/2024] It isn't needed to add nested association constraints, neither for conditions nor creation restrictions, because association is added to beginning_of_chain. --- CHANGELOG | 3 ++- lib/active_scaffold/actions/core.rb | 11 +++++----- lib/active_scaffold/actions/create.rb | 10 ++------- lib/active_scaffold/actions/nested.rb | 6 +----- lib/active_scaffold/actions/update.rb | 1 - lib/active_scaffold/config/base.rb | 9 +++++--- lib/active_scaffold/constraints.rb | 21 ++++++++++++------- .../data_structures/nested_info.rb | 12 +++++------ lib/active_scaffold/data_structures/set.rb | 4 ++++ 9 files changed, 39 insertions(+), 38 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index de46a963b5..f0bec0a2cb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ = 3.2.9 (not released) -- remove some duplicated conditions with constraints +- remove duplicated conditions with constraints +- fix constraints for polymorphic associations = 3.2.8 - add deprecation for update_column, update_columns should be used instead diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index f036f42f70..0a348920a4 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -27,7 +27,6 @@ def nested? end def render_field_for_inplace_editing - register_constraints_with_action_columns(active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested? @record = find_if_allowed(params[:id], :update) render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>" end @@ -162,11 +161,11 @@ def conditions_from_params def new_model model = beginning_of_chain - if model.columns_hash[model.inheritance_column] - build_options = {model.inheritance_column.to_sym => active_scaffold_config.model_id} if nested? && nested.association && nested.association.collection? - params = self.params # in new action inheritance_column must be in params - params = params[:record] || {} unless params[model.inheritance_column] # in create action must be inside record key - model = params.delete(model.inheritance_column).camelize.constantize if params[model.inheritance_column] + if model.columns_hash[column = model.inheritance_column] + build_options = {column.to_sym => active_scaffold_config.model_id} if nested? && nested.association && nested.association.collection? + model_name = params.delete(column) # in new action inheritance_column must be in params + model_name ||= params[:record].delete(column) unless params[:record].blank? # in create action must be inside record key + model = model_name.camelize.constantize if model_name end model.respond_to?(:build) ? model.build(build_options || {}) : model.new end diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 3784a9fab5..7d2e728281 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -78,10 +78,7 @@ def create_respond_to_yaml def do_new @record = new_model apply_constraints_to_record(@record) - if nested? - create_association_with_parent(@record) - register_constraints_with_action_columns - end + create_association_with_parent(@record) if nested? @record end @@ -93,10 +90,7 @@ def do_create(hash = nil) active_scaffold_config.model.transaction do @record = update_record_from_params(new_model, active_scaffold_config.create.columns, hash) apply_constraints_to_record(@record, :allow_autosave => true) - if nested? - create_association_with_parent(@record) - register_constraints_with_action_columns - end + create_association_with_parent(@record) if nested? create_save end rescue ActiveRecord::ActiveRecordError => ex diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 1ed0ed682f..dbbc3aac8a 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -26,11 +26,7 @@ def nested? def set_nested if params[:parent_scaffold] && (params[:association] || params[:named_scope]) @nested = ActiveScaffold::DataStructures::NestedInfo.get(active_scaffold_config.model, params) - unless @nested.nil? - active_scaffold_constraints.merge! @nested.constraints - active_scaffold_constraints[:id] = params[:id] if @nested.belongs_to? - register_constraints_with_action_columns - end + register_constraints_with_action_columns(@nested.constrained_fields) unless @nested.nil? end end diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 499f2c2c59..e4373d5b4c 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -65,7 +65,6 @@ def update_respond_to_yaml # A simple method to find and prepare a record for editing # May be overridden to customize the record (set default values, etc.) def do_edit - register_constraints_with_action_columns(active_scaffold_config.update.hide_nested_column ? [] : [:update]) if nested? @record = find_if_allowed(params[:id], :update) end diff --git a/lib/active_scaffold/config/base.rb b/lib/active_scaffold/config/base.rb index 1d5a90f1ad..3350de7215 100644 --- a/lib/active_scaffold/config/base.rb +++ b/lib/active_scaffold/config/base.rb @@ -63,9 +63,12 @@ def formats=(val) private def columns=(val) - @columns = ActiveScaffold::DataStructures::ActionColumns.new(*val) - @columns.action = self - @columns.set_columns(@core.columns) if @columns.respond_to?(:set_columns) + @columns.set_values(*val) if @column + @columns ||= ActiveScaffold::DataStructures::ActionColumns.new(*val).tap do |columns| + columns.action = self + columns.set_columns(@core.columns) if @columns.respond_to?(:set_columns) + columns + end @columns end end diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 9501b998c3..02188148ce 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -12,9 +12,13 @@ def active_scaffold_constraints # This lets the ActionColumns object skip constrained columns. # # If the constraint value is a Hash, then we assume the constraint is a multi-level association constraint (the reverse of a has_many :through) and we do NOT register the constraint column. - def register_constraints_with_action_columns(exclude_actions = []) - constrained_fields = active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect{|k| k.to_sym} + def register_constraints_with_action_columns(constrained_fields = nil) + constrained_fields ||= [] + constrained_fields |= active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect(&:to_sym) + exclude_actions = [] exclude_actions << :list unless active_scaffold_config.list.hide_nested_column + exclude_actions << :update unless active_scaffold_config.update.hide_nested_column + if self.class.uses_active_scaffold? # we actually want to do this whether constrained_fields exist or not, so that we can reset the array when they don't active_scaffold_config.actions.each do |action_name| @@ -108,17 +112,17 @@ def condition_from_association_constraint(association, value) condition = {"#{table}.#{field}" => value} if association.options[:polymorphic] - begin - parent_scaffold = "#{session_info[:parent_scaffold].to_s.camelize}Controller".constantize - condition["#{table}.#{association.name}_type"] = parent_scaffold.active_scaffold_config.model_id.to_s - rescue ActiveScaffold::ControllerNotFound - nil - end + raise ActiveScaffold::MalformedConstraint, polymorphic_constraint_error(association), caller unless params[:parent_model] + condition["#{table}.#{association.name}_type"] = params[:parent_model].constantize.model.to_s end condition end + def polymorphic_constraint_error(association) + "Malformed constraint. You have added a constraint for #{association.name} polymorphic association but parent_model is not set." + end + def constraint_error(klass, column_name) "Malformed constraint `#{klass}##{column_name}'. If it's a legitimate column, and you are using a nested scaffold, please specify or double-check the reverse association name." end @@ -140,6 +144,7 @@ def apply_constraints_to_record(record, options = {}) if column.plural_association? record.send("#{k}").send(:<<, column.association.klass.find(v)) elsif column.association.options[:polymorphic] + raise ActiveScaffold::MalformedConstraint, polymorphic_constraint_error(column.association), caller unless params[:parent_model] record.send("#{k}=", params[:parent_model].constantize.find(v)) else # regular singular association record.send("#{k}=", column.association.klass.find(v)) diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 918742f711..58e09952ec 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -19,7 +19,7 @@ def self.get(model, params) end end - attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :constrained_fields, :constraints, :scope + attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :constrained_fields, :scope def initialize(model, nested_info) @parent_model = nested_info[:parent_model] @@ -108,16 +108,16 @@ def to_params protected def iterate_model_associations(model) - @constraints = {} - @constraints[association.foreign_key.to_sym] = parent_id unless association.belongs_to? + @constrained_fields = Set.new + constrained_fields << association.foreign_key.to_sym unless association.belongs_to? model.reflect_on_all_associations.each do |current| if !current.belongs_to? && association.foreign_key == current.association_foreign_key - constraints[current.name.to_sym] = parent_id + constrained_fields << current.name.to_sym @child_association = current if current.klass == @parent_model end if association.foreign_key == current.foreign_key # show columns for has_many and has_one child associationes - constraints[current.name.to_sym] = parent_id if current.belongs_to? + constrained_fields << current.name.to_sym if current.belongs_to? if association.options[:as] and current.options[:polymorphic] @child_association = current if association.options[:as].to_sym == current.name else @@ -125,7 +125,7 @@ def iterate_model_associations(model) end end end - @constrained_fields = @constraints.keys + @constrained_fields = @constrained_fields.to_a end end diff --git a/lib/active_scaffold/data_structures/set.rb b/lib/active_scaffold/data_structures/set.rb index 1cae9c7c42..29cbb43b1d 100644 --- a/lib/active_scaffold/data_structures/set.rb +++ b/lib/active_scaffold/data_structures/set.rb @@ -4,6 +4,10 @@ class Set include ActiveScaffold::Configurable def initialize(*args) + set_values(*args) + end + + def set_values(*args) @set = [] self.add *args end From 8f88b6477dbda3bc5620eb063ac118b40760b849 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 22 May 2012 02:16:21 +0200 Subject: [PATCH 1496/2024] bump version to 3.2.9 --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 41ce7164b7..4202126b60 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 8 + PATCH = 9 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From c8c6a82397b3b2cad7b74a2da6026c1023a0f6bd Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 22 May 2012 02:28:16 +0200 Subject: [PATCH 1497/2024] check hide_nested_column if action is enabled --- CHANGELOG | 5 ++++- lib/active_scaffold/constraints.rb | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f0bec0a2cb..b7f4c7dd69 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,7 @@ -= 3.2.9 (not released) += 3.2.10 (not released yet) +- fix nested scaffolds with update action disabled + += 3.2.9 - remove duplicated conditions with constraints - fix constraints for polymorphic associations diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 02188148ce..0cdc1f0b0e 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -16,8 +16,11 @@ def register_constraints_with_action_columns(constrained_fields = nil) constrained_fields ||= [] constrained_fields |= active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect(&:to_sym) exclude_actions = [] - exclude_actions << :list unless active_scaffold_config.list.hide_nested_column - exclude_actions << :update unless active_scaffold_config.update.hide_nested_column + [:list, :update].each do |action_name| + if active_scaffold_config.actions.include? action_name + exclude_actions << action_name unless active_scaffold_config.send(action_name).hide_nested_column + end + end if self.class.uses_active_scaffold? # we actually want to do this whether constrained_fields exist or not, so that we can reset the array when they don't From c2d04dafe6f423ffa28022abd3eeca22b93a81e8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 22 May 2012 10:34:52 -1000 Subject: [PATCH 1498/2024] initial work for tableless support --- CHANGELOG | 1 + lib/active_scaffold/actions/delete.rb | 4 +- lib/active_scaffold/config/base.rb | 2 +- .../data_structures/action_columns.rb | 2 - lib/active_scaffold/data_structures/column.rb | 2 + lib/active_scaffold/tableless.rb | 66 +++++++++++++++++++ lib/active_scaffold_env.rb | 3 + 7 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 lib/active_scaffold/tableless.rb diff --git a/CHANGELOG b/CHANGELOG index b7f4c7dd69..20b621b47a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ = 3.2.10 (not released yet) - fix nested scaffolds with update action disabled += initial work for tableless support (index with limited options) = 3.2.9 - remove duplicated conditions with constraints diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index ee8082b202..2e79e8a8e8 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -50,9 +50,11 @@ def do_destroy begin self.successful = @record.destroy marked_records.delete @record.id.to_s if successful? - rescue + rescue Exception => ex flash[:warning] = as_(:cant_destroy_record, :record => @record.to_label) self.successful = false + logger.debug ex.message + logger.debug ex.backtrace.join("\n") end end diff --git a/lib/active_scaffold/config/base.rb b/lib/active_scaffold/config/base.rb index 3350de7215..6370cc74d7 100644 --- a/lib/active_scaffold/config/base.rb +++ b/lib/active_scaffold/config/base.rb @@ -63,7 +63,7 @@ def formats=(val) private def columns=(val) - @columns.set_values(*val) if @column + @columns.set_values(*val) if @columns @columns ||= ActiveScaffold::DataStructures::ActionColumns.new(*val).tap do |columns| columns.action = self columns.set_columns(@core.columns) if @columns.respond_to?(:set_columns) diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index e3fc836ec4..e3d841a612 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -103,8 +103,6 @@ def skip_column?(column, options) result = false # skip if this matches a constrained column result = true if constraint_columns.include?(column.name.to_sym) - # skip if this matches the field_name of a constrained column - result = true if column.field_name and constraint_columns.include?(column.field_name.to_sym) # skip this field if it's not authorized unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.crud_type, :column => column.name) self.unauthorized_columns << column.name.to_sym diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index b80bb4d1a0..97354ea836 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -358,6 +358,8 @@ def initialize_sort self.sort = {:method => "#{self.name}.join(',')"} elsif @active_record_class.connection self.sort = {:sql => self.field} + else + self.sort = false end end end diff --git a/lib/active_scaffold/tableless.rb b/lib/active_scaffold/tableless.rb new file mode 100644 index 0000000000..63d7ceb58d --- /dev/null +++ b/lib/active_scaffold/tableless.rb @@ -0,0 +1,66 @@ +class ActiveScaffold::Tableless < ActiveRecord::Base + class Relation < ActiveRecord::Relation + attr_reader :conditions + def initialize(klass, table) + super + @conditions ||= [] + end + + def initialize_copy(other) + @conditions = @conditions.dup + super + end + + def where(opts, *rest) + unless opts.blank? + opts = opts.with_indifferent_access if opts.is_a? Hash + @conditions << (rest.empty? ? opts : [opts, *rest]) + end + self + end + + def merge(r) + super.tap do |merged| + merged.conditions.concat r.conditions unless r.nil? || r.is_a?(Array) + end + end + + def to_a + @klass.find_all(self) + end + + def find_one(id) + @klass.find_one(id, self) + end + end + + def self.columns; @columns ||= []; end + def self.table_name; @table_name ||= ActiveModel::Naming.plural(self); end + def self.connection; nil; end + def self.table_exists?; true; end + self.abstract_class = true + class << self + private + def relation + @relation ||= ActiveScaffold::Tableless::Relation.new(self, arel_table) + super + end + end + + def self.column(name, sql_type = nil, options = {}) + column = ActiveRecord::ConnectionAdapters::Column.new(name.to_s, options[:default], sql_type.to_s, options.has_key?(:null) ? options[:null] : true) + column.tap { columns << column } + end + + def self.find_all(relation) + raise 'self.find_all must be implemented in a Tableless model' + end + + def self.find_one(id, relation) + raise 'self.find_one must be implemented in a Tableless model' + end + + def destroy + raise 'destroy must be implemented in a Tableless model' + end +end diff --git a/lib/active_scaffold_env.rb b/lib/active_scaffold_env.rb index 9610141ece..0f94c4556e 100644 --- a/lib/active_scaffold_env.rb +++ b/lib/active_scaffold_env.rb @@ -1,5 +1,8 @@ # TODO: clean up extensions. some could be organized for autoloading, and others could be removed entirely. Dir["#{File.dirname __FILE__}/active_scaffold/extensions/*.rb"].each { |file| require file } +module ActiveScaffold + autoload :Tableless, 'active_scaffold/tableless' +end ActionController::Base.send(:include, ActiveScaffold) ActionController::Base.send(:include, RespondsToParent) From 92ecc729fd70e2371e48b5ec4e6fa4627cc80d5a Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 22 May 2012 16:07:00 -1000 Subject: [PATCH 1499/2024] fix scrolling to top when a nested scaffold is closed --- CHANGELOG | 3 ++- app/assets/javascripts/jquery/active_scaffold.js | 4 ++-- app/assets/javascripts/prototype/active_scaffold.js | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 20b621b47a..19537eb0a0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ = 3.2.10 (not released yet) - fix nested scaffolds with update action disabled -= initial work for tableless support (index with limited options) +- initial work for tableless support (index with limited options) +- fix scrolling on closing nested scaffolds = 3.2.9 - remove duplicated conditions with constraints diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index de0ab85f86..8f251b54b2 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -85,7 +85,7 @@ jQuery(document).ready(function() { if (action_link) { if (action_link.position) { - action_link.close(response); + action_link.close(); } else { response.evalResponse(); } @@ -931,7 +931,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ this.enable(); this.adapter.remove(); if (this.hide_target) this.target.show(); - if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target, ActiveScaffold.config.scroll_on_close == 'checkInViewport'); + if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target.attr('id'), ActiveScaffold.config.scroll_on_close == 'checkInViewport'); }, get_new_adapter_id: function() { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 36323f2274..191b3a50ff 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -109,7 +109,7 @@ document.observe("dom:loaded", function() { var action_link = ActiveScaffold.find_action_link(event.findElement()); if (action_link) { if (action_link.position) { - action_link.close(event.memo.request.responseText); + action_link.close(); } else { event.memo.request.evalResponse(); } @@ -819,7 +819,7 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ this.enable(); this.adapter.remove(); if (this.hide_target) this.target.show(); - if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target, ActiveScaffold.config.scroll_on_close == 'checkInViewport'); + if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target.id, ActiveScaffold.config.scroll_on_close == 'checkInViewport'); }, get_new_adapter_id: function() { From 5c6bc8a081a219db7cc6223614b932ea72c7e675 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 23 May 2012 04:07:42 +0200 Subject: [PATCH 1500/2024] fix calculations which were broken in 3.2.9 --- CHANGELOG | 1 + lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/finder.rb | 8 ++++++++ lib/active_scaffold/helpers/view_helpers.rb | 6 +----- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 19537eb0a0..fa42538e1e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ - fix nested scaffolds with update action disabled - initial work for tableless support (index with limited options) - fix scrolling on closing nested scaffolds +- fix calculations which were broken in 3.2.9 = 3.2.9 - remove duplicated conditions with constraints diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 0a348920a4..53cc564203 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -6,7 +6,7 @@ def self.included(base) after_filter :clear_flashes end base.helper_method :nested? - base.helper_method :beginning_of_chain + base.helper_method :calculate base.helper_method :new_model end def render_field diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index c7b7787d97..ee74a8c9c3 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -325,6 +325,14 @@ def find_page(options = {}) end pager.page(options[:page]) end + + def calculate(column) + conditions = all_conditions + includes = active_scaffold_config.list.count_includes + includes ||= active_scaffold_includes unless conditions.nil? + append_to_query(beginning_of_chain, :conditions => conditions, :includes => includes, + :joins => joins_for_collection).calculate(column.calculate, column.name) + end def append_to_query(query, options) options.assert_valid_keys :where, :select, :group, :reorder, :limit, :offset, :joins, :includes, :lock, :readonly, :from, :conditions diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index fe923c3ce4..f5c8297bbc 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -264,11 +264,7 @@ def column_empty?(column_value) def column_calculation(column) unless column.calculate.instance_of? Proc - conditions = controller.send(:all_conditions) - includes = active_scaffold_config.list.count_includes - includes ||= controller.send(:active_scaffold_includes) unless conditions.nil? - calculation = beginning_of_chain.calculate(column.calculate, column.name, :conditions => conditions, - :joins => controller.send(:joins_for_collection), :include => includes) + calculate(column) else column.calculate.call(@records) end From 16e7e4697cbbe0e14590fcccc5daaa0239aa63c0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 23 May 2012 04:08:50 +0200 Subject: [PATCH 1501/2024] bump to 3.2.10 --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 4202126b60..af5ade4aaf 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 9 + PATCH = 10 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From fbae8525d62551e002e753e380bd6ea8ec44aafa Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 23 May 2012 04:10:33 +0200 Subject: [PATCH 1502/2024] fix typo in partial --- frontends/default/views/_form_attribute.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_form_attribute.html.erb b/frontends/default/views/_form_attribute.html.erb index ca5511b67f..77136bd507 100644 --- a/frontends/default/views/_form_attribute.html.erb +++ b/frontends/default/views/_form_attribute.html.erb @@ -10,7 +10,7 @@ <% unless local_assigns[:only_value] %> <%=raw active_scaffold_input_for column, scope %> <% else %> - <%= content_tag :span, get_column_value(@record, column), options.except(:name) %> + <%= content_tag :span, get_column_value(@record, column), column_options.except(:name) %> <%= hidden_field :record, column.association ? column.association.foreign_key : column.name, active_scaffold_input_options(column, scope) -%> <% end %> <% if column.update_columns -%> From 7e2429fead977f142d8b0972033b2c99f44c9b40 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 22 May 2012 16:30:35 -1000 Subject: [PATCH 1503/2024] don't add conditions for constrained fields in conditions_from_params, they will be added to beginning_of_chain --- lib/active_scaffold/actions/core.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 53cc564203..843ea75dfb 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -154,6 +154,7 @@ def conditions_from_params params.reject {|key, value| [:controller, :action, :id, :page, :sort, :sort_direction].include?(key.to_sym)}.each do |key, value| next unless active_scaffold_config.model.columns_hash[key.to_s] next if active_scaffold_constraints[key.to_sym] + next if nested? and nested.constrained_fields.include? key.to_sym conditions[key] = value end conditions From 53d0b72ec348a604b16429e4cd4616ff58932c65 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 23 May 2012 22:14:34 +0200 Subject: [PATCH 1504/2024] fix count includes --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index ee74a8c9c3..9cabb7ef6f 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -284,7 +284,7 @@ def finder_options(options = {}) # Returns a hash with options to count records, rejecting select and order options # See finder_options for valid options def count_options(find_options = {}, count_includes = nil) - count_includes ||= find_options[:includes] unless find_options[:where].nil? + count_includes ||= find_options[:includes] unless find_options[:conditions].nil? options = find_options.reject{|k,v| [:select, :reorder].include? k} options[:includes] = count_includes options From 52203aac72ebdb5a48228ab9a94b549015e1ea23 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 23 May 2012 22:16:25 +0200 Subject: [PATCH 1505/2024] update changelog --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index fa42538e1e..750bc6e8e1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,7 +2,7 @@ - fix nested scaffolds with update action disabled - initial work for tableless support (index with limited options) - fix scrolling on closing nested scaffolds -- fix calculations which were broken in 3.2.9 +- fix calculations and count includes which were broken in 3.2.9 = 3.2.9 - remove duplicated conditions with constraints From 0403de83438fba205e3e29ff87eec6cdc751c9d9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 23 May 2012 10:31:11 -1000 Subject: [PATCH 1506/2024] support for :validate_first in batch_create and bump to 3.2.11 --- lib/active_scaffold/actions/create.rb | 18 +++++++++--------- lib/active_scaffold/actions/update.rb | 3 ++- lib/active_scaffold/config/core.rb | 4 ++-- lib/active_scaffold/version.rb | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 7d2e728281..d31c976189 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -84,14 +84,16 @@ def do_new # A somewhat complex method to actually create a new record. The complexity is from support for subforms and associated records. # If you want to customize this behavior, consider using the +before_create_save+ and +after_create_save+ callbacks. - def do_create(hash = nil) - hash ||= params[:record] + def do_create(options = {}) + attributes = options[:attributes] || params[:record] begin active_scaffold_config.model.transaction do - @record = update_record_from_params(new_model, active_scaffold_config.create.columns, hash) + @record = update_record_from_params(new_model, active_scaffold_config.create.columns, attributes) apply_constraints_to_record(@record, :allow_autosave => true) create_association_with_parent(@record) if nested? - create_save + before_create_save(@record) + self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit + create_save(@record) unless options[:skip_save] end rescue ActiveRecord::ActiveRecordError => ex flash[:error] = ex.message @@ -99,12 +101,10 @@ def do_create(hash = nil) end end - def create_save - before_create_save(@record) - self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit + def create_save(record) if successful? - @record.save! and @record.save_associated! - after_create_save(@record) + record.save! and record.save_associated! + after_create_save(record) end end diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index e4373d5b4c..b972a74001 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -76,9 +76,10 @@ def do_update end def update_save(options = {}) + attributes = options[:attributes] || params[:record] begin active_scaffold_config.model.transaction do - @record = update_record_from_params(@record, active_scaffold_config.update.columns, params[:record]) unless options[:no_record_param_update] + @record = update_record_from_params(@record, active_scaffold_config.update.columns, attributes) unless options[:no_record_param_update] before_update_save(@record) self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit if successful? diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index 3ba7417545..d653492e73 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -176,9 +176,9 @@ def method_missing(name, *args) end def self.method_missing(name, *args) - klass = "ActiveScaffold::Config::#{name.to_s.titleize}".constantize rescue nil + klass = "ActiveScaffold::Config::#{name.to_s.camelcase}".constantize rescue nil if @@actions.include? name.to_s.underscore and klass - return eval("ActiveScaffold::Config::#{name.to_s.titleize}") + return eval("ActiveScaffold::Config::#{name.to_s.camelcase}") end super end diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index af5ade4aaf..2ff121d86e 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 10 + PATCH = 11 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 29dbfd959e18cc795fd48d443a14d650314ae82b Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 23 May 2012 12:11:51 -1000 Subject: [PATCH 1507/2024] support for count in tableless models --- lib/active_scaffold/tableless.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/active_scaffold/tableless.rb b/lib/active_scaffold/tableless.rb index 63d7ceb58d..5bb590342b 100644 --- a/lib/active_scaffold/tableless.rb +++ b/lib/active_scaffold/tableless.rb @@ -32,6 +32,10 @@ def to_a def find_one(id) @klass.find_one(id, self) end + + def count + @klass.count(self) + end end def self.columns; @columns ||= []; end @@ -60,6 +64,14 @@ def self.find_one(id, relation) raise 'self.find_one must be implemented in a Tableless model' end + def self.count(*args) + if args.size == 1 && args.first.is_a?(Relation) + find_all(args.first).size + else + scoped.count(*args) + end + end + def destroy raise 'destroy must be implemented in a Tableless model' end From b01f89d50251b1c8c782a18db26576c898258bfc Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 23 May 2012 16:41:55 -1000 Subject: [PATCH 1508/2024] fix changelog --- CHANGELOG | 11 +++++++++-- .../data_structures/nested_info.rb | 2 +- lib/active_scaffold/tableless.rb | 18 ++++++++++++------ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 750bc6e8e1..188b00409f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,15 @@ -= 3.2.10 (not released yet) += 3.2.12 (not released yet) + += 3.2.11 +- improve support for tableless models and active_scaffold_batch +- fix count includes which were broken in 3.2.9 +- remove duplicated conditions in nested scaffolds, added by conditions_from_params + += 3.2.10 - fix nested scaffolds with update action disabled - initial work for tableless support (index with limited options) - fix scrolling on closing nested scaffolds -- fix calculations and count includes which were broken in 3.2.9 +- fix calculations which were broken in 3.2.9 = 3.2.9 - remove duplicated conditions with constraints diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 58e09952ec..c274cf04df 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -38,7 +38,7 @@ def new_instance? end def parent_scope - parent_model.find(parent_id) + @parent_scope ||= parent_model.find(parent_id) end def habtm? diff --git a/lib/active_scaffold/tableless.rb b/lib/active_scaffold/tableless.rb index 5bb590342b..7ee1873b43 100644 --- a/lib/active_scaffold/tableless.rb +++ b/lib/active_scaffold/tableless.rb @@ -25,6 +25,12 @@ def merge(r) end end + def except(*skips) + super.tap do |new_relation| + new_relation.conditions = conditions unless skips.include? :where + end + end + def to_a @klass.find_all(self) end @@ -33,8 +39,8 @@ def find_one(id) @klass.find_one(id, self) end - def count - @klass.count(self) + def execute_simple_calculation(operation, column_name, distinct) + @klass.execute_simple_calculation(self, operation, column_name, distinct) end end @@ -64,11 +70,11 @@ def self.find_one(id, relation) raise 'self.find_one must be implemented in a Tableless model' end - def self.count(*args) - if args.size == 1 && args.first.is_a?(Relation) - find_all(args.first).size + def self.execute_simple_calculation(relation, operation, column_name, distinct) + if operation == 'count' && column_name == :all && !distinct + find_all(relation).size else - scoped.count(*args) + raise "self.execute_simple_calculation must be implemented in a Tableless model to support #{operation} #{column_name} #{' distinct' if distinct} columns" end end From ccba339e9750410b34de93f6c612c1e95b8fa4d8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 24 May 2012 15:24:28 -1000 Subject: [PATCH 1509/2024] fix div id for nested scaffolds --- CHANGELOG | 2 ++ lib/active_scaffold/helpers/id_helpers.rb | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 188b00409f..f74d3c4767 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,6 @@ = 3.2.12 (not released yet) +- improve support for tableless models, add support for count +- fix div id for nested scaffolds = 3.2.11 - improve support for tableless models and active_scaffold_batch diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index 8811a9a4a3..280dbadab5 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -6,10 +6,14 @@ def id_from_controller(controller) controller.to_s.gsub("/", "__").html_safe end - def controller_id(controller = (params[:eid] || params[:parent_controller] || params[:controller])) + def controller_id(controller = (params[:eid] || nested_id || params[:parent_controller] || params[:controller])) controller_id ||= 'as_' + id_from_controller(controller) end + def nested_id + "#{nested.parent_scaffold.controller_path}-#{nested.parent_id}-#{params[:controller]}" if nested? + end + def active_scaffold_id "#{controller_id}-active-scaffold" end From 003b66f74ac50f68a9b7fc2ad58f0a25eefbd523 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 24 May 2012 15:25:45 -1000 Subject: [PATCH 1510/2024] start cleaning action columns code --- lib/active_scaffold/config/core.rb | 2 +- .../data_structures/action_columns.rb | 34 +++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index d653492e73..612899cec4 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -133,7 +133,7 @@ def initialize(model_id) # To be called after your finished configuration def _load_action_columns - ActiveScaffold::DataStructures::ActionColumns.class_eval {include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration} + #ActiveScaffold::DataStructures::ActionColumns.class_eval {include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration} # then, register the column objects self.actions.each do |action_name| diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index e3d841a612..de0dc8e604 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -38,27 +38,20 @@ def include?(item) end def names - self.collect(&:name) + if @columns + self.collect(&:name) + else + names_without_auth_check + end end def names_without_auth_check Array(@set) end - protected - - def collect_columns - @set.collect {|col| col.is_a?(ActiveScaffold::DataStructures::ActionColumns) ? col.collect_columns : col} - end - - # called during clone or dup. makes the clone/dup deeper. - def initialize_copy(from) - @set = from.instance_variable_get('@set').clone - end - # A package of stuff to add after the configuration block. This is an attempt at making a certain level of functionality inaccessible during configuration, to reduce possible breakage from misuse. # The bulk of the package is a means of connecting the referential column set (ActionColumns) with the actual column objects (Columns). This lets us iterate over the set and yield real column objects. - module AfterConfiguration + #module AfterConfiguration # Redefine the each method to yield actual Column objects. # It will skip constrained and unauthorized columns. # @@ -66,10 +59,10 @@ module AfterConfiguration # * :flatten - whether to recursively iterate on nested sets. default is false. # * :for - the record (or class) being iterated over. used for column-level security. default is the class. def each(options = {}, &proc) - options[:for] ||= @columns.active_record_class + options[:for] ||= @columns.active_record_class unless @columns.nil? self.unauthorized_columns = [] @set.each do |item| - unless item.is_a? ActiveScaffold::DataStructures::ActionColumns + unless item.is_a?(ActiveScaffold::DataStructures::ActionColumns) || @columns.nil? item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class)) next if self.skip_column?(item, options) end @@ -133,6 +126,17 @@ def unauthorized_columns def length ((@set - self.constraint_columns) - self.unauthorized_columns).length end + #end + + protected + + def collect_columns + @set.collect {|col| col.is_a?(ActiveScaffold::DataStructures::ActionColumns) ? col.collect_columns : col} + end + + # called during clone or dup. makes the clone/dup deeper. + def initialize_copy(from) + @set = from.instance_variable_get('@set').clone end end end From d6fe7b250ca95936661d2ccfbe08e21d8d44b59c Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 24 May 2012 15:29:20 -1000 Subject: [PATCH 1511/2024] add timestamped messages and highlight messages features --- CHANGELOG | 1 + .../stylesheets/active_scaffold_layout.css | 4 ++++ frontends/default/views/_messages.html.erb | 2 +- lib/active_scaffold/config/core.rb | 16 ++++++++++++++++ lib/active_scaffold/helpers/view_helpers.rb | 13 +++++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index f74d3c4767..8a73d45192 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ = 3.2.12 (not released yet) - improve support for tableless models, add support for count - fix div id for nested scaffolds +- add config.timestamped_messages and config.highlight_messages = 3.2.11 - improve support for tableless models and active_scaffold_batch diff --git a/app/assets/stylesheets/active_scaffold_layout.css b/app/assets/stylesheets/active_scaffold_layout.css index 1c1ae8f408..cf99eafe98 100644 --- a/app/assets/stylesheets/active_scaffold_layout.css +++ b/app/assets/stylesheets/active_scaffold_layout.css @@ -450,6 +450,10 @@ position: relative; margin: 2px 7px; line-height: 12px; } +.active-scaffold .message .timestamp, +.active-scaffold .message .message-content { +display: inline; +} .active-scaffold .filtered-message .reset { position: absolute; diff --git a/frontends/default/views/_messages.html.erb b/frontends/default/views/_messages.html.erb index 8b21e1c117..aa2a197ada 100644 --- a/frontends/default/views/_messages.html.erb +++ b/frontends/default/views/_messages.html.erb @@ -1,7 +1,7 @@ <% for name in [:info, :warning, :error] %> <% if flash[name] %> <div class="<%= "#{name}-message message" %>"> - <%= h flash[name] %> + <%= display_message flash[name] %> <% if request.xhr? %> <a href="#" class="close" title="<%= as_(:close) %>"><%= as_(:close) %></a> <% end %> diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index 612899cec4..243130e311 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -60,6 +60,14 @@ def self.ignore_columns=(val) cattr_accessor :sti_create_links @@sti_create_links = true + # prefix messages with current timestamp, set the format to display (you can use I18n keys) or true and :short will be used + cattr_accessor :timestamped_messages + @@timestamped_messages = false + + # a hash of string (or array of strings) and highlighter string to highlight words in messages. It will use highlight rails helper + cattr_accessor :highlight_messages + @@highlight_messages = nil + # instance-level configuration # ---------------------------- @@ -101,6 +109,12 @@ def label(options={}) # STI children models, use an array of model names attr_accessor :sti_children + # prefix messages with current timestamp, set the format to display (you can use I18n keys) or true and :short will be used + attr_accessor :timestamped_messages + + # a hash of string (or array of strings) and highlighter string to highlight words in messages. It will use highlight rails helper + attr_accessor :highlight_messages + ## ## internal usage only below this point ## ------------------------------------ @@ -129,6 +143,8 @@ def initialize(model_id) # inherit from the global set of action links @action_links = self.class.action_links.clone + @timestamped_messages = self.class.timestamped_messages + @highlight_messages = self.class.highlight_messages end # To be called after your finished configuration diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index f5c8297bbc..3e0c2436d1 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -308,6 +308,19 @@ def override_helper(column, suffix) method if respond_to?(method) end + def display_message(message) + if (highlights = active_scaffold_config.highlight_messages) + message = highlights.inject(message) do |msg, (phrases, highlighter)| + highlight(msg, phrases, highlighter) + end + end + if (format = active_scaffold_config.timestamped_messages) + format = :short if format == true + message = "#{content_tag :div, l(Time.current, :format => format), :class => 'timestamp'} #{content_tag :div, message, :class => 'message-content'}".html_safe + end + message + end + def active_scaffold_error_messages_for(*params) options = params.extract_options!.symbolize_keys options.reverse_merge!(:container_tag => :div, :list_type => :ul) From 015834566f3ea6ccec2a8715d4ba7c583103bf6b Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 24 May 2012 14:22:48 -1000 Subject: [PATCH 1512/2024] try to fix nested loop calling super instead of alias method chain --- lib/active_scaffold/actions/nested.rb | 2 +- lib/active_scaffold/bridges/cancan/cancan_bridge.rb | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index dbbc3aac8a..310bcd1bdd 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -77,7 +77,7 @@ def beginning_of_chain if nested.association.collection? nested.parent_scope.send(nested.association.name) elsif nested.child_association.belongs_to? - active_scaffold_config.model.where(nested.child_association.foreign_key => nested.parent_scope) + super.model.where(nested.child_association.foreign_key => nested.parent_scope) end elsif nested? && nested.scope nested.parent_scope.send(nested.scope) diff --git a/lib/active_scaffold/bridges/cancan/cancan_bridge.rb b/lib/active_scaffold/bridges/cancan/cancan_bridge.rb index 4737108ccc..1100f594c0 100644 --- a/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +++ b/lib/active_scaffold/bridges/cancan/cancan_bridge.rb @@ -42,13 +42,9 @@ def active_scaffold_with_cancan(model_id = nil, &block) # beginning of chain integration module Actions module Core - extend ActiveSupport::Concern - included do - alias_method_chain :beginning_of_chain, :cancan - end # :TODO can this be expanded more ? - def beginning_of_chain_with_cancan - beginning_of_chain_without_cancan.accessible_by(current_ability) + def beginning_of_chain + super.accessible_by(current_ability) end end end From 689ff64a661b5abf38dab23f415e69c5b3a3f668 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 25 May 2012 08:29:59 -1000 Subject: [PATCH 1513/2024] don't display 500 error in all nested scaffolds --- app/assets/javascripts/jquery/active_scaffold.js | 16 +++++++++------- .../javascripts/prototype/active_scaffold.js | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 8f251b54b2..f084a64f89 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -1,7 +1,7 @@ jQuery(document).ready(function() { jQuery('form.as_form').live('ajax:beforeSend', function(event) { var as_form = jQuery(this).closest("form"); - if (as_form && as_form.attr('data-loading') == 'true') { + if (as_form.attr('data-loading') == 'true') { ActiveScaffold.disable_form(as_form); } return true; @@ -9,19 +9,19 @@ jQuery(document).ready(function() { jQuery('form.as_form').live('ajax:complete', function(event) { var as_form = jQuery(this).closest("form"); - if (as_form && as_form.attr('data-loading') == 'true') { + if (as_form.attr('data-loading') == 'true') { ActiveScaffold.enable_form(as_form); } }); jQuery('form.as_form').live('ajax:error', function(event, xhr, status, error) { var as_div = jQuery(this).closest("div.active-scaffold"); - if (as_div) { - ActiveScaffold.report_500_response(as_div) + if (as_div.length) { + ActiveScaffold.report_500_response(as_div); } }); jQuery('form.as_form.as_remote_upload').live('submit', function(event) { var as_form = jQuery(this).closest("form"); - if (as_form && as_form.attr('data-loading') == 'true') { + if (as_form.attr('data-loading') == 'true') { setTimeout("ActiveScaffold.disable_form('" + as_form.attr('id') + "')", 10); } return true; @@ -541,8 +541,10 @@ var ActiveScaffold = { }, report_500_response: function(active_scaffold_id) { - server_error = jQuery(active_scaffold_id).find('td.messages-container p.server-error'); - if (!jQuery(server_error).is(':visible')) { + var server_error = jQuery(active_scaffold_id).find('td.messages-container p.server-error').first(); + if (server_error.is(':visible')) { + ActiveScaffold.highlight(server_error); + } else { server_error.show(); } }, diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 191b3a50ff..3446554953 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -488,7 +488,7 @@ var ActiveScaffold = { }, report_500_response: function(active_scaffold_id) { - server_error = $(active_scaffold_id).down('td.messages-container p.server-error'); + var server_error = $(active_scaffold_id).down('td.messages-container p.server-error'); if (server_error.visible()) { server_error.highlight(); } else { From 07a54ddd68d09106f4acb4bb2c1c9e04940a27ec Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 25 May 2012 09:18:59 -1000 Subject: [PATCH 1514/2024] don't load plural associations when tried authorization, breaks disabling eager loading and displaying associations to improve performance --- CHANGELOG | 1 + lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 8a73d45192..ab0404ac3a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ - improve support for tableless models, add support for count - fix div id for nested scaffolds - add config.timestamped_messages and config.highlight_messages +- Improve performance using class to check authorization for plural associations which are not loaded = 3.2.11 - improve support for tableless models and active_scaffold_batch diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index db24b5dcf7..b983f7db97 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -92,7 +92,7 @@ def configure_column_link(link, associated, actions) def column_link_authorized?(link, column, record, associated) if column.association - associated_for_authorized = if associated.nil? || (associated.respond_to?(:blank?) && associated.blank?) + associated_for_authorized = if associated.nil? || (column.plural_association? && !associated.loaded?) || (associated.respond_to?(:blank?) && associated.blank?) column.association.klass elsif [:has_many, :has_and_belongs_to_many].include? column.association.macro associated.first From 012496c0f5243d185e9662325339d22bfd734e94 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 25 May 2012 09:46:25 -1000 Subject: [PATCH 1515/2024] Fix using a scope in main form, it wasn't working for associations --- CHANGELOG | 1 + frontends/default/views/_form_association.html.erb | 2 +- frontends/default/views/_horizontal_subform.html.erb | 4 ++-- frontends/default/views/_vertical_subform.html.erb | 2 +- lib/active_scaffold/helpers/form_column_helpers.rb | 6 +++--- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ab0404ac3a..c8944e04d5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ - fix div id for nested scaffolds - add config.timestamped_messages and config.highlight_messages - Improve performance using class to check authorization for plural associations which are not loaded +- Fix using a scope in main form, it wasn't working for associations (for create multiple from active_scaffold_batch) = 3.2.11 - improve support for tableless models and active_scaffold_batch diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index ee60ccda1b..a300d376fc 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -11,7 +11,7 @@ subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_reco <div id ="<%= subform_div_id %>" <%= 'style="display: none;"'.html_safe if column.collapsed -%>> <%# HACK to be able to delete all associated records %> <%= hidden_field_tag "#{active_scaffold_input_options(column)[:name]}[0]", '' if column.plural_association? %> -<%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record} %> +<%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record, :scope => scope} %> </div> <%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%> <% @record = parent_record -%> diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index 646bd21412..59f635c9ef 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -12,11 +12,11 @@ </td> </tr> <% end %> - <%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> + <%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> <% end -%> </tbody> <tfoot> - <%= render :partial => 'horizontal_subform_footer', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column} %> + <%= render :partial => 'horizontal_subform_footer', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column} %> </tfoot> </table> <%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%> diff --git a/frontends/default/views/_vertical_subform.html.erb b/frontends/default/views/_vertical_subform.html.erb index 5b3bc15eca..cfed97582a 100644 --- a/frontends/default/views/_vertical_subform.html.erb +++ b/frontends/default/views/_vertical_subform.html.erb @@ -6,7 +6,7 @@ <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> </div> <% end %> - <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> + <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> <% end -%> </div> <%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%> diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 645ae3ae16..722b143ad7 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -278,11 +278,11 @@ def column_renders_as(column) end end - def column_scope(column) + def column_scope(column, scope = nil) if column.plural_association? - "[#{column.name}][#{@record.id || generate_temporary_id}]" + "#{scope}[#{column.name}][#{@record.id || generate_temporary_id}]" else - "[#{column.name}]" + "#{scope}[#{column.name}]" end end From f9f2b9c4e2f1e6679f1cae0fcbe3b45d7b890962 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 25 May 2012 12:28:12 -1000 Subject: [PATCH 1516/2024] replace inplace edit handle with --, it can be translated --- config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/locales/es.yml | 1 + config/locales/fr.yml | 1 + config/locales/hu.yml | 1 + config/locales/ja.yml | 1 + config/locales/ru.yml | 1 + lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 8 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index e50fd6cb7b..4c305b55a1 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -31,6 +31,7 @@ de: filtered: '(Gefiltert)' found: 'Gefunden' hide: 'Verstecken' + inplace_edit_handle: '--' live_search: 'Live-Suche' loading: 'Lade…' next: 'Vor' diff --git a/config/locales/en.yml b/config/locales/en.yml index 64b8248e98..25e0e76899 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -31,6 +31,7 @@ en: filtered: '(Filtered)' found: 'Found' hide: 'Hide' + inplace_edit_handle: '--' live_search: 'Live Search' loading: 'Loading…' next: 'Next' diff --git a/config/locales/es.yml b/config/locales/es.yml index 5d55f40d9a..bc65606236 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -31,6 +31,7 @@ es: one: 'encontrado' other: 'encontrados' hide: 'Ocultar' + inplace_edit_handle: '--' live_search: 'Buscar en Vivo' loading: 'Cargando…' nested_for_model: '%{nested_model} de %{parent_model}' diff --git a/config/locales/fr.yml b/config/locales/fr.yml index e163900c0b..5e647ca09a 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -31,6 +31,7 @@ fr: filtered: '(Filtré)' found: 'Trouvé' hide: 'Cacher' + inplace_edit_handle: '--' live_search: 'Recherche en temps réel' loading: 'Chargement…' next: 'Suivant' diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 24ac3f6c7a..c171107c60 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -31,6 +31,7 @@ hu: filtered: '(Szűrt)' found: 'Találat' hide: 'Elrejtés' + inplace_edit_handle: '--' live_search: 'Élő keresés' loading: 'Betöltés…' next: 'Következő' diff --git a/config/locales/ja.yml b/config/locales/ja.yml index da3cb742b5..3c3f95f08a 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -31,6 +31,7 @@ ja: filtered: '(フィルタ中)' found: '個ありました' hide: '隠す' + inplace_edit_handle: '--' live_search: 'その場で検索' loading: '読み込み中…' next: '次' diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 2c851e4141..9db15d0b99 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -35,6 +35,7 @@ ru: many: 'записей' other: 'записи' hide: 'Скрыть' + inplace_edit_handle: '--' live_search: 'Поиск' loading: 'Загрузка…' next: 'Следующее' diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index b983f7db97..95ef73cca0 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -256,7 +256,7 @@ def active_scaffold_inplace_edit(record, column, options = {}) tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field", :title => as_(:click_to_edit), 'data-ie_id' => record.id.to_s} - content_tag(:span, as_(:click_to_edit), :class => 'handle') << + content_tag(:span, as_(:inplace_edit_handle), :class => 'handle') << content_tag(:span, formatted_column, tag_options) end From 7c14ddb3298a79cfa6e7e4e46baec12a04707dd7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Sat, 26 May 2012 09:49:24 +0200 Subject: [PATCH 1517/2024] fix nested with has_one associations --- lib/active_scaffold/actions/nested.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 310bcd1bdd..3f722e1cc4 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -77,7 +77,7 @@ def beginning_of_chain if nested.association.collection? nested.parent_scope.send(nested.association.name) elsif nested.child_association.belongs_to? - super.model.where(nested.child_association.foreign_key => nested.parent_scope) + super.where(nested.child_association.foreign_key => nested.parent_scope) end elsif nested? && nested.scope nested.parent_scope.send(nested.scope) From 63c69ef8844aa5fab07438d446c946f5d19136af Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Sat, 26 May 2012 21:25:46 +0200 Subject: [PATCH 1518/2024] cancan was broke, alias_method_chain is needed to patch method in Core module --- lib/active_scaffold/bridges/cancan/cancan_bridge.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/bridges/cancan/cancan_bridge.rb b/lib/active_scaffold/bridges/cancan/cancan_bridge.rb index 1100f594c0..4737108ccc 100644 --- a/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +++ b/lib/active_scaffold/bridges/cancan/cancan_bridge.rb @@ -42,9 +42,13 @@ def active_scaffold_with_cancan(model_id = nil, &block) # beginning of chain integration module Actions module Core + extend ActiveSupport::Concern + included do + alias_method_chain :beginning_of_chain, :cancan + end # :TODO can this be expanded more ? - def beginning_of_chain - super.accessible_by(current_ability) + def beginning_of_chain_with_cancan + beginning_of_chain_without_cancan.accessible_by(current_ability) end end end From 683a87ee6f1431e904e6453eafafd471012a6344 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 29 May 2012 09:03:30 +0200 Subject: [PATCH 1519/2024] don't load items before go last page, don't go last page when there is no results --- CHANGELOG | 1 + lib/active_scaffold/actions/list.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index c8944e04d5..c8c6b5e0f5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ - add config.timestamped_messages and config.highlight_messages - Improve performance using class to check authorization for plural associations which are not loaded - Fix using a scope in main form, it wasn't working for associations (for create multiple from active_scaffold_batch) +- Fix searches with no results, it was loading first page without conditions = 3.2.11 - improve support for tableless models and active_scaffold_batch diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index f66bcf8a13..62a6fb2823 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -76,7 +76,8 @@ def do_list end page = find_page(options) - if page.items.blank? && !page.pager.infinite? + total_pages = page.pager.number_of_pages + if !page.pager.infinite? && !total_pages.zero? && page.number > total_pages page = page.pager.last active_scaffold_config.list.user.page = page.number end From fb398275b32cdeffaf25855d01e0e3ba9076ba95 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 29 May 2012 09:30:22 +0200 Subject: [PATCH 1520/2024] allow to change highlight options with js_config --- CHANGELOG | 1 + .../javascripts/jquery/active_scaffold.js | 2 +- .../javascripts/prototype/active_scaffold.js | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c8c6b5e0f5..96fc19915a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ - Improve performance using class to check authorization for plural associations which are not loaded - Fix using a scope in main form, it wasn't working for associations (for create multiple from active_scaffold_batch) - Fix searches with no results, it was loading first page without conditions +- Allow to change highlight options with ActiveScaffold.js_config = 3.2.11 - improve support for tableless models and active_scaffold_batch diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index f084a64f89..c15b9f0efe 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -605,7 +605,7 @@ var ActiveScaffold = { highlight: function(element) { if (typeof(element) == 'string') element = jQuery('#' + element); if (typeof(element.effect) == 'function') { - element.effect("highlight", {}, 3000); + element.effect("highlight", jQuery.extend({}, ActiveScaffold.js_config.highlight), 3000); } }, diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 3446554953..518dbd3c30 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -375,7 +375,7 @@ var ActiveScaffold = { row = $(row); var new_row = this.replace(row, html) if (row.hasClassName('even-record')) new_row.addClassName('even-record'); - new_row.highlight(); + ActiveScaffold.highlight(new_row); }, replace: function(element, html) { @@ -451,7 +451,7 @@ var ActiveScaffold = { this.stripe(tbody); this.hide_empty_message(tbody); this.increment_record_count(tbody.up('div.active-scaffold')); - new_row.highlight(); + ActiveScaffold.highlight(new_row); }, delete_record_row: function(row, page_reload_url) { @@ -490,7 +490,7 @@ var ActiveScaffold = { report_500_response: function(active_scaffold_id) { var server_error = $(active_scaffold_id).down('td.messages-container p.server-error'); if (server_error.visible()) { - server_error.highlight(); + ActiveScaffold.highlight(server_error); } else { server_error.show(); } @@ -668,6 +668,13 @@ var ActiveScaffold = { draggable_lists: function(element) { new DraggableLists(element); + }, + + highlight: function(element) { + element = $(element); + if (typeof(element.highlight) == 'function') { + element.highlight(Object.extend({duration: 3}, ActiveScaffold.js_config.highlight)); + } } } @@ -907,7 +914,7 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra else { return false; } - this.adapter.down('td').down().highlight(); + ActiveScaffold.highlight(this.adapter.down('td').down()); }, close: function($super, refreshed_content) { @@ -965,7 +972,7 @@ ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstrac else { throw 'Unknown position "' + this.position + '"' } - this.adapter.down('td').down().highlight(); + ActiveScaffold.highlight(this.adapter.down('td').down()); }, reload: function() { From d87030d31a108af1b559450505f1350eaef13ed2 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 29 May 2012 11:57:58 -1000 Subject: [PATCH 1521/2024] allow to set sortable options in jquery, and fix issue with edit_associated using wrong ID --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- frontends/default/views/_form_association_footer.html.erb | 4 ++-- lib/active_scaffold/actions/subform.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index c15b9f0efe..80623568e1 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -661,7 +661,7 @@ var ActiveScaffold = { sortable: function(element, controller, options, url_params) { if (typeof(element) == 'string') element = '#' + element; var element = jQuery(element); - var sortable_options = {}; + var sortable_options = jQuery.extend({}, options); if (options.update === true) { url_params.authenticity_token = jQuery('meta[name=csrf-param]').attr('content'); sortable_options.update = function(event, ui) { diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index f1bef8030a..faeb6fed90 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -11,8 +11,8 @@ show_add_new = column_show_add_new(column, associated, @record) return unless show_add_new or show_add_existing -edit_associated_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :associated_id => '--ID--', :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_existing -add_new_url = url_for(:action => 'edit_associated', :id => parent_record.id, :association => column.name, :eid => params[:eid], :parent_controller => params[:parent_controller], :parent_id => params[:parent_id]) if show_add_new +edit_associated_url = params_for(:action => 'edit_associated', :child_association => column.name, :associated_id => '--ID--') if show_add_existing +add_new_url = params_for(:action => 'edit_associated', :child_association => column.name) if show_add_new -%> <div class="footer-wrapper"> diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index e0151c061c..a2e9dec401 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -9,7 +9,7 @@ def edit_associated def do_edit_associated @parent_record = params[:id].nil? ? new_model : find_if_allowed(params[:id], :update) - @column = active_scaffold_config.columns[params[:association]] + @column = active_scaffold_config.columns[params[:child_association]] # NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all. @record = @column.association.klass.find(params[:associated_id]) if params[:associated_id] From acfedee374cbb0213699ef3dcb22eacf9537026f Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 29 May 2012 12:00:26 -1000 Subject: [PATCH 1522/2024] fix typo, js_config for controller, config in JS --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- app/assets/javascripts/prototype/active_scaffold.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 80623568e1..f6dc744384 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -605,7 +605,7 @@ var ActiveScaffold = { highlight: function(element) { if (typeof(element) == 'string') element = jQuery('#' + element); if (typeof(element.effect) == 'function') { - element.effect("highlight", jQuery.extend({}, ActiveScaffold.js_config.highlight), 3000); + element.effect("highlight", jQuery.extend({}, ActiveScaffold.config.highlight), 3000); } }, diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 518dbd3c30..ae4e1c9433 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -673,7 +673,7 @@ var ActiveScaffold = { highlight: function(element) { element = $(element); if (typeof(element.highlight) == 'function') { - element.highlight(Object.extend({duration: 3}, ActiveScaffold.js_config.highlight)); + element.highlight(Object.extend({duration: 3}, ActiveScaffold.config.highlight)); } } } From a7696e642c626306b496d28c5aa274d688a183e1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 30 May 2012 10:15:33 -1000 Subject: [PATCH 1523/2024] fix plural associations subform for multiple create, scope was missing (from active_scaffold_batch) --- .../default/views/_form_association.html.erb | 2 +- .../helpers/list_column_helpers.rb | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index a300d376fc..424f9d8119 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -10,7 +10,7 @@ subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_reco <h5><%= column.label -%></h5> <div id ="<%= subform_div_id %>" <%= 'style="display: none;"'.html_safe if column.collapsed -%>> <%# HACK to be able to delete all associated records %> -<%= hidden_field_tag "#{active_scaffold_input_options(column)[:name]}[0]", '' if column.plural_association? %> +<%= hidden_field_tag "#{active_scaffold_input_options(column, scope)[:name]}[0]", '' if column.plural_association? %> <%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record, :scope => scope} %> </div> <%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%> diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 95ef73cca0..edfa721664 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -92,10 +92,11 @@ def configure_column_link(link, associated, actions) def column_link_authorized?(link, column, record, associated) if column.association - associated_for_authorized = if associated.nil? || (column.plural_association? && !associated.loaded?) || (associated.respond_to?(:blank?) && associated.blank?) + associated_for_authorized = if associated.nil? || (associated.respond_to?(:blank?) && associated.blank?) column.association.klass elsif [:has_many, :has_and_belongs_to_many].include? column.association.macro - associated.first + # may be cached with [] or [nil] to avoid some queries + associated.first || column.association.klass else associated end @@ -150,7 +151,7 @@ def format_column_value(record, column, value = nil) value ||= record.send(column.name) unless record.nil? if value && column.association # cache association size before calling column_empty? associated_size = value.size if column.plural_association? and column.associated_number? # get count before cache association - cache_association(value, column) if column.plural_association? + cache_association(value, column, associated_size) if column.plural_association? end if column.association.nil? or column_empty?(value) if column.form_ui == :select && column.options[:options] @@ -222,14 +223,16 @@ def format_value(column_value, options = {}) clean_column_value(value) end - def cache_association(value, column) + def cache_association(value, column, size) # we are not using eager loading, cache firsts records in order not to query the database in a future unless value.loaded? - # load at least one record, is needed for column_empty? and checking permissions + # load at least one record, is needed to display '...' if column.associated_limit.nil? Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries" - else + elsif column.associated_limit > 0 value.target = value.find(:all, :limit => column.associated_limit + 1, :select => column.select_columns) + else + value.target = size.to_i.zero? ? [] : [nil] end end end From d7d2a14c53df06d617439b89c9a83abc85b7f853 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 30 May 2012 13:35:22 -1000 Subject: [PATCH 1524/2024] send scope to edit_associated, for create multiple records (active_scaffold_batch support) --- frontends/default/views/_form_association_footer.html.erb | 4 ++-- frontends/default/views/_horizontal_subform.html.erb | 2 +- frontends/default/views/_vertical_subform.html.erb | 2 +- lib/active_scaffold/actions/subform.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index faeb6fed90..a4b4ae670a 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -11,8 +11,8 @@ show_add_new = column_show_add_new(column, associated, @record) return unless show_add_new or show_add_existing -edit_associated_url = params_for(:action => 'edit_associated', :child_association => column.name, :associated_id => '--ID--') if show_add_existing -add_new_url = params_for(:action => 'edit_associated', :child_association => column.name) if show_add_new +edit_associated_url = params_for(:action => 'edit_associated', :child_association => column.name, :associated_id => '--ID--', :scope => scope) if show_add_existing +add_new_url = params_for(:action => 'edit_associated', :child_association => column.name, :scope => scope) if show_add_new -%> <div class="footer-wrapper"> diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index 59f635c9ef..29fa339bbc 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -19,4 +19,4 @@ <%= render :partial => 'horizontal_subform_footer', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column} %> </tfoot> </table> -<%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%> +<%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated, :scope => scope} -%> diff --git a/frontends/default/views/_vertical_subform.html.erb b/frontends/default/views/_vertical_subform.html.erb index cfed97582a..26614b4490 100644 --- a/frontends/default/views/_vertical_subform.html.erb +++ b/frontends/default/views/_vertical_subform.html.erb @@ -9,4 +9,4 @@ <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> <% end -%> </div> -<%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%> +<%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated, :scope => scope} -%> diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index a2e9dec401..7fe4e85e6b 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -15,7 +15,7 @@ def do_edit_associated @record = @column.association.klass.find(params[:associated_id]) if params[:associated_id] @record ||= build_associated(@column, @parent_record) - @scope = "[#{@column.name}]" + @scope = "#{params[:scope]}[#{@column.name}]" @scope += (@record.new_record?) ? "[#{(Time.now.to_f*1000).to_i.to_s}]" : "[#{@record.id}]" if @column.plural_association? end From 101142a4054a5d25ea31c44569d885f3cd6d73b3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 31 May 2012 09:32:25 -1000 Subject: [PATCH 1525/2024] enable eager loading in row, or some associations can be set to [nil] and break user code --- CHANGELOG | 2 +- lib/active_scaffold/actions/list.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 96fc19915a..d951c029b0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,7 +2,7 @@ - improve support for tableless models, add support for count - fix div id for nested scaffolds - add config.timestamped_messages and config.highlight_messages -- Improve performance using class to check authorization for plural associations which are not loaded +- Improve performance using class to check authorization for plural associations which are not loaded, and avoiding to load associations if it's not needed - Fix using a scope in main form, it wasn't working for associations (for create multiple from active_scaffold_batch) - Fix searches with no results, it was loading first page without conditions - Allow to change highlight options with ActiveScaffold.js_config diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 62a6fb2823..164c117c33 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -11,7 +11,8 @@ def index # get just a single row def row - @record = find_if_allowed(params[:id], :read) + klass = beginning_of_chain.includes(active_scaffold_includes) + @record = find_if_allowed(params[:id], :read, klass) respond_to_action(:row) end From e7774a4093e659766cdb3d6849f42293e24ebf2b Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 31 May 2012 10:23:07 -1000 Subject: [PATCH 1526/2024] allow to override column count calculation for colspan --- CHANGELOG | 1 + frontends/default/views/_list_inline_adapter.html.erb | 2 +- frontends/default/views/_list_messages.html.erb | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d951c029b0..030f327c63 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ - Fix using a scope in main form, it wasn't working for associations (for create multiple from active_scaffold_batch) - Fix searches with no results, it was loading first page without conditions - Allow to change highlight options with ActiveScaffold.js_config +- allow to override column count calculation for colspan = 3.2.11 - improve support for tableless models and active_scaffold_batch diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index 1990cf9d02..207330ce18 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -1,5 +1,5 @@ <% - column_count = if nested? and action_name == 'index' + column_count ||= if nested? and action_name == 'index' active_scaffold_config_for(nested.parent_model).list.columns.count + 1 else active_scaffold_config.list.columns.count + 1 diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index eb7b9a85a1..0b7aa1c87b 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -1,6 +1,7 @@ +<% column_count ||= columns.length + 1 -%> <tbody class="messages"> <tr class="record even-record"> - <td colspan="<%= columns.length + 1 -%>" class="messages-container"> + <td colspan="<%= column_count -%>" class="messages-container"> <p class="error-message message server-error" style="display:none;"> <%= as_(:internal_error).html_safe %> <a href="#" class="close" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a> From 8527f5c4909afe38be11fde3ed816a3f83694eed Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 31 May 2012 12:14:20 -1000 Subject: [PATCH 1527/2024] avoiding to load associations if it's not needed, and load includes when refreshing row --- lib/active_scaffold/actions/list.rb | 1 + lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 164c117c33..dd1fb8952c 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -11,6 +11,7 @@ def index # get just a single row def row + set_includes_for_list_columns klass = beginning_of_chain.includes(active_scaffold_includes) @record = find_if_allowed(params[:id], :read, klass) respond_to_action(:row) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index edfa721664..b1df8bd64d 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -92,7 +92,7 @@ def configure_column_link(link, associated, actions) def column_link_authorized?(link, column, record, associated) if column.association - associated_for_authorized = if associated.nil? || (associated.respond_to?(:blank?) && associated.blank?) + associated_for_authorized = if associated.nil? || (column.plural_association? && !associated.loaded?) || (associated.respond_to?(:blank?) && associated.blank?) column.association.klass elsif [:has_many, :has_and_belongs_to_many].include? column.association.macro # may be cached with [] or [nil] to avoid some queries From 42dbc8ba6fc58b7e399a78f0ebf718590bc31ef0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 31 May 2012 13:44:39 -1000 Subject: [PATCH 1528/2024] separate row in get_row and row, as list and do_list --- lib/active_scaffold/actions/list.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index dd1fb8952c..3ff4d36e48 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -11,9 +11,7 @@ def index # get just a single row def row - set_includes_for_list_columns - klass = beginning_of_chain.includes(active_scaffold_includes) - @record = find_if_allowed(params[:id], :read, klass) + get_row respond_to_action(:row) end @@ -61,6 +59,12 @@ def set_includes_for_list_columns includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact self.active_scaffold_includes.concat includes_for_list_columns end + + def get_row + set_includes_for_list_columns + klass = beginning_of_chain.includes(active_scaffold_includes) + @record = find_if_allowed(params[:id], :read, klass) + end # The actual algorithm to prepare for the list view def do_list From 6b8ab9cc1ac1967c350db4be9a5c19316164c39a Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 1 Jun 2012 09:08:25 -1000 Subject: [PATCH 1529/2024] fix on_create and on_update, you must specify :formats=>[:js] after rendering a html partial --- frontends/default/views/add_existing.js.erb | 2 +- frontends/default/views/destroy.js.erb | 4 ++-- frontends/default/views/on_action_update.js.erb | 2 +- frontends/default/views/on_create.js.erb | 4 ++-- frontends/default/views/on_update.js.erb | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/frontends/default/views/add_existing.js.erb b/frontends/default/views/add_existing.js.erb index a26167d307..ea16f7e505 100644 --- a/frontends/default/views/add_existing.js.erb +++ b/frontends/default/views/add_existing.js.erb @@ -1,7 +1,7 @@ <% new_row = render :partial => 'list_record', :locals => {:record => @record} %> ActiveScaffold.create_record_row('<%= active_scaffold_id %>', '<%= escape_javascript(new_row) %>', <%= {:insert_at => :top}.to_json.html_safe %>); -<%= render :partial => 'update_calculations' %> +<%= render :partial => 'update_calculations', :formats => [:js] %> <% if form_stays_open ||= true %> <%# why not just re-render the form? that wouldn't utilize a possible do_new override which sets default values.%> diff --git a/frontends/default/views/destroy.js.erb b/frontends/default/views/destroy.js.erb index 6a8503509b..3e5d349851 100644 --- a/frontends/default/views/destroy.js.erb +++ b/frontends/default/views/destroy.js.erb @@ -6,7 +6,7 @@ <% current_id = controller_id(params[:eid] || params[:parent_sti]) -%> ActiveScaffold.delete_record_row('<%= element_row_id(:controller_id => current_id, :action => 'list', :id => params[:id]) %>', '<%= url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max)) %>'); <% messages_id = active_scaffold_messages_id(:controller_id => current_id) %> - <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => current_id)} %> + <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => current_id)}, :formats => [:js] %> <% elsif render_parent_action == :index %> <% if controller.respond_to?(:render_component_into_view) %> <%= escape_javascript(controller.send(:render_component_into_view, render_parent_options)) %> @@ -18,7 +18,7 @@ <%= render :partial => 'refresh_list' %> <% else %> ActiveScaffold.delete_record_row('<%= element_row_id(:action => 'list', :id => params[:id]) %>', '<%= url_for(params_for(:action => :index, :id => nil, :page => [active_scaffold_config.list.user.page.to_i - 1, 1].max)) %>'); - <%= render :partial => 'update_calculations' %> + <%= render :partial => 'update_calculations', :formats => [:js] %> <% end %> <% else %> <% flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) %> diff --git a/frontends/default/views/on_action_update.js.erb b/frontends/default/views/on_action_update.js.erb index 95ffd5c6f6..ca54d17482 100644 --- a/frontends/default/views/on_action_update.js.erb +++ b/frontends/default/views/on_action_update.js.erb @@ -8,7 +8,7 @@ ActiveScaffold.update_row('<%= element_row_id(:action => :list, :id => @record.id) %>', '<%= row %>'); ActiveScaffold.scroll_to('<%= element_row_id(:action => :list, :id => @record.id) %>', true); <% end %> - <%= render :partial => 'update_calculations' %> + <%= render :partial => 'update_calculations', :formats => [:js] %> <% else %> <% if @action_link.nil? || @action_link.position %> ActiveScaffold.find_action_link('<%= element_row_id(:action => action_name) %>').close(); diff --git a/frontends/default/views/on_create.js.erb b/frontends/default/views/on_create.js.erb index e30918670f..b47fffe00c 100644 --- a/frontends/default/views/on_create.js.erb +++ b/frontends/default/views/on_create.js.erb @@ -17,7 +17,7 @@ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'mess <% end %> action_link.close(); <% end %> - <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)} unless render_parent_action == :index %> + <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)}, :formats => [:js] unless render_parent_action == :index %> <% else %> <% if nested_singular_association? || render_parent_action == :row %> action_link.close(); @@ -29,7 +29,7 @@ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'mess <% elsif params[:parent_controller].nil? %> <% new_row = render :partial => 'list_record', :locals => {:record => @record} %> ActiveScaffold.create_record_row(action_link.scaffold(),'<%= escape_javascript(new_row) %>', <%= {:insert_at => insert_at}.to_json.html_safe %>); - <%= render :partial => 'update_calculations' %> + <%= render :partial => 'update_calculations', :formats => [:js] %> <% end %> <% unless render_parent? %> diff --git a/frontends/default/views/on_update.js.erb b/frontends/default/views/on_update.js.erb index 8a52c09076..2c9aaab39b 100644 --- a/frontends/default/views/on_update.js.erb +++ b/frontends/default/views/on_update.js.erb @@ -9,22 +9,22 @@ action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'mes <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> <% if nested_singular_association? || render_parent_action == :row %> action_link.close('<%= escape_javascript(parent_rendered) %>'); - <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)} %> + <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)}, :formats => [:js] %> <% elsif render_parent_action == :index %> <%= escape_javascript(parent_rendered) %> <% end %> <% else %> <% if nested_singular_association? || render_parent_action == :row %> action_link.close(); - <% end %> - ActiveScaffold.reload('<%= url_for render_parent_options %>'); + <% end %> + ActiveScaffold.reload('<%= url_for render_parent_options %>'); <% end %> <% elsif update_refresh_list? %> <%= render :partial => 'refresh_list' %> <% else %> <% updated_row = render :partial => 'list_record', :locals => {:record => @record} %> action_link.close('<%= escape_javascript(updated_row) %>'); - <%= render :partial => 'update_calculations' %> + <%= render :partial => 'update_calculations', :formats => [:js] %> <% end %> <% end %> <% else %> From 1dd98910cd16e1420aa35ed8ee5523d2532f8f2d Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 1 Jun 2012 10:26:52 -1000 Subject: [PATCH 1530/2024] remove conditions_from_params from nested links --- CHANGELOG | 1 + lib/active_scaffold/actions/core.rb | 16 +++++++++------- .../helpers/controller_helpers.rb | 6 +++++- lib/active_scaffold/helpers/view_helpers.rb | 11 +++++++---- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 030f327c63..c76fca4a7a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ - Fix searches with no results, it was loading first page without conditions - Allow to change highlight options with ActiveScaffold.js_config - allow to override column count calculation for colspan +- Remove conditions_from_params from nested links = 3.2.11 - improve support for tableless models and active_scaffold_batch diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 843ea75dfb..16c0e904cf 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -150,14 +150,16 @@ def beginning_of_chain # Builds search conditions by search params for column names. This allows urls like "contacts/list?company_id=5". def conditions_from_params - conditions = {} - params.reject {|key, value| [:controller, :action, :id, :page, :sort, :sort_direction].include?(key.to_sym)}.each do |key, value| - next unless active_scaffold_config.model.columns_hash[key.to_s] - next if active_scaffold_constraints[key.to_sym] - next if nested? and nested.constrained_fields.include? key.to_sym - conditions[key] = value + @conditions_from_params ||= begin + conditions = {} + params.reject {|key, value| [:controller, :action, :id, :page, :sort, :sort_direction].include?(key.to_sym)}.each do |key, value| + next unless active_scaffold_config.model.columns_hash[key.to_s] + next if active_scaffold_constraints[key.to_sym] + next if nested? and nested.constrained_fields.include? key.to_sym + conditions[key.to_sym] = value + end + conditions end - conditions end def new_model diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 361758755a..fa9732c5e5 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -2,10 +2,14 @@ module ActiveScaffold module Helpers module ControllerHelpers def self.included(controller) - controller.class_eval { helper_method :params_for, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated} + controller.class_eval { helper_method :params_for, :params_conditions, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated} end include ActiveScaffold::Helpers::IdHelpers + + def params_conditions + conditions_from_params.keys + end def params_for(options = {}) # :adapter and :position are one-use rendering arguments. they should not propagate. diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 3e0c2436d1..774e0302b2 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -123,9 +123,11 @@ def action_link_url_options(link, url_options, record, options = {}) url_options[:controller] = link.controller.to_s if link.controller url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller] url_options.merge! link.parameters if link.parameters - @link_record = record - url_options.merge! self.instance_eval(&(link.dynamic_parameters)) if link.dynamic_parameters.is_a?(Proc) - @link_record = nil + if link.dynamic_parameters.is_a?(Proc) + @link_record = record + url_options.merge! self.instance_eval(&(link.dynamic_parameters)) + @link_record = nil + end url_options_for_nested_link(link.column, record, link, url_options, options) if link.nested_link? url_options_for_sti_link(link.column, record, link, url_options, options) unless record.nil? || active_scaffold_config.sti_children.nil? url_options[:_method] = link.method if !link.confirm? && link.inline? && link.method != :get @@ -195,7 +197,8 @@ def url_options_for_nested_link(column, record, link, url_options, options = {}) url_options[active_scaffold_config.model.name.foreign_key.to_sym] = url_options.delete(:id) url_options[:eid] = nil # needed for nested scaffolds open from an embedded scaffold end - nested.constrained_fields.each { |field| url_options.delete field } if nested? + url_options.except! *params_conditions + url_options.except! *nested.constrained_fields if nested? end def url_options_for_sti_link(column, record, link, url_options, options = {}) From c6677f27bce942c7bb0d480903e39f2e3440486a Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 1 Jun 2012 11:32:35 -1000 Subject: [PATCH 1531/2024] display title in action links with image --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 774e0302b2..7dd5336ea0 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -182,7 +182,7 @@ def action_link_html(link, url, html_options, record) if link.image.nil? html = link_to(label, url, html_options) else - html = link_to(image_tag(link.image[:name] , :size => link.image[:size], :alt => label), url, html_options) + html = link_to(image_tag(link.image[:name], :size => link.image[:size], :alt => label, :title => label), url, html_options) end # if url is nil we would like to generate an anchor without href attribute url.nil? ? html.sub(/href=".*?"/, '').html_safe : html.html_safe From bc45325e246cf4b8ea5c96aeb9980cae56aa4189 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 1 Jun 2012 14:30:51 -1000 Subject: [PATCH 1532/2024] fix column count for nested forms (singular associations) --- frontends/default/views/_list_inline_adapter.html.erb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index 207330ce18..58653b3bf3 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -1,8 +1,11 @@ <% - column_count ||= if nested? and action_name == 'index' - active_scaffold_config_for(nested.parent_model).list.columns.count + 1 - else - active_scaffold_config.list.columns.count + 1 + column_count ||= begin + config = if nested? and (nested.singular_association? || action_name == 'index') + active_scaffold_config_for(nested.parent_model) + else + active_scaffold_config + end + config.list.columns.count + 1 end %> <%# nested_id, allows us to remove a nested scaffold programmatically %> From 459020ae238c077482981d42f8a77a90a41cb1e8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 1 Jun 2012 14:31:16 -1000 Subject: [PATCH 1533/2024] Update is not really needed for mark --- lib/active_scaffold/config/mark.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/config/mark.rb b/lib/active_scaffold/config/mark.rb index 4def5d09bb..a32168ac06 100644 --- a/lib/active_scaffold/config/mark.rb +++ b/lib/active_scaffold/config/mark.rb @@ -13,12 +13,8 @@ class Mark < Base def initialize(core_config) @core = core_config @mark_all_mode = self.class.mark_all_mode - if core_config.actions.include?(:update) - @core.model.send(:include, ActiveScaffold::MarkedModel) unless @core.model.ancestors.include?(ActiveScaffold::MarkedModel) - add_mark_column - else - raise "Mark action requires update action in controller for model: #{core_config.model.to_s}" - end + @core.model.send(:include, ActiveScaffold::MarkedModel) unless @core.model < ActiveScaffold::MarkedModel + add_mark_column end protected From 2bdb37a77df123f6c9bb17ff1a6701a89bce4ca6 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 1 Jun 2012 14:32:53 -1000 Subject: [PATCH 1534/2024] Add some methods to test kind of nested association --- .../data_structures/nested_info.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index c274cf04df..2ae1d5ad09 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -44,7 +44,11 @@ def parent_scope def habtm? false end - + + def has_many? + false + end + def belongs_to? false end @@ -52,6 +56,14 @@ def belongs_to? def has_one? false end + + def singular_association? + belongs_to? || has_one? + end + + def plural_association? + has_many? || habtm? + end def readonly? false @@ -73,6 +85,10 @@ def name self.association.name end + def has_many? + association.macro == :has_many + end + def habtm? association.macro == :has_and_belongs_to_many end From f660bed7436161cf529341859fdc634690ef6d55 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 1 Jun 2012 15:54:15 -1000 Subject: [PATCH 1535/2024] fix nested forms for singular assocs --- CHANGELOG | 1 + lib/active_scaffold/helpers/controller_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index c76fca4a7a..3c2005dbc2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ - Allow to change highlight options with ActiveScaffold.js_config - allow to override column count calculation for colspan - Remove conditions_from_params from nested links +- Fix nested forms for singular associations = 3.2.11 - improve support for tableless models and active_scaffold_batch diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index fa9732c5e5..0fc79e247c 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Helpers module ControllerHelpers def self.included(controller) - controller.class_eval { helper_method :params_for, :params_conditions, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated} + controller.class_eval { helper_method :params_for, :params_conditions, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_controller, :render_parent_action, :nested_singular_association?, :build_associated} end include ActiveScaffold::Helpers::IdHelpers From a7d8557193663a46d45aa8697bce9a0151c468b7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 1 Jun 2012 16:43:19 -1000 Subject: [PATCH 1536/2024] render_component doesn't work for nested forms inside a nested scaffolds, parent constraints are forgotten --- .../javascripts/jquery/active_scaffold.js | 13 ++++++++++--- .../javascripts/prototype/active_scaffold.js | 16 +++++++++++++--- frontends/default/views/on_create.js.erb | 18 ++---------------- frontends/default/views/on_update.js.erb | 13 ++----------- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index f6dc744384..19337347c4 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -1026,10 +1026,17 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ ActiveScaffold.highlight(this.adapter.find('td')); }, - close: function(refreshed_content) { + close: function(refreshed_content_or_reload) { this._super(); - if (refreshed_content) { - ActiveScaffold.update_row(this.target, refreshed_content); + if (refreshed_content_or_reload) { + if (typeof refreshed_content_or_reload == 'string') { + ActiveScaffold.update_row(this.target, refreshed_content); + } else if (this.refresh_url) { + var target = this.target; + jQuery.get(this.refresh_url, function(e, status, response) { + ActiveScaffold.update_row(target, response.responseText); + }); + } } }, diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index ae4e1c9433..f98c988e0e 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -917,10 +917,20 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra ActiveScaffold.highlight(this.adapter.down('td').down()); }, - close: function($super, refreshed_content) { + close: function($super, refreshed_content_or_reload) { $super(); - if (refreshed_content) { - ActiveScaffold.update_row(this.target, refreshed_content); + if (refreshed_content_or_reload) { + if (typeof refreshed_content_or_reload == 'string') { + ActiveScaffold.update_row(this.target, refreshed_content); + } else if (this.refresh_url) { + var target = this.target; + new Ajax.Request(this.refresh_url, { + method: 'get', + onComplete: function(response) { + ActiveScaffold.update_row(target, response.responseText); + } + }); + } } }, diff --git a/frontends/default/views/on_create.js.erb b/frontends/default/views/on_create.js.erb index b47fffe00c..06fdbfac4c 100644 --- a/frontends/default/views/on_create.js.erb +++ b/frontends/default/views/on_create.js.erb @@ -5,23 +5,9 @@ var action_link = ActiveScaffold.find_action_link('<%= form_selector%>'); action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages'))%>'); <% if controller.send :successful? %> <% if render_parent? %> - <% if controller.respond_to?(:render_component_into_view) %> - <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> - <% if nested_singular_association? %> - action_link.close('<%= escape_javascript(parent_rendered)%>'); - <% else %> - <% if render_parent_action == :row %> - ActiveScaffold.create_record_row(action_link.scaffold(),'<%= escape_javascript(parent_rendered) %>', <%= {:insert_at => insert_at}.to_json.html_safe %>); - <% elsif render_parent_action == :index %> - <%= escape_javascript(parent_rendered) %> - <% end %> - action_link.close(); - <% end %> - <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)}, :formats => [:js] unless render_parent_action == :index %> + <% if nested_singular_association? || render_parent_action == :row %> + action_link.close(true); <% else %> - <% if nested_singular_association? || render_parent_action == :row %> - action_link.close(); - <% end %> ActiveScaffold.reload('<%= url_for render_parent_options %>'); <% end %> <% elsif (active_scaffold_config.create.refresh_list) %> diff --git a/frontends/default/views/on_update.js.erb b/frontends/default/views/on_update.js.erb index 2c9aaab39b..65a8a63eef 100644 --- a/frontends/default/views/on_update.js.erb +++ b/frontends/default/views/on_update.js.erb @@ -5,18 +5,9 @@ action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'mes <% if controller.send :successful? %> <% if !active_scaffold_config.update.persistent %> <% if render_parent? %> - <% if controller.respond_to?(:render_component_into_view) %> - <% parent_rendered = controller.send(:render_component_into_view, render_parent_options) %> - <% if nested_singular_association? || render_parent_action == :row %> - action_link.close('<%= escape_javascript(parent_rendered) %>'); - <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => render_parent_controller)}, :formats => [:js] %> - <% elsif render_parent_action == :index %> - <%= escape_javascript(parent_rendered) %> - <% end %> + <% if nested_singular_association? || render_parent_action == :row %> + action_link.close(true); <% else %> - <% if nested_singular_association? || render_parent_action == :row %> - action_link.close(); - <% end %> ActiveScaffold.reload('<%= url_for render_parent_options %>'); <% end %> <% elsif update_refresh_list? %> From 5c12cf1ac62390941acf7e77a000151187477ea9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 1 Jun 2012 16:44:19 -1000 Subject: [PATCH 1537/2024] remove unused method with last change --- lib/active_scaffold/helpers/controller_helpers.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 0fc79e247c..7d6ba156cb 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Helpers module ControllerHelpers def self.included(controller) - controller.class_eval { helper_method :params_for, :params_conditions, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_controller, :render_parent_action, :nested_singular_association?, :build_associated} + controller.class_eval { helper_method :params_for, :params_conditions, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated} end include ActiveScaffold::Helpers::IdHelpers @@ -85,14 +85,6 @@ def render_parent_action end if @parent_action.nil? @parent_action end - - def render_parent_controller - if nested_singular_association? - nested.parent_scaffold.controller_path - else - params[:parent_sti] - end - end def build_associated(column, record) if column.singular_association? From 77ff3e87ca5f18ac4cb5c2cba5250d8fd111faa9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 1 Jun 2012 18:10:35 -1000 Subject: [PATCH 1538/2024] fix typo --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- app/assets/javascripts/prototype/active_scaffold.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 19337347c4..95f5f823bd 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -1030,7 +1030,7 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ this._super(); if (refreshed_content_or_reload) { if (typeof refreshed_content_or_reload == 'string') { - ActiveScaffold.update_row(this.target, refreshed_content); + ActiveScaffold.update_row(this.target, refreshed_content_or_reload); } else if (this.refresh_url) { var target = this.target; jQuery.get(this.refresh_url, function(e, status, response) { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index f98c988e0e..e23485086b 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -921,7 +921,7 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra $super(); if (refreshed_content_or_reload) { if (typeof refreshed_content_or_reload == 'string') { - ActiveScaffold.update_row(this.target, refreshed_content); + ActiveScaffold.update_row(this.target, refreshed_content_or_update); } else if (this.refresh_url) { var target = this.target; new Ajax.Request(this.refresh_url, { From 4c6ff9e4936fbb87c9b1e30222ee8a1e83d37ef5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 1 Jun 2012 18:23:35 -1000 Subject: [PATCH 1539/2024] fix triggering element_updated in ActiveScaffold#replace --- app/assets/javascripts/jquery/active_scaffold.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 95f5f823bd..2e258c1857 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -418,12 +418,10 @@ var ActiveScaffold = { replace: function(element, html) { if (typeof(element) == 'string') element = '#' + element; element = jQuery(element); - element.replaceWith(html); - if (element.attr('id')) { - element = jQuery('#' + element.attr('id')); - } - element.trigger('as:element_updated'); - return element; + var new_element = jQuery(html); + element.replaceWith(new_element); + new_element.trigger('as:element_updated'); + return new_element; }, replace_html: function(element, html) { From b53f77996eec20d2e3c6f4e13f04a32b38a11c84 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 1 Jun 2012 19:53:35 -1000 Subject: [PATCH 1540/2024] fix closing nested scaffolds --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 2e258c1857..69c82abea0 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -80,7 +80,7 @@ jQuery(document).ready(function() { } return true; }); - jQuery('a.as_cancel').live('ajax:success', function(event, response) { + jQuery('a.as_cancel').live('ajax:complete', function(event, response) { var action_link = ActiveScaffold.find_action_link(jQuery(this)); if (action_link) { From b9ac1c93cbe387e670045d7c0851da1dcfc5606d Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 1 Jun 2012 22:37:26 -1000 Subject: [PATCH 1541/2024] really fix closing nested scaffolds --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- frontends/default/views/_row.html.erb | 7 +------ frontends/default/views/row.js.erb | 1 + lib/active_scaffold/actions/list.rb | 4 ++-- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 69c82abea0..2e258c1857 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -80,7 +80,7 @@ jQuery(document).ready(function() { } return true; }); - jQuery('a.as_cancel').live('ajax:complete', function(event, response) { + jQuery('a.as_cancel').live('ajax:success', function(event, response) { var action_link = ActiveScaffold.find_action_link(jQuery(this)); if (action_link) { diff --git a/frontends/default/views/_row.html.erb b/frontends/default/views/_row.html.erb index 33d0f4e0de..79475acb57 100644 --- a/frontends/default/views/_row.html.erb +++ b/frontends/default/views/_row.html.erb @@ -1,6 +1 @@ -<%= render :partial => 'list_record', :locals => {:record => record}%> -<%= javascript_tag do %> - <%= render :partial => 'update_calculations', :formats => [:js] %> -<% end %> - - +<%= render :partial => 'list_record', :locals => {:record => record} %> diff --git a/frontends/default/views/row.js.erb b/frontends/default/views/row.js.erb index a346641218..36afd71ee5 100644 --- a/frontends/default/views/row.js.erb +++ b/frontends/default/views/row.js.erb @@ -1 +1,2 @@ ActiveScaffold.update_row('<%= element_row_id(:action => :list) %>', '<%= escape_javascript render(:partial => 'row', :locals => {:record => @record}) %>'); +<%= render :partial => 'update_calculations', :formats => [:js] %> diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 3ff4d36e48..ad4ff6581d 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -50,8 +50,8 @@ def list_respond_to_yaml render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status end - def row_respond_to_html - render(:partial => 'row', :locals => {:record => @record}) + def row_respond_to_js + render end # The actual algorithm to prepare for the list view From 0c464bc9e8328aebb2d61096eeac19fe18fa05d0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Sat, 2 Jun 2012 19:07:23 -1000 Subject: [PATCH 1542/2024] enable to get constraints in helpers, so can be used in options_for_association_conditions, for example --- CHANGELOG | 1 + lib/active_scaffold.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 3c2005dbc2..5ee21449ef 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ - allow to override column count calculation for colspan - Remove conditions_from_params from nested links - Fix nested forms for singular associations +- enable to get constraints in helpers, so can be used in options_for_association_conditions, for example = 3.2.11 - improve support for tableless models and active_scaffold_batch diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index ae2ae3d64c..5c86f98a4d 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -70,6 +70,7 @@ def self.included(base) base.helper_method :touch_device? base.helper_method :hover_via_click? + base.helper_method :active_scaffold_constraints end def self.set_defaults(&block) From 6fa9146cbd520bcd6c3a053fc46201f6ed419b4b Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Sat, 2 Jun 2012 20:22:17 -1000 Subject: [PATCH 1543/2024] update and delete work in nested through --- CHANGELOG | 1 + lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/actions/nested.rb | 2 ++ lib/active_scaffold/data_structures/nested_info.rb | 14 +++++++++----- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5ee21449ef..923e095225 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ - Remove conditions_from_params from nested links - Fix nested forms for singular associations - enable to get constraints in helpers, so can be used in options_for_association_conditions, for example +- Allow to edit has_one :through association in nested forms = 3.2.11 - improve support for tableless models and active_scaffold_batch diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index d31c976189..87283cdab7 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -122,7 +122,7 @@ def create_ignore? end def create_authorized? - (!nested? || !nested.readonly?) && authorized_for?(:crud_type => :create) + (!nested? || !nested.readonly? || !nested.through?) && authorized_for?(:crud_type => :create) end private def create_authorized_filter diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 3f722e1cc4..ffa1fdd40f 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -76,6 +76,8 @@ def beginning_of_chain if nested? && nested.association && !nested.association.belongs_to? if nested.association.collection? nested.parent_scope.send(nested.association.name) + elsif nested.association.options[:through] # has_one :through doesn't need conditions + super elsif nested.child_association.belongs_to? super.where(nested.child_association.foreign_key => nested.parent_scope) end diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 2ae1d5ad09..554ff651c2 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -64,6 +64,10 @@ def singular_association? def plural_association? has_many? || habtm? end + + def through_association? + false + end def readonly? false @@ -101,12 +105,12 @@ def has_one? association.macro == :has_one end + def through_association? + association.options[:through] + end + def readonly? - if association.options.has_key? :readonly - association.options[:readonly] - else - association.options.has_key? :through - end + association.options[:readonly] end def sorted? From a8a343722a7b962d9df6fbd55d56ab906a8acff9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 12 Jun 2012 16:35:04 +0200 Subject: [PATCH 1544/2024] restore active_scaffold_config.model instead of super in nested, fixes #165 --- lib/active_scaffold/actions/nested.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index ffa1fdd40f..660944fa80 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -77,14 +77,14 @@ def beginning_of_chain if nested.association.collection? nested.parent_scope.send(nested.association.name) elsif nested.association.options[:through] # has_one :through doesn't need conditions - super + active_scaffold_config.model elsif nested.child_association.belongs_to? - super.where(nested.child_association.foreign_key => nested.parent_scope) + active_scaffold_config.model.where(nested.child_association.foreign_key => nested.parent_scope) end elsif nested? && nested.scope nested.parent_scope.send(nested.scope) else - super + active_scaffold_config.model end end From e0fa6360c0a0a54915891ecc99eccec45fb9a50f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 12 Jun 2012 16:36:13 +0200 Subject: [PATCH 1545/2024] bump version to 3.2.12 --- CHANGELOG | 1 + lib/active_scaffold/version.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 923e095225..3deb82f380 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ - Fix nested forms for singular associations - enable to get constraints in helpers, so can be used in options_for_association_conditions, for example - Allow to edit has_one :through association in nested forms +- Fix cancan bridge broken in a previous release = 3.2.11 - improve support for tableless models and active_scaffold_batch diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 2ff121d86e..fb23059af2 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 11 + PATCH = 12 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From b31e6eee0ef5a9ba6b22110a919df1eecdfb9f9d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 13 Jun 2012 17:06:12 +0200 Subject: [PATCH 1546/2024] fix mark action --- CHANGELOG | 1 + .../javascripts/jquery/active_scaffold.js | 58 +++++++------- .../javascripts/prototype/active_scaffold.js | 54 ++++++------- config/locales/de.yml | 4 + config/locales/en.yml | 4 + config/locales/es.yml | 4 + config/locales/fr.yml | 4 + config/locales/hu.yml | 4 + config/locales/ja.yml | 4 + config/locales/ru.yml | 4 + frontends/default/views/on_mark.js.erb | 6 ++ frontends/default/views/on_mark_all.js.erb | 12 --- lib/active_scaffold/actions/delete.rb | 2 +- lib/active_scaffold/actions/mark.rb | 59 ++++++++------ lib/active_scaffold/config/form.rb | 2 +- lib/active_scaffold/config/list.rb | 8 -- lib/active_scaffold/config/mark.rb | 11 ++- .../extensions/routing_mapper.rb | 4 +- lib/active_scaffold/finder.rb | 23 +++--- .../helpers/list_column_helpers.rb | 78 +++++++++++-------- lib/active_scaffold/helpers/view_helpers.rb | 2 +- lib/active_scaffold/marked_model.rb | 8 +- test/config/list_test.rb | 6 -- 23 files changed, 199 insertions(+), 163 deletions(-) create mode 100644 frontends/default/views/on_mark.js.erb delete mode 100644 frontends/default/views/on_mark_all.js.erb diff --git a/CHANGELOG b/CHANGELOG index 3deb82f380..a6713d31cd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ - enable to get constraints in helpers, so can be used in options_for_association_conditions, for example - Allow to edit has_one :through association in nested forms - Fix cancan bridge broken in a previous release +- Fix mark action = 3.2.11 - improve support for tableless models and active_scaffold_batch diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 2e258c1857..d300c5c412 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -122,7 +122,7 @@ jQuery(document).ready(function() { } return true; }); - jQuery('td.in_place_editor_field').live('click', function(event) { + jQuery('td.in_place_editor_field, th.as_marked-column_heading').live('click', function(event) { var span = jQuery(this).find('span.in_place_editor_field'); span.data('addEmptyOnCancel', jQuery(this).hasClass('empty')); jQuery(this).removeClass('empty'); @@ -585,13 +585,13 @@ var ActiveScaffold = { }, read_inplace_edit_heading_attributes: function(column_heading, options) { - if (column_heading.attr('data-ie_cancel_text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.attr('data-ie_cancel_text') + "</button>"; - if (column_heading.attr('data-ie_loading_text')) options.loading_text = column_heading.attr('data-ie_loading_text'); - if (column_heading.attr('data-ie_saving_text')) options.saving_text = column_heading.attr('data-ie_saving_text'); - if (column_heading.attr('data-ie_save_text')) options.save_button = '<button class="inplace_save">' + column_heading.attr('data-ie_save_text') + "</button>"; - if (column_heading.attr('data-ie_rows')) options.textarea_rows = column_heading.attr('data-ie_rows'); - if (column_heading.attr('data-ie_cols')) options.textarea_cols = column_heading.attr('data-ie_cols'); - if (column_heading.attr('data-ie_size')) options.text_size = column_heading.attr('data-ie_size'); + if (column_heading.data('ie-cancel-text')) options.cancel_button = '<button class="inplace_cancel">' + column_heading.data('ie-cancel-text') + "</button>"; + if (column_heading.data('ie-loading-text')) options.loading_text = column_heading.data('ie-loading-text'); + if (column_heading.data('ie-saving-text')) options.saving_text = column_heading.data('ie-saving-text'); + if (column_heading.data('ie-save-text')) options.save_button = '<button class="inplace_save">' + column_heading.data('ie-save-text') + "</button>"; + if (column_heading.data('ie-rows')) options.textarea_rows = column_heading.data('ie-rows'); + if (column_heading.data('ie-cols')) options.textarea_cols = column_heading.data('ie-cols'); + if (column_heading.data('ie-size')) options.text_size = column_heading.data('ie-size'); }, create_inplace_editor: function(span, options) { @@ -684,19 +684,21 @@ var ActiveScaffold = { mark_records: function(element, options) { if (typeof(element) == 'string') element = '#' + element; var element = jQuery(element); - var mark_checkboxes = jQuery('#' + element.attr('id') + ' > tr.record td.marked-column input[type="checkbox"]'); - mark_checkboxes.each(function (index) { - var item = jQuery(this); - if(options.checked === true) { - item.attr('checked', 'checked'); - } else { - item.removeAttr('checked'); - } - item.attr('value', ('' + !options.checked)); - }); - if(options.include_mark_all === true) { - var mark_all_checkbox = element.prev('thead').find('th.marked-column_heading span input[type="checkbox"]'); - if(options.checked === true) { + if (options.include_checkboxes) { + var mark_checkboxes = jQuery('#' + element.attr('id') + ' > tr.record td.as_marked-column input[type="checkbox"]'); + mark_checkboxes.each(function (index) { + var item = jQuery(this); + if(options.checked) { + item.attr('checked', 'checked'); + } else { + item.removeAttr('checked'); + } + item.attr('value', ('' + !options.checked)); + }); + } + if(options.include_mark_all) { + var mark_all_checkbox = element.prevAll('thead').find('th.as_marked-column_heading span input[type="checkbox"]'); + if(options.checked) { mark_all_checkbox.attr('checked', 'checked'); } else { mark_all_checkbox.removeAttr('checked'); @@ -735,16 +737,16 @@ var ActiveScaffold = { column_heading = my_parent; } - var render_url = column_heading.attr('data-ie_render_url'), - mode = column_heading.attr('data-ie_mode'), - record_id = span.attr('data-ie_id'); + var render_url = column_heading.data('ie-render-url'), + mode = column_heading.data('ie-mode'), + record_id = span.data('ie-id') || ''; ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options); - if (span.attr('data-ie_url')) { - options.url = span.attr('data-ie_url').replace(/__id__/, record_id); + if (span.data('ie-url')) { + options.url = span.data('ie-url').replace(/__id__/, record_id); } else { - options.url = column_heading.attr('data-ie_url').replace(/__id__/, record_id); + options.url = column_heading.data('ie-url').replace(/__id__/, record_id); } if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content'); @@ -764,7 +766,7 @@ var ActiveScaffold = { if (render_url) { var plural = false; - if (column_heading.attr('data-ie_plural')) plural = true; + if (column_heading.data('ie-plural')) plural = true; options.field_type = 'remote'; options.editor_url = render_url.replace(/__id__/, record_id) } diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index e23485086b..609770adc8 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -170,18 +170,18 @@ document.observe("dom:loaded", function() { column_heading = my_parent; } - var render_url = column_heading.readAttribute('data-ie_render_url'), - mode = column_heading.readAttribute('data-ie_mode'), - record_id = span.readAttribute('data-ie_id'); + var render_url = column_heading.readAttribute('data-ie-render-url'), + mode = column_heading.readAttribute('data-ie-mode'), + record_id = span.readAttribute('data-ie-id') || ''; ActiveScaffold.read_inplace_edit_heading_attributes(column_heading, options); - if (span.readAttribute('data-ie_url')) { - options.url = span.readAttribute('data-ie_url'); + if (span.readAttribute('data-ie-url')) { + options.url = span.readAttribute('data-ie-url'); } else { - options.url = column_heading.readAttribute('data-ie_url'); + options.url = column_heading.readAttribute('data-ie-url'); } - if (record_id) options.url = options.url.sub('__id__', record_id); + options.url = options.url.sub('__id__', record_id); if (csrf_param) options['params'] = csrf_param.readAttribute('content') + '=' + csrf_token.readAttribute('content'); @@ -200,7 +200,7 @@ document.observe("dom:loaded", function() { if (render_url) { var plural = false; - if (column_heading.readAttribute('data-ie_plural')) plural = true; + if (column_heading.readAttribute('data-ie-plural')) plural = true; options['onFormCustomization'] = new Function('element', 'form', 'element.setFieldFromAjax(' + "'" + render_url.sub('__id__', record_id) + "', {plural: " + plural + '});'); } @@ -530,13 +530,13 @@ var ActiveScaffold = { }, read_inplace_edit_heading_attributes: function(column_heading, options) { - if (column_heading.readAttribute('data-ie_cancel_text')) options.cancelText = column_heading.readAttribute('data-ie_cancel_text'); - if (column_heading.readAttribute('data-ie_loading_text')) options.loadingText = column_heading.readAttribute('data-ie_loading_text'); - if (column_heading.readAttribute('data-ie_saving_text')) options.savingText = column_heading.readAttribute('data-ie_saving_text'); - if (column_heading.readAttribute('data-ie_save_text')) options.okText = column_heading.readAttribute('data-ie_save_text'); - if (column_heading.readAttribute('data-ie_rows')) options.rows = column_heading.readAttribute('data-ie_rows'); - if (column_heading.readAttribute('data-ie_cols')) options.cols = column_heading.readAttribute('data-ie_cols'); - if (column_heading.readAttribute('data-ie_size')) options.size = column_heading.readAttribute('data-ie_size'); + if (column_heading.readAttribute('data-ie-cancel-text')) options.cancelText = column_heading.readAttribute('data-ie-cancel-text'); + if (column_heading.readAttribute('data-ie-loading-text')) options.loadingText = column_heading.readAttribute('data-ie-loading-text'); + if (column_heading.readAttribute('data-ie-saving-text')) options.savingText = column_heading.readAttribute('data-ie-saving-text'); + if (column_heading.readAttribute('data-ie-save-text')) options.okText = column_heading.readAttribute('data-ie-save-text'); + if (column_heading.readAttribute('data-ie-rows')) options.rows = column-heading.readAttribute('data-ie-rows'); + if (column_heading.readAttribute('data-ie-cols')) options.cols = column-heading.readAttribute('data-ie-cols'); + if (column_heading.readAttribute('data-ie-size')) options.size = column-heading.readAttribute('data-ie-size'); }, create_inplace_editor: function(span, options) { @@ -610,18 +610,20 @@ var ActiveScaffold = { // element is tbody id mark_records: function(element, options) { var element = $(element); - var mark_checkboxes = $$('#' + element.readAttribute('id') + ' > tr.record td.marked-column input[type="checkbox"]'); - mark_checkboxes.each(function(item) { - if(options.checked === true) { - item.writeAttribute({ checked: 'checked' }); - } else { - item.removeAttribute('checked'); - } - item.writeAttribute('value', ('' + !options.checked)); - }); - if(options.include_mark_all === true) { + if (options.include_checkboxes) { + var mark_checkboxes = $$('#' + element.readAttribute('id') + ' > tr.record td.marked-column input[type="checkbox"]'); + mark_checkboxes.each(function(item) { + if(options.checked) { + item.writeAttribute({ checked: 'checked' }); + } else { + item.removeAttribute('checked'); + } + item.writeAttribute('value', ('' + !options.checked)); + }); + } + if(options.include_mark_all) { var mark_all_checkbox = element.previous('thead').down('th.marked-column_heading span input[type="checkbox"]'); - if(options.checked === true) { + if(options.checked) { mark_all_checkbox.writeAttribute({ checked: 'checked' }); } else { mark_all_checkbox.removeAttribute('checked'); diff --git a/config/locales/de.yml b/config/locales/de.yml index 4c305b55a1..e162737c9b 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -34,6 +34,7 @@ de: inplace_edit_handle: '--' live_search: 'Live-Suche' loading: 'Lade…' + mark_all_records: "Mark all" next: 'Vor' no_entries: 'Keine Einträge' no_options: 'Keine Optionen' @@ -42,6 +43,9 @@ de: pdf: 'PDF' previous: 'Zurück' print: 'Drucken' + records_marked: + one: "1 marked %{model}" + other: "%{count} marked %{model}" refresh: 'Neu laden' remove: 'Entfernen' remove_file: 'Entferne oder Ersetze Datei' diff --git a/config/locales/en.yml b/config/locales/en.yml index 25e0e76899..6549401e60 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -34,6 +34,7 @@ en: inplace_edit_handle: '--' live_search: 'Live Search' loading: 'Loading…' + mark_all_records: "Mark all" next: 'Next' no_entries: 'No Entries' no_options: 'no options' @@ -42,6 +43,9 @@ en: pdf: 'PDF' previous: 'Previous' print: 'Print' + records_marked: + one: "1 marked %{model}" + other: "%{count} marked %{model}" refresh: 'Refresh' remove: 'Remove' remove_file: 'Remove or Replace file' diff --git a/config/locales/es.yml b/config/locales/es.yml index bc65606236..d722044744 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -34,6 +34,7 @@ es: inplace_edit_handle: '--' live_search: 'Buscar en Vivo' loading: 'Cargando…' + mark_all_records: "Seleccionar todos" nested_for_model: '%{nested_model} de %{parent_model}' nested_of_model: '%{nested_model} de %{parent_model}' next: 'Siguiente' @@ -44,6 +45,9 @@ es: pdf: 'PDF' previous: 'Anterior' print: 'Imprimir' + records_marked: + one: "1 %{model} seleccionado" + other: "%{count} %{model} seleccionados" refresh: 'Recargar' remove: 'Eliminar' remove_file: 'Eliminar o Reemplazar archivo' diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 5e647ca09a..912d5e6ee0 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -34,6 +34,7 @@ fr: inplace_edit_handle: '--' live_search: 'Recherche en temps réel' loading: 'Chargement…' + mark_all_records: "Mark all" next: 'Suivant' no_entries: "Pas d'entrée" no_options: "pas d'option" @@ -42,6 +43,9 @@ fr: pdf: 'PDF' previous: 'Précédent' print: 'Imprimer' + records_marked: + one: "1 marked %{model}" + other: "%{count} marked %{model}" refresh: 'Rafraîchir' remove: 'Supprimer' remove_file: 'Supprimer et remplacer le fichier' diff --git a/config/locales/hu.yml b/config/locales/hu.yml index c171107c60..181c922554 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -34,6 +34,7 @@ hu: inplace_edit_handle: '--' live_search: 'Élő keresés' loading: 'Betöltés…' + mark_all_records: "Mark all" next: 'Következő' no_entries: 'Nincs elem' no_options: 'nincsenek opciók' @@ -42,6 +43,9 @@ hu: pdf: 'PDF' previous: 'Előző' print: 'Nyomtatás' + records_marked: + one: "1 marked %{model}" + other: "%{count} marked %{model}" refresh: 'Frissítés' remove: 'Törlés' remove_file: 'Fájl törlése, vagy cseréje' diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 3c3f95f08a..2162e1f659 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -34,6 +34,7 @@ ja: inplace_edit_handle: '--' live_search: 'その場で検索' loading: '読み込み中…' + mark_all_records: "Mark all" next: '次' no_entries: '見つかりませんでした' no_options: 'オプション無し' @@ -42,6 +43,9 @@ ja: pdf: 'PDF' previous: '前' print: '印刷' + records_marked: + one: "1 marked %{model}" + other: "%{count} marked %{model}" refresh: 'Refresh' # needed? remove: '削除' remove_file: 'ファイルを削除または置換' diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 9db15d0b99..2e629d0bc6 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -38,6 +38,7 @@ ru: inplace_edit_handle: '--' live_search: 'Поиск' loading: 'Загрузка…' + mark_all_records: "Mark all" next: 'Следующее' no_entries: 'Нет записей' no_options: 'Нет вариантов' @@ -46,6 +47,9 @@ ru: pdf: 'PDF' previous: 'Предыдущее' print: 'Печать' + records_marked: + one: "1 marked %{model}" + other: "%{count} marked %{model}" refresh: 'Обновить' remove: 'Удалить' remove_file: 'Удалить или заменить файл' diff --git a/frontends/default/views/on_mark.js.erb b/frontends/default/views/on_mark.js.erb new file mode 100644 index 0000000000..f18d5b79b4 --- /dev/null +++ b/frontends/default/views/on_mark.js.erb @@ -0,0 +1,6 @@ +<% + checked = all_marked? unless local_assigns.has_key? :checked + options = {:checked => checked, :include_mark_all => true, :include_checkboxes => params[:id].nil?} +%> +ActiveScaffold.mark_records('<%= active_scaffold_tbody_id %>',<%= options.to_json.html_safe %>); +<%= render :partial => 'update_messages' %> diff --git a/frontends/default/views/on_mark_all.js.erb b/frontends/default/views/on_mark_all.js.erb deleted file mode 100644 index f4e05b69eb..0000000000 --- a/frontends/default/views/on_mark_all.js.erb +++ /dev/null @@ -1,12 +0,0 @@ -<%options = {:checked => mark_all, - :include_mark_all => true}%> -ActiveScaffold.mark_records('<%=active_scaffold_tbody_id%>',<%=options.to_json.html_safe%>); -<%if active_scaffold_config.model.marked.length>0 then %> - <%if active_scaffold_config.model.marked.length < @page.pager.count then%> - ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>','<%="#{active_scaffold_config.model.marked.length.to_s} records marked. Press <a href=\"#{url_for(:action=>"mark_all",:mark_target=>"scope")}\">here</a> to select all #{@page.pager.count} records.".html_safe%>'); - <%else%> - ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>','<%="All #{@page.pager.count} records marked".html_safe%>'); - <%end%> -<%else%> - ActiveScaffold.replace_html('<%=active_scaffold_messages_id%>',''); -<%end%> diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 2e79e8a8e8..a7ccc6e89f 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -49,7 +49,7 @@ def do_destroy @record ||= destroy_find_record begin self.successful = @record.destroy - marked_records.delete @record.id.to_s if successful? + @record.as_marked = false if successful? rescue Exception => ex flash[:warning] = as_(:cant_destroy_record, :record => @record.to_label) self.successful = false diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index 7d73fa4d5f..86acecbee4 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -3,58 +3,69 @@ module Mark def self.included(base) base.before_filter :mark_authorized?, :only => :mark - #base.prepend_before_filter :assign_marked_records_to_model + base.prepend_before_filter :assign_marked_records_to_model base.helper_method :marked_records end - def mark_all - if mark_all? || mark_all_scope_forced? - do_mark_all + def mark + if mark? || mark_all_scope_forced? + do_mark else - do_unmark + do_demark end - do_list - respond_to_action(:mark_all) + if marked_records.length > 0 + link = "<a href=\"#{url_for(:action=>:mark, :id=>'', :mark_target => :scope)}\" data-method=\"post\" data-remote=\"true\">#{as_ :mark_all_records}</a>" + count = marked_records.length + flash[:info] = as_(:records_marked, :count => count, :model => active_scaffold_config.label(:count => count), :link => link) + end + respond_to_action(:mark) end protected - def mark_all_respond_to_html + def mark_respond_to_html + do_list list_respond_to_html end - def mark_all_respond_to_js - render :action => 'on_mark_all', :locals => {:mark_all => mark_all?} + def mark_respond_to_js + if params[:id] + do_search if respond_to? :do_search + set_includes_for_list_columns + @page = find_page(:pagination => active_scaffold_config.mark.mark_all_mode != :page) + render :action => 'on_mark' + else + render :action => 'on_mark', :locals => {:checked => mark?} + end end # We need to give the ActiveRecord classes a handle to currently marked records. We don't want to just pass the object, - # because the object may change. So we give ActiveRecord a proc that ties to the - # marked_records_method on this ApplicationController. + # because the object may change. So we give ActiveRecord a proc that ties to the marked_records_method on this ApplicationController. def assign_marked_records_to_model active_scaffold_config.model.marked_records = marked_records end def mark? - params[:value] == 'true' - end - - def mark_all? - @mark_all ||= [true, 'true', 1, '1', 'T', 't'].include?(params[:value].class == String ? params[:value].downcase : params[:value]) + @mark ||= [true, 'true', 1, '1', 'T', 't'].include?(params[:value].class == String ? params[:value].downcase : params[:value]) end def mark_all_scope_forced? - !params[:mark_target].nil? && params[:mark_target]=='scope' + params[:mark_target] == 'scope' unless params[:id] end - - def do_mark_all - if active_scaffold_config.mark.mark_all_mode == :page && !mark_all_scope_forced? then + + def do_mark + if params[:id] + find_if_allowed(params[:id], :read).as_marked = true + elsif active_scaffold_config.mark.mark_all_mode == :page && !mark_all_scope_forced? each_record_in_page {|record| marked_records << record.id} else each_record_in_scope {|record| marked_records << record.id} end end - def do_demark_all - if active_scaffold_config.mark.mark_all_mode == :page then + def do_demark + if params[:id] + find_if_allowed(params[:id], :read).as_marked = false + elsif active_scaffold_config.mark.mark_all_mode == :page each_record_in_page {|record| marked_records.delete(record.id)} else each_record_in_scope {|record| marked_records.delete(record.id)} @@ -67,7 +78,7 @@ def mark_authorized? authorized_for?(:crud_type => :read) end - def mark_all_formats + def mark_formats (default_formats + active_scaffold_config.formats).uniq end end diff --git a/lib/active_scaffold/config/form.rb b/lib/active_scaffold/config/form.rb index c88f875004..1364b3bbe2 100644 --- a/lib/active_scaffold/config/form.rb +++ b/lib/active_scaffold/config/form.rb @@ -47,7 +47,7 @@ def initialize(core_config) def columns unless @columns # lazy evaluation self.columns = @core.columns._inheritable - self.columns.exclude :created_on, :created_at, :updated_on, :updated_at, :marked + self.columns.exclude :created_on, :created_at, :updated_on, :updated_at, :as_marked self.columns.exclude *@core.columns.collect{|c| c.name if c.polymorphic_association?}.compact end @columns diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index aa63938550..9894cd2875 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -20,7 +20,6 @@ def initialize(core_config) @pagination = self.class.pagination @show_search_reset = self.class.show_search_reset @reset_link = self.class.reset_link.clone - @mark_records = self.class.mark_records @wrap_tag = self.class.wrap_tag @always_show_search = self.class.always_show_search @always_show_create = self.class.always_show_create @@ -62,10 +61,6 @@ def page_links_window=(value) cattr_accessor :pagination @@pagination = true - # Add a checkbox in front of each record to mark them and use them with a batch action later - cattr_accessor :mark_records - @@mark_records = false - # show a link to reset the search next to filtered message cattr_accessor :show_search_reset @@show_search_reset = true @@ -130,9 +125,6 @@ def page_links_window=(value) # the ActionLink to reset search attr_reader :reset_link - # Add a checkbox in front of each record to mark them and use them with a batch action later - attr_accessor :mark_records - # the default sorting. should be an array of hashes of {column_name => direction}, e.g. [{:a => 'desc'}, {:b => 'asc'}]. to just sort on one column, you can simply provide a hash, though, e.g. {:a => 'desc'}. def sorting=(val) val = [val] if val.is_a? Hash diff --git a/lib/active_scaffold/config/mark.rb b/lib/active_scaffold/config/mark.rb index a32168ac06..07ac3720e8 100644 --- a/lib/active_scaffold/config/mark.rb +++ b/lib/active_scaffold/config/mark.rb @@ -20,12 +20,11 @@ def initialize(core_config) protected def add_mark_column - @core.columns.add :marked - @core.columns[:marked].label = 'M' - @core.columns[:marked].form_ui = :checkbox - @core.columns[:marked].inplace_edit = true - @core.columns[:marked].sort = false - @core.list.columns = [:marked] + @core.list.columns.names_without_auth_check unless @core.list.columns.include? :marked + @core.columns.add :as_marked + @core.columns[:as_marked].label = 'M' + @core.columns[:as_marked].list_ui = :marked + @core.columns[:as_marked].sort = false + @core.list.columns = [:as_marked] + @core.list.columns.names_without_auth_check unless @core.list.columns.include? :as_marked end end end diff --git a/lib/active_scaffold/extensions/routing_mapper.rb b/lib/active_scaffold/extensions/routing_mapper.rb index d3877ab1b9..83020d29c7 100644 --- a/lib/active_scaffold/extensions/routing_mapper.rb +++ b/lib/active_scaffold/extensions/routing_mapper.rb @@ -1,8 +1,8 @@ module ActionDispatch module Routing ACTIVE_SCAFFOLD_CORE_ROUTING = { - :collection => {:show_search => :get, :render_field => :get}, - :member => {:row => :get, :update_column => :post, :render_field => :get} + :collection => {:show_search => :get, :render_field => :get, :mark => :post}, + :member => {:row => :get, :update_column => :post, :render_field => :get, :mark => :post} } ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = { :collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post}, diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 9cabb7ef6f..0cc8210c20 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -281,13 +281,19 @@ def finder_options(options = {}) finder_options end - # Returns a hash with options to count records, rejecting select and order options - # See finder_options for valid options - def count_options(find_options = {}, count_includes = nil) + def count_items(find_options = {}, count_includes = nil) count_includes ||= find_options[:includes] unless find_options[:conditions].nil? options = find_options.reject{|k,v| [:select, :reorder].include? k} options[:includes] = count_includes - options + + # NOTE: we must use :include in the count query, because some conditions may reference other tables + count_query = append_to_query(beginning_of_chain, options) + count = count_query.count + + # Converts count to an integer if ActiveRecord returned an OrderedHash + # that happens when find_options contains a :group key + count = count.length if count.is_a? ActiveSupport::OrderedHash + count end # returns a Paginator::Page (not from ActiveRecord::Paginator) for the given parameters @@ -298,18 +304,13 @@ def find_page(options = {}) options[:page] ||= 1 find_options = finder_options(options) - klass = beginning_of_chain # NOTE: we must use :include in the count query, because some conditions may reference other tables if options[:pagination] && options[:pagination] != :infinite - count_query = append_to_query(klass, count_options(find_options, options[:count_includes])) - count = count_query.count unless options[:pagination] == :infinite + count = count_items(find_options, options[:count_includes]) end - - # Converts count to an integer if ActiveRecord returned an OrderedHash - # that happens when find_options contains a :group key - count = count.length if count.is_a? ActiveSupport::OrderedHash + klass = beginning_of_chain # we build the paginator differently for method- and sql-based sorting if options[:sorting] and options[:sorting].sorts_by_method? pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index b1df8bd64d..d00468d27b 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -126,6 +126,11 @@ def active_scaffold_column_text(column, record) clean_column_value(truncate(record.send(column.name), :length => column.options[:truncate] || 50)) end + def active_scaffold_column_marked(column, record) + options = {:id => nil, :object => record} + content_tag(:span, check_box(:record, column.name, options), :class => 'in_place_editor_field', :data => {:ie_id => record.id.to_s}) + end + def active_scaffold_column_checkbox(column, record) options = {:disabled => true, :id => nil, :object => record} options.delete(:disabled) if inplace_edit?(record, column) @@ -257,7 +262,7 @@ def active_scaffold_inplace_edit(record, column, options = {}) formatted_column = options[:formatted_column] || format_column_value(record, column) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field", - :title => as_(:click_to_edit), 'data-ie_id' => record.id.to_s} + :title => as_(:click_to_edit), :data => {:ie_id => record.id.to_s}} content_tag(:span, as_(:inplace_edit_handle), :class => 'handle') << content_tag(:span, formatted_column, tag_options) @@ -279,54 +284,65 @@ def inplace_edit_control_css_class "as_inplace_pattern" end - def inplace_edit_tag_attributes(column) - tag_options = {} - tag_options['data-ie_url'] = url_for({:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => '__id__'}) - tag_options['data-ie_cancel_text'] = column.options[:cancel_text] || as_(:cancel) - tag_options['data-ie_loading_text'] = column.options[:loading_text] || as_(:loading) - tag_options['data-ie_save_text'] = column.options[:save_text] || as_(:update) - tag_options['data-ie_saving_text'] = column.options[:saving_text] || as_(:saving) - tag_options['data-ie_rows'] = column.options[:rows] || 5 if column.column.try(:type) == :text - tag_options['data-ie_cols'] = column.options[:cols] if column.options[:cols] - tag_options['data-ie_size'] = column.options[:size] if column.options[:size] + def inplace_edit_data(column) + data = {} + data[:ie_url] = url_for({:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => '__id__'}) + data[:ie_cancel_text] = column.options[:cancel_text] || as_(:cancel) + data[:ie_loading_text] = column.options[:loading_text] || as_(:loading) + data[:ie_save_text] = column.options[:save_text] || as_(:update) + data[:ie_saving_text] = column.options[:saving_text] || as_(:saving) + data[:ie_rows] = column.options[:rows] || 5 if column.column.try(:type) == :text + data[:ie_cols] = column.options[:cols] if column.options[:cols] + data[:ie_size] = column.options[:size] if column.options[:size] if column.list_ui == :checkbox - tag_options['data-ie_mode'] = :inline_checkbox + data[:ie_mode] = :inline_checkbox elsif inplace_edit_cloning?(column) - tag_options['data-ie_mode'] = :clone + data[:ie_mode] = :clone elsif column.inplace_edit == :ajax url = url_for(:controller => params_for[:controller], :action => 'render_field', :id => '__id__', :column => column.name, :update_column => column.name, :in_place_editing => true) plural = column.plural_association? && !override_form_field?(column) && [:select, :record_select].include?(column.form_ui) - tag_options['data-ie_render_url'] = url - tag_options['data-ie_mode'] = :ajax - tag_options['data-ie_plural'] = plural + data[:ie_render_url] = url + data[:ie_mode] = :ajax + data[:ie_plural] = plural end - tag_options + data end - def mark_column_heading - if active_scaffold_config.mark.mark_all_mode == :page then - all_marked = true - @page.items.each do |record| - all_marked = false if !marked_records.entries.include?(record.id) - end + def all_marked? + if active_scaffold_config.mark.mark_all_mode == :page + all_marked = @page.items.detect { |record| !marked_records.include?(record.id) }.nil? else all_marked = (marked_records.length >= @page.pager.count) end - tag_options = {:id => "#{controller_id}_mark_heading", :class => "mark_heading in_place_editor_field"} - tag_options['data-ie_url'] = url_for({:controller => params_for[:controller], :action => 'mark_all', :eid => params[:eid]}) - content_tag(:span, check_box_tag("#{controller_id}_mark_heading_span_input", !all_marked, all_marked), tag_options) + end + + def mark_column_heading + tag_options = { + :id => "#{controller_id}_mark_heading", + :class => "mark_heading in_place_editor_field", + } + content_tag(:span, check_box_tag("#{controller_id}_mark_heading_span_input", '1', all_marked?), tag_options) end def render_column_heading(column, sorting, sort_direction) tag_options = {:id => active_scaffold_column_header_id(column), :class => column_heading_class(column, sorting), :title => column.description} - tag_options.merge!(inplace_edit_tag_attributes(column)) if column.inplace_edit + if column.name == :as_marked + tag_options[:data] = { + :ie_mode => :inline_checkbox, + :ie_url => url_for(:controller => params_for[:controller], :action => 'mark', :id => '__id__', :eid => params[:eid]) + } + else + tag_options[:data] = inplace_edit_data(column) if column.inplace_edit + end content_tag(:th, column_heading_value(column, sorting, sort_direction) + inplace_edit_control(column), tag_options) end def column_heading_value(column, sorting, sort_direction) - if column.sortable? + if column.name == :as_marked + mark_column_heading + elsif column.sortable? options = {:id => nil, :class => "as_sort", 'data-page-history' => controller_id, :remote => true, :method => :get} @@ -334,11 +350,7 @@ def column_heading_value(column, sorting, sort_direction) :sort => column.name, :sort_direction => sort_direction) link_to column.label, url_options, options else - if column.name != :marked - content_tag(:p, column.label) - else - mark_column_heading - end + content_tag(:p, column.label) end end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 7dd5336ea0..2894d712e3 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -240,7 +240,7 @@ def column_class(column, column_value, record) classes << 'empty' if column_empty? column_value classes << 'sorted' if active_scaffold_config.list.user.sorting.sorts_on?(column) classes << 'numeric' if column.column and [:decimal, :float, :integer].include?(column.column.type) - classes << 'in_place_editor_field' if inplace_edit?(record, column) + classes << 'in_place_editor_field' if inplace_edit?(record, column) or column.list_ui == :marked classes.join(' ').rstrip end diff --git a/lib/active_scaffold/marked_model.rb b/lib/active_scaffold/marked_model.rb index bccad358c8..b2ec62ed4d 100644 --- a/lib/active_scaffold/marked_model.rb +++ b/lib/active_scaffold/marked_model.rb @@ -4,17 +4,17 @@ module MarkedModel def self.included(base) base.extend ClassMethods - base.scope :marked, lambda {{:conditions => {:id => base.marked_records.to_a}}} + base.scope :as_marked, lambda { where(:id => base.marked_records.to_a) } end - def marked + def as_marked marked_records.include?(self.id) end - def marked=(value) + def as_marked=(value) value = [true, 'true', 1, '1', 'T', 't'].include?(value.class == String ? value.downcase : value) if value == true - marked_records << self.id if !marked + marked_records << self.id if !as_marked else marked_records.delete(self.id) end diff --git a/test/config/list_test.rb b/test/config/list_test.rb index 057e5e06d2..f61d0f95ee 100644 --- a/test/config/list_test.rb +++ b/test/config/list_test.rb @@ -25,7 +25,6 @@ def test_default_options assert_equal :filtered, @config.list.filtered_message assert !@config.list.always_show_create assert !@config.list.always_show_search - assert !@config.list.mark_records assert @config.list.count_includes.nil? assert_equal 'ModelStubs', @config.list.label assert @config.list.sorting.sorts_on?(:id) @@ -73,11 +72,6 @@ def test_sorting assert !@config.list.sorting.sorts_on?(:id) end - def test_mark_records - @config.list.mark_records = true - assert @config.list.mark_records - end - def test_per_page per_page = 35 @config.list.per_page = per_page From 7d886e04e3b6cba3b8e33c029315adabfa50a3a4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 13 Jun 2012 17:33:40 +0200 Subject: [PATCH 1547/2024] cleanup mark all code, more DRY --- lib/active_scaffold/actions/mark.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index 86acecbee4..eac56aa618 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -56,9 +56,9 @@ def do_mark if params[:id] find_if_allowed(params[:id], :read).as_marked = true elsif active_scaffold_config.mark.mark_all_mode == :page && !mark_all_scope_forced? - each_record_in_page {|record| marked_records << record.id} + each_record_in_page { |record| record.as_marked = true } else - each_record_in_scope {|record| marked_records << record.id} + each_record_in_scope { |record| record.as_marked = true } end end @@ -66,9 +66,9 @@ def do_demark if params[:id] find_if_allowed(params[:id], :read).as_marked = false elsif active_scaffold_config.mark.mark_all_mode == :page - each_record_in_page {|record| marked_records.delete(record.id)} + each_record_in_page { |record| record.as_marked = false } else - each_record_in_scope {|record| marked_records.delete(record.id)} + each_record_in_scope { |record| record.as_marked = false } end end From d2c173f8558f4e00a81003ce8688b9a66fcfd1b2 Mon Sep 17 00:00:00 2001 From: Novikov Andrey <envek@envek.name> Date: Thu, 14 Jun 2012 23:53:56 +1000 Subject: [PATCH 1548/2024] Fixed russian localization for API:Mark --- config/locales/ru.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 2e629d0bc6..11e3fe8e38 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -38,7 +38,7 @@ ru: inplace_edit_handle: '--' live_search: 'Поиск' loading: 'Загрузка…' - mark_all_records: "Mark all" + mark_all_records: "Отметить все" next: 'Следующее' no_entries: 'Нет записей' no_options: 'Нет вариантов' @@ -48,8 +48,10 @@ ru: previous: 'Предыдущее' print: 'Печать' records_marked: - one: "1 marked %{model}" - other: "%{count} marked %{model}" + one: "Отмечена 1 запись" + few: "Отмечено %{count} записи" + many: "Отмечено %{count} записей" + other: "Отмечено %{count} записи" refresh: 'Обновить' remove: 'Удалить' remove_file: 'Удалить или заменить файл' From 0c01d763cfce3f910368491e672e2a7f493d916e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 19 Jun 2012 12:44:11 +0200 Subject: [PATCH 1549/2024] add each_marked_record method --- lib/active_scaffold/actions/core.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 16c0e904cf..1ecb29887f 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -75,6 +75,10 @@ def clear_flashes end end + def each_marked_record(&block) + active_scaffold_config.model.find(marked_records.to_a).each &block + end + def marked_records active_scaffold_session_storage[:marked_records] ||= Set.new end From 311930f906f91221f7455e22c114c958809615cf Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 21 Jun 2012 17:28:44 +0200 Subject: [PATCH 1550/2024] Fix do_destroy, fixes #168 --- CHANGELOG | 5 ++++- lib/active_scaffold/actions/delete.rb | 1 - lib/active_scaffold/actions/mark.rb | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a6713d31cd..f86b1d1003 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,7 @@ -= 3.2.12 (not released yet) += 3.2.13 (not released yet) +- Fix destroy action, was broken in 3.2.12 + += 3.2.12 - improve support for tableless models, add support for count - fix div id for nested scaffolds - add config.timestamped_messages and config.highlight_messages diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index a7ccc6e89f..481de3f1ee 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -49,7 +49,6 @@ def do_destroy @record ||= destroy_find_record begin self.successful = @record.destroy - @record.as_marked = false if successful? rescue Exception => ex flash[:warning] = as_(:cant_destroy_record, :record => @record.to_label) self.successful = false diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index eac56aa618..eb6cb0d0d9 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -72,6 +72,11 @@ def do_demark end end + def do_destroy + super + @record.as_marked = false if successful? + end + # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def mark_authorized? From 8987ac4c828477370021cdcef7fd3613337dfaa4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 21 Jun 2012 17:30:31 +0200 Subject: [PATCH 1551/2024] remove default sorting for associations --- CHANGELOG | 1 + frontends/default/views/_form_hidden_attribute.html.erb | 7 ++++++- frontends/default/views/_render_field.js.erb | 2 +- lib/active_scaffold/data_structures/column.rb | 6 +----- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f86b1d1003..548843ede4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ = 3.2.13 (not released yet) - Fix destroy action, was broken in 3.2.12 +- Remove default :method sorting for associations, it wasn't useful and can be slow = 3.2.12 - improve support for tableless models, add support for count diff --git a/frontends/default/views/_form_hidden_attribute.html.erb b/frontends/default/views/_form_hidden_attribute.html.erb index e7afb2964e..3be3b66433 100644 --- a/frontends/default/views/_form_hidden_attribute.html.erb +++ b/frontends/default/views/_form_hidden_attribute.html.erb @@ -1,2 +1,7 @@ <% scope ||= nil %> -<%= hidden_field :record, column.name, active_scaffold_input_options(column, scope) %> +<dl style="display: none;"> +<dt></dt> +<dd> + <%= hidden_field :record, column.name, active_scaffold_input_options(column, scope) %> +</dd> +</dl> diff --git a/frontends/default/views/_render_field.js.erb b/frontends/default/views/_render_field.js.erb index 0225bf7868..df4d697a74 100644 --- a/frontends/default/views/_render_field.js.erb +++ b/frontends/default/views/_render_field.js.erb @@ -2,7 +2,7 @@ column = if render_field.is_a? ActiveScaffold::DataStructures::Column render_field else - active_scaffold_config.columns[render_field.to_sym] unless render_field.is_a? ActiveScaffold::DataStructures::Column + active_scaffold_config.columns[render_field.to_sym] end @rendered ||= Set.new return if @rendered.include? column.name diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 97354ea836..5a0bd829ae 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -352,11 +352,7 @@ def initialize_sort # we don't automatically enable method sorting for virtual columns because it's slow, and we expect fewer complaints this way. self.sort = false else - if self.singular_association? - self.sort = {:method => "#{self.name}.to_s"} - elsif self.plural_association? - self.sort = {:method => "#{self.name}.join(',')"} - elsif @active_record_class.connection + if column && @active_record_class.connection self.sort = {:sql => self.field} else self.sort = false From 193d033d122276dff410d289246655a5b99b5dd6 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 26 Jun 2012 09:38:08 +0200 Subject: [PATCH 1552/2024] use rails 3 way to rescue from exceptions --- CHANGELOG | 1 + lib/active_scaffold/actions/core.rb | 12 +----------- .../extensions/action_controller_rendering.rb | 2 -- .../extensions/action_controller_rescueing.rb | 7 +++++++ 4 files changed, 9 insertions(+), 13 deletions(-) create mode 100644 lib/active_scaffold/extensions/action_controller_rescueing.rb diff --git a/CHANGELOG b/CHANGELOG index 548843ede4..3588885aad 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ = 3.2.13 (not released yet) - Fix destroy action, was broken in 3.2.12 - Remove default :method sorting for associations, it wasn't useful and can be slow +- Rescue from ActiveScaffold::ActionNotAllowed and ActiveScaffold::RecordNotAllowed with 401 response, it can be overrided with deny_access method in ApplicationController. = 3.2.12 - improve support for tableless models, add support for count diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 1ecb29887f..91405606da 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -4,6 +4,7 @@ def self.included(base) base.class_eval do before_filter :register_constraints_with_action_columns, :if => :embedded? after_filter :clear_flashes + rescue_from ActiveScaffold::RecordNotAllowed, ActiveScaffold::ActionNotAllowed, :with => :deny_access end base.helper_method :nested? base.helper_method :calculate @@ -197,16 +198,5 @@ def action_formats (default_formats + active_scaffold_config.formats).uniq end end - - def response_code_for_rescue(exception) - case exception - when ActiveScaffold::RecordNotAllowed - "403 Record Not Allowed" - when ActiveScaffold::ActionNotAllowed - "403 Action Not Allowed" - else - super - end - end end end diff --git a/lib/active_scaffold/extensions/action_controller_rendering.rb b/lib/active_scaffold/extensions/action_controller_rendering.rb index 60e16994c2..da5e5e7e42 100644 --- a/lib/active_scaffold/extensions/action_controller_rendering.rb +++ b/lib/active_scaffold/extensions/action_controller_rendering.rb @@ -15,8 +15,6 @@ def render_with_active_scaffold(*args, &block) end end alias_method_chain :render, :active_scaffold - - # Rails 2.x implementation is post-initialization on :active_scaffold method end end diff --git a/lib/active_scaffold/extensions/action_controller_rescueing.rb b/lib/active_scaffold/extensions/action_controller_rescueing.rb new file mode 100644 index 0000000000..56d46c8dbb --- /dev/null +++ b/lib/active_scaffold/extensions/action_controller_rescueing.rb @@ -0,0 +1,7 @@ +module ActionController #:nodoc: + class Base + def deny_access + head :unauthorized + end + end +end From bda6b7135c784359e82484788c80aee4595c49b5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 26 Jun 2012 12:33:53 +0200 Subject: [PATCH 1553/2024] fix null translation --- config/locales/de.yml | 2 +- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- config/locales/fr.yml | 2 +- config/locales/hu.yml | 2 +- config/locales/ja.yml | 2 +- config/locales/ru.yml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/config/locales/de.yml b/config/locales/de.yml index e162737c9b..fae85ec7b1 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -96,7 +96,7 @@ de: months: 'Monate' years: 'Jahre' optional_attributes: 'Weitere' - null: 'Null' + :null: 'Null' not_null: 'Nicht Null' date_picker_options: weekHeader: 'Wo' diff --git a/config/locales/en.yml b/config/locales/en.yml index 6549401e60..f951ec7594 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -96,7 +96,7 @@ en: months: 'Months' years: 'Years' optional_attributes: 'Further Options' - null: 'Null' + :null: 'Null' not_null: 'Not Null' date_picker_options: weekHeader: 'Wk' diff --git a/config/locales/es.yml b/config/locales/es.yml index d722044744..b7e52fa78f 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -98,7 +98,7 @@ es: months: 'Meses' years: 'Años' optional_attributes: 'Más opciones' - null: 'Nulo' + :null: 'Nulo' not_null: 'No Nulo' date_picker_options: weekHeader: 'Sm' diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 912d5e6ee0..14fe00f3a4 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -96,7 +96,7 @@ fr: months: 'Mois' years: 'Années' optional_attributes: 'Options additionnelles' - null: 'Nulle' + :null: 'Nulle' not_null: 'Non Nulle' date_picker_options: weekHeader: 'Sm' diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 181c922554..46fe78acaa 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -96,7 +96,7 @@ hu: months: 'Months' years: 'Years' optional_attributes: 'Further Options' - null: 'Null' + :null: 'Null' not_null: 'Not Null' date_picker_options: weekHeader: 'Wk' diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 2162e1f659..a36e695ea2 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -96,7 +96,7 @@ ja: months: 'Months' years: 'Years' optional_attributes: 'Further Options' - null: 'Null' + :null: 'Null' not_null: 'Not Null' date_picker_options: weekHeader: 'Wk' diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 11e3fe8e38..88ed002eab 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -102,7 +102,7 @@ ru: months: 'месяцев' years: 'лет' optional_attributes: 'Дополнительные настройки' - null: 'Пусто' + :null: 'Пусто' not_null: 'Не пусто' date_picker_options: weekHeader: 'Нед.' From bd87e7fc518926804b7956a121b149779109dc71 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 26 Jun 2012 13:00:31 +0200 Subject: [PATCH 1554/2024] allow to set array in search_sql so one column can search in multiple db columns, resulting sql chunks will be OR'ed --- CHANGELOG | 1 + lib/active_scaffold/bridges/date_picker.rb | 2 +- .../bridges/date_picker/ext.rb | 7 ++ .../bridges/date_picker/helper.rb | 2 +- .../bridges/shared/date_bridge.rb | 6 +- lib/active_scaffold/data_structures/column.rb | 5 +- lib/active_scaffold/finder.rb | 98 +++++++++++-------- 7 files changed, 75 insertions(+), 46 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3588885aad..287fdd7309 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ - Fix destroy action, was broken in 3.2.12 - Remove default :method sorting for associations, it wasn't useful and can be slow - Rescue from ActiveScaffold::ActionNotAllowed and ActiveScaffold::RecordNotAllowed with 401 response, it can be overrided with deny_access method in ApplicationController. +- Allow to set arrays in search_sql so one column can search in multiple db columns, resulting sql chunks will be OR'ed = 3.2.12 - improve support for tableless models, add support for count diff --git a/lib/active_scaffold/bridges/date_picker.rb b/lib/active_scaffold/bridges/date_picker.rb index 54a871c11e..f0ae0fa961 100644 --- a/lib/active_scaffold/bridges/date_picker.rb +++ b/lib/active_scaffold/bridges/date_picker.rb @@ -8,7 +8,7 @@ def self.install? ActiveScaffold.js_framework == :jquery end def self.localization - "jQuery(function($){ + "jQuery(function($){ if (typeof($.datepicker) === 'object') { #{Helper.date_options_for_locales} $.datepicker.setDefaults($.datepicker.regional['#{::I18n.locale}']); diff --git a/lib/active_scaffold/bridges/date_picker/ext.rb b/lib/active_scaffold/bridges/date_picker/ext.rb index 74e698cf18..0d8388d0c2 100644 --- a/lib/active_scaffold/bridges/date_picker/ext.rb +++ b/lib/active_scaffold/bridges/date_picker/ext.rb @@ -49,6 +49,13 @@ def fallback_string_to_date_with_date_picker(string) end ActiveScaffold::Finder::ClassMethods.module_eval do include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods + def datetime_conversion_for_condition(column) + if column.search_ui == :date_picker + :to_date + else + super + end + end alias_method :condition_for_date_picker_type, :condition_for_date_bridge_type alias_method :condition_for_datetime_picker_type, :condition_for_date_picker_type end diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index 1fcf97b41d..0d6f26272f 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -158,7 +158,7 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current options = active_scaffold_input_text_options(options.merge(column.options)) options[:class] << " #{column.search_ui.to_s}" options[:style] = (options[:show].nil? || options[:show]) ? nil : "display: none" - format = options.delete(:format) || column.form_ui == :date_picker ? :default : :picker + format = options.delete(:format) || column.search_ui == :date_picker ? :default : :picker datepicker_format_options(column, format, options) text_field_tag("#{options[:name]}[#{name}]", value ? l(value, :format => format) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) end diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index 90fd33e297..605be69958 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -112,15 +112,15 @@ def condition_for_date_bridge_type(column, value, like_pattern) column.search_sql.call(from_value, to_value, operator) else unless operator.nil? - ["#{column.search_sql} #{value[:opt]} ?", from_value.to_s(:db)] unless from_value.nil? + ["%{search_sql} #{value[:opt]} ?", from_value.to_s(:db)] unless from_value.nil? else - ["#{column.search_sql} BETWEEN ? AND ?", from_value.to_s(:db), to_value.to_s(:db)] unless from_value.nil? && to_value.nil? + ["%{search_sql} BETWEEN ? AND ?", from_value.to_s(:db), to_value.to_s(:db)] unless from_value.nil? && to_value.nil? end end end def date_bridge_from_to(column, value) - conversion = column.column.type == :date ? :to_date : :to_time + conversion = datetime_conversion_for_condition(column) case value[:opt] when 'RANGE' date_bridge_from_to_for_range(column, value).collect(&conversion) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 5a0bd829ae..1892f0d48c 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -179,7 +179,10 @@ def includes=(value) # describes how to search on a column # search = true default, uses intelligent search sql # search = "CONCAT(a, b)" define your own sql for searching. this should be the "left-side" of a WHERE condition. the operator and value will be supplied by ActiveScaffold. - attr_writer :search_sql + # search = [:a, :b] searches in both fields + def search_sql=(value) + @search_sql = (value == true || value.is_a?(Proc)) ? value : Array(value) + end def search_sql self.initialize_search_sql if @search_sql === true @search_sql diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 0cc8210c20..d796cc84da 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -17,13 +17,18 @@ def create_conditions_for_columns(tokens, columns, text_search = :full) where_clauses = [] columns.each do |column| - where_clauses << ((column.column.nil? || column.column.text?) ? "#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?" : "#{column.search_sql} = ?") + Array(column.search_sql).each do |search_sql| + where_clauses << "#{search_sql} #{(column.column.nil? || column.column.text?) ? ActiveScaffold::Finder.like_operator : '='} ?" + end end phrase = where_clauses.join(' OR ') tokens.collect do |value| columns.inject([phrase]) do |condition, column| - condition.push((column.column.nil? || column.column.text?) ? like_pattern.sub('?', value) : column.column.type_cast(value)) + Array(column.search_sql).size.times do + condition.push((column.column.nil? || column.column.text?) ? like_pattern.sub('?', value) : column.column.type_cast(value)) + end + condition end end end @@ -39,32 +44,37 @@ def condition_for_column(column, value, text_search = :full) return unless column and column.search_sql and not value.blank? search_ui = column.search_ui || column.column.try(:type) begin - if search_ui && self.respond_to?("condition_for_#{search_ui}_type") + sql, *values = if search_ui && self.respond_to?("condition_for_#{search_ui}_type") self.send("condition_for_#{search_ui}_type", column, value, like_pattern) else - unless column.search_sql.instance_of? Proc + if column.search_sql.instance_of? Proc + column.search_sql.call(value) + else case search_ui - when :boolean, :checkbox - ["#{column.search_sql} = ?", column.column.type_cast(value)] - when :integer, :decimal, :float - condition_for_numeric(column, value) - when :string, :range - condition_for_range(column, value, like_pattern) - when :date, :time, :datetime, :timestamp - condition_for_datetime(column, value) - when :select, :multi_select, :country, :usa_state - ["#{column.search_sql} in (?)", Array(value)] + when :boolean, :checkbox + ["%{search_sql} = ?", column.column ? column.column.type_cast(value) : value] + when :integer, :decimal, :float + condition_for_numeric(column, value) + when :string, :range + condition_for_range(column, value, like_pattern) + when :date, :time, :datetime, :timestamp + condition_for_datetime(column, value) + when :select, :multi_select, :country, :usa_state + ["%{search_sql} in (?)", [Array(value)]] + else + if column.column.nil? || column.column.text? + ["%{search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] else - if column.column.nil? || column.column.text? - ["#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] - else - ["#{column.search_sql} = ?", column.column.type_cast(value)] - end + ["%{search_sql} = ?", column.column.type_cast(value)] + end end - else - column.search_sql.call(value) end end + return nil unless sql + + conditions = [column.search_sql.collect { |search_sql| sql % {:search_sql => search_sql} }.join ' OR '] + conditions += values*column.search_sql.size if values.present? + conditions rescue Exception => e logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column :#{column.name}, search_ui = #{search_ui} in #{self.name}" raise e @@ -73,33 +83,33 @@ def condition_for_column(column, value, text_search = :full) def condition_for_numeric(column, value) if !value.is_a?(Hash) - ["#{column.search_sql} = ?", condition_value_for_numeric(column, value)] + ["%{search_sql} = ?", condition_value_for_numeric(column, value)] elsif value[:from].blank? or not ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) nil elsif value[:opt] == 'BETWEEN' - ["#{column.search_sql} BETWEEN ? AND ?", condition_value_for_numeric(column, value[:from]), condition_value_for_numeric(column, value[:to])] - else - ["#{column.search_sql} #{value[:opt]} ?", condition_value_for_numeric(column, value[:from])] + ["(%{search_sql} BETWEEN ? AND ?)", condition_value_for_numeric(column, value[:from]), condition_value_for_numeric(column, value[:to])] + else + ["%{search_sql} #{value[:opt]} ?", condition_value_for_numeric(column, value[:from])] end end def condition_for_range(column, value, like_pattern = nil) if !value.is_a?(Hash) if column.column.nil? || column.column.text? - ["#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] + ["%{search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] else - ["#{column.search_sql} = ?", column.column.type_cast(value)] + ["%{search_sql} = ?", column.column.type_cast(value)] end elsif ActiveScaffold::Finder::NullComparators.include?(value[:opt]) condition_for_null_type(column, value[:opt], like_pattern) elsif value[:from].blank? nil elsif ActiveScaffold::Finder::StringComparators.values.include?(value[:opt]) - ["#{column.search_sql} #{ActiveScaffold::Finder.like_operator} ?", value[:opt].sub('?', value[:from])] + ["%{search_sql} #{ActiveScaffold::Finder.like_operator} ?", value[:opt].sub('?', value[:from])] elsif value[:opt] == 'BETWEEN' - ["#{column.search_sql} BETWEEN ? AND ?", value[:from], value[:to]] + ["(%{search_sql} BETWEEN ? AND ?)", value[:from], value[:to]] elsif ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) - ["#{column.search_sql} #{value[:opt]} ?", value[:from]] + ["%{search_sql} #{value[:opt]} ?", value[:from]] else nil end @@ -157,37 +167,45 @@ def i18n_number_to_native_format(value) value end end + + def datetime_conversion_for_condition(column) + if column.column + column.column.type == :date ? :to_date : :to_time + else + :to_time + end + end def condition_for_datetime(column, value, like_pattern = nil) - conversion = column.column.type == :date ? :to_date : :to_time + conversion = datetime_conversion_for_condition(column) from_value = condition_value_for_datetime(value[:from], conversion) to_value = condition_value_for_datetime(value[:to], conversion) if from_value.nil? and to_value.nil? nil elsif !from_value - ["#{column.search_sql} <= ?", to_value.to_s(:db)] + ["%{search_sql} <= ?", to_value.to_s(:db)] elsif !to_value - ["#{column.search_sql} >= ?", from_value.to_s(:db)] + ["%{search_sql} >= ?", from_value.to_s(:db)] else - ["#{column.search_sql} BETWEEN ? AND ?", from_value.to_s(:db), to_value.to_s(:db)] + ["%{search_sql} BETWEEN ? AND ?", from_value.to_s(:db), to_value.to_s(:db)] end end def condition_for_record_select_type(column, value, like_pattern = nil) if value.is_a?(Array) - ["#{column.search_sql} IN (?)", value] + ["%{search_sql} IN (?)", value] else - ["#{column.search_sql} = ?", value] + ["%{search_sql} = ?", value] end end def condition_for_null_type(column, value, like_pattern = nil) case value.to_sym when :null - ["#{column.search_sql} is null"] + ["%{search_sql} is null", []] when :not_null - ["#{column.search_sql} is not null"] + ["%{search_sql} is not null", []] else nil end @@ -218,8 +236,8 @@ def like_pattern(text_search) :ends_with => '%?' } NullComparators = [ - :null, - :not_null + 'null', + 'not_null' ] From af76ea5fb1cd1c95085e6a52d70c9ae6b6c06f43 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 26 Jun 2012 13:50:53 +0200 Subject: [PATCH 1555/2024] hide text input on searching for null or not null --- CHANGELOG | 1 + app/assets/javascripts/jquery/active_scaffold.js | 6 ++++-- app/assets/javascripts/prototype/active_scaffold.js | 1 + lib/active_scaffold/helpers/search_column_helpers.rb | 6 ++++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 287fdd7309..b5d5193700 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ - Remove default :method sorting for associations, it wasn't useful and can be slow - Rescue from ActiveScaffold::ActionNotAllowed and ActiveScaffold::RecordNotAllowed with 401 response, it can be overrided with deny_access method in ApplicationController. - Allow to set arrays in search_sql so one column can search in multiple db columns, resulting sql chunks will be OR'ed +- Hide text input on searching for null or not null = 3.2.12 - improve support for tableless models, add support for count diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index d300c5c412..13f189ad53 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -166,11 +166,13 @@ jQuery(document).ready(function() { }); jQuery('select.as_search_range_option').live('change', function(event) { - ActiveScaffold[jQuery(this).val() == 'BETWEEN' ? 'show' : 'hide'](jQuery(this).parent().find('.as_search_range_between')); + var element = jQuery(this); + ActiveScaffold[element.val() == 'BETWEEN' ? 'show' : 'hide'](element.closest('dd').find('.as_search_range_between')); + ActiveScaffold[(element.val() == 'null' || element.val() == 'not_null') ? 'hide' : 'show'](element.attr('id').replace(/_opt/, '_numeric')); return true; }); - jQuery('select.as_search_range_option').live('change', function(event) { + jQuery('select.as_search_date_time_option').live('change', function(event) { var element = jQuery(this); ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric')); ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend')); diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 609770adc8..337f809e15 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -252,6 +252,7 @@ document.observe("dom:loaded", function() { document.on('change', 'select.as_search_range_option', function(event) { var element = event.findElement(); Element[element.value == 'BETWEEN' ? 'show' : 'hide'](element.readAttribute('id').sub('_opt', '_between')); + Element[(element.value == 'null' || element.value == 'not_null') ? 'hide' : 'show'](element.readAttribute('id').sub('_opt', '_numeric')); return true; }); document.on('change', 'select.as_search_date_time_option', function(event) { diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 62e5ec49a0..670335a882 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -179,10 +179,12 @@ def active_scaffold_search_range(column, options) options_for_select(select_options, opt_value), :id => "#{options[:id]}_opt", :class => "as_search_range_option") - html << ' ' << text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(:id => options[:id], :size => text_field_size)) - html << ' ' << content_tag(:span, (' - ' + text_field_tag("#{options[:name]}[to]", to_value, + html << content_tag("span", :id => "#{options[:id]}_numeric", :style => ActiveScaffold::Finder::NullComparators.include?(opt_value) ? "display: none" : nil) do + text_field_tag("#{options[:name]}[from]", from_value, active_scaffold_input_text_options(:id => options[:id], :size => text_field_size)) << + content_tag(:span, (' - ' + text_field_tag("#{options[:name]}[to]", to_value, active_scaffold_input_text_options(:id => "#{options[:id]}_to", :size => text_field_size))).html_safe, :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => (opt_value == 'BETWEEN') ? nil : "display: none") + end content_tag :span, html, :class => 'search_range' end alias_method :active_scaffold_search_integer, :active_scaffold_search_range From 845ccb715534c2c4e21e3b3a8ee2cc47d8008845 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 27 Jun 2012 12:05:19 +0200 Subject: [PATCH 1556/2024] add numeric-input class for numeric inputs --- lib/active_scaffold/helpers/form_column_helpers.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 722b143ad7..b722899b32 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -73,8 +73,11 @@ def active_scaffold_input_options(column, scope = nil, options = {}) # Fix for keeping unique IDs in subform id_control = "record_#{column.name}_#{[params[:eid], params[:id]].compact.join '_'}" id_control += scope_id(scope) if scope + + classes = "#{column.name}-input" + classes += ' numeric-input' if column.number? - { :name => name, :class => "#{column.name}-input", :id => id_control}.merge(options) + { :name => name, :class => classes, :id => id_control}.merge(options) end def update_columns_options(column, scope, options) From 8f6e3a4e85a97e25e739247353bc9be54b13a4c6 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 27 Jun 2012 12:06:52 +0200 Subject: [PATCH 1557/2024] add some classes in subforms --- CHANGELOG | 1 + frontends/default/views/_horizontal_subform_header.html.erb | 2 +- frontends/default/views/_horizontal_subform_record.html.erb | 2 +- frontends/default/views/_vertical_subform_record.html.erb | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b5d5193700..ea501541a2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ - Rescue from ActiveScaffold::ActionNotAllowed and ActiveScaffold::RecordNotAllowed with 401 response, it can be overrided with deny_access method in ApplicationController. - Allow to set arrays in search_sql so one column can search in multiple db columns, resulting sql chunks will be OR'ed - Hide text input on searching for null or not null +- Add some classes to forms to improve CSS customization = 3.2.12 - improve support for tableless models, add support for count diff --git a/frontends/default/views/_horizontal_subform_header.html.erb b/frontends/default/views/_horizontal_subform_header.html.erb index eedab39455..32261420e9 100644 --- a/frontends/default/views/_horizontal_subform_header.html.erb +++ b/frontends/default/views/_horizontal_subform_header.html.erb @@ -5,7 +5,7 @@ hidden = column_renders_as(column) == :hidden next unless in_subform?(column, parent_record) -%> - <th class="<%= "#{'required' if column.required?} #{'hidden' if hidden}" %>"><label><%= column.label unless hidden %></label></th> + <th class="<%= "#{column.name}-column #{'required' if column.required?} #{'hidden' if hidden}" %>"><label><%= column.label unless hidden %></label></th> <% end -%> </tr> </thead> diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb index 707c82e01c..7bbd18c772 100644 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ b/frontends/default/views/_horizontal_subform_record.html.erb @@ -24,7 +24,7 @@ <% unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) -%> <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%> <% else -%> - <p class="<%= column.name %>-input"><%= get_column_value(@record, column) -%></p> + <%= content_tag :span, get_column_value(@record, column), active_scaffold_input_options(column, scope).except(:name) -%> <% end -%> </td> <% end -%> diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_vertical_subform_record.html.erb index 80b9e09a7f..7178fdcd71 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_vertical_subform_record.html.erb @@ -24,7 +24,7 @@ <% unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) -%> <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%> <% else -%> - <p class="<%= column.name %>-input"><%= get_column_value(@record, column) -%></p> + <%= content_tag :span, get_column_value(@record, column), active_scaffold_input_options(column, scope).except(:name) -%> <% end -%> </li> <% end -%> From 4549f77c70047979fc4dffa10823498f7ba1e3cf Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 27 Jun 2012 14:15:05 +0200 Subject: [PATCH 1558/2024] fix nested links for STI controllers, if link is configured in base controller, children controllers weren't send as parent_scaffold --- CHANGELOG | 1 + frontends/default/views/_list_inline_adapter.html.erb | 1 + lib/active_scaffold.rb | 4 ++-- lib/active_scaffold/config/nested.rb | 2 +- lib/active_scaffold/data_structures/nested_info.rb | 6 +++++- lib/active_scaffold/helpers/view_helpers.rb | 4 +++- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ea501541a2..6af7e1e4d7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ - Allow to set arrays in search_sql so one column can search in multiple db columns, resulting sql chunks will be OR'ed - Hide text input on searching for null or not null - Add some classes to forms to improve CSS customization +- Fix nested links for STI controllers with common configuration in a base controller = 3.2.12 - improve support for tableless models, add support for count diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index 58653b3bf3..451e536775 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -1,4 +1,5 @@ <% +debugger column_count ||= begin config = if nested? and (nested.singular_association? || action_name == 'index') active_scaffold_config_for(nested.parent_model) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 5c86f98a4d..eb641a0980 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -266,7 +266,7 @@ def link_for_association(column, options = {}) unless controller.nil? options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column options[:parameters] ||= {} - options[:parameters].reverse_merge! :parent_scaffold => controller_path, :association => column.association.name + options[:parameters].reverse_merge! :association => column.association.name if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. @@ -285,7 +285,7 @@ def link_for_association(column, options = {}) def link_for_association_as_scope(scope, options = {}) options.reverse_merge! :label => scope, :position => :after, :type => :member, :controller => controller_path options[:parameters] ||= {} - options[:parameters].reverse_merge! :parent_scaffold => controller_path, :named_scope => scope + options[:parameters].reverse_merge! :named_scope => scope ActiveScaffold::DataStructures::ActionLink.new('index', options) end diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index 6eb5f4702f..bc29943969 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -21,7 +21,7 @@ def initialize(core_config) def add_link(attribute, options = {}) column = @core.columns[attribute.to_sym] unless column.nil? || column.association.nil? - options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) + options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) action_link = @core.link_for_association(column, options) action_link.action ||= :index @core.action_links.add_to_group(action_link, action_group) unless action_link.nil? diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 554ff651c2..ebac210918 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -6,7 +6,11 @@ def self.get(model, params) nested_info[:name] = (params[:association] || params[:named_scope]).to_sym nested_info[:parent_scaffold] = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize nested_info[:parent_model] = nested_info[:parent_scaffold].active_scaffold_config.model - nested_info[:parent_id] = params[nested_info[:parent_model].name.foreign_key] + nested_info[:parent_id] = if params[:association].nil? + params[nested_info[:parent_model].name.foreign_key] + else + params[nested_info[:parent_model].reflect_on_association(params[:association].to_sym).active_record.name.foreign_key] + end if nested_info[:parent_id] unless params[:association].nil? ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, nested_info) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 2894d712e3..b6a963c282 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -189,11 +189,13 @@ def action_link_html(link, url, html_options, record) end def url_options_for_nested_link(column, record, link, url_options, options = {}) - if column && column.association + if column && column.association + url_options[:parent_scaffold] = controller_path url_options[column.association.active_record.name.foreign_key.to_sym] = url_options.delete(:id) url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present? url_options[:eid] = nil # needed for nested scaffolds open from an embedded scaffold elsif link.parameters && link.parameters[:named_scope] + url_options[:parent_scaffold] = controller_path url_options[active_scaffold_config.model.name.foreign_key.to_sym] = url_options.delete(:id) url_options[:eid] = nil # needed for nested scaffolds open from an embedded scaffold end From af7292651b56c06c2575064641a43acb2a46468b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 27 Jun 2012 14:20:23 +0200 Subject: [PATCH 1559/2024] remove debugger --- frontends/default/views/_list_inline_adapter.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index 451e536775..58653b3bf3 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -1,5 +1,4 @@ <% -debugger column_count ||= begin config = if nested? and (nested.singular_association? || action_name == 'index') active_scaffold_config_for(nested.parent_model) From 4d7618ea09800c749980c35882fee79424b88279 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 28 Jun 2012 12:24:36 +0200 Subject: [PATCH 1560/2024] fix generator, remove duplicated route --- CHANGELOG | 1 + lib/generators/active_scaffold/active_scaffold_generator.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 6af7e1e4d7..be4c76a728 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ - Hide text input on searching for null or not null - Add some classes to forms to improve CSS customization - Fix nested links for STI controllers with common configuration in a base controller +- Fix adding routes twice in active_scaffold generator = 3.2.12 - improve support for tableless models, add support for count diff --git a/lib/generators/active_scaffold/active_scaffold_generator.rb b/lib/generators/active_scaffold/active_scaffold_generator.rb index 8dd1928df4..929f2a69e1 100644 --- a/lib/generators/active_scaffold/active_scaffold_generator.rb +++ b/lib/generators/active_scaffold/active_scaffold_generator.rb @@ -5,6 +5,7 @@ module Rails module Generators class ActiveScaffoldGenerator < ResourceGenerator #metagenerator remove_hook_for :resource_controller + remove_hook_for :resource_route remove_class_option :actions def add_resource_route From 928d3e4e1d6c11cda5f68517c89b9bb79330705c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 28 Jun 2012 12:28:25 +0200 Subject: [PATCH 1561/2024] Restore old behavior for action_link's security_method, ignore_method already hides the link --- CHANGELOG | 1 + frontends/default/views/_update_actions.html.erb | 2 +- lib/active_scaffold/config/show.rb | 2 +- lib/active_scaffold/config/update.rb | 2 +- lib/active_scaffold/data_structures/action_links.rb | 9 +++++++-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index be4c76a728..dab9c646f8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ - Add some classes to forms to improve CSS customization - Fix nested links for STI controllers with common configuration in a base controller - Fix adding routes twice in active_scaffold generator +- Restore old behavior for action_link's security_method, ignore_method already hides the link = 3.2.12 - improve support for tableless models, add support for count diff --git a/frontends/default/views/_update_actions.html.erb b/frontends/default/views/_update_actions.html.erb index e16e05ab91..9993dba6cf 100644 --- a/frontends/default/views/_update_actions.html.erb +++ b/frontends/default/views/_update_actions.html.erb @@ -1,7 +1,7 @@ <div class="active-scaffold-header"> <div class="actions"> <% active_scaffold_config.action_links.member.each do |link| -%> - <% next unless link.action == 'nested' -%> + <% next unless link.action == 'index' -%> <% next if skip_action_link(link) -%> <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : "<a class='disabled'>#{link.label}</a>" -%> <% end -%> diff --git a/lib/active_scaffold/config/show.rb b/lib/active_scaffold/config/show.rb index e25d19ef87..458cff5ffd 100644 --- a/lib/active_scaffold/config/show.rb +++ b/lib/active_scaffold/config/show.rb @@ -11,7 +11,7 @@ def initialize(core_config) # global level configuration # -------------------------- cattr_accessor :link - @@link = ActiveScaffold::DataStructures::ActionLink.new('show', :label => :show, :type => :member, :security_method => :show_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('show', :label => :show, :type => :member, :security_method => :show_authorized?, :ignore_method => :show_ignore?) # instance-level configuration # ---------------------------- diff --git a/lib/active_scaffold/config/update.rb b/lib/active_scaffold/config/update.rb index 10b241929b..67d96b4ca0 100644 --- a/lib/active_scaffold/config/update.rb +++ b/lib/active_scaffold/config/update.rb @@ -15,7 +15,7 @@ def self.link def self.link=(val) @@link = val end - @@link = ActiveScaffold::DataStructures::ActionLink.new('edit', :label => :edit, :type => :member, :security_method => :update_authorized?) + @@link = ActiveScaffold::DataStructures::ActionLink.new('edit', :label => :edit, :type => :member, :security_method => :update_authorized?, :ignore_method => :update_ignore?) # instance-level configuration # ---------------------------- diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 3dac351799..b38c60c996 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -121,7 +121,12 @@ def traverse(controller, options = {}, &block) first_action = false end elsif controller.nil? || !skip_action_link(controller, link, *(Array(options[:for]))) - authorized = options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action) + security_method = link.security_method_set? || controller.respond_to?(link.security_method) + authorized = if security_method + controller.send(link.security_method, *args) + else + options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action) + end yield(self, link, {:authorized => authorized, :first_action => first_action, :level => options[:level]}) first_action = false end @@ -173,7 +178,7 @@ def #{name} protected def skip_action_link(controller, link, *args) - (!link.ignore_method.nil? && controller.respond_to?(link.ignore_method) && controller.send(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args)) + !link.ignore_method.nil? && controller.respond_to?(link.ignore_method) && controller.send(link.ignore_method, *args) end # called during clone or dup. makes the clone/dup deeper. From 0229937ed54c011367a28bda40bd0ef3714f80a9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 28 Jun 2012 12:53:53 +0200 Subject: [PATCH 1562/2024] fix typo in ruby 1.9 --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index d796cc84da..92b2f11b32 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -72,7 +72,7 @@ def condition_for_column(column, value, text_search = :full) end return nil unless sql - conditions = [column.search_sql.collect { |search_sql| sql % {:search_sql => search_sql} }.join ' OR '] + conditions = [column.search_sql.collect { |search_sql| sql % {:search_sql => search_sql} }.join(' OR ')] conditions += values*column.search_sql.size if values.present? conditions rescue Exception => e From 53eafc27c8c90ffe08985aa535599cd5e9c2d5ce Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 28 Jun 2012 15:02:38 +0200 Subject: [PATCH 1563/2024] fix removing empty class when filling column with inplace edit --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 13f189ad53..2a73da2354 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -442,7 +442,7 @@ var ActiveScaffold = { update_inplace_edit: function(element, value, empty) { if (typeof(element) == 'string') element = '#' + element; this.replace_html(jQuery(element), value); - if (empty) jQuery(element).closest('td').addClass('empty'); + jQuery(element).closest('td')[empty ? 'addClass' : 'removeClass']('empty'); }, hide: function(element) { From b2141b6a530d7183b3e79c83be8776417e5eb395 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 2 Jul 2012 12:57:04 +0200 Subject: [PATCH 1564/2024] Add data-cancel-refresh to action links and change nested scaffolds to use this instead of hard code behavior in list_inline_adapter --- CHANGELOG | 1 + app/assets/javascripts/jquery/active_scaffold.js | 6 +++--- app/assets/javascripts/prototype/active_scaffold.js | 6 +++--- frontends/default/views/_base_form.html.erb | 2 +- frontends/default/views/_list_inline_adapter.html.erb | 2 +- frontends/default/views/_show.html.erb | 2 +- lib/active_scaffold.rb | 2 +- lib/active_scaffold/data_structures/action_link.rb | 6 ++++++ lib/active_scaffold/helpers/view_helpers.rb | 1 + 9 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index dab9c646f8..7485b0d54d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ - Fix nested links for STI controllers with common configuration in a base controller - Fix adding routes twice in active_scaffold generator - Restore old behavior for action_link's security_method, ignore_method already hides the link +- Add data-cancel-refresh to action links, so nested scaffold's behaviour can be applied to other action links and when adapter is closed row will be refreshed. = 3.2.12 - improve support for tableless models, add support for count diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 2a73da2354..a35fbe38cb 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -72,8 +72,8 @@ jQuery(document).ready(function() { if (action_link) { var cancel_url = as_cancel.attr('href'); - var refresh_data = as_cancel.attr('data-refresh'); - if (refresh_data !== 'true' || !cancel_url) { + var refresh_data = action_link.tag.data('cancel-refresh'); + if (!refresh_data || !cancel_url) { action_link.close(); return false; } @@ -973,7 +973,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ this.adapter = element; this.adapter.addClass('as_adapter'); this.adapter.data('action_link', this); - if (this.refresh_url) jQuery('.as_cancel[data-refresh=true]', this.adapter).attr('href', this.refresh_url); + if (this.refresh_url) jQuery('.as_cancel', this.adapter).attr('href', this.refresh_url); } }); diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 337f809e15..8a2d83b0a4 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -95,10 +95,10 @@ document.observe("dom:loaded", function() { var action_link = ActiveScaffold.find_action_link(as_cancel); if (action_link) { - var refresh_data = as_cancel.readAttribute('data-refresh'); - if (refresh_data === 'true' && action_link.refresh_url) { + var refresh_data = action_link.readAttribute('data-cancel-refresh'); + if (refresh_data && action_link.refresh_url) { event.memo.url = action_link.refresh_url; - } else if (refresh_data === 'false' || as_cancel.readAttribute('href').blank()) { + } else if (!refresh_data || as_cancel.readAttribute('href').blank()) { action_link.close(); event.stop(); } diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index fe69483797..f825c45434 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -20,7 +20,7 @@ options = {:onsubmit => onsubmit, :class => "as_form #{form_action.to_s}", :method => method, 'data-loading' => true} -cancel_options = {:class => 'as_cancel', 'data-refresh' => false} +cancel_options = {:class => 'as_cancel'} cancel_options[:remote] = true if xhr #cancel link does nt have to care about multipart forms if xhr && multipart # file_uploads diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index 58653b3bf3..9066d89c2c 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -12,7 +12,7 @@ <tr class="inline-adapter" id="<%= element_row_id :action => :nested %>"> <td colspan="<%= column_count %>" class="inline-adapter-cell"> <div class="<%= "#{params[:action]}-view" if params[:action] %> <%= "#{nested? ? nested.name : id_from_controller(params[:controller])}-view" %> view"> - <%= link_to(as_(:close), '', :class => 'inline-adapter-close as_cancel', :remote => true, :title => as_(:close), 'data-refresh' => (action_name == 'index' ? true : false)) -%> + <%= link_to(as_(:close), '', :class => 'inline-adapter-close as_cancel', :remote => true, :title => as_(:close)) -%> <%= payload -%> </div> </td> diff --git a/frontends/default/views/_show.html.erb b/frontends/default/views/_show.html.erb index 8a28421b95..91e8dc6e25 100644 --- a/frontends/default/views/_show.html.erb +++ b/frontends/default/views/_show.html.erb @@ -3,6 +3,6 @@ <%= render :partial => 'show_columns', :locals => {:columns => active_scaffold_config.show.columns} -%> <p class="form-footer"> - <%= link_to as_(:close), main_path_to_return, :class => 'as_cancel', :remote => request.xhr?, 'data-refresh' => false %> + <%= link_to as_(:close), main_path_to_return, :class => 'as_cancel', :remote => request.xhr? %> <%= loading_indicator_tag(:action => :create, :id => params[:id]) %> </p> diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index eb641a0980..a1e79c1e62 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -270,7 +270,7 @@ def link_for_association(column, options = {}) if column.plural_association? # note: we can't create nested scaffolds on :through associations because there's no reverse association. - ActiveScaffold::DataStructures::ActionLink.new('index', options) #unless column.through_association? + ActiveScaffold::DataStructures::ActionLink.new('index', options.merge(:refresh_on_close => true)) #unless column.through_association? else actions = controller.active_scaffold_config.actions unless controller == :polymorph actions ||= [:create, :update, :show] diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 756f8b38fb..7f6b37886b 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -82,6 +82,7 @@ def dhtml_confirm? end # what method to call on the controller to see if this action_link should be visible + # if method return false, link will be disabled # note that this is only the UI part of the security. to prevent URL hax0rz, you also need security on requests (e.g. don't execute update method unless authorized). attr_writer :security_method def security_method @@ -91,7 +92,12 @@ def security_method def security_method_set? !!@security_method end + + # enable it to refresh the parent row when the view is closed + attr_accessor :refresh_on_close + # what method to call on the controller to see if this action_link should be visible + # if method return true, link won't be displayed attr_accessor :ignore_method # the crud type of the (eventual?) action. different than :method, because this crud action may not be imminent. diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index b6a963c282..6ccca054be 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -146,6 +146,7 @@ def action_link_html_options(link, url_options, record, html_options) html_options[:data][:confirm] = link.confirm(record.try(:to_label)) if link.confirm? html_options[:data][:position] = link.position if link.position and link.inline? html_options[:data][:action] = link.action if link.inline? + html_options[:data][:'cancel-refresh'] = true if link.inline? and link.refresh_on_close if link.popup? html_options[:data][:popup] = true html_options[:target] = '_blank' From 7c0c39e59f32d991914e947d9af0b949e5dbaa11 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 3 Jul 2012 05:17:05 -1000 Subject: [PATCH 1565/2024] fix tableless models for >= rails 3.2.5 --- CHANGELOG | 1 + lib/active_scaffold/data_structures/column.rb | 7 ++++--- lib/active_scaffold/tableless.rb | 1 - 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7485b0d54d..fd0a6bdb33 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ - Fix adding routes twice in active_scaffold generator - Restore old behavior for action_link's security_method, ignore_method already hides the link - Add data-cancel-refresh to action links, so nested scaffold's behaviour can be applied to other action links and when adapter is closed row will be refreshed. +- fix support for tableless models in rails >= 3.2.5 = 3.2.12 - improve support for tableless models, add support for count diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 1892f0d48c..b0220ba509 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -284,6 +284,7 @@ def ==(other) #:nodoc: # instantiation is handled internally through the DataStructures::Columns object def initialize(name, active_record_class) #:nodoc: self.name = name.to_sym + @tableless = active_record_class < ActiveScaffold::Tableless @column = active_record_class.columns_hash[self.name.to_s] @association = active_record_class.reflect_on_association(self.name) @autolink = !@association.nil? @@ -355,7 +356,7 @@ def initialize_sort # we don't automatically enable method sorting for virtual columns because it's slow, and we expect fewer complaints this way. self.sort = false else - if column && @active_record_class.connection + if column && @tableless self.sort = {:sql => self.field} else self.sort = false @@ -366,9 +367,9 @@ def initialize_sort def initialize_search_sql self.search_sql = unless self.virtual? if association.nil? - self.field.to_s unless @active_record_class.connection.nil? + self.field.to_s unless @tableless elsif !self.polymorphic_association? - [association.klass.quoted_table_name, association.klass.quoted_primary_key].join('.') unless association.klass.connection.nil? + [association.klass.quoted_table_name, association.klass.quoted_primary_key].join('.') unless association.klass < ActiveScaffold::Tableless end end end diff --git a/lib/active_scaffold/tableless.rb b/lib/active_scaffold/tableless.rb index 7ee1873b43..29b56d7c5f 100644 --- a/lib/active_scaffold/tableless.rb +++ b/lib/active_scaffold/tableless.rb @@ -46,7 +46,6 @@ def execute_simple_calculation(operation, column_name, distinct) def self.columns; @columns ||= []; end def self.table_name; @table_name ||= ActiveModel::Naming.plural(self); end - def self.connection; nil; end def self.table_exists?; true; end self.abstract_class = true class << self From 4dda7bc1fd6c92b8476804d16505a5e3afdfccc3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 3 Jul 2012 05:18:14 -1000 Subject: [PATCH 1566/2024] bump version --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index fb23059af2..b1b9669d8e 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 12 + PATCH = 13 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From ecc55374ff3463ca628bde3a46767789000a251a Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 3 Jul 2012 06:07:11 -1000 Subject: [PATCH 1567/2024] fix typo breaking sorting --- lib/active_scaffold/data_structures/column.rb | 2 +- lib/active_scaffold/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index b0220ba509..9d2d96f8b3 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -356,7 +356,7 @@ def initialize_sort # we don't automatically enable method sorting for virtual columns because it's slow, and we expect fewer complaints this way. self.sort = false else - if column && @tableless + if column && !@tableless self.sort = {:sql => self.field} else self.sort = false diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index b1b9669d8e..a2e369b22b 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 2 - PATCH = 13 + PATCH = 14 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 18cbd55e19661d7e5481c344a179c92e7112cde3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 6 Jul 2012 14:50:25 +0200 Subject: [PATCH 1568/2024] list rendering optimization, 50% speedup --- frontends/default/views/_list.html.erb | 2 +- .../default/views/_list_actions.html.erb | 15 --- .../default/views/_list_messages.html.erb | 2 - frontends/default/views/_list_record.html.erb | 29 ++++- .../views/_list_record_columns.html.erb | 8 -- .../active_record_permissions.rb | 41 +++++-- .../bridges/carrierwave/list_ui.rb | 2 +- .../bridges/dragonfly/form_ui.rb | 2 +- .../bridges/dragonfly/list_ui.rb | 2 +- .../bridges/file_column/list_ui.rb | 8 +- .../bridges/paperclip/form_ui.rb | 2 +- .../bridges/paperclip/list_ui.rb | 2 +- lib/active_scaffold/data_structures/column.rb | 3 + .../helpers/list_column_helpers.rb | 44 +++++--- lib/active_scaffold/helpers/view_helpers.rb | 106 +++++++++++------- test/bridges/paperclip_test.rb | 4 +- 16 files changed, 161 insertions(+), 111 deletions(-) delete mode 100644 frontends/default/views/_list_actions.html.erb delete mode 100644 frontends/default/views/_list_record_columns.html.erb diff --git a/frontends/default/views/_list.html.erb b/frontends/default/views/_list.html.erb index b163eb48bf..1ee5a7cdb3 100644 --- a/frontends/default/views/_list.html.erb +++ b/frontends/default/views/_list.html.erb @@ -8,7 +8,7 @@ <%= render :partial => 'list_messages', :locals => {:columns => columns} %> <tbody class="records" id="<%= active_scaffold_tbody_id %>"> <% if !@records.empty? -%> - <%= render :partial => 'list_record', :collection => @page.items, :locals => { :hidden => false, :columns => columns, :action_links => active_scaffold_config.action_links.member} %> + <%= render :partial => 'list_record', :collection => @page.items, :locals => {:hidden => false, :columns => columns, :action_links => active_scaffold_config.action_links.member, :data_refresh => url_for(params_for(:action => :row, :id => '--ID--', :_method => :get))} %> <% end -%> <% if columns.any? {|c| c.calculation?} -%> <%= render :partial => 'list_calculations', :locals => {:columns => columns} %> diff --git a/frontends/default/views/_list_actions.html.erb b/frontends/default/views/_list_actions.html.erb deleted file mode 100644 index 53b1e38d11..0000000000 --- a/frontends/default/views/_list_actions.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -<td class="actions"><table cellpadding="0" cellspacing="0"> - <tr> - <td class="indicator-container"> - <%= loading_indicator_tag(:action => :record, :id => record.id) %> - </td> - <%= render :partial => 'action_group', :locals => {:action_links => action_links || active_scaffold_config.action_links.member, - :url_options => url_options, - :record => record, - :traverse_options => {:for => record.persisted? ? record : record.class}, - :start_level_0_tag => '<td>', - :end_level_0_tag => '</td>'} %> - </tr> -</table> -</td> - diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index 0b7aa1c87b..d1a965bbce 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -24,5 +24,3 @@ </td> </tr> </tbody> - - diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 0618e5bf59..23228670f9 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -4,10 +4,33 @@ columns ||= list_columns tr_class = cycle("", "even-record") + ' ' + list_row_class(record) url_options = params_for(:action => :list, :id => record.id) action_links ||= active_scaffold_config.action_links.member +data_refresh ||= url_for(params_for(:action => :row, :id => '--ID--', :_method => :get)) -%> -<tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= url_for(params_for(:action => :row, :id => record.id, :_method => :get)).html_safe %>"> - <%= render :partial => 'list_record_columns', :locals => {:record => record, :columns => columns} %> - <%= render :partial => 'list_actions', :locals => {:record => record, :url_options => url_options, :action_links => action_links} unless action_links.empty? %> +<tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= data_refresh.sub('--ID--', record.id.to_s).html_safe %>"> + <% columns.each do |column| %> + <% authorized = record.authorized_for?(:crud_type => :read, :column => column.name) -%> + <% column_value = authorized ? get_column_value(record, column) : active_scaffold_config.list.empty_field_text -%> + + <%= content_tag :td, column_attributes(column, record).merge(:class => column_class(column, column_value, record)) do %> + <%= authorized ? render_list_column(column_value, column, record) : column_value %> + <% end %> + <% end -%> + + <td class="actions"><table cellpadding="0" cellspacing="0"> + <tr> + <td class="indicator-container"> + <%= loading_indicator_tag(:action => :record, :id => record.id) %> + </td> + <%= render :partial => 'action_group', :locals => {:action_links => action_links, + :url_options => url_options, + :record => record, + :traverse_options => {:for => record.persisted? ? record : record.class}, + :start_level_0_tag => '<td>', + :end_level_0_tag => '</td>'} %> + </tr> + </table></td> + + <%= render_nested_view(action_links, url_options, record) unless @nested_auto_open.nil? %> </tr> diff --git a/frontends/default/views/_list_record_columns.html.erb b/frontends/default/views/_list_record_columns.html.erb deleted file mode 100644 index 40244aa689..0000000000 --- a/frontends/default/views/_list_record_columns.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -<% columns.each do |column| %> - <% authorized = record.authorized_for?(:crud_type => :read, :column => column.name) -%> - <% column_value = authorized ? get_column_value(record, column) : active_scaffold_config.list.empty_field_text -%> - - <%= content_tag :td, column_attributes(column, record).merge(:class => column_class(column, column_value, record)) do %> - <%= authorized ? render_list_column(column_value, column, record) : column_value %> - <% end %> -<% end -%> diff --git a/lib/active_scaffold/active_record_permissions.rb b/lib/active_scaffold/active_record_permissions.rb index d092ce1783..c3be43cd83 100644 --- a/lib/active_scaffold/active_record_permissions.rb +++ b/lib/active_scaffold/active_record_permissions.rb @@ -65,6 +65,10 @@ module Permissions def self.included(base) base.extend SecurityMethods base.send :include, SecurityMethods + class << base + attr_accessor :class_security_methods + attr_accessor :instance_security_methods + end end # Because any class-level queries get delegated to the instance level via a new record, @@ -85,34 +89,47 @@ module SecurityMethods def authorized_for?(options = {}) raise ArgumentError, "unknown crud type #{options[:crud_type]}" if options[:crud_type] and ![:create, :read, :update, :delete].include?(options[:crud_type]) + # collect other possibly-related methods that actually exist + methods = cached_authorized_for_methods(options) + return ActiveRecordPermissions.default_permission if methods.empty? + return send(methods.first) if methods.one? + + # if any method returns false, then return false + return false if methods.any? {|m| !send(m)} + true + end + + def cached_authorized_for_methods(options) + key = "#{options[:crud_type]}##{options[:column]}##{options[:action]}" + if self.is_a? Class + self.class_security_methods ||= {} + self.class_security_methods[key] ||= authorized_for_methods(options) + else + self.class.instance_security_methods ||= {} + self.class.instance_security_methods[key] ||= authorized_for_methods(options) + end + end + + def authorized_for_methods(options) # column_authorized_for_crud_type? has the highest priority over other methods, # you can disable a crud verb and enable that verb for a column # (for example, disable update and enable inplace_edit in a column) method = column_and_crud_type_security_method(options[:column], options[:crud_type]) - return send(method) if method and respond_to?(method) + return [method] if method and respond_to?(method) # authorized_for_action? has higher priority than other methods, # you can disable a crud verb and enable an action with that crud verb # (for example, disable update and enable an action with update as crud type) method = action_security_method(options[:action]) - return send(method) if method and respond_to?(method) + return [method] if method and respond_to?(method) # collect other possibly-related methods that actually exist methods = [ column_security_method(options[:column]), crud_type_security_method(options[:crud_type]), ].compact.select {|m| respond_to?(m)} - - # if any method returns false, then return false - return false if methods.any? {|m| !send(m)} - - # if any method actually exists then it must've returned true, so return true - return true unless methods.empty? - - # if no method exists, return the default permission - return ActiveRecordPermissions.default_permission end - + private def column_security_method(column) diff --git a/lib/active_scaffold/bridges/carrierwave/list_ui.rb b/lib/active_scaffold/bridges/carrierwave/list_ui.rb index f9079710cd..ba799242df 100644 --- a/lib/active_scaffold/bridges/carrierwave/list_ui.rb +++ b/lib/active_scaffold/bridges/carrierwave/list_ui.rb @@ -1,7 +1,7 @@ module ActiveScaffold module Helpers module ListColumnHelpers - def active_scaffold_column_carrierwave(column, record) + def active_scaffold_column_carrierwave(record, column) carrierwave = record.send("#{column.name}") return nil unless !carrierwave.file.blank? thumbnail_style = ActiveScaffold::Bridges::Carrierwave::CarrierwaveBridgeHelpers.thumbnail_style diff --git a/lib/active_scaffold/bridges/dragonfly/form_ui.rb b/lib/active_scaffold/bridges/dragonfly/form_ui.rb index c709db31a0..017e9aa6d0 100644 --- a/lib/active_scaffold/bridges/dragonfly/form_ui.rb +++ b/lib/active_scaffold/bridges/dragonfly/form_ui.rb @@ -12,7 +12,7 @@ def active_scaffold_input_dragonfly(column, options) js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;"; end - content = active_scaffold_column_dragonfly(column, @record) + content = active_scaffold_column_dragonfly(@record, column) content_tag(:div, content + " | " + hidden_field(:record, "remove_#{column.name}", :value => "false") + diff --git a/lib/active_scaffold/bridges/dragonfly/list_ui.rb b/lib/active_scaffold/bridges/dragonfly/list_ui.rb index d8e49b30f8..0da2f71cca 100644 --- a/lib/active_scaffold/bridges/dragonfly/list_ui.rb +++ b/lib/active_scaffold/bridges/dragonfly/list_ui.rb @@ -1,7 +1,7 @@ module ActiveScaffold module Helpers module ListColumnHelpers - def active_scaffold_column_dragonfly(column, record) + def active_scaffold_column_dragonfly(record, column) attachment = record.send("#{column.name}") return nil unless attachment.present? content = if attachment.image? diff --git a/lib/active_scaffold/bridges/file_column/list_ui.rb b/lib/active_scaffold/bridges/file_column/list_ui.rb index edb7199319..7a0a21462d 100644 --- a/lib/active_scaffold/bridges/file_column/list_ui.rb +++ b/lib/active_scaffold/bridges/file_column/list_ui.rb @@ -2,18 +2,18 @@ module ActiveScaffold module Helpers # Helpers that assist with the rendering of a List Column module ListColumnHelpers - def active_scaffold_column_download_link_with_filename(column, record) + def active_scaffold_column_download_link_with_filename(record, column) return nil if record.send(column.name).nil? - active_scaffold_column_download_link(column, record, File.basename(record.send(column.name))) + active_scaffold_column_download_link(record, column, File.basename(record.send(column.name))) end - def active_scaffold_column_download_link(column, record, label = nil) + def active_scaffold_column_download_link(record, column, label = nil) return nil if record.send(column.name).nil? label||=as_(:download) link_to( label, url_for_file_column(record, column.name.to_s), :popup => true) end - def active_scaffold_column_thumbnail(column, record) + def active_scaffold_column_thumbnail(record, column) return nil if record.send(column.name).nil? link_to( image_tag(url_for_file_column(record, column.name.to_s, "thumb"), :border => 0), diff --git a/lib/active_scaffold/bridges/paperclip/form_ui.rb b/lib/active_scaffold/bridges/paperclip/form_ui.rb index 324b9789f0..0295019f57 100644 --- a/lib/active_scaffold/bridges/paperclip/form_ui.rb +++ b/lib/active_scaffold/bridges/paperclip/form_ui.rb @@ -12,7 +12,7 @@ def active_scaffold_input_paperclip(column, options) js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;"; end - content = active_scaffold_column_paperclip(column, @record) + content = active_scaffold_column_paperclip(@record, column) content_tag(:div, content + " | " + hidden_field(:record, "delete_#{column.name}", :value => "false") + diff --git a/lib/active_scaffold/bridges/paperclip/list_ui.rb b/lib/active_scaffold/bridges/paperclip/list_ui.rb index bce065610b..58d9e417a8 100644 --- a/lib/active_scaffold/bridges/paperclip/list_ui.rb +++ b/lib/active_scaffold/bridges/paperclip/list_ui.rb @@ -1,7 +1,7 @@ module ActiveScaffold module Helpers module ListColumnHelpers - def active_scaffold_column_paperclip(column, record) + def active_scaffold_column_paperclip(record, column) paperclip = record.send("#{column.name}") return nil unless paperclip.file? content = if paperclip.styles.include?(ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.thumbnail_style) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 9d2d96f8b3..0b8be76926 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -349,6 +349,9 @@ def number_to_native(value) end end + # to cache method to get value in list + attr_accessor :list_method + protected def initialize_sort diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index d00468d27b..451ddc1293 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -5,27 +5,37 @@ module Helpers module ListColumnHelpers def get_column_value(record, column) begin - # check for an override helper - value = if (method = column_override(column)) + method = get_column_method(record, column) + value = send(method, record, column) + value = ' '.html_safe if value.nil? or value.blank? # fix for IE 6 + return value + rescue Exception => e + logger.error "#{Time.now.to_s} #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}" + raise e + end + end + + + def get_column_method(record, column) + # check for an override helper + method = column.list_method + unless method + method = if (method = column_override(column)) # we only pass the record as the argument. we previously also passed the formatted_value, # but mike perham pointed out that prohibited the usage of overrides to improve on the # performance of our default formatting. see issue #138. - send(method, record) + method # second, check if the dev has specified a valid list_ui for this column elsif column.list_ui and (method = override_column_ui(column.list_ui)) - send(method, column, record) + method elsif column.column and (method = override_column_ui(column.column.type)) - send(method, column, record) + method else - format_column_value(record, column) + :format_column_value end - - value = ' '.html_safe if value.nil? or (value.respond_to?(:empty?) and value.empty?) # fix for IE 6 - return value - rescue Exception => e - logger.error Time.now.to_s + "#{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}" - raise e + column.list_method = method end + method end # TODO: move empty_field_text and   logic in here? @@ -122,16 +132,16 @@ def clean_column_value(v) ## ## Overrides ## - def active_scaffold_column_text(column, record) + def active_scaffold_column_text(record, column) clean_column_value(truncate(record.send(column.name), :length => column.options[:truncate] || 50)) end - def active_scaffold_column_marked(column, record) + def active_scaffold_column_marked(record, column) options = {:id => nil, :object => record} content_tag(:span, check_box(:record, column.name, options), :class => 'in_place_editor_field', :data => {:ie_id => record.id.to_s}) end - def active_scaffold_column_checkbox(column, record) + def active_scaffold_column_checkbox(record, column) options = {:disabled => true, :id => nil, :object => record} options.delete(:disabled) if inplace_edit?(record, column) check_box(:record, column.name, options) @@ -144,8 +154,10 @@ def column_override(column) # the naming convention for overriding column types with helpers def override_column_ui(list_ui) + @_column_ui_overrides ||= {} + return @_column_ui_overrides[list_ui] if @_column_ui_overrides.include? list_ui method = "active_scaffold_column_#{list_ui}" - method if respond_to? method + @_column_ui_overrides[list_ui] = (method if respond_to? method) end alias_method :override_column_ui?, :override_column_ui diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 6ccca054be..53686e7e08 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -141,12 +141,14 @@ def action_link_html_options(link, url_options, record, html_options) # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails html_options[:method] = link.method if link.method != :get - html_options[:class] += ' as_action' if link.inline? html_options[:data] = {} html_options[:data][:confirm] = link.confirm(record.try(:to_label)) if link.confirm? - html_options[:data][:position] = link.position if link.position and link.inline? - html_options[:data][:action] = link.action if link.inline? - html_options[:data][:'cancel-refresh'] = true if link.inline? and link.refresh_on_close + if link.inline? + html_options[:class] += ' as_action' + html_options[:data][:position] = link.position if link.position + html_options[:data][:action] = link.action + html_options[:data][:'cancel-refresh'] = true if link.refresh_on_close + end if link.popup? html_options[:data][:popup] = true html_options[:target] = '_blank' @@ -154,8 +156,10 @@ def action_link_html_options(link, url_options, record, html_options) html_options[:id] = link_id html_options[:remote] = true unless link.page? || link.popup? if link.dhtml_confirm? - html_options[:class] += ' as_action' if !link.inline? - html_options[:page_link] = 'true' if !link.inline? + unless link.inline? + html_options[:class] += ' as_action' + html_options[:page_link] = 'true' + end html_options[:dhtml_confirm] = link.dhtml_confirm.value html_options[:onclick] = link.dhtml_confirm.onclick_function(controller, link_id) end @@ -165,12 +169,15 @@ def action_link_html_options(link, url_options, record, html_options) def get_action_link_id(url_options, record = nil, column = nil) id = url_options[:id] || url_options[:parent_id] - id = "#{column.association.name}-#{record.id}" if column && column.plural_association? - if record.try(column.association.name.to_sym).present? - id = "#{column.association.name}-#{record.send(column.association.name).id}-#{record.id}" - else - id = "#{column.association.name}-#{record.id}" unless record.nil? - end if column && column.singular_association? + if column && column.plural_association? + id = "#{column.association.name}-#{record.id}" + elsif column && column.singular_association? + if record.try(column.association.name.to_sym).present? + id = "#{column.association.name}-#{record.send(column.association.name).id}-#{record.id}" + else + id = "#{column.association.name}-#{record.id}" unless record.nil? + end + end id = "#{id}-#{url_options[:batch_scope].downcase}" if url_options[:batch_scope] action_id = "#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}#{url_options[:action].to_s}" action_link_id(action_id, id) @@ -178,15 +185,14 @@ def get_action_link_id(url_options, record = nil, column = nil) def action_link_html(link, url, html_options, record) # issue 260, use url_options[:link] if it exists. This prevents DB data from being localized. - label = url.delete(:link) if url.is_a?(Hash) + label = url.delete(:link) if url.is_a?(Hash) label ||= link.label - if link.image.nil? - html = link_to(label, url, html_options) + label = image_tag(link.image[:name], :size => link.image[:size], :alt => label, :title => label) if link.image + if url.nil? + content_tag(:a, label, html_options) else - html = link_to(image_tag(link.image[:name], :size => link.image[:size], :alt => label, :title => label), url, html_options) + link_to(label, url, html_options) end - # if url is nil we would like to generate an anchor without href attribute - url.nil? ? html.sub(/href=".*?"/, '').html_safe : html.html_safe end def url_options_for_nested_link(column, record, link, url_options, options = {}) @@ -219,9 +225,15 @@ def url_options_for_sti_link(column, record, link, url_options, options = {}) end end - def list_row_class(record) + def list_row_class_method(record) + return @_list_row_class_method if defined? @_list_row_class_method class_override_helper = :"#{clean_class_name(record.class.name)}_list_row_class" - respond_to?(class_override_helper) ? send(class_override_helper, record) : '' + @_list_row_class_method = (class_override_helper if respond_to?(class_override_helper)) + end + + def list_row_class(record) + class_override_helper = list_row_class_method(record) + class_override_helper ? send(class_override_helper, record) : '' end def column_attributes(column, record) @@ -231,39 +243,39 @@ def column_attributes(column, record) end def column_class(column, column_value, record) - classes = [] - classes << "#{column.name}-column" + @_column_classes ||= {} + @_column_classes[column.name] ||= begin + classes = "#{column.name}-column " + classes << 'sorted ' if active_scaffold_config.list.user.sorting.sorts_on?(column) + classes << 'numeric ' if column.column and [:decimal, :float, :integer].include?(column.column.type) + classes << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) + end + classes = "#{@_column_classes[column.name]} " + classes << 'empty ' if column_empty? column_value + classes << 'in_place_editor_field ' if inplace_edit?(record, column) or column.list_ui == :marked if column.css_class.is_a?(Proc) css_class = column.css_class.call(column_value, record) classes << css_class unless css_class.nil? - else - classes << column.css_class - end unless column.css_class.nil? - - classes << 'empty' if column_empty? column_value - classes << 'sorted' if active_scaffold_config.list.user.sorting.sorts_on?(column) - classes << 'numeric' if column.column and [:decimal, :float, :integer].include?(column.column.type) - classes << 'in_place_editor_field' if inplace_edit?(record, column) or column.list_ui == :marked - classes.join(' ').rstrip + end + classes end def column_heading_class(column, sorting) - classes = [] - classes << "#{column.name}-column_heading" - classes << "sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column + classes = "#{column.name}-column_heading " + classes << "sorted #{sorting.direction_of(column).downcase} " if sorting.sorts_on? column classes << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) - classes.join(' ') + classes end def as_main_div_class - classes = ["active-scaffold", "active-scaffold-#{controller_id}", "#{id_from_controller params[:controller]}-view", "#{active_scaffold_config.theme}-theme"] - classes << "as_touch" if touch_device? - classes.join(' ') + classes = "active-scaffold active-scaffold-#{controller_id} #{id_from_controller params[:controller]}-view #{active_scaffold_config.theme}-theme" + classes << " as_touch" if touch_device? + classes end def column_empty?(column_value) empty = column_value.nil? - empty ||= column_value.blank? if column_value.respond_to? :blank? + empty ||= column_value.blank? empty ||= [' ', active_scaffold_config.list.empty_field_text].include? column_value if String === column_value return empty end @@ -308,10 +320,18 @@ def override_helper_name(column, suffix, class_prefix = false) end def override_helper(column, suffix) - method_with_class = override_helper_name(column, suffix, true) - return method_with_class if respond_to?(method_with_class) - method = override_helper_name(column, suffix) - method if respond_to?(method) + @_override_helpers ||= {} + @_override_helpers[suffix] ||= {} + return @_override_helpers[suffix][column.name] if @_override_helpers[suffix].include? column.name + @_override_helpers[suffix][column.name] = begin + method_with_class = override_helper_name(column, suffix, true) + if respond_to?(method_with_class) + method_with_class + else + method = override_helper_name(column, suffix) + method if respond_to?(method) + end + end end def display_message(message) diff --git a/test/bridges/paperclip_test.rb b/test/bridges/paperclip_test.rb index a2b7a33c37..6b0b85ed06 100644 --- a/test/bridges/paperclip_test.rb +++ b/test/bridges/paperclip_test.rb @@ -49,10 +49,10 @@ def test_list_ui company = Company.new company.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => Company.attachment_definitions[:logo])) - assert_dom_equal '<a href="/system/file" onclick="window.open(this.href);return false;">file</a>', active_scaffold_column_paperclip(config.columns[:logo], company) + assert_dom_equal '<a href="/system/file" onclick="window.open(this.href);return false;">file</a>', active_scaffold_column_paperclip(company, config.columns[:logo]) company.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => {:thumbnail => '40x40'})) - assert_dom_equal '<a href="/system/file" onclick="window.open(this.href);return false;"><img src="/system/file" border="0" alt="File"/></a>', active_scaffold_column_paperclip(config.columns[:logo], company) + assert_dom_equal '<a href="/system/file" onclick="window.open(this.href);return false;"><img src="/system/file" border="0" alt="File"/></a>', active_scaffold_column_paperclip(company, config.columns[:logo]) end def test_form_ui From d2ceb891c5ecdd421d347125b0c0cdec1730834c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 6 Jul 2012 15:10:09 +0200 Subject: [PATCH 1569/2024] small optimization in action_group partial --- .../default/views/_action_group.html.erb | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/frontends/default/views/_action_group.html.erb b/frontends/default/views/_action_group.html.erb index 4d2e455015..e4a8d9038a 100644 --- a/frontends/default/views/_action_group.html.erb +++ b/frontends/default/views/_action_group.html.erb @@ -4,21 +4,22 @@ <% action_links.traverse(controller, traverse_options) do |parent, link, options| -%> <% if (options[:node] == :finished_traversing) -%> <%= "</ul>#{(options[:level] == 0 ? "</div>#{end_level_0_tag}": '</li>')}".html_safe %> + <% elsif (options[:node] == :start_traversing) -%> - <% html_classes = [] - html_classes << 'hover_click' if hover_via_click? %> - <% if options[:level] == 0 %> - <% html_classes << 'action_group' %> - <%= "#{start_level_0_tag}<div class=\"#{html_classes.join(' ')}\" #{"onclick=\"\"" if hover_via_click?}> #{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %> - <% else %> - <% html_classes << 'top' if options[:first_action] %> - <%= "<li #{"class=\"#{html_classes.join(' ')}\"" unless html_classes.empty?} #{"onclick=\"\"" if hover_via_click?}>#{content_tag(:div, as_(parent.name), :class => (parent.name.to_s).downcase)}<ul>".html_safe %> - <% end %> + <% html_classes = hover_via_click? ? 'hover_click ' : '' %> + <% if options[:level] == 0 %> + <% html_classes << 'action_group' %> + <%= "#{start_level_0_tag}<div class=\"#{html_classes}\" #{"onclick=\"\"" if hover_via_click?}><div class=\"#{parent.name.to_s.downcase}\">#{as_(parent.name)}</div><ul>".html_safe %> + <% else %> + <% html_classes << 'top' if options[:first_action] %> + <%= "<li#{" class=\"#{html_classes}\"" unless html_classes.empty?}#{" onclick=\"\"" if hover_via_click?}><div class=\"#{parent.name.to_s.downcase}\">#{as_(parent.name)}</div><ul>".html_safe %> + <% end %> + <% else -%> <% if options[:level] == 0 %> <%= "#{start_level_0_tag}#{render_group_action_link(link, url_options, options, record)}#{end_level_0_tag}".html_safe %> <% else %> - <%= content_tag('li', render_group_action_link(link, url_options, options, record), options[:first_action] ? {:class => 'top'}: {}) %> + <li<%= ' class="top"'.html_safe %>><%= render_group_action_link(link, url_options, options, record) %></li> <% end %> <% end -%> <% end -%> \ No newline at end of file From 16fc4fcbab7a2c7a88f7faa63fd7553f41a790a8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 6 Jul 2012 07:15:56 -1000 Subject: [PATCH 1570/2024] backwards compatible fields override --- lib/active_scaffold/helpers/list_column_helpers.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 451ddc1293..ac0d765246 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -6,7 +6,11 @@ module ListColumnHelpers def get_column_value(record, column) begin method = get_column_method(record, column) - value = send(method, record, column) + value = if method(method).arity == 1 + send(method, record) + else + send(method, record, column) + end value = ' '.html_safe if value.nil? or value.blank? # fix for IE 6 return value rescue Exception => e From a19eca0df6b806bbb19dfd66d012ac1ab778e8fa Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 9 Jul 2012 10:48:41 +0200 Subject: [PATCH 1571/2024] add deprecation warning about field override signature change --- lib/active_scaffold/helpers/list_column_helpers.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index ac0d765246..ff9c57ca1a 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -7,6 +7,7 @@ def get_column_value(record, column) begin method = get_column_method(record, column) value = if method(method).arity == 1 + ActiveSupport::Deprecation.warn("Add column argument to field override, signature is unified with list_ui") send(method, record) else send(method, record, column) From d4ad0540cd2091007a1d1a7e9f23bed0b72b7bb5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 9 Jul 2012 14:40:27 +0200 Subject: [PATCH 1572/2024] optimization: cache action links url generation --- .../default/views/_action_group.html.erb | 4 +- frontends/default/views/_list_header.html.erb | 1 - .../default/views/_list_messages.html.erb | 2 +- frontends/default/views/_list_record.html.erb | 5 +- .../default/views/_update_actions.html.erb | 2 +- frontends/default/views/update.html.erb | 2 +- lib/active_scaffold/config/list.rb | 2 +- .../data_structures/action_link.rb | 4 +- .../helpers/controller_helpers.rb | 6 +- .../helpers/list_column_helpers.rb | 12 +-- lib/active_scaffold/helpers/view_helpers.rb | 102 +++++++++++++----- 11 files changed, 92 insertions(+), 50 deletions(-) diff --git a/frontends/default/views/_action_group.html.erb b/frontends/default/views/_action_group.html.erb index e4a8d9038a..40443cb006 100644 --- a/frontends/default/views/_action_group.html.erb +++ b/frontends/default/views/_action_group.html.erb @@ -17,9 +17,9 @@ <% else -%> <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}#{render_group_action_link(link, url_options, options, record)}#{end_level_0_tag}".html_safe %> + <%= "#{start_level_0_tag}#{render_group_action_link(link, options, record)}#{end_level_0_tag}".html_safe %> <% else %> - <li<%= ' class="top"'.html_safe %>><%= render_group_action_link(link, url_options, options, record) %></li> + <li<%= ' class="top"'.html_safe %>><%= render_group_action_link(link, options, record) %></li> <% end %> <% end -%> <% end -%> \ No newline at end of file diff --git a/frontends/default/views/_list_header.html.erb b/frontends/default/views/_list_header.html.erb index e46c82ca9d..fc3136a080 100644 --- a/frontends/default/views/_list_header.html.erb +++ b/frontends/default/views/_list_header.html.erb @@ -2,7 +2,6 @@ unless action_links.empty? -%> <div class="actions"> <%= render :partial => 'action_group', :locals => {:action_links => action_links, - :url_options => params_for, :traverse_options => nested? ? {:reverse => true} : {}} %> <%= loading_indicator_tag(:action => :table) %> </div> diff --git a/frontends/default/views/_list_messages.html.erb b/frontends/default/views/_list_messages.html.erb index d1a965bbce..5428637f20 100644 --- a/frontends/default/views/_list_messages.html.erb +++ b/frontends/default/views/_list_messages.html.erb @@ -14,7 +14,7 @@ <% if active_scaffold_config.list.show_search_reset && @filtered -%> <div class="reset"> <%= loading_indicator_tag(:action => :record, :id => nil) %> - <%= render_action_link(active_scaffold_config.list.reset_link, params_for(:search => '')) %> + <%= render_action_link(active_scaffold_config.list.reset_link) %> </div> <% end -%> </div> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 23228670f9..7acf1eaee4 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -2,7 +2,7 @@ record = list_record if list_record # compat with render :partial :collection columns ||= list_columns tr_class = cycle("", "even-record") + ' ' + list_row_class(record) -url_options = params_for(:action => :list, :id => record.id) +url_options = params_for(:action => :list, :id => '--ID--') action_links ||= active_scaffold_config.action_links.member data_refresh ||= url_for(params_for(:action => :row, :id => '--ID--', :_method => :get)) -%> @@ -23,7 +23,6 @@ data_refresh ||= url_for(params_for(:action => :row, :id => '--ID--', :_method = <%= loading_indicator_tag(:action => :record, :id => record.id) %> </td> <%= render :partial => 'action_group', :locals => {:action_links => action_links, - :url_options => url_options, :record => record, :traverse_options => {:for => record.persisted? ? record : record.class}, :start_level_0_tag => '<td>', @@ -32,5 +31,5 @@ data_refresh ||= url_for(params_for(:action => :row, :id => '--ID--', :_method = </table></td> - <%= render_nested_view(action_links, url_options, record) unless @nested_auto_open.nil? %> + <%= render_nested_view(action_links, record) unless @nested_auto_open.nil? %> </tr> diff --git a/frontends/default/views/_update_actions.html.erb b/frontends/default/views/_update_actions.html.erb index 9993dba6cf..2baff6925f 100644 --- a/frontends/default/views/_update_actions.html.erb +++ b/frontends/default/views/_update_actions.html.erb @@ -3,7 +3,7 @@ <% active_scaffold_config.action_links.member.each do |link| -%> <% next unless link.action == 'index' -%> <% next if skip_action_link(link) -%> - <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, url_options, record) : "<a class='disabled'>#{link.label}</a>" -%> + <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, record) : "<a class='disabled'>#{link.label}</a>" -%> <% end -%> </div> </div> diff --git a/frontends/default/views/update.html.erb b/frontends/default/views/update.html.erb index 3909b937e3..529fe95e17 100644 --- a/frontends/default/views/update.html.erb +++ b/frontends/default/views/update.html.erb @@ -1,7 +1,7 @@ <div class="active-scaffold"> <div class="update-view <%= "#{id_from_controller params[:controller]}-view" %> view"> <% if active_scaffold_config.update.nested_links and active_scaffold_config.action_links.member.empty? -%> - <%= render :partial => 'update_actions', :locals => {:record => @record, :url_options => params_for(:action => :list, :id => @record.id)} %> + <%= render :partial => 'update_actions', :locals => {:record => @record} %> <% end -%> <%= render :partial => 'update_form' -%> </div> diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 9894cd2875..e4f783edc7 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -67,7 +67,7 @@ def page_links_window=(value) # the ActionLink to reset search cattr_reader :reset_link - @@reset_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :collection, :position => false) + @@reset_link = ActiveScaffold::DataStructures::ActionLink.new('index', :label => :click_to_reset, :type => :collection, :position => false, :parameters => {:search => ''}) # wrap normal cells (not inplace editable columns or with link) with a tag # it allows for more css styling diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 7f6b37886b..6843933cb7 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -177,8 +177,8 @@ def nested_link? @column || (parameters && parameters[:named_scope]) end - # Internal use: generated eid for this action_link - attr_accessor :eid + # Internal use: generated url for this action_link + attr_accessor :cached_url end diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 7d6ba156cb..3452e0d706 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -2,14 +2,10 @@ module ActiveScaffold module Helpers module ControllerHelpers def self.included(controller) - controller.class_eval { helper_method :params_for, :params_conditions, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated} + controller.class_eval { helper_method :params_for, :conditions_from_params, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated} end include ActiveScaffold::Helpers::IdHelpers - - def params_conditions - conditions_from_params.keys - end def params_for(options = {}) # :adapter and :position are one-use rendering arguments. they should not propagate. diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index ff9c57ca1a..3786ad4a5c 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -49,18 +49,18 @@ def render_list_column(text, column, record) if column.link link = column.link associated = record.send(column.association.name) if column.association - url_options = params_for(:action => nil, :id => record.id) + html_options = {} # setup automatic link if column.autolink? && column.singular_association? # link to inline form link = action_link_to_inline_form(column, record, associated, text) return text if link.nil? else - url_options[:link] = text + html_options[:link] = text end if column_link_authorized?(link, column, record, associated) - render_action_link(link, url_options, record) + render_action_link(link, record, html_options) else "<a class='disabled'>#{text}</a>".html_safe end @@ -371,12 +371,12 @@ def column_heading_value(column, sorting, sort_direction) end end - def render_nested_view(action_links, url_options, record) + def render_nested_view(action_links, record) rendered = [] action_links.member.each do |link| if link.nested_link? && link.column && @nested_auto_open[link.column.name] && @records.length <= @nested_auto_open[link.column.name] && controller.respond_to?(:render_component_into_view) - link_url_options = {:adapter => '_list_inline_adapter', :format => :js}.merge(action_link_url_options(link, url_options, record, options = {:reuse_eid => true})) - link_id = get_action_link_id(link_url_options, record, link.column) + link_url_options = {:adapter => '_list_inline_adapter', :format => :js}.merge(action_link_url_options(link, record)) + link_id = get_action_link_id(link, record) rendered << (controller.send(:render_component_into_view, link_url_options) + javascript_tag("ActiveScaffold.ActionLink.get('#{link_id}').set_opened();")) end end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 53686e7e08..c173dcb308 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -103,39 +103,92 @@ def skip_action_link(link, *args) (!link.ignore_method.nil? && controller.respond_to?(link.ignore_method) && controller.send(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args)) end - def render_action_link(link, url_options, record = nil, html_options = {}) - url_options = action_link_url_options(link, url_options, record) - html_options = action_link_html_options(link, url_options, record, html_options) - action_link_html(link, url_options, html_options, record) + def render_action_link(link, record = nil, html_options = {}) + url = action_link_url(link, record) + html_options = action_link_html_options(link, record, html_options) + action_link_html(link, url, html_options, record) end - def render_group_action_link(link, url_options, options, record = nil) + def render_group_action_link(link, options, record = nil) if link.type == :member && !options[:authorized] action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}, record) else - render_action_link(link, url_options, record) + render_action_link(link, record) end end - def action_link_url_options(link, url_options, record, options = {}) - url_options = url_options.clone - url_options[:action] = link.action + def action_link_url(link, record) + url = if link.cached_url + link.cached_url + else + url = url_for(action_link_url_options(link, record)) + link.cached_url = url unless link.dynamic_parameters.is_a?(Proc) + url + end + + url = record ? url.sub('--ID--', record.id.to_s) : url + query_string, non_nested_query_string = query_string_for_action_links(link) + if query_string || (!link.nested_link? && non_nested_query_string) + url << (url.include?('?') ? '&' : '?') + url << query_string if query_string + url << non_nested_query_string if !link.nested_link? && non_nested_query_string + end + url + end + + def query_string_for_action_links(link) + if defined?(@query_string) && link.parameters.none? { |k, v| @query_string_params.include? k } + return [@query_string, @non_nested_query_string] + end + keep = true + @query_string_params = Set.new + query_string_for_all = nil + query_string_options = [] + non_nested_query_string_options = [] + + params_for.except(:controller, :action, :id).each do |key, value| + if link.parameters.include? key + keep = false + next + end + @query_string_params << key + qs = "#{key}=#{value}" + if key == :eid || conditions_from_params.include?(key) || (nested? && nested.constrained_fields.include?(key)) + non_nested_query_string_options << qs + else + query_string_options << qs + end + end + + query_string = URI.escape(query_string_options.join('&')) if query_string_options.present? + if non_nested_query_string_options.present? + non_nested_query_string = "#{'&' if query_string}#{URI.escape(non_nested_query_string_options.join('&'))}" + end + if keep + @query_string = query_string + @non_nested_query_string = non_nested_query_string + end + [query_string, non_nested_query_string] + end + + def action_link_url_options(link, record) + url_options = {:action => link.action} + url_options[:id] = '--ID--' unless record.nil? url_options[:controller] = link.controller.to_s if link.controller - url_options.delete(:search) if link.controller and link.controller.to_s != params[:controller] url_options.merge! link.parameters if link.parameters if link.dynamic_parameters.is_a?(Proc) @link_record = record url_options.merge! self.instance_eval(&(link.dynamic_parameters)) @link_record = nil end - url_options_for_nested_link(link.column, record, link, url_options, options) if link.nested_link? - url_options_for_sti_link(link.column, record, link, url_options, options) unless record.nil? || active_scaffold_config.sti_children.nil? + url_options_for_nested_link(link.column, record, link, url_options) if link.nested_link? + url_options_for_sti_link(link.column, record, link, url_options) unless record.nil? || active_scaffold_config.sti_children.nil? url_options[:_method] = link.method if !link.confirm? && link.inline? && link.method != :get url_options end - def action_link_html_options(link, url_options, record, html_options) - link_id = get_action_link_id(url_options, record, link.column) + def action_link_html_options(link, record, html_options) + link_id = get_action_link_id(link, record) html_options.reverse_merge! link.html_options.merge(:class => link.action.to_s) # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails @@ -167,8 +220,9 @@ def action_link_html_options(link, url_options, record, html_options) html_options end - def get_action_link_id(url_options, record = nil, column = nil) - id = url_options[:id] || url_options[:parent_id] + def get_action_link_id(link, record = nil, column = nil) + column ||= link.column + id = record ? record.id.to_s : (nested? ? nested.parent_id : '') if column && column.plural_association? id = "#{column.association.name}-#{record.id}" elsif column && column.singular_association? @@ -178,14 +232,12 @@ def get_action_link_id(url_options, record = nil, column = nil) id = "#{column.association.name}-#{record.id}" unless record.nil? end end - id = "#{id}-#{url_options[:batch_scope].downcase}" if url_options[:batch_scope] - action_id = "#{id_from_controller(url_options[:controller]) + '-' if url_options[:parent_controller]}#{url_options[:action].to_s}" + action_id = "#{id_from_controller("#{link.controller}-") if params[:parent_controller]}#{link.action}" action_link_id(action_id, id) end def action_link_html(link, url, html_options, record) - # issue 260, use url_options[:link] if it exists. This prevents DB data from being localized. - label = url.delete(:link) if url.is_a?(Hash) + label = html_options.delete(:link) label ||= link.label label = image_tag(link.image[:name], :size => link.image[:size], :alt => label, :title => label) if link.image if url.nil? @@ -195,22 +247,18 @@ def action_link_html(link, url, html_options, record) end end - def url_options_for_nested_link(column, record, link, url_options, options = {}) + def url_options_for_nested_link(column, record, link, url_options) if column && column.association url_options[:parent_scaffold] = controller_path url_options[column.association.active_record.name.foreign_key.to_sym] = url_options.delete(:id) - url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present? - url_options[:eid] = nil # needed for nested scaffolds open from an embedded scaffold + #url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present? FIXME on fixing singular nested links elsif link.parameters && link.parameters[:named_scope] url_options[:parent_scaffold] = controller_path url_options[active_scaffold_config.model.name.foreign_key.to_sym] = url_options.delete(:id) - url_options[:eid] = nil # needed for nested scaffolds open from an embedded scaffold end - url_options.except! *params_conditions - url_options.except! *nested.constrained_fields if nested? end - def url_options_for_sti_link(column, record, link, url_options, options = {}) + def url_options_for_sti_link(column, record, link, url_options) #need to find out controller of current record type #and set parameters # its quite difficult to detect an sti link From 7956022d53ac90c4ed2134b2eac0dc16c1d3fa7a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 9 Jul 2012 14:53:02 +0200 Subject: [PATCH 1573/2024] add keep_open to action links --- app/assets/javascripts/jquery/active_scaffold.js | 5 ++++- app/assets/javascripts/prototype/active_scaffold.js | 6 +++++- lib/active_scaffold/data_structures/action_link.rb | 6 ++++++ lib/active_scaffold/helpers/view_helpers.rb | 3 ++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index a35fbe38cb..7555266c2f 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -974,6 +974,9 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ this.adapter.addClass('as_adapter'); this.adapter.data('action_link', this); if (this.refresh_url) jQuery('.as_cancel', this.adapter).attr('href', this.refresh_url); + }, + keep_open: function() { + return this.tag.data('keep-open'); } }); @@ -999,7 +1002,7 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ close_previous_adapter: function() { var _this = this; jQuery.each(this.set.links, function(index, item) { - if (item.url != _this.url && item.is_disabled() && item.adapter) { + if (item.url != _this.url && item.is_disabled() && !item.keep_open() && item.adapter) { item.enable(); item.adapter.remove(); } diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 8a2d83b0a4..84444be8c3 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -868,6 +868,10 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ this.adapter = element; this.adapter.addClassName('as_adapter'); this.adapter.store('action_link', this); + }, + + keep_open: function() { + return !this.tag.readAttribute('data-keep-open').blank(); } }); @@ -891,7 +895,7 @@ ActiveScaffold.Actions.Record = Class.create(ActiveScaffold.Actions.Abstract, { ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstract, { close_previous_adapter: function() { this.set.links.each(function(item) { - if (item.url != this.url && item.is_disabled() && item.adapter) { + if (item.url != this.url && item.is_disabled() && !item.keep_open() && item.adapter) { item.enable(); item.adapter.remove(); } diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 6843933cb7..cb1eea4373 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -172,6 +172,12 @@ def position # nested action_links are referencing a column attr_accessor :column + # don't close the panel when another action link is open + attr_writer :keep_open + def keep_open? + @keep_open + end + # indicates that this a nested_link def nested_link? @column || (parameters && parameters[:named_scope]) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index c173dcb308..ea74bcdf7a 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -200,7 +200,8 @@ def action_link_html_options(link, record, html_options) html_options[:class] += ' as_action' html_options[:data][:position] = link.position if link.position html_options[:data][:action] = link.action - html_options[:data][:'cancel-refresh'] = true if link.refresh_on_close + html_options[:data][:cancel_refresh] = true if link.refresh_on_close + html_options[:data][:keep_open] = true if link.keep_open? end if link.popup? html_options[:data][:popup] = true From 830aef8431934872e53b53ede26de72512baad27 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 9 Jul 2012 14:57:46 +0200 Subject: [PATCH 1574/2024] fix reset link in search and field search --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- app/assets/javascripts/prototype/active_scaffold.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 7555266c2f..0e92e55e1f 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -72,7 +72,7 @@ jQuery(document).ready(function() { if (action_link) { var cancel_url = as_cancel.attr('href'); - var refresh_data = action_link.tag.data('cancel-refresh'); + var refresh_data = action_link.tag.data('cancel-refresh') || as_cancel.data('refresh'); if (!refresh_data || !cancel_url) { action_link.close(); return false; diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 84444be8c3..dd8240d6c2 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -95,7 +95,7 @@ document.observe("dom:loaded", function() { var action_link = ActiveScaffold.find_action_link(as_cancel); if (action_link) { - var refresh_data = action_link.readAttribute('data-cancel-refresh'); + var refresh_data = action_link.readAttribute('data-cancel-refresh') || as_cancel.readAttribute('data-refresh'); if (refresh_data && action_link.refresh_url) { event.memo.url = action_link.refresh_url; } else if (!refresh_data || as_cancel.readAttribute('href').blank()) { From 5cdf309bbb3f74b70ad05aea76c86708804cfbcf Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 9 Jul 2012 21:00:02 -1000 Subject: [PATCH 1575/2024] fix nested links in nested scaffolds --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index ea74bcdf7a..efc2f65940 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -153,7 +153,7 @@ def query_string_for_action_links(link) end @query_string_params << key qs = "#{key}=#{value}" - if key == :eid || conditions_from_params.include?(key) || (nested? && nested.constrained_fields.include?(key)) + if [:eid, :parent_scaffold].include?(key) || conditions_from_params.include?(key) || (nested? && nested.constrained_fields.include?(key)) non_nested_query_string_options << qs else query_string_options << qs From 98e75c05bb3774abeb706fd587b889499a1ab068 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 10 Jul 2012 11:07:06 +0200 Subject: [PATCH 1576/2024] clean associated_valid? --- lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/actions/update.rb | 2 +- lib/active_scaffold/extensions/unsaved_associated.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 87283cdab7..2c96640cc1 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -92,7 +92,7 @@ def do_create(options = {}) apply_constraints_to_record(@record, :allow_autosave => true) create_association_with_parent(@record) if nested? before_create_save(@record) - self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit + self.successful = [@record.valid?, @record.associated_valid?].all? # this syntax avoids a short-circuit create_save(@record) unless options[:skip_save] end rescue ActiveRecord::ActiveRecordError => ex diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index b972a74001..ce25b5a877 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -81,7 +81,7 @@ def update_save(options = {}) active_scaffold_config.model.transaction do @record = update_record_from_params(@record, active_scaffold_config.update.columns, attributes) unless options[:no_record_param_update] before_update_save(@record) - self.successful = [@record.valid?, @record.associated_valid?].all? {|v| v == true} # this syntax avoids a short-circuit + self.successful = [@record.valid?, @record.associated_valid?].all? # this syntax avoids a short-circuit if successful? @record.save! and @record.save_associated! after_update_save(@record) diff --git a/lib/active_scaffold/extensions/unsaved_associated.rb b/lib/active_scaffold/extensions/unsaved_associated.rb index c2683c99a9..c683cff192 100644 --- a/lib/active_scaffold/extensions/unsaved_associated.rb +++ b/lib/active_scaffold/extensions/unsaved_associated.rb @@ -4,7 +4,7 @@ def associated_valid?(path = []) return true if path.include?(self) # prevent recursion (if associated and parent are new records) path << self # using [].all? syntax to avoid a short-circuit - with_unsaved_associated { |a| [a.valid?, a.associated_valid?(path)].all? {|v| v == true} } + with_unsaved_associated { |a| [a.valid?, a.associated_valid?(path)].all? } end def save_associated @@ -31,7 +31,7 @@ def no_errors_in_associated? # only those associations will be traversed. # # Otherwise the default behaviour of traversing all associations will be preserved. - def associations_for_update + def associations_for_update(columns) if self.respond_to?( :scaffold_update_nofollow ) self.class.reflect_on_all_associations.reject { |association| self.scaffold_update_nofollow.include?( association.name ) } elsif self.respond_to?( :scaffold_update_follow ) From 4ee94c2f0be671698833a67971c4f912bcb94de8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 10 Jul 2012 11:11:55 +0200 Subject: [PATCH 1577/2024] fix last commit --- lib/active_scaffold/extensions/unsaved_associated.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/unsaved_associated.rb b/lib/active_scaffold/extensions/unsaved_associated.rb index c683cff192..fd6817ed94 100644 --- a/lib/active_scaffold/extensions/unsaved_associated.rb +++ b/lib/active_scaffold/extensions/unsaved_associated.rb @@ -31,7 +31,7 @@ def no_errors_in_associated? # only those associations will be traversed. # # Otherwise the default behaviour of traversing all associations will be preserved. - def associations_for_update(columns) + def associations_for_update if self.respond_to?( :scaffold_update_nofollow ) self.class.reflect_on_all_associations.reject { |association| self.scaffold_update_nofollow.include?( association.name ) } elsif self.respond_to?( :scaffold_update_follow ) From 93a5383ce4c5f74a0c1b211fd86cbc86379bc5ee Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 10 Jul 2012 11:15:34 +0200 Subject: [PATCH 1578/2024] fix caching url for collection links in nested scaffolds --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index efc2f65940..b7f98d5e21 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -126,7 +126,7 @@ def action_link_url(link, record) url end - url = record ? url.sub('--ID--', record.id.to_s) : url + url = record ? url.sub('--ID--', record.id.to_s) : url.clone query_string, non_nested_query_string = query_string_for_action_links(link) if query_string || (!link.nested_link? && non_nested_query_string) url << (url.include?('?') ? '&' : '?') From abe9df52d66bee28f25128703ae3f26b6e128158 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 10 Jul 2012 11:17:11 +0200 Subject: [PATCH 1579/2024] update changelog --- CHANGELOG | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index fd0a6bdb33..da5face548 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,10 @@ -= 3.2.13 (not released yet) += 3.2.15 (not released yet) +- Prepare to unify field overrides and list_ui method signatures + += 3.2.14 +- Fix default sorting, it was broken in 3.2.13 + += 3.2.13 - Fix destroy action, was broken in 3.2.12 - Remove default :method sorting for associations, it wasn't useful and can be slow - Rescue from ActiveScaffold::ActionNotAllowed and ActiveScaffold::RecordNotAllowed with 401 response, it can be overrided with deny_access method in ApplicationController. From 5087d4987ace9d04d00d7f5616e9e61f98f30a9d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 10 Jul 2012 11:20:42 +0200 Subject: [PATCH 1580/2024] update changelog --- CHANGELOG | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index da5face548..6d31f75037 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ += master +- Unify field overrides and list_ui method signatures +- Improve performance removing some partials and adding some caching for helper overrides and UIs, and caching url generation for lists + = 3.2.15 (not released yet) - Prepare to unify field overrides and list_ui method signatures From a0b9b80aff459ff1c355dd41bfa11458d156bb2e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 10 Jul 2012 11:22:14 +0200 Subject: [PATCH 1581/2024] fix show overrides, broken with list_ui signature change --- lib/active_scaffold/helpers/show_column_helpers.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/show_column_helpers.rb b/lib/active_scaffold/helpers/show_column_helpers.rb index 376cb150a9..ea5f623ab5 100644 --- a/lib/active_scaffold/helpers/show_column_helpers.rb +++ b/lib/active_scaffold/helpers/show_column_helpers.rb @@ -8,7 +8,12 @@ def show_column_value(record, column) # we only pass the record as the argument. we previously also passed the formatted_value, # but mike perham pointed out that prohibited the usage of overrides to improve on the # performance of our default formatting. see issue #138. - send(method, record) + if method(method).arity == 1 + ActiveSupport::Deprecation.warn("Add column argument to field override, signature is unified with list_ui") + send(method, record) + else + send(method, record, column) + end # second, check if the dev has specified a valid list_ui for this column elsif column.list_ui and (method = override_show_column_ui(column.list_ui)) send(method, column, record) @@ -21,7 +26,7 @@ def show_column_value(record, column) end end - def active_scaffold_show_text(column, record) + def active_scaffold_show_text(record, column) simple_format(clean_column_value(record.send(column.name))) end From bb7f415ca5c04d8f625db244c95a16d0d4e8079d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 10 Jul 2012 13:34:03 +0200 Subject: [PATCH 1582/2024] fix #171 nested form links broken --- lib/active_scaffold/helpers/view_helpers.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index b7f98d5e21..35652d7687 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -127,6 +127,7 @@ def action_link_url(link, record) end url = record ? url.sub('--ID--', record.id.to_s) : url.clone + url = url.sub('--CHILD_ID--', record.send(link.column.association.name).id.to_s) if link.column.try(:singular_association?) && record.send(link.column.association.name).present? query_string, non_nested_query_string = query_string_for_action_links(link) if query_string || (!link.nested_link? && non_nested_query_string) url << (url.include?('?') ? '&' : '?') @@ -252,7 +253,7 @@ def url_options_for_nested_link(column, record, link, url_options) if column && column.association url_options[:parent_scaffold] = controller_path url_options[column.association.active_record.name.foreign_key.to_sym] = url_options.delete(:id) - #url_options[:id] = record.send(column.association.name).id if column.singular_association? && record.send(column.association.name).present? FIXME on fixing singular nested links + url_options[:id] = '--CHILD_ID--' if column.singular_association? && record.send(column.association.name).present? # FIXME on fixing singular nested links elsif link.parameters && link.parameters[:named_scope] url_options[:parent_scaffold] = controller_path url_options[active_scaffold_config.model.name.foreign_key.to_sym] = url_options.delete(:id) From 913c4bbae942200d94733606235880b398a0b748 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 10 Jul 2012 14:13:37 +0200 Subject: [PATCH 1583/2024] drop rails 3.1 support --- CHANGELOG | 1 + active_scaffold.gemspec | 2 +- .../extensions/action_controller_rescueing.rb | 1 + .../extensions/active_association_reflection.rb | 2 -- .../extensions/active_record_offset.rb | 12 ------------ .../extensions/nil_id_in_url_params.rb | 7 ------- 6 files changed, 3 insertions(+), 22 deletions(-) delete mode 100644 lib/active_scaffold/extensions/active_record_offset.rb delete mode 100644 lib/active_scaffold/extensions/nil_id_in_url_params.rb diff --git a/CHANGELOG b/CHANGELOG index 6d31f75037..ce0e4b3971 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ = master - Unify field overrides and list_ui method signatures - Improve performance removing some partials and adding some caching for helper overrides and UIs, and caching url generation for lists +- Drop support for rails 3.1 = 3.2.15 (not released yet) - Prepare to unify field overrides and list_ui method signatures diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index db8fd8d78e..4e5984d8cb 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -25,6 +25,6 @@ Gem::Specification.new do |s| s.add_development_dependency(%q<bundler>, ["~> 1.0.0"]) s.add_development_dependency(%q<rcov>, [">= 0"]) #s.add_runtime_dependency(%q<render_component_vho>, [">= 0"]) - s.add_runtime_dependency(%q<rails>, [">= 3.1.3"]) + s.add_runtime_dependency(%q<rails>, "~> 3.2.0") end diff --git a/lib/active_scaffold/extensions/action_controller_rescueing.rb b/lib/active_scaffold/extensions/action_controller_rescueing.rb index 56d46c8dbb..69745f1396 100644 --- a/lib/active_scaffold/extensions/action_controller_rescueing.rb +++ b/lib/active_scaffold/extensions/action_controller_rescueing.rb @@ -1,5 +1,6 @@ module ActionController #:nodoc: class Base + # adding to ActionController::Base so it can overrided in ApplicationController def deny_access head :unauthorized end diff --git a/lib/active_scaffold/extensions/active_association_reflection.rb b/lib/active_scaffold/extensions/active_association_reflection.rb index 561ed60e58..7cce939990 100644 --- a/lib/active_scaffold/extensions/active_association_reflection.rb +++ b/lib/active_scaffold/extensions/active_association_reflection.rb @@ -12,11 +12,9 @@ def klass_with_sti(*opts) end end def build_association(*opts, &block) - @original_build_association_called = true # FIXME: remove when 3.1 support is dropped klass_with_sti(*opts).new(*opts, &block) end def create_association(*opts, &block) - @original_build_association_called = true # FIXME: remove when 3.1 support is dropped klass_with_sti(*opts).create(*opts, &block) end end diff --git a/lib/active_scaffold/extensions/active_record_offset.rb b/lib/active_scaffold/extensions/active_record_offset.rb deleted file mode 100644 index 4bbd6d9779..0000000000 --- a/lib/active_scaffold/extensions/active_record_offset.rb +++ /dev/null @@ -1,12 +0,0 @@ -# Bugfix: Team.offset(1).limit(1) throws an error -ActiveRecord::Base.instance_eval do - def offset(*args, &block) - scoped.__send__(:offset, *args, &block) - rescue NoMethodError - if scoped.nil? - 'depends on :allow_nil' - else - raise - end - end -end diff --git a/lib/active_scaffold/extensions/nil_id_in_url_params.rb b/lib/active_scaffold/extensions/nil_id_in_url_params.rb deleted file mode 100644 index 29be1d3340..0000000000 --- a/lib/active_scaffold/extensions/nil_id_in_url_params.rb +++ /dev/null @@ -1,7 +0,0 @@ -class ActionController::Routing::RouteSet - def generate_with_nil_id_awareness(*args) - args[0].delete(:id) if args[0][:id].nil? - generate_without_nil_id_awareness(*args) - end - alias_method_chain :generate, :nil_id_awareness -end \ No newline at end of file From 18cbffb818a60c8afffc2dda47b5579dd1b5e4a3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 10 Jul 2012 21:09:21 -1000 Subject: [PATCH 1584/2024] fix nested links in nested scaffolds --- frontends/default/views/_list_record.html.erb | 1 - lib/active_scaffold/helpers/view_helpers.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 7acf1eaee4..2cb509783a 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -2,7 +2,6 @@ record = list_record if list_record # compat with render :partial :collection columns ||= list_columns tr_class = cycle("", "even-record") + ' ' + list_row_class(record) -url_options = params_for(:action => :list, :id => '--ID--') action_links ||= active_scaffold_config.action_links.member data_refresh ||= url_for(params_for(:action => :row, :id => '--ID--', :_method => :get)) -%> diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 35652d7687..14dc898e17 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -154,7 +154,7 @@ def query_string_for_action_links(link) end @query_string_params << key qs = "#{key}=#{value}" - if [:eid, :parent_scaffold].include?(key) || conditions_from_params.include?(key) || (nested? && nested.constrained_fields.include?(key)) + if [:eid, :association, :parent_scaffold].include?(key) || conditions_from_params.include?(key) || (nested? && nested.constrained_fields.include?(key)) non_nested_query_string_options << qs else query_string_options << qs From 1349fd0e80173031019ec7b6ab3aed8a2a70de27 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 11 Jul 2012 02:18:18 -1000 Subject: [PATCH 1585/2024] add persistent :optional to update action --- app/assets/javascripts/jquery/active_scaffold.js | 1 + config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/locales/es.yml | 1 + config/locales/fr.yml | 1 + config/locales/hu.yml | 1 + config/locales/ja.yml | 1 + config/locales/ru.yml | 1 + frontends/default/views/_base_form.html.erb | 5 ++++- frontends/default/views/on_update.js.erb | 10 +++++++--- 10 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 0e92e55e1f..66493884b8 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -547,6 +547,7 @@ var ActiveScaffold = { } else { server_error.show(); } + ActiveScaffold.scroll_to(server_error, ActiveScaffold.config.scroll_on_close == 'checkInViewport'); }, find_action_link: function(element) { diff --git a/config/locales/de.yml b/config/locales/de.yml index fae85ec7b1..140e79e232 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -6,6 +6,7 @@ de: add: 'Hinzufügen' add_existing: 'Existierenden Eintrag hinzufügen' add_existing_model: 'Existierende %{model} hinzufügen' + apply: 'Apply' are_you_sure_to_delete: 'Sind Sie sicher?' cancel: 'Abbrechen' click_to_edit: 'Zum Editieren anklicken' diff --git a/config/locales/en.yml b/config/locales/en.yml index f951ec7594..7b89df8c78 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -6,6 +6,7 @@ en: add: 'Add' add_existing: 'Add Existing' add_existing_model: 'Add Existing %{model}' + apply: 'Apply' are_you_sure_to_delete: 'Are you sure you want to delete %{label}?' cancel: 'Cancel' click_to_edit: 'Click to edit' diff --git a/config/locales/es.yml b/config/locales/es.yml index b7e52fa78f..7b9c3cf0f4 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -6,6 +6,7 @@ es: add: 'Añadir' add_existing: 'Añadir Existente' add_existing_model: 'Añadir %{model} Existente' + apply: 'Aplicar' are_you_sure_to_delete: '¿Estás seguro de que quieres borrar %{label}?' cancel: 'Cancelar' click_to_edit: 'Pulsa para editar' diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 14fe00f3a4..650ee66280 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -6,6 +6,7 @@ fr: add: 'Ajouter' add_existing: 'Ajouter un(e) existant(e)' add_existing_model: 'Ajouter un(e) %{model} existant(e)' + apply: 'Apply' are_you_sure_to_delete: 'Êtes vous sûr?' cancel: 'Annuler' click_to_edit: 'Cliquer pour éditer' diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 46fe78acaa..3cfa1b66a4 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -6,6 +6,7 @@ hu: add: 'Hozzáadás' add_existing: 'Meglevő hozzáadása' add_existing_model: 'Meglevő %{model} hozzáadása' + apply: 'Apply' are_you_sure_to_delete: 'Biztos vagy benne?' cancel: 'Mégse' click_to_edit: 'Kattints a szerkesztéshez' diff --git a/config/locales/ja.yml b/config/locales/ja.yml index a36e695ea2..830d001e0d 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -6,6 +6,7 @@ ja: add: '追加' add_existing: '既存のものを追加' add_existing_model: '既存の%{model}を追加' + apply: 'Apply' are_you_sure_to_delete: '本当によいですか?' cancel: 'キャンセル' click_to_edit: 'クリックして編集' diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 88ed002eab..410e368729 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -6,6 +6,7 @@ ru: add: 'Добавить запись' add_existing: 'Добавить существующую запись' add_existing_model: '%{model}: добавить существующую запись' + apply: 'Apply' are_you_sure_to_delete: 'Удалить %{label}?' cancel: 'Отмена' click_to_edit: 'Нажмите для редактирования' diff --git a/frontends/default/views/_base_form.html.erb b/frontends/default/views/_base_form.html.erb index f825c45434..6b7e742615 100644 --- a/frontends/default/views/_base_form.html.erb +++ b/frontends/default/views/_base_form.html.erb @@ -5,9 +5,11 @@ if active_scaffold_config.actions.include? form_action multipart ||= active_scaffold_config.send(form_action).multipart? columns ||= active_scaffold_config.send(form_action).columns + persistent ||= active_scaffold_config.send(form_action).persistent else multipart ||= false columns ||= nil + persistent ||= false end method ||= :post cancel_link = true if cancel_link.nil? @@ -40,7 +42,8 @@ end <%= render :partial => body_partial, :locals => { :columns => columns, :form_action => form_action, :scope => scope } %> <p class="form-footer"> - <%= submit_tag as_(submit_text), :class => "submit" %> + <%= submit_tag as_(submit_text), :class => "submit" if !persistent || persistent == :optional %> + <%= submit_tag as_(:apply), :class => "submit", :name => 'dont_close' if persistent %> <%= link_to(as_(:cancel), main_path_to_return, cancel_options) if cancel_link %> <%= loading_indicator_tag(:action => form_action, :id => params[:id]) %> <%= render :partial => footer_extension, :locals => { :form_action => form_action } if footer_extension %> diff --git a/frontends/default/views/on_update.js.erb b/frontends/default/views/on_update.js.erb index 65a8a63eef..be14d24528 100644 --- a/frontends/default/views/on_update.js.erb +++ b/frontends/default/views/on_update.js.erb @@ -3,7 +3,12 @@ try { var action_link = ActiveScaffold.find_action_link('<%= form_selector %>'); action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'messages')) %>'); <% if controller.send :successful? %> - <% if !active_scaffold_config.update.persistent %> + <% if params[:dont_close] %> + <% row_selector = element_row_id(:action => :list, :id => @record.id) %> + ActiveScaffold.update_row('<%= row_selector %>', '<%= escape_javascript(render(:partial => 'list_record', :locals => {:record => @record})) %>'); + <%= render :partial => 'update_calculations', :formats => [:js] %> + ActiveScaffold.scroll_to('<%= row_selector %>', true); + <% else %> <% if render_parent? %> <% if nested_singular_association? || render_parent_action == :row %> action_link.close(true); @@ -13,8 +18,7 @@ action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'mes <% elsif update_refresh_list? %> <%= render :partial => 'refresh_list' %> <% else %> - <% updated_row = render :partial => 'list_record', :locals => {:record => @record} %> - action_link.close('<%= escape_javascript(updated_row) %>'); + action_link.close('<%= escape_javascript(render(:partial => 'list_record', :locals => {:record => @record})) %>'); <%= render :partial => 'update_calculations', :formats => [:js] %> <% end %> <% end %> From eb2fdba9f8dfbe1b73e3f1736b84c9c65adfbc35 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 11 Jul 2012 14:42:36 +0200 Subject: [PATCH 1586/2024] update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index ce0e4b3971..c0061e67dd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ = 3.2.15 (not released yet) - Prepare to unify field overrides and list_ui method signatures +- Add :optional to update.persistent = 3.2.14 - Fix default sorting, it was broken in 3.2.13 From a10fa2116281f98f9127d3535447b9dc3d566889 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 11 Jul 2012 20:45:31 -1000 Subject: [PATCH 1587/2024] don't scroll to row when apply changes without close --- frontends/default/views/on_update.js.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/frontends/default/views/on_update.js.erb b/frontends/default/views/on_update.js.erb index be14d24528..05c1b35222 100644 --- a/frontends/default/views/on_update.js.erb +++ b/frontends/default/views/on_update.js.erb @@ -7,7 +7,6 @@ action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'mes <% row_selector = element_row_id(:action => :list, :id => @record.id) %> ActiveScaffold.update_row('<%= row_selector %>', '<%= escape_javascript(render(:partial => 'list_record', :locals => {:record => @record})) %>'); <%= render :partial => 'update_calculations', :formats => [:js] %> - ActiveScaffold.scroll_to('<%= row_selector %>', true); <% else %> <% if render_parent? %> <% if nested_singular_association? || render_parent_action == :row %> From acab727fec294ef76fdba1f2a5ced5ad81bda152 Mon Sep 17 00:00:00 2001 From: Novikov Andrey <envek@envek.name> Date: Fri, 13 Jul 2012 14:14:38 +1000 Subject: [PATCH 1588/2024] Add support for some new HTML5 forms in column.form_ui --- .../helpers/form_column_helpers.rb | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index b722899b32..3dc68c65e0 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -192,6 +192,39 @@ def active_scaffold_input_virtual(column, options) text_field :record, column.name, options.merge(column.options) end + # Some fields from HTML5 (primarily for using in-browser validation) + # Sadly, many of them lacks browser support + + # A text box, that accepts only valid email address (in-browser validation) + def active_scaffold_input_email(column, options) + options = active_scaffold_input_text_options(options) + email_field :record, column.name, options.merge(column.options) + end + + # A text box, that accepts only valid URI (in-browser validation) + def active_scaffold_input_url(column, options) + options = active_scaffold_input_text_options(options) + url_field :record, column.name, options.merge(column.options) + end + + # A text box, that accepts only valid phone-number (in-browser validation) + def active_scaffold_input_telephone(column, options) + options = active_scaffold_input_text_options(options) + telephone_field :record, column.name, options.merge(column.options) + end + + # A spinbox control for number values (in-browser validation) + def active_scaffold_input_number(column, options) + options = active_scaffold_input_text_options(options) + number_field :record, column.name, options.merge(column.options) + end + + # A slider control for number values (in-browser validation) + def active_scaffold_input_range(column, options) + options = active_scaffold_input_text_options(options) + range_field :record, column.name, options.merge(column.options) + end + # # Column.type-based inputs # From fd727d2b787492d8a83ba16227b7ebd954c1d0ee Mon Sep 17 00:00:00 2001 From: Novikov Andrey <envek@envek.name> Date: Fri, 13 Jul 2012 14:17:00 +1000 Subject: [PATCH 1589/2024] Use numeric constraints (min, max, step) for number and range input fields from model validators --- .../helpers/form_column_helpers.rb | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 3dc68c65e0..d112172ca8 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -215,12 +215,14 @@ def active_scaffold_input_telephone(column, options) # A spinbox control for number values (in-browser validation) def active_scaffold_input_number(column, options) + options = numerical_constraints_for_column(column, options) options = active_scaffold_input_text_options(options) number_field :record, column.name, options.merge(column.options) end # A slider control for number values (in-browser validation) def active_scaffold_input_range(column, options) + options = numerical_constraints_for_column(column, options) options = active_scaffold_input_text_options(options) range_field :record, column.name, options.merge(column.options) end @@ -342,6 +344,45 @@ def active_scaffold_add_existing_label active_scaffold_config.model.model_name.human end end + + # Try to get numerical constraints from model's validators + def numerical_constraints_for_column(column, options) + validators = column.active_record_class.validators.select do |v| + v.is_a? ActiveModel::Validations::NumericalityValidator and v.attributes.include? column.name + end + equal_to = validators.map{ |v| v.options[:equal_to] }.compact.first + # If there is equal_to constraint - use it (unless otherwise specified by user) + if equal_to and not (options[:min] or options[:max]) + options[:min] = options[:max] = equal_to + else # find minimum and maximum from validators + # we can safely modify :min and :max by 1 for :greater_tnan or :less_than value only for integer values + only_integer = validators.map{ |v| v.options[:only_integer] }.compact.any? + margin = only_integer ? 1 : 0 + # Minimum + unless options[:min] + min = validators.map{ |v| v.options[:greater_than_or_equal] }.compact.max + greater_than = validators.map{ |v| v.options[:greater_than] }.compact.max + options[:min] = [min, (greater_than.nil?? nil : greater_than+margin)].compact.max + end + # Maximum + unless options[:max] + max = validators.map{ |v| v.options[:less_than_or_equal] }.compact.min + less_than = validators.map{ |v| v.options[:less_than] }.compact.min + options[:max] = [max, (less_than.nil?? nil : less_than-margin)].compact.min + end + # Set step = 2 for column values restricted to be odd or even (but only if minimum is set) + unless options[:step] + only_odd_valid = validators.map{ |v| v.options[:odd] }.compact.any? + only_even_valid = validators.map{ |v| v.options[:even] }.compact.any? + if options[:min] and options[:min].respond_to? "even?" and (only_odd_valid or only_even_valid) + options[:step] = 2 + options[:min] += 1 if only_odd_valid and not options[:min].odd? + options[:min] += 1 if only_even_valid and not options[:min].even? + end + end + end + return options + end end end end From 11d9d936790acbe23d81ee96aea0c1adb9f9ae97 Mon Sep 17 00:00:00 2001 From: Novikov Andrey <envek@envek.name> Date: Fri, 13 Jul 2012 14:23:42 +1000 Subject: [PATCH 1590/2024] Add support for required and placeholder html5 attributes --- lib/active_scaffold/data_structures/column.rb | 6 ++++++ lib/active_scaffold/helpers/form_column_helpers.rb | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 0b8be76926..3fd51fb0a7 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -43,6 +43,12 @@ def description end end + # A placeholder text, to be used inside blank text fields to describe, what should be typed in + attr_writer :placeholder + def placeholder + @placeholder || I18n.t(name, :scope => [:activerecord, :placeholder, active_record_class.to_s.underscore.to_sym], :default => '') + end + # this will be /joined/ to the :name for the td's class attribute. useful if you want to style columns on different ActiveScaffolds the same way, but the columns have different names. attr_accessor :css_class diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index d112172ca8..cbb9322323 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -70,6 +70,10 @@ def active_scaffold_input_text_options(options = {}) def active_scaffold_input_options(column, scope = nil, options = {}) name = scope ? "record#{scope}[#{column.name}]" : "record[#{column.name}]" + # Add some HTML5 attributes for in-browser validation and better user experience + options[:required] = true if column.required? + options[:placeholder] = column.placeholder if column.placeholder + # Fix for keeping unique IDs in subform id_control = "record_#{column.name}_#{[params[:eid], params[:id]].compact.join '_'}" id_control += scope_id(scope) if scope From 46a79cf9c611574ca3cb90372aa0dba97a40f366 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 12 Jul 2012 22:25:09 -1000 Subject: [PATCH 1591/2024] avoid loading associations only in list and row actions, fix for update row after update record --- lib/active_scaffold/actions/list.rb | 1 + lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index ad4ff6581d..6f0f0dcc6b 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -56,6 +56,7 @@ def row_respond_to_js # The actual algorithm to prepare for the list view def set_includes_for_list_columns + @cache_associations = true includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact self.active_scaffold_includes.concat includes_for_list_columns end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 3786ad4a5c..057a2b8409 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -253,7 +253,7 @@ def cache_association(value, column, size) Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries" elsif column.associated_limit > 0 value.target = value.find(:all, :limit => column.associated_limit + 1, :select => column.select_columns) - else + elsif @cache_associations value.target = size.to_i.zero? ? [] : [nil] end end From dcdc4ce03834854f69ef501cefbe52af8d2b3bd8 Mon Sep 17 00:00:00 2001 From: Novikov Andrey <envek@envek.name> Date: Fri, 13 Jul 2012 21:36:14 +1000 Subject: [PATCH 1592/2024] Set form.ui = :number for number columns by default. --- lib/active_scaffold/data_structures/column.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 3fd51fb0a7..72ab7eb58b 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -306,6 +306,7 @@ def initialize(name, active_record_class) #:nodoc: @options = {:format => :i18n_number} if self.number? @form_ui = :checkbox if @column and @column.type == :boolean @form_ui = :textarea if @column and @column.type == :text + @form_ui = :number if @column and self.number? @allow_add_existing = true @form_ui = self.class.association_form_ui if @association && self.class.association_form_ui From 5a483d63c6954b2eeaecbe7a1b030f0695b2d8c7 Mon Sep 17 00:00:00 2001 From: Novikov Andrey <envek@envek.name> Date: Fri, 13 Jul 2012 21:37:19 +1000 Subject: [PATCH 1593/2024] Cache numerical constraints in column for number columns --- lib/active_scaffold/data_structures/column.rb | 3 + .../helpers/form_column_helpers.rb | 65 ++++++++++--------- 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 72ab7eb58b..9309bcee09 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -359,6 +359,9 @@ def number_to_native(value) # to cache method to get value in list attr_accessor :list_method + # cache constraints for numeric columns (get in ActiveScaffold::Helpers::FormColumnHelpers::numerical_constraints_for_column) + attr_accessor :numerical_constraints + protected def initialize_sort diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index cbb9322323..f9966708aa 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -351,39 +351,44 @@ def active_scaffold_add_existing_label # Try to get numerical constraints from model's validators def numerical_constraints_for_column(column, options) - validators = column.active_record_class.validators.select do |v| - v.is_a? ActiveModel::Validations::NumericalityValidator and v.attributes.include? column.name - end - equal_to = validators.map{ |v| v.options[:equal_to] }.compact.first - # If there is equal_to constraint - use it (unless otherwise specified by user) - if equal_to and not (options[:min] or options[:max]) - options[:min] = options[:max] = equal_to - else # find minimum and maximum from validators - # we can safely modify :min and :max by 1 for :greater_tnan or :less_than value only for integer values - only_integer = validators.map{ |v| v.options[:only_integer] }.compact.any? - margin = only_integer ? 1 : 0 - # Minimum - unless options[:min] - min = validators.map{ |v| v.options[:greater_than_or_equal] }.compact.max - greater_than = validators.map{ |v| v.options[:greater_than] }.compact.max - options[:min] = [min, (greater_than.nil?? nil : greater_than+margin)].compact.max - end - # Maximum - unless options[:max] - max = validators.map{ |v| v.options[:less_than_or_equal] }.compact.min - less_than = validators.map{ |v| v.options[:less_than] }.compact.min - options[:max] = [max, (less_than.nil?? nil : less_than-margin)].compact.min + if column.numerical_constraints + return column.numerical_constraints.merge(options) + else + validators = column.active_record_class.validators.select do |v| + v.is_a? ActiveModel::Validations::NumericalityValidator and v.attributes.include? column.name end - # Set step = 2 for column values restricted to be odd or even (but only if minimum is set) - unless options[:step] - only_odd_valid = validators.map{ |v| v.options[:odd] }.compact.any? - only_even_valid = validators.map{ |v| v.options[:even] }.compact.any? - if options[:min] and options[:min].respond_to? "even?" and (only_odd_valid or only_even_valid) - options[:step] = 2 - options[:min] += 1 if only_odd_valid and not options[:min].odd? - options[:min] += 1 if only_even_valid and not options[:min].even? + equal_to = validators.map{ |v| v.options[:equal_to] }.compact.first + # If there is equal_to constraint - use it (unless otherwise specified by user) + if equal_to and not (options[:min] or options[:max]) + options[:min] = options[:max] = equal_to + else # find minimum and maximum from validators + # we can safely modify :min and :max by 1 for :greater_tnan or :less_than value only for integer values + only_integer = validators.map{ |v| v.options[:only_integer] }.compact.any? + margin = only_integer ? 1 : 0 + # Minimum + unless options[:min] + min = validators.map{ |v| v.options[:greater_than_or_equal] }.compact.max + greater_than = validators.map{ |v| v.options[:greater_than] }.compact.max + options[:min] = [min, (greater_than.nil?? nil : greater_than+margin)].compact.max + end + # Maximum + unless options[:max] + max = validators.map{ |v| v.options[:less_than_or_equal] }.compact.min + less_than = validators.map{ |v| v.options[:less_than] }.compact.min + options[:max] = [max, (less_than.nil?? nil : less_than-margin)].compact.min + end + # Set step = 2 for column values restricted to be odd or even (but only if minimum is set) + unless options[:step] + only_odd_valid = validators.map{ |v| v.options[:odd] }.compact.any? + only_even_valid = validators.map{ |v| v.options[:even] }.compact.any? + if options[:min] and options[:min].respond_to? "even?" and (only_odd_valid or only_even_valid) + options[:step] = 2 + options[:min] += 1 if only_odd_valid and not options[:min].odd? + options[:min] += 1 if only_even_valid and not options[:min].even? + end end end + column.numerical_constraints = options.select{ |key| [:min, :max, :step].include? key } end return options end From aa1b0949bc67ffc34f0f07bfed95f254795f3674 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 13 Jul 2012 14:34:23 +0200 Subject: [PATCH 1594/2024] fix show ui parameters order --- lib/active_scaffold/helpers/show_column_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/show_column_helpers.rb b/lib/active_scaffold/helpers/show_column_helpers.rb index ea5f623ab5..f8f8ab399a 100644 --- a/lib/active_scaffold/helpers/show_column_helpers.rb +++ b/lib/active_scaffold/helpers/show_column_helpers.rb @@ -16,10 +16,10 @@ def show_column_value(record, column) end # second, check if the dev has specified a valid list_ui for this column elsif column.list_ui and (method = override_show_column_ui(column.list_ui)) - send(method, column, record) + send(method, record, column) else if column.column and (method = override_show_column_ui(column.column.type)) - send(method, column, record) + send(method, record, column) else get_column_value(record, column) end From 4efad04331d73296b3459f8e85adc9229122119d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 13 Jul 2012 15:12:48 +0200 Subject: [PATCH 1595/2024] trigger as:element_updated in new subform rows --- app/assets/javascripts/jquery/active_scaffold.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 66493884b8..733e0af3d9 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -627,9 +627,11 @@ var ActiveScaffold = { create_associated_record_form: function(element, content, options) { if (typeof(element) == 'string') element = '#' + element; var element = jQuery(element); + content = jQuery(content); if (options.singular == false) { if (!(options.id && jQuery('#' + options.id).size() > 0)) { - element.append(content); + var new_element = element.append(content); + content.trigger('as:element_updated'); } } else { var current = jQuery('#' + element.attr('id') + ' .association-record') @@ -637,6 +639,7 @@ var ActiveScaffold = { this.replace(current[0], content); } else { element.prepend(content); + content.trigger('as:element_updated'); } } }, From 9b5edaa8fd1745733419050f298a18ee061bf972 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 13 Jul 2012 15:15:44 +0200 Subject: [PATCH 1596/2024] update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index c0061e67dd..31e4aff348 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ = 3.2.15 (not released yet) - Prepare to unify field overrides and list_ui method signatures - Add :optional to update.persistent +- Add missing triggering of as:element_updated in new subform rows = 3.2.14 - Fix default sorting, it was broken in 3.2.13 From bf989896ae8195df2a21d68b559fc4cb37b3562e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 13 Jul 2012 15:20:14 +0200 Subject: [PATCH 1597/2024] update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 31e4aff348..e902f1b06e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ - Unify field overrides and list_ui method signatures - Improve performance removing some partials and adding some caching for helper overrides and UIs, and caching url generation for lists - Drop support for rails 3.1 +- Add HTML5 form fields = 3.2.15 (not released yet) - Prepare to unify field overrides and list_ui method signatures From 22cc68684926c4aa30a9e4b3a40dc91ab0d5120f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 16 Jul 2012 09:46:43 +0200 Subject: [PATCH 1598/2024] fix saving numerical constraints --- .../helpers/form_column_helpers.rb | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index f9966708aa..44824e5cca 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -351,46 +351,50 @@ def active_scaffold_add_existing_label # Try to get numerical constraints from model's validators def numerical_constraints_for_column(column, options) - if column.numerical_constraints - return column.numerical_constraints.merge(options) - else + if column.numerical_constraints.nil? + numerical_constraints = {} validators = column.active_record_class.validators.select do |v| v.is_a? ActiveModel::Validations::NumericalityValidator and v.attributes.include? column.name end equal_to = validators.map{ |v| v.options[:equal_to] }.compact.first + # If there is equal_to constraint - use it (unless otherwise specified by user) if equal_to and not (options[:min] or options[:max]) - options[:min] = options[:max] = equal_to + numerical_constraints[:min] = numerical_constraints[:max] = equal_to else # find minimum and maximum from validators # we can safely modify :min and :max by 1 for :greater_tnan or :less_than value only for integer values only_integer = validators.map{ |v| v.options[:only_integer] }.compact.any? margin = only_integer ? 1 : 0 + # Minimum unless options[:min] min = validators.map{ |v| v.options[:greater_than_or_equal] }.compact.max greater_than = validators.map{ |v| v.options[:greater_than] }.compact.max - options[:min] = [min, (greater_than.nil?? nil : greater_than+margin)].compact.max + numerical_constraints[:min] = [min, (greater_than.nil?? nil : greater_than+margin)].compact.max end + # Maximum unless options[:max] max = validators.map{ |v| v.options[:less_than_or_equal] }.compact.min less_than = validators.map{ |v| v.options[:less_than] }.compact.min - options[:max] = [max, (less_than.nil?? nil : less_than-margin)].compact.min + numerical_constraints[:max] = [max, (less_than.nil?? nil : less_than-margin)].compact.min end + # Set step = 2 for column values restricted to be odd or even (but only if minimum is set) unless options[:step] only_odd_valid = validators.map{ |v| v.options[:odd] }.compact.any? only_even_valid = validators.map{ |v| v.options[:even] }.compact.any? - if options[:min] and options[:min].respond_to? "even?" and (only_odd_valid or only_even_valid) - options[:step] = 2 - options[:min] += 1 if only_odd_valid and not options[:min].odd? - options[:min] += 1 if only_even_valid and not options[:min].even? + if options[:min] and options[:min].respond_to? :even? and (only_odd_valid or only_even_valid) + numerical_constraints[:step] = 2 + numerical_constraints[:min] += 1 if only_odd_valid and not options[:min].odd? + numerical_constraints[:min] += 1 if only_even_valid and not options[:min].even? end end end - column.numerical_constraints = options.select{ |key| [:min, :max, :step].include? key } + + column.numerical_constraints = numerical_constraints end - return options + return column.numerical_constraints.merge(options) end end end From 3f4a19e597cd752a3deef8b400899af5c806f8ed Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 16 Jul 2012 09:46:59 +0200 Subject: [PATCH 1599/2024] don't add empty placeholder --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 44824e5cca..d6169eb6bc 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -72,7 +72,7 @@ def active_scaffold_input_options(column, scope = nil, options = {}) # Add some HTML5 attributes for in-browser validation and better user experience options[:required] = true if column.required? - options[:placeholder] = column.placeholder if column.placeholder + options[:placeholder] = column.placeholder if column.placeholder.present? # Fix for keeping unique IDs in subform id_control = "record_#{column.name}_#{[params[:eid], params[:id]].compact.join '_'}" From aab9e3286f46fe5b79466ff26306eabd024bbf25 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 16 Jul 2012 09:47:18 +0200 Subject: [PATCH 1600/2024] fix for numbers with decimals --- lib/active_scaffold/helpers/form_column_helpers.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index d6169eb6bc..eddfead813 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -389,6 +389,7 @@ def numerical_constraints_for_column(column, options) numerical_constraints[:min] += 1 if only_odd_valid and not options[:min].odd? numerical_constraints[:min] += 1 if only_even_valid and not options[:min].even? end + numerical_constraints[:step] ||= 'any' unless only_integer end end From 8b009683ffdbc499ca478d779fd95d6144adb9b7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 16 Jul 2012 11:49:32 +0200 Subject: [PATCH 1601/2024] skip adding required for blank records added automatically --- app/assets/stylesheets/active_scaffold_colors.css.scss | 3 +++ frontends/default/views/_form_association.html.erb | 6 +++++- lib/active_scaffold/helpers/form_column_helpers.rb | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/active_scaffold_colors.css.scss b/app/assets/stylesheets/active_scaffold_colors.css.scss index 273cd0e448..f78158e626 100644 --- a/app/assets/stylesheets/active_scaffold_colors.css.scss +++ b/app/assets/stylesheets/active_scaffold_colors.css.scss @@ -335,6 +335,9 @@ color: $placeholder_color; border-color: $input_border_color; } +.active-scaffold input:invalid, +.active-scaffold textarea:invalid, +.active-scaffold select:invalid, .active-scaffold .fieldWithErrors input, .active-scaffold .field_with_errors input, .active-scaffold .fieldWithErrors textarea, diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index 424f9d8119..d615e1988e 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -5,6 +5,7 @@ associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless if show_blank_record = column.show_blank_record?(associated) associated << build_associated(column, parent_record) end +@disable_required_for_new = show_blank_record unless (column.singular_association? && column.required?) subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_record.id || 99999999999})}-div" -%> <h5><%= column.label -%></h5> @@ -14,4 +15,7 @@ subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_reco <%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record, :scope => scope} %> </div> <%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%> -<% @record = parent_record -%> +<% + @record = parent_record + @disable_required_for_new = nil +-%> diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index eddfead813..50435d04e2 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -71,7 +71,9 @@ def active_scaffold_input_options(column, scope = nil, options = {}) name = scope ? "record#{scope}[#{column.name}]" : "record[#{column.name}]" # Add some HTML5 attributes for in-browser validation and better user experience - options[:required] = true if column.required? + if column.required? && (!@disable_required_for_new || scope.nil? || @record.persisted?) + options[:required] = true + end options[:placeholder] = column.placeholder if column.placeholder.present? # Fix for keeping unique IDs in subform From 97707c7700f6d9373e57479ad69f335e1c57bbc2 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 16 Jul 2012 13:21:46 +0200 Subject: [PATCH 1602/2024] validate number of decimals stored in DB --- .../helpers/form_column_helpers.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 50435d04e2..621ee84b85 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -358,35 +358,38 @@ def numerical_constraints_for_column(column, options) validators = column.active_record_class.validators.select do |v| v.is_a? ActiveModel::Validations::NumericalityValidator and v.attributes.include? column.name end - equal_to = validators.map{ |v| v.options[:equal_to] }.compact.first + equal_to = (v = validators.find{ |v| v.options[:equal_to] }) ? v.options[:equal_to] : nil # If there is equal_to constraint - use it (unless otherwise specified by user) if equal_to and not (options[:min] or options[:max]) numerical_constraints[:min] = numerical_constraints[:max] = equal_to else # find minimum and maximum from validators # we can safely modify :min and :max by 1 for :greater_tnan or :less_than value only for integer values - only_integer = validators.map{ |v| v.options[:only_integer] }.compact.any? + only_integer = column.column.type == :integer if column.column + only_integer ||= !!validators.find{ |v| v.options[:only_integer] } margin = only_integer ? 1 : 0 # Minimum unless options[:min] min = validators.map{ |v| v.options[:greater_than_or_equal] }.compact.max greater_than = validators.map{ |v| v.options[:greater_than] }.compact.max - numerical_constraints[:min] = [min, (greater_than.nil?? nil : greater_than+margin)].compact.max + numerical_constraints[:min] = [min, (greater_than+margin if greater_than)].compact.max end # Maximum unless options[:max] max = validators.map{ |v| v.options[:less_than_or_equal] }.compact.min less_than = validators.map{ |v| v.options[:less_than] }.compact.min - numerical_constraints[:max] = [max, (less_than.nil?? nil : less_than-margin)].compact.min + numerical_constraints[:max] = [max, (less_than-margin if less_than)].compact.min end # Set step = 2 for column values restricted to be odd or even (but only if minimum is set) unless options[:step] - only_odd_valid = validators.map{ |v| v.options[:odd] }.compact.any? - only_even_valid = validators.map{ |v| v.options[:even] }.compact.any? - if options[:min] and options[:min].respond_to? :even? and (only_odd_valid or only_even_valid) + only_odd_valid = validators.any?{ |v| v.options[:odd] } + only_even_valid = validators.any?{ |v| v.options[:even] } unless only_odd_valid + if !only_integer + numerical_constraints[:step] ||= "0.#{'0'*(column.column.scale-1)}1" if column.column && column.column.scale.to_i > 0 + elsif options[:min] and options[:min].respond_to? :even? and (only_odd_valid or only_even_valid) numerical_constraints[:step] = 2 numerical_constraints[:min] += 1 if only_odd_valid and not options[:min].odd? numerical_constraints[:min] += 1 if only_even_valid and not options[:min].even? From 7aa0d7f79e09d70f5b0513d3c7af47d9290efd89 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 17 Jul 2012 09:45:53 +0200 Subject: [PATCH 1603/2024] add fulltext to display text columns without truncating --- lib/active_scaffold/actions/list.rb | 2 +- lib/active_scaffold/helpers/list_column_helpers.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 6f0f0dcc6b..94281511e1 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -51,7 +51,7 @@ def list_respond_to_yaml end def row_respond_to_js - render + render :action => 'row' end # The actual algorithm to prepare for the list view diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 057a2b8409..e5ce6d5d97 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -141,6 +141,10 @@ def active_scaffold_column_text(record, column) clean_column_value(truncate(record.send(column.name), :length => column.options[:truncate] || 50)) end + def active_scaffold_column_fulltext(record, column) + clean_column_value(record.send(column.name)) + end + def active_scaffold_column_marked(record, column) options = {:id => nil, :object => record} content_tag(:span, check_box(:record, column.name, options), :class => 'in_place_editor_field', :data => {:ie_id => record.id.to_s}) From 29e58e0950fff015b5bb6cd9fea6f6623659050b Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 17 Jul 2012 18:17:36 +0200 Subject: [PATCH 1604/2024] Remove code for rails 3.1 --- lib/active_scaffold/extensions/action_view_rendering.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 528b097281..9860161e1a 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -4,11 +4,7 @@ module ViewPaths def find_all_templates(name, partial = false, locals = {}) prefixes.collect do |prefix| view_paths.collect do |resolver| - if Rails.version < '3.2.0' # FIXME: remove when rails 3.1 support is dropped - temp_args = *args_for_lookup(name, [prefix], partial, locals) - else - temp_args = *args_for_lookup(name, [prefix], partial, locals, {}) - end + temp_args = *args_for_lookup(name, [prefix], partial, locals, {}) temp_args[1] = temp_args[1][0] resolver.find_all(*temp_args) end From 5ad260ce9d2f651fea0ab7513e0fcb9e5f4a0822 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 18 Jul 2012 22:10:17 +0200 Subject: [PATCH 1605/2024] Add :chosen form_ui, and :chosen and :multi_chosen search_ui --- CHANGELOG | 1 + .../javascripts/jquery/active_scaffold.js | 13 ++++++++ .../javascripts/jquery/jquery.editinplace.js | 2 +- lib/active_scaffold/bridges/chosen.rb | 14 ++++++++ lib/active_scaffold/bridges/chosen/helpers.rb | 33 +++++++++++++++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 lib/active_scaffold/bridges/chosen.rb create mode 100644 lib/active_scaffold/bridges/chosen/helpers.rb diff --git a/CHANGELOG b/CHANGELOG index e902f1b06e..0f855b30ff 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ - Improve performance removing some partials and adding some caching for helper overrides and UIs, and caching url generation for lists - Drop support for rails 3.1 - Add HTML5 form fields +- Add :chosen form_ui, and :chosen and :multi_chosen search_ui = 3.2.15 (not released yet) - Prepare to unify field overrides and list_ui method signatures diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 733e0af3d9..433f572768 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -213,6 +213,17 @@ jQuery(document).ready(function() { ActiveScaffold.hide(jQuery(this).closest('.message')); e.preventDefault(); }); + + jQuery(document).on('as:element_updated', function(event) { + jQuery('select.chosen', event.target).chosen(); + }); + jQuery(document).on('as:action_success', 'a.as_action', function(event, action_link) { + if (action_link.adapter) { + jQuery('select.chosen', action_link.adapter).chosen(); + } + }); + jQuery('select.chosen').chosen(); + }); /* Simple Inheritance @@ -775,6 +786,8 @@ var ActiveScaffold = { if (column_heading.data('ie-plural')) plural = true; options.field_type = 'remote'; options.editor_url = render_url.replace(/__id__/, record_id) + if (!options.delegate) options.delegate = {} + options.delegate.didOpenEditInPlace = function(dom) { dom.trigger('as:element_updated'); } } if (mode === 'inline_checkbox') { ActiveScaffold.process_checkbox_inplace_edit(span.find('input:checkbox'), options); diff --git a/app/assets/javascripts/jquery/jquery.editinplace.js b/app/assets/javascripts/jquery/jquery.editinplace.js index 833fd3a575..571ab834b6 100644 --- a/app/assets/javascripts/jquery/jquery.editinplace.js +++ b/app/assets/javascripts/jquery/jquery.editinplace.js @@ -470,7 +470,7 @@ $.extend(InlineEditor.prototype, { if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent)) return; - var editor = this.dom.find(':input:not(:button)').not('input:checkbox:not(:checked)').not('input:radio:not(:checked)'); + var editor = this.dom.find('[name]:input:not(:button,[name=""])').not('input:checkbox:not(:checked)').not('input:radio:not(:checked)'); var enteredText = ''; if (editor.length > 1) { enteredText = jQuery.map(editor, function(item, index) { diff --git a/lib/active_scaffold/bridges/chosen.rb b/lib/active_scaffold/bridges/chosen.rb new file mode 100644 index 0000000000..74eaf8b816 --- /dev/null +++ b/lib/active_scaffold/bridges/chosen.rb @@ -0,0 +1,14 @@ +class ActiveScaffold::Bridges::Chosen < ActiveScaffold::DataStructures::Bridge + def self.install + require File.join(File.dirname(__FILE__), "chosen/helpers.rb") + end + def self.install? + super && [:jquery, :prototype].include?(ActiveScaffold.js_framework) + end + def self.stylesheets + 'chosen' + end + def self.javascripts + "chosen-#{ActiveScaffold.js_framework}" + end +end diff --git a/lib/active_scaffold/bridges/chosen/helpers.rb b/lib/active_scaffold/bridges/chosen/helpers.rb new file mode 100644 index 0000000000..cba22c9b8a --- /dev/null +++ b/lib/active_scaffold/bridges/chosen/helpers.rb @@ -0,0 +1,33 @@ +class ActiveScaffold::Bridges::Chosen + module Helpers + def self.included(base) + base.class_eval do + include FormColumnHelpers + include SearchColumnHelpers + end + end + + module FormColumnHelpers + # requires RecordSelect plugin to be installed and configured. + def active_scaffold_input_chosen(column, options) + options[:class] << ' chosen' + active_scaffold_input_select(column, options) + end + end + + module SearchColumnHelpers + def active_scaffold_search_chosen(column, options) + options[:class] << ' chosen' + active_scaffold_search_select(column, options) + end + + def active_scaffold_search_multi_chosen(column, options) + options[:class] << ' chosen' + options[:multiple] = true + active_scaffold_search_select(column, options) + end + end + end +end + +ActionView::Base.class_eval { include ActiveScaffold::Bridges::Chosen::Helpers } From 0ba148fb90f734641f735c3c297ccc02349ba20f Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 18 Jul 2012 22:10:46 +0200 Subject: [PATCH 1606/2024] fix select field_search conditions --- lib/active_scaffold/finder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 92b2f11b32..586c323caa 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -59,8 +59,8 @@ def condition_for_column(column, value, text_search = :full) condition_for_range(column, value, like_pattern) when :date, :time, :datetime, :timestamp condition_for_datetime(column, value) - when :select, :multi_select, :country, :usa_state - ["%{search_sql} in (?)", [Array(value)]] + when :select, :multi_select, :country, :usa_state, :chosen, :multi_chosen + ["%{search_sql} in (?)", Array(value)] else if column.column.nil? || column.column.text? ["%{search_sql} #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)] From 493f3c04494c266959e6057249e940e581bf3b66 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 18 Jul 2012 22:11:41 +0200 Subject: [PATCH 1607/2024] update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 0f855b30ff..3cb5e47aa4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ - Prepare to unify field overrides and list_ui method signatures - Add :optional to update.persistent - Add missing triggering of as:element_updated in new subform rows +- Fix conditions for :select in field_search = 3.2.14 - Fix default sorting, it was broken in 3.2.13 From 254abb6ad40516cf1160af1db78eb1f1e0a372da Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 18 Jul 2012 23:03:30 +0200 Subject: [PATCH 1608/2024] use chosen for plural associations instead of checkbox list --- lib/active_scaffold/bridges/chosen/helpers.rb | 16 +++++++++++++--- .../helpers/form_column_helpers.rb | 11 +++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/bridges/chosen/helpers.rb b/lib/active_scaffold/bridges/chosen/helpers.rb index cba22c9b8a..7f558d893d 100644 --- a/lib/active_scaffold/bridges/chosen/helpers.rb +++ b/lib/active_scaffold/bridges/chosen/helpers.rb @@ -9,9 +9,19 @@ def self.included(base) module FormColumnHelpers # requires RecordSelect plugin to be installed and configured. - def active_scaffold_input_chosen(column, options) - options[:class] << ' chosen' - active_scaffold_input_select(column, options) + def active_scaffold_input_chosen(column, html_options) + html_options[:class] << ' chosen' + if column.plural_association? + associated_options, select_options = active_scaffold_plural_association_options(column) + options = {:selected => associated_options.collect {|a| a[1]}, :include_blank => as_(:_select_)} + + html_options.update(:multiple => true).update(column.options[:html_options] || {}) + options.update(column.options) + html_options[:name] = "#{html_options[:name]}[]" if html_options[:multiple] == true && !html_options[:name].to_s.ends_with?("[]") + select(:record, column.name, select_options, options, html_options) + else + active_scaffold_input_select(column, html_options) + end end end diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 621ee84b85..ccb6486d99 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -113,18 +113,21 @@ def active_scaffold_input_singular_association(column, html_options) select_options.unshift([ associated.to_label, associated.id ]) unless associated.nil? or select_options.find {|label, id| id == associated.id} method = column.name - #html_options[:name] += '[id]' options = {:selected => associated.try(:id), :include_blank => as_(:_select_)} html_options.update(column.options[:html_options] || {}) options.update(column.options) - html_options[:name] = "#{html_options[:name]}[]" if (html_options[:multiple] == true && !html_options[:name].to_s.ends_with?("[]")) + html_options[:name] = "#{html_options[:name]}[]" if html_options[:multiple] == true && !html_options[:name].to_s.ends_with?("[]") select(:record, method, select_options.uniq, options, html_options) end - def active_scaffold_input_plural_association(column, options) + def active_scaffold_plural_association_options(column) associated_options = @record.send(column.association.name).collect {|r| [r.to_label, r.id]} - select_options = associated_options | options_for_association(column.association) + [associated_options, associated_options | options_for_association(column.association)] + end + + def active_scaffold_input_plural_association(column, options) + associated_options, select_options = active_scaffold_plural_association_options(column) return content_tag(:span, as_(:no_options), :class => options[:class], :id => options[:id]) if select_options.empty? active_scaffold_checkbox_list(column, select_options, associated_options.collect {|a| a[1]}, options) From a1539d59109223227686c59d29204cb3b74bbb36 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 20 Jul 2012 08:37:44 +0200 Subject: [PATCH 1609/2024] move chosen JS to a file included only when using chosen --- app/assets/javascripts/jquery/active_scaffold.js | 10 ---------- .../javascripts/jquery/active_scaffold_chosen.js | 11 +++++++++++ .../javascripts/prototype/active_scaffold_chosen.js | 0 lib/active_scaffold/bridges/chosen.rb | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 app/assets/javascripts/jquery/active_scaffold_chosen.js create mode 100644 app/assets/javascripts/prototype/active_scaffold_chosen.js diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 433f572768..95282f9cc7 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -214,16 +214,6 @@ jQuery(document).ready(function() { e.preventDefault(); }); - jQuery(document).on('as:element_updated', function(event) { - jQuery('select.chosen', event.target).chosen(); - }); - jQuery(document).on('as:action_success', 'a.as_action', function(event, action_link) { - if (action_link.adapter) { - jQuery('select.chosen', action_link.adapter).chosen(); - } - }); - jQuery('select.chosen').chosen(); - }); /* Simple Inheritance diff --git a/app/assets/javascripts/jquery/active_scaffold_chosen.js b/app/assets/javascripts/jquery/active_scaffold_chosen.js new file mode 100644 index 0000000000..a06d466dcb --- /dev/null +++ b/app/assets/javascripts/jquery/active_scaffold_chosen.js @@ -0,0 +1,11 @@ +jQuery(document).ready(function() { + jQuery(document).on('as:element_updated', function(event) { + jQuery('select.chosen', event.target).chosen(); + }); + jQuery(document).on('as:action_success', 'a.as_action', function(event, action_link) { + if (action_link.adapter) { + jQuery('select.chosen', action_link.adapter).chosen(); + } + }); + jQuery('select.chosen').chosen(); +}); diff --git a/app/assets/javascripts/prototype/active_scaffold_chosen.js b/app/assets/javascripts/prototype/active_scaffold_chosen.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/active_scaffold/bridges/chosen.rb b/lib/active_scaffold/bridges/chosen.rb index 74eaf8b816..17595394cc 100644 --- a/lib/active_scaffold/bridges/chosen.rb +++ b/lib/active_scaffold/bridges/chosen.rb @@ -9,6 +9,6 @@ def self.stylesheets 'chosen' end def self.javascripts - "chosen-#{ActiveScaffold.js_framework}" + "chosen-#{ActiveScaffold.js_framework} #{ActiveScaffold.js_framework}/active_scaffold_chosen" end end From a65250f2ec1e0555726cc0b56db790a4e1dbd4d9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 20 Jul 2012 10:54:07 +0200 Subject: [PATCH 1610/2024] trigger as:element_updated on loading embedded --- lib/active_scaffold/extensions/action_view_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 9860161e1a..8eb5b45ce5 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -83,7 +83,7 @@ def render_with_active_scaffold(*args, &block) if ActiveScaffold.js_framework == :prototype javascript_tag("new Ajax.Updater('#{id}', '#{url}', {method: 'get', evalScripts: true});") elsif ActiveScaffold.js_framework == :jquery - javascript_tag("jQuery('##{id}').load('#{url}');") + javascript_tag("jQuery('##{id}').load('#{url}', function() { $(this).trigger('as:element_updated'); });") end end end From 041156cd3a5369cc2c46649dad05e61f3049c178 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 20 Jul 2012 13:06:49 +0200 Subject: [PATCH 1611/2024] disable i18n_number conversion for :number form_ui, browsers which support input number send numbers with dot and it breaks for 3 decimals --- lib/active_scaffold/attribute_params.rb | 2 +- lib/active_scaffold/finder.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 3144b9f152..b89b05e92d 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -104,7 +104,7 @@ def column_value_from_param_simple_value(parent_record, column, value) column.association.klass.find(value) if value and not value.empty? elsif column.plural_association? column_plural_assocation_value_from_value(column, value) - elsif column.number? && [:i18n_number, :currency].include?(column.options[:format]) + elsif column.number? && [:i18n_number, :currency].include?(column.options[:format]) && column.form_ui != :number self.class.i18n_number_to_native_format(value) else # convert empty strings into nil. this works better with 'null => true' columns (and validations), diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 586c323caa..7ae1bb84cc 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -146,7 +146,7 @@ def condition_value_for_datetime(value, conversion = :to_time) def condition_value_for_numeric(column, value) return value if value.nil? - value = i18n_number_to_native_format(value) if [:i18n_number, :currency].include?(column.options[:format]) + value = i18n_number_to_native_format(value) if [:i18n_number, :currency].include?(column.options[:format]) && column.search_ui != :number case (column.search_ui || column.column.type) when :integer then value.to_i rescue value ? 1 : 0 when :float then value.to_f From 4b83caea5d575f1079379ee648406f54287a027e Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 19 Jul 2012 18:55:39 +0200 Subject: [PATCH 1612/2024] cleanup attribute params --- lib/active_scaffold/attribute_params.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index b89b05e92d..44c05dd71a 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -101,7 +101,7 @@ def column_value_from_param_value(parent_record, column, value) def column_value_from_param_simple_value(parent_record, column, value) if column.singular_association? # it's a single id - column.association.klass.find(value) if value and not value.empty? + column.association.klass.find(value) if value.present? elsif column.plural_association? column_plural_assocation_value_from_value(column, value) elsif column.number? && [:i18n_number, :currency].include?(column.options[:format]) && column.form_ui != :number @@ -118,7 +118,7 @@ def column_value_from_param_simple_value(parent_record, column, value) def column_plural_assocation_value_from_value(column, value) # it's an array of ids if value and not value.empty? - ids = value.select {|id| id.respond_to?(:empty?) ? !id.empty? : true} + ids = value.select {|id| id.present?} ids.empty? ? [] : column.association.klass.find(ids) end end From bafa5e09ca96ba0f95c858d3e769d91daf2ab304 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 19 Jul 2012 19:19:18 +0200 Subject: [PATCH 1613/2024] Remove position absolute for header actions, there is no point in that --- app/assets/stylesheets/active_scaffold_layout.css | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/assets/stylesheets/active_scaffold_layout.css b/app/assets/stylesheets/active_scaffold_layout.css index cf99eafe98..68ff37846b 100644 --- a/app/assets/stylesheets/active_scaffold_layout.css +++ b/app/assets/stylesheets/active_scaffold_layout.css @@ -139,13 +139,6 @@ background-color: transparent; cursor: default; } -.active-scaffold-header div.actions { -position: absolute; -right: 5px; -top: 5px; -text-align: right; -} - /* Table :: Column Headers ============================= */ From 0ad8e9580cfce82a33bef9fc000ceaa82f0155d4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 20 Jul 2012 16:41:21 +0200 Subject: [PATCH 1614/2024] fix nested with has_one associations --- CHANGELOG | 1 + lib/active_scaffold.rb | 2 +- lib/active_scaffold/config/nested.rb | 3 +- .../helpers/list_column_helpers.rb | 63 +--------------- lib/active_scaffold/helpers/view_helpers.rb | 71 ++++++++++++++++++- 5 files changed, 73 insertions(+), 67 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3cb5e47aa4..7a5f99e8e2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ - Drop support for rails 3.1 - Add HTML5 form fields - Add :chosen form_ui, and :chosen and :multi_chosen search_ui +- Fix nested with has_one associations = 3.2.15 (not released yet) - Prepare to unify field overrides and list_ui method signatures diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index a1e79c1e62..142bcd008d 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -264,7 +264,7 @@ def link_for_association(column, options = {}) controller = active_scaffold_controller_for_column(column, options) unless controller.nil? - options.reverse_merge! :label => column.label, :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column + options.reverse_merge! :position => :after, :type => :member, :controller => (controller == :polymorph ? controller : controller.controller_path), :column => column options[:parameters] ||= {} options[:parameters].reverse_merge! :association => column.association.name if column.plural_association? diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index bc29943969..e3ab61181a 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -21,9 +21,8 @@ def initialize(core_config) def add_link(attribute, options = {}) column = @core.columns[attribute.to_sym] unless column.nil? || column.association.nil? - options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => 2, :default => column.association.klass.name.pluralize}) + options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => column.singular_association? ? 1 : 2, :default => column.association.klass.name.pluralize}) action_link = @core.link_for_association(column, options) - action_link.action ||= :index @core.action_links.add_to_group(action_link, action_group) unless action_link.nil? else diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index e5ce6d5d97..bd6f443e02 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -49,18 +49,9 @@ def render_list_column(text, column, record) if column.link link = column.link associated = record.send(column.association.name) if column.association - html_options = {} - # setup automatic link - if column.autolink? && column.singular_association? # link to inline form - link = action_link_to_inline_form(column, record, associated, text) - return text if link.nil? - else - html_options[:link] = text - end - - if column_link_authorized?(link, column, record, associated) - render_action_link(link, record, html_options) + if link.action.nil? || column_link_authorized?(link, column, record, associated) + render_action_link(link, record, {:link => text}) else "<a class='disabled'>#{text}</a>".html_safe end @@ -73,56 +64,6 @@ def render_list_column(text, column, record) end end - # setup the action link to inline form - def action_link_to_inline_form(column, record, associated, text) - link = column.link.clone - link.label = text - if column.polymorphic_association? - polymorphic_controller = controller_path_for_activerecord(record.send(column.association.name).class) - return link if polymorphic_controller.nil? - link.controller = polymorphic_controller - end - configure_column_link(link, associated, column.actions_for_association_links) - end - - def configure_column_link(link, associated, actions) - if column_empty?(associated) # if association is empty, we only can link to create form - if actions.include?(:new) - link.action = 'new' - link.crud_type = :create - link.label = as_(:create_new) - end - elsif actions.include?(:edit) - link.action = 'edit' - link.crud_type = :update - elsif actions.include?(:show) - link.action = 'show' - link.crud_type = :read - elsif actions.include?(:list) - link.action = 'index' - link.crud_type = :read - end - link if link.action.present? - end - - def column_link_authorized?(link, column, record, associated) - if column.association - associated_for_authorized = if associated.nil? || (column.plural_association? && !associated.loaded?) || (associated.respond_to?(:blank?) && associated.blank?) - column.association.klass - elsif [:has_many, :has_and_belongs_to_many].include? column.association.macro - # may be cached with [] or [nil] to avoid some queries - associated.first || column.association.klass - else - associated - end - authorized = associated_for_authorized.authorized_for?(:crud_type => link.crud_type) - authorized = authorized and record.authorized_for?(:crud_type => :update, :column => column.name) if link.crud_type == :create - authorized - else - record.authorized_for?(:crud_type => link.crud_type) - end - end - # There are two basic ways to clean a column's value: h() and sanitize(). The latter is useful # when the column contains *valid* html data, and you want to just disable any scripting. People # can always use field overrides to clean data one way or the other, but having this override diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 14dc898e17..22d36d5c46 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -104,8 +104,12 @@ def skip_action_link(link, *args) end def render_action_link(link, record = nil, html_options = {}) - url = action_link_url(link, record) - html_options = action_link_html_options(link, record, html_options) + if link.action.nil? + link = action_link_to_inline_form(link, record, html_options) + html_options.delete :link if link.crud_type == :create + end + url = action_link_url(link, record) unless link.action.nil? + html_options = action_link_html_options(link, record, html_options) unless link.action.nil? action_link_html(link, url, html_options, record) end @@ -116,6 +120,65 @@ def render_group_action_link(link, options, record = nil) render_action_link(link, record) end end + + # setup the action link to inline form + def action_link_to_inline_form(link, record, html_options) + link = link.clone + associated = record.send(link.column.association.name) + if link.column.polymorphic_association? + link.controller = controller_path_for_activerecord(associated.class) + return link if link.controller.nil? + end + configure_column_link(link, record, associated) + end + + def configure_column_link(link, record, associated, actions = nil) + actions ||= link.column.actions_for_association_links + if column_empty?(associated) # if association is empty, we only can link to create form + if actions.include?(:new) + link.action = 'new' + link.crud_type = :create + link.label ||= as_(:create_new) + end + elsif actions.include?(:edit) + link.action = 'edit' + link.crud_type = :update + elsif actions.include?(:show) + link.action = 'show' + link.crud_type = :read + elsif actions.include?(:list) + link.action = 'index' + link.crud_type = :read + end + + unless column_link_authorized?(link, record, associated) + link.action = nil + # if action is edit and is not authorized, fallback to show if it's enabled + if link.crud_type == :update && actions.include?(:show) + link = configure_column_link(link, record, associated, [:show]) + end + end + link + end + + def column_link_authorized?(link, record, associated) + column = link.column + if column.association + associated_for_authorized = if associated.nil? || (column.plural_association? && !associated.loaded?) || (associated.respond_to?(:blank?) && associated.blank?) + column.association.klass + elsif [:has_many, :has_and_belongs_to_many].include? column.association.macro + # may be cached with [] or [nil] to avoid some queries + associated.first || column.association.klass + else + associated + end + authorized = associated_for_authorized.authorized_for?(:crud_type => link.crud_type) + authorized = authorized and record.authorized_for?(:crud_type => :update, :column => column.name) if link.crud_type == :create + authorized + else + record.authorized_for?(:crud_type => link.crud_type) + end + end def action_link_url(link, record) url = if link.cached_url @@ -253,7 +316,9 @@ def url_options_for_nested_link(column, record, link, url_options) if column && column.association url_options[:parent_scaffold] = controller_path url_options[column.association.active_record.name.foreign_key.to_sym] = url_options.delete(:id) - url_options[:id] = '--CHILD_ID--' if column.singular_association? && record.send(column.association.name).present? # FIXME on fixing singular nested links + if column.singular_association? && url_options[:action].to_sym != :index + url_options[:id] = '--CHILD_ID--' if record.send(column.association.name).present? + end elsif link.parameters && link.parameters[:named_scope] url_options[:parent_scaffold] = controller_path url_options[active_scaffold_config.model.name.foreign_key.to_sym] = url_options.delete(:id) From 6bd681500b5f7e86dae505e440ccd79c591c1aca Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 20 Jul 2012 17:02:58 +0200 Subject: [PATCH 1615/2024] use alias_method_chain instead of super --- CHANGELOG | 1 + lib/active_scaffold/bridges/date_picker/ext.rb | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7a5f99e8e2..b6e955aee9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ - Add :optional to update.persistent - Add missing triggering of as:element_updated in new subform rows - Fix conditions for :select in field_search +- Fix datetime field search = 3.2.14 - Fix default sorting, it was broken in 3.2.13 diff --git a/lib/active_scaffold/bridges/date_picker/ext.rb b/lib/active_scaffold/bridges/date_picker/ext.rb index 0d8388d0c2..25a3a56ecf 100644 --- a/lib/active_scaffold/bridges/date_picker/ext.rb +++ b/lib/active_scaffold/bridges/date_picker/ext.rb @@ -49,13 +49,15 @@ def fallback_string_to_date_with_date_picker(string) end ActiveScaffold::Finder::ClassMethods.module_eval do include ActiveScaffold::Bridges::Shared::DateBridge::Finder::ClassMethods - def datetime_conversion_for_condition(column) + def datetime_conversion_for_condition_with_datepicker(column) if column.search_ui == :date_picker :to_date else - super + datetime_conversion_for_condition_without_datepicker end end + alias_method_chain :datetime_conversion_for_condition, :datepicker + alias_method :condition_for_date_picker_type, :condition_for_date_bridge_type alias_method :condition_for_datetime_picker_type, :condition_for_date_picker_type end From e1aa175bba3334cd8f022f768c4bd7b3d6fc4e6b Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 20 Jul 2012 17:55:45 +0200 Subject: [PATCH 1616/2024] add 2 js files in chosen --- lib/active_scaffold/bridges/chosen.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/chosen.rb b/lib/active_scaffold/bridges/chosen.rb index 17595394cc..59705d7cc7 100644 --- a/lib/active_scaffold/bridges/chosen.rb +++ b/lib/active_scaffold/bridges/chosen.rb @@ -9,6 +9,6 @@ def self.stylesheets 'chosen' end def self.javascripts - "chosen-#{ActiveScaffold.js_framework} #{ActiveScaffold.js_framework}/active_scaffold_chosen" + ["chosen-#{ActiveScaffold.js_framework}", "#{ActiveScaffold.js_framework}/active_scaffold_chosen"] end end From 563d137dcdbc61244b7f9d174aff0bb80ae95431 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 20 Jul 2012 18:49:48 +0200 Subject: [PATCH 1617/2024] add column argument, is used in list helpers --- lib/active_scaffold/helpers/view_helpers.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 22d36d5c46..3ff57f743e 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -151,7 +151,7 @@ def configure_column_link(link, record, associated, actions = nil) link.crud_type = :read end - unless column_link_authorized?(link, record, associated) + unless column_link_authorized?(link, link.column, record, associated) link.action = nil # if action is edit and is not authorized, fallback to show if it's enabled if link.crud_type == :update && actions.include?(:show) @@ -161,8 +161,7 @@ def configure_column_link(link, record, associated, actions = nil) link end - def column_link_authorized?(link, record, associated) - column = link.column + def column_link_authorized?(link, column, record, associated) if column.association associated_for_authorized = if associated.nil? || (column.plural_association? && !associated.loaded?) || (associated.respond_to?(:blank?) && associated.blank?) column.association.klass From 601de7ecbb0f7f4fa972cc4c64e71afce0e56d23 Mon Sep 17 00:00:00 2001 From: Nick Rogers <ncrogers@gmail.com> Date: Fri, 20 Jul 2012 13:16:30 -0700 Subject: [PATCH 1618/2024] Fix alias_method_chain for datetime field search --- lib/active_scaffold/bridges/date_picker/ext.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/date_picker/ext.rb b/lib/active_scaffold/bridges/date_picker/ext.rb index 25a3a56ecf..f7429ad530 100644 --- a/lib/active_scaffold/bridges/date_picker/ext.rb +++ b/lib/active_scaffold/bridges/date_picker/ext.rb @@ -53,7 +53,7 @@ def datetime_conversion_for_condition_with_datepicker(column) if column.search_ui == :date_picker :to_date else - datetime_conversion_for_condition_without_datepicker + datetime_conversion_for_condition_without_datepicker(column) end end alias_method_chain :datetime_conversion_for_condition, :datepicker From 3f390f1d3921a5f079579f7efd2ff8cc5be50443 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 30 Jul 2012 14:58:44 +0200 Subject: [PATCH 1619/2024] support optgroup in :select and :chosen form_ui --- CHANGELOG | 1 + .../views/_form_association_footer.html.erb | 2 +- lib/active_scaffold/bridges/chosen/helpers.rb | 7 ++++- .../helpers/association_helpers.rb | 7 +++++ .../helpers/form_column_helpers.rb | 29 ++++++++++++++----- .../helpers/search_column_helpers.rb | 13 +++++++-- 6 files changed, 46 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b6e955aee9..b339abc237 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ - Add HTML5 form fields - Add :chosen form_ui, and :chosen and :multi_chosen search_ui - Fix nested with has_one associations +- Support optgroup in :select and :chosen form_ui = 3.2.15 (not released yet) - Prepare to unify field overrides and list_ui method signatures diff --git a/frontends/default/views/_form_association_footer.html.erb b/frontends/default/views/_form_association_footer.html.erb index a4b4ae670a..ec09466ca9 100644 --- a/frontends/default/views/_form_association_footer.html.erb +++ b/frontends/default/views/_form_association_footer.html.erb @@ -36,7 +36,7 @@ add_new_url = params_for(:action => 'edit_associated', :child_association => col <% if remote_controller and remote_controller.respond_to? :uses_record_select? and remote_controller.uses_record_select? -%> <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "ActiveScaffold.record_select_onselect(#{edit_associated_url.to_json}, #{active_scaffold_id.to_json}, id);" -%> <% else -%> - <% select_options = options_for_select(options_for_association(column.association)) + <% select_options = options_from_collection_for_select(sorted_association_options_find(column.association), :id, :to_label) add_existing_id = "#{sub_form_id(:association => column.name)}-add-existing" %> <%= select_tag 'associated_id', '<option value="">'.html_safe + as_(:_select_) + '</option>'.html_safe + select_options %> <%= link_to as_(:add_existing), edit_associated_url, :id => add_existing_id, :remote => true, :class=> column.plural_association? ? 'as_add_existing' : 'as_replace_existing', :style => "display: none;" %> diff --git a/lib/active_scaffold/bridges/chosen/helpers.rb b/lib/active_scaffold/bridges/chosen/helpers.rb index 7f558d893d..d91310c4b7 100644 --- a/lib/active_scaffold/bridges/chosen/helpers.rb +++ b/lib/active_scaffold/bridges/chosen/helpers.rb @@ -18,7 +18,12 @@ def active_scaffold_input_chosen(column, html_options) html_options.update(:multiple => true).update(column.options[:html_options] || {}) options.update(column.options) html_options[:name] = "#{html_options[:name]}[]" if html_options[:multiple] == true && !html_options[:name].to_s.ends_with?("[]") - select(:record, column.name, select_options, options, html_options) + + if optgroup = options.delete(:optgroup) + select(:record, column.name, grouped_options_for_select(select_options, optgroup), options, html_options) + else + collection_select(:record, column.name, select_options, :id, :to_label, options, html_options) + end else active_scaffold_input_select(column, html_options) end diff --git a/lib/active_scaffold/helpers/association_helpers.rb b/lib/active_scaffold/helpers/association_helpers.rb index 753de6ea80..bf17414254 100644 --- a/lib/active_scaffold/helpers/association_helpers.rb +++ b/lib/active_scaffold/helpers/association_helpers.rb @@ -3,17 +3,24 @@ module Helpers module AssociationHelpers # Provides a way to honor the :conditions on an association while searching the association's klass def association_options_find(association, conditions = nil) + conditions = options_for_association_conditions(association) if conditions.nil? relation = association.klass.where(conditions).where(association.options[:conditions]) relation = relation.includes(association.options[:include]) if association.options[:include] relation.all end + # Provides a way to honor the :conditions on an association while searching the association's klass + def sorted_association_options_find(association, conditions = nil) + association_options_find(association, conditions).sort_by(&:to_label) + end + def association_options_count(association, conditions = nil) association.klass.where(conditions).where(association.options[:conditions]).count end # returns options for the given association as a collection of [id, label] pairs intended for the +options_for_select+ helper. def options_for_association(association, include_all = false) + ActiveSupport::Deprecation.warn "options_for_association should not be used, use association_options_find directly" available_records = association_options_find(association, include_all ? nil : options_for_association_conditions(association)) available_records ||= [] available_records.sort{|a,b| a.to_label <=> b.to_label}.collect { |model| [ model.to_label, model.id ] } diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index ccb6486d99..656667cd4d 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -105,12 +105,19 @@ def update_columns_options(column, scope, options) ## ## Form input methods ## + + def grouped_options_for_select(select_options, optgroup) + group_label = active_scaffold_config.columns[optgroup].try(:association) ? :to_label : :to_s + select_options.group_by(&optgroup.to_sym).collect do |group, options| + [group.send(group_label), options.collect {|r| [r.to_label, r.id]}] + end + end def active_scaffold_input_singular_association(column, html_options) associated = @record.send(column.association.name) - select_options = options_for_association(column.association) - select_options.unshift([ associated.to_label, associated.id ]) unless associated.nil? or select_options.find {|label, id| id == associated.id} + select_options = sorted_association_options_find(column.association) + select_options.unshift(associated) unless associated.nil? || select_options.include?(associated) method = column.name options = {:selected => associated.try(:id), :include_blank => as_(:_select_)} @@ -118,19 +125,24 @@ def active_scaffold_input_singular_association(column, html_options) html_options.update(column.options[:html_options] || {}) options.update(column.options) html_options[:name] = "#{html_options[:name]}[]" if html_options[:multiple] == true && !html_options[:name].to_s.ends_with?("[]") - select(:record, method, select_options.uniq, options, html_options) + + if optgroup = options.delete(:optgroup) + select(:record, method, grouped_options_for_select(select_options, optgroup), options, html_options) + else + collection_select(:record, method, select_options, :id, :to_label, options, html_options) + end end def active_scaffold_plural_association_options(column) - associated_options = @record.send(column.association.name).collect {|r| [r.to_label, r.id]} - [associated_options, associated_options | options_for_association(column.association)] + associated_options = @record.send(column.association.name) + [associated_options, associated_options | sorted_association_options_find(column.association)] end def active_scaffold_input_plural_association(column, options) associated_options, select_options = active_scaffold_plural_association_options(column) return content_tag(:span, as_(:no_options), :class => options[:class], :id => options[:id]) if select_options.empty? - active_scaffold_checkbox_list(column, select_options, associated_options.collect {|a| a[1]}, options) + active_scaffold_checkbox_list(column, select_options.collect {|r| [r.to_label, r.id]}, associated_options.collect(&:id), options) end def active_scaffold_checkbox_list(column, select_options, associated_ids, options) @@ -340,8 +352,9 @@ def active_scaffold_add_existing_input(options) options.merge!(active_scaffold_input_text_options) record_select_field(options[:name], @record, options) else - select_options = options_for_select(options_for_association(nested.association)) #unless column.through_association? - select_options ||= options_for_select(active_scaffold_config.model.all.collect {|c| [h(c.to_label), c.id]}) + select_options = sorted_association_options_find(nested.association) #unless column.through_association? + select_options ||= active_scaffold_config.model.all + select_options = options_from_collection_for_select(select_options, :id, :to_label) select_tag 'associated_id', ('<option value="">' + as_(:_select_) + '</option>' + select_options).html_safe unless select_options.empty? end end diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 670335a882..16a2fa72bc 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -61,7 +61,7 @@ def active_scaffold_search_multi_select(column, options) associated.collect!(&:to_i) if column.association - select_options = options_for_association(column.association, false) + select_options = sorted_association_options_find(column.association).collect {|r| [r.to_label, r.id]} else select_options = column.options[:options].collect do |text, value| active_scaffold_translated_option(column, text, value) @@ -77,7 +77,7 @@ def active_scaffold_search_select(column, html_options) if column.association associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil? method = column.association.macro == :belongs_to ? column.association.foreign_key : column.name - select_options = options_for_association(column.association, true) + select_options = sorted_association_options_find(column.association, false) else method = column.name select_options = column.options[:options].collect do |text, value| @@ -92,7 +92,14 @@ def active_scaffold_search_select(column, html_options) else options[:include_blank] ||= as_(:_select_) end - select(:record, method, select_options, options, html_options) + + if optgroup = options.delete(:optgroup) + select(:record, method, grouped_options_for_select(select_options, optgroup), options, html_options) + elsif column.association + collection_select(:record, method, select_options, :id, :to_label, options, html_options) + else + select(:record, method, select_options, options, html_options) + end end def active_scaffold_search_text(column, options) From 77bd66577fe5dd408809b843c4b01673a65e17fd Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 1 Aug 2012 14:08:33 +0200 Subject: [PATCH 1620/2024] fix optgroup, check column type in associated model --- lib/active_scaffold/bridges/chosen/helpers.rb | 2 +- lib/active_scaffold/helpers/form_column_helpers.rb | 6 +++--- lib/active_scaffold/helpers/search_column_helpers.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/bridges/chosen/helpers.rb b/lib/active_scaffold/bridges/chosen/helpers.rb index d91310c4b7..6b4c409f47 100644 --- a/lib/active_scaffold/bridges/chosen/helpers.rb +++ b/lib/active_scaffold/bridges/chosen/helpers.rb @@ -20,7 +20,7 @@ def active_scaffold_input_chosen(column, html_options) html_options[:name] = "#{html_options[:name]}[]" if html_options[:multiple] == true && !html_options[:name].to_s.ends_with?("[]") if optgroup = options.delete(:optgroup) - select(:record, column.name, grouped_options_for_select(select_options, optgroup), options, html_options) + select(:record, column.name, grouped_options_for_select(column, select_options, optgroup), options, html_options) else collection_select(:record, column.name, select_options, :id, :to_label, options, html_options) end diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 656667cd4d..479c77f584 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -106,8 +106,8 @@ def update_columns_options(column, scope, options) ## Form input methods ## - def grouped_options_for_select(select_options, optgroup) - group_label = active_scaffold_config.columns[optgroup].try(:association) ? :to_label : :to_s + def grouped_options_for_select(column, select_options, optgroup) + group_label = active_scaffold_config_for(column.association.klass).columns[optgroup].try(:association) ? :to_label : :to_s select_options.group_by(&optgroup.to_sym).collect do |group, options| [group.send(group_label), options.collect {|r| [r.to_label, r.id]}] end @@ -127,7 +127,7 @@ def active_scaffold_input_singular_association(column, html_options) html_options[:name] = "#{html_options[:name]}[]" if html_options[:multiple] == true && !html_options[:name].to_s.ends_with?("[]") if optgroup = options.delete(:optgroup) - select(:record, method, grouped_options_for_select(select_options, optgroup), options, html_options) + select(:record, method, grouped_options_for_select(column, select_options, optgroup), options, html_options) else collection_select(:record, method, select_options, :id, :to_label, options, html_options) end diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 16a2fa72bc..4ca5fd0e8d 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -94,7 +94,7 @@ def active_scaffold_search_select(column, html_options) end if optgroup = options.delete(:optgroup) - select(:record, method, grouped_options_for_select(select_options, optgroup), options, html_options) + select(:record, method, grouped_options_for_select(column, select_options, optgroup), options, html_options) elsif column.association collection_select(:record, method, select_options, :id, :to_label, options, html_options) else From 7b967bf7848b52bf1a0ab5c8e869e7e765b4b86d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 7 Aug 2012 14:18:11 +0200 Subject: [PATCH 1621/2024] fix calling authorized methods in action_links.traverse and using record in default methods for member actions. Fixes #178 --- lib/active_scaffold/actions/delete.rb | 2 +- lib/active_scaffold/actions/show.rb | 2 +- lib/active_scaffold/actions/update.rb | 2 +- lib/active_scaffold/data_structures/action_links.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 481de3f1ee..2cbf42111b 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -60,7 +60,7 @@ def do_destroy # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def delete_authorized?(record = nil) - (!nested? || !nested.readonly?) && authorized_for?(:crud_type => :delete) + (!nested? || !nested.readonly?) && (record || self).send(:authorized_for?, :crud_type => :delete) end private def delete_authorized_filter diff --git a/lib/active_scaffold/actions/show.rb b/lib/active_scaffold/actions/show.rb index b4896a98bf..852fca5561 100644 --- a/lib/active_scaffold/actions/show.rb +++ b/lib/active_scaffold/actions/show.rb @@ -47,7 +47,7 @@ def do_show # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def show_authorized?(record = nil) - authorized_for?(:crud_type => :read) + (record || self).send(:authorized_for?, :crud_type => :read) end private def show_authorized_filter diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index ce25b5a877..f01182529d 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -139,7 +139,7 @@ def update_refresh_list? # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def update_authorized?(record = nil) - (!nested? || !nested.readonly?) && authorized_for?(:crud_type => :update) + (!nested? || !nested.readonly?) && (record || self).send(:authorized_for?, :crud_type => :update) end private def update_authorized_filter diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index b38c60c996..ff97a6fddb 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -123,7 +123,7 @@ def traverse(controller, options = {}, &block) elsif controller.nil? || !skip_action_link(controller, link, *(Array(options[:for]))) security_method = link.security_method_set? || controller.respond_to?(link.security_method) authorized = if security_method - controller.send(link.security_method, *args) + controller.send(link.security_method, *(Array(options[:for]))) else options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action) end From 286e142e3ec0ab0a89a42200cdb4d321a465eac0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 7 Aug 2012 14:25:06 +0200 Subject: [PATCH 1622/2024] update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index b339abc237..b005a782c4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,7 @@ - Add missing triggering of as:element_updated in new subform rows - Fix conditions for :select in field_search - Fix datetime field search +- Fix authorization checking in member action links = 3.2.14 - Fix default sorting, it was broken in 3.2.13 From ac83e397c9d74f1ec74d28820fe11b9002a20514 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 8 Aug 2012 14:23:02 +0200 Subject: [PATCH 1623/2024] add ignore_order_from_association to ignore :order from association definition in nested scaffolds --- lib/active_scaffold/actions/nested.rb | 2 +- lib/active_scaffold/config/nested.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 660944fa80..b0eb43eee9 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -37,7 +37,7 @@ def configure_nested else as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => nested_parent_record.to_label) end - if nested.sorted? + if nested.sorted? && !active_scaffold_config.nested.ignore_order_from_association active_scaffold_config.list.user.nested_default_sorting = {:table_name => active_scaffold_config.model.model_name, :default_sorting => nested.default_sorting} end end diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index e3ab61181a..2fba93c2c7 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -6,16 +6,21 @@ def initialize(core_config) super @label = :add_existing_model @shallow_delete = self.class.shallow_delete + @ignore_order_from_association = self.class.ignore_order_from_association end # global level configuration # -------------------------- cattr_accessor :shallow_delete @@shallow_delete = true + + cattr_accessor :ignore_order_from_association # instance-level configuration # ---------------------------- attr_accessor :shallow_delete + + attr_accessor :ignore_order_from_association # Add a nested ActionLink def add_link(attribute, options = {}) From a436aedb27547a4e8b813bcfa93dcd1a0ad609b9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 9 Aug 2012 08:36:11 +0200 Subject: [PATCH 1624/2024] don't display column.css_class when is a proc in subsection --- frontends/default/views/_form.html.erb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index 04b86b2f36..9dacbb6cf8 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -2,6 +2,7 @@ scope ||= nil subsection_id ||= nil show_unauthorized_columns = active_scaffold_config.send(form_action).show_unauthorized_columns + column_css_class = column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %> <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= "style=\"display: none;\"".html_safe if columns.collapsed %>> <% columns.each :for => @record, :crud_type => (:read if show_unauthorized_columns) do |column| %> @@ -9,17 +10,17 @@ <% renders_as = column_renders_as(column) %> <% if renders_as == :subsection -%> <% subsection_id = sub_section_id(:sub_section => column.label) %> - <li class="sub-section <%= column.css_class %>"> + <li class="sub-section <%= column_css_class %>"> <h5><%= column.label %></h5> <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id, :form_action => form_action, :scope => scope } %> <%= link_to_visibility_toggle(subsection_id, {:default_visible => !column.collapsed}) -%> </li> <% elsif renders_as == :subform and !override_form_field?(column) and authorized -%> - <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %> <%=column.name%>-sub-form" id="<%= sub_form_id(:association => column.name) %>"> + <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column_css_class %> <%=column.name%>-sub-form" id="<%= sub_form_id(:association => column.name) %>"> <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column, :scope => scope } -%> </li> <% else -%> - <li class="form-element <%= 'required' if column.required? %> <%= column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %>"> + <li class="form-element <%= 'required' if column.required? %> <%= column_css_class %>"> <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column, :only_value => !authorized, :scope => scope } -%> </li> <% end -%> From 8395242696f596fd0ba4c0fc6548e2293315a9f4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 9 Aug 2012 08:37:29 +0200 Subject: [PATCH 1625/2024] update changelog Conflicts: CHANGELOG --- CHANGELOG | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index b005a782c4..68e983a432 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,7 +7,10 @@ - Fix nested with has_one associations - Support optgroup in :select and :chosen form_ui -= 3.2.15 (not released yet) += 3.2.16 +- Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group + += 3.2.15 - Prepare to unify field overrides and list_ui method signatures - Add :optional to update.persistent - Add missing triggering of as:element_updated in new subform rows From ac87fb29ce0f4eee0c28a9a7fb02363b79938145 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 13 Aug 2012 14:53:47 +0200 Subject: [PATCH 1626/2024] delete params in render_field action, if some associations are updated add_new links would have these params --- lib/active_scaffold/actions/core.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 91405606da..eadef41a98 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -33,11 +33,11 @@ def render_field_for_inplace_editing end def render_field_for_update_columns - column = active_scaffold_config.columns[params[:column]] + column = active_scaffold_config.columns[params.delete(:column)] unless column.nil? @source_id = params.delete(:source_id) @columns = column.update_columns - @scope = params[:scope] + @scope = params.delete(:scope) if column.send_form_on_update_column if @scope @@ -53,7 +53,7 @@ def render_field_for_update_columns @record = update_record_from_params(@record, active_scaffold_config.send(@scope ? :subform : (id ? :update : :create)).columns, hash) else @record = new_model - value = column_value_from_param_value(@record, column, params[:value]) + value = column_value_from_param_value(@record, column, params.delete(:value)) @record.send "#{column.name}=", value end From 3b51bf65b1d270ab16a2f6eba6ee91fc3ece8eba Mon Sep 17 00:00:00 2001 From: Craig P Jolicoeur <cpjolicoeur@gmail.com> Date: Mon, 13 Aug 2012 12:33:06 -0300 Subject: [PATCH 1627/2024] wrong parameter name used --- app/assets/javascripts/prototype/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index dd8240d6c2..c684443cab 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -928,7 +928,7 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra $super(); if (refreshed_content_or_reload) { if (typeof refreshed_content_or_reload == 'string') { - ActiveScaffold.update_row(this.target, refreshed_content_or_update); + ActiveScaffold.update_row(this.target, refreshed_content_or_reload); } else if (this.refresh_url) { var target = this.target; new Ajax.Request(this.refresh_url, { From a5291f1e85224a56a861d5b3cc44215ed83077ba Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Tue, 14 Aug 2012 10:01:55 +0200 Subject: [PATCH 1628/2024] fix main_path_to_return for nested forms --- .gitignore | 1 + lib/active_scaffold/helpers/controller_helpers.rb | 13 ++++--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index c918d37478..3979b07ba8 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,4 @@ pkg # # For kdevelop: *.kdev4 +.project diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 3452e0d706..2e8914457f 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -28,22 +28,17 @@ def main_path_to_return params[:return_to] else parameters = {} - if params[:parent_controller] - parameters[:controller] = params[:parent_controller] - #parameters[:eid] = params[:parent_controller] # not neeeded anymore? + if params[:parent_scaffold] && nested? && nested.singular_association? + parameters[:controller] = params[:parent_scaffold] + #parameters[:eid] = params[:parent_scaffold] # not neeeded anymore? end parameters.merge! nested.to_params if nested? if params[:parent_sti] parameters[:controller] = params[:parent_sti] #parameters[:eid] = nil # not neeeded anymore? end - parameters[:parent_column] = nil - parameters[:parent_id] = nil parameters[:action] = "index" - parameters[:id] = nil - parameters[:associated_id] = nil - parameters[:utf8] = nil - params_for(parameters) + params_for(parameters).except(:parent_column, :parent_id, :id, :associated_id, :utf8) end end From e4ddad0242669e6139316a6c015844d791549fe1 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Tue, 14 Aug 2012 10:41:21 +0200 Subject: [PATCH 1629/2024] Fix last commit about css_class --- CHANGELOG | 2 +- frontends/default/views/_form.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 68e983a432..120b4ac56e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,7 +7,7 @@ - Fix nested with has_one associations - Support optgroup in :select and :chosen form_ui -= 3.2.16 += 3.2.16 (not released) - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group = 3.2.15 diff --git a/frontends/default/views/_form.html.erb b/frontends/default/views/_form.html.erb index 9dacbb6cf8..111199aa09 100644 --- a/frontends/default/views/_form.html.erb +++ b/frontends/default/views/_form.html.erb @@ -2,10 +2,10 @@ scope ||= nil subsection_id ||= nil show_unauthorized_columns = active_scaffold_config.send(form_action).show_unauthorized_columns - column_css_class = column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %> <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= "style=\"display: none;\"".html_safe if columns.collapsed %>> <% columns.each :for => @record, :crud_type => (:read if show_unauthorized_columns) do |column| %> + <% column_css_class = column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %> <% authorized = show_unauthorized_columns ? @record.authorized_for?(:crud_type => form_action, :column => column.name) : true %> <% renders_as = column_renders_as(column) %> <% if renders_as == :subsection -%> From 4bd501db88600584d8e88042429eed8c155b49cf Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 16 Aug 2012 13:29:17 +0200 Subject: [PATCH 1630/2024] use date_bridge_column_date? to get datetime conversion --- lib/active_scaffold/finder.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 7ae1bb84cc..41268b9853 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -169,7 +169,9 @@ def i18n_number_to_native_format(value) end def datetime_conversion_for_condition(column) - if column.column + if respond_to? :date_bridge_column_date? + date_bridge_column_date?(column) ? :to_date : :to_time + elsif column.column column.column.type == :date ? :to_date : :to_time else :to_time From 3131bf4a0e94fbdbbfa880a410c7a5cd6c42e0e1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 16 Aug 2012 13:43:23 +0200 Subject: [PATCH 1631/2024] Revert "use date_bridge_column_date? to get datetime conversion" This reverts commit 4bd501db88600584d8e88042429eed8c155b49cf. --- lib/active_scaffold/finder.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 41268b9853..7ae1bb84cc 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -169,9 +169,7 @@ def i18n_number_to_native_format(value) end def datetime_conversion_for_condition(column) - if respond_to? :date_bridge_column_date? - date_bridge_column_date?(column) ? :to_date : :to_time - elsif column.column + if column.column column.column.type == :date ? :to_date : :to_time else :to_time From b72a7aa593f15d2a3e48b113d4ff7b3e6ffaf578 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 17 Aug 2012 12:32:51 +0200 Subject: [PATCH 1632/2024] restore constraints when controller is not nested, needed for self-associations --- lib/active_scaffold/actions/core.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index eadef41a98..fba7146b44 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -2,7 +2,7 @@ module ActiveScaffold::Actions module Core def self.included(base) base.class_eval do - before_filter :register_constraints_with_action_columns, :if => :embedded? + prepend_before_filter :register_constraints_with_action_columns, :unless => :nested? after_filter :clear_flashes rescue_from ActiveScaffold::RecordNotAllowed, ActiveScaffold::ActionNotAllowed, :with => :deny_access end From 444d96f4163ee9fa12e8c36e6f085f59f3493e03 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 17 Aug 2012 12:33:58 +0200 Subject: [PATCH 1633/2024] don't add self as constraint, needed for self-associations. Also convert to string foreign keys before comparing, by default are strings but can be defined as symbols --- lib/active_scaffold/data_structures/nested_info.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index ebac210918..0a63f025ff 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -135,11 +135,11 @@ def iterate_model_associations(model) @constrained_fields = Set.new constrained_fields << association.foreign_key.to_sym unless association.belongs_to? model.reflect_on_all_associations.each do |current| - if !current.belongs_to? && association.foreign_key == current.association_foreign_key + if !current.belongs_to? && association != current && association.foreign_key.to_s == current.association_foreign_key.to_s constrained_fields << current.name.to_sym @child_association = current if current.klass == @parent_model end - if association.foreign_key == current.foreign_key + if association.foreign_key.to_s == current.foreign_key.to_s # show columns for has_many and has_one child associationes constrained_fields << current.name.to_sym if current.belongs_to? if association.options[:as] and current.options[:polymorphic] From bb1e6a4e21d393ff21367d15dde3cd68d36f6057 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 17 Aug 2012 12:37:39 +0200 Subject: [PATCH 1634/2024] fix colspan for self-associations, fixes #184 --- frontends/default/views/_list_inline_adapter.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/frontends/default/views/_list_inline_adapter.html.erb index 9066d89c2c..316a4d8a71 100644 --- a/frontends/default/views/_list_inline_adapter.html.erb +++ b/frontends/default/views/_list_inline_adapter.html.erb @@ -5,7 +5,8 @@ else active_scaffold_config end - config.list.columns.count + 1 + # increment in 1 for self-associations, parent_model config will have constraints too + config.list.columns.count + 1 + (config == active_scaffold_config ? 1 : 0) end %> <%# nested_id, allows us to remove a nested scaffold programmatically %> From c959033ac0a3a09e4427224690dc91f857126d3f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 17 Aug 2012 12:58:56 +0200 Subject: [PATCH 1635/2024] update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 120b4ac56e..fe33b3463d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ = 3.2.16 (not released) - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group +- Fix constraints and colspan in self-referential associations = 3.2.15 - Prepare to unify field overrides and list_ui method signatures From 8dfbf6acdef3d8ec445edb154f6e169d82d0b9ea Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 17 Aug 2012 14:38:20 +0200 Subject: [PATCH 1636/2024] Fix rendering parent row after creating or updating in a nested form. Fixes #185 --- CHANGELOG | 1 + lib/active_scaffold/actions/list.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index fe33b3463d..e0f8cbcdb3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ = 3.2.16 (not released) - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group - Fix constraints and colspan in self-referential associations +- Fix rendering parent row after creating or updating in a nested form (singular associations) = 3.2.15 - Prepare to unify field overrides and list_ui method signatures diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 94281511e1..b1f429a6f0 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -50,6 +50,10 @@ def list_respond_to_yaml render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status end + def row_respond_to_html + render(:partial => 'row', :locals => {:record => @record}) + end + def row_respond_to_js render :action => 'row' end From 28af443baa508b14ae321b0cfe619162a7b2f214 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Mon, 20 Aug 2012 09:52:12 +0200 Subject: [PATCH 1637/2024] Allow block in association_options_find to use scopes to restrict options --- lib/active_scaffold/helpers/association_helpers.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/helpers/association_helpers.rb b/lib/active_scaffold/helpers/association_helpers.rb index bf17414254..950861c7e2 100644 --- a/lib/active_scaffold/helpers/association_helpers.rb +++ b/lib/active_scaffold/helpers/association_helpers.rb @@ -6,6 +6,7 @@ def association_options_find(association, conditions = nil) conditions = options_for_association_conditions(association) if conditions.nil? relation = association.klass.where(conditions).where(association.options[:conditions]) relation = relation.includes(association.options[:include]) if association.options[:include] + relation = yield(relation) if block_given? relation.all end From 44bee04a9277155f810718296ed89b9ff959f940 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 22 Aug 2012 10:36:20 +0200 Subject: [PATCH 1638/2024] translate select options for select form_ui (include_blank and prompt) --- CHANGELOG | 1 + lib/active_scaffold/helpers/form_column_helpers.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index e0f8cbcdb3..bc91a35193 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group - Fix constraints and colspan in self-referential associations - Fix rendering parent row after creating or updating in a nested form (singular associations) +- Translate include_blank and prompt in form_ui :select = 3.2.15 - Prepare to unify field overrides and list_ui method signatures diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 479c77f584..89abc8352e 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -113,6 +113,12 @@ def grouped_options_for_select(column, select_options, optgroup) end end + def active_scaffold_translate_select_options(options) + options[:include_blank] = as_(options[:include_blank]) if options[:include_blank].is_a? Symbol + options[:prompt] = as_(options[:prompt]) if options[:prompt].is_a? Symbol + options + end + def active_scaffold_input_singular_association(column, html_options) associated = @record.send(column.association.name) @@ -125,6 +131,7 @@ def active_scaffold_input_singular_association(column, html_options) html_options.update(column.options[:html_options] || {}) options.update(column.options) html_options[:name] = "#{html_options[:name]}[]" if html_options[:multiple] == true && !html_options[:name].to_s.ends_with?("[]") + active_scaffold_translate_select_options(options) if optgroup = options.delete(:optgroup) select(:record, method, grouped_options_for_select(column, select_options, optgroup), options, html_options) @@ -174,6 +181,7 @@ def active_scaffold_input_enum(column, html_options) end html_options.update(column.options[:html_options] || {}) options.update(column.options) + active_scaffold_translate_select_options(options) select(:record, column.name, options_for_select, options, html_options) end From 276dea987d1b03e52ce55a8dbc429a6d5d472ce4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 22 Aug 2012 13:36:55 +0200 Subject: [PATCH 1639/2024] add support for render_form_field in subforms with multiple trs --- CHANGELOG | 1 + app/assets/javascripts/jquery/active_scaffold.js | 9 ++------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index bc91a35193..4a34eed9cc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ - Add :chosen form_ui, and :chosen and :multi_chosen search_ui - Fix nested with has_one associations - Support optgroup in :select and :chosen form_ui +- Support render_form_field with multiple rows (rows with associated-record class) = 3.2.16 (not released) - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 95282f9cc7..632fa512b9 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -532,13 +532,8 @@ var ActiveScaffold = { if (errors.hasClass('association-record-errors')) { this.remove(errors); } - var associated = jQuery(record).next(); + record = jQuery(record).nextUntil('.association-record').andSelf(); this.remove(record); - while (associated.hasClass('associated-record')) { - record = associated; - associated = jQuery(record).next(); - this.remove(record); - } }, report_500_response: function(active_scaffold_id) { @@ -648,7 +643,7 @@ var ActiveScaffold = { render_form_field: function(source, content, options) { if (typeof(source) == 'string') source = '#' + source; var source = jQuery(source); - var element = source.closest('.association-record'); + var element = source.closest('.association-record').nextUntil('.association-record').andSelf(); if (element.length == 0) { element = source.closest('form > ol.form'); } From ad74a57f1785d45ba7763020f20fa63f8377dc30 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 24 Aug 2012 09:47:21 +0200 Subject: [PATCH 1640/2024] improve searching ActiveScaffold views and render :super --- lib/active_scaffold.rb | 14 ++++-- .../extensions/action_view_rendering.rb | 50 +++++++------------ 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 142bcd008d..9811988880 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -159,9 +159,14 @@ def self.exclude_bridges def self.root File.dirname(__FILE__) + "/.." end + + def details_for_lookup + super.merge(:active_scaffold_view_paths => self.class.active_scaffold_paths) + end module ClassMethods def active_scaffold(model_id = nil, &block) + extend Prefixes # initialize bridges here ActiveScaffold::Bridges.run_all @@ -211,12 +216,13 @@ def active_scaffold(model_id = nil, &block) end end end - self.append_view_path active_scaffold_paths self._add_sti_create_links if self.active_scaffold_config.add_sti_create_links? end - def parent_prefixes - @parent_prefixes ||= super << 'active_scaffold_overrides' << '' + module Prefixes + def parent_prefixes + @parent_prefixes ||= super << 'active_scaffold_overrides' + end end # To be called after include action modules @@ -300,7 +306,7 @@ def active_scaffold_paths @active_scaffold_paths = [] @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil? @active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil? - @active_scaffold_paths + @active_scaffold_paths = ActionView::PathSet.new(@active_scaffold_paths) end def active_scaffold_config diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 8eb5b45ce5..880d048587 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -1,16 +1,13 @@ module ActionView class LookupContext - module ViewPaths - def find_all_templates(name, partial = false, locals = {}) - prefixes.collect do |prefix| - view_paths.collect do |resolver| - temp_args = *args_for_lookup(name, [prefix], partial, locals, {}) - temp_args[1] = temp_args[1][0] - resolver.find_all(*temp_args) - end - end.flatten! - end + register_detail(:active_scaffold_view_paths) { nil } + def find(name, prefixes = [], partial = false, keys = [], options = {}) + template = @view_paths.find_all(*args_for_lookup(name, prefixes, partial, keys, options)).first + template ||= active_scaffold_view_paths.find(*args_for_lookup(name, '', partial, keys, options)) if active_scaffold_view_paths + raise(MissingTemplate.new(@view_paths, *args)) unless template + template end + alias :find_template :find end end @@ -40,21 +37,7 @@ module RenderingHelper # Defining options[:label] lets you completely customize the list title for the embedded scaffold. # def render_with_active_scaffold(*args, &block) - if args.first == :super - last_view = view_stack.last || {:view => instance_variable_get(:@virtual_path).split('/').last} - options = args[1] || {} - options[:locals] ||= {} - options[:locals].reverse_merge!(last_view[:locals] || {}) - if last_view[:templates].nil? - last_view[:templates] = lookup_context.find_all_templates(last_view[:view], last_view[:partial], options[:locals].keys) - last_view[:templates].shift - end - options[:template] = last_view[:templates].shift - view_stack << last_view - result = render_without_active_scaffold options - view_stack.pop - result - elsif args.first.is_a? Hash and args.first[:active_scaffold] + if args.first.is_a? Hash and args.first[:active_scaffold] require 'digest/md5' options = args.first @@ -88,14 +71,19 @@ def render_with_active_scaffold(*args, &block) end end + elsif args.first == :super + prefix, template = @virtual_path.split('/') + last_view = view_stack.last || {} + options = args[1] || {} + options[:locals] ||= {} + options[:locals].reverse_merge!(last_view[:locals] || {}) + options[:template] = template + options[:prefixes] = lookup_context.prefixes.drop((lookup_context.prefixes.find_index(prefix) || -1) + 1) + render_without_active_scaffold options else options = args.first - if options.is_a?(Hash) - current_view = {:view => options[:partial], :partial => true} if options[:partial] - current_view = {:view => options[:template], :partial => false} if current_view.nil? && options[:template] - current_view[:locals] = options[:locals] if !current_view.nil? && options[:locals] - view_stack << current_view if current_view.present? - end + current_view = {:locals => options[:locals]} if options.is_a?(Hash) + view_stack << current_view if current_view.present? result = render_without_active_scaffold(*args, &block) view_stack.pop if current_view.present? result From d4900abbbd36f64ce0f2b6a9ee9ea7117befda3d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 27 Aug 2012 09:45:03 +0200 Subject: [PATCH 1641/2024] use id for render_field only with send_form_on_update_columns, in other case is not used --- lib/active_scaffold/helpers/form_column_helpers.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 89abc8352e..422edd0414 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -89,7 +89,8 @@ def active_scaffold_input_options(column, scope = nil, options = {}) def update_columns_options(column, scope, options) if column.update_columns form_action = params[:action] == 'edit' ? :update : :create - url_params = {:action => 'render_field', :id => params[:id], :column => column.name} + url_params = {:action => 'render_field', :column => column.name} + url_params[:id] = @record.id if column.send_form_on_update_column url_params[:eid] = params[:eid] if params[:eid] url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope url_params[:scope] = scope if scope From 845849d866e62b09f0d846c66e0e4b69d7027051 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 27 Aug 2012 14:54:20 +0200 Subject: [PATCH 1642/2024] invoke dynamic_parameters with argument instead of using instance variables --- lib/active_scaffold/helpers/view_helpers.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 3ff57f743e..1b8ec33d26 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -240,9 +240,11 @@ def action_link_url_options(link, record) url_options[:controller] = link.controller.to_s if link.controller url_options.merge! link.parameters if link.parameters if link.dynamic_parameters.is_a?(Proc) - @link_record = record - url_options.merge! self.instance_eval(&(link.dynamic_parameters)) - @link_record = nil + if record.nil? + url_options.merge! link.dynamic_parameters.call + else + url_options.merge! link.dynamic_parameters.call(record) + end end url_options_for_nested_link(link.column, record, link, url_options) if link.nested_link? url_options_for_sti_link(link.column, record, link, url_options) unless record.nil? || active_scaffold_config.sti_children.nil? From ac0f18f550d0721e50f26a146e4a00a6507eab96 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 27 Aug 2012 15:39:14 +0200 Subject: [PATCH 1643/2024] cache_associations in actions which update a row --- lib/active_scaffold/actions/list.rb | 12 +++++++----- lib/active_scaffold/actions/mark.rb | 2 +- lib/active_scaffold/actions/show.rb | 4 +++- lib/active_scaffold/actions/update.rb | 6 ++++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index b1f429a6f0..23d88be71c 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -59,21 +59,21 @@ def row_respond_to_js end # The actual algorithm to prepare for the list view - def set_includes_for_list_columns + def set_includes_for_columns(action = :list) @cache_associations = true - includes_for_list_columns = active_scaffold_config.list.columns.collect{ |c| c.includes }.flatten.uniq.compact + includes_for_list_columns = active_scaffold_config.send(action).columns.collect{ |c| c.includes }.flatten.uniq.compact self.active_scaffold_includes.concat includes_for_list_columns end def get_row - set_includes_for_list_columns + set_includes_for_columns klass = beginning_of_chain.includes(active_scaffold_includes) @record = find_if_allowed(params[:id], :read, klass) end # The actual algorithm to prepare for the list view def do_list - set_includes_for_list_columns + set_includes_for_columns options = { :sorting => active_scaffold_config.list.user.sorting, :count_includes => active_scaffold_config.list.user.count_includes } @@ -135,7 +135,9 @@ def process_action_link_action(render_action = :action_update, crud_type = nil) @action_link = active_scaffold_config.action_links[action_name] if params[:id] && params[:id] && params[:id].to_i > 0 crud_type ||= (request.post? || request.put?) ? :update : :delete - @record = find_if_allowed(params[:id], crud_type) + set_includes_for_columns + klass = beginning_of_chain.includes(active_scaffold_includes) + @record = find_if_allowed(params[:id], crud_type, klass) unless @record.nil? yield @record else diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index eb6cb0d0d9..c0e8fb9da9 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -30,7 +30,7 @@ def mark_respond_to_html def mark_respond_to_js if params[:id] do_search if respond_to? :do_search - set_includes_for_list_columns + set_includes_for_columns if active_scaffold_config.actions.include? :list @page = find_page(:pagination => active_scaffold_config.mark.mark_all_mode != :page) render :action => 'on_mark' else diff --git a/lib/active_scaffold/actions/show.rb b/lib/active_scaffold/actions/show.rb index 852fca5561..c3fffb2d24 100644 --- a/lib/active_scaffold/actions/show.rb +++ b/lib/active_scaffold/actions/show.rb @@ -41,7 +41,9 @@ def show_respond_to_html # A simple method to retrieve and prepare a record for showing. # May be overridden to customize show routine def do_show - @record = find_if_allowed(params[:id], :read) + set_includes_for_columns(:show) if active_scaffold_config.actions.include? :list + klass = beginning_of_chain.includes(active_scaffold_includes) + @record = find_if_allowed(params[:id], :read, klass) end # The default security delegates to ActiveRecordPermissions. diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index f01182529d..7d1f5f62f0 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -65,7 +65,9 @@ def update_respond_to_yaml # A simple method to find and prepare a record for editing # May be overridden to customize the record (set default values, etc.) def do_edit - @record = find_if_allowed(params[:id], :update) + set_includes_for_columns if active_scaffold_config.actions.include? :list + klass = beginning_of_chain.includes(active_scaffold_includes) + @record = find_if_allowed(params[:id], :update, klass) end # A complex method to update a record. The complexity comes from the support for subforms, and saving associated records. @@ -104,7 +106,7 @@ def update_save(options = {}) end def do_update_column - @record = active_scaffold_config.model.find(params[:id]) + @record = find_if_allowed(params[:id], :read) if @record.authorized_for?(:crud_type => :update, :column => params[:column]) column = active_scaffold_config.columns[params[:column].to_sym] unless @record.column_for_attribute(params[:column]).nil? || @record.column_for_attribute(params[:column]).null From 87bd14fc582dcd34fa6159f0b8168aed57272b1f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 28 Aug 2012 12:54:31 +0200 Subject: [PATCH 1644/2024] fix overriding views in active_scaffold plugins --- lib/active_scaffold.rb | 4 --- lib/active_scaffold/actions/core.rb | 4 +++ .../extensions/action_view_rendering.rb | 29 +++++++++++++++---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 9811988880..e349589771 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -159,10 +159,6 @@ def self.exclude_bridges def self.root File.dirname(__FILE__) + "/.." end - - def details_for_lookup - super.merge(:active_scaffold_view_paths => self.class.active_scaffold_paths) - end module ClassMethods def active_scaffold(model_id = nil, &block) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index fba7146b44..3986779091 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -26,6 +26,10 @@ def embedded? def nested? false end + + def details_for_lookup + super.merge(:active_scaffold_view_paths => self.class.active_scaffold_paths) + end def render_field_for_inplace_editing @record = find_if_allowed(params[:id], :update) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 880d048587..4a22a053fc 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -1,11 +1,18 @@ module ActionView class LookupContext + attr_accessor :last_template register_detail(:active_scaffold_view_paths) { nil } + def find(name, prefixes = [], partial = false, keys = [], options = {}) - template = @view_paths.find_all(*args_for_lookup(name, prefixes, partial, keys, options)).first - template ||= active_scaffold_view_paths.find(*args_for_lookup(name, '', partial, keys, options)) if active_scaffold_view_paths + unless prefixes.one? && prefixes.first.blank? + template = @view_paths.find_all(*args_for_lookup(name, prefixes, partial, keys, options)).first + end + if active_scaffold_view_paths && template.nil? + view_paths = active_scaffold_view_paths.is_a?(ActionView::PathSet) ? active_scaffold_view_paths : ActionView::PathSet.new(active_scaffold_view_paths) + template = view_paths.find(*args_for_lookup(name, '', partial, keys, options)) + end raise(MissingTemplate.new(@view_paths, *args)) unless template - template + self.last_template = template end alias :find_template :find end @@ -77,9 +84,19 @@ def render_with_active_scaffold(*args, &block) options = args[1] || {} options[:locals] ||= {} options[:locals].reverse_merge!(last_view[:locals] || {}) - options[:template] = template - options[:prefixes] = lookup_context.prefixes.drop((lookup_context.prefixes.find_index(prefix) || -1) + 1) - render_without_active_scaffold options + options[:template] = template || prefix + # if template is nil we are rendering an active_scaffold (or active_scaffold's plugin) view + if template + options[:prefixes] = lookup_context.prefixes.drop((lookup_context.prefixes.find_index(prefix) || -1) + 1) + else + options[:prefixes] = [''] + active_scaffold_view_paths = lookup_context.active_scaffold_view_paths + last_view_path = File.dirname(lookup_context.last_template.inspect) + lookup_context.active_scaffold_view_paths = active_scaffold_view_paths.drop(active_scaffold_view_paths.find_index {|path| path.to_s == last_view_path} + 1) + end + result = render_without_active_scaffold options + lookup_context.active_scaffold_view_paths = active_scaffold_view_paths unless template + result else options = args.first current_view = {:locals => options[:locals]} if options.is_a?(Hash) From c05b1463b07a7f0d50dbe9da946ac2ed39dc1b3a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 28 Aug 2012 14:20:02 +0200 Subject: [PATCH 1645/2024] add background color for nested even rows --- app/assets/stylesheets/active_scaffold_colors.css.scss | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/active_scaffold_colors.css.scss b/app/assets/stylesheets/active_scaffold_colors.css.scss index f78158e626..aa127a4df4 100644 --- a/app/assets/stylesheets/active_scaffold_colors.css.scss +++ b/app/assets/stylesheets/active_scaffold_colors.css.scss @@ -48,6 +48,7 @@ $nested_bg: #DAFFCD !default; $nested_border_color: #7FCF00 !default; $nested_footer_color: #444 !default; $nested_column_bg: #ECFFE7 !default; +$nested_column_even_bg: #fff !default; $nested_column_border_color: $column_border_color !default; $second_nested_bg: #FFFFBB !default; @@ -228,10 +229,13 @@ border-color: $nested_border_color; color: $nested_footer_color; } -.active-scaffold .active-scaffold td { +.active-scaffold .active-scaffold tr.record { background-color: $nested_column_bg; border-color: $nested_column_border_color; } +.active-scaffold .active-scaffold tr.even-record { +background-color: $nested_column_even_bg; +} .active-scaffold .active-scaffold td.inline-adapter-cell { background-color: $second_nested_bg; From ea5cd8fbc123b6fb5e771b7f844386279ee0b25b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 29 Aug 2012 12:58:24 +0200 Subject: [PATCH 1646/2024] avoid crash when prefixes is nil, fixes #191 --- lib/active_scaffold/extensions/action_view_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 4a22a053fc..db47833c4c 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -4,7 +4,7 @@ class LookupContext register_detail(:active_scaffold_view_paths) { nil } def find(name, prefixes = [], partial = false, keys = [], options = {}) - unless prefixes.one? && prefixes.first.blank? + unless active_scaffold_view_paths && prefixes && prefixes.one? && prefixes.first.blank? template = @view_paths.find_all(*args_for_lookup(name, prefixes, partial, keys, options)).first end if active_scaffold_view_paths && template.nil? From e7b49e5f95e074d494be80df311f4b388d208181 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 29 Aug 2012 13:19:42 +0200 Subject: [PATCH 1647/2024] fix missing template exception, fixes #192 --- lib/active_scaffold/extensions/action_view_rendering.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index db47833c4c..c2c132f238 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -5,13 +5,16 @@ class LookupContext def find(name, prefixes = [], partial = false, keys = [], options = {}) unless active_scaffold_view_paths && prefixes && prefixes.one? && prefixes.first.blank? - template = @view_paths.find_all(*args_for_lookup(name, prefixes, partial, keys, options)).first + args = args_for_lookup(name, prefixes, partial, keys, options) + view_paths = @view_paths + template = @view_paths.find_all(*args).first end if active_scaffold_view_paths && template.nil? view_paths = active_scaffold_view_paths.is_a?(ActionView::PathSet) ? active_scaffold_view_paths : ActionView::PathSet.new(active_scaffold_view_paths) + args ||= args_for_lookup(name, '', partial, keys, options) template = view_paths.find(*args_for_lookup(name, '', partial, keys, options)) end - raise(MissingTemplate.new(@view_paths, *args)) unless template + raise(MissingTemplate.new(view_paths, *args)) unless template self.last_template = template end alias :find_template :find From a968e89c8381198d26d91bcad7d9e8a45e400fae Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 29 Aug 2012 22:32:54 +0200 Subject: [PATCH 1648/2024] fix mark for nested scaffolds, fixes #189 --- CHANGELOG | 1 + lib/active_scaffold/actions/mark.rb | 5 ++--- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4a34eed9cc..ee386d6a80 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,7 @@ - Fix constraints and colspan in self-referential associations - Fix rendering parent row after creating or updating in a nested form (singular associations) - Translate include_blank and prompt in form_ui :select +- Fix mark for nested scaffolds = 3.2.15 - Prepare to unify field overrides and list_ui method signatures diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index c0e8fb9da9..42958b1921 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -3,7 +3,7 @@ module Mark def self.included(base) base.before_filter :mark_authorized?, :only => :mark - base.prepend_before_filter :assign_marked_records_to_model + base.before_filter :assign_marked_records_to_model base.helper_method :marked_records end @@ -14,9 +14,8 @@ def mark do_demark end if marked_records.length > 0 - link = "<a href=\"#{url_for(:action=>:mark, :id=>'', :mark_target => :scope)}\" data-method=\"post\" data-remote=\"true\">#{as_ :mark_all_records}</a>" count = marked_records.length - flash[:info] = as_(:records_marked, :count => count, :model => active_scaffold_config.label(:count => count), :link => link) + flash[:info] = as_(:records_marked, :count => count, :model => active_scaffold_config.label(:count => count)) end respond_to_action(:mark) end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index bd6f443e02..bf644a31c1 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -292,7 +292,7 @@ def render_column_heading(column, sorting, sort_direction) if column.name == :as_marked tag_options[:data] = { :ie_mode => :inline_checkbox, - :ie_url => url_for(:controller => params_for[:controller], :action => 'mark', :id => '__id__', :eid => params[:eid]) + :ie_url => url_for(params_for(:action => 'mark', :id => '__id__')) } else tag_options[:data] = inplace_edit_data(column) if column.inplace_edit From 4e665fb7dea53a2640121a35d83f2d64862c52e0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 30 Aug 2012 09:55:53 +0200 Subject: [PATCH 1649/2024] fix sti creation --- CHANGELOG | 1 + .../javascripts/jquery/active_scaffold.js | 7 +++++++ .../javascripts/prototype/active_scaffold.js | 10 ++++++++++ frontends/default/views/on_create.js.erb | 4 +++- lib/active_scaffold/actions/core.rb | 7 ++++--- .../active_association_reflection.rb | 20 ------------------- .../helpers/controller_helpers.rb | 8 ++------ lib/active_scaffold/helpers/view_helpers.rb | 2 +- 8 files changed, 28 insertions(+), 31 deletions(-) delete mode 100644 lib/active_scaffold/extensions/active_association_reflection.rb diff --git a/CHANGELOG b/CHANGELOG index ee386d6a80..01467993a6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,7 @@ - Fix rendering parent row after creating or updating in a nested form (singular associations) - Translate include_blank and prompt in form_ui :select - Fix mark for nested scaffolds +- Fix STI creation = 3.2.15 - Prepare to unify field overrides and list_ui method signatures diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 632fa512b9..f58ca11aa4 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -505,6 +505,13 @@ var ActiveScaffold = { this.increment_record_count(tbody.closest('div.active-scaffold')); ActiveScaffold.highlight(new_row); }, + + create_record_row_from_url: function(active_scaffold_id, url, options) { + jQuery.get(url, function(row) { + ActiveScaffold.create_record_row(action_link.scaffold(), row, options); + action_link.close(); + }); + }, delete_record_row: function(row, page_reload_url) { if (typeof(row) == 'string') row = '#' + row; diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index c684443cab..940fbec66f 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -454,6 +454,16 @@ var ActiveScaffold = { this.increment_record_count(tbody.up('div.active-scaffold')); ActiveScaffold.highlight(new_row); }, + + create_record_row_from_url: function(action_link, url, options) { + new Ajax.Request(url, { + method: 'get', + onComplete: function(response) { + ActiveScaffold.create_record_row(action_link.scaffold(), row, options); + action_link.close(); + } + }); + }, delete_record_row: function(row, page_reload_url) { row = $(row); diff --git a/frontends/default/views/on_create.js.erb b/frontends/default/views/on_create.js.erb index 06fdbfac4c..70f7f4800a 100644 --- a/frontends/default/views/on_create.js.erb +++ b/frontends/default/views/on_create.js.erb @@ -5,8 +5,10 @@ var action_link = ActiveScaffold.find_action_link('<%= form_selector%>'); action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages'))%>'); <% if controller.send :successful? %> <% if render_parent? %> - <% if nested_singular_association? || render_parent_action == :row %> + <% if nested_singular_association? %> action_link.close(true); + <% elsif params[:parent_sti] && render_parent_action == :row %> + ActiveScaffold.create_record_row_from_url(action_link,'<%= url_for(render_parent_options) %>', <%= {:insert_at => insert_at}.to_json.html_safe %>); <% else %> ActiveScaffold.reload('<%= url_for render_parent_options %>'); <% end %> diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 3986779091..1cfc99bc70 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -173,11 +173,12 @@ def conditions_from_params def new_model model = beginning_of_chain - if model.columns_hash[column = model.inheritance_column] - build_options = {column.to_sym => active_scaffold_config.model_id} if nested? && nested.association && nested.association.collection? + if nested? && nested.association && nested.association.collection? && model.columns_hash[column = model.inheritance_column] model_name = params.delete(column) # in new action inheritance_column must be in params model_name ||= params[:record].delete(column) unless params[:record].blank? # in create action must be inside record key - model = model_name.camelize.constantize if model_name + model_name = model_name.camelize if model_name + model_name ||= active_scaffold_config.model.name + build_options = {column.to_sym => model_name} if model_name end model.respond_to?(:build) ? model.build(build_options || {}) : model.new end diff --git a/lib/active_scaffold/extensions/active_association_reflection.rb b/lib/active_scaffold/extensions/active_association_reflection.rb deleted file mode 100644 index 7cce939990..0000000000 --- a/lib/active_scaffold/extensions/active_association_reflection.rb +++ /dev/null @@ -1,20 +0,0 @@ -# Bugfix: building an sti model from an association fails -# https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6306-collection-associations-build-method-not-supported-for-sti -# https://github.com/rails/rails/issues/815 -# https://github.com/rails/rails/pull/1686 -ActiveRecord::Reflection::AssociationReflection.class_eval do - def klass_with_sti(*opts) - sti_col = klass.inheritance_column - if sti_col and (h = opts.first).is_a? Hash and (passed_type = ( h[sti_col] || h[sti_col.to_sym] )) and (new_klass = active_record.send(:compute_type, passed_type)) < klass - new_klass - else - klass - end - end - def build_association(*opts, &block) - klass_with_sti(*opts).new(*opts, &block) - end - def create_association(*opts, &block) - klass_with_sti(*opts).create(*opts, &block) - end -end diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 2e8914457f..63c5e644e9 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -54,12 +54,8 @@ def render_parent_options if nested_singular_association? {:controller => nested.parent_scaffold.controller_path, :action => :row, :id => nested.parent_id} elsif params[:parent_sti] - options = {:controller => params[:parent_sti], :action => render_parent_action} - if render_parent_action(params[:parent_sti]) == :index - options.merge(params.slice(:eid)) - else - options.merge({:id => @record.id}) - end + options = params_for(:controller => params[:parent_sti], :action => render_parent_action, :parent_sti => nil) + options.merge(:id => @record.id) if render_parent_action == :row end end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 1b8ec33d26..86e12e8482 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -298,7 +298,7 @@ def get_action_link_id(link, record = nil, column = nil) id = "#{column.association.name}-#{record.id}" unless record.nil? end end - action_id = "#{id_from_controller("#{link.controller}-") if params[:parent_controller]}#{link.action}" + action_id = "#{id_from_controller("#{link.controller}-") if params[:parent_controller] || link.controller != controller.controller_path}#{link.action}" action_link_id(action_id, id) end From 8b1e0453eb63e363d326189b57ed1e4667c2cd7d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 30 Aug 2012 10:15:27 +0200 Subject: [PATCH 1650/2024] fix null search for numeric fields --- CHANGELOG | 1 + lib/active_scaffold/finder.rb | 2 ++ lib/active_scaffold/helpers/human_condition_helpers.rb | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 01467993a6..df4dc76cc6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,7 @@ - Translate include_blank and prompt in form_ui :select - Fix mark for nested scaffolds - Fix STI creation +- Fix null search for numeric columns = 3.2.15 - Prepare to unify field overrides and list_ui method signatures diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 7ae1bb84cc..e1fab12120 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -84,6 +84,8 @@ def condition_for_column(column, value, text_search = :full) def condition_for_numeric(column, value) if !value.is_a?(Hash) ["%{search_sql} = ?", condition_value_for_numeric(column, value)] + elsif ActiveScaffold::Finder::NullComparators.include?(value[:opt]) + condition_for_null_type(column, value[:opt]) elsif value[:from].blank? or not ActiveScaffold::Finder::NumericComparators.include?(value[:opt]) nil elsif value[:opt] == 'BETWEEN' diff --git a/lib/active_scaffold/helpers/human_condition_helpers.rb b/lib/active_scaffold/helpers/human_condition_helpers.rb index 67f48c4a51..fce4cbc0c8 100644 --- a/lib/active_scaffold/helpers/human_condition_helpers.rb +++ b/lib/active_scaffold/helpers/human_condition_helpers.rb @@ -14,7 +14,7 @@ def active_scaffold_human_condition_for(column) else case search_ui when :integer, :decimal, :float - "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{format_number_value(controller.class.condition_value_for_numeric(column, value[:from]), column.options)} #{value[:opt] == 'BETWEEN' ? '- ' + format_number_value(controller.class.condition_value_for_numeric(column, value[:to]), column.options).to_s : ''}" + "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt].downcase).downcase} #{format_number_value(controller.class.condition_value_for_numeric(column, value[:from]), column.options) if value[:from].present?} #{value[:opt] == 'BETWEEN' ? '- ' + format_number_value(controller.class.condition_value_for_numeric(column, value[:to]), column.options).to_s : ''}" when :string opt = ActiveScaffold::Finder::StringComparators.index(value[:opt]) || value[:opt] "#{column.active_record_class.human_attribute_name(column.name)} #{as_(opt).downcase} '#{value[:from]}' #{opt == 'BETWEEN' ? '- ' + value[:to].to_s : ''}" From 73ba5e12d657bcf2f49b5781c79e6c7b70f7377d Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 30 Aug 2012 16:44:56 +0200 Subject: [PATCH 1651/2024] fix duplicated params in action_links, fixes #186 --- lib/active_scaffold/helpers/view_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 86e12e8482..4bcd9c8937 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -204,17 +204,17 @@ def query_string_for_action_links(link) return [@query_string, @non_nested_query_string] end keep = true - @query_string_params = Set.new + @query_string_params ||= Set.new query_string_for_all = nil query_string_options = [] non_nested_query_string_options = [] params_for.except(:controller, :action, :id).each do |key, value| + @query_string_params << key if link.parameters.include? key keep = false next end - @query_string_params << key qs = "#{key}=#{value}" if [:eid, :association, :parent_scaffold].include?(key) || conditions_from_params.include?(key) || (nested? && nested.constrained_fields.include?(key)) non_nested_query_string_options << qs From 218e1d7545419296a1114089be310a3e7c1cdb72 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 30 Aug 2012 17:24:44 +0200 Subject: [PATCH 1652/2024] keep order for records in plural subforms, so new records are saved in same order as form order --- CHANGELOG | 1 + lib/active_scaffold/attribute_params.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index df4dc76cc6..ab080698e1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ - Fix nested with has_one associations - Support optgroup in :select and :chosen form_ui - Support render_form_field with multiple rows (rows with associated-record class) +- keep order for records in plural subforms, so new records are saved in same order as form order = 3.2.16 (not released) - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 44c05dd71a..2339270ff4 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -137,7 +137,7 @@ def column_value_from_param_hash_value(parent_record, column, value) manage_nested_record_from_params(parent_record, column, value) elsif column.plural_association? # HACK to be able to delete all associated records, hash will include "0" => "" - value.collect {|key, value| manage_nested_record_from_params(parent_record, column, value) unless value == ""}.compact + value.sort.collect {|key, value| manage_nested_record_from_params(parent_record, column, value) unless value == ""}.compact else value end From de61d18a56fcbdec506f72953dd80aaabaa9f50a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 31 Aug 2012 15:15:49 +0200 Subject: [PATCH 1653/2024] update row or table after updating a column with inplace_edit --- CHANGELOG | 1 + .../javascripts/jquery/active_scaffold.js | 35 ++++++++++++++---- .../javascripts/jquery/jquery.editinplace.js | 4 +++ frontends/default/views/_refresh_list.js.erb | 2 +- frontends/default/views/row.js.erb | 2 +- frontends/default/views/update_column.js.erb | 36 +++++++++++-------- lib/active_scaffold/actions/update.rb | 19 +++++----- .../helpers/list_column_helpers.rb | 1 + 8 files changed, 68 insertions(+), 32 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index df4dc76cc6..9c2b52b73c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ - Fix nested with has_one associations - Support optgroup in :select and :chosen form_ui - Support render_form_field with multiple rows (rows with associated-record class) +- Support for updating row or table after updating a column with inplace_edit = 3.2.16 (not released) - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index f58ca11aa4..e0d971bf61 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -461,22 +461,22 @@ var ActiveScaffold = { jQuery(element).get(0).reset(); }, - disable_form: function(as_form) { + disable_form: function(as_form, skip_loading_indicator) { if (typeof(as_form) == 'string') as_form = '#' + as_form; as_form = jQuery(as_form) var loading_indicator = jQuery('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); - if (loading_indicator) loading_indicator.css('visibility','visible'); + if (!skip_loading_indicator && loading_indicator) loading_indicator.css('visibility','visible'); jQuery('input[type=submit]', as_form).attr('disabled', 'disabled'); - as_form[0].disabled_fields = jQuery("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled'); + jQuery("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled').attr('data-remove-disabled', true); }, - enable_form: function(as_form) { + enable_form: function(as_form, skip_loading_indicator) { if (typeof(as_form) == 'string') as_form = '#' + as_form; as_form = jQuery(as_form) var loading_indicator = jQuery('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); - if (loading_indicator) loading_indicator.css('visibility','hidden'); + if (!skip_loading_indicator && loading_indicator) loading_indicator.css('visibility','hidden'); jQuery('input[type=submit]', as_form).removeAttr('disabled'); - as_form[0].disabled_fields.removeAttr('disabled'); + jQuery("input[data-remove-disabled],select[data-remove-disabled],textarea[data-remove-disabled]", as_form).removeAttr('disabled data-remove-disabled'); }, focus_first_element_of_form: function(form_element) { @@ -581,6 +581,9 @@ var ActiveScaffold = { type: "POST", data: options['params'], dataType: options.ajax_data_type, + beforeSend: function(request, settings) { + if (options.beforeSend) options.beforeSend.call(checkbox, request, settings); + }, after: function(request){ checkbox.attr('disabled', 'disabled'); }, @@ -725,7 +728,7 @@ var ActiveScaffold = { element_id: 'editor_id', ajax_data_type: "script", delegate: { - willCloseEditInPlace: function(span, options, enteredText) { + willCloseEditInPlace: function(span, options) { if (span.data('addEmptyOnCancel')) span.closest('td').addClass('empty'); } }, @@ -781,6 +784,24 @@ var ActiveScaffold = { if (!options.delegate) options.delegate = {} options.delegate.didOpenEditInPlace = function(dom) { dom.trigger('as:element_updated'); } } + var actions, forms; + options.beforeSend = function(xhr, settings) { + switch (span.data('ie-update')) { + case 'update_row': + actions = span.closest('tr').find('.actions a:not(.disabled)').addClass('disabled'); + break; + case 'update_table': + var table = span.closest('.as_content'); + actions = table.find('.actions a:not(.disabled)').addClass('disabled'); + forms = table.find('.as_form'); + ActiveScaffold.disable_form(forms); + break; + } + } + options.error = options.success = function() { + if (actions) actions.removeClass('disabled'); + if (forms) ActiveScaffold.enable_form(forms); + } if (mode === 'inline_checkbox') { ActiveScaffold.process_checkbox_inplace_edit(span.find('input:checkbox'), options); } else { diff --git a/app/assets/javascripts/jquery/jquery.editinplace.js b/app/assets/javascripts/jquery/jquery.editinplace.js index 571ab834b6..e0d31fc3ff 100644 --- a/app/assets/javascripts/jquery/jquery.editinplace.js +++ b/app/assets/javascripts/jquery/jquery.editinplace.js @@ -84,6 +84,7 @@ $.fn.editInPlace.defaults = { callback: null, // function: function to be called when editing is complete; cancels ajax submission to the url param. Prototype: function(idOfEditor, enteredText, orinalHTMLContent, settingsParams, callbacks). The function needs to return the value that should be shown in the dom. Returning undefined means cancel and will restore the dom and trigger an error. callbacks is a dictionary with two functions didStartSaving and didEndSaving() that you can use to tell the inline editor that it should start and stop any saving animations it has configured. /* DEPRECATED in 2.1.0 */ Parameter idOfEditor, use $(this).attr('id') instead callback_skip_dom_reset: false, // boolean: set this to true if the callback should handle replacing the editor with the new value to show + beforeSend: null, // function: this function gets called before sending new value to server. Prototype: function(request, requestSettings) success: null, // function: this function gets called if server responds with a success. Prototype: function(newEditorContentString) error: null, // function: this function gets called if server responds with an error. Prototype: function(request) error_sink: function(idOfEditor, errorString) { alert(errorString); }, // function: gets id of the editor and the error. Make sure the editor has an id, or it will just be undefined. If set to null, no error will be reported. /* DEPRECATED in 2.1.0 */ Parameter idOfEditor, use $(this).attr('id') instead @@ -576,6 +577,9 @@ $.extend(InlineEditor.prototype, { type: "POST", data: data, dataType: that.settings.ajax_data_type, + beforeSend: function(request, settings) { + that.triggerCallback(that.settings.beforeSend, request, settings); + }, complete: function(request){ that.didEndSaving(); }, diff --git a/frontends/default/views/_refresh_list.js.erb b/frontends/default/views/_refresh_list.js.erb index d79ec9783f..9333b9cb16 100644 --- a/frontends/default/views/_refresh_list.js.erb +++ b/frontends/default/views/_refresh_list.js.erb @@ -1 +1 @@ -ActiveScaffold.replace_html('<%= active_scaffold_content_id %>', '<%= escape_javascript(render(:partial => 'list', :layout => false)) %>'); +ActiveScaffold.replace_html('<%= active_scaffold_content_id %>', '<%= escape_javascript(render('list')) %>'); diff --git a/frontends/default/views/row.js.erb b/frontends/default/views/row.js.erb index 36afd71ee5..4363a09009 100644 --- a/frontends/default/views/row.js.erb +++ b/frontends/default/views/row.js.erb @@ -1,2 +1,2 @@ -ActiveScaffold.update_row('<%= element_row_id(:action => :list) %>', '<%= escape_javascript render(:partial => 'row', :locals => {:record => @record}) %>'); +ActiveScaffold.update_row('<%= element_row_id(:action => :list) %>', '<%= escape_javascript render('row', :record => @record) %>'); <%= render :partial => 'update_calculations', :formats => [:js] %> diff --git a/frontends/default/views/update_column.js.erb b/frontends/default/views/update_column.js.erb index 5305eef641..91ee3a0b98 100644 --- a/frontends/default/views/update_column.js.erb +++ b/frontends/default/views/update_column.js.erb @@ -1,15 +1,23 @@ -<% @column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => params[:column]) %> -<% unless controller.send :successful? %> +<% sleep 1 %> +<% @column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => @column.name) -%> +<% unless controller.send :successful? -%> alert('<%= escape_javascript(@record.errors.full_messages.join("\n")) %>'); - <% @record.reload %> -<% end %> -<% column = active_scaffold_config.columns[params[:column]] %> -<% formatted_value = get_column_value(@record, column) %> -<% if column.inplace_edit %> - ActiveScaffold.update_inplace_edit('<%= @column_span_id %>','<%= escape_javascript(formatted_value) %>', <%= column_empty?(formatted_value).to_json %>); -<% else %> - ActiveScaffold.replace_html('<%= @column_span_id %>','<%= escape_javascript(formatted_value) %>'); -<% end %> -<% if column.calculation? %> - ActiveScaffold.replace_html('<%= active_scaffold_calculations_id(:column => column) %>', '<%= escape_javascript(render_column_calculation(column)) %>'); -<% end %> + <% @record.reload -%> +<% end -%> +<% if @column.inplace_edit + update_row = @column.inplace_edit if controller.send :successful? -%> + <% case update_row + when :update_row -%> + ActiveScaffold.update_row('<%= element_row_id(:action => :list) %>', '<%= escape_javascript render('row', :record => @record) %>'); + <% when :update_table -%> + ActiveScaffold.replace_html('<%= active_scaffold_content_id %>', '<%= escape_javascript(render('list')) %>'); + <% else + formatted_value = get_column_value(@record, @column) -%> + ActiveScaffold.update_inplace_edit('<%= @column_span_id %>','<%= escape_javascript(get_column_value(@record, @column)) %>', <%= column_empty?(formatted_value).to_json %>); + <% end -%> +<% else -%> + ActiveScaffold.replace_html('<%= @column_span_id %>','<%= escape_javascript(get_column_value(@record, @column)) %>'); +<% end -%> +<% if @column.calculation? -%> + ActiveScaffold.replace_html('<%= active_scaffold_calculations_id(:column => @column) %>', '<%= escape_javascript(render_column_calculation(@column)) %>'); +<% end -%> diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 7d1f5f62f0..2bcebb90e0 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -108,21 +108,22 @@ def update_save(options = {}) def do_update_column @record = find_if_allowed(params[:id], :read) if @record.authorized_for?(:crud_type => :update, :column => params[:column]) - column = active_scaffold_config.columns[params[:column].to_sym] - unless @record.column_for_attribute(params[:column]).nil? || @record.column_for_attribute(params[:column]).null - if @record.column_for_attribute(params[:column]).default == true + @column = active_scaffold_config.columns[params[:column].to_sym] + unless @column.column.nil? || @column.column.null + if @column.column.default == true params[:value] ||= false else - params[:value] ||= @record.column_for_attribute(params[:column]).default + params[:value] ||= @column.column.default end end - unless column.nil? - params[:value] = column_value_from_param_value(@record, column, params[:value]) - params[:value] = [] if params[:value].nil? && column.form_ui && column.plural_association? + unless @column.nil? + params[:value] = column_value_from_param_value(@record, @column, params[:value]) + params[:value] = [] if params[:value].nil? && @column.form_ui && @column.plural_association? end - @record.send("#{params[:column]}=", params[:value]) + @record.send("#{@column.name}=", params[:value]) before_update_save(@record) - @record.save + self.successful = @record.save + do_list if self.successful? && @column.inplace_edit == :update_table after_update_save(@record) end end diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index bf644a31c1..41c5c96a74 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -225,6 +225,7 @@ def active_scaffold_inplace_edit(record, column, options = {}) id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s} tag_options = {:id => element_cell_id(id_options), :class => "in_place_editor_field", :title => as_(:click_to_edit), :data => {:ie_id => record.id.to_s}} + tag_options[:data][:ie_update] = column.inplace_edit if column.inplace_edit != true content_tag(:span, as_(:inplace_edit_handle), :class => 'handle') << content_tag(:span, formatted_column, tag_options) From 69bb5fd1d30de6c9483cc09049118ff5957f53ce Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Sat, 1 Sep 2012 11:43:06 +0200 Subject: [PATCH 1654/2024] remove deprecated methods on 3.2.16 --- frontends/default/views/refresh_list.js.erb | 2 -- lib/active_scaffold/config/list.rb | 12 ------------ lib/active_scaffold/data_structures/column.rb | 10 ---------- lib/active_scaffold/helpers/list_column_helpers.rb | 7 +------ lib/active_scaffold/helpers/show_column_helpers.rb | 7 +------ 5 files changed, 2 insertions(+), 36 deletions(-) delete mode 100644 frontends/default/views/refresh_list.js.erb diff --git a/frontends/default/views/refresh_list.js.erb b/frontends/default/views/refresh_list.js.erb deleted file mode 100644 index c5855d99a7..0000000000 --- a/frontends/default/views/refresh_list.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -<% ActiveSupport::Deprecation.warn "You should use render :partial => 'refresh_list' instead of render :action => 'refresh_list'" %> -<%= render :partial => 'refresh_list' %> diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index e4f783edc7..df55020cc6 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -39,13 +39,6 @@ def initialize(core_config) cattr_accessor :page_links_outer_window @@page_links_outer_window = 0 - class << self - def page_links_window=(value) - ActiveSupport::Deprecation.warn("Use page_links_inner_window", caller(1)) - self.page_links_inner_window = value - end - end - # what string to use when a field is empty cattr_accessor :empty_field_text @@empty_field_text = '-' @@ -102,11 +95,6 @@ def columns # how many page links around current page to show attr_accessor :page_links_outer_window - def page_links_window=(value) - ActiveSupport::Deprecation.warn("Use page_links_inner_window", caller(1)) - self.page_links_inner_window = value - end - # What kind of pagination to use: # * true: The usual pagination # * :infinite: Treat the source as having an infinite number of pages (i.e. don't count the records; useful for large tables where counting is slow and we don't really care anyway) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 9309bcee09..3f7f72bbc4 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -72,16 +72,6 @@ def update_columns=(column_names) cattr_accessor :send_form_on_update_column attr_accessor :send_form_on_update_column - # column to be updated in a form when this column changes - def update_column=(column_name) - ActiveSupport::Deprecation.warn "Use update_columns= instead of update_column=" - self.update_columns = column_name - end - - # send all the form instead of only new value when this column change - cattr_accessor :send_form_on_update_column - attr_accessor :send_form_on_update_column - # sorting on a column can be configured four ways: # sort = true default, uses intelligent sorting sql default # sort = false sometimes sorting doesn't make sense diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index bf644a31c1..85b9ae90c6 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -6,12 +6,7 @@ module ListColumnHelpers def get_column_value(record, column) begin method = get_column_method(record, column) - value = if method(method).arity == 1 - ActiveSupport::Deprecation.warn("Add column argument to field override, signature is unified with list_ui") - send(method, record) - else - send(method, record, column) - end + value = send(method, record, column) value = ' '.html_safe if value.nil? or value.blank? # fix for IE 6 return value rescue Exception => e diff --git a/lib/active_scaffold/helpers/show_column_helpers.rb b/lib/active_scaffold/helpers/show_column_helpers.rb index f8f8ab399a..c0a10d8d66 100644 --- a/lib/active_scaffold/helpers/show_column_helpers.rb +++ b/lib/active_scaffold/helpers/show_column_helpers.rb @@ -8,12 +8,7 @@ def show_column_value(record, column) # we only pass the record as the argument. we previously also passed the formatted_value, # but mike perham pointed out that prohibited the usage of overrides to improve on the # performance of our default formatting. see issue #138. - if method(method).arity == 1 - ActiveSupport::Deprecation.warn("Add column argument to field override, signature is unified with list_ui") - send(method, record) - else - send(method, record, column) - end + send(method, record, column) # second, check if the dev has specified a valid list_ui for this column elsif column.list_ui and (method = override_show_column_ui(column.list_ui)) send(method, record, column) From d20a64f404280c3f4f0d1ffc5b992c3a934efb0d Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Sat, 1 Sep 2012 11:56:11 +0200 Subject: [PATCH 1655/2024] Fix recordselect inplace_edit with plural associations in ruby 1.9, fixes #193 --- CHANGELOG | 1 + lib/active_scaffold/attribute_params.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index ab080698e1..b06cbfca16 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,7 @@ - Fix mark for nested scaffolds - Fix STI creation - Fix null search for numeric columns +- Fix recordselect inplace_edit with plural associations in ruby 1.9 = 3.2.15 - Prepare to unify field overrides and list_ui method signatures diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 2339270ff4..091d0ae187 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -103,7 +103,7 @@ def column_value_from_param_simple_value(parent_record, column, value) # it's a single id column.association.klass.find(value) if value.present? elsif column.plural_association? - column_plural_assocation_value_from_value(column, value) + column_plural_assocation_value_from_value(column, Array(value)) elsif column.number? && [:i18n_number, :currency].include?(column.options[:format]) && column.form_ui != :number self.class.i18n_number_to_native_format(value) else From 34d229138aba37101a471f33987dc7b3e2c7a7a3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Sat, 1 Sep 2012 11:57:54 +0200 Subject: [PATCH 1656/2024] update changelog and version --- CHANGELOG | 2 +- lib/active_scaffold/version.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b06cbfca16..7e6e39596d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,7 +9,7 @@ - Support render_form_field with multiple rows (rows with associated-record class) - keep order for records in plural subforms, so new records are saved in same order as form order -= 3.2.16 (not released) += 3.2.16 - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group - Fix constraints and colspan in self-referential associations - Fix rendering parent row after creating or updating in a nested form (singular associations) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index a2e369b22b..a5fb5ee44d 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -1,8 +1,8 @@ module ActiveScaffold module Version MAJOR = 3 - MINOR = 2 - PATCH = 14 + MINOR = 3 + PATCH = "0rc" STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 08e82288535407dd66ad0f7c96ce3b2855135038 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 3 Sep 2012 00:22:03 +0200 Subject: [PATCH 1657/2024] support add_subgroup in horizontal subforms --- CHANGELOG | 3 +- .../default/views/_form_association.html.erb | 5 +- ....erb => _form_association_record.html.erb} | 57 ++++++++++++++----- .../default/views/_form_attribute.html.erb | 20 +++---- .../views/_horizontal_subform.html.erb | 3 +- .../views/_horizontal_subform_header.html.erb | 5 +- .../views/_horizontal_subform_record.html.erb | 43 -------------- .../default/views/_vertical_subform.html.erb | 3 +- .../helpers/form_column_helpers.rb | 8 +++ 9 files changed, 70 insertions(+), 77 deletions(-) rename frontends/default/views/{_vertical_subform_record.html.erb => _form_association_record.html.erb} (50%) delete mode 100644 frontends/default/views/_horizontal_subform_record.html.erb diff --git a/CHANGELOG b/CHANGELOG index 7e6e39596d..115da2893c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,7 +7,8 @@ - Fix nested with has_one associations - Support optgroup in :select and :chosen form_ui - Support render_form_field with multiple rows (rows with associated-record class) -- keep order for records in plural subforms, so new records are saved in same order as form order +- Keep order for records in plural subforms, so new records are saved in same order as form order +- Support add_subgroup in horizontal subforms = 3.2.16 - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group diff --git a/frontends/default/views/_form_association.html.erb b/frontends/default/views/_form_association.html.erb index d615e1988e..ab48385f44 100644 --- a/frontends/default/views/_form_association.html.erb +++ b/frontends/default/views/_form_association.html.erb @@ -11,8 +11,9 @@ subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_reco <h5><%= column.label -%></h5> <div id ="<%= subform_div_id %>" <%= 'style="display: none;"'.html_safe if column.collapsed -%>> <%# HACK to be able to delete all associated records %> -<%= hidden_field_tag "#{active_scaffold_input_options(column, scope)[:name]}[0]", '' if column.plural_association? %> -<%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record, :scope => scope} %> + <%= hidden_field_tag "#{active_scaffold_input_options(column, scope)[:name]}[0]", '' if column.plural_association? %> + <%= render :partial => subform_partial_for_column(column), :locals => {:column => column, :parent_record => parent_record, :associated => associated, :show_blank_record => show_blank_record, :scope => scope} %> + <%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated, :scope => scope} -%> </div> <%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%> <% diff --git a/frontends/default/views/_vertical_subform_record.html.erb b/frontends/default/views/_form_association_record.html.erb similarity index 50% rename from frontends/default/views/_vertical_subform_record.html.erb rename to frontends/default/views/_form_association_record.html.erb index 7178fdcd71..edc02f2396 100644 --- a/frontends/default/views/_vertical_subform_record.html.erb +++ b/frontends/default/views/_form_association_record.html.erb @@ -6,38 +6,65 @@ config = active_scaffold_config_for(@record.class) options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) tr_id = "association-#{options[:id]}" + + if config.subform.layout == :vertical + row_tag ||= :ol + column_tag ||= :li + default_col_class = ['form-element'] + flatten = true unless local_assigns.has_key? :flatten + else + row_tag ||= :tr + column_tag ||= :td + default_col_class = [] + flatten ||= false + end + + columns_length = 0 + columns_groups = [] -%> -<ol id="<%= tr_id %>" class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> -<% config.subform.columns.each :for => @record.class, :crud_type => :read, :flatten => true do |column| %> +<%= content_tag row_tag, :id => tr_id, :class => "association-record#{' association-record-new' if @record.new_record?}#{' locked' if locked}" do %> +<% config.subform.columns.each :for => @record.class, :crud_type => :read, :flatten => flatten do |column| %> <% + if column.is_a? ActiveScaffold::DataStructures::ActionColumns + columns_groups << column + next + end + next unless in_subform?(column, parent_record) + columns_length += 1 show_actions = true column = column.clone column.form_ui ||= :select if column.association - col_class = ['form-element'] + col_class = default_col_class.clone col_class << 'required' if column.required? - col_class << column.css_class unless column.css_class.nil? + col_class << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) col_class << 'hidden' if column_renders_as(column) == :hidden -%> - <li class="<%= col_class.join(' ') %>"> - <% unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) -%> - <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%> - <% else -%> - <%= content_tag :span, get_column_value(@record, column), active_scaffold_input_options(column, scope).except(:name) -%> - <% end -%> - </li> + <%= content_tag column_tag, :class => col_class.join(' ') do %> + <%= active_scaffold_render_subform_column(column, scope, crud_type, readonly) %> + <% end %> <% end -%> <% if show_actions -%> - <li class="actions"> + <%= content_tag column_tag, :class => "actions" do %> <% if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> <% destroy_id = "#{options[:id]}-destroy" %> <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.delete_subform_record(\"#{tr_id}\"); return false;", :style=> "display: none;" %> <%= javascript_tag("ActiveScaffold.show('#{destroy_id}');") if !locked %> - <% end %> + <% end %> <% unless @record.new_record? %> <input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= @record.id -%>" /> <% end -%> - </li> + <% end %> <% end -%> -</ol> +<% end %> + +<% columns_groups.each do |column| %> +<%= content_tag row_tag, :class => 'associated_record' do %> + <%= content_tag column_tag, :colspan => columns_length do %> + <% column.each :for => @record.class, :crud_type => :read, :flatten => true do |col| %> + <%= active_scaffold_render_subform_column(col, scope, crud_type, readonly) %> + <% end %> + <% end %> +<% end %> +<% end %> \ No newline at end of file diff --git a/frontends/default/views/_form_attribute.html.erb b/frontends/default/views/_form_attribute.html.erb index 77136bd507..09b6626908 100644 --- a/frontends/default/views/_form_attribute.html.erb +++ b/frontends/default/views/_form_attribute.html.erb @@ -7,17 +7,17 @@ <label for="<%= column_options[:id] %>"><%= column.label %></label> </dt> <dd> - <% unless local_assigns[:only_value] %> + <% unless local_assigns[:only_value] %> <%=raw active_scaffold_input_for column, scope %> - <% else %> + <% else %> <%= content_tag :span, get_column_value(@record, column), column_options.except(:name) %> - <%= hidden_field :record, column.association ? column.association.foreign_key : column.name, active_scaffold_input_options(column, scope) -%> - <% end %> - <% if column.update_columns -%> - <%= loading_indicator_tag(:action => :render_field, :id => params[:id]) %> - <% end -%> - <% if column.description.present? -%> - <span class="description"><%= column.description %></span> - <% end -%> + <%= hidden_field :record, column.association ? column.association.foreign_key : column.name, column_options -%> + <% end %> + <% if column.update_columns -%> + <%= loading_indicator_tag(:action => :render_field, :id => params[:id]) %> + <% end -%> + <% if column.description.present? -%> + <span class="description"><%= column.description %></span> + <% end -%> </dd> </dl> diff --git a/frontends/default/views/_horizontal_subform.html.erb b/frontends/default/views/_horizontal_subform.html.erb index 29fa339bbc..ac8406ef41 100644 --- a/frontends/default/views/_horizontal_subform.html.erb +++ b/frontends/default/views/_horizontal_subform.html.erb @@ -12,11 +12,10 @@ </td> </tr> <% end %> - <%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> + <%= render :partial => 'form_association_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> <% end -%> </tbody> <tfoot> <%= render :partial => 'horizontal_subform_footer', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column} %> </tfoot> </table> -<%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated, :scope => scope} -%> diff --git a/frontends/default/views/_horizontal_subform_header.html.erb b/frontends/default/views/_horizontal_subform_header.html.erb index 32261420e9..59281f73b3 100644 --- a/frontends/default/views/_horizontal_subform_header.html.erb +++ b/frontends/default/views/_horizontal_subform_header.html.erb @@ -1,9 +1,10 @@ <thead> <tr> <% - active_scaffold_config_for(record.class).subform.columns.each :for => record.class, :crud_type => :read, :flatten => true do |column| - hidden = column_renders_as(column) == :hidden + active_scaffold_config_for(record.class).subform.columns.each :for => record.class, :crud_type => :read do |column| + next if column.is_a? ActiveScaffold::DataStructures::ActionColumns next unless in_subform?(column, parent_record) + hidden = column_renders_as(column) == :hidden -%> <th class="<%= "#{column.name}-column #{'required' if column.required?} #{'hidden' if hidden}" %>"><label><%= column.label unless hidden %></label></th> <% end -%> diff --git a/frontends/default/views/_horizontal_subform_record.html.erb b/frontends/default/views/_horizontal_subform_record.html.erb deleted file mode 100644 index 7bbd18c772..0000000000 --- a/frontends/default/views/_horizontal_subform_record.html.erb +++ /dev/null @@ -1,43 +0,0 @@ -<% - record_column = column - readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) - crud_type = @record.new_record? ? :create : (readonly ? :read : :update) - show_actions = false - config = active_scaffold_config_for(@record.class) - options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) - tr_id = "association-#{options[:id]}" --%> -<tr id="<%= tr_id %>" class="association-record <%= 'association-record-new' if @record.new_record? -%> <%= 'locked' if locked -%>"> -<% config.subform.columns.each :for => @record.class, :crud_type => :read, :flatten => true do |column| %> -<% - next unless in_subform?(column, parent_record) - show_actions = true - column = column.clone - column.form_ui ||= :select if column.association - - col_class = [] - col_class << 'required' if column.required? - col_class << column.css_class unless column.css_class.nil? - col_class << 'hidden' if column_renders_as(column) == :hidden --%> - <td class="<%= col_class.join(' ') %>"> - <% unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) -%> - <%= render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } -%> - <% else -%> - <%= content_tag :span, get_column_value(@record, column), active_scaffold_input_options(column, scope).except(:name) -%> - <% end -%> - </td> -<% end -%> -<% if show_actions -%> - <td class="actions"> - <% if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> - <% destroy_id = "#{options[:id]}-destroy" %> - <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.delete_subform_record(\"#{tr_id}\"); return false;", :style=> "display: none;" %> - <%= javascript_tag("ActiveScaffold.show('#{destroy_id}');") if !locked %> - <% end %> - <% unless @record.new_record? %> - <input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= @record.id -%>" /> - <% end -%> - </td> -<% end -%> -</tr> diff --git a/frontends/default/views/_vertical_subform.html.erb b/frontends/default/views/_vertical_subform.html.erb index 26614b4490..3ae089448e 100644 --- a/frontends/default/views/_vertical_subform.html.erb +++ b/frontends/default/views/_vertical_subform.html.erb @@ -6,7 +6,6 @@ <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> </div> <% end %> - <%= render :partial => 'vertical_subform_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> + <%= render :partial => 'form_association_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> <% end -%> </div> -<%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated, :scope => scope} -%> diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 422edd0414..c7a974cc12 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -58,6 +58,14 @@ def active_scaffold_render_input(column, options) raise e end end + + def active_scaffold_render_subform_column(column, scope, crud_type, readonly) + unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) + render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } + else + content_tag :span, get_column_value(@record, column), active_scaffold_input_options(column, scope).except(:name) + end + end # the standard active scaffold options used for textual inputs def active_scaffold_input_text_options(options = {}) From c63b6fe2efd5672252d0cd63c1f04ab33891b2f3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 3 Sep 2012 09:35:17 +0200 Subject: [PATCH 1658/2024] use new view in edit_associated --- frontends/default/views/edit_associated.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/edit_associated.js.erb b/frontends/default/views/edit_associated.js.erb index 94547a95fb..fd7c067576 100644 --- a/frontends/default/views/edit_associated.js.erb +++ b/frontends/default/views/edit_associated.js.erb @@ -1,5 +1,5 @@ <% -associated_form = render :partial => "#{subform_partial_for_column(@column)}_record", :locals => {:scope => @scope, :parent_record => @parent_record, :column => @column, :locked => @record.new_record? && @column.singular_association?} +associated_form = render :partial => "form_association_record", :locals => {:scope => @scope, :parent_record => @parent_record, :column => @column, :locked => @record.new_record? && @column.singular_association?} options = {:singular => false} if @column.singular_association? options[:singular] = true From e7bb59f961374d2fd3e01904d99ce962c4e8e466 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 3 Sep 2012 09:43:27 +0200 Subject: [PATCH 1659/2024] change class name --- frontends/default/views/_form_association_record.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/_form_association_record.html.erb b/frontends/default/views/_form_association_record.html.erb index edc02f2396..27d242b685 100644 --- a/frontends/default/views/_form_association_record.html.erb +++ b/frontends/default/views/_form_association_record.html.erb @@ -60,7 +60,7 @@ <% end %> <% columns_groups.each do |column| %> -<%= content_tag row_tag, :class => 'associated_record' do %> +<%= content_tag row_tag, :class => 'associated-record' do %> <%= content_tag column_tag, :colspan => columns_length do %> <% column.each :for => @record.class, :crud_type => :read, :flatten => true do |col| %> <%= active_scaffold_render_subform_column(col, scope, crud_type, readonly) %> From 0a969476f60f1aeb07b495a76b3c52dd7ade441f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 3 Sep 2012 10:04:57 +0200 Subject: [PATCH 1660/2024] support for updating columns after updating a column with inplace edit --- CHANGELOG | 2 +- frontends/default/views/_update_column.js.erb | 14 ++++++++++++++ frontends/default/views/update_column.js.erb | 8 ++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 frontends/default/views/_update_column.js.erb diff --git a/CHANGELOG b/CHANGELOG index 9cebc4df12..080b1b86a1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,7 +7,7 @@ - Fix nested with has_one associations - Support optgroup in :select and :chosen form_ui - Support render_form_field with multiple rows (rows with associated-record class) -- Support for updating row or table after updating a column with inplace_edit +- Support for updating columns, row or table after updating a column with inplace_edit - Keep order for records in plural subforms, so new records are saved in same order as form order - Support add_subgroup in horizontal subforms diff --git a/frontends/default/views/_update_column.js.erb b/frontends/default/views/_update_column.js.erb new file mode 100644 index 0000000000..7ef476d2d3 --- /dev/null +++ b/frontends/default/views/_update_column.js.erb @@ -0,0 +1,14 @@ +<% + column = if update_column.is_a? ActiveScaffold::DataStructures::Column + update_column + else + active_scaffold_config.columns[update_column.to_sym] + end + @rendered ||= Set.new + return if @rendered.include? column.name + @rendered << column.name +-%> +ActiveScaffold.replace_html('<%= row_id %> .<%= column.name %>-column','<%= escape_javascript(get_column_value(@record, column)) %>'); +<% if column.update_columns && !column.update_columns.empty? %> + <%= render(:partial => 'update_column', :collection => column.update_columns, :locals => {:row_id => row_id})%> +<% end %> diff --git a/frontends/default/views/update_column.js.erb b/frontends/default/views/update_column.js.erb index 91ee3a0b98..acfc84010c 100644 --- a/frontends/default/views/update_column.js.erb +++ b/frontends/default/views/update_column.js.erb @@ -6,14 +6,18 @@ <% end -%> <% if @column.inplace_edit update_row = @column.inplace_edit if controller.send :successful? -%> - <% case update_row + <% case @column.inplace_edit when :update_row -%> ActiveScaffold.update_row('<%= element_row_id(:action => :list) %>', '<%= escape_javascript render('row', :record => @record) %>'); <% when :update_table -%> ActiveScaffold.replace_html('<%= active_scaffold_content_id %>', '<%= escape_javascript(render('list')) %>'); <% else formatted_value = get_column_value(@record, @column) -%> - ActiveScaffold.update_inplace_edit('<%= @column_span_id %>','<%= escape_javascript(get_column_value(@record, @column)) %>', <%= column_empty?(formatted_value).to_json %>); + ActiveScaffold.update_inplace_edit('<%= @column_span_id %>','<%= escape_javascript(formatted_value) %>', <%= column_empty?(formatted_value).to_json %>); + <% if update_row == :update_columns && @column.update_columns + @rendered = Set.new([@column.name]) -%> + <%= render :partial => 'update_column', :collection => Array(@column.update_columns), :locals => {:row_id => element_row_id(:action => :list, :id => @record.id)} %> + <% end %> <% end -%> <% else -%> ActiveScaffold.replace_html('<%= @column_span_id %>','<%= escape_javascript(get_column_value(@record, @column)) %>'); From 21b05389e73dfb20b983a33f096e1e4feb2134ea Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 3 Sep 2012 13:44:00 +0200 Subject: [PATCH 1661/2024] use a new attribute for :update_row and others, so can be used with inplace_edit :ajax too --- frontends/default/views/_update_column.js.erb | 2 +- frontends/default/views/update_column.js.erb | 6 +++--- lib/active_scaffold/data_structures/column.rb | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/frontends/default/views/_update_column.js.erb b/frontends/default/views/_update_column.js.erb index 7ef476d2d3..77d958c235 100644 --- a/frontends/default/views/_update_column.js.erb +++ b/frontends/default/views/_update_column.js.erb @@ -10,5 +10,5 @@ -%> ActiveScaffold.replace_html('<%= row_id %> .<%= column.name %>-column','<%= escape_javascript(get_column_value(@record, column)) %>'); <% if column.update_columns && !column.update_columns.empty? %> - <%= render(:partial => 'update_column', :collection => column.update_columns, :locals => {:row_id => row_id})%> + <%= render(:partial => 'update_column', :collection => column.update_columns & active_scaffold_config.list.columns.names, :locals => {:row_id => row_id})%> <% end %> diff --git a/frontends/default/views/update_column.js.erb b/frontends/default/views/update_column.js.erb index acfc84010c..e0a4a7f33c 100644 --- a/frontends/default/views/update_column.js.erb +++ b/frontends/default/views/update_column.js.erb @@ -5,7 +5,7 @@ <% @record.reload -%> <% end -%> <% if @column.inplace_edit - update_row = @column.inplace_edit if controller.send :successful? -%> + update_row = @column.inplace_edit_update if controller.send :successful? -%> <% case @column.inplace_edit when :update_row -%> ActiveScaffold.update_row('<%= element_row_id(:action => :list) %>', '<%= escape_javascript render('row', :record => @record) %>'); @@ -14,9 +14,9 @@ <% else formatted_value = get_column_value(@record, @column) -%> ActiveScaffold.update_inplace_edit('<%= @column_span_id %>','<%= escape_javascript(formatted_value) %>', <%= column_empty?(formatted_value).to_json %>); - <% if update_row == :update_columns && @column.update_columns + <% if update_row == :update_columns && @column.update_columns && !@column.update_columns.empty? @rendered = Set.new([@column.name]) -%> - <%= render :partial => 'update_column', :collection => Array(@column.update_columns), :locals => {:row_id => element_row_id(:action => :list, :id => @record.id)} %> + <%= render :partial => 'update_column', :collection => @column.update_columns & active_scaffold_config.list.columns.names, :locals => {:row_id => element_row_id(:action => :list, :id => @record.id)} %> <% end %> <% end -%> <% else -%> diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 3f7f72bbc4..1c8d392f86 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -13,6 +13,8 @@ def inplace_edit=(value) self.clear_link if value @inplace_edit = value end + + attr_accessor :inplace_edit_update # Whether this column set is collapsed by default in contexts where collapsing is supported attr_accessor :collapsed From cbed0340a36ead5c1e3a8c10bb46db71b5f871a6 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 3 Sep 2012 02:58:03 -1000 Subject: [PATCH 1662/2024] fix update_colums, row and table in nested scaffolds --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 71965dd691..fa995291e0 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -244,7 +244,7 @@ def inplace_edit_control_css_class def inplace_edit_data(column) data = {} - data[:ie_url] = url_for({:controller => params_for[:controller], :action => "update_column", :column => column.name, :id => '__id__'}) + data[:ie_url] = url_for(params_for(:action => "update_column", :column => column.name, :id => '__id__')) data[:ie_cancel_text] = column.options[:cancel_text] || as_(:cancel) data[:ie_loading_text] = column.options[:loading_text] || as_(:loading) data[:ie_save_text] = column.options[:save_text] || as_(:update) From 172d7bc461b0e051e923ccbb921a20f16dcfd2d7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 3 Sep 2012 03:07:31 -1000 Subject: [PATCH 1663/2024] fix typo --- frontends/default/views/update_column.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontends/default/views/update_column.js.erb b/frontends/default/views/update_column.js.erb index e0a4a7f33c..48ea8994d1 100644 --- a/frontends/default/views/update_column.js.erb +++ b/frontends/default/views/update_column.js.erb @@ -6,7 +6,7 @@ <% end -%> <% if @column.inplace_edit update_row = @column.inplace_edit_update if controller.send :successful? -%> - <% case @column.inplace_edit + <% case update_row when :update_row -%> ActiveScaffold.update_row('<%= element_row_id(:action => :list) %>', '<%= escape_javascript render('row', :record => @record) %>'); <% when :update_table -%> From c2950e99ac0076fbcd3669b630faf8905290bdf8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 4 Sep 2012 03:22:58 -1000 Subject: [PATCH 1664/2024] remove associated_id (from add_existing select) from params_for --- lib/active_scaffold/helpers/controller_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 63c5e644e9..d4a6947dd7 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -12,7 +12,7 @@ def params_for(options = {}) # :sort, :sort_direction, and :page are arguments that stored in the session. they need not propagate. # and wow. no we don't want to propagate :record. # :commit is a special rails variable for form buttons - blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token, :iframe] + blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token, :iframe, :associated_id] unless @params_for @params_for = {} params.select { |key, value| blacklist.exclude? key.to_sym if key }.each {|key, value| @params_for[key.to_sym] = value.duplicable? ? value.clone : value} From afed461f13e1dc43ecca2e7251152b9def25c9e8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 4 Sep 2012 16:04:45 +0200 Subject: [PATCH 1665/2024] fix nested for belongs_to associations with :list action --- CHANGELOG | 2 +- lib/active_scaffold/actions/nested.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 080b1b86a1..95ebd2d8f5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,7 +4,7 @@ - Drop support for rails 3.1 - Add HTML5 form fields - Add :chosen form_ui, and :chosen and :multi_chosen search_ui -- Fix nested with has_one associations +- Fix nested with has_one associations, and belongs_to associations with :list action - Support optgroup in :select and :chosen form_ui - Support render_form_field with multiple rows (rows with associated-record class) - Support for updating columns, row or table after updating a column with inplace_edit diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index b0eb43eee9..193f50f897 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -73,13 +73,15 @@ def include_habtm_actions end def beginning_of_chain - if nested? && nested.association && !nested.association.belongs_to? + if nested? && nested.association if nested.association.collection? nested.parent_scope.send(nested.association.name) elsif nested.association.options[:through] # has_one :through doesn't need conditions active_scaffold_config.model elsif nested.child_association.belongs_to? active_scaffold_config.model.where(nested.child_association.foreign_key => nested.parent_scope) + elsif nested.association.belongs_to? + active_scaffold_config.model.joins(nested.child_association.name).where(nested.association.active_record.table_name => {nested.association.active_record.primary_key => nested.parent_scope}) end elsif nested? && nested.scope nested.parent_scope.send(nested.scope) From da99129d8547b950fe16e123930bb30b48f04fe5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 4 Sep 2012 18:04:39 +0200 Subject: [PATCH 1666/2024] fix nested links for self-associations, fixes #180 --- lib/active_scaffold/actions/core.rb | 2 +- .../data_structures/nested_info.rb | 56 ++++++++----------- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 3 files changed, 24 insertions(+), 36 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 1cfc99bc70..664e906a99 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -164,7 +164,7 @@ def conditions_from_params params.reject {|key, value| [:controller, :action, :id, :page, :sort, :sort_direction].include?(key.to_sym)}.each do |key, value| next unless active_scaffold_config.model.columns_hash[key.to_s] next if active_scaffold_constraints[key.to_sym] - next if nested? and nested.constrained_fields.include? key.to_sym + next if nested? and nested.param_name == key.to_sym conditions[key.to_sym] = value end conditions diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 0a63f025ff..e651247e0b 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -3,32 +3,21 @@ class NestedInfo def self.get(model, params) nested_info = {} begin - nested_info[:name] = (params[:association] || params[:named_scope]).to_sym - nested_info[:parent_scaffold] = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize - nested_info[:parent_model] = nested_info[:parent_scaffold].active_scaffold_config.model - nested_info[:parent_id] = if params[:association].nil? - params[nested_info[:parent_model].name.foreign_key] + unless params[:association].nil? + ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, params) else - params[nested_info[:parent_model].reflect_on_association(params[:association].to_sym).active_record.name.foreign_key] - end - if nested_info[:parent_id] - unless params[:association].nil? - ActiveScaffold::DataStructures::NestedInfoAssociation.new(model, nested_info) - else - ActiveScaffold::DataStructures::NestedInfoScope.new(model, nested_info) - end + ActiveScaffold::DataStructures::NestedInfoScope.new(model, params) end rescue ActiveScaffold::ControllerNotFound nil end end - attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :constrained_fields, :scope + attr_accessor :association, :child_association, :parent_model, :parent_scaffold, :parent_id, :param_name, :constrained_fields, :scope - def initialize(model, nested_info) - @parent_model = nested_info[:parent_model] - @parent_id = nested_info[:parent_id] - @parent_scaffold = nested_info[:parent_scaffold] + def initialize(model, params) + @parent_scaffold = "#{params[:parent_scaffold].to_s.camelize}Controller".constantize + @parent_model = @parent_scaffold.active_scaffold_config.model end def to_params @@ -83,9 +72,11 @@ def sorted? end class NestedInfoAssociation < NestedInfo - def initialize(model, nested_info) - super(model, nested_info) - @association = parent_model.reflect_on_association(nested_info[:name]) + def initialize(model, params) + super + @association = parent_model.reflect_on_association(params[:association].to_sym) + @param_name = @association.active_record.name.foreign_key.to_sym + @parent_id = params[@param_name] iterate_model_associations(model) end @@ -135,28 +126,25 @@ def iterate_model_associations(model) @constrained_fields = Set.new constrained_fields << association.foreign_key.to_sym unless association.belongs_to? model.reflect_on_all_associations.each do |current| - if !current.belongs_to? && association != current && association.foreign_key.to_s == current.association_foreign_key.to_s - constrained_fields << current.name.to_sym - @child_association = current if current.klass == @parent_model - end - if association.foreign_key.to_s == current.foreign_key.to_s - # show columns for has_many and has_one child associationes - constrained_fields << current.name.to_sym if current.belongs_to? - if association.options[:as] and current.options[:polymorphic] + if association != current && association.foreign_key.to_s == current.foreign_key.to_s + if current.belongs_to? && current.options[:polymorphic] && association.options[:as] @child_association = current if association.options[:as].to_sym == current.name - else - @child_association = current if current.klass == @parent_model + elsif current.klass == @parent_model + @child_association = current end end end + constrained_fields << @child_association.name.to_sym @constrained_fields = @constrained_fields.to_a end end class NestedInfoScope < NestedInfo - def initialize(model, nested_info) - super(model, nested_info) - @scope = nested_info[:name] + def initialize(model, params) + super + @scope = params[:named_scope].to_sym + @param_name = parent_model.name.foreign_key.to_sym + @parent_id = params[@param_name] @constrained_fields = [] end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 4bcd9c8937..b8618e06cd 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -216,7 +216,7 @@ def query_string_for_action_links(link) next end qs = "#{key}=#{value}" - if [:eid, :association, :parent_scaffold].include?(key) || conditions_from_params.include?(key) || (nested? && nested.constrained_fields.include?(key)) + if [:eid, :association, :parent_scaffold].include?(key) || conditions_from_params.include?(key) || (nested? && nested.param_name == key) non_nested_query_string_options << qs else query_string_options << qs From 40e4718e95312a114b892ddc57449df8884ed40c Mon Sep 17 00:00:00 2001 From: Lyndon Maydwell <maydwell@gmail.com> Date: Wed, 5 Sep 2012 15:57:06 +0800 Subject: [PATCH 1667/2024] Removing trailing whitespace from controller template --- .../active_scaffold_controller/templates/controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/active_scaffold_controller/templates/controller.rb b/lib/generators/active_scaffold_controller/templates/controller.rb index 6f0581e738..5f8638b5b0 100644 --- a/lib/generators/active_scaffold_controller/templates/controller.rb +++ b/lib/generators/active_scaffold_controller/templates/controller.rb @@ -1,4 +1,4 @@ class <%= controller_class_name %>Controller < ApplicationController active_scaffold :<%= class_name.demodulize.underscore %> do |conf| end -end \ No newline at end of file +end From 3d907a3ca48def4a0fa53a7e8836f558b875963a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 5 Sep 2012 19:14:55 +0200 Subject: [PATCH 1668/2024] fix constraints for columns with multiple columns in search_sql, fixes #194 --- CHANGELOG | 3 +++ lib/active_scaffold/constraints.rb | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 95ebd2d8f5..101bbe9cdb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,9 @@ - Keep order for records in plural subforms, so new records are saved in same order as form order - Support add_subgroup in horizontal subforms += 3.2.17 (not released yet) +- fix constraints for columns with multiple columns in search_sql + = 3.2.16 - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group - Fix constraints and colspan in self-referential associations diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 0cdc1f0b0e..4363fdc71d 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -17,7 +17,7 @@ def register_constraints_with_action_columns(constrained_fields = nil) constrained_fields |= active_scaffold_constraints.reject{|k, v| v.is_a? Hash}.keys.collect(&:to_sym) exclude_actions = [] [:list, :update].each do |action_name| - if active_scaffold_config.actions.include? action_name + if active_scaffold_config.actions.include? action_name exclude_actions << action_name unless active_scaffold_config.send(action_name).hide_nested_column end end @@ -70,7 +70,7 @@ def conditions_from_constraints # regular column constraints elsif column.searchable? && params[column.name] != v active_scaffold_includes.concat column.includes - conditions << ["#{column.search_sql} = ?", v] + conditions << [column.search_sql.collect { |search_sql| "#{search_sql} = ?" }.join(' OR '), *([v] * column.search_sql.size)] end # unknown-to-activescaffold-but-real-database-column constraint elsif active_scaffold_config.model.columns_hash[k.to_s] && params[column.name] != v From 87e32aaf9698c947a9f4dcc3a7b0b0563376d812 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 11 Sep 2012 06:37:09 -1000 Subject: [PATCH 1669/2024] remove unauthorized collection links --- CHANGELOG | 1 + lib/active_scaffold/data_structures/action_links.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 101bbe9cdb..0f71ac93aa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,7 @@ = 3.2.17 (not released yet) - fix constraints for columns with multiple columns in search_sql +- remove unauthorized collection links = 3.2.16 - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index ff97a6fddb..a6d1b33a69 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -127,6 +127,7 @@ def traverse(controller, options = {}, &block) else options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action) end + next unless authorized || link.type == :member yield(self, link, {:authorized => authorized, :first_action => first_action, :level => options[:level]}) first_action = false end From 5ec56b3b67e5a1e9a4b9f67c55a0a0e373fe8251 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 11 Sep 2012 12:36:09 -1000 Subject: [PATCH 1670/2024] copy parameters and html_options on cloning action links fix use of conf.create.link.parameters[:param] = value which was changing parameters for all controllers --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 0f71ac93aa..e77fabccde 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,7 @@ = 3.2.17 (not released yet) - fix constraints for columns with multiple columns in search_sql - remove unauthorized collection links +- copy parameters and html_options on cloning action link = 3.2.16 - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group From 6192237acb10c19c5c9f7434347140d20ac66ba0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 17 Sep 2012 09:51:24 -1000 Subject: [PATCH 1671/2024] fix render :super with vendored gems, fixes #196 --- lib/active_scaffold/extensions/action_view_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index c2c132f238..da0fada7ac 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -94,7 +94,7 @@ def render_with_active_scaffold(*args, &block) else options[:prefixes] = [''] active_scaffold_view_paths = lookup_context.active_scaffold_view_paths - last_view_path = File.dirname(lookup_context.last_template.inspect) + last_view_path = File.expand_path(File.dirname(lookup_context.last_template.inspect), Rails.root) lookup_context.active_scaffold_view_paths = active_scaffold_view_paths.drop(active_scaffold_view_paths.find_index {|path| path.to_s == last_view_path} + 1) end result = render_without_active_scaffold options From ca58dc956c428e39d6c35f2821c0cab6d8231040 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 17 Sep 2012 19:49:28 -1000 Subject: [PATCH 1672/2024] simplify get child_association in nested reusing association.reverse. fixes #197 --- .../data_structures/nested_info.rb | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index e651247e0b..9c98790c82 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -123,19 +123,12 @@ def to_params protected def iterate_model_associations(model) - @constrained_fields = Set.new + @constrained_fields = [] constrained_fields << association.foreign_key.to_sym unless association.belongs_to? - model.reflect_on_all_associations.each do |current| - if association != current && association.foreign_key.to_s == current.foreign_key.to_s - if current.belongs_to? && current.options[:polymorphic] && association.options[:as] - @child_association = current if association.options[:as].to_sym == current.name - elsif current.klass == @parent_model - @child_association = current - end - end + if association.reverse + @child_association = model.reflect_on_association(association.reverse) + constrained_fields << @child_association.name unless @child_association == association end - constrained_fields << @child_association.name.to_sym - @constrained_fields = @constrained_fields.to_a end end From 40f40466b42795449bc3660ceb8d95c1ba1a5602 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 18 Sep 2012 19:27:02 -1000 Subject: [PATCH 1673/2024] fix missing argument --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index e77fabccde..8d1b80ff43 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,7 @@ - fix constraints for columns with multiple columns in search_sql - remove unauthorized collection links - copy parameters and html_options on cloning action link +- fix missing argument in datepicker conditions = 3.2.16 - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group From 27f9386866d339e798f08d0e0ee71fae160605e7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 21 Sep 2012 16:36:25 -1000 Subject: [PATCH 1674/2024] rename inplace_edit_update values --- frontends/default/views/update_column.js.erb | 10 +++++----- lib/active_scaffold/actions/update.rb | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frontends/default/views/update_column.js.erb b/frontends/default/views/update_column.js.erb index 48ea8994d1..5d2f35ede8 100644 --- a/frontends/default/views/update_column.js.erb +++ b/frontends/default/views/update_column.js.erb @@ -5,16 +5,16 @@ <% @record.reload -%> <% end -%> <% if @column.inplace_edit - update_row = @column.inplace_edit_update if controller.send :successful? -%> - <% case update_row - when :update_row -%> + ipe_update = @column.inplace_edit_update if controller.send :successful? -%> + <% case ipe_update + when :row -%> ActiveScaffold.update_row('<%= element_row_id(:action => :list) %>', '<%= escape_javascript render('row', :record => @record) %>'); - <% when :update_table -%> + <% when :table -%> ActiveScaffold.replace_html('<%= active_scaffold_content_id %>', '<%= escape_javascript(render('list')) %>'); <% else formatted_value = get_column_value(@record, @column) -%> ActiveScaffold.update_inplace_edit('<%= @column_span_id %>','<%= escape_javascript(formatted_value) %>', <%= column_empty?(formatted_value).to_json %>); - <% if update_row == :update_columns && @column.update_columns && !@column.update_columns.empty? + <% if ipe_update == :columns && @column.update_columns && !@column.update_columns.empty? @rendered = Set.new([@column.name]) -%> <%= render :partial => 'update_column', :collection => @column.update_columns & active_scaffold_config.list.columns.names, :locals => {:row_id => element_row_id(:action => :list, :id => @record.id)} %> <% end %> diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 2bcebb90e0..4da972be22 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -123,7 +123,7 @@ def do_update_column @record.send("#{@column.name}=", params[:value]) before_update_save(@record) self.successful = @record.save - do_list if self.successful? && @column.inplace_edit == :update_table + do_list if self.successful? && @column.inplace_edit_update == :table after_update_save(@record) end end From 3172a775f6d2b411a07d4ff32234c97e4e9590ff Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 21 Sep 2012 16:48:43 -1000 Subject: [PATCH 1675/2024] don't add update_column to a field if update_columns are not present in form for example, they can be set for inplace edit update --- lib/active_scaffold/data_structures/action_columns.rb | 6 +++--- lib/active_scaffold/helpers/form_column_helpers.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index de0dc8e604..f4092dd2e5 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -39,7 +39,7 @@ def include?(item) def names if @columns - self.collect(&:name) + self.collect_visible(:flatten => true) { |c| c.name } else names_without_auth_check end @@ -84,9 +84,9 @@ def collect_visible(options = {}, &proc) next if self.skip_column?(item, options) end if item.is_a? ActiveScaffold::DataStructures::ActionColumns and options.has_key?(:flatten) and options[:flatten] - columns = columns + item.collect(options, &proc) + columns += item.collect_visible(options, &proc) else - columns << item + columns << (block_given? ? yield(item) : item) end end columns diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index c7a974cc12..7c7362b233 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -95,8 +95,8 @@ def active_scaffold_input_options(column, scope = nil, options = {}) end def update_columns_options(column, scope, options) - if column.update_columns - form_action = params[:action] == 'edit' ? :update : :create + form_action = params[:action] == 'edit' ? :update : :create + if column.update_columns && (column.update_columns & active_scaffold_config.send(form_action).columns.names).present? url_params = {:action => 'render_field', :column => column.name} url_params[:id] = @record.id if column.send_form_on_update_column url_params[:eid] = params[:eid] if params[:eid] From 6235334b31445612335bcbd0db253b4679eb7d2e Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 21 Sep 2012 17:12:12 -1000 Subject: [PATCH 1676/2024] loading indicator on inplace editing --- app/assets/javascripts/jquery/active_scaffold.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index e0d971bf61..ae718c5d24 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -574,7 +574,7 @@ var ActiveScaffold = { }, process_checkbox_inplace_edit: function(checkbox, options) { - var checked = checkbox.is(':checked'); + var checked = checkbox.is(':checked'), td = checkbox.closest('td'); if (checked === true) options['params'] += '&value=1'; jQuery.ajax({ url: options.url, @@ -583,12 +583,14 @@ var ActiveScaffold = { dataType: options.ajax_data_type, beforeSend: function(request, settings) { if (options.beforeSend) options.beforeSend.call(checkbox, request, settings); - }, - after: function(request){ checkbox.attr('disabled', 'disabled'); + td.closest('tr').find('td.actions .loading-indicator').css('visibility','visible'); }, complete: function(request){ checkbox.removeAttr('disabled'); + }, + success: function(request){ + td.closest('tr').find('td.actions .loading-indicator').css('visibility','hidden'); } }); }, @@ -730,6 +732,10 @@ var ActiveScaffold = { delegate: { willCloseEditInPlace: function(span, options) { if (span.data('addEmptyOnCancel')) span.closest('td').addClass('empty'); + span.closest('tr').find('td.actions .loading-indicator').css('visibility','visible'); + }, + didCloseEditInPlace: function(span, options) { + span.closest('tr').find('td.actions .loading-indicator').css('visibility','hidden'); } }, update_value: 'value'}, From d08b69688ca6f882936efe7e4e06420d42d62830 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 24 Sep 2012 10:05:33 -1000 Subject: [PATCH 1677/2024] default styles for subgroups in horizontal subforms --- app/assets/stylesheets/active_scaffold_layout.css | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/assets/stylesheets/active_scaffold_layout.css b/app/assets/stylesheets/active_scaffold_layout.css index 68ff37846b..655ded3ed8 100644 --- a/app/assets/stylesheets/active_scaffold_layout.css +++ b/app/assets/stylesheets/active_scaffold_layout.css @@ -780,6 +780,11 @@ background: none; display: none; } +.active-scaffold .horizontal-sub-form .associated-record dl { +float: left; +margin-right: 5px; +} + .active-scaffold .sub-form .checkbox-list { padding: 0 2px 2px 2px; border: solid 1px; From 7bd2800275365ae5b89b038a799860f0f3229cf7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 24 Sep 2012 22:18:23 -1000 Subject: [PATCH 1678/2024] check authorization in model for plural associations nested links --- CHANGELOG | 1 + lib/active_scaffold/helpers/view_helpers.rb | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8d1b80ff43..a834ebab44 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -16,6 +16,7 @@ - remove unauthorized collection links - copy parameters and html_options on cloning action link - fix missing argument in datepicker conditions +- check authorization in model for plural associations nested links = 3.2.16 - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index b8618e06cd..fd4f6cb1d6 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -163,11 +163,8 @@ def configure_column_link(link, record, associated, actions = nil) def column_link_authorized?(link, column, record, associated) if column.association - associated_for_authorized = if associated.nil? || (column.plural_association? && !associated.loaded?) || (associated.respond_to?(:blank?) && associated.blank?) + associated_for_authorized = if column.plural_association? || (associated.respond_to?(:blank?) && associated.blank?) column.association.klass - elsif [:has_many, :has_and_belongs_to_many].include? column.association.macro - # may be cached with [] or [nil] to avoid some queries - associated.first || column.association.klass else associated end From e0da0cffd15aa8bc66bdc09354459672b2d54f6c Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 24 Sep 2012 22:36:13 -1000 Subject: [PATCH 1679/2024] allow to set action_group in nested.add_link --- CHANGELOG | 1 + lib/active_scaffold/config/nested.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a834ebab44..cb3a9b2394 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ - Support for updating columns, row or table after updating a column with inplace_edit - Keep order for records in plural subforms, so new records are saved in same order as form order - Support add_subgroup in horizontal subforms +- Allow to set action_group in nested.add_link = 3.2.17 (not released yet) - fix constraints for columns with multiple columns in search_sql diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index 2fba93c2c7..1850e5c7d0 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -27,10 +27,11 @@ def add_link(attribute, options = {}) column = @core.columns[attribute.to_sym] unless column.nil? || column.association.nil? options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => column.singular_association? ? 1 : 2, :default => column.association.klass.name.pluralize}) + action_group = options.delete(:action_group) || self.action_group action_link = @core.link_for_association(column, options) @core.action_links.add_to_group(action_link, action_group) unless action_link.nil? else - + # TODO: raise exception end end From 2c8844a8153d54e7450795e753e102fa7b9fb148 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 25 Sep 2012 07:32:34 -1000 Subject: [PATCH 1680/2024] last commit backported to 3.2 branch --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index cb3a9b2394..2972107900 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,7 +10,6 @@ - Support for updating columns, row or table after updating a column with inplace_edit - Keep order for records in plural subforms, so new records are saved in same order as form order - Support add_subgroup in horizontal subforms -- Allow to set action_group in nested.add_link = 3.2.17 (not released yet) - fix constraints for columns with multiple columns in search_sql @@ -18,6 +17,7 @@ - copy parameters and html_options on cloning action link - fix missing argument in datepicker conditions - check authorization in model for plural associations nested links +- Allow to set action_group in nested.add_link = 3.2.16 - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group From ad85ae06dc56b4c015070bc73a8df99d06f13d9c Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 25 Sep 2012 10:32:30 -1000 Subject: [PATCH 1681/2024] only preload associations when row is updated, also fixes some bugs no saving --- lib/active_scaffold/actions/update.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 4da972be22..c64285777b 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -48,7 +48,13 @@ def update_respond_to_html end def update_respond_to_js if successful? - do_refresh_list if update_refresh_list? && !render_parent? + if !render_parent? && active_scaffold_config.actions.include?(:list) + if update_refresh_list? + do_refresh_list + else + get_row + end + end flash.now[:info] = as_(:updated_model, :model => @record.to_label) if active_scaffold_config.update.persistent end render :action => 'on_update' @@ -62,12 +68,11 @@ def update_respond_to_json def update_respond_to_yaml render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.update.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status end + # A simple method to find and prepare a record for editing # May be overridden to customize the record (set default values, etc.) def do_edit - set_includes_for_columns if active_scaffold_config.actions.include? :list - klass = beginning_of_chain.includes(active_scaffold_includes) - @record = find_if_allowed(params[:id], :update, klass) + @record = find_if_allowed(params[:id], :update) end # A complex method to update a record. The complexity comes from the support for subforms, and saving associated records. @@ -123,7 +128,13 @@ def do_update_column @record.send("#{@column.name}=", params[:value]) before_update_save(@record) self.successful = @record.save - do_list if self.successful? && @column.inplace_edit_update == :table + if self.successful? && active_scaffold_config.actions.include?(:list) + if @column.inplace_edit_update == :table + do_list + elsif @column.inplace_edit_update + get_row + end + end after_update_save(@record) end end From 93afa7624e72bcac3faedc6f11e805fc7d7dce1f Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 27 Sep 2012 01:55:08 -1000 Subject: [PATCH 1682/2024] refactor so nested action links for singular associations get disabled class when they are not authorized, dry rendering disabled link --- frontends/default/views/_action_group.html.erb | 6 +++--- frontends/default/views/_list_record.html.erb | 11 ++++++----- .../default/views/_update_actions.html.erb | 2 +- .../helpers/list_column_helpers.rb | 7 +------ lib/active_scaffold/helpers/view_helpers.rb | 17 +++++++---------- 5 files changed, 18 insertions(+), 25 deletions(-) diff --git a/frontends/default/views/_action_group.html.erb b/frontends/default/views/_action_group.html.erb index 40443cb006..94da2dc664 100644 --- a/frontends/default/views/_action_group.html.erb +++ b/frontends/default/views/_action_group.html.erb @@ -17,9 +17,9 @@ <% else -%> <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}#{render_group_action_link(link, options, record)}#{end_level_0_tag}".html_safe %> + <%= "#{start_level_0_tag}#{render_action_link(link, record, options)}#{end_level_0_tag}".html_safe %> <% else %> - <li<%= ' class="top"'.html_safe %>><%= render_group_action_link(link, options, record) %></li> + <li<%= ' class="top"'.html_safe %>><%= render_action_link(link, record, options) %></li> <% end %> <% end -%> -<% end -%> \ No newline at end of file +<% end -%> diff --git a/frontends/default/views/_list_record.html.erb b/frontends/default/views/_list_record.html.erb index 2cb509783a..97341683d2 100644 --- a/frontends/default/views/_list_record.html.erb +++ b/frontends/default/views/_list_record.html.erb @@ -21,11 +21,12 @@ data_refresh ||= url_for(params_for(:action => :row, :id => '--ID--', :_method = <td class="indicator-container"> <%= loading_indicator_tag(:action => :record, :id => record.id) %> </td> - <%= render :partial => 'action_group', :locals => {:action_links => action_links, - :record => record, - :traverse_options => {:for => record.persisted? ? record : record.class}, - :start_level_0_tag => '<td>', - :end_level_0_tag => '</td>'} %> + <%= render :partial => 'action_group', :locals => { :action_links => action_links, + :record => record, + :traverse_options => {:for => record.persisted? ? record : record.class}, + :start_level_0_tag => '<td>', + :end_level_0_tag => '</td>' + } %> </tr> </table></td> diff --git a/frontends/default/views/_update_actions.html.erb b/frontends/default/views/_update_actions.html.erb index 2baff6925f..9598e17aca 100644 --- a/frontends/default/views/_update_actions.html.erb +++ b/frontends/default/views/_update_actions.html.erb @@ -3,7 +3,7 @@ <% active_scaffold_config.action_links.member.each do |link| -%> <% next unless link.action == 'index' -%> <% next if skip_action_link(link) -%> - <%= record.authorized_for?(:crud_type => link.crud_type, :action => link.action) ? render_action_link(link, record) : "<a class='disabled'>#{link.label}</a>" -%> + <%= render_action_link(link, record, :authorized => record.authorized_for?(:crud_type => link.crud_type, :action => link.action)) -%> <% end -%> </div> </div> diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index fa995291e0..9468528e3b 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -44,12 +44,7 @@ def render_list_column(text, column, record) if column.link link = column.link associated = record.send(column.association.name) if column.association - - if link.action.nil? || column_link_authorized?(link, column, record, associated) - render_action_link(link, record, {:link => text}) - else - "<a class='disabled'>#{text}</a>".html_safe - end + render_action_link(link, record, :link => text, :authorized => link.action.nil? || column_link_authorized?(link, column, record, associated)) elsif inplace_edit?(record, column) active_scaffold_inplace_edit(record, column, {:formatted_column => text}) elsif active_scaffold_config.list.wrap_tag diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index fd4f6cb1d6..9645304bd3 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -106,18 +106,15 @@ def skip_action_link(link, *args) def render_action_link(link, record = nil, html_options = {}) if link.action.nil? link = action_link_to_inline_form(link, record, html_options) - html_options.delete :link if link.crud_type == :create + options[:authorized] = false if link.action.nil? + options.delete :link if link.crud_type == :create end - url = action_link_url(link, record) unless link.action.nil? - html_options = action_link_html_options(link, record, html_options) unless link.action.nil? - action_link_html(link, url, html_options, record) - end - - def render_group_action_link(link, options, record = nil) - if link.type == :member && !options[:authorized] - action_link_html(link, nil, {:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"}, record) + if link.action.nil? || (link.type == :member && options.has_key?(:authorized) && !options[:authorized]) + action_link_html(link, nil, html_options.merge(:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"), record) else - render_action_link(link, record) + url = action_link_url(link, record) + html_options = action_link_html_options(link, record, options) + action_link_html(link, url, html_options, record) end end From 62df7e7f15262631fac9fe02c65277fdcb876d0d Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 27 Sep 2012 08:19:45 -1000 Subject: [PATCH 1683/2024] fix argument name --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 9645304bd3..5afcccf6ba 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -103,7 +103,7 @@ def skip_action_link(link, *args) (!link.ignore_method.nil? && controller.respond_to?(link.ignore_method) && controller.send(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args)) end - def render_action_link(link, record = nil, html_options = {}) + def render_action_link(link, record = nil, options = {}) if link.action.nil? link = action_link_to_inline_form(link, record, html_options) options[:authorized] = false if link.action.nil? From 591b82cc863fa87604a99a5b45b9b8cab85ee47c Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 27 Sep 2012 08:22:05 -1000 Subject: [PATCH 1684/2024] remove unused arguments --- lib/active_scaffold/helpers/view_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 5afcccf6ba..340a4ff3af 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -105,7 +105,7 @@ def skip_action_link(link, *args) def render_action_link(link, record = nil, options = {}) if link.action.nil? - link = action_link_to_inline_form(link, record, html_options) + link = action_link_to_inline_form(link, record) options[:authorized] = false if link.action.nil? options.delete :link if link.crud_type == :create end @@ -119,7 +119,7 @@ def render_action_link(link, record = nil, options = {}) end # setup the action link to inline form - def action_link_to_inline_form(link, record, html_options) + def action_link_to_inline_form(link, record) link = link.clone associated = record.send(link.column.association.name) if link.column.polymorphic_association? From f30952383d20dce5bfe173f860f4e3ada5e9ffd3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 27 Sep 2012 10:14:10 -1000 Subject: [PATCH 1685/2024] fix for nested with polymorphic associations --- lib/active_scaffold/data_structures/nested_info.rb | 4 ++-- .../extensions/reverse_associations.rb | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 9c98790c82..3e3bd244b7 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -125,8 +125,8 @@ def to_params def iterate_model_associations(model) @constrained_fields = [] constrained_fields << association.foreign_key.to_sym unless association.belongs_to? - if association.reverse - @child_association = model.reflect_on_association(association.reverse) + if reverse = association.reverse(model) + @child_association = model.reflect_on_association(reverse) constrained_fields << @child_association.name unless @child_association == association end end diff --git a/lib/active_scaffold/extensions/reverse_associations.rb b/lib/active_scaffold/extensions/reverse_associations.rb index bade4f10cc..6026044cc4 100644 --- a/lib/active_scaffold/extensions/reverse_associations.rb +++ b/lib/active_scaffold/extensions/reverse_associations.rb @@ -7,19 +7,23 @@ def inverse_for?(klass) end attr_writer :reverse - def reverse - @reverse ||= inverse_of.try(:name) + def reverse(klass = nil) + unless defined? @reverse + @reverse ||= inverse_of.try(:name) + end + @reverse || (autodetect_inverse(klass).try(:name) unless klass.nil?) end def inverse_of_with_autodetect inverse_of_without_autodetect || autodetect_inverse end alias_method_chain :inverse_of, :autodetect - + protected - def autodetect_inverse - return nil if options[:polymorphic] + def autodetect_inverse(klass = nil) + return nil if klass.nil? && options[:polymorphic] + klass ||= self.klass reverse_matches = [] # stage 1 filter: collect associations that point back to this model and use the same foreign_key From ab3c5c3c93c76a39ff7f2e72bc91f59bdfb07579 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 27 Sep 2012 10:34:35 -1000 Subject: [PATCH 1686/2024] another more wrong variable --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 340a4ff3af..93ab8008d3 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -110,7 +110,7 @@ def render_action_link(link, record = nil, options = {}) options.delete :link if link.crud_type == :create end if link.action.nil? || (link.type == :member && options.has_key?(:authorized) && !options[:authorized]) - action_link_html(link, nil, html_options.merge(:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"), record) + action_link_html(link, nil, options.merge(:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"), record) else url = action_link_url(link, record) html_options = action_link_html_options(link, record, options) From 6df8e4c9b021afefe6be52ba94e84b4a5541aeb8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 27 Sep 2012 11:47:30 -1000 Subject: [PATCH 1687/2024] fix for html_options[:class] using symbol --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 93ab8008d3..fc01e4761d 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -110,7 +110,7 @@ def render_action_link(link, record = nil, options = {}) options.delete :link if link.crud_type == :create end if link.action.nil? || (link.type == :member && options.has_key?(:authorized) && !options[:authorized]) - action_link_html(link, nil, options.merge(:class => "disabled #{link.action}#{link.html_options[:class].blank? ? '' : (' ' + link.html_options[:class])}"), record) + action_link_html(link, nil, options.merge(:class => "disabled #{link.action}#{" #{link.html_options[:class]}" unless link.html_options[:class].blank?}"), record) else url = action_link_url(link, record) html_options = action_link_html_options(link, record, options) From 823bb86bdc19e499a7d73081c72bdb92ea2d0714 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 27 Sep 2012 12:03:04 -1000 Subject: [PATCH 1688/2024] new option for association_options_find useful for select with polimorphyc associations --- lib/active_scaffold/helpers/association_helpers.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/association_helpers.rb b/lib/active_scaffold/helpers/association_helpers.rb index 950861c7e2..9ee6b92258 100644 --- a/lib/active_scaffold/helpers/association_helpers.rb +++ b/lib/active_scaffold/helpers/association_helpers.rb @@ -2,9 +2,10 @@ module ActiveScaffold module Helpers module AssociationHelpers # Provides a way to honor the :conditions on an association while searching the association's klass - def association_options_find(association, conditions = nil) + def association_options_find(association, conditions = nil, klass = nil) + klass ||= association.klass conditions = options_for_association_conditions(association) if conditions.nil? - relation = association.klass.where(conditions).where(association.options[:conditions]) + relation = klass.where(conditions).where(association.options[:conditions]) relation = relation.includes(association.options[:include]) if association.options[:include] relation = yield(relation) if block_given? relation.all From f2cf352278dec7228e6d1aa4b37841c3d3c9ed19 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 27 Sep 2012 12:04:05 -1000 Subject: [PATCH 1689/2024] update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 2972107900..299abb1da5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ - Support for updating columns, row or table after updating a column with inplace_edit - Keep order for records in plural subforms, so new records are saved in same order as form order - Support add_subgroup in horizontal subforms +- Improve support in helpers for using :select form_ui with polimorphy associations (needs to use a select to choose the class) = 3.2.17 (not released yet) - fix constraints for columns with multiple columns in search_sql From b777ec7d27db704eb682f6a51f42f9c0816a093d Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 27 Sep 2012 12:59:25 -1000 Subject: [PATCH 1690/2024] improve has_many through support --- CHANGELOG | 1 + lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/data_structures/nested_info.rb | 10 ++++++++++ lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 299abb1da5..ae3ec16ffd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,7 @@ - Keep order for records in plural subforms, so new records are saved in same order as form order - Support add_subgroup in horizontal subforms - Improve support in helpers for using :select form_ui with polimorphy associations (needs to use a select to choose the class) +- Allow to create in nested has_many :through associations, when source association is a belongs_to = 3.2.17 (not released yet) - fix constraints for columns with multiple columns in search_sql diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 2c96640cc1..49d32ec1fc 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -122,7 +122,7 @@ def create_ignore? end def create_authorized? - (!nested? || !nested.readonly? || !nested.through?) && authorized_for?(:crud_type => :create) + !(nested? && (nested.readonly? || nested.readonly_through_association?)) && authorized_for?(:crud_type => :create) end private def create_authorized_filter diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 3e3bd244b7..620aa3db14 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -58,6 +58,10 @@ def plural_association? has_many? || habtm? end + def readonly_through_association? + false + end + def through_association? false end @@ -100,6 +104,12 @@ def has_one? association.macro == :has_one end + # A through association with has_one or has_many as source association + # create cannot be called in such through association + def readonly_through_association? + association.options[:through] && association.source_reflection.macro != :belongs_to + end + def through_association? association.options[:through] end diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 7c7362b233..c32a27a553 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -369,7 +369,7 @@ def active_scaffold_add_existing_input(options) options.merge!(active_scaffold_input_text_options) record_select_field(options[:name], @record, options) else - select_options = sorted_association_options_find(nested.association) #unless column.through_association? + select_options = sorted_association_options_find(nested.association) select_options ||= active_scaffold_config.model.all select_options = options_from_collection_for_select(select_options, :id, :to_label) select_tag 'associated_id', ('<option value="">' + as_(:_select_) + '</option>' + select_options).html_safe unless select_options.empty? From c97c4c8d53baef28f1a7ff8240154ea05122490e Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 27 Sep 2012 13:16:26 -1000 Subject: [PATCH 1691/2024] search using selected model in foreign_type column, improve support for selecting polymorphic associations --- lib/active_scaffold/helpers/association_helpers.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/association_helpers.rb b/lib/active_scaffold/helpers/association_helpers.rb index 9ee6b92258..d2e6c5d0e5 100644 --- a/lib/active_scaffold/helpers/association_helpers.rb +++ b/lib/active_scaffold/helpers/association_helpers.rb @@ -3,7 +3,17 @@ module Helpers module AssociationHelpers # Provides a way to honor the :conditions on an association while searching the association's klass def association_options_find(association, conditions = nil, klass = nil) - klass ||= association.klass + if klass.nil? && association.options[:polymorphic] + class_name = @record.send(association.foreign_type) + if class_name.present? + klass = class_name.constantize + else + return [] + end + else + klass ||= association.klass + end + conditions = options_for_association_conditions(association) if conditions.nil? relation = klass.where(conditions).where(association.options[:conditions]) relation = relation.includes(association.options[:include]) if association.options[:include] From a6d90ca2eca9101d6061767c18418a81a092d255 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 27 Sep 2012 17:07:54 -1000 Subject: [PATCH 1692/2024] fix inplace edit with :table update, fixes #199 --- lib/active_scaffold/actions/update.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index c64285777b..9c02a3099a 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -18,7 +18,7 @@ def update # for inline (inlist) editing def update_column do_update_column - @column_span_id = params[:editor_id] || params[:editorId] + @column_span_id = params.delete(:editor_id) || params.delete(:editorId) end protected @@ -111,21 +111,23 @@ def update_save(options = {}) end def do_update_column + # delete from params so update :table won't break urls, also they shouldn't be used in sort links too + value = params.delete(:value) + column = params.delete(:column).to_sym + params.delete(:original_html) + params.delete(:original_value) + @record = find_if_allowed(params[:id], :read) - if @record.authorized_for?(:crud_type => :update, :column => params[:column]) - @column = active_scaffold_config.columns[params[:column].to_sym] - unless @column.column.nil? || @column.column.null - if @column.column.default == true - params[:value] ||= false - else - params[:value] ||= @column.column.default - end + if @record.authorized_for?(:crud_type => :update, :column => column) + @column = active_scaffold_config.columns[column] + value ||= unless @column.column.nil? || @column.column.null + @column.column.default == true ? false : @column.column.default end unless @column.nil? - params[:value] = column_value_from_param_value(@record, @column, params[:value]) - params[:value] = [] if params[:value].nil? && @column.form_ui && @column.plural_association? + value = column_value_from_param_value(@record, @column, value) + value = [] if value.nil? && @column.form_ui && @column.plural_association? end - @record.send("#{@column.name}=", params[:value]) + @record.send("#{@column.name}=", value) before_update_save(@record) self.successful = @record.save if self.successful? && active_scaffold_config.actions.include?(:list) From 848ea9cae2078696a11febe8f8923624179a57f7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 27 Sep 2012 17:31:46 -1000 Subject: [PATCH 1693/2024] fix tabs --- .../javascripts/jquery/jquery.editinplace.js | 264 +++++++++--------- 1 file changed, 132 insertions(+), 132 deletions(-) diff --git a/app/assets/javascripts/jquery/jquery.editinplace.js b/app/assets/javascripts/jquery/jquery.editinplace.js index e0d31fc3ff..8e72f79c11 100644 --- a/app/assets/javascripts/jquery/jquery.editinplace.js +++ b/app/assets/javascripts/jquery/jquery.editinplace.js @@ -46,15 +46,15 @@ $.fn.editInPlace = function(options) { /// Required Options: Either url or callback, so the editor knows what to do with the edited values. $.fn.editInPlace.defaults = { url: "", // string: POST URL to send edited content - ajax_data_type: "html", // string: dataType (html|script) for ajax call to save updated value + ajax_data_type: "html", // string: dataType (html|script) for ajax call to save updated value bg_over: "#ffc", // string: background color of hover of unactivated editor bg_out: "transparent", // string: background color on restore from hover - hover_class: "", // string: class added to root element during hover. Will override bg_over and bg_out + hover_class: "", // string: class added to root element during hover. Will override bg_over and bg_out show_buttons: false, // boolean: will show the buttons: cancel or save; will automatically cancel out the onBlur functionality save_button: '<button class="inplace_save">Save</button>', // string: image button tag to use as “Save” button cancel_button: '<button class="inplace_cancel">Cancel</button>', // string: image button tag to use as “Cancel” button params: "", // string: example: first_name=dave&last_name=hauenstein extra paramters sent via the post request to the server - field_type: "text", // string: "text", "textarea", or "select", or "remote", or "clone"; The type of form field that will appear on instantiation + field_type: "text", // string: "text", "textarea", or "select", or "remote", or "clone"; The type of form field that will appear on instantiation default_text: "(Click here to add text)", // string: text to show up if the element that has this functionality is empty use_html: false, // boolean, set to true if the editor should use jQuery.fn.html() to extract the value to show from the dom node (keep in mind that IE will uppercase all tags, so use with caution) textarea_rows: 10, // integer: set rows attribute of textarea, if field_type is set to textarea. Use CSS if possible though @@ -62,29 +62,29 @@ $.fn.editInPlace.defaults = { select_text: "Choose new value", // string: default text to show up in select box select_options: "", // string or array: Used if field_type is set to 'select'. Can be comma delimited list of options 'textandValue,text:value', Array of options ['textAndValue', 'text:value'] or array of arrays ['textAndValue', ['text', 'value']]. The last form is especially usefull if your labels or values contain colons) text_size: null, // integer: set cols attribute of text input, if field_type is set to text. Use CSS if possible though - editor_url: null, // for field_type: remote url to get html_code for edit_control - loading_text: 'Loading...', // shown if inplace editor is loaded from server + editor_url: null, // for field_type: remote url to get html_code for edit_control + loading_text: 'Loading...', // shown if inplace editor is loaded from server // Specifying callback_skip_dom_reset will disable all saving_* options saving_text: undefined, // string: text to be used when server is saving information. Example "Saving..." saving_image: "", // string: uses saving text specify an image location instead of text while server is saving saving_animation_color: 'transparent', // hex color string, will be the color the pulsing animation during the save pulses to. Note: Only works if jquery-ui is loaded - clone_selector: null, // if field_type clone a selector to clone editor from - clone_id_suffix: null, // if field_type clone a suffix to create unique ids + clone_selector: null, // if field_type clone a selector to clone editor from + clone_id_suffix: null, // if field_type clone a suffix to create unique ids value_required: false, // boolean: if set to true, the element will not be saved unless a value is entered element_id: "element_id", // string: name of parameter holding the id or the editable update_value: "update_value", // string: name of parameter holding the updated/edited value original_value: 'original_value', // string: name of parameter holding the updated/edited value original_html: "original_html", // string: name of parameter holding original_html value of the editable /* DEPRECATED in 2.2.0 */ use original_value instead. - save_if_nothing_changed: false, // boolean: submit to function or server even if the user did not change anything + save_if_nothing_changed: false, // boolean: submit to function or server even if the user did not change anything on_blur: "save", // string: "save" or null; what to do on blur; will be overridden if show_buttons is true cancel: "", // string: if not empty, a jquery selector for elements that will not cause the editor to open even though they are clicked. E.g. if you have extra buttons inside editable fields // All callbacks will have this set to the DOM node of the editor that triggered the callback callback: null, // function: function to be called when editing is complete; cancels ajax submission to the url param. Prototype: function(idOfEditor, enteredText, orinalHTMLContent, settingsParams, callbacks). The function needs to return the value that should be shown in the dom. Returning undefined means cancel and will restore the dom and trigger an error. callbacks is a dictionary with two functions didStartSaving and didEndSaving() that you can use to tell the inline editor that it should start and stop any saving animations it has configured. /* DEPRECATED in 2.1.0 */ Parameter idOfEditor, use $(this).attr('id') instead - callback_skip_dom_reset: false, // boolean: set this to true if the callback should handle replacing the editor with the new value to show - beforeSend: null, // function: this function gets called before sending new value to server. Prototype: function(request, requestSettings) + callback_skip_dom_reset: false, // boolean: set this to true if the callback should handle replacing the editor with the new value to show + beforeSend: null, // function: this function gets called before sending new value to server. Prototype: function(request, requestSettings) success: null, // function: this function gets called if server responds with a success. Prototype: function(newEditorContentString) error: null, // function: this function gets called if server responds with an error. Prototype: function(request) error_sink: function(idOfEditor, errorString) { alert(errorString); }, // function: gets id of the editor and the error. Make sure the editor has an id, or it will just be undefined. If set to null, no error will be reported. /* DEPRECATED in 2.1.0 */ Parameter idOfEditor, use $(this).attr('id') instead @@ -157,7 +157,7 @@ $.extend(InlineEditor.prototype, { }, disconnectOpeningEvents: function() { - // prevent re-opening the editor when it is already open + // prevent re-opening the editor when it is already open this.dom.unbind('.editInPlace'); }, @@ -185,8 +185,8 @@ $.extend(InlineEditor.prototype, { this.saveOriginalValue(); this.markEditorAsActive(); this.replaceContentWithEditor(); - this.setInitialValue(); - this.workAroundMissingBlurBug(); + this.setInitialValue(); + this.workAroundMissingBlurBug(); this.connectClosingEventsToEditor(); this.triggerDelegateCall('didOpenEditInPlace'); }, @@ -241,15 +241,15 @@ $.extend(InlineEditor.prototype, { }, workAroundMissingBlurBug: function() { - // Strangely, all browser will forget to send a blur event to an input element - // when another one is created and selected programmatically. (at least under some circumstances). - // This means that if another inline editor is opened, existing inline editors will _not_ close - // if they are configured to submit when blurred. + // Strangely, all browser will forget to send a blur event to an input element + // when another one is created and selected programmatically. (at least under some circumstances). + // This means that if another inline editor is opened, existing inline editors will _not_ close + // if they are configured to submit when blurred. // Using parents() instead document as base to workaround the fact that in the unittests // the editor is not a child of window.document but of a document fragment - var ourInput = this.dom.find(':input'); - this.dom.parents(':last').find('.editInPlace-active :input').not(ourInput).blur(); + var ourInput = this.dom.find(':input'); + this.dom.parents(':last').find('.editInPlace-active :input').not(ourInput).blur(); }, replaceContentWithEditor: function() { @@ -271,7 +271,7 @@ $.extend(InlineEditor.prototype, { editor = this.createSelectEditor(); else if ("text" === this.settings.field_type) editor = $('<input type="text" ' + this.inputNameAndClass() - + ' size="' + this.settings.text_size + '" />'); + + ' size="' + this.settings.text_size + '" />'); else if ("textarea" === this.settings.field_type) editor = $('<textarea ' + this.inputNameAndClass() + ' rows="' + this.settings.textarea_rows + '" ' @@ -279,93 +279,93 @@ $.extend(InlineEditor.prototype, { else if ("remote" === this.settings.field_type) editor = this.createRemoteGeneratedEditor(); else if ("clone" === this.settings.field_type) { - editor = this.cloneEditor(); - return editor; + editor = this.cloneEditor(); + return editor; } return editor; }, - setInitialValue: function() { - if (this.settings.field_type == 'remote') return; // remote generated editor doesn't need initial value - var initialValue = this.triggerDelegateCall('willOpenEditInPlace', this.originalValue); - var editor = this.dom.find(':input'); - editor.val(initialValue); - - // Workaround for select fields which don't contain the original value. - // Somehow the browsers don't like to select the instructional choice (disabled) in that case - if (editor.val() !== initialValue) - editor.val(''); // selects instructional choice - }, - + setInitialValue: function() { + if (this.settings.field_type == 'remote') return; // remote generated editor doesn't need initial value + var initialValue = this.triggerDelegateCall('willOpenEditInPlace', this.originalValue); + var editor = this.dom.find(':input'); + editor.val(initialValue); + + // Workaround for select fields which don't contain the original value. + // Somehow the browsers don't like to select the instructional choice (disabled) in that case + if (editor.val() !== initialValue) + editor.val(''); // selects instructional choice + }, + createRemoteGeneratedEditor: function () { - this.dom.html(this.settings.loading_text); - return $($.ajax({ - url: this.settings.editor_url, - async: false - }).responseText); + this.dom.html(this.settings.loading_text); + return $($.ajax({ + url: this.settings.editor_url, + async: false + }).responseText); }, cloneEditor: function() { - var patternNodes = this.getPatternNodes(this.settings.clone_selector); - if (patternNodes.editNode == null) { - alert('did not find any matching node for ' + this.settings.clone_selector); - return; - } - - var editorNode = patternNodes.editNode.clone(); - var clonedNodes = null; - if (editorNode.attr('id')) editorNode.attr('id', editorNode.attr('id') + this.settings.clone_id_suffix); - editorNode.attr('name', 'inplace_value'); - editorNode.addClass('editor_field'); - this.setValue(editorNode, this.originalValue); - clonedNodes = editorNode; - - if (patternNodes.additionalNodes) { - patternNodes.additionalNodes.each(function (index, node) { - var patternNode = $(node).clone(); - if (patternNode.attr('id')) { - patternNode.attr('id', patternNode.attr('id') + this.settings.clone_id_suffix); - } - clonedNodes = clonedNodes.after(patternNode); - }); - } - return clonedNodes; - }, - - getPatternNodes: function(clone_selector) { - var nodes = {editNode: null, additionalNodes: null}; - var selectedNodes = $(clone_selector); - var firstNode = selectedNodes.first(); - - if (typeof(firstNode) !== 'undefined') { - // AS inplace_edit_control_container -> we have to select all child nodes - // Workaround for ie which does not support css > selector - if (firstNode.hasClass('as_inplace_pattern')) { - selectedNodes = firstNode.children(); - } - nodes.editNode = selectedNodes.first(); - nodes.additionalNodes = selectedNodes.slice(1); - } - return nodes; - }, - - setValue: function(editField, textValue) { - var function_name = 'setValueFor' + editField.get(0).nodeName.toLowerCase(); - if (typeof(this[function_name]) == 'function') { - this[function_name](editField, textValue); - } else { - editField.val(textValue); - } - }, - - setValueForselect: function(editField, textValue) { - var option_value = editField.children("option:contains('" + textValue + "')").val(); - - if (typeof(option_value) !== 'undefined') { - editField.val(option_value); - } - }, + var patternNodes = this.getPatternNodes(this.settings.clone_selector); + if (patternNodes.editNode == null) { + alert('did not find any matching node for ' + this.settings.clone_selector); + return; + } + + var editorNode = patternNodes.editNode.clone(); + var clonedNodes = null; + if (editorNode.attr('id')) editorNode.attr('id', editorNode.attr('id') + this.settings.clone_id_suffix); + editorNode.attr('name', 'inplace_value'); + editorNode.addClass('editor_field'); + this.setValue(editorNode, this.originalValue); + clonedNodes = editorNode; + + if (patternNodes.additionalNodes) { + patternNodes.additionalNodes.each(function (index, node) { + var patternNode = $(node).clone(); + if (patternNode.attr('id')) { + patternNode.attr('id', patternNode.attr('id') + this.settings.clone_id_suffix); + } + clonedNodes = clonedNodes.after(patternNode); + }); + } + return clonedNodes; + }, + + getPatternNodes: function(clone_selector) { + var nodes = {editNode: null, additionalNodes: null}; + var selectedNodes = $(clone_selector); + var firstNode = selectedNodes.first(); + + if (typeof(firstNode) !== 'undefined') { + // AS inplace_edit_control_container -> we have to select all child nodes + // Workaround for ie which does not support css > selector + if (firstNode.hasClass('as_inplace_pattern')) { + selectedNodes = firstNode.children(); + } + nodes.editNode = selectedNodes.first(); + nodes.additionalNodes = selectedNodes.slice(1); + } + return nodes; + }, + setValue: function(editField, textValue) { + var function_name = 'setValueFor' + editField.get(0).nodeName.toLowerCase(); + if (typeof(this[function_name]) == 'function') { + this[function_name](editField, textValue); + } else { + editField.val(textValue); + } + }, + + setValueForselect: function(editField, textValue) { + var option_value = editField.children("option:contains('" + textValue + "')").val(); + + if (typeof(option_value) !== 'undefined') { + editField.val(option_value); + } + }, + inputNameAndClass: function() { return ' name="inplace_value" class="inplace_field" '; }, @@ -387,10 +387,10 @@ $.extend(InlineEditor.prototype, { var value = trim(currentTextAndValue[1] || currentTextAndValue[0]); var text = trim(currentTextAndValue[0]); - var option = $('<option>').val(value).text(text); + var option = $('<option>').val(value).text(text); editor.append(option); } - + return editor; }, @@ -450,7 +450,7 @@ $.extend(InlineEditor.prototype, { if (enter === event.which) return that.dom.find('form').submit(); }); - + }, handleCancelEditor: function(anEvent) { @@ -471,15 +471,15 @@ $.extend(InlineEditor.prototype, { if (false === this.triggerDelegateCall('shouldCloseEditInPlace', true, anEvent)) return; - var editor = this.dom.find('[name]:input:not(:button,[name=""])').not('input:checkbox:not(:checked)').not('input:radio:not(:checked)'); - var enteredText = ''; - if (editor.length > 1) { - enteredText = jQuery.map(editor, function(item, index) { - return $(item).val(); - }); - } else { - enteredText = editor.val(); - } + var editor = this.dom.find('[name]:input:not(:button,[name=""])').not('input:checkbox:not(:checked)').not('input:radio:not(:checked)'); + var enteredText = ''; + if (editor.length > 1) { + enteredText = jQuery.map(editor, function(item, index) { + return $(item).val(); + }); + } else { + enteredText = editor.val(); + } enteredText = this.triggerDelegateCall('willCloseEditInPlace', enteredText); if (this.isDisabledDefaultSelectChoice() @@ -556,15 +556,15 @@ $.extend(InlineEditor.prototype, { handleSubmitToServer: function(enteredText) { var data = ''; - if (typeof(enteredText) === 'string') { - data += this.settings.update_value + '=' + encodeURIComponent(enteredText) + '&'; - } else { - for(var i = 0;i < enteredText.length; i++) { - data += this.settings.update_value + '[]=' + encodeURIComponent(enteredText[i]) + '&'; - } - } - - data += this.settings.element_id + '=' + this.dom.attr("id") + if (typeof(enteredText) === 'string') { + data += this.settings.update_value + '=' + encodeURIComponent(enteredText) + '&'; + } else { + for(var i = 0;i < enteredText.length; i++) { + data += this.settings.update_value + '[]=' + encodeURIComponent(enteredText[i]) + '&'; + } + } + + data += this.settings.element_id + '=' + this.dom.attr("id") + ((this.settings.params) ? '&' + this.settings.params : '') + '&' + this.settings.original_html + '=' + encodeURIComponent(this.originalValue) /* DEPRECATED in 2.2.0 */ + '&' + this.settings.original_value + '=' + encodeURIComponent(this.originalValue); @@ -577,22 +577,22 @@ $.extend(InlineEditor.prototype, { type: "POST", data: data, dataType: that.settings.ajax_data_type, - beforeSend: function(request, settings) { - that.triggerCallback(that.settings.beforeSend, request, settings); - }, + beforeSend: function(request, settings) { + that.triggerCallback(that.settings.beforeSend, request, settings); + }, complete: function(request){ that.didEndSaving(); }, success: function(data){ - if (that.settings.ajax_data_type == 'html') { - var new_text = data || that.settings.default_text; - - /* put the newly updated info into the original element */ - // FIXME: should be affected by the preferences switch - that.dom.html(new_text); - // REFACT: remove dom parameter, already in this, not documented, should be easy to remove - // REFACT: callback should be able to override what gets put into the DOM - } + if (that.settings.ajax_data_type == 'html') { + var new_text = data || that.settings.default_text; + + /* put the newly updated info into the original element */ + // FIXME: should be affected by the preferences switch + that.dom.html(new_text); + // REFACT: remove dom parameter, already in this, not documented, should be easy to remove + // REFACT: callback should be able to override what gets put into the DOM + } that.triggerCallback(that.settings.success,data); }, error: function(request) { @@ -624,7 +624,7 @@ $.extend(InlineEditor.prototype, { || ! $.isFunction(this.settings.delegate[aDelegateMethodName])) return defaultReturnValue; - var delegateReturnValue = this.settings.delegate[aDelegateMethodName](this.dom, this.settings, optionalEvent); + var delegateReturnValue = this.settings.delegate[aDelegateMethodName](this.dom, this.settings, optionalEvent); return (undefined === delegateReturnValue) ? defaultReturnValue : delegateReturnValue; From 3c9bff12442557f54f4cb32dfc527974116487c8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 28 Sep 2012 11:12:00 -1000 Subject: [PATCH 1694/2024] remove all, is not needed and query can be changed if do_list is reused or overrided --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index e1fab12120..f2cda6c628 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -341,7 +341,7 @@ def find_page(options = {}) else pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| find_options.merge!(:offset => offset, :limit => per_page) if options[:pagination] - append_to_query(klass, find_options).all + append_to_query(klass, find_options) end end pager.page(options[:page]) From 5c5917d4463a7387da2e5329f959773e1c62714c Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 2 Oct 2012 04:50:10 -1000 Subject: [PATCH 1695/2024] fix saving polymorphic associations with :select --- CHANGELOG | 2 +- lib/active_scaffold/attribute_params.rb | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ae3ec16ffd..de0f49e102 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,7 +10,7 @@ - Support for updating columns, row or table after updating a column with inplace_edit - Keep order for records in plural subforms, so new records are saved in same order as form order - Support add_subgroup in horizontal subforms -- Improve support in helpers for using :select form_ui with polimorphy associations (needs to use a select to choose the class) +- Improve support in helpers for using :select form_ui with polymorphic associations (needs to use a select to choose the class) - Allow to create in nested has_many :through associations, when source association is a belongs_to = 3.2.17 (not released yet) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 091d0ae187..738430901b 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -100,8 +100,15 @@ def column_value_from_param_value(parent_record, column, value) def column_value_from_param_simple_value(parent_record, column, value) if column.singular_association? - # it's a single id - column.association.klass.find(value) if value.present? + if value.present? + if column.polymorphic_association? + class_name = parent_record.send(column.association.foreign_type) + class_name.constantize.find(value) if class_name + else + # it's a single id + column.association.klass.find(value) + end + end elsif column.plural_association? column_plural_assocation_value_from_value(column, Array(value)) elsif column.number? && [:i18n_number, :currency].include?(column.options[:format]) && column.form_ui != :number From 82c70f2adaaeaa5c6ab72d2762bf03a08c6139b1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 5 Oct 2012 18:30:59 +0200 Subject: [PATCH 1696/2024] fix current page when is inside outer window --- CHANGELOG | 1 + lib/active_scaffold/helpers/pagination_helpers.rb | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index de0f49e102..b945737e1f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -20,6 +20,7 @@ - fix missing argument in datepicker conditions - check authorization in model for plural associations nested links - Allow to set action_group in nested.add_link +- fix current page when is inside outer window = 3.2.16 - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group diff --git a/lib/active_scaffold/helpers/pagination_helpers.rb b/lib/active_scaffold/helpers/pagination_helpers.rb index ef4eab0fdd..71fa08a201 100644 --- a/lib/active_scaffold/helpers/pagination_helpers.rb +++ b/lib/active_scaffold/helpers/pagination_helpers.rb @@ -16,10 +16,14 @@ def pagination_ajax_links(current_page, url_options, options, inner_window, oute end html = [] - last_page = 1 - last_page.upto(last_page + outer_window) do |num| - html << pagination_ajax_link(num, url_options, options) - last_page = num + if current_page.number == 1 + last_page = 0 + else + last_page = 1 + last_page.upto([last_page + outer_window, current_page.number - 1].min) do |num| + html << pagination_ajax_link(num, url_options, options) + last_page = num + end end if current_page.pager.infinite? offsets.reverse.each do |offset| From 5ce2b384a47704af4d04bcfff89ef8592dd8469d Mon Sep 17 00:00:00 2001 From: Michal Ochman <ocherek@gmail.com> Date: Thu, 11 Oct 2012 19:22:10 +0200 Subject: [PATCH 1697/2024] Fix 'Cancel' link bug --- app/assets/javascripts/prototype/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 940fbec66f..84c98bdffa 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -95,7 +95,7 @@ document.observe("dom:loaded", function() { var action_link = ActiveScaffold.find_action_link(as_cancel); if (action_link) { - var refresh_data = action_link.readAttribute('data-cancel-refresh') || as_cancel.readAttribute('data-refresh'); + var refresh_data = action_link.tag.readAttribute('data-cancel-refresh') || as_cancel.readAttribute('data-refresh'); if (refresh_data && action_link.refresh_url) { event.memo.url = action_link.refresh_url; } else if (!refresh_data || as_cancel.readAttribute('href').blank()) { From c13e14d0436846fd05d1f39c6d89e34a6b07fb0c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 16 Oct 2012 14:17:35 +0200 Subject: [PATCH 1698/2024] fix update columns in subforms --- .../helpers/form_column_helpers.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index c32a27a553..096f73db4a 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -95,13 +95,20 @@ def active_scaffold_input_options(column, scope = nil, options = {}) end def update_columns_options(column, scope, options) - form_action = params[:action] == 'edit' ? :update : :create - if column.update_columns && (column.update_columns & active_scaffold_config.send(form_action).columns.names).present? + form_action = if scope + subform_controller = controller.class.active_scaffold_controller_for(@record.class) + subform_controller.active_scaffold_config.subform + else + active_scaffold_config.send(params[:action] == 'edit' ? :update : :create) + end + if column.update_columns && (column.update_columns & form_action.columns.names).present? url_params = {:action => 'render_field', :column => column.name} url_params[:id] = @record.id if column.send_form_on_update_column url_params[:eid] = params[:eid] if params[:eid] - url_params[:controller] = controller.class.active_scaffold_controller_for(@record.class).controller_path if scope - url_params[:scope] = scope if scope + if scope + url_params[:controller] = subform_controller.controller_path + url_params[:scope] = scope + end options[:class] = "#{options[:class]} update_form".strip options['data-update_url'] = url_for(url_params) From 00d7b46693c366b5853c173060701bc06dec2fc4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 17 Oct 2012 19:13:38 +0200 Subject: [PATCH 1699/2024] don't check update columns with inplace edit columns --- lib/active_scaffold/helpers/form_column_helpers.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 096f73db4a..2d7199e5d9 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -98,10 +98,12 @@ def update_columns_options(column, scope, options) form_action = if scope subform_controller = controller.class.active_scaffold_controller_for(@record.class) subform_controller.active_scaffold_config.subform - else - active_scaffold_config.send(params[:action] == 'edit' ? :update : :create) + elsif [:new, :create].include? params[:action].to_sym + active_scaffold_config.create + elsif [:edit, :update].include? params[:action].to_sym + active_scaffold_config.update end - if column.update_columns && (column.update_columns & form_action.columns.names).present? + if form_action && column.update_columns && (column.update_columns & form_action.columns.names).present? url_params = {:action => 'render_field', :column => column.name} url_params[:id] = @record.id if column.send_form_on_update_column url_params[:eid] = params[:eid] if params[:eid] From 5683650d7de965aeba9b5598d9484facf46ee305 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 17 Oct 2012 20:24:21 +0200 Subject: [PATCH 1700/2024] fix calculations using field_search with has_many includes --- CHANGELOG | 1 + lib/active_scaffold/data_structures/column.rb | 10 +++++----- lib/active_scaffold/finder.rb | 10 ++++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b945737e1f..9a72c5024b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ - Support add_subgroup in horizontal subforms - Improve support in helpers for using :select form_ui with polymorphic associations (needs to use a select to choose the class) - Allow to create in nested has_many :through associations, when source association is a belongs_to +- Fix calculations using field_search with has_many includes = 3.2.17 (not released yet) - fix constraints for columns with multiple columns in search_sql diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 1c8d392f86..a5857fa63c 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -354,6 +354,11 @@ def number_to_native(value) # cache constraints for numeric columns (get in ActiveScaffold::Helpers::FormColumnHelpers::numerical_constraints_for_column) attr_accessor :numerical_constraints + # the table.field name for this column, if applicable + def field + @field ||= [@active_record_class.quoted_table_name, field_name].join('.') + end + protected def initialize_sort @@ -381,11 +386,6 @@ def initialize_search_sql # the table name from the ActiveRecord class attr_reader :table - - # the table.field name for this column, if applicable - def field - @field ||= [@active_record_class.quoted_table_name, field_name].join('.') - end def estimate_weight if singular_association? diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index f2cda6c628..7e94ac7c55 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -351,8 +351,14 @@ def calculate(column) conditions = all_conditions includes = active_scaffold_config.list.count_includes includes ||= active_scaffold_includes unless conditions.nil? - append_to_query(beginning_of_chain, :conditions => conditions, :includes => includes, - :joins => joins_for_collection).calculate(column.calculate, column.name) + primary_key = active_scaffold_config.model.primary_key + subquery = append_to_query(beginning_of_chain, :conditions => conditions, :joins => joins_for_collection) + subquery = subquery.select(active_scaffold_config.columns[primary_key].field) + if includes + includes_relation = beginning_of_chain.includes(includes) + subquery = subquery.send(:apply_join_dependency, subquery, includes_relation.send(:construct_join_dependency_for_association_find)) + end + beginning_of_chain.where(primary_key => subquery).calculate(column.calculate, column.name) end def append_to_query(query, options) From 8b85265946d6ebfe8a1461b04ef741e76f58ac10 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 18 Oct 2012 14:15:53 +0200 Subject: [PATCH 1701/2024] fix render field with update columns --- lib/active_scaffold/helpers/form_column_helpers.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 2d7199e5d9..1a407857a3 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -98,10 +98,8 @@ def update_columns_options(column, scope, options) form_action = if scope subform_controller = controller.class.active_scaffold_controller_for(@record.class) subform_controller.active_scaffold_config.subform - elsif [:new, :create].include? params[:action].to_sym - active_scaffold_config.create - elsif [:edit, :update].include? params[:action].to_sym - active_scaffold_config.update + elsif [:new, :create, :edit, :update, :render_field].include? params[:action].to_sym + active_scaffold_config.send(@record.new_record? :create : :update) end if form_action && column.update_columns && (column.update_columns & form_action.columns.names).present? url_params = {:action => 'render_field', :column => column.name} From 8d00629d0fd44eeee35a90ac7353b155206e439d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 18 Oct 2012 14:18:08 +0200 Subject: [PATCH 1702/2024] fix typo --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 1a407857a3..61e1ead2be 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -99,7 +99,7 @@ def update_columns_options(column, scope, options) subform_controller = controller.class.active_scaffold_controller_for(@record.class) subform_controller.active_scaffold_config.subform elsif [:new, :create, :edit, :update, :render_field].include? params[:action].to_sym - active_scaffold_config.send(@record.new_record? :create : :update) + active_scaffold_config.send(@record.new_record? ? :create : :update) end if form_action && column.update_columns && (column.update_columns & form_action.columns.names).present? url_params = {:action => 'render_field', :column => column.name} From 9008bb1cc1a5113df636db19a87d0a2b5f13c052 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 19 Oct 2012 13:04:23 +0200 Subject: [PATCH 1703/2024] simplify render :super and finding activescaffold views --- .../_action_group.html.erb | 0 .../_add_existing_form.html.erb | 0 .../_base_form.html.erb | 0 .../_create_form.html.erb | 0 .../_create_form_on_list.html.erb | 0 .../_field_search.html.erb | 0 .../active_scaffold_overrides}/_form.html.erb | 0 .../_form_association.html.erb | 0 .../_form_association_footer.html.erb | 0 .../_form_association_record.html.erb | 0 .../_form_attribute.html.erb | 0 .../_form_hidden_attribute.html.erb | 0 .../_form_messages.html.erb | 0 .../_horizontal_subform.html.erb | 0 .../_horizontal_subform_footer.html.erb | 0 .../_horizontal_subform_header.html.erb | 0 .../_human_conditions.html.erb | 0 .../active_scaffold_overrides}/_list.html.erb | 0 .../_list_calculations.html.erb | 0 .../_list_column_headings.html.erb | 0 .../_list_header.html.erb | 0 .../_list_inline_adapter.html.erb | 0 .../_list_messages.html.erb | 0 .../_list_pagination.html.erb | 0 .../_list_pagination_links.html.erb | 0 .../_list_record.html.erb | 0 .../_list_with_header.html.erb | 0 .../_messages.html.erb | 0 .../_refresh_list.js.erb | 0 .../_render_field.js.erb | 0 .../active_scaffold_overrides}/_row.html.erb | 0 .../_search.html.erb | 0 .../_search_attribute.html.erb | 0 .../active_scaffold_overrides}/_show.html.erb | 0 .../_show_columns.html.erb | 0 .../_update_actions.html.erb | 0 .../_update_calculations.js.erb | 0 .../_update_column.js.erb | 0 .../_update_form.html.erb | 0 .../_update_messages.js.erb | 0 .../_vertical_subform.html.erb | 0 .../action_confirmation.html.erb | 0 .../add_existing.js.erb | 0 .../add_existing_form.html.erb | 0 .../create.html.erb | 0 .../delete.html.erb | 0 .../active_scaffold_overrides}/destroy.js.erb | 0 .../edit_associated.js.erb | 0 .../field_search.html.erb | 0 .../form_messages.js.erb | 0 .../active_scaffold_overrides}/list.html.erb | 0 .../on_action_update.js.erb | 0 .../on_create.js.erb | 0 .../active_scaffold_overrides}/on_mark.js.erb | 0 .../on_update.js.erb | 0 .../render_field.js.erb | 0 .../active_scaffold_overrides}/row.js.erb | 0 .../search.html.erb | 0 .../active_scaffold_overrides}/show.html.erb | 0 .../update.html.erb | 0 .../update_column.js.erb | 0 .../update_row.js.erb | 0 lib/active_scaffold.rb | 29 ++++-------- lib/active_scaffold/actions/core.rb | 4 -- .../extensions/action_view_rendering.rb | 46 ++++++++----------- 65 files changed, 26 insertions(+), 53 deletions(-) rename {frontends/default/views => app/views/active_scaffold_overrides}/_action_group.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_add_existing_form.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_base_form.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_create_form.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_create_form_on_list.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_field_search.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_form.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_form_association.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_form_association_footer.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_form_association_record.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_form_attribute.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_form_hidden_attribute.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_form_messages.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_horizontal_subform.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_horizontal_subform_footer.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_horizontal_subform_header.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_human_conditions.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_list.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_list_calculations.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_list_column_headings.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_list_header.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_list_inline_adapter.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_list_messages.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_list_pagination.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_list_pagination_links.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_list_record.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_list_with_header.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_messages.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_refresh_list.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_render_field.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_row.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_search.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_search_attribute.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_show.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_show_columns.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_update_actions.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_update_calculations.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_update_column.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_update_form.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_update_messages.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/_vertical_subform.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/action_confirmation.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/add_existing.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/add_existing_form.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/create.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/delete.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/destroy.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/edit_associated.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/field_search.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/form_messages.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/list.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/on_action_update.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/on_create.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/on_mark.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/on_update.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/render_field.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/row.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/search.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/show.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/update.html.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/update_column.js.erb (100%) rename {frontends/default/views => app/views/active_scaffold_overrides}/update_row.js.erb (100%) diff --git a/frontends/default/views/_action_group.html.erb b/app/views/active_scaffold_overrides/_action_group.html.erb similarity index 100% rename from frontends/default/views/_action_group.html.erb rename to app/views/active_scaffold_overrides/_action_group.html.erb diff --git a/frontends/default/views/_add_existing_form.html.erb b/app/views/active_scaffold_overrides/_add_existing_form.html.erb similarity index 100% rename from frontends/default/views/_add_existing_form.html.erb rename to app/views/active_scaffold_overrides/_add_existing_form.html.erb diff --git a/frontends/default/views/_base_form.html.erb b/app/views/active_scaffold_overrides/_base_form.html.erb similarity index 100% rename from frontends/default/views/_base_form.html.erb rename to app/views/active_scaffold_overrides/_base_form.html.erb diff --git a/frontends/default/views/_create_form.html.erb b/app/views/active_scaffold_overrides/_create_form.html.erb similarity index 100% rename from frontends/default/views/_create_form.html.erb rename to app/views/active_scaffold_overrides/_create_form.html.erb diff --git a/frontends/default/views/_create_form_on_list.html.erb b/app/views/active_scaffold_overrides/_create_form_on_list.html.erb similarity index 100% rename from frontends/default/views/_create_form_on_list.html.erb rename to app/views/active_scaffold_overrides/_create_form_on_list.html.erb diff --git a/frontends/default/views/_field_search.html.erb b/app/views/active_scaffold_overrides/_field_search.html.erb similarity index 100% rename from frontends/default/views/_field_search.html.erb rename to app/views/active_scaffold_overrides/_field_search.html.erb diff --git a/frontends/default/views/_form.html.erb b/app/views/active_scaffold_overrides/_form.html.erb similarity index 100% rename from frontends/default/views/_form.html.erb rename to app/views/active_scaffold_overrides/_form.html.erb diff --git a/frontends/default/views/_form_association.html.erb b/app/views/active_scaffold_overrides/_form_association.html.erb similarity index 100% rename from frontends/default/views/_form_association.html.erb rename to app/views/active_scaffold_overrides/_form_association.html.erb diff --git a/frontends/default/views/_form_association_footer.html.erb b/app/views/active_scaffold_overrides/_form_association_footer.html.erb similarity index 100% rename from frontends/default/views/_form_association_footer.html.erb rename to app/views/active_scaffold_overrides/_form_association_footer.html.erb diff --git a/frontends/default/views/_form_association_record.html.erb b/app/views/active_scaffold_overrides/_form_association_record.html.erb similarity index 100% rename from frontends/default/views/_form_association_record.html.erb rename to app/views/active_scaffold_overrides/_form_association_record.html.erb diff --git a/frontends/default/views/_form_attribute.html.erb b/app/views/active_scaffold_overrides/_form_attribute.html.erb similarity index 100% rename from frontends/default/views/_form_attribute.html.erb rename to app/views/active_scaffold_overrides/_form_attribute.html.erb diff --git a/frontends/default/views/_form_hidden_attribute.html.erb b/app/views/active_scaffold_overrides/_form_hidden_attribute.html.erb similarity index 100% rename from frontends/default/views/_form_hidden_attribute.html.erb rename to app/views/active_scaffold_overrides/_form_hidden_attribute.html.erb diff --git a/frontends/default/views/_form_messages.html.erb b/app/views/active_scaffold_overrides/_form_messages.html.erb similarity index 100% rename from frontends/default/views/_form_messages.html.erb rename to app/views/active_scaffold_overrides/_form_messages.html.erb diff --git a/frontends/default/views/_horizontal_subform.html.erb b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb similarity index 100% rename from frontends/default/views/_horizontal_subform.html.erb rename to app/views/active_scaffold_overrides/_horizontal_subform.html.erb diff --git a/frontends/default/views/_horizontal_subform_footer.html.erb b/app/views/active_scaffold_overrides/_horizontal_subform_footer.html.erb similarity index 100% rename from frontends/default/views/_horizontal_subform_footer.html.erb rename to app/views/active_scaffold_overrides/_horizontal_subform_footer.html.erb diff --git a/frontends/default/views/_horizontal_subform_header.html.erb b/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb similarity index 100% rename from frontends/default/views/_horizontal_subform_header.html.erb rename to app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb diff --git a/frontends/default/views/_human_conditions.html.erb b/app/views/active_scaffold_overrides/_human_conditions.html.erb similarity index 100% rename from frontends/default/views/_human_conditions.html.erb rename to app/views/active_scaffold_overrides/_human_conditions.html.erb diff --git a/frontends/default/views/_list.html.erb b/app/views/active_scaffold_overrides/_list.html.erb similarity index 100% rename from frontends/default/views/_list.html.erb rename to app/views/active_scaffold_overrides/_list.html.erb diff --git a/frontends/default/views/_list_calculations.html.erb b/app/views/active_scaffold_overrides/_list_calculations.html.erb similarity index 100% rename from frontends/default/views/_list_calculations.html.erb rename to app/views/active_scaffold_overrides/_list_calculations.html.erb diff --git a/frontends/default/views/_list_column_headings.html.erb b/app/views/active_scaffold_overrides/_list_column_headings.html.erb similarity index 100% rename from frontends/default/views/_list_column_headings.html.erb rename to app/views/active_scaffold_overrides/_list_column_headings.html.erb diff --git a/frontends/default/views/_list_header.html.erb b/app/views/active_scaffold_overrides/_list_header.html.erb similarity index 100% rename from frontends/default/views/_list_header.html.erb rename to app/views/active_scaffold_overrides/_list_header.html.erb diff --git a/frontends/default/views/_list_inline_adapter.html.erb b/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb similarity index 100% rename from frontends/default/views/_list_inline_adapter.html.erb rename to app/views/active_scaffold_overrides/_list_inline_adapter.html.erb diff --git a/frontends/default/views/_list_messages.html.erb b/app/views/active_scaffold_overrides/_list_messages.html.erb similarity index 100% rename from frontends/default/views/_list_messages.html.erb rename to app/views/active_scaffold_overrides/_list_messages.html.erb diff --git a/frontends/default/views/_list_pagination.html.erb b/app/views/active_scaffold_overrides/_list_pagination.html.erb similarity index 100% rename from frontends/default/views/_list_pagination.html.erb rename to app/views/active_scaffold_overrides/_list_pagination.html.erb diff --git a/frontends/default/views/_list_pagination_links.html.erb b/app/views/active_scaffold_overrides/_list_pagination_links.html.erb similarity index 100% rename from frontends/default/views/_list_pagination_links.html.erb rename to app/views/active_scaffold_overrides/_list_pagination_links.html.erb diff --git a/frontends/default/views/_list_record.html.erb b/app/views/active_scaffold_overrides/_list_record.html.erb similarity index 100% rename from frontends/default/views/_list_record.html.erb rename to app/views/active_scaffold_overrides/_list_record.html.erb diff --git a/frontends/default/views/_list_with_header.html.erb b/app/views/active_scaffold_overrides/_list_with_header.html.erb similarity index 100% rename from frontends/default/views/_list_with_header.html.erb rename to app/views/active_scaffold_overrides/_list_with_header.html.erb diff --git a/frontends/default/views/_messages.html.erb b/app/views/active_scaffold_overrides/_messages.html.erb similarity index 100% rename from frontends/default/views/_messages.html.erb rename to app/views/active_scaffold_overrides/_messages.html.erb diff --git a/frontends/default/views/_refresh_list.js.erb b/app/views/active_scaffold_overrides/_refresh_list.js.erb similarity index 100% rename from frontends/default/views/_refresh_list.js.erb rename to app/views/active_scaffold_overrides/_refresh_list.js.erb diff --git a/frontends/default/views/_render_field.js.erb b/app/views/active_scaffold_overrides/_render_field.js.erb similarity index 100% rename from frontends/default/views/_render_field.js.erb rename to app/views/active_scaffold_overrides/_render_field.js.erb diff --git a/frontends/default/views/_row.html.erb b/app/views/active_scaffold_overrides/_row.html.erb similarity index 100% rename from frontends/default/views/_row.html.erb rename to app/views/active_scaffold_overrides/_row.html.erb diff --git a/frontends/default/views/_search.html.erb b/app/views/active_scaffold_overrides/_search.html.erb similarity index 100% rename from frontends/default/views/_search.html.erb rename to app/views/active_scaffold_overrides/_search.html.erb diff --git a/frontends/default/views/_search_attribute.html.erb b/app/views/active_scaffold_overrides/_search_attribute.html.erb similarity index 100% rename from frontends/default/views/_search_attribute.html.erb rename to app/views/active_scaffold_overrides/_search_attribute.html.erb diff --git a/frontends/default/views/_show.html.erb b/app/views/active_scaffold_overrides/_show.html.erb similarity index 100% rename from frontends/default/views/_show.html.erb rename to app/views/active_scaffold_overrides/_show.html.erb diff --git a/frontends/default/views/_show_columns.html.erb b/app/views/active_scaffold_overrides/_show_columns.html.erb similarity index 100% rename from frontends/default/views/_show_columns.html.erb rename to app/views/active_scaffold_overrides/_show_columns.html.erb diff --git a/frontends/default/views/_update_actions.html.erb b/app/views/active_scaffold_overrides/_update_actions.html.erb similarity index 100% rename from frontends/default/views/_update_actions.html.erb rename to app/views/active_scaffold_overrides/_update_actions.html.erb diff --git a/frontends/default/views/_update_calculations.js.erb b/app/views/active_scaffold_overrides/_update_calculations.js.erb similarity index 100% rename from frontends/default/views/_update_calculations.js.erb rename to app/views/active_scaffold_overrides/_update_calculations.js.erb diff --git a/frontends/default/views/_update_column.js.erb b/app/views/active_scaffold_overrides/_update_column.js.erb similarity index 100% rename from frontends/default/views/_update_column.js.erb rename to app/views/active_scaffold_overrides/_update_column.js.erb diff --git a/frontends/default/views/_update_form.html.erb b/app/views/active_scaffold_overrides/_update_form.html.erb similarity index 100% rename from frontends/default/views/_update_form.html.erb rename to app/views/active_scaffold_overrides/_update_form.html.erb diff --git a/frontends/default/views/_update_messages.js.erb b/app/views/active_scaffold_overrides/_update_messages.js.erb similarity index 100% rename from frontends/default/views/_update_messages.js.erb rename to app/views/active_scaffold_overrides/_update_messages.js.erb diff --git a/frontends/default/views/_vertical_subform.html.erb b/app/views/active_scaffold_overrides/_vertical_subform.html.erb similarity index 100% rename from frontends/default/views/_vertical_subform.html.erb rename to app/views/active_scaffold_overrides/_vertical_subform.html.erb diff --git a/frontends/default/views/action_confirmation.html.erb b/app/views/active_scaffold_overrides/action_confirmation.html.erb similarity index 100% rename from frontends/default/views/action_confirmation.html.erb rename to app/views/active_scaffold_overrides/action_confirmation.html.erb diff --git a/frontends/default/views/add_existing.js.erb b/app/views/active_scaffold_overrides/add_existing.js.erb similarity index 100% rename from frontends/default/views/add_existing.js.erb rename to app/views/active_scaffold_overrides/add_existing.js.erb diff --git a/frontends/default/views/add_existing_form.html.erb b/app/views/active_scaffold_overrides/add_existing_form.html.erb similarity index 100% rename from frontends/default/views/add_existing_form.html.erb rename to app/views/active_scaffold_overrides/add_existing_form.html.erb diff --git a/frontends/default/views/create.html.erb b/app/views/active_scaffold_overrides/create.html.erb similarity index 100% rename from frontends/default/views/create.html.erb rename to app/views/active_scaffold_overrides/create.html.erb diff --git a/frontends/default/views/delete.html.erb b/app/views/active_scaffold_overrides/delete.html.erb similarity index 100% rename from frontends/default/views/delete.html.erb rename to app/views/active_scaffold_overrides/delete.html.erb diff --git a/frontends/default/views/destroy.js.erb b/app/views/active_scaffold_overrides/destroy.js.erb similarity index 100% rename from frontends/default/views/destroy.js.erb rename to app/views/active_scaffold_overrides/destroy.js.erb diff --git a/frontends/default/views/edit_associated.js.erb b/app/views/active_scaffold_overrides/edit_associated.js.erb similarity index 100% rename from frontends/default/views/edit_associated.js.erb rename to app/views/active_scaffold_overrides/edit_associated.js.erb diff --git a/frontends/default/views/field_search.html.erb b/app/views/active_scaffold_overrides/field_search.html.erb similarity index 100% rename from frontends/default/views/field_search.html.erb rename to app/views/active_scaffold_overrides/field_search.html.erb diff --git a/frontends/default/views/form_messages.js.erb b/app/views/active_scaffold_overrides/form_messages.js.erb similarity index 100% rename from frontends/default/views/form_messages.js.erb rename to app/views/active_scaffold_overrides/form_messages.js.erb diff --git a/frontends/default/views/list.html.erb b/app/views/active_scaffold_overrides/list.html.erb similarity index 100% rename from frontends/default/views/list.html.erb rename to app/views/active_scaffold_overrides/list.html.erb diff --git a/frontends/default/views/on_action_update.js.erb b/app/views/active_scaffold_overrides/on_action_update.js.erb similarity index 100% rename from frontends/default/views/on_action_update.js.erb rename to app/views/active_scaffold_overrides/on_action_update.js.erb diff --git a/frontends/default/views/on_create.js.erb b/app/views/active_scaffold_overrides/on_create.js.erb similarity index 100% rename from frontends/default/views/on_create.js.erb rename to app/views/active_scaffold_overrides/on_create.js.erb diff --git a/frontends/default/views/on_mark.js.erb b/app/views/active_scaffold_overrides/on_mark.js.erb similarity index 100% rename from frontends/default/views/on_mark.js.erb rename to app/views/active_scaffold_overrides/on_mark.js.erb diff --git a/frontends/default/views/on_update.js.erb b/app/views/active_scaffold_overrides/on_update.js.erb similarity index 100% rename from frontends/default/views/on_update.js.erb rename to app/views/active_scaffold_overrides/on_update.js.erb diff --git a/frontends/default/views/render_field.js.erb b/app/views/active_scaffold_overrides/render_field.js.erb similarity index 100% rename from frontends/default/views/render_field.js.erb rename to app/views/active_scaffold_overrides/render_field.js.erb diff --git a/frontends/default/views/row.js.erb b/app/views/active_scaffold_overrides/row.js.erb similarity index 100% rename from frontends/default/views/row.js.erb rename to app/views/active_scaffold_overrides/row.js.erb diff --git a/frontends/default/views/search.html.erb b/app/views/active_scaffold_overrides/search.html.erb similarity index 100% rename from frontends/default/views/search.html.erb rename to app/views/active_scaffold_overrides/search.html.erb diff --git a/frontends/default/views/show.html.erb b/app/views/active_scaffold_overrides/show.html.erb similarity index 100% rename from frontends/default/views/show.html.erb rename to app/views/active_scaffold_overrides/show.html.erb diff --git a/frontends/default/views/update.html.erb b/app/views/active_scaffold_overrides/update.html.erb similarity index 100% rename from frontends/default/views/update.html.erb rename to app/views/active_scaffold_overrides/update.html.erb diff --git a/frontends/default/views/update_column.js.erb b/app/views/active_scaffold_overrides/update_column.js.erb similarity index 100% rename from frontends/default/views/update_column.js.erb rename to app/views/active_scaffold_overrides/update_column.js.erb diff --git a/frontends/default/views/update_row.js.erb b/app/views/active_scaffold_overrides/update_row.js.erb similarity index 100% rename from frontends/default/views/update_row.js.erb rename to app/views/active_scaffold_overrides/update_row.js.erb diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index e349589771..0ebef12c2a 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -173,16 +173,7 @@ def active_scaffold(model_id = nil, &block) @active_scaffold_config = ActiveScaffold::Config::Core.new(model_id) @active_scaffold_config_block = block self.links_for_associations - - @active_scaffold_frontends = [] - if active_scaffold_config.frontend.to_sym != :default - active_scaffold_custom_frontend_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'frontends', active_scaffold_config.frontend.to_s , 'views') - @active_scaffold_frontends << active_scaffold_custom_frontend_path - end - active_scaffold_default_frontend_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'frontends', 'default' , 'views') - @active_scaffold_frontends << active_scaffold_default_frontend_path - @active_scaffold_custom_paths = [] - + self.active_scaffold_superclasses_blocks.each {|superblock| self.active_scaffold_config.configure &superblock} self.active_scaffold_config.sti_children = nil # reset sti_children if set in parent block self.active_scaffold_config.configure &block if block_given? @@ -292,17 +283,13 @@ def link_for_association_as_scope(scope, options = {}) end def add_active_scaffold_path(path) - @active_scaffold_paths = nil # Force active_scaffold_paths to rebuild - @active_scaffold_custom_paths << path - end - - def active_scaffold_paths - return @active_scaffold_paths unless @active_scaffold_paths.nil? - - @active_scaffold_paths = [] - @active_scaffold_paths.concat @active_scaffold_custom_paths unless @active_scaffold_custom_paths.nil? - @active_scaffold_paths.concat @active_scaffold_frontends unless @active_scaffold_frontends.nil? - @active_scaffold_paths = ActionView::PathSet.new(@active_scaffold_paths) + as_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'app', 'views') + index = view_paths.find_index { |p| p.to_s == as_path } + if index + view_paths.insert index, path + else + append_view_path path + end end def active_scaffold_config diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 664e906a99..a1e2197cde 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -26,10 +26,6 @@ def embedded? def nested? false end - - def details_for_lookup - super.merge(:active_scaffold_view_paths => self.class.active_scaffold_paths) - end def render_field_for_inplace_editing @record = find_if_allowed(params[:id], :update) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index da0fada7ac..239b93747e 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -1,23 +1,11 @@ module ActionView class LookupContext attr_accessor :last_template - register_detail(:active_scaffold_view_paths) { nil } - def find(name, prefixes = [], partial = false, keys = [], options = {}) - unless active_scaffold_view_paths && prefixes && prefixes.one? && prefixes.first.blank? - args = args_for_lookup(name, prefixes, partial, keys, options) - view_paths = @view_paths - template = @view_paths.find_all(*args).first - end - if active_scaffold_view_paths && template.nil? - view_paths = active_scaffold_view_paths.is_a?(ActionView::PathSet) ? active_scaffold_view_paths : ActionView::PathSet.new(active_scaffold_view_paths) - args ||= args_for_lookup(name, '', partial, keys, options) - template = view_paths.find(*args_for_lookup(name, '', partial, keys, options)) - end - raise(MissingTemplate.new(view_paths, *args)) unless template - self.last_template = template + def find_template_with_last_template(name, prefixes = [], partial = false, keys = [], options = {}) + self.last_template = find_template_without_last_template(name, prefixes, partial, keys, options) end - alias :find_template :find + alias_method_chain :find_template, :last_template end end @@ -83,29 +71,31 @@ def render_with_active_scaffold(*args, &block) elsif args.first == :super prefix, template = @virtual_path.split('/') - last_view = view_stack.last || {} options = args[1] || {} options[:locals] ||= {} - options[:locals].reverse_merge!(last_view[:locals] || {}) - options[:template] = template || prefix - # if template is nil we are rendering an active_scaffold (or active_scaffold's plugin) view - if template + options[:locals] = view_stack.last[:locals].merge!(options[:locals]) if view_stack.last && view_stack.last[:locals] + options[:template] = template + # if prefix is active_scaffold_overrides we must try to render with this prefix in following paths + if prefix != 'active_scaffold_overrides' options[:prefixes] = lookup_context.prefixes.drop((lookup_context.prefixes.find_index(prefix) || -1) + 1) else - options[:prefixes] = [''] - active_scaffold_view_paths = lookup_context.active_scaffold_view_paths - last_view_path = File.expand_path(File.dirname(lookup_context.last_template.inspect), Rails.root) - lookup_context.active_scaffold_view_paths = active_scaffold_view_paths.drop(active_scaffold_view_paths.find_index {|path| path.to_s == last_view_path} + 1) + options[:prefixes] = ['active_scaffold_overrides'] + view_paths = lookup_context.view_paths + last_view_path = File.expand_path(File.dirname(File.dirname(lookup_context.last_template.inspect)), Rails.root) + lookup_context.view_paths = view_paths.drop(view_paths.find_index {|path| path.to_s == last_view_path} + 1) end result = render_without_active_scaffold options - lookup_context.active_scaffold_view_paths = active_scaffold_view_paths unless template + lookup_context.view_paths = view_paths if view_paths result else - options = args.first - current_view = {:locals => options[:locals]} if options.is_a?(Hash) - view_stack << current_view if current_view.present? + last_template = lookup_context.last_template + if args.first.is_a?(Hash) + current_view = {:locals => args.first[:locals]} + view_stack << current_view + end result = render_without_active_scaffold(*args, &block) view_stack.pop if current_view.present? + lookup_context.last_template = last_template result end end From 9d45269676e5906054dec92e480d8514d7842a28 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 23 Oct 2012 11:15:20 -1000 Subject: [PATCH 1704/2024] allow to define as routes with multiple methods (eg. get, post) --- lib/active_scaffold/extensions/routing_mapper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/extensions/routing_mapper.rb b/lib/active_scaffold/extensions/routing_mapper.rb index 83020d29c7..3a14a59107 100644 --- a/lib/active_scaffold/extensions/routing_mapper.rb +++ b/lib/active_scaffold/extensions/routing_mapper.rb @@ -12,10 +12,10 @@ class Mapper module Base def as_routes(options = {:association => true}) collection do - ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].each {|name, type| send(type, name)} + ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection].each {|name, type| match(name, :via => type)} end member do - ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each {|name, type| send(type, name)} + ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each {|name, type| match(name, :via => type)} end as_association_routes if options[:association] end From f49004fdab657cdae287ae4c243c2b6c2bdf2614 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 24 Oct 2012 08:59:33 +0200 Subject: [PATCH 1705/2024] move nested params to constant --- lib/active_scaffold/helpers/view_helpers.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index fc01e4761d..af7e8c4f7e 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -3,6 +3,7 @@ module Helpers # All extra helpers that should be included in the View. # Also a dumping ground for uncategorized helpers. module ViewHelpers + NESTED_PARAMS = [:eid, :association, :parent_scaffold] include ActiveScaffold::Helpers::IdHelpers include ActiveScaffold::Helpers::AssociationHelpers include ActiveScaffold::Helpers::PaginationHelpers @@ -210,7 +211,7 @@ def query_string_for_action_links(link) next end qs = "#{key}=#{value}" - if [:eid, :association, :parent_scaffold].include?(key) || conditions_from_params.include?(key) || (nested? && nested.param_name == key) + if NESTED_PARAMS.include?(key) || conditions_from_params.include?(key) || (nested? && nested.param_name == key) non_nested_query_string_options << qs else query_string_options << qs From b98632888cb287d951638aa298e636d63f7a26d7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 24 Oct 2012 09:49:32 +0200 Subject: [PATCH 1706/2024] fix add_active_scaffold_path, it was changing view_paths for all controllers --- lib/active_scaffold.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 0ebef12c2a..9576ad9d28 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -286,7 +286,7 @@ def add_active_scaffold_path(path) as_path = File.join(ActiveScaffold::Config::Core.plugin_directory, 'app', 'views') index = view_paths.find_index { |p| p.to_s == as_path } if index - view_paths.insert index, path + self.view_paths = view_paths[0..index-1] + Array(path) + view_paths[index..-1] else append_view_path path end From 876706b9fb4c672334e3f20b8b75139e41f9126b Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 24 Oct 2012 09:55:14 +0200 Subject: [PATCH 1707/2024] remove dont_close from form params --- lib/active_scaffold/helpers/controller_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index d4a6947dd7..d0e75a632e 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -12,7 +12,7 @@ def params_for(options = {}) # :sort, :sort_direction, and :page are arguments that stored in the session. they need not propagate. # and wow. no we don't want to propagate :record. # :commit is a special rails variable for form buttons - blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token, :iframe, :associated_id] + blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token, :iframe, :associated_id, :dont_close] unless @params_for @params_for = {} params.select { |key, value| blacklist.exclude? key.to_sym if key }.each {|key, value| @params_for[key.to_sym] = value.duplicable? ? value.clone : value} From 74189e965b46192844545058bf5db39f9546b97d Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 24 Oct 2012 10:33:04 +0200 Subject: [PATCH 1708/2024] fix update after apply --- app/views/active_scaffold_overrides/on_update.js.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/active_scaffold_overrides/on_update.js.erb b/app/views/active_scaffold_overrides/on_update.js.erb index 05c1b35222..c33d6932d2 100644 --- a/app/views/active_scaffold_overrides/on_update.js.erb +++ b/app/views/active_scaffold_overrides/on_update.js.erb @@ -6,6 +6,7 @@ action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'mes <% if params[:dont_close] %> <% row_selector = element_row_id(:action => :list, :id => @record.id) %> ActiveScaffold.update_row('<%= row_selector %>', '<%= escape_javascript(render(:partial => 'list_record', :locals => {:record => @record})) %>'); + action_link.target = $('#<%= row_selector %>'); <%= render :partial => 'update_calculations', :formats => [:js] %> <% else %> <% if render_parent? %> From f11f083916b3992b8f898b499d35457d8f87cd30 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 24 Oct 2012 14:16:16 +0200 Subject: [PATCH 1709/2024] fix label for nested.add_link with polymorphic associations --- lib/active_scaffold/config/nested.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index 1850e5c7d0..4c717dffc9 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -26,7 +26,12 @@ def initialize(core_config) def add_link(attribute, options = {}) column = @core.columns[attribute.to_sym] unless column.nil? || column.association.nil? - options.reverse_merge! :security_method => :nested_authorized?, :label => column.association.klass.model_name.human({:count => column.singular_association? ? 1 : 2, :default => column.association.klass.name.pluralize}) + label = if column.polymorphic_association? + column.label + else + column.association.klass.model_name.human({:count => column.singular_association? ? 1 : 2, :default => column.association.klass.name.pluralize}) + end + options.reverse_merge! :security_method => :nested_authorized?, :label => label action_group = options.delete(:action_group) || self.action_group action_link = @core.link_for_association(column, options) @core.action_links.add_to_group(action_link, action_group) unless action_link.nil? From a799d68d2166801809b646a875d45f8bba93fe55 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 24 Oct 2012 14:22:24 +0200 Subject: [PATCH 1710/2024] fix for nested.add_link with polymorphic associations and fixed action --- lib/active_scaffold/helpers/view_helpers.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index af7e8c4f7e..d1949a6636 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -105,7 +105,7 @@ def skip_action_link(link, *args) end def render_action_link(link, record = nil, options = {}) - if link.action.nil? + if link.action.nil? || link.column.try(:polymorphic_association?) link = action_link_to_inline_form(link, record) options[:authorized] = false if link.action.nil? options.delete :link if link.crud_type == :create @@ -127,7 +127,8 @@ def action_link_to_inline_form(link, record) link.controller = controller_path_for_activerecord(associated.class) return link if link.controller.nil? end - configure_column_link(link, record, associated) + link = configure_column_link(link, record, associated) if link.action.nil? + link end def configure_column_link(link, record, associated, actions = nil) From 5bd0685032370cc9c94d526da886e7a0a586a334 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 24 Oct 2012 14:25:12 +0200 Subject: [PATCH 1711/2024] fix for nested.add_link with polymorphic associations and nil value --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index d1949a6636..ca5e5ab10a 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -107,7 +107,7 @@ def skip_action_link(link, *args) def render_action_link(link, record = nil, options = {}) if link.action.nil? || link.column.try(:polymorphic_association?) link = action_link_to_inline_form(link, record) - options[:authorized] = false if link.action.nil? + options[:authorized] = false if link.action.nil? || link.controller.nil? options.delete :link if link.crud_type == :create end if link.action.nil? || (link.type == :member && options.has_key?(:authorized) && !options[:authorized]) From 1d6509dd18ccb1d25cc4a12a7d1224e4c4dc054e Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 24 Oct 2012 23:40:35 -1000 Subject: [PATCH 1712/2024] allow to use :id in list to get one-item lists --- lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/helpers/controller_helpers.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index a1e2197cde..835d31d1b4 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -157,7 +157,7 @@ def beginning_of_chain def conditions_from_params @conditions_from_params ||= begin conditions = {} - params.reject {|key, value| [:controller, :action, :id, :page, :sort, :sort_direction].include?(key.to_sym)}.each do |key, value| + params.except(:controller, :action, :page, :sort, :sort_direction).each do |key, value| next unless active_scaffold_config.model.columns_hash[key.to_s] next if active_scaffold_constraints[key.to_sym] next if nested? and nested.param_name == key.to_sym diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index d0e75a632e..a606ae111b 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -15,7 +15,7 @@ def params_for(options = {}) blacklist = [:adapter, :position, :sort, :sort_direction, :page, :record, :commit, :_method, :authenticity_token, :iframe, :associated_id, :dont_close] unless @params_for @params_for = {} - params.select { |key, value| blacklist.exclude? key.to_sym if key }.each {|key, value| @params_for[key.to_sym] = value.duplicable? ? value.clone : value} + params.except(*blacklist).each {|key, value| @params_for[key.to_sym] = value.duplicable? ? value.clone : value} @params_for[:controller] = '/' + @params_for[:controller].to_s unless @params_for[:controller].to_s.first(1) == '/' # for namespaced controllers @params_for.delete(:id) if @params_for[:id].nil? end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index ca5e5ab10a..e801132d84 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -315,6 +315,8 @@ def url_options_for_nested_link(column, record, link, url_options) url_options[column.association.active_record.name.foreign_key.to_sym] = url_options.delete(:id) if column.singular_association? && url_options[:action].to_sym != :index url_options[:id] = '--CHILD_ID--' if record.send(column.association.name).present? + else + url_options[:id] = nil end elsif link.parameters && link.parameters[:named_scope] url_options[:parent_scaffold] = controller_path From e49c50a64e0a8c7f007c95d0416a1d632eae270e Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 25 Oct 2012 00:18:31 -1000 Subject: [PATCH 1713/2024] fix one cached link, child_id must be set and removed with sub for records without associated record --- lib/active_scaffold/helpers/view_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index e801132d84..f4f15a2034 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -185,7 +185,7 @@ def action_link_url(link, record) end url = record ? url.sub('--ID--', record.id.to_s) : url.clone - url = url.sub('--CHILD_ID--', record.send(link.column.association.name).id.to_s) if link.column.try(:singular_association?) && record.send(link.column.association.name).present? + url = url.sub('--CHILD_ID--', record.send(link.column.association.name).try(:id).to_s) if link.column.try(:singular_association?) query_string, non_nested_query_string = query_string_for_action_links(link) if query_string || (!link.nested_link? && non_nested_query_string) url << (url.include?('?') ? '&' : '?') @@ -314,7 +314,7 @@ def url_options_for_nested_link(column, record, link, url_options) url_options[:parent_scaffold] = controller_path url_options[column.association.active_record.name.foreign_key.to_sym] = url_options.delete(:id) if column.singular_association? && url_options[:action].to_sym != :index - url_options[:id] = '--CHILD_ID--' if record.send(column.association.name).present? + url_options[:id] = '--CHILD_ID--' else url_options[:id] = nil end From 3ca866ddccc6130f8ef63a0ca7f3a20048fc4722 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 25 Oct 2012 21:03:44 -1000 Subject: [PATCH 1714/2024] don't check reverse if association is not present --- lib/active_scaffold/attribute_params.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 738430901b..07ecfc5c23 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -66,7 +66,7 @@ def update_record_from_params(parent_record, columns, attributes) if parent_record.new_record? parent_record.class.reflect_on_all_associations.each do |a| next unless [:has_one, :has_many].include?(a.macro) and not (a.options[:through] || a.options[:finder_sql]) - next unless association_proxy = parent_record.send(a.name) + next unless association_proxy = parent_record.send(a.name).present? raise ActiveScaffold::ReverseAssociationRequired, "Association #{a.name} in class #{parent_record.class.name}: In order to support :has_one and :has_many where the parent record is new and the child record(s) validate the presence of the parent, ActiveScaffold requires the reverse association (the belongs_to)." unless a.reverse From 996bc198c12800e265eb872246ec32430f38c54b Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 26 Oct 2012 01:57:54 -1000 Subject: [PATCH 1715/2024] Add support to ActiveScaffold.create_record_row to insert after or before of an element --- CHANGELOG | 1 + app/assets/javascripts/jquery/active_scaffold.js | 13 +++++++++++++ .../javascripts/prototype/active_scaffold.js | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 9a72c5024b..d4f5b51288 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,7 @@ - Improve support in helpers for using :select form_ui with polymorphic associations (needs to use a select to choose the class) - Allow to create in nested has_many :through associations, when source association is a belongs_to - Fix calculations using field_search with has_many includes +- Add support to ActiveScaffold.create_record_row to insert after or before of an element = 3.2.17 (not released yet) - fix constraints for columns with multiple columns in search_sql diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index ae718c5d24..03b8e91434 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -499,6 +499,19 @@ var ActiveScaffold = { } else { new_row = tbody.append(html).children().last(); } + } else if (typeof options.insert_at == 'object') { + var insert_method, get_method, row, id; + if (options.insert_at.after) { + insert_method = 'after'; + get_method = 'next'; + } else { + insert_method = 'before'; + get_method = 'prev'; + } + if (id = options.insert_at[insert_method]) row = tbody.children('#' + id); + if (row && row.length) { + new_row = row[insert_method](html)[get_method](); + } } this.stripe(tbody); this.hide_empty_message(tbody); diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 84c98bdffa..729ca21f96 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -447,6 +447,20 @@ var ActiveScaffold = { tbody.insert({bottom: html}); } new_row = Selector.findChildElements(tbody, ['tr.record']).last(); + } else if (typeof options.insert_at == 'object') { + var insert_method, get_method, row, id; + if (options.insert_at.after) { + insert_method = 'after'; + get_method = 'next'; + } else { + insert_method = 'before'; + get_method = 'previous'; + } + if (id = options.insert_at[insert_method]) row = $(id); + if (row) { + row.insert({insert_method: html}); + new_row = row[get_method](); + } } this.stripe(tbody); From 4d3effde8a6ebefeb1d0efeac2734950cc4b967d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 26 Oct 2012 17:15:27 +0200 Subject: [PATCH 1716/2024] change version to 3.3.0.rc --- lib/active_scaffold/actions/update.rb | 2 +- lib/active_scaffold/config/core.rb | 3 +-- lib/active_scaffold/version.rb | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 9c02a3099a..92e1c9ebae 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -155,7 +155,7 @@ def update_refresh_list? # The default security delegates to ActiveRecordPermissions. # You may override the method to customize. def update_authorized?(record = nil) - (!nested? || !nested.readonly?) && (record || self).send(:authorized_for?, :crud_type => :update) + (!nested? || !nested.readonly?) && (record || self).authorized_for?(:crud_type => :update) end private def update_authorized_filter diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index 243130e311..2715b00875 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -154,8 +154,7 @@ def _load_action_columns # then, register the column objects self.actions.each do |action_name| action = self.send(action_name) - next unless action.respond_to? :columns - action.columns.set_columns(self.columns) + action.columns.set_columns(self.columns) if action.respond_to?(:columns) end end diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index a5fb5ee44d..6ec7c4b699 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 3 - PATCH = "0rc" + PATCH = "0.rc" STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From b74e828ec1aee6a098a76a4c0088bcb06c3aa758 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 26 Oct 2012 04:32:19 -1000 Subject: [PATCH 1717/2024] fix translation of -select- in :select form_ui for non-association columns --- lib/active_scaffold/helpers/form_column_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 61e1ead2be..cfd3b416b6 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -130,8 +130,8 @@ def grouped_options_for_select(column, select_options, optgroup) end def active_scaffold_translate_select_options(options) - options[:include_blank] = as_(options[:include_blank]) if options[:include_blank].is_a? Symbol - options[:prompt] = as_(options[:prompt]) if options[:prompt].is_a? Symbol + options[:include_blank] = as_(options[:include_blank].to_s) if options[:include_blank].is_a? Symbol + options[:prompt] = as_(options[:prompt].to_s) if options[:prompt].is_a? Symbol options end From afb77582e713254a21faf3b119434810fce53158 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 26 Oct 2012 11:35:20 -1000 Subject: [PATCH 1718/2024] fix update columns in form when some columns are not displayed --- app/views/active_scaffold_overrides/_render_field.js.erb | 1 + lib/active_scaffold/actions/core.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_render_field.js.erb b/app/views/active_scaffold_overrides/_render_field.js.erb index df4d697a74..49c901baf0 100644 --- a/app/views/active_scaffold_overrides/_render_field.js.erb +++ b/app/views/active_scaffold_overrides/_render_field.js.erb @@ -4,6 +4,7 @@ else active_scaffold_config.columns[render_field.to_sym] end + return unless @main_columns.include? column.name @rendered ||= Set.new return if @rendered.include? column.name @rendered << column.name diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 835d31d1b4..c73d5de258 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -38,6 +38,7 @@ def render_field_for_update_columns @source_id = params.delete(:source_id) @columns = column.update_columns @scope = params.delete(:scope) + @main_columns = active_scaffold_config.send(@scope ? :subform : (params[:id] ? :update : :create)).columns if column.send_form_on_update_column if @scope @@ -50,7 +51,7 @@ def render_field_for_update_columns id = params[:id] end @record = id ? find_if_allowed(id, :update) : new_model - @record = update_record_from_params(@record, active_scaffold_config.send(@scope ? :subform : (id ? :update : :create)).columns, hash) + @record = update_record_from_params(@record, @main_columns, hash) else @record = new_model value = column_value_from_param_value(@record, column, params.delete(:value)) From 4feed66ccc51b9bfb59811fd6cde28ee0ff49efb Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 26 Oct 2012 11:53:55 -1000 Subject: [PATCH 1719/2024] fix recordselect with polymorphic asociations --- CHANGELOG | 1 + lib/active_scaffold/bridges/record_select/helpers.rb | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d4f5b51288..a108f95dce 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,7 @@ - check authorization in model for plural associations nested links - Allow to set action_group in nested.add_link - fix current page when is inside outer window +- Support record select with polymorphic associations = 3.2.16 - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group diff --git a/lib/active_scaffold/bridges/record_select/helpers.rb b/lib/active_scaffold/bridges/record_select/helpers.rb index 795734110b..7d2d330f35 100644 --- a/lib/active_scaffold/bridges/record_select/helpers.rb +++ b/lib/active_scaffold/bridges/record_select/helpers.rb @@ -25,7 +25,14 @@ def active_scaffold_record_select(column, options, value, multiple) unless column.association raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)." end - remote_controller = active_scaffold_controller_for(column.association.klass).controller_path + klass = if column.polymorphic_association? + @record.send(column.association.foreign_type).constantize rescue nil + else + column.association.klass + end + return content_tag :span, '', :class => options[:class] unless klass + + remote_controller = active_scaffold_controller_for(klass).controller_path # if the opposite association is a :belongs_to (in that case association in this class must be has_one or has_many) # then only show records that have not been associated yet @@ -41,7 +48,7 @@ def active_scaffold_record_select(column, options, value, multiple) html = if multiple record_multi_select_field(options[:name], value || [], record_select_options) else - record_select_field(options[:name], value || column.association.klass.new, record_select_options) + record_select_field(options[:name], value || klass.new, record_select_options) end html = self.class.field_error_proc.call(html, self) if @record.errors[column.name].any? html From 4533a698f3a93397a8159cb3b9c6d8a5d11fa16d Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 26 Oct 2012 11:55:32 -1000 Subject: [PATCH 1720/2024] fix refreshing columns with inplace editor after updating a column --- app/views/active_scaffold_overrides/_update_column.js.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_update_column.js.erb b/app/views/active_scaffold_overrides/_update_column.js.erb index 77d958c235..c4cd3ff4c0 100644 --- a/app/views/active_scaffold_overrides/_update_column.js.erb +++ b/app/views/active_scaffold_overrides/_update_column.js.erb @@ -8,7 +8,9 @@ return if @rendered.include? column.name @rendered << column.name -%> -ActiveScaffold.replace_html('<%= row_id %> .<%= column.name %>-column','<%= escape_javascript(get_column_value(@record, column)) %>'); +<% if @record.authorized_for?(:crud_type => :read, :column => column.name) -%> + ActiveScaffold.replace_html('<%= row_id %> .<%= column.name %>-column','<%= escape_javascript(render_list_column(get_column_value(@record, column), column, @record)) %>'); +<% end -%> <% if column.update_columns && !column.update_columns.empty? %> <%= render(:partial => 'update_column', :collection => column.update_columns & active_scaffold_config.list.columns.names, :locals => {:row_id => row_id})%> <% end %> From 990b737b63e0a440dd40cc6df94a5ca8814be9d2 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 29 Oct 2012 07:29:47 +0100 Subject: [PATCH 1721/2024] fix saving --- lib/active_scaffold/attribute_params.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 07ecfc5c23..895131877b 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -66,7 +66,7 @@ def update_record_from_params(parent_record, columns, attributes) if parent_record.new_record? parent_record.class.reflect_on_all_associations.each do |a| next unless [:has_one, :has_many].include?(a.macro) and not (a.options[:through] || a.options[:finder_sql]) - next unless association_proxy = parent_record.send(a.name).present? + next unless (association_proxy = parent_record.send(a.name)).present? raise ActiveScaffold::ReverseAssociationRequired, "Association #{a.name} in class #{parent_record.class.name}: In order to support :has_one and :has_many where the parent record is new and the child record(s) validate the presence of the parent, ActiveScaffold requires the reverse association (the belongs_to)." unless a.reverse From 4349c82a125d1be0ba028cf639217d1f8797f028 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 29 Oct 2012 07:50:23 +0100 Subject: [PATCH 1722/2024] fix updating table after inplace edit updating --- lib/active_scaffold/actions/update.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 92e1c9ebae..42c7f65ffc 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -117,7 +117,7 @@ def do_update_column params.delete(:original_html) params.delete(:original_value) - @record = find_if_allowed(params[:id], :read) + @record = find_if_allowed(params.delete(:id), :read) if @record.authorized_for?(:crud_type => :update, :column => column) @column = active_scaffold_config.columns[column] value ||= unless @column.column.nil? || @column.column.null From db858bcb477af30baf7f321bd604637a0ed5bc53 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 29 Oct 2012 07:55:18 +0100 Subject: [PATCH 1723/2024] remove sleep --- app/views/active_scaffold_overrides/update_column.js.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/update_column.js.erb b/app/views/active_scaffold_overrides/update_column.js.erb index 5d2f35ede8..802efa1246 100644 --- a/app/views/active_scaffold_overrides/update_column.js.erb +++ b/app/views/active_scaffold_overrides/update_column.js.erb @@ -1,4 +1,3 @@ -<% sleep 1 %> <% @column_span_id ||= element_cell_id(:id => @record.id.to_s, :action => 'update_column', :name => @column.name) -%> <% unless controller.send :successful? -%> alert('<%= escape_javascript(@record.errors.full_messages.join("\n")) %>'); From e05e84dce913c41af01d6f4d97aab6d0529c308c Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 29 Oct 2012 10:13:34 +0100 Subject: [PATCH 1724/2024] fix inplace_edit_update --- lib/active_scaffold/actions/update.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 42c7f65ffc..3dfd76df6d 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -117,7 +117,7 @@ def do_update_column params.delete(:original_html) params.delete(:original_value) - @record = find_if_allowed(params.delete(:id), :read) + @record = find_if_allowed(params[:id], :read) if @record.authorized_for?(:crud_type => :update, :column => column) @column = active_scaffold_config.columns[column] value ||= unless @column.column.nil? || @column.column.null @@ -132,6 +132,7 @@ def do_update_column self.successful = @record.save if self.successful? && active_scaffold_config.actions.include?(:list) if @column.inplace_edit_update == :table + params.delete(:id) do_list elsif @column.inplace_edit_update get_row From 1ad4f138d7f533fc4c65a7b9594df40da2a554ab Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 29 Oct 2012 10:33:50 +0100 Subject: [PATCH 1725/2024] fix column action links with wrap_tag --- app/assets/javascripts/jquery/active_scaffold.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 03b8e91434..e963f97e57 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -937,11 +937,10 @@ ActiveScaffold.ActionLink = { var parent = element.closest('.actions'); if (parent.length === 0) { // maybe an column action_link - parent = element.parent(); + parent = element.closest('tr.record'); } - if (parent && parent.is('td')) { + if (parent && parent.is('tr')) { // record action - parent = parent.closest('tr.record'); var target = parent.find('a.as_action'); var loading_indicator = parent.find('td.actions .loading-indicator'); new ActiveScaffold.Actions.Record(target, parent, loading_indicator); From af3f85e2765675da26360efa34d5d5dc4e9e04bc Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 29 Oct 2012 14:04:34 +0100 Subject: [PATCH 1726/2024] fix sort_by :method => :method_name --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 7e94ac7c55..a190cce3d9 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -394,7 +394,7 @@ def apply_conditions(query, *conditions) def sort_collection_by_column(collection, column, order) sorter = column.sort[:method] collection = collection.sort_by { |record| - value = (sorter.is_a? Proc) ? record.instance_eval(&sorter) : record.instance_eval(sorter) + value = (sorter.is_a? Proc) ? record.instance_eval(&sorter) : record.instance_eval(sorter.to_s) value = '' if value.nil? value } From 12a644b48a8f020cc9d5fa05c3c67515e56b7bc0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 29 Oct 2012 17:17:36 +0100 Subject: [PATCH 1727/2024] fix display indicator in member actions --- app/assets/javascripts/jquery/active_scaffold.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index e963f97e57..032e7704c7 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -935,11 +935,11 @@ ActiveScaffold.ActionLink = { element.data(); // $ 1.4.2 workaround if (typeof(element.data('action_link')) === 'undefined' && !element.hasClass('as_adapter')) { var parent = element.closest('.actions'); - if (parent.length === 0) { + if (parent.length === 0 || parent.is('td')) { // maybe an column action_link parent = element.closest('tr.record'); } - if (parent && parent.is('tr')) { + if (parent.is('tr')) { // record action var target = parent.find('a.as_action'); var loading_indicator = parent.find('td.actions .loading-indicator'); From 5abd6100a13b2f3ecf2d535da2710e4d415ed5f3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 29 Oct 2012 09:27:36 -1000 Subject: [PATCH 1728/2024] add dynamic action_group --- CHANGELOG | 1 + app/assets/javascripts/jquery/active_scaffold.js | 11 +++++++++++ app/assets/javascripts/prototype/active_scaffold.js | 11 +++++++++++ app/assets/stylesheets/active_scaffold_layout.css | 10 +++++++++- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a108f95dce..9fe0626336 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,7 @@ - Allow to create in nested has_many :through associations, when source association is a belongs_to - Fix calculations using field_search with has_many includes - Add support to ActiveScaffold.create_record_row to insert after or before of an element +- Add support for dynamic action group = 3.2.17 (not released yet) - fix constraints for columns with multiple columns in search_sql diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 032e7704c7..72d07548a2 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -1,4 +1,8 @@ jQuery(document).ready(function() { + jQuery(document).click(function(event) { + var group = jQuery(event.target).closest('.action_group.dyn ul'); + jQuery('.action_group.dyn ul').not(group).remove(); + }); jQuery('form.as_form').live('ajax:beforeSend', function(event) { var as_form = jQuery(this).closest("form"); if (as_form.attr('data-loading') == 'true') { @@ -571,6 +575,13 @@ var ActiveScaffold = { element = jQuery(element); return ActiveScaffold.ActionLink.get(element.is('.actions a') ? element : element.closest('.as_adapter')); }, + + display_dynamic_action_group: function(link, html) { + if (typeof(link) == 'string') link = jQuery('#' + link); + link.next('ul').remove(); + link.closest('td').addClass('action_group dyn'); + link.after(html); + }, scroll_to: function(element, checkInViewport) { if (typeof checkInViewport == 'undefined') checkInViewport = true; diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 729ca21f96..443f79cfcd 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -12,6 +12,10 @@ if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFu document.observe("dom:loaded", function() { + document.on('click', function(event) { + var group = event.findElement().up('.action_group.dyn ul'); + $$('.action_group.dyn ul').reject(function(i) { i == group}).invoke('remove'); + }); document.on('ajax:create', 'form.as_form', function(event) { var source = event.findElement(); var as_form = event.findElement('form'); @@ -525,6 +529,13 @@ var ActiveScaffold = { element = $(element); return ActiveScaffold.ActionLink.get(element.match('.actions a') ? element : element.up('.as_adapter')); }, + + display_dynamic_action_group: function(link, html) { + link = $(link); + link.next('ul').remove(); + link.up('td').addClassName('action_group dyn'); + link.insert({after: html}); + }, scroll_to: function(element, checkInViewport) { if (typeof checkInViewport == 'undefined') checkInViewport = true; diff --git a/app/assets/stylesheets/active_scaffold_layout.css b/app/assets/stylesheets/active_scaffold_layout.css index 655ded3ed8..fe0f2e6dbb 100644 --- a/app/assets/stylesheets/active_scaffold_layout.css +++ b/app/assets/stylesheets/active_scaffold_layout.css @@ -257,6 +257,11 @@ line-height: 200%; display: none; width: 150px; right: 0px; +z-index: 2; +} +.active-scaffold .actions .action_group.dyn ul { +width: auto; +display: block; } .active-scaffold .actions .action_group ul ul { @@ -272,7 +277,7 @@ border-top: 1px dashed; display: block; position: relative; width: auto; -z-index: 2; +text-align: left; } .active-scaffold .actions .action_group ul li div { @@ -289,6 +294,9 @@ z-index: 2; background-position: 5px 50%; background-repeat: no-repeat; } +.active-scaffold .actions .action_group.dyn ul li a { + padding-left: 5px; +} .active-scaffold .actions .action_group ul li.top { border-top-width: 0px; From 57ce15896004b89384b80faaee41c8cb9707c155 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Oct 2012 13:26:59 +0100 Subject: [PATCH 1729/2024] use nested_parent_record and delete nested#parent_scope --- lib/active_scaffold/actions/nested.rb | 8 ++++---- lib/active_scaffold/data_structures/nested_info.rb | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 193f50f897..c0fa4955bb 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -75,16 +75,16 @@ def include_habtm_actions def beginning_of_chain if nested? && nested.association if nested.association.collection? - nested.parent_scope.send(nested.association.name) + nested_parent_record.send(nested.association.name) elsif nested.association.options[:through] # has_one :through doesn't need conditions active_scaffold_config.model elsif nested.child_association.belongs_to? - active_scaffold_config.model.where(nested.child_association.foreign_key => nested.parent_scope) + active_scaffold_config.model.where(nested.child_association.foreign_key => nested_parent_record) elsif nested.association.belongs_to? - active_scaffold_config.model.joins(nested.child_association.name).where(nested.association.active_record.table_name => {nested.association.active_record.primary_key => nested.parent_scope}) + active_scaffold_config.model.joins(nested.child_association.name).where(nested.association.active_record.table_name => {nested.association.active_record.primary_key => nested_parent_record}) end elsif nested? && nested.scope - nested.parent_scope.send(nested.scope) + nested_parent_record.send(nested.scope) else active_scaffold_config.model end diff --git a/lib/active_scaffold/data_structures/nested_info.rb b/lib/active_scaffold/data_structures/nested_info.rb index 620aa3db14..31e14e10af 100644 --- a/lib/active_scaffold/data_structures/nested_info.rb +++ b/lib/active_scaffold/data_structures/nested_info.rb @@ -30,10 +30,6 @@ def new_instance? result end - def parent_scope - @parent_scope ||= parent_model.find(parent_id) - end - def habtm? false end From 0b34dbd199881153dddf86667879062fd70ce486 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Oct 2012 15:58:41 +0100 Subject: [PATCH 1730/2024] fix column count in inline adapter for forms and views --- CHANGELOG | 1 + .../active_scaffold_overrides/_list_inline_adapter.html.erb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 9fe0626336..763cb4ad8f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -25,6 +25,7 @@ - Allow to set action_group in nested.add_link - fix current page when is inside outer window - Support record select with polymorphic associations +- Fix column count in inline adapter for forms and views = 3.2.16 - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group diff --git a/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb b/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb index 316a4d8a71..62600380bc 100644 --- a/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb +++ b/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb @@ -6,7 +6,7 @@ active_scaffold_config end # increment in 1 for self-associations, parent_model config will have constraints too - config.list.columns.count + 1 + (config == active_scaffold_config ? 1 : 0) + config.list.columns.count + 1 + (config == active_scaffold_config && action_name == 'index' ? 1 : 0) end %> <%# nested_id, allows us to remove a nested scaffold programmatically %> From 3a37246c164887b41f35495f98f6d45483503956 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Oct 2012 16:42:26 +0100 Subject: [PATCH 1731/2024] fix nested without reverse association --- lib/active_scaffold/actions/nested.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index c0fa4955bb..9ec65020da 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -76,7 +76,7 @@ def beginning_of_chain if nested? && nested.association if nested.association.collection? nested_parent_record.send(nested.association.name) - elsif nested.association.options[:through] # has_one :through doesn't need conditions + elsif nested.association.options[:through] || nested.child_association.nil? # has_one :through doesn't need conditions, and without child_association is not possible to add them active_scaffold_config.model elsif nested.child_association.belongs_to? active_scaffold_config.model.where(nested.child_association.foreign_key => nested_parent_record) From 198afcc05cf8175447da1d97867a9089b90a318a Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Oct 2012 17:20:46 +0100 Subject: [PATCH 1732/2024] fix #203 don't cache parent_id in links inside a nested scaffold --- lib/active_scaffold/helpers/view_helpers.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index f4f15a2034..34cd095b2c 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -185,7 +185,11 @@ def action_link_url(link, record) end url = record ? url.sub('--ID--', record.id.to_s) : url.clone - url = url.sub('--CHILD_ID--', record.send(link.column.association.name).try(:id).to_s) if link.column.try(:singular_association?) + if link.column.try(:singular_association?) + url = url.sub('--CHILD_ID--', record.send(link.column.association.name).try(:id).to_s) + elsif nested? + url = url.sub('--CHILD_ID--', params[nested.param_name]) + end query_string, non_nested_query_string = query_string_for_action_links(link) if query_string || (!link.nested_link? && non_nested_query_string) url << (url.include?('?') ? '&' : '?') @@ -242,7 +246,11 @@ def action_link_url_options(link, record) url_options.merge! link.dynamic_parameters.call(record) end end - url_options_for_nested_link(link.column, record, link, url_options) if link.nested_link? + if link.nested_link? + url_options_for_nested_link(link.column, record, link, url_options) + elsif nested? + url_options[nested.param_name] = '--CHILD_ID--' + end url_options_for_sti_link(link.column, record, link, url_options) unless record.nil? || active_scaffold_config.sti_children.nil? url_options[:_method] = link.method if !link.confirm? && link.inline? && link.method != :get url_options From fc42c9425a76706b161e8883181d68afc42bd23d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 30 Oct 2012 17:34:40 +0100 Subject: [PATCH 1733/2024] add option to disable caching of action link urls, give cleaner urls when as_nested_resource is used, related #203 --- CHANGELOG | 2 +- lib/active_scaffold/config/core.rb | 8 +++++++ lib/active_scaffold/helpers/view_helpers.rb | 24 ++++++++++++++------- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 763cb4ad8f..2e028f22d9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ = master - Unify field overrides and list_ui method signatures -- Improve performance removing some partials and adding some caching for helper overrides and UIs, and caching url generation for lists +- Improve performance removing some partials and adding some caching for helper overrides and UIs, and caching url generation for lists (optional) - Drop support for rails 3.1 - Add HTML5 form fields - Add :chosen form_ui, and :chosen and :multi_chosen search_ui diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index 2715b00875..34403a8d12 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -25,6 +25,10 @@ def self.actions=(val) cattr_accessor :theme @@theme = :default + # enable caching of action link urls + cattr_accessor :cache_action_link_urls + @@cache_action_link_urls = true + # lets you disable the DHTML history def self.dhtml_history=(val) @@dhtml_history = val @@ -91,6 +95,9 @@ def columns=(val) # lets you override the global ActiveScaffold theme for a specific controller attr_accessor :theme + # enable caching of action link urls + attr_accessor :cache_action_link_urls + # lets you specify whether add a create link for each sti child for a specific controller attr_accessor :sti_create_links def add_sti_create_links? @@ -139,6 +146,7 @@ def initialize(model_id) # inherit the global frontend @frontend = self.class.frontend @theme = self.class.theme + @cache_action_link_urls = self.class.cache_action_link_urls @sti_create_links = self.class.sti_create_links # inherit from the global set of action links diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 34cd095b2c..de61247635 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -179,9 +179,14 @@ def action_link_url(link, record) url = if link.cached_url link.cached_url else - url = url_for(action_link_url_options(link, record)) - link.cached_url = url unless link.dynamic_parameters.is_a?(Proc) - url + url_options = action_link_url_options(link, record) + if active_scaffold_config.cache_action_link_urls + url = url_for(url_options) + link.cached_url = url unless link.dynamic_parameters.is_a?(Proc) + url + else + url_for(params_for(url_options)) + end end url = record ? url.sub('--ID--', record.id.to_s) : url.clone @@ -190,11 +195,14 @@ def action_link_url(link, record) elsif nested? url = url.sub('--CHILD_ID--', params[nested.param_name]) end - query_string, non_nested_query_string = query_string_for_action_links(link) - if query_string || (!link.nested_link? && non_nested_query_string) - url << (url.include?('?') ? '&' : '?') - url << query_string if query_string - url << non_nested_query_string if !link.nested_link? && non_nested_query_string + + if active_scaffold_config.cache_action_link_urls + query_string, non_nested_query_string = query_string_for_action_links(link) + if query_string || (!link.nested_link? && non_nested_query_string) + url << (url.include?('?') ? '&' : '?') + url << query_string if query_string + url << non_nested_query_string if !link.nested_link? && non_nested_query_string + end end url end From 978659cae7d4cc2f9fbf0f3e744f1e770a7f2b85 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 31 Oct 2012 00:08:33 -1000 Subject: [PATCH 1734/2024] hide dynamic group after click --- app/assets/javascripts/jquery/active_scaffold.js | 3 +-- app/assets/javascripts/prototype/active_scaffold.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 72d07548a2..303b7d8ef4 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -1,7 +1,6 @@ jQuery(document).ready(function() { jQuery(document).click(function(event) { - var group = jQuery(event.target).closest('.action_group.dyn ul'); - jQuery('.action_group.dyn ul').not(group).remove(); + jQuery('.action_group.dyn ul').remove(); }); jQuery('form.as_form').live('ajax:beforeSend', function(event) { var as_form = jQuery(this).closest("form"); diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 443f79cfcd..5c0746cf6f 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -13,8 +13,7 @@ if (!Element.Methods.highlight) Element.addMethods({highlight: Prototype.emptyFu document.observe("dom:loaded", function() { document.on('click', function(event) { - var group = event.findElement().up('.action_group.dyn ul'); - $$('.action_group.dyn ul').reject(function(i) { i == group}).invoke('remove'); + $$('.action_group.dyn ul').invoke('remove'); }); document.on('ajax:create', 'form.as_form', function(event) { var source = event.findElement(); From 9cc9f1a070917e6a4dd14d424592f57127206066 Mon Sep 17 00:00:00 2001 From: Nick Rogers <ncrogers@gmail.com> Date: Sat, 3 Nov 2012 15:35:39 -0700 Subject: [PATCH 1735/2024] Fix nil comparison with Fixnum exception when @page.pager.count returns nil (e.g., within rails functional test environment). --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 9468528e3b..972bdddda7 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -266,7 +266,7 @@ def all_marked? if active_scaffold_config.mark.mark_all_mode == :page all_marked = @page.items.detect { |record| !marked_records.include?(record.id) }.nil? else - all_marked = (marked_records.length >= @page.pager.count) + all_marked = (marked_records.length >= @page.pager.count.to_i) end end From 96a8b6de0e2b8b7ec9e3038216f484e3a7db44ca Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 5 Nov 2012 21:09:24 -1000 Subject: [PATCH 1736/2024] fix url --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index de61247635..c8ea1fb7e3 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -193,7 +193,7 @@ def action_link_url(link, record) if link.column.try(:singular_association?) url = url.sub('--CHILD_ID--', record.send(link.column.association.name).try(:id).to_s) elsif nested? - url = url.sub('--CHILD_ID--', params[nested.param_name]) + url = url.sub('--CHILD_ID--', params[nested.param_name].to_s) end if active_scaffold_config.cache_action_link_urls From 37394d2b011061d7c4143a53f32151493f4269f3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 6 Nov 2012 15:58:15 +0100 Subject: [PATCH 1737/2024] support class prefix on human_condition_column helper, fixes #205 --- CHANGELOG | 1 + lib/active_scaffold/helpers/human_condition_helpers.rb | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2e028f22d9..b43f81b19d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,7 @@ - Fix calculations using field_search with has_many includes - Add support to ActiveScaffold.create_record_row to insert after or before of an element - Add support for dynamic action group +- Add support for class prefix on human condition helpers = 3.2.17 (not released yet) - fix constraints for columns with multiple columns in search_sql diff --git a/lib/active_scaffold/helpers/human_condition_helpers.rb b/lib/active_scaffold/helpers/human_condition_helpers.rb index fce4cbc0c8..ec0a02887c 100644 --- a/lib/active_scaffold/helpers/human_condition_helpers.rb +++ b/lib/active_scaffold/helpers/human_condition_helpers.rb @@ -45,14 +45,11 @@ def active_scaffold_human_condition_for(column) end unless value.nil? end - def override_human_condition_column?(column) - respond_to?(override_human_condition_column(column)) - end - # the naming convention for overriding form fields with helpers def override_human_condition_column(column) - "#{column.name}_human_condition_column" + override_helper column, 'human_condition_column' end + alias_method :override_human_condition_column?, :override_human_condition_column def override_human_condition?(search_ui) respond_to?(override_human_condition(search_ui)) From 871e5289ea2007460c9dcd0c43f9c4d979751c9d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 6 Nov 2012 15:58:53 +0100 Subject: [PATCH 1738/2024] backport for 3.2.x --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index b43f81b19d..06d7fc718b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,7 +15,6 @@ - Fix calculations using field_search with has_many includes - Add support to ActiveScaffold.create_record_row to insert after or before of an element - Add support for dynamic action group -- Add support for class prefix on human condition helpers = 3.2.17 (not released yet) - fix constraints for columns with multiple columns in search_sql @@ -27,6 +26,7 @@ - fix current page when is inside outer window - Support record select with polymorphic associations - Fix column count in inline adapter for forms and views +- Add support for class prefix on human condition helpers = 3.2.16 - Fix use of column.css_class in form when is a proc, it wasn't skipped when form was a columns group From 3b3d135573c935d6649495a95761bfa7775decd0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 6 Nov 2012 16:08:50 +0100 Subject: [PATCH 1739/2024] add route to index filtering by id --- lib/active_scaffold/extensions/routing_mapper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/extensions/routing_mapper.rb b/lib/active_scaffold/extensions/routing_mapper.rb index 3a14a59107..397cba4ad0 100644 --- a/lib/active_scaffold/extensions/routing_mapper.rb +++ b/lib/active_scaffold/extensions/routing_mapper.rb @@ -16,6 +16,7 @@ def as_routes(options = {:association => true}) end member do ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:member].each {|name, type| match(name, :via => type)} + get 'list', :action => :index end as_association_routes if options[:association] end From 7f6ac25eb161bb8201054f49a46bae7e54682ab1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 6 Nov 2012 16:45:46 +0100 Subject: [PATCH 1740/2024] fix build association for has_one through, fixes #209 --- lib/active_scaffold/helpers/controller_helpers.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index a606ae111b..eb32ae0a17 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -75,7 +75,11 @@ def render_parent_action def build_associated(column, record) if column.singular_association? - record.send(:"build_#{column.name}") + if column.association.options[:through] + record.send(:"build_#{column.association.through_reflection.name}").send(:"build_#{column.name}") + else + record.send(:"build_#{column.name}") + end else record.send(column.name).build end From 4874ef8650a6a00dda0ff45b1778460dd4109052 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 6 Nov 2012 22:18:58 -1000 Subject: [PATCH 1741/2024] don't cache action_link url between requests --- lib/active_scaffold/data_structures/action_link.rb | 5 +++-- lib/active_scaffold/helpers/view_helpers.rb | 9 ++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index cb1eea4373..9ad849d67f 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -183,8 +183,9 @@ def nested_link? @column || (parameters && parameters[:named_scope]) end - # Internal use: generated url for this action_link - attr_accessor :cached_url + def name_to_cache_link_url + @name_to_cache_link_url ||= :"@#{controller || 'self'}_#{action}#{'_' if parameters.present?}#{parameters.map{|k,v| "#{k}_#{v}"}.join('_')}_link_url" + end end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index c8ea1fb7e3..28327e10d7 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -174,15 +174,14 @@ def column_link_authorized?(link, column, record, associated) record.authorized_for?(:crud_type => link.crud_type) end end - + def action_link_url(link, record) - url = if link.cached_url - link.cached_url - else + url = instance_variable_get(link.name_to_cache_link_url) + url ||= begin url_options = action_link_url_options(link, record) if active_scaffold_config.cache_action_link_urls url = url_for(url_options) - link.cached_url = url unless link.dynamic_parameters.is_a?(Proc) + instance_variable_set(link.name_to_cache_link_url, url) unless link.dynamic_parameters.is_a?(Proc) url else url_for(params_for(url_options)) From 8e1467e25e17e78e0c7a13ad9c685c7c159de9ef Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 7 Nov 2012 01:00:11 -1000 Subject: [PATCH 1742/2024] load nested record with readonly false --- lib/active_scaffold/actions/nested.rb | 2 +- lib/active_scaffold/actions/update.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index 9ec65020da..cd4839b5ef 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -81,7 +81,7 @@ def beginning_of_chain elsif nested.child_association.belongs_to? active_scaffold_config.model.where(nested.child_association.foreign_key => nested_parent_record) elsif nested.association.belongs_to? - active_scaffold_config.model.joins(nested.child_association.name).where(nested.association.active_record.table_name => {nested.association.active_record.primary_key => nested_parent_record}) + active_scaffold_config.model.joins(nested.child_association.name).where(nested.association.active_record.table_name => {nested.association.active_record.primary_key => nested_parent_record}).readonly(false) end elsif nested? && nested.scope nested_parent_record.send(nested.scope) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 3dfd76df6d..ad67de7d62 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -72,6 +72,7 @@ def update_respond_to_yaml # A simple method to find and prepare a record for editing # May be overridden to customize the record (set default values, etc.) def do_edit + debugger @record = find_if_allowed(params[:id], :update) end From 1a378c0252a691917539c93f78583f34a8dff027 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 7 Nov 2012 17:32:36 +0100 Subject: [PATCH 1743/2024] main_return_path without id --- lib/active_scaffold/helpers/controller_helpers.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index eb32ae0a17..f68f1103b8 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -38,7 +38,8 @@ def main_path_to_return #parameters[:eid] = nil # not neeeded anymore? end parameters[:action] = "index" - params_for(parameters).except(:parent_column, :parent_id, :id, :associated_id, :utf8) + parameters[:id] = nil + params_for(parameters).except(:parent_column, :parent_id, :associated_id, :utf8) end end From 9fbd71160dc426f73b04ee0be9883ffd33ba1f23 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 8 Nov 2012 13:47:43 +0100 Subject: [PATCH 1744/2024] fix duplicate with create persistent --- app/views/active_scaffold_overrides/on_create.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/on_create.js.erb b/app/views/active_scaffold_overrides/on_create.js.erb index 70f7f4800a..105f97c1bc 100644 --- a/app/views/active_scaffold_overrides/on_create.js.erb +++ b/app/views/active_scaffold_overrides/on_create.js.erb @@ -22,7 +22,7 @@ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'mess <% unless render_parent? %> <% if (active_scaffold_config.create.persistent) %> - action_link.reload(); + if (action_link) action_link.reload(); <% else %> action_link.close(); <% end %> From 72bb3293b60af8ad755e48ca9201c74b7dccc6c9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 8 Nov 2012 14:06:34 +0100 Subject: [PATCH 1745/2024] fix duplicate with create persistent --- app/views/active_scaffold_overrides/on_create.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/on_create.js.erb b/app/views/active_scaffold_overrides/on_create.js.erb index 105f97c1bc..76ea9b0a00 100644 --- a/app/views/active_scaffold_overrides/on_create.js.erb +++ b/app/views/active_scaffold_overrides/on_create.js.erb @@ -22,7 +22,7 @@ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'mess <% unless render_parent? %> <% if (active_scaffold_config.create.persistent) %> - if (action_link) action_link.reload(); + if (action_link.reload) action_link.reload(); <% else %> action_link.close(); <% end %> From 5a1f1190708c7734d10ddb1480c44cf45e5fbcd9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 8 Nov 2012 14:17:24 +0100 Subject: [PATCH 1746/2024] reload record ActionLink too --- app/assets/javascripts/jquery/active_scaffold.js | 10 +++++----- app/assets/javascripts/prototype/active_scaffold.js | 10 +++++----- app/views/active_scaffold_overrides/on_create.js.erb | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 303b7d8ef4..3882aeeb2d 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -996,6 +996,11 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target.attr('id'), ActiveScaffold.config.scroll_on_close == 'checkInViewport'); }, + reload: function() { + this.close(); + this.open(); + }, + get_new_adapter_id: function() { var id = 'adapter_'; var i = 0; @@ -1155,9 +1160,4 @@ ActiveScaffold.ActionLink.Table = ActiveScaffold.ActionLink.Abstract.extend({ } ActiveScaffold.highlight(this.adapter.find('td').first().children()); }, - - reload: function() { - this.close(); - this.open(); - }, }); diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 5c0746cf6f..6cfafa1ef0 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -866,6 +866,11 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target.id, ActiveScaffold.config.scroll_on_close == 'checkInViewport'); }, + reload: function() { + this.close(); + this.open(); + }, + get_new_adapter_id: function() { var id = 'adapter_'; var i = 0; @@ -1025,11 +1030,6 @@ ActiveScaffold.ActionLink.Table = Class.create(ActiveScaffold.ActionLink.Abstrac } ActiveScaffold.highlight(this.adapter.down('td').down()); }, - - reload: function() { - this.close(); - this.open(); - }, }); if (Ajax.InPlaceEditor) { diff --git a/app/views/active_scaffold_overrides/on_create.js.erb b/app/views/active_scaffold_overrides/on_create.js.erb index 76ea9b0a00..70f7f4800a 100644 --- a/app/views/active_scaffold_overrides/on_create.js.erb +++ b/app/views/active_scaffold_overrides/on_create.js.erb @@ -22,7 +22,7 @@ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'mess <% unless render_parent? %> <% if (active_scaffold_config.create.persistent) %> - if (action_link.reload) action_link.reload(); + action_link.reload(); <% else %> action_link.close(); <% end %> From 640a0e6412b70d4d0130610418525b34e693ad78 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 8 Nov 2012 17:00:39 +0100 Subject: [PATCH 1747/2024] remove debugger --- lib/active_scaffold/actions/update.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index ad67de7d62..3dfd76df6d 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -72,7 +72,6 @@ def update_respond_to_yaml # A simple method to find and prepare a record for editing # May be overridden to customize the record (set default values, etc.) def do_edit - debugger @record = find_if_allowed(params[:id], :update) end From 0ec61d7a3f37d5c05925df045686ed42157c162b Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 8 Nov 2012 22:22:51 -1000 Subject: [PATCH 1748/2024] close dynamic group when click remote link --- app/assets/javascripts/jquery/active_scaffold.js | 3 +++ app/assets/javascripts/prototype/active_scaffold.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 3882aeeb2d..671ec58b1d 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -2,6 +2,9 @@ jQuery(document).ready(function() { jQuery(document).click(function(event) { jQuery('.action_group.dyn ul').remove(); }); + jQuery(document).on('ajax:beforeSend', '.action_group.dyn a', function() { + jQuery('.action_group.dyn ul').remove(); + }); jQuery('form.as_form').live('ajax:beforeSend', function(event) { var as_form = jQuery(this).closest("form"); if (as_form.attr('data-loading') == 'true') { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 6cfafa1ef0..e03313581b 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -15,6 +15,9 @@ document.observe("dom:loaded", function() { document.on('click', function(event) { $$('.action_group.dyn ul').invoke('remove'); }); + document.on('ajax:beforeSend', '.action_group.dyn a', function() { + $$('.action_group.dyn ul').invoke('remove'); + }); document.on('ajax:create', 'form.as_form', function(event) { var source = event.findElement(); var as_form = event.findElement('form'); From f82584db2a8e23ee68f7d3a5365e9d394e215e75 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 8 Nov 2012 22:43:34 -1000 Subject: [PATCH 1749/2024] close dynamic group and hide loading indicator on completing remote link --- app/assets/javascripts/jquery/active_scaffold.js | 6 ++++-- app/assets/javascripts/prototype/active_scaffold.js | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 671ec58b1d..b8fb092560 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -2,8 +2,10 @@ jQuery(document).ready(function() { jQuery(document).click(function(event) { jQuery('.action_group.dyn ul').remove(); }); - jQuery(document).on('ajax:beforeSend', '.action_group.dyn a', function() { - jQuery('.action_group.dyn ul').remove(); + jQuery(document).on('ajax:complete', '.action_group.dyn ul a', function(event) { + var action_link = ActiveScaffold.find_action_link(event.target); + if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden'); + jQuery(event.target).closest('.action_group.dyn ul').remove(); }); jQuery('form.as_form').live('ajax:beforeSend', function(event) { var as_form = jQuery(this).closest("form"); diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index e03313581b..872f12d20f 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -15,8 +15,11 @@ document.observe("dom:loaded", function() { document.on('click', function(event) { $$('.action_group.dyn ul').invoke('remove'); }); - document.on('ajax:beforeSend', '.action_group.dyn a', function() { - $$('.action_group.dyn ul').invoke('remove'); + document.on('ajax:complete', '.action_group.dyn ul a', function() { + var source = event.findElement(); + var action_link = ActiveScaffold.find_action_link(source); + if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden'); + $(source).up('.action_group.dyn ul').remove(); }); document.on('ajax:create', 'form.as_form', function(event) { var source = event.findElement(); From ca035d7507b09e5f8277025861d977f6d237d227 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Sat, 10 Nov 2012 00:24:44 +0100 Subject: [PATCH 1750/2024] fix refresh after update --- lib/active_scaffold/actions/update.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 3dfd76df6d..ae2a163c57 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -50,6 +50,7 @@ def update_respond_to_js if successful? if !render_parent? && active_scaffold_config.actions.include?(:list) if update_refresh_list? + params.delete(:id) # needed to get right list do_refresh_list else get_row From 9e06ba2db8b3b53db65e11bbbfacdf34965685da Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Sat, 10 Nov 2012 00:29:57 +0100 Subject: [PATCH 1751/2024] fix rendering refresh after update --- app/views/active_scaffold_overrides/on_update.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/on_update.js.erb b/app/views/active_scaffold_overrides/on_update.js.erb index c33d6932d2..3486e86ada 100644 --- a/app/views/active_scaffold_overrides/on_update.js.erb +++ b/app/views/active_scaffold_overrides/on_update.js.erb @@ -1,5 +1,5 @@ try { -<% form_selector = "#{element_form_id(:action => :update)}" %> +<% form_selector = "#{element_form_id(:action => :update, :id => @record.id)}" %> var action_link = ActiveScaffold.find_action_link('<%= form_selector %>'); action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'messages')) %>'); <% if controller.send :successful? %> From a0f865c3088e92db8bd2f2459ae6089e2b5474ca Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 13 Nov 2012 12:13:33 +0100 Subject: [PATCH 1752/2024] delete id on do_refresh_list --- lib/active_scaffold/actions/list.rb | 1 + lib/active_scaffold/actions/update.rb | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 23d88be71c..bc2ba3bc5a 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -96,6 +96,7 @@ def do_list end def do_refresh_list + params.delete(:id) do_search if respond_to? :do_search do_list end diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index ae2a163c57..3dfd76df6d 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -50,7 +50,6 @@ def update_respond_to_js if successful? if !render_parent? && active_scaffold_config.actions.include?(:list) if update_refresh_list? - params.delete(:id) # needed to get right list do_refresh_list else get_row From 3e6be98d7fd4cc2c710004b88102b13b193c13ce Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 14 Nov 2012 18:12:07 +0100 Subject: [PATCH 1753/2024] fix caching action links for namespaced controllers, fixes #211 --- lib/active_scaffold/data_structures/action_link.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index 9ad849d67f..ecd70387f0 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -184,7 +184,7 @@ def nested_link? end def name_to_cache_link_url - @name_to_cache_link_url ||= :"@#{controller || 'self'}_#{action}#{'_' if parameters.present?}#{parameters.map{|k,v| "#{k}_#{v}"}.join('_')}_link_url" + @name_to_cache_link_url ||= "@#{controller || 'self'}_#{action}#{'_' if parameters.present?}#{parameters.map{|k,v| "#{k}_#{v}"}.join('_')}_link_url".gsub('/', '_').to_sym end From 3e1ecc08c9d152274930f735941b35e33dac4976 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 14 Nov 2012 21:15:55 +0100 Subject: [PATCH 1754/2024] move hidden input out of ul --- lib/active_scaffold/helpers/form_column_helpers.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index cfd3b416b6..3db8135f46 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -169,8 +169,9 @@ def active_scaffold_input_plural_association(column, options) end def active_scaffold_checkbox_list(column, select_options, associated_ids, options) - html = content_tag :ul, :class => "#{options[:class]} checkbox-list", :id => options[:id] do - content = hidden_field_tag("#{options[:name]}[]", '') + html = hidden_field_tag("#{options[:name]}[]", '') + html << content_tag(:ul, :class => "#{options[:class]} checkbox-list", :id => options[:id]) do + content = ''.html_safe select_options.each_with_index do |option, i| label, id = option this_id = "#{options[:id]}_#{i}_id" From 1418b9548b155ce75b0d60b39896b445e304c150 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 15 Nov 2012 12:58:14 +0100 Subject: [PATCH 1755/2024] add class to dl in associated-record row (subgroups in subforms) --- .../_form_association_record.html.erb | 2 +- .../_form_attribute.html.erb | 2 +- .../helpers/form_column_helpers.rb | 16 +++++++++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/views/active_scaffold_overrides/_form_association_record.html.erb b/app/views/active_scaffold_overrides/_form_association_record.html.erb index 27d242b685..167f717e8d 100644 --- a/app/views/active_scaffold_overrides/_form_association_record.html.erb +++ b/app/views/active_scaffold_overrides/_form_association_record.html.erb @@ -63,7 +63,7 @@ <%= content_tag row_tag, :class => 'associated-record' do %> <%= content_tag column_tag, :colspan => columns_length do %> <% column.each :for => @record.class, :crud_type => :read, :flatten => true do |col| %> - <%= active_scaffold_render_subform_column(col, scope, crud_type, readonly) %> + <%= active_scaffold_render_subform_column(col, scope, crud_type, readonly, true) %> <% end %> <% end %> <% end %> diff --git a/app/views/active_scaffold_overrides/_form_attribute.html.erb b/app/views/active_scaffold_overrides/_form_attribute.html.erb index 09b6626908..1529e5ba1e 100644 --- a/app/views/active_scaffold_overrides/_form_attribute.html.erb +++ b/app/views/active_scaffold_overrides/_form_attribute.html.erb @@ -2,7 +2,7 @@ scope ||= nil column_options = active_scaffold_input_options(column, scope) %> -<dl> +<dl<%= " class=\"#{col_class}\"".html_safe if local_assigns[:col_class].present? %>> <dt> <label for="<%= column_options[:id] %>"><%= column.label %></label> </dt> diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 3db8135f46..c71d5d5580 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -59,11 +59,21 @@ def active_scaffold_render_input(column, options) end end - def active_scaffold_render_subform_column(column, scope, crud_type, readonly) + def active_scaffold_render_subform_column(column, scope, crud_type, readonly, add_class = false) + if add_class + col_class = [] + col_class << 'required' if column.required? + col_class << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) + col_class << 'hidden' if column_renders_as(column) == :hidden + col_class << 'checkbox' if column.form_ui == :checkbox + col_class = col_class.join(' ') + end unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) - render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope } + render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope, :col_class => col_class } else - content_tag :span, get_column_value(@record, column), active_scaffold_input_options(column, scope).except(:name) + options = active_scaffold_input_options(column, scope).except(:name) + options[:class] = "#{options[:class]} #{col_class}" if col_class + content_tag :span, get_column_value(@record, column), options end end From 7bfb70793a7c6762f2003b3325571c198cf774d1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 19 Nov 2012 14:09:32 +0100 Subject: [PATCH 1756/2024] use hash for caching action links urls, fixes #213 --- lib/active_scaffold/data_structures/action_link.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_link.rb b/lib/active_scaffold/data_structures/action_link.rb index ecd70387f0..d0d4388816 100644 --- a/lib/active_scaffold/data_structures/action_link.rb +++ b/lib/active_scaffold/data_structures/action_link.rb @@ -184,7 +184,7 @@ def nested_link? end def name_to_cache_link_url - @name_to_cache_link_url ||= "@#{controller || 'self'}_#{action}#{'_' if parameters.present?}#{parameters.map{|k,v| "#{k}_#{v}"}.join('_')}_link_url".gsub('/', '_').to_sym + @name_to_cache_link_url ||= :"#{controller || 'self'}_#{action}#{'_' if parameters.present?}#{parameters.map{|k,v| "#{k}_#{v}"}.join('_')}_link_url" end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 28327e10d7..ddf0b1f6ab 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -176,12 +176,12 @@ def column_link_authorized?(link, column, record, associated) end def action_link_url(link, record) - url = instance_variable_get(link.name_to_cache_link_url) + url = (@action_links_urls ||= {})[link.name_to_cache_link_url] url ||= begin url_options = action_link_url_options(link, record) if active_scaffold_config.cache_action_link_urls url = url_for(url_options) - instance_variable_set(link.name_to_cache_link_url, url) unless link.dynamic_parameters.is_a?(Proc) + @action_links_urls[link.name_to_cache_link_url] = url unless link.dynamic_parameters.is_a?(Proc) url else url_for(params_for(url_options)) From 4ab1811cbdeac474d6b8ed5caaaf2a336512907e Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 20 Nov 2012 17:25:54 +0100 Subject: [PATCH 1757/2024] different text for add existing and replace existing --- .../_form_association_footer.html.erb | 5 +++-- config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/locales/es.yml | 1 + config/locales/fr.yml | 1 + config/locales/hu.yml | 1 + config/locales/ja.yml | 1 + config/locales/ru.yml | 1 + 8 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/views/active_scaffold_overrides/_form_association_footer.html.erb b/app/views/active_scaffold_overrides/_form_association_footer.html.erb index ec09466ca9..66c09693ef 100644 --- a/app/views/active_scaffold_overrides/_form_association_footer.html.erb +++ b/app/views/active_scaffold_overrides/_form_association_footer.html.erb @@ -37,9 +37,10 @@ add_new_url = params_for(:action => 'edit_associated', :child_association => col <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "ActiveScaffold.record_select_onselect(#{edit_associated_url.to_json}, #{active_scaffold_id.to_json}, id);" -%> <% else -%> <% select_options = options_from_collection_for_select(sorted_association_options_find(column.association), :id, :to_label) - add_existing_id = "#{sub_form_id(:association => column.name)}-add-existing" %> + add_existing_id = "#{sub_form_id(:association => column.name)}-add-existing" + add_existing_label = column.plural_association? ? :add_existing : :replace_existing %> <%= select_tag 'associated_id', '<option value="">'.html_safe + as_(:_select_) + '</option>'.html_safe + select_options %> - <%= link_to as_(:add_existing), edit_associated_url, :id => add_existing_id, :remote => true, :class=> column.plural_association? ? 'as_add_existing' : 'as_replace_existing', :style => "display: none;" %> + <%= link_to as_(add_existing_label), edit_associated_url, :id => add_existing_id, :remote => true, :class=> "as_#{add_existing_label}", :style => "display: none;" %> <%= javascript_tag("ActiveScaffold.show('#{add_existing_id}');") %> <% end -%> <% end -%> diff --git a/config/locales/de.yml b/config/locales/de.yml index 140e79e232..dabd5fe043 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -50,6 +50,7 @@ de: refresh: 'Neu laden' remove: 'Entfernen' remove_file: 'Entferne oder Ersetze Datei' + replace_existing: 'Existierenden ersetzen' replace_with_new: 'Mit Neuer ersetzen' revisions_for_model: 'Revisionen für %{model}' reset: 'Zurücksetzen' diff --git a/config/locales/en.yml b/config/locales/en.yml index 7b89df8c78..0a860bffd7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -50,6 +50,7 @@ en: refresh: 'Refresh' remove: 'Remove' remove_file: 'Remove or Replace file' + replace_existing: 'Replace Existing' replace_with_new: 'Replace With New' revisions_for_model: 'Revisions for %{model}' reset: 'Reset' diff --git a/config/locales/es.yml b/config/locales/es.yml index 7b9c3cf0f4..c01b544358 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -52,6 +52,7 @@ es: refresh: 'Recargar' remove: 'Eliminar' remove_file: 'Eliminar o Reemplazar archivo' + replace_with_new: 'Reemplazar existente' replace_with_new: 'Reemplazar con Nuevo' revisions_for_model: 'Revisiones de %{model}' reset: 'Restaurar' diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 650ee66280..91d9d72d44 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -50,6 +50,7 @@ fr: refresh: 'Rafraîchir' remove: 'Supprimer' remove_file: 'Supprimer et remplacer le fichier' + replace_existing: 'Remplacer existant(e)' replace_with_new: 'Remplacer avec le nouveau' revisions_for_model: 'Révision pour %{model}' reset: 'Annuler' diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 3cfa1b66a4..7f1e0c415b 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -50,6 +50,7 @@ hu: refresh: 'Frissítés' remove: 'Törlés' remove_file: 'Fájl törlése, vagy cseréje' + replace_existing: 'Replace existing' replace_with_new: 'Csere újjal' revisions_for_model: '%{model} revíziói' reset: 'Alapállapot' diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 830d001e0d..6aa11f585f 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -50,6 +50,7 @@ ja: refresh: 'Refresh' # needed? remove: '削除' remove_file: 'ファイルを削除または置換' + replace_existing: 'Replace existing' replace_with_new: '新しいもので置換' revisions_for_model: 'Revisions for %{model}' # neede? reset: 'リセット' diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 410e368729..c64cd2461b 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -56,6 +56,7 @@ ru: refresh: 'Обновить' remove: 'Удалить' remove_file: 'Удалить или заменить файл' + replace_existing: 'Replace existing' replace_with_new: 'Заменить новым' revisions_for_model: '%{model}: редакции' reset: 'Сброс' From 59220edb1b7624a1a7b673ced9a6a83761dfe7aa Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 20 Nov 2012 17:44:45 +0100 Subject: [PATCH 1758/2024] fix spanish translation --- config/locales/es.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/es.yml b/config/locales/es.yml index c01b544358..6f7a63932a 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -52,7 +52,7 @@ es: refresh: 'Recargar' remove: 'Eliminar' remove_file: 'Eliminar o Reemplazar archivo' - replace_with_new: 'Reemplazar existente' + replace_existing: 'Reemplazar existente' replace_with_new: 'Reemplazar con Nuevo' revisions_for_model: 'Revisiones de %{model}' reset: 'Restaurar' From 7643f1a42b42c19c10a5cb0501ee15f5e3d92bd5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 21 Nov 2012 18:01:35 +0100 Subject: [PATCH 1759/2024] fix on_action_update default view --- app/views/active_scaffold_overrides/on_action_update.js.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/active_scaffold_overrides/on_action_update.js.erb b/app/views/active_scaffold_overrides/on_action_update.js.erb index ca54d17482..869c08e90b 100644 --- a/app/views/active_scaffold_overrides/on_action_update.js.erb +++ b/app/views/active_scaffold_overrides/on_action_update.js.erb @@ -2,15 +2,15 @@ <% if @record %> <%= render :partial => 'update_messages' %> <% row = escape_javascript(render(:partial => 'list_record', :locals => {:record => @record})) -%> - <% if @action_link.nil? || @action_link.position %> - ActiveScaffold.find_action_link('<%= element_row_id(:action => :list, :id => @record.id) %>').close('<%= row %>'); + <% if @action_link.try(:position) %> + ActiveScaffold.find_action_link('<%= element_form_id(:action => action_name) %>').close('<%= row %>'); <% else %> ActiveScaffold.update_row('<%= element_row_id(:action => :list, :id => @record.id) %>', '<%= row %>'); ActiveScaffold.scroll_to('<%= element_row_id(:action => :list, :id => @record.id) %>', true); <% end %> <%= render :partial => 'update_calculations', :formats => [:js] %> <% else %> - <% if @action_link.nil? || @action_link.position %> + <% if @action_link.try(:position) %> ActiveScaffold.find_action_link('<%= element_row_id(:action => action_name) %>').close(); <% end %> <%= render :partial => 'refresh_list' %> From 5addec4237fe8203201522ebc52d3fc6ecd8442f Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 21 Nov 2012 18:01:52 +0100 Subject: [PATCH 1760/2024] fix conditions_from_params for boolean columns --- lib/active_scaffold/actions/core.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index c73d5de258..4afe0d6217 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -159,10 +159,12 @@ def conditions_from_params @conditions_from_params ||= begin conditions = {} params.except(:controller, :action, :page, :sort, :sort_direction).each do |key, value| - next unless active_scaffold_config.model.columns_hash[key.to_s] - next if active_scaffold_constraints[key.to_sym] - next if nested? and nested.param_name == key.to_sym - conditions[key.to_sym] = value + column = active_scaffold_config.model.columns_hash[key.to_s] + key = key.to_sym + next unless column + next if active_scaffold_constraints[key] + next if nested? and nested.param_name == key + conditions[key] = column.type_cast(value) end conditions end From 9079f49ee618b1ce6e6d2e95806ce7291a05c1bf Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 22 Nov 2012 00:29:13 +0100 Subject: [PATCH 1761/2024] fix main_path_to_return for nested forms, and use nested.parent_id instead of old params[:parent_id] for id helpers --- lib/active_scaffold/helpers/controller_helpers.rb | 4 +++- lib/active_scaffold/helpers/id_helpers.rb | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index f68f1103b8..3eef53a5a8 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -27,9 +27,11 @@ def main_path_to_return if params[:return_to] params[:return_to] else + exclude_parameters = [:utf8, :associated_id] parameters = {} if params[:parent_scaffold] && nested? && nested.singular_association? parameters[:controller] = params[:parent_scaffold] + exclude_parameters.concat [nested.param_name, :association, :parent_scaffold] #parameters[:eid] = params[:parent_scaffold] # not neeeded anymore? end parameters.merge! nested.to_params if nested? @@ -39,7 +41,7 @@ def main_path_to_return end parameters[:action] = "index" parameters[:id] = nil - params_for(parameters).except(:parent_column, :parent_id, :associated_id, :utf8) + params_for(parameters).except(*exclude_parameters) end end diff --git a/lib/active_scaffold/helpers/id_helpers.rb b/lib/active_scaffold/helpers/id_helpers.rb index 280dbadab5..830ffc4774 100644 --- a/lib/active_scaffold/helpers/id_helpers.rb +++ b/lib/active_scaffold/helpers/id_helpers.rb @@ -58,14 +58,14 @@ def active_scaffold_column_header_id(column) def element_row_id(options = {}) options[:action] ||= params[:action] options[:id] ||= params[:id] - options[:id] ||= params[:parent_id] + options[:id] ||= nested.parent_id if nested? clean_id "#{options[:controller_id] || controller_id}-#{options[:action]}-#{options[:id]}-row" end def element_cell_id(options = {}) options[:action] ||= params[:action] options[:id] ||= params[:id] - options[:id] ||= params[:parent_id] + options[:id] ||= nested.parent_id if nested? options[:name] ||= params[:name] clean_id "#{controller_id}-#{options[:action]}-#{options[:id]}-#{options[:name]}-cell" end @@ -73,7 +73,7 @@ def element_cell_id(options = {}) def element_form_id(options = {}) options[:action] ||= params[:action] options[:id] ||= params[:id] - options[:id] ||= params[:parent_id] + options[:id] ||= nested.parent_id if nested? clean_id "#{controller_id}-#{options[:action]}-#{options[:id]}-form" end @@ -89,26 +89,26 @@ def loading_indicator_id(options = {}) def sub_section_id(options = {}) options[:id] ||= params[:id] - options[:id] ||= params[:parent_id] + options[:id] ||= nested.parent_id if nested? clean_id "#{controller_id}-#{options[:id]}-#{options[:sub_section]}-subsection" end def sub_form_id(options = {}) options[:id] ||= params[:id] - options[:id] ||= params[:parent_id] + options[:id] ||= nested.parent_id if nested? clean_id "#{controller_id}-#{options[:id]}-#{options[:association]}-subform" end def sub_form_list_id(options = {}) options[:id] ||= params[:id] - options[:id] ||= params[:parent_id] + options[:id] ||= nested.parent_id if nested? clean_id "#{controller_id}-#{options[:id]}-#{options[:association]}-subform-list" end def element_messages_id(options = {}) options[:action] ||= params[:action] options[:id] ||= params[:id] - options[:id] ||= params[:parent_id] + options[:id] ||= nested.parent_id if nested? clean_id "#{controller_id}-#{options[:action]}-#{options[:id]}-messages" end From 5905d627174bc8f40b50629f93d33c7d5095f123 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 23 Nov 2012 16:01:40 +0100 Subject: [PATCH 1762/2024] fix loading indicator for reset search --- app/assets/javascripts/jquery/active_scaffold.js | 1 + app/assets/javascripts/prototype/active_scaffold.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index b8fb092560..fed72d373f 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -958,6 +958,7 @@ ActiveScaffold.ActionLink = { // record action var target = parent.find('a.as_action'); var loading_indicator = parent.find('td.actions .loading-indicator'); + if (!loading_indicator.length) loading_indicator = element.parent().find('.loading-indicator'); new ActiveScaffold.Actions.Record(target, parent, loading_indicator); } else if (parent && parent.is('div')) { //table action diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 872f12d20f..5f99079469 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -833,7 +833,9 @@ ActiveScaffold.ActionLink = { if (parent && parent.nodeName.toUpperCase() == 'TD') { // record action parent = parent.up('tr.record') - new ActiveScaffold.Actions.Record(parent.select('a.as_action'), parent, parent.down('td.actions .loading-indicator')); + var loading_indicator = parent.down('td.actions .loading-indicator'); + if (!loading_indicator) loading_indicator = element.parent().find('.loading-indicator'); + new ActiveScaffold.Actions.Record(parent.select('a.as_action'), parent, loading_indicator); } else if (parent && parent.nodeName.toUpperCase() == 'DIV') { //table action new ActiveScaffold.Actions.Table(parent.select('a.as_action'), parent.up('div.active-scaffold').down('tbody.before-header'), parent.down('.loading-indicator')); From b6909d8b29f938beacedc13f6104e308475ab92e Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 28 Nov 2012 09:21:58 +0100 Subject: [PATCH 1763/2024] render field update subform columns using active_scaffold_render_subform_column --- app/views/active_scaffold_overrides/_render_field.js.erb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_render_field.js.erb b/app/views/active_scaffold_overrides/_render_field.js.erb index 49c901baf0..34a23d6ddb 100644 --- a/app/views/active_scaffold_overrides/_render_field.js.erb +++ b/app/views/active_scaffold_overrides/_render_field.js.erb @@ -13,9 +13,16 @@ else options = {:is_subform => false, :field_class => "#{column.name}-input"} end + html = if scope + readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) + crud_type = @record.new_record? ? :create : (readonly ? :read : :update) + active_scaffold_render_subform_column(column, scope, crud_type, readonly, !active_scaffold_config.subform.columns.names_without_auth_check.include?(column.name)) + else + render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope }) + end -%> -ActiveScaffold.render_form_field('<%= source_id %>','<%= escape_javascript(render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope })) %>', <%= options.to_json.html_safe %>); +ActiveScaffold.render_form_field('<%= source_id %>','<%= escape_javascript(html) %>', <%= options.to_json.html_safe %>); <%if column.update_columns && !column.update_columns.empty?%> <%= render(:partial => "render_field", :collection => column.update_columns, :locals => {:source_id => source_id, :scope => scope})%> <%end%> From 6b38c2f8926bda49ca10d78f90cc67aa267b1be5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 28 Nov 2012 12:15:01 +0100 Subject: [PATCH 1764/2024] use post for render_field, and allow to send only current row (in subforms) --- app/assets/javascripts/jquery/active_scaffold.js | 11 +++++++---- app/assets/javascripts/prototype/active_scaffold.js | 10 +++++++--- lib/active_scaffold/extensions/routing_mapper.rb | 4 ++-- lib/active_scaffold/helpers/form_column_helpers.rb | 4 ++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index fed72d373f..22b1485a41 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -850,11 +850,13 @@ var ActiveScaffold = { var params = null; if (send_form) { - var selector; + var selector, base = as_form; + if (send_form == 'row') base = element.closest('.association-record, form'); if (selector = element.data('update_send_form_selector')) - params = as_form.find(selector).serialize(); - else params = as_form.serialize(); - params += '&' + jQuery.param({"source_id": source_id}); + params = base.find(selector).serialize(); + else if (send_form != as_form) params = base.find(':input').serialize(); + else base.serialize(); + params += '&_method=&' + jQuery.param({"source_id": source_id}); } else { params = {value: val}; params.source_id = source_id; @@ -863,6 +865,7 @@ var ActiveScaffold = { jQuery.ajax({ url: url, data: params, + type: 'post', beforeSend: function(event) { element.nextAll('img.loading-indicator').css('visibility','visible'); ActiveScaffold.disable_form(as_form); diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 5f99079469..53499b6841 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -680,17 +680,21 @@ var ActiveScaffold = { var params = null; if (send_form) { - var selector; + var selector, base = as_form; + if (send_form == 'row') base = element.up('.association-record, form'); if (selector = element.readAttribute('data-update_send_form_selector')) - params = Form.serializeElements(as_form.getElementsBySelector(selector), true); + params = Form.serializeElements(base.getElementsBySelector(selector), true); + else if (base != as_form) + params = Form.serializeElements(base.getElementsBySelector('input, textarea, select'), true); else params = as_form.serialize(true); + params['_method'] = ''; } else { params = {value: val}; } params.source_id = source_id; new Ajax.Request(url, { - method: 'get', + method: 'post', parameters: params, onLoading: function(response) { element.next('img.loading-indicator').style.visibility = 'visible'; diff --git a/lib/active_scaffold/extensions/routing_mapper.rb b/lib/active_scaffold/extensions/routing_mapper.rb index 397cba4ad0..f30a479d96 100644 --- a/lib/active_scaffold/extensions/routing_mapper.rb +++ b/lib/active_scaffold/extensions/routing_mapper.rb @@ -1,8 +1,8 @@ module ActionDispatch module Routing ACTIVE_SCAFFOLD_CORE_ROUTING = { - :collection => {:show_search => :get, :render_field => :get, :mark => :post}, - :member => {:row => :get, :update_column => :post, :render_field => :get, :mark => :post} + :collection => {:show_search => :get, :render_field => :post, :mark => :post}, + :member => {:row => :get, :update_column => :post, :render_field => :post, :mark => :post} } ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = { :collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post}, diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index c71d5d5580..1b42e6a40d 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -112,7 +112,7 @@ def update_columns_options(column, scope, options) active_scaffold_config.send(@record.new_record? ? :create : :update) end if form_action && column.update_columns && (column.update_columns & form_action.columns.names).present? - url_params = {:action => 'render_field', :column => column.name} + url_params = {:action => 'render_field', :column => column.name, :id => nil} url_params[:id] = @record.id if column.send_form_on_update_column url_params[:eid] = params[:eid] if params[:eid] if scope @@ -122,7 +122,7 @@ def update_columns_options(column, scope, options) options[:class] = "#{options[:class]} update_form".strip options['data-update_url'] = url_for(url_params) - options['data-update_send_form'] = true if column.send_form_on_update_column + options['data-update_send_form'] = column.send_form_on_update_column options['data-update_send_form_selector'] = column.options[:send_form_selector] if column.options[:send_form_selector] end options From dc535b43b086c626dd5eeeac8d6528bce4b1a174 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 28 Nov 2012 23:28:26 +0100 Subject: [PATCH 1765/2024] move action_group code to a helper method, skip action_groups when all links are ignored --- .../_action_group.html.erb | 25 -------- .../_list_header.html.erb | 3 +- .../_list_record.html.erb | 7 +-- .../_update_actions.html.erb | 4 +- .../data_structures/action_links.rb | 41 ++---------- lib/active_scaffold/helpers/view_helpers.rb | 62 ++++++++++++++++++- 6 files changed, 69 insertions(+), 73 deletions(-) delete mode 100644 app/views/active_scaffold_overrides/_action_group.html.erb diff --git a/app/views/active_scaffold_overrides/_action_group.html.erb b/app/views/active_scaffold_overrides/_action_group.html.erb deleted file mode 100644 index 94da2dc664..0000000000 --- a/app/views/active_scaffold_overrides/_action_group.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<% record ||= nil - start_level_0_tag ||= '' - end_level_0_tag ||= ''%> -<% action_links.traverse(controller, traverse_options) do |parent, link, options| -%> - <% if (options[:node] == :finished_traversing) -%> - <%= "</ul>#{(options[:level] == 0 ? "</div>#{end_level_0_tag}": '</li>')}".html_safe %> - - <% elsif (options[:node] == :start_traversing) -%> - <% html_classes = hover_via_click? ? 'hover_click ' : '' %> - <% if options[:level] == 0 %> - <% html_classes << 'action_group' %> - <%= "#{start_level_0_tag}<div class=\"#{html_classes}\" #{"onclick=\"\"" if hover_via_click?}><div class=\"#{parent.name.to_s.downcase}\">#{as_(parent.name)}</div><ul>".html_safe %> - <% else %> - <% html_classes << 'top' if options[:first_action] %> - <%= "<li#{" class=\"#{html_classes}\"" unless html_classes.empty?}#{" onclick=\"\"" if hover_via_click?}><div class=\"#{parent.name.to_s.downcase}\">#{as_(parent.name)}</div><ul>".html_safe %> - <% end %> - - <% else -%> - <% if options[:level] == 0 %> - <%= "#{start_level_0_tag}#{render_action_link(link, record, options)}#{end_level_0_tag}".html_safe %> - <% else %> - <li<%= ' class="top"'.html_safe %>><%= render_action_link(link, record, options) %></li> - <% end %> - <% end -%> -<% end -%> diff --git a/app/views/active_scaffold_overrides/_list_header.html.erb b/app/views/active_scaffold_overrides/_list_header.html.erb index fc3136a080..a9a0bf614c 100644 --- a/app/views/active_scaffold_overrides/_list_header.html.erb +++ b/app/views/active_scaffold_overrides/_list_header.html.erb @@ -1,8 +1,7 @@ <% action_links = active_scaffold_config.action_links.collection unless action_links.empty? -%> <div class="actions"> - <%= render :partial => 'action_group', :locals => {:action_links => action_links, - :traverse_options => nested? ? {:reverse => true} : {}} %> + <%= display_action_links(action_links, nil, :skip_unauthorized => true, :reverse => nested?) %> <%= loading_indicator_tag(:action => :table) %> </div> <% end %> diff --git a/app/views/active_scaffold_overrides/_list_record.html.erb b/app/views/active_scaffold_overrides/_list_record.html.erb index 97341683d2..decb82d655 100644 --- a/app/views/active_scaffold_overrides/_list_record.html.erb +++ b/app/views/active_scaffold_overrides/_list_record.html.erb @@ -21,12 +21,7 @@ data_refresh ||= url_for(params_for(:action => :row, :id => '--ID--', :_method = <td class="indicator-container"> <%= loading_indicator_tag(:action => :record, :id => record.id) %> </td> - <%= render :partial => 'action_group', :locals => { :action_links => action_links, - :record => record, - :traverse_options => {:for => record.persisted? ? record : record.class}, - :start_level_0_tag => '<td>', - :end_level_0_tag => '</td>' - } %> + <%= display_action_links(action_links, record, :level_0_tag => :td, :for => record.persisted? ? record : record.class) %> </tr> </table></td> diff --git a/app/views/active_scaffold_overrides/_update_actions.html.erb b/app/views/active_scaffold_overrides/_update_actions.html.erb index 9598e17aca..def042480c 100644 --- a/app/views/active_scaffold_overrides/_update_actions.html.erb +++ b/app/views/active_scaffold_overrides/_update_actions.html.erb @@ -2,8 +2,8 @@ <div class="actions"> <% active_scaffold_config.action_links.member.each do |link| -%> <% next unless link.action == 'index' -%> - <% next if skip_action_link(link) -%> - <%= render_action_link(link, record, :authorized => record.authorized_for?(:crud_type => link.crud_type, :action => link.action)) -%> + <% next if skip_action_link?(link, record) || !action_link_authorized?(link, record) -%> + <%= render_action_link(link, record, :authorized => true) -%> <% end -%> </div> </div> diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index a6d1b33a69..ba342cc744 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -88,8 +88,9 @@ def delete_group(name) # iterates over the links, possibly by type def each(options = {}, &block) - @set.each {|item| - if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) + method = options[:reverse] ? :reverse_each : :each + @set.send(method) do |item| + if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) && !options[:groups] item.each(options, &block) else if options[:include_set] @@ -98,7 +99,7 @@ def each(options = {}, &block) yield item end end - } + end end def collect_by_type(type = nil) @@ -107,34 +108,6 @@ def collect_by_type(type = nil) links end - def traverse(controller, options = {}, &block) - traverse_method = options.delete(:reverse).nil? ? :each : :reverse_each - options[:level] ||= -1 - options[:level] += 1 - first_action = true - @set.send(traverse_method) do |link| - if link.is_a?(ActiveScaffold::DataStructures::ActionLinks) - unless link.empty? - yield(link, nil, {:node => :start_traversing, :first_action => first_action, :level => options[:level]}) - link.traverse(controller,options, &block) - yield(link, nil, {:node => :finished_traversing, :first_action => first_action, :level => options[:level]}) - first_action = false - end - elsif controller.nil? || !skip_action_link(controller, link, *(Array(options[:for]))) - security_method = link.security_method_set? || controller.respond_to?(link.security_method) - authorized = if security_method - controller.send(link.security_method, *(Array(options[:for]))) - else - options[:for].nil? ? true : options[:for].authorized_for?(:crud_type => link.crud_type, :action => link.action) - end - next unless authorized || link.type == :member - yield(self, link, {:authorized => authorized, :first_action => first_action, :level => options[:level]}) - first_action = false - end - end - options[:level] -= 1 - end - def collect @set end @@ -178,14 +151,10 @@ def #{name} protected - def skip_action_link(controller, link, *args) - !link.ignore_method.nil? && controller.respond_to?(link.ignore_method) && controller.send(link.ignore_method, *args) - end - # called during clone or dup. makes the clone/dup deeper. def initialize_copy(from) @set = [] from.instance_variable_get('@set').each { |link| @set << link.clone } end end -end \ No newline at end of file +end diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index ddf0b1f6ab..73e7413ca4 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -100,8 +100,66 @@ def link_to_visibility_toggle(id, options = {}) javascript_tag("ActiveScaffold.create_visibility_toggle('#{id}', #{options.to_json});") end - def skip_action_link(link, *args) - (!link.ignore_method.nil? && controller.respond_to?(link.ignore_method) && controller.send(link.ignore_method, *args)) || ((link.security_method_set? or controller.respond_to? link.security_method) and !controller.send(link.security_method, *args)) + def skip_action_link?(link, *args) + !link.ignore_method.nil? && controller.respond_to?(link.ignore_method) && controller.send(link.ignore_method, *args) + end + + def action_link_authorized?(link, *args) + security_method = link.security_method_set? || controller.respond_to?(link.security_method) + authorized = if security_method + controller.send(link.security_method, *args) + else + args.empty? ? true : args.first.authorized_for?(:crud_type => link.crud_type, :action => link.action) + end + end + + def display_action_links(action_links, record, options, &block) + options[:level_0_tag] ||= nil + options[:options_level_0_tag] ||= nil + options[:level] ||= 0 + options[:first_action] = true + output = ActiveSupport::SafeBuffer.new + + action_links.each(:reverse => options.delete(:reverse), :groups => true) do |link| + if link.is_a? ActiveScaffold::DataStructures::ActionLinks + unless link.empty? + options[:level] += 1 + content = display_action_links(link, record, options, &block) + options[:level] -= 1 + if content.present? + output << display_action_link(link, content, record, options) + options[:first_action] = false + end + end + elsif !skip_action_link?(link, *Array(options[:for])) + authorized = action_link_authorized?(link, *Array(options[:for])) + next if !authorized && options[:skip_unauthorized] + output << display_action_link(link, nil, record, options.merge(:authorized => authorized)) + options[:first_action] = false + end + end + output + end + + def display_action_link(link, content, record, options) + if content + html_classes = hover_via_click? ? 'hover_click ' : '' + if options[:level] == 0 + html_classes << 'action_group' + group_tag = :div + else + html_classes << 'top' if options[:first_action] + group_tag = :li + end + content = content_tag(group_tag, :class => (html_classes if html_classes.present?), :onclick => ('' if hover_via_click?)) do + content_tag(:div, as_(link.name), :class => link.name.to_s.downcase) << content_tag(:ul, content) + end + else + content = render_action_link(link, record, options) + content = content_tag(:li, content, :class => ('top' if options[:first_action])) unless options[:level] == 0 + end + content = content_tag(options[:level_0_tag], content, options[:options_level_0_tag]) if options[:level] == 0 && options[:level_0_tag] + content end def render_action_link(link, record = nil, options = {}) From bf09cf03c493f50987c9c62b4a67a5842f5cfb56 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 29 Nov 2012 20:53:12 +0100 Subject: [PATCH 1766/2024] add class to messages div --- app/views/active_scaffold_overrides/_list_messages.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_list_messages.html.erb b/app/views/active_scaffold_overrides/_list_messages.html.erb index 5428637f20..778313a5dd 100644 --- a/app/views/active_scaffold_overrides/_list_messages.html.erb +++ b/app/views/active_scaffold_overrides/_list_messages.html.erb @@ -6,7 +6,7 @@ <%= as_(:internal_error).html_safe %> <a href="#" class="close" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a> </p> - <div id="<%= active_scaffold_messages_id -%>"> + <div id="<%= active_scaffold_messages_id -%>" class="action-messages"> <%= render :partial => 'messages' %> </div> <div class="filtered-message" <%= ' style="display:none;" '.html_safe unless @filtered %>> From a2ce7855e460faf4985453ca8fc053449074de1b Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 29 Nov 2012 21:03:00 +0100 Subject: [PATCH 1767/2024] option to display messages above or below header --- .../active_scaffold_overrides/_list.html.erb | 17 +++++++++++++++++ .../_list_messages.html.erb | 2 ++ lib/active_scaffold/config/list.rb | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/app/views/active_scaffold_overrides/_list.html.erb b/app/views/active_scaffold_overrides/_list.html.erb index 1ee5a7cdb3..f2e09c0b9c 100644 --- a/app/views/active_scaffold_overrides/_list.html.erb +++ b/app/views/active_scaffold_overrides/_list.html.erb @@ -1,3 +1,20 @@ +<% if active_scaffold_config.list.messages_above_header %> +<table> + <tbody> + <tr> + <td class="messages-container"> + <p class="error-message message server-error" style="display:none;"> + <%= as_(:internal_error).html_safe %> + <a href="#" class="close" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a> + </p> + <div id="<%= active_scaffold_messages_id -%>" class="action-messages"> + <%= render :partial => 'messages' %> + </div> + </td> + </tr> + </tbody> +</table> +<% end %> <table cellpadding="0" cellspacing="0"> <thead> <tr> diff --git a/app/views/active_scaffold_overrides/_list_messages.html.erb b/app/views/active_scaffold_overrides/_list_messages.html.erb index 778313a5dd..6008b2c1d8 100644 --- a/app/views/active_scaffold_overrides/_list_messages.html.erb +++ b/app/views/active_scaffold_overrides/_list_messages.html.erb @@ -2,6 +2,7 @@ <tbody class="messages"> <tr class="record even-record"> <td colspan="<%= column_count -%>" class="messages-container"> +<% unless active_scaffold_config.list.messages_above_header %> <p class="error-message message server-error" style="display:none;"> <%= as_(:internal_error).html_safe %> <a href="#" class="close" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a> @@ -9,6 +10,7 @@ <div id="<%= active_scaffold_messages_id -%>" class="action-messages"> <%= render :partial => 'messages' %> </div> +<% end %> <div class="filtered-message" <%= ' style="display:none;" '.html_safe unless @filtered %>> <%= @filtered.is_a?(Array) ? render(:partial => 'human_conditions', :locals => {:columns => @filtered}) : as_(active_scaffold_config.list.filtered_message) %> <% if active_scaffold_config.list.show_search_reset && @filtered -%> diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index df55020cc6..5c57ab59be 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -23,6 +23,7 @@ def initialize(core_config) @wrap_tag = self.class.wrap_tag @always_show_search = self.class.always_show_search @always_show_create = self.class.always_show_create + @messages_above_header = self.class.messages_above_header end # global level configuration @@ -43,6 +44,10 @@ def initialize(core_config) cattr_accessor :empty_field_text @@empty_field_text = '-' + # display messages above table header + cattr_accessor :messages_above_header + @@messages_above_header = false + # what string to use to join records from plural associations cattr_accessor :association_join_text @@association_join_text = ', ' @@ -104,6 +109,9 @@ def columns # what string to use when a field is empty attr_accessor :empty_field_text + # display messages above table header + attr_accessor :messages_above_header + # what string to use to join records from plural associations attr_accessor :association_join_text From 4430cf2bd5923480df4259445ff47908a08a0181 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 29 Nov 2012 23:04:05 +0100 Subject: [PATCH 1768/2024] callbacks for removing events, so effects can be added, and use as:element_created instead of as:element_updated for new elements --- .../javascripts/jquery/active_scaffold.js | 31 ++++++++++--------- .../javascripts/prototype/active_scaffold.js | 27 +++++++++------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 22b1485a41..96f2cfe5d7 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -443,9 +443,10 @@ var ActiveScaffold = { return element; }, - remove: function(element) { + remove: function(element, callback) { if (typeof(element) == 'string') element = '#' + element; jQuery(element).remove(); + if (callback) callback(); }, update_inplace_edit: function(element, value, empty) { @@ -524,7 +525,7 @@ var ActiveScaffold = { this.stripe(tbody); this.hide_empty_message(tbody); this.increment_record_count(tbody.closest('div.active-scaffold')); - ActiveScaffold.highlight(new_row); + this.highlight(new_row); }, create_record_row_from_url: function(active_scaffold_id, url, options) { @@ -547,10 +548,11 @@ var ActiveScaffold = { } } - row.remove(); - this.stripe(tbody); - this.decrement_record_count(tbody.closest('div.active-scaffold')); - this.reload_if_empty(tbody, page_reload_url); + ActiveScaffold.remove(row, function() { + ActiveScaffold.stripe(tbody); + ActiveScaffold.decrement_record_count(tbody.closest('div.active-scaffold')); + ActiveScaffold.reload_if_empty(tbody, page_reload_url); + }); }, delete_subform_record: function(record) { @@ -667,7 +669,7 @@ var ActiveScaffold = { if (options.singular == false) { if (!(options.id && jQuery('#' + options.id).size() > 0)) { var new_element = element.append(content); - content.trigger('as:element_updated'); + content.trigger('as:element_created'); } } else { var current = jQuery('#' + element.attr('id') + ' .association-record') @@ -675,7 +677,7 @@ var ActiveScaffold = { this.replace(current[0], content); } else { element.prepend(content); - content.trigger('as:element_updated'); + content.trigger('as:element_created'); } } }, @@ -999,10 +1001,12 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ }, close: function() { - this.enable(); - this.adapter.remove(); - if (this.hide_target) this.target.show(); - if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target.attr('id'), ActiveScaffold.config.scroll_on_close == 'checkInViewport'); + var link = this; + ActiveScaffold.remove(this.adapter, function() { + link.enable(); + if (link.hide_target) link.target.show(); + if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(link.target.attr('id'), ActiveScaffold.config.scroll_on_close == 'checkInViewport'); + }); }, reload: function() { @@ -1075,8 +1079,7 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ var _this = this; jQuery.each(this.set.links, function(index, item) { if (item.url != _this.url && item.is_disabled() && !item.keep_open() && item.adapter) { - item.enable(); - item.adapter.remove(); + ActiveScaffold.remove(item.adapter, function () { item.enable(); }); } }); }, diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 53499b6841..3a78a994d8 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -401,8 +401,9 @@ var ActiveScaffold = { return element; }, - remove: function(element) { + remove: function(element, callback) { $(element).remove(); + if (callback) callback(); }, update_inplace_edit: function(element, value, empty) { @@ -500,11 +501,12 @@ var ActiveScaffold = { action_link.close_previous_adapter(); } } - row.remove(); - tbody = $(tbody); - this.stripe(tbody); - this.decrement_record_count(tbody.up('div.active-scaffold')); - this.reload_if_empty(tbody, page_reload_url); + ActiveScaffold.remove(row, function() { + tbody = $(tbody); + ActiveScaffold.stripe(tbody); + ActiveScaffold.decrement_record_count(tbody.up('div.active-scaffold')); + ActiveScaffold.reload_if_empty(tbody, page_reload_url); + }); }, delete_subform_record: function(record) { @@ -872,10 +874,12 @@ ActiveScaffold.ActionLink.Abstract = Class.create({ }, close: function() { - this.enable(); - this.adapter.remove(); - if (this.hide_target) this.target.show(); - if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(this.target.id, ActiveScaffold.config.scroll_on_close == 'checkInViewport'); + var link = this; + ActiveScaffold.remove(this.adapter, function() { + link.enable(); + if (link.hide_target) link.target.show(); + if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(link.target.id, ActiveScaffold.config.scroll_on_close == 'checkInViewport'); + }); }, reload: function() { @@ -947,8 +951,7 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra close_previous_adapter: function() { this.set.links.each(function(item) { if (item.url != this.url && item.is_disabled() && !item.keep_open() && item.adapter) { - item.enable(); - item.adapter.remove(); + ActiveScaffold.remove(item.adapter, function () { item.enable(); }); } }.bind(this)); }, From 60e27fe492d00fc69caa52531aff4ccd911a7e13 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 30 Nov 2012 17:36:09 +0100 Subject: [PATCH 1769/2024] allow to override options for select in non-assocation columns --- lib/active_scaffold/helpers/form_column_helpers.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 1b42e6a40d..117afea392 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -200,10 +200,14 @@ def active_scaffold_translated_option(column, text, value = nil) value = text if value.nil? [(text.is_a?(Symbol) ? column.active_record_class.human_attribute_name(text) : text), value] end + + def active_scaffold_enum_options(column) + column.options[:options] + end def active_scaffold_input_enum(column, html_options) options = { :selected => @record.send(column.name) } - options_for_select = column.options[:options].collect do |text, value| + options_for_select = active_scaffold_enum_options(column).collect do |text, value| active_scaffold_translated_option(column, text, value) end html_options.update(column.options[:html_options] || {}) From e0c1b6de1bf90abe13d60d28ee89444a074452d5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 3 Dec 2012 20:24:48 +0100 Subject: [PATCH 1770/2024] fix route and security checks for inplace edit fields --- lib/active_scaffold/actions/core.rb | 4 ++-- lib/active_scaffold/extensions/routing_mapper.rb | 2 +- lib/active_scaffold/finder.rb | 8 +++++--- lib/active_scaffold/helpers/list_column_helpers.rb | 5 ++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 4afe0d6217..06e044e547 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -11,7 +11,7 @@ def self.included(base) base.helper_method :new_model end def render_field - if params[:in_place_editing] + if request.get? render_field_for_inplace_editing else render_field_for_update_columns @@ -28,7 +28,7 @@ def nested? end def render_field_for_inplace_editing - @record = find_if_allowed(params[:id], :update) + @record = find_if_allowed(params[:id], :crud_type => :update, :column => params[:update_column]) render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>" end diff --git a/lib/active_scaffold/extensions/routing_mapper.rb b/lib/active_scaffold/extensions/routing_mapper.rb index f30a479d96..b93eae272e 100644 --- a/lib/active_scaffold/extensions/routing_mapper.rb +++ b/lib/active_scaffold/extensions/routing_mapper.rb @@ -2,7 +2,7 @@ module ActionDispatch module Routing ACTIVE_SCAFFOLD_CORE_ROUTING = { :collection => {:show_search => :get, :render_field => :post, :mark => :post}, - :member => {:row => :get, :update_column => :post, :render_field => :post, :mark => :post} + :member => {:row => :get, :update_column => :post, :render_field => [:get, :post], :mark => :post} } ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = { :collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post}, diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index a190cce3d9..a4066ce563 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -275,12 +275,14 @@ def all_conditions ] end - # returns a single record (the given id) but only if it's allowed for the specified action. + # returns a single record (the given id) but only if it's allowed for the specified security options. + # security options can be a hash for authorized_for? method or a value to check as a :crud_type # accomplishes this by checking model.#{action}_authorized? # TODO: this should reside on the model, not the controller - def find_if_allowed(id, crud_type, klass = beginning_of_chain) + def find_if_allowed(id, security_options, klass = beginning_of_chain) record = klass.find(id) - raise ActiveScaffold::RecordNotAllowed, "#{klass} with id = #{id}" unless record.authorized_for?(:crud_type => crud_type.to_sym) + security_options = {:crud_type => security_options.to_sym} unless security_options.is_a? Hash + raise ActiveScaffold::RecordNotAllowed, "#{klass} with id = #{id}" unless record.authorized_for? security_options return record end # valid options may include: diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 972bdddda7..5f7484b0d5 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -201,8 +201,7 @@ def cache_association(value, column, size) def inplace_edit?(record, column) if column.inplace_edit editable = controller.send(:update_authorized?, record) if controller.respond_to?(:update_authorized?) - editable = record.authorized_for?(:crud_type => :update, :column => column.name) if editable.nil? || editable == true - editable + editable ||= record.authorized_for?(:crud_type => :update, :column => column.name) end end @@ -253,7 +252,7 @@ def inplace_edit_data(column) elsif inplace_edit_cloning?(column) data[:ie_mode] = :clone elsif column.inplace_edit == :ajax - url = url_for(:controller => params_for[:controller], :action => 'render_field', :id => '__id__', :column => column.name, :update_column => column.name, :in_place_editing => true) + url = url_for(:controller => params_for[:controller], :action => 'render_field', :id => '__id__', :update_column => column.name) plural = column.plural_association? && !override_form_field?(column) && [:select, :record_select].include?(column.form_ui) data[:ie_render_url] = url data[:ie_mode] = :ajax From 343ebf114eba5251b5489031356ef652ce4deb0f Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 3 Dec 2012 20:46:31 +0100 Subject: [PATCH 1771/2024] add skip_groups option to ActionColumns#each --- lib/active_scaffold/data_structures/action_columns.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index f4092dd2e5..faa970d3a0 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -66,8 +66,12 @@ def each(options = {}, &proc) item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class)) next if self.skip_column?(item, options) end - if item.is_a? ActiveScaffold::DataStructures::ActionColumns and options.has_key?(:flatten) and options[:flatten] - item.each(options, &proc) + if item.is_a? ActiveScaffold::DataStructures::ActionColumns + if options[:flatten] + item.each(options, &proc) + elsif !options[:skip_groups] + yield item + end else yield item end From f2c909b77d69e3a54140d2c1805fe00f6b78e73f Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 4 Dec 2012 09:07:04 +0100 Subject: [PATCH 1772/2024] update JS code, disable form on submit for normal forms too --- .../javascripts/jquery/active_scaffold.js | 85 +++++++++---------- .../javascripts/prototype/active_scaffold.js | 2 +- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 96f2cfe5d7..f47e33ec5e 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -7,34 +7,34 @@ jQuery(document).ready(function() { if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden'); jQuery(event.target).closest('.action_group.dyn ul').remove(); }); - jQuery('form.as_form').live('ajax:beforeSend', function(event) { + jQuery(document).on('ajax:beforeSend', 'form.as_form', function(event) { var as_form = jQuery(this).closest("form"); - if (as_form.attr('data-loading') == 'true') { + if (as_form.data('loading') == true) { ActiveScaffold.disable_form(as_form); } return true; }); - jQuery('form.as_form').live('ajax:complete', function(event) { + jQuery(document).on('ajax:complete', 'form.as_form', function(event) { var as_form = jQuery(this).closest("form"); - if (as_form.attr('data-loading') == 'true') { + if (as_form.data('loading') == true) { ActiveScaffold.enable_form(as_form); } }); - jQuery('form.as_form').live('ajax:error', function(event, xhr, status, error) { + jQuery(document).on('ajax:error', 'form.as_form', function(event, xhr, status, error) { var as_div = jQuery(this).closest("div.active-scaffold"); if (as_div.length) { ActiveScaffold.report_500_response(as_div); } }); - jQuery('form.as_form.as_remote_upload').live('submit', function(event) { + jQuery(document).on('submit', 'form.as_form:not([data-remote])', function(event) { var as_form = jQuery(this).closest("form"); - if (as_form.attr('data-loading') == 'true') { + if (as_form.data('loading') == true) { setTimeout("ActiveScaffold.disable_form('" + as_form.attr('id') + "')", 10); } return true; }); - jQuery('a.as_action').live('ajax:before', function(event) { + jQuery(document).on('ajax:before', 'a.as_action', function(event) { var action_link = ActiveScaffold.ActionLink.get(jQuery(this)); if (action_link) { if (action_link.is_disabled()) { @@ -46,7 +46,7 @@ jQuery(document).ready(function() { } return true; }); - jQuery('a.as_action').live('ajax:success', function(event, response) { + jQuery(document).on('ajax:success', 'a.as_action', function(event, response) { var action_link = ActiveScaffold.ActionLink.get(jQuery(this)); if (action_link) { if (action_link.position) { @@ -59,14 +59,14 @@ jQuery(document).ready(function() { } return true; }); - jQuery('a.as_action').live('ajax:complete', function(event) { + jQuery(document).on('ajax:complete', 'a.as_action', function(event) { var action_link = ActiveScaffold.ActionLink.get(jQuery(this)); if (action_link) { if (action_link.loading_indicator) action_link.loading_indicator.css('visibility','hidden'); } return true; }); - jQuery('a.as_action').live('ajax:error', function(event, xhr, status, error) { + jQuery(document).on('ajax:error', 'a.as_action', function(event, xhr, status, error) { var action_link = ActiveScaffold.ActionLink.get(jQuery(this)); if (action_link) { ActiveScaffold.report_500_response(action_link.scaffold_id()); @@ -74,7 +74,7 @@ jQuery(document).ready(function() { } return true; }); - jQuery('a.as_cancel').live('ajax:before', function(event) { + jQuery(document).on('ajax:before', 'a.as_cancel', function(event) { var as_cancel = jQuery(this); var action_link = ActiveScaffold.find_action_link(as_cancel); @@ -88,7 +88,7 @@ jQuery(document).ready(function() { } return true; }); - jQuery('a.as_cancel').live('ajax:success', function(event, response) { + jQuery(document).on('ajax:success', 'a.as_cancel', function(event, response) { var action_link = ActiveScaffold.find_action_link(jQuery(this)); if (action_link) { @@ -100,28 +100,27 @@ jQuery(document).ready(function() { } return true; }); - jQuery('a.as_cancel').live('ajax:error', function(event, xhr, status, error) { + jQuery(document).on('ajax:error', 'a.as_cancel', function(event, xhr, status, error) { var action_link = ActiveScaffold.find_action_link(jQuery(this)); if (action_link) { ActiveScaffold.report_500_response(action_link.scaffold_id()); } return true; }); - jQuery('a.as_sort').live('ajax:before', function(event) { + jQuery(document).on('ajax:before', 'a.as_sort', function(event) { var as_sort = jQuery(this); - var history_controller_id = as_sort.attr('data-page-history'); + var history_controller_id = as_sort.data('page-history'); if (history_controller_id) addActiveScaffoldPageToHistory(as_sort.attr('href'), history_controller_id); as_sort.closest('th').addClass('loading'); return true; }); - jQuery('a.as_sort').live('ajax:error', function(event, xhr, status, error) { + jQuery(document).on('ajax:error', 'a.as_sort', function(event, xhr, status, error) { var as_scaffold = jQuery(this).closest('.active-scaffold'); ActiveScaffold.report_500_response(as_scaffold); return true; }); - jQuery('td.in_place_editor_field').live('hover', function(event) { + jQuery(document).on('hover', 'td.in_place_editor_field', function(event) { var td = jQuery(this), span = td.find('span.in_place_editor_field'); - span.data(); // $ 1.4.2 workaround if (event.type == 'mouseenter') { if (td.hasClass('empty') || typeof(span.data('editInPlace')) === 'undefined') td.find('span').addClass("hover"); } @@ -130,30 +129,30 @@ jQuery(document).ready(function() { } return true; }); - jQuery('td.in_place_editor_field, th.as_marked-column_heading').live('click', function(event) { + jQuery(document).on('click', 'td.in_place_editor_field, th.as_marked-column_heading', function(event) { var span = jQuery(this).find('span.in_place_editor_field'); span.data('addEmptyOnCancel', jQuery(this).hasClass('empty')); jQuery(this).removeClass('empty'); if (span.data('editInPlace')) span.trigger('click.editInPlace'); else ActiveScaffold.in_place_editor_field_clicked(span); }); - jQuery('a.as_paginate').live('ajax:before',function(event) { + jQuery(document).on('ajax:before', 'a.as_paginate',function(event) { var as_paginate = jQuery(this); - var history_controller_id = as_paginate.attr('data-page-history'); + var history_controller_id = as_paginate.data('page-history'); if (history_controller_id) addActiveScaffoldPageToHistory(as_paginate.attr('href'), history_controller_id); as_paginate.prevAll('img.loading-indicator').css('visibility','visible'); return true; }); - jQuery('a.as_paginate').live('ajax:error', function(event, xhr, status, error) { + jQuery(document).on('ajax:error', 'a.as_paginate', function(event, xhr, status, error) { var as_scaffold = jQuery(this).closest('.active-scaffold'); ActiveScaffold.report_500_response(as_scaffold); return true; }); - jQuery('a.as_paginate').live('ajax:complete', function(event) { + jQuery(document).on('ajax:complete', 'a.as_paginate', function(event) { jQuery(this).prevAll('img.loading-indicator').css('visibility','hidden'); return true; }); - jQuery('a.as_add_existing, a.as_replace_existing').live('ajax:before', function(event) { + jQuery(document).on('ajax:before', 'a.as_add_existing, a.as_replace_existing', function(event) { var id = jQuery(this).prev().val(); if (id) { if (!jQuery(this).data('href')) jQuery(this).data('href', jQuery(this).attr('href')); @@ -161,26 +160,26 @@ jQuery(document).ready(function() { return true; } else return false; }); - jQuery('input.update_form:not(.recordselect), textarea.update_form, select.update_form').live('change', function(event) { + jQuery(document).on('change', 'input.update_form:not(.recordselect), textarea.update_form, select.update_form', function(event) { var element = jQuery(this); var value = element.is("input:checkbox:not(:checked)") ? null : element.val(); - ActiveScaffold.update_column(element, element.attr('data-update_url'), element.attr('data-update_send_form'), element.attr('id'), value); + ActiveScaffold.update_column(element, element.data('update_url'), element.data('update_send_form'), element.attr('id'), value); return true; }); - jQuery('input.recordselect.update_form').live('recordselect:change', function(event, id, label) { + jQuery(document).on('recordselect:change', 'input.recordselect.update_form', function(event, id, label) { var element = jQuery(this); - ActiveScaffold.update_column(element, element.attr('data-update_url'), element.attr('data-update_send_form'), element.attr('id'), id); + ActiveScaffold.update_column(element, element.data('update_url'), element.data('update_send_form'), element.attr('id'), id); return true; }); - jQuery('select.as_search_range_option').live('change', function(event) { + jQuery(document).on('change', 'select.as_search_range_option', function(event) { var element = jQuery(this); ActiveScaffold[element.val() == 'BETWEEN' ? 'show' : 'hide'](element.closest('dd').find('.as_search_range_between')); ActiveScaffold[(element.val() == 'null' || element.val() == 'not_null') ? 'hide' : 'show'](element.attr('id').replace(/_opt/, '_numeric')); return true; }); - jQuery('select.as_search_date_time_option').live('change', function(event) { + jQuery(document).on('change', 'select.as_search_date_time_option', function(event) { var element = jQuery(this); ActiveScaffold[!(element.val() == 'PAST' || element.val() == 'FUTURE' || element.val() == 'RANGE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_numeric')); ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend')); @@ -188,18 +187,18 @@ jQuery(document).ready(function() { return true; }); - jQuery('select.as_update_date_operator').live('change', function(event) { + jQuery(document).on('change', 'select.as_update_date_operator', function(event) { ActiveScaffold[jQuery(this).val() == 'REPLACE' ? 'show' : 'hide'](jQuery(this).next()); ActiveScaffold[jQuery(this).val() == 'REPLACE' ? 'hide' : 'show'](jQuery(this).next().next()); return true; }); - jQuery('a[data-popup]').live('click', function(e) { + jQuery(document).on('click', 'a[data-popup]', function(e) { window.open(jQuery(this).attr('href')); e.preventDefault(); }); - jQuery('.hover_click').live("click", function(event) { + jQuery(document).on("click", '.hover_click', function(event) { var element = jQuery(this); var ul_element = element.children('ul').first(); if (ul_element.is(':visible')) { @@ -209,7 +208,7 @@ jQuery(document).ready(function() { } return false; }); - jQuery('.hover_click a.as_action').live('click', function(event) { + jQuery(document).on('click', '.hover_click a.as_action', function(event) { var element = jQuery(this).closest('.hover_click'); if (element) { element.find('ul').hide(); @@ -217,7 +216,7 @@ jQuery(document).ready(function() { return true; }); - jQuery('.message a.close').live('click', function(e) { + jQuery(document).on('click', '.message a.close', function(e) { ActiveScaffold.hide(jQuery(this).closest('.message')); e.preventDefault(); }); @@ -476,6 +475,7 @@ var ActiveScaffold = { var loading_indicator = jQuery('#' + as_form.attr('id').replace(/-form$/, '-loading-indicator')); if (!skip_loading_indicator && loading_indicator) loading_indicator.css('visibility','visible'); jQuery('input[type=submit]', as_form).attr('disabled', 'disabled'); + // data-remote-disabled attr instead of set data because is used to in selector later jQuery("input:enabled,select:enabled,textarea:enabled", as_form).attr('disabled', 'disabled').attr('data-remove-disabled', true); }, @@ -752,7 +752,6 @@ var ActiveScaffold = { }, in_place_editor_field_clicked: function(span) { - span.data(); // $ 1.4.2 workaround // test editor is open if (typeof(span.data('editInPlace')) === 'undefined') { var options = {show_buttons: true, @@ -799,11 +798,11 @@ var ActiveScaffold = { if (csrf_param) options['params'] = csrf_param.attr('content') + '=' + csrf_token.attr('content'); - if (span.closest('div.active-scaffold').attr('data-eid')) { + if (span.closest('div.active-scaffold').data('eid')) { if (options['params'].length > 0) { options['params'] += "&"; } - options['params'] += ("eid=" + span.closest('div.active-scaffold').attr('data-eid')); + options['params'] += ("eid=" + span.closest('div.active-scaffold').data('eid')); } if (mode === 'clone') { @@ -981,12 +980,12 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ init: function(a, target, loading_indicator) { this.tag = jQuery(a); this.url = this.tag.attr('href'); - this.method = this.tag.attr('data-method') || 'get'; + this.method = this.tag.data('method') || 'get'; this.target = target; this.loading_indicator = loading_indicator; this.hide_target = false; - this.position = this.tag.attr('data-position'); - this.action = this.tag.attr('data-action'); + this.position = this.tag.data('position'); + this.action = this.tag.data('action'); this.tag.data('action_link', this); return this; @@ -1062,7 +1061,7 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ ActiveScaffold.Actions.Record = ActiveScaffold.Actions.Abstract.extend({ instantiate_link: function(link) { var l = new ActiveScaffold.ActionLink.Record(link, this.target, this.loading_indicator); - var refresh = this.target.attr('data-refresh'); + var refresh = this.target.data('refresh'); if (refresh) l.refresh_url = refresh; if (l.position) { diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 3a78a994d8..c396b1b680 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -51,7 +51,7 @@ document.observe("dom:loaded", function() { return false; } }); - document.on('submit', 'form.as_form.as_remote_upload', function(event) { + document.on('submit', 'form.as_form:not([data-remote])', function(event) { var as_form = event.findElement('form'); if (as_form && as_form.readAttribute('data-loading') == 'true') { setTimeout("ActiveScaffold.disable_form('" + as_form.readAttribute('id') + "')", 10); From 827319a470a80d5ee1c32e15732b57cfd7bb0abe Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 5 Dec 2012 06:10:10 -1000 Subject: [PATCH 1773/2024] update jquery timepicker --- .../javascripts/jquery-ui-timepicker-addon.js | 3158 ++++++++++------- 1 file changed, 1882 insertions(+), 1276 deletions(-) diff --git a/vendor/assets/javascripts/jquery-ui-timepicker-addon.js b/vendor/assets/javascripts/jquery-ui-timepicker-addon.js index d72c481d5e..5a0f59821c 100644 --- a/vendor/assets/javascripts/jquery-ui-timepicker-addon.js +++ b/vendor/assets/javascripts/jquery-ui-timepicker-addon.js @@ -1,1276 +1,1882 @@ -/* -* jQuery timepicker addon -* By: Trent Richardson [http://trentrichardson.com] -* Version 0.9.7 -* Last Modified: 10/02/2011 -* -* Copyright 2011 Trent Richardson -* Dual licensed under the MIT and GPL licenses. -* http://trentrichardson.com/Impromptu/GPL-LICENSE.txt -* http://trentrichardson.com/Impromptu/MIT-LICENSE.txt -* -* HERES THE CSS: -* .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; } -* .ui-timepicker-div dl { text-align: left; } -* .ui-timepicker-div dl dt { height: 25px; } -* .ui-timepicker-div dl dd { margin: -25px 10px 10px 65px; } -* .ui-timepicker-div td { font-size: 90%; } -* .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; } -*/ - -(function($) { - -$.extend($.ui, { timepicker: { version: "0.9.7" } }); - -/* Time picker manager. - Use the singleton instance of this class, $.timepicker, to interact with the time picker. - Settings for (groups of) time pickers are maintained in an instance object, - allowing multiple different settings on the same page. */ - -function Timepicker() { - this.regional = []; // Available regional settings, indexed by language code - this.regional[''] = { // Default regional settings - currentText: 'Now', - closeText: 'Done', - ampm: false, - amNames: ['AM', 'A'], - pmNames: ['PM', 'P'], - timeFormat: 'hh:mm tt', - timeSuffix: '', - timeOnlyTitle: 'Choose Time', - timeText: 'Time', - hourText: 'Hour', - minuteText: 'Minute', - secondText: 'Second', - millisecText: 'Millisecond', - timezoneText: 'Time Zone' - }; - this._defaults = { // Global defaults for all the datetime picker instances - showButtonPanel: true, - timeOnly: false, - showHour: true, - showMinute: true, - showSecond: false, - showMillisec: false, - showTimezone: false, - showTime: true, - stepHour: 0.05, - stepMinute: 0.05, - stepSecond: 0.05, - stepMillisec: 0.5, - hour: 0, - minute: 0, - second: 0, - millisec: 0, - timezone: '+0000', - hourMin: 0, - minuteMin: 0, - secondMin: 0, - millisecMin: 0, - hourMax: 23, - minuteMax: 59, - secondMax: 59, - millisecMax: 999, - minDateTime: null, - maxDateTime: null, - onSelect: null, - hourGrid: 0, - minuteGrid: 0, - secondGrid: 0, - millisecGrid: 0, - alwaysSetTime: true, - separator: ' ', - altFieldTimeOnly: true, - showTimepicker: true, - timezoneIso8609: false, - timezoneList: null - }; - $.extend(this._defaults, this.regional['']); -} - -$.extend(Timepicker.prototype, { - $input: null, - $altInput: null, - $timeObj: null, - inst: null, - hour_slider: null, - minute_slider: null, - second_slider: null, - millisec_slider: null, - timezone_select: null, - hour: 0, - minute: 0, - second: 0, - millisec: 0, - timezone: '+0000', - hourMinOriginal: null, - minuteMinOriginal: null, - secondMinOriginal: null, - millisecMinOriginal: null, - hourMaxOriginal: null, - minuteMaxOriginal: null, - secondMaxOriginal: null, - millisecMaxOriginal: null, - ampm: '', - formattedDate: '', - formattedTime: '', - formattedDateTime: '', - timezoneList: null, - - /* Override the default settings for all instances of the time picker. - @param settings object - the new settings to use as defaults (anonymous object) - @return the manager object */ - setDefaults: function(settings) { - extendRemove(this._defaults, settings || {}); - return this; - }, - - //######################################################################## - // Create a new Timepicker instance - //######################################################################## - _newInst: function($input, o) { - var tp_inst = new Timepicker(), - inlineSettings = {}; - - for (var attrName in this._defaults) { - var attrValue = $input.attr('time:' + attrName); - if (attrValue) { - try { - inlineSettings[attrName] = eval(attrValue); - } catch (err) { - inlineSettings[attrName] = attrValue; - } - } - } - tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, { - beforeShow: function(input, dp_inst) { - if ($.isFunction(o.beforeShow)) - o.beforeShow(input, dp_inst, tp_inst); - }, - onChangeMonthYear: function(year, month, dp_inst) { - // Update the time as well : this prevents the time from disappearing from the $input field. - tp_inst._updateDateTime(dp_inst); - if ($.isFunction(o.onChangeMonthYear)) - o.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst); - }, - onClose: function(dateText, dp_inst) { - if (tp_inst.timeDefined === true && $input.val() != '') - tp_inst._updateDateTime(dp_inst); - if ($.isFunction(o.onClose)) - o.onClose.call($input[0], dateText, dp_inst, tp_inst); - }, - timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); - }); - tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { return val.toUpperCase() }); - tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { return val.toUpperCase() }); - - if (tp_inst._defaults.timezoneList === null) { - var timezoneList = []; - for (var i = -11; i <= 12; i++) - timezoneList.push((i >= 0 ? '+' : '-') + ('0' + Math.abs(i).toString()).slice(-2) + '00'); - if (tp_inst._defaults.timezoneIso8609) - timezoneList = $.map(timezoneList, function(val) { - return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3)); - }); - tp_inst._defaults.timezoneList = timezoneList; - } - - tp_inst.hour = tp_inst._defaults.hour; - tp_inst.minute = tp_inst._defaults.minute; - tp_inst.second = tp_inst._defaults.second; - tp_inst.millisec = tp_inst._defaults.millisec; - tp_inst.ampm = ''; - tp_inst.$input = $input; - - if (o.altField) - tp_inst.$altInput = $(o.altField) - .css({ cursor: 'pointer' }) - .focus(function(){ $input.trigger("focus"); }); - - if(tp_inst._defaults.minDate==0 || tp_inst._defaults.minDateTime==0) - { - tp_inst._defaults.minDate=new Date(); - } - if(tp_inst._defaults.maxDate==0 || tp_inst._defaults.maxDateTime==0) - { - tp_inst._defaults.maxDate=new Date(); - } - - // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime.. - if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) - tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime()); - if(tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date) - tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime()); - if(tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date) - tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime()); - if(tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) - tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime()); - return tp_inst; - }, - - //######################################################################## - // add our sliders to the calendar - //######################################################################## - _addTimePicker: function(dp_inst) { - var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? - this.$input.val() + ' ' + this.$altInput.val() : - this.$input.val(); - - this.timeDefined = this._parseTime(currDT); - this._limitMinMaxDateTime(dp_inst, false); - this._injectTimePicker(); - }, - - //######################################################################## - // parse the time string from input value or _setTime - //######################################################################## - _parseTime: function(timeString, withDate) { - var regstr = this._defaults.timeFormat.toString() - .replace(/h{1,2}/ig, '(\\d?\\d)') - .replace(/m{1,2}/ig, '(\\d?\\d)') - .replace(/s{1,2}/ig, '(\\d?\\d)') - .replace(/l{1}/ig, '(\\d?\\d?\\d)') - .replace(/t{1,2}/ig, this._getPatternAmpm()) - .replace(/z{1}/ig, '(z|[-+]\\d\\d:?\\d\\d)?') - .replace(/\s/g, '\\s?') + this._defaults.timeSuffix + '$', - order = this._getFormatPositions(), - ampm = '', - treg; - - if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]); - - if (withDate || !this._defaults.timeOnly) { - // the time should come after x number of characters and a space. - // x = at least the length of text specified by the date format - var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat'); - // escape special regex characters in the seperator - var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); - regstr = '.{' + dp_dateFormat.length + ',}' + this._defaults.separator.replace(specials, "\\$&") + regstr; - } - - treg = timeString.match(new RegExp(regstr, 'i')); - - if (treg) { - if (order.t !== -1) { - if (treg[order.t] === undefined || treg[order.t].length === 0) { - ampm = ''; - this.ampm = ''; - } else { - ampm = $.inArray(treg[order.t].toUpperCase(), this.amNames) !== -1 ? 'AM' : 'PM'; - this.ampm = this._defaults[ampm == 'AM' ? 'amNames' : 'pmNames'][0]; - } - } - - if (order.h !== -1) { - if (ampm == 'AM' && treg[order.h] == '12') - this.hour = 0; // 12am = 0 hour - else if (ampm == 'PM' && treg[order.h] != '12') - this.hour = (parseFloat(treg[order.h]) + 12).toFixed(0); // 12pm = 12 hour, any other pm = hour + 12 - else this.hour = Number(treg[order.h]); - } - - if (order.m !== -1) this.minute = Number(treg[order.m]); - if (order.s !== -1) this.second = Number(treg[order.s]); - if (order.l !== -1) this.millisec = Number(treg[order.l]); - if (order.z !== -1 && treg[order.z] !== undefined) { - var tz = treg[order.z].toUpperCase(); - switch (tz.length) { - case 1: // Z - tz = this._defaults.timezoneIso8609 ? 'Z' : '+0000'; - break; - case 5: // +hhmm - if (this._defaults.timezoneIso8609) - tz = tz.substring(1) == '0000' - ? 'Z' - : tz.substring(0, 3) + ':' + tz.substring(3); - break; - case 6: // +hh:mm - if (!this._defaults.timezoneIso8609) - tz = tz == 'Z' || tz.substring(1) == '00:00' - ? '+0000' - : tz.replace(/:/, ''); - else if (tz.substring(1) == '00:00') - tz = 'Z'; - break; - } - this.timezone = tz; - } - - return true; - - } - return false; - }, - - //######################################################################## - // pattern for standard and localized AM/PM markers - //######################################################################## - _getPatternAmpm: function() { - var markers = []; - o = this._defaults; - if (o.amNames) - $.merge(markers, o.amNames); - if (o.pmNames) - $.merge(markers, o.pmNames); - markers = $.map(markers, function(val) { return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&') }); - return '(' + markers.join('|') + ')?'; - }, - - //######################################################################## - // figure out position of time elements.. cause js cant do named captures - //######################################################################## - _getFormatPositions: function() { - var finds = this._defaults.timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z)/g), - orders = { h: -1, m: -1, s: -1, l: -1, t: -1, z: -1 }; - - if (finds) - for (var i = 0; i < finds.length; i++) - if (orders[finds[i].toString().charAt(0)] == -1) - orders[finds[i].toString().charAt(0)] = i + 1; - - return orders; - }, - - //######################################################################## - // generate and inject html for timepicker into ui datepicker - //######################################################################## - _injectTimePicker: function() { - var $dp = this.inst.dpDiv, - o = this._defaults, - tp_inst = this, - // Added by Peter Medeiros: - // - Figure out what the hour/minute/second max should be based on the step values. - // - Example: if stepMinute is 15, then minMax is 45. - hourMax = (o.hourMax - ((o.hourMax - o.hourMin) % o.stepHour)).toFixed(0), - minMax = (o.minuteMax - ((o.minuteMax - o.minuteMin) % o.stepMinute)).toFixed(0), - secMax = (o.secondMax - ((o.secondMax - o.secondMin) % o.stepSecond)).toFixed(0), - millisecMax = (o.millisecMax - ((o.millisecMax - o.millisecMin) % o.stepMillisec)).toFixed(0), - dp_id = this.inst.id.toString().replace(/([^A-Za-z0-9_])/g, ''); - - // Prevent displaying twice - //if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0) { - if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0 && o.showTimepicker) { - var noDisplay = ' style="display:none;"', - html = '<div class="ui-timepicker-div" id="ui-timepicker-div-' + dp_id + '"><dl>' + - '<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_' + dp_id + '"' + - ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' + - '<dd class="ui_tpicker_time" id="ui_tpicker_time_' + dp_id + '"' + - ((o.showTime) ? '' : noDisplay) + '></dd>' + - '<dt class="ui_tpicker_hour_label" id="ui_tpicker_hour_label_' + dp_id + '"' + - ((o.showHour) ? '' : noDisplay) + '>' + o.hourText + '</dt>', - hourGridSize = 0, - minuteGridSize = 0, - secondGridSize = 0, - millisecGridSize = 0, - size; - - // Hours - if (o.showHour && o.hourGrid > 0) { - html += '<dd class="ui_tpicker_hour">' + - '<div id="ui_tpicker_hour_' + dp_id + '"' + ((o.showHour) ? '' : noDisplay) + '></div>' + - '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>'; - - for (var h = o.hourMin; h <= hourMax; h += parseInt(o.hourGrid,10)) { - hourGridSize++; - var tmph = (o.ampm && h > 12) ? h-12 : h; - if (tmph < 10) tmph = '0' + tmph; - if (o.ampm) { - if (h == 0) tmph = 12 +'a'; - else if (h < 12) tmph += 'a'; - else tmph += 'p'; - } - html += '<td>' + tmph + '</td>'; - } - - html += '</tr></table></div>' + - '</dd>'; - } else html += '<dd class="ui_tpicker_hour" id="ui_tpicker_hour_' + dp_id + '"' + - ((o.showHour) ? '' : noDisplay) + '></dd>'; - - html += '<dt class="ui_tpicker_minute_label" id="ui_tpicker_minute_label_' + dp_id + '"' + - ((o.showMinute) ? '' : noDisplay) + '>' + o.minuteText + '</dt>'; - - // Minutes - if (o.showMinute && o.minuteGrid > 0) { - html += '<dd class="ui_tpicker_minute ui_tpicker_minute_' + o.minuteGrid + '">' + - '<div id="ui_tpicker_minute_' + dp_id + '"' + - ((o.showMinute) ? '' : noDisplay) + '></div>' + - '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>'; - - for (var m = o.minuteMin; m <= minMax; m += parseInt(o.minuteGrid,10)) { - minuteGridSize++; - html += '<td>' + ((m < 10) ? '0' : '') + m + '</td>'; - } - - html += '</tr></table></div>' + - '</dd>'; - } else html += '<dd class="ui_tpicker_minute" id="ui_tpicker_minute_' + dp_id + '"' + - ((o.showMinute) ? '' : noDisplay) + '></dd>'; - - // Seconds - html += '<dt class="ui_tpicker_second_label" id="ui_tpicker_second_label_' + dp_id + '"' + - ((o.showSecond) ? '' : noDisplay) + '>' + o.secondText + '</dt>'; - - if (o.showSecond && o.secondGrid > 0) { - html += '<dd class="ui_tpicker_second ui_tpicker_second_' + o.secondGrid + '">' + - '<div id="ui_tpicker_second_' + dp_id + '"' + - ((o.showSecond) ? '' : noDisplay) + '></div>' + - '<div style="padding-left: 1px"><table><tr>'; - - for (var s = o.secondMin; s <= secMax; s += parseInt(o.secondGrid,10)) { - secondGridSize++; - html += '<td>' + ((s < 10) ? '0' : '') + s + '</td>'; - } - - html += '</tr></table></div>' + - '</dd>'; - } else html += '<dd class="ui_tpicker_second" id="ui_tpicker_second_' + dp_id + '"' + - ((o.showSecond) ? '' : noDisplay) + '></dd>'; - - // Milliseconds - html += '<dt class="ui_tpicker_millisec_label" id="ui_tpicker_millisec_label_' + dp_id + '"' + - ((o.showMillisec) ? '' : noDisplay) + '>' + o.millisecText + '</dt>'; - - if (o.showMillisec && o.millisecGrid > 0) { - html += '<dd class="ui_tpicker_millisec ui_tpicker_millisec_' + o.millisecGrid + '">' + - '<div id="ui_tpicker_millisec_' + dp_id + '"' + - ((o.showMillisec) ? '' : noDisplay) + '></div>' + - '<div style="padding-left: 1px"><table><tr>'; - - for (var l = o.millisecMin; l <= millisecMax; l += parseInt(o.millisecGrid,10)) { - millisecGridSize++; - html += '<td>' + ((l < 10) ? '0' : '') + s + '</td>'; - } - - html += '</tr></table></div>' + - '</dd>'; - } else html += '<dd class="ui_tpicker_millisec" id="ui_tpicker_millisec_' + dp_id + '"' + - ((o.showMillisec) ? '' : noDisplay) + '></dd>'; - - // Timezone - html += '<dt class="ui_tpicker_timezone_label" id="ui_tpicker_timezone_label_' + dp_id + '"' + - ((o.showTimezone) ? '' : noDisplay) + '>' + o.timezoneText + '</dt>'; - html += '<dd class="ui_tpicker_timezone" id="ui_tpicker_timezone_' + dp_id + '"' + - ((o.showTimezone) ? '' : noDisplay) + '></dd>'; - - html += '</dl></div>'; - $tp = $(html); - - // if we only want time picker... - if (o.timeOnly === true) { - $tp.prepend( - '<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' + - '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' + - '</div>'); - $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide(); - } - - this.hour_slider = $tp.find('#ui_tpicker_hour_'+ dp_id).slider({ - orientation: "horizontal", - value: this.hour, - min: o.hourMin, - max: hourMax, - step: o.stepHour, - slide: function(event, ui) { - tp_inst.hour_slider.slider( "option", "value", ui.value); - tp_inst._onTimeChange(); - } - }); - - // Updated by Peter Medeiros: - // - Pass in Event and UI instance into slide function - this.minute_slider = $tp.find('#ui_tpicker_minute_'+ dp_id).slider({ - orientation: "horizontal", - value: this.minute, - min: o.minuteMin, - max: minMax, - step: o.stepMinute, - slide: function(event, ui) { - // update the global minute slider instance value with the current slider value - tp_inst.minute_slider.slider( "option", "value", ui.value); - tp_inst._onTimeChange(); - } - }); - - this.second_slider = $tp.find('#ui_tpicker_second_'+ dp_id).slider({ - orientation: "horizontal", - value: this.second, - min: o.secondMin, - max: secMax, - step: o.stepSecond, - slide: function(event, ui) { - tp_inst.second_slider.slider( "option", "value", ui.value); - tp_inst._onTimeChange(); - } - }); - - this.millisec_slider = $tp.find('#ui_tpicker_millisec_'+ dp_id).slider({ - orientation: "horizontal", - value: this.millisec, - min: o.millisecMin, - max: millisecMax, - step: o.stepMillisec, - slide: function(event, ui) { - tp_inst.millisec_slider.slider( "option", "value", ui.value); - tp_inst._onTimeChange(); - } - }); - - this.timezone_select = $tp.find('#ui_tpicker_timezone_'+ dp_id).append('<select></select>').find("select"); - $.fn.append.apply(this.timezone_select, - $.map(o.timezoneList, function(val, idx) { - return $("<option />") - .val(typeof val == "object" ? val.value : val) - .text(typeof val == "object" ? val.label : val); - }) - ); - this.timezone_select.val((typeof this.timezone != "undefined" && this.timezone != null && this.timezone != "") ? this.timezone : o.timezone); - this.timezone_select.change(function() { - tp_inst._onTimeChange(); - }); - - // Add grid functionality - if (o.showHour && o.hourGrid > 0) { - size = 100 * hourGridSize * o.hourGrid / (hourMax - o.hourMin); - - $tp.find(".ui_tpicker_hour table").css({ - width: size + "%", - marginLeft: (size / (-2 * hourGridSize)) + "%", - borderCollapse: 'collapse' - }).find("td").each( function(index) { - $(this).click(function() { - var h = $(this).html(); - if(o.ampm) { - var ap = h.substring(2).toLowerCase(), - aph = parseInt(h.substring(0,2), 10); - if (ap == 'a') { - if (aph == 12) h = 0; - else h = aph; - } else if (aph == 12) h = 12; - else h = aph + 12; - } - tp_inst.hour_slider.slider("option", "value", h); - tp_inst._onTimeChange(); - tp_inst._onSelectHandler(); - }).css({ - cursor: 'pointer', - width: (100 / hourGridSize) + '%', - textAlign: 'center', - overflow: 'hidden' - }); - }); - } - - if (o.showMinute && o.minuteGrid > 0) { - size = 100 * minuteGridSize * o.minuteGrid / (minMax - o.minuteMin); - $tp.find(".ui_tpicker_minute table").css({ - width: size + "%", - marginLeft: (size / (-2 * minuteGridSize)) + "%", - borderCollapse: 'collapse' - }).find("td").each(function(index) { - $(this).click(function() { - tp_inst.minute_slider.slider("option", "value", $(this).html()); - tp_inst._onTimeChange(); - tp_inst._onSelectHandler(); - }).css({ - cursor: 'pointer', - width: (100 / minuteGridSize) + '%', - textAlign: 'center', - overflow: 'hidden' - }); - }); - } - - if (o.showSecond && o.secondGrid > 0) { - $tp.find(".ui_tpicker_second table").css({ - width: size + "%", - marginLeft: (size / (-2 * secondGridSize)) + "%", - borderCollapse: 'collapse' - }).find("td").each(function(index) { - $(this).click(function() { - tp_inst.second_slider.slider("option", "value", $(this).html()); - tp_inst._onTimeChange(); - tp_inst._onSelectHandler(); - }).css({ - cursor: 'pointer', - width: (100 / secondGridSize) + '%', - textAlign: 'center', - overflow: 'hidden' - }); - }); - } - - if (o.showMillisec && o.millisecGrid > 0) { - $tp.find(".ui_tpicker_millisec table").css({ - width: size + "%", - marginLeft: (size / (-2 * millisecGridSize)) + "%", - borderCollapse: 'collapse' - }).find("td").each(function(index) { - $(this).click(function() { - tp_inst.millisec_slider.slider("option", "value", $(this).html()); - tp_inst._onTimeChange(); - tp_inst._onSelectHandler(); - }).css({ - cursor: 'pointer', - width: (100 / millisecGridSize) + '%', - textAlign: 'center', - overflow: 'hidden' - }); - }); - } - - var $buttonPanel = $dp.find('.ui-datepicker-buttonpane'); - if ($buttonPanel.length) $buttonPanel.before($tp); - else $dp.append($tp); - - this.$timeObj = $tp.find('#ui_tpicker_time_'+ dp_id); - - if (this.inst !== null) { - var timeDefined = this.timeDefined; - this._onTimeChange(); - this.timeDefined = timeDefined; - } - - //Emulate datepicker onSelect behavior. Call on slidestop. - var onSelectDelegate = function() { - tp_inst._onSelectHandler(); - }; - this.hour_slider.bind('slidestop',onSelectDelegate); - this.minute_slider.bind('slidestop',onSelectDelegate); - this.second_slider.bind('slidestop',onSelectDelegate); - this.millisec_slider.bind('slidestop',onSelectDelegate); - } - }, - - //######################################################################## - // This function tries to limit the ability to go outside the - // min/max date range - //######################################################################## - _limitMinMaxDateTime: function(dp_inst, adjustSliders){ - var o = this._defaults, - dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay); - - if(!this._defaults.showTimepicker) return; // No time so nothing to check here - - if($.datepicker._get(dp_inst, 'minDateTime') !== null && $.datepicker._get(dp_inst, 'minDateTime') !== undefined && dp_date){ - var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'), - minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0); - - if(this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null || this.millisecMinOriginal === null){ - this.hourMinOriginal = o.hourMin; - this.minuteMinOriginal = o.minuteMin; - this.secondMinOriginal = o.secondMin; - this.millisecMinOriginal = o.millisecMin; - } - - if(dp_inst.settings.timeOnly || minDateTimeDate.getTime() == dp_date.getTime()) { - this._defaults.hourMin = minDateTime.getHours(); - if (this.hour <= this._defaults.hourMin) { - this.hour = this._defaults.hourMin; - this._defaults.minuteMin = minDateTime.getMinutes(); - if (this.minute <= this._defaults.minuteMin) { - this.minute = this._defaults.minuteMin; - this._defaults.secondMin = minDateTime.getSeconds(); - } else if (this.second <= this._defaults.secondMin){ - this.second = this._defaults.secondMin; - this._defaults.millisecMin = minDateTime.getMilliseconds(); - } else { - if(this.millisec < this._defaults.millisecMin) - this.millisec = this._defaults.millisecMin; - this._defaults.millisecMin = this.millisecMinOriginal; - } - } else { - this._defaults.minuteMin = this.minuteMinOriginal; - this._defaults.secondMin = this.secondMinOriginal; - this._defaults.millisecMin = this.millisecMinOriginal; - } - }else{ - this._defaults.hourMin = this.hourMinOriginal; - this._defaults.minuteMin = this.minuteMinOriginal; - this._defaults.secondMin = this.secondMinOriginal; - this._defaults.millisecMin = this.millisecMinOriginal; - } - } - - if($.datepicker._get(dp_inst, 'maxDateTime') !== null && $.datepicker._get(dp_inst, 'maxDateTime') !== undefined && dp_date){ - var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'), - maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0); - - if(this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null){ - this.hourMaxOriginal = o.hourMax; - this.minuteMaxOriginal = o.minuteMax; - this.secondMaxOriginal = o.secondMax; - this.millisecMaxOriginal = o.millisecMax; - } - - if(dp_inst.settings.timeOnly || maxDateTimeDate.getTime() == dp_date.getTime()){ - this._defaults.hourMax = maxDateTime.getHours(); - if (this.hour >= this._defaults.hourMax) { - this.hour = this._defaults.hourMax; - this._defaults.minuteMax = maxDateTime.getMinutes(); - if (this.minute >= this._defaults.minuteMax) { - this.minute = this._defaults.minuteMax; - this._defaults.secondMax = maxDateTime.getSeconds(); - } else if (this.second >= this._defaults.secondMax) { - this.second = this._defaults.secondMax; - this._defaults.millisecMax = maxDateTime.getMilliseconds(); - } else { - if(this.millisec > this._defaults.millisecMax) this.millisec = this._defaults.millisecMax; - this._defaults.millisecMax = this.millisecMaxOriginal; - } - } else { - this._defaults.minuteMax = this.minuteMaxOriginal; - this._defaults.secondMax = this.secondMaxOriginal; - this._defaults.millisecMax = this.millisecMaxOriginal; - } - }else{ - this._defaults.hourMax = this.hourMaxOriginal; - this._defaults.minuteMax = this.minuteMaxOriginal; - this._defaults.secondMax = this.secondMaxOriginal; - this._defaults.millisecMax = this.millisecMaxOriginal; - } - } - - if(adjustSliders !== undefined && adjustSliders === true){ - var hourMax = (this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)).toFixed(0), - minMax = (this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)).toFixed(0), - secMax = (this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)).toFixed(0), - millisecMax = (this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)).toFixed(0); - - if(this.hour_slider) - this.hour_slider.slider("option", { min: this._defaults.hourMin, max: hourMax }).slider('value', this.hour); - if(this.minute_slider) - this.minute_slider.slider("option", { min: this._defaults.minuteMin, max: minMax }).slider('value', this.minute); - if(this.second_slider) - this.second_slider.slider("option", { min: this._defaults.secondMin, max: secMax }).slider('value', this.second); - if(this.millisec_slider) - this.millisec_slider.slider("option", { min: this._defaults.millisecMin, max: millisecMax }).slider('value', this.millisec); - } - - }, - - - //######################################################################## - // when a slider moves, set the internal time... - // on time change is also called when the time is updated in the text field - //######################################################################## - _onTimeChange: function() { - var hour = (this.hour_slider) ? this.hour_slider.slider('value') : false, - minute = (this.minute_slider) ? this.minute_slider.slider('value') : false, - second = (this.second_slider) ? this.second_slider.slider('value') : false, - millisec = (this.millisec_slider) ? this.millisec_slider.slider('value') : false, - timezone = (this.timezone_select) ? this.timezone_select.val() : false, - o = this._defaults; - - if (typeof(hour) == 'object') hour = false; - if (typeof(minute) == 'object') minute = false; - if (typeof(second) == 'object') second = false; - if (typeof(millisec) == 'object') millisec = false; - if (typeof(timezone) == 'object') timezone = false; - - if (hour !== false) hour = parseInt(hour,10); - if (minute !== false) minute = parseInt(minute,10); - if (second !== false) second = parseInt(second,10); - if (millisec !== false) millisec = parseInt(millisec,10); - - var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0]; - - // If the update was done in the input field, the input field should not be updated. - // If the update was done using the sliders, update the input field. - var hasChanged = (hour != this.hour || minute != this.minute - || second != this.second || millisec != this.millisec - || (this.ampm.length > 0 - && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) - || timezone != this.timezone); - - if (hasChanged) { - - if (hour !== false)this.hour = hour; - if (minute !== false) this.minute = minute; - if (second !== false) this.second = second; - if (millisec !== false) this.millisec = millisec; - if (timezone !== false) this.timezone = timezone; - - if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]); - - this._limitMinMaxDateTime(this.inst, true); - } - if (o.ampm) this.ampm = ampm; - - this._formatTime(); - if (this.$timeObj) this.$timeObj.text(this.formattedTime + o.timeSuffix); - this.timeDefined = true; - if (hasChanged) this._updateDateTime(); - }, - - //######################################################################## - // call custom onSelect. - // bind to sliders slidestop, and grid click. - //######################################################################## - _onSelectHandler: function() { - var onSelect = this._defaults.onSelect; - var inputEl = this.$input ? this.$input[0] : null; - if (onSelect && inputEl) { - onSelect.apply(inputEl, [this.formattedDateTime, this]); - } - }, - - //######################################################################## - // format the time all pretty... - //######################################################################## - _formatTime: function(time, format, ampm) { - if (ampm == undefined) ampm = this._defaults.ampm; - time = time || { hour: this.hour, minute: this.minute, second: this.second, millisec: this.millisec, ampm: this.ampm, timezone: this.timezone }; - var tmptime = (format || this._defaults.timeFormat).toString(); - - var hour = parseInt(time.hour, 10); - if (ampm) { - if (!$.inArray(time.ampm.toUpperCase(), this.amNames) !== -1) - hour = hour % 12; - if (hour === 0) - hour = 12; - } - tmptime = tmptime.replace(/(?:hh?|mm?|ss?|[tT]{1,2}|[lz])/g, function(match) { - switch (match.toLowerCase()) { - case 'hh': return ('0' + hour).slice(-2); - case 'h': return hour; - case 'mm': return ('0' + time.minute).slice(-2); - case 'm': return time.minute; - case 'ss': return ('0' + time.second).slice(-2); - case 's': return time.second; - case 'l': return ('00' + time.millisec).slice(-3); - case 'z': return time.timezone; - case 't': case 'tt': - if (ampm) { - var _ampm = time.ampm; - if (match.length == 1) - _ampm = _ampm.charAt(0); - return match.charAt(0) == 'T' ? _ampm.toUpperCase() : _ampm.toLowerCase(); - } - return ''; - } - }); - - if (arguments.length) return tmptime; - else this.formattedTime = tmptime; - }, - - //######################################################################## - // update our input with the new date time.. - //######################################################################## - _updateDateTime: function(dp_inst) { - dp_inst = this.inst || dp_inst, - dt = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay), - dateFmt = $.datepicker._get(dp_inst, 'dateFormat'), - formatCfg = $.datepicker._getFormatConfig(dp_inst), - timeAvailable = dt !== null && this.timeDefined; - this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg); - var formattedDateTime = this.formattedDate; - if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0)) - return; - - if (this._defaults.timeOnly === true) { - formattedDateTime = this.formattedTime; - } else if (this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) { - formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix; - } - - this.formattedDateTime = formattedDateTime; - - if(!this._defaults.showTimepicker) { - this.$input.val(this.formattedDate); - } else if (this.$altInput && this._defaults.altFieldTimeOnly === true) { - this.$altInput.val(this.formattedTime); - this.$input.val(this.formattedDate); - } else if(this.$altInput) { - this.$altInput.val(formattedDateTime); - this.$input.val(formattedDateTime); - } else { - this.$input.val(formattedDateTime); - } - - this.$input.trigger("change"); - } - -}); - -$.fn.extend({ - //######################################################################## - // shorthand just to use timepicker.. - //######################################################################## - timepicker: function(o) { - o = o || {}; - var tmp_args = arguments; - - if (typeof o == 'object') tmp_args[0] = $.extend(o, { timeOnly: true }); - - return $(this).each(function() { - $.fn.datetimepicker.apply($(this), tmp_args); - }); - }, - - //######################################################################## - // extend timepicker to datepicker - //######################################################################## - datetimepicker: function(o) { - o = o || {}; - var $input = this, - tmp_args = arguments; - - if (typeof(o) == 'string'){ - if(o == 'getDate') - return $.fn.datepicker.apply($(this[0]), tmp_args); - else - return this.each(function() { - var $t = $(this); - $t.datepicker.apply($t, tmp_args); - }); - } - else - return this.each(function() { - var $t = $(this); - $t.datepicker($.timepicker._newInst($t, o)._defaults); - }); - } -}); - -//######################################################################## -// the bad hack :/ override datepicker so it doesnt close on select -// inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378 -//######################################################################## -$.datepicker._base_selectDate = $.datepicker._selectDate; -$.datepicker._selectDate = function (id, dateStr) { - var inst = this._getInst($(id)[0]), - tp_inst = this._get(inst, 'timepicker'); - - if (tp_inst) { - tp_inst._limitMinMaxDateTime(inst, true); - inst.inline = inst.stay_open = true; - //This way the onSelect handler called from calendarpicker get the full dateTime - this._base_selectDate(id, dateStr); - inst.inline = inst.stay_open = false; - this._notifyChange(inst); - this._updateDatepicker(inst); - } - else this._base_selectDate(id, dateStr); -}; - -//############################################################################################# -// second bad hack :/ override datepicker so it triggers an event when changing the input field -// and does not redraw the datepicker on every selectDate event -//############################################################################################# -$.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker; -$.datepicker._updateDatepicker = function(inst) { - - // don't popup the datepicker if there is another instance already opened - var input = inst.input[0]; - if($.datepicker._curInst && - $.datepicker._curInst != inst && - $.datepicker._datepickerShowing && - $.datepicker._lastInput != input) { - return; - } - - if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) { - - this._base_updateDatepicker(inst); - - // Reload the time control when changing something in the input text field. - var tp_inst = this._get(inst, 'timepicker'); - if(tp_inst) tp_inst._addTimePicker(inst); - } -}; - -//####################################################################################### -// third bad hack :/ override datepicker so it allows spaces and colon in the input field -//####################################################################################### -$.datepicker._base_doKeyPress = $.datepicker._doKeyPress; -$.datepicker._doKeyPress = function(event) { - var inst = $.datepicker._getInst(event.target), - tp_inst = $.datepicker._get(inst, 'timepicker'); - - if (tp_inst) { - if ($.datepicker._get(inst, 'constrainInput')) { - var ampm = tp_inst._defaults.ampm, - dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')), - datetimeChars = tp_inst._defaults.timeFormat.toString() - .replace(/[hms]/g, '') - .replace(/TT/g, ampm ? 'APM' : '') - .replace(/Tt/g, ampm ? 'AaPpMm' : '') - .replace(/tT/g, ampm ? 'AaPpMm' : '') - .replace(/T/g, ampm ? 'AP' : '') - .replace(/tt/g, ampm ? 'apm' : '') - .replace(/t/g, ampm ? 'ap' : '') + - " " + - tp_inst._defaults.separator + - tp_inst._defaults.timeSuffix + - (tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') + - (tp_inst._defaults.amNames.join('')) + - (tp_inst._defaults.pmNames.join('')) + - dateChars, - chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode); - return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1); - } - } - - return $.datepicker._base_doKeyPress(event); -}; - -//####################################################################################### -// Override key up event to sync manual input changes. -//####################################################################################### -$.datepicker._base_doKeyUp = $.datepicker._doKeyUp; -$.datepicker._doKeyUp = function (event) { - var inst = $.datepicker._getInst(event.target), - tp_inst = $.datepicker._get(inst, 'timepicker'); - - if (tp_inst) { - if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) { - try { - $.datepicker._updateDatepicker(inst); - } - catch (err) { - $.datepicker.log(err); - } - } - } - - return $.datepicker._base_doKeyUp(event); -}; - -//####################################################################################### -// override "Today" button to also grab the time. -//####################################################################################### -$.datepicker._base_gotoToday = $.datepicker._gotoToday; -$.datepicker._gotoToday = function(id) { - var inst = this._getInst($(id)[0]), - $dp = inst.dpDiv; - this._base_gotoToday(id); - var now = new Date(); - var tp_inst = this._get(inst, 'timepicker'); - if (tp_inst._defaults.showTimezone && tp_inst.timezone_select) { - var tzoffset = now.getTimezoneOffset(); // If +0100, returns -60 - var tzsign = tzoffset > 0 ? '-' : '+'; - tzoffset = Math.abs(tzoffset); - var tzmin = tzoffset % 60 - tzoffset = tzsign + ('0' + (tzoffset - tzmin) / 60).slice(-2) + ('0' + tzmin).slice(-2); - if (tp_inst._defaults.timezoneIso8609) - tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3); - tp_inst.timezone_select.val(tzoffset); - } - this._setTime(inst, now); - $( '.ui-datepicker-today', $dp).click(); -}; - -//####################################################################################### -// Disable & enable the Time in the datetimepicker -//####################################################################################### -$.datepicker._disableTimepickerDatepicker = function(target, date, withDate) { - var inst = this._getInst(target), - tp_inst = this._get(inst, 'timepicker'); - $(target).datepicker('getDate'); // Init selected[Year|Month|Day] - if (tp_inst) { - tp_inst._defaults.showTimepicker = false; - tp_inst._updateDateTime(inst); - } -}; - -$.datepicker._enableTimepickerDatepicker = function(target, date, withDate) { - var inst = this._getInst(target), - tp_inst = this._get(inst, 'timepicker'); - $(target).datepicker('getDate'); // Init selected[Year|Month|Day] - if (tp_inst) { - tp_inst._defaults.showTimepicker = true; - tp_inst._addTimePicker(inst); // Could be disabled on page load - tp_inst._updateDateTime(inst); - } -}; - -//####################################################################################### -// Create our own set time function -//####################################################################################### -$.datepicker._setTime = function(inst, date) { - var tp_inst = this._get(inst, 'timepicker'); - if (tp_inst) { - var defaults = tp_inst._defaults, - // calling _setTime with no date sets time to defaults - hour = date ? date.getHours() : defaults.hour, - minute = date ? date.getMinutes() : defaults.minute, - second = date ? date.getSeconds() : defaults.second, - millisec = date ? date.getMilliseconds() : defaults.millisec; - - //check if within min/max times.. - if ((hour < defaults.hourMin || hour > defaults.hourMax) || (minute < defaults.minuteMin || minute > defaults.minuteMax) || (second < defaults.secondMin || second > defaults.secondMax) || (millisec < defaults.millisecMin || millisec > defaults.millisecMax)) { - hour = defaults.hourMin; - minute = defaults.minuteMin; - second = defaults.secondMin; - millisec = defaults.millisecMin; - } - - tp_inst.hour = hour; - tp_inst.minute = minute; - tp_inst.second = second; - tp_inst.millisec = millisec; - - if (tp_inst.hour_slider) tp_inst.hour_slider.slider('value', hour); - if (tp_inst.minute_slider) tp_inst.minute_slider.slider('value', minute); - if (tp_inst.second_slider) tp_inst.second_slider.slider('value', second); - if (tp_inst.millisec_slider) tp_inst.millisec_slider.slider('value', millisec); - - tp_inst._onTimeChange(); - tp_inst._updateDateTime(inst); - } -}; - -//####################################################################################### -// Create new public method to set only time, callable as $().datepicker('setTime', date) -//####################################################################################### -$.datepicker._setTimeDatepicker = function(target, date, withDate) { - var inst = this._getInst(target), - tp_inst = this._get(inst, 'timepicker'); - - if (tp_inst) { - this._setDateFromField(inst); - var tp_date; - if (date) { - if (typeof date == "string") { - tp_inst._parseTime(date, withDate); - tp_date = new Date(); - tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec); - } - else tp_date = new Date(date.getTime()); - if (tp_date.toString() == 'Invalid Date') tp_date = undefined; - this._setTime(inst, tp_date); - } - } - -}; - -//####################################################################################### -// override setDate() to allow setting time too within Date object -//####################################################################################### -$.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker; -$.datepicker._setDateDatepicker = function(target, date) { - var inst = this._getInst(target), - tp_date = (date instanceof Date) ? new Date(date.getTime()) : date; - - this._updateDatepicker(inst); - this._base_setDateDatepicker.apply(this, arguments); - this._setTimeDatepicker(target, tp_date, true); -}; - -//####################################################################################### -// override getDate() to allow getting time too within Date object -//####################################################################################### -$.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker; -$.datepicker._getDateDatepicker = function(target, noDefault) { - var inst = this._getInst(target), - tp_inst = this._get(inst, 'timepicker'); - - if (tp_inst) { - this._setDateFromField(inst, noDefault); - var date = this._getDate(inst); - if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec); - return date; - } - return this._base_getDateDatepicker(target, noDefault); -}; - -//####################################################################################### -// override parseDate() because UI 1.8.14 throws an error about "Extra characters" -// An option in datapicker to ignore extra format characters would be nicer. -//####################################################################################### -$.datepicker._base_parseDate = $.datepicker.parseDate; -$.datepicker.parseDate = function(format, value, settings) { - var date; - try { - date = this._base_parseDate(format, value, settings); - } catch (err) { - // Hack! The error message ends with a colon, a space, and - // the "extra" characters. We rely on that instead of - // attempting to perfectly reproduce the parsing algorithm. - date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings); - } - return date; -}; - -//####################################################################################### -// override formatDate to set date with time to the input -//####################################################################################### -$.datepicker._base_formatDate=$.datepicker._formatDate; -$.datepicker._formatDate = function(inst, day, month, year){ - var tp_inst = this._get(inst, 'timepicker'); - if(tp_inst) - { - if(day) - var b = this._base_formatDate(inst, day, month, year); - tp_inst._updateDateTime(); - return tp_inst.$input.val(); - } - return this._base_formatDate(inst); -} - -//####################################################################################### -// override options setter to add time to maxDate(Time) and minDate(Time). MaxDate -//####################################################################################### -$.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker; -$.datepicker._optionDatepicker = function(target, name, value) { - var inst = this._getInst(target), - tp_inst = this._get(inst, 'timepicker'); - if (tp_inst) { - var min,max,onselect; - if (typeof name == 'string') { // if min/max was set with the string - if (name==='minDate' || name==='minDateTime' ) - min = value; - else if (name==='maxDate' || name==='maxDateTime') - max = value; - else if (name==='onSelect') - onselect=value; - } else if (typeof name == 'object') { //if min/max was set with the JSON - if(name.minDate) - min = name.minDate; - else if (name.minDateTime) - min = name.minDateTime; - else if (name.maxDate) - max = name.maxDate; - else if (name.maxDateTime) - max = name.maxDateTime; - } - if(min){ //if min was set - if(min==0) - min=new Date(); - else - min= new Date(min); - - tp_inst._defaults.minDate = min; - tp_inst._defaults.minDateTime = min; - } else if (max){ //if max was set - if(max==0) - max=new Date(); - else - max= new Date(max); - tp_inst._defaults.maxDate = max; - tp_inst._defaults.maxDateTime = max; - } - else if (onselect) - tp_inst._defaults.onSelect=onselect; - } - this._base_optionDatepicker(target, name, value); -}; - -//####################################################################################### -// jQuery extend now ignores nulls! -//####################################################################################### -function extendRemove(target, props) { - $.extend(target, props); - for (var name in props) - if (props[name] === null || props[name] === undefined) - target[name] = props[name]; - return target; -} - -$.timepicker = new Timepicker(); // singleton instance -$.timepicker.version = "0.9.7"; - -})(jQuery); - +/* + * jQuery timepicker addon + * By: Trent Richardson [http://trentrichardson.com] + * Version 1.1.1 + * Last Modified: 11/07/2012 + * + * Copyright 2012 Trent Richardson + * You may use this project under MIT or GPL licenses. + * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt + * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt + */ + +/*jslint evil: true, white: false, undef: false, nomen: false */ + +(function($) { + + /* + * Lets not redefine timepicker, Prevent "Uncaught RangeError: Maximum call stack size exceeded" + */ + $.ui.timepicker = $.ui.timepicker || {}; + if ($.ui.timepicker.version) { + return; + } + + /* + * Extend jQueryUI, get it started with our version number + */ + $.extend($.ui, { + timepicker: { + version: "1.1.1" + } + }); + + /* + * Timepicker manager. + * Use the singleton instance of this class, $.timepicker, to interact with the time picker. + * Settings for (groups of) time pickers are maintained in an instance object, + * allowing multiple different settings on the same page. + */ + function Timepicker() { + this.regional = []; // Available regional settings, indexed by language code + this.regional[''] = { // Default regional settings + currentText: 'Now', + closeText: 'Done', + amNames: ['AM', 'A'], + pmNames: ['PM', 'P'], + timeFormat: 'HH:mm', + timeSuffix: '', + timeOnlyTitle: 'Choose Time', + timeText: 'Time', + hourText: 'Hour', + minuteText: 'Minute', + secondText: 'Second', + millisecText: 'Millisecond', + timezoneText: 'Time Zone', + isRTL: false + }; + this._defaults = { // Global defaults for all the datetime picker instances + showButtonPanel: true, + timeOnly: false, + showHour: true, + showMinute: true, + showSecond: false, + showMillisec: false, + showTimezone: false, + showTime: true, + stepHour: 1, + stepMinute: 1, + stepSecond: 1, + stepMillisec: 1, + hour: 0, + minute: 0, + second: 0, + millisec: 0, + timezone: null, + useLocalTimezone: false, + defaultTimezone: "+0000", + hourMin: 0, + minuteMin: 0, + secondMin: 0, + millisecMin: 0, + hourMax: 23, + minuteMax: 59, + secondMax: 59, + millisecMax: 999, + minDateTime: null, + maxDateTime: null, + onSelect: null, + hourGrid: 0, + minuteGrid: 0, + secondGrid: 0, + millisecGrid: 0, + alwaysSetTime: true, + separator: ' ', + altFieldTimeOnly: true, + altTimeFormat: null, + altSeparator: null, + altTimeSuffix: null, + pickerTimeFormat: null, + pickerTimeSuffix: null, + showTimepicker: true, + timezoneIso8601: false, + timezoneList: null, + addSliderAccess: false, + sliderAccessArgs: null, + controlType: 'slider', + defaultValue: null, + parse: 'strict' + }; + $.extend(this._defaults, this.regional['']); + } + + $.extend(Timepicker.prototype, { + $input: null, + $altInput: null, + $timeObj: null, + inst: null, + hour_slider: null, + minute_slider: null, + second_slider: null, + millisec_slider: null, + timezone_select: null, + hour: 0, + minute: 0, + second: 0, + millisec: 0, + timezone: null, + defaultTimezone: "+0000", + hourMinOriginal: null, + minuteMinOriginal: null, + secondMinOriginal: null, + millisecMinOriginal: null, + hourMaxOriginal: null, + minuteMaxOriginal: null, + secondMaxOriginal: null, + millisecMaxOriginal: null, + ampm: '', + formattedDate: '', + formattedTime: '', + formattedDateTime: '', + timezoneList: null, + units: ['hour','minute','second','millisec'], + control: null, + + /* + * Override the default settings for all instances of the time picker. + * @param settings object - the new settings to use as defaults (anonymous object) + * @return the manager object + */ + setDefaults: function(settings) { + extendRemove(this._defaults, settings || {}); + return this; + }, + + /* + * Create a new Timepicker instance + */ + _newInst: function($input, o) { + var tp_inst = new Timepicker(), + inlineSettings = {}, + fns = {}, + overrides, i; + + for (var attrName in this._defaults) { + if(this._defaults.hasOwnProperty(attrName)){ + var attrValue = $input.attr('time:' + attrName); + if (attrValue) { + try { + inlineSettings[attrName] = eval(attrValue); + } catch (err) { + inlineSettings[attrName] = attrValue; + } + } + } + } + overrides = { + beforeShow: function (input, dp_inst) { + if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) { + return tp_inst._defaults.evnts.beforeShow.call($input[0], input, dp_inst, tp_inst); + } + }, + onChangeMonthYear: function (year, month, dp_inst) { + // Update the time as well : this prevents the time from disappearing from the $input field. + tp_inst._updateDateTime(dp_inst); + if ($.isFunction(tp_inst._defaults.evnts.onChangeMonthYear)) { + tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst); + } + }, + onClose: function (dateText, dp_inst) { + if (tp_inst.timeDefined === true && $input.val() !== '') { + tp_inst._updateDateTime(dp_inst); + } + if ($.isFunction(tp_inst._defaults.evnts.onClose)) { + tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst); + } + } + }; + for (i in overrides) { + if (overrides.hasOwnProperty(i)) { + fns[i] = o[i] || null; + } + } + tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, overrides, { + evnts:fns, + timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); + }); + tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { + return val.toUpperCase(); + }); + tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { + return val.toUpperCase(); + }); + + // controlType is string - key to our this._controls + if(typeof(tp_inst._defaults.controlType) === 'string'){ + if($.fn[tp_inst._defaults.controlType] === undefined){ + tp_inst._defaults.controlType = 'select'; + } + tp_inst.control = tp_inst._controls[tp_inst._defaults.controlType]; + } + // controlType is an object and must implement create, options, value methods + else{ + tp_inst.control = tp_inst._defaults.controlType; + } + + if (tp_inst._defaults.timezoneList === null) { + var timezoneList = ['-1200', '-1100', '-1000', '-0930', '-0900', '-0800', '-0700', '-0600', '-0500', '-0430', '-0400', '-0330', '-0300', '-0200', '-0100', '+0000', + '+0100', '+0200', '+0300', '+0330', '+0400', '+0430', '+0500', '+0530', '+0545', '+0600', '+0630', '+0700', '+0800', '+0845', '+0900', '+0930', + '+1000', '+1030', '+1100', '+1130', '+1200', '+1245', '+1300', '+1400']; + + if (tp_inst._defaults.timezoneIso8601) { + timezoneList = $.map(timezoneList, function(val) { + return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3)); + }); + } + tp_inst._defaults.timezoneList = timezoneList; + } + + tp_inst.timezone = tp_inst._defaults.timezone; + tp_inst.hour = tp_inst._defaults.hour; + tp_inst.minute = tp_inst._defaults.minute; + tp_inst.second = tp_inst._defaults.second; + tp_inst.millisec = tp_inst._defaults.millisec; + tp_inst.ampm = ''; + tp_inst.$input = $input; + + if (o.altField) { + tp_inst.$altInput = $(o.altField).css({ + cursor: 'pointer' + }).focus(function() { + $input.trigger("focus"); + }); + } + + if (tp_inst._defaults.minDate === 0 || tp_inst._defaults.minDateTime === 0) { + tp_inst._defaults.minDate = new Date(); + } + if (tp_inst._defaults.maxDate === 0 || tp_inst._defaults.maxDateTime === 0) { + tp_inst._defaults.maxDate = new Date(); + } + + // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime.. + if (tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) { + tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime()); + } + if (tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date) { + tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime()); + } + if (tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date) { + tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime()); + } + if (tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) { + tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime()); + } + tp_inst.$input.bind('focus', function() { + tp_inst._onFocus(); + }); + + return tp_inst; + }, + + /* + * add our sliders to the calendar + */ + _addTimePicker: function(dp_inst) { + var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val(); + + this.timeDefined = this._parseTime(currDT); + this._limitMinMaxDateTime(dp_inst, false); + this._injectTimePicker(); + }, + + /* + * parse the time string from input value or _setTime + */ + _parseTime: function(timeString, withDate) { + if (!this.inst) { + this.inst = $.datepicker._getInst(this.$input[0]); + } + + if (withDate || !this._defaults.timeOnly) { + var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat'); + try { + var parseRes = parseDateTimeInternal(dp_dateFormat, this._defaults.timeFormat, timeString, $.datepicker._getFormatConfig(this.inst), this._defaults); + if (!parseRes.timeObj) { + return false; + } + $.extend(this, parseRes.timeObj); + } catch (err) { + $.datepicker.log("Error parsing the date/time string: " + err + + "\ndate/time string = " + timeString + + "\ntimeFormat = " + this._defaults.timeFormat + + "\ndateFormat = " + dp_dateFormat); + return false; + } + return true; + } else { + var timeObj = $.datepicker.parseTime(this._defaults.timeFormat, timeString, this._defaults); + if (!timeObj) { + return false; + } + $.extend(this, timeObj); + return true; + } + }, + + /* + * generate and inject html for timepicker into ui datepicker + */ + _injectTimePicker: function() { + var $dp = this.inst.dpDiv, + o = this.inst.settings, + tp_inst = this, + litem = '', + uitem = '', + max = {}, + gridSize = {}, + size = null; + + // Prevent displaying twice + if ($dp.find("div.ui-timepicker-div").length === 0 && o.showTimepicker) { + var noDisplay = ' style="display:none;"', + html = '<div class="ui-timepicker-div'+ (o.isRTL? ' ui-timepicker-rtl' : '') +'"><dl>' + '<dt class="ui_tpicker_time_label"' + ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' + + '<dd class="ui_tpicker_time"' + ((o.showTime) ? '' : noDisplay) + '></dd>'; + + // Create the markup + for(var i=0,l=this.units.length; i<l; i++){ + litem = this.units[i]; + uitem = litem.substr(0,1).toUpperCase() + litem.substr(1); + // Added by Peter Medeiros: + // - Figure out what the hour/minute/second max should be based on the step values. + // - Example: if stepMinute is 15, then minMax is 45. + max[litem] = parseInt((o[litem+'Max'] - ((o[litem+'Max'] - o[litem+'Min']) % o['step'+uitem])), 10); + gridSize[litem] = 0; + + html += '<dt class="ui_tpicker_'+ litem +'_label"' + ((o['show'+uitem]) ? '' : noDisplay) + '>' + o[litem +'Text'] + '</dt>' + + '<dd class="ui_tpicker_'+ litem +'"><div class="ui_tpicker_'+ litem +'_slider"' + ((o['show'+uitem]) ? '' : noDisplay) + '></div>'; + + if (o['show'+uitem] && o[litem+'Grid'] > 0) { + html += '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>'; + + if(litem == 'hour'){ + for (var h = o[litem+'Min']; h <= max[litem]; h += parseInt(o[litem+'Grid'], 10)) { + gridSize[litem]++; + var tmph = $.datepicker.formatTime(useAmpm(o.pickerTimeFormat || o.timeFormat)? 'hht':'HH', {hour:h}, o); + html += '<td data-for="'+litem+'">' + tmph + '</td>'; + } + } + else{ + for (var m = o[litem+'Min']; m <= max[litem]; m += parseInt(o[litem+'Grid'], 10)) { + gridSize[litem]++; + html += '<td data-for="'+litem+'">' + ((m < 10) ? '0' : '') + m + '</td>'; + } + } + + html += '</tr></table></div>'; + } + html += '</dd>'; + } + + // Timezone + html += '<dt class="ui_tpicker_timezone_label"' + ((o.showTimezone) ? '' : noDisplay) + '>' + o.timezoneText + '</dt>'; + html += '<dd class="ui_tpicker_timezone" ' + ((o.showTimezone) ? '' : noDisplay) + '></dd>'; + + // Create the elements from string + html += '</dl></div>'; + var $tp = $(html); + + // if we only want time picker... + if (o.timeOnly === true) { + $tp.prepend('<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' + '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' + '</div>'); + $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide(); + } + + // add sliders, adjust grids, add events + for(var i=0,l=tp_inst.units.length; i<l; i++){ + litem = tp_inst.units[i]; + uitem = litem.substr(0,1).toUpperCase() + litem.substr(1); + + // add the slider + tp_inst[litem+'_slider'] = tp_inst.control.create(tp_inst, $tp.find('.ui_tpicker_'+litem+'_slider'), litem, tp_inst[litem], o[litem+'Min'], max[litem], o['step'+uitem]); + + // adjust the grid and add click event + if (o['show'+uitem] && o[litem+'Grid'] > 0) { + size = 100 * gridSize[litem] * o[litem+'Grid'] / (max[litem] - o[litem+'Min']); + $tp.find('.ui_tpicker_'+litem+' table').css({ + width: size + "%", + marginLeft: o.isRTL? '0' : ((size / (-2 * gridSize[litem])) + "%"), + marginRight: o.isRTL? ((size / (-2 * gridSize[litem])) + "%") : '0', + borderCollapse: 'collapse' + }).find("td").click(function(e){ + var $t = $(this), + h = $t.html(), + n = parseInt(h.replace(/[^0-9]/g),10), + ap = h.replace(/[^apm]/ig), + f = $t.data('for'); // loses scope, so we use data-for + + if(f == 'hour'){ + if(ap.indexOf('p') !== -1 && n < 12){ + n += 12; + } + else{ + if(ap.indexOf('a') !== -1 && n === 12){ + n = 0; + } + } + } + + tp_inst.control.value(tp_inst, tp_inst[f+'_slider'], litem, n); + + tp_inst._onTimeChange(); + tp_inst._onSelectHandler(); + }) + .css({ + cursor: 'pointer', + width: (100 / gridSize[litem]) + '%', + textAlign: 'center', + overflow: 'hidden' + }); + } // end if grid > 0 + } // end for loop + + // Add timezone options + this.timezone_select = $tp.find('.ui_tpicker_timezone').append('<select></select>').find("select"); + $.fn.append.apply(this.timezone_select, + $.map(o.timezoneList, function(val, idx) { + return $("<option />").val(typeof val == "object" ? val.value : val).text(typeof val == "object" ? val.label : val); + })); + if (typeof(this.timezone) != "undefined" && this.timezone !== null && this.timezone !== "") { + var local_date = new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12); + var local_timezone = $.timepicker.timeZoneOffsetString(local_date); + if (local_timezone == this.timezone) { + selectLocalTimeZone(tp_inst); + } else { + this.timezone_select.val(this.timezone); + } + } else { + if (typeof(this.hour) != "undefined" && this.hour !== null && this.hour !== "") { + this.timezone_select.val(o.defaultTimezone); + } else { + selectLocalTimeZone(tp_inst); + } + } + this.timezone_select.change(function() { + tp_inst._defaults.useLocalTimezone = false; + tp_inst._onTimeChange(); + }); + // End timezone options + + // inject timepicker into datepicker + var $buttonPanel = $dp.find('.ui-datepicker-buttonpane'); + if ($buttonPanel.length) { + $buttonPanel.before($tp); + } else { + $dp.append($tp); + } + + this.$timeObj = $tp.find('.ui_tpicker_time'); + + if (this.inst !== null) { + var timeDefined = this.timeDefined; + this._onTimeChange(); + this.timeDefined = timeDefined; + } + + // slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/ + if (this._defaults.addSliderAccess) { + var sliderAccessArgs = this._defaults.sliderAccessArgs, + rtl = this._defaults.isRTL; + sliderAccessArgs.isRTL = rtl; + + setTimeout(function() { // fix for inline mode + if ($tp.find('.ui-slider-access').length === 0) { + $tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs); + + // fix any grids since sliders are shorter + var sliderAccessWidth = $tp.find('.ui-slider-access:eq(0)').outerWidth(true); + if (sliderAccessWidth) { + $tp.find('table:visible').each(function() { + var $g = $(this), + oldWidth = $g.outerWidth(), + oldMarginLeft = $g.css(rtl? 'marginRight':'marginLeft').toString().replace('%', ''), + newWidth = oldWidth - sliderAccessWidth, + newMarginLeft = ((oldMarginLeft * newWidth) / oldWidth) + '%', + css = { width: newWidth, marginRight: 0, marginLeft: 0 }; + css[rtl? 'marginRight':'marginLeft'] = newMarginLeft; + $g.css(css); + }); + } + } + }, 10); + } + // end slideAccess integration + + } + }, + + /* + * This function tries to limit the ability to go outside the + * min/max date range + */ + _limitMinMaxDateTime: function(dp_inst, adjustSliders) { + var o = this._defaults, + dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay); + + if (!this._defaults.showTimepicker) { + return; + } // No time so nothing to check here + + if ($.datepicker._get(dp_inst, 'minDateTime') !== null && $.datepicker._get(dp_inst, 'minDateTime') !== undefined && dp_date) { + var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'), + minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0); + + if (this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null || this.millisecMinOriginal === null) { + this.hourMinOriginal = o.hourMin; + this.minuteMinOriginal = o.minuteMin; + this.secondMinOriginal = o.secondMin; + this.millisecMinOriginal = o.millisecMin; + } + + if (dp_inst.settings.timeOnly || minDateTimeDate.getTime() == dp_date.getTime()) { + this._defaults.hourMin = minDateTime.getHours(); + if (this.hour <= this._defaults.hourMin) { + this.hour = this._defaults.hourMin; + this._defaults.minuteMin = minDateTime.getMinutes(); + if (this.minute <= this._defaults.minuteMin) { + this.minute = this._defaults.minuteMin; + this._defaults.secondMin = minDateTime.getSeconds(); + if (this.second <= this._defaults.secondMin) { + this.second = this._defaults.secondMin; + this._defaults.millisecMin = minDateTime.getMilliseconds(); + } else { + if (this.millisec < this._defaults.millisecMin) { + this.millisec = this._defaults.millisecMin; + } + this._defaults.millisecMin = this.millisecMinOriginal; + } + } else { + this._defaults.secondMin = this.secondMinOriginal; + this._defaults.millisecMin = this.millisecMinOriginal; + } + } else { + this._defaults.minuteMin = this.minuteMinOriginal; + this._defaults.secondMin = this.secondMinOriginal; + this._defaults.millisecMin = this.millisecMinOriginal; + } + } else { + this._defaults.hourMin = this.hourMinOriginal; + this._defaults.minuteMin = this.minuteMinOriginal; + this._defaults.secondMin = this.secondMinOriginal; + this._defaults.millisecMin = this.millisecMinOriginal; + } + } + + if ($.datepicker._get(dp_inst, 'maxDateTime') !== null && $.datepicker._get(dp_inst, 'maxDateTime') !== undefined && dp_date) { + var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'), + maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0); + + if (this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null) { + this.hourMaxOriginal = o.hourMax; + this.minuteMaxOriginal = o.minuteMax; + this.secondMaxOriginal = o.secondMax; + this.millisecMaxOriginal = o.millisecMax; + } + + if (dp_inst.settings.timeOnly || maxDateTimeDate.getTime() == dp_date.getTime()) { + this._defaults.hourMax = maxDateTime.getHours(); + if (this.hour >= this._defaults.hourMax) { + this.hour = this._defaults.hourMax; + this._defaults.minuteMax = maxDateTime.getMinutes(); + if (this.minute >= this._defaults.minuteMax) { + this.minute = this._defaults.minuteMax; + this._defaults.secondMax = maxDateTime.getSeconds(); + } else if (this.second >= this._defaults.secondMax) { + this.second = this._defaults.secondMax; + this._defaults.millisecMax = maxDateTime.getMilliseconds(); + } else { + if (this.millisec > this._defaults.millisecMax) { + this.millisec = this._defaults.millisecMax; + } + this._defaults.millisecMax = this.millisecMaxOriginal; + } + } else { + this._defaults.minuteMax = this.minuteMaxOriginal; + this._defaults.secondMax = this.secondMaxOriginal; + this._defaults.millisecMax = this.millisecMaxOriginal; + } + } else { + this._defaults.hourMax = this.hourMaxOriginal; + this._defaults.minuteMax = this.minuteMaxOriginal; + this._defaults.secondMax = this.secondMaxOriginal; + this._defaults.millisecMax = this.millisecMaxOriginal; + } + } + + if (adjustSliders !== undefined && adjustSliders === true) { + var hourMax = parseInt((this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)), 10), + minMax = parseInt((this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)), 10), + secMax = parseInt((this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)), 10), + millisecMax = parseInt((this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)), 10); + + if (this.hour_slider) { + this.control.options(this, this.hour_slider, 'hour', { min: this._defaults.hourMin, max: hourMax }); + this.control.value(this, this.hour_slider, 'hour', this.hour); + } + if (this.minute_slider) { + this.control.options(this, this.minute_slider, 'minute', { min: this._defaults.minuteMin, max: minMax }); + this.control.value(this, this.minute_slider, 'minute', this.minute); + } + if (this.second_slider) { + this.control.options(this, this.second_slider, 'second', { min: this._defaults.secondMin, max: secMax }); + this.control.value(this, this.second_slider, 'second', this.second); + } + if (this.millisec_slider) { + this.control.options(this, this.millisec_slider, 'millisec', { min: this._defaults.millisecMin, max: millisecMax }); + this.control.value(this, this.millisec_slider, 'millisec', this.millisec); + } + } + + }, + + /* + * when a slider moves, set the internal time... + * on time change is also called when the time is updated in the text field + */ + _onTimeChange: function() { + var hour = (this.hour_slider) ? this.control.value(this, this.hour_slider, 'hour') : false, + minute = (this.minute_slider) ? this.control.value(this, this.minute_slider, 'minute') : false, + second = (this.second_slider) ? this.control.value(this, this.second_slider, 'second') : false, + millisec = (this.millisec_slider) ? this.control.value(this, this.millisec_slider, 'millisec') : false, + timezone = (this.timezone_select) ? this.timezone_select.val() : false, + o = this._defaults, + pickerTimeFormat = o.pickerTimeFormat || o.timeFormat, + pickerTimeSuffix = o.pickerTimeSuffix || o.timeSuffix; + + if (typeof(hour) == 'object') { + hour = false; + } + if (typeof(minute) == 'object') { + minute = false; + } + if (typeof(second) == 'object') { + second = false; + } + if (typeof(millisec) == 'object') { + millisec = false; + } + if (typeof(timezone) == 'object') { + timezone = false; + } + + if (hour !== false) { + hour = parseInt(hour, 10); + } + if (minute !== false) { + minute = parseInt(minute, 10); + } + if (second !== false) { + second = parseInt(second, 10); + } + if (millisec !== false) { + millisec = parseInt(millisec, 10); + } + + var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0]; + + // If the update was done in the input field, the input field should not be updated. + // If the update was done using the sliders, update the input field. + var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || millisec != this.millisec + || (this.ampm.length > 0 && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) + || ((this.timezone === null && timezone != this.defaultTimezone) || (this.timezone !== null && timezone != this.timezone))); + + if (hasChanged) { + + if (hour !== false) { + this.hour = hour; + } + if (minute !== false) { + this.minute = minute; + } + if (second !== false) { + this.second = second; + } + if (millisec !== false) { + this.millisec = millisec; + } + if (timezone !== false) { + this.timezone = timezone; + } + + if (!this.inst) { + this.inst = $.datepicker._getInst(this.$input[0]); + } + + this._limitMinMaxDateTime(this.inst, true); + } + if (useAmpm(o.timeFormat)) { + this.ampm = ampm; + } + + // Updates the time within the timepicker + this.formattedTime = $.datepicker.formatTime(o.timeFormat, this, o); + if (this.$timeObj) { + if(pickerTimeFormat === o.timeFormat){ + this.$timeObj.text(this.formattedTime + pickerTimeSuffix); + } + else{ + this.$timeObj.text($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix); + } + } + + this.timeDefined = true; + if (hasChanged) { + this._updateDateTime(); + } + }, + + /* + * call custom onSelect. + * bind to sliders slidestop, and grid click. + */ + _onSelectHandler: function() { + var onSelect = this._defaults.onSelect || this.inst.settings.onSelect; + var inputEl = this.$input ? this.$input[0] : null; + if (onSelect && inputEl) { + onSelect.apply(inputEl, [this.formattedDateTime, this]); + } + }, + + /* + * update our input with the new date time.. + */ + _updateDateTime: function(dp_inst) { + dp_inst = this.inst || dp_inst; + var dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)), + dateFmt = $.datepicker._get(dp_inst, 'dateFormat'), + formatCfg = $.datepicker._getFormatConfig(dp_inst), + timeAvailable = dt !== null && this.timeDefined; + this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg); + var formattedDateTime = this.formattedDate; + + /* + * remove following lines to force every changes in date picker to change the input value + * Bug descriptions: when an input field has a default value, and click on the field to pop up the date picker. + * If the user manually empty the value in the input field, the date picker will never change selected value. + */ + //if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0)) { + // return; + //} + + if (this._defaults.timeOnly === true) { + formattedDateTime = this.formattedTime; + } else if (this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) { + formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix; + } + + this.formattedDateTime = formattedDateTime; + + if (!this._defaults.showTimepicker) { + this.$input.val(this.formattedDate); + } else if (this.$altInput && this._defaults.altFieldTimeOnly === true) { + this.$altInput.val(this.formattedTime); + this.$input.val(this.formattedDate); + } else if (this.$altInput) { + this.$input.val(formattedDateTime); + var altFormattedDateTime = '', + altSeparator = this._defaults.altSeparator ? this._defaults.altSeparator : this._defaults.separator, + altTimeSuffix = this._defaults.altTimeSuffix ? this._defaults.altTimeSuffix : this._defaults.timeSuffix; + + if (this._defaults.altFormat) altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg); + else altFormattedDateTime = this.formattedDate; + if (altFormattedDateTime) altFormattedDateTime += altSeparator; + if (this._defaults.altTimeFormat) altFormattedDateTime += $.datepicker.formatTime(this._defaults.altTimeFormat, this, this._defaults) + altTimeSuffix; + else altFormattedDateTime += this.formattedTime + altTimeSuffix; + this.$altInput.val(altFormattedDateTime); + } else { + this.$input.val(formattedDateTime); + } + + this.$input.trigger("change"); + }, + + _onFocus: function() { + if (!this.$input.val() && this._defaults.defaultValue) { + this.$input.val(this._defaults.defaultValue); + var inst = $.datepicker._getInst(this.$input.get(0)), + tp_inst = $.datepicker._get(inst, 'timepicker'); + if (tp_inst) { + if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) { + try { + $.datepicker._updateDatepicker(inst); + } catch (err) { + $.datepicker.log(err); + } + } + } + } + }, + + /* + * Small abstraction to control types + * We can add more, just be sure to follow the pattern: create, options, value + */ + _controls: { + // slider methods + slider: { + create: function(tp_inst, obj, unit, val, min, max, step){ + var rtl = tp_inst._defaults.isRTL; // if rtl go -60->0 instead of 0->60 + return obj.prop('slide', null).slider({ + orientation: "horizontal", + value: rtl? val*-1 : val, + min: rtl? max*-1 : min, + max: rtl? min*-1 : max, + step: step, + slide: function(event, ui) { + tp_inst.control.value(tp_inst, $(this), unit, rtl? ui.value*-1:ui.value); + tp_inst._onTimeChange(); + }, + stop: function(event, ui) { + tp_inst._onSelectHandler(); + } + }); + }, + options: function(tp_inst, obj, unit, opts, val){ + if(tp_inst._defaults.isRTL){ + if(typeof(opts) == 'string'){ + if(opts == 'min' || opts == 'max'){ + if(val !== undefined) + return obj.slider(opts, val*-1); + return Math.abs(obj.slider(opts)); + } + return obj.slider(opts); + } + var min = opts.min, + max = opts.max; + opts.min = opts.max = null; + if(min !== undefined) + opts.max = min * -1; + if(max !== undefined) + opts.min = max * -1; + return obj.slider(opts); + } + if(typeof(opts) == 'string' && val !== undefined) + return obj.slider(opts, val); + return obj.slider(opts); + }, + value: function(tp_inst, obj, unit, val){ + if(tp_inst._defaults.isRTL){ + if(val !== undefined) + return obj.slider('value', val*-1); + return Math.abs(obj.slider('value')); + } + if(val !== undefined) + return obj.slider('value', val); + return obj.slider('value'); + } + }, + // select methods + select: { + create: function(tp_inst, obj, unit, val, min, max, step){ + var sel = '<select class="ui-timepicker-select" data-unit="'+ unit +'" data-min="'+ min +'" data-max="'+ max +'" data-step="'+ step +'">', + ul = tp_inst._defaults.timeFormat.indexOf('t') !== -1? 'toLowerCase':'toUpperCase', + m = 0; + + for(var i=min; i<=max; i+=step){ + sel += '<option value="'+ i +'"'+ (i==val? ' selected':'') +'>'; + if(unit == 'hour' && useAmpm(tp_inst._defaults.pickerTimeFormat || tp_inst._defaults.timeFormat)) + sel += $.datepicker.formatTime("hh TT", {hour:i}, tp_inst._defaults); + else if(unit == 'millisec' || i >= 10) sel += i; + else sel += '0'+ i.toString(); + sel += '</option>'; + } + sel += '</select>'; + + obj.children('select').remove(); + + $(sel).appendTo(obj).change(function(e){ + tp_inst._onTimeChange(); + tp_inst._onSelectHandler(); + }); + + return obj; + }, + options: function(tp_inst, obj, unit, opts, val){ + var o = {}, + $t = obj.children('select'); + if(typeof(opts) == 'string'){ + if(val === undefined) + return $t.data(opts); + o[opts] = val; + } + else o = opts; + return tp_inst.control.create(tp_inst, obj, $t.data('unit'), $t.val(), o.min || $t.data('min'), o.max || $t.data('max'), o.step || $t.data('step')); + }, + value: function(tp_inst, obj, unit, val){ + var $t = obj.children('select'); + if(val !== undefined) + return $t.val(val); + return $t.val(); + } + } + } // end _controls + + }); + + $.fn.extend({ + /* + * shorthand just to use timepicker.. + */ + timepicker: function(o) { + o = o || {}; + var tmp_args = Array.prototype.slice.call(arguments); + + if (typeof o == 'object') { + tmp_args[0] = $.extend(o, { + timeOnly: true + }); + } + + return $(this).each(function() { + $.fn.datetimepicker.apply($(this), tmp_args); + }); + }, + + /* + * extend timepicker to datepicker + */ + datetimepicker: function(o) { + o = o || {}; + var tmp_args = arguments; + + if (typeof(o) == 'string') { + if (o == 'getDate') { + return $.fn.datepicker.apply($(this[0]), tmp_args); + } else { + return this.each(function() { + var $t = $(this); + $t.datepicker.apply($t, tmp_args); + }); + } + } else { + return this.each(function() { + var $t = $(this); + $t.datepicker($.timepicker._newInst($t, o)._defaults); + }); + } + } + }); + + /* + * Public Utility to parse date and time + */ + $.datepicker.parseDateTime = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) { + var parseRes = parseDateTimeInternal(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings); + if (parseRes.timeObj) { + var t = parseRes.timeObj; + parseRes.date.setHours(t.hour, t.minute, t.second, t.millisec); + } + + return parseRes.date; + }; + + /* + * Public utility to parse time + */ + $.datepicker.parseTime = function(timeFormat, timeString, options) { + var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {}); + + // Strict parse requires the timeString to match the timeFormat exactly + var strictParse = function(f, s, o){ + + // pattern for standard and localized AM/PM markers + var getPatternAmpm = function(amNames, pmNames) { + var markers = []; + if (amNames) { + $.merge(markers, amNames); + } + if (pmNames) { + $.merge(markers, pmNames); + } + markers = $.map(markers, function(val) { + return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&'); + }); + return '(' + markers.join('|') + ')?'; + }; + + // figure out position of time elements.. cause js cant do named captures + var getFormatPositions = function(timeFormat) { + var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z|'.*?')/g), + orders = { + h: -1, + m: -1, + s: -1, + l: -1, + t: -1, + z: -1 + }; + + if (finds) { + for (var i = 0; i < finds.length; i++) { + if (orders[finds[i].toString().charAt(0)] == -1) { + orders[finds[i].toString().charAt(0)] = i + 1; + } + } + } + return orders; + }; + + var regstr = '^' + f.toString() + .replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[lz]|'.*?')/g, function (match) { + switch (match.charAt(0).toLowerCase()) { + case 'h': return '(\\d?\\d)'; + case 'm': return '(\\d?\\d)'; + case 's': return '(\\d?\\d)'; + case 'l': return '(\\d?\\d?\\d)'; + case 'z': return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?'; + case 't': return getPatternAmpm(o.amNames, o.pmNames); + default: // literal escaped in quotes + return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?'; + } + }) + .replace(/\s/g, '\\s?') + + o.timeSuffix + '$', + order = getFormatPositions(f), + ampm = '', + treg; + + treg = s.match(new RegExp(regstr, 'i')); + + var resTime = { + hour: 0, + minute: 0, + second: 0, + millisec: 0 + }; + + if (treg) { + if (order.t !== -1) { + if (treg[order.t] === undefined || treg[order.t].length === 0) { + ampm = ''; + resTime.ampm = ''; + } else { + ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames) !== -1 ? 'AM' : 'PM'; + resTime.ampm = o[ampm == 'AM' ? 'amNames' : 'pmNames'][0]; + } + } + + if (order.h !== -1) { + if (ampm == 'AM' && treg[order.h] == '12') { + resTime.hour = 0; // 12am = 0 hour + } else { + if (ampm == 'PM' && treg[order.h] != '12') { + resTime.hour = parseInt(treg[order.h], 10) + 12; // 12pm = 12 hour, any other pm = hour + 12 + } else { + resTime.hour = Number(treg[order.h]); + } + } + } + + if (order.m !== -1) { + resTime.minute = Number(treg[order.m]); + } + if (order.s !== -1) { + resTime.second = Number(treg[order.s]); + } + if (order.l !== -1) { + resTime.millisec = Number(treg[order.l]); + } + if (order.z !== -1 && treg[order.z] !== undefined) { + var tz = treg[order.z].toUpperCase(); + switch (tz.length) { + case 1: + // Z + tz = o.timezoneIso8601 ? 'Z' : '+0000'; + break; + case 5: + // +hhmm + if (o.timezoneIso8601) { + tz = tz.substring(1) == '0000' ? 'Z' : tz.substring(0, 3) + ':' + tz.substring(3); + } + break; + case 6: + // +hh:mm + if (!o.timezoneIso8601) { + tz = tz == 'Z' || tz.substring(1) == '00:00' ? '+0000' : tz.replace(/:/, ''); + } else { + if (tz.substring(1) == '00:00') { + tz = 'Z'; + } + } + break; + } + resTime.timezone = tz; + } + + + return resTime; + } + return false; + };// end strictParse + + // First try JS Date, if that fails, use strictParse + var looseParse = function(f,s,o){ + try{ + var d = new Date('2012-01-01 '+ s); + return { + hour: d.getHours(), + minutes: d.getMinutes(), + seconds: d.getSeconds(), + millisec: d.getMilliseconds(), + timezone: $.timepicker.timeZoneOffsetString(d) + }; + } + catch(err){ + try{ + return strictParse(f,s,o); + } + catch(err2){ + $.datepicker.log("Unable to parse \ntimeString: "+ s +"\ntimeFormat: "+ f); + } + } + return false; + }; // end looseParse + + if(typeof o.parse === "function"){ + return o.parse(timeFormat, timeString, o) + } + if(o.parse === 'loose'){ + return looseParse(timeFormat, timeString, o); + } + return strictParse(timeFormat, timeString, o); + }; + + /* + * Public utility to format the time + * format = string format of the time + * time = a {}, not a Date() for timezones + * options = essentially the regional[].. amNames, pmNames, ampm + */ + $.datepicker.formatTime = function(format, time, options) { + options = options || {}; + options = $.extend({}, $.timepicker._defaults, options); + time = $.extend({ + hour: 0, + minute: 0, + second: 0, + millisec: 0, + timezone: '+0000' + }, time); + + var tmptime = format, + ampmName = options.amNames[0], + hour = parseInt(time.hour, 10); + + if (hour > 11) { + ampmName = options.pmNames[0]; + } + + tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[lz]|('.*?'|".*?"))/g, function(match) { + switch (match) { + case 'HH': + return ('0' + hour).slice(-2); + case 'H': + return hour; + case 'hh': + return ('0' + convert24to12(hour)).slice(-2); + case 'h': + return convert24to12(hour); + case 'mm': + return ('0' + time.minute).slice(-2); + case 'm': + return time.minute; + case 'ss': + return ('0' + time.second).slice(-2); + case 's': + return time.second; + case 'l': + return ('00' + time.millisec).slice(-3); + case 'z': + return time.timezone === null? options.defaultTimezone : time.timezone; + case 'T': + return ampmName.charAt(0).toUpperCase(); + case 'TT': + return ampmName.toUpperCase(); + case 't': + return ampmName.charAt(0).toLowerCase(); + case 'tt': + return ampmName.toLowerCase(); + default: + return match.replace(/\'/g, "") || "'"; + } + }); + + tmptime = $.trim(tmptime); + return tmptime; + }; + + /* + * the bad hack :/ override datepicker so it doesnt close on select + // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378 + */ + $.datepicker._base_selectDate = $.datepicker._selectDate; + $.datepicker._selectDate = function(id, dateStr) { + var inst = this._getInst($(id)[0]), + tp_inst = this._get(inst, 'timepicker'); + + if (tp_inst) { + tp_inst._limitMinMaxDateTime(inst, true); + inst.inline = inst.stay_open = true; + //This way the onSelect handler called from calendarpicker get the full dateTime + this._base_selectDate(id, dateStr); + inst.inline = inst.stay_open = false; + this._notifyChange(inst); + this._updateDatepicker(inst); + } else { + this._base_selectDate(id, dateStr); + } + }; + + /* + * second bad hack :/ override datepicker so it triggers an event when changing the input field + * and does not redraw the datepicker on every selectDate event + */ + $.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker; + $.datepicker._updateDatepicker = function(inst) { + + // don't popup the datepicker if there is another instance already opened + var input = inst.input[0]; + if ($.datepicker._curInst && $.datepicker._curInst != inst && $.datepicker._datepickerShowing && $.datepicker._lastInput != input) { + return; + } + + if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) { + + this._base_updateDatepicker(inst); + + // Reload the time control when changing something in the input text field. + var tp_inst = this._get(inst, 'timepicker'); + if (tp_inst) { + tp_inst._addTimePicker(inst); + + if (tp_inst._defaults.useLocalTimezone) { //checks daylight saving with the new date. + var date = new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay, 12); + selectLocalTimeZone(tp_inst, date); + tp_inst._onTimeChange(); + } + } + } + }; + + /* + * third bad hack :/ override datepicker so it allows spaces and colon in the input field + */ + $.datepicker._base_doKeyPress = $.datepicker._doKeyPress; + $.datepicker._doKeyPress = function(event) { + var inst = $.datepicker._getInst(event.target), + tp_inst = $.datepicker._get(inst, 'timepicker'); + + if (tp_inst) { + if ($.datepicker._get(inst, 'constrainInput')) { + var ampm = useAmpm(tp_inst._defaults.timeFormat), + dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')), + datetimeChars = tp_inst._defaults.timeFormat.toString() + .replace(/[hms]/g, '') + .replace(/TT/g, ampm ? 'APM' : '') + .replace(/Tt/g, ampm ? 'AaPpMm' : '') + .replace(/tT/g, ampm ? 'AaPpMm' : '') + .replace(/T/g, ampm ? 'AP' : '') + .replace(/tt/g, ampm ? 'apm' : '') + .replace(/t/g, ampm ? 'ap' : '') + + " " + tp_inst._defaults.separator + + tp_inst._defaults.timeSuffix + + (tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') + + (tp_inst._defaults.amNames.join('')) + (tp_inst._defaults.pmNames.join('')) + + dateChars, + chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode); + return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1); + } + } + + return $.datepicker._base_doKeyPress(event); + }; + + /* + * Fourth bad hack :/ override _updateAlternate function used in inline mode to init altField + */ + $.datepicker._base_updateAlternate = $.datepicker._updateAlternate; + /* Update any alternate field to synchronise with the main field. */ + $.datepicker._updateAlternate = function(inst) { + var tp_inst = this._get(inst, 'timepicker'); + if(tp_inst){ + var altField = tp_inst._defaults.altField; + if (altField) { // update alternate field too + var altFormat = tp_inst._defaults.altFormat || tp_inst._defaults.dateFormat, + date = this._getDate(inst), + formatCfg = $.datepicker._getFormatConfig(inst), + altFormattedDateTime = '', + altSeparator = tp_inst._defaults.altSeparator ? tp_inst._defaults.altSeparator : tp_inst._defaults.separator, + altTimeSuffix = tp_inst._defaults.altTimeSuffix ? tp_inst._defaults.altTimeSuffix : tp_inst._defaults.timeSuffix, + altTimeFormat = tp_inst._defaults.altTimeFormat !== null ? tp_inst._defaults.altTimeFormat : tp_inst._defaults.timeFormat; + + altFormattedDateTime += $.datepicker.formatTime(altTimeFormat, tp_inst, tp_inst._defaults) + altTimeSuffix; + if(!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly){ + if(tp_inst._defaults.altFormat) + altFormattedDateTime = $.datepicker.formatDate(tp_inst._defaults.altFormat, (date === null ? new Date() : date), formatCfg) + altSeparator + altFormattedDateTime; + else altFormattedDateTime = tp_inst.formattedDate + altSeparator + altFormattedDateTime; + } + $(altField).val(altFormattedDateTime); + } + } + else{ + $.datepicker._base_updateAlternate(inst); + } + }; + + /* + * Override key up event to sync manual input changes. + */ + $.datepicker._base_doKeyUp = $.datepicker._doKeyUp; + $.datepicker._doKeyUp = function(event) { + var inst = $.datepicker._getInst(event.target), + tp_inst = $.datepicker._get(inst, 'timepicker'); + + if (tp_inst) { + if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) { + try { + $.datepicker._updateDatepicker(inst); + } catch (err) { + $.datepicker.log(err); + } + } + } + + return $.datepicker._base_doKeyUp(event); + }; + + /* + * override "Today" button to also grab the time. + */ + $.datepicker._base_gotoToday = $.datepicker._gotoToday; + $.datepicker._gotoToday = function(id) { + var inst = this._getInst($(id)[0]), + $dp = inst.dpDiv; + this._base_gotoToday(id); + var tp_inst = this._get(inst, 'timepicker'); + selectLocalTimeZone(tp_inst); + var now = new Date(); + this._setTime(inst, now); + $('.ui-datepicker-today', $dp).click(); + }; + + /* + * Disable & enable the Time in the datetimepicker + */ + $.datepicker._disableTimepickerDatepicker = function(target) { + var inst = this._getInst(target); + if (!inst) { + return; + } + + var tp_inst = this._get(inst, 'timepicker'); + $(target).datepicker('getDate'); // Init selected[Year|Month|Day] + if (tp_inst) { + tp_inst._defaults.showTimepicker = false; + tp_inst._updateDateTime(inst); + } + }; + + $.datepicker._enableTimepickerDatepicker = function(target) { + var inst = this._getInst(target); + if (!inst) { + return; + } + + var tp_inst = this._get(inst, 'timepicker'); + $(target).datepicker('getDate'); // Init selected[Year|Month|Day] + if (tp_inst) { + tp_inst._defaults.showTimepicker = true; + tp_inst._addTimePicker(inst); // Could be disabled on page load + tp_inst._updateDateTime(inst); + } + }; + + /* + * Create our own set time function + */ + $.datepicker._setTime = function(inst, date) { + var tp_inst = this._get(inst, 'timepicker'); + if (tp_inst) { + var defaults = tp_inst._defaults; + + // calling _setTime with no date sets time to defaults + tp_inst.hour = date ? date.getHours() : defaults.hour; + tp_inst.minute = date ? date.getMinutes() : defaults.minute; + tp_inst.second = date ? date.getSeconds() : defaults.second; + tp_inst.millisec = date ? date.getMilliseconds() : defaults.millisec; + + //check if within min/max times.. + tp_inst._limitMinMaxDateTime(inst, true); + + tp_inst._onTimeChange(); + tp_inst._updateDateTime(inst); + } + }; + + /* + * Create new public method to set only time, callable as $().datepicker('setTime', date) + */ + $.datepicker._setTimeDatepicker = function(target, date, withDate) { + var inst = this._getInst(target); + if (!inst) { + return; + } + + var tp_inst = this._get(inst, 'timepicker'); + + if (tp_inst) { + this._setDateFromField(inst); + var tp_date; + if (date) { + if (typeof date == "string") { + tp_inst._parseTime(date, withDate); + tp_date = new Date(); + tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec); + } else { + tp_date = new Date(date.getTime()); + } + if (tp_date.toString() == 'Invalid Date') { + tp_date = undefined; + } + this._setTime(inst, tp_date); + } + } + + }; + + /* + * override setDate() to allow setting time too within Date object + */ + $.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker; + $.datepicker._setDateDatepicker = function(target, date) { + var inst = this._getInst(target); + if (!inst) { + return; + } + + var tp_date = (date instanceof Date) ? new Date(date.getTime()) : date; + + this._updateDatepicker(inst); + this._base_setDateDatepicker.apply(this, arguments); + this._setTimeDatepicker(target, tp_date, true); + }; + + /* + * override getDate() to allow getting time too within Date object + */ + $.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker; + $.datepicker._getDateDatepicker = function(target, noDefault) { + var inst = this._getInst(target); + if (!inst) { + return; + } + + var tp_inst = this._get(inst, 'timepicker'); + + if (tp_inst) { + // if it hasn't yet been defined, grab from field + if(inst.lastVal === undefined){ + this._setDateFromField(inst, noDefault); + } + + var date = this._getDate(inst); + if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) { + date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec); + } + return date; + } + return this._base_getDateDatepicker(target, noDefault); + }; + + /* + * override parseDate() because UI 1.8.14 throws an error about "Extra characters" + * An option in datapicker to ignore extra format characters would be nicer. + */ + $.datepicker._base_parseDate = $.datepicker.parseDate; + $.datepicker.parseDate = function(format, value, settings) { + var date; + try { + date = this._base_parseDate(format, value, settings); + } catch (err) { + // Hack! The error message ends with a colon, a space, and + // the "extra" characters. We rely on that instead of + // attempting to perfectly reproduce the parsing algorithm. + date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings); + $.datepicker.log("Error parsing the date string: " + err + "\ndate string = " + value + "\ndate format = " + format); + } + return date; + }; + + /* + * override formatDate to set date with time to the input + */ + $.datepicker._base_formatDate = $.datepicker._formatDate; + $.datepicker._formatDate = function(inst, day, month, year) { + var tp_inst = this._get(inst, 'timepicker'); + if (tp_inst) { + tp_inst._updateDateTime(inst); + return tp_inst.$input.val(); + } + return this._base_formatDate(inst); + }; + + /* + * override options setter to add time to maxDate(Time) and minDate(Time). MaxDate + */ + $.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker; + $.datepicker._optionDatepicker = function(target, name, value) { + var inst = this._getInst(target), + name_clone; + if (!inst) { + return null; + } + + var tp_inst = this._get(inst, 'timepicker'); + if (tp_inst) { + var min = null, + max = null, + onselect = null, + overrides = tp_inst._defaults.evnts, + fns = {}, + prop; + if (typeof name == 'string') { // if min/max was set with the string + if (name === 'minDate' || name === 'minDateTime') { + min = value; + } else if (name === 'maxDate' || name === 'maxDateTime') { + max = value; + } else if (name === 'onSelect') { + onselect = value; + } else if (overrides.hasOwnProperty(name)) { + if (typeof (value) === 'undefined') { + return overrides[name]; + } + fns[name] = value; + name_clone = {}; //empty results in exiting function after overrides updated + } + } else if (typeof name == 'object') { //if min/max was set with the JSON + if (name.minDate) { + min = name.minDate; + } else if (name.minDateTime) { + min = name.minDateTime; + } else if (name.maxDate) { + max = name.maxDate; + } else if (name.maxDateTime) { + max = name.maxDateTime; + } + for (prop in overrides) { + if (overrides.hasOwnProperty(prop) && name[prop]) { + fns[prop] = name[prop]; + } + } + } + for (prop in fns) { + if (fns.hasOwnProperty(prop)) { + overrides[prop] = fns[prop]; + if (!name_clone) { name_clone = $.extend({}, name);} + delete name_clone[prop]; + } + } + if (name_clone && isEmptyObject(name_clone)) { return; } + if (min) { //if min was set + if (min === 0) { + min = new Date(); + } else { + min = new Date(min); + } + tp_inst._defaults.minDate = min; + tp_inst._defaults.minDateTime = min; + } else if (max) { //if max was set + if (max === 0) { + max = new Date(); + } else { + max = new Date(max); + } + tp_inst._defaults.maxDate = max; + tp_inst._defaults.maxDateTime = max; + } else if (onselect) { + tp_inst._defaults.onSelect = onselect; + } + } + if (value === undefined) { + return this._base_optionDatepicker.call($.datepicker, target, name); + } + return this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value); + }; + /* + * jQuery isEmptyObject does not check hasOwnProperty - if someone has added to the object prototype, + * it will return false for all objects + */ + var isEmptyObject = function(obj) { + var prop; + for (prop in obj) { + if (obj.hasOwnProperty(obj)) { + return false; + } + } + return true; + }; + + /* + * jQuery extend now ignores nulls! + */ + var extendRemove = function(target, props) { + $.extend(target, props); + for (var name in props) { + if (props[name] === null || props[name] === undefined) { + target[name] = props[name]; + } + } + return target; + }; + + /* + * Determine by the time format if should use ampm + * Returns true if should use ampm, false if not + */ + var useAmpm = function(timeFormat){ + return (timeFormat.indexOf('t') !== -1 && timeFormat.indexOf('h') !== -1); + }; + + /* + * Converts 24 hour format into 12 hour + * Returns 12 hour without leading 0 + */ + var convert24to12 = function(hour) { + if (hour > 12) { + hour = hour - 12; + } + + if (hour == 0) { + hour = 12; + } + + return String(hour); + }; + + /* + * Splits datetime string into date ans time substrings. + * Throws exception when date can't be parsed + * Returns [dateString, timeString] + */ + var splitDateTime = function(dateFormat, dateTimeString, dateSettings, timeSettings) { + try { + // The idea is to get the number separator occurances in datetime and the time format requested (since time has + // fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split. + var separator = timeSettings && timeSettings.separator ? timeSettings.separator : $.timepicker._defaults.separator, + format = timeSettings && timeSettings.timeFormat ? timeSettings.timeFormat : $.timepicker._defaults.timeFormat, + timeParts = format.split(separator), // how many occurances of separator may be in our format? + timePartsLen = timeParts.length, + allParts = dateTimeString.split(separator), + allPartsLen = allParts.length; + + if (allPartsLen > 1) { + return [ + allParts.splice(0,allPartsLen-timePartsLen).join(separator), + allParts.splice(0,timePartsLen).join(separator) + ]; + } + + } catch (err) { + $.datepicker.log('Could not split the date from the time. Please check the following datetimepicker options' + + "\nthrown error: " + err + + "\ndateTimeString" + dateTimeString + + "\ndateFormat = " + dateFormat + + "\nseparator = " + timeSettings.separator + + "\ntimeFormat = " + timeSettings.timeFormat); + + if (err.indexOf(":") >= 0) { + // Hack! The error message ends with a colon, a space, and + // the "extra" characters. We rely on that instead of + // attempting to perfectly reproduce the parsing algorithm. + var dateStringLength = dateTimeString.length - (err.length - err.indexOf(':') - 2), + timeString = dateTimeString.substring(dateStringLength); + + return [$.trim(dateTimeString.substring(0, dateStringLength)), $.trim(dateTimeString.substring(dateStringLength))]; + + } else { + throw err; + } + } + return [dateTimeString, '']; + }; + + /* + * Internal function to parse datetime interval + * Returns: {date: Date, timeObj: Object}, where + * date - parsed date without time (type Date) + * timeObj = {hour: , minute: , second: , millisec: } - parsed time. Optional + */ + var parseDateTimeInternal = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) { + var date; + var splitRes = splitDateTime(dateFormat, dateTimeString, dateSettings, timeSettings); + date = $.datepicker._base_parseDate(dateFormat, splitRes[0], dateSettings); + if (splitRes[1] !== '') { + var timeString = splitRes[1], + parsedTime = $.datepicker.parseTime(timeFormat, timeString, timeSettings); + + if (parsedTime === null) { + throw 'Wrong time format'; + } + return { + date: date, + timeObj: parsedTime + }; + } else { + return { + date: date + }; + } + }; + + /* + * Internal function to set timezone_select to the local timezone + */ + var selectLocalTimeZone = function(tp_inst, date) { + if (tp_inst && tp_inst.timezone_select) { + tp_inst._defaults.useLocalTimezone = true; + var now = typeof date !== 'undefined' ? date : new Date(); + var tzoffset = $.timepicker.timeZoneOffsetString(now); + if (tp_inst._defaults.timezoneIso8601) { + tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3); + } + tp_inst.timezone_select.val(tzoffset); + } + }; + + /* + * Create a Singleton Insance + */ + $.timepicker = new Timepicker(); + + /** + * Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5) + * @param date + * @return string + */ + $.timepicker.timeZoneOffsetString = function(date) { + var off = date.getTimezoneOffset() * -1, + minutes = off % 60, + hours = (off - minutes) / 60; + return (off >= 0 ? '+' : '-') + ('0' + (hours * 101).toString()).substr(-2) + ('0' + (minutes * 101).toString()).substr(-2); + }; + + /** + * Calls `timepicker()` on the `startTime` and `endTime` elements, and configures them to + * enforce date range limits. + * n.b. The input value must be correctly formatted (reformatting is not supported) + * @param Element startTime + * @param Element endTime + * @param obj options Options for the timepicker() call + * @return jQuery + */ + $.timepicker.timeRange = function(startTime, endTime, options) { + return $.timepicker.handleRange('timepicker', startTime, endTime, options); + }; + + /** + * Calls `datetimepicker` on the `startTime` and `endTime` elements, and configures them to + * enforce date range limits. + * @param Element startTime + * @param Element endTime + * @param obj options Options for the `timepicker()` call. Also supports `reformat`, + * a boolean value that can be used to reformat the input values to the `dateFormat`. + * @param string method Can be used to specify the type of picker to be added + * @return jQuery + */ + $.timepicker.dateTimeRange = function(startTime, endTime, options) { + $.timepicker.dateRange(startTime, endTime, options, 'datetimepicker'); + }; + + /** + * Calls `method` on the `startTime` and `endTime` elements, and configures them to + * enforce date range limits. + * @param Element startTime + * @param Element endTime + * @param obj options Options for the `timepicker()` call. Also supports `reformat`, + * a boolean value that can be used to reformat the input values to the `dateFormat`. + * @param string method Can be used to specify the type of picker to be added + * @return jQuery + */ + $.timepicker.dateRange = function(startTime, endTime, options, method) { + method = method || 'datepicker'; + $.timepicker.handleRange(method, startTime, endTime, options); + }; + + /** + * Calls `method` on the `startTime` and `endTime` elements, and configures them to + * enforce date range limits. + * @param string method Can be used to specify the type of picker to be added + * @param Element startTime + * @param Element endTime + * @param obj options Options for the `timepicker()` call. Also supports `reformat`, + * a boolean value that can be used to reformat the input values to the `dateFormat`. + * @return jQuery + */ + $.timepicker.handleRange = function(method, startTime, endTime, options) { + $.fn[method].call(startTime, $.extend({ + onClose: function(dateText, inst) { + checkDates(this, endTime, dateText); + }, + onSelect: function(selectedDateTime) { + selected(this, endTime, 'minDate'); + } + }, options, options.start)); + $.fn[method].call(endTime, $.extend({ + onClose: function(dateText, inst) { + checkDates(this, startTime, dateText); + }, + onSelect: function(selectedDateTime) { + selected(this, startTime, 'maxDate'); + } + }, options, options.end)); + // timepicker doesn't provide access to its 'timeFormat' option, + // nor could I get datepicker.formatTime() to behave with times, so I + // have disabled reformatting for timepicker + if (method != 'timepicker' && options.reformat) { + $([startTime, endTime]).each(function() { + var format = $(this)[method].call($(this), 'option', 'dateFormat'), + date = new Date($(this).val()); + if ($(this).val() && date) { + $(this).val($.datepicker.formatDate(format, date)); + } + }); + } + checkDates(startTime, endTime, startTime.val()); + + function checkDates(changed, other, dateText) { + if (other.val() && (new Date(startTime.val()) > new Date(endTime.val()))) { + other.val(dateText); + } + } + selected(startTime, endTime, 'minDate'); + selected(endTime, startTime, 'maxDate'); + + function selected(changed, other, option) { + if (!$(changed).val()) { + return; + } + var date = $(changed)[method].call($(changed), 'getDate'); + // timepicker doesn't implement 'getDate' and returns a jQuery + if (date.getTime) { + $(other)[method].call($(other), 'option', option, date); + } + } + return $([startTime.get(0), endTime.get(0)]); + }; + + /* + * Keep up with the version + */ + $.timepicker.version = "1.1.1"; + +})(jQuery); From 6fc0072f8c4dc04ee846b36b0e558f0a7fac1e3d Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 5 Dec 2012 18:40:57 +0100 Subject: [PATCH 1774/2024] fix draggable lists --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index f47e33ec5e..da97579345 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -885,7 +885,7 @@ var ActiveScaffold = { }, draggable_lists: function(element) { - jQuery('#' + element).draggable_lists(); + jQuery('ul#' + element).draggable_lists(); } } From 037d5b34f0442739c318cad5a2dcc7d661859d03 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 7 Dec 2012 00:42:34 +0100 Subject: [PATCH 1775/2024] fix conversion to 12 and 24 hours format in timepicker --- app/assets/javascripts/jquery/active_scaffold.js | 6 +++--- lib/active_scaffold/bridges/date_picker/helper.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index da97579345..34ac37fdcc 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -1,4 +1,4 @@ -jQuery(document).ready(function() { +jQuery(document).ready(function($) { jQuery(document).click(function(event) { jQuery('.action_group.dyn ul').remove(); }); @@ -296,7 +296,7 @@ jQuery(document).ready(function() { */ if (typeof(jQuery.fn.delayedObserver) === 'undefined') { - (function() { + (function($) { var delayedObserverStack = []; var observed; @@ -342,7 +342,7 @@ if (typeof(jQuery.fn.delayedObserver) === 'undefined') { }); } }); - })(); + })(jQuery); }; diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index 0d6f26272f..f92419a300 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -12,7 +12,7 @@ module Helper /%m/ => 'mm', /%y/ => 'y', /%Y/ => 'yy', - /%H/ => 'hh', # options ampm => false + /%H/ => 'HH', # options ampm => false /%I/ => 'hh', # options ampm => true /%M/ => 'mm', /%p/ => 'tt', @@ -110,7 +110,7 @@ def self.to_datepicker_format(rails_format) def self.split_datetime_format(datetime_format) date_format = datetime_format time_format = nil - time_start_indicators = %w{hh mm tt ss} + time_start_indicators = %w{HH hh mm tt ss} unless datetime_format.nil? start_indicator = time_start_indicators.detect {|indicator| datetime_format.include?(indicator)} unless start_indicator.nil? From 937ea9f35efde1f3e1a9f0f224cff883ab04707e Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Sat, 8 Dec 2012 15:10:12 +0100 Subject: [PATCH 1776/2024] fix format conversion with literals or custom format in datetime_picker --- lib/active_scaffold/bridges/date_picker/helper.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index f92419a300..47cb2b7971 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -101,6 +101,7 @@ def self.to_datepicker_format(rails_format) nil end js_format = rails_format.dup + js_format.gsub! /([ ]|^)([^% ]\S*)/, " '\\2'" DATE_FORMAT_CONVERSION.each do |key, value| js_format.gsub!(key, value) end @@ -115,8 +116,8 @@ def self.split_datetime_format(datetime_format) start_indicator = time_start_indicators.detect {|indicator| datetime_format.include?(indicator)} unless start_indicator.nil? pos_time_format = datetime_format.index(start_indicator) - date_format = datetime_format.to(pos_time_format - 1) - time_format = datetime_format.from(pos_time_format) + date_format = datetime_format.to(pos_time_format - 1).strip + time_format = datetime_format.from(pos_time_format).strip end end return date_format, time_format @@ -158,7 +159,7 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current options = active_scaffold_input_text_options(options.merge(column.options)) options[:class] << " #{column.search_ui.to_s}" options[:style] = (options[:show].nil? || options[:show]) ? nil : "display: none" - format = options.delete(:format) || column.search_ui == :date_picker ? :default : :picker + format = options.delete(:format) || (column.search_ui == :date_picker ? :default : :picker) datepicker_format_options(column, format, options) text_field_tag("#{options[:name]}[#{name}]", value ? l(value, :format => format) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) end @@ -169,7 +170,7 @@ def active_scaffold_input_date_picker(column, options) options = active_scaffold_input_text_options(options.merge(column.options)) options[:class] << " #{column.form_ui.to_s}" value = controller.class.condition_value_for_datetime(@record.send(column.name), column.form_ui == :date_picker ? :to_date : :to_time) - format = options.delete(:format) || column.form_ui == :date_picker ? :default : :picker + format = options.delete(:format) || (column.form_ui == :date_picker ? :default : :picker) datepicker_format_options(column, format, options) options[:value] = (value ? l(value, :format => format) : nil) text_field(:record, column.name, options) From dd17e4e79e787661d65fb220bd23c74c85e01799 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Sat, 8 Dec 2012 21:36:32 +0100 Subject: [PATCH 1777/2024] remove unused routes --- lib/active_scaffold/bridges/cancan/cancan_bridge.rb | 3 +-- lib/active_scaffold/extensions/routing_mapper.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/bridges/cancan/cancan_bridge.rb b/lib/active_scaffold/bridges/cancan/cancan_bridge.rb index 4737108ccc..bcf4ac31e5 100644 --- a/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +++ b/lib/active_scaffold/bridges/cancan/cancan_bridge.rb @@ -11,8 +11,7 @@ module CanCan module Ability def as_action_aliases alias_action :list, :row, :show_search, :render_field, :to => :read - alias_action :update_column, :add_association, :edit_associated, - :edit_associated, :new_existing, :add_existing, :to => :update + alias_action :update_column, :edit_associated, :new_existing, :add_existing, :to => :update alias_action :delete, :destroy_existing, :to => :destroy end end diff --git a/lib/active_scaffold/extensions/routing_mapper.rb b/lib/active_scaffold/extensions/routing_mapper.rb index b93eae272e..30f8da6cde 100644 --- a/lib/active_scaffold/extensions/routing_mapper.rb +++ b/lib/active_scaffold/extensions/routing_mapper.rb @@ -6,7 +6,7 @@ module Routing } ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING = { :collection => {:edit_associated => :get, :new_existing => :get, :add_existing => :post}, - :member => {:edit_associated => :get, :add_association => :get, :destroy_existing => :delete} + :member => {:edit_associated => :get, :destroy_existing => :delete} } class Mapper module Base From 04c580efdb5b4b819bb122b0c77b25f939dce3d4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 10 Dec 2012 15:57:27 +0100 Subject: [PATCH 1778/2024] avoid crash when association definition is wrong, better not to find inverse --- lib/active_scaffold/extensions/reverse_associations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/reverse_associations.rb b/lib/active_scaffold/extensions/reverse_associations.rb index 6026044cc4..ddf1c3ac66 100644 --- a/lib/active_scaffold/extensions/reverse_associations.rb +++ b/lib/active_scaffold/extensions/reverse_associations.rb @@ -35,7 +35,7 @@ def autodetect_inverse(klass = nil) else # skip over has_many :through associations next if assoc.options[:through] - next unless assoc.options[:polymorphic] or assoc.class_name.constantize == self.active_record + next unless assoc.options[:polymorphic] or assoc.class_name == self.active_record.name case [assoc.macro, self.macro].find_all{|m| m == :has_and_belongs_to_many}.length # if both are a habtm, then match them based on the join table From 50e0ec848b4fe6537518ffa031802adef0aef7f9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 14 Dec 2012 15:24:09 +0100 Subject: [PATCH 1779/2024] fix initial value for select inplace editors --- app/assets/javascripts/jquery/jquery.editinplace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/jquery.editinplace.js b/app/assets/javascripts/jquery/jquery.editinplace.js index 8e72f79c11..7fc34a4dc3 100644 --- a/app/assets/javascripts/jquery/jquery.editinplace.js +++ b/app/assets/javascripts/jquery/jquery.editinplace.js @@ -286,7 +286,7 @@ $.extend(InlineEditor.prototype, { }, setInitialValue: function() { - if (this.settings.field_type == 'remote') return; // remote generated editor doesn't need initial value + if (this.settings.field_type == 'remote' || this.settings.field_type == 'clone') return; // remote and clone generated editor doesn't need initial value var initialValue = this.triggerDelegateCall('willOpenEditInPlace', this.originalValue); var editor = this.dom.find(':input'); editor.val(initialValue); From fb5217a7a03ff3810e208732e49736fe3cb64630 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 17 Dec 2012 10:19:14 +0100 Subject: [PATCH 1780/2024] get columns subgroups to add or exclude more columns --- lib/active_scaffold/data_structures/action_columns.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index faa970d3a0..6f115a1cfb 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -16,6 +16,16 @@ def css_class @label.to_s.underscore end + # this is so that array.delete and array.include?, etc., will work by column name + def ==(other) #:nodoc: + # another ActionColumns + if other.class == self.class + self.label == other.label + else + @label.to_s == other.to_s + end + end + # Whether this column set is collapsed by default in contexts where collapsing is supported attr_accessor :collapsed From 35be5887929c8041d491cf6d82250c8d31a13bc7 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 17 Dec 2012 15:04:10 +0100 Subject: [PATCH 1781/2024] add ignore methods to actions --- lib/active_scaffold/actions/delete.rb | 3 +++ lib/active_scaffold/actions/show.rb | 3 +++ lib/active_scaffold/actions/update.rb | 3 +++ 3 files changed, 9 insertions(+) diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 2cbf42111b..03fbe79293 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -62,6 +62,9 @@ def do_destroy def delete_authorized?(record = nil) (!nested? || !nested.readonly?) && (record || self).send(:authorized_for?, :crud_type => :delete) end + def delete_ignore?(record = nil) + (!nested? || !nested.readonly?) && self.send(:authorized_for?, :crud_type => :delete) + end private def delete_authorized_filter link = active_scaffold_config.delete.link || active_scaffold_config.delete.class.link diff --git a/lib/active_scaffold/actions/show.rb b/lib/active_scaffold/actions/show.rb index c3fffb2d24..afd51299a8 100644 --- a/lib/active_scaffold/actions/show.rb +++ b/lib/active_scaffold/actions/show.rb @@ -51,6 +51,9 @@ def do_show def show_authorized?(record = nil) (record || self).send(:authorized_for?, :crud_type => :read) end + def show_ignore?(record = nil) + self.send(:authorized_for?, :crud_type => :read) + end private def show_authorized_filter link = active_scaffold_config.show.link || active_scaffold_config.show.class.link diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 3dfd76df6d..c793bac8f3 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -158,6 +158,9 @@ def update_refresh_list? def update_authorized?(record = nil) (!nested? || !nested.readonly?) && (record || self).authorized_for?(:crud_type => :update) end + def update_ignore?(record = nil) + self.authorized_for?(:crud_type => :update) + end private def update_authorized_filter link = active_scaffold_config.update.link || active_scaffold_config.update.class.link From dbd91530dfbbab3fc9dba5956c4760b1e762942b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 17 Dec 2012 15:11:18 +0100 Subject: [PATCH 1782/2024] fix ignore methods --- lib/active_scaffold/actions/delete.rb | 2 +- lib/active_scaffold/actions/show.rb | 2 +- lib/active_scaffold/actions/update.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 03fbe79293..753fe5ae97 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -63,7 +63,7 @@ def delete_authorized?(record = nil) (!nested? || !nested.readonly?) && (record || self).send(:authorized_for?, :crud_type => :delete) end def delete_ignore?(record = nil) - (!nested? || !nested.readonly?) && self.send(:authorized_for?, :crud_type => :delete) + (nested? && nested.readonly?) || !self.send(:authorized_for?, :crud_type => :delete) end private def delete_authorized_filter diff --git a/lib/active_scaffold/actions/show.rb b/lib/active_scaffold/actions/show.rb index afd51299a8..5e7554e023 100644 --- a/lib/active_scaffold/actions/show.rb +++ b/lib/active_scaffold/actions/show.rb @@ -52,7 +52,7 @@ def show_authorized?(record = nil) (record || self).send(:authorized_for?, :crud_type => :read) end def show_ignore?(record = nil) - self.send(:authorized_for?, :crud_type => :read) + !self.send(:authorized_for?, :crud_type => :read) end private def show_authorized_filter diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index c793bac8f3..1c5a13b4a3 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -159,7 +159,7 @@ def update_authorized?(record = nil) (!nested? || !nested.readonly?) && (record || self).authorized_for?(:crud_type => :update) end def update_ignore?(record = nil) - self.authorized_for?(:crud_type => :update) + !self.authorized_for?(:crud_type => :update) end private def update_authorized_filter From 92ee234abd6a785e500a17f68876e8ada9a99041 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 14 Dec 2012 19:17:54 +0100 Subject: [PATCH 1783/2024] move sortable to plugin --- app/assets/javascripts/jquery/active_scaffold.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 34ac37fdcc..2a4e6c2f0d 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -700,21 +700,6 @@ var ActiveScaffold = { } }, - sortable: function(element, controller, options, url_params) { - if (typeof(element) == 'string') element = '#' + element; - var element = jQuery(element); - var sortable_options = jQuery.extend({}, options); - if (options.update === true) { - url_params.authenticity_token = jQuery('meta[name=csrf-param]').attr('content'); - sortable_options.update = function(event, ui) { - var url = controller + '/' + options.action + '?' - url += jQuery(this).sortable('serialize',{key: encodeURIComponent(jQuery(this).attr('id') + '[]'), expression:/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/}); - jQuery.post(url.append_params(url_params)); - } - } - element.sortable(sortable_options); - }, - record_select_onselect: function(edit_associated_url, active_scaffold_id, id){ jQuery.ajax({ url: edit_associated_url.split('--ID--').join(id), From 84cd7bb756a6813061625b009f8fa60aba3d98f1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 17 Dec 2012 18:55:58 +0100 Subject: [PATCH 1784/2024] group related rows (tr) in tbody, it simplifies removing row with associated rows and sorting them --- .../javascripts/jquery/active_scaffold.js | 13 +++++-------- .../_form_association_record.html.erb | 19 +++++++++++++++++-- .../_horizontal_subform.html.erb | 17 ++++------------- .../_vertical_subform.html.erb | 7 ++----- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 2a4e6c2f0d..60823bc600 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -557,12 +557,7 @@ var ActiveScaffold = { delete_subform_record: function(record) { if (typeof(record) == 'string') record = '#' + record; - record = jQuery(record); - var errors = record.prev(); - if (errors.hasClass('association-record-errors')) { - this.remove(errors); - } - record = jQuery(record).nextUntil('.association-record').andSelf(); + record = jQuery(record).closest('.sub-form-record'); this.remove(record); }, @@ -668,11 +663,13 @@ var ActiveScaffold = { content = jQuery(content); if (options.singular == false) { if (!(options.id && jQuery('#' + options.id).size() > 0)) { - var new_element = element.append(content); + var tfoot = element.find('tfoot'); + if (tfoot.length) tfoot.before(content); + else element.append(content); content.trigger('as:element_created'); } } else { - var current = jQuery('#' + element.attr('id') + ' .association-record') + var current = jQuery('#' + element.attr('id') + ' .sub-form-record') if (current[0]) { this.replace(current[0], content); } else { diff --git a/app/views/active_scaffold_overrides/_form_association_record.html.erb b/app/views/active_scaffold_overrides/_form_association_record.html.erb index 167f717e8d..7650b26a8a 100644 --- a/app/views/active_scaffold_overrides/_form_association_record.html.erb +++ b/app/views/active_scaffold_overrides/_form_association_record.html.erb @@ -8,20 +8,34 @@ tr_id = "association-#{options[:id]}" if config.subform.layout == :vertical + record_tag ||= :div row_tag ||= :ol column_tag ||= :li + error_tag ||= :div + error_inner_tag ||= nil default_col_class = ['form-element'] flatten = true unless local_assigns.has_key? :flatten else + record_tag ||= :tbody row_tag ||= :tr column_tag ||= :td + error_tag ||= :tr + error_inner_tag ||= :td default_col_class = [] flatten ||= false end + index ||= nil columns_length = 0 columns_groups = [] -%> +<<%= record_tag %> class="sub-form-record"> +<% unless @record.errors.empty? -%> +<%= content_tag error_tag, :class => "association-record-errors", :id => element_messages_id(:action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}") do %> + <% errors = active_scaffold_error_messages_for(:record, :object_name => @record.class.model_name.human.downcase) %> + <%= error_inner_tag ? content_tag(error_inner_tag, errors, :colspan => (active_scaffold_config_for(@record.class).subform.columns.length + 1 if error_inner_tag == :td)) : errors %> +<% end %> +<% end %> <%= content_tag row_tag, :id => tr_id, :class => "association-record#{' association-record-new' if @record.new_record?}#{' locked' if locked}" do %> <% config.subform.columns.each :for => @record.class, :crud_type => :read, :flatten => flatten do |column| %> <% @@ -61,10 +75,11 @@ <% columns_groups.each do |column| %> <%= content_tag row_tag, :class => 'associated-record' do %> - <%= content_tag column_tag, :colspan => columns_length do %> + <%= content_tag column_tag, :colspan => (columns_length if column_tag == :td) do %> <% column.each :for => @record.class, :crud_type => :read, :flatten => true do |col| %> <%= active_scaffold_render_subform_column(col, scope, crud_type, readonly, true) %> <% end %> <% end %> <% end %> -<% end %> \ No newline at end of file +<% end %> +</<%= record_tag %>> diff --git a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb index ac8406ef41..22c1e09fe6 100644 --- a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +++ b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb @@ -1,20 +1,11 @@ -<table cellpadding="0" cellspacing="0"> +<table cellpadding="0" cellspacing="0" id="<%= sub_form_list_id(:association => column.name) %>"> <% @record = associated.empty? ? build_associated(column, parent_record) : associated.last -%> <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record, :record => @record} %> - <tbody id="<%= sub_form_list_id(:association => column.name) %>"> - <% associated.each_index do |index| %> + <% associated.each_index do |index| %> <% @record = associated[index] -%> - <% if @record.errors.count -%> - <tr class="association-record-errors"> - <td colspan="<%= active_scaffold_config_for(@record.class).subform.columns.length + 1 %>" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>"> - <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> - </td> - </tr> - <% end %> - <%= render :partial => 'form_association_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> - <% end -%> - </tbody> + <%= render :partial => 'form_association_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last, :index => index} %> + <% end -%> <tfoot> <%= render :partial => 'horizontal_subform_footer', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column} %> </tfoot> diff --git a/app/views/active_scaffold_overrides/_vertical_subform.html.erb b/app/views/active_scaffold_overrides/_vertical_subform.html.erb index 3ae089448e..cef0162ae2 100644 --- a/app/views/active_scaffold_overrides/_vertical_subform.html.erb +++ b/app/views/active_scaffold_overrides/_vertical_subform.html.erb @@ -1,11 +1,8 @@ <div id="<%= sub_form_list_id(:association => column.name) %>"> <% associated.each_index do |index| %> + <div class="sub-form-record"> <% @record = associated[index] -%> - <% if @record.errors.count -%> - <div class="association-record-errors" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>"> - <%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %> + <%= render :partial => 'form_association_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last, :index => index} %> </div> - <% end %> - <%= render :partial => 'form_association_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last} %> <% end -%> </div> From 5d1ca155ee5da1a820f75022a1f4ab32650a6c57 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Tue, 18 Dec 2012 15:18:50 +0100 Subject: [PATCH 1785/2024] update gems --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 951cbaee42..21a32921f5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ GEM remote: http://rubygems.org/ specs: json (1.6.3) - rake (0.9.2.2) + rake (10.0.3) rcov (0.9.9) rdoc (3.11) json (~> 1.4) From 5584b9532bea48762add634b4d08286c19260fb5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Wed, 19 Dec 2012 14:15:00 +0100 Subject: [PATCH 1786/2024] fix double .sub-form-record in vertical subforms --- app/views/active_scaffold_overrides/_vertical_subform.html.erb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/active_scaffold_overrides/_vertical_subform.html.erb b/app/views/active_scaffold_overrides/_vertical_subform.html.erb index cef0162ae2..1cde1bd48e 100644 --- a/app/views/active_scaffold_overrides/_vertical_subform.html.erb +++ b/app/views/active_scaffold_overrides/_vertical_subform.html.erb @@ -1,8 +1,6 @@ <div id="<%= sub_form_list_id(:association => column.name) %>"> <% associated.each_index do |index| %> - <div class="sub-form-record"> <% @record = associated[index] -%> <%= render :partial => 'form_association_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last, :index => index} %> - </div> <% end -%> </div> From dcfaa59f1e9c139ce08fc4bacebfc772c4f7cffc Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 20 Dec 2012 16:02:13 +0100 Subject: [PATCH 1787/2024] support changing select with custom HTML on replace_existing --- app/assets/javascripts/jquery/active_scaffold.js | 4 +++- app/assets/javascripts/prototype/active_scaffold.js | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 60823bc600..3658b3c047 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -153,7 +153,9 @@ jQuery(document).ready(function($) { return true; }); jQuery(document).on('ajax:before', 'a.as_add_existing, a.as_replace_existing', function(event) { - var id = jQuery(this).prev().val(); + var prev = jQuery(this).prev(); + if (!prev.is(':input')) prev = prev.find(':input'); + var id = prev.val(); if (id) { if (!jQuery(this).data('href')) jQuery(this).data('href', jQuery(this).attr('href')); jQuery(this).attr('href', jQuery(this).data('href').replace('--ID--', id)); diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index c396b1b680..ff323c7267 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -244,9 +244,13 @@ document.observe("dom:loaded", function() { }); document.on('ajax:before', 'a.as_add_existing, a.as_replace_existing', function(event) { var button = event.findElement(); - var url = button.readAttribute('href').sub('--ID--', button.previous().getValue()); - event.memo.url = url; - return true; + var prev = button.previous(); + if (!prev.match('input,select')) prev = prev.down('input,select'); + var id = prev.getValue(); + if (id) { + event.memo.url = button.readAttribute('href').sub('--ID--', id); + return true; + } else return false; }); document.on('change', 'input.update_form, textarea.update_form, select.update_form', function(event) { var element = event.findElement(); From cc061dfa76d31033f9a7da7c9959d20b237da9d3 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 20 Dec 2012 18:11:38 +0100 Subject: [PATCH 1788/2024] fix render :super multiple times in different views --- lib/active_scaffold/extensions/action_view_rendering.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 239b93747e..d915ad1db1 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -80,19 +80,20 @@ def render_with_active_scaffold(*args, &block) options[:prefixes] = lookup_context.prefixes.drop((lookup_context.prefixes.find_index(prefix) || -1) + 1) else options[:prefixes] = ['active_scaffold_overrides'] - view_paths = lookup_context.view_paths last_view_path = File.expand_path(File.dirname(File.dirname(lookup_context.last_template.inspect)), Rails.root) lookup_context.view_paths = view_paths.drop(view_paths.find_index {|path| path.to_s == last_view_path} + 1) end result = render_without_active_scaffold options - lookup_context.view_paths = view_paths if view_paths + lookup_context.view_paths = @_view_paths if @_view_paths result else + @_view_paths ||= lookup_context.view_paths.clone last_template = lookup_context.last_template if args.first.is_a?(Hash) current_view = {:locals => args.first[:locals]} view_stack << current_view end + lookup_context.view_paths = @_view_paths # reset view_paths in case a view render :super, and then render :partial result = render_without_active_scaffold(*args, &block) view_stack.pop if current_view.present? lookup_context.last_template = last_template From 824446cb1c6f4c68ed5c132530892f3124a80863 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 21 Dec 2012 06:51:01 -1000 Subject: [PATCH 1789/2024] Use step options when setting current time --- vendor/assets/javascripts/jquery-ui-timepicker-addon.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vendor/assets/javascripts/jquery-ui-timepicker-addon.js b/vendor/assets/javascripts/jquery-ui-timepicker-addon.js index 5a0f59821c..299e85028f 100644 --- a/vendor/assets/javascripts/jquery-ui-timepicker-addon.js +++ b/vendor/assets/javascripts/jquery-ui-timepicker-addon.js @@ -621,19 +621,19 @@ if (this.hour_slider) { this.control.options(this, this.hour_slider, 'hour', { min: this._defaults.hourMin, max: hourMax }); - this.control.value(this, this.hour_slider, 'hour', this.hour); + this.control.value(this, this.hour_slider, 'hour', this.hour - this.hour % this._defaults.stepHour); } if (this.minute_slider) { this.control.options(this, this.minute_slider, 'minute', { min: this._defaults.minuteMin, max: minMax }); - this.control.value(this, this.minute_slider, 'minute', this.minute); + this.control.value(this, this.minute_slider, 'minute', this.minute - this.minute % this._defaults.stepMinute); } if (this.second_slider) { this.control.options(this, this.second_slider, 'second', { min: this._defaults.secondMin, max: secMax }); - this.control.value(this, this.second_slider, 'second', this.second); + this.control.value(this, this.second_slider, 'second', this.second - this.second % this._defaults.stepSecond); } if (this.millisec_slider) { this.control.options(this, this.millisec_slider, 'millisec', { min: this._defaults.millisecMin, max: millisecMax }); - this.control.value(this, this.millisec_slider, 'millisec', this.millisec); + this.control.value(this, this.millisec_slider, 'millisec', this.millisec - this.millisec % this._defaults.stepMillisec); } } From 7a65715bd6f3c3cd02678ef9b09314834df8fd21 Mon Sep 17 00:00:00 2001 From: Yuri Kovalov <yuri@yurikoval.com> Date: Tue, 25 Dec 2012 15:31:53 +0900 Subject: [PATCH 1790/2024] Allow the use of symbol and string in action_link config. --- lib/active_scaffold/data_structures/action_links.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index ba342cc744..0922102e3b 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -49,7 +49,7 @@ def [](val) collected = item[val] links << collected unless collected.nil? else - links << item if item.action == val.to_s + links << item if item.action.to_s == val.to_s end end links.first From 7f03b2bb9a922f7ee5c08d0496778a1f68185c50 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 26 Dec 2012 09:23:45 +0100 Subject: [PATCH 1791/2024] complete datetime if people write only date --- lib/active_scaffold/finder.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index a4066ce563..46dd16f5d4 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -137,6 +137,11 @@ def condition_value_for_datetime(value, conversion = :to_time) time_parts = [[:hour, '%H'], [:min, '%M'], [:sec, '%S']].collect {|part, format_part| format_part if parts[part].present?}.compact format = "#{I18n.t('date.formats.default')} #{time_parts.join(':')} #{'%z' if parts[:offset].present?}" else + if parts[:hour] + value += time_parts = [:min, :sec].collect {|part| ':00' unless parts[part].present?}.compact.join + else + value += ' 00:00:00' + end format += ' %z' if parts[:offset].present? && format !~ /%z/i end time = DateTime.strptime(value, format) From 8f5281eff19e666d62157e805bc7318b3bf8079e Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 26 Dec 2012 23:35:53 -1000 Subject: [PATCH 1792/2024] fix view paths when first rendering is :super --- lib/active_scaffold/extensions/action_view_rendering.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index d915ad1db1..8a5dd76b85 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -70,6 +70,7 @@ def render_with_active_scaffold(*args, &block) end elsif args.first == :super + @_view_paths ||= lookup_context.view_paths.clone prefix, template = @virtual_path.split('/') options = args[1] || {} options[:locals] ||= {} From 4afd54599a434b44c0cfb458cda2f1b2ac339f3b Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 27 Dec 2012 14:40:06 +0100 Subject: [PATCH 1793/2024] column_value_for_<column_type>_type methods so form_ui can define conversion methods in controller, like conversion methods for field_search --- lib/active_scaffold/attribute_params.rb | 17 ++++++++++++++++- lib/active_scaffold/bridges/date_picker/ext.rb | 12 ++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 895131877b..a8cded06eb 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -91,12 +91,27 @@ def manage_nested_record_from_params(parent_record, column, attributes) def column_value_from_param_value(parent_record, column, value) # convert the value, possibly by instantiating associated objects - if value.is_a?(Hash) + form_ui = column.form_ui || column.column.try(:type) + if form_ui && self.respond_to?("column_value_for#{form_ui}_type") + self.send("column_value_for#{form_ui}_type", parent_record, column, value) + elsif value.is_a?(Hash) column_value_from_param_hash_value(parent_record, column, value) else column_value_from_param_simple_value(parent_record, column, value) end end + + def datetime_conversion_for_value(column) + if column.column + column.column.type == :date ? :to_date : :to_time + else + :to_time + end + end + + def column_value_for_datetime_type(parent_record, column, value) + self.class.condition_value_for_datetime(value, self.class.datetime_conversion_for_condition(column)) + end def column_value_from_param_simple_value(parent_record, column, value) if column.singular_association? diff --git a/lib/active_scaffold/bridges/date_picker/ext.rb b/lib/active_scaffold/bridges/date_picker/ext.rb index f7429ad530..08da977ef1 100644 --- a/lib/active_scaffold/bridges/date_picker/ext.rb +++ b/lib/active_scaffold/bridges/date_picker/ext.rb @@ -61,3 +61,15 @@ def datetime_conversion_for_condition_with_datepicker(column) alias_method :condition_for_date_picker_type, :condition_for_date_bridge_type alias_method :condition_for_datetime_picker_type, :condition_for_date_picker_type end +ActiveScaffold::AttributeParams.module_eval do + def datetime_conversion_for_value_with_datepicker(column) + if column.form_ui == :date_picker + :to_date + else + datetime_conversion_for_value_without_datepicker(column) + end + end + alias_method_chain :datetime_conversion_for_value, :datepicker + alias_method :column_value_for_date_picker_type, :column_value_for_datetime_type + alias_method :column_value_for_datetime_picker_type, :column_value_for_datetime_type +end From b82eac8ef7ff52bb730c35ddb6d531c7ea8b3f66 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Thu, 27 Dec 2012 14:52:28 +0100 Subject: [PATCH 1794/2024] fix name for column_value_for_<column_type>_type methods --- lib/active_scaffold/attribute_params.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index a8cded06eb..e9462e3936 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -92,8 +92,8 @@ def manage_nested_record_from_params(parent_record, column, attributes) def column_value_from_param_value(parent_record, column, value) # convert the value, possibly by instantiating associated objects form_ui = column.form_ui || column.column.try(:type) - if form_ui && self.respond_to?("column_value_for#{form_ui}_type") - self.send("column_value_for#{form_ui}_type", parent_record, column, value) + if form_ui && self.respond_to?("column_value_for_#{form_ui}_type") + self.send("column_value_for_#{form_ui}_type", parent_record, column, value) elsif value.is_a?(Hash) column_value_from_param_hash_value(parent_record, column, value) else From 0ca82f360c2b5cae77bcc193ec09cbeedee74601 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 10 Jan 2013 03:12:36 -1000 Subject: [PATCH 1795/2024] minutes and seconds are not required to parse datetime --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 46dd16f5d4..33f1c60246 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -138,7 +138,7 @@ def condition_value_for_datetime(value, conversion = :to_time) format = "#{I18n.t('date.formats.default')} #{time_parts.join(':')} #{'%z' if parts[:offset].present?}" else if parts[:hour] - value += time_parts = [:min, :sec].collect {|part| ':00' unless parts[part].present?}.compact.join + [[:min, '%M'], [:sec, '%S']].each {|part, f| format.gsub!(":#{f}", '') unless parts[part].present?} else value += ' 00:00:00' end From da2e7c21a0872d2786eacbd70c1c872e424add2c Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 14 Jan 2013 12:19:02 -1000 Subject: [PATCH 1796/2024] remove record from list if it doesn't fullfil current conditions after updating it --- app/views/active_scaffold_overrides/on_update.js.erb | 7 ++++++- lib/active_scaffold/actions/update.rb | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/views/active_scaffold_overrides/on_update.js.erb b/app/views/active_scaffold_overrides/on_update.js.erb index 3486e86ada..4042e51280 100644 --- a/app/views/active_scaffold_overrides/on_update.js.erb +++ b/app/views/active_scaffold_overrides/on_update.js.erb @@ -1,5 +1,5 @@ try { -<% form_selector = "#{element_form_id(:action => :update, :id => @record.id)}" %> +<% form_selector = "#{element_form_id(:action => :update, :id => @record.try(:id) || params[:id])}" %> var action_link = ActiveScaffold.find_action_link('<%= form_selector %>'); action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'messages')) %>'); <% if controller.send :successful? %> @@ -18,7 +18,12 @@ action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'mes <% elsif update_refresh_list? %> <%= render :partial => 'refresh_list' %> <% else %> + <% if @record %> action_link.close('<%= escape_javascript(render(:partial => 'list_record', :locals => {:record => @record})) %>'); + <% else %> + action_link.close(); + ActiveScaffold.delete_record_row('<%= element_row_id(:action => :list, :id => params[:id]) %>'); + <% end %> <%= render :partial => 'update_calculations', :formats => [:js] %> <% end %> <% end %> diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 1c5a13b4a3..941735b6f7 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -52,7 +52,8 @@ def update_respond_to_js if update_refresh_list? do_refresh_list else - get_row + # get_row so associations are cached like in list action + @record = get_row rescue nil # if record doesn't fullfil current conditions remove it from list end end flash.now[:info] = as_(:updated_model, :model => @record.to_label) if active_scaffold_config.update.persistent From 1b7466105244f566e163aca02cad8425f306d4f6 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 14 Jan 2013 13:54:32 -1000 Subject: [PATCH 1797/2024] skip contraint columns for sorting --- lib/active_scaffold/config/list.rb | 4 ++++ lib/active_scaffold/data_structures/sorting.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 5c57ab59be..0cb04cc831 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -230,6 +230,10 @@ def sorting @sorting = sorting else @sorting = default_sorting + if @conf.columns.constraint_columns.present? + @sorting = @sorting.clone + @sorting.constraint_columns = @conf.columns.constraint_columns + end end end @sorting diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 6b17cc5e5f..7358635de9 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -3,9 +3,12 @@ module ActiveScaffold::DataStructures class Sorting include Enumerable + attr_accessor :constraint_columns + def initialize(columns) @columns = columns @clauses = [] + @constraint_columns = [] end def set_default_sorting(model) @@ -91,6 +94,7 @@ def clause # unless the sorting is by method, create the sql string order = [] each do |sort_column, sort_direction| + next if constraint_columns.include? sort_column.name sql = sort_column.sort[:sql] next if sql.nil? or sql.empty? From 99404eb1bad99eb9569af1e9623900408e227396 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Tue, 15 Jan 2013 10:01:22 -1000 Subject: [PATCH 1798/2024] add description to header on horizontal subforms --- .../_horizontal_subform_header.html.erb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb b/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb index 59281f73b3..f4def5d3c5 100644 --- a/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +++ b/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb @@ -6,7 +6,12 @@ next unless in_subform?(column, parent_record) hidden = column_renders_as(column) == :hidden -%> - <th class="<%= "#{column.name}-column #{'required' if column.required?} #{'hidden' if hidden}" %>"><label><%= column.label unless hidden %></label></th> + <th class="<%= "#{column.name}-column #{'required' if column.required?} #{'hidden' if hidden}" %>"> + <label><%= column.label unless hidden %></label> + <% if column.description.present? -%> + <span class="description"><%= column.description %></span> + <% end -%> + </th> <% end -%> </tr> </thead> From 0199a9fadb9b3a46ba457391aef432336754a925 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 16 Jan 2013 12:33:36 -1000 Subject: [PATCH 1799/2024] add field_attributes helper --- .../active_scaffold_overrides/_form_attribute.html.erb | 6 +++++- lib/active_scaffold/helpers/form_column_helpers.rb | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_form_attribute.html.erb b/app/views/active_scaffold_overrides/_form_attribute.html.erb index 1529e5ba1e..9bcf06787b 100644 --- a/app/views/active_scaffold_overrides/_form_attribute.html.erb +++ b/app/views/active_scaffold_overrides/_form_attribute.html.erb @@ -1,8 +1,12 @@ <% scope ||= nil column_options = active_scaffold_input_options(column, scope) + attributes = field_attributes(column, @record) + if local_assigns[:col_class].present? + attributes[:class] = "#{attributes[:class]} #{col_class}" + end %> -<dl<%= " class=\"#{col_class}\"".html_safe if local_assigns[:col_class].present? %>> +<%= tag :dl, attributes, true %> <dt> <label for="<%= column_options[:id] %>"><%= column.label %></label> </dt> diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 117afea392..688463d580 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -128,6 +128,10 @@ def update_columns_options(column, scope, options) options end + def field_attributes(column, record) + {} + end + ## ## Form input methods ## From 8eaa742b0917bed94541a41f87c1c29a49d04cc4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 16 Jan 2013 12:48:32 -1000 Subject: [PATCH 1800/2024] update changelog --- CHANGELOG | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 06d7fc718b..a4070f7094 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,14 @@ - Fix calculations using field_search with has_many includes - Add support to ActiveScaffold.create_record_row to insert after or before of an element - Add support for dynamic action group +- Improve parsing of datetimes +- Add support for lists filtered by id (one-item lists) +- Fix update_columns with sending whole big forms +- Improve update_columns on subforms +- Support to override ActiveScaffold.remove so effects can be added on page elements deletion +- Add support for conversion methods in controller, so form_uis can define how to convert params to values +- Avoid sorting by contraint columns +- Cosmetic fixes and improvements = 3.2.17 (not released yet) - fix constraints for columns with multiple columns in search_sql From c1bead6e9c16cf7f062a3eb19244443966b26e40 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 16 Jan 2013 15:01:18 -1000 Subject: [PATCH 1801/2024] use instance variable for column on render_field --- lib/active_scaffold/actions/core.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 06e044e547..17bacb04e2 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -33,14 +33,14 @@ def render_field_for_inplace_editing end def render_field_for_update_columns - column = active_scaffold_config.columns[params.delete(:column)] - unless column.nil? + @column = active_scaffold_config.columns[params.delete(:column)] + unless @column.nil? @source_id = params.delete(:source_id) - @columns = column.update_columns + @columns = @column.update_columns @scope = params.delete(:scope) @main_columns = active_scaffold_config.send(@scope ? :subform : (params[:id] ? :update : :create)).columns - if column.send_form_on_update_column + if @column.send_form_on_update_column if @scope hash = @scope.gsub('[','').split(']').inject(params[:record]) do |hash, index| hash[index] @@ -54,11 +54,11 @@ def render_field_for_update_columns @record = update_record_from_params(@record, @main_columns, hash) else @record = new_model - value = column_value_from_param_value(@record, column, params.delete(:value)) - @record.send "#{column.name}=", value + value = column_value_from_param_value(@record, @column, params.delete(:value)) + @record.send "#{@column.name}=", value end - after_render_field(@record, column) + after_render_field(@record, @column) end end From f8a6288249550e948040a51f1b82b9645d35ff45 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 17 Jan 2013 15:37:00 -1000 Subject: [PATCH 1802/2024] don't render adapter if response is js --- .../extensions/action_controller_rendering.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/extensions/action_controller_rendering.rb b/lib/active_scaffold/extensions/action_controller_rendering.rb index da5e5e7e42..62220548ba 100644 --- a/lib/active_scaffold/extensions/action_controller_rendering.rb +++ b/lib/active_scaffold/extensions/action_controller_rendering.rb @@ -6,10 +6,14 @@ def render_with_active_scaffold(*args, &block) @rendering_adapter = true # recursion control # if we need an adapter, then we render the actual stuff to a string and insert it into the adapter template opts = args.blank? ? Hash.new : args.first - render :partial => params[:adapter][1..-1], - :locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe}, - :use_full_path => true, :layout => false, :content_type => :html - @rendering_adapter = nil # recursion control + unless opts[:js] || opts[:formats] == [:js] + render :partial => params[:adapter][1..-1], + :locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe}, + :use_full_path => true, :layout => false, :content_type => :html + @rendering_adapter = nil # recursion control + else + render_without_active_scaffold(*args, &block) + end else render_without_active_scaffold(*args, &block) end From 271200fd926e80fc40682c5ddbb4144217645f2c Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 17 Jan 2013 15:56:46 -1000 Subject: [PATCH 1803/2024] fix last commit --- lib/active_scaffold/extensions/action_controller_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_controller_rendering.rb b/lib/active_scaffold/extensions/action_controller_rendering.rb index 62220548ba..6020ae8731 100644 --- a/lib/active_scaffold/extensions/action_controller_rendering.rb +++ b/lib/active_scaffold/extensions/action_controller_rendering.rb @@ -6,7 +6,7 @@ def render_with_active_scaffold(*args, &block) @rendering_adapter = true # recursion control # if we need an adapter, then we render the actual stuff to a string and insert it into the adapter template opts = args.blank? ? Hash.new : args.first - unless opts[:js] || opts[:formats] == [:js] + unless opts[:js] || (opts[:formats] || lookup_context.formats).include?(:js) render :partial => params[:adapter][1..-1], :locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe}, :use_full_path => true, :layout => false, :content_type => :html From 145e9b0f152e421901d0b5f73a4b94f2b7d2b980 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 17 Jan 2013 16:28:11 -1000 Subject: [PATCH 1804/2024] fix last commit, it broke ajax actions --- lib/active_scaffold/extensions/action_controller_rendering.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_controller_rendering.rb b/lib/active_scaffold/extensions/action_controller_rendering.rb index 6020ae8731..51c89eed4e 100644 --- a/lib/active_scaffold/extensions/action_controller_rendering.rb +++ b/lib/active_scaffold/extensions/action_controller_rendering.rb @@ -6,7 +6,7 @@ def render_with_active_scaffold(*args, &block) @rendering_adapter = true # recursion control # if we need an adapter, then we render the actual stuff to a string and insert it into the adapter template opts = args.blank? ? Hash.new : args.first - unless opts[:js] || (opts[:formats] || lookup_context.formats).include?(:js) + unless opts[:js] || opts[:formats] == [:js] || opts[:partial].blank? render :partial => params[:adapter][1..-1], :locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe}, :use_full_path => true, :layout => false, :content_type => :html From c39009e90231b58ac235ba7f550c0405dc1eec4d Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 16 Jan 2013 09:15:03 +0100 Subject: [PATCH 1805/2024] update changelog, 3.2.17 was released --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a4070f7094..2f1a2995d3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -24,7 +24,7 @@ - Avoid sorting by contraint columns - Cosmetic fixes and improvements -= 3.2.17 (not released yet) += 3.2.17 - fix constraints for columns with multiple columns in search_sql - remove unauthorized collection links - copy parameters and html_options on cloning action link From 5d79bc266c310fa26bba81be5a43b6940f65e235 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 18 Jan 2013 19:12:11 +0100 Subject: [PATCH 1806/2024] add missing preventDefault and stop --- app/assets/javascripts/jquery/active_scaffold.js | 3 ++- app/assets/javascripts/prototype/active_scaffold.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 3658b3c047..689df9fbde 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -652,7 +652,8 @@ var ActiveScaffold = { var initial_label = (options.default_visible === true) ? options.hide_label : options.show_label; toggler.append(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)'); - toggler.children('a').click(function() { + toggler.children('a').click(function(e) { + e.preventDefault(); toggable.toggle(); jQuery(this).html((toggable.is(':hidden')) ? options.show_label : options.hide_label); return false; diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index ff323c7267..168dc247f2 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -603,6 +603,7 @@ var ActiveScaffold = { toggler.insert(' (<a class="visibility-toggle" href="#">' + initial_label + '</a>)'); toggler.firstDescendant().observe('click', function(event) { var element = event.element(); + event.stop(); toggable.toggle(); element.innerHTML = (toggable.style.display == 'none') ? options.show_label : options.hide_label; return false; From fd880cb09429d6464a0edb8116437e917d7e8cdf Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 18 Jan 2013 08:49:03 -1000 Subject: [PATCH 1807/2024] Revert "don't render adapter if response is js" This reverts commit f8a6288249550e948040a51f1b82b9645d35ff45. Conflicts: lib/active_scaffold/extensions/action_controller_rendering.rb --- .../extensions/action_controller_rendering.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/extensions/action_controller_rendering.rb b/lib/active_scaffold/extensions/action_controller_rendering.rb index 51c89eed4e..da5e5e7e42 100644 --- a/lib/active_scaffold/extensions/action_controller_rendering.rb +++ b/lib/active_scaffold/extensions/action_controller_rendering.rb @@ -6,14 +6,10 @@ def render_with_active_scaffold(*args, &block) @rendering_adapter = true # recursion control # if we need an adapter, then we render the actual stuff to a string and insert it into the adapter template opts = args.blank? ? Hash.new : args.first - unless opts[:js] || opts[:formats] == [:js] || opts[:partial].blank? - render :partial => params[:adapter][1..-1], - :locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe}, - :use_full_path => true, :layout => false, :content_type => :html - @rendering_adapter = nil # recursion control - else - render_without_active_scaffold(*args, &block) - end + render :partial => params[:adapter][1..-1], + :locals => {:payload => render_to_string(opts.merge(:layout => false), &block).html_safe}, + :use_full_path => true, :layout => false, :content_type => :html + @rendering_adapter = nil # recursion control else render_without_active_scaffold(*args, &block) end From abe35a4d3b92f47b5e9acf1ddad21524c9a10997 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Fri, 18 Jan 2013 16:52:38 -1000 Subject: [PATCH 1808/2024] clean description when is used as title --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 5f7484b0d5..6c4cd7d719 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -278,7 +278,7 @@ def mark_column_heading end def render_column_heading(column, sorting, sort_direction) - tag_options = {:id => active_scaffold_column_header_id(column), :class => column_heading_class(column, sorting), :title => column.description} + tag_options = {:id => active_scaffold_column_header_id(column), :class => column_heading_class(column, sorting), :title => strip_tags(column.description)} if column.name == :as_marked tag_options[:data] = { :ie_mode => :inline_checkbox, From 6755e8c648c3e765751a435ad032b8dacc04046e Mon Sep 17 00:00:00 2001 From: Peter Shoukry <pshoukry@gmail.com> Date: Mon, 21 Jan 2013 09:57:23 +0200 Subject: [PATCH 1809/2024] rewrites methods using jquery.live() to use jquery.on() as they are deprecated in jquery 1.9. - jquery api documentation for the live() method: http://api.jquery.com/live/ --- .../jquery/date_picker_bridge.js.erb | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/jquery/date_picker_bridge.js.erb b/app/assets/javascripts/jquery/date_picker_bridge.js.erb index c56a45529a..c0aef51c59 100644 --- a/app/assets/javascripts/jquery/date_picker_bridge.js.erb +++ b/app/assets/javascripts/jquery/date_picker_bridge.js.erb @@ -1,24 +1,22 @@ <%= ActiveScaffold::Bridges[:date_picker].localization %> - -jQuery(document).ready(function() { - jQuery('input.date_picker').live('focus', function(event) { - var date_picker = jQuery(this); - if (typeof(date_picker.datepicker) == 'function') { - if (!date_picker.hasClass('hasDatepicker')) { - date_picker.datepicker(); - date_picker.trigger('focus'); - } +jQuery(document).on("focus", "input.date_picker", function(){ + var date_picker = jQuery(this); + if (typeof(date_picker.datepicker) == 'function') { + if (!date_picker.hasClass('hasDatepicker')) { + date_picker.datepicker(); + date_picker.trigger('focus'); } - return true; - }); - jQuery('input.datetime_picker').live('focus', function(event) { - var date_picker = jQuery(this); - if (typeof(date_picker.datetimepicker) == 'function') { - if (!date_picker.hasClass('hasDatepicker')) { - date_picker.datetimepicker(); - date_picker.trigger('focus'); - } + } + return true; +}); + +jQuery(document).on("focus", "input.date_picker", function(){ + var date_picker = jQuery(this); + if (typeof(date_picker.datetimepicker) == 'function') { + if (!date_picker.hasClass('hasDatepicker')) { + date_picker.datetimepicker(); + date_picker.trigger('focus'); } - return true; - }); + } + return true; }); From 68492d44b0b77637c5e4947d4d067c2ebf857116 Mon Sep 17 00:00:00 2001 From: Peter Shoukry <pshoukry@gmail.com> Date: Mon, 21 Jan 2013 10:10:54 +0200 Subject: [PATCH 1810/2024] Fixes input.datetime_picker selector name --- app/assets/javascripts/jquery/date_picker_bridge.js.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/jquery/date_picker_bridge.js.erb b/app/assets/javascripts/jquery/date_picker_bridge.js.erb index c0aef51c59..01c8d56144 100644 --- a/app/assets/javascripts/jquery/date_picker_bridge.js.erb +++ b/app/assets/javascripts/jquery/date_picker_bridge.js.erb @@ -10,7 +10,7 @@ jQuery(document).on("focus", "input.date_picker", function(){ return true; }); -jQuery(document).on("focus", "input.date_picker", function(){ +jQuery(document).on("focus", "input.datetime_picker", function(){ var date_picker = jQuery(this); if (typeof(date_picker.datetimepicker) == 'function') { if (!date_picker.hasClass('hasDatepicker')) { @@ -19,4 +19,4 @@ jQuery(document).on("focus", "input.date_picker", function(){ } } return true; -}); +}); \ No newline at end of file From 5fbb2dc503dbe64499b15aa9d7e5df9a6134764a Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 21 Jan 2013 11:40:06 -1000 Subject: [PATCH 1811/2024] pass xhr to report_500_response so it can be overrided and do different actions depending on xhr status --- app/assets/javascripts/jquery/active_scaffold.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 689df9fbde..6bf4a2d87e 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -24,7 +24,7 @@ jQuery(document).ready(function($) { jQuery(document).on('ajax:error', 'form.as_form', function(event, xhr, status, error) { var as_div = jQuery(this).closest("div.active-scaffold"); if (as_div.length) { - ActiveScaffold.report_500_response(as_div); + ActiveScaffold.report_500_response(as_div, xhr); } }); jQuery(document).on('submit', 'form.as_form:not([data-remote])', function(event) { @@ -69,7 +69,7 @@ jQuery(document).ready(function($) { jQuery(document).on('ajax:error', 'a.as_action', function(event, xhr, status, error) { var action_link = ActiveScaffold.ActionLink.get(jQuery(this)); if (action_link) { - ActiveScaffold.report_500_response(action_link.scaffold_id()); + ActiveScaffold.report_500_response(action_link.scaffold_id(), xhr); action_link.enable(); } return true; @@ -103,7 +103,7 @@ jQuery(document).ready(function($) { jQuery(document).on('ajax:error', 'a.as_cancel', function(event, xhr, status, error) { var action_link = ActiveScaffold.find_action_link(jQuery(this)); if (action_link) { - ActiveScaffold.report_500_response(action_link.scaffold_id()); + ActiveScaffold.report_500_response(action_link.scaffold_id(), xhr); } return true; }); @@ -116,7 +116,7 @@ jQuery(document).ready(function($) { }); jQuery(document).on('ajax:error', 'a.as_sort', function(event, xhr, status, error) { var as_scaffold = jQuery(this).closest('.active-scaffold'); - ActiveScaffold.report_500_response(as_scaffold); + ActiveScaffold.report_500_response(as_scaffold, xhr); return true; }); jQuery(document).on('hover', 'td.in_place_editor_field', function(event) { @@ -145,7 +145,7 @@ jQuery(document).ready(function($) { }); jQuery(document).on('ajax:error', 'a.as_paginate', function(event, xhr, status, error) { var as_scaffold = jQuery(this).closest('.active-scaffold'); - ActiveScaffold.report_500_response(as_scaffold); + ActiveScaffold.report_500_response(as_scaffold, xhr); return true; }); jQuery(document).on('ajax:complete', 'a.as_paginate', function(event) { @@ -704,7 +704,7 @@ var ActiveScaffold = { jQuery.ajax({ url: edit_associated_url.split('--ID--').join(id), error: function(xhr, textStatus, errorThrown){ - ActiveScaffold.report_500_response(active_scaffold_id) + ActiveScaffold.report_500_response(active_scaffold_id, xhr) } }); }, @@ -863,7 +863,7 @@ var ActiveScaffold = { error: function (xhr, status, error) { var as_div = element.closest("div.active-scaffold"); if (as_div) { - ActiveScaffold.report_500_response(as_div); + ActiveScaffold.report_500_response(as_div, xhr); } } }); From 52ff24341a43320b7fabba08cc3da9ba038a4eb8 Mon Sep 17 00:00:00 2001 From: Novikov Andrey <envek@envek.name> Date: Tue, 22 Jan 2013 10:42:52 +1000 Subject: [PATCH 1812/2024] Fix error with 'Add existing record' using record_select --- .../active_scaffold_overrides/_form_association_footer.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_form_association_footer.html.erb b/app/views/active_scaffold_overrides/_form_association_footer.html.erb index 66c09693ef..51449637d0 100644 --- a/app/views/active_scaffold_overrides/_form_association_footer.html.erb +++ b/app/views/active_scaffold_overrides/_form_association_footer.html.erb @@ -34,7 +34,7 @@ add_new_url = params_for(:action => 'edit_associated', :child_association => col <% if show_add_existing -%> <% if remote_controller and remote_controller.respond_to? :uses_record_select? and remote_controller.uses_record_select? -%> - <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "ActiveScaffold.record_select_onselect(#{edit_associated_url.to_json}, #{active_scaffold_id.to_json}, id);" -%> + <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "ActiveScaffold.record_select_onselect(#{url_for(edit_associated_url).to_json}, #{active_scaffold_id.to_json}, id);" -%> <% else -%> <% select_options = options_from_collection_for_select(sorted_association_options_find(column.association), :id, :to_label) add_existing_id = "#{sub_form_id(:association => column.name)}-add-existing" From 71830e721c127d6c0fb4fa9789cf3abb347ff2c1 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 23 Jan 2013 08:41:27 -1000 Subject: [PATCH 1813/2024] fix #232, grouped_options_for_select conflict --- lib/active_scaffold/bridges/chosen/helpers.rb | 2 +- lib/active_scaffold/helpers/form_column_helpers.rb | 4 ++-- lib/active_scaffold/helpers/search_column_helpers.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/bridges/chosen/helpers.rb b/lib/active_scaffold/bridges/chosen/helpers.rb index 6b4c409f47..13f862cef0 100644 --- a/lib/active_scaffold/bridges/chosen/helpers.rb +++ b/lib/active_scaffold/bridges/chosen/helpers.rb @@ -20,7 +20,7 @@ def active_scaffold_input_chosen(column, html_options) html_options[:name] = "#{html_options[:name]}[]" if html_options[:multiple] == true && !html_options[:name].to_s.ends_with?("[]") if optgroup = options.delete(:optgroup) - select(:record, column.name, grouped_options_for_select(column, select_options, optgroup), options, html_options) + select(:record, column.name, active_scaffold_grouped_options(column, select_options, optgroup), options, html_options) else collection_select(:record, column.name, select_options, :id, :to_label, options, html_options) end diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 688463d580..50bd1277cb 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -136,7 +136,7 @@ def field_attributes(column, record) ## Form input methods ## - def grouped_options_for_select(column, select_options, optgroup) + def active_scaffold_grouped_options(column, select_options, optgroup) group_label = active_scaffold_config_for(column.association.klass).columns[optgroup].try(:association) ? :to_label : :to_s select_options.group_by(&optgroup.to_sym).collect do |group, options| [group.send(group_label), options.collect {|r| [r.to_label, r.id]}] @@ -164,7 +164,7 @@ def active_scaffold_input_singular_association(column, html_options) active_scaffold_translate_select_options(options) if optgroup = options.delete(:optgroup) - select(:record, method, grouped_options_for_select(column, select_options, optgroup), options, html_options) + select(:record, method, active_scaffold_grouped_options(column, select_options, optgroup), options, html_options) else collection_select(:record, method, select_options, :id, :to_label, options, html_options) end diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 4ca5fd0e8d..d96747763b 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -94,7 +94,7 @@ def active_scaffold_search_select(column, html_options) end if optgroup = options.delete(:optgroup) - select(:record, method, grouped_options_for_select(column, select_options, optgroup), options, html_options) + select(:record, method, active_scaffold_grouped_options(column, select_options, optgroup), options, html_options) elsif column.association collection_select(:record, method, select_options, :id, :to_label, options, html_options) else From 2fb3429e3171cfdb565888464825dca59bdba160 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 23 Jan 2013 12:13:26 -1000 Subject: [PATCH 1814/2024] view for inplace edit remote overriding --- .../active_scaffold_overrides/render_field_inplace.html.erb | 1 + lib/active_scaffold/actions/core.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 app/views/active_scaffold_overrides/render_field_inplace.html.erb diff --git a/app/views/active_scaffold_overrides/render_field_inplace.html.erb b/app/views/active_scaffold_overrides/render_field_inplace.html.erb new file mode 100644 index 0000000000..06448a7202 --- /dev/null +++ b/app/views/active_scaffold_overrides/render_field_inplace.html.erb @@ -0,0 +1 @@ +<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %> diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 17bacb04e2..a1b157239b 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -29,7 +29,7 @@ def nested? def render_field_for_inplace_editing @record = find_if_allowed(params[:id], :crud_type => :update, :column => params[:update_column]) - render :inline => "<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %>" + render :action => 'render_field_inplace', :layout => false end def render_field_for_update_columns From 1141e097be7b87b9a851ef7c76578f3456735ac4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 23 Jan 2013 12:27:37 -1000 Subject: [PATCH 1815/2024] set @column in render_field_inplace --- .../active_scaffold_overrides/render_field_inplace.html.erb | 2 +- lib/active_scaffold/actions/core.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/render_field_inplace.html.erb b/app/views/active_scaffold_overrides/render_field_inplace.html.erb index 06448a7202..337a4c9816 100644 --- a/app/views/active_scaffold_overrides/render_field_inplace.html.erb +++ b/app/views/active_scaffold_overrides/render_field_inplace.html.erb @@ -1 +1 @@ -<%= active_scaffold_input_for(active_scaffold_config.columns[params[:update_column].to_sym]) %> +<%= active_scaffold_input_for(active_scaffold_config.columns[@column.name]) %> diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index a1b157239b..53606adb06 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -28,6 +28,7 @@ def nested? end def render_field_for_inplace_editing + @column = active_scaffold_config.columns[params[:update_column]] @record = find_if_allowed(params[:id], :crud_type => :update, :column => params[:update_column]) render :action => 'render_field_inplace', :layout => false end From eb4f7869f0082b2bd83214e579b12accb83122df Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 24 Jan 2013 14:20:04 -1000 Subject: [PATCH 1816/2024] simplify old code --- lib/active_scaffold/actions/core.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 53606adb06..f5b0c7a620 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -71,11 +71,7 @@ def authorized_for?(options = {}) end def clear_flashes - if request.xhr? - flash.keys.each do |flash_key| - flash[flash_key] = nil - end - end + flash.clear if request.xhr? end def each_marked_record(&block) From d902f326630a04c04d456e44df742b40e457fd60 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Sun, 27 Jan 2013 12:03:58 +0100 Subject: [PATCH 1817/2024] fix parsing date and datetime using translated days and months --- lib/active_scaffold/attribute_params.rb | 2 +- .../calendar_date_select/as_cds_bridge.rb | 2 +- .../bridges/date_picker/helper.rb | 4 +-- .../bridges/shared/date_bridge.rb | 4 +-- lib/active_scaffold/finder.rb | 27 +++++++++++++++---- .../helpers/human_condition_helpers.rb | 6 ++--- 6 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index e9462e3936..73696b2e9d 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -110,7 +110,7 @@ def datetime_conversion_for_value(column) end def column_value_for_datetime_type(parent_record, column, value) - self.class.condition_value_for_datetime(value, self.class.datetime_conversion_for_condition(column)) + self.class.condition_value_for_datetime(column, value, self.class.datetime_conversion_for_condition(column)) end def column_value_from_param_simple_value(parent_record, column, value) diff --git a/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb b/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb index bfa20e1954..2dd4fdaf86 100644 --- a/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +++ b/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb @@ -34,7 +34,7 @@ def active_scaffold_input_calendar_date_select(column, options) module SearchColumnHelpers def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) if current_search.is_a? Hash - value = controller.class.condition_value_for_datetime(current_search[name], column.column.type == :date ? :to_date : :to_time) + value = controller.class.condition_value_for_datetime(column, current_search[name], column.column.type == :date ? :to_date : :to_time) else value = current_search end diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index 47cb2b7971..b617281d19 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -151,7 +151,7 @@ def datepicker_format_options(column, format, options) module SearchColumnHelpers def active_scaffold_search_date_bridge_calendar_control(column, options, current_search, name) if current_search.is_a? Hash - value = controller.class.condition_value_for_datetime(current_search[name], column.search_ui == :date_picker ? :to_date : :to_time) + value = controller.class.condition_value_for_datetime(column, current_search[name], column.search_ui == :date_picker ? :to_date : :to_time) else value = current_search end @@ -169,7 +169,7 @@ module FormColumnHelpers def active_scaffold_input_date_picker(column, options) options = active_scaffold_input_text_options(options.merge(column.options)) options[:class] << " #{column.form_ui.to_s}" - value = controller.class.condition_value_for_datetime(@record.send(column.name), column.form_ui == :date_picker ? :to_date : :to_time) + value = controller.class.condition_value_for_datetime(column, @record.send(column.name), column.form_ui == :date_picker ? :to_date : :to_time) format = options.delete(:format) || (column.form_ui == :date_picker ? :default : :picker) datepicker_format_options(column, format, options) options[:value] = (value ? l(value, :format => format) : nil) diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index 605be69958..c9290a302d 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -127,7 +127,7 @@ def date_bridge_from_to(column, value) when 'PAST', 'FUTURE' date_bridge_from_to_for_trend(column, value).collect(&conversion) else - ['from', 'to'].collect { |field| condition_value_for_datetime(value[field], conversion)} + ['from', 'to'].collect { |field| condition_value_for_datetime(column, value[field], conversion)} end end @@ -206,4 +206,4 @@ def date_bridge_column_date?(column) ActiveScaffold::Finder.const_set('DateRanges', ["TODAY", "YESTERDAY", "TOMORROW", "THIS_WEEK", "PREV_WEEK", "NEXT_WEEK", "THIS_MONTH", "PREV_MONTH", "NEXT_MONTH", - "THIS_YEAR", "PREV_YEAR", "NEXT_YEAR"]) \ No newline at end of file + "THIS_YEAR", "PREV_YEAR", "NEXT_YEAR"]) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 33f1c60246..610a552487 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -116,8 +116,24 @@ def condition_for_range(column, value, like_pattern = nil) nil end end + + def translate_days_and_months(value, format) + keys = { + '%A' => 'date.day_names', + '%a' => 'date.abbr_day_names', + '%B' => 'date.month_names', + '%b' => 'date.abbr_month_names' + } + keys.each do |f, k| + if format.include? f + table = Hash[I18n.t(k).compact.zip(I18n.t(k, :locale => :en).compact)] + value.gsub!(Regexp.union(table.keys)) { |s| table[s] } + end + end + value + end - def condition_value_for_datetime(value, conversion = :to_time) + def condition_value_for_datetime(column, value, conversion = :to_time) if value.is_a? Hash Time.zone.local(*[:year, :month, :day, :hour, :minute, :second].collect {|part| value[part].to_i}) rescue nil elsif value.respond_to?(:strftime) @@ -129,10 +145,10 @@ def condition_value_for_datetime(value, conversion = :to_time) value.send(conversion) end elsif conversion == :to_date - Date.strptime(value, I18n.t('date.formats.default')) rescue nil + Date.strptime(value, I18n.t("date.formats.#{column.options[:format] || :default}")) rescue nil else parts = Date._parse(value) - format = I18n.translate 'time.formats.picker', :default => '' if ActiveScaffold.js_framework == :jquery + format = I18n.translate "time.formats.#{column.options[:format] || :picker}", :default => '' if ActiveScaffold.js_framework == :jquery if format.blank? time_parts = [[:hour, '%H'], [:min, '%M'], [:sec, '%S']].collect {|part, format_part| format_part if parts[part].present?}.compact format = "#{I18n.t('date.formats.default')} #{time_parts.join(':')} #{'%z' if parts[:offset].present?}" @@ -144,6 +160,7 @@ def condition_value_for_datetime(value, conversion = :to_time) end format += ' %z' if parts[:offset].present? && format !~ /%z/i end + value = translate_days_and_months(value, format) if I18n.locale != :en time = DateTime.strptime(value, format) time = Time.zone.local_to_utc(time).in_time_zone unless parts[:offset] time = time.send(conversion) unless conversion == :to_time @@ -185,8 +202,8 @@ def datetime_conversion_for_condition(column) def condition_for_datetime(column, value, like_pattern = nil) conversion = datetime_conversion_for_condition(column) - from_value = condition_value_for_datetime(value[:from], conversion) - to_value = condition_value_for_datetime(value[:to], conversion) + from_value = condition_value_for_datetime(column, value[:from], conversion) + to_value = condition_value_for_datetime(column, value[:to], conversion) if from_value.nil? and to_value.nil? nil diff --git a/lib/active_scaffold/helpers/human_condition_helpers.rb b/lib/active_scaffold/helpers/human_condition_helpers.rb index ec0a02887c..2e611c7164 100644 --- a/lib/active_scaffold/helpers/human_condition_helpers.rb +++ b/lib/active_scaffold/helpers/human_condition_helpers.rb @@ -20,8 +20,8 @@ def active_scaffold_human_condition_for(column) "#{column.active_record_class.human_attribute_name(column.name)} #{as_(opt).downcase} '#{value[:from]}' #{opt == 'BETWEEN' ? '- ' + value[:to].to_s : ''}" when :date, :time, :datetime, :timestamp conversion = column.column.type == :date ? :to_date : :to_time - from = controller.condition_value_for_datetime(value[:from], conversion) - to = controller.condition_value_for_datetime(value[:to], conversion) + from = controller.condition_value_for_datetime(column, value[:from], conversion) + to = controller.condition_value_for_datetime(column, value[:to], conversion) "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value[:opt])} #{I18n.l(from)} #{value[:opt] == 'BETWEEN' ? '- ' + I18n.l(to) : ''}" when :select, :multi_select, :record_select associated = value @@ -61,4 +61,4 @@ def override_human_condition(search_ui) end end end -end \ No newline at end of file +end From 7da890c21b3e246dd09b781f16f61d9a69542041 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 28 Jan 2013 19:31:29 +0100 Subject: [PATCH 1818/2024] between needs both from and to, if from or to is nil won't work --- lib/active_scaffold/bridges/shared/date_bridge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index c9290a302d..9fbd38f6e6 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -114,7 +114,7 @@ def condition_for_date_bridge_type(column, value, like_pattern) unless operator.nil? ["%{search_sql} #{value[:opt]} ?", from_value.to_s(:db)] unless from_value.nil? else - ["%{search_sql} BETWEEN ? AND ?", from_value.to_s(:db), to_value.to_s(:db)] unless from_value.nil? && to_value.nil? + ["%{search_sql} BETWEEN ? AND ?", from_value.to_s(:db), to_value.to_s(:db)] unless from_value.nil? || to_value.nil? end end end From 6743680f07c348104af927b5c03af8dfb285dcf0 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 28 Jan 2013 10:05:27 -1000 Subject: [PATCH 1819/2024] remove use of deprecated features in 1.8.0 and removed in 1.9.0 --- .../javascripts/jquery/active_scaffold.js | 29 ++++++++----------- .../javascripts/jquery/draggable_lists.js | 3 +- .../javascripts/jquery/jquery.editinplace.js | 4 +++ 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 6bf4a2d87e..0bcd6f475b 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -1,4 +1,10 @@ jQuery(document).ready(function($) { + if (jQuery().jquery < '1.8.0') { + var error = 'ActiveScaffold requires jquery 1.8.0 or greater, please use jquery-rails 2.1.x gem or greater'; + if (typeof console != 'undefined') console.error(error); + else alert(error); + } + jQuery(document).click(function(event) { jQuery('.action_group.dyn ul').remove(); }); @@ -119,7 +125,7 @@ jQuery(document).ready(function($) { ActiveScaffold.report_500_response(as_scaffold, xhr); return true; }); - jQuery(document).on('hover', 'td.in_place_editor_field', function(event) { + jQuery(document).on('mouseenter mouseleave', 'td.in_place_editor_field', function(event) { var td = jQuery(this), span = td.find('span.in_place_editor_field'); if (event.type == 'mouseenter') { if (td.hasClass('empty') || typeof(span.data('editInPlace')) === 'undefined') td.find('span').addClass("hover"); @@ -685,7 +691,7 @@ var ActiveScaffold = { render_form_field: function(source, content, options) { if (typeof(source) == 'string') source = '#' + source; var source = jQuery(source); - var element = source.closest('.association-record').nextUntil('.association-record').andSelf(); + var element = source.closest('.association-record').nextUntil('.association-record').addBack(); if (element.length == 0) { element = source.closest('form > ol.form'); } @@ -715,24 +721,13 @@ var ActiveScaffold = { var element = jQuery(element); if (options.include_checkboxes) { var mark_checkboxes = jQuery('#' + element.attr('id') + ' > tr.record td.as_marked-column input[type="checkbox"]'); - mark_checkboxes.each(function (index) { - var item = jQuery(this); - if(options.checked) { - item.attr('checked', 'checked'); - } else { - item.removeAttr('checked'); - } - item.attr('value', ('' + !options.checked)); - }); + mark_checkboxes.prop('checked', !!options.checked); + mark_checkboxes.val('' + !options.checked); } if(options.include_mark_all) { var mark_all_checkbox = element.prevAll('thead').find('th.as_marked-column_heading span input[type="checkbox"]'); - if(options.checked) { - mark_all_checkbox.attr('checked', 'checked'); - } else { - mark_all_checkbox.removeAttr('checked'); - } - mark_all_checkbox.attr('value', ('' + !options.checked)); + mark_all_checkbox.prop('checked', !!options.checked); + mark_all_checkbox.val('' + !options.checked); } }, diff --git a/app/assets/javascripts/jquery/draggable_lists.js b/app/assets/javascripts/jquery/draggable_lists.js index c03baa8eee..92aa42ef2d 100644 --- a/app/assets/javascripts/jquery/draggable_lists.js +++ b/app/assets/javascripts/jquery/draggable_lists.js @@ -18,8 +18,7 @@ jQuery.fn.draggable_lists = function() { drop: function(event, ui) { jQuery(this).append(ui.draggable); var input = jQuery('input:checkbox', ui.draggable); - if (jQuery(this).hasClass('selected')) input.attr('checked', 'checked'); - else input.removeAttr('checked'); + input.prop('checked', jQuery(this).hasClass('selected')); ui.draggable.css({left: '0px', top: '0px'}); } }); diff --git a/app/assets/javascripts/jquery/jquery.editinplace.js b/app/assets/javascripts/jquery/jquery.editinplace.js index 7fc34a4dc3..bdaf3ecdba 100644 --- a/app/assets/javascripts/jquery/jquery.editinplace.js +++ b/app/assets/javascripts/jquery/jquery.editinplace.js @@ -420,8 +420,10 @@ $.extend(InlineEditor.prototype, { form.find(".inplace_field").blur(cancelEditorAction); // workaround for msie & firefox bug where it won't submit on enter if no button is shown + /* TODO find a way to restore it without $.browser if it doesn't work if ($.browser.mozilla || $.browser.msie) this.bindSubmitOnEnterInInput(); + */ } form.keyup(function(anEvent) { @@ -433,8 +435,10 @@ $.extend(InlineEditor.prototype, { // workaround for webkit nightlies where they won't submit at all on enter // REFACT: find a way to just target the nightlies + /* TODO find a way to restore it without $.browser if it doesn't work if ($.browser.safari) this.bindSubmitOnEnterInInput(); + */ form.submit(saveEditorAction); From e64fe4447948940c55d8b2c0a1ed8966f0acba9e Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 28 Jan 2013 10:11:58 -1000 Subject: [PATCH 1820/2024] update changelog --- CHANGELOG | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 2f1a2995d3..cef76836f1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -24,6 +24,10 @@ - Avoid sorting by contraint columns - Cosmetic fixes and improvements += 3.2.18 +- Fix add existing record with record_select +- Disable link for polymorphic associations in 3.2.x, it doesn't work + = 3.2.17 - fix constraints for columns with multiple columns in search_sql - remove unauthorized collection links From 1792e0463ebd26829045105365927f01102677c9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 28 Jan 2013 10:41:18 -1000 Subject: [PATCH 1821/2024] fix render :super for namespaced controllers, fixes #237 --- lib/active_scaffold/extensions/action_view_rendering.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 8a5dd76b85..4a955727df 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -71,7 +71,10 @@ def render_with_active_scaffold(*args, &block) elsif args.first == :super @_view_paths ||= lookup_context.view_paths.clone - prefix, template = @virtual_path.split('/') + parts = @virtual_path.split('/') + template = parts.pop + prefix = parts.join('/') + options = args[1] || {} options[:locals] ||= {} options[:locals] = view_stack.last[:locals].merge!(options[:locals]) if view_stack.last && view_stack.last[:locals] From 8c501b431d5e6115ac242e0a82a58e2594c977e5 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 28 Jan 2013 11:28:46 -1000 Subject: [PATCH 1822/2024] enable multipart form after update with apply button, fixes #219 --- CHANGELOG | 1 + app/views/active_scaffold_overrides/on_update.js.erb | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index cef76836f1..cf27db453b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,7 @@ - Add support for conversion methods in controller, so form_uis can define how to convert params to values - Avoid sorting by contraint columns - Cosmetic fixes and improvements +- Fix multipart persistent update form = 3.2.18 - Fix add existing record with record_select diff --git a/app/views/active_scaffold_overrides/on_update.js.erb b/app/views/active_scaffold_overrides/on_update.js.erb index 4042e51280..74d8b8c51d 100644 --- a/app/views/active_scaffold_overrides/on_update.js.erb +++ b/app/views/active_scaffold_overrides/on_update.js.erb @@ -8,6 +8,7 @@ action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'mes ActiveScaffold.update_row('<%= row_selector %>', '<%= escape_javascript(render(:partial => 'list_record', :locals => {:record => @record})) %>'); action_link.target = $('#<%= row_selector %>'); <%= render :partial => 'update_calculations', :formats => [:js] %> + <%= "ActiveScaffold.enable_form('#{form_selector}');" if params[:iframe] == 'true' %> <% else %> <% if render_parent? %> <% if nested_singular_association? || render_parent_action == :row %> From 4112241ac33a89abe5b86ec73f86179eb64bba7e Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Mon, 28 Jan 2013 14:50:23 -1000 Subject: [PATCH 1823/2024] update changelog --- CHANGELOG | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index cf27db453b..aa1e14feec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -25,6 +25,9 @@ - Cosmetic fixes and improvements - Fix multipart persistent update form += 3.2.19 (not released yet) +- Avoid crashing when between is chosen and from or to is not filled + = 3.2.18 - Fix add existing record with record_select - Disable link for polymorphic associations in 3.2.x, it doesn't work From 9001c624563e029d32e57e617d867210c51359e4 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 30 Jan 2013 10:23:58 -1000 Subject: [PATCH 1824/2024] display error message only when @record.errors is not empty --- app/views/active_scaffold_overrides/destroy.js.erb | 2 +- app/views/active_scaffold_overrides/on_action_update.js.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/active_scaffold_overrides/destroy.js.erb b/app/views/active_scaffold_overrides/destroy.js.erb index 3e5d349851..a5563647e0 100644 --- a/app/views/active_scaffold_overrides/destroy.js.erb +++ b/app/views/active_scaffold_overrides/destroy.js.erb @@ -21,6 +21,6 @@ <%= render :partial => 'update_calculations', :formats => [:js] %> <% end %> <% else %> - <% flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) %> + <% flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) if @record.errors.present? %> <% end %> <%= render :partial => 'update_messages', :locals => {:messages_id => messages_id} %> diff --git a/app/views/active_scaffold_overrides/on_action_update.js.erb b/app/views/active_scaffold_overrides/on_action_update.js.erb index 869c08e90b..2508867cb6 100644 --- a/app/views/active_scaffold_overrides/on_action_update.js.erb +++ b/app/views/active_scaffold_overrides/on_action_update.js.erb @@ -16,7 +16,7 @@ <%= render :partial => 'refresh_list' %> <% end %> <% else %> - <% flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) %> + <% flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) if @record.errors.present? %> ActiveScaffold.replace_html('<%= active_scaffold_messages_id %>','<%= escape_javascript(render(:partial => 'messages')) %>'); ActiveScaffold.scroll_to('<%= active_scaffold_messages_id %>', true); <% end %> From 53c074fd2f07a63b93ab33fb15f6ca88fe3f9208 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 30 Jan 2013 11:28:00 -1000 Subject: [PATCH 1825/2024] more fixes for jquery 1.9 --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- app/views/active_scaffold_overrides/_list_record.html.erb | 1 - app/views/active_scaffold_overrides/row.js.erb | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 0bcd6f475b..df085df33e 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -436,7 +436,7 @@ var ActiveScaffold = { replace: function(element, html) { if (typeof(element) == 'string') element = '#' + element; element = jQuery(element); - var new_element = jQuery(html); + var new_element = jQuery.parseHTML(html); element.replaceWith(new_element); new_element.trigger('as:element_updated'); return new_element; diff --git a/app/views/active_scaffold_overrides/_list_record.html.erb b/app/views/active_scaffold_overrides/_list_record.html.erb index decb82d655..cd3b0db4e7 100644 --- a/app/views/active_scaffold_overrides/_list_record.html.erb +++ b/app/views/active_scaffold_overrides/_list_record.html.erb @@ -5,7 +5,6 @@ tr_class = cycle("", "even-record") + ' ' + list_row_class(record) action_links ||= active_scaffold_config.action_links.member data_refresh ||= url_for(params_for(:action => :row, :id => '--ID--', :_method => :get)) -%> - <tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= data_refresh.sub('--ID--', record.id.to_s).html_safe %>"> <% columns.each do |column| %> <% authorized = record.authorized_for?(:crud_type => :read, :column => column.name) -%> diff --git a/app/views/active_scaffold_overrides/row.js.erb b/app/views/active_scaffold_overrides/row.js.erb index 4363a09009..27a37f4e73 100644 --- a/app/views/active_scaffold_overrides/row.js.erb +++ b/app/views/active_scaffold_overrides/row.js.erb @@ -1,2 +1,2 @@ -ActiveScaffold.update_row('<%= element_row_id(:action => :list) %>', '<%= escape_javascript render('row', :record => @record) %>'); +ActiveScaffold.update_row('<%= element_row_id(:action => :list) %>', '<%= escape_javascript render('list_record', :record => @record) %>'); <%= render :partial => 'update_calculations', :formats => [:js] %> From 445baca33820836ab50e4b1105d3a4802bb41e8b Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 30 Jan 2013 11:28:35 -1000 Subject: [PATCH 1826/2024] update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index aa1e14feec..e1246a1235 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -24,6 +24,7 @@ - Avoid sorting by contraint columns - Cosmetic fixes and improvements - Fix multipart persistent update form +- Support jquery 1.9 (jquery-rails 2.2.0 gem) = 3.2.19 (not released yet) - Avoid crashing when between is chosen and from or to is not filled From e44c2063655ef03375376b91c5c2374169926eaf Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 30 Jan 2013 11:54:41 -1000 Subject: [PATCH 1827/2024] only parse strings, in case someone uses ActiveScaffold.replace with elements instead of string --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index df085df33e..24b4fb91a4 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -436,7 +436,7 @@ var ActiveScaffold = { replace: function(element, html) { if (typeof(element) == 'string') element = '#' + element; element = jQuery(element); - var new_element = jQuery.parseHTML(html); + var new_element = typeof(html) == 'string' ? jQuery.parseHTML(html) : jQuery(html); element.replaceWith(new_element); new_element.trigger('as:element_updated'); return new_element; From 883033be839e419ed30179e6aa26b325eb1351a9 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 30 Jan 2013 13:31:31 -1000 Subject: [PATCH 1828/2024] fix trigger on replacing html string --- app/assets/javascripts/jquery/active_scaffold.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 24b4fb91a4..0953bea454 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -436,7 +436,8 @@ var ActiveScaffold = { replace: function(element, html) { if (typeof(element) == 'string') element = '#' + element; element = jQuery(element); - var new_element = typeof(html) == 'string' ? jQuery.parseHTML(html) : jQuery(html); + var new_element = typeof(html) == 'string' ? jQuery.parseHTML(html) : html; + new_element = jQuery(new_element); element.replaceWith(new_element); new_element.trigger('as:element_updated'); return new_element; From 0fdaece4b890833446affee2ad140fb321d78125 Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 30 Jan 2013 13:37:57 -1000 Subject: [PATCH 1829/2024] another fix for highliting after updating row --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 0953bea454..7e0b049f2c 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -436,7 +436,7 @@ var ActiveScaffold = { replace: function(element, html) { if (typeof(element) == 'string') element = '#' + element; element = jQuery(element); - var new_element = typeof(html) == 'string' ? jQuery.parseHTML(html) : html; + var new_element = typeof(html) == 'string' ? jQuery.parseHTML(html.trim()) : html; new_element = jQuery(new_element); element.replaceWith(new_element); new_element.trigger('as:element_updated'); From e9a7c2219e3fbbf08a2bb7ae659e6b71848a732f Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Thu, 31 Jan 2013 10:36:24 -1000 Subject: [PATCH 1830/2024] fix tableless for rails 3.2.11 --- lib/active_scaffold/tableless.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/active_scaffold/tableless.rb b/lib/active_scaffold/tableless.rb index 29b56d7c5f..e18e9c3bbc 100644 --- a/lib/active_scaffold/tableless.rb +++ b/lib/active_scaffold/tableless.rb @@ -51,8 +51,7 @@ def self.table_exists?; true; end class << self private def relation - @relation ||= ActiveScaffold::Tableless::Relation.new(self, arel_table) - super + ActiveScaffold::Tableless::Relation.new(self, arel_table) end end From b3e774c7c756b200c3a07c282fc2bbb7e4ecf11a Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 8 Feb 2013 09:27:59 +0100 Subject: [PATCH 1831/2024] raise exception on tableless when record is not found --- lib/active_scaffold/tableless.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/tableless.rb b/lib/active_scaffold/tableless.rb index e18e9c3bbc..447af4b940 100644 --- a/lib/active_scaffold/tableless.rb +++ b/lib/active_scaffold/tableless.rb @@ -36,7 +36,7 @@ def to_a end def find_one(id) - @klass.find_one(id, self) + @klass.find_one(id, self) or raise ActiveRecord::RecordNotFound end def execute_simple_calculation(operation, column_name, distinct) From 72295b7ac9b91f166c18ef9e6bbf6f8b21b110f8 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 8 Feb 2013 12:33:24 +0100 Subject: [PATCH 1832/2024] avoid checking authorization for subsection --- app/views/active_scaffold_overrides/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_form.html.erb b/app/views/active_scaffold_overrides/_form.html.erb index 111199aa09..3693d7d31f 100644 --- a/app/views/active_scaffold_overrides/_form.html.erb +++ b/app/views/active_scaffold_overrides/_form.html.erb @@ -6,8 +6,8 @@ <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= "style=\"display: none;\"".html_safe if columns.collapsed %>> <% columns.each :for => @record, :crud_type => (:read if show_unauthorized_columns) do |column| %> <% column_css_class = column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %> - <% authorized = show_unauthorized_columns ? @record.authorized_for?(:crud_type => form_action, :column => column.name) : true %> <% renders_as = column_renders_as(column) %> + <% authorized = show_unauthorized_columns ? @record.authorized_for?(:crud_type => form_action, :column => column.name) : true unless renders_as == :subsection %> <% if renders_as == :subsection -%> <% subsection_id = sub_section_id(:sub_section => column.label) %> <li class="sub-section <%= column_css_class %>"> From 3f4080180ebcbb4e60b9dd5c6a45b74cf980dd21 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Fri, 8 Feb 2013 17:10:59 +0100 Subject: [PATCH 1833/2024] format_column_calculation helper --- lib/active_scaffold/helpers/view_helpers.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 73e7413ca4..3c3faae8f4 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -479,7 +479,10 @@ def render_column_calculation(column) calculation = column_calculation(column) override_formatter = "render_#{column.name}_#{column.calculate.is_a?(Proc) ? :calculate : column.calculate}" calculation = send(override_formatter, calculation) if respond_to? override_formatter + format_column_calculation(column, calculation) + end + def format_column_calculation(column, calculation) "#{"#{as_(column.calculate)}: " unless column.calculate.is_a? Proc}#{format_column_value nil, column, calculation}" end From 532ab6b872feda80ab046d965835d9a087344a31 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 11 Feb 2013 16:06:47 +0100 Subject: [PATCH 1834/2024] Doesn't crash when datetime format is invalid --- lib/active_scaffold/finder.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 610a552487..972f36ae07 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -161,9 +161,11 @@ def condition_value_for_datetime(column, value, conversion = :to_time) format += ' %z' if parts[:offset].present? && format !~ /%z/i end value = translate_days_and_months(value, format) if I18n.locale != :en - time = DateTime.strptime(value, format) - time = Time.zone.local_to_utc(time).in_time_zone unless parts[:offset] - time = time.send(conversion) unless conversion == :to_time + time = DateTime.strptime(value, format) rescue nil + if time + time = Time.zone.local_to_utc(time).in_time_zone unless parts[:offset] + time = time.send(conversion) unless conversion == :to_time + end time end unless value.nil? || value.blank? end From ec2107c89cae85cbf3975e569205429fe0921795 Mon Sep 17 00:00:00 2001 From: scambra <sergio@entrecables.com> Date: Mon, 11 Feb 2013 16:21:14 +0100 Subject: [PATCH 1835/2024] parse datetime defaults to today when date is missing --- lib/active_scaffold/finder.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 972f36ae07..0475cb1c89 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -160,6 +160,9 @@ def condition_value_for_datetime(column, value, conversion = :to_time) end format += ' %z' if parts[:offset].present? && format !~ /%z/i end + if !parts[:year] && !parts[:month] && !parts[:mday] + value = "#{Date.today.strftime(format.gsub(/%[HI].*/, ''))} #{value}" + end value = translate_days_and_months(value, format) if I18n.locale != :en time = DateTime.strptime(value, format) rescue nil if time From 2eda8a3a9c47dcc2f17d406c7cc9e50a71d9cf59 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 12 Feb 2013 20:25:57 +0100 Subject: [PATCH 1836/2024] bump to 3.3.0.rc2 --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 6ec7c4b699..4614de1876 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 3 - PATCH = "0.rc" + PATCH = "0.rc2" STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From fa2c5db59e372e7fc95f5599f37ff7b1847d71c9 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 14 Feb 2013 08:51:26 +0100 Subject: [PATCH 1837/2024] reduce usage of session --- CHANGELOG | 1 + lib/active_scaffold.rb | 16 +++++++++---- lib/active_scaffold/actions/core.rb | 1 + lib/active_scaffold/config/base.rb | 12 +++++++++- lib/active_scaffold/config/list.rb | 23 ++++++++++--------- .../extensions/action_view_rendering.rb | 6 ++++- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e1246a1235..dd3950f855 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -25,6 +25,7 @@ - Cosmetic fixes and improvements - Fix multipart persistent update form - Support jquery 1.9 (jquery-rails 2.2.0 gem) +- Reduce usage of session = 3.2.19 (not released yet) - Avoid crashing when between is chosen and from or to is not filled diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 9576ad9d28..4ebb4446cc 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -85,21 +85,29 @@ def active_scaffold_config_for(klass) self.class.active_scaffold_config_for(klass) end - def active_scaffold_session_storage(id = nil) + def active_scaffold_session_storage_key(id = nil) id ||= params[:eid] || "#{params[:controller]}#{"_#{nested.parent_id}" if nested?}" - session_index = "as:#{id}" + "as:#{id}" + end + + def active_scaffold_session_storage(id = nil) + session_index = active_scaffold_session_storage_key(id) session[session_index] ||= {} session[session_index] end + def clear_storage + session_index = active_scaffold_session_storage_key + session.delete(session_index) unless session[session_index].present? + end + # at some point we need to pass the session and params into config. we'll just take care of that before any particular action occurs by passing those hashes off to the UserSettings class of each action. def handle_user_settings if self.class.uses_active_scaffold? active_scaffold_config.actions.each do |action_name| conf_instance = active_scaffold_config.send(action_name) rescue next next if conf_instance.class::UserSettings == ActiveScaffold::Config::Base::UserSettings # if it hasn't been extended, skip it - active_scaffold_session_storage[action_name] ||= {} - conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, active_scaffold_session_storage[action_name], params) + conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, active_scaffold_session_storage, params) end end end diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index f5b0c7a620..c586c04bdc 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -4,6 +4,7 @@ def self.included(base) base.class_eval do prepend_before_filter :register_constraints_with_action_columns, :unless => :nested? after_filter :clear_flashes + after_filter :clear_storage rescue_from ActiveScaffold::RecordNotAllowed, ActiveScaffold::ActionNotAllowed, :with => :deny_access end base.helper_method :nested? diff --git a/lib/active_scaffold/config/base.rb b/lib/active_scaffold/config/base.rb index 6370cc74d7..ed7315f338 100644 --- a/lib/active_scaffold/config/base.rb +++ b/lib/active_scaffold/config/base.rb @@ -42,15 +42,25 @@ def label(model = nil) attr_accessor :action_group class UserSettings - def initialize(conf, storage, params) + def initialize(conf, storage, params, action = :base) # the session hash relevant to this action @session = storage # all the request params @params = params # the configuration object for this action @conf = conf + @action = action end end + + def [](key) + @session[@action][key] if @action && @session[@action] + end + + def []=(key, value) + @session[@action] ||= {} + @session[@action][key] = value + end def formats @formats ||= [] diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 0cb04cc831..e6c5ba1ef2 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -184,27 +184,28 @@ def hide_nested_column class UserSettings < UserSettings def initialize(conf, storage, params) - super(conf,storage,params) + super(conf, storage, params, :list) @sorting = nil end + attr_writer :label # This label has alread been localized. def label - @session[:label] ? @session[:label] : @conf.label + @label || @conf.label end def per_page - @session['per_page'] = @params['limit'].to_i if @params.has_key? 'limit' - @session['per_page'] || @conf.per_page + self['per_page'] = @params['limit'].to_i if @params.has_key? 'limit' + self['per_page'] || @conf.per_page end def page - @session['page'] = @params['page'] if @params.has_key? 'page' - @session['page'] || 1 + self['page'] = @params['page'] if @params.has_key? 'page' + self['page'] || 1 end def page=(value = nil) - @session['page'] = value + self['page'] = value end attr_reader :nested_default_sorting @@ -221,12 +222,12 @@ def default_sorting def sorting if @sorting.nil? # we want to store as little as possible in the session, but we want to return a Sorting data structure. so we recreate it each page load based on session data. - @session['sort'] = [@params['sort'], @params['sort_direction']] if @params['sort'] and @params['sort_direction'] - @session['sort'] = nil if @params['sort_direction'] == 'reset' + self['sort'] = [@params['sort'], @params['sort_direction']] if @params['sort'] and @params['sort_direction'] + self['sort'] = nil if @params['sort_direction'] == 'reset' - if @session['sort'] + if self['sort'] sorting = @conf.sorting.clone - sorting.set(*@session['sort']) + sorting.set(*self['sort']) @sorting = sorting else @sorting = default_sorting diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 4a955727df..469b42f029 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -43,7 +43,11 @@ def render_with_active_scaffold(*args, &block) constraints = options[:constraints] conditions = options[:conditions] eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s) - session["as:#{eid}"] = {:constraints => constraints, :conditions => conditions, :list => {:label => args.first[:label]}} + eid_info = {} + eid_info[:constraints] = constraints if constraints + eid_info[:conditions] = conditions if conditions + eid_info[:list] = {:label => args.first[:label]} if args.first[:label] + session["as:#{eid}"] = eid_info options[:params] ||= {} options[:params].merge! :eid => eid, :embedded => true From 0f33aa57f9f873af2834065b56580b286531cd8b Mon Sep 17 00:00:00 2001 From: scambra <sergio@enpijama.es> Date: Wed, 13 Feb 2013 22:00:03 -1000 Subject: [PATCH 1838/2024] fix get and set on UserSettings --- lib/active_scaffold/config/base.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold/config/base.rb b/lib/active_scaffold/config/base.rb index ed7315f338..3d722a04da 100644 --- a/lib/active_scaffold/config/base.rb +++ b/lib/active_scaffold/config/base.rb @@ -51,15 +51,15 @@ def initialize(conf, storage, params, action = :base) @conf = conf @action = action end - end - def [](key) - @session[@action][key] if @action && @session[@action] - end + def [](key) + @session[@action][key] if @action && @session[@action] + end - def []=(key, value) - @session[@action] ||= {} - @session[@action][key] = value + def []=(key, value) + @session[@action] ||= {} + @session[@action][key] = value + end end def formats From a751497deb37dd0f5d11f402ac799ecbcd53b347 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 13 Feb 2013 22:08:50 -1000 Subject: [PATCH 1839/2024] fix nested label --- lib/active_scaffold/actions/nested.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index cd4839b5ef..e49a320e93 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -32,7 +32,7 @@ def set_nested def configure_nested if nested? - active_scaffold_session_storage[:list][:label] = if nested.belongs_to? + active_scaffold_config.list.user.label = if nested.belongs_to? as_(:nested_of_model, :nested_model => active_scaffold_config.model.model_name.human, :parent_model => nested_parent_record.to_label) else as_(:nested_for_model, :nested_model => active_scaffold_config.list.label, :parent_model => nested_parent_record.to_label) From 28043a92fd7245e53fc235f37bae03f366913141 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 14 Feb 2013 16:49:39 +0100 Subject: [PATCH 1840/2024] add flash warning message with wrong date and datetimes --- lib/active_scaffold/attribute_params.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 73696b2e9d..c1331dd202 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -74,7 +74,8 @@ def update_record_from_params(parent_record, columns, attributes) association_proxy.each { |record| record.send("#{a.reverse}=", parent_record) } end end - + + flash[:warning] = parent_record.errors.to_a.join("\n") if parent_record.errors.present? parent_record end @@ -110,7 +111,11 @@ def datetime_conversion_for_value(column) end def column_value_for_datetime_type(parent_record, column, value) - self.class.condition_value_for_datetime(column, value, self.class.datetime_conversion_for_condition(column)) + new_value = self.class.condition_value_for_datetime(column, value, self.class.datetime_conversion_for_condition(column)) + if new_value.nil? && value.present? + parent_record.errors.add column.name, :invalid + end + new_value end def column_value_from_param_simple_value(parent_record, column, value) From d95d788f92b49466e86b82c90c3f10ac367ece54 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Wed, 20 Feb 2013 13:03:43 +0100 Subject: [PATCH 1841/2024] fix render_field with subgroups on subforms --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 7e0b049f2c..0ce0fa4ad9 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -692,7 +692,7 @@ var ActiveScaffold = { render_form_field: function(source, content, options) { if (typeof(source) == 'string') source = '#' + source; var source = jQuery(source); - var element = source.closest('.association-record').nextUntil('.association-record').addBack(); + var element = source.closest('.sub-form-record'); if (element.length == 0) { element = source.closest('form > ol.form'); } From d4a9c278b7e5cc4eeacc7657cac444c444baef49 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Thu, 21 Feb 2013 11:51:23 +0100 Subject: [PATCH 1842/2024] event onclick on subforms a.destroy replaced by data-delete-id --- app/assets/javascripts/jquery/active_scaffold.js | 5 +++++ .../_form_association_record.html.erb | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 0ce0fa4ad9..8bfd1095a4 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -200,6 +200,11 @@ jQuery(document).ready(function($) { ActiveScaffold[jQuery(this).val() == 'REPLACE' ? 'hide' : 'show'](jQuery(this).next().next()); return true; }); + + jQuery(document).on('click', '.active-scaffold .sub-form a.destroy', function(event) { + event.preventDefault(); + ActiveScaffold.delete_subform_record($(this).data('delete-id')); + }); jQuery(document).on('click', 'a[data-popup]', function(e) { window.open(jQuery(this).attr('href')); diff --git a/app/views/active_scaffold_overrides/_form_association_record.html.erb b/app/views/active_scaffold_overrides/_form_association_record.html.erb index 7650b26a8a..e5ccd142bc 100644 --- a/app/views/active_scaffold_overrides/_form_association_record.html.erb +++ b/app/views/active_scaffold_overrides/_form_association_record.html.erb @@ -62,9 +62,7 @@ <% if show_actions -%> <%= content_tag column_tag, :class => "actions" do %> <% if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> - <% destroy_id = "#{options[:id]}-destroy" %> - <%= link_to as_(:remove), '#', :class => 'destroy', :id => destroy_id , :onclick => "ActiveScaffold.delete_subform_record(\"#{tr_id}\"); return false;", :style=> "display: none;" %> - <%= javascript_tag("ActiveScaffold.show('#{destroy_id}');") if !locked %> + <%= link_to as_(:remove), '#', :class => 'destroy', :id => "#{options[:id]}-destroy" , :data => {:delete_id => tr_id} unless locked %> <% end %> <% unless @record.new_record? %> <input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= @record.id -%>" /> From defb1aa9167a4fb07bfd1e1dfb8931d609370afe Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 21 Feb 2013 13:11:10 +0100 Subject: [PATCH 1843/2024] display create on list header for nested scaffolds too --- app/views/active_scaffold_overrides/_list_with_header.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_list_with_header.html.erb b/app/views/active_scaffold_overrides/_list_with_header.html.erb index eb8d3faaa0..b116d19681 100644 --- a/app/views/active_scaffold_overrides/_list_with_header.html.erb +++ b/app/views/active_scaffold_overrides/_list_with_header.html.erb @@ -17,7 +17,7 @@ <% else %> <tr><td></td></tr> <% end %> - <% if !nested? && active_scaffold_config.list.always_show_create %> + <% if active_scaffold_config.list.always_show_create %> <% old_record, @record = @record, new_model %> <tr> <td> From f9f271ae1b58fd4f0413dc355fe7ddc39152c092 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 21 Feb 2013 02:43:20 -1000 Subject: [PATCH 1844/2024] fix always_show_create on nested --- .../on_create.js.erb | 20 ++++++++++++------- lib/active_scaffold/actions/create.rb | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/views/active_scaffold_overrides/on_create.js.erb b/app/views/active_scaffold_overrides/on_create.js.erb index 70f7f4800a..dea1c95884 100644 --- a/app/views/active_scaffold_overrides/on_create.js.erb +++ b/app/views/active_scaffold_overrides/on_create.js.erb @@ -1,9 +1,13 @@ try { <% form_selector = "#{element_form_id(:action => :create)}" -insert_at ||= :top %> -var action_link = ActiveScaffold.find_action_link('<%= form_selector%>'); -action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'messages'))%>'); -<% if controller.send :successful? %> +insert_at ||= :top -%> +<% if active_scaffold_config.list.always_show_create -%> +<%= render :partial => 'update_messages' %> +<% else -%> +var action_link = ActiveScaffold.find_action_link('<%= form_selector %>'); +action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'messages')) %>'); +<% end -%> +<% if controller.send :successful? -%> <% if render_parent? %> <% if nested_singular_association? %> action_link.close(true); @@ -12,16 +16,18 @@ action_link.update_flash_messages('<%=escape_javascript(render(:partial => 'mess <% else %> ActiveScaffold.reload('<%= url_for render_parent_options %>'); <% end %> - <% elsif (active_scaffold_config.create.refresh_list) %> + <% elsif active_scaffold_config.create.refresh_list %> <%= render :partial => 'refresh_list' %> <% elsif params[:parent_controller].nil? %> <% new_row = render :partial => 'list_record', :locals => {:record => @record} %> - ActiveScaffold.create_record_row(action_link.scaffold(),'<%= escape_javascript(new_row) %>', <%= {:insert_at => insert_at}.to_json.html_safe %>); + ActiveScaffold.create_record_row(action_link ? action_link.scaffold() : '<%= active_scaffold_id %>', '<%= escape_javascript(new_row) %>', <%= {:insert_at => insert_at}.to_json.html_safe %>); <%= render :partial => 'update_calculations', :formats => [:js] %> <% end %> <% unless render_parent? %> - <% if (active_scaffold_config.create.persistent) %> + <% if active_scaffold_config.list.always_show_create %> + ActiveScaffold.reset_form('<%= form_selector %>'); + <% elsif active_scaffold_config.create.persistent %> action_link.reload(); <% else %> action_link.close(); diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 49d32ec1fc..1260358255 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -47,7 +47,7 @@ def create_respond_to_html return_to_main end else - if !nested? && active_scaffold_config.actions.include?(:list) && active_scaffold_config.list.always_show_create + if active_scaffold_config.actions.include?(:list) && active_scaffold_config.list.always_show_create list else render(:action => 'create') @@ -118,7 +118,7 @@ def after_create_save(record); end # You may override the method to customize. def create_ignore? - nested? && active_scaffold_config.list.always_show_create + active_scaffold_config.list.always_show_create end def create_authorized? From 4233bb2a3fad75a6142356e7cb369c00e29f7f70 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 21 Feb 2013 03:03:37 -1000 Subject: [PATCH 1845/2024] remove non html attributes from action links --- lib/active_scaffold/helpers/view_helpers.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 3c3faae8f4..8792901711 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -169,7 +169,7 @@ def render_action_link(link, record = nil, options = {}) options.delete :link if link.crud_type == :create end if link.action.nil? || (link.type == :member && options.has_key?(:authorized) && !options[:authorized]) - action_link_html(link, nil, options.merge(:class => "disabled #{link.action}#{" #{link.html_options[:class]}" unless link.html_options[:class].blank?}"), record) + action_link_html(link, nil, {:class => "disabled #{link.action}#{" #{link.html_options[:class]}" unless link.html_options[:class].blank?}"}, record) else url = action_link_url(link, record) html_options = action_link_html_options(link, record, options) @@ -321,9 +321,10 @@ def action_link_url_options(link, record) url_options end - def action_link_html_options(link, record, html_options) + def action_link_html_options(link, record, options) link_id = get_action_link_id(link, record) - html_options.reverse_merge! link.html_options.merge(:class => link.action.to_s) + html_options = link.html_options.merge(:class => [link.html_options[:class], link.action.to_s].compact.join(' ')) + html_options[:link] = options[:link] if options[:link] # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails html_options[:method] = link.method if link.method != :get @@ -331,7 +332,7 @@ def action_link_html_options(link, record, html_options) html_options[:data] = {} html_options[:data][:confirm] = link.confirm(record.try(:to_label)) if link.confirm? if link.inline? - html_options[:class] += ' as_action' + html_options[:class] << ' as_action' html_options[:data][:position] = link.position if link.position html_options[:data][:action] = link.action html_options[:data][:cancel_refresh] = true if link.refresh_on_close @@ -345,13 +346,12 @@ def action_link_html_options(link, record, html_options) html_options[:remote] = true unless link.page? || link.popup? if link.dhtml_confirm? unless link.inline? - html_options[:class] += ' as_action' + html_options[:class] << ' as_action' html_options[:page_link] = 'true' end html_options[:dhtml_confirm] = link.dhtml_confirm.value html_options[:onclick] = link.dhtml_confirm.onclick_function(controller, link_id) end - html_options[:class] += " #{link.html_options[:class]}" unless link.html_options[:class].blank? html_options end From 1a4dbb9a2c3dea5df0d2e153321b4ede17e7ad01 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 21 Feb 2013 14:45:02 +0100 Subject: [PATCH 1846/2024] add auto_select_columns and enable required only for validations without :if or :unless --- lib/active_scaffold/data_structures/column.rb | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index a5857fa63c..2312a60aef 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -22,6 +22,9 @@ def inplace_edit=(value) # Whether to enable add_existing for this column attr_accessor :allow_add_existing + # What columns load from main table + attr_accessor :auto_select_columns + # Any extra parameters this particular column uses. This is for create/update purposes. def params # lazy initialize @@ -293,6 +296,13 @@ def initialize(name, active_record_class) #:nodoc: @show_blank_record = self.class.show_blank_record @send_form_on_update_column = self.class.send_form_on_update_column @actions_for_association_links = self.class.actions_for_association_links.clone if @association + @auto_select_columns = if @association.nil? && @column + [field] + elsif polymorphic_association? + [field, quoted_field(@active_record_class.connection.quote_column_name(@association.foreign_type))] + elsif @association && self.association.macro == :belongs_to + [field] + end self.number = @column.try(:number?) @options = {:format => :i18n_number} if self.number? @@ -305,8 +315,8 @@ def initialize(name, active_record_class) #:nodoc: # default all the configurable variables self.css_class = '' self.required = active_record_class.validators_on(self.name).any? do |val| - ActiveModel::Validations::PresenceValidator === val or ( - ActiveModel::Validations::InclusionValidator === val and not val.options[:allow_nil] and not val.options[:allow_blank] + !val.options[:if] && !val.options[:unless] && (ActiveModel::Validations::PresenceValidator === val || + (ActiveModel::Validations::InclusionValidator === val && !val.options[:allow_nil] && !val.options[:allow_blank]) ) end self.sort = true @@ -356,11 +366,15 @@ def number_to_native(value) # the table.field name for this column, if applicable def field - @field ||= [@active_record_class.quoted_table_name, field_name].join('.') + @field ||= quoted_field(field_name) end protected + def quoted_field(name) + [@active_record_class.quoted_table_name, name].join('.') + end + def initialize_sort if self.virtual? # we don't automatically enable method sorting for virtual columns because it's slow, and we expect fewer complaints this way. From 31f8122f8368a14e530294a897360ba46b3850f7 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 21 Feb 2013 15:20:27 +0100 Subject: [PATCH 1847/2024] fix text link for non authorized links --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 8792901711..c95d831149 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -169,7 +169,7 @@ def render_action_link(link, record = nil, options = {}) options.delete :link if link.crud_type == :create end if link.action.nil? || (link.type == :member && options.has_key?(:authorized) && !options[:authorized]) - action_link_html(link, nil, {:class => "disabled #{link.action}#{" #{link.html_options[:class]}" unless link.html_options[:class].blank?}"}, record) + action_link_html(link, nil, {:link => options[:link], :class => "disabled #{link.action}#{" #{link.html_options[:class]}" unless link.html_options[:class].blank?}"}, record) else url = action_link_url(link, record) html_options = action_link_html_options(link, record, options) From 24be040e559c1d2652155e790d64ba3c441be969 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 21 Feb 2013 15:31:04 +0100 Subject: [PATCH 1848/2024] auto_select_columns --- lib/active_scaffold/actions/list.rb | 3 +++ lib/active_scaffold/config/list.rb | 8 ++++++++ lib/active_scaffold/finder.rb | 5 +++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index bc2ba3bc5a..ff43def41a 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -85,6 +85,9 @@ def do_list :pagination => active_scaffold_config.list.pagination }) end + if active_scaffold_config.list.auto_select_columns + options[:select] = active_scaffold_config.list.columns.map(&:auto_select_columns).compact.flatten + active_scaffold_config.columns[active_scaffold_config.model.primary_key].auto_select_columns + end page = find_page(options) total_pages = page.pager.number_of_pages diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index e6c5ba1ef2..0bc85dd824 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -24,6 +24,7 @@ def initialize(core_config) @always_show_search = self.class.always_show_search @always_show_create = self.class.always_show_create @messages_above_header = self.class.messages_above_header + @auto_select_columns = self.class.auto_select_columns end # global level configuration @@ -80,6 +81,10 @@ def initialize(core_config) cattr_accessor :always_show_create @@always_show_create = false + # Enable auto select columns on list, so only columns needed for list columns are selected + cattr_accessor :auto_select_columns + @@auto_select_columns = true + # instance-level configuration # ---------------------------- @@ -182,6 +187,9 @@ def hide_nested_column # it allows for more css styling attr_accessor :wrap_tag + # Enable auto select columns on list, so only columns needed for list columns are selected + attr_accessor :auto_select_columns + class UserSettings < UserSettings def initialize(conf, storage, params) super(conf, storage, params, :list) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 0475cb1c89..810ddd1fcf 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -324,7 +324,8 @@ def finder_options(options = {}) finder_options = { :reorder => options[:sorting].try(:clause), :conditions => search_conditions, :joins => joins_for_finder, - :includes => full_includes} + :includes => full_includes, + :select => options[:select]} finder_options.merge! custom_finder_options finder_options @@ -348,7 +349,7 @@ def count_items(find_options = {}, count_includes = nil) # returns a Paginator::Page (not from ActiveRecord::Paginator) for the given parameters # See finder_options for valid options def find_page(options = {}) - options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination + options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination, :select options[:per_page] ||= 999999999 options[:page] ||= 1 From b294b45d8c9e35d985794524b6ba508feed37d92 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 21 Feb 2013 15:35:23 +0100 Subject: [PATCH 1849/2024] auto select columns default to false --- lib/active_scaffold/config/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 0bc85dd824..5e1393ec6c 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -83,7 +83,7 @@ def initialize(core_config) # Enable auto select columns on list, so only columns needed for list columns are selected cattr_accessor :auto_select_columns - @@auto_select_columns = true + @@auto_select_columns = false # instance-level configuration # ---------------------------- From 4feed580e46e1ac3044bca58ccf77809a271d8bd Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 21 Feb 2013 16:41:10 +0100 Subject: [PATCH 1850/2024] rename select_columns to select_associated_columns, auto_select_columns now is select_columns --- lib/active_scaffold/data_structures/column.rb | 6 +++--- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 2312a60aef..8e62f4be8d 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -23,7 +23,7 @@ def inplace_edit=(value) attr_accessor :allow_add_existing # What columns load from main table - attr_accessor :auto_select_columns + attr_accessor :select_columns # Any extra parameters this particular column uses. This is for create/update purposes. def params @@ -175,7 +175,7 @@ def includes=(value) end # a collection of columns to load when eager loading is disabled, if it's nil all columns will be loaded - attr_accessor :select_columns + attr_accessor :select_associated_columns # describes how to search on a column # search = true default, uses intelligent search sql @@ -296,7 +296,7 @@ def initialize(name, active_record_class) #:nodoc: @show_blank_record = self.class.show_blank_record @send_form_on_update_column = self.class.send_form_on_update_column @actions_for_association_links = self.class.actions_for_association_links.clone if @association - @auto_select_columns = if @association.nil? && @column + @select_columns = if @association.nil? && @column [field] elsif polymorphic_association? [field, quoted_field(@active_record_class.connection.quote_column_name(@association.foreign_type))] diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 6c4cd7d719..44eaa71b71 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -187,7 +187,7 @@ def cache_association(value, column, size) if column.associated_limit.nil? Rails.logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries" elsif column.associated_limit > 0 - value.target = value.find(:all, :limit => column.associated_limit + 1, :select => column.select_columns) + value.target = value.find(:all, :limit => column.associated_limit + 1, :select => column.select_associated_columns) elsif @cache_associations value.target = size.to_i.zero? ? [] : [nil] end From 5d89d6ea12031284e28dd81dd91c4144f87e7471 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 21 Feb 2013 16:59:46 +0100 Subject: [PATCH 1851/2024] avoid deleting conditions from options, fixes #246 --- lib/active_scaffold/finder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 810ddd1fcf..cdcd49b52d 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -393,8 +393,8 @@ def calculate(column) def append_to_query(query, options) options.assert_valid_keys :where, :select, :group, :reorder, :limit, :offset, :joins, :includes, :lock, :readonly, :from, :conditions - query = apply_conditions(query, *options.delete(:conditions)) if options[:conditions] - options.reject{|k, v| v.blank?}.inject(query) do |query, (k, v)| + query = apply_conditions(query, *options[:conditions]) if options[:conditions] + options.reject{|k, v| k == :conditions || v.blank?}.inject(query) do |query, (k, v)| query.send((k.to_sym), v) end end From 0594e58e562bc444fcfcc7d8ad2cf82f7cd7dd70 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 21 Feb 2013 18:15:53 +0100 Subject: [PATCH 1852/2024] cache helper overrides per class --- lib/active_scaffold/helpers/view_helpers.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index c95d831149..9672fa4d62 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -512,8 +512,9 @@ def override_helper_name(column, suffix, class_prefix = false) def override_helper(column, suffix) @_override_helpers ||= {} @_override_helpers[suffix] ||= {} - return @_override_helpers[suffix][column.name] if @_override_helpers[suffix].include? column.name - @_override_helpers[suffix][column.name] = begin + @_override_helpers[suffix][@record.class.name] ||= {} + return @_override_helpers[suffix][@record.class.name][column.name] if @_override_helpers[suffix][@record.class.name].include? column.name + @_override_helpers[suffix][@record.class.name][column.name] = begin method_with_class = override_helper_name(column, suffix, true) if respond_to?(method_with_class) method_with_class From cb4a10697c2081bff4321c45beda04b649410450 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 26 Feb 2013 14:46:39 +0100 Subject: [PATCH 1853/2024] fix auto_select_columns --- lib/active_scaffold/actions/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index ff43def41a..c5d8e6357b 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -86,7 +86,7 @@ def do_list }) end if active_scaffold_config.list.auto_select_columns - options[:select] = active_scaffold_config.list.columns.map(&:auto_select_columns).compact.flatten + active_scaffold_config.columns[active_scaffold_config.model.primary_key].auto_select_columns + options[:select] = active_scaffold_config.list.columns.map(&:select_columns).compact.flatten + active_scaffold_config.columns[active_scaffold_config.model.primary_key].auto_select_columns end page = find_page(options) From 62a8c9439606da802a56f160999722a1039cf273 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 26 Feb 2013 14:48:33 +0100 Subject: [PATCH 1854/2024] fix auto_select_columns --- lib/active_scaffold/actions/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index c5d8e6357b..d2f78f4b26 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -86,7 +86,7 @@ def do_list }) end if active_scaffold_config.list.auto_select_columns - options[:select] = active_scaffold_config.list.columns.map(&:select_columns).compact.flatten + active_scaffold_config.columns[active_scaffold_config.model.primary_key].auto_select_columns + options[:select] = active_scaffold_config.list.columns.map(&:select_columns).compact.flatten + active_scaffold_config.columns[active_scaffold_config.model.primary_key].select_columns end page = find_page(options) From bb99eadd377271af0030552631ef5e5f5c98e9ad Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 26 Feb 2013 15:12:20 +0100 Subject: [PATCH 1855/2024] auto select counter cache column --- lib/active_scaffold/data_structures/column.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 8e62f4be8d..91c07f997c 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -300,8 +300,12 @@ def initialize(name, active_record_class) #:nodoc: [field] elsif polymorphic_association? [field, quoted_field(@active_record_class.connection.quote_column_name(@association.foreign_type))] - elsif @association && self.association.macro == :belongs_to - [field] + elsif @association + if self.association.macro == :belongs_to + [field] + elsif active_record_class.columns_hash[count_column = "#{@association.name}_count"] + [quoted_field(@active_record_class.connection.quote_column_name(count_column))] + end end self.number = @column.try(:number?) From e87e6dfbd175edfeec7e762d60f91f2fa1913e72 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 26 Feb 2013 15:16:54 +0100 Subject: [PATCH 1856/2024] select_columns for has_many/has_one through belongs_to --- lib/active_scaffold/data_structures/column.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 91c07f997c..df60a96740 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -303,8 +303,15 @@ def initialize(name, active_record_class) #:nodoc: elsif @association if self.association.macro == :belongs_to [field] - elsif active_record_class.columns_hash[count_column = "#{@association.name}_count"] - [quoted_field(@active_record_class.connection.quote_column_name(count_column))] + else + columns = [] + if active_record_class.columns_hash[count_column = "#{@association.name}_count"] + coumns << quoted_field(@active_record_class.connection.quote_column_name(count_column))] + end + if @association.through_reflection.try(:macro) == :belongs_to + columns << quoted_field(@active_record_class.connection.quote_column_name(@association.through_reflection.foreign_key)) + end + columns end end From 2d6a88e9616fb55fabd1292af203d33c2a181baa Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 26 Feb 2013 17:40:49 +0100 Subject: [PATCH 1857/2024] fix typo --- lib/active_scaffold/data_structures/column.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index df60a96740..ace7b8be05 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -306,7 +306,7 @@ def initialize(name, active_record_class) #:nodoc: else columns = [] if active_record_class.columns_hash[count_column = "#{@association.name}_count"] - coumns << quoted_field(@active_record_class.connection.quote_column_name(count_column))] + coumns << quoted_field(@active_record_class.connection.quote_column_name(count_column)) end if @association.through_reflection.try(:macro) == :belongs_to columns << quoted_field(@active_record_class.connection.quote_column_name(@association.through_reflection.foreign_key)) From b195873cfc4d69acc91eb5b11acbffcd7a531461 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 26 Feb 2013 17:44:17 +0100 Subject: [PATCH 1858/2024] fix typo --- lib/active_scaffold/data_structures/column.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index ace7b8be05..8410c8a803 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -306,7 +306,7 @@ def initialize(name, active_record_class) #:nodoc: else columns = [] if active_record_class.columns_hash[count_column = "#{@association.name}_count"] - coumns << quoted_field(@active_record_class.connection.quote_column_name(count_column)) + columns << quoted_field(@active_record_class.connection.quote_column_name(count_column)) end if @association.through_reflection.try(:macro) == :belongs_to columns << quoted_field(@active_record_class.connection.quote_column_name(@association.through_reflection.foreign_key)) From 05a44c203be08afe27689435911e3162a619bc9e Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 28 Feb 2013 02:18:24 -1000 Subject: [PATCH 1859/2024] fix on action update for collection actions --- app/views/active_scaffold_overrides/on_action_update.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/on_action_update.js.erb b/app/views/active_scaffold_overrides/on_action_update.js.erb index 2508867cb6..effddbb9ae 100644 --- a/app/views/active_scaffold_overrides/on_action_update.js.erb +++ b/app/views/active_scaffold_overrides/on_action_update.js.erb @@ -16,7 +16,7 @@ <%= render :partial => 'refresh_list' %> <% end %> <% else %> - <% flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) if @record.errors.present? %> + <% flash[:error] = active_scaffold_error_messages_for(@record, :object_name => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :header_message => '', :message => "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}", :container_tag => nil, :list_type => :br) if @record.try(:errors).present? %> ActiveScaffold.replace_html('<%= active_scaffold_messages_id %>','<%= escape_javascript(render(:partial => 'messages')) %>'); ActiveScaffold.scroll_to('<%= active_scaffold_messages_id %>', true); <% end %> From 2536a29a1d21469278c95b7f2a87deba14040be6 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 1 Mar 2013 10:28:15 +0100 Subject: [PATCH 1860/2024] encoding for date_picker_bridge, fixes #249 --- app/assets/javascripts/jquery/date_picker_bridge.js.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/date_picker_bridge.js.erb b/app/assets/javascripts/jquery/date_picker_bridge.js.erb index 01c8d56144..d7be7792f9 100644 --- a/app/assets/javascripts/jquery/date_picker_bridge.js.erb +++ b/app/assets/javascripts/jquery/date_picker_bridge.js.erb @@ -1,3 +1,4 @@ +<%# encoding: utf-8 %> <%= ActiveScaffold::Bridges[:date_picker].localization %> jQuery(document).on("focus", "input.date_picker", function(){ var date_picker = jQuery(this); @@ -19,4 +20,4 @@ jQuery(document).on("focus", "input.datetime_picker", function(){ } } return true; -}); \ No newline at end of file +}); From 9ec29591473d75fc22fbdb2e1dd532647e7951be Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 1 Mar 2013 03:15:44 -1000 Subject: [PATCH 1861/2024] support unsuccessful action with list_inline_adapter --- .../active_scaffold_overrides/_list_inline_adapter.html.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb b/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb index 62600380bc..7c0d6454de 100644 --- a/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb +++ b/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb @@ -12,10 +12,12 @@ <%# nested_id, allows us to remove a nested scaffold programmatically %> <tr class="inline-adapter" id="<%= element_row_id :action => :nested %>"> <td colspan="<%= column_count %>" class="inline-adapter-cell"> +<% if controller.send(:successful?) %> <div class="<%= "#{params[:action]}-view" if params[:action] %> <%= "#{nested? ? nested.name : id_from_controller(params[:controller])}-view" %> view"> <%= link_to(as_(:close), '', :class => 'inline-adapter-close as_cancel', :remote => true, :title => as_(:close)) -%> <%= payload -%> </div> +<% end %> </td> </tr> -<%= javascript_tag("var action_link = ActiveScaffold.ActionLink.get('#{element_row_id(:action => :nested)}'); if (action_link) action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');") %> +<%= javascript_tag("setTimeout(function() { var action_link = ActiveScaffold.ActionLink.get('#{element_row_id(:action => :nested)}'); if (action_link) { action_link.update_flash_messages('#{escape_javascript(render(:partial => 'messages').strip)}');#{' action_link.close(); ActiveScaffold.scroll_to(action_link.scaffold(), ActiveScaffold.config.scroll_on_close == "checkInViewport");' unless controller.send(:successful?)} } }, 10);") %> From 26062627f719e60f7cc799562d7f0c441c27bd0b Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 6 Mar 2013 13:07:07 +0100 Subject: [PATCH 1862/2024] fix successful?, always true if not set to false, fixes #253 --- lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/actions/show.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index c586c04bdc..d4a4dadee2 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -119,7 +119,7 @@ def response_object # circumvent this method by setting @success directly. def successful? if @successful.nil? - @record || @records + true else @successful end diff --git a/lib/active_scaffold/actions/show.rb b/lib/active_scaffold/actions/show.rb index 5e7554e023..76ef6d69ea 100644 --- a/lib/active_scaffold/actions/show.rb +++ b/lib/active_scaffold/actions/show.rb @@ -9,7 +9,6 @@ def show # just render action_confirmation message for destroy unless params.delete :destroy_action do_show - successful? respond_to_action(:show) else @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0 From 102fa656ce6a5132e267e7382d9d2fd2da1369b9 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 6 Mar 2013 17:45:35 +0100 Subject: [PATCH 1863/2024] bump to rc3 now it works with rails 3.2.13 --- lib/active_scaffold/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 4614de1876..ded5c749ba 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 3 - PATCH = "0.rc2" + PATCH = "0.rc3" STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 7a87fae69ca21985ec69214f1c7942d37187e3de Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 7 Mar 2013 14:18:08 +0100 Subject: [PATCH 1864/2024] remove multiple count queries, fixes #248 --- app/views/active_scaffold_overrides/_list.html.erb | 2 +- .../active_scaffold_overrides/_list_messages.html.erb | 2 +- lib/active_scaffold/extensions/paginator_extensions.rb | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/views/active_scaffold_overrides/_list.html.erb b/app/views/active_scaffold_overrides/_list.html.erb index f2e09c0b9c..aff7813e5f 100644 --- a/app/views/active_scaffold_overrides/_list.html.erb +++ b/app/views/active_scaffold_overrides/_list.html.erb @@ -24,7 +24,7 @@ </thead> <%= render :partial => 'list_messages', :locals => {:columns => columns} %> <tbody class="records" id="<%= active_scaffold_tbody_id %>"> - <% if !@records.empty? -%> + <% if !@page.empty? -%> <%= render :partial => 'list_record', :collection => @page.items, :locals => {:hidden => false, :columns => columns, :action_links => active_scaffold_config.action_links.member, :data_refresh => url_for(params_for(:action => :row, :id => '--ID--', :_method => :get))} %> <% end -%> <% if columns.any? {|c| c.calculation?} -%> diff --git a/app/views/active_scaffold_overrides/_list_messages.html.erb b/app/views/active_scaffold_overrides/_list_messages.html.erb index 6008b2c1d8..46a411ddb0 100644 --- a/app/views/active_scaffold_overrides/_list_messages.html.erb +++ b/app/views/active_scaffold_overrides/_list_messages.html.erb @@ -20,7 +20,7 @@ </div> <% end -%> </div> - <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" '.html_safe unless @page.items.empty? %>> + <p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" '.html_safe unless @page.empty? %>> <%= as_(active_scaffold_config.list.no_entries_message) %> </p> </td> diff --git a/lib/active_scaffold/extensions/paginator_extensions.rb b/lib/active_scaffold/extensions/paginator_extensions.rb index 153030ecb2..b6736063f8 100644 --- a/lib/active_scaffold/extensions/paginator_extensions.rb +++ b/lib/active_scaffold/extensions/paginator_extensions.rb @@ -20,6 +20,14 @@ def next_with_infinite? next_without_infinite? end alias_method_chain :next?, :infinite + + def empty? + if @pager.infinite? + items.to_a.empty? + else + @pager.count == 0 + end + end end end From 3cbbb4df8d3255c7b6896d57dd21919397271ca0 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 7 Mar 2013 17:31:20 +0100 Subject: [PATCH 1865/2024] fix bitfields bridge --- lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb b/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb index 984cc7c074..25f62b9c99 100644 --- a/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +++ b/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb @@ -19,7 +19,7 @@ def _load_action_columns_with_bitfields self.model.bitfields.each do |column_name, options| columns = options.keys.sort_by { |column| self.columns[column].weight } [:create, :update, :show, :subform].each do |action| - self.send(action).columns.add_subgroup(column_name) { |group| group.add *columns } if self.actions.included? action + self.send(action).columns.add_subgroup(column_name) { |group| group.add *columns } if self.actions.include? action end end if self.model.respond_to?(:bitfields) and self.model.bitfields.present? From 19f55e893dfd18cb3e83c2a9854eab862a577728 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 7 Mar 2013 17:49:46 +0100 Subject: [PATCH 1866/2024] exclude bifield column from actions where subgroup is created --- lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb b/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb index 25f62b9c99..305c378021 100644 --- a/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +++ b/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb @@ -19,7 +19,10 @@ def _load_action_columns_with_bitfields self.model.bitfields.each do |column_name, options| columns = options.keys.sort_by { |column| self.columns[column].weight } [:create, :update, :show, :subform].each do |action| - self.send(action).columns.add_subgroup(column_name) { |group| group.add *columns } if self.actions.include? action + if self.actions.include? action + self.send(action).columns.exclude column_name + self.send(action).columns.add_subgroup(column_name) { |group| group.add *columns } + end end end if self.model.respond_to?(:bitfields) and self.model.bitfields.present? From 5a95febc50805d1bd4c08d1a6ccd8433a3af7445 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 7 Mar 2013 17:50:53 +0100 Subject: [PATCH 1867/2024] remove some partials to improve form performance --- .../_form_attribute.html.erb | 27 ------------------- .../_form_hidden_attribute.html.erb | 7 ----- 2 files changed, 34 deletions(-) delete mode 100644 app/views/active_scaffold_overrides/_form_attribute.html.erb delete mode 100644 app/views/active_scaffold_overrides/_form_hidden_attribute.html.erb diff --git a/app/views/active_scaffold_overrides/_form_attribute.html.erb b/app/views/active_scaffold_overrides/_form_attribute.html.erb deleted file mode 100644 index 9bcf06787b..0000000000 --- a/app/views/active_scaffold_overrides/_form_attribute.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -<% - scope ||= nil - column_options = active_scaffold_input_options(column, scope) - attributes = field_attributes(column, @record) - if local_assigns[:col_class].present? - attributes[:class] = "#{attributes[:class]} #{col_class}" - end -%> -<%= tag :dl, attributes, true %> - <dt> - <label for="<%= column_options[:id] %>"><%= column.label %></label> - </dt> - <dd> - <% unless local_assigns[:only_value] %> - <%=raw active_scaffold_input_for column, scope %> - <% else %> - <%= content_tag :span, get_column_value(@record, column), column_options.except(:name) %> - <%= hidden_field :record, column.association ? column.association.foreign_key : column.name, column_options -%> - <% end %> - <% if column.update_columns -%> - <%= loading_indicator_tag(:action => :render_field, :id => params[:id]) %> - <% end -%> - <% if column.description.present? -%> - <span class="description"><%= column.description %></span> - <% end -%> - </dd> -</dl> diff --git a/app/views/active_scaffold_overrides/_form_hidden_attribute.html.erb b/app/views/active_scaffold_overrides/_form_hidden_attribute.html.erb deleted file mode 100644 index 3be3b66433..0000000000 --- a/app/views/active_scaffold_overrides/_form_hidden_attribute.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -<% scope ||= nil %> -<dl style="display: none;"> -<dt></dt> -<dd> - <%= hidden_field :record, column.name, active_scaffold_input_options(column, scope) %> -</dd> -</dl> From 2d3d8448c3c3c0d93fa9050777ab47ae7396038c Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 8 Mar 2013 13:34:17 +0100 Subject: [PATCH 1868/2024] keep old session info on embedded session, so info like config_list is kept --- CHANGELOG | 2 +- .../active_scaffold_overrides/_form.html.erb | 6 +- .../_render_field.js.erb | 5 +- .../extensions/action_view_rendering.rb | 21 +++++-- .../helpers/form_column_helpers.rb | 60 +++++++++++++------ 5 files changed, 64 insertions(+), 30 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index dd3950f855..c13e9579ca 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ = master - Unify field overrides and list_ui method signatures -- Improve performance removing some partials and adding some caching for helper overrides and UIs, and caching url generation for lists (optional) +- Improve performance removing some partials and adding some caching for helper overrides and UIs, and caching url generation for lists (caching url is optional) - Drop support for rails 3.1 - Add HTML5 form fields - Add :chosen form_ui, and :chosen and :multi_chosen search_ui diff --git a/app/views/active_scaffold_overrides/_form.html.erb b/app/views/active_scaffold_overrides/_form.html.erb index 3693d7d31f..159de95ab7 100644 --- a/app/views/active_scaffold_overrides/_form.html.erb +++ b/app/views/active_scaffold_overrides/_form.html.erb @@ -15,13 +15,13 @@ <%= render :partial => 'form', :locals => { :columns => column, :subsection_id => subsection_id, :form_action => form_action, :scope => scope } %> <%= link_to_visibility_toggle(subsection_id, {:default_visible => !column.collapsed}) -%> </li> - <% elsif renders_as == :subform and !override_form_field?(column) and authorized -%> + <% elsif renders_as == :subform and authorized -%> <li class="sub-form <%= active_scaffold_config_for(column.association.klass).subform.layout %>-sub-form <%= column_css_class %> <%=column.name%>-sub-form" id="<%= sub_form_id(:association => column.name) %>"> - <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column, :scope => scope } -%> + <%= render_column(column, @record, renders_as, scope) %> </li> <% else -%> <li class="form-element <%= 'required' if column.required? %> <%= column_css_class %>"> - <%=raw render :partial => form_partial_for_column(column, renders_as), :locals => { :column => column, :only_value => !authorized, :scope => scope } -%> + <%= render_column(column, @record, renders_as, scope, !authorized) %> </li> <% end -%> <% end -%> diff --git a/app/views/active_scaffold_overrides/_render_field.js.erb b/app/views/active_scaffold_overrides/_render_field.js.erb index 34a23d6ddb..f9cf288dd6 100644 --- a/app/views/active_scaffold_overrides/_render_field.js.erb +++ b/app/views/active_scaffold_overrides/_render_field.js.erb @@ -8,7 +8,8 @@ @rendered ||= Set.new return if @rendered.include? column.name @rendered << column.name - if column_renders_as(column) == :subform + renders_as = column_renders_as(column) + if renders_as == :subform options = {:is_subform => true, :field_class => "#{column.name}-sub-form"} else options = {:is_subform => false, :field_class => "#{column.name}-input"} @@ -18,7 +19,7 @@ crud_type = @record.new_record? ? :create : (readonly ? :read : :update) active_scaffold_render_subform_column(column, scope, crud_type, readonly, !active_scaffold_config.subform.columns.names_without_auth_check.include?(column.name)) else - render(:partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope }) + render_column(column, @record, renders_as, scope) end -%> diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 469b42f029..7abeac886d 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -43,11 +43,22 @@ def render_with_active_scaffold(*args, &block) constraints = options[:constraints] conditions = options[:conditions] eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s) - eid_info = {} - eid_info[:constraints] = constraints if constraints - eid_info[:conditions] = conditions if conditions - eid_info[:list] = {:label => args.first[:label]} if args.first[:label] - session["as:#{eid}"] = eid_info + eid_info = session["as:#{eid}"] ||= {} + if constraints + eid_info[:constraints] = constraints + else + eid_info.delete :constraints + end + if conditions + eid_info[:conditions] = conditions + else + eid_info.delete :conditions + end + if args.first[:label] + eid_info[:list] = {:label => args.first[:label]} + else + eid_info.delete :list + end options[:params] ||= {} options[:params].merge! :eid => eid, :embedded => true diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 50bd1277cb..82e305bb4f 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -4,14 +4,12 @@ module Helpers module FormColumnHelpers # This method decides which input to use for the given column. # It does not do any rendering. It only decides which method is responsible for rendering. - def active_scaffold_input_for(column, scope = nil, options = {}) - options = active_scaffold_input_options(column, scope, options) + def active_scaffold_input_for(column, scope = nil, options = nil) + options ||= active_scaffold_input_options(column, scope) options = update_columns_options(column, scope, options) active_scaffold_render_input(column, options) end - alias form_column active_scaffold_input_for - def active_scaffold_render_input(column, options) begin # first, check if the dev has created an override for this specific field @@ -69,7 +67,7 @@ def active_scaffold_render_subform_column(column, scope, crud_type, readonly, ad col_class = col_class.join(' ') end unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) - render :partial => form_partial_for_column(column), :locals => { :column => column, :scope => scope, :col_class => col_class } + render_column(column, @record, column_renders_as(column), scope, false, col_class) else options = active_scaffold_input_options(column, scope).except(:name) options[:class] = "#{options[:class]} #{col_class}" if col_class @@ -131,6 +129,43 @@ def update_columns_options(column, scope, options) def field_attributes(column, record) {} end + + def render_column(column, record, renders_as, scope = nil, only_value = false, col_class = nil) + if override_form_field_partial?(column) + render :partial => override_form_field_partial(column), :locals => { :column => column, :only_value => only_value, :scope => scope, :col_class => col_class } + elsif renders_as == :field || override_form_field?(column) + form_attribute(column, record, scope, only_value) + elsif renders_as == :subform + render :partial => 'form_association', :locals => { :column => column, :scope => scope } + else + form_hidden_attribute(column, record, scope) + end + end + + def form_attribute(column, record, scope = nil, only_value = false, col_class = nil) + column_options = active_scaffold_input_options(column, scope) + attributes = field_attributes(column, record) + attributes[:class] = "#{attributes[:class]} #{col_class}" if col_class.present? + field = unless only_value + active_scaffold_input_for column, scope, column_options.merge(:object => record) + else + content_tag(:span, get_column_value(@record, column), column_options.except(:name)) << + hidden_field(:record, column.association ? column.association.foreign_key : column.name, column_options.merge(:object => record)) + end + + content_tag :dl, attributes do + %|<dt>#{label_tag column_options[:id], column.label}</dt><dd>#{field} +#{loading_indicator_tag(:action => :render_field, :id => params[:id]) if column.update_columns} +#{content_tag :span, column.description, :class => 'description' if column.description.present?} +</dd>|.html_safe + end + end + + def form_hidden_attribute(column, record, scope = nil) + %|<dl style="display: none;"><dt></dt><dd> +#{hidden_field :record, column.name, active_scaffold_input_options(column, scope).merge(:object => record)} +</dd></dl>|.html_safe + end ## ## Form input methods @@ -342,19 +377,6 @@ def override_input(form_ui) end alias_method :override_input?, :override_input - def form_partial_for_column(column, renders_as = nil) - renders_as ||= column_renders_as(column) - if override_form_field_partial?(column) - override_form_field_partial(column) - elsif renders_as == :field or override_form_field?(column) - "form_attribute" - elsif renders_as == :subform - "form_association" - elsif renders_as == :hidden - "form_hidden_attribute" - end - end - def subform_partial_for_column(column) subform_partial = "#{active_scaffold_config_for(column.association.klass).subform.layout}_subform" if override_subform_partial?(column, subform_partial) @@ -373,7 +395,7 @@ def column_renders_as(column) return :subsection elsif column.active_record_class.locking_column.to_s == column.name.to_s or column.form_ui == :hidden return :hidden - elsif column.association.nil? or column.form_ui or !active_scaffold_config_for(column.association.klass).actions.include?(:subform) + elsif column.association.nil? or column.form_ui or !active_scaffold_config_for(column.association.klass).actions.include?(:subform) or override_form_field?(column) return :field else return :subform From 2bb446213be2c5d8391d9116c3e17bfddcb8713c Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 12 Mar 2013 00:13:01 -1000 Subject: [PATCH 1869/2024] fix always show create --- app/views/active_scaffold_overrides/on_create.js.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/on_create.js.erb b/app/views/active_scaffold_overrides/on_create.js.erb index dea1c95884..cbedefad46 100644 --- a/app/views/active_scaffold_overrides/on_create.js.erb +++ b/app/views/active_scaffold_overrides/on_create.js.erb @@ -1,10 +1,11 @@ try { +var action_link; <% form_selector = "#{element_form_id(:action => :create)}" insert_at ||= :top -%> <% if active_scaffold_config.list.always_show_create -%> <%= render :partial => 'update_messages' %> <% else -%> -var action_link = ActiveScaffold.find_action_link('<%= form_selector %>'); +action_link = ActiveScaffold.find_action_link('<%= form_selector %>'); action_link.update_flash_messages('<%= escape_javascript(render(:partial => 'messages')) %>'); <% end -%> <% if controller.send :successful? -%> From 7cabbdd738180b63e1fac8610d69c3e97abae46e Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 14 Mar 2013 17:17:40 +0100 Subject: [PATCH 1870/2024] keep scripts on parsing html --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 8bfd1095a4..432377d158 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -441,7 +441,7 @@ var ActiveScaffold = { replace: function(element, html) { if (typeof(element) == 'string') element = '#' + element; element = jQuery(element); - var new_element = typeof(html) == 'string' ? jQuery.parseHTML(html.trim()) : html; + var new_element = typeof(html) == 'string' ? jQuery.parseHTML(html.trim(), true) : html; new_element = jQuery(new_element); element.replaceWith(new_element); new_element.trigger('as:element_updated'); From 7687be8bc6ada9d76c971e32e5c03140bc35a286 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 14 Mar 2013 17:28:55 +0100 Subject: [PATCH 1871/2024] keep session cleaner --- lib/active_scaffold/extensions/action_view_rendering.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 7abeac886d..f7a58ec6b5 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -59,6 +59,7 @@ def render_with_active_scaffold(*args, &block) else eid_info.delete :list end + session.delete "as:#{eid}" if eid_info.empty? options[:params] ||= {} options[:params].merge! :eid => eid, :embedded => true From 034cf599635964c46e010174f4552dd072d04558 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 14 Mar 2013 17:58:35 +0100 Subject: [PATCH 1872/2024] refresh_with_header --- CHANGELOG | 1 + app/views/active_scaffold_overrides/_refresh_list.js.erb | 4 ++++ lib/active_scaffold/config/list.rb | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index c13e9579ca..d84944d10b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -26,6 +26,7 @@ - Fix multipart persistent update form - Support jquery 1.9 (jquery-rails 2.2.0 gem) - Reduce usage of session +- Allow to include header on list refreshing = 3.2.19 (not released yet) - Avoid crashing when between is chosen and from or to is not filled diff --git a/app/views/active_scaffold_overrides/_refresh_list.js.erb b/app/views/active_scaffold_overrides/_refresh_list.js.erb index 9333b9cb16..8a20d894f6 100644 --- a/app/views/active_scaffold_overrides/_refresh_list.js.erb +++ b/app/views/active_scaffold_overrides/_refresh_list.js.erb @@ -1 +1,5 @@ +<% if active_scaffold_config.list.refresh_with_header -%> +ActiveScaffold.replace('<%= active_scaffold_id %>', '<%= escape_javascript(render('list_with_header')) %>'); +<% else -%> ActiveScaffold.replace_html('<%= active_scaffold_content_id %>', '<%= escape_javascript(render('list')) %>'); +<% end -%> diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 5e1393ec6c..7771acdeed 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -25,10 +25,15 @@ def initialize(core_config) @always_show_create = self.class.always_show_create @messages_above_header = self.class.messages_above_header @auto_select_columns = self.class.auto_select_columns + @refresh_with_header = self.class.refresh_with_header end # global level configuration # -------------------------- + # include list header on refresh + cattr_accessor :refresh_with_header + @@refresh_with_header = false + # how many records to show per page cattr_accessor :per_page @@per_page = 15 @@ -96,6 +101,9 @@ def columns public :columns= + # include list header on refresh + attr_accessor :refresh_with_header + # how many rows to show at once attr_accessor :per_page From 2477e094b961b5f0141e40dbd7ff759f4d81794a Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 14 Mar 2013 21:15:08 +0100 Subject: [PATCH 1873/2024] outer joins for search --- CHANGELOG | 1 + lib/active_scaffold/actions/field_search.rb | 9 +++--- lib/active_scaffold/actions/list.rb | 2 +- lib/active_scaffold/actions/search.rb | 4 +-- lib/active_scaffold/data_structures/column.rb | 17 +++++++++- .../extensions/left_outer_joins.rb | 31 +++++++++++++++++++ lib/active_scaffold/finder.rb | 10 ++++-- 7 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 lib/active_scaffold/extensions/left_outer_joins.rb diff --git a/CHANGELOG b/CHANGELOG index d84944d10b..56d6f216be 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -27,6 +27,7 @@ - Support jquery 1.9 (jquery-rails 2.2.0 gem) - Reduce usage of session - Allow to include header on list refreshing +- Add search_joins to columns, so it's possible to do left joins without loading associations only for searching = 3.2.19 (not released yet) - Avoid crashing when between is chosen and from or to is not filled diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index e725f8626d..9b9cb9270b 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -48,19 +48,18 @@ def do_search columns = active_scaffold_config.field_search.columns search_params.each do |key, value| next unless columns.include? key - search_condition = self.class.condition_for_column(active_scaffold_config.columns[key], value, text_search) + column = active_scaffold_config.columns[key] + search_condition = self.class.condition_for_column(column, value, text_search) unless search_condition.blank? + self.active_scaffold_outer_joins << column.search_joins unless column.includes.present? && list_columns.include?(column) self.active_scaffold_conditions << search_condition - filtered_columns << active_scaffold_config.columns[key] + filtered_columns << column end end unless filtered_columns.blank? @filtered = active_scaffold_config.field_search.human_conditions ? filtered_columns : true end - includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact - self.active_scaffold_includes.concat includes_for_search_columns - active_scaffold_config.list.user.page = nil end end diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index d2f78f4b26..41d230b49f 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -204,7 +204,7 @@ def action_confirmation_formats end def list_columns - active_scaffold_config.list.columns.collect_visible + @list_columns ||= active_scaffold_config.list.columns.collect_visible end def list_columns_names diff --git a/lib/active_scaffold/actions/search.rb b/lib/active_scaffold/actions/search.rb index ac069128c1..a7b6fdc513 100644 --- a/lib/active_scaffold/actions/search.rb +++ b/lib/active_scaffold/actions/search.rb @@ -29,8 +29,8 @@ def do_search @filtered = !search_conditions.blank? self.active_scaffold_conditions.concat search_conditions if @filtered - includes_for_search_columns = columns.collect{ |column| column.includes}.flatten.uniq.compact - self.active_scaffold_includes.concat includes_for_search_columns + outer_joins = columns.collect{ |column| column.search_joins unless column.includes.present? && list_columns.include?(column)} + self.active_scaffold_outer_joins.concat outer_joins.flatten.uniq.compact active_scaffold_config.list.user.page = nil end diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 8410c8a803..6677d39ebe 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -174,6 +174,18 @@ def includes=(value) end end + # a collection of associations to do left join when this column is included on search + def search_joins + @search_joins || @includes + end + + def search_joins=(value) + @search_joins = case value + when Array then value + else [value] # automatically convert to an array + end + end + # a collection of columns to load when eager loading is disabled, if it's nil all columns will be loaded attr_accessor :select_associated_columns @@ -335,7 +347,10 @@ def initialize(name, active_record_class) #:nodoc: @weight = estimate_weight - self.includes = (association and not polymorphic_association?) ? [association.name] : [] + if association && !polymorphic_association? + self.includes = [association.name] + self.search_joins = self.includes.clone + end end # just the field (not table.field) diff --git a/lib/active_scaffold/extensions/left_outer_joins.rb b/lib/active_scaffold/extensions/left_outer_joins.rb new file mode 100644 index 0000000000..f6b9272654 --- /dev/null +++ b/lib/active_scaffold/extensions/left_outer_joins.rb @@ -0,0 +1,31 @@ +module ActiveScaffold + module OuterJoins + def outer_joins(*assocs) + joins(outer_joins_sql(*assocs)) + end + + private + def outer_joins_sql(*assocs) + assocs.collect do |assoc| + if assoc.is_a? Array + outer_joins_sql(*assoc) + elsif assoc.is_a? Hash + assoc.collect do |key, val| + [left_outer_join_sql(key), klass.reflect_on_association(key).klass.outer_joins_sql(*val)] + end + else + left_outer_join_sql(assoc) if assoc + end + end.flatten.compact + end + + def left_outer_join_sql(association_name) + t = ActiveRecord::Associations::JoinDependency.new(klass, association_name, []).join_associations.first.join_relation(klass).arel + t.joins(t) + end + end +end +ActiveRecord::QueryMethods.send :include, ActiveScaffold::OuterJoins +module ActiveRecord::Querying + delegate :outer_joins, :outer_joins_sql, :to => :scoped +end diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index cdcd49b52d..e2a58a24b2 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -292,6 +292,11 @@ def active_scaffold_habtm_joins @active_scaffold_habtm_joins ||= [] end + attr_writer :active_scaffold_outer_joins + def active_scaffold_outer_joins + @active_scaffold_outer_joins ||= [] + end + def all_conditions [ active_scaffold_conditions, # from the search modules @@ -324,6 +329,7 @@ def finder_options(options = {}) finder_options = { :reorder => options[:sorting].try(:clause), :conditions => search_conditions, :joins => joins_for_finder, + :outer_joins => active_scaffold_outer_joins, :includes => full_includes, :select => options[:select]} @@ -382,7 +388,7 @@ def calculate(column) includes = active_scaffold_config.list.count_includes includes ||= active_scaffold_includes unless conditions.nil? primary_key = active_scaffold_config.model.primary_key - subquery = append_to_query(beginning_of_chain, :conditions => conditions, :joins => joins_for_collection) + subquery = append_to_query(beginning_of_chain, :conditions => conditions, :joins => joins_for_finder, :outer_joins => active_scaffold_outer_joins) subquery = subquery.select(active_scaffold_config.columns[primary_key].field) if includes includes_relation = beginning_of_chain.includes(includes) @@ -392,7 +398,7 @@ def calculate(column) end def append_to_query(query, options) - options.assert_valid_keys :where, :select, :group, :reorder, :limit, :offset, :joins, :includes, :lock, :readonly, :from, :conditions + options.assert_valid_keys :where, :select, :group, :reorder, :limit, :offset, :joins, :outer_joins, :includes, :lock, :readonly, :from, :conditions query = apply_conditions(query, *options[:conditions]) if options[:conditions] options.reject{|k, v| k == :conditions || v.blank?}.inject(query) do |query, (k, v)| query.send((k.to_sym), v) From c3770fd0f130904e48b31dc607cf218e0af41d4a Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 15 Mar 2013 12:59:18 +0100 Subject: [PATCH 1874/2024] fix changing label on embedded scaffolds --- lib/active_scaffold/config/list.rb | 2 +- lib/active_scaffold/extensions/action_view_rendering.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 7771acdeed..8016844dfb 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -207,7 +207,7 @@ def initialize(conf, storage, params) attr_writer :label # This label has alread been localized. def label - @label || @conf.label + self[:label] || @label || @conf.label end def per_page diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index f7a58ec6b5..9b03db07ba 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -54,8 +54,8 @@ def render_with_active_scaffold(*args, &block) else eid_info.delete :conditions end - if args.first[:label] - eid_info[:list] = {:label => args.first[:label]} + if options[:label] + eid_info[:list] = {:label => options[:label]} else eid_info.delete :list end From a7c86c3d5322ba4fe65f96892e667bafc7aca8f4 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 15 Mar 2013 13:10:20 +0100 Subject: [PATCH 1875/2024] move label link generation to action_link_html_options --- lib/active_scaffold/helpers/view_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 9672fa4d62..fc60cb8885 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -324,7 +324,8 @@ def action_link_url_options(link, record) def action_link_html_options(link, record, options) link_id = get_action_link_id(link, record) html_options = link.html_options.merge(:class => [link.html_options[:class], link.action.to_s].compact.join(' ')) - html_options[:link] = options[:link] if options[:link] + html_options[:link] = image_tag(link.image[:name], :size => link.image[:size], :alt => label, :title => label) if link.image + html_options[:link] ||= options[:link] if options[:link] # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails html_options[:method] = link.method if link.method != :get @@ -374,7 +375,6 @@ def get_action_link_id(link, record = nil, column = nil) def action_link_html(link, url, html_options, record) label = html_options.delete(:link) label ||= link.label - label = image_tag(link.image[:name], :size => link.image[:size], :alt => label, :title => label) if link.image if url.nil? content_tag(:a, label, html_options) else From df22c5d49f4fbde8a4dda8f4d64176c74964c2d7 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 15 Mar 2013 13:14:25 +0100 Subject: [PATCH 1876/2024] fix move label link generation to action_link_html_options --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index fc60cb8885..1001b1deec 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -324,7 +324,7 @@ def action_link_url_options(link, record) def action_link_html_options(link, record, options) link_id = get_action_link_id(link, record) html_options = link.html_options.merge(:class => [link.html_options[:class], link.action.to_s].compact.join(' ')) - html_options[:link] = image_tag(link.image[:name], :size => link.image[:size], :alt => label, :title => label) if link.image + html_options[:link] = image_tag(link.image[:name], :size => link.image[:size], :alt => options[:link] || link.label, :title => options[:link] || link.label) if link.image html_options[:link] ||= options[:link] if options[:link] # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails From 6490215c67c2bec38f4884a2c84f09a61612b5c6 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 15 Mar 2013 13:50:21 +0100 Subject: [PATCH 1877/2024] fix move label link generation to action_link_html_options for disabled links --- lib/active_scaffold/helpers/view_helpers.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 1001b1deec..89465c439c 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -169,7 +169,7 @@ def render_action_link(link, record = nil, options = {}) options.delete :link if link.crud_type == :create end if link.action.nil? || (link.type == :member && options.has_key?(:authorized) && !options[:authorized]) - action_link_html(link, nil, {:link => options[:link], :class => "disabled #{link.action}#{" #{link.html_options[:class]}" unless link.html_options[:class].blank?}"}, record) + action_link_html(link, nil, {:link => action_link_text(link, options), :class => "disabled #{link.action}#{" #{link.html_options[:class]}" unless link.html_options[:class].blank?}"}, record) else url = action_link_url(link, record) html_options = action_link_html_options(link, record, options) @@ -321,11 +321,15 @@ def action_link_url_options(link, record) url_options end + def action_link_text(link, options) + text = image_tag(link.image[:name], :size => link.image[:size], :alt => options[:link] || link.label, :title => options[:link] || link.label) if link.image + text || options[:link] + end + def action_link_html_options(link, record, options) link_id = get_action_link_id(link, record) html_options = link.html_options.merge(:class => [link.html_options[:class], link.action.to_s].compact.join(' ')) - html_options[:link] = image_tag(link.image[:name], :size => link.image[:size], :alt => options[:link] || link.label, :title => options[:link] || link.label) if link.image - html_options[:link] ||= options[:link] if options[:link] + html_options[:link] = action_link_text(link, options) # Needs to be in html_options to as the adding _method to the url is no longer supported by Rails html_options[:method] = link.method if link.method != :get From 7d6390e7ccc05c296cf8c03bb0842e223125f4ec Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 15 Mar 2013 02:55:03 -1000 Subject: [PATCH 1878/2024] fix constraints --- lib/active_scaffold/constraints.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 4363fdc71d..212351e8be 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -69,7 +69,7 @@ def conditions_from_constraints # regular column constraints elsif column.searchable? && params[column.name] != v - active_scaffold_includes.concat column.includes + active_scaffold_includes.concat column.includes if column.includes.present? conditions << [column.search_sql.collect { |search_sql| "#{search_sql} = ?" }.join(' OR '), *([v] * column.search_sql.size)] end # unknown-to-activescaffold-but-real-database-column constraint From 7eeb2ca7ad2e86664a48bf54fe43358af915dcf7 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 15 Mar 2013 17:21:25 +0100 Subject: [PATCH 1879/2024] fix outer joins --- lib/active_scaffold/extensions/left_outer_joins.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/extensions/left_outer_joins.rb b/lib/active_scaffold/extensions/left_outer_joins.rb index f6b9272654..a162b2f6a8 100644 --- a/lib/active_scaffold/extensions/left_outer_joins.rb +++ b/lib/active_scaffold/extensions/left_outer_joins.rb @@ -25,7 +25,7 @@ def left_outer_join_sql(association_name) end end end -ActiveRecord::QueryMethods.send :include, ActiveScaffold::OuterJoins +ActiveRecord::Relation.send :include, ActiveScaffold::OuterJoins module ActiveRecord::Querying delegate :outer_joins, :outer_joins_sql, :to => :scoped end From 608268ea2943c9ca4e8c285c12b189bcaae95ae1 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 19 Mar 2013 03:46:24 -1000 Subject: [PATCH 1880/2024] fix set focus for inplace edit clone or ajax --- CHANGELOG | 1 + .../render_field_inplace.html.erb | 7 ++++++- lib/active_scaffold/helpers/list_column_helpers.rb | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 56d6f216be..69a972ba56 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -28,6 +28,7 @@ - Reduce usage of session - Allow to include header on list refreshing - Add search_joins to columns, so it's possible to do left joins without loading associations only for searching +- Fix set focus for inplace edit clone and ajax = 3.2.19 (not released yet) - Avoid crashing when between is chosen and from or to is not filled diff --git a/app/views/active_scaffold_overrides/render_field_inplace.html.erb b/app/views/active_scaffold_overrides/render_field_inplace.html.erb index 337a4c9816..bb068b9096 100644 --- a/app/views/active_scaffold_overrides/render_field_inplace.html.erb +++ b/app/views/active_scaffold_overrides/render_field_inplace.html.erb @@ -1 +1,6 @@ -<%= active_scaffold_input_for(active_scaffold_config.columns[@column.name]) %> +<% + column = active_scaffold_config.columns[@column.name] + options = active_scaffold_input_options(column) + options[:class] = "#{options[:class]} inplace_field" +-%> +<%= active_scaffold_input_for(column, nil, options) %> diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 44eaa71b71..3989f4c6ea 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -226,7 +226,9 @@ def inplace_edit_control(column) column = column.clone column.options = column.options.clone column.form_ui = :select if (column.association && column.form_ui.nil?) - content_tag(:div, active_scaffold_input_for(column), :style => "display:none;", :class => inplace_edit_control_css_class).tap do + options = active_scaffold_input_options(column) + options[:class] = "#{options[:class]} inplace_field" + content_tag(:div, active_scaffold_input_for(column, nil, options), :style => "display:none;", :class => inplace_edit_control_css_class).tap do @record = old_record end end From 5e81dac358ffe2c343e203efa9676b67ee9a8358 Mon Sep 17 00:00:00 2001 From: guycall <ruinenlust@gmail.com> Date: Tue, 19 Mar 2013 23:50:18 +0000 Subject: [PATCH 1881/2024] Update and rename README to README.md Improved the documentation for this branch (rails-3.2) --- README | 66 ------------------------------------------------------ README.md | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 66 deletions(-) delete mode 100644 README create mode 100644 README.md diff --git a/README b/README deleted file mode 100644 index 3bb4a2c94f..0000000000 --- a/README +++ /dev/null @@ -1,66 +0,0 @@ -ActiveScaffold Gem/Plugin by Scott Rutherford (scott@caronsoftware.com), Richard White (rrwhite@gmail.com), Lance Ivy (lance@cainlevy.net), Ed Moss, Tim Harper and Sergio Cambra (sergio@entrecables.com) - -Uses DhtmlHistory by Brad Neuberg (bkn3@columbia.edu) -http://codinginparadise.org - -Uses Querystring by Adam Vandenberg -http://adamv.com/dev/javascript/querystring - -Uses Paginator by Bruce Williams -http://paginator.rubyforge.org/ - -Supports RecordSelect by Lance Ivy -http://code.google.com/p/recordselect/ - -== Version Information - -If you want to use the gem, add to your Gemfile: - gem "active_scaffold" - -In case you would like to use most recent commit: - gem 'active_scaffold', :git => 'git://github.com/activescaffold/active_scaffold.git' - -3.1.* and 3.2.* versions works with rails 3.1 and 3.2, 3.0.* versions with rails 3.0. -To use previous rails versions you will have to install the right branch as a plugin. - -Active Scaffold master currently supports rails 3.1 and rails 3.2, you can use following branches for previous rails versions: -Rails 3.0.*: Active Scaffold rails-3.0 -Rails 2.3.*: Active Scaffold rails-2.3 and v2.4 -Rails 2.2.*: Active Scaffold rails-2.2 -Rails 2.1.*: Active Scaffold rails-2.1 -Rails < 2.1: Active Scaffold 1-1-stable (no guarantees) - -Since Rails 2.3, render_component plugin is needed for nested and embedded scaffolds. It works with rails-2.3 branch from ewildgoose repository: -script/plugin install git://github.com/ewildgoose/render_component.git -r rails-2.3 - -Since Rails 3.0 render_component is not used for nesting, but is optional for embedded scaffolds. -For Rails 3.0, https://github.com/rails/verification.git is also needed, not in rails 3.1 or higher. - -If you want to install as plugins under vendor/plugins, install these versions: - rails plugin install git://github.com/vhochstein/render_component.git - rails plugin install git://github.com/rails/verification.git - rails plugin install git://github.com/activescaffold/active_scaffold.git -r 'rails-3.0' - -== Pick your own javascript framework - -The Rails 3.0 version uses unobtrusive Javascript, so you are free to pick your javascript framework. -Out of the box Prototype or JQuery are supported for rails 3.1 and later. For rails 3.0 pick a JS file: - -Prototype 1.7 (default js framework) -rails.js in git://github.com/vhochstein/prototype-ujs.git - -JQuery 1.4.1, 1.4.2 -https://github.com/vhochstein/jquery-ujs/raw/jquery1_4_2/src/rails.js - -JQuery > 1.4.2 -https://github.com/vhochstein/jquery-ujs/raw/master/src/rails.js - -To configure the javascript framework when installed under vendor/plugins/ -uncomment last line in config/initializers/active_scaffold.rb in order to use jquery instead of prototype. -That file is created when you install ActiveScaffold as a plugin. - -To configure the javascript framework when installed as a gem: -Add a config/initializers/active_scaffold.rb containing: -ActiveScaffold.js_framework = :jquery # :prototype is the default - -Released under the MIT license (included) diff --git a/README.md b/README.md new file mode 100644 index 0000000000..a8100adb4f --- /dev/null +++ b/README.md @@ -0,0 +1,67 @@ +Overview +======== +ActiveScaffold provides a quick and powerful user interfaces for CRUD (create, read, update, delete) operations for Rails applications. It offers additonal features including searching, pagination & layout control. + +Branch Details +-------------- +This branch (rails-3.2) on Github supports Rails 3.1 & 3.2, and is the current source of the 3.2.x line of gems. The master branch has dropped support for Rails 3.1 + +Quick Start +----------- +To get started with a new Rails project + +Added to Gemfile + + gem 'active_scaffold' + +Run the following commands + + bundle install + bundle exec rake db:create + rails g active_scaffold User name:string + bundle exec rake db:migrate + +Add the following line to app/assets/javascripts/application.js + + //= require active_scaffold + +Add the following line to /app/assets/stylesheets/application.css + + *= require active_scaffold + +Run the app and visit localhost:3000/teams + +Configuration +------------- +See Wiki for instructions on customising ActiveScaffold and to find the full API details. + +Compatability Issues +-------------------- +jQuery 1.9 deprecates some methods that this branch still uses (NB: jQuery 1.9 is supported in the master branch). You'll therefore need to ensure you use jQuery 1.8. You can do this by fixing version in your Gemfile: + + gem 'jquery-rails', '2.1.4' + +active_scaffold_batch plugin gem (versions 3.2.x) require the master branch. Therefore if you wish to try using active_scaffold_batch with this branch, you'll need to fork the project and edit the runtime dependency in the gempsec file (use at your own discretion) + +Credits +------- +ActiveScaffold grew out of a project named Ajaxscaffold dating back to 2006. It has had numerous contributors including: + +ActiveScaffold Gem/Plugin by Scott Rutherford (scott@caronsoftware.com), Richard White (rrwhite@gmail.com), Lance Ivy (lance@cainlevy.net), Ed Moss, Tim Harper and Sergio Cambra (sergio@entrecables.com) + +Uses DhtmlHistory by Brad Neuberg (bkn3@columbia.edu) +http://codinginparadise.org + +Uses Querystring by Adam Vandenberg +http://adamv.com/dev/javascript/querystring + +Uses Paginator by Bruce Williams +http://paginator.rubyforge.org/ + +Supports RecordSelect by Lance Ivy +http://code.google.com/p/recordselect/ + + +License +======= +Released under the MIT license (included) From f482b5b285f8aface6c9ec2660359ed2aafaf881 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 20 Mar 2013 10:55:50 +0100 Subject: [PATCH 1882/2024] fix gemspec --- active_scaffold.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index 4e5984d8cb..7e05c654cc 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -12,9 +12,9 @@ Gem::Specification.new do |s| s.summary = %q{Rails 3.1 Version of activescaffold supporting prototype and jquery} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.require_paths = ["lib"] - s.files = `git ls-files {app,config,frontends,lib,public,shoulda_macros,vendor}`.split("\n") + %w[MIT-LICENSE CHANGELOG README] + s.files = `git ls-files {app,config,frontends,lib,public,shoulda_macros,vendor}`.split("\n") + %w[MIT-LICENSE CHANGELOG README.md] s.extra_rdoc_files = [ - "README" + "README.md" ] s.licenses = ["MIT"] s.test_files = `git ls-files test`.split("\n") From 76aa610966ffe8a922bffd90d5b8df68630f00e2 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 20 Mar 2013 13:02:39 +0100 Subject: [PATCH 1883/2024] allow to override label for list column headings --- CHANGELOG | 1 + lib/active_scaffold/helpers/list_column_helpers.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 69a972ba56..dab03fe76f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -29,6 +29,7 @@ - Allow to include header on list refreshing - Add search_joins to columns, so it's possible to do left joins without loading associations only for searching - Fix set focus for inplace edit clone and ajax +- Allow to override label for list column headings with a new helper method column_heading_label = 3.2.19 (not released yet) - Avoid crashing when between is chosen and from or to is not filled diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 3989f4c6ea..e6e7d8a628 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -302,12 +302,16 @@ def column_heading_value(column, sorting, sort_direction) :remote => true, :method => :get} url_options = params_for(:action => :index, :page => 1, :sort => column.name, :sort_direction => sort_direction) - link_to column.label, url_options, options + link_to column_heading_label(column), url_options, options else - content_tag(:p, column.label) + content_tag(:p, column_heading_label(column)) end end + def column_heading_label(column) + column.label + end + def render_nested_view(action_links, record) rendered = [] action_links.member.each do |link| From 5525e37abf7c19bcd173a8f0e9812a4260435936 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 20 Mar 2013 13:03:47 +0100 Subject: [PATCH 1884/2024] 3.2.19 is already released --- CHANGELOG | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index dab03fe76f..8d3b53ae5a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -= master += 3.3.0 (not released yet) - Unify field overrides and list_ui method signatures - Improve performance removing some partials and adding some caching for helper overrides and UIs, and caching url generation for lists (caching url is optional) - Drop support for rails 3.1 @@ -31,7 +31,7 @@ - Fix set focus for inplace edit clone and ajax - Allow to override label for list column headings with a new helper method column_heading_label -= 3.2.19 (not released yet) += 3.2.19 - Avoid crashing when between is chosen and from or to is not filled = 3.2.18 From e9987690162ff3ac19459cec8589e0d35c3e4246 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Thu, 21 Mar 2013 15:00:21 +0100 Subject: [PATCH 1885/2024] Keep focus on last field when render_field is called --- app/assets/javascripts/jquery/active_scaffold.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 432377d158..3593413316 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -5,6 +5,7 @@ jQuery(document).ready(function($) { else alert(error); } + jQuery(document).on('focus', function() { ActiveScaffold.last_focus = this; }); jQuery(document).click(function(event) { jQuery('.action_group.dyn ul').remove(); }); @@ -364,6 +365,7 @@ if (typeof(jQuery.fn.delayedObserver) === 'undefined') { */ var ActiveScaffold = { + last_focus: null, records_for: function(tbody_id) { if (typeof(tbody_id) == 'string') tbody_id = '#' + tbody_id; return jQuery(tbody_id).children('.record'); @@ -860,6 +862,7 @@ var ActiveScaffold = { complete: function(event) { element.nextAll('img.loading-indicator').css('visibility','hidden'); ActiveScaffold.enable_form(as_form); + if (ActiveScaffold.last_focus) $(ActiveScaffold.last_focus).focus().select(); }, error: function (xhr, status, error) { var as_div = element.closest("div.active-scaffold"); From c07b1828f234616510545ed9eb36e122713cb838 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 21 Mar 2013 15:35:17 +0100 Subject: [PATCH 1886/2024] add empty create and update tableless --- CHANGELOG | 2 ++ lib/active_scaffold/tableless.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 8d3b53ae5a..753755d648 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -30,6 +30,8 @@ - Add search_joins to columns, so it's possible to do left joins without loading associations only for searching - Fix set focus for inplace edit clone and ajax - Allow to override label for list column headings with a new helper method column_heading_label +- Keep focus on last field when render_field is called +- Add empty create and update methods to tableless = 3.2.19 - Avoid crashing when between is chosen and from or to is not filled diff --git a/lib/active_scaffold/tableless.rb b/lib/active_scaffold/tableless.rb index 447af4b940..57e84b9fbe 100644 --- a/lib/active_scaffold/tableless.rb +++ b/lib/active_scaffold/tableless.rb @@ -79,4 +79,12 @@ def self.execute_simple_calculation(relation, operation, column_name, distinct) def destroy raise 'destroy must be implemented in a Tableless model' end + + def create #:nodoc: + run_callbacks(:create) {} + end + + def update(*) #:nodoc: + run_callbacks(:update) {} + end end From 1cd771ad15b3f42403925f56e5b4230e1baaabb6 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 21 Mar 2013 17:25:12 +0100 Subject: [PATCH 1887/2024] fix refresh_list after create and update uploading file --- lib/active_scaffold/actions/create.rb | 1 + lib/active_scaffold/actions/update.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 1260358255..574896fedf 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -33,6 +33,7 @@ def new_respond_to_js def create_respond_to_html if params[:iframe]=='true' # was this an iframe post ? + do_refresh_list if successful? && active_scaffold_config.create.refresh_list && !render_parent? responds_to_parent do render :action => 'on_create', :formats => [:js], :layout => false end diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 941735b6f7..ed7d0df1ca 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -34,6 +34,7 @@ def edit_respond_to_js end def update_respond_to_html if params[:iframe]=='true' # was this an iframe post ? + do_refresh_list if successful? && active_scaffold_config.create.refresh_list && !render_parent? responds_to_parent do render :action => 'on_update', :formats => [:js], :layout => false end From 5d3fc91b0d040687caced59a1ce3b66c96ffa8ce Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 21 Mar 2013 19:31:56 +0100 Subject: [PATCH 1888/2024] fix Keep focus on last field --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 3593413316..ad7a58445b 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -5,7 +5,7 @@ jQuery(document).ready(function($) { else alert(error); } - jQuery(document).on('focus', function() { ActiveScaffold.last_focus = this; }); + jQuery(document).on('focus', ':input', function() { ActiveScaffold.last_focus = this; }); jQuery(document).click(function(event) { jQuery('.action_group.dyn ul').remove(); }); From 4fee208e12a1c43de491ab07655d5cfb0741aa70 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 22 Mar 2013 17:30:12 +0100 Subject: [PATCH 1889/2024] fix removing action link --- lib/active_scaffold/data_structures/action_links.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 0922102e3b..f65869b1c5 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -70,8 +70,8 @@ def find_duplicate(link) def delete(val) self.each({:include_set => true}) do |link, set| - if link.action == val.to_s - set.delete_if {|item| item.is_a?(ActiveScaffold::DataStructures::ActionLink) && item.action == val.to_s} + if link.action.to_s == val.to_s + set.delete link end end end @@ -79,7 +79,7 @@ def delete(val) def delete_group(name) @set.each do |group| if group.name == name - @set.delete_if {|item| item.is_a?(ActiveScaffold::DataStructures::ActionLinks) && item.name == name} + @set.delete group else group.delete_group(name) end if group.is_a?(ActiveScaffold::DataStructures::ActionLinks) From e5e7c5341203f2063ef872688be8f319d7b5fb0a Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 25 Mar 2013 15:17:38 +0100 Subject: [PATCH 1890/2024] support outer_joins with sql code --- lib/active_scaffold/extensions/left_outer_joins.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/extensions/left_outer_joins.rb b/lib/active_scaffold/extensions/left_outer_joins.rb index a162b2f6a8..f066407a9d 100644 --- a/lib/active_scaffold/extensions/left_outer_joins.rb +++ b/lib/active_scaffold/extensions/left_outer_joins.rb @@ -13,8 +13,10 @@ def outer_joins_sql(*assocs) assoc.collect do |key, val| [left_outer_join_sql(key), klass.reflect_on_association(key).klass.outer_joins_sql(*val)] end - else - left_outer_join_sql(assoc) if assoc + elsif assoc.is_a? Symbol + left_outer_join_sql(assoc) + elsif assoc + assoc end end.flatten.compact end From f0809062e11f53b8fd56f6ba2ef746ea0d852c4d Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 25 Mar 2013 15:31:02 +0100 Subject: [PATCH 1891/2024] clean helper --- lib/active_scaffold/helpers/form_column_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 82e305bb4f..9f72ec272f 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -191,7 +191,7 @@ def active_scaffold_input_singular_association(column, html_options) select_options.unshift(associated) unless associated.nil? || select_options.include?(associated) method = column.name - options = {:selected => associated.try(:id), :include_blank => as_(:_select_)} + options = {:selected => associated.try(:id), :include_blank => as_(:_select_), :object => html_options.delete(:object)} html_options.update(column.options[:html_options] || {}) options.update(column.options) @@ -245,7 +245,7 @@ def active_scaffold_enum_options(column) end def active_scaffold_input_enum(column, html_options) - options = { :selected => @record.send(column.name) } + options = { :selected => @record.send(column.name), :object => html_options.delete(:object) } options_for_select = active_scaffold_enum_options(column).collect do |text, value| active_scaffold_translated_option(column, text, value) end From f29ba88b73d4fe9ee62db190b2f57b549dec8e6e Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 25 Mar 2013 17:48:41 +0100 Subject: [PATCH 1892/2024] clean queries and improve calculation override --- lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/constraints.rb | 2 +- lib/active_scaffold/finder.rb | 10 +++++----- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index d4a4dadee2..b051ad6635 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -8,7 +8,7 @@ def self.included(base) rescue_from ActiveScaffold::RecordNotAllowed, ActiveScaffold::ActionNotAllowed, :with => :deny_access end base.helper_method :nested? - base.helper_method :calculate + base.helper_method :calculate_query base.helper_method :new_model end def render_field diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 212351e8be..2ad6d9a874 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -79,7 +79,7 @@ def conditions_from_constraints raise ActiveScaffold::MalformedConstraint, constraint_error(active_scaffold_config.model, k), caller end end - conditions + conditions.reject(&:blank?) end # We do NOT want to use .search_sql. If anything, search_sql will refer diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index e2a58a24b2..f30475a2d3 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -304,7 +304,7 @@ def all_conditions conditions_from_params, # from the parameters (e.g. /users/list?first_name=Fred) conditions_from_constraints, # from any constraints (embedded scaffolds) active_scaffold_session_storage[:conditions] # embedding conditions (weaker constraints) - ] + ].reject(&:blank?) end # returns a single record (the given id) but only if it's allowed for the specified security options. @@ -338,7 +338,7 @@ def finder_options(options = {}) end def count_items(find_options = {}, count_includes = nil) - count_includes ||= find_options[:includes] unless find_options[:conditions].nil? + count_includes ||= find_options[:includes] unless find_options[:conditions].blank? options = find_options.reject{|k,v| [:select, :reorder].include? k} options[:includes] = count_includes @@ -383,10 +383,10 @@ def find_page(options = {}) pager.page(options[:page]) end - def calculate(column) + def calculate_query conditions = all_conditions includes = active_scaffold_config.list.count_includes - includes ||= active_scaffold_includes unless conditions.nil? + includes ||= active_scaffold_includes unless conditions.blank? primary_key = active_scaffold_config.model.primary_key subquery = append_to_query(beginning_of_chain, :conditions => conditions, :joins => joins_for_finder, :outer_joins => active_scaffold_outer_joins) subquery = subquery.select(active_scaffold_config.columns[primary_key].field) @@ -394,7 +394,7 @@ def calculate(column) includes_relation = beginning_of_chain.includes(includes) subquery = subquery.send(:apply_join_dependency, subquery, includes_relation.send(:construct_join_dependency_for_association_find)) end - beginning_of_chain.where(primary_key => subquery).calculate(column.calculate, column.name) + active_scaffold_config.model.where(primary_key => subquery) end def append_to_query(query, options) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 89465c439c..f4645ad92d 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -473,7 +473,7 @@ def column_empty?(column_value) def column_calculation(column) unless column.calculate.instance_of? Proc - calculate(column) + calculate_query.calculate(column.calculate, column.name) else column.calculate.call(@records) end From 4331b2a4c514845526d10430177dc5e87610fb93 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Tue, 26 Mar 2013 12:52:05 +0100 Subject: [PATCH 1893/2024] use :object --- lib/active_scaffold/helpers/form_column_helpers.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 9f72ec272f..1164089644 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -14,7 +14,7 @@ def active_scaffold_render_input(column, options) begin # first, check if the dev has created an override for this specific field if (method = override_form_field(column)) - send(method, @record, options) + send(method, options[:object] || @record, options) # second, check if the dev has specified a valid form_ui for this column elsif column.form_ui and (method = override_input(column.form_ui)) send(method, column, options) @@ -29,7 +29,7 @@ def active_scaffold_render_input(column, options) raise "Unknown form_ui `#{column.form_ui}' for column `#{column.name}'" end elsif column.virtual? - options[:value] = format_number_value(@record.send(column.name), column.options) if column.number? + options[:value] = format_number_value((options[:object] || @record).send(column.name), column.options) if column.number? active_scaffold_input_virtual(column, options) else # regular model attribute column @@ -46,7 +46,7 @@ def active_scaffold_render_input(column, options) options[:size] ||= ActionView::Helpers::InstanceTag::DEFAULT_FIELD_OPTIONS["size"] end options[:include_blank] = true if column.column.null and [:date, :datetime, :time].include?(column.column.type) - options[:value] = format_number_value(@record.send(column.name), column.options) if column.number? + options[:value] = format_number_value((options[:object] || @raecord).send(column.name), column.options) if column.number? text_field(:record, column.name, options.merge(column.options)) end end From 3f60dbc9e1b9627c1f9a3afa29546562f803578b Mon Sep 17 00:00:00 2001 From: robg <rob.golkosky@doxo.com> Date: Fri, 29 Mar 2013 15:25:31 -0700 Subject: [PATCH 1894/2024] Don't trigger an association load when checking for unsaved associations --- lib/active_scaffold/extensions/unsaved_associated.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/extensions/unsaved_associated.rb b/lib/active_scaffold/extensions/unsaved_associated.rb index fd6817ed94..860b5096e6 100644 --- a/lib/active_scaffold/extensions/unsaved_associated.rb +++ b/lib/active_scaffold/extensions/unsaved_associated.rb @@ -47,10 +47,10 @@ def associations_for_update # returns false if any yield returns false. # returns true otherwise, even when none of the associations have been instantiated. build wrapper methods accordingly. def with_unsaved_associated - associations_for_update.all? do |association| - association_proxy = send(association.name) - if association_proxy - records = association_proxy + associations_for_update.all? do |assoc| + association_proxy = self.association(assoc.name) + if association_proxy.target.present? + records = association_proxy.target records = [records] unless records.is_a? Array # convert singular associations into collections for ease of use records.select {|r| r.unsaved? and not r.readonly?}.all? {|r| yield r} # must use select instead of find_all, which Rails overrides on association proxies for db access else From a7737d37281611a4d647957985e5a64e4dcb715c Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 1 Apr 2013 14:29:56 +0200 Subject: [PATCH 1895/2024] improve some notes about 3.2 and 3.3 versions --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a8100adb4f..628f8b2b8a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ActiveScaffold provides a quick and powerful user interfaces for CRUD (create, r Branch Details -------------- -This branch (rails-3.2) on Github supports Rails 3.1 & 3.2, and is the current source of the 3.2.x line of gems. The master branch has dropped support for Rails 3.1 +rails-3.2 branch on Github supports Rails 3.1 & 3.2, and is the current source of the 3.2.x line of gems. The master branch (3.3.x) has dropped support for Rails 3.1 Quick Start ----------- @@ -37,11 +37,11 @@ See Wiki for instructions on customising ActiveScaffold and to find the full API Compatability Issues -------------------- -jQuery 1.9 deprecates some methods that this branch still uses (NB: jQuery 1.9 is supported in the master branch). You'll therefore need to ensure you use jQuery 1.8. You can do this by fixing version in your Gemfile: +jQuery 1.9 deprecates some methods that rails-3.2 branch still uses (NB: jQuery 1.9 is supported in 3.3.x, the master branch). You'll therefore need to ensure you use jQuery 1.8. You can do this by fixing version in your Gemfile: gem 'jquery-rails', '2.1.4' -active_scaffold_batch plugin gem (versions 3.2.x) require the master branch. Therefore if you wish to try using active_scaffold_batch with this branch, you'll need to fork the project and edit the runtime dependency in the gempsec file (use at your own discretion) +active_scaffold_batch plugin gem (versions 3.2.x) require 3.3.x (master branch). Therefore if you wish to try using active_scaffold_batch with this branch, you'll need to fork the project and edit the runtime dependency in the gemspec file (use at your own discretion) Credits ------- From 6b20854609601ce2d3746dcbf2742979ba8a29c0 Mon Sep 17 00:00:00 2001 From: Guillaume Montard <montard@vodeclic.com> Date: Tue, 2 Apr 2013 17:35:51 +0200 Subject: [PATCH 1896/2024] Debug TinyMce Bridge --- lib/active_scaffold/bridges/tiny_mce/helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/tiny_mce/helpers.rb b/lib/active_scaffold/bridges/tiny_mce/helpers.rb index 0301c8c557..827e937f5e 100644 --- a/lib/active_scaffold/bridges/tiny_mce/helpers.rb +++ b/lib/active_scaffold/bridges/tiny_mce/helpers.rb @@ -16,7 +16,7 @@ def active_scaffold_input_text_editor(column, options) options[:class] = "#{options[:class]} mceEditor #{column.options[:class]}".strip settings = { :theme => 'simple' }.merge(column.options[:tinymce] || {}) - settings = settings.to_s.gsub(/:(.+?)\=\>/, '\1:') + settings = settings.to_json settings = "tinyMCE.settings = #{settings};" html = [] From 5443cb05c3b3d23ea05930578272be87cfe98c41 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 5 Apr 2013 11:43:26 +0200 Subject: [PATCH 1897/2024] fix checking methods in ruby 1.9 --- lib/active_scaffold.rb | 1 + lib/active_scaffold/bridges/calendar_date_select.rb | 2 +- lib/active_scaffold/bridges/file_column.rb | 2 +- .../bridges/file_column/as_file_column_bridge.rb | 2 +- .../bridges/file_column/file_column_helpers.rb | 4 ++-- lib/active_scaffold/bridges/paperclip.rb | 2 +- .../bridges/paperclip/paperclip_bridge_helpers.rb | 2 +- 7 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 4ebb4446cc..326d0fec8f 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -16,6 +16,7 @@ require 'json' # for js_config module ActiveScaffold + METHOD_CONVERSION = RUBY_VERSION < '1.9' ? :to_s : :to_sym autoload :AttributeParams, 'active_scaffold/attribute_params' autoload :Configurable, 'active_scaffold/configurable' autoload :Constraints, 'active_scaffold/constraints' diff --git a/lib/active_scaffold/bridges/calendar_date_select.rb b/lib/active_scaffold/bridges/calendar_date_select.rb index 0849c90ac7..54a610a898 100644 --- a/lib/active_scaffold/bridges/calendar_date_select.rb +++ b/lib/active_scaffold/bridges/calendar_date_select.rb @@ -3,7 +3,7 @@ def self.install # check to see if the old bridge was installed. If so, warn them # we can detect this by checking to see if the bridge was installed before calling this code - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_calendar_date_select") + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_calendar_date_select".send(::ActiveScaffol::METHOD_CONVERSION)) raise RuntimeError, "We've detected that you have active_scaffold_calendar_date_select_bridge installed. This plugin has been moved to core. Please remove active_scaffold_calendar_date_select_bridge to prevent any conflicts" end diff --git a/lib/active_scaffold/bridges/file_column.rb b/lib/active_scaffold/bridges/file_column.rb index 25b92fdddc..4106411982 100644 --- a/lib/active_scaffold/bridges/file_column.rb +++ b/lib/active_scaffold/bridges/file_column.rb @@ -1,6 +1,6 @@ class ActiveScaffold::Bridges::FileColumn < ActiveScaffold::DataStructures::Bridge def self.install - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_file_column") + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_file_column".send(::ActiveScaffol::METHOD_CONVERSION)) raise RuntimeError, "We've detected that you have active_scaffold_file_column_bridge installed. This plugin has been moved to core. Please remove active_scaffold_file_column_bridge to prevent any conflicts" end require File.join(File.dirname(__FILE__), "file_column/as_file_column_bridge") diff --git a/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb b/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb index 9fec882bc5..59e017d4d5 100644 --- a/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +++ b/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb @@ -24,7 +24,7 @@ def initialize_with_file_column(model_id) } end - alias_method_chain :initialize, :file_column unless self.instance_methods.include?("initialize_without_file_column") + alias_method_chain :initialize, :file_column unless self.instance_methods.include?("initialize_without_file_column".send(::ActiveScaffol::METHOD_CONVERSION)) def configure_file_column_field(field) # set list_ui first because it gets its default value from form_ui diff --git a/lib/active_scaffold/bridges/file_column/file_column_helpers.rb b/lib/active_scaffold/bridges/file_column/file_column_helpers.rb index 5a235f544b..cd15620ceb 100644 --- a/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +++ b/lib/active_scaffold/bridges/file_column/file_column_helpers.rb @@ -4,12 +4,12 @@ class FileColumn module FileColumnHelpers class << self def file_column_fields(klass) - klass.instance_methods.grep(/_just_uploaded\?$/).collect{|m| m[0..-16].to_sym } + klass.instance_methods.select{|m| m.to_s =~ /_just_uploaded\?$/}.collect{|m| m[0..-16].to_sym } end def generate_delete_helpers(klass) file_column_fields(klass).each { |field| - klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("#{field}_with_delete=") + klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("#{field}_with_delete=".send(::ActiveScaffol::METHOD_CONVERSION)) attr_reader :delete_#{field} def delete_#{field}=(value) diff --git a/lib/active_scaffold/bridges/paperclip.rb b/lib/active_scaffold/bridges/paperclip.rb index de8a61aed1..7b5d8c2640 100644 --- a/lib/active_scaffold/bridges/paperclip.rb +++ b/lib/active_scaffold/bridges/paperclip.rb @@ -1,6 +1,6 @@ class ActiveScaffold::Bridges::Paperclip < ActiveScaffold::DataStructures::Bridge def self.install - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip") + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip".send(::ActiveScaffol::METHOD_CONVERSION)) raise RuntimeError, "We've detected that you have active_scaffold_paperclip_bridge installed. This plugin has been moved to core. Please remove active_scaffold_paperclip_bridge to prevent any conflicts" end require File.join(File.dirname(__FILE__), "paperclip/form_ui") diff --git a/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb b/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb index c1706c11fb..a2a8715737 100644 --- a/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +++ b/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb @@ -6,7 +6,7 @@ module PaperclipBridgeHelpers self.thumbnail_style = :thumbnail def self.generate_delete_helper(klass, field) - klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.instance_methods.include?("delete_#{field}=") + klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.instance_methods.include?("delete_#{field}=".send(::ActiveScaffol::METHOD_CONVERSION)) attr_reader :delete_#{field} def delete_#{field}=(value) From d77fec609cb1e0aa48c81a7841870e72f79fbe98 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 5 Apr 2013 11:46:37 +0200 Subject: [PATCH 1898/2024] update changelog --- CHANGELOG | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 753755d648..3029b01a3f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -33,6 +33,10 @@ - Keep focus on last field when render_field is called - Add empty create and update methods to tableless += 3.2.20 (not released yet) +- Some fixes for ruby 1.9 +- Some fixes for rails 3.1 + = 3.2.19 - Avoid crashing when between is chosen and from or to is not filled From 092712d10944cff6a9669b5102269a990c84460c Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 5 Apr 2013 12:03:48 +0200 Subject: [PATCH 1899/2024] fix typo --- lib/active_scaffold/bridges/calendar_date_select.rb | 2 +- lib/active_scaffold/bridges/file_column.rb | 2 +- .../bridges/file_column/as_file_column_bridge.rb | 2 +- lib/active_scaffold/bridges/file_column/file_column_helpers.rb | 2 +- lib/active_scaffold/bridges/paperclip.rb | 2 +- .../bridges/paperclip/paperclip_bridge_helpers.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/bridges/calendar_date_select.rb b/lib/active_scaffold/bridges/calendar_date_select.rb index 54a610a898..655d578a51 100644 --- a/lib/active_scaffold/bridges/calendar_date_select.rb +++ b/lib/active_scaffold/bridges/calendar_date_select.rb @@ -3,7 +3,7 @@ def self.install # check to see if the old bridge was installed. If so, warn them # we can detect this by checking to see if the bridge was installed before calling this code - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_calendar_date_select".send(::ActiveScaffol::METHOD_CONVERSION)) + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_calendar_date_select".send(::ActiveScaffold::METHOD_CONVERSION)) raise RuntimeError, "We've detected that you have active_scaffold_calendar_date_select_bridge installed. This plugin has been moved to core. Please remove active_scaffold_calendar_date_select_bridge to prevent any conflicts" end diff --git a/lib/active_scaffold/bridges/file_column.rb b/lib/active_scaffold/bridges/file_column.rb index 4106411982..6573fac02a 100644 --- a/lib/active_scaffold/bridges/file_column.rb +++ b/lib/active_scaffold/bridges/file_column.rb @@ -1,6 +1,6 @@ class ActiveScaffold::Bridges::FileColumn < ActiveScaffold::DataStructures::Bridge def self.install - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_file_column".send(::ActiveScaffol::METHOD_CONVERSION)) + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_file_column".send(::ActiveScaffold::METHOD_CONVERSION)) raise RuntimeError, "We've detected that you have active_scaffold_file_column_bridge installed. This plugin has been moved to core. Please remove active_scaffold_file_column_bridge to prevent any conflicts" end require File.join(File.dirname(__FILE__), "file_column/as_file_column_bridge") diff --git a/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb b/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb index 59e017d4d5..10987440ed 100644 --- a/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +++ b/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb @@ -24,7 +24,7 @@ def initialize_with_file_column(model_id) } end - alias_method_chain :initialize, :file_column unless self.instance_methods.include?("initialize_without_file_column".send(::ActiveScaffol::METHOD_CONVERSION)) + alias_method_chain :initialize, :file_column unless self.instance_methods.include?("initialize_without_file_column".send(::ActiveScaffold::METHOD_CONVERSION)) def configure_file_column_field(field) # set list_ui first because it gets its default value from form_ui diff --git a/lib/active_scaffold/bridges/file_column/file_column_helpers.rb b/lib/active_scaffold/bridges/file_column/file_column_helpers.rb index cd15620ceb..57acac9715 100644 --- a/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +++ b/lib/active_scaffold/bridges/file_column/file_column_helpers.rb @@ -9,7 +9,7 @@ def file_column_fields(klass) def generate_delete_helpers(klass) file_column_fields(klass).each { |field| - klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("#{field}_with_delete=".send(::ActiveScaffol::METHOD_CONVERSION)) + klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("#{field}_with_delete=".send(::ActiveScaffold::METHOD_CONVERSION)) attr_reader :delete_#{field} def delete_#{field}=(value) diff --git a/lib/active_scaffold/bridges/paperclip.rb b/lib/active_scaffold/bridges/paperclip.rb index 7b5d8c2640..2314870caa 100644 --- a/lib/active_scaffold/bridges/paperclip.rb +++ b/lib/active_scaffold/bridges/paperclip.rb @@ -1,6 +1,6 @@ class ActiveScaffold::Bridges::Paperclip < ActiveScaffold::DataStructures::Bridge def self.install - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip".send(::ActiveScaffol::METHOD_CONVERSION)) + if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip".send(::ActiveScaffold::METHOD_CONVERSION)) raise RuntimeError, "We've detected that you have active_scaffold_paperclip_bridge installed. This plugin has been moved to core. Please remove active_scaffold_paperclip_bridge to prevent any conflicts" end require File.join(File.dirname(__FILE__), "paperclip/form_ui") diff --git a/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb b/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb index a2a8715737..b460ac8971 100644 --- a/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +++ b/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb @@ -6,7 +6,7 @@ module PaperclipBridgeHelpers self.thumbnail_style = :thumbnail def self.generate_delete_helper(klass, field) - klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.instance_methods.include?("delete_#{field}=".send(::ActiveScaffol::METHOD_CONVERSION)) + klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.instance_methods.include?("delete_#{field}=".send(::ActiveScaffold::METHOD_CONVERSION)) attr_reader :delete_#{field} def delete_#{field}=(value) From 7531a223dfd2e4d4ef2de26180df72da40499545 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 5 Apr 2013 00:08:21 -1000 Subject: [PATCH 1900/2024] fix render_field when beginning_of_chain is overrided and params are needed --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 1164089644..b52e739076 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -110,7 +110,7 @@ def update_columns_options(column, scope, options) active_scaffold_config.send(@record.new_record? ? :create : :update) end if form_action && column.update_columns && (column.update_columns & form_action.columns.names).present? - url_params = {:action => 'render_field', :column => column.name, :id => nil} + url_params = params_for(:action => 'render_field', :column => column.name, :id => nil) url_params[:id] = @record.id if column.send_form_on_update_column url_params[:eid] = params[:eid] if params[:eid] if scope From 45810a0518ad9ca81a052ba924f234791f2c1dfc Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 5 Apr 2013 12:43:21 +0200 Subject: [PATCH 1901/2024] fix create_associated_record_row when views are overrided and more tfoot are added --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index ad7a58445b..c8be1914e2 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -680,7 +680,7 @@ var ActiveScaffold = { content = jQuery(content); if (options.singular == false) { if (!(options.id && jQuery('#' + options.id).size() > 0)) { - var tfoot = element.find('tfoot'); + var tfoot = element.children('tfoot'); if (tfoot.length) tfoot.before(content); else element.append(content); content.trigger('as:element_created'); From c4a685dc0b478bab44fc6bfaf2c436fad004e04b Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 5 Apr 2013 14:28:58 +0200 Subject: [PATCH 1902/2024] fix detection of empty for has_and_belongs_to_many on subforms, fixes #258 --- lib/active_scaffold/attribute_params.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index c1331dd202..a4edb1e340 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -217,7 +217,7 @@ def attributes_hash_is_empty?(hash, klass) if value.is_a?(Hash) attributes_hash_is_empty?(value, klass) elsif value.is_a?(Array) - value.any? {|id| id.respond_to?(:empty?) ? !id.empty? : true} + value.all?(&:blank?) else value.respond_to?(:empty?) ? value.empty? : false end From cf3f7ed09e2cda3690ac281cc53e9da7ee0377bb Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 5 Apr 2013 14:29:35 +0200 Subject: [PATCH 1903/2024] add changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 3029b01a3f..4d3a6c2276 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -36,6 +36,7 @@ = 3.2.20 (not released yet) - Some fixes for ruby 1.9 - Some fixes for rails 3.1 +- Fix detection of empty for has_and_belongs_to_many on subforms = 3.2.19 - Avoid crashing when between is chosen and from or to is not filled From a9f09948aa0a09b36e9c0e01980f6c723725c16a Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 5 Apr 2013 14:30:29 +0200 Subject: [PATCH 1904/2024] Update changelog --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 4d3a6c2276..b36ab05be0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -33,7 +33,7 @@ - Keep focus on last field when render_field is called - Add empty create and update methods to tableless -= 3.2.20 (not released yet) += 3.2.20 - Some fixes for ruby 1.9 - Some fixes for rails 3.1 - Fix detection of empty for has_and_belongs_to_many on subforms From bd85bfc97adddfc77703121c6b13c9726c77f838 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 5 Apr 2013 15:11:25 +0200 Subject: [PATCH 1905/2024] always send id for render_field --- lib/active_scaffold/helpers/form_column_helpers.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index b52e739076..8ff85f76a9 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -110,8 +110,7 @@ def update_columns_options(column, scope, options) active_scaffold_config.send(@record.new_record? ? :create : :update) end if form_action && column.update_columns && (column.update_columns & form_action.columns.names).present? - url_params = params_for(:action => 'render_field', :column => column.name, :id => nil) - url_params[:id] = @record.id if column.send_form_on_update_column + url_params = params_for(:action => 'render_field', :column => column.name, :id => @record.id) url_params[:eid] = params[:eid] if params[:eid] if scope url_params[:controller] = subform_controller.controller_path From cb3a1ce003148ef7759c5ef7ee36a55859a46ce2 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 5 Apr 2013 19:21:28 +0200 Subject: [PATCH 1906/2024] allow multiple subform levels --- CHANGELOG | 1 + .../_form_association.html.erb | 2 +- .../_form_association_footer.html.erb | 10 ++++++---- .../_horizontal_subform.html.erb | 2 +- .../_vertical_subform.html.erb | 2 +- .../active_scaffold_overrides/edit_associated.js.erb | 2 +- lib/active_scaffold/actions/subform.rb | 3 ++- lib/active_scaffold/helpers/controller_helpers.rb | 12 +++++++++++- lib/active_scaffold/helpers/view_helpers.rb | 4 ---- 9 files changed, 24 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b36ab05be0..b00e1d4711 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -32,6 +32,7 @@ - Allow to override label for list column headings with a new helper method column_heading_label - Keep focus on last field when render_field is called - Add empty create and update methods to tableless +- Allow multiple subform levels = 3.2.20 - Some fixes for ruby 1.9 diff --git a/app/views/active_scaffold_overrides/_form_association.html.erb b/app/views/active_scaffold_overrides/_form_association.html.erb index ab48385f44..f183b5db16 100644 --- a/app/views/active_scaffold_overrides/_form_association.html.erb +++ b/app/views/active_scaffold_overrides/_form_association.html.erb @@ -6,7 +6,7 @@ if show_blank_record = column.show_blank_record?(associated) associated << build_associated(column, parent_record) end @disable_required_for_new = show_blank_record unless (column.singular_association? && column.required?) -subform_div_id = "#{sub_form_id({:association => column.name, :id => parent_record.id || 99999999999})}-div" +subform_div_id = "#{sub_form_id(:association => column.name, :id => parent_record.id || generated_id(parent_record) || 99999999999)}-div" -%> <h5><%= column.label -%></h5> <div id ="<%= subform_div_id %>" <%= 'style="display: none;"'.html_safe if column.collapsed -%>> diff --git a/app/views/active_scaffold_overrides/_form_association_footer.html.erb b/app/views/active_scaffold_overrides/_form_association_footer.html.erb index 51449637d0..0df7b32538 100644 --- a/app/views/active_scaffold_overrides/_form_association_footer.html.erb +++ b/app/views/active_scaffold_overrides/_form_association_footer.html.erb @@ -11,8 +11,10 @@ show_add_new = column_show_add_new(column, associated, @record) return unless show_add_new or show_add_existing -edit_associated_url = params_for(:action => 'edit_associated', :child_association => column.name, :associated_id => '--ID--', :scope => scope) if show_add_existing -add_new_url = params_for(:action => 'edit_associated', :child_association => column.name, :scope => scope) if show_add_new +temporary_id = generated_id(parent_record) if parent_record.new_record? +controller_path = active_scaffold_controller_for(parent_record.class).controller_path +edit_associated_url = params_for(:controller => controller_path, :action => 'edit_associated', :child_association => column.name, :associated_id => '--ID--', :scope => scope, :id => parent_record.id, :generated_id => temporary_id, :parent_controller => controller.controller_path) if show_add_existing +add_new_url = params_for(:controller => controller_path, :action => 'edit_associated', :child_association => column.name, :scope => scope, :id => parent_record.id, :generated_id => temporary_id, :parent_controller => controller.controller_path) if show_add_new -%> <div class="footer-wrapper"> @@ -25,7 +27,7 @@ add_new_url = params_for(:action => 'edit_associated', :child_association => col add_label = as_(:replace_with_new) add_class = 'as_replace_with_new' end - create_another_id = "#{sub_form_id(:association => column.name)}-create-another" %> + create_another_id = "#{sub_form_id(:association => column.name, :id => parent_record.id || temporary_id || 99999999999)}-create-another" %> <%= link_to add_label, add_new_url, :id => create_another_id, :remote => true, :class => add_class, :style=> "display: none;" %> <%= javascript_tag("ActiveScaffold.show('#{create_another_id}');") %> <% end -%> @@ -37,7 +39,7 @@ add_new_url = params_for(:action => 'edit_associated', :child_association => col <%= link_to_record_select as_(:add_existing), remote_controller.controller_path, :onselect => "ActiveScaffold.record_select_onselect(#{url_for(edit_associated_url).to_json}, #{active_scaffold_id.to_json}, id);" -%> <% else -%> <% select_options = options_from_collection_for_select(sorted_association_options_find(column.association), :id, :to_label) - add_existing_id = "#{sub_form_id(:association => column.name)}-add-existing" + add_existing_id = "#{sub_form_id(:association => column.name, :id => parent_record.id || temporary_id || 99999999999)}-add-existing" add_existing_label = column.plural_association? ? :add_existing : :replace_existing %> <%= select_tag 'associated_id', '<option value="">'.html_safe + as_(:_select_) + '</option>'.html_safe + select_options %> <%= link_to as_(add_existing_label), edit_associated_url, :id => add_existing_id, :remote => true, :class=> "as_#{add_existing_label}", :style => "display: none;" %> diff --git a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb index 22c1e09fe6..461f940936 100644 --- a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +++ b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb @@ -1,4 +1,4 @@ -<table cellpadding="0" cellspacing="0" id="<%= sub_form_list_id(:association => column.name) %>"> +<table cellpadding="0" cellspacing="0" id="<%= sub_form_list_id(:association => column.name, :id => parent_record.id || generated_id(parent_record) || 99999999999) %>"> <% @record = associated.empty? ? build_associated(column, parent_record) : associated.last -%> <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record, :record => @record} %> diff --git a/app/views/active_scaffold_overrides/_vertical_subform.html.erb b/app/views/active_scaffold_overrides/_vertical_subform.html.erb index 1cde1bd48e..22572e0d04 100644 --- a/app/views/active_scaffold_overrides/_vertical_subform.html.erb +++ b/app/views/active_scaffold_overrides/_vertical_subform.html.erb @@ -1,4 +1,4 @@ -<div id="<%= sub_form_list_id(:association => column.name) %>"> +<div id="<%= sub_form_list_id(:association => column.name, :id => parent_record.id || generated_id(parent_record) || 99999999999) %>"> <% associated.each_index do |index| %> <% @record = associated[index] -%> <%= render :partial => 'form_association_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last, :index => index} %> diff --git a/app/views/active_scaffold_overrides/edit_associated.js.erb b/app/views/active_scaffold_overrides/edit_associated.js.erb index fd7c067576..9a49abfa01 100644 --- a/app/views/active_scaffold_overrides/edit_associated.js.erb +++ b/app/views/active_scaffold_overrides/edit_associated.js.erb @@ -9,4 +9,4 @@ else options[:id] = active_scaffold_input_options(column, @scope)[:id] end end %> -ActiveScaffold.create_associated_record_form('<%=sub_form_list_id(:association => @column.name)%>','<%=escape_javascript(associated_form)%>', <%= options.to_json.html_safe %>); +ActiveScaffold.create_associated_record_form('<%=sub_form_list_id(:association => @column.name, :id => @parent_record.id || generated_id(@parent_record) || 99999999999)%>','<%=escape_javascript(associated_form)%>', <%= options.to_json.html_safe %>); diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index 7fe4e85e6b..e9609f1b60 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -9,6 +9,7 @@ def edit_associated def do_edit_associated @parent_record = params[:id].nil? ? new_model : find_if_allowed(params[:id], :update) + generate_temporary_id(@parent_record, params[:generated_id]) if @parent_record.new_record? && params[:generated_id] @column = active_scaffold_config.columns[params[:child_association]] # NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all. @@ -16,7 +17,7 @@ def do_edit_associated @record ||= build_associated(@column, @parent_record) @scope = "#{params[:scope]}[#{@column.name}]" - @scope += (@record.new_record?) ? "[#{(Time.now.to_f*1000).to_i.to_s}]" : "[#{@record.id}]" if @column.plural_association? + @scope += "[#{@record.id || generate_temporary_id(@record)}]" if @column.plural_association? end end diff --git a/lib/active_scaffold/helpers/controller_helpers.rb b/lib/active_scaffold/helpers/controller_helpers.rb index 3eef53a5a8..abc5db09b7 100644 --- a/lib/active_scaffold/helpers/controller_helpers.rb +++ b/lib/active_scaffold/helpers/controller_helpers.rb @@ -2,11 +2,21 @@ module ActiveScaffold module Helpers module ControllerHelpers def self.included(controller) - controller.class_eval { helper_method :params_for, :conditions_from_params, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated} + controller.class_eval { helper_method :params_for, :conditions_from_params, :main_path_to_return, :render_parent?, :render_parent_options, :render_parent_action, :nested_singular_association?, :build_associated, :generate_temporary_id, :generated_id} end include ActiveScaffold::Helpers::IdHelpers + def generate_temporary_id(record = nil, generated_id = nil) + (generated_id || (Time.now.to_f*1000).to_i.to_s).tap do |id| + (@temporary_ids ||= {})[record.class.name] = id if record + end + end + + def generated_id(record) + @temporary_ids[record.class.name] if record && @temporary_ids + end + def params_for(options = {}) # :adapter and :position are one-use rendering arguments. they should not propagate. # :sort, :sort_direction, and :page are arguments that stored in the session. they need not propagate. diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index f4645ad92d..7c32fe5352 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -49,10 +49,6 @@ def template_exists?(template_name, partial = false) lookup_context.exists? template_name, '', partial end - def generate_temporary_id - (Time.now.to_f*1000).to_i.to_s - end - # Turns [[label, value]] into <option> tags # Takes optional parameter of :include_blank def option_tags_for(select_options, options = {}) From 80cc09b85e553114fb734a8871ff807dd92cce63 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 9 Apr 2013 01:47:37 -1000 Subject: [PATCH 1907/2024] fix render_field on nested scaffolds --- lib/active_scaffold/helpers/form_column_helpers.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 8ff85f76a9..c91556e0c5 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -111,6 +111,7 @@ def update_columns_options(column, scope, options) end if form_action && column.update_columns && (column.update_columns & form_action.columns.names).present? url_params = params_for(:action => 'render_field', :column => column.name, :id => @record.id) + url_params = url_params.except(:parent_scaffold, :association, nested.param_name) if nested? url_params[:eid] = params[:eid] if params[:eid] if scope url_params[:controller] = subform_controller.controller_path From 328d7778e891901461fa66edabf87697c88d3112 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Tue, 9 Apr 2013 18:16:43 +0200 Subject: [PATCH 1908/2024] fix includes for show columns with groups --- lib/active_scaffold/actions/list.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 41d230b49f..aa72086ca3 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -61,7 +61,7 @@ def row_respond_to_js # The actual algorithm to prepare for the list view def set_includes_for_columns(action = :list) @cache_associations = true - includes_for_list_columns = active_scaffold_config.send(action).columns.collect{ |c| c.includes }.flatten.uniq.compact + includes_for_list_columns = active_scaffold_config.send(action).columns.collect_visible(:flatten => true){ |c| c.includes }.flatten.uniq.compact self.active_scaffold_includes.concat includes_for_list_columns end From 11988fff0f01666b1cc902a9b5824248e11b2e49 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Tue, 9 Apr 2013 18:16:58 +0200 Subject: [PATCH 1909/2024] add column_default_value to check defaults on virtual columns --- lib/active_scaffold/attribute_params.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index a4edb1e340..933e6f9287 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -212,7 +212,7 @@ def attributes_hash_is_empty?(hash, klass) next true if column and ignore_column_types.include?(column.type) # defaults are pre-filled on the form. we can't use them to determine if the user intends a new row. - next true if column and value == column.default.to_s + next true if value == column_default_value(column_name, klass, column) if value.is_a?(Hash) attributes_hash_is_empty?(value, klass) @@ -223,5 +223,9 @@ def attributes_hash_is_empty?(hash, klass) end end end + + def column_default_value(column_name, klass, column) + column.default.to_s if column + end end end From fb0b08c8487a0e212201fce08a7259c0f6b82bea Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Tue, 9 Apr 2013 18:31:36 +0200 Subject: [PATCH 1910/2024] fix required on html5 for auto blank records with multilevel subforms --- app/views/active_scaffold_overrides/_form_association.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_form_association.html.erb b/app/views/active_scaffold_overrides/_form_association.html.erb index f183b5db16..2d11dae14e 100644 --- a/app/views/active_scaffold_overrides/_form_association.html.erb +++ b/app/views/active_scaffold_overrides/_form_association.html.erb @@ -5,6 +5,7 @@ associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless if show_blank_record = column.show_blank_record?(associated) associated << build_associated(column, parent_record) end +disable_required_for_new = @disable_required_for_new @disable_required_for_new = show_blank_record unless (column.singular_association? && column.required?) subform_div_id = "#{sub_form_id(:association => column.name, :id => parent_record.id || generated_id(parent_record) || 99999999999)}-div" -%> @@ -18,5 +19,5 @@ subform_div_id = "#{sub_form_id(:association => column.name, :id => parent_recor <%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%> <% @record = parent_record - @disable_required_for_new = nil + @disable_required_for_new = disable_required_for_new -%> From 07acb9bdeceee8e59c84a8b86d3bad67b3a49e4f Mon Sep 17 00:00:00 2001 From: Miguel Guinada <mguinada@gmail.com> Date: Tue, 9 Apr 2013 17:52:03 +0100 Subject: [PATCH 1911/2024] Adds a default entry to I18n to ActiveScaffold::Bridges::DatePicker --- lib/active_scaffold/bridges/date_picker/helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index e9240215f9..3a02d0e50a 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -71,7 +71,7 @@ def self.datetime_options_for_locales def self.datetime_options(locale) begin - rails_time_format = I18n.translate! 'time.formats.picker', :locale => locale + rails_time_format = I18n.translate! 'time.formats.picker', :locale => locale, :default => '%a, %d %b %Y %H:%M:%S' datetime_picker_options = {:ampm => false, :hourText => I18n.translate!('datetime.prompts.hour', :locale => locale), :minuteText => I18n.translate!('datetime.prompts.minute', :locale => locale), From 970fbde098e59a689f62bdd5e4fe660b2aa5a5ce Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 10 Apr 2013 16:04:10 +0200 Subject: [PATCH 1912/2024] fix generator for namespaced model, fixes #263 --- .../active_scaffold_controller/templates/controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/generators/active_scaffold_controller/templates/controller.rb b/lib/generators/active_scaffold_controller/templates/controller.rb index 5f8638b5b0..c1c52b7b09 100644 --- a/lib/generators/active_scaffold_controller/templates/controller.rb +++ b/lib/generators/active_scaffold_controller/templates/controller.rb @@ -1,4 +1,10 @@ +<% if namespaced? -%> +require_dependency "<%= namespaced_file_path %>/application_controller" + +<% end -%> +<% module_namespacing do -%> class <%= controller_class_name %>Controller < ApplicationController - active_scaffold :<%= class_name.demodulize.underscore %> do |conf| + active_scaffold :"<%= class_name.underscore %>" do |conf| end end +<% end -%> From 726412f59904e0539a51bdf98863b9b3be770ba8 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 10 Apr 2013 16:53:36 +0200 Subject: [PATCH 1913/2024] fix respond_to for rails 2.0, fixes #250 --- lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/actions/list.rb | 6 +++--- lib/active_scaffold/actions/mark.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index b051ad6635..417579fce0 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -185,7 +185,7 @@ def respond_to_action(action) respond_to do |type| action_formats.each do |format| type.send(format) do - if respond_to?(method_name = "#{action}_respond_to_#{format}") + if respond_to?(method_name = "#{action}_respond_to_#{format}", true) send(method_name) end end diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index aa72086ca3..4c46bf3fce 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -100,20 +100,20 @@ def do_list def do_refresh_list params.delete(:id) - do_search if respond_to? :do_search + do_search if respond_to? :do_search, true do_list end def each_record_in_page _page = active_scaffold_config.list.user.page - do_search if respond_to? :do_search + do_search if respond_to? :do_search, true active_scaffold_config.list.user.page = _page do_list @page.items.each {|record| yield record} end def each_record_in_scope - do_search if respond_to? :do_search + do_search if respond_to? :do_search, true append_to_query(beginning_of_chain, finder_options).all.each {|record| yield record} end diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index 42958b1921..04b4ae8f6f 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -28,7 +28,7 @@ def mark_respond_to_html def mark_respond_to_js if params[:id] - do_search if respond_to? :do_search + do_search if respond_to? :do_search, true set_includes_for_columns if active_scaffold_config.actions.include? :list @page = find_page(:pagination => active_scaffold_config.mark.mark_all_mode != :page) render :action => 'on_mark' From 7651fa62a8d871d8511b3df13745deb81011fc31 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 11 Apr 2013 11:59:26 +0200 Subject: [PATCH 1914/2024] close all open adapters before delete row, try to fix #264 --- app/assets/javascripts/jquery/active_scaffold.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index c8be1914e2..dcd01ec2bf 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -556,13 +556,10 @@ var ActiveScaffold = { row = jQuery(row); var tbody = row.closest('tbody.records'); - var current_action_node = row.find('td.actions a.disabled').first(); - if (current_action_node) { - var action_link = ActiveScaffold.ActionLink.get(current_action_node); - if (action_link) { - action_link.close_previous_adapter(); - } - } + row.find('a.disabled').each(function() {; + var action_link = ActiveScaffold.ActionLink.get(this); + if (action_link) action_link.close(); + }); ActiveScaffold.remove(row, function() { ActiveScaffold.stripe(tbody); From 6e563f7e1eb8709ed6ac7448f586ee728624a17b Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Thu, 18 Apr 2013 13:07:16 +0200 Subject: [PATCH 1915/2024] only hide columns when there is a form_action --- app/views/active_scaffold_overrides/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_form.html.erb b/app/views/active_scaffold_overrides/_form.html.erb index 159de95ab7..1db47f4d09 100644 --- a/app/views/active_scaffold_overrides/_form.html.erb +++ b/app/views/active_scaffold_overrides/_form.html.erb @@ -1,7 +1,7 @@ <% scope ||= nil subsection_id ||= nil - show_unauthorized_columns = active_scaffold_config.send(form_action).show_unauthorized_columns + show_unauthorized_columns = active_scaffold_config.send(form_action).show_unauthorized_columns if active_scaffold_config.actions.include? form_action %> <ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= "style=\"display: none;\"".html_safe if columns.collapsed %>> <% columns.each :for => @record, :crud_type => (:read if show_unauthorized_columns) do |column| %> From f49fc8a33736b6129bf7ab3e5208a6652fc5c085 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Thu, 18 Apr 2013 13:11:31 +0200 Subject: [PATCH 1916/2024] the action doesnt need to be a crud type --- lib/active_scaffold/data_structures/action_columns.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index 6f115a1cfb..9e5a598eef 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -93,7 +93,7 @@ def collect_visible(options = {}, &proc) options[:for] ||= @columns.active_record_class self.unauthorized_columns = [] @set.each do |item| - unless item.is_a? ActiveScaffold::DataStructures::ActionColumns + unless item.is_a? ActiveScaffold::DataStructures::ActionColumns || @columns.nil? item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class)) next if self.skip_column?(item, options) end @@ -111,7 +111,7 @@ def skip_column?(column, options) # skip if this matches a constrained column result = true if constraint_columns.include?(column.name.to_sym) # skip this field if it's not authorized - unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.crud_type, :column => column.name) + unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.try(:crud_type), :column => column.name) self.unauthorized_columns << column.name.to_sym result = true end From 82d3b57adf0893b309a59a105779641150d28e1d Mon Sep 17 00:00:00 2001 From: Andrey Korobkov <korobkov@fryxell.info> Date: Thu, 18 Apr 2013 20:29:59 +0400 Subject: [PATCH 1917/2024] Fixed typos --- lib/active_scaffold/actions/list.rb | 16 ++++++++-------- lib/active_scaffold/actions/show.rb | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 4c46bf3fce..a5a0ac202f 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -24,7 +24,7 @@ def list @nested_auto_open = active_scaffold_config.list.nested_auto_open respond_to_action(:list) end - + protected def list_respond_to_html if embedded? @@ -49,11 +49,11 @@ def list_respond_to_json def list_respond_to_yaml render :text => Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status end - + def row_respond_to_html render(:partial => 'row', :locals => {:record => @record}) end - + def row_respond_to_js render :action => 'row' end @@ -64,7 +64,7 @@ def set_includes_for_columns(action = :list) includes_for_list_columns = active_scaffold_config.send(action).columns.collect_visible(:flatten => true){ |c| c.includes }.flatten.uniq.compact self.active_scaffold_includes.concat includes_for_list_columns end - + def get_row set_includes_for_columns klass = beginning_of_chain.includes(active_scaffold_includes) @@ -97,7 +97,7 @@ def do_list end @page, @records = page, page.items end - + def do_refresh_list params.delete(:id) do_search if respond_to? :do_search, true @@ -133,11 +133,11 @@ def list_authorized? def process_action_link_action(render_action = :action_update, crud_type = nil) if request.get? # someone has disabled javascript, we have to show confirmation form first - @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0 + @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id].to_i > 0 respond_to_action(:action_confirmation) else @action_link = active_scaffold_config.action_links[action_name] - if params[:id] && params[:id] && params[:id].to_i > 0 + if params[:id] && params[:id].to_i > 0 crud_type ||= (request.post? || request.put?) ? :update : :delete set_includes_for_columns klass = beginning_of_chain.includes(active_scaffold_includes) @@ -180,7 +180,7 @@ def action_update_respond_to_json def action_update_respond_to_yaml render :text => successful? ? "" : Hash.from_xml(response_object.to_xml(:only => list_columns_names)).to_yaml, :content_type => Mime::YAML, :status => response_status end - + private def list_authorized_filter raise ActiveScaffold::ActionNotAllowed unless list_authorized? diff --git a/lib/active_scaffold/actions/show.rb b/lib/active_scaffold/actions/show.rb index 76ef6d69ea..8f2ca6c3a4 100644 --- a/lib/active_scaffold/actions/show.rb +++ b/lib/active_scaffold/actions/show.rb @@ -11,13 +11,13 @@ def show do_show respond_to_action(:show) else - @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id] && params[:id].to_i > 0 + @record = find_if_allowed(params[:id], :read) if params[:id] && params[:id].to_i > 0 action_confirmation_respond_to_html(:destroy) end end protected - + def show_respond_to_json render :text => response_object.to_json(:only => active_scaffold_config.show.columns.names), :content_type => Mime::JSON, :status => response_status end @@ -53,7 +53,7 @@ def show_authorized?(record = nil) def show_ignore?(record = nil) !self.send(:authorized_for?, :crud_type => :read) end - private + private def show_authorized_filter link = active_scaffold_config.show.link || active_scaffold_config.show.class.link raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method) From 3fc52f6822c1a96749337babb207c6e44c8180aa Mon Sep 17 00:00:00 2001 From: Andrey Korobkov <korobkov@fryxell.info> Date: Thu, 18 Apr 2013 20:45:58 +0400 Subject: [PATCH 1918/2024] updating russian locale --- config/locales/ru.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/config/locales/ru.yml b/config/locales/ru.yml index c64cd2461b..ee617554e3 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -6,7 +6,7 @@ ru: add: 'Добавить запись' add_existing: 'Добавить существующую запись' add_existing_model: '%{model}: добавить существующую запись' - apply: 'Apply' + apply: 'Применить' are_you_sure_to_delete: 'Удалить %{label}?' cancel: 'Отмена' click_to_edit: 'Нажмите для редактирования' @@ -30,7 +30,7 @@ ru: nested_of_model: '%{nested_model} @ %{parent_model}' 'false': 'Нет' filtered: '(Найденное)' - found: + found: one: 'запись' few: 'записи' many: 'записей' @@ -56,7 +56,7 @@ ru: refresh: 'Обновить' remove: 'Удалить' remove_file: 'Удалить или заменить файл' - replace_existing: 'Replace existing' + replace_existing: 'Заменить существующим' replace_with_new: 'Заменить новым' revisions_for_model: '%{model}: редакции' reset: 'Сброс' @@ -111,13 +111,13 @@ ru: firstDay: 1 isRTL: false showMonthAfterYear: false - + datetime_picker_options: - + human_conditions: boolean: "%{column} = %{value}" association: "%{column} = %{value}" - + errors: template: header: From 7172b114e082dad9407e120f160af2b4ba97f4eb Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Fri, 26 Apr 2013 13:31:40 +0200 Subject: [PATCH 1919/2024] fix field id on render_field from subforms --- lib/active_scaffold/helpers/form_column_helpers.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index c91556e0c5..65ba646cf8 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -93,7 +93,7 @@ def active_scaffold_input_options(column, scope = nil, options = {}) options[:placeholder] = column.placeholder if column.placeholder.present? # Fix for keeping unique IDs in subform - id_control = "record_#{column.name}_#{[params[:eid], params[:id]].compact.join '_'}" + id_control = "record_#{column.name}_#{[params[:eid], params[:parent_id] || params[:id]].compact.join '_'}" id_control += scope_id(scope) if scope classes = "#{column.name}-input" @@ -116,6 +116,7 @@ def update_columns_options(column, scope, options) if scope url_params[:controller] = subform_controller.controller_path url_params[:scope] = scope + url_params[:parent_id] = params[:parent_id] || params[:id] end options[:class] = "#{options[:class]} update_form".strip From c47c447bc65744853d4abdd8be70fdf282b6596b Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 7 May 2013 00:42:13 -1000 Subject: [PATCH 1920/2024] fix render field on nested without subform --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 65ba646cf8..7fb0d0f13d 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -111,7 +111,7 @@ def update_columns_options(column, scope, options) end if form_action && column.update_columns && (column.update_columns & form_action.columns.names).present? url_params = params_for(:action => 'render_field', :column => column.name, :id => @record.id) - url_params = url_params.except(:parent_scaffold, :association, nested.param_name) if nested? + url_params = url_params.except(:parent_scaffold, :association, nested.param_name) if nested? && scope url_params[:eid] = params[:eid] if params[:eid] if scope url_params[:controller] = subform_controller.controller_path From b8da0a8ce5868e1f1ee2b1653b0ca2871bc9edd4 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 7 May 2013 01:03:14 -1000 Subject: [PATCH 1921/2024] fix horizonta_subform when parent is nil --- .../active_scaffold_overrides/_horizontal_subform.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb index 461f940936..613cfc3495 100644 --- a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +++ b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb @@ -1,4 +1,4 @@ -<table cellpadding="0" cellspacing="0" id="<%= sub_form_list_id(:association => column.name, :id => parent_record.id || generated_id(parent_record) || 99999999999) %>"> +<table cellpadding="0" cellspacing="0" id="<%= sub_form_list_id(:association => column.name, :id => parent_record.try(:id) || generated_id(parent_record) || 99999999999) %>"> <% @record = associated.empty? ? build_associated(column, parent_record) : associated.last -%> <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record, :record => @record} %> From 3220c41b9f93351b54bce2c2e6c3909de8c0d9da Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 6 May 2013 14:29:38 +0200 Subject: [PATCH 1922/2024] support column.options in file columns --- lib/active_scaffold/bridges/carrierwave/form_ui.rb | 4 ++-- lib/active_scaffold/bridges/dragonfly/form_ui.rb | 4 ++-- lib/active_scaffold/bridges/paperclip/form_ui.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold/bridges/carrierwave/form_ui.rb b/lib/active_scaffold/bridges/carrierwave/form_ui.rb index 9042f95820..6cb36f9a4b 100644 --- a/lib/active_scaffold/bridges/carrierwave/form_ui.rb +++ b/lib/active_scaffold/bridges/carrierwave/form_ui.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Helpers module FormColumnHelpers def active_scaffold_input_carrierwave(column, options) - options = active_scaffold_input_text_options(options) + options = active_scaffold_input_text_options(options.merge(column.options)) carrierwave = @record.send("#{column.name}") if !carrierwave.file.blank? @@ -42,4 +42,4 @@ def active_scaffold_input_carrierwave(column, options) end end end -end \ No newline at end of file +end diff --git a/lib/active_scaffold/bridges/dragonfly/form_ui.rb b/lib/active_scaffold/bridges/dragonfly/form_ui.rb index 017e9aa6d0..04d96cef10 100644 --- a/lib/active_scaffold/bridges/dragonfly/form_ui.rb +++ b/lib/active_scaffold/bridges/dragonfly/form_ui.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Helpers module FormColumnHelpers def active_scaffold_input_dragonfly(column, options) - options = active_scaffold_input_text_options(options) + options = active_scaffold_input_text_options(options.merge(column.options)) input = file_field(:record, column.name, options) dragonfly = @record.send("#{column.name}") if dragonfly.present? @@ -24,4 +24,4 @@ def active_scaffold_input_dragonfly(column, options) end end end -end \ No newline at end of file +end diff --git a/lib/active_scaffold/bridges/paperclip/form_ui.rb b/lib/active_scaffold/bridges/paperclip/form_ui.rb index 0295019f57..26238ee412 100644 --- a/lib/active_scaffold/bridges/paperclip/form_ui.rb +++ b/lib/active_scaffold/bridges/paperclip/form_ui.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Helpers module FormColumnHelpers def active_scaffold_input_paperclip(column, options) - options = active_scaffold_input_text_options(options) + options = active_scaffold_input_text_options(options.merge(column.options)) input = file_field(:record, column.name, options) paperclip = @record.send("#{column.name}") if paperclip.file? @@ -24,4 +24,4 @@ def active_scaffold_input_paperclip(column, options) end end end -end \ No newline at end of file +end From c7605c8ed0f6f31d02aaec338021a8306b606ca0 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 8 May 2013 15:05:02 +0200 Subject: [PATCH 1923/2024] release 3.3.0 --- CHANGELOG | 2 +- Gemfile.lock | 2 +- lib/active_scaffold/version.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b00e1d4711..eb5bba16c5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -= 3.3.0 (not released yet) += 3.3.0 - Unify field overrides and list_ui method signatures - Improve performance removing some partials and adding some caching for helper overrides and UIs, and caching url generation for lists (caching url is optional) - Drop support for rails 3.1 diff --git a/Gemfile.lock b/Gemfile.lock index 21a32921f5..d1da1a5767 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ GEM remote: http://rubygems.org/ specs: json (1.6.3) - rake (10.0.3) + rake (10.0.4) rcov (0.9.9) rdoc (3.11) json (~> 1.4) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index ded5c749ba..aaf2a56a41 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 3 - PATCH = "0.rc3" + PATCH = 0 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 55265b9dcca6d77d8f2c13f524d683d1ced51c9b Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 9 May 2013 13:46:54 +0200 Subject: [PATCH 1924/2024] fixed issue on adapter colspan when active_scaffold_config_list is used --- CHANGELOG | 3 +++ app/assets/javascripts/jquery/active_scaffold.js | 2 ++ app/assets/javascripts/prototype/active_scaffold.js | 2 ++ .../_list_inline_adapter.html.erb | 13 +------------ 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index eb5bba16c5..c1f33e7b6b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ += 3.3.1 (not released) +- Set adapter colspan (nested lists and forms) using javascript, fixed issue when active_scaffold_config_list is used + = 3.3.0 - Unify field overrides and list_ui method signatures - Improve performance removing some partials and adding some caching for helper overrides and UIs, and caching url generation for lists (caching url is optional) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index dcd01ec2bf..6288b3ea4a 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -1077,6 +1077,7 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ this.hide_target = true; } + var colspan = this.target.children().length; if (this.position == 'after') { this.target.after(content); this.set_adapter(this.target.next()); @@ -1088,6 +1089,7 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ else { return false; } + this.adapter.find('.inline-adapter-cell:first').attr('colspan', colspan); ActiveScaffold.highlight(this.adapter.find('td')); }, diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index 168dc247f2..a903f844b4 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -969,6 +969,7 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra this.hide_target = true; } + var colspan = this.target.childElements().length; if (this.position == 'after') { this.target.insert({after:content}); this.set_adapter(this.target.next()); @@ -980,6 +981,7 @@ ActiveScaffold.ActionLink.Record = Class.create(ActiveScaffold.ActionLink.Abstra else { return false; } + this.adapter.down('.inline-adapter-cell').writeAttribute('colspan', colspan); ActiveScaffold.highlight(this.adapter.down('td').down()); }, diff --git a/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb b/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb index 7c0d6454de..13d6e46a88 100644 --- a/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb +++ b/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb @@ -1,17 +1,6 @@ -<% - column_count ||= begin - config = if nested? and (nested.singular_association? || action_name == 'index') - active_scaffold_config_for(nested.parent_model) - else - active_scaffold_config - end - # increment in 1 for self-associations, parent_model config will have constraints too - config.list.columns.count + 1 + (config == active_scaffold_config && action_name == 'index' ? 1 : 0) - end -%> <%# nested_id, allows us to remove a nested scaffold programmatically %> <tr class="inline-adapter" id="<%= element_row_id :action => :nested %>"> - <td colspan="<%= column_count %>" class="inline-adapter-cell"> + <td class="inline-adapter-cell"> <% if controller.send(:successful?) %> <div class="<%= "#{params[:action]}-view" if params[:action] %> <%= "#{nested? ? nested.name : id_from_controller(params[:controller])}-view" %> view"> <%= link_to(as_(:close), '', :class => 'inline-adapter-close as_cancel', :remote => true, :title => as_(:close)) -%> From 2aeeba6bc66395c4637d97b27ca5dd87d99eb0d5 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 14 May 2013 13:00:55 +0200 Subject: [PATCH 1925/2024] remove unneeded check, that bug is not on AR anymore --- lib/active_scaffold/attribute_params.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index 933e6f9287..17a49dfda6 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -57,9 +57,7 @@ def update_record_from_params(parent_record, columns, attributes) parent_record.send(:assign_multiparameter_attributes, multi_parameter_attributes[column.name]) elsif attributes.has_key? column.name value = column_value_from_param_value(parent_record, column, attributes[column.name]) - - # we avoid assigning a value that already exists because otherwise has_one associations will break (AR bug in has_one_association.rb#replace) - parent_record.send("#{column.name}=", value) unless parent_record.send(column.name) == value + parent_record.send("#{column.name}=", value) end end From 06bec1715f957de5c6438745ab18bc4eab54014d Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 14 May 2013 13:02:41 +0200 Subject: [PATCH 1926/2024] update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index c1f33e7b6b..806c19d50d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ = 3.3.1 (not released) - Set adapter colspan (nested lists and forms) using javascript, fixed issue when active_scaffold_config_list is used +- Fix bug saving default values when get method is overrided on model to return default value = 3.3.0 - Unify field overrides and list_ui method signatures From 7d150656fab8789ea964860e83c763b9ed0613e4 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 14 May 2013 15:54:54 +0200 Subject: [PATCH 1927/2024] fix list calculations html --- .../_list_calculations.html.erb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/views/active_scaffold_overrides/_list_calculations.html.erb b/app/views/active_scaffold_overrides/_list_calculations.html.erb index d0491c1cc0..497ac70eaa 100644 --- a/app/views/active_scaffold_overrides/_list_calculations.html.erb +++ b/app/views/active_scaffold_overrides/_list_calculations.html.erb @@ -2,13 +2,11 @@ columns ||= list_columns -%> <tr id="<%= active_scaffold_calculations_id %>" class="active-scaffold-calculations"> <% columns.each do |column| -%> - <td <%= "id=#{active_scaffold_calculations_id(:column => column)}" if column.calculation? %>> - <% if column.calculation? -%> - <%= render_column_calculation(column) %> - <% else -%> -   - <% end -%> - </td> + <% if column.calculation? %>> + <td id="<%= active_scaffold_calculations_id(:column => column) %>"><%= render_column_calculation(column) %></td> + <% else %> + <td> </td> + <% end -%> <% end -%> <% unless active_scaffold_config.action_links.empty? -%> <td class="actions"> </td> From 894b22d4e286d2dbe0d424d541e143dfef0fbfcc Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 14 May 2013 15:58:28 +0200 Subject: [PATCH 1928/2024] fix close without adapter --- CHANGELOG | 1 + app/assets/javascripts/jquery/active_scaffold.js | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 806c19d50d..0780139c3d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ = 3.3.1 (not released) - Set adapter colspan (nested lists and forms) using javascript, fixed issue when active_scaffold_config_list is used - Fix bug saving default values when get method is overrided on model to return default value +- Fix close action_link without adapter = 3.3.0 - Unify field overrides and list_ui method signatures diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 6288b3ea4a..13d0b51bfe 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -986,12 +986,14 @@ ActiveScaffold.ActionLink.Abstract = Class.extend({ }, close: function() { - var link = this; - ActiveScaffold.remove(this.adapter, function() { - link.enable(); - if (link.hide_target) link.target.show(); - if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(link.target.attr('id'), ActiveScaffold.config.scroll_on_close == 'checkInViewport'); - }); + if (this.adapter) { + var link = this; + ActiveScaffold.remove(this.adapter, function() { + link.enable(); + if (link.hide_target) link.target.show(); + if (ActiveScaffold.config.scroll_on_close) ActiveScaffold.scroll_to(link.target.attr('id'), ActiveScaffold.config.scroll_on_close == 'checkInViewport'); + }); + } }, reload: function() { From 02d5c0402089fa45ac6462746aa772fbd17a3776 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 14 May 2013 16:06:48 +0200 Subject: [PATCH 1929/2024] remove > character --- app/views/active_scaffold_overrides/_list_calculations.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_list_calculations.html.erb b/app/views/active_scaffold_overrides/_list_calculations.html.erb index 497ac70eaa..568e78b3c1 100644 --- a/app/views/active_scaffold_overrides/_list_calculations.html.erb +++ b/app/views/active_scaffold_overrides/_list_calculations.html.erb @@ -2,7 +2,7 @@ columns ||= list_columns -%> <tr id="<%= active_scaffold_calculations_id %>" class="active-scaffold-calculations"> <% columns.each do |column| -%> - <% if column.calculation? %>> + <% if column.calculation? %> <td id="<%= active_scaffold_calculations_id(:column => column) %>"><%= render_column_calculation(column) %></td> <% else %> <td> </td> From a2ca094312e440437e6dc6aec0716cb9b3fb3c24 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 14 May 2013 16:10:56 +0200 Subject: [PATCH 1930/2024] fix update calculations after destroy row --- app/views/active_scaffold_overrides/_update_calculations.js.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/active_scaffold_overrides/_update_calculations.js.erb b/app/views/active_scaffold_overrides/_update_calculations.js.erb index 32347d8282..4f017b2703 100644 --- a/app/views/active_scaffold_overrides/_update_calculations.js.erb +++ b/app/views/active_scaffold_overrides/_update_calculations.js.erb @@ -1,4 +1,5 @@ <% calculations_id ||= active_scaffold_calculations_id -%> <% if active_scaffold_config.list.columns.any? {|c| c.calculation?} %> +<% params.delete[:id] %> ActiveScaffold.replace('<%= calculations_id %>', '<%= escape_javascript(render(:partial => 'list_calculations')) %>'); <% end %> From 45ca31a07cf651e13ae05c6cc2ccb842a8cdf812 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 14 May 2013 16:11:33 +0200 Subject: [PATCH 1931/2024] update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 0780139c3d..c1f5675bcf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ - Set adapter colspan (nested lists and forms) using javascript, fixed issue when active_scaffold_config_list is used - Fix bug saving default values when get method is overrided on model to return default value - Fix close action_link without adapter +- Fix update calculations after destroy a row = 3.3.0 - Unify field overrides and list_ui method signatures From 2702e35f4aff3dd6b765e6076e8b94247b259c8c Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 14 May 2013 16:13:56 +0200 Subject: [PATCH 1932/2024] fix previous commit --- app/views/active_scaffold_overrides/_update_calculations.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_update_calculations.js.erb b/app/views/active_scaffold_overrides/_update_calculations.js.erb index 4f017b2703..d01ac2dfd4 100644 --- a/app/views/active_scaffold_overrides/_update_calculations.js.erb +++ b/app/views/active_scaffold_overrides/_update_calculations.js.erb @@ -1,5 +1,5 @@ <% calculations_id ||= active_scaffold_calculations_id -%> <% if active_scaffold_config.list.columns.any? {|c| c.calculation?} %> -<% params.delete[:id] %> +<% params.delete(:id) %> ActiveScaffold.replace('<%= calculations_id %>', '<%= escape_javascript(render(:partial => 'list_calculations')) %>'); <% end %> From e4d72067d0c6bcfb88a255729616871ef837cb5a Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 16 May 2013 14:24:13 +0200 Subject: [PATCH 1933/2024] use col_class from subform --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 7fb0d0f13d..a358c4e3eb 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -135,7 +135,7 @@ def render_column(column, record, renders_as, scope = nil, only_value = false, c if override_form_field_partial?(column) render :partial => override_form_field_partial(column), :locals => { :column => column, :only_value => only_value, :scope => scope, :col_class => col_class } elsif renders_as == :field || override_form_field?(column) - form_attribute(column, record, scope, only_value) + form_attribute(column, record, scope, only_value, col_class) elsif renders_as == :subform render :partial => 'form_association', :locals => { :column => column, :scope => scope } else From 8859412b3b803ef065ebe40ee1495fa29420424b Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 21 May 2013 10:05:27 +0200 Subject: [PATCH 1934/2024] fix count and calculate searching with count_includes --- lib/active_scaffold/actions/field_search.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index 9b9cb9270b..0e5b5085c1 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -51,7 +51,7 @@ def do_search column = active_scaffold_config.columns[key] search_condition = self.class.condition_for_column(column, value, text_search) unless search_condition.blank? - self.active_scaffold_outer_joins << column.search_joins unless column.includes.present? && list_columns.include?(column) + self.active_scaffold_outer_joins << column.search_joins unless active_scaffold_config.list.user.count_includes.nil? && column.includes.present? && list_columns.include?(column) self.active_scaffold_conditions << search_condition filtered_columns << column end From b150d43459d87a6dd529bd190670d8b4792acfcf Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 21 May 2013 10:06:20 +0200 Subject: [PATCH 1935/2024] update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index c1f5675bcf..867652053d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ - Fix bug saving default values when get method is overrided on model to return default value - Fix close action_link without adapter - Fix update calculations after destroy a row +- Fix count and calculate searching with count_includes = 3.3.0 - Unify field overrides and list_ui method signatures From 2cfaada5213f4f20d5ee6f382030537a8d4ec482 Mon Sep 17 00:00:00 2001 From: Dave LaDelfa <public@ladelfa.net> Date: Tue, 21 May 2013 12:11:38 -0700 Subject: [PATCH 1936/2024] CRUD links have no controller attached, and call id_from_controller unnecssarily, thus creating link ids with an extra hyphen character. This can't be found when, e.g. after create, javascript action (going through action_link_id) tries to find the link by id. --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 7c32fe5352..1d41e45772 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -368,7 +368,7 @@ def get_action_link_id(link, record = nil, column = nil) id = "#{column.association.name}-#{record.id}" unless record.nil? end end - action_id = "#{id_from_controller("#{link.controller}-") if params[:parent_controller] || link.controller != controller.controller_path}#{link.action}" + action_id = "#{id_from_controller("#{link.controller}-") if params[:parent_controller] || (link.controller && link.controller != controller.controller_path)}#{link.action}" action_link_id(action_id, id) end From fd32e4331ba394eb07c1e9ddb34824666c83ecdc Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 22 May 2013 12:26:53 +0200 Subject: [PATCH 1937/2024] update changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 867652053d..b3505a962b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,7 @@ - Fix close action_link without adapter - Fix update calculations after destroy a row - Fix count and calculate searching with count_includes +- Fix action_after_create = 3.3.0 - Unify field overrides and list_ui method signatures From d95467be69d7dee186cac838090ab69e0b83ff4f Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 27 May 2013 14:50:11 -1000 Subject: [PATCH 1938/2024] use method_defined? --- lib/active_scaffold.rb | 1 - lib/active_scaffold/bridges/calendar_date_select.rb | 2 +- lib/active_scaffold/bridges/file_column.rb | 2 +- .../bridges/file_column/as_file_column_bridge.rb | 2 +- .../bridges/file_column/file_column_helpers.rb | 2 +- lib/active_scaffold/bridges/paperclip.rb | 2 +- .../bridges/paperclip/paperclip_bridge_helpers.rb | 2 +- test/bridges/paperclip_test.rb | 4 ++-- 8 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 326d0fec8f..4ebb4446cc 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -16,7 +16,6 @@ require 'json' # for js_config module ActiveScaffold - METHOD_CONVERSION = RUBY_VERSION < '1.9' ? :to_s : :to_sym autoload :AttributeParams, 'active_scaffold/attribute_params' autoload :Configurable, 'active_scaffold/configurable' autoload :Constraints, 'active_scaffold/constraints' diff --git a/lib/active_scaffold/bridges/calendar_date_select.rb b/lib/active_scaffold/bridges/calendar_date_select.rb index 655d578a51..d7498487e7 100644 --- a/lib/active_scaffold/bridges/calendar_date_select.rb +++ b/lib/active_scaffold/bridges/calendar_date_select.rb @@ -3,7 +3,7 @@ def self.install # check to see if the old bridge was installed. If so, warn them # we can detect this by checking to see if the bridge was installed before calling this code - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_calendar_date_select".send(::ActiveScaffold::METHOD_CONVERSION)) + if ActiveScaffold::Config::Core.method_defined?(:initialize_with_calendar_date_select) raise RuntimeError, "We've detected that you have active_scaffold_calendar_date_select_bridge installed. This plugin has been moved to core. Please remove active_scaffold_calendar_date_select_bridge to prevent any conflicts" end diff --git a/lib/active_scaffold/bridges/file_column.rb b/lib/active_scaffold/bridges/file_column.rb index 6573fac02a..47a81ec812 100644 --- a/lib/active_scaffold/bridges/file_column.rb +++ b/lib/active_scaffold/bridges/file_column.rb @@ -1,6 +1,6 @@ class ActiveScaffold::Bridges::FileColumn < ActiveScaffold::DataStructures::Bridge def self.install - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_file_column".send(::ActiveScaffold::METHOD_CONVERSION)) + if ActiveScaffold::Config::Core.method_defined?(:initialize_with_file_column) raise RuntimeError, "We've detected that you have active_scaffold_file_column_bridge installed. This plugin has been moved to core. Please remove active_scaffold_file_column_bridge to prevent any conflicts" end require File.join(File.dirname(__FILE__), "file_column/as_file_column_bridge") diff --git a/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb b/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb index 10987440ed..e35707957d 100644 --- a/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +++ b/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb @@ -24,7 +24,7 @@ def initialize_with_file_column(model_id) } end - alias_method_chain :initialize, :file_column unless self.instance_methods.include?("initialize_without_file_column".send(::ActiveScaffold::METHOD_CONVERSION)) + alias_method_chain :initialize, :file_column unless self.method_defined?(:initialize_without_file_column) def configure_file_column_field(field) # set list_ui first because it gets its default value from form_ui diff --git a/lib/active_scaffold/bridges/file_column/file_column_helpers.rb b/lib/active_scaffold/bridges/file_column/file_column_helpers.rb index 57acac9715..c3fbb3f991 100644 --- a/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +++ b/lib/active_scaffold/bridges/file_column/file_column_helpers.rb @@ -9,7 +9,7 @@ def file_column_fields(klass) def generate_delete_helpers(klass) file_column_fields(klass).each { |field| - klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("#{field}_with_delete=".send(::ActiveScaffold::METHOD_CONVERSION)) + klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.method_defined?(:"#{field}_with_delete=") attr_reader :delete_#{field} def delete_#{field}=(value) diff --git a/lib/active_scaffold/bridges/paperclip.rb b/lib/active_scaffold/bridges/paperclip.rb index 2314870caa..8618f509e5 100644 --- a/lib/active_scaffold/bridges/paperclip.rb +++ b/lib/active_scaffold/bridges/paperclip.rb @@ -1,6 +1,6 @@ class ActiveScaffold::Bridges::Paperclip < ActiveScaffold::DataStructures::Bridge def self.install - if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip".send(::ActiveScaffold::METHOD_CONVERSION)) + if ActiveScaffold::Config::Core.method_defined?(:initialize_with_paperclip) raise RuntimeError, "We've detected that you have active_scaffold_paperclip_bridge installed. This plugin has been moved to core. Please remove active_scaffold_paperclip_bridge to prevent any conflicts" end require File.join(File.dirname(__FILE__), "paperclip/form_ui") diff --git a/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb b/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb index b460ac8971..5a8562f3e7 100644 --- a/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +++ b/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb @@ -6,7 +6,7 @@ module PaperclipBridgeHelpers self.thumbnail_style = :thumbnail def self.generate_delete_helper(klass, field) - klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.instance_methods.include?("delete_#{field}=".send(::ActiveScaffold::METHOD_CONVERSION)) + klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.method_defined?(:"delete_#{field}=") attr_reader :delete_#{field} def delete_#{field}=(value) diff --git a/test/bridges/paperclip_test.rb b/test/bridges/paperclip_test.rb index 6b0b85ed06..7ea697ed3a 100644 --- a/test/bridges/paperclip_test.rb +++ b/test/bridges/paperclip_test.rb @@ -29,8 +29,8 @@ def test_initialization %w(logo_file_name logo_file_size logo_updated_at logo_content_type).each do |attr| assert !config.columns._inheritable.include?(attr.to_sym) end - assert Company.instance_methods.include?('delete_logo') - assert Company.instance_methods.include?('delete_logo=') + assert Company.method_defined?(:delete_logo) + assert Company.method_defined?(:'delete_logo=') end def test_delete From 09108831a2852163281e4f9f07ebe9fec433d660 Mon Sep 17 00:00:00 2001 From: Sebastian Eichner <mailsp@sebastian-eichner.de> Date: Wed, 29 May 2013 12:34:13 +0200 Subject: [PATCH 1939/2024] fix typo --- lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index a358c4e3eb..51d20bbea7 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -46,7 +46,7 @@ def active_scaffold_render_input(column, options) options[:size] ||= ActionView::Helpers::InstanceTag::DEFAULT_FIELD_OPTIONS["size"] end options[:include_blank] = true if column.column.null and [:date, :datetime, :time].include?(column.column.type) - options[:value] = format_number_value((options[:object] || @raecord).send(column.name), column.options) if column.number? + options[:value] = format_number_value((options[:object] || @record).send(column.name), column.options) if column.number? text_field(:record, column.name, options.merge(column.options)) end end From 3d1a8513e2c6f03b8eb80f1c27695e7af27be8de Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 30 May 2013 09:58:49 +0200 Subject: [PATCH 1940/2024] fixes for ruby2 --- app/views/active_scaffold_overrides/destroy.js.erb | 2 +- lib/active_scaffold/actions/core.rb | 2 +- lib/active_scaffold/actions/list.rb | 6 +++--- lib/active_scaffold/actions/mark.rb | 2 +- lib/active_scaffold/attribute_params.rb | 2 +- lib/active_scaffold/extensions/action_view_rendering.rb | 2 +- lib/active_scaffold/helpers/form_column_helpers.rb | 4 ++-- lib/active_scaffold/helpers/list_column_helpers.rb | 4 ++-- lib/active_scaffold/helpers/view_helpers.rb | 4 ++-- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/views/active_scaffold_overrides/destroy.js.erb b/app/views/active_scaffold_overrides/destroy.js.erb index a5563647e0..f0c5d0c20c 100644 --- a/app/views/active_scaffold_overrides/destroy.js.erb +++ b/app/views/active_scaffold_overrides/destroy.js.erb @@ -8,7 +8,7 @@ <% messages_id = active_scaffold_messages_id(:controller_id => current_id) %> <%= render :partial => 'update_calculations', :locals => {:calculations_id => active_scaffold_calculations_id(:controller_id => current_id)}, :formats => [:js] %> <% elsif render_parent_action == :index %> - <% if controller.respond_to?(:render_component_into_view) %> + <% if controller.respond_to?(:render_component_into_view, true) %> <%= escape_javascript(controller.send(:render_component_into_view, render_parent_options)) %> <% else %> ActiveScaffold.reload('<%= url_for render_parent_options %>'); diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index b051ad6635..417579fce0 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -185,7 +185,7 @@ def respond_to_action(action) respond_to do |type| action_formats.each do |format| type.send(format) do - if respond_to?(method_name = "#{action}_respond_to_#{format}") + if respond_to?(method_name = "#{action}_respond_to_#{format}", true) send(method_name) end end diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 41d230b49f..33cedb4389 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -100,20 +100,20 @@ def do_list def do_refresh_list params.delete(:id) - do_search if respond_to? :do_search + do_search if respond_to? :do_search, true do_list end def each_record_in_page _page = active_scaffold_config.list.user.page - do_search if respond_to? :do_search + do_search if respond_to? :do_search, true active_scaffold_config.list.user.page = _page do_list @page.items.each {|record| yield record} end def each_record_in_scope - do_search if respond_to? :do_search + do_search if respond_to? :do_search, true append_to_query(beginning_of_chain, finder_options).all.each {|record| yield record} end diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index 42958b1921..04b4ae8f6f 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -28,7 +28,7 @@ def mark_respond_to_html def mark_respond_to_js if params[:id] - do_search if respond_to? :do_search + do_search if respond_to? :do_search, true set_includes_for_columns if active_scaffold_config.actions.include? :list @page = find_page(:pagination => active_scaffold_config.mark.mark_all_mode != :page) render :action => 'on_mark' diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index c1331dd202..4e39603668 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -93,7 +93,7 @@ def manage_nested_record_from_params(parent_record, column, attributes) def column_value_from_param_value(parent_record, column, value) # convert the value, possibly by instantiating associated objects form_ui = column.form_ui || column.column.try(:type) - if form_ui && self.respond_to?("column_value_for_#{form_ui}_type") + if form_ui && self.respond_to?("column_value_for_#{form_ui}_type", true) self.send("column_value_for_#{form_ui}_type", parent_record, column, value) elsif value.is_a?(Hash) column_value_from_param_hash_value(parent_record, column, value) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 9b03db07ba..fc2000a708 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -66,7 +66,7 @@ def render_with_active_scaffold(*args, &block) id = "as_#{eid}-embedded" url_options = {:controller => remote_controller.to_s, :action => 'index'}.merge(options[:params]) - if controller.respond_to?(:render_component_into_view) + if controller.respond_to?(:render_component_into_view, true) controller.send(:render_component_into_view, url_options) else content_tag(:div, :id => id, :class => 'active-scaffold-component') do diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 1164089644..c8e6790bff 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -411,7 +411,7 @@ def column_scope(column, scope = nil) end def active_scaffold_add_existing_input(options) - if ActiveScaffold.js_framework == :prototype && controller.respond_to?(:record_select_config) + if ActiveScaffold.js_framework == :prototype && controller.respond_to?(:record_select_config, true) remote_controller = active_scaffold_controller_for(record_select_config.model).controller_path options.merge!(:controller => remote_controller) options.merge!(active_scaffold_input_text_options) @@ -425,7 +425,7 @@ def active_scaffold_add_existing_input(options) end def active_scaffold_add_existing_label - if controller.respond_to?(:record_select_config) + if controller.respond_to?(:record_select_config, true) record_select_config.model.model_name.human else active_scaffold_config.model.model_name.human diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index e6e7d8a628..e87cb2e9df 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -200,7 +200,7 @@ def cache_association(value, column, size) def inplace_edit?(record, column) if column.inplace_edit - editable = controller.send(:update_authorized?, record) if controller.respond_to?(:update_authorized?) + editable = controller.send(:update_authorized?, record) if controller.respond_to?(:update_authorized?, true) editable ||= record.authorized_for?(:crud_type => :update, :column => column.name) end end @@ -315,7 +315,7 @@ def column_heading_label(column) def render_nested_view(action_links, record) rendered = [] action_links.member.each do |link| - if link.nested_link? && link.column && @nested_auto_open[link.column.name] && @records.length <= @nested_auto_open[link.column.name] && controller.respond_to?(:render_component_into_view) + if link.nested_link? && link.column && @nested_auto_open[link.column.name] && @records.length <= @nested_auto_open[link.column.name] && controller.respond_to?(:render_component_into_view, true) link_url_options = {:adapter => '_list_inline_adapter', :format => :js}.merge(action_link_url_options(link, record)) link_id = get_action_link_id(link, record) rendered << (controller.send(:render_component_into_view, link_url_options) + javascript_tag("ActiveScaffold.ActionLink.get('#{link_id}').set_opened();")) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index f4645ad92d..408365c6e1 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -101,11 +101,11 @@ def link_to_visibility_toggle(id, options = {}) end def skip_action_link?(link, *args) - !link.ignore_method.nil? && controller.respond_to?(link.ignore_method) && controller.send(link.ignore_method, *args) + !link.ignore_method.nil? && controller.respond_to?(link.ignore_method, true) && controller.send(link.ignore_method, *args) end def action_link_authorized?(link, *args) - security_method = link.security_method_set? || controller.respond_to?(link.security_method) + security_method = link.security_method_set? || controller.respond_to?(link.security_method, true) authorized = if security_method controller.send(link.security_method, *args) else From f6bf5fb2e52291a38dbcd0cd719739557ec40715 Mon Sep 17 00:00:00 2001 From: Chris Barber <barberchris01@gmail.com> Date: Thu, 30 May 2013 16:06:09 -0700 Subject: [PATCH 1941/2024] On subforms for readonly associations, don't show blank record, and don't make editable fields for newly associated existing records --- lib/active_scaffold/actions/subform.rb | 2 +- lib/active_scaffold/data_structures/column.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index e9609f1b60..0cc2d0b8c3 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -2,7 +2,7 @@ module ActiveScaffold::Actions module Subform def edit_associated do_edit_associated - render :action => 'edit_associated', :formats => [:js] + render :action => 'edit_associated', :formats => [:js], :readonly => @column.association.options[:readonly] end protected diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 6677d39ebe..2b990fe641 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -226,7 +226,7 @@ def associated_number? attr_writer :show_blank_record def show_blank_record?(associated) if @show_blank_record - return false unless self.association.klass.authorized_for?(:crud_type => :create) + return false unless self.association.klass.authorized_for?(:crud_type => :create) and not self.association.options[:readonly] self.plural_association? or (self.singular_association? and associated.blank?) end end From 87eca30ed9629e39b8a6e1e00c86d17c2edf54e1 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 6 Jun 2013 08:35:22 +0200 Subject: [PATCH 1942/2024] fix checking jquery version, fixes #279 --- app/assets/javascripts/jquery/active_scaffold.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 13d0b51bfe..543f496d3a 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -1,5 +1,5 @@ jQuery(document).ready(function($) { - if (jQuery().jquery < '1.8.0') { + if (/1\.[2-7]\..*/.test(jQuery().jquery)) { var error = 'ActiveScaffold requires jquery 1.8.0 or greater, please use jquery-rails 2.1.x gem or greater'; if (typeof console != 'undefined') console.error(error); else alert(error); From 8f1a77ce7b7ab2d18193a058d1bdec86d428adaf Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 6 Jun 2013 08:54:07 -1000 Subject: [PATCH 1943/2024] cache association options --- CHANGELOG | 1 + lib/active_scaffold/config/core.rb | 8 ++++++ .../helpers/association_helpers.rb | 25 +++++++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b3505a962b..bdf06c3c64 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ - Fix update calculations after destroy a row - Fix count and calculate searching with count_includes - Fix action_after_create +- Cache associations options (for :select form_ui on associations), it can be disabled with config.cache_association_options = false = 3.3.0 - Unify field overrides and list_ui method signatures diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index 34403a8d12..bc62903ce1 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -29,6 +29,10 @@ def self.actions=(val) cattr_accessor :cache_action_link_urls @@cache_action_link_urls = true + # enable caching of association options + cattr_accessor :cache_association_options + @@cache_association_options = true + # lets you disable the DHTML history def self.dhtml_history=(val) @@dhtml_history = val @@ -98,6 +102,9 @@ def columns=(val) # enable caching of action link urls attr_accessor :cache_action_link_urls + # enable caching of association options + attr_accessor :cache_association_options + # lets you specify whether add a create link for each sti child for a specific controller attr_accessor :sti_create_links def add_sti_create_links? @@ -147,6 +154,7 @@ def initialize(model_id) @frontend = self.class.frontend @theme = self.class.theme @cache_action_link_urls = self.class.cache_action_link_urls + @cache_association_options = self.class.cache_association_options @sti_create_links = self.class.sti_create_links # inherit from the global set of action links diff --git a/lib/active_scaffold/helpers/association_helpers.rb b/lib/active_scaffold/helpers/association_helpers.rb index d2e6c5d0e5..71504406af 100644 --- a/lib/active_scaffold/helpers/association_helpers.rb +++ b/lib/active_scaffold/helpers/association_helpers.rb @@ -1,6 +1,17 @@ module ActiveScaffold module Helpers module AssociationHelpers + # Cache the optins for select + def cache_association_options(association, conditions, klass, cache = true) + if active_scaffold_config.cache_association_options && cache + @_associations_cache ||= Hash.new { |h,k| h[k] = {} } + key = [association.name, association.active_record.name, klass.name].join('/') + @_associations_cache[key][conditions] ||= yield + else + yield + end + end + # Provides a way to honor the :conditions on an association while searching the association's klass def association_options_find(association, conditions = nil, klass = nil) if klass.nil? && association.options[:polymorphic] @@ -10,18 +21,22 @@ def association_options_find(association, conditions = nil, klass = nil) else return [] end + cache = !block_given? else + cache = !block_given? && klass.nil? klass ||= association.klass end conditions = options_for_association_conditions(association) if conditions.nil? - relation = klass.where(conditions).where(association.options[:conditions]) - relation = relation.includes(association.options[:include]) if association.options[:include] - relation = yield(relation) if block_given? - relation.all + cache_association_options(association, conditions, klass, cache) do + relation = klass.where(conditions).where(association.options[:conditions]) + relation = relation.includes(association.options[:include]) if association.options[:include] + relation = yield(relation) if block_given? + relation.to_a + end end - # Provides a way to honor the :conditions on an association while searching the association's klass + # Sorts the options for select def sorted_association_options_find(association, conditions = nil) association_options_find(association, conditions).sort_by(&:to_label) end From 7a3b0e388c979a593eab6920ff22342013c93562 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 6 Jun 2013 09:24:54 -1000 Subject: [PATCH 1944/2024] use render :partial with :collection in subforms, high performance improvement for very long subforms Clean some code to avoid changing @record in partials --- .../_form_association.html.erb | 10 +++--- .../_form_association_record.html.erb | 32 +++++++++++-------- .../_horizontal_subform.html.erb | 11 ++++--- .../_vertical_subform.html.erb | 7 ++-- .../edit_associated.js.erb | 2 +- lib/active_scaffold/actions/core.rb | 1 + 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/app/views/active_scaffold_overrides/_form_association.html.erb b/app/views/active_scaffold_overrides/_form_association.html.erb index 2d11dae14e..9e68a80b79 100644 --- a/app/views/active_scaffold_overrides/_form_association.html.erb +++ b/app/views/active_scaffold_overrides/_form_association.html.erb @@ -1,12 +1,12 @@ <% -parent_record = @record +parent_record = @record # save @record, some partial can change @record associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) -if show_blank_record = column.show_blank_record?(associated) - associated << build_associated(column, parent_record) +if column.show_blank_record?(associated) + show_blank_record = build_associated(column, parent_record) end disable_required_for_new = @disable_required_for_new -@disable_required_for_new = show_blank_record unless (column.singular_association? && column.required?) +@disable_required_for_new = !!show_blank_record unless (column.singular_association? && column.required?) subform_div_id = "#{sub_form_id(:association => column.name, :id => parent_record.id || generated_id(parent_record) || 99999999999)}-div" -%> <h5><%= column.label -%></h5> @@ -18,6 +18,6 @@ subform_div_id = "#{sub_form_id(:association => column.name, :id => parent_recor </div> <%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%> <% - @record = parent_record + @record = parent_record # restore @record, some partials can change it @disable_required_for_new = disable_required_for_new -%> diff --git a/app/views/active_scaffold_overrides/_form_association_record.html.erb b/app/views/active_scaffold_overrides/_form_association_record.html.erb index e5ccd142bc..61d170c2e1 100644 --- a/app/views/active_scaffold_overrides/_form_association_record.html.erb +++ b/app/views/active_scaffold_overrides/_form_association_record.html.erb @@ -1,10 +1,14 @@ <% record_column = column - readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) - crud_type = @record.new_record? ? :create : (readonly ? :read : :update) + Rails.logger.warn "Relying on @record to render form_asssociation_record partial with no :object is deprecated, called from #{caller(1).detect {|l| l =~ /\.erb:/ }.gsub(/(.*:\d+):.*/, '\1')}" unless local_assigns[:form_association_record] + record = form_association_record ||= @record # TODO remove me, backwards compatibility, no :collection neither object in render + @record = record # TODO remove me, backward compatibility, helpers using @record + readonly = (record.readonly? or not record.authorized_for?(:crud_type => :update)) + crud_type = record.new_record? ? :create : (readonly ? :read : :update) show_actions = false - config = active_scaffold_config_for(@record.class) - options = active_scaffold_input_options(config.columns[@record.class.primary_key], scope) + locked ||= false + config = active_scaffold_config_for(record.class) + options = active_scaffold_input_options(config.columns[record.class.primary_key], scope) tr_id = "association-#{options[:id]}" if config.subform.layout == :vertical @@ -24,20 +28,20 @@ default_col_class = [] flatten ||= false end - index ||= nil + index ||= form_association_record_counter ||= nil columns_length = 0 columns_groups = [] -%> <<%= record_tag %> class="sub-form-record"> -<% unless @record.errors.empty? -%> -<%= content_tag error_tag, :class => "association-record-errors", :id => element_messages_id(:action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}") do %> - <% errors = active_scaffold_error_messages_for(:record, :object_name => @record.class.model_name.human.downcase) %> - <%= error_inner_tag ? content_tag(error_inner_tag, errors, :colspan => (active_scaffold_config_for(@record.class).subform.columns.length + 1 if error_inner_tag == :td)) : errors %> +<% unless record.errors.empty? -%> +<%= content_tag error_tag, :class => "association-record-errors", :id => element_messages_id(:action => record.class.name.underscore, :id => "#{parent_record.id}-#{index}") do %> + <% errors = active_scaffold_error_messages_for(:record, :object_name => record.class.model_name.human.downcase) %> + <%= error_inner_tag ? content_tag(error_inner_tag, errors, :colspan => (active_scaffold_config_for(record.class).subform.columns.length + 1 if error_inner_tag == :td)) : errors %> <% end %> <% end %> -<%= content_tag row_tag, :id => tr_id, :class => "association-record#{' association-record-new' if @record.new_record?}#{' locked' if locked}" do %> -<% config.subform.columns.each :for => @record.class, :crud_type => :read, :flatten => flatten do |column| %> +<%= content_tag row_tag, :id => tr_id, :class => "association-record#{' association-record-new' if record.new_record?}#{' locked' if locked}" do %> +<% config.subform.columns.each :for => record.class, :crud_type => :read, :flatten => flatten do |column| %> <% if column.is_a? ActiveScaffold::DataStructures::ActionColumns columns_groups << column @@ -61,11 +65,11 @@ <% end -%> <% if show_actions -%> <%= content_tag column_tag, :class => "actions" do %> - <% if record_column.plural_association? and (@record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> + <% if record_column.plural_association? and (record.authorized_for?(:crud_type => :delete) or not [:destroy, :delete_all].include?(record_column.association.options[:dependent])) %> <%= link_to as_(:remove), '#', :class => 'destroy', :id => "#{options[:id]}-destroy" , :data => {:delete_id => tr_id} unless locked %> <% end %> - <% unless @record.new_record? %> - <input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= @record.id -%>" /> + <% unless record.new_record? %> + <input type="hidden" name="<%= options[:name] -%>" id="<%= options[:id] -%>" value="<%= record.id -%>" /> <% end -%> <% end %> <% end -%> diff --git a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb index 613cfc3495..c4ac622b93 100644 --- a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +++ b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb @@ -1,11 +1,12 @@ <table cellpadding="0" cellspacing="0" id="<%= sub_form_list_id(:association => column.name, :id => parent_record.try(:id) || generated_id(parent_record) || 99999999999) %>"> - <% @record = associated.empty? ? build_associated(column, parent_record) : associated.last -%> +<% + @record = show_blank_record || build_associated(column, parent_record) + association_scope = column_scope(column, scope) +-%> <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record, :record => @record} %> - <% associated.each_index do |index| %> - <% @record = associated[index] -%> - <%= render :partial => 'form_association_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last, :index => index} %> - <% end -%> + <%= render :partial => 'form_association_record', :collection => associated, :locals => {:scope => association_scope, :parent_record => parent_record, :column => column} %> + <%= render :partial => 'form_association_record', :object => show_blank_record, :locals => {:scope => association_scope, :parent_record => parent_record, :column => column, :locked => true, :index => associated.size} if show_blank_record %> <tfoot> <%= render :partial => 'horizontal_subform_footer', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column} %> </tfoot> diff --git a/app/views/active_scaffold_overrides/_vertical_subform.html.erb b/app/views/active_scaffold_overrides/_vertical_subform.html.erb index 22572e0d04..f35cc26809 100644 --- a/app/views/active_scaffold_overrides/_vertical_subform.html.erb +++ b/app/views/active_scaffold_overrides/_vertical_subform.html.erb @@ -1,6 +1,5 @@ <div id="<%= sub_form_list_id(:association => column.name, :id => parent_record.id || generated_id(parent_record) || 99999999999) %>"> - <% associated.each_index do |index| %> - <% @record = associated[index] -%> - <%= render :partial => 'form_association_record', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column, :locked => show_blank_record && @record.new_record? && @record == associated.last, :index => index} %> - <% end -%> +<% association_scope = column_scope(column, scope) -%> + <%= render :partial => 'form_association_record', :collection => associated, :locals => {:scope => association_scope, :parent_record => parent_record, :column => column} %> + <%= render :partial => 'form_association_record', :object => show_blank_record, :locals => {:scope => association_scope, :parent_record => parent_record, :column => column, :locked => true, :index => associated.size} if show_blank_record %> </div> diff --git a/app/views/active_scaffold_overrides/edit_associated.js.erb b/app/views/active_scaffold_overrides/edit_associated.js.erb index 9a49abfa01..0f1d150dd5 100644 --- a/app/views/active_scaffold_overrides/edit_associated.js.erb +++ b/app/views/active_scaffold_overrides/edit_associated.js.erb @@ -1,5 +1,5 @@ <% -associated_form = render :partial => "form_association_record", :locals => {:scope => @scope, :parent_record => @parent_record, :column => @column, :locked => @record.new_record? && @column.singular_association?} +associated_form = render :partial => "form_association_record", :object => @record, :locals => {:scope => @scope, :parent_record => @parent_record, :column => @column, :locked => @record.new_record? && @column.singular_association?} options = {:singular => false} if @column.singular_association? options[:singular] = true diff --git a/lib/active_scaffold/actions/core.rb b/lib/active_scaffold/actions/core.rb index 417579fce0..f5f5dd24ef 100644 --- a/lib/active_scaffold/actions/core.rb +++ b/lib/active_scaffold/actions/core.rb @@ -7,6 +7,7 @@ def self.included(base) after_filter :clear_storage rescue_from ActiveScaffold::RecordNotAllowed, ActiveScaffold::ActionNotAllowed, :with => :deny_access end + base.helper_method :successful? base.helper_method :nested? base.helper_method :calculate_query base.helper_method :new_model From ae4937726a4c3f0e58aa1a4d6532373bd55d5502 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 6 Jun 2013 10:07:25 -1000 Subject: [PATCH 1945/2024] remove some uses of @record and use record argument --- CHANGELOG | 1 + .../_form_association.html.erb | 4 +-- .../_form_association_record.html.erb | 4 +-- .../_render_field.js.erb | 2 +- .../helpers/form_column_helpers.rb | 31 +++++++++++-------- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index bdf06c3c64..b147cc44e1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ - Fix count and calculate searching with count_includes - Fix action_after_create - Cache associations options (for :select form_ui on associations), it can be disabled with config.cache_association_options = false +- Clean some code so we can stop changing @record in partials and using @record in helpers = 3.3.0 - Unify field overrides and list_ui method signatures diff --git a/app/views/active_scaffold_overrides/_form_association.html.erb b/app/views/active_scaffold_overrides/_form_association.html.erb index 9e68a80b79..da9e4d1221 100644 --- a/app/views/active_scaffold_overrides/_form_association.html.erb +++ b/app/views/active_scaffold_overrides/_form_association.html.erb @@ -1,5 +1,5 @@ <% -parent_record = @record # save @record, some partial can change @record +parent_record ||= @record # save @record, some partial can change @record TODO remove when changing @record is removed associated = column.singular_association? ? [parent_record.send(column.name)].compact : parent_record.send(column.name).to_a associated = associated.sort_by {|r| r.new_record? ? 99999999999 : r.id} unless column.association.options.has_key?(:order) if column.show_blank_record?(associated) @@ -18,6 +18,6 @@ subform_div_id = "#{sub_form_id(:association => column.name, :id => parent_recor </div> <%= link_to_visibility_toggle(subform_div_id, {:default_visible => !column.collapsed}) -%> <% - @record = parent_record # restore @record, some partials can change it + @record = parent_record # restore @record, some partials can change it TODO remove when changing @record is removed @disable_required_for_new = disable_required_for_new -%> diff --git a/app/views/active_scaffold_overrides/_form_association_record.html.erb b/app/views/active_scaffold_overrides/_form_association_record.html.erb index 61d170c2e1..9c5aab300e 100644 --- a/app/views/active_scaffold_overrides/_form_association_record.html.erb +++ b/app/views/active_scaffold_overrides/_form_association_record.html.erb @@ -60,7 +60,7 @@ col_class << 'hidden' if column_renders_as(column) == :hidden -%> <%= content_tag column_tag, :class => col_class.join(' ') do %> - <%= active_scaffold_render_subform_column(column, scope, crud_type, readonly) %> + <%= active_scaffold_render_subform_column(column, scope, crud_type, readonly, false, record) %> <% end %> <% end -%> <% if show_actions -%> @@ -79,7 +79,7 @@ <%= content_tag row_tag, :class => 'associated-record' do %> <%= content_tag column_tag, :colspan => (columns_length if column_tag == :td) do %> <% column.each :for => @record.class, :crud_type => :read, :flatten => true do |col| %> - <%= active_scaffold_render_subform_column(col, scope, crud_type, readonly, true) %> + <%= active_scaffold_render_subform_column(col, scope, crud_type, readonly, true, record) %> <% end %> <% end %> <% end %> diff --git a/app/views/active_scaffold_overrides/_render_field.js.erb b/app/views/active_scaffold_overrides/_render_field.js.erb index f9cf288dd6..536f33e072 100644 --- a/app/views/active_scaffold_overrides/_render_field.js.erb +++ b/app/views/active_scaffold_overrides/_render_field.js.erb @@ -17,7 +17,7 @@ html = if scope readonly = (@record.readonly? or not @record.authorized_for?(:crud_type => :update)) crud_type = @record.new_record? ? :create : (readonly ? :read : :update) - active_scaffold_render_subform_column(column, scope, crud_type, readonly, !active_scaffold_config.subform.columns.names_without_auth_check.include?(column.name)) + active_scaffold_render_subform_column(column, scope, crud_type, readonly, !active_scaffold_config.subform.columns.names_without_auth_check.include?(column.name), @record) else render_column(column, @record, renders_as, scope) end diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index d7284968a2..b68ff29ac2 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -57,7 +57,9 @@ def active_scaffold_render_input(column, options) end end - def active_scaffold_render_subform_column(column, scope, crud_type, readonly, add_class = false) + def active_scaffold_render_subform_column(column, scope, crud_type, readonly, add_class = false, record = nil) + Rails.logger.warn "Relying on @record is deprecated, call active_scaffold_render_subform_column with record. Called from #{caller.first.gsub(/(.*:\d+):.*/, '\1')}" if record.nil? # TODO Remove when relying on @record is removed + record ||= @record # TODO Remove when relying on @record is removed if add_class col_class = [] col_class << 'required' if column.required? @@ -66,12 +68,12 @@ def active_scaffold_render_subform_column(column, scope, crud_type, readonly, ad col_class << 'checkbox' if column.form_ui == :checkbox col_class = col_class.join(' ') end - unless readonly and not @record.new_record? or not @record.authorized_for?(:crud_type => crud_type, :column => column.name) - render_column(column, @record, column_renders_as(column), scope, false, col_class) + unless readonly and not record.new_record? or not record.authorized_for?(:crud_type => crud_type, :column => column.name) + render_column(column, record, column_renders_as(column), scope, false, col_class) else options = active_scaffold_input_options(column, scope).except(:name) options[:class] = "#{options[:class]} #{col_class}" if col_class - content_tag :span, get_column_value(@record, column), options + content_tag :span, get_column_value(record, column), options end end @@ -103,14 +105,17 @@ def active_scaffold_input_options(column, scope = nil, options = {}) end def update_columns_options(column, scope, options) + record = options[:object] + Rails.logger.warn "Relying on @record is deprecated, call update_columns_options with record. Called from #{caller.first.gsub(/(.*:\d+):.*/, '\1')}" if record.nil? # TODO Remove when relying on @record is removed + record ||= @record # TODO Remove when relying on @record is removed form_action = if scope - subform_controller = controller.class.active_scaffold_controller_for(@record.class) + subform_controller = controller.class.active_scaffold_controller_for(record.class) subform_controller.active_scaffold_config.subform elsif [:new, :create, :edit, :update, :render_field].include? params[:action].to_sym - active_scaffold_config.send(@record.new_record? ? :create : :update) + active_scaffold_config.send(record.new_record? ? :create : :update) end if form_action && column.update_columns && (column.update_columns & form_action.columns.names).present? - url_params = params_for(:action => 'render_field', :column => column.name, :id => @record.id) + url_params = params_for(:action => 'render_field', :column => column.name, :id => record.id) url_params = url_params.except(:parent_scaffold, :association, nested.param_name) if nested? && scope url_params[:eid] = params[:eid] if params[:eid] if scope @@ -133,25 +138,25 @@ def field_attributes(column, record) def render_column(column, record, renders_as, scope = nil, only_value = false, col_class = nil) if override_form_field_partial?(column) - render :partial => override_form_field_partial(column), :locals => { :column => column, :only_value => only_value, :scope => scope, :col_class => col_class } + render :partial => override_form_field_partial(column), :locals => { :column => column, :only_value => only_value, :scope => scope, :col_class => col_class, :record => record } elsif renders_as == :field || override_form_field?(column) form_attribute(column, record, scope, only_value, col_class) elsif renders_as == :subform - render :partial => 'form_association', :locals => { :column => column, :scope => scope } + render :partial => 'form_association', :locals => { :column => column, :scope => scope, :parent_record => record } else form_hidden_attribute(column, record, scope) end end def form_attribute(column, record, scope = nil, only_value = false, col_class = nil) - column_options = active_scaffold_input_options(column, scope) + column_options = active_scaffold_input_options(column, scope, :object => record) attributes = field_attributes(column, record) attributes[:class] = "#{attributes[:class]} #{col_class}" if col_class.present? field = unless only_value - active_scaffold_input_for column, scope, column_options.merge(:object => record) + active_scaffold_input_for column, scope, column_options else - content_tag(:span, get_column_value(@record, column), column_options.except(:name)) << - hidden_field(:record, column.association ? column.association.foreign_key : column.name, column_options.merge(:object => record)) + content_tag(:span, get_column_value(record, column), column_options.except(:name, :object)) << + hidden_field(:record, column.association ? column.association.foreign_key : column.name, column_options) end content_tag :dl, attributes do From 534098e674300d4612da63f1f7b4439795339ca0 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 6 Jun 2013 14:39:04 -1000 Subject: [PATCH 1946/2024] add localeapp and update translation files --- Gemfile | 2 + Gemfile.lock | 15 ++ config/initializers/localeapp.rb | 5 + config/locales/de.yml | 218 +++++++++++++-------------- config/locales/en.yml | 220 ++++++++++++++-------------- config/locales/es.yml | 225 ++++++++++++++-------------- config/locales/fr.yml | 244 +++++++++++++++---------------- config/locales/hu.yml | 219 ++++++++++++++------------- config/locales/ja.yml | 219 ++++++++++++++------------- config/locales/ru.yml | 240 +++++++++++++++--------------- 10 files changed, 808 insertions(+), 799 deletions(-) create mode 100644 config/initializers/localeapp.rb diff --git a/Gemfile b/Gemfile index ac5bfbfb5a..1a4943a576 100644 --- a/Gemfile +++ b/Gemfile @@ -11,4 +11,6 @@ group :development do gem "shoulda", ">= 0" gem "bundler", ">= 1.0.0" gem "rcov", ">= 0" + gem "localeapp" + gem "rack" end diff --git a/Gemfile.lock b/Gemfile.lock index d1da1a5767..02d03251ff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,18 +1,33 @@ GEM remote: http://rubygems.org/ specs: + gli (2.5.6) + i18n (0.6.4) json (1.6.3) + localeapp (0.6.9) + gli + i18n + json + rest-client + ya2yaml + mime-types (1.23) + rack (1.5.2) rake (10.0.4) rcov (0.9.9) rdoc (3.11) json (~> 1.4) + rest-client (1.6.7) + mime-types (>= 1.16) shoulda (2.11.3) + ya2yaml (0.31) PLATFORMS ruby DEPENDENCIES bundler (>= 1.0.0) + localeapp + rack rake rcov rdoc diff --git a/config/initializers/localeapp.rb b/config/initializers/localeapp.rb new file mode 100644 index 0000000000..1a20d5df17 --- /dev/null +++ b/config/initializers/localeapp.rb @@ -0,0 +1,5 @@ +require 'localeapp/rails' + +Localeapp.configure do |config| + config.api_key = 'VslrfM4Xuorsfk1972PSRqTY7pKKWAaqUC0IHswHZ5tVXvjEQ8' +end diff --git a/config/locales/de.yml b/config/locales/de.yml index dabd5fe043..71acd092c5 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1,126 +1,126 @@ de: time: formats: - picker: "%d.%m.%Y %H:%M" + picker: ! '%d.%m.%Y %H:%M' active_scaffold: - add: 'Hinzufügen' - add_existing: 'Existierenden Eintrag hinzufügen' - add_existing_model: 'Existierende %{model} hinzufügen' - apply: 'Apply' - are_you_sure_to_delete: 'Sind Sie sicher?' - cancel: 'Abbrechen' - click_to_edit: 'Zum Editieren anklicken' - click_to_reset: 'Reset' - close: 'Schließen' - config_list: 'Konfigurieren' - config_list_model: 'Konfiguriere Spalten für %{model}' - create: 'Anlegen' - create_model: 'Lege %{model} an' - create_another: 'Weitere anlegen' - created_model: '%{model} angelegt' - create_new: 'Neu anlegen' - customize: 'Anpassen' - delete: 'Löschen' - deleted_model: '%{model} gelöscht' - delimiter: 'Trennzeichen' - download: 'Download' - edit: 'Bearbeiten' - export: 'Exportieren' - nested_for_model: '%{nested_model} für %{parent_model}' - nested_of_model: '%{nested_model} von %{parent_model}' + add: Hinzufügen + add_existing: Existierenden Eintrag hinzufügen + add_existing_model: Existierende %{model} hinzufügen + apply: Apply + are_you_sure_to_delete: Sind Sie sicher? + cancel: Abbrechen + click_to_edit: Zum Editieren anklicken + click_to_reset: Reset + close: Schließen + config_list: Konfigurieren + config_list_model: Konfiguriere Spalten für %{model} + create: Anlegen + create_model: Lege %{model} an + create_another: Weitere anlegen + created_model: ! '%{model} angelegt' + create_new: Neu anlegen + customize: Anpassen + delete: Löschen + deleted_model: ! '%{model} gelöscht' + delimiter: Trennzeichen + download: Download + edit: Bearbeiten + export: Exportieren + nested_for_model: ! '%{nested_model} für %{parent_model}' + nested_of_model: ! '%{nested_model} von %{parent_model}' 'false': 'False' - filtered: '(Gefiltert)' - found: 'Gefunden' - hide: 'Verstecken' - inplace_edit_handle: '--' - live_search: 'Live-Suche' - loading: 'Lade…' - mark_all_records: "Mark all" - next: 'Vor' - no_entries: 'Keine Einträge' - no_options: 'Keine Optionen' - omit_header: 'Lasse Header weg' - options: 'Optionen' - pdf: 'PDF' - previous: 'Zurück' - print: 'Drucken' + filtered: (Gefiltert) + found: Gefunden + hide: Verstecken + inplace_edit_handle: -- + live_search: Live-Suche + loading: Lade… + mark_all_records: Mark all + next: Vor + no_entries: Keine Einträge + no_options: Keine Optionen + omit_header: Lasse Header weg + options: Optionen + pdf: PDF + previous: Zurück + print: Drucken records_marked: - one: "1 marked %{model}" - other: "%{count} marked %{model}" - refresh: 'Neu laden' - remove: 'Entfernen' - remove_file: 'Entferne oder Ersetze Datei' - replace_existing: 'Existierenden ersetzen' - replace_with_new: 'Mit Neuer ersetzen' - revisions_for_model: 'Revisionen für %{model}' - reset: 'Zurücksetzen' - saving: 'Speichern…' - search: 'Suche' - search_terms: 'Suchbegriffe' - _select_: '- Auswählen -' - show: 'Anzeigen' - show_model: 'Zeige %{model} an' - _to_ : ' zu ' + one: 1 marked %{model} + other: ! '%{count} marked %{model}' + refresh: Neu laden + remove: Entfernen + remove_file: Entferne oder Ersetze Datei + replace_existing: Existierenden ersetzen + replace_with_new: Mit Neuer ersetzen + revisions_for_model: Revisionen für %{model} + reset: Zurücksetzen + saving: Speichern… + search: Suche + search_terms: Suchbegriffe + _select_: ! '- Auswählen -' + show: Anzeigen + show_model: Zeige %{model} an + _to_: ! ' zu ' 'true': 'True' - update: 'Speichern' - update_model: 'Editiere %{model}' - updated_model: '%{model} aktualisiert' - '=': '=' - '>=': '>=' - '<=': '<=' - '>': '>' - '<': '<' - '!=': '!=' - between: 'Zwischen' - contains: 'Enthält' - begins_with: 'Beginnt' - ends_with: 'Endet' - today: 'Heute' - yesterday: 'Gestern' - tomorrow: 'Morgen' - this_week: 'Diese Woche' - prev_week: 'Letzte Woche' - next_week: 'Nächste Woche' - this_month: 'Diesen Monat' - prev_month: 'Letzten Monat' - next_month: 'Nächsten Monat' - this_year: 'Dieses Jahr' - prev_year: 'Letztes Jahr' - next_year: 'Nächstes Jahr' - past: 'Letzten' - future: 'Nächsten' - range: 'Zeitraum' - seconds: 'Sekunden' - minutes: 'Minuten' - hours: 'Stunden' - days: 'Tage' - weeks: 'Wochen' - months: 'Monate' - years: 'Jahre' - optional_attributes: 'Weitere' + update: Speichern + update_model: Editiere %{model} + updated_model: ! '%{model} aktualisiert' + =: = + ! '>=': ! '>=' + <=: <= + ! '>': ! '>' + <: < + ! '!=': ! '!=' + between: Zwischen + contains: Enthält + begins_with: Beginnt + ends_with: Endet + today: Heute + yesterday: Gestern + tomorrow: Morgen + this_week: Diese Woche + prev_week: Letzte Woche + next_week: Nächste Woche + this_month: Diesen Monat + prev_month: Letzten Monat + next_month: Nächsten Monat + this_year: Dieses Jahr + prev_year: Letztes Jahr + next_year: Nächstes Jahr + past: Letzten + future: Nächsten + range: Zeitraum + seconds: Sekunden + minutes: Minuten + hours: Stunden + days: Tage + weeks: Wochen + months: Monate + years: Jahre + optional_attributes: Weitere :null: 'Null' - not_null: 'Nicht Null' + not_null: Nicht Null date_picker_options: - weekHeader: 'Wo' + weekHeader: Wo firstDay: 1 isRTL: false showMonthAfterYear: false datetime_picker_options: - timeText: 'Uhrzeit' - currentText: 'Jetzt' - closeText: 'Schließen' + timeText: Uhrzeit + currentText: Jetzt + closeText: Schließen human_conditions: - boolean: "%{column} = %{value}" - association: "%{column} = %{value}" + boolean: ! '%{column} = %{value}' + association: ! '%{column} = %{value}' errors: template: header: - one: "Konnte %{model} nicht speichern: ein Fehler." - other: "Konnte %{model} nicht speichern: %{count} Fehler." - body: "Bitte überprüfen Sie die folgenden Felder:" - # error_messages - cant_destroy_record: "%{record} kann nicht gelöscht werden" - internal_error: 'Fehler bei der Verarbeitung (code 500, Interner Fehler)' - version_inconsistency: 'Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben.' - record_not_saved: 'Eintrag kann nicht gespeichert werden. Ursache unbekannt.' - no_authorization_for_action: "Keine Berechtigung für Aktion %{action}" + one: ! 'Konnte %{model} nicht speichern: ein Fehler.' + other: ! 'Konnte %{model} nicht speichern: %{count} Fehler.' + body: ! 'Bitte überprüfen Sie die folgenden Felder:' + cant_destroy_record: ! '%{record} kann nicht gelöscht werden' + internal_error: Fehler bei der Verarbeitung (code 500, Interner Fehler) + version_inconsistency: Inkonsistente Versionen - dieser Eintrag wurde verändert nachdem Sie mit der Bearbeitung begonnen haben. + record_not_saved: Eintrag kann nicht gespeichert werden. Ursache unbekannt. + no_authorization_for_action: Keine Berechtigung für Aktion %{action} + 'null': 'Null' diff --git a/config/locales/en.yml b/config/locales/en.yml index 0a860bffd7..4f4adcd131 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,128 +1,126 @@ en: time: formats: - picker: "%a, %d %b %Y %H:%M:%S" + picker: ! '%a, %d %b %Y %H:%M:%S' active_scaffold: - add: 'Add' - add_existing: 'Add Existing' - add_existing_model: 'Add Existing %{model}' - apply: 'Apply' - are_you_sure_to_delete: 'Are you sure you want to delete %{label}?' - cancel: 'Cancel' - click_to_edit: 'Click to edit' - click_to_reset: 'Click to reset' - close: 'Close' - config_list: 'Configure' - config_list_model: 'Configure Columns for %{model}' - create: 'Create' - create_model: 'Create %{model}' - create_another: 'Create Another %{model}' - created_model: 'Created %{model}' - create_new: 'Create New' - customize: 'Customize' - delete: 'Delete' - deleted_model: 'Deleted %{model}' - delimiter: 'Delimiter' - download: 'Download' - edit: 'Edit' - export: 'Export' - nested_for_model: '%{nested_model} for %{parent_model}' - nested_of_model: '%{nested_model} of %{parent_model}' + add: Add + add_existing: Add Existing + add_existing_model: Add Existing %{model} + apply: Apply + are_you_sure_to_delete: Are you sure you want to delete %{label}? + cancel: Cancel + click_to_edit: Click to edit + click_to_reset: Click to reset + close: Close + config_list: Configure + config_list_model: Configure Columns for %{model} + create: Create + create_model: Create %{model} + create_another: Create Another %{model} + created_model: Created %{model} + create_new: Create New + customize: Customize + delete: Delete + deleted_model: Deleted %{model} + delimiter: Delimiter + download: Download + edit: Edit + export: Export + nested_for_model: ! '%{nested_model} for %{parent_model}' + nested_of_model: ! '%{nested_model} of %{parent_model}' 'false': 'False' - filtered: '(Filtered)' - found: 'Found' - hide: 'Hide' - inplace_edit_handle: '--' - live_search: 'Live Search' - loading: 'Loading…' - mark_all_records: "Mark all" - next: 'Next' - no_entries: 'No Entries' - no_options: 'no options' - omit_header: 'Omit Header' - options: 'Options' - pdf: 'PDF' - previous: 'Previous' - print: 'Print' + filtered: (Filtered) + found: Found + hide: Hide + inplace_edit_handle: -- + live_search: Live Search + loading: Loading… + mark_all_records: Mark all + next: Next + no_entries: No Entries + no_options: no options + omit_header: Omit Header + options: Options + pdf: PDF + previous: Previous + print: Print records_marked: - one: "1 marked %{model}" - other: "%{count} marked %{model}" - refresh: 'Refresh' - remove: 'Remove' - remove_file: 'Remove or Replace file' - replace_existing: 'Replace Existing' - replace_with_new: 'Replace With New' - revisions_for_model: 'Revisions for %{model}' - reset: 'Reset' - saving: 'Saving…' - search: 'Search' - search_terms: 'Search Terms' - _select_: '- select -' - show: 'Show' - show_model: 'Show %{model}' - _to_ : ' to ' + one: 1 marked %{model} + other: ! '%{count} marked %{model}' + refresh: Refresh + remove: Remove + remove_file: Remove or Replace file + replace_existing: Replace Existing + replace_with_new: Replace With New + revisions_for_model: Revisions for %{model} + reset: Reset + saving: Saving… + search: Search + search_terms: Search Terms + _select_: ! '- select -' + show: Show + show_model: Show %{model} + _to_: ! ' to ' 'true': 'True' - update: 'Update' - update_model: 'Update %{model}' - updated_model: 'Updated %{model}' - '=': '=' - '>=': '>=' - '<=': '<=' - '>': '>' - '<': '<' - '!=': '!=' - between: 'Between' - contains: 'Contains' - begins_with: 'Begins with' - ends_with: 'Ends with' - today: 'Today' - yesterday: 'Yesterday' - tomorrow: 'Tommorrow' - this_week: 'This Week' - prev_week: 'Last Week' - next_week: 'Next Week' - this_month: 'This Month' - prev_month: 'Last Month' - next_month: 'Next Month' - this_year: 'This Year' - prev_year: 'Last Year' - next_year: 'Next Year' - past: 'Past' - future: 'Future' - range: 'Range' - seconds: 'Seconds' - minutes: 'Minutes' - hours: 'Hours' - days: 'Days' - weeks: 'Weeks' - months: 'Months' - years: 'Years' - optional_attributes: 'Further Options' + update: Update + update_model: Update %{model} + updated_model: Updated %{model} + =: = + ! '>=': ! '>=' + <=: <= + ! '>': ! '>' + <: < + ! '!=': ! '!=' + between: Between + contains: Contains + begins_with: Begins with + ends_with: Ends with + today: Today + yesterday: Yesterday + tomorrow: Tommorrow + this_week: This Week + prev_week: Last Week + next_week: Next Week + this_month: This Month + prev_month: Last Month + next_month: Next Month + this_year: This Year + prev_year: Last Year + next_year: Next Year + past: Past + future: Future + range: Range + seconds: Seconds + minutes: Minutes + hours: Hours + days: Days + weeks: Weeks + months: Months + years: Years + optional_attributes: Further Options :null: 'Null' - not_null: 'Not Null' + not_null: Not Null date_picker_options: - weekHeader: 'Wk' + weekHeader: Wk firstDay: 0 isRTL: false showMonthAfterYear: false - datetime_picker_options: - + closeText: Close + currentText: Now + timeText: Hour human_conditions: - boolean: "%{column} = %{value}" - association: "%{column} = %{value}" - + boolean: ! '%{column} = %{value}' + association: ! '%{column} = %{value}' errors: template: header: - one: "1 error prohibited this %{model} from being saved." - other: "%{count} errors prohibited this %{model} from being saved" - - body: "There were problems with the following fields:" - - # error_messages - cant_destroy_record: "%{record} can't be destroyed" - internal_error: 'Request Failed (code 500, Internal Error)' - version_inconsistency: 'Version inconsistency - this record has been modified since you started editing it.' - record_not_saved: 'Failed to save record cause of an unknown error' - no_authorization_for_action: "No Authorization for action %{action}" + one: 1 error prohibited this %{model} from being saved. + other: ! '%{count} errors prohibited this %{model} from being saved' + body: ! 'There were problems with the following fields:' + cant_destroy_record: ! '%{record} can''t be destroyed' + internal_error: Request Failed (code 500, Internal Error) + version_inconsistency: Version inconsistency - this record has been modified since you started editing it. + record_not_saved: Failed to save record cause of an unknown error + no_authorization_for_action: No Authorization for action %{action} + 'null': 'Null' diff --git a/config/locales/es.yml b/config/locales/es.yml index 6f7a63932a..a46d3dcaff 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1,129 +1,128 @@ es: time: formats: - picker: "%a, %d %b %Y %H:%M:%S" + picker: ! '%a, %d %b %Y %H:%M:%S' active_scaffold: - add: 'Añadir' - add_existing: 'Añadir Existente' - add_existing_model: 'Añadir %{model} Existente' - apply: 'Aplicar' - are_you_sure_to_delete: '¿Estás seguro de que quieres borrar %{label}?' - cancel: 'Cancelar' - click_to_edit: 'Pulsa para editar' - click_to_reset: 'Pulsa para restaurar' - close: 'Cerrar' - config_list: 'Configurar' - config_list_model: 'Configurar columnas de %{model}' - create: 'Crear' - create_model: 'Crear %{model}' - create_another: 'Crear Otro %{model}' - created_model: '%{model} creado' - create_new: 'Crear Nuevo' - customize: 'Personalizar' - delete: 'Borrar' - deleted_model: '%{model} borrado' - delimiter: 'Delimitador' - download: 'Descargar' - edit: 'Editar' - export: 'Exportar' + add: Añadir + add_existing: Añadir Existente + add_existing_model: Añadir %{model} Existente + apply: Aplicar + are_you_sure_to_delete: ¿Estás seguro de que quieres borrar %{label}? + cancel: Cancelar + click_to_edit: Pulsa para editar + click_to_reset: Pulsa para restaurar + close: Cerrar + config_list: Configurar + config_list_model: Configurar columnas de %{model} + create: Crear + create_model: Crear %{model} + create_another: Crear Otro %{model} + created_model: ! '%{model} creado' + create_new: Crear Nuevo + customize: Personalizar + delete: Borrar + deleted_model: ! '%{model} borrado' + delimiter: Delimitador + download: Descargar + edit: Editar + export: Exportar 'false': 'No' - filtered: '(Filtrado)' + filtered: (Filtrado) found: - one: 'encontrado' - other: 'encontrados' - hide: 'Ocultar' - inplace_edit_handle: '--' - live_search: 'Buscar en Vivo' - loading: 'Cargando…' - mark_all_records: "Seleccionar todos" - nested_for_model: '%{nested_model} de %{parent_model}' - nested_of_model: '%{nested_model} de %{parent_model}' - next: 'Siguiente' - no_entries: 'Sin entradas' - no_options: 'sin opciones' - omit_header: 'Omitir Cabecera' - options: 'Opciones' - pdf: 'PDF' - previous: 'Anterior' - print: 'Imprimir' + one: encontrado + other: encontrados + hide: Ocultar + inplace_edit_handle: -- + live_search: Buscar en Vivo + loading: Cargando… + mark_all_records: Seleccionar todos + nested_for_model: ! '%{nested_model} de %{parent_model}' + nested_of_model: ! '%{nested_model} de %{parent_model}' + next: Siguiente + no_entries: Sin entradas + no_options: sin opciones + omit_header: Omitir Cabecera + options: Opciones + pdf: PDF + previous: Anterior + print: Imprimir records_marked: - one: "1 %{model} seleccionado" - other: "%{count} %{model} seleccionados" - refresh: 'Recargar' - remove: 'Eliminar' - remove_file: 'Eliminar o Reemplazar archivo' - replace_existing: 'Reemplazar existente' - replace_with_new: 'Reemplazar con Nuevo' - revisions_for_model: 'Revisiones de %{model}' - reset: 'Restaurar' - saving: 'Guardando…' - search: 'Buscar' - search_terms: 'Términos a buscar' - _select_: '- seleccionar -' - show: 'Ver' - show_model: 'Ver %{model}' - _to_ : ' a ' - 'true': 'Sí' - update: 'Actualizar' - update_model: 'Actualizar %{model}' - updated_model: '%{model} actualizado' - '=': 'Igual' - '>=': 'Mayor o igual' - '<=': 'Menor o igual' - '>': 'Mayor' - '<': 'Menor' - '!=': 'Distinto' - between: 'Entre' - contains: 'Contiene' - begins_with: 'Empieza con' - ends_with: 'Termina con' - today: 'Hoy' - yesterday: 'Ayer' - tomorrow: 'Mañana' - this_week: 'Esta semana' - prev_week: 'Semana pasada' - next_week: 'Próxima semana' - this_month: 'Este mes' - prev_month: 'Mes pasado' - next_month: 'Próximo mes' - this_year: 'Este año' - prev_year: 'Año pasado' - next_year: 'Próximo año' - past: 'Pasado' - future: 'Futuro' - range: 'Rango' - seconds: 'Segundos' - minutes: 'Minutos' - hours: 'Horas' - days: 'Días' - weeks: 'Semanas' - months: 'Meses' - years: 'Años' - optional_attributes: 'Más opciones' - :null: 'Nulo' - not_null: 'No Nulo' + one: 1 %{model} seleccionado + other: ! '%{count} %{model} seleccionados' + refresh: Recargar + remove: Eliminar + remove_file: Eliminar o Reemplazar archivo + replace_existing: Reemplazar existente + replace_with_new: Reemplazar con Nuevo + revisions_for_model: Revisiones de %{model} + reset: Restaurar + saving: Guardando… + search: Buscar + search_terms: Términos a buscar + _select_: ! '- seleccionar -' + show: Ver + show_model: Ver %{model} + _to_: ! ' a ' + 'true': Sí + update: Actualizar + update_model: Actualizar %{model} + updated_model: ! '%{model} actualizado' + =: Igual + ! '>=': Mayor o igual + <=: Menor o igual + ! '>': Mayor + <: Menor + ! '!=': Distinto + between: Entre + contains: Contiene + begins_with: Empieza con + ends_with: Termina con + today: Hoy + yesterday: Ayer + tomorrow: Mañana + this_week: Esta semana + prev_week: Semana pasada + next_week: Próxima semana + this_month: Este mes + prev_month: Mes pasado + next_month: Próximo mes + this_year: Este año + prev_year: Año pasado + next_year: Próximo año + past: Pasado + future: Futuro + range: Rango + seconds: Segundos + minutes: Minutos + hours: Horas + days: Días + weeks: Semanas + months: Meses + years: Años + optional_attributes: Más opciones + :null: Nulo + not_null: No Nulo date_picker_options: - weekHeader: 'Sm' + weekHeader: Sm firstDay: 1 isRTL: false showMonthAfterYear: false datetime_picker_options: - timeText: 'Hora' - currentText: 'Ahora' - closeText: 'Cerrar' + timeText: Hora + currentText: Ahora + closeText: Cerrar human_conditions: - boolean: "%{column} = %{value}" - association: "%{column} = %{value}" + boolean: ! '%{column} = %{value}' + association: ! '%{column} = %{value}' errors: template: header: - one: "No se pudo guardar debido a un error." - other: "No se pudo guardar debido a %{count} errores." - body: "Hubo problemas con los siguientes campos:" - - # error_messages - cant_destroy_record: "No se pudo borrar %{record}" - internal_error: 'Petición fallida (código 500, error interno)' - version_inconsistency: 'Inconsistencia de versiones - este registro se ha modificado después de que empezó a editarlo.' - record_not_saved: 'Fallo guardando el registro debido a un error desconocido' - no_authorization_for_action: "No dispone de autorización para la acción %{action}" + one: No se pudo guardar %{model} debido a un error. + other: No se pudo guardar %{model} debido a %{count} errores. + body: ! 'Hubo problemas con los siguientes campos:' + cant_destroy_record: No se pudo borrar %{record} + internal_error: Petición fallida (código 500, error interno) + version_inconsistency: Inconsistencia de versiones - este registro se ha modificado después de que empezó a editarlo. + record_not_saved: Fallo guardando el registro debido a un error desconocido + no_authorization_for_action: No dispone de autorización para la acción %{action} + 'null': Nulo diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 91d9d72d44..ae01dfdefe 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -1,132 +1,126 @@ -fr: +fr: time: formats: - picker: "%a, %d %b %Y %H:%M:%S" - active_scaffold: - add: 'Ajouter' - add_existing: 'Ajouter un(e) existant(e)' - add_existing_model: 'Ajouter un(e) %{model} existant(e)' - apply: 'Apply' - are_you_sure_to_delete: 'Êtes vous sûr?' - cancel: 'Annuler' - click_to_edit: 'Cliquer pour éditer' - click_to_reset: 'Cliquer pour ré-initialiser' - close: 'Fermer' - config_list: 'Configure' - config_list_model: 'Configure Columns for %{model}' - create: 'Créer' - create_model: 'Créer %{model}' - create_another: 'Créer un autre' - created_model: '%{model} créé' - create_new: 'Créer un nouveau' - customize: 'Personnaliser' - delete: 'Supprimer' - deleted_model: 'Suppression de %{model}' - delimiter: 'Délimiteur' - download: 'Télécharger' - edit: 'Éditer' - export: 'Exporter' - nested_for_model: '%{nested_model} pour %{parent_model}' - nested_of_model: '%{nested_model} de %{parent_model}' - 'false': 'Faux' - filtered: '(Filtré)' - found: 'Trouvé' - hide: 'Cacher' - inplace_edit_handle: '--' - live_search: 'Recherche en temps réel' - loading: 'Chargement…' - mark_all_records: "Mark all" - next: 'Suivant' - no_entries: "Pas d'entrée" - no_options: "pas d'option" - omit_header: 'Omettre les en-têtes' - options: 'Options' - pdf: 'PDF' - previous: 'Précédent' - print: 'Imprimer' + picker: ! '%a, %d %b %Y %H:%M:%S' + active_scaffold: + add: Ajouter + add_existing: Ajouter un(e) existant(e) + add_existing_model: Ajouter un(e) %{model} existant(e) + apply: Apply + are_you_sure_to_delete: Êtes vous sûr? + cancel: Annuler + click_to_edit: Cliquer pour éditer + click_to_reset: Cliquer pour ré-initialiser + close: Fermer + config_list: Configure + config_list_model: Configure Columns for %{model} + create: Créer + create_model: Créer %{model} + create_another: Créer un autre + created_model: ! '%{model} créé' + create_new: Créer un nouveau + customize: Personnaliser + delete: Supprimer + deleted_model: Suppression de %{model} + delimiter: Délimiteur + download: Télécharger + edit: Éditer + export: Exporter + nested_for_model: ! '%{nested_model} pour %{parent_model}' + nested_of_model: ! '%{nested_model} de %{parent_model}' + 'false': Faux + filtered: (Filtré) + found: Trouvé + hide: Cacher + inplace_edit_handle: -- + live_search: Recherche en temps réel + loading: Chargement… + mark_all_records: Mark all + next: Suivant + no_entries: Pas d'entrée + no_options: pas d'option + omit_header: Omettre les en-têtes + options: Options + pdf: PDF + previous: Précédent + print: Imprimer records_marked: - one: "1 marked %{model}" - other: "%{count} marked %{model}" - refresh: 'Rafraîchir' - remove: 'Supprimer' - remove_file: 'Supprimer et remplacer le fichier' - replace_existing: 'Remplacer existant(e)' - replace_with_new: 'Remplacer avec le nouveau' - revisions_for_model: 'Révision pour %{model}' - reset: 'Annuler' - saving: 'Sauvegarder…' - search: 'Rechercher' - search_terms: 'Recherche de termes' - _select_: '- sélectionner -' - show: 'Montrer' - show_model: 'Montrer %{model}' - _to_ : ' à ' - 'true': 'Vrai' - update: 'Mettre à jour' - update_model: 'Mettre à jour le(/la) %{model}' - updated_model: 'Mis à jour de %{model}' - '=': '=' - '>=': '>=' - '<=': '<=' - '>': '>' - '<': '<' - '!=': '!=' - between: 'Entre' - contains: 'Contient' - begins_with: 'Commençant par' - ends_with: 'Se terminant par' - today: "Aujourd'hui" - yesterday: 'Hier' - tomorrow: 'Demain' - this_week: 'Cette Semaine' - prev_week: 'Semaine dernière' - next_week: 'Semaine prochaine' - this_month: 'Ce Mois' - prev_month: 'Mois dernier' - next_month: 'Mois prochain' - this_year: 'Cette Année' - prev_year: 'Année dernière' - next_year: 'Année prochaine' - past: 'Passé' - future: 'Futur' - range: 'Intervale' - seconds: 'Secondes' - minutes: 'Minutes' - hours: 'Heures' - days: 'Jours' - weeks: 'Semaines' - months: 'Mois' - years: 'Années' - optional_attributes: 'Options additionnelles' - :null: 'Nulle' - not_null: 'Non Nulle' - date_picker_options: - weekHeader: 'Sm' + one: 1 marked %{model} + other: ! '%{count} marked %{model}' + refresh: Rafraîchir + remove: Supprimer + remove_file: Supprimer et remplacer le fichier + replace_existing: Remplacer existant(e) + replace_with_new: Remplacer avec le nouveau + revisions_for_model: Révision pour %{model} + reset: Annuler + saving: Sauvegarder… + search: Rechercher + search_terms: Recherche de termes + _select_: ! '- sélectionner -' + show: Montrer + show_model: Montrer %{model} + _to_: ! ' à ' + 'true': Vrai + update: Mettre à jour + update_model: Mettre à jour le(/la) %{model} + updated_model: Mis à jour de %{model} + =: = + ! '>=': ! '>=' + <=: <= + ! '>': ! '>' + <: < + ! '!=': ! '!=' + between: Entre + contains: Contient + begins_with: Commençant par + ends_with: Se terminant par + today: Aujourd'hui + yesterday: Hier + tomorrow: Demain + this_week: Cette Semaine + prev_week: Semaine dernière + next_week: Semaine prochaine + this_month: Ce Mois + prev_month: Mois dernier + next_month: Mois prochain + this_year: Cette Année + prev_year: Année dernière + next_year: Année prochaine + past: Passé + future: Futur + range: Intervale + seconds: Secondes + minutes: Minutes + hours: Heures + days: Jours + weeks: Semaines + months: Mois + years: Années + optional_attributes: Options additionnelles + :null: Nulle + not_null: Non Nulle + date_picker_options: + weekHeader: Sm firstDay: 1 isRTL: false showMonthAfterYear: false - - datetime_picker_options: - timeText: 'Heure' - currentText: 'Maintenant' - closeText: 'Fermer' - + datetime_picker_options: + timeText: Heure + currentText: Maintenant + closeText: Fermer human_conditions: - boolean: "%{column} = %{value}" - association: "%{column} = %{value}" - - errors: - template: - header: - one: "1 erreur interdit ce(tte) %{model} d'être sauvegardé." - other: "%{count} erreurs interdit ce(tte) %{model} d'être sauvegardé" - - body: "Il y avait des problèmes avec les champs suivants :" - - - # error_messages - cant_destroy_record: "%{record} ne peut être supprimé" - internal_error: 'Erreur de la requête (code 500, Erreur interne)' - version_inconsistency: "Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer." - record_not_saved: "Impossible d'enregistrer l'enregistrement à cause d'une erreur inconnue" - no_authorization_for_action: "Aucune autorisation pour l'action %{action}" + boolean: ! '%{column} = %{value}' + association: ! '%{column} = %{value}' + errors: + template: + header: + one: 1 erreur interdit ce(tte) %{model} d'être sauvegardé. + other: ! '%{count} erreurs interdit ce(tte) %{model} d''être sauvegardé' + body: ! 'Il y avait des problèmes avec les champs suivants :' + cant_destroy_record: ! '%{record} ne peut être supprimé' + internal_error: Erreur de la requête (code 500, Erreur interne) + version_inconsistency: Version incomplète - Cet enregistrement a été modifié depuis que vous avez commencé à l'éditer. + record_not_saved: Impossible d'enregistrer l'enregistrement à cause d'une erreur inconnue + no_authorization_for_action: Aucune autorisation pour l'action %{action} + 'null': Nulle diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 7f1e0c415b..20e424078a 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -1,127 +1,126 @@ hu: time: formats: - picker: "%a, %d %b %Y %H:%M:%S" + picker: ! '%a, %d %b %Y %H:%M:%S' active_scaffold: - add: 'Hozzáadás' - add_existing: 'Meglevő hozzáadása' - add_existing_model: 'Meglevő %{model} hozzáadása' - apply: 'Apply' - are_you_sure_to_delete: 'Biztos vagy benne?' - cancel: 'Mégse' - click_to_edit: 'Kattints a szerkesztéshez' - click_to_reset: 'Kattints az alapállapothoz' - close: 'Bezárás' - config_list: 'Configure' - config_list_model: 'Configure Columns for %{model}' - create: 'Létrehozás' - create_model: '%{model} létrehozása' - create_another: 'Mégegy hozzáadása' - created_model: '%{model} létrehozva' - create_new: 'Új létrehozása' - customize: 'Testreszabás' - delete: 'Törlés' - deleted_model: '%{model} törölve' - delimiter: 'Elválasztó' - download: 'Letöltés' - edit: 'Szerkesztés' - export: 'Exportálás' - nested_for_model: '%{nested_model} / %{parent_model}' - nested_of_model: '%{nested_model} of %{parent_model}' + add: Hozzáadás + add_existing: Meglevő hozzáadása + add_existing_model: Meglevő %{model} hozzáadása + apply: Apply + are_you_sure_to_delete: + cancel: Mégse + click_to_edit: Kattints a szerkesztéshez + click_to_reset: Kattints az alapállapothoz + close: Bezárás + config_list: Configure + config_list_model: Configure Columns for %{model} + create: Létrehozás + create_model: ! '%{model} létrehozása' + create_another: + created_model: ! '%{model} létrehozva' + create_new: Új létrehozása + customize: Testreszabás + delete: Törlés + deleted_model: ! '%{model} törölve' + delimiter: Elválasztó + download: Letöltés + edit: Szerkesztés + export: Exportálás + nested_for_model: ! '%{nested_model} / %{parent_model}' + nested_of_model: ! '%{nested_model} of %{parent_model}' 'false': 'False' - filtered: '(Szűrt)' - found: 'Találat' - hide: 'Elrejtés' - inplace_edit_handle: '--' - live_search: 'Élő keresés' - loading: 'Betöltés…' - mark_all_records: "Mark all" - next: 'Következő' - no_entries: 'Nincs elem' - no_options: 'nincsenek opciók' - omit_header: 'Fejléc mellőzése' - options: 'Opciók' - pdf: 'PDF' - previous: 'Előző' - print: 'Nyomtatás' + filtered: (Szűrt) + found: Találat + hide: Elrejtés + inplace_edit_handle: -- + live_search: Élő keresés + loading: Betöltés… + mark_all_records: Mark all + next: Következő + no_entries: Nincs elem + no_options: nincsenek opciók + omit_header: Fejléc mellőzése + options: Opciók + pdf: PDF + previous: Előző + print: Nyomtatás records_marked: - one: "1 marked %{model}" - other: "%{count} marked %{model}" - refresh: 'Frissítés' - remove: 'Törlés' - remove_file: 'Fájl törlése, vagy cseréje' - replace_existing: 'Replace existing' - replace_with_new: 'Csere újjal' - revisions_for_model: '%{model} revíziói' - reset: 'Alapállapot' - saving: 'Mentés…' - search: 'Keresés' - search_terms: 'Keresési kifejezések' - _select_: '- válassz -' - show: 'Mutatás' - show_model: '%{model} mutatása' - _to_ : ' – ' + one: 1 marked %{model} + other: ! '%{count} marked %{model}' + refresh: Frissítés + remove: Törlés + remove_file: Fájl törlése, vagy cseréje + replace_existing: Replace existing + replace_with_new: Csere újjal + revisions_for_model: ! '%{model} revíziói' + reset: Alapállapot + saving: Mentés… + search: Keresés + search_terms: Keresési kifejezések + _select_: ! '- válassz -' + show: Mutatás + show_model: ! '%{model} mutatása' + _to_: ! ' – ' 'true': 'True' - update: 'Modosítás' - update_model: '%{model} modosítása' - updated_model: '%{model} módosítva' - '=': '=' - '>=': '>=' - '<=': '<=' - '>': '>' - '<': '<' - '!=': '!=' - between: 'Között' - contains: 'Contains' - begins_with: 'Begins with' - ends_with: 'Ends with' - today: 'Today' - yesterday: 'Yesterday' - tomorrow: 'Tommorrow' - this_week: 'This Week' - prev_week: 'Last Week' - next_week: 'Next Week' - this_month: 'This Month' - prev_month: 'Last Month' - next_month: 'Next Month' - this_year: 'This Year' - prev_year: 'Last Year' - next_year: 'Next Year' - past: 'Past' - future: 'Future' - range: 'Range' - seconds: 'Seconds' - minutes: 'Minutes' - hours: 'Hours' - days: 'Days' - weeks: 'Weeks' - months: 'Months' - years: 'Years' - optional_attributes: 'Further Options' + update: Modosítás + update_model: ! '%{model} modosítása' + updated_model: ! '%{model} módosítva' + =: = + ! '>=': ! '>=' + <=: <= + ! '>': ! '>' + <: < + ! '!=': ! '!=' + between: Között + contains: Contains + begins_with: Begins with + ends_with: Ends with + today: Today + yesterday: Yesterday + tomorrow: Tommorrow + this_week: This Week + prev_week: Last Week + next_week: Next Week + this_month: This Month + prev_month: Last Month + next_month: Next Month + this_year: This Year + prev_year: Last Year + next_year: Next Year + past: Past + future: Future + range: Range + seconds: Seconds + minutes: Minutes + hours: Hours + days: Days + weeks: Weeks + months: Months + years: Years + optional_attributes: Further Options :null: 'Null' - not_null: 'Not Null' + not_null: Not Null date_picker_options: - weekHeader: 'Wk' + weekHeader: Wk firstDay: 0 isRTL: false showMonthAfterYear: false - datetime_picker_options: - + closeText: + currentText: + timeText: human_conditions: - boolean: "%{column} = %{value}" - association: "%{column} = %{value}" - + boolean: ! '%{column} = %{value}' + association: ! '%{column} = %{value}' errors: template: header: - one: "1 error prohibited this %{model} from being saved." - other: "%{count} errors prohibited this %{model} from being saved" - - body: "There were problems with the following fields:" - - # error_messages - cant_destroy_record: "nem törölhető: %{record}" - internal_error: 'A lekérés sikertelen (code 500, Internal Error)' - version_inconsistency: 'Verzió ütközés - ezt a rekordot módosították mióta elkezdted szerkeszteni.' - failed_to_save_record: 'Failed to save record cause of an unknown error' + one: 1 error prohibited this %{model} from being saved. + other: ! '%{count} errors prohibited this %{model} from being saved' + body: ! 'There were problems with the following fields:' + cant_destroy_record: ! 'nem törölhető: %{record}' + internal_error: A lekérés sikertelen (code 500, Internal Error) + version_inconsistency: Verzió ütközés - ezt a rekordot módosították mióta elkezdted szerkeszteni. + no_authorization_for_action: + 'null': 'Null' + record_not_saved: diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 6aa11f585f..126074fc4c 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -1,127 +1,126 @@ ja: time: formats: - picker: "%a, %d %b %Y %H:%M:%S" + picker: ! '%a, %d %b %Y %H:%M:%S' active_scaffold: - add: '追加' - add_existing: '既存のものを追加' - add_existing_model: '既存の%{model}を追加' - apply: 'Apply' - are_you_sure_to_delete: '本当によいですか?' - cancel: 'キャンセル' - click_to_edit: 'クリックして編集' - click_to_reset: 'Click to reset' - close: '閉じる' - config_list: 'Configure' - config_list_model: 'Configure Columns for %{model}' - create: '作成' - create_model: '%{model}を作成' - create_another: '別のものを作成' - created_model: '%{model}を作成しました' - create_new: '新規作成' - customize: 'カスタマイズ' - delete: '削除' - deleted_model: '%{model}を削除しました' - delimiter: 'Delimiter' # needed? - download: 'ダウンロード' - edit: '編集' - export: 'Export' # needed? - nested_for_model: '%{parent_model}の%{nested_model}' - nested_of_model: '%{nested_model} of %{parent_model}' + add: 追加 + add_existing: 既存のものを追加 + add_existing_model: 既存の%{model}を追加 + apply: Apply + are_you_sure_to_delete: + cancel: キャンセル + click_to_edit: クリックして編集 + click_to_reset: Click to reset + close: 閉じる + config_list: Configure + config_list_model: Configure Columns for %{model} + create: 作成 + create_model: ! '%{model}を作成' + create_another: + created_model: ! '%{model}を作成しました' + create_new: 新規作成 + customize: カスタマイズ + delete: 削除 + deleted_model: ! '%{model}を削除しました' + delimiter: Delimiter + download: ダウンロード + edit: 編集 + export: Export + nested_for_model: ! '%{parent_model}の%{nested_model}' + nested_of_model: ! '%{nested_model} of %{parent_model}' 'false': 'False' - filtered: '(フィルタ中)' - found: '個ありました' - hide: '隠す' - inplace_edit_handle: '--' - live_search: 'その場で検索' - loading: '読み込み中…' - mark_all_records: "Mark all" - next: '次' - no_entries: '見つかりませんでした' - no_options: 'オプション無し' - omit_header: 'Omit Header' # needed? - options: 'オプション' - pdf: 'PDF' - previous: '前' - print: '印刷' + filtered: (フィルタ中) + found: 個ありました + hide: 隠す + inplace_edit_handle: -- + live_search: その場で検索 + loading: 読み込み中… + mark_all_records: Mark all + next: 次 + no_entries: 見つかりませんでした + no_options: オプション無し + omit_header: Omit Header + options: オプション + pdf: PDF + previous: 前 + print: 印刷 records_marked: - one: "1 marked %{model}" - other: "%{count} marked %{model}" - refresh: 'Refresh' # needed? - remove: '削除' - remove_file: 'ファイルを削除または置換' - replace_existing: 'Replace existing' - replace_with_new: '新しいもので置換' - revisions_for_model: 'Revisions for %{model}' # neede? - reset: 'リセット' - saving: '保存中…' - search: '検索' - search_terms: '検索単語' - _select_: '- 選択してください -' - show: '表示' - show_model: '%{model}を表示' - _to_ : ' to ' # needed? + one: 1 marked %{model} + other: ! '%{count} marked %{model}' + refresh: Refresh + remove: 削除 + remove_file: ファイルを削除または置換 + replace_existing: Replace existing + replace_with_new: 新しいもので置換 + revisions_for_model: Revisions for %{model} + reset: リセット + saving: 保存中… + search: 検索 + search_terms: 検索単語 + _select_: ! '- 選択してください -' + show: 表示 + show_model: ! '%{model}を表示' + _to_: ! ' to ' 'true': 'True' - update: '更新' - update_model: '%{model}を更新' - updated_model: '%{model}を更新しました' - '=': '=' - '>=': '>=' - '<=': '<=' - '>': '>' - '<': '<' - '!=': '!=' - between: 'Between' # needed? - contains: 'Contains' - begins_with: 'Begins with' - ends_with: 'Ends with' - today: 'Today' - yesterday: 'Yesterday' - tomorrow: 'Tommorrow' - this_week: 'This Week' - prev_week: 'Last Week' - next_week: 'Next Week' - this_month: 'This Month' - prev_month: 'Last Month' - next_month: 'Next Month' - this_year: 'This Year' - prev_year: 'Last Year' - next_year: 'Next Year' - past: 'Past' - future: 'Future' - range: 'Range' - seconds: 'Seconds' - minutes: 'Minutes' - hours: 'Hours' - days: 'Days' - weeks: 'Weeks' - months: 'Months' - years: 'Years' - optional_attributes: 'Further Options' + update: 更新 + update_model: ! '%{model}を更新' + updated_model: ! '%{model}を更新しました' + =: = + ! '>=': ! '>=' + <=: <= + ! '>': ! '>' + <: < + ! '!=': ! '!=' + between: Between + contains: Contains + begins_with: Begins with + ends_with: Ends with + today: Today + yesterday: Yesterday + tomorrow: Tommorrow + this_week: This Week + prev_week: Last Week + next_week: Next Week + this_month: This Month + prev_month: Last Month + next_month: Next Month + this_year: This Year + prev_year: Last Year + next_year: Next Year + past: Past + future: Future + range: Range + seconds: Seconds + minutes: Minutes + hours: Hours + days: Days + weeks: Weeks + months: Months + years: Years + optional_attributes: Further Options :null: 'Null' - not_null: 'Not Null' + not_null: Not Null date_picker_options: - weekHeader: 'Wk' + weekHeader: Wk firstDay: 0 isRTL: false showMonthAfterYear: false - datetime_picker_options: - + closeText: + currentText: + timeText: human_conditions: - boolean: "%{column} = %{value}" - association: "%{column} = %{value}" - + boolean: ! '%{column} = %{value}' + association: ! '%{column} = %{value}' errors: template: header: - one: "1 error prohibited this %{model} from being saved." - other: "%{count} errors prohibited this %{model} from being saved" - - body: "There were problems with the following fields:" - - # error_messages - cant_destroy_record: "%{record}を削除で来ません" - internal_error: 'リクエストが失敗しました(コード500: 内部エラー)' - version_inconsistency: 'バージョンが一致しません - あなたが編集している間にこのレコードが変更されました。' - failed_to_save_record: 'Failed to save record cause of an unknown error' + one: 1 error prohibited this %{model} from being saved. + other: ! '%{count} errors prohibited this %{model} from being saved' + body: ! 'There were problems with the following fields:' + cant_destroy_record: ! '%{record}を削除で来ません' + internal_error: ! 'リクエストが失敗しました(コード500: 内部エラー)' + version_inconsistency: バージョンが一致しません - あなたが編集している間にこのレコードが変更されました。 + no_authorization_for_action: + 'null': 'Null' + record_not_saved: diff --git a/config/locales/ru.yml b/config/locales/ru.yml index ee617554e3..4d1220caaa 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -1,136 +1,134 @@ ru: time: formats: - picker: "%a, %d %b %Y %H:%M:%S" + picker: ! '%a, %d %b %Y %H:%M:%S' active_scaffold: - add: 'Добавить запись' - add_existing: 'Добавить существующую запись' - add_existing_model: '%{model}: добавить существующую запись' - apply: 'Применить' - are_you_sure_to_delete: 'Удалить %{label}?' - cancel: 'Отмена' - click_to_edit: 'Нажмите для редактирования' - click_to_reset: 'Нажмите для сброса' - close: 'Закрыть' - config_list: 'Настройки списка' - config_list_model: '%{model}: настройки списка' - create: 'Создать' - create_model: '%{model}: создать запись' - create_another: 'Создать другую запись' - created_model: '%{model}: запись создана' - create_new: 'Создать новую запись' - customize: 'Настроить' - delete: 'Удалить' - deleted_model: '%{model}: запись удалена' - delimiter: 'Разделитель' - download: 'Загрузить' - edit: 'Изменить' - export: 'Экспорт' - nested_for_model: '%{parent_model} / %{nested_model}' - nested_of_model: '%{nested_model} @ %{parent_model}' - 'false': 'Нет' - filtered: '(Найденное)' + add: Добавить запись + add_existing: Добавить существующую запись + add_existing_model: ! '%{model}: добавить существующую запись' + apply: Применить + are_you_sure_to_delete: Удалить %{label}? + cancel: Отмена + click_to_edit: Нажмите для редактирования + click_to_reset: Нажмите для сброса + close: Закрыть + config_list: Настройки списка + config_list_model: ! '%{model}: настройки списка' + create: Создать + create_model: ! '%{model}: создать запись' + create_another: Создать другую запись + created_model: ! '%{model}: запись создана' + create_new: Создать новую запись + customize: Настроить + delete: Удалить + deleted_model: ! '%{model}: запись удалена' + delimiter: Разделитель + download: Загрузить + edit: Изменить + export: Экспорт + nested_for_model: ! '%{parent_model} / %{nested_model}' + nested_of_model: ! '%{nested_model} @ %{parent_model}' + 'false': Нет + filtered: (Найденное) found: - one: 'запись' - few: 'записи' - many: 'записей' - other: 'записи' - hide: 'Скрыть' - inplace_edit_handle: '--' - live_search: 'Поиск' - loading: 'Загрузка…' - mark_all_records: "Отметить все" - next: 'Следующее' - no_entries: 'Нет записей' - no_options: 'Нет вариантов' - omit_header: 'Пропустить заголовок' - options: 'Настройки' - pdf: 'PDF' - previous: 'Предыдущее' - print: 'Печать' + one: запись + few: записи + many: записей + other: записи + hide: Скрыть + inplace_edit_handle: -- + live_search: Поиск + loading: Загрузка… + mark_all_records: Отметить все + next: Следующее + no_entries: Нет записей + no_options: Нет вариантов + omit_header: Пропустить заголовок + options: Настройки + pdf: PDF + previous: Предыдущее + print: Печать records_marked: - one: "Отмечена 1 запись" - few: "Отмечено %{count} записи" - many: "Отмечено %{count} записей" - other: "Отмечено %{count} записи" - refresh: 'Обновить' - remove: 'Удалить' - remove_file: 'Удалить или заменить файл' - replace_existing: 'Заменить существующим' - replace_with_new: 'Заменить новым' - revisions_for_model: '%{model}: редакции' - reset: 'Сброс' - saving: 'Сохранение…' - search: 'Поиск' - search_terms: 'Ключевые слова' - _select_: '- выбрать -' - show: 'Показать' - show_model: '%{model}: показать запись' - _to_ : ' to ' - 'true': 'Да' - update: 'Обновить запись' - update_model: '%{model}: обновить запись' - updated_model: '%{model}: запись обновлена' - '=': '=' - '>=': '>=' - '<=': '<=' - '>': '>' - '<': '<' - '!=': '!=' - between: 'В интервале' - contains: 'Содержит' - begins_with: 'Начинается с' - ends_with: 'Оканчивается на' - today: 'Сегодня' - yesterday: 'Вчера' - tomorrow: 'Завтра' - this_week: 'На этой неделе' - prev_week: 'На прошлой неделе' - next_week: 'На следующей неделе' - this_month: 'В этом месяце' - prev_month: 'В прошлом месяце' - next_month: 'В следующем месяце' - this_year: 'В этом году' - prev_year: 'В прошлом году' - next_year: 'В следующем году' - past: 'Прошедшие' - future: 'Будущие' - range: 'Интервал' - seconds: 'секунд' - minutes: 'минут' - hours: 'часов' - days: 'дней' - weeks: 'недель' - months: 'месяцев' - years: 'лет' - optional_attributes: 'Дополнительные настройки' - :null: 'Пусто' - not_null: 'Не пусто' + one: Отмечена 1 запись + few: Отмечено %{count} записи + many: Отмечено %{count} записей + other: Отмечено %{count} записи + refresh: Обновить + remove: Удалить + remove_file: Удалить или заменить файл + replace_existing: Заменить существующим + replace_with_new: Заменить новым + revisions_for_model: ! '%{model}: редакции' + reset: Сброс + saving: Сохранение… + search: Поиск + search_terms: Ключевые слова + _select_: ! '- выбрать -' + show: Показать + show_model: ! '%{model}: показать запись' + _to_: ! ' to ' + 'true': Да + update: Обновить запись + update_model: ! '%{model}: обновить запись' + updated_model: ! '%{model}: запись обновлена' + =: = + ! '>=': ! '>=' + <=: <= + ! '>': ! '>' + <: < + ! '!=': ! '!=' + between: В интервале + contains: Содержит + begins_with: Начинается с + ends_with: Оканчивается на + today: Сегодня + yesterday: Вчера + tomorrow: Завтра + this_week: На этой неделе + prev_week: На прошлой неделе + next_week: На следующей неделе + this_month: В этом месяце + prev_month: В прошлом месяце + next_month: В следующем месяце + this_year: В этом году + prev_year: В прошлом году + next_year: В следующем году + past: Прошедшие + future: Будущие + range: Интервал + seconds: секунд + minutes: минут + hours: часов + days: дней + weeks: недель + months: месяцев + years: лет + optional_attributes: Дополнительные настройки + :null: Пусто + not_null: Не пусто date_picker_options: - weekHeader: 'Нед.' + weekHeader: Нед. firstDay: 1 isRTL: false showMonthAfterYear: false - datetime_picker_options: - + closeText: + currentText: + timeText: human_conditions: - boolean: "%{column} = %{value}" - association: "%{column} = %{value}" - + boolean: ! '%{column} = %{value}' + association: ! '%{column} = %{value}' errors: template: header: - one: '%{model}: сохранение не удалось из-за %{count} ошибки' - few: '%{model}: сохранение не удалось из-за %{count} ошибок' - many: '%{model}: сохранение не удалось из-за %{count} ошибок' - other: '%{model}: сохранение не удалось из-за %{count} ошибки' - body: 'Проблемы возникли со следующими полями:' - - # error_messages - cant_destroy_record: 'Запись %{record} не может быть удалена' - internal_error: '500 Внутренняя ошибка сервера' - version_inconsistency: 'Эта запись была обновлена с того момента, как вы начали ее редактировать' - record_not_saved: 'Запись не может быть сохранена из-за неизвестной ошибки' - no_authorization_for_action: 'Нет прав на выполнение действия "%{action}"' - + one: ! '%{model}: сохранение не удалось из-за %{count} ошибки' + few: ! '%{model}: сохранение не удалось из-за %{count} ошибок' + many: ! '%{model}: сохранение не удалось из-за %{count} ошибок' + other: ! '%{model}: сохранение не удалось из-за %{count} ошибки' + body: ! 'Проблемы возникли со следующими полями:' + cant_destroy_record: Запись %{record} не может быть удалена + internal_error: 500 Внутренняя ошибка сервера + version_inconsistency: Эта запись была обновлена с того момента, как вы начали ее редактировать + record_not_saved: Запись не может быть сохранена из-за неизвестной ошибки + no_authorization_for_action: Нет прав на выполнение действия "%{action}" + 'null': Пусто From b6548f2d26790d0aea7916b4c63751df3da8456e Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 6 Jun 2013 14:52:55 -1000 Subject: [PATCH 1947/2024] remove localeapp intializer from git, app cannot start --- .gitignore | 1 + config/initializers/localeapp.rb | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 config/initializers/localeapp.rb diff --git a/.gitignore b/.gitignore index 3979b07ba8..54e1a4a1fa 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,4 @@ pkg # For kdevelop: *.kdev4 .project +config/initializers/localeapp.rb diff --git a/config/initializers/localeapp.rb b/config/initializers/localeapp.rb deleted file mode 100644 index 1a20d5df17..0000000000 --- a/config/initializers/localeapp.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'localeapp/rails' - -Localeapp.configure do |config| - config.api_key = 'VslrfM4Xuorsfk1972PSRqTY7pKKWAaqUC0IHswHZ5tVXvjEQ8' -end From be07734d8eb4d156ab238f8e6845e1e6f58378ac Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 6 Jun 2013 15:26:06 -1000 Subject: [PATCH 1948/2024] fix typo on translation --- config/locales/en.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 4f4adcd131..c16735654e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -77,7 +77,7 @@ en: ends_with: Ends with today: Today yesterday: Yesterday - tomorrow: Tommorrow + tomorrow: Tomorrow this_week: This Week prev_week: Last Week next_week: Next Week From 915a4ab36e9e16e02ce11aaad8c04d0c571fa956 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 7 Jun 2013 09:36:04 +0200 Subject: [PATCH 1949/2024] update french --- .gitignore | 3 +++ config/locales/fr.yml | 18 +++++++++--------- config/locales/ru.yml | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 54e1a4a1fa..fde8b5163b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,9 @@ pkg # sass generated .sass-cache +# logs +log/** + # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore: # # * Create a file at ~/.gitignore diff --git a/config/locales/fr.yml b/config/locales/fr.yml index ae01dfdefe..5995e3fbcd 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -6,17 +6,17 @@ fr: add: Ajouter add_existing: Ajouter un(e) existant(e) add_existing_model: Ajouter un(e) %{model} existant(e) - apply: Apply - are_you_sure_to_delete: Êtes vous sûr? + apply: Appliquer + are_you_sure_to_delete: Êtes vous sûr de vouloir supprimer %{label} ? cancel: Annuler click_to_edit: Cliquer pour éditer click_to_reset: Cliquer pour ré-initialiser close: Fermer - config_list: Configure - config_list_model: Configure Columns for %{model} + config_list: Configurer + config_list_model: Configurer les colonnes pour %{model} create: Créer create_model: Créer %{model} - create_another: Créer un autre + create_another: Créer un autre %{model} created_model: ! '%{model} créé' create_new: Créer un nouveau customize: Personnaliser @@ -35,7 +35,7 @@ fr: inplace_edit_handle: -- live_search: Recherche en temps réel loading: Chargement… - mark_all_records: Mark all + mark_all_records: Marquer tous next: Suivant no_entries: Pas d'entrée no_options: pas d'option @@ -45,8 +45,8 @@ fr: previous: Précédent print: Imprimer records_marked: - one: 1 marked %{model} - other: ! '%{count} marked %{model}' + one: 1 %{model} marqué + other: ! '%{count} %{model} marqués' refresh: Rafraîchir remove: Supprimer remove_file: Supprimer et remplacer le fichier @@ -116,7 +116,7 @@ fr: template: header: one: 1 erreur interdit ce(tte) %{model} d'être sauvegardé. - other: ! '%{count} erreurs interdit ce(tte) %{model} d''être sauvegardé' + other: ! '%{count} erreurs interdisent ce(tte) %{model} d''être sauvegardé' body: ! 'Il y avait des problèmes avec les champs suivants :' cant_destroy_record: ! '%{record} ne peut être supprimé' internal_error: Erreur de la requête (code 500, Erreur interne) diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 4d1220caaa..0891bb6dc8 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -16,7 +16,7 @@ ru: config_list_model: ! '%{model}: настройки списка' create: Создать create_model: ! '%{model}: создать запись' - create_another: Создать другую запись + create_another: ! '%{model}: Создать другую запись' created_model: ! '%{model}: запись создана' create_new: Создать новую запись customize: Настроить From 02f44b40ae0424ac5740792e3dd9fdab1630a7c2 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 7 Jun 2013 09:31:03 -1000 Subject: [PATCH 1950/2024] Support jquery-rails 3 gem and jquery-ui-rails gem --- CHANGELOG | 1 + app/assets/javascripts/active_scaffold.js.erb | 6 ++++++ lib/active_scaffold/bridges/date_picker.rb | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index b147cc44e1..5456839587 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ - Fix action_after_create - Cache associations options (for :select form_ui on associations), it can be disabled with config.cache_association_options = false - Clean some code so we can stop changing @record in partials and using @record in helpers +- Support jquery-rails 3 gem and jquery-ui-rails gem = 3.3.0 - Unify field overrides and list_ui method signatures diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index 832e679f6e..ef426faeb3 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -1,7 +1,13 @@ <% case ActiveScaffold.js_framework %> <% when :jquery %> +<% if Jquery::Rails.const_defined? 'JQUERY_UI_VERSION' %> <% require_asset "jquery-ui" %> <% require_asset "jquery-ui-timepicker-addon" %> +<% elsif Jquery.const_defined? 'Ui' %> +<% require_asset "jquery.ui.core" %> +<% require_asset "jquery.ui.datepicker" %> +<% require_asset "jquery-ui-timepicker-addon" %> +<% end %> <% require_asset "jquery/active_scaffold" %> <% require_asset "jquery/jquery.editinplace" %> <% require_asset "jquery/date_picker_bridge" %> diff --git a/lib/active_scaffold/bridges/date_picker.rb b/lib/active_scaffold/bridges/date_picker.rb index f0ae0fa961..ebc272a1ed 100644 --- a/lib/active_scaffold/bridges/date_picker.rb +++ b/lib/active_scaffold/bridges/date_picker.rb @@ -5,7 +5,10 @@ def self.install require File.join(File.dirname(__FILE__), "date_picker/ext.rb") end def self.install? - ActiveScaffold.js_framework == :jquery + ActiveScaffold.js_framework == :jquery && jquery_ui_included? + end + def self.jquery_ui_included? + Jquery::Rails.const_defined?('JQUERY_UI_VERSION') || Jquery.const_defined?('Ui') end def self.localization "jQuery(function($){ From 9e3b1ffb9ab2c1c45ba470a7bd8b1abc40990ca1 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 7 Jun 2013 09:45:08 -1000 Subject: [PATCH 1951/2024] remove cellpadding and cellspacing, fixes #149 --- CHANGELOG | 1 + app/assets/stylesheets/active_scaffold_layout.css | 3 ++- .../active_scaffold_overrides/_horizontal_subform.html.erb | 2 +- app/views/active_scaffold_overrides/_list.html.erb | 2 +- app/views/active_scaffold_overrides/_list_record.html.erb | 2 +- app/views/active_scaffold_overrides/_list_with_header.html.erb | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5456839587..a196c81fcc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ - Cache associations options (for :select form_ui on associations), it can be disabled with config.cache_association_options = false - Clean some code so we can stop changing @record in partials and using @record in helpers - Support jquery-rails 3 gem and jquery-ui-rails gem +- Clean some invalid HTML = 3.3.0 - Unify field overrides and list_ui method signatures diff --git a/app/assets/stylesheets/active_scaffold_layout.css b/app/assets/stylesheets/active_scaffold_layout.css index fe0f2e6dbb..dd13a9069b 100644 --- a/app/assets/stylesheets/active_scaffold_layout.css +++ b/app/assets/stylesheets/active_scaffold_layout.css @@ -13,8 +13,9 @@ margin: 5px 0; .active-scaffold table { width: 100%; -border-collapse: separate; +border-collapse: collapse; } +.active-scaffold td, .active-scaffold th { padding: 0; } .active-scaffold a, .active-scaffold a:visited { diff --git a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb index c4ac622b93..a863d979b5 100644 --- a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +++ b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb @@ -1,4 +1,4 @@ -<table cellpadding="0" cellspacing="0" id="<%= sub_form_list_id(:association => column.name, :id => parent_record.try(:id) || generated_id(parent_record) || 99999999999) %>"> +<table id="<%= sub_form_list_id(:association => column.name, :id => parent_record.try(:id) || generated_id(parent_record) || 99999999999) %>"> <% @record = show_blank_record || build_associated(column, parent_record) association_scope = column_scope(column, scope) diff --git a/app/views/active_scaffold_overrides/_list.html.erb b/app/views/active_scaffold_overrides/_list.html.erb index aff7813e5f..1fda6b6e08 100644 --- a/app/views/active_scaffold_overrides/_list.html.erb +++ b/app/views/active_scaffold_overrides/_list.html.erb @@ -15,7 +15,7 @@ </tbody> </table> <% end %> -<table cellpadding="0" cellspacing="0"> +<table> <thead> <tr> <% columns = list_columns %> diff --git a/app/views/active_scaffold_overrides/_list_record.html.erb b/app/views/active_scaffold_overrides/_list_record.html.erb index cd3b0db4e7..0631968892 100644 --- a/app/views/active_scaffold_overrides/_list_record.html.erb +++ b/app/views/active_scaffold_overrides/_list_record.html.erb @@ -15,7 +15,7 @@ data_refresh ||= url_for(params_for(:action => :row, :id => '--ID--', :_method = <% end %> <% end -%> - <td class="actions"><table cellpadding="0" cellspacing="0"> + <td class="actions"><table> <tr> <td class="indicator-container"> <%= loading_indicator_tag(:action => :record, :id => record.id) %> diff --git a/app/views/active_scaffold_overrides/_list_with_header.html.erb b/app/views/active_scaffold_overrides/_list_with_header.html.erb index b116d19681..395e7988af 100644 --- a/app/views/active_scaffold_overrides/_list_with_header.html.erb +++ b/app/views/active_scaffold_overrides/_list_with_header.html.erb @@ -2,7 +2,7 @@ <div class="active-scaffold-header"> <%= render :partial => 'list_header' %> </div> - <table cellpadding="0" cellspacing="0"> + <table> <tbody class="before-header" id="<%= before_header_id -%>"> <% if active_scaffold_config.list.always_show_search %> <% old_record, @record = @record, new_model %> From 3124739a45c1283d4710b1bd781fe259ebd88198 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 7 Jun 2013 09:48:13 -1000 Subject: [PATCH 1952/2024] add sortable --- app/assets/javascripts/active_scaffold.js.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index ef426faeb3..a80c356e80 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -5,6 +5,7 @@ <% require_asset "jquery-ui-timepicker-addon" %> <% elsif Jquery.const_defined? 'Ui' %> <% require_asset "jquery.ui.core" %> +<% require_asset "jquery.ui.sortable" %> <% require_asset "jquery.ui.datepicker" %> <% require_asset "jquery-ui-timepicker-addon" %> <% end %> From 84874518294e069783a7520d548667e736c47105 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 7 Jun 2013 11:09:28 -1000 Subject: [PATCH 1953/2024] support inline settings with data- prefix for datepicker and datetimepicker --- .../jquery/date_picker_bridge.js.erb | 19 +++++++++++++++++++ .../bridges/date_picker/helper.rb | 10 +++++----- .../bridges/shared/date_bridge.rb | 2 +- .../javascripts/jquery-ui-timepicker-addon.js | 2 +- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/jquery/date_picker_bridge.js.erb b/app/assets/javascripts/jquery/date_picker_bridge.js.erb index d7be7792f9..795b12948b 100644 --- a/app/assets/javascripts/jquery/date_picker_bridge.js.erb +++ b/app/assets/javascripts/jquery/date_picker_bridge.js.erb @@ -1,5 +1,24 @@ <%# encoding: utf-8 %> <%= ActiveScaffold::Bridges[:date_picker].localization %> +$.datepicker.__proto__._attachDatepicker_without_inlineSettings = $.datepicker.__proto__._attachDatepicker; +$.extend($.datepicker.__proto__, { + _attachDatepicker: function(target, settings) { + var inlineSettings = {}, $target = $(target); + for (var attrName in this._defaults) { + if(this._defaults.hasOwnProperty(attrName)){ + var attrValue = $target.data(attrName.toLowerCase()); + if (attrValue) { + try { + inlineSettings[attrName] = eval(attrValue); + } catch (err) { + inlineSettings[attrName] = attrValue; + } + } + } + } + this._attachDatepicker_without_inlineSettings(target, $.extend({}, settings || {}, inlineSettings)); + } +}); jQuery(document).on("focus", "input.date_picker", function(){ var date_picker = jQuery(this); if (typeof(date_picker.datepicker) == 'function') { diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index d44866200f..6b036fd2ac 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -131,18 +131,18 @@ def datepicker_split_datetime_format(datetime_format) def to_datepicker_format(rails_format) ActiveScaffold::Bridges::DatePicker::Helper.to_datepicker_format(rails_format) end - + def datepicker_format_options(column, format, options) if column.form_ui == :date_picker js_format = to_datepicker_format(I18n.translate!("date.formats.#{format}")) - options['date:dateFormat'] = js_format unless js_format.nil? + options['data-dateFormat'] = js_format unless js_format.nil? else rails_time_format = I18n.translate!("time.formats.#{format}") date_format, time_format = datepicker_split_datetime_format(self.to_datepicker_format(rails_time_format)) - options['date:dateFormat'] = date_format unless date_format.nil? + options['data-dateFormat'] = date_format unless date_format.nil? unless time_format.nil? - options['time:timeFormat'] = time_format - options['time:ampm'] = true if rails_time_format.include?('%I') + options['data-timeFormat'] = time_format + options['data-ampm'] = true if rails_time_format.include?('%I') end end unless format == :default end diff --git a/lib/active_scaffold/bridges/shared/date_bridge.rb b/lib/active_scaffold/bridges/shared/date_bridge.rb index 9fbd38f6e6..f243769fcf 100644 --- a/lib/active_scaffold/bridges/shared/date_bridge.rb +++ b/lib/active_scaffold/bridges/shared/date_bridge.rb @@ -57,7 +57,7 @@ def active_scaffold_search_date_bridge_trend_units(column) def active_scaffold_search_date_bridge_range_tag(column, options, current_search) range_controls = select_tag("search[#{column.name}][range]", options_for_select( ActiveScaffold::Finder::DateRanges.collect{|range| [as_(range.downcase.to_sym), range]}, current_search["range"]), - :class => 'text-input') + :class => 'text-input', :id => nil) content_tag("span", range_controls.html_safe, :id => "#{options[:id]}_range", :style => (current_search['opt'] == 'RANGE') ? nil : "display: none") end diff --git a/vendor/assets/javascripts/jquery-ui-timepicker-addon.js b/vendor/assets/javascripts/jquery-ui-timepicker-addon.js index 299e85028f..c7aec4c366 100644 --- a/vendor/assets/javascripts/jquery-ui-timepicker-addon.js +++ b/vendor/assets/javascripts/jquery-ui-timepicker-addon.js @@ -163,7 +163,7 @@ for (var attrName in this._defaults) { if(this._defaults.hasOwnProperty(attrName)){ - var attrValue = $input.attr('time:' + attrName); + var attrValue = $input.data(attrName.toLowerCase()); if (attrValue) { try { inlineSettings[attrName] = eval(attrValue); From 67c20fc5c9a1b005d46fd2530db141034f21f769 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 7 Jun 2013 11:10:38 -1000 Subject: [PATCH 1954/2024] clean html --- app/assets/stylesheets/active_scaffold_layout.css | 3 +++ app/views/active_scaffold_overrides/_list_pagination.html.erb | 2 +- app/views/active_scaffold_overrides/_list_record.html.erb | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/active_scaffold_layout.css b/app/assets/stylesheets/active_scaffold_layout.css index dd13a9069b..b0b1785276 100644 --- a/app/assets/stylesheets/active_scaffold_layout.css +++ b/app/assets/stylesheets/active_scaffold_layout.css @@ -401,6 +401,9 @@ padding: 3px 0px 2px 0px; border-bottom: none; font: bold 12px arial, sans-serif; } +.active-scaffold .active-scaffold-footer > br { +clear: both; +} .active-scaffold-footer .active-scaffold-pagination { float: right; diff --git a/app/views/active_scaffold_overrides/_list_pagination.html.erb b/app/views/active_scaffold_overrides/_list_pagination.html.erb index 863d2e109a..3f5ce64ac8 100644 --- a/app/views/active_scaffold_overrides/_list_pagination.html.erb +++ b/app/views/active_scaffold_overrides/_list_pagination.html.erb @@ -6,6 +6,6 @@ <div class="active-scaffold-pagination"> <%= render :partial => 'list_pagination_links', :locals => { :current_page => @page } if @page.pager.infinite? || @page.pager.number_of_pages > 1 %> </div> - <br clear="both" /><%# a hack for the Rico Corner problem %> + <br /><!-- to clear this block --> </div> <% end -%> diff --git a/app/views/active_scaffold_overrides/_list_record.html.erb b/app/views/active_scaffold_overrides/_list_record.html.erb index 0631968892..4adde5cc16 100644 --- a/app/views/active_scaffold_overrides/_list_record.html.erb +++ b/app/views/active_scaffold_overrides/_list_record.html.erb @@ -5,7 +5,7 @@ tr_class = cycle("", "even-record") + ' ' + list_row_class(record) action_links ||= active_scaffold_config.action_links.member data_refresh ||= url_for(params_for(:action => :row, :id => '--ID--', :_method => :get)) -%> -<tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= data_refresh.sub('--ID--', record.id.to_s).html_safe %>"> +<tr class="record <%= tr_class %>" id="<%= element_row_id(:action => :list, :id => record.id) %>" data-refresh="<%= data_refresh.sub('--ID--', record.id.to_s) %>"> <% columns.each do |column| %> <% authorized = record.authorized_for?(:crud_type => :read, :column => column.name) -%> <% column_value = authorized ? get_column_value(record, column) : active_scaffold_config.list.empty_field_text -%> From 9405210944946717346754099f784411de8d262d Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 7 Jun 2013 11:56:59 -1000 Subject: [PATCH 1955/2024] clean html, remove for attribute from labels for plural association columns --- lib/active_scaffold/helpers/form_column_helpers.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index b68ff29ac2..f66adf95e2 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -160,12 +160,16 @@ def form_attribute(column, record, scope = nil, only_value = false, col_class = end content_tag :dl, attributes do - %|<dt>#{label_tag column_options[:id], column.label}</dt><dd>#{field} + %|<dt>#{label_tag label_for(column, column_options), column.label}</dt><dd>#{field} #{loading_indicator_tag(:action => :render_field, :id => params[:id]) if column.update_columns} #{content_tag :span, column.description, :class => 'description' if column.description.present?} </dd>|.html_safe end end + + def label_for(column, options) + options[:id] unless column.form_ui == :select && column.plural_association? + end def form_hidden_attribute(column, record, scope = nil) %|<dl style="display: none;"><dt></dt><dd> @@ -224,7 +228,7 @@ def active_scaffold_input_plural_association(column, options) end def active_scaffold_checkbox_list(column, select_options, associated_ids, options) - html = hidden_field_tag("#{options[:name]}[]", '') + html = hidden_field_tag("#{options[:name]}[]", '', :id => nil) html << content_tag(:ul, :class => "#{options[:class]} checkbox-list", :id => options[:id]) do content = ''.html_safe select_options.each_with_index do |option, i| From 480cd2ff34716066f911083fe0615c91ed8b4c52 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 7 Jun 2013 12:24:02 -1000 Subject: [PATCH 1956/2024] avoid using @record in search helpers --- .../_field_search.html.erb | 4 ++-- .../_search_attribute.html.erb | 10 ++++----- .../bridges/date_picker/helper.rb | 2 +- .../helpers/search_column_helpers.rb | 22 ++++++++++++++----- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/app/views/active_scaffold_overrides/_field_search.html.erb b/app/views/active_scaffold_overrides/_field_search.html.erb index 674fca40ef..9be68c6c6a 100644 --- a/app/views/active_scaffold_overrides/_field_search.html.erb +++ b/app/views/active_scaffold_overrides/_field_search.html.erb @@ -9,14 +9,14 @@ form_tag url_options, options %> <ol class="form"> <% visibles, hiddens = visibles_and_hiddens(active_scaffold_config.field_search) %> <% visibles.each do |column| -%> - <%= render :partial => 'search_attribute', :locals => {:column => column} %> + <li class="form-element"><%= search_attribute(column, @record) %></li> <% end -%> <% unless hiddens.empty? -%> <li class="sub-section"> <h5><%= as_(:optional_attributes) %></h5> <ol id ="<%= sub_section_id(:sub_section => 'further_options') %>" class="form" style="display:none;"> <% hiddens.each do |column| -%> - <%= render :partial => 'search_attribute', :locals => {:column => column} %> + <li class="form-element"><%= search_attribute(column, @record) %></li> <% end -%> </ol> <%= link_to_visibility_toggle(sub_section_id(:sub_section => 'further_options'), {:default_visible => false}) %> diff --git a/app/views/active_scaffold_overrides/_search_attribute.html.erb b/app/views/active_scaffold_overrides/_search_attribute.html.erb index fff5053223..b769abb1fd 100644 --- a/app/views/active_scaffold_overrides/_search_attribute.html.erb +++ b/app/views/active_scaffold_overrides/_search_attribute.html.erb @@ -1,10 +1,10 @@ <li class="form-element"> - <dl> - <dt> - <label for="<%= "search_#{column.name}" %>"><%= column.label %></label> - </dt> + <dl> + <dt> + <label for="<%= "search_#{column.name}" %>"><%= column.label %></label> + </dt> <dd> <%= active_scaffold_search_for(column) %> </dd> </dl> -</li> \ No newline at end of file +</li> diff --git a/lib/active_scaffold/bridges/date_picker/helper.rb b/lib/active_scaffold/bridges/date_picker/helper.rb index 6b036fd2ac..9fb9ceb80c 100644 --- a/lib/active_scaffold/bridges/date_picker/helper.rb +++ b/lib/active_scaffold/bridges/date_picker/helper.rb @@ -161,7 +161,7 @@ def active_scaffold_search_date_bridge_calendar_control(column, options, current options[:style] = (options[:show].nil? || options[:show]) ? nil : "display: none" format = options.delete(:format) || (column.search_ui == :date_picker ? :default : :picker) datepicker_format_options(column, format, options) - text_field_tag("#{options[:name]}[#{name}]", value ? l(value, :format => format) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]")) + text_field_tag("#{options[:name]}[#{name}]", value ? l(value, :format => format) : nil, options.merge(:id => "#{options[:id]}_#{name}", :name => "#{options[:name]}[#{name}]", :object => nil)) end end diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index d96747763b..75e3bc02d0 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -4,12 +4,12 @@ module Helpers module SearchColumnHelpers # This method decides which input to use for the given column. # It does not do any rendering. It only decides which method is responsible for rendering. - def active_scaffold_search_for(column) - options = active_scaffold_search_options(column) + def active_scaffold_search_for(column, options = nil) + options ||= active_scaffold_search_options(column) # first, check if the dev has created an override for this specific field for search if (method = override_search_field(column)) - send(method, @record, options) + send(method, options[:object] || @record, options) # second, check if the dev has specified a valid search_ui for this column, using specific ui for searches elsif column.search_ui and (method = override_search(column.search_ui)) @@ -21,7 +21,7 @@ def active_scaffold_search_for(column) # fourth, check if the dev has created an override for this specific field elsif (method = override_form_field(column)) - send(method, @record, options) + send(method, options[:object] || @record, options) # fallback: we get to make the decision else @@ -51,6 +51,16 @@ def active_scaffold_search_options(column) { :name => "search[#{column.name}]", :class => "#{column.name}-input", :id => "search_#{column.name}", :value => field_search_params[column.name] } end + def search_attribute(column, record) + column_options = active_scaffold_search_options(column).merge(:object => record) + field = active_scaffold_search_for column, column_options + %|<dl><dt>#{label_tag search_label_for(column, column_options), column.label}</dt><dd>#{field}</dd></dl>|.html_safe + end + + def search_label_for(column, options) + options[:id] unless [:range, :integer, :decimal, :float, :string, :date_picker, :datetime_picker, :calendar_date_select].include? column.search_ui + end + ## ## Search input methods ## @@ -114,7 +124,7 @@ def active_scaffold_search_boolean(column, options) select_options << [as_(:true), true] select_options << [as_(:false), false] - select_tag(options[:name], options_for_select(select_options, column.column.type_cast(field_search_params[column.name]))) + select_tag(options[:name], options_for_select(select_options, column.column.type_cast(field_search_params[column.name])), :id => options[:id]) end # we can't use checkbox ui because it's not possible to decide whether search for this field or not alias_method :active_scaffold_search_checkbox, :active_scaffold_search_boolean @@ -123,7 +133,7 @@ def active_scaffold_search_null(column, options) select_options = [] select_options << [as_(:_select_), nil] select_options.concat ActiveScaffold::Finder::NullComparators.collect {|comp| [as_(comp), comp]} - select_tag(options[:name], options_for_select(select_options, field_search_params[column.name])) + select_tag(options[:name], options_for_select(select_options, field_search_params[column.name]), :id => options[:id]) end def field_search_params_range_values(column) From 1083d490a5b156d6b65f45ffe66b4f9b6065403a Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 7 Jun 2013 12:24:44 -1000 Subject: [PATCH 1957/2024] remove unused partial --- .../_search_attribute.html.erb | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 app/views/active_scaffold_overrides/_search_attribute.html.erb diff --git a/app/views/active_scaffold_overrides/_search_attribute.html.erb b/app/views/active_scaffold_overrides/_search_attribute.html.erb deleted file mode 100644 index b769abb1fd..0000000000 --- a/app/views/active_scaffold_overrides/_search_attribute.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -<li class="form-element"> - <dl> - <dt> - <label for="<%= "search_#{column.name}" %>"><%= column.label %></label> - </dt> - <dd> - <%= active_scaffold_search_for(column) %> - </dd> - </dl> -</li> From 5ac68b9a8d9b86d48d23cafd94eed2144c478267 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 10 Jun 2013 11:28:15 -1000 Subject: [PATCH 1958/2024] Avoid record creation for render subform columns header --- .../active_scaffold_overrides/_horizontal_subform.html.erb | 4 ++-- .../_horizontal_subform_header.html.erb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb index a863d979b5..c8c1ef830e 100644 --- a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +++ b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb @@ -1,9 +1,9 @@ <table id="<%= sub_form_list_id(:association => column.name, :id => parent_record.try(:id) || generated_id(parent_record) || 99999999999) %>"> <% - @record = show_blank_record || build_associated(column, parent_record) + header_record_class = show_blank_record.try(:class) || column.association.klass association_scope = column_scope(column, scope) -%> - <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record, :record => @record} %> + <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record, :record_class => header_record_class} %> <%= render :partial => 'form_association_record', :collection => associated, :locals => {:scope => association_scope, :parent_record => parent_record, :column => column} %> <%= render :partial => 'form_association_record', :object => show_blank_record, :locals => {:scope => association_scope, :parent_record => parent_record, :column => column, :locked => true, :index => associated.size} if show_blank_record %> diff --git a/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb b/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb index f4def5d3c5..f26f675069 100644 --- a/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb +++ b/app/views/active_scaffold_overrides/_horizontal_subform_header.html.erb @@ -1,7 +1,7 @@ <thead> <tr> <% - active_scaffold_config_for(record.class).subform.columns.each :for => record.class, :crud_type => :read do |column| + active_scaffold_config_for(record_class).subform.columns.each :for => record_class, :crud_type => :read do |column| next if column.is_a? ActiveScaffold::DataStructures::ActionColumns next unless in_subform?(column, parent_record) hidden = column_renders_as(column) == :hidden From 112a0d1c3b1d5ba4cff97e2708b148082966f562 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 10 Jun 2013 11:52:14 -1000 Subject: [PATCH 1959/2024] fix scope calculation on subform, it was broken when render was changed to use :collection --- .../_form_association_record.html.erb | 1 + .../active_scaffold_overrides/_horizontal_subform.html.erb | 7 +++---- .../active_scaffold_overrides/_vertical_subform.html.erb | 5 ++--- app/views/active_scaffold_overrides/edit_associated.js.erb | 2 +- lib/active_scaffold/actions/subform.rb | 4 +--- lib/active_scaffold/helpers/form_column_helpers.rb | 5 +++-- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/views/active_scaffold_overrides/_form_association_record.html.erb b/app/views/active_scaffold_overrides/_form_association_record.html.erb index 9c5aab300e..7de22b9706 100644 --- a/app/views/active_scaffold_overrides/_form_association_record.html.erb +++ b/app/views/active_scaffold_overrides/_form_association_record.html.erb @@ -8,6 +8,7 @@ show_actions = false locked ||= false config = active_scaffold_config_for(record.class) + scope = column_scope(record_column, scope, record) options = active_scaffold_input_options(config.columns[record.class.primary_key], scope) tr_id = "association-#{options[:id]}" diff --git a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb index c8c1ef830e..02b250f376 100644 --- a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +++ b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb @@ -1,13 +1,12 @@ <table id="<%= sub_form_list_id(:association => column.name, :id => parent_record.try(:id) || generated_id(parent_record) || 99999999999) %>"> <% header_record_class = show_blank_record.try(:class) || column.association.klass - association_scope = column_scope(column, scope) -%> <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record, :record_class => header_record_class} %> - <%= render :partial => 'form_association_record', :collection => associated, :locals => {:scope => association_scope, :parent_record => parent_record, :column => column} %> - <%= render :partial => 'form_association_record', :object => show_blank_record, :locals => {:scope => association_scope, :parent_record => parent_record, :column => column, :locked => true, :index => associated.size} if show_blank_record %> + <%= render :partial => 'form_association_record', :collection => associated, :locals => {:scope => scope, :parent_record => parent_record, :column => column} %> + <%= render :partial => 'form_association_record', :object => show_blank_record, :locals => {:scope => scope, :parent_record => parent_record, :column => column, :locked => true, :index => associated.size} if show_blank_record %> <tfoot> - <%= render :partial => 'horizontal_subform_footer', :locals => {:scope => column_scope(column, scope), :parent_record => parent_record, :column => column} %> + <%= render :partial => 'horizontal_subform_footer', :locals => {:scope => scope, :parent_record => parent_record, :column => column} %> </tfoot> </table> diff --git a/app/views/active_scaffold_overrides/_vertical_subform.html.erb b/app/views/active_scaffold_overrides/_vertical_subform.html.erb index f35cc26809..023fb86ffc 100644 --- a/app/views/active_scaffold_overrides/_vertical_subform.html.erb +++ b/app/views/active_scaffold_overrides/_vertical_subform.html.erb @@ -1,5 +1,4 @@ <div id="<%= sub_form_list_id(:association => column.name, :id => parent_record.id || generated_id(parent_record) || 99999999999) %>"> -<% association_scope = column_scope(column, scope) -%> - <%= render :partial => 'form_association_record', :collection => associated, :locals => {:scope => association_scope, :parent_record => parent_record, :column => column} %> - <%= render :partial => 'form_association_record', :object => show_blank_record, :locals => {:scope => association_scope, :parent_record => parent_record, :column => column, :locked => true, :index => associated.size} if show_blank_record %> + <%= render :partial => 'form_association_record', :collection => associated, :locals => {:scope => scope, :parent_record => parent_record, :column => column} %> + <%= render :partial => 'form_association_record', :object => show_blank_record, :locals => {:scope => scope, :parent_record => parent_record, :column => column, :locked => true, :index => associated.size} if show_blank_record %> </div> diff --git a/app/views/active_scaffold_overrides/edit_associated.js.erb b/app/views/active_scaffold_overrides/edit_associated.js.erb index 0f1d150dd5..7f2a1cb057 100644 --- a/app/views/active_scaffold_overrides/edit_associated.js.erb +++ b/app/views/active_scaffold_overrides/edit_associated.js.erb @@ -6,7 +6,7 @@ if @column.singular_association? else unless @record.new_record? column = active_scaffold_config_for(@record.class).columns[@record.class.primary_key] - options[:id] = active_scaffold_input_options(column, @scope)[:id] + options[:id] = active_scaffold_input_options(column, column_scope(@column, @scope, @record))[:id] end end %> ActiveScaffold.create_associated_record_form('<%=sub_form_list_id(:association => @column.name, :id => @parent_record.id || generated_id(@parent_record) || 99999999999)%>','<%=escape_javascript(associated_form)%>', <%= options.to_json.html_safe %>); diff --git a/lib/active_scaffold/actions/subform.rb b/lib/active_scaffold/actions/subform.rb index 0cc2d0b8c3..02c39673b1 100644 --- a/lib/active_scaffold/actions/subform.rb +++ b/lib/active_scaffold/actions/subform.rb @@ -15,9 +15,7 @@ def do_edit_associated # NOTE: we don't check whether the user is allowed to update this record, because if not, we'll still let them associate the record. we'll just refuse to do more than associate, is all. @record = @column.association.klass.find(params[:associated_id]) if params[:associated_id] @record ||= build_associated(@column, @parent_record) - - @scope = "#{params[:scope]}[#{@column.name}]" - @scope += "[#{@record.id || generate_temporary_id(@record)}]" if @column.plural_association? + @scope = params[:scope] end end diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index f66adf95e2..524c79db17 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -412,9 +412,10 @@ def column_renders_as(column) end end - def column_scope(column, scope = nil) + def column_scope(column, scope = nil, record = nil) + Rails.logger.warn "Relying on @record is deprecated, call column_scope with record. Called from #{caller.first.gsub(/(.*:\d+):.*/, '\1')}" if record.nil? # TODO Remove when relying on @record is removed if column.plural_association? - "#{scope}[#{column.name}][#{@record.id || generate_temporary_id}]" + "#{scope}[#{column.name}][#{record.id || generate_temporary_id}]" else "#{scope}[#{column.name}]" end From adedcfaf7e116fbbd5ce66c0bc34175956c3e1b0 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 10 Jun 2013 16:03:29 -1000 Subject: [PATCH 1960/2024] Use list_columns method for setting associations includes, so columns excluded with config_list plugin are not used --- lib/active_scaffold/actions/list.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index a5a0ac202f..2df5d30041 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -61,7 +61,12 @@ def row_respond_to_js # The actual algorithm to prepare for the list view def set_includes_for_columns(action = :list) @cache_associations = true - includes_for_list_columns = active_scaffold_config.send(action).columns.collect_visible(:flatten => true){ |c| c.includes }.flatten.uniq.compact + columns = if respond_to?(:"#{action}_columns") + send(:"#{action}_columns") + else + active_scaffold_config.send(action).columns.collect_visible(:flatten => true) + end + includes_for_list_columns = columns.map{ |c| c.includes }.flatten.uniq.compact self.active_scaffold_includes.concat includes_for_list_columns end From 6d001588b9f335fa738dd8f409223ea0f23b42ed Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 11 Jun 2013 10:01:18 -1000 Subject: [PATCH 1961/2024] avoid using @record for inplace edit template --- lib/active_scaffold/helpers/list_column_helpers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index e87cb2e9df..52c0635c51 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -222,11 +222,11 @@ def active_scaffold_inplace_edit(record, column, options = {}) def inplace_edit_control(column) if inplace_edit?(active_scaffold_config.model, column) and inplace_edit_cloning?(column) - old_record, @record = @record, new_model + old_record, @record = @record, new_model # TODO remove when relying on @record is removed column = column.clone column.options = column.options.clone column.form_ui = :select if (column.association && column.form_ui.nil?) - options = active_scaffold_input_options(column) + options = active_scaffold_input_options(column).merge(:object => new_model) options[:class] = "#{options[:class]} inplace_field" content_tag(:div, active_scaffold_input_for(column, nil, options), :style => "display:none;", :class => inplace_edit_control_css_class).tap do @record = old_record From 8b02973a483e72ca4a5dc402c3429cd2bb4ff925 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 11 Jun 2013 10:02:03 -1000 Subject: [PATCH 1962/2024] clear session when setting nil values --- lib/active_scaffold/config/base.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/config/base.rb b/lib/active_scaffold/config/base.rb index 3d722a04da..7c03141422 100644 --- a/lib/active_scaffold/config/base.rb +++ b/lib/active_scaffold/config/base.rb @@ -58,7 +58,12 @@ def [](key) def []=(key, value) @session[@action] ||= {} - @session[@action][key] = value + if value + @session[@action][key] = value + else + @session[@action].delete key + @session.delete @action if @session[@action].empty? + end end end From cf9a1142683d711ffd9b5f1267d1b5d4b60e8d1f Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 11 Jun 2013 10:38:58 -1000 Subject: [PATCH 1963/2024] store user settings (sort, page, search_params) into session is optional now, fixes #280 --- CHANGELOG | 1 + lib/active_scaffold.rb | 3 ++- lib/active_scaffold/actions/common_search.rb | 10 +++++++--- lib/active_scaffold/actions/field_search.rb | 1 + lib/active_scaffold/config/core.rb | 8 ++++++++ lib/active_scaffold/config/list.rb | 4 ++++ lib/active_scaffold/helpers/list_column_helpers.rb | 3 +++ lib/active_scaffold/helpers/pagination_helpers.rb | 8 ++++++++ 8 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a196c81fcc..6a8ae5e241 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ - Clean some code so we can stop changing @record in partials and using @record in helpers - Support jquery-rails 3 gem and jquery-ui-rails gem - Clean some invalid HTML +- Add store_user_settings option to enable storing sort, page and search params into session (enabled by default for backwards compatibility) = 3.3.0 - Unify field overrides and list_ui method signatures diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 4ebb4446cc..9ed248e003 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -107,7 +107,8 @@ def handle_user_settings active_scaffold_config.actions.each do |action_name| conf_instance = active_scaffold_config.send(action_name) rescue next next if conf_instance.class::UserSettings == ActiveScaffold::Config::Base::UserSettings # if it hasn't been extended, skip it - conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, active_scaffold_session_storage, params) + storage = active_scaffold_config.store_user_settings ? active_scaffold_session_storage : {} + conf_instance.user = conf_instance.class::UserSettings.new(conf_instance, storage, params) end end end diff --git a/lib/active_scaffold/actions/common_search.rb b/lib/active_scaffold/actions/common_search.rb index d6fa8adac9..4f998c3d5f 100644 --- a/lib/active_scaffold/actions/common_search.rb +++ b/lib/active_scaffold/actions/common_search.rb @@ -2,11 +2,15 @@ module ActiveScaffold::Actions module CommonSearch protected def store_search_params_into_session - active_scaffold_session_storage[:search] = params.delete :search if params[:search] + if active_scaffold_config.store_user_settings + active_scaffold_session_storage[:search] = params.delete :search if params[:search] + else + @search_params = params.delete :search + end end - + def search_params - active_scaffold_session_storage[:search] + @search_params || active_scaffold_session_storage[:search] end def search_ignore? diff --git a/lib/active_scaffold/actions/field_search.rb b/lib/active_scaffold/actions/field_search.rb index 0e5b5085c1..af63f31274 100644 --- a/lib/active_scaffold/actions/field_search.rb +++ b/lib/active_scaffold/actions/field_search.rb @@ -6,6 +6,7 @@ def self.included(base) base.before_filter :store_search_params_into_session, :only => [:index] base.before_filter :do_search, :only => [:index] base.helper_method :field_search_params + base.helper_method :search_params end # FieldSearch uses params[:search] and not @record because search conditions do not always pass the Model's validations. diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index bc62903ce1..e97b6f45a2 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -33,6 +33,10 @@ def self.actions=(val) cattr_accessor :cache_association_options @@cache_association_options = true + # enable saving user settings in session (per_page, limit, page, sort, search params) + cattr_accessor :store_user_settings + @@store_user_settings = true + # lets you disable the DHTML history def self.dhtml_history=(val) @@dhtml_history = val @@ -105,6 +109,9 @@ def columns=(val) # enable caching of association options attr_accessor :cache_association_options + # enable saving user settings in session (per_page, limit, page, sort, search params) + attr_accessor :store_user_settings + # lets you specify whether add a create link for each sti child for a specific controller attr_accessor :sti_create_links def add_sti_create_links? @@ -155,6 +162,7 @@ def initialize(model_id) @theme = self.class.theme @cache_action_link_urls = self.class.cache_action_link_urls @cache_association_options = self.class.cache_association_options + @store_user_settings = self.class.store_user_settings @sti_create_links = self.class.sti_create_links # inherit from the global set of action links diff --git a/lib/active_scaffold/config/list.rb b/lib/active_scaffold/config/list.rb index 8016844dfb..c0bdf55c89 100644 --- a/lib/active_scaffold/config/list.rb +++ b/lib/active_scaffold/config/list.rb @@ -235,6 +235,10 @@ def default_sorting nested_default_sorting.nil? ? @conf.sorting : nested_default_sorting end + def user_sorting? + @params['sort'] && @params['sort_direction'] != 'reset' + end + def sorting if @sorting.nil? # we want to store as little as possible in the session, but we want to return a Sorting data structure. so we recreate it each page load based on session data. diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 52c0635c51..3867a05903 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -302,6 +302,9 @@ def column_heading_value(column, sorting, sort_direction) :remote => true, :method => :get} url_options = params_for(:action => :index, :page => 1, :sort => column.name, :sort_direction => sort_direction) + unless active_scaffold_config.store_user_settings + url_options.merge!(:search => search_params) if search_params.present? + end link_to column_heading_label(column), url_options, options else content_tag(:p, column_heading_label(column)) diff --git a/lib/active_scaffold/helpers/pagination_helpers.rb b/lib/active_scaffold/helpers/pagination_helpers.rb index 71fa08a201..7a625ee53a 100644 --- a/lib/active_scaffold/helpers/pagination_helpers.rb +++ b/lib/active_scaffold/helpers/pagination_helpers.rb @@ -6,6 +6,14 @@ def pagination_ajax_link(page_number, url_options, options) end def pagination_ajax_links(current_page, url_options, options, inner_window, outer_window) + unless active_scaffold_config.store_user_settings + url_options.merge!(:search => search_params) if search_params.present? + if active_scaffold_config.list.user.user_sorting? + column, direction = active_scaffold_config.list.user.sorting.first + url_options.merge!(:sort => column.name, :sort_direction => direction) + end + end + start_number = current_page.number - inner_window end_number = current_page.number + inner_window start_number = 1 if start_number <= 0 From 33c63237fc8fbca184332d5f9fed5710f646abba Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 12 Jun 2013 09:03:41 +0200 Subject: [PATCH 1964/2024] mostrar False en listado cuando list_ui es boolean --- lib/active_scaffold/helpers/view_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 5b5cb7bd40..ecc39a3f41 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -462,7 +462,7 @@ def as_main_div_class def column_empty?(column_value) empty = column_value.nil? - empty ||= column_value.blank? + empty ||= column_value != false && column_value.blank? empty ||= [' ', active_scaffold_config.list.empty_field_text].include? column_value if String === column_value return empty end From bbff8ab73435472d00fc1f5dbeadfee8825dea94 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 12 Jun 2013 09:04:05 +0200 Subject: [PATCH 1965/2024] borrar cache list_method al cambiar list_ui (o form_ui si no hay list_ui) --- lib/active_scaffold/data_structures/column.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 2b990fe641..10e8d42562 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -108,12 +108,19 @@ def sort_by(options) # supported options: # * for association columns # * :select - displays a simple <select> or a collection of checkboxes to (dis)associate records - attr_writer :form_ui + def form_ui=(value) + self.list_method = nil if @list_ui.nil? && value != @form_ui + @form_ui = value + end def form_ui @form_ui end - attr_writer :list_ui + def list_ui=(value) + self.list_method = nil if value != @list_ui + @list_ui = value + end + def list_ui @list_ui || @form_ui end From 1f4308442faf94b71fa099677ebfa0927bb4fc91 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Wed, 12 Jun 2013 16:50:00 +0300 Subject: [PATCH 1966/2024] overridable method to change the label on a search field for a column --- lib/active_scaffold/helpers/search_column_helpers.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 75e3bc02d0..e24213d419 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -54,7 +54,7 @@ def active_scaffold_search_options(column) def search_attribute(column, record) column_options = active_scaffold_search_options(column).merge(:object => record) field = active_scaffold_search_for column, column_options - %|<dl><dt>#{label_tag search_label_for(column, column_options), column.label}</dt><dd>#{field}</dd></dl>|.html_safe + %|<dl><dt>#{label_tag search_label_for(column, column_options), search_column_label(column)}</dt><dd>#{field}</dd></dl>|.html_safe end def search_label_for(column, options) @@ -233,6 +233,10 @@ def active_scaffold_search_time(column, options) ## ## Search column override signatures ## + + def search_column_label(column) + column.label + end def override_search_field(column) override_helper column, 'search_column' From 27f51e7fa19e39caf1a75f53638de4a53cd5e833 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 12 Jun 2013 08:40:24 -1000 Subject: [PATCH 1967/2024] subform should work when show_blank_record is false --- .../active_scaffold_overrides/_horizontal_subform.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb index 02b250f376..0b3b514b4c 100644 --- a/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +++ b/app/views/active_scaffold_overrides/_horizontal_subform.html.erb @@ -1,6 +1,6 @@ <table id="<%= sub_form_list_id(:association => column.name, :id => parent_record.try(:id) || generated_id(parent_record) || 99999999999) %>"> <% - header_record_class = show_blank_record.try(:class) || column.association.klass + header_record_class = (show_blank_record && show_blank_record.class) || column.association.klass -%> <%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record, :record_class => header_record_class} %> From d2e9ebf81fc33ca97ee6649247f26b93a68c3372 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 13 Jun 2013 07:34:17 +0200 Subject: [PATCH 1968/2024] add record to search_column_label, it can be useful for using I18n.t --- lib/active_scaffold/helpers/search_column_helpers.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index e24213d419..489ed071e0 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -54,7 +54,7 @@ def active_scaffold_search_options(column) def search_attribute(column, record) column_options = active_scaffold_search_options(column).merge(:object => record) field = active_scaffold_search_for column, column_options - %|<dl><dt>#{label_tag search_label_for(column, column_options), search_column_label(column)}</dt><dd>#{field}</dd></dl>|.html_safe + %|<dl><dt>#{label_tag search_label_for(column, column_options), search_column_label(column, record)}</dt><dd>#{field}</dd></dl>|.html_safe end def search_label_for(column, options) @@ -233,8 +233,8 @@ def active_scaffold_search_time(column, options) ## ## Search column override signatures ## - - def search_column_label(column) + + def search_column_label(column, record) column.label end From 3423163307b12788743399137c42fcc1a841f8b9 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 14 Jun 2013 13:28:48 -1000 Subject: [PATCH 1969/2024] Fix each_record_in_scope when conditions_for_collection needs some includes --- lib/active_scaffold/actions/list.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 2df5d30041..561c6378d9 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -119,6 +119,7 @@ def each_record_in_page def each_record_in_scope do_search if respond_to? :do_search, true + set_includes_for_columns append_to_query(beginning_of_chain, finder_options).all.each {|record| yield record} end From 0168b2ff829e8e254d2c536ece22ac2afb0e1257 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 14 Jun 2013 13:46:33 -1000 Subject: [PATCH 1970/2024] Use Object.getPrototypeOf instead of __proto__, latter doesn't work in IE --- CHANGELOG | 3 +++ app/assets/javascripts/jquery/date_picker_bridge.js.erb | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 6a8ae5e241..181a9075c3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,9 @@ - Support jquery-rails 3 gem and jquery-ui-rails gem - Clean some invalid HTML - Add store_user_settings option to enable storing sort, page and search params into session (enabled by default for backwards compatibility) +- Fix each_record_in_scope when conditions_for_collection needs some includes +- Add method to override label in search fields (field_search) +- Add method to override attributes for column headings on list = 3.3.0 - Unify field overrides and list_ui method signatures diff --git a/app/assets/javascripts/jquery/date_picker_bridge.js.erb b/app/assets/javascripts/jquery/date_picker_bridge.js.erb index 795b12948b..10c6cff734 100644 --- a/app/assets/javascripts/jquery/date_picker_bridge.js.erb +++ b/app/assets/javascripts/jquery/date_picker_bridge.js.erb @@ -1,7 +1,7 @@ <%# encoding: utf-8 %> <%= ActiveScaffold::Bridges[:date_picker].localization %> -$.datepicker.__proto__._attachDatepicker_without_inlineSettings = $.datepicker.__proto__._attachDatepicker; -$.extend($.datepicker.__proto__, { +Object.getPrototypeOf($.datepicker)._attachDatepicker_without_inlineSettings = Object.getPrototypeOf($.datepicker)._attachDatepicker; +$.extend(Object.getPrototypeOf($.datepicker), { _attachDatepicker: function(target, settings) { var inlineSettings = {}, $target = $(target); for (var attrName in this._defaults) { From 5d8c249a9c3d2d3ca80051b6743330752f1e86ec Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 14 Jun 2013 13:58:06 -1000 Subject: [PATCH 1971/2024] ensure getPrototypeOf is defined in old browsers --- app/assets/javascripts/active_scaffold.js.erb | 1 + vendor/assets/javascripts/getprototypeof.js | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 vendor/assets/javascripts/getprototypeof.js diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index a80c356e80..4d23e28905 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -1,5 +1,6 @@ <% case ActiveScaffold.js_framework %> <% when :jquery %> +<% require_asset "getprototypeof" %> <% if Jquery::Rails.const_defined? 'JQUERY_UI_VERSION' %> <% require_asset "jquery-ui" %> <% require_asset "jquery-ui-timepicker-addon" %> diff --git a/vendor/assets/javascripts/getprototypeof.js b/vendor/assets/javascripts/getprototypeof.js new file mode 100644 index 0000000000..5cb930f5b1 --- /dev/null +++ b/vendor/assets/javascripts/getprototypeof.js @@ -0,0 +1,12 @@ +if ( typeof Object.getPrototypeOf !== "function" ) { + if ( typeof "test".__proto__ === "object" ) { + Object.getPrototypeOf = function(object){ + return object.__proto__; + }; + } else { + Object.getPrototypeOf = function(object){ + // May break if the constructor has been tampered with + return object.constructor.prototype; + }; + } +} From b5640c74685ce86b2cef461fa461aa376563196c Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Thu, 20 Jun 2013 15:25:39 +0200 Subject: [PATCH 1972/2024] fix render :super when render is called as render partial, and support :object option. Fixes row action when list_record is overrided --- .../extensions/action_view_rendering.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index fc2000a708..9aa542276c 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -93,7 +93,10 @@ def render_with_active_scaffold(*args, &block) options = args[1] || {} options[:locals] ||= {} - options[:locals] = view_stack.last[:locals].merge!(options[:locals]) if view_stack.last && view_stack.last[:locals] + if view_stack.last + options[:locals] = view_stack.last[:locals].merge!(options[:locals]) if view_stack.last[:locals] + options[:object] ||= view_stack.last[:object] if view_stack.last[:object] + end options[:template] = template # if prefix is active_scaffold_overrides we must try to render with this prefix in following paths if prefix != 'active_scaffold_overrides' @@ -109,10 +112,12 @@ def render_with_active_scaffold(*args, &block) else @_view_paths ||= lookup_context.view_paths.clone last_template = lookup_context.last_template - if args.first.is_a?(Hash) - current_view = {:locals => args.first[:locals]} - view_stack << current_view + if args[0].is_a?(Hash) + current_view = {:locals => args[0][:locals], :object => args[0][:object]} + else # call is render 'partial', locals_hash + current_view = {:locals => args[1]} end + view_stack << current_view if current_view lookup_context.view_paths = @_view_paths # reset view_paths in case a view render :super, and then render :partial result = render_without_active_scaffold(*args, &block) view_stack.pop if current_view.present? From 26e406aae7f922abcc14c34043d99278e5bb7a7b Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Thu, 20 Jun 2013 15:27:21 +0200 Subject: [PATCH 1973/2024] Support security_method and ignore_method in columns link --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- lib/active_scaffold/helpers/view_helpers.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 3867a05903..8036353dde 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -41,7 +41,7 @@ def get_column_method(record, column) # TODO: move empty_field_text and   logic in here? # TODO: we need to distinguish between the automatic links *we* create and the ones that the dev specified. some logic may not apply if the dev specified the link. def render_list_column(text, column, record) - if column.link + if column.link && !skip_action_link?(column.link, record) link = column.link associated = record.send(column.association.name) if column.association render_action_link(link, record, :link => text, :authorized => link.action.nil? || column_link_authorized?(link, column, record, associated)) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index ecc39a3f41..94abf5f168 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -224,8 +224,8 @@ def column_link_authorized?(link, column, record, associated) authorized = associated_for_authorized.authorized_for?(:crud_type => link.crud_type) authorized = authorized and record.authorized_for?(:crud_type => :update, :column => column.name) if link.crud_type == :create authorized - else - record.authorized_for?(:crud_type => link.crud_type) + else + action_link_authorized?(link, record) end end From 941616f4ee08233a9341ee5f84233e884136e479 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Thu, 20 Jun 2013 15:27:54 +0200 Subject: [PATCH 1974/2024] update changelog --- CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 181a9075c3..2f11f0113b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -13,6 +13,8 @@ - Fix each_record_in_scope when conditions_for_collection needs some includes - Add method to override label in search fields (field_search) - Add method to override attributes for column headings on list +- Support security_method and ignore_method in column's link +- render :super should work for every render call (with partial and locals or with only one hash) = 3.3.0 - Unify field overrides and list_ui method signatures From ef8b8ffccadfe8e2a3c6271cc03c7eeb1bca2dcd Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 24 Jun 2013 13:35:46 +0200 Subject: [PATCH 1975/2024] bump to 3.3.1 --- CHANGELOG | 2 +- lib/active_scaffold/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2f11f0113b..d0ca0f22f1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -= 3.3.1 (not released) += 3.3.1 - Set adapter colspan (nested lists and forms) using javascript, fixed issue when active_scaffold_config_list is used - Fix bug saving default values when get method is overrided on model to return default value - Fix close action_link without adapter diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index aaf2a56a41..a3ee8d0719 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 3 - PATCH = 0 + PATCH = 1 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 53fe4873be71b2a9f48d01e597dcf10ec0a3e520 Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Mon, 24 Jun 2013 15:51:38 +0200 Subject: [PATCH 1976/2024] fix subforms inside subforms --- CHANGELOG | 3 +++ lib/active_scaffold/helpers/form_column_helpers.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index d0ca0f22f1..b36503d39b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ += 3.3.2 (not released) +- Fix subforms inside subforms + = 3.3.1 - Set adapter colspan (nested lists and forms) using javascript, fixed issue when active_scaffold_config_list is used - Fix bug saving default values when get method is overrided on model to return default value diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 524c79db17..41e610f952 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -415,7 +415,7 @@ def column_renders_as(column) def column_scope(column, scope = nil, record = nil) Rails.logger.warn "Relying on @record is deprecated, call column_scope with record. Called from #{caller.first.gsub(/(.*:\d+):.*/, '\1')}" if record.nil? # TODO Remove when relying on @record is removed if column.plural_association? - "#{scope}[#{column.name}][#{record.id || generate_temporary_id}]" + "#{scope}[#{column.name}][#{record.id || generate_temporary_id(record)}]" else "#{scope}[#{column.name}]" end From 8e5fd7dcecbf4e4e262efd9dcbb8f8e9c0f02abb Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 24 Jun 2013 05:40:12 -1000 Subject: [PATCH 1977/2024] Fix draggable for jquery-rails 3 gem --- CHANGELOG | 1 + app/assets/javascripts/active_scaffold.js.erb | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index b36503d39b..bc14db3c2a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ = 3.3.2 (not released) - Fix subforms inside subforms +- Fix draggable for jquery-rails 3 gem = 3.3.1 - Set adapter colspan (nested lists and forms) using javascript, fixed issue when active_scaffold_config_list is used diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index 4d23e28905..d145d79e0d 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -7,6 +7,7 @@ <% elsif Jquery.const_defined? 'Ui' %> <% require_asset "jquery.ui.core" %> <% require_asset "jquery.ui.sortable" %> +<% require_asset "jquery.ui.draggable" %> <% require_asset "jquery.ui.datepicker" %> <% require_asset "jquery-ui-timepicker-addon" %> <% end %> From 87c09b63fbb2a7af67b27dd2ec0a67aa60cd7e05 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 24 Jun 2013 05:41:43 -1000 Subject: [PATCH 1978/2024] Fix draggable for jquery-rails 3 gem --- app/assets/javascripts/active_scaffold.js.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index d145d79e0d..8561e8015f 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -8,6 +8,7 @@ <% require_asset "jquery.ui.core" %> <% require_asset "jquery.ui.sortable" %> <% require_asset "jquery.ui.draggable" %> +<% require_asset "jquery.ui.droppable" %> <% require_asset "jquery.ui.datepicker" %> <% require_asset "jquery-ui-timepicker-addon" %> <% end %> From 94369f8978b96c46999a3a2c440c33242f620ad2 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 26 Jun 2013 13:41:26 +0200 Subject: [PATCH 1979/2024] Support to change attributes in list column headings with column_heading_attributes helper --- CHANGELOG | 1 + lib/active_scaffold/helpers/list_column_helpers.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index bc14db3c2a..3616e1e1d2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ = 3.3.2 (not released) - Fix subforms inside subforms - Fix draggable for jquery-rails 3 gem +- Support to change attributes in list column headings with column_heading_attributes helper = 3.3.1 - Set adapter colspan (nested lists and forms) using javascript, fixed issue when active_scaffold_config_list is used diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 8036353dde..9daf0e804c 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -279,8 +279,12 @@ def mark_column_heading content_tag(:span, check_box_tag("#{controller_id}_mark_heading_span_input", '1', all_marked?), tag_options) end - def render_column_heading(column, sorting, sort_direction) + def column_heading_attributes(column, sorting, sort_direction) tag_options = {:id => active_scaffold_column_header_id(column), :class => column_heading_class(column, sorting), :title => strip_tags(column.description)} + end + + def render_column_heading(column, sorting, sort_direction) + tag_options = column_heading_attributes(column, sorting, sort_direction) if column.name == :as_marked tag_options[:data] = { :ie_mode => :inline_checkbox, From ed39354bdbc70830c88b25e0f46946899abf40bd Mon Sep 17 00:00:00 2001 From: Pedro Pablo Guijarro <pedro@programatica.es> Date: Tue, 2 Jul 2013 14:21:08 +0200 Subject: [PATCH 1980/2024] keep url for embedded --- CHANGELOG | 1 + lib/active_scaffold/extensions/action_view_rendering.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3616e1e1d2..c02d4164fd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ - Fix subforms inside subforms - Fix draggable for jquery-rails 3 gem - Support to change attributes in list column headings with column_heading_attributes helper +- Keep url for embedded in data-refresh attr of active-scaffold-component div = 3.3.1 - Set adapter colspan (nested lists and forms) using javascript, fixed issue when active_scaffold_config_list is used diff --git a/lib/active_scaffold/extensions/action_view_rendering.rb b/lib/active_scaffold/extensions/action_view_rendering.rb index 9aa542276c..fc7b2c3c54 100644 --- a/lib/active_scaffold/extensions/action_view_rendering.rb +++ b/lib/active_scaffold/extensions/action_view_rendering.rb @@ -69,8 +69,8 @@ def render_with_active_scaffold(*args, &block) if controller.respond_to?(:render_component_into_view, true) controller.send(:render_component_into_view, url_options) else - content_tag(:div, :id => id, :class => 'active-scaffold-component') do - url = url_for(url_options) + url = url_for(url_options) + content_tag(:div, :id => id, :class => 'active-scaffold-component', :data => {:refresh => url}) do # parse the ActiveRecord model name from the controller path, which # might be a namespaced controller (e.g., 'admin/admins') model = remote_controller.to_s.sub(/.*\//, '').singularize From e413a52876b697f66ff2713ebb109d4db52f3586 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 4 Jul 2013 13:49:18 +0200 Subject: [PATCH 1981/2024] Remove duplicated results when searching with outer_joins in plural associations --- CHANGELOG | 1 + lib/active_scaffold/finder.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index c02d4164fd..67655f146b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ - Fix draggable for jquery-rails 3 gem - Support to change attributes in list column headings with column_heading_attributes helper - Keep url for embedded in data-refresh attr of active-scaffold-component div +- Remove duplicated results when searching with outer_joins in plural associations = 3.3.1 - Set adapter colspan (nested lists and forms) using javascript, fixed issue when active_scaffold_config_list is used diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index f30475a2d3..0cfe2a7528 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -344,7 +344,7 @@ def count_items(find_options = {}, count_includes = nil) # NOTE: we must use :include in the count query, because some conditions may reference other tables count_query = append_to_query(beginning_of_chain, options) - count = count_query.count + count = count_query.count(:distinct => true) # Converts count to an integer if ActiveRecord returned an OrderedHash # that happens when find_options contains a :group key @@ -367,6 +367,7 @@ def find_page(options = {}) end klass = beginning_of_chain + klass = klass.uniq if find_options[:outer_joins].present? # we build the paginator differently for method- and sql-based sorting if options[:sorting] and options[:sorting].sorts_by_method? pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| From 7ceb9ff6f93b9e76f0320576e730b7bae194b73e Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 4 Jul 2013 14:05:15 +0200 Subject: [PATCH 1982/2024] bump to 3.3.2 --- CHANGELOG | 2 +- lib/active_scaffold/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 67655f146b..8039bb1aa2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -= 3.3.2 (not released) += 3.3.2 - Fix subforms inside subforms - Fix draggable for jquery-rails 3 gem - Support to change attributes in list column headings with column_heading_attributes helper diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index a3ee8d0719..183f6fdc47 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 3 - PATCH = 1 + PATCH = 2 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From 1f7e136f5d96ecc26d48dd1a5bcc65c444ddf1ab Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 5 Jul 2013 13:45:23 +0200 Subject: [PATCH 1983/2024] Allow to override select options in active_scaffold_search_select --- CHANGELOG | 3 +++ lib/active_scaffold/helpers/search_column_helpers.rb | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8039bb1aa2..53670c9532 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ += 3.3.3 (not released) +- Allow to override select options in active_scaffold_search_select + = 3.3.2 - Fix subforms inside subforms - Fix draggable for jquery-rails 3 gem diff --git a/lib/active_scaffold/helpers/search_column_helpers.rb b/lib/active_scaffold/helpers/search_column_helpers.rb index 489ed071e0..6edf4f3758 100644 --- a/lib/active_scaffold/helpers/search_column_helpers.rb +++ b/lib/active_scaffold/helpers/search_column_helpers.rb @@ -82,7 +82,7 @@ def active_scaffold_search_multi_select(column, options) active_scaffold_checkbox_list(column, select_options, associated, options) end - def active_scaffold_search_select(column, html_options) + def active_scaffold_search_select(column, html_options, options = {}) associated = html_options.delete :value if column.association associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil? @@ -95,7 +95,7 @@ def active_scaffold_search_select(column, html_options) end end - options = { :selected => associated }.merge! column.options + options = options.merge(:selected => associated).merge column.options html_options.merge! column.options[:html_options] || {} if html_options[:multiple] html_options[:name] += '[]' From 5fbfc6df60a261783bbcb108a6ab4c6c596de6db Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 8 Jul 2013 10:41:36 +0200 Subject: [PATCH 1984/2024] add effects from jquery ui --- CHANGELOG | 1 + app/assets/javascripts/active_scaffold.js.erb | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 53670c9532..b2781453ee 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ = 3.3.3 (not released) - Allow to override select options in active_scaffold_search_select +- Load effects from jQuery UI when using jquery-rails 3 gem = 3.3.2 - Fix subforms inside subforms diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index 8561e8015f..9ca4e6260c 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -6,6 +6,7 @@ <% require_asset "jquery-ui-timepicker-addon" %> <% elsif Jquery.const_defined? 'Ui' %> <% require_asset "jquery.ui.core" %> +<% require_asset "jquery.ui.effects" %> <% require_asset "jquery.ui.sortable" %> <% require_asset "jquery.ui.draggable" %> <% require_asset "jquery.ui.droppable" %> From 36840809566d07e364ab37dc47354abd5642b31e Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 8 Jul 2013 10:44:36 +0200 Subject: [PATCH 1985/2024] fix jquery.ui.effect --- app/assets/javascripts/active_scaffold.js.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index 9ca4e6260c..d5936310a7 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -6,7 +6,7 @@ <% require_asset "jquery-ui-timepicker-addon" %> <% elsif Jquery.const_defined? 'Ui' %> <% require_asset "jquery.ui.core" %> -<% require_asset "jquery.ui.effects" %> +<% require_asset "jquery.ui.effect" %> <% require_asset "jquery.ui.sortable" %> <% require_asset "jquery.ui.draggable" %> <% require_asset "jquery.ui.droppable" %> From 5b68a1e07a378c274abd83891ce1430770062c41 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 9 Jul 2013 08:43:07 +0200 Subject: [PATCH 1986/2024] remove frontends from gemspec --- active_scaffold.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active_scaffold.gemspec b/active_scaffold.gemspec index 7e05c654cc..631010ce5a 100644 --- a/active_scaffold.gemspec +++ b/active_scaffold.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |s| s.summary = %q{Rails 3.1 Version of activescaffold supporting prototype and jquery} s.description = %q{Save time and headaches, and create a more easily maintainable set of pages, with ActiveScaffold. ActiveScaffold handles all your CRUD (create, read, update, delete) user interface needs, leaving you more time to focus on more challenging (and interesting!) problems.} s.require_paths = ["lib"] - s.files = `git ls-files {app,config,frontends,lib,public,shoulda_macros,vendor}`.split("\n") + %w[MIT-LICENSE CHANGELOG README.md] + s.files = `git ls-files {app,config,lib,public,shoulda_macros,vendor}`.split("\n") + %w[MIT-LICENSE CHANGELOG README.md] s.extra_rdoc_files = [ "README.md" ] From 01ba0d47bb3d933d5d01c212d35f83f548d03416 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 9 Jul 2013 12:05:44 +0200 Subject: [PATCH 1987/2024] fix default count on tableless models --- lib/active_scaffold/tableless.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/tableless.rb b/lib/active_scaffold/tableless.rb index 57e84b9fbe..55cc0aa177 100644 --- a/lib/active_scaffold/tableless.rb +++ b/lib/active_scaffold/tableless.rb @@ -69,10 +69,10 @@ def self.find_one(id, relation) end def self.execute_simple_calculation(relation, operation, column_name, distinct) - if operation == 'count' && column_name == :all && !distinct + if operation == 'count' && [:id, :all].include?(column_name) find_all(relation).size else - raise "self.execute_simple_calculation must be implemented in a Tableless model to support #{operation} #{column_name} #{' distinct' if distinct} columns" + raise "self.execute_simple_calculation must be implemented in a Tableless model to support #{operation} #{column_name}#{' distinct' if distinct} columns" end end From 2ebaf5f032d6e29d47dcc2625b805e1e79837467 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 9 Jul 2013 12:10:35 +0200 Subject: [PATCH 1988/2024] fix default count on tableless models with non :id primary key --- lib/active_scaffold/tableless.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/tableless.rb b/lib/active_scaffold/tableless.rb index 55cc0aa177..c664f4bca0 100644 --- a/lib/active_scaffold/tableless.rb +++ b/lib/active_scaffold/tableless.rb @@ -69,7 +69,7 @@ def self.find_one(id, relation) end def self.execute_simple_calculation(relation, operation, column_name, distinct) - if operation == 'count' && [:id, :all].include?(column_name) + if operation == 'count' && [relation.klass.primary_key, :all].include?(column_name) find_all(relation).size else raise "self.execute_simple_calculation must be implemented in a Tableless model to support #{operation} #{column_name}#{' distinct' if distinct} columns" From b1b01bc0b16d01bda70e3db72d30336e07b1c12d Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 9 Jul 2013 07:52:59 -1000 Subject: [PATCH 1989/2024] prepare mock_app for testing --- Gemfile | 18 ++- Gemfile.lock | 87 ++++++++++++- .../active_scaffold_dependent_protect_test.rb | 34 ------ test/mock_app/Rakefile | 7 ++ test/mock_app/config.ru | 4 + test/mock_app/config/application.rb | 11 ++ test/mock_app/config/boot.rb | 115 +----------------- test/mock_app/config/database.yml | 4 +- test/mock_app/config/environment.rb | 46 +------ .../config/environments/development.rb | 34 ++++-- .../config/environments/production.rb | 61 +++++++--- test/mock_app/config/environments/test.rb | 49 ++++---- .../initializers/backtrace_silencers.rb | 4 +- .../config/initializers/inflections.rb | 2 +- .../config/initializers/new_rails_defaults.rb | 19 --- .../config/initializers/secret_token.rb | 7 ++ .../config/initializers/session_store.rb | 11 +- .../config/initializers/wrap_parameters.rb | 14 +++ test/mock_app/config/routes.rb | 44 +------ test/test_helper.rb | 16 +-- 20 files changed, 254 insertions(+), 333 deletions(-) delete mode 100644 test/bridges/active_scaffold_dependent_protect_test.rb create mode 100644 test/mock_app/Rakefile create mode 100644 test/mock_app/config.ru create mode 100644 test/mock_app/config/application.rb delete mode 100644 test/mock_app/config/initializers/new_rails_defaults.rb create mode 100644 test/mock_app/config/initializers/secret_token.rb create mode 100644 test/mock_app/config/initializers/wrap_parameters.rb diff --git a/Gemfile b/Gemfile index 1a4943a576..1c08285b89 100644 --- a/Gemfile +++ b/Gemfile @@ -5,12 +5,24 @@ source "http://rubygems.org" # Add dependencies to develop your gem here. # Include everything needed to run rake, tests, features, etc. -group :development do +group :development, :test do gem "rake" gem "rdoc" - gem "shoulda", ">= 0" gem "bundler", ">= 1.0.0" - gem "rcov", ">= 0" gem "localeapp" gem "rack" end + +group :test do + gem "shoulda", ">= 0" + gem "rcov", ">= 0" + gem "mocha" + gem "rails", "~> 3.2.6" + platforms :jruby do + gem 'activerecord-jdbcsqlite3-adapter' + end + + platforms :ruby do + gem "sqlite3" + end +end diff --git a/Gemfile.lock b/Gemfile.lock index 02d03251ff..3646d0e6df 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,34 +1,111 @@ GEM remote: http://rubygems.org/ specs: + actionmailer (3.2.13) + actionpack (= 3.2.13) + mail (~> 2.5.3) + actionpack (3.2.13) + activemodel (= 3.2.13) + activesupport (= 3.2.13) + builder (~> 3.0.0) + erubis (~> 2.7.0) + journey (~> 1.0.4) + rack (~> 1.4.5) + rack-cache (~> 1.2) + rack-test (~> 0.6.1) + sprockets (~> 2.2.1) + activemodel (3.2.13) + activesupport (= 3.2.13) + builder (~> 3.0.0) + activerecord (3.2.13) + activemodel (= 3.2.13) + activesupport (= 3.2.13) + arel (~> 3.0.2) + tzinfo (~> 0.3.29) + activeresource (3.2.13) + activemodel (= 3.2.13) + activesupport (= 3.2.13) + activesupport (3.2.13) + i18n (= 0.6.1) + multi_json (~> 1.0) + arel (3.0.2) + builder (3.0.4) + erubis (2.7.0) gli (2.5.6) - i18n (0.6.4) - json (1.6.3) + hike (1.2.3) + i18n (0.6.1) + journey (1.0.4) + json (1.8.0) localeapp (0.6.9) gli i18n json rest-client ya2yaml + mail (2.5.4) + mime-types (~> 1.16) + treetop (~> 1.4.8) + metaclass (0.0.1) mime-types (1.23) - rack (1.5.2) - rake (10.0.4) + mocha (0.13.3) + metaclass (~> 0.0.1) + multi_json (1.7.7) + polyglot (0.3.3) + rack (1.4.5) + rack-cache (1.2) + rack (>= 0.4) + rack-ssl (1.3.3) + rack + rack-test (0.6.2) + rack (>= 1.0) + rails (3.2.13) + actionmailer (= 3.2.13) + actionpack (= 3.2.13) + activerecord (= 3.2.13) + activeresource (= 3.2.13) + activesupport (= 3.2.13) + bundler (~> 1.0) + railties (= 3.2.13) + railties (3.2.13) + actionpack (= 3.2.13) + activesupport (= 3.2.13) + rack-ssl (~> 1.3.2) + rake (>= 0.8.7) + rdoc (~> 3.4) + thor (>= 0.14.6, < 2.0) + rake (10.1.0) rcov (0.9.9) - rdoc (3.11) + rdoc (3.12.2) json (~> 1.4) rest-client (1.6.7) mime-types (>= 1.16) shoulda (2.11.3) + sprockets (2.2.2) + hike (~> 1.2) + multi_json (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sqlite3 (1.3.7) + thor (0.18.1) + tilt (1.4.1) + treetop (1.4.14) + polyglot + polyglot (>= 0.3.1) + tzinfo (0.3.37) ya2yaml (0.31) PLATFORMS ruby DEPENDENCIES + activerecord-jdbcsqlite3-adapter bundler (>= 1.0.0) localeapp + mocha rack + rails (~> 3.2.6) rake rcov rdoc shoulda + sqlite3 diff --git a/test/bridges/active_scaffold_dependent_protect_test.rb b/test/bridges/active_scaffold_dependent_protect_test.rb deleted file mode 100644 index d5d1c99cf8..0000000000 --- a/test/bridges/active_scaffold_dependent_protect_test.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'test/unit' -require File.join(File.dirname(__FILE__), 'company') - -class ActiveScaffoldDependentProtectTest < Test::Unit::TestCase - def test_destroy_protected_with_companies - protected_firm = Company.new(:with_companies) - assert !protected_firm.send(:authorized_for_delete?) - end - - def test_destroy_protected_with_company - protected_firm = Company.new(:with_company) - assert !protected_firm.send(:authorized_for_delete?) - end - - def test_destroy_protected_with_main_company - protected_firm = Company.new(:with_main_company) - assert !protected_firm.send(:authorized_for_delete?) - end - - def test_destroy_protected_without_companies - protected_firm_without_companies = Company.new(:without_companies) - assert protected_firm_without_companies.send(:authorized_for_delete?) - end - - def test_destroy_protected_without_company - protected_firm_without_company = Company.new(:without_company) - assert protected_firm_without_company.send(:authorized_for_delete?) - end - - def test_destroy_protected_without_main_company - protected_firm_without_main_company = Company.new(:without_main_company) - assert protected_firm_without_main_company.send(:authorized_for_delete?) - end -end diff --git a/test/mock_app/Rakefile b/test/mock_app/Rakefile new file mode 100644 index 0000000000..96709167f9 --- /dev/null +++ b/test/mock_app/Rakefile @@ -0,0 +1,7 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) +require 'rake' + +RailsApp::Application.load_tasks diff --git a/test/mock_app/config.ru b/test/mock_app/config.ru new file mode 100644 index 0000000000..86a587d07d --- /dev/null +++ b/test/mock_app/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run TestApp::Application diff --git a/test/mock_app/config/application.rb b/test/mock_app/config/application.rb new file mode 100644 index 0000000000..2a193e9693 --- /dev/null +++ b/test/mock_app/config/application.rb @@ -0,0 +1,11 @@ +require File.expand_path('../boot', __FILE__) + +require "rails/all" +require "rails/test_unit/railtie" + +module RailsApp + class Application < Rails::Application + config.filter_parameters << :password + config.action_mailer.default_url_options = { :host => "localhost:3000" } + end +end diff --git a/test/mock_app/config/boot.rb b/test/mock_app/config/boot.rb index 0ad0f787f8..562b08f1db 100644 --- a/test/mock_app/config/boot.rb +++ b/test/mock_app/config/boot.rb @@ -1,110 +1,7 @@ -# Don't change this file! -# Configure your app in config/environment.rb and config/environments/*.rb - -RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) - -module Rails - class << self - def boot! - unless booted? - preinitialize - pick_boot.run - end - end - - def booted? - defined? Rails::Initializer - end - - def pick_boot - (vendor_rails? ? VendorBoot : GemBoot).new - end - - def vendor_rails? - File.exist?("#{RAILS_ROOT}/vendor/rails") - end - - def preinitialize - load(preinitializer_path) if File.exist?(preinitializer_path) - end - - def preinitializer_path - "#{RAILS_ROOT}/config/preinitializer.rb" - end - end - - class Boot - def run - load_initializer - Rails::Initializer.run(:set_load_path) - end - end - - class VendorBoot < Boot - def load_initializer - require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer" - Rails::Initializer.run(:install_gem_spec_stubs) - Rails::GemDependency.add_frozen_gem_path - end - end - - class GemBoot < Boot - def load_initializer - self.class.load_rubygems - load_rails_gem - require 'initializer' - end - - def load_rails_gem - if version = self.class.gem_version - gem 'rails', version - else - gem 'rails' - end - rescue Gem::LoadError => load_error - $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.) - exit 1 - end - - class << self - def rubygems_version - Gem::RubyGemsVersion rescue nil - end - - def gem_version - if defined? RAILS_GEM_VERSION - RAILS_GEM_VERSION - elsif ENV.include?('RAILS_GEM_VERSION') - ENV['RAILS_GEM_VERSION'] - else - parse_gem_version(read_environment_rb) - end - end - - def load_rubygems - require 'rubygems' - min_version = '1.3.1' - unless rubygems_version >= min_version - $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.) - exit 1 - end - - rescue LoadError - $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org) - exit 1 - end - - def parse_gem_version(text) - $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/ - end - - private - def read_environment_rb - File.read("#{RAILS_ROOT}/config/environment.rb") - end - end - end +begin + require File.expand_path("../../../../.bundle/environment", __FILE__) +rescue LoadError + require 'rubygems' + require 'bundler' + Bundler.setup :default, :test, :rails end - -# All that for this: -Rails.boot! diff --git a/test/mock_app/config/database.yml b/test/mock_app/config/database.yml index 6d6e3dae74..d9a169e1cc 100644 --- a/test/mock_app/config/database.yml +++ b/test/mock_app/config/database.yml @@ -2,7 +2,7 @@ # gem install sqlite3-ruby (not necessary on OS X Leopard) development: adapter: sqlite3 - database: db/development.sqlite3 + database: ":memory:" pool: 5 timeout: 5000 @@ -11,6 +11,6 @@ development: # Do not set this db to the same as development or production. test: adapter: sqlite3 - database: db/test.sqlite3 + database: ":memory:" pool: 5 timeout: 5000 diff --git a/test/mock_app/config/environment.rb b/test/mock_app/config/environment.rb index 8602ac9f6d..cb86aabf1b 100644 --- a/test/mock_app/config/environment.rb +++ b/test/mock_app/config/environment.rb @@ -1,43 +1,5 @@ -# Be sure to restart your server when you modify this file +# Load the rails application +require File.expand_path('../application', __FILE__) -# Specifies gem version of Rails to use when vendor/rails is not present -#RAILS_GEM_VERSION = '2.3.3' unless defined? RAILS_GEM_VERSION - -# Bootstrap the Rails environment, frameworks, and default configuration -require File.join(File.dirname(__FILE__), 'boot') - -Rails::Initializer.run do |config| - # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. - - # Add additional load paths for your own custom dirs - # config.load_paths += %W( #{RAILS_ROOT}/extras ) - - # Specify gems that this application depends on and have them installed with rake gems:install - # config.gem "bj" - # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" - # config.gem "sqlite3-ruby", :lib => "sqlite3" - # config.gem "aws-s3", :lib => "aws/s3" - - # Only load the plugins named here, in the order given (default is alphabetical). - # :all can be used as a placeholder for all plugins not explicitly named - # config.plugins = [ :exception_notification, :ssl_requirement, :all ] - config.plugin_paths += %W(#{RAILS_ROOT}/../../..) - config.plugins = [:active_scaffold] - - # Skip frameworks you're not going to use. To use Rails without a database, - # you must remove the Active Record framework. - # config.frameworks -= [ :active_record, :active_resource, :action_mailer ] - - # Activate observers that should always be running - # config.active_record.observers = :cacher, :garbage_collector, :forum_observer - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. - config.time_zone = 'UTC' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] - # config.i18n.default_locale = :de -end +# Initialize the rails application +RailsApp::Application.initialize! diff --git a/test/mock_app/config/environments/development.rb b/test/mock_app/config/environments/development.rb index 85c9a6080e..3ee72fd1de 100644 --- a/test/mock_app/config/environments/development.rb +++ b/test/mock_app/config/environments/development.rb @@ -1,17 +1,25 @@ -# Settings specified here will take precedence over those in config/environment.rb +RailsApp::Application.configure do + # Settings specified here will take precedence over those in config/environment.rb -# In the development environment your application's code is reloaded on -# every request. This slows down response time but is perfect for development -# since you don't have to restart the webserver when you make code changes. -config.cache_classes = false + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the webserver when you make code changes. + config.cache_classes = false -# Log error messages when you accidentally call methods on nil. -config.whiny_nils = true + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true -# Show full error reports and disable caching -config.action_controller.consider_all_requests_local = true -config.action_view.debug_rjs = true -config.action_controller.perform_caching = false + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger + config.active_support.deprecation = :log + + # Only use best-standards-support built into browsers + config.action_dispatch.best_standards_support = :builtin +end -# Don't care if the mailer can't send -config.action_mailer.raise_delivery_errors = false \ No newline at end of file diff --git a/test/mock_app/config/environments/production.rb b/test/mock_app/config/environments/production.rb index 27119d2d18..9548ff666e 100644 --- a/test/mock_app/config/environments/production.rb +++ b/test/mock_app/config/environments/production.rb @@ -1,28 +1,49 @@ -# Settings specified here will take precedence over those in config/environment.rb +RailsApp::Application.configure do + # Settings specified here will take precedence over those in config/environment.rb -# The production environment is meant for finished, "live" apps. -# Code is not reloaded between requests -config.cache_classes = true + # The production environment is meant for finished, "live" apps. + # Code is not reloaded between requests + config.cache_classes = true -# Full error reports are disabled and caching is turned on -config.action_controller.consider_all_requests_local = false -config.action_controller.perform_caching = true -config.action_view.cache_template_loading = true + # Full error reports are disabled and caching is turned on + config.consider_all_requests_local = false + config.action_controller.perform_caching = true -# See everything in the log (default is :info) -# config.log_level = :debug + # Specifies the header that your server uses for sending files + config.action_dispatch.x_sendfile_header = "X-Sendfile" -# Use a different logger for distributed setups -# config.logger = SyslogLogger.new + # For nginx: + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' -# Use a different cache store in production -# config.cache_store = :mem_cache_store + # If you have no front-end server that supports something like X-Sendfile, + # just comment this out and Rails will serve the files -# Enable serving of images, stylesheets, and javascripts from an asset server -# config.action_controller.asset_host = "http://assets.example.com" + # See everything in the log (default is :info) + # config.log_level = :debug -# Disable delivery errors, bad email addresses will be ignored -# config.action_mailer.raise_delivery_errors = false + # Use a different logger for distributed setups + # config.logger = SyslogLogger.new -# Enable threaded mode -# config.threadsafe! \ No newline at end of file + # Use a different cache store in production + # config.cache_store = :mem_cache_store + + # Disable Rails's static asset server + # In production, Apache or nginx will already do this + config.serve_static_assets = false + + # Enable serving of images, stylesheets, and javascripts from an asset server + # config.action_controller.asset_host = "http://assets.example.com" + + # Disable delivery errors, bad email addresses will be ignored + # config.action_mailer.raise_delivery_errors = false + + # Enable threaded mode + # config.threadsafe! + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found) + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners + config.active_support.deprecation = :notify +end diff --git a/test/mock_app/config/environments/test.rb b/test/mock_app/config/environments/test.rb index d6f80a4080..3f2687a07f 100644 --- a/test/mock_app/config/environments/test.rb +++ b/test/mock_app/config/environments/test.rb @@ -1,28 +1,33 @@ -# Settings specified here will take precedence over those in config/environment.rb +RailsApp::Application.configure do + # Settings specified here will take precedence over those in config/environment.rb -# The test environment is used exclusively to run your application's -# test suite. You never need to work with it otherwise. Remember that -# your test database is "scratch space" for the test suite and is wiped -# and recreated between test runs. Don't rely on the data there! -config.cache_classes = true + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + config.eager_load = false -# Log error messages when you accidentally call methods on nil. -config.whiny_nils = true + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false -# Show full error reports and disable caching -config.action_controller.consider_all_requests_local = true -config.action_controller.perform_caching = false -config.action_view.cache_template_loading = true + # Raise exceptions instead of rendering exception templates + config.action_dispatch.show_exceptions = false -# Disable request forgery protection in test environment -config.action_controller.allow_forgery_protection = false + # Disable request forgery protection in test environment + config.action_controller.allow_forgery_protection = false -# Tell Action Mailer not to deliver emails to the real world. -# The :test delivery method accumulates sent emails in the -# ActionMailer::Base.deliveries array. -config.action_mailer.delivery_method = :test + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test -# Use SQL instead of Active Record's schema dumper when creating the test database. -# This is necessary if your schema can't be completely dumped by the schema dumper, -# like if you have constraints or database-specific column types -# config.active_record.schema_format = :sql \ No newline at end of file + # Use SQL instead of Active Record's schema dumper when creating the test database. + # This is necessary if your schema can't be completely dumped by the schema dumper, + # like if you have constraints or database-specific column types + # config.active_record.schema_format = :sql + + # Print deprecation notices to the stderr + config.active_support.deprecation = :stderr +end diff --git a/test/mock_app/config/initializers/backtrace_silencers.rb b/test/mock_app/config/initializers/backtrace_silencers.rb index c2169ed01c..56ddc8da86 100644 --- a/test/mock_app/config/initializers/backtrace_silencers.rb +++ b/test/mock_app/config/initializers/backtrace_silencers.rb @@ -3,5 +3,5 @@ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } -# You can also remove all the silencers if you're trying do debug a problem that might steem from framework code. -# Rails.backtrace_cleaner.remove_silencers! \ No newline at end of file +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +Rails.backtrace_cleaner.remove_silencers! diff --git a/test/mock_app/config/initializers/inflections.rb b/test/mock_app/config/initializers/inflections.rb index d531b8bb82..9e8b0131f8 100644 --- a/test/mock_app/config/initializers/inflections.rb +++ b/test/mock_app/config/initializers/inflections.rb @@ -1,6 +1,6 @@ # Be sure to restart your server when you modify this file. -# Add new inflection rules using the following format +# Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' diff --git a/test/mock_app/config/initializers/new_rails_defaults.rb b/test/mock_app/config/initializers/new_rails_defaults.rb deleted file mode 100644 index 8ec3186c84..0000000000 --- a/test/mock_app/config/initializers/new_rails_defaults.rb +++ /dev/null @@ -1,19 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# These settings change the behavior of Rails 2 apps and will be defaults -# for Rails 3. You can remove this initializer when Rails 3 is released. - -if defined?(ActiveRecord) - # Include Active Record class name as root for JSON serialized output. - ActiveRecord::Base.include_root_in_json = true - - # Store the full class name (including module namespace) in STI type column. - ActiveRecord::Base.store_full_sti_class = true -end - -# Use ISO 8601 format for JSON serialized times and dates. -ActiveSupport.use_standard_json_time_format = true - -# Don't escape HTML entities in JSON, leave that for the #json_escape helper. -# if you're including raw json in an HTML page. -ActiveSupport.escape_html_entities_in_json = false \ No newline at end of file diff --git a/test/mock_app/config/initializers/secret_token.rb b/test/mock_app/config/initializers/secret_token.rb new file mode 100644 index 0000000000..3e3abfb653 --- /dev/null +++ b/test/mock_app/config/initializers/secret_token.rb @@ -0,0 +1,7 @@ +# 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. +RailsApp::Application.config.secret_token = 'e997edf9d7eba5cf89a76a046fa53f5d66261d22cfcf29e3f538c75ad2d175b106bd5d099f44f6ce34ad3b3162d71cfaa37d2d4f4b38645288331427b4c2a607' diff --git a/test/mock_app/config/initializers/session_store.rb b/test/mock_app/config/initializers/session_store.rb index 1428988764..26b78c0771 100644 --- a/test/mock_app/config/initializers/session_store.rb +++ b/test/mock_app/config/initializers/session_store.rb @@ -1,15 +1,8 @@ # Be sure to restart your server when you modify this file. -# Your secret key for verifying cookie session data integrity. -# If you change this key, all old sessions 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. -ActionController::Base.session = { - :key => '_mock_app_session', - :secret => 'ed0122432f6132fc5c99c928dc133a0863df7f24b0f2d53ce9dc2e9885a9b1f944d8ac6390333e2f1a72f902554bdaca75024fb23eb11a4548b0af4731439be2' -} +RailsApp::Application.config.session_store :cookie_store, :key => '_test_app_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rake db:sessions:create") -# ActionController::Base.session_store = :active_record_store +# RailsApp::Application.config.session_store :active_record_store diff --git a/test/mock_app/config/initializers/wrap_parameters.rb b/test/mock_app/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000000..c948e06341 --- /dev/null +++ b/test/mock_app/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters(:format => [:json]) +end + +# Disable root element in JSON by default. +ActiveSupport.on_load(:active_record) do + self.include_root_in_json = false +end diff --git a/test/mock_app/config/routes.rb b/test/mock_app/config/routes.rb index ea14ce1bfc..c9440918ae 100644 --- a/test/mock_app/config/routes.rb +++ b/test/mock_app/config/routes.rb @@ -1,43 +1,3 @@ -ActionController::Routing::Routes.draw do |map| - # The priority is based upon order of creation: first created -> highest priority. - - # Sample of regular route: - # map.connect 'products/:id', :controller => 'catalog', :action => 'view' - # Keep in mind you can assign values other than :controller and :action - - # Sample of named route: - # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' - # This route can be invoked with purchase_url(:id => product.id) - - # Sample resource route (maps HTTP verbs to controller actions automatically): - # map.resources :products - - # Sample resource route with options: - # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get } - - # Sample resource route with sub-resources: - # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller - - # Sample resource route with more complex sub-resources - # map.resources :products do |products| - # products.resources :comments - # products.resources :sales, :collection => { :recent => :get } - # end - - # Sample resource route within a namespace: - # map.namespace :admin do |admin| - # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb) - # admin.resources :products - # end - - # You can have the root of your site routed with map.root -- just remember to delete public/index.html. - # map.root :controller => "welcome" - - # See how all your routes lay out with "rake routes" - - # Install the default routes as the lowest priority. - # Note: These default routes make all actions in every controller accessible via GET requests. You should - # consider removing or commenting them out if you're using named routes and resources. - map.connect ':controller/:action/:id' - map.connect ':controller/:action/:id.:format' +RailsApp::Application.routes.draw do + match ':controller(/:action(/:id))' end diff --git a/test/test_helper.rb b/test/test_helper.rb index 1770d073cf..c246d539a8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,18 +1,14 @@ -require 'test/unit' -require 'rubygems' -require 'action_controller' -require 'action_view/test_case' -require 'mocha' +ENV['RAILS_ENV'] = 'test' +$:.unshift File.dirname(__FILE__) +require "mock_app/config/environment" +require 'rails/test_help' + +require 'mocha/setup' begin require 'redgreen' rescue LoadError end -ENV['RAILS_ENV'] = 'test' -ENV['RAILS_ROOT'] ||= File.join(File.dirname(__FILE__), 'mock_app') - -require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb')) - def load_schema stdout = $stdout $stdout = StringIO.new # suppress output while building the schema From 7b7b6372ed564e478d8d9451754618080e103aa3 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 9 Jul 2013 20:55:38 -1000 Subject: [PATCH 1990/2024] fix searching in nested scaffolds --- lib/active_scaffold/finder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 0cfe2a7528..3fd2473256 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -367,7 +367,7 @@ def find_page(options = {}) end klass = beginning_of_chain - klass = klass.uniq if find_options[:outer_joins].present? + klass = klass.where(nil).uniq if find_options[:outer_joins].present? # HACK: call where(nil) because calling uniq on associations (nested scaffolds) send SQL to DB # we build the paginator differently for method- and sql-based sorting if options[:sorting] and options[:sorting].sorts_by_method? pager = ::Paginator.new(count, options[:per_page]) do |offset, per_page| From 0208085050999401bc9e4b188d8fbdc02dba0c94 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 9 Jul 2013 20:56:15 -1000 Subject: [PATCH 1991/2024] fix searching in nested scaffolds --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index b2781453ee..c37ddc1e06 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ = 3.3.3 (not released) - Allow to override select options in active_scaffold_search_select - Load effects from jQuery UI when using jquery-rails 3 gem +- Fix searching on nested scaffolds (broken on 3.3.2) = 3.3.2 - Fix subforms inside subforms From 76f7d2a8545f2dc44339598443838e9046d0fc8e Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 12 Jul 2013 13:43:00 +0200 Subject: [PATCH 1992/2024] Revert "it's possible to sort using a function, in that case ActiveScaffold can't get the column" This reverts commit d939b1d40cff5cb82f28ec84433ccd2d61506edc. --- lib/active_scaffold/data_structures/sorting.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/sorting.rb b/lib/active_scaffold/data_structures/sorting.rb index 7358635de9..e71d2e41fe 100644 --- a/lib/active_scaffold/data_structures/sorting.rb +++ b/lib/active_scaffold/data_structures/sorting.rb @@ -35,8 +35,9 @@ def add(column_name, direction = nil) direction ||= 'ASC' direction = direction.to_s.upcase column = get_column(column_name) + raise ArgumentError, "Could not find column #{column_name}" if column.nil? raise ArgumentError, "Sorting direction unknown" unless [:ASC, :DESC].include? direction.to_sym - @clauses << [column, direction.untaint] if column and column.sortable? + @clauses << [column, direction.untaint] if column.sortable? raise ArgumentError, "Can't mix :method- and :sql-based sorting" if mixed_sorting? end From fb38fab6f2f4f338c23867e4fc5b1a2a9fae25da Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 12 Jul 2013 14:53:05 +0200 Subject: [PATCH 1993/2024] fix some tests --- Rakefile | 2 +- lib/active_scaffold/attribute_params.rb | 4 +- lib/active_scaffold/config/core.rb | 2 - lib/active_scaffold/constraints.rb | 4 +- .../data_structures/action_columns.rb | 140 +++++++++--------- lib/active_scaffold/data_structures/column.rb | 8 +- lib/active_scaffold/finder.rb | 14 +- test/data_structures/action_columns_test.rb | 6 +- test/data_structures/action_link_test.rb | 2 +- test/data_structures/action_links_test.rb | 6 +- test/data_structures/actions_test.rb | 4 +- .../association_column_test.rb | 11 +- test/data_structures/column_test.rb | 8 +- test/data_structures/columns_test.rb | 5 +- test/data_structures/error_message_test.rb | 4 +- test/data_structures/set_test.rb | 5 +- test/data_structures/sorting_test.rb | 3 +- test/data_structures/standard_column_test.rb | 5 +- test/data_structures/virtual_column_test.rb | 2 +- test/extensions/active_record_test.rb | 5 +- test/extensions/array_test.rb | 4 +- test/misc/active_record_permissions_test.rb | 2 +- test/misc/attribute_params_test.rb | 7 +- test/misc/configurable_test.rb | 4 +- test/misc/constraints_test.rb | 58 ++++---- test/misc/finder_test.rb | 3 +- test/misc/lang_test.rb | 2 +- test/model_stub.rb | 4 +- test/test_helper.rb | 1 + 29 files changed, 152 insertions(+), 173 deletions(-) diff --git a/Rakefile b/Rakefile index 7b65523a85..4f4b8f34dc 100644 --- a/Rakefile +++ b/Rakefile @@ -14,7 +14,7 @@ require 'find' desc 'Test ActiveScaffold.' Rake::TestTask.new(:test) do |t| - t.libs << 'lib' + t.libs << 'lib' << 'test' t.pattern = 'test/**/*_test.rb' t.verbose = true end diff --git a/lib/active_scaffold/attribute_params.rb b/lib/active_scaffold/attribute_params.rb index c63f766cb2..526420057d 100644 --- a/lib/active_scaffold/attribute_params.rb +++ b/lib/active_scaffold/attribute_params.rb @@ -129,8 +129,8 @@ def column_value_from_param_simple_value(parent_record, column, value) end elsif column.plural_association? column_plural_assocation_value_from_value(column, Array(value)) - elsif column.number? && [:i18n_number, :currency].include?(column.options[:format]) && column.form_ui != :number - self.class.i18n_number_to_native_format(value) + elsif column.number? && column.options[:format] && column.form_ui != :number + column.number_to_native(value) else # convert empty strings into nil. this works better with 'null => true' columns (and validations), # and 'null => false' columns should just convert back to an empty string. diff --git a/lib/active_scaffold/config/core.rb b/lib/active_scaffold/config/core.rb index e97b6f45a2..1c94060474 100644 --- a/lib/active_scaffold/config/core.rb +++ b/lib/active_scaffold/config/core.rb @@ -173,8 +173,6 @@ def initialize(model_id) # To be called after your finished configuration def _load_action_columns - #ActiveScaffold::DataStructures::ActionColumns.class_eval {include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration} - # then, register the column objects self.actions.each do |action_name| action = self.send(action_name) diff --git a/lib/active_scaffold/constraints.rb b/lib/active_scaffold/constraints.rb index 2ad6d9a874..dcd6da6944 100644 --- a/lib/active_scaffold/constraints.rb +++ b/lib/active_scaffold/constraints.rb @@ -62,7 +62,7 @@ def conditions_from_constraints elsif column.association if column.association.macro == :has_and_belongs_to_many active_scaffold_habtm_joins.concat column.includes - else + elsif !column.association.options[:polymorphic] active_scaffold_includes.concat column.includes end hash_conditions.merge!(condition_from_association_constraint(column.association, v)) @@ -116,7 +116,7 @@ def condition_from_association_constraint(association, value) condition = {"#{table}.#{field}" => value} if association.options[:polymorphic] raise ActiveScaffold::MalformedConstraint, polymorphic_constraint_error(association), caller unless params[:parent_model] - condition["#{table}.#{association.name}_type"] = params[:parent_model].constantize.model.to_s + condition["#{table}.#{association.name}_type"] = params[:parent_model].constantize.to_s end condition diff --git a/lib/active_scaffold/data_structures/action_columns.rb b/lib/active_scaffold/data_structures/action_columns.rb index 9e5a598eef..9b0fc6b4d1 100644 --- a/lib/active_scaffold/data_structures/action_columns.rb +++ b/lib/active_scaffold/data_structures/action_columns.rb @@ -59,88 +59,84 @@ def names_without_auth_check Array(@set) end - # A package of stuff to add after the configuration block. This is an attempt at making a certain level of functionality inaccessible during configuration, to reduce possible breakage from misuse. - # The bulk of the package is a means of connecting the referential column set (ActionColumns) with the actual column objects (Columns). This lets us iterate over the set and yield real column objects. - #module AfterConfiguration - # Redefine the each method to yield actual Column objects. - # It will skip constrained and unauthorized columns. - # - # Options: - # * :flatten - whether to recursively iterate on nested sets. default is false. - # * :for - the record (or class) being iterated over. used for column-level security. default is the class. - def each(options = {}, &proc) - options[:for] ||= @columns.active_record_class unless @columns.nil? - self.unauthorized_columns = [] - @set.each do |item| - unless item.is_a?(ActiveScaffold::DataStructures::ActionColumns) || @columns.nil? - item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class)) - next if self.skip_column?(item, options) - end - if item.is_a? ActiveScaffold::DataStructures::ActionColumns - if options[:flatten] - item.each(options, &proc) - elsif !options[:skip_groups] - yield item - end - else + # Redefine the each method to yield actual Column objects. + # It will skip constrained and unauthorized columns. + # + # Options: + # * :flatten - whether to recursively iterate on nested sets. default is false. + # * :for - the record (or class) being iterated over. used for column-level security. default is the class. + def each(options = {}, &proc) + options[:for] ||= @columns.active_record_class unless @columns.nil? + self.unauthorized_columns = [] + @set.each do |item| + unless item.is_a?(ActiveScaffold::DataStructures::ActionColumns) || @columns.nil? + item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class)) + next if self.skip_column?(item, options) + end + if item.is_a? ActiveScaffold::DataStructures::ActionColumns + if options[:flatten] + item.each(options, &proc) + elsif !options[:skip_groups] yield item end + else + yield item end end - - def collect_visible(options = {}, &proc) - columns = [] - options[:for] ||= @columns.active_record_class - self.unauthorized_columns = [] - @set.each do |item| - unless item.is_a? ActiveScaffold::DataStructures::ActionColumns || @columns.nil? - item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class)) - next if self.skip_column?(item, options) - end - if item.is_a? ActiveScaffold::DataStructures::ActionColumns and options.has_key?(:flatten) and options[:flatten] - columns += item.collect_visible(options, &proc) - else - columns << (block_given? ? yield(item) : item) - end + end + + def collect_visible(options = {}, &proc) + columns = [] + options[:for] ||= @columns.active_record_class + self.unauthorized_columns = [] + @set.each do |item| + unless item.is_a? ActiveScaffold::DataStructures::ActionColumns || @columns.nil? + item = (@columns[item] || ActiveScaffold::DataStructures::Column.new(item.to_sym, @columns.active_record_class)) + next if self.skip_column?(item, options) end - columns - end - - def skip_column?(column, options) - result = false - # skip if this matches a constrained column - result = true if constraint_columns.include?(column.name.to_sym) - # skip this field if it's not authorized - unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.try(:crud_type), :column => column.name) - self.unauthorized_columns << column.name.to_sym - result = true + if item.is_a? ActiveScaffold::DataStructures::ActionColumns and options.has_key?(:flatten) and options[:flatten] + columns += item.collect_visible(options, &proc) + else + columns << (block_given? ? yield(item) : item) end - return result end - - # registers a set of column objects (recursively, for all nested ActionColumns) - def set_columns(columns) - @columns = columns - # iterate over @set instead of self to avoid dealing with security queries - @set.each do |item| - item.set_columns(columns) if item.respond_to? :set_columns - end + columns + end + + def skip_column?(column, options) + result = false + # skip if this matches a constrained column + result = true if constraint_columns.include?(column.name.to_sym) + # skip this field if it's not authorized + unless options[:for].authorized_for?(:action => options[:action], :crud_type => options[:crud_type] || self.action.try(:crud_type), :column => column.name) + self.unauthorized_columns << column.name.to_sym + result = true end + return result + end - attr_writer :constraint_columns - def constraint_columns - @constraint_columns ||= [] + # registers a set of column objects (recursively, for all nested ActionColumns) + def set_columns(columns) + @columns = columns + # iterate over @set instead of self to avoid dealing with security queries + @set.each do |item| + item.set_columns(columns) if item.respond_to? :set_columns end - - attr_writer :unauthorized_columns - def unauthorized_columns - @unauthorized_columns ||= [] - end - - def length - ((@set - self.constraint_columns) - self.unauthorized_columns).length - end - #end + end + + attr_writer :constraint_columns + def constraint_columns + @constraint_columns ||= [] + end + + attr_writer :unauthorized_columns + def unauthorized_columns + @unauthorized_columns ||= [] + end + + def length + ((@set - self.constraint_columns) - self.unauthorized_columns).length + end protected diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index 10e8d42562..cd828c342a 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -201,14 +201,18 @@ def search_joins=(value) # search = "CONCAT(a, b)" define your own sql for searching. this should be the "left-side" of a WHERE condition. the operator and value will be supplied by ActiveScaffold. # search = [:a, :b] searches in both fields def search_sql=(value) - @search_sql = (value == true || value.is_a?(Proc)) ? value : Array(value) + @search_sql = if value + (value == true || value.is_a?(Proc)) ? value : Array(value) + else + value + end end def search_sql self.initialize_search_sql if @search_sql === true @search_sql end def searchable? - search_sql != false && search_sql != nil + !!search_sql end # to modify the default order of columns diff --git a/lib/active_scaffold/finder.rb b/lib/active_scaffold/finder.rb index 3fd2473256..3dabf34443 100644 --- a/lib/active_scaffold/finder.rb +++ b/lib/active_scaffold/finder.rb @@ -175,7 +175,7 @@ def condition_value_for_datetime(column, value, conversion = :to_time) def condition_value_for_numeric(column, value) return value if value.nil? - value = i18n_number_to_native_format(value) if [:i18n_number, :currency].include?(column.options[:format]) && column.search_ui != :number + value = column.number_to_native(value) if column.options[:format] && column.search_ui != :number case (column.search_ui || column.column.type) when :integer then value.to_i rescue value ? 1 : 0 when :float then value.to_f @@ -184,18 +184,6 @@ def condition_value_for_numeric(column, value) value end end - - def i18n_number_to_native_format(value) - native = '.' - delimiter = I18n.t('number.format.delimiter') - separator = I18n.t('number.format.separator') - return value if value.blank? || !value.is_a?(String) - unless delimiter == native && !value.include?(separator) && value !~ /\.\d{3}$/ - value.gsub(/[^0-9\-#{I18n.t('number.format.separator')}]/, '').gsub(I18n.t('number.format.separator'), native) - else - value - end - end def datetime_conversion_for_condition(column) if column.column diff --git a/test/data_structures/action_columns_test.rb b/test/data_structures/action_columns_test.rb index b99760fb92..43d37272e9 100644 --- a/test/data_structures/action_columns_test.rb +++ b/test/data_structures/action_columns_test.rb @@ -1,6 +1,6 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' # require 'test/model_stub' -require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/data_structures/set.rb') +#require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/data_structures/set.rb') class ActionColumnsTest < Test::Unit::TestCase def setup @@ -110,4 +110,4 @@ def test_include assert @columns.include?(:c) assert !@columns.include?(:d) end -end \ No newline at end of file +end diff --git a/test/data_structures/action_link_test.rb b/test/data_structures/action_link_test.rb index ff27bca233..47c5741d65 100644 --- a/test/data_structures/action_link_test.rb +++ b/test/data_structures/action_link_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class ActionLinkTest < Test::Unit::TestCase def setup diff --git a/test/data_structures/action_links_test.rb b/test/data_structures/action_links_test.rb index 380925534b..3603ae807b 100644 --- a/test/data_structures/action_links_test.rb +++ b/test/data_structures/action_links_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class ActionLinksTest < Test::Unit::TestCase def setup @@ -53,10 +53,10 @@ def test_each @links.add 'foo', :type => :collection @links.add 'bar', :type => :member - @links.each :collection do |link| + @links.collection.each do |link| assert_equal 'foo', link.action end - @links.each :member do |link| + @links.member.each do |link| assert_equal 'bar', link.action end end diff --git a/test/data_structures/actions_test.rb b/test/data_structures/actions_test.rb index a0eea235a9..4f2c585f7f 100644 --- a/test/data_structures/actions_test.rb +++ b/test/data_structures/actions_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class ActionsTest < Test::Unit::TestCase def setup @@ -22,4 +22,4 @@ def test_add @actions.add 'c' assert @actions.include?('c') end -end \ No newline at end of file +end diff --git a/test/data_structures/association_column_test.rb b/test/data_structures/association_column_test.rb index 0abe073a47..2f9e017a6b 100644 --- a/test/data_structures/association_column_test.rb +++ b/test/data_structures/association_column_test.rb @@ -1,5 +1,5 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') -require File.join(File.dirname(__FILE__), '../model_stub') +require 'test_helper' +require 'model_stub' class AssociationColumnTest < Test::Unit::TestCase def setup @@ -12,15 +12,14 @@ def test_virtuality end def test_sorting - # sorting on association columns is method-based - hash = {:method => "other_model.to_s"} - assert_equal hash, @association_column.sort + # sorting on association columns is not defined + assert_equal false, @association_column.sort end def test_searching # by default searching on association columns uses primary key assert @association_column.searchable? - assert_equal '"model_stubs"."id"', @association_column.search_sql + assert_equal ['"model_stubs"."id"'], @association_column.search_sql end def test_association diff --git a/test/data_structures/column_test.rb b/test/data_structures/column_test.rb index 04dd1dc857..88ff598fa5 100644 --- a/test/data_structures/column_test.rb +++ b/test/data_structures/column_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class ColumnTest < Test::Unit::TestCase def setup @@ -121,9 +121,9 @@ def test_sortable def test_custom_search @column.search_sql = true - assert_equal '"model_stubs"."a"', @column.search_sql + assert_equal ['"model_stubs"."a"'], @column.search_sql @column.search_sql = 'foobar' - assert_equal 'foobar', @column.search_sql + assert_equal ['foobar'], @column.search_sql assert @column.searchable? end @@ -172,7 +172,7 @@ def test_action_link end def test_includes - assert_equal [], @column.includes + assert_equal nil, @column.includes # make sure that when a non-array comes in, an array comes out @column.includes = :column_name diff --git a/test/data_structures/columns_test.rb b/test/data_structures/columns_test.rb index 203e42866f..9f843486c7 100644 --- a/test/data_structures/columns_test.rb +++ b/test/data_structures/columns_test.rb @@ -1,5 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') -# require 'test/model_stub' +require 'test_helper' class ColumnsTest < Test::Unit::TestCase def setup @@ -66,4 +65,4 @@ def test_block_config assert @columns.include?(:d) assert @columns.include?(:c) end -end \ No newline at end of file +end diff --git a/test/data_structures/error_message_test.rb b/test/data_structures/error_message_test.rb index 1cd1fee039..1a1760ca31 100644 --- a/test/data_structures/error_message_test.rb +++ b/test/data_structures/error_message_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class ErrorMessageTest < Test::Unit::TestCase def setup @@ -25,4 +25,4 @@ def test_yaml assert yml.has_key?(:error) assert_equal 'foo', yml[:error] end -end \ No newline at end of file +end diff --git a/test/data_structures/set_test.rb b/test/data_structures/set_test.rb index e1c044d78b..556a4cbcc8 100644 --- a/test/data_structures/set_test.rb +++ b/test/data_structures/set_test.rb @@ -1,5 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') -# require 'test/model_stub' +require 'test_helper' class SetTest < Test::Unit::TestCase def setup @@ -83,4 +82,4 @@ def test_include assert @items.include?(:b) assert !@items.include?(:d) end -end \ No newline at end of file +end diff --git a/test/data_structures/sorting_test.rb b/test/data_structures/sorting_test.rb index 37a096da81..14301b9382 100644 --- a/test/data_structures/sorting_test.rb +++ b/test/data_structures/sorting_test.rb @@ -1,5 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') -# require 'test/model_stub' +require 'test_helper' class SortingTest < Test::Unit::TestCase def setup diff --git a/test/data_structures/standard_column_test.rb b/test/data_structures/standard_column_test.rb index 22a919d3aa..40281f8b16 100644 --- a/test/data_structures/standard_column_test.rb +++ b/test/data_structures/standard_column_test.rb @@ -1,5 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') -# require 'test/model_stub' +require 'test_helper' class StandardColumnTest < Test::Unit::TestCase def setup @@ -19,6 +18,6 @@ def test_sorting def test_searching assert @standard_column.searchable? - assert_equal '"model_stubs"."a"', @standard_column.search_sql # check default + assert_equal ['"model_stubs"."a"'], @standard_column.search_sql # check default end end diff --git a/test/data_structures/virtual_column_test.rb b/test/data_structures/virtual_column_test.rb index 96607ce64a..2474a7b746 100644 --- a/test/data_structures/virtual_column_test.rb +++ b/test/data_structures/virtual_column_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class VirtualColumnTest < Test::Unit::TestCase def setup diff --git a/test/extensions/active_record_test.rb b/test/extensions/active_record_test.rb index 6ad58b1682..bbe3007d86 100644 --- a/test/extensions/active_record_test.rb +++ b/test/extensions/active_record_test.rb @@ -1,5 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') -#require 'test/model_stub' +require 'test_helper' class ActiveRecordTest < Test::Unit::TestCase def setup @@ -42,4 +41,4 @@ def name assert_equal 'name', @record.to_label end -end \ No newline at end of file +end diff --git a/test/extensions/array_test.rb b/test/extensions/array_test.rb index 3976fc257e..cfef49df75 100644 --- a/test/extensions/array_test.rb +++ b/test/extensions/array_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class ArrayTest < Test::Unit::TestCase def test_after @@ -9,4 +9,4 @@ def test_after assert_equal 'a', @sequence.after('c') assert_equal nil, @sequence.after('d') end -end \ No newline at end of file +end diff --git a/test/misc/active_record_permissions_test.rb b/test/misc/active_record_permissions_test.rb index 375c2e0aca..803b09279b 100644 --- a/test/misc/active_record_permissions_test.rb +++ b/test/misc/active_record_permissions_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class PermissionModel < ActiveRecord::Base def self.columns; [] end diff --git a/test/misc/attribute_params_test.rb b/test/misc/attribute_params_test.rb index b956aeab34..8317fa50ae 100644 --- a/test/misc/attribute_params_test.rb +++ b/test/misc/attribute_params_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class NumberModel < ActiveRecord::Base abstract_class = true @@ -9,6 +9,7 @@ def self.columns class AttributeParamsTest < Test::Unit::TestCase include ActiveScaffold::AttributeParams + include ActiveScaffold::Finder def setup I18n.backend.store_translations :en, :number => {:format => { @@ -27,9 +28,7 @@ def setup }} @config = config_for('number_model') - class << @config.list.columns - include ActiveScaffold::DataStructures::ActionColumns::AfterConfiguration - end + @config.columns[:number].form_ui = nil @config.list.columns.set_columns @config.columns end diff --git a/test/misc/configurable_test.rb b/test/misc/configurable_test.rb index e68e73fca0..711b66277f 100644 --- a/test/misc/configurable_test.rb +++ b/test/misc/configurable_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class ConfigurableClass FOO = 'bar' @@ -93,4 +93,4 @@ def test_arity # but we want to let people accept the configurable class as the first argument, too assert_equal 'bar', ConfigurableClass.configure {|a| a.foo} end -end \ No newline at end of file +end diff --git a/test/misc/constraints_test.rb b/test/misc/constraints_test.rb index 3737e04062..bb67a7bbbe 100644 --- a/test/misc/constraints_test.rb +++ b/test/misc/constraints_test.rb @@ -1,11 +1,11 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' module ModelStubs class ModelStub < ActiveRecord::Base abstract_class = true def self.columns; [ActiveRecord::ConnectionAdapters::Column.new('foo', '')] end def self.table_name - to_s.split('::').last.underscore.pluralize + @table_name || to_s.split('::').last.underscore.pluralize end self.store_full_sti_class = false end @@ -43,31 +43,31 @@ class Role < ModelStub ## class OtherAddress < ModelStub - set_table_name 'addresses' + self.table_name = 'addresses' belongs_to :other_addressable, :polymorphic => true end class OtherUser < ModelStub - set_table_name 'users' + self.table_name = 'users' has_and_belongs_to_many :other_roles, :class_name => 'ModelStubs::OtherRole', :foreign_key => 'user_id', :association_foreign_key => 'role_id', :join_table => 'roles_users' has_one :other_subscription, :class_name => 'ModelStubs::OtherSubscription', :foreign_key => 'user_id' has_one :other_address, :as => :other_addressable, :class_name => 'ModelStubs::OtherAddress', :foreign_key => 'addressable_id' end class OtherService < ModelStub - set_table_name 'services' + self.table_name = 'services' has_many :other_subscriptions, :class_name => 'ModelStubs::OtherSubscription', :foreign_key => 'service_id' has_many :other_users, :through => :other_subscriptions # :class_name and :foreign_key are ignored for :through end class OtherSubscription < ModelStub - set_table_name 'subscriptions' + self.table_name = 'subscriptions' belongs_to :other_service, :class_name => 'ModelStubs::OtherService', :foreign_key => 'service_id' belongs_to :other_user, :class_name => 'ModelStubs::OtherUser', :foreign_key => 'user_id' end class OtherRole < ModelStub - set_table_name 'roles' + self.table_name = 'roles' has_and_belongs_to_many :other_users, :class_name => 'ModelStubs::OtherUser', :foreign_key => 'role_id', :association_foreign_key => 'user_id', :join_table => 'roles_users' end @@ -112,72 +112,72 @@ def setup def test_constraint_conditions_for_default_associations @test_object.active_scaffold_config = config_for('user') # has_one (vs belongs_to) - assert_constraint_condition({:subscription => 5}, ['subscriptions.id = ?', 5], 'find the user with subscription #5') + assert_constraint_condition({:subscription => 5}, [{'subscriptions.id' => 5}], 'find the user with subscription #5') # habtm (vs habtm) - assert_constraint_condition({:roles => 4}, ['roles_users.role_id = ?', 4], 'find all users with role #4') + assert_constraint_condition({:roles => 4}, [{'roles_users.role_id' => 4}], 'find all users with role #4') # has_one (vs polymorphic) - assert_constraint_condition({:address => 11}, ['addresses.id = ?', 11], 'find the user with address #11') + assert_constraint_condition({:address => 11}, [{'addresses.id' => 11}], 'find the user with address #11') # reverse of a has_many :through - assert_constraint_condition({:subscription => {:service => 5}}, ['services.id = ?', 5], 'find all users subscribed to service #5') + assert_constraint_condition({:subscription => {:service => 5}}, [{'services.id' => 5}], 'find all users subscribed to service #5') assert(@test_object.active_scaffold_includes.include?({:subscription => :service}), 'multi-level association include') @test_object.active_scaffold_config = config_for('subscription') # belongs_to (vs has_one) - assert_constraint_condition({:user => 2}, ['subscriptions.user_id = ?', 2], 'find the subscription for user #2') + assert_constraint_condition({:user => 2}, [{'subscriptions.user_id' => 2}], 'find the subscription for user #2') # belongs_to (vs has_many) - assert_constraint_condition({:service => 1}, ['subscriptions.service_id = ?', 1], 'find all subscriptions for service #1') + assert_constraint_condition({:service => 1}, [{'subscriptions.service_id' => 1}], 'find all subscriptions for service #1') @test_object.active_scaffold_config = config_for('service') # has_many (vs belongs_to) - assert_constraint_condition({:subscriptions => 10}, ['subscriptions.id = ?', 10], 'find the service with subscription #10') + assert_constraint_condition({:subscriptions => 10}, [{'subscriptions.id' => 10}], 'find the service with subscription #10') # has_many :through (through has_many) - assert_constraint_condition({:users => 7}, ['users.id = ?', 7], 'find the service with user #7') + assert_constraint_condition({:users => 7}, [{'users.id' => 7}], 'find the service with user #7') @test_object.active_scaffold_config = config_for('address') # belongs_to :polymorphic => true - @test_object.params[:parent_model] = 'User' - assert_constraint_condition({:addressable => 14}, ['addresses.addressable_id = ?', 14, 'addresses.addressable_type = ?', 'User'], 'find all addresses for user #14') + @test_object.params[:parent_model] = 'ModelStubs::User' + assert_constraint_condition({:addressable => 14}, [{'addresses.addressable_id' => 14, 'addresses.addressable_type' => 'ModelStubs::User'}], 'find all addresses for user #14') end def test_constraint_conditions_for_configured_associations @test_object.active_scaffold_config = config_for('other_user') # has_one (vs belongs_to) - assert_constraint_condition({:other_subscription => 5}, ['subscriptions.id = ?', 5], 'find the user with subscription #5') + assert_constraint_condition({:other_subscription => 5}, [{'subscriptions.id' => 5}], 'find the user with subscription #5') # habtm (vs habtm) - assert_constraint_condition({:other_roles => 4}, ['roles_users.role_id = ?', 4], 'find all users with role #4') + assert_constraint_condition({:other_roles => 4}, [{'roles_users.role_id' => 4}], 'find all users with role #4') # has_one (vs polymorphic) - assert_constraint_condition({:other_address => 11}, ['addresses.id = ?', 11], 'find the user with address #11') + assert_constraint_condition({:other_address => 11}, [{'addresses.id' => 11}], 'find the user with address #11') # reverse of a has_many :through - assert_constraint_condition({:other_subscription => {:other_service => 5}}, ['services.id = ?', 5], 'find all users subscribed to service #5') + assert_constraint_condition({:other_subscription => {:other_service => 5}}, [{'services.id' => 5}], 'find all users subscribed to service #5') @test_object.active_scaffold_config = config_for('other_subscription') # belongs_to (vs has_one) - assert_constraint_condition({:other_user => 2}, ['subscriptions.user_id = ?', 2], 'find the subscription for user #2') + assert_constraint_condition({:other_user => 2}, [{'subscriptions.user_id' => 2}], 'find the subscription for user #2') # belongs_to (vs has_many) - assert_constraint_condition({:other_service => 1}, ['subscriptions.service_id = ?', 1], 'find all subscriptions for service #1') + assert_constraint_condition({:other_service => 1}, [{'subscriptions.service_id' => 1}], 'find all subscriptions for service #1') @test_object.active_scaffold_config = config_for('other_service') # has_many (vs belongs_to) - assert_constraint_condition({:other_subscriptions => 10}, ['subscriptions.id = ?', 10], 'find the service with subscription #10') + assert_constraint_condition({:other_subscriptions => 10}, [{'subscriptions.id' => 10}], 'find the service with subscription #10') # has_many :through (through has_many) - assert_constraint_condition({:other_users => 7}, ['users.id = ?', 7], 'find the service with user #7') + assert_constraint_condition({:other_users => 7}, [{'users.id' => 7}], 'find the service with user #7') @test_object.active_scaffold_config = config_for('other_address') # belongs_to :polymorphic => true - @test_object.params[:parent_model] = 'OtherUser' - assert_constraint_condition({:other_addressable => 14}, ['addresses.other_addressable_id = ?', 14, 'addresses.other_addressable_type = ?', 'OtherUser'], 'find all addresses for user #14') + @test_object.params[:parent_model] = 'ModelStubs::OtherUser' + assert_constraint_condition({:other_addressable => 14}, [{'addresses.other_addressable_id' => 14, 'addresses.other_addressable_type' => 'ModelStubs::OtherUser'}], 'find all addresses for user #14') end def test_constraint_conditions_for_normal_attributes @test_object.active_scaffold_config = config_for('user') - assert_constraint_condition({'foo' => 'bar'}, ['"users"."foo" = ?', 'bar'], 'normal column-based constraint') + assert_constraint_condition({'foo' => 'bar'}, [['"users"."foo" = ?', 'bar']], 'normal column-based constraint') end def test_constraint_conditions_for_associations_with_primary_key_option @test_object.active_scaffold_config = config_for('primary_key_location') #user = ModelStubs::PrimaryKeyUser.new(:id => 1, :name => 'User Name') ModelStubs::PrimaryKeyUser.expects(:find).with(1).returns(stub(:id => 1, :name => 'User Name')) - assert_constraint_condition({'user' => 1}, ['primary_key_locations.username = ?', 'User Name'], 'association with primary-key constraint') + assert_constraint_condition({'user' => 1}, [{'primary_key_locations.username' => 'User Name'}], 'association with primary-key constraint') end protected diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index cc57c3877f..650d52c3f8 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -1,5 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') -# require 'test/model_stub' +require 'test_helper' class ClassWithFinder include ActiveScaffold::Finder diff --git a/test/misc/lang_test.rb b/test/misc/lang_test.rb index bcd0600c94..a3b3427b9b 100644 --- a/test/misc/lang_test.rb +++ b/test/misc/lang_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class LocalizationTest < Test::Unit::TestCase diff --git a/test/model_stub.rb b/test/model_stub.rb index 270e2f10a2..a407b03e21 100644 --- a/test/model_stub.rb +++ b/test/model_stub.rb @@ -10,8 +10,8 @@ class ModelStub < ActiveRecord::Base @@nested_scope_calls = [] cattr_accessor :nested_scope_calls - named_scope :a_is_defined, :conditions => "a is not null" - named_scope :b_like, lambda {|pattern| {:conditions => ["b like ?", pattern]}} + scope :a_is_defined, :conditions => "a is not null" + scope :b_like, lambda {|pattern| {:conditions => ["b like ?", pattern]}} def self.a_is_defined @@nested_scope_calls << :a_is_defined diff --git a/test/test_helper.rb b/test/test_helper.rb index c246d539a8..587c1449b7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,6 +2,7 @@ $:.unshift File.dirname(__FILE__) require "mock_app/config/environment" require 'rails/test_help' +require 'active_scaffold' require 'mocha/setup' begin From ce4b203a7a92d5a3fab5d78b3aa0473808e789b7 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 12 Jul 2013 15:12:08 +0200 Subject: [PATCH 1994/2024] fix helpers tests --- lib/active_scaffold/helpers/list_column_helpers.rb | 2 +- lib/active_scaffold/helpers/pagination_helpers.rb | 2 +- test/helpers/form_column_helpers_test.rb | 12 ++++++------ test/helpers/list_column_helpers_test.rb | 5 ++++- test/helpers/pagination_helpers_test.rb | 10 +++++++--- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/active_scaffold/helpers/list_column_helpers.rb b/lib/active_scaffold/helpers/list_column_helpers.rb index 9daf0e804c..1da4d4fb37 100644 --- a/lib/active_scaffold/helpers/list_column_helpers.rb +++ b/lib/active_scaffold/helpers/list_column_helpers.rb @@ -160,7 +160,7 @@ def format_association_value(value, column, size) if column.associated_limit == 0 size if column.associated_number? else - joined_associated = firsts.join(active_scaffold_config.list.association_join_text) + joined_associated = firsts.join(h(active_scaffold_config.list.association_join_text)).html_safe joined_associated << " (#{size})" if column.associated_number? and column.associated_limit and value.size > column.associated_limit joined_associated end diff --git a/lib/active_scaffold/helpers/pagination_helpers.rb b/lib/active_scaffold/helpers/pagination_helpers.rb index 7a625ee53a..b98550c980 100644 --- a/lib/active_scaffold/helpers/pagination_helpers.rb +++ b/lib/active_scaffold/helpers/pagination_helpers.rb @@ -38,7 +38,7 @@ def pagination_ajax_links(current_page, url_options, options, inner_window, oute page = current_page.number - offset if page < start_number && page > last_page html << '..' if page > last_page + 1 - html << pagination_ajax_link(page, params) + html << pagination_ajax_link(page, url_options, options) last_page = page end end diff --git a/test/helpers/form_column_helpers_test.rb b/test/helpers/form_column_helpers_test.rb index c7ed79a304..3cdc6de125 100644 --- a/test/helpers/form_column_helpers_test.rb +++ b/test/helpers/form_column_helpers_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class FormColumnHelpersTest < ActionView::TestCase include ActiveScaffold::Helpers::FormColumnHelpers @@ -10,22 +10,22 @@ def setup def test_choices_for_select_form_ui_for_simple_column @column.options[:options] = [:value_1, :value_2, :value_3] - assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">Value 1</option><option value="value_2">Value 2</option><option value="value_3">Value 3</option></select>', active_scaffold_input_select(@column, {}) + assert_dom_equal "<select name=\"record[a]\" id=\"record_a\"><option value=\"value_1\">Value 1</option>\n<option value=\"value_2\">Value 2</option>\n<option value=\"value_3\">Value 3</option></select>", active_scaffold_input_select(@column, {}) @column.options[:options] = %w(value_1 value_2 value_3) - assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">value_1</option><option value="value_2">value_2</option><option value="value_3">value_3</option></select>', active_scaffold_input_select(@column, {}) + assert_dom_equal "<select name=\"record[a]\" id=\"record_a\"><option value=\"value_1\">value_1</option>\n<option value=\"value_2\">value_2</option>\n<option value=\"value_3\">value_3</option></select>", active_scaffold_input_select(@column, {}) @column.options[:options] = [%w(text_1 value_1), %w(text_2 value_2), %w(text_3 value_3)] - assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">text_1</option><option value="value_2">text_2</option><option value="value_3">text_3</option></select>', active_scaffold_input_select(@column, {}) + assert_dom_equal "<select name=\"record[a]\" id=\"record_a\"><option value=\"value_1\">text_1</option>\n<option value=\"value_2\">text_2</option>\n<option value=\"value_3\">text_3</option></select>", active_scaffold_input_select(@column, {}) @column.options[:options] = [[:text_1, :value_1], [:text_2, :value_2], [:text_3, :value_3]] - assert_dom_equal '<select name="record[a]" id="record_a"><option value="value_1">Text 1</option><option value="value_2">Text 2</option><option value="value_3">Text 3</option></select>', active_scaffold_input_select(@column, {}) + assert_dom_equal "<select name=\"record[a]\" id=\"record_a\"><option value=\"value_1\">Text 1</option>\n<option value=\"value_2\">Text 2</option>\n<option value=\"value_3\">Text 3</option></select>", active_scaffold_input_select(@column, {}) end def test_options_for_select_form_ui_for_simple_column @column.options = {:include_blank => 'None', :selected => 'value_2', :disabled => %w(value_1 value_3)} @column.options[:options] = %w(value_1 value_2 value_3) @column.options[:html_options] = {:class => 'big'} - assert_dom_equal '<select name="record[a]" class="big" id="record_a"><option value="">None</option><option disabled="disabled" value="value_1">value_1</option><option selected="selected" value="value_2">value_2</option><option disabled="disabled" value="value_3">value_3</option></select>', active_scaffold_input_select(@column, {}) + assert_dom_equal "<select name=\"record[a]\" class=\"big\" id=\"record_a\"><option value=\"\">None</option>\n<option disabled=\"disabled\" value=\"value_1\">value_1</option>\n<option selected=\"selected\" value=\"value_2\">value_2</option>\n<option disabled=\"disabled\" value=\"value_3\">value_3</option></select>", active_scaffold_input_select(@column, {}) end end diff --git a/test/helpers/list_column_helpers_test.rb b/test/helpers/list_column_helpers_test.rb index 38f4c781a9..f465b75932 100644 --- a/test/helpers/list_column_helpers_test.rb +++ b/test/helpers/list_column_helpers_test.rb @@ -1,8 +1,9 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class ListColumnHelpersTest < ActionView::TestCase include ActiveScaffold::Helpers::ListColumnHelpers include ActiveScaffold::Helpers::ViewHelpers + include ::ERB::Util def setup @column = ActiveScaffold::DataStructures::Column.new(:a, ModelStub) @@ -32,6 +33,8 @@ def test_association_join_text value.each {|v| v.stubs(:to_label).returns(v)} assert_equal '1, 2, 3, … (4)', format_association_value(value, @association_column, value.size) @config.list.stubs(:association_join_text => ',<br/>') + assert_equal '1,<br/>2,<br/>3,<br/>… (4)', format_association_value(value, @association_column, value.size) + @config.list.stubs(:association_join_text => ',<br/>'.html_safe) assert_equal '1,<br/>2,<br/>3,<br/>… (4)', format_association_value(value, @association_column, value.size) end diff --git a/test/helpers/pagination_helpers_test.rb b/test/helpers/pagination_helpers_test.rb index bdf50c0bb2..6d5b907a73 100644 --- a/test/helpers/pagination_helpers_test.rb +++ b/test/helpers/pagination_helpers_test.rb @@ -1,8 +1,12 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class PaginationHelpersTest < Test::Unit::TestCase include ActiveScaffold::Helpers::PaginationHelpers + def active_scaffold_config + @config ||= config_for('model_stub') + end + def test_links self.stubs(:pagination_ajax_link).returns('l') @@ -50,10 +54,10 @@ def test_links_with_infinite_pagination def links(current, last_page, window_size = 2, infinite = false) paginator = stub(:last => last_page = stub(:number => last_page), :infinite? => infinite) current_page = stub(:number => current, :pager => paginator) - pagination_ajax_links(current_page, {}, window_size) + pagination_ajax_links(current_page, {}, {}, window_size, 0) end - def content_tag(tag, text) + def content_tag(tag, text, *args) text end end From 8e842c8ba57d049f2eab5b8fd62411296f781446 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 12 Jul 2013 15:35:25 +0200 Subject: [PATCH 1995/2024] fix some config tests --- test/config/base_test.rb | 2 +- test/config/create_test.rb | 6 +++--- test/config/delete_test.rb | 4 ++-- test/config/field_search_test.rb | 2 +- test/config/search_test.rb | 2 +- test/config/show_test.rb | 4 ++-- test/config/subform_test.rb | 2 +- test/config/update_test.rb | 8 ++++---- test/test_helper.rb | 2 ++ 9 files changed, 17 insertions(+), 15 deletions(-) diff --git a/test/config/base_test.rb b/test/config/base_test.rb index 9fab684293..85312d8180 100644 --- a/test/config/base_test.rb +++ b/test/config/base_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class Config::BaseTest < Test::Unit::TestCase def setup diff --git a/test/config/create_test.rb b/test/config/create_test.rb index 0f9f002ab0..b9cc88096d 100644 --- a/test/config/create_test.rb +++ b/test/config/create_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class Config::CreateTest < Test::Unit::TestCase def setup @@ -13,7 +13,7 @@ def teardown def test_default_options assert !@config.create.persistent assert @config.create.action_after_create.nil? - assert_equal 'Create ModelStub', @config.create.label + assert_equal 'Create Model stub', @config.create.label end def test_link_defaults @@ -43,7 +43,7 @@ def test_label assert_equal label, @config.create.label I18n.backend.store_translations :en, :active_scaffold => {:create_new_model => 'Create new %{model}'} @config.create.label = :create_new_model - assert_equal 'Create new ModelStub', @config.create.label + assert_equal 'Create new Model stub', @config.create.label end def test_persistent diff --git a/test/config/delete_test.rb b/test/config/delete_test.rb index 8d3f11674d..d9be5f7fc0 100644 --- a/test/config/delete_test.rb +++ b/test/config/delete_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class Config::DeleteTest < Test::Unit::TestCase def setup @@ -15,7 +15,7 @@ def test_link_defaults assert !link.page? assert !link.popup? assert link.confirm? - assert_equal "delete", link.action + assert_equal "destroy", link.action assert_equal "Delete", link.label assert link.inline? blank = {} diff --git a/test/config/field_search_test.rb b/test/config/field_search_test.rb index ed6f9c49e6..2bcdb3546d 100644 --- a/test/config/field_search_test.rb +++ b/test/config/field_search_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class Config::FieldSearchTest < Test::Unit::TestCase def setup diff --git a/test/config/search_test.rb b/test/config/search_test.rb index 5db57a6a5b..9478b5fdbb 100644 --- a/test/config/search_test.rb +++ b/test/config/search_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class Config::SearchTest < Test::Unit::TestCase def setup diff --git a/test/config/show_test.rb b/test/config/show_test.rb index 59110411d6..4a0aad9ff6 100644 --- a/test/config/show_test.rb +++ b/test/config/show_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class Config::ShowTest < Test::Unit::TestCase def setup @@ -37,7 +37,7 @@ def test_label assert_equal label, @config.show.label I18n.backend.store_translations :en, :active_scaffold => {:view_model => 'View %{model}'} @config.show.label = :view_model - assert_equal 'View ModelStub', @config.show.label + assert_equal 'View Model stub', @config.show.label assert_equal 'View record', @config.show.label('record') end end diff --git a/test/config/subform_test.rb b/test/config/subform_test.rb index aed277f73c..6adf484506 100644 --- a/test/config/subform_test.rb +++ b/test/config/subform_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class Config::SubformTest < Test::Unit::TestCase def setup diff --git a/test/config/update_test.rb b/test/config/update_test.rb index 497227828c..f21e9241fb 100644 --- a/test/config/update_test.rb +++ b/test/config/update_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class Config::UpdateTest < Test::Unit::TestCase def setup @@ -15,7 +15,7 @@ def test__params_for_columns__returns_all_params def test_default_options assert !@config.update.persistent assert !@config.update.nested_links - assert_equal 'Update ModelStub', @config.update.label + assert_equal 'Model stub', @config.update.label end def test_persistent @@ -34,7 +34,7 @@ def test_label assert_equal label, @config.update.label I18n.backend.store_translations :en, :active_scaffold => {:change_model => 'Change %{model}'} @config.update.label = :change_model - assert_equal 'Change ModelStub', @config.update.label + assert_equal 'Change Model stub', @config.update.label assert_equal 'Change record', @config.update.label('record') end -end \ No newline at end of file +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 587c1449b7..671d3d422a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -28,6 +28,8 @@ def silence_stderr(&block) require File.join(File.dirname(__FILE__), file) end +I18n.backend.store_translations :en, YAML.load_file(File.expand_path('../../config/locales/en.yml', __FILE__))["en"] + class Test::Unit::TestCase protected def config_for(klass, namespace = nil) From 9580564ddb99817f2e494a766e365ce80537784f Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 15 Jul 2013 11:44:55 +0200 Subject: [PATCH 1996/2024] fix nested tests --- lib/active_scaffold/config/nested.rb | 9 ++++-- test/config/nested_test.rb | 48 +++++++++++----------------- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/lib/active_scaffold/config/nested.rb b/lib/active_scaffold/config/nested.rb index 4c717dffc9..6aadcf338f 100644 --- a/lib/active_scaffold/config/nested.rb +++ b/lib/active_scaffold/config/nested.rb @@ -25,7 +25,7 @@ def initialize(core_config) # Add a nested ActionLink def add_link(attribute, options = {}) column = @core.columns[attribute.to_sym] - unless column.nil? || column.association.nil? + if column && column.association label = if column.polymorphic_association? column.label else @@ -35,8 +35,11 @@ def add_link(attribute, options = {}) action_group = options.delete(:action_group) || self.action_group action_link = @core.link_for_association(column, options) @core.action_links.add_to_group(action_link, action_group) unless action_link.nil? - else - # TODO: raise exception + action_link + elsif column.nil? + raise ArgumentError.new("unknown column #{attribute}") + elsif column.association.nil? + raise ArgumentError.new("column #{attribute} is not an association") end end diff --git a/test/config/nested_test.rb b/test/config/nested_test.rb index 0bc54a2209..e5158a7f9d 100644 --- a/test/config/nested_test.rb +++ b/test/config/nested_test.rb @@ -1,13 +1,17 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class Config::NestedTest < Test::Unit::TestCase + class ModelStubsController < ActionController::Base + active_scaffold + end + def setup - @config = ActiveScaffold::Config::Core.new :model_stub + @config = ActiveScaffold::Config::Core.new(:model_stub) end def test_default_options - assert !@config.nested.shallow_delete - assert_equal 'Add Existing ModelStub', @config.nested.label + assert @config.nested.shallow_delete + assert_equal 'Add Existing Model stub', @config.nested.label end def test_label @@ -16,7 +20,7 @@ def test_label assert_equal label, @config.nested.label I18n.backend.store_translations :en, :active_scaffold => {:create_model => 'Add new %{model}'} @config.nested.label = :create_model - assert_equal 'Add new ModelStub', @config.nested.label + assert_equal 'Add new Model stub', @config.nested.label end def test_shallow_delete @@ -24,36 +28,22 @@ def test_shallow_delete assert @config.nested.shallow_delete end - def test_add_link_deprecation - ActiveSupport::Deprecation.silence { @config.nested.add_link :custom_link, [:assoc_1, :assoc_2] } - link = @config.action_links['nested'] - assert_equal 'Custom Link', link.label - assert_equal 'nested', link.action - assert_equal :after, link.position - assert !link.page? - assert !link.popup? - assert !link.confirm? - assert link.inline? - assert_equal :assoc_1, link.parameters[:associations] - assert_equal 'assoc_1', link.html_options[:class] - assert_equal :get, link.method - assert_equal :member, link.type - assert_equal :read, link.crud_type - assert_equal :nested_authorized?, link.security_method - end - def test_add_link - @config.nested.add_link :custom_link, :assoc_1 - link = @config.action_links['nested'] - assert_equal 'Custom Link', link.label - assert_equal 'nested', link.action + assert_raise(ArgumentError) { @config.nested.add_link :assoc_1 } + config = @config + ModelStubsController.class_eval do + config.configure { nested.add_link :other_models } + end + link = @config.action_links['index'] + assert_equal 'ModelStubs', link.label + assert_equal 'index', link.action assert_equal :after, link.position assert !link.page? assert !link.popup? assert !link.confirm? assert link.inline? - assert_equal :assoc_1, link.parameters[:associations] - assert_equal 'assoc_1', link.html_options[:class] + assert link.refresh_on_close + assert_equal :other_models, link.parameters[:association] assert_equal :get, link.method assert_equal :member, link.type assert_equal :read, link.crud_type From 42fa8affbc61641f6873a719ad9b91c3b5c6f7d0 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 15 Jul 2013 11:45:51 +0200 Subject: [PATCH 1997/2024] fix list tests --- test/config/list_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/config/list_test.rb b/test/config/list_test.rb index f61d0f95ee..e3634fffed 100644 --- a/test/config/list_test.rb +++ b/test/config/list_test.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class Config::ListTest < Test::Unit::TestCase def setup @@ -16,7 +16,7 @@ def test_label def test_default_options assert_equal 15, @config.list.per_page - assert_equal 2, @config.list.page_links_window + assert_equal 2, @config.list.page_links_inner_window assert_equal '-', @config.list.empty_field_text assert_equal ', ', @config.list.association_join_text assert_equal true, @config.list.pagination @@ -80,8 +80,8 @@ def test_per_page def test_page_links_window page_links_window = 3 - @config.list.page_links_window = page_links_window - assert_equal page_links_window, @config.list.page_links_window + @config.list.page_links_inner_window = page_links_window + assert_equal page_links_window, @config.list.page_links_inner_window end def test_always_show_create From ac871af5d3765da5fb46db4af20d8c2b0970f121 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 15 Jul 2013 12:02:29 +0200 Subject: [PATCH 1998/2024] fix sti tests --- lib/active_scaffold.rb | 2 +- test/config/core_test.rb | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/active_scaffold.rb b/lib/active_scaffold.rb index 9ed248e003..e346e24a08 100644 --- a/lib/active_scaffold.rb +++ b/lib/active_scaffold.rb @@ -228,7 +228,7 @@ def _add_sti_create_links active_scaffold_config.action_links.collection.delete('new') active_scaffold_config.sti_children.each do |child| new_sti_link = Marshal.load(Marshal.dump(new_action_link)) # deep clone - new_sti_link.label = child.to_s.camelize.constantize.model_name.human + new_sti_link.label = as_(:create_model, :model => child.to_s.camelize.constantize.model_name.human) new_sti_link.parameters = {:parent_sti => controller_path} new_sti_link.controller = Proc.new { active_scaffold_controller_for(child.to_s.camelize.constantize).controller_path } active_scaffold_config.action_links.collection.create.add(new_sti_link) diff --git a/test/config/core_test.rb b/test/config/core_test.rb index c1994d5ee7..c6c0a2f10c 100644 --- a/test/config/core_test.rb +++ b/test/config/core_test.rb @@ -1,8 +1,10 @@ -require File.join(File.dirname(__FILE__), '../test_helper.rb') +require 'test_helper' class Config::CoreTest < Test::Unit::TestCase + class ModelStubsController < ActionController::Base; end def setup @config = ActiveScaffold::Config::Core.new :model_stub + ModelStubsController.instance_variable_set :@active_scaffold_config, @config end def test_default_options @@ -11,7 +13,7 @@ def test_default_options assert_equal [:create, :list, :search, :update, :delete, :show, :nested, :subform], @config.actions.to_a assert_equal :default, @config.frontend assert_equal :default, @config.theme - assert_equal 'ModelStub', @config.label(:count => 1) + assert_equal 'Model stub', @config.label(:count => 1) assert_equal 'ModelStubs', @config.label end @@ -37,10 +39,11 @@ def test_actions def test_form_ui_in_sti @config.columns << :type + @config.sti_create_links = false @config.sti_children = [:model_stub] @config._configure_sti assert_equal :select, @config.columns[:type].form_ui - assert_equal [['Modelstub', 'ModelStub']], @config.columns[:type].options[:options] + assert_equal [['Model stub', 'ModelStub']], @config.columns[:type].options[:options] @config.columns[:type].form_ui = nil @config.sti_create_links = true @@ -52,7 +55,8 @@ def test_sti_children_links @config.sti_children = [:model_stub] @config.sti_create_links = true @config.action_links.add @config.create.link - @config._add_sti_create_links - assert_equal 'Create Modelstub', @config.action_links[:new].label + ModelStubsController.send(:_add_sti_create_links) + assert_equal 'Create Model stub', @config.action_links[:new].label + assert_equal 'config/core_test/model_stubs', @config.action_links[:new].parameters[:parent_sti] end end From a9fdb48d675e01be25dfbe53c6a3d90a36507aaa Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 15 Jul 2013 12:20:59 +0200 Subject: [PATCH 1999/2024] fix finder tests --- test/misc/finder_test.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/misc/finder_test.rb b/test/misc/finder_test.rb index 650d52c3f8..964081807f 100644 --- a/test/misc/finder_test.rb +++ b/test/misc/finder_test.rb @@ -32,16 +32,16 @@ def test_create_conditions_for_columns ] expected_conditions = [ - '("model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?) AND ("model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?)', - '%foo%', '%foo%', '%bar%', '%bar%' - ] + ['"model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?', '%foo%', '%foo%'], + ['"model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?', '%bar%', '%bar%'] + ] assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns(tokens, columns) expected_conditions = [ - '("model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?)', + '"model_stubs"."a" LIKE ? OR "model_stubs"."b" LIKE ?', '%foo%', '%foo%' ] - assert_equal expected_conditions, ClassWithFinder.create_conditions_for_columns('foo', columns) + assert_equal [expected_conditions], ClassWithFinder.create_conditions_for_columns('foo', columns) assert_equal nil, ClassWithFinder.create_conditions_for_columns('foo', []) end @@ -68,8 +68,9 @@ def test_method_sorting def test_count_with_group @klass.expects(:custom_finder_options).returns({:group => :a}) - ModelStub.expects(:count).returns(ActiveSupport::OrderedHash['foo', 5]) - ModelStub.expects(:find).with(:all, has_entries(:limit => 20, :offset => 0)) + ActiveRecord::Relation.any_instance.expects(:count).returns(ActiveSupport::OrderedHash['foo', 5]) + ActiveRecord::Relation.any_instance.expects(:limit).with(20).returns(ModelStub.where(nil)) + ActiveRecord::Relation.any_instance.expects(:offset).with(0).returns(ModelStub.where(nil)) page = @klass.send :find_page, :per_page => 20, :pagination => true page.items @@ -79,7 +80,10 @@ def test_count_with_group end def test_disabled_pagination - ModelStub.expects(:find).with(:all, Not(has_entries(:limit => 20, :offset => 0))) + ActiveRecord::Relation.any_instance.expects(:count).never + ActiveRecord::Relation.any_instance.expects(:limit).never + ActiveRecord::Relation.any_instance.expects(:offset).never + ModelStub.expects(:count).never page = @klass.send :find_page, :per_page => 20, :pagination => false page.items end From c270db2d728a0a13096ad5fd8c882ebcfda10c0a Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 15 Jul 2013 15:19:33 +0200 Subject: [PATCH 2000/2024] fix bridges tests --- lib/active_scaffold/bridges/date_picker.rb | 2 +- test/bridges/bridge_test.rb | 50 +++++++++------------- test/bridges/company.rb | 5 --- test/const_mocker.rb | 28 ++++++------ 4 files changed, 34 insertions(+), 51 deletions(-) diff --git a/lib/active_scaffold/bridges/date_picker.rb b/lib/active_scaffold/bridges/date_picker.rb index ebc272a1ed..eed4795b3b 100644 --- a/lib/active_scaffold/bridges/date_picker.rb +++ b/lib/active_scaffold/bridges/date_picker.rb @@ -8,7 +8,7 @@ def self.install? ActiveScaffold.js_framework == :jquery && jquery_ui_included? end def self.jquery_ui_included? - Jquery::Rails.const_defined?('JQUERY_UI_VERSION') || Jquery.const_defined?('Ui') + Jquery::Rails.const_defined?('JQUERY_UI_VERSION') || Jquery.const_defined?('Ui') if Object.const_defined?('Jquery') end def self.localization "jQuery(function($){ diff --git a/test/bridges/bridge_test.rb b/test/bridges/bridge_test.rb index 7f39ff2236..7002df098b 100644 --- a/test/bridges/bridge_test.rb +++ b/test/bridges/bridge_test.rb @@ -3,7 +3,7 @@ def dbg; require "ruby-debug"; debugger; end; require File.join(File.dirname(__FILE__), '../test_helper.rb') -class Bridges::BridgeTest < Test::Unit::TestCase +class BridgeTest < Test::Unit::TestCase def setup @const_store = {} end @@ -12,36 +12,29 @@ def teardown end def test__shouldnt_throw_errors - ActiveScaffold::Bridge.run_all + ActiveScaffold::Bridges.run_all end def test__cds_bridge + js, ActiveScaffold.js_framework = ActiveScaffold.js_framework, :prototype ConstMocker.mock("CalendarDateSelect") do |cm| cm.remove assert(! bridge_will_be_installed("CalendarDateSelect")) cm.declare assert(bridge_will_be_installed("CalendarDateSelect")) end + ActiveScaffold.js_framework = js end def test__file_column_bridge ConstMocker.mock("FileColumn") do |cm| - cm.remove - assert(! bridge_will_be_installed("FileColumn")) + cm.remove + assert(! bridge_will_be_installed("FileColumn")) cm.declare assert(bridge_will_be_installed("FileColumn")) end end - def test__dependent_protect_bridge - ConstMocker.mock("DependentProtect") do |cm| - cm.remove - assert(! bridge_will_be_installed("DependentProtect")) - cm.declare - assert(bridge_will_be_installed("DependentProtect")) - end - end - def test__paperclip_bridge ConstMocker.mock("Paperclip") do |cm| cm.remove @@ -51,22 +44,21 @@ def test__paperclip_bridge end end - def test__unobtrusive_date_picker_bridge - ConstMocker.mock("UnobtrusiveDatePicker") do |cm| - cm.remove - assert(! bridge_will_be_installed("UnobtrusiveDatePicker")) - cm.declare - assert(bridge_will_be_installed("UnobtrusiveDatePicker")) + def test__date_picker_bridge + ConstMocker.mock("Jquery") do |jquery| + jquery.declare + ConstMocker.mock("Rails", jquery.const) do |rails| + rails.declare + ConstMocker.mock("Ui", jquery.const) do |cm| + cm.remove + assert(! bridge_will_be_installed("DatePicker")) + cm.declare + assert(bridge_will_be_installed("DatePicker")) + end + end end end - def test__validation_reflection_bridge - class << ActiveRecord::Base; undef_method :reflect_on_validations_for; end rescue nil - assert(! bridge_will_be_installed("ValidationReflection")) - class << ActiveRecord::Base; define_method :reflect_on_validations_for, lambda{}; end - assert(bridge_will_be_installed("ValidationReflection")) - end - def test__semantic_attributes_bridge ConstMocker.mock("SemanticAttributes") do |cm| cm.remove @@ -79,12 +71,12 @@ def test__semantic_attributes_bridge protected def find_bridge(name) - ActiveScaffold::Bridge.bridges.find{|b| b.name.to_s==name.to_s} + ActiveScaffold::Bridges[name.to_s.underscore.to_sym] end def bridge_will_be_installed(name) assert bridge=find_bridge(name), "No bridge found matching #{name}" - bridge.instance_variable_get("@install_if").call + bridge.install? end -end \ No newline at end of file +end diff --git a/test/bridges/company.rb b/test/bridges/company.rb index 0c84d163ed..e44fcf4e5b 100644 --- a/test/bridges/company.rb +++ b/test/bridges/company.rb @@ -1,7 +1,5 @@ require 'rubygems' require 'active_record' -require 'active_record/reflection' -require File.join(File.dirname(__FILE__), '../../lib/bridges/dependent_protect/lib/dependent_protect_bridge') # Mocking everything necesary to test the plugin. class Company @@ -44,9 +42,6 @@ def self.before_destroy(s=nil) @@before = s end - include ActiveRecord::Reflection - include DependentProtectSecurity - def self.has_many(association_id, options = {}) reflection = create_reflection(:has_many, association_id, options, self) end diff --git a/test/const_mocker.rb b/test/const_mocker.rb index 32e1b80379..76b629a5bb 100644 --- a/test/const_mocker.rb +++ b/test/const_mocker.rb @@ -1,30 +1,26 @@ class ConstMocker - def initialize(*const_names) - @const_names = const_names - @const_states = {} - @const_names.each{|const_name| - @const_states[const_name] = Object.const_defined?(const_name) ? Object.const_get(const_name) : nil - } + def initialize(const_name, parent = Object) + @parent = parent + @const_name = const_name + @const_state = nil + @const_state = @parent.const_defined?(@const_name) ? @parent.const_get(@const_name) : nil end def remove - @const_names.each{|const_name| - Object.send :remove_const, const_name if Object.const_defined?(const_name) - } + @parent.send :remove_const, @const_name if @parent.const_defined?(@const_name) end def declare - @const_names.each{|const_name| - Object.class_eval "class #{const_name}; end;" unless Object.const_defined?(const_name) - } + @parent.const_set @const_name, Class.new unless @parent.const_defined?(@const_name) end def restore remove - - @const_states.each_pair{|const_name, const| - Object.const_set const_name, const if const - } + @parent.const_set @const_name, @const_state if @const_state + end + + def const + @parent.const_get @const_name end def self.mock(*const_names, &block) From c8e0915df2f9bc6b52efbb24b5d51b150364da84 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Tue, 16 Jul 2013 01:53:49 -1000 Subject: [PATCH 2001/2024] move setting colspan before ater/before, sometimes changing colspan scrolls page --- app/assets/javascripts/jquery/active_scaffold.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 543f496d3a..6aaaa66d1d 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -1080,6 +1080,10 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ } var colspan = this.target.children().length; + if (content && this.position) { + content = jQuery(content); + content.find('.inline-adapter-cell:first').attr('colspan', colspan); + } if (this.position == 'after') { this.target.after(content); this.set_adapter(this.target.next()); @@ -1091,7 +1095,6 @@ ActiveScaffold.ActionLink.Record = ActiveScaffold.ActionLink.Abstract.extend({ else { return false; } - this.adapter.find('.inline-adapter-cell:first').attr('colspan', colspan); ActiveScaffold.highlight(this.adapter.find('td')); }, From 4de0e1073422719070727305d4853319d0321989 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 17 Jul 2013 11:17:08 +0200 Subject: [PATCH 2002/2024] fix searching when includes is set to nil --- CHANGELOG | 1 + lib/active_scaffold/data_structures/column.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index c37ddc1e06..4215d8f8fb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ - Allow to override select options in active_scaffold_search_select - Load effects from jQuery UI when using jquery-rails 3 gem - Fix searching on nested scaffolds (broken on 3.3.2) +- Fix searching when includes is set to nil = 3.3.2 - Fix subforms inside subforms diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index cd828c342a..eaa7b361c8 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -177,7 +177,7 @@ def calculation? def includes=(value) @includes = case value when Array then value - else [value] # automatically convert to an array + else Array(value) # automatically convert to an array end end From d5ab6938d5d059204e54336f2ae3e8b31a76b839 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 17 Jul 2013 11:27:52 +0200 Subject: [PATCH 2003/2024] fix searching when includes is set to nil --- lib/active_scaffold/data_structures/column.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/active_scaffold/data_structures/column.rb b/lib/active_scaffold/data_structures/column.rb index eaa7b361c8..a1dbab60be 100644 --- a/lib/active_scaffold/data_structures/column.rb +++ b/lib/active_scaffold/data_structures/column.rb @@ -177,7 +177,7 @@ def calculation? def includes=(value) @includes = case value when Array then value - else Array(value) # automatically convert to an array + else value ? [value] : value # not convert nil to [nil] end end From dbebeea07f1daafacb3a555dcf182b022bce057a Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 17 Jul 2013 12:05:40 +0200 Subject: [PATCH 2004/2024] test for setting nil in includes --- test/data_structures/column_test.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/data_structures/column_test.rb b/test/data_structures/column_test.rb index 88ff598fa5..0ad07a144f 100644 --- a/test/data_structures/column_test.rb +++ b/test/data_structures/column_test.rb @@ -181,5 +181,9 @@ def test_includes # make sure that when a non-array comes in, an array comes out @column.includes = [:column_name] assert_equal([:column_name], @column.includes) + + # make sure that when a non-array comes in, an array comes out + @column.includes = nil + assert_nil @column.includes end end From 0396a10fe69dc0ca6075be91eadd9cfd7281d9e3 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 17 Jul 2013 12:34:08 +0200 Subject: [PATCH 2005/2024] test validation reflection --- test/bridges/bridge_test.rb | 5 +- test/bridges/validation_reflection_test.rb | 57 ------------------- test/{bridges => }/company.rb | 12 ++-- .../validation_reflection_test.rb | 51 +++++++++++++++++ test/model_stub.rb | 1 - test/test_helper.rb | 2 +- 6 files changed, 57 insertions(+), 71 deletions(-) delete mode 100644 test/bridges/validation_reflection_test.rb rename test/{bridges => }/company.rb (87%) create mode 100644 test/data_structures/validation_reflection_test.rb diff --git a/test/bridges/bridge_test.rb b/test/bridges/bridge_test.rb index 7002df098b..95ed1a7e18 100644 --- a/test/bridges/bridge_test.rb +++ b/test/bridges/bridge_test.rb @@ -1,7 +1,4 @@ -def dbg; require "ruby-debug"; debugger; end; - -require File.join(File.dirname(__FILE__), '../test_helper.rb') - +require 'test_helper' class BridgeTest < Test::Unit::TestCase def setup diff --git a/test/bridges/validation_reflection_test.rb b/test/bridges/validation_reflection_test.rb deleted file mode 100644 index f838fea6bf..0000000000 --- a/test/bridges/validation_reflection_test.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'test/unit' -require File.join(File.dirname(__FILE__), 'company') -require File.join(File.dirname(__FILE__), '../../lib/bridges/validation_reflection/lib/validation_reflection_bridge') - -class ColumnWithValidationReflection < ActiveScaffold::DataStructures::Column - include ActiveScaffold::ValidationReflectionBridge -end - -class ValidationReflectionTest < Test::Unit::TestCase - def test_set_required_for_validates_presence_of - Company.expects(:reflect_on_validations_for).with(:name).returns([stub(:macro => :validates_presence_of)]) - column = ColumnWithValidationReflection.new(:name, Company) - assert column.required? - end - - def test_set_required_for_validates_inclusion_of - Company.expects(:reflect_on_validations_for).with(:name).returns([stub(:macro => :validates_inclusion_of, :options => {})]) - column = ColumnWithValidationReflection.new(:name, Company) - assert column.required? - end - - def test_not_set_required_for_validates_inclusion_of_and_allow_nil - Company.expects(:reflect_on_validations_for).with(:name).returns([stub(:macro => :validates_inclusion_of, :options => {:allow_nil => true})]) - column = ColumnWithValidationReflection.new(:name, Company) - assert !column.required? - end - - def test_not_set_required_for_validates_inclusion_of_and_allow_blank - Company.expects(:reflect_on_validations_for).with(:name).returns([stub(:macro => :validates_inclusion_of, :options => {:allow_blank => true})]) - column = ColumnWithValidationReflection.new(:name, Company) - assert !column.required? - end - - def test_not_set_required_for_no_validation - Company.expects(:reflect_on_validations_for).with(:name).returns([]) - column = ColumnWithValidationReflection.new(:name, Company) - assert !column.required? - end - - def test_set_required_for_validates_presence_of_in_association - Company.stubs(:reflect_on_validations_for).returns([stub(:macro => :validates_presence_of)], []) - column = ColumnWithValidationReflection.new(:main_company, Company) - assert column.required? - end - - def test_set_required_for_validates_presence_of_in_foreign_key - Company.stubs(:reflect_on_validations_for).returns([], [stub(:macro => :validates_presence_of)]) - column = ColumnWithValidationReflection.new(:main_company, Company) - assert column.required? - end - - def test_not_set_required_for_no_validation_in_association_neither_foreign_key - Company.stubs(:reflect_on_validations_for).returns([]) - column = ColumnWithValidationReflection.new(:main_company, Company) - assert !column.required? - end -end diff --git a/test/bridges/company.rb b/test/company.rb similarity index 87% rename from test/bridges/company.rb rename to test/company.rb index e44fcf4e5b..18085b738c 100644 --- a/test/bridges/company.rb +++ b/test/company.rb @@ -1,8 +1,4 @@ -require 'rubygems' -require 'active_record' - -# Mocking everything necesary to test the plugin. -class Company +class Company < ActiveRecord::Base def initialize(with_or_without = nil) @with_companies = with_or_without == :with_companies @with_company = with_or_without == :with_company @@ -51,9 +47,9 @@ def self.has_one(association_id, options = {}) def self.belongs_to(association_id, options = {}) reflection = create_reflection(:belongs_to, association_id, options, self) end - has_many :companies, :dependent => :protect - has_one :company, :dependent => :protect - belongs_to :main_company, :dependent => :protect, :class_name => 'Company' + has_many :companies + has_one :company + belongs_to :main_company, :class_name => 'Company' def companies if @with_companies diff --git a/test/data_structures/validation_reflection_test.rb b/test/data_structures/validation_reflection_test.rb new file mode 100644 index 0000000000..53c60556c8 --- /dev/null +++ b/test/data_structures/validation_reflection_test.rb @@ -0,0 +1,51 @@ +require 'test_helper' + +class ValidationReflectionTest < Test::Unit::TestCase + def test_set_required_for_validates_presence_of + column = ActiveScaffold::DataStructures::Column.new(:name, Company) + assert !column.required? + Company.expects(:validators_on).with(:name).returns([ActiveModel::Validations::PresenceValidator.new(:attributes => :name)]) + column = ActiveScaffold::DataStructures::Column.new(:name, Company) + assert column.required? + end + + def test_set_required_for_validates_inclusion_of + column = ActiveScaffold::DataStructures::Column.new(:name, Company) + assert !column.required? + Company.expects(:validators_on).with(:name).returns([ActiveModel::Validations::InclusionValidator.new(:attributes => :name, :in => [])]) + column = ActiveScaffold::DataStructures::Column.new(:name, Company) + assert column.required? + end + + def test_not_set_required_for_validates_inclusion_of_and_allow_nil + Company.expects(:validators_on).with(:name).returns([ActiveModel::Validations::InclusionValidator.new(:attributes => :name, :in => [], :allow_nil => true)]) + column = ActiveScaffold::DataStructures::Column.new(:name, Company) + assert !column.required? + end + + def test_not_set_required_for_validates_inclusion_of_and_allow_blank + Company.expects(:validators_on).with(:name).returns([ActiveModel::Validations::InclusionValidator.new(:attributes => :name, :in => [], :allow_blank => true)]) + column = ActiveScaffold::DataStructures::Column.new(:name, Company) + assert !column.required? + end + + def test_not_set_required_for_no_validation + Company.expects(:validators_on).with(:name).returns([]) + column = ActiveScaffold::DataStructures::Column.new(:name, Company) + assert !column.required? + end + + def test_set_required_for_validates_presence_of_in_association + column = ActiveScaffold::DataStructures::Column.new(:main_company, Company) + assert !column.required? + Company.expects(:validators_on).with(:main_company).returns([ActiveModel::Validations::PresenceValidator.new(:attributes => :main_company)]) + column = ActiveScaffold::DataStructures::Column.new(:main_company, Company) + assert column.required? + end + + def test_not_set_required_for_no_validation_in_association_neither_foreign_key + Company.expects(:validators_on).returns([]) + column = ActiveScaffold::DataStructures::Column.new(:main_company, Company) + assert !column.required? + end +end diff --git a/test/model_stub.rb b/test/model_stub.rb index a407b03e21..3ac3aa23ff 100644 --- a/test/model_stub.rb +++ b/test/model_stub.rb @@ -1,5 +1,4 @@ class ModelStub < ActiveRecord::Base - abstract_class = true has_one :other_model, :class_name => 'ModelStub' has_many :other_models, :class_name => 'ModelStub' diff --git a/test/test_helper.rb b/test/test_helper.rb index 671d3d422a..8f2834af06 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -24,7 +24,7 @@ def silence_stderr(&block) $stderr = stderr end -for file in %w[model_stub const_mocker] +for file in %w[model_stub const_mocker company] require File.join(File.dirname(__FILE__), file) end From 7916d9fff4b35be0e9f29a5a0f45bc166fbb1601 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 17 Jul 2013 13:54:26 +0200 Subject: [PATCH 2006/2024] fix bridge tests --- test/bridges/date_picker_test.rb | 29 ++++++++++++ test/bridges/paperclip_test.rb | 21 ++++----- test/bridges/tiny_mce_test.rb | 14 +++--- test/bridges/unobtrusive_date_picker_test.rb | 49 -------------------- test/company.rb | 10 ++++ 5 files changed, 56 insertions(+), 67 deletions(-) create mode 100644 test/bridges/date_picker_test.rb delete mode 100644 test/bridges/unobtrusive_date_picker_test.rb diff --git a/test/bridges/date_picker_test.rb b/test/bridges/date_picker_test.rb new file mode 100644 index 0000000000..812bdd5bdc --- /dev/null +++ b/test/bridges/date_picker_test.rb @@ -0,0 +1,29 @@ +require 'test/test_helper' +require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/date_picker/ext') +#require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/date_picker/helper') + +class DatePickerTest < ActionView::TestCase + include ActiveScaffold::Helpers::ViewHelpers + include ActiveScaffold::Bridges::DatePicker::Helper::FormColumnHelpers + include ActiveScaffold::Bridges::DatePicker::Helper::DatepickerColumnHelpers + + def setup + @controller.class.class_eval do + include ActiveScaffold::Finder + end + end + + def test_set_form_ui + config = ActiveScaffold::Config::Core.new(:company) + assert_equal nil, config.columns[:name].form_ui, 'form_ui for name' + assert_equal :date_picker, config.columns[:date].form_ui, 'form_ui for date' + assert_equal :datetime_picker, config.columns[:datetime].form_ui, 'form_ui for datetime' + end + + def test_form_ui + config = ActiveScaffold::Config::Core.new(:company) + @record = Company.new + assert active_scaffold_input_date_picker(config.columns[:date], :name => 'record[date]', :id => 'record_date') + assert active_scaffold_input_date_picker(config.columns[:datetime], :name => 'record[datetime]', :id => 'record_datetime') + end +end diff --git a/test/bridges/paperclip_test.rb b/test/bridges/paperclip_test.rb index 7ea697ed3a..c752193301 100644 --- a/test/bridges/paperclip_test.rb +++ b/test/bridges/paperclip_test.rb @@ -1,12 +1,11 @@ -require 'test/unit' -require File.join(File.dirname(__FILE__), 'company') -require File.join(File.dirname(__FILE__), '../../lib/bridges/paperclip/lib/paperclip_bridge') -require File.join(File.dirname(__FILE__), '../../lib/bridges/paperclip/lib/paperclip_bridge_helpers') -require File.join(File.dirname(__FILE__), '../../lib/bridges/paperclip/lib/form_ui') -require File.join(File.dirname(__FILE__), '../../lib/bridges/paperclip/lib/list_ui') +require 'test/test_helper' +require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/paperclip_bridge', __FILE__) +require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers', __FILE__) +require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/form_ui', __FILE__) +require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/list_ui', __FILE__) class PaperclipCore < ActiveScaffold::Config::Core - include ActiveScaffold::PaperclipBridge + include ActiveScaffold::Bridges::Paperclip::PaperclipBridge end class PaperclipTest < ActionView::TestCase @@ -49,10 +48,10 @@ def test_list_ui company = Company.new company.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => Company.attachment_definitions[:logo])) - assert_dom_equal '<a href="/system/file" onclick="window.open(this.href);return false;">file</a>', active_scaffold_column_paperclip(company, config.columns[:logo]) + assert_dom_equal '<a href="/system/file" data-popup="true" target="_blank">file</a>', active_scaffold_column_paperclip(company, config.columns[:logo]) company.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => {:thumbnail => '40x40'})) - assert_dom_equal '<a href="/system/file" onclick="window.open(this.href);return false;"><img src="/system/file" border="0" alt="File"/></a>', active_scaffold_column_paperclip(company, config.columns[:logo]) + assert_dom_equal '<a href="/system/file" data-popup="true" target="_blank"><img src="/system/file" border="0" alt="File"/></a>', active_scaffold_column_paperclip(company, config.columns[:logo]) end def test_form_ui @@ -60,9 +59,9 @@ def test_form_ui @record = Company.new @record.stubs(:logo).returns(stub(:file? => true, :original_filename => 'file', :url => '/system/file', :styles => Company.attachment_definitions[:logo])) - assert_dom_equal '<div><a href="/system/file" onclick="window.open(this.href);return false;">file</a>|<a href="#" onclick="$(this).next().value=\'true\'; $(this).up().hide().next().show(); return false;">Remove or Replace file</a><input name="record[delete_logo]" type="hidden" id="record_delete_logo" value="false" /></div><div style="display: none"><input name="record[logo]" size="30" type="file" id="record_logo" /></div>', active_scaffold_input_paperclip(config.columns[:logo], :name => 'record[logo]', :id => 'record_logo') + assert_dom_equal '<div><a href="/system/file" data-popup="true" target="_blank">file</a> | <input name="record[delete_logo]" type="hidden" id="record_delete_logo" value="false" /><a href="#" onclick="$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;">Remove or Replace file</a></div><div style="display: none"><input name="record[logo]" class="text-input" autocomplete="off" type="file" id="record_logo" /></div>', active_scaffold_input_paperclip(config.columns[:logo], :name => 'record[logo]', :id => 'record_logo') @record.stubs(:logo).returns(stub(:file? => false)) - assert_dom_equal '<input name="record[logo]" size="30" type="file" id="record_logo" />', active_scaffold_input_paperclip(config.columns[:logo], :name => 'record[logo]', :id => 'record_logo') + assert_dom_equal '<input name="record[logo]" class="text-input" autocomplete="off" type="file" id="record_logo" />', active_scaffold_input_paperclip(config.columns[:logo], :name => 'record[logo]', :id => 'record_logo') end end diff --git a/test/bridges/tiny_mce_test.rb b/test/bridges/tiny_mce_test.rb index 764e80ef40..f4f7b73f03 100644 --- a/test/bridges/tiny_mce_test.rb +++ b/test/bridges/tiny_mce_test.rb @@ -1,21 +1,21 @@ -require 'test/unit' -require File.join(File.dirname(__FILE__), 'company') -require File.join(File.dirname(__FILE__), '../../lib/bridges/tiny_mce/lib/tiny_mce_bridge') +require 'test/test_helper' +require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/tiny_mce/helpers') class TinyMceTest < ActionView::TestCase include ActiveScaffold::Helpers::ViewHelpers - include ActiveScaffold::TinyMceBridge + include ActiveScaffold::Bridges::TinyMce::Helpers def test_includes - assert_match /.*<script type="text\/javascript">.*ActiveScaffold\.ActionLink\.Abstract\.prototype\.close = function\(\).*<\/script>.*/m, active_scaffold_includes + ActiveScaffold::Bridges::TinyMce.expects(:install?).returns(true) + assert ActiveScaffold::Bridges.all_javascripts.include?("tinymce-jquery") end def test_form_ui - config = PaperclipCore.new(:company) + config = ActiveScaffold::Config::Core.new(:company) @record = Company.new self.expects(:request).returns(stub(:xhr? => true)) - assert_dom_equal "<textarea name=\"record[name]\" class=\"name-input mceEditor\" id=\"record_name\"></textarea><script type=\"text/javascript\">\n//<![CDATA[\ntinyMCE.execCommand('mceAddControl', false, 'record_name');\n//]]>\n</script>", active_scaffold_input_text_editor(config.columns[:name], :name => 'record[name]', :id => 'record_name', :class => 'name-input') + assert_dom_equal "<textarea name=\"record[name]\" class=\"name-input mceEditor\" id=\"record_name\">\n</textarea>\n<script type=\"text/javascript\">\n//<![CDATA[\ntinyMCE.settings = {\"theme\":\"simple\"};tinyMCE.execCommand('mceAddControl', false, 'record_name');\n//]]>\n</script>", active_scaffold_input_text_editor(config.columns[:name], :name => 'record[name]', :id => 'record_name', :class => 'name-input', :object => @record) end protected diff --git a/test/bridges/unobtrusive_date_picker_test.rb b/test/bridges/unobtrusive_date_picker_test.rb deleted file mode 100644 index 98ee3bfec6..0000000000 --- a/test/bridges/unobtrusive_date_picker_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'test/unit' -require File.join(File.dirname(__FILE__), 'company') -require File.join(File.dirname(__FILE__), '../../lib/bridges/unobtrusive_date_picker/lib/unobtrusive_date_picker_bridge') -require File.join(File.dirname(__FILE__), '../../lib/bridges/unobtrusive_date_picker/lib/view_helpers') -require File.join(File.dirname(__FILE__), '../../lib/bridges/unobtrusive_date_picker/lib/form_ui') - -class UDPCore < ActiveScaffold::Config::Core - include ActiveScaffold::UnobtrusiveDatePickerBridge -end - -class UnobtrusiveDatePickerTest < ActionView::TestCase - include ActiveScaffold::Helpers::ViewHelpers - include ActiveScaffold::UnobtrusiveDatePickerHelpers - - def test_set_form_ui - config = UDPCore.new(:company) - assert_equal nil, config.columns[:name].form_ui, 'form_ui for name' - assert_equal :datepicker, config.columns[:date].form_ui, 'form_ui for date' - assert_equal :datepicker, config.columns[:datetime].form_ui, 'form_ui for datetime' - end - - def test_stylesheets - assert active_scaffold_stylesheets.include?('datepicker.css') - end - - def test_javascripts - assert active_scaffold_javascripts.include?('datepicker.js') - assert active_scaffold_javascripts.include?('datepicker_lang/es.js') - end - - def test_form_ui - config = UDPCore.new(:company) - self.expects(:date_select).returns('') - self.expects(:date_picker).returns('') - assert active_scaffold_input_datepicker(config.columns[:date], :name => 'record[date]', :id => 'record_date') - - self.expects(:datetime_select).returns('') - self.expects(:date_picker).returns('') - assert active_scaffold_input_datepicker(config.columns[:datetime], :name => 'record[datetime]', :id => 'record_datetime') - end - - private - def unobtrusive_datepicker_stylesheets - ['datepicker.css'] - end - def unobtrusive_datepicker_javascripts - ['datepicker.js', 'datepicker_lang/es.js'] - end -end diff --git a/test/company.rb b/test/company.rb index 18085b738c..9c2d30f705 100644 --- a/test/company.rb +++ b/test/company.rb @@ -3,6 +3,8 @@ def initialize(with_or_without = nil) @with_companies = with_or_without == :with_companies @with_company = with_or_without == :with_company @with_main_company = with_or_without == :with_main_company + @attributes = {} + @attributes_cache = {} end def self.columns_hash @@ -69,4 +71,12 @@ def main_company def name end + + def date + Date.today + end + + def datetime + Time.now + end end From 452c7f81b77c55eb81ad1e6d866d0028fc366684 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 22 Jul 2013 10:10:19 +0200 Subject: [PATCH 2007/2024] fix tests for ruby 2 --- Gemfile | 2 +- Gemfile.lock | 7 +- test/bridges/date_picker_test.rb | 2 +- test/bridges/paperclip_test.rb | 2 +- test/bridges/tiny_mce_test.rb | 2 +- test/config/base_test.rb | 24 ++-- test/config/core_test.rb | 114 +++++++-------- test/config/create_test.rb | 108 +++++++------- test/config/delete_test.rb | 58 ++++---- test/config/field_search_test.rb | 86 ++++++------ test/config/list_test.rb | 234 ++++++++++++++++--------------- test/config/nested_test.rb | 94 +++++++------ test/config/search_test.rb | 112 +++++++-------- test/config/show_test.rb | 80 +++++------ test/config/subform_test.rb | 26 ++-- test/config/update_test.rb | 74 +++++----- test/test_helper.rb | 5 +- 17 files changed, 529 insertions(+), 501 deletions(-) diff --git a/Gemfile b/Gemfile index 1c08285b89..24478d943d 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,7 @@ end group :test do gem "shoulda", ">= 0" - gem "rcov", ">= 0" + gem "simplecov", ">= 0" gem "mocha" gem "rails", "~> 3.2.6" platforms :jruby do diff --git a/Gemfile.lock b/Gemfile.lock index 3646d0e6df..713e793a44 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -74,12 +74,15 @@ GEM rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (10.1.0) - rcov (0.9.9) rdoc (3.12.2) json (~> 1.4) rest-client (1.6.7) mime-types (>= 1.16) shoulda (2.11.3) + simplecov (0.7.1) + multi_json (~> 1.0) + simplecov-html (~> 0.7.1) + simplecov-html (0.7.1) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) @@ -105,7 +108,7 @@ DEPENDENCIES rack rails (~> 3.2.6) rake - rcov rdoc shoulda + simplecov sqlite3 diff --git a/test/bridges/date_picker_test.rb b/test/bridges/date_picker_test.rb index 812bdd5bdc..909521e6c9 100644 --- a/test/bridges/date_picker_test.rb +++ b/test/bridges/date_picker_test.rb @@ -1,4 +1,4 @@ -require 'test/test_helper' +require 'test_helper' require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/date_picker/ext') #require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/date_picker/helper') diff --git a/test/bridges/paperclip_test.rb b/test/bridges/paperclip_test.rb index c752193301..185d218561 100644 --- a/test/bridges/paperclip_test.rb +++ b/test/bridges/paperclip_test.rb @@ -1,4 +1,4 @@ -require 'test/test_helper' +require 'test_helper' require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/paperclip_bridge', __FILE__) require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers', __FILE__) require File.expand_path('../../../lib/active_scaffold/bridges/paperclip/form_ui', __FILE__) diff --git a/test/bridges/tiny_mce_test.rb b/test/bridges/tiny_mce_test.rb index f4f7b73f03..ad91e88659 100644 --- a/test/bridges/tiny_mce_test.rb +++ b/test/bridges/tiny_mce_test.rb @@ -1,4 +1,4 @@ -require 'test/test_helper' +require 'test_helper' require File.join(File.dirname(__FILE__), '../../lib/active_scaffold/bridges/tiny_mce/helpers') class TinyMceTest < ActionView::TestCase diff --git a/test/config/base_test.rb b/test/config/base_test.rb index 85312d8180..347e69b2f1 100644 --- a/test/config/base_test.rb +++ b/test/config/base_test.rb @@ -1,15 +1,17 @@ require 'test_helper' -class Config::BaseTest < Test::Unit::TestCase - def setup - @base = ActiveScaffold::Config::Base.new(ActiveScaffold::Config::Core.new(:model_stub)) - end - - def test_formats - assert_equal [], @base.formats - @base.formats << :pdf - assert_equal [:pdf], @base.formats - @base.formats = [:html] - assert_equal [:html], @base.formats +module Config + class BaseTest < Test::Unit::TestCase + def setup + @base = ActiveScaffold::Config::Base.new(ActiveScaffold::Config::Core.new(:model_stub)) + end + + def test_formats + assert_equal [], @base.formats + @base.formats << :pdf + assert_equal [:pdf], @base.formats + @base.formats = [:html] + assert_equal [:html], @base.formats + end end end diff --git a/test/config/core_test.rb b/test/config/core_test.rb index c6c0a2f10c..a03907aae8 100644 --- a/test/config/core_test.rb +++ b/test/config/core_test.rb @@ -1,62 +1,64 @@ require 'test_helper' -class Config::CoreTest < Test::Unit::TestCase - class ModelStubsController < ActionController::Base; end - def setup - @config = ActiveScaffold::Config::Core.new :model_stub - ModelStubsController.instance_variable_set :@active_scaffold_config, @config - end - - def test_default_options - assert !@config.add_sti_create_links? - assert !@config.sti_children - assert_equal [:create, :list, :search, :update, :delete, :show, :nested, :subform], @config.actions.to_a - assert_equal :default, @config.frontend - assert_equal :default, @config.theme - assert_equal 'Model stub', @config.label(:count => 1) - assert_equal 'ModelStubs', @config.label - end - - def test_add_sti_children - @config.sti_create_links = true - assert !@config.add_sti_create_links? - @config.sti_children = [:a] - assert @config.add_sti_create_links? - end - - def test_sti_children - @config.sti_children = [:a] - assert_equal [:a], @config.sti_children - end - - def test_actions - assert @config.actions.include?(:create) - @config.actions = [:list] - assert !@config.actions.include?(:create) - assert_equal [:list], @config.actions.to_a - end - - def test_form_ui_in_sti - @config.columns << :type +module Config + class CoreTest < Test::Unit::TestCase + class ModelStubsController < ActionController::Base; end + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + ModelStubsController.instance_variable_set :@active_scaffold_config, @config + end - @config.sti_create_links = false - @config.sti_children = [:model_stub] - @config._configure_sti - assert_equal :select, @config.columns[:type].form_ui - assert_equal [['Model stub', 'ModelStub']], @config.columns[:type].options[:options] + def test_default_options + assert !@config.add_sti_create_links? + assert !@config.sti_children + assert_equal [:create, :list, :search, :update, :delete, :show, :nested, :subform], @config.actions.to_a + assert_equal :default, @config.frontend + assert_equal :default, @config.theme + assert_equal 'Model stub', @config.label(:count => 1) + assert_equal 'ModelStubs', @config.label + end - @config.columns[:type].form_ui = nil - @config.sti_create_links = true - @config._configure_sti - assert_equal :hidden, @config.columns[:type].form_ui - end - - def test_sti_children_links - @config.sti_children = [:model_stub] - @config.sti_create_links = true - @config.action_links.add @config.create.link - ModelStubsController.send(:_add_sti_create_links) - assert_equal 'Create Model stub', @config.action_links[:new].label - assert_equal 'config/core_test/model_stubs', @config.action_links[:new].parameters[:parent_sti] + def test_add_sti_children + @config.sti_create_links = true + assert !@config.add_sti_create_links? + @config.sti_children = [:a] + assert @config.add_sti_create_links? + end + + def test_sti_children + @config.sti_children = [:a] + assert_equal [:a], @config.sti_children + end + + def test_actions + assert @config.actions.include?(:create) + @config.actions = [:list] + assert !@config.actions.include?(:create) + assert_equal [:list], @config.actions.to_a + end + + def test_form_ui_in_sti + @config.columns << :type + + @config.sti_create_links = false + @config.sti_children = [:model_stub] + @config._configure_sti + assert_equal :select, @config.columns[:type].form_ui + assert_equal [['Model stub', 'ModelStub']], @config.columns[:type].options[:options] + + @config.columns[:type].form_ui = nil + @config.sti_create_links = true + @config._configure_sti + assert_equal :hidden, @config.columns[:type].form_ui + end + + def test_sti_children_links + @config.sti_children = [:model_stub] + @config.sti_create_links = true + @config.action_links.add @config.create.link + ModelStubsController.send(:_add_sti_create_links) + assert_equal 'Create Model stub', @config.action_links[:new].label + assert_equal 'config/core_test/model_stubs', @config.action_links[:new].parameters[:parent_sti] + end end end diff --git a/test/config/create_test.rb b/test/config/create_test.rb index b9cc88096d..ebe51b1563 100644 --- a/test/config/create_test.rb +++ b/test/config/create_test.rb @@ -1,58 +1,60 @@ require 'test_helper' -class Config::CreateTest < Test::Unit::TestCase - def setup - @config = ActiveScaffold::Config::Core.new :model_stub - @default_link = @config.create.link - end - - def teardown - @config.create.link = @default_link - end - - def test_default_options - assert !@config.create.persistent - assert @config.create.action_after_create.nil? - assert_equal 'Create Model stub', @config.create.label - end +module Config + class CreateTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + @default_link = @config.create.link + end + + def teardown + @config.create.link = @default_link + end + + def test_default_options + assert !@config.create.persistent + assert @config.create.action_after_create.nil? + assert_equal 'Create Model stub', @config.create.label + end - def test_link_defaults - link = @config.create.link - assert !link.page? - assert !link.popup? - assert !link.confirm? - assert_equal "new", link.action - assert_equal "Create New", link.label - assert link.inline? - blank = {} - assert_equal blank, link.html_options - assert_equal :get, link.method - assert_equal :collection, link.type - assert_equal :create, link.crud_type - assert_equal :create_authorized?, link.security_method - end - - def test_setting_link - @config.create.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys') - assert_not_equal(@default_link, @config.create.link) - end - - def test_label - label = 'create new monkeys' - @config.create.label = label - assert_equal label, @config.create.label - I18n.backend.store_translations :en, :active_scaffold => {:create_new_model => 'Create new %{model}'} - @config.create.label = :create_new_model - assert_equal 'Create new Model stub', @config.create.label - end - - def test_persistent - @config.create.persistent = true - assert @config.create.persistent - end - - def test_action_after_create - @config.create.action_after_create = :edit - assert_equal :edit, @config.create.action_after_create + def test_link_defaults + link = @config.create.link + assert !link.page? + assert !link.popup? + assert !link.confirm? + assert_equal "new", link.action + assert_equal "Create New", link.label + assert link.inline? + blank = {} + assert_equal blank, link.html_options + assert_equal :get, link.method + assert_equal :collection, link.type + assert_equal :create, link.crud_type + assert_equal :create_authorized?, link.security_method + end + + def test_setting_link + @config.create.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys') + assert_not_equal(@default_link, @config.create.link) + end + + def test_label + label = 'create new monkeys' + @config.create.label = label + assert_equal label, @config.create.label + I18n.backend.store_translations :en, :active_scaffold => {:create_new_model => 'Create new %{model}'} + @config.create.label = :create_new_model + assert_equal 'Create new Model stub', @config.create.label + end + + def test_persistent + @config.create.persistent = true + assert @config.create.persistent + end + + def test_action_after_create + @config.create.action_after_create = :edit + assert_equal :edit, @config.create.action_after_create + end end end diff --git a/test/config/delete_test.rb b/test/config/delete_test.rb index d9be5f7fc0..6218b992c2 100644 --- a/test/config/delete_test.rb +++ b/test/config/delete_test.rb @@ -1,33 +1,35 @@ require 'test_helper' -class Config::DeleteTest < Test::Unit::TestCase - def setup - @config = ActiveScaffold::Config::Core.new :model_stub - @default_link = @config.delete.link - end - - def teardown - @config.delete.link = @default_link - end +module Config + class DeleteTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + @default_link = @config.delete.link + end + + def teardown + @config.delete.link = @default_link + end - def test_link_defaults - link = @config.delete.link - assert !link.page? - assert !link.popup? - assert link.confirm? - assert_equal "destroy", link.action - assert_equal "Delete", link.label - assert link.inline? - blank = {} - assert_equal blank, link.html_options - assert_equal :delete, link.method - assert_equal :member, link.type - assert_equal :delete, link.crud_type - assert_equal :delete_authorized?, link.security_method - end - - def test_setting_link - @config.delete.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys') - assert_not_equal(@default_link, @config.delete.link) + def test_link_defaults + link = @config.delete.link + assert !link.page? + assert !link.popup? + assert link.confirm? + assert_equal "destroy", link.action + assert_equal "Delete", link.label + assert link.inline? + blank = {} + assert_equal blank, link.html_options + assert_equal :delete, link.method + assert_equal :member, link.type + assert_equal :delete, link.crud_type + assert_equal :delete_authorized?, link.security_method + end + + def test_setting_link + @config.delete.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys') + assert_not_equal(@default_link, @config.delete.link) + end end end diff --git a/test/config/field_search_test.rb b/test/config/field_search_test.rb index 2bcdb3546d..ec0c9954cf 100644 --- a/test/config/field_search_test.rb +++ b/test/config/field_search_test.rb @@ -1,47 +1,49 @@ require 'test_helper' -class Config::FieldSearchTest < Test::Unit::TestCase - def setup - @config = ActiveScaffold::Config::Core.new :model_stub - @config.actions.swap :search, :field_search - @default_link = @config.field_search.link - end - - def teardown - @config.field_search.link = @default_link - end - - def test_default_options - assert_equal :full, @config.field_search.text_search - end - - def test_text_search - @config.field_search.text_search = :start - assert_equal :start, @config.field_search.text_search - @config.field_search.text_search = :end - assert_equal :end, @config.field_search.text_search - @config.field_search.text_search = false - assert !@config.field_search.text_search - end +module Config + class FieldSearchTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + @config.actions.swap :search, :field_search + @default_link = @config.field_search.link + end + + def teardown + @config.field_search.link = @default_link + end + + def test_default_options + assert_equal :full, @config.field_search.text_search + end + + def test_text_search + @config.field_search.text_search = :start + assert_equal :start, @config.field_search.text_search + @config.field_search.text_search = :end + assert_equal :end, @config.field_search.text_search + @config.field_search.text_search = false + assert !@config.field_search.text_search + end - def test_link_defaults - link = @config.field_search.link - assert !link.page? - assert !link.popup? - assert !link.confirm? - assert_equal "show_search", link.action - assert_equal "Search", link.label - assert link.inline? - blank = {} - assert_equal blank, link.html_options - assert_equal :get, link.method - assert_equal :collection, link.type - assert_equal :read, link.crud_type - assert_equal :search_authorized?, link.security_method - end - - def test_setting_link - @config.field_search.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys') - assert_not_equal(@default_link, @config.field_search.link) + def test_link_defaults + link = @config.field_search.link + assert !link.page? + assert !link.popup? + assert !link.confirm? + assert_equal "show_search", link.action + assert_equal "Search", link.label + assert link.inline? + blank = {} + assert_equal blank, link.html_options + assert_equal :get, link.method + assert_equal :collection, link.type + assert_equal :read, link.crud_type + assert_equal :search_authorized?, link.security_method + end + + def test_setting_link + @config.field_search.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys') + assert_not_equal(@default_link, @config.field_search.link) + end end end diff --git a/test/config/list_test.rb b/test/config/list_test.rb index e3634fffed..b5da0bc62f 100644 --- a/test/config/list_test.rb +++ b/test/config/list_test.rb @@ -1,123 +1,125 @@ require 'test_helper' -class Config::ListTest < Test::Unit::TestCase - def setup - @config = ActiveScaffold::Config::Core.new :model_stub - end +module Config + class ListTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + end - def test_label - I18n.backend.store_translations :en, :active_scaffold => {:resource => {:one => 'Resource', :other => 'Resources'}} - @config.list.label = :resource - assert_equal 'Resources', @config.list.label - label = 'monkeys' - @config.list.label = label - assert_equal label, @config.list.label - end + def test_label + I18n.backend.store_translations :en, :active_scaffold => {:resource => {:one => 'Resource', :other => 'Resources'}} + @config.list.label = :resource + assert_equal 'Resources', @config.list.label + label = 'monkeys' + @config.list.label = label + assert_equal label, @config.list.label + end - def test_default_options - assert_equal 15, @config.list.per_page - assert_equal 2, @config.list.page_links_inner_window - assert_equal '-', @config.list.empty_field_text - assert_equal ', ', @config.list.association_join_text - assert_equal true, @config.list.pagination - assert_equal 'search', @config.list.search_partial - assert_equal :no_entries, @config.list.no_entries_message - assert_equal :filtered, @config.list.filtered_message - assert !@config.list.always_show_create - assert !@config.list.always_show_search - assert @config.list.count_includes.nil? - assert_equal 'ModelStubs', @config.list.label - assert @config.list.sorting.sorts_on?(:id) - assert_equal 'ASC', @config.list.sorting.direction_of(:id) - end - - def test_empty_field_text - @config.list.empty_field_text = '(missing)' - assert_equal '(missing)', @config.list.empty_field_text - end - - def test_association_join_text - @config.list.association_join_text = '<br/>' - assert_equal '<br/>', @config.list.association_join_text - end - - def test_no_entries - @config.list.no_entries_message = 'No items' - assert_equal 'No items', @config.list.no_entries_message - end - - def test_filtered_message - @config.list.filtered_message = 'filtered items' - assert_equal 'filtered items', @config.list.filtered_message - end - - def test_pagination - @config.list.pagination = :infinite - assert_equal :infinite, @config.list.pagination - @config.list.pagination = false - assert !@config.list.pagination - end - - def test_sorting - @config.list.sorting = {:a => :desc} - assert @config.list.sorting.sorts_on?(:a) - assert_equal 'DESC', @config.list.sorting.direction_of(:a) - assert !@config.list.sorting.sorts_on?(:id) + def test_default_options + assert_equal 15, @config.list.per_page + assert_equal 2, @config.list.page_links_inner_window + assert_equal '-', @config.list.empty_field_text + assert_equal ', ', @config.list.association_join_text + assert_equal true, @config.list.pagination + assert_equal 'search', @config.list.search_partial + assert_equal :no_entries, @config.list.no_entries_message + assert_equal :filtered, @config.list.filtered_message + assert !@config.list.always_show_create + assert !@config.list.always_show_search + assert @config.list.count_includes.nil? + assert_equal 'ModelStubs', @config.list.label + assert @config.list.sorting.sorts_on?(:id) + assert_equal 'ASC', @config.list.sorting.direction_of(:id) + end - @config.list.sorting = [{:a => :asc}, {:b => :desc}] - assert @config.list.sorting.sorts_on?(:a) - assert_equal 'ASC', @config.list.sorting.direction_of(:a) - assert @config.list.sorting.sorts_on?(:b) - assert_equal 'DESC', @config.list.sorting.direction_of(:b) - assert !@config.list.sorting.sorts_on?(:id) - end - - def test_per_page - per_page = 35 - @config.list.per_page = per_page - assert_equal per_page, @config.list.per_page - end - - def test_page_links_window - page_links_window = 3 - @config.list.page_links_inner_window = page_links_window - assert_equal page_links_window, @config.list.page_links_inner_window - end - - def test_always_show_create - always_show_create = true - @config.list.always_show_create = always_show_create - assert_equal always_show_create, @config.list.always_show_create - end - - def test_always_show_create_when_create_is_not_enabled - always_show_create = true - @config.list.always_show_create = always_show_create - @config.actions.exclude :create - assert_equal false, @config.list.always_show_create - end - - def test_always_show_search - @config.list.always_show_search = true - assert @config.list.always_show_search - assert_equal 'search', @config.list.search_partial - end - - def test_always_show_search_when_search_is_not_enabled - @config.list.always_show_search = true - @config.actions.exclude :search - assert_equal false, @config.list.always_show_search - end - - def test_always_show_search_when_field_search - @config.list.always_show_search = true - @config.actions.swap :search, :field_search - assert @config.list.always_show_search - assert_equal 'field_search', @config.list.search_partial - end - - def test_count_includes - @config.list.count_includes = [:assoc_1, :assoc_2] - assert_equal [:assoc_1, :assoc_2], @config.list.count_includes + def test_empty_field_text + @config.list.empty_field_text = '(missing)' + assert_equal '(missing)', @config.list.empty_field_text + end + + def test_association_join_text + @config.list.association_join_text = '<br/>' + assert_equal '<br/>', @config.list.association_join_text + end + + def test_no_entries + @config.list.no_entries_message = 'No items' + assert_equal 'No items', @config.list.no_entries_message + end + + def test_filtered_message + @config.list.filtered_message = 'filtered items' + assert_equal 'filtered items', @config.list.filtered_message + end + + def test_pagination + @config.list.pagination = :infinite + assert_equal :infinite, @config.list.pagination + @config.list.pagination = false + assert !@config.list.pagination + end + + def test_sorting + @config.list.sorting = {:a => :desc} + assert @config.list.sorting.sorts_on?(:a) + assert_equal 'DESC', @config.list.sorting.direction_of(:a) + assert !@config.list.sorting.sorts_on?(:id) + + @config.list.sorting = [{:a => :asc}, {:b => :desc}] + assert @config.list.sorting.sorts_on?(:a) + assert_equal 'ASC', @config.list.sorting.direction_of(:a) + assert @config.list.sorting.sorts_on?(:b) + assert_equal 'DESC', @config.list.sorting.direction_of(:b) + assert !@config.list.sorting.sorts_on?(:id) + end + + def test_per_page + per_page = 35 + @config.list.per_page = per_page + assert_equal per_page, @config.list.per_page + end + + def test_page_links_window + page_links_window = 3 + @config.list.page_links_inner_window = page_links_window + assert_equal page_links_window, @config.list.page_links_inner_window + end + + def test_always_show_create + always_show_create = true + @config.list.always_show_create = always_show_create + assert_equal always_show_create, @config.list.always_show_create + end + + def test_always_show_create_when_create_is_not_enabled + always_show_create = true + @config.list.always_show_create = always_show_create + @config.actions.exclude :create + assert_equal false, @config.list.always_show_create + end + + def test_always_show_search + @config.list.always_show_search = true + assert @config.list.always_show_search + assert_equal 'search', @config.list.search_partial + end + + def test_always_show_search_when_search_is_not_enabled + @config.list.always_show_search = true + @config.actions.exclude :search + assert_equal false, @config.list.always_show_search + end + + def test_always_show_search_when_field_search + @config.list.always_show_search = true + @config.actions.swap :search, :field_search + assert @config.list.always_show_search + assert_equal 'field_search', @config.list.search_partial + end + + def test_count_includes + @config.list.count_includes = [:assoc_1, :assoc_2] + assert_equal [:assoc_1, :assoc_2], @config.list.count_includes + end end end diff --git a/test/config/nested_test.rb b/test/config/nested_test.rb index e5158a7f9d..f02f4cb557 100644 --- a/test/config/nested_test.rb +++ b/test/config/nested_test.rb @@ -1,52 +1,54 @@ require 'test_helper' -class Config::NestedTest < Test::Unit::TestCase - class ModelStubsController < ActionController::Base - active_scaffold - end +module Config + class NestedTest < Test::Unit::TestCase + class ModelStubsController < ActionController::Base + active_scaffold + end - def setup - @config = ActiveScaffold::Config::Core.new(:model_stub) - end - - def test_default_options - assert @config.nested.shallow_delete - assert_equal 'Add Existing Model stub', @config.nested.label - end - - def test_label - label = 'nested monkeys' - @config.nested.label = label - assert_equal label, @config.nested.label - I18n.backend.store_translations :en, :active_scaffold => {:create_model => 'Add new %{model}'} - @config.nested.label = :create_model - assert_equal 'Add new Model stub', @config.nested.label - end - - def test_shallow_delete - @config.nested.shallow_delete = true - assert @config.nested.shallow_delete - end - - def test_add_link - assert_raise(ArgumentError) { @config.nested.add_link :assoc_1 } - config = @config - ModelStubsController.class_eval do - config.configure { nested.add_link :other_models } + def setup + @config = ActiveScaffold::Config::Core.new(:model_stub) + end + + def test_default_options + assert @config.nested.shallow_delete + assert_equal 'Add Existing Model stub', @config.nested.label + end + + def test_label + label = 'nested monkeys' + @config.nested.label = label + assert_equal label, @config.nested.label + I18n.backend.store_translations :en, :active_scaffold => {:create_model => 'Add new %{model}'} + @config.nested.label = :create_model + assert_equal 'Add new Model stub', @config.nested.label + end + + def test_shallow_delete + @config.nested.shallow_delete = true + assert @config.nested.shallow_delete + end + + def test_add_link + assert_raise(ArgumentError) { @config.nested.add_link :assoc_1 } + config = @config + ModelStubsController.class_eval do + config.configure { nested.add_link :other_models } + end + link = @config.action_links['index'] + assert_equal 'ModelStubs', link.label + assert_equal 'index', link.action + assert_equal :after, link.position + assert !link.page? + assert !link.popup? + assert !link.confirm? + assert link.inline? + assert link.refresh_on_close + assert_equal :other_models, link.parameters[:association] + assert_equal :get, link.method + assert_equal :member, link.type + assert_equal :read, link.crud_type + assert_equal :nested_authorized?, link.security_method end - link = @config.action_links['index'] - assert_equal 'ModelStubs', link.label - assert_equal 'index', link.action - assert_equal :after, link.position - assert !link.page? - assert !link.popup? - assert !link.confirm? - assert link.inline? - assert link.refresh_on_close - assert_equal :other_models, link.parameters[:association] - assert_equal :get, link.method - assert_equal :member, link.type - assert_equal :read, link.crud_type - assert_equal :nested_authorized?, link.security_method end end diff --git a/test/config/search_test.rb b/test/config/search_test.rb index 9478b5fdbb..426059b13e 100644 --- a/test/config/search_test.rb +++ b/test/config/search_test.rb @@ -1,60 +1,62 @@ require 'test_helper' -class Config::SearchTest < Test::Unit::TestCase - def setup - @config = ActiveScaffold::Config::Core.new :model_stub - @default_link = @config.search.link - end - - def teardown - @config.search.link = @default_link - end - - def test_default_options - assert_equal :full, @config.search.text_search - assert !@config.search.live? - assert_equal ' ', @config.search.split_terms - end - - def test_text_search - @config.search.text_search = :start - assert_equal :start, @config.search.text_search - @config.search.text_search = :end - assert_equal :end, @config.search.text_search - @config.search.text_search = false - assert !@config.search.text_search - end - - def test_live - @config.search.live = true - assert @config.search.live? - end - - def test_split_terms - @config.search.split_terms = nil - assert @config.search.split_terms.nil? - @config.search.split_terms = ',' - assert_equal ',', @config.search.split_terms - end +module Config + class SearchTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + @default_link = @config.search.link + end + + def teardown + @config.search.link = @default_link + end + + def test_default_options + assert_equal :full, @config.search.text_search + assert !@config.search.live? + assert_equal ' ', @config.search.split_terms + end + + def test_text_search + @config.search.text_search = :start + assert_equal :start, @config.search.text_search + @config.search.text_search = :end + assert_equal :end, @config.search.text_search + @config.search.text_search = false + assert !@config.search.text_search + end + + def test_live + @config.search.live = true + assert @config.search.live? + end + + def test_split_terms + @config.search.split_terms = nil + assert @config.search.split_terms.nil? + @config.search.split_terms = ',' + assert_equal ',', @config.search.split_terms + end - def test_link_defaults - link = @config.search.link - assert !link.page? - assert !link.popup? - assert !link.confirm? - assert_equal "show_search", link.action - assert_equal "Search", link.label - assert link.inline? - blank = {} - assert_equal blank, link.html_options - assert_equal :get, link.method - assert_equal :collection, link.type - assert_equal :read, link.crud_type - assert_equal :search_authorized?, link.security_method - end - - def test_setting_link - @config.search.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys') - assert_not_equal(@default_link, @config.search.link) + def test_link_defaults + link = @config.search.link + assert !link.page? + assert !link.popup? + assert !link.confirm? + assert_equal "show_search", link.action + assert_equal "Search", link.label + assert link.inline? + blank = {} + assert_equal blank, link.html_options + assert_equal :get, link.method + assert_equal :collection, link.type + assert_equal :read, link.crud_type + assert_equal :search_authorized?, link.security_method + end + + def test_setting_link + @config.search.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys') + assert_not_equal(@default_link, @config.search.link) + end end end diff --git a/test/config/show_test.rb b/test/config/show_test.rb index 4a0aad9ff6..408fb57ca4 100644 --- a/test/config/show_test.rb +++ b/test/config/show_test.rb @@ -1,43 +1,45 @@ require 'test_helper' -class Config::ShowTest < Test::Unit::TestCase - def setup - @config = ActiveScaffold::Config::Core.new :model_stub - @default_link = @config.show.link - end - - def teardown - @config.show.link = @default_link - end - - def test_link_defaults - link = @config.show.link - assert !link.page? - assert !link.popup? - assert !link.confirm? - assert_equal "show", link.action - assert_equal "Show", link.label - assert link.inline? - blank = {} - assert_equal blank, link.html_options - assert_equal :get, link.method - assert_equal :member, link.type - assert_equal :read, link.crud_type - assert_equal :show_authorized?, link.security_method - end - - def test_setting_link - @config.show.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys') - assert_not_equal(@default_link, @config.show.link) - end - - def test_label - label = 'show monkeys' - @config.show.label = label - assert_equal label, @config.show.label - I18n.backend.store_translations :en, :active_scaffold => {:view_model => 'View %{model}'} - @config.show.label = :view_model - assert_equal 'View Model stub', @config.show.label - assert_equal 'View record', @config.show.label('record') +module Config + class ShowTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + @default_link = @config.show.link + end + + def teardown + @config.show.link = @default_link + end + + def test_link_defaults + link = @config.show.link + assert !link.page? + assert !link.popup? + assert !link.confirm? + assert_equal "show", link.action + assert_equal "Show", link.label + assert link.inline? + blank = {} + assert_equal blank, link.html_options + assert_equal :get, link.method + assert_equal :member, link.type + assert_equal :read, link.crud_type + assert_equal :show_authorized?, link.security_method + end + + def test_setting_link + @config.show.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys') + assert_not_equal(@default_link, @config.show.link) + end + + def test_label + label = 'show monkeys' + @config.show.label = label + assert_equal label, @config.show.label + I18n.backend.store_translations :en, :active_scaffold => {:view_model => 'View %{model}'} + @config.show.label = :view_model + assert_equal 'View Model stub', @config.show.label + assert_equal 'View record', @config.show.label('record') + end end end diff --git a/test/config/subform_test.rb b/test/config/subform_test.rb index 6adf484506..27ccc17be3 100644 --- a/test/config/subform_test.rb +++ b/test/config/subform_test.rb @@ -1,17 +1,19 @@ require 'test_helper' -class Config::SubformTest < Test::Unit::TestCase - def setup - @config = ActiveScaffold::Config::Core.new :model_stub - end +module Config + class SubformTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + end - def test_defaults - assert_equal :horizontal, @config.subform.layout - end - - def test_setting_layout - layout = :vertical - @config.subform.layout = layout - assert_equal layout, @config.subform.layout + def test_defaults + assert_equal :horizontal, @config.subform.layout + end + + def test_setting_layout + layout = :vertical + @config.subform.layout = layout + assert_equal layout, @config.subform.layout + end end end diff --git a/test/config/update_test.rb b/test/config/update_test.rb index f21e9241fb..5f49a851fa 100644 --- a/test/config/update_test.rb +++ b/test/config/update_test.rb @@ -1,40 +1,42 @@ require 'test_helper' -class Config::UpdateTest < Test::Unit::TestCase - def setup - @config = ActiveScaffold::Config::Core.new :model_stub - end - - def test__params_for_columns__returns_all_params - @config._load_action_columns - @config.columns[:a].params.add :keep_a, :a_temp - assert @config.columns[:a].params.include?(:keep_a) - assert @config.columns[:a].params.include?(:a_temp) - end - - def test_default_options - assert !@config.update.persistent - assert !@config.update.nested_links - assert_equal 'Model stub', @config.update.label - end - - def test_persistent - @config.update.persistent = true - assert @config.update.persistent - end - - def test_nested_links - @config.update.nested_links = true - assert @config.update.nested_links - end - - def test_label - label = 'update new monkeys' - @config.update.label = label - assert_equal label, @config.update.label - I18n.backend.store_translations :en, :active_scaffold => {:change_model => 'Change %{model}'} - @config.update.label = :change_model - assert_equal 'Change Model stub', @config.update.label - assert_equal 'Change record', @config.update.label('record') +module Config + class UpdateTest < Test::Unit::TestCase + def setup + @config = ActiveScaffold::Config::Core.new :model_stub + end + + def test__params_for_columns__returns_all_params + @config._load_action_columns + @config.columns[:a].params.add :keep_a, :a_temp + assert @config.columns[:a].params.include?(:keep_a) + assert @config.columns[:a].params.include?(:a_temp) + end + + def test_default_options + assert !@config.update.persistent + assert !@config.update.nested_links + assert_equal 'Model stub', @config.update.label + end + + def test_persistent + @config.update.persistent = true + assert @config.update.persistent + end + + def test_nested_links + @config.update.nested_links = true + assert @config.update.nested_links + end + + def test_label + label = 'update new monkeys' + @config.update.label = label + assert_equal label, @config.update.label + I18n.backend.store_translations :en, :active_scaffold => {:change_model => 'Change %{model}'} + @config.update.label = :change_model + assert_equal 'Change Model stub', @config.update.label + assert_equal 'Change record', @config.update.label('record') + end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 8f2834af06..bd4acf2bee 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,7 @@ +require 'simplecov' +SimpleCov.start + ENV['RAILS_ENV'] = 'test' -$:.unshift File.dirname(__FILE__) require "mock_app/config/environment" require 'rails/test_help' require 'active_scaffold' @@ -36,3 +38,4 @@ def config_for(klass, namespace = nil) ActiveScaffold::Config::Core.new("#{namespace}#{klass.to_s.underscore.downcase}") end end +Object.send :remove_const, :Config From ccb8171f5dd4d899271643be03d26367e62eb16b Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Mon, 22 Jul 2013 11:30:49 +0200 Subject: [PATCH 2008/2024] fix tests on ruby 2 --- test/const_mocker.rb | 8 ++++---- test/test_helper.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/const_mocker.rb b/test/const_mocker.rb index 76b629a5bb..c25a9f3262 100644 --- a/test/const_mocker.rb +++ b/test/const_mocker.rb @@ -11,7 +11,7 @@ def remove end def declare - @parent.const_set @const_name, Class.new unless @parent.const_defined?(@const_name) + @parent.const_set @const_name, Class.new end def restore @@ -20,11 +20,11 @@ def restore end def const - @parent.const_get @const_name + @parent.const_get @const_name if @parent.const_defined?(@const_name) end - def self.mock(*const_names, &block) - cm = new(*const_names) + def self.mock(const_name, parent = Object, &block) + cm = new(const_name, parent) yield(cm) cm.restore true diff --git a/test/test_helper.rb b/test/test_helper.rb index bd4acf2bee..ee934a751d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,5 @@ require 'simplecov' -SimpleCov.start +SimpleCov.start { add_filter 'test' } ENV['RAILS_ENV'] = 'test' require "mock_app/config/environment" From f299f2ee5be5afb31daa5f15ce8c386d075538ac Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 24 Jul 2013 00:20:56 -1000 Subject: [PATCH 2009/2024] keep @record in other variable when get_row is called so flash message works --- lib/active_scaffold/actions/update.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index ed7d0df1ca..1381def1ea 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -53,11 +53,12 @@ def update_respond_to_js if update_refresh_list? do_refresh_list else + @updated_record = @record # get_row so associations are cached like in list action @record = get_row rescue nil # if record doesn't fullfil current conditions remove it from list end end - flash.now[:info] = as_(:updated_model, :model => @record.to_label) if active_scaffold_config.update.persistent + flash.now[:info] = as_(:updated_model, :model => (@updated_record || @record).to_label) if active_scaffold_config.update.persistent end render :action => 'on_update' end From 81be9389c7a8759875491fadcc7d03881f8aca0f Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <claudius.nicolae@gmail.com> Date: Sun, 4 Aug 2013 16:55:56 +0300 Subject: [PATCH 2010/2024] fix broken sti links because of caching --- lib/active_scaffold/helpers/view_helpers.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 94abf5f168..1d9ef8c67e 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -235,7 +235,12 @@ def action_link_url(link, record) url_options = action_link_url_options(link, record) if active_scaffold_config.cache_action_link_urls url = url_for(url_options) - @action_links_urls[link.name_to_cache_link_url] = url unless link.dynamic_parameters.is_a?(Proc) + model = active_scaffold_config.model + is_sti = model.columns_hash.include?(model.inheritance_column) + is_sti &&= record[model.inheritance_column].present? if record + unless link.dynamic_parameters.is_a?(Proc) || is_sti + @action_links_urls[link.name_to_cache_link_url] = url + end url else url_for(params_for(url_options)) From f51ebb9a5f19b46b6dc7cc9884634617940fd2f2 Mon Sep 17 00:00:00 2001 From: Nicolae Claudius <claudius.nicolae@gmail.com> Date: Sun, 4 Aug 2013 17:14:13 +0300 Subject: [PATCH 2011/2024] small optimization on STI links --- lib/active_scaffold/helpers/view_helpers.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 1d9ef8c67e..af90b77d44 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -236,9 +236,9 @@ def action_link_url(link, record) if active_scaffold_config.cache_action_link_urls url = url_for(url_options) model = active_scaffold_config.model - is_sti = model.columns_hash.include?(model.inheritance_column) - is_sti &&= record[model.inheritance_column].present? if record - unless link.dynamic_parameters.is_a?(Proc) || is_sti + is_sti_record = record && model.columns_hash.include?(model.inheritance_column) && + record[model.inheritance_column].present? + unless link.dynamic_parameters.is_a?(Proc) || is_sti_record @action_links_urls[link.name_to_cache_link_url] = url end url From 2ce774828aae2fbe19f06aa412d05b3bc0d9ef7d Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 7 Aug 2013 00:41:08 -1000 Subject: [PATCH 2012/2024] always send parent_controller to render_field requests on subforms --- CHANGELOG | 1 + lib/active_scaffold/helpers/form_column_helpers.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 4215d8f8fb..8b746d775c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ - Load effects from jQuery UI when using jquery-rails 3 gem - Fix searching on nested scaffolds (broken on 3.3.2) - Fix searching when includes is set to nil +- Send parent_controller for render_field requests on subforms for persisted records, as new records were already sending it = 3.3.2 - Fix subforms inside subforms diff --git a/lib/active_scaffold/helpers/form_column_helpers.rb b/lib/active_scaffold/helpers/form_column_helpers.rb index 41e610f952..e1c28da2ae 100644 --- a/lib/active_scaffold/helpers/form_column_helpers.rb +++ b/lib/active_scaffold/helpers/form_column_helpers.rb @@ -119,6 +119,7 @@ def update_columns_options(column, scope, options) url_params = url_params.except(:parent_scaffold, :association, nested.param_name) if nested? && scope url_params[:eid] = params[:eid] if params[:eid] if scope + url_params[:parent_controller] ||= url_params[:controller] url_params[:controller] = subform_controller.controller_path url_params[:scope] = scope url_params[:parent_id] = params[:parent_id] || params[:id] From 76c3939a26708d1e379a382b8d5b833202d45e72 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 7 Aug 2013 13:57:25 +0200 Subject: [PATCH 2013/2024] fix popup links with method --- app/assets/javascripts/jquery/active_scaffold.js | 5 ----- app/assets/javascripts/prototype/active_scaffold.js | 5 ----- lib/active_scaffold/helpers/view_helpers.rb | 5 +---- 3 files changed, 1 insertion(+), 14 deletions(-) diff --git a/app/assets/javascripts/jquery/active_scaffold.js b/app/assets/javascripts/jquery/active_scaffold.js index 6aaaa66d1d..904be770fe 100644 --- a/app/assets/javascripts/jquery/active_scaffold.js +++ b/app/assets/javascripts/jquery/active_scaffold.js @@ -207,11 +207,6 @@ jQuery(document).ready(function($) { ActiveScaffold.delete_subform_record($(this).data('delete-id')); }); - jQuery(document).on('click', 'a[data-popup]', function(e) { - window.open(jQuery(this).attr('href')); - e.preventDefault(); - }); - jQuery(document).on("click", '.hover_click', function(event) { var element = jQuery(this); var ul_element = element.children('ul').first(); diff --git a/app/assets/javascripts/prototype/active_scaffold.js b/app/assets/javascripts/prototype/active_scaffold.js index a903f844b4..935b4f4eac 100644 --- a/app/assets/javascripts/prototype/active_scaffold.js +++ b/app/assets/javascripts/prototype/active_scaffold.js @@ -282,11 +282,6 @@ document.observe("dom:loaded", function() { Element[element.value == 'REPLACE' ? 'hide' : 'show'](element.next('span')); return true; }); - document.on("click", "a[data-popup]", function(event, element) { - if (event.stopped) return; - window.open($(element).href); - event.stop(); - }); document.on("click", ".hover_click", function(event, element) { var ul_element = element.down('ul'); if (ul_element.getStyle('display') === 'none') { diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 94abf5f168..cb025b3508 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -339,10 +339,7 @@ def action_link_html_options(link, record, options) html_options[:data][:cancel_refresh] = true if link.refresh_on_close html_options[:data][:keep_open] = true if link.keep_open? end - if link.popup? - html_options[:data][:popup] = true - html_options[:target] = '_blank' - end + html_options[:target] = '_blank' if link.popup? html_options[:id] = link_id html_options[:remote] = true unless link.page? || link.popup? if link.dhtml_confirm? From 1c45c418ac28bb345ced38a86a83226d48b4893e Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 7 Aug 2013 13:59:11 +0200 Subject: [PATCH 2014/2024] fix when jquery-ui is not loaded --- app/assets/javascripts/active_scaffold.js.erb | 6 ++-- .../jquery/date_picker_bridge.js.erb | 30 ++++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/active_scaffold.js.erb b/app/assets/javascripts/active_scaffold.js.erb index d5936310a7..bcad558e4c 100644 --- a/app/assets/javascripts/active_scaffold.js.erb +++ b/app/assets/javascripts/active_scaffold.js.erb @@ -4,6 +4,8 @@ <% if Jquery::Rails.const_defined? 'JQUERY_UI_VERSION' %> <% require_asset "jquery-ui" %> <% require_asset "jquery-ui-timepicker-addon" %> +<% require_asset "jquery/date_picker_bridge" %> +<% require_asset "jquery/draggable_lists" %> <% elsif Jquery.const_defined? 'Ui' %> <% require_asset "jquery.ui.core" %> <% require_asset "jquery.ui.effect" %> @@ -12,11 +14,11 @@ <% require_asset "jquery.ui.droppable" %> <% require_asset "jquery.ui.datepicker" %> <% require_asset "jquery-ui-timepicker-addon" %> +<% require_asset "jquery/date_picker_bridge" %> +<% require_asset "jquery/draggable_lists" %> <% end %> <% require_asset "jquery/active_scaffold" %> <% require_asset "jquery/jquery.editinplace" %> -<% require_asset "jquery/date_picker_bridge" %> -<% require_asset "jquery/draggable_lists" %> <% when :prototype %> <% require_asset "effects" %> <% require_asset "controls" %> diff --git a/app/assets/javascripts/jquery/date_picker_bridge.js.erb b/app/assets/javascripts/jquery/date_picker_bridge.js.erb index 10c6cff734..d7364b5c3d 100644 --- a/app/assets/javascripts/jquery/date_picker_bridge.js.erb +++ b/app/assets/javascripts/jquery/date_picker_bridge.js.erb @@ -1,23 +1,25 @@ <%# encoding: utf-8 %> <%= ActiveScaffold::Bridges[:date_picker].localization %> -Object.getPrototypeOf($.datepicker)._attachDatepicker_without_inlineSettings = Object.getPrototypeOf($.datepicker)._attachDatepicker; -$.extend(Object.getPrototypeOf($.datepicker), { - _attachDatepicker: function(target, settings) { - var inlineSettings = {}, $target = $(target); - for (var attrName in this._defaults) { - if(this._defaults.hasOwnProperty(attrName)){ - var attrValue = $target.data(attrName.toLowerCase()); - if (attrValue) { - try { - inlineSettings[attrName] = eval(attrValue); - } catch (err) { - inlineSettings[attrName] = attrValue; +jQuery(function($) { + Object.getPrototypeOf($.datepicker)._attachDatepicker_without_inlineSettings = Object.getPrototypeOf($.datepicker)._attachDatepicker; + $.extend(Object.getPrototypeOf($.datepicker), { + _attachDatepicker: function(target, settings) { + var inlineSettings = {}, $target = $(target); + for (var attrName in this._defaults) { + if(this._defaults.hasOwnProperty(attrName)){ + var attrValue = $target.data(attrName.toLowerCase()); + if (attrValue) { + try { + inlineSettings[attrName] = eval(attrValue); + } catch (err) { + inlineSettings[attrName] = attrValue; + } } } } + this._attachDatepicker_without_inlineSettings(target, $.extend({}, settings || {}, inlineSettings)); } - this._attachDatepicker_without_inlineSettings(target, $.extend({}, settings || {}, inlineSettings)); - } + }); }); jQuery(document).on("focus", "input.date_picker", function(){ var date_picker = jQuery(this); From 27a9d3536312561525f7f7b9de484ef657e98618 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 7 Aug 2013 14:10:09 +0200 Subject: [PATCH 2015/2024] fix loading styles from jquery ui rails gem --- CHANGELOG | 2 ++ app/assets/stylesheets/active_scaffold.css.scss | 2 +- app/assets/stylesheets/active_scaffold_jquery_ui.css.erb | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/active_scaffold_jquery_ui.css.erb diff --git a/CHANGELOG b/CHANGELOG index 8b746d775c..b82c04e99d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,8 @@ - Fix searching on nested scaffolds (broken on 3.3.2) - Fix searching when includes is set to nil - Send parent_controller for render_field requests on subforms for persisted records, as new records were already sending it +- Avoid loading some JS when jquery-ui is not available +- Load CSS from jquery ui rails gem = 3.3.2 - Fix subforms inside subforms diff --git a/app/assets/stylesheets/active_scaffold.css.scss b/app/assets/stylesheets/active_scaffold.css.scss index 805a845703..a103cd5c1a 100644 --- a/app/assets/stylesheets/active_scaffold.css.scss +++ b/app/assets/stylesheets/active_scaffold.css.scss @@ -9,6 +9,6 @@ @import 'active_scaffold_layout'; @import 'active_scaffold_images'; -@import 'jquery-ui'; +@import 'active_scaffold_jquery_ui'; @import 'active_scaffold_extensions'; @import 'active_scaffold_colors'; diff --git a/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb b/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb new file mode 100644 index 0000000000..701b9c46b3 --- /dev/null +++ b/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb @@ -0,0 +1,5 @@ +<% if Jquery::Rails.const_defined? 'JQUERY_UI_VERSION' %> +<% require_asset "jquery-ui" %> +<% elsif Jquery.const_defined? 'Ui' %> +<% require_asset "jquery.ui.datepicker" %> +<% end %> From fad546e643ef0d1aaf5c7d61b60dbb08f0df2e3f Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 7 Aug 2013 14:31:09 +0200 Subject: [PATCH 2016/2024] still loading theme in jquery ui rails gem --- vendor/assets/stylesheets/jquery-ui-theme.css | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 vendor/assets/stylesheets/jquery-ui-theme.css diff --git a/vendor/assets/stylesheets/jquery-ui-theme.css b/vendor/assets/stylesheets/jquery-ui-theme.css new file mode 100644 index 0000000000..5b9d843f28 --- /dev/null +++ b/vendor/assets/stylesheets/jquery-ui-theme.css @@ -0,0 +1,47 @@ +/* Component containers +----------------------------------*/ +.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee url(ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x; color: #333333; } +.ui-widget-content a { color: #333333; } +.ui-widget-header { border: 1px solid #e78f08; background: #f6a828 url(ui-bg_gloss-wave_35_f6a828_500x100.png) 50% 50% repeat-x; color: #ffffff; font-weight: bold; } +.ui-widget-header a { color: #ffffff; } + +/* Interaction states +----------------------------------*/ +.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 url(ui-bg_glass_100_f6f6f6_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #1c94c4; } +.ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #1c94c4; text-decoration: none; } +.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #fbcb09; background: #fdf5ce url(ui-bg_glass_100_fdf5ce_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #c77405; } +.ui-state-hover a, .ui-state-hover a:hover { color: #c77405; text-decoration: none; } +.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #fbd850; background: #ffffff url(ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #eb8f00; } +.ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #eb8f00; text-decoration: none; } +.ui-widget :active { outline: none; } + +/* Interaction Cues +----------------------------------*/ +.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fed22f; background: #ffe45c url(ui-bg_highlight-soft_75_ffe45c_1x100.png) 50% top repeat-x; color: #363636; } +.ui-state-highlight a, .ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a { color: #363636; } +.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 url(ui-bg_diagonals-thick_18_b81900_40x40.png) 50% 50% repeat; color: #ffffff; } +.ui-state-error a, .ui-widget-content .ui-state-error a, .ui-widget-header .ui-state-error a { color: #ffffff; } +.ui-state-error-text, .ui-widget-content .ui-state-error-text, .ui-widget-header .ui-state-error-text { color: #ffffff; } +.ui-priority-primary, .ui-widget-content .ui-priority-primary, .ui-widget-header .ui-priority-primary { font-weight: bold; } +.ui-priority-secondary, .ui-widget-content .ui-priority-secondary, .ui-widget-header .ui-priority-secondary { opacity: .7; filter:Alpha(Opacity=70); font-weight: normal; } +.ui-state-disabled, .ui-widget-content .ui-state-disabled, .ui-widget-header .ui-state-disabled { opacity: .35; filter:Alpha(Opacity=35); background-image: none; } + +/* Icons +----------------------------------*/ + +/* states and images */ +.ui-icon { background-image: url(ui-icons_222222_256x240.png); } +.ui-widget-content .ui-icon {background-image: url(ui-icons_222222_256x240.png); } +.ui-widget-header .ui-icon {background-image: url(ui-icons_ffffff_256x240.png); } +.ui-state-default .ui-icon { background-image: url(ui-icons_ef8c08_256x240.png); } +.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(ui-icons_ef8c08_256x240.png); } +.ui-state-active .ui-icon {background-image: url(ui-icons_ef8c08_256x240.png); } +.ui-state-highlight .ui-icon {background-image: url(ui-icons_228ef1_256x240.png); } +.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(ui-icons_ffd27a_256x240.png); } + +/* Misc visuals +----------------------------------*/ + +/* Overlays */ +.ui-widget-overlay { background: #666666 url(ui-bg_diagonals-thick_20_666666_40x40.png) 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); } +.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 url(ui-bg_flat_10_000000_40x100.png) 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; } From 449092cc65f42637f84d8a500c311a67728efeae Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 7 Aug 2013 14:34:51 +0200 Subject: [PATCH 2017/2024] still loading theme in jquery ui rails gem --- .../active_scaffold_jquery_ui.css.erb | 2 + vendor/assets/stylesheets/jquery-ui.css | 38 +------------------ 2 files changed, 4 insertions(+), 36 deletions(-) diff --git a/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb b/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb index 701b9c46b3..0a8fb37515 100644 --- a/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb +++ b/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb @@ -1,5 +1,7 @@ <% if Jquery::Rails.const_defined? 'JQUERY_UI_VERSION' %> <% require_asset "jquery-ui" %> +<% require_asset "jquery-ui-theme" %> <% elsif Jquery.const_defined? 'Ui' %> <% require_asset "jquery.ui.datepicker" %> +<% require_asset "jquery-ui-theme" %> <% end %> diff --git a/vendor/assets/stylesheets/jquery-ui.css b/vendor/assets/stylesheets/jquery-ui.css index 77c68d3637..91c5e96a71 100644 --- a/vendor/assets/stylesheets/jquery-ui.css +++ b/vendor/assets/stylesheets/jquery-ui.css @@ -59,44 +59,12 @@ .ui-widget { font-family: Trebuchet MS, Tahoma, Verdana, Arial, sans-serif; font-size: 1.1em; } .ui-widget .ui-widget { font-size: 1em; } .ui-widget input, .ui-widget select, .ui-widget textarea, .ui-widget button { font-family: Trebuchet MS, Tahoma, Verdana, Arial, sans-serif; font-size: 1em; } -.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee url(ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x; color: #333333; } -.ui-widget-content a { color: #333333; } -.ui-widget-header { border: 1px solid #e78f08; background: #f6a828 url(ui-bg_gloss-wave_35_f6a828_500x100.png) 50% 50% repeat-x; color: #ffffff; font-weight: bold; } -.ui-widget-header a { color: #ffffff; } - -/* Interaction states -----------------------------------*/ -.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 url(ui-bg_glass_100_f6f6f6_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #1c94c4; } -.ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #1c94c4; text-decoration: none; } -.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #fbcb09; background: #fdf5ce url(ui-bg_glass_100_fdf5ce_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #c77405; } -.ui-state-hover a, .ui-state-hover a:hover { color: #c77405; text-decoration: none; } -.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #fbd850; background: #ffffff url(ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #eb8f00; } -.ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #eb8f00; text-decoration: none; } -.ui-widget :active { outline: none; } - -/* Interaction Cues -----------------------------------*/ -.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fed22f; background: #ffe45c url(ui-bg_highlight-soft_75_ffe45c_1x100.png) 50% top repeat-x; color: #363636; } -.ui-state-highlight a, .ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a { color: #363636; } -.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 url(ui-bg_diagonals-thick_18_b81900_40x40.png) 50% 50% repeat; color: #ffffff; } -.ui-state-error a, .ui-widget-content .ui-state-error a, .ui-widget-header .ui-state-error a { color: #ffffff; } -.ui-state-error-text, .ui-widget-content .ui-state-error-text, .ui-widget-header .ui-state-error-text { color: #ffffff; } -.ui-priority-primary, .ui-widget-content .ui-priority-primary, .ui-widget-header .ui-priority-primary { font-weight: bold; } -.ui-priority-secondary, .ui-widget-content .ui-priority-secondary, .ui-widget-header .ui-priority-secondary { opacity: .7; filter:Alpha(Opacity=70); font-weight: normal; } -.ui-state-disabled, .ui-widget-content .ui-state-disabled, .ui-widget-header .ui-state-disabled { opacity: .35; filter:Alpha(Opacity=35); background-image: none; } /* Icons ----------------------------------*/ /* states and images */ -.ui-icon { width: 16px; height: 16px; background-image: url(ui-icons_222222_256x240.png); } -.ui-widget-content .ui-icon {background-image: url(ui-icons_222222_256x240.png); } -.ui-widget-header .ui-icon {background-image: url(ui-icons_ffffff_256x240.png); } -.ui-state-default .ui-icon { background-image: url(ui-icons_ef8c08_256x240.png); } -.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(ui-icons_ef8c08_256x240.png); } -.ui-state-active .ui-icon {background-image: url(ui-icons_ef8c08_256x240.png); } -.ui-state-highlight .ui-icon {background-image: url(ui-icons_228ef1_256x240.png); } -.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(ui-icons_ffd27a_256x240.png); } +.ui-icon { width: 16px; height: 16px; } /* positioning */ .ui-icon-carat-1-n { background-position: 0 0; } @@ -285,9 +253,7 @@ .ui-corner-all, .ui-corner-bottom, .ui-corner-left, .ui-corner-bl { -moz-border-radius-bottomleft: 4px; -webkit-border-bottom-left-radius: 4px; -khtml-border-bottom-left-radius: 4px; border-bottom-left-radius: 4px; } .ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br { -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 4px; -khtml-border-bottom-right-radius: 4px; border-bottom-right-radius: 4px; } -/* Overlays */ -.ui-widget-overlay { background: #666666 url(ui-bg_diagonals-thick_20_666666_40x40.png) 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); } -.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 url(ui-bg_flat_10_000000_40x100.png) 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }/* +/* * jQuery UI Resizable 1.8.14 * * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) From 07516476b743d1aa264135ed3504943e09182b10 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 7 Aug 2013 14:39:22 +0200 Subject: [PATCH 2018/2024] use scss and image-url for jquery-ui images --- ...-ui-theme.css => jquery-ui-theme.css.scss} | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) rename vendor/assets/stylesheets/{jquery-ui-theme.css => jquery-ui-theme.css.scss} (59%) diff --git a/vendor/assets/stylesheets/jquery-ui-theme.css b/vendor/assets/stylesheets/jquery-ui-theme.css.scss similarity index 59% rename from vendor/assets/stylesheets/jquery-ui-theme.css rename to vendor/assets/stylesheets/jquery-ui-theme.css.scss index 5b9d843f28..21161d53ca 100644 --- a/vendor/assets/stylesheets/jquery-ui-theme.css +++ b/vendor/assets/stylesheets/jquery-ui-theme.css.scss @@ -1,25 +1,25 @@ /* Component containers ----------------------------------*/ -.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee url(ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x; color: #333333; } +.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee image-url(ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x; color: #333333; } .ui-widget-content a { color: #333333; } -.ui-widget-header { border: 1px solid #e78f08; background: #f6a828 url(ui-bg_gloss-wave_35_f6a828_500x100.png) 50% 50% repeat-x; color: #ffffff; font-weight: bold; } +.ui-widget-header { border: 1px solid #e78f08; background: #f6a828 image-url(ui-bg_gloss-wave_35_f6a828_500x100.png) 50% 50% repeat-x; color: #ffffff; font-weight: bold; } .ui-widget-header a { color: #ffffff; } /* Interaction states ----------------------------------*/ -.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 url(ui-bg_glass_100_f6f6f6_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #1c94c4; } +.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 image-url(ui-bg_glass_100_f6f6f6_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #1c94c4; } .ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #1c94c4; text-decoration: none; } -.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #fbcb09; background: #fdf5ce url(ui-bg_glass_100_fdf5ce_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #c77405; } +.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #fbcb09; background: #fdf5ce image-url(ui-bg_glass_100_fdf5ce_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #c77405; } .ui-state-hover a, .ui-state-hover a:hover { color: #c77405; text-decoration: none; } -.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #fbd850; background: #ffffff url(ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #eb8f00; } +.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #fbd850; background: #ffffff image-url(ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #eb8f00; } .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #eb8f00; text-decoration: none; } .ui-widget :active { outline: none; } /* Interaction Cues ----------------------------------*/ -.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fed22f; background: #ffe45c url(ui-bg_highlight-soft_75_ffe45c_1x100.png) 50% top repeat-x; color: #363636; } +.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fed22f; background: #ffe45c image-url(ui-bg_highlight-soft_75_ffe45c_1x100.png) 50% top repeat-x; color: #363636; } .ui-state-highlight a, .ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a { color: #363636; } -.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 url(ui-bg_diagonals-thick_18_b81900_40x40.png) 50% 50% repeat; color: #ffffff; } +.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 image-url(ui-bg_diagonals-thick_18_b81900_40x40.png) 50% 50% repeat; color: #ffffff; } .ui-state-error a, .ui-widget-content .ui-state-error a, .ui-widget-header .ui-state-error a { color: #ffffff; } .ui-state-error-text, .ui-widget-content .ui-state-error-text, .ui-widget-header .ui-state-error-text { color: #ffffff; } .ui-priority-primary, .ui-widget-content .ui-priority-primary, .ui-widget-header .ui-priority-primary { font-weight: bold; } @@ -30,18 +30,18 @@ ----------------------------------*/ /* states and images */ -.ui-icon { background-image: url(ui-icons_222222_256x240.png); } -.ui-widget-content .ui-icon {background-image: url(ui-icons_222222_256x240.png); } -.ui-widget-header .ui-icon {background-image: url(ui-icons_ffffff_256x240.png); } -.ui-state-default .ui-icon { background-image: url(ui-icons_ef8c08_256x240.png); } -.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(ui-icons_ef8c08_256x240.png); } -.ui-state-active .ui-icon {background-image: url(ui-icons_ef8c08_256x240.png); } -.ui-state-highlight .ui-icon {background-image: url(ui-icons_228ef1_256x240.png); } -.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(ui-icons_ffd27a_256x240.png); } +.ui-icon { background-image: image-url(ui-icons_222222_256x240.png); } +.ui-widget-content .ui-icon {background-image: image-url(ui-icons_222222_256x240.png); } +.ui-widget-header .ui-icon {background-image: image-url(ui-icons_ffffff_256x240.png); } +.ui-state-default .ui-icon { background-image: image-url(ui-icons_ef8c08_256x240.png); } +.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: image-url(ui-icons_ef8c08_256x240.png); } +.ui-state-active .ui-icon {background-image: image-url(ui-icons_ef8c08_256x240.png); } +.ui-state-highlight .ui-icon {background-image: image-url(ui-icons_228ef1_256x240.png); } +.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: image-url(ui-icons_ffd27a_256x240.png); } /* Misc visuals ----------------------------------*/ /* Overlays */ -.ui-widget-overlay { background: #666666 url(ui-bg_diagonals-thick_20_666666_40x40.png) 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); } -.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 url(ui-bg_flat_10_000000_40x100.png) 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; } +.ui-widget-overlay { background: #666666 image-url(ui-bg_diagonals-thick_20_666666_40x40.png) 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); } +.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 image-url(ui-bg_flat_10_000000_40x100.png) 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; } From 9b1e0eb95b58e7ef9c5ccf2a0e0cc06346b62775 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 7 Aug 2013 15:04:26 +0200 Subject: [PATCH 2019/2024] use css.erb instead of scss, it fails when loaded from erb --- ...theme.css.scss => jquery-ui-theme.css.erb} | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) rename vendor/assets/stylesheets/{jquery-ui-theme.css.scss => jquery-ui-theme.css.erb} (57%) diff --git a/vendor/assets/stylesheets/jquery-ui-theme.css.scss b/vendor/assets/stylesheets/jquery-ui-theme.css.erb similarity index 57% rename from vendor/assets/stylesheets/jquery-ui-theme.css.scss rename to vendor/assets/stylesheets/jquery-ui-theme.css.erb index 21161d53ca..2f976167b3 100644 --- a/vendor/assets/stylesheets/jquery-ui-theme.css.scss +++ b/vendor/assets/stylesheets/jquery-ui-theme.css.erb @@ -1,25 +1,25 @@ /* Component containers ----------------------------------*/ -.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee image-url(ui-bg_highlight-soft_100_eeeeee_1x100.png) 50% top repeat-x; color: #333333; } +.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee <%= image_path('ui-bg_highlight-soft_100_eeeeee_1x100.png') %> 50% top repeat-x; color: #333333; } .ui-widget-content a { color: #333333; } -.ui-widget-header { border: 1px solid #e78f08; background: #f6a828 image-url(ui-bg_gloss-wave_35_f6a828_500x100.png) 50% 50% repeat-x; color: #ffffff; font-weight: bold; } +.ui-widget-header { border: 1px solid #e78f08; background: #f6a828 <%= image_path('ui-bg_gloss-wave_35_f6a828_500x100.png') %> 50% 50% repeat-x; color: #ffffff; font-weight: bold; } .ui-widget-header a { color: #ffffff; } /* Interaction states ----------------------------------*/ -.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 image-url(ui-bg_glass_100_f6f6f6_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #1c94c4; } +.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 <%= image_path('ui-bg_glass_100_f6f6f6_1x400.png') %> 50% 50% repeat-x; font-weight: bold; color: #1c94c4; } .ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #1c94c4; text-decoration: none; } -.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #fbcb09; background: #fdf5ce image-url(ui-bg_glass_100_fdf5ce_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #c77405; } +.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #fbcb09; background: #fdf5ce <%= image_path('ui-bg_glass_100_fdf5ce_1x400.png') %> 50% 50% repeat-x; font-weight: bold; color: #c77405; } .ui-state-hover a, .ui-state-hover a:hover { color: #c77405; text-decoration: none; } -.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #fbd850; background: #ffffff image-url(ui-bg_glass_65_ffffff_1x400.png) 50% 50% repeat-x; font-weight: bold; color: #eb8f00; } +.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #fbd850; background: #ffffff <%= image_path('ui-bg_glass_65_ffffff_1x400.png') %> 50% 50% repeat-x; font-weight: bold; color: #eb8f00; } .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #eb8f00; text-decoration: none; } .ui-widget :active { outline: none; } /* Interaction Cues ----------------------------------*/ -.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fed22f; background: #ffe45c image-url(ui-bg_highlight-soft_75_ffe45c_1x100.png) 50% top repeat-x; color: #363636; } +.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fed22f; background: #ffe45c <%= image_path('ui-bg_highlight-soft_75_ffe45c_1x100.png') %> 50% top repeat-x; color: #363636; } .ui-state-highlight a, .ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a { color: #363636; } -.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 image-url(ui-bg_diagonals-thick_18_b81900_40x40.png) 50% 50% repeat; color: #ffffff; } +.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 <%= image_path('ui-bg_diagonals-thick_18_b81900_40x40.png') %> 50% 50% repeat; color: #ffffff; } .ui-state-error a, .ui-widget-content .ui-state-error a, .ui-widget-header .ui-state-error a { color: #ffffff; } .ui-state-error-text, .ui-widget-content .ui-state-error-text, .ui-widget-header .ui-state-error-text { color: #ffffff; } .ui-priority-primary, .ui-widget-content .ui-priority-primary, .ui-widget-header .ui-priority-primary { font-weight: bold; } @@ -30,18 +30,18 @@ ----------------------------------*/ /* states and images */ -.ui-icon { background-image: image-url(ui-icons_222222_256x240.png); } -.ui-widget-content .ui-icon {background-image: image-url(ui-icons_222222_256x240.png); } -.ui-widget-header .ui-icon {background-image: image-url(ui-icons_ffffff_256x240.png); } -.ui-state-default .ui-icon { background-image: image-url(ui-icons_ef8c08_256x240.png); } -.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: image-url(ui-icons_ef8c08_256x240.png); } -.ui-state-active .ui-icon {background-image: image-url(ui-icons_ef8c08_256x240.png); } -.ui-state-highlight .ui-icon {background-image: image-url(ui-icons_228ef1_256x240.png); } -.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: image-url(ui-icons_ffd27a_256x240.png); } +.ui-icon { background-image: <%= image_path('ui-icons_222222_256x240.png') %>; } +.ui-widget-content .ui-icon {background-image: <%= image_path('ui-icons_222222_256x240.png') %>; } +.ui-widget-header .ui-icon {background-image: <%= image_path('ui-icons_ffffff_256x240.png') %>; } +.ui-state-default .ui-icon { background-image: <%= image_path('ui-icons_ef8c08_256x240.png') %>; } +.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: <%= image_path('ui-icons_ef8c08_256x240.png') %>; } +.ui-state-active .ui-icon {background-image: <%= image_path('ui-icons_ef8c08_256x240.png') %>; } +.ui-state-highlight .ui-icon {background-image: <%= image_path('ui-icons_228ef1_256x240.png') %>; } +.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: <%= image_path('ui-icons_ffd27a_256x240.png') %>; } /* Misc visuals ----------------------------------*/ /* Overlays */ -.ui-widget-overlay { background: #666666 image-url(ui-bg_diagonals-thick_20_666666_40x40.png) 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); } -.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 image-url(ui-bg_flat_10_000000_40x100.png) 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; } +.ui-widget-overlay { background: #666666 <%= image_path('ui-bg_diagonals-thick_20_666666_40x40.png') %> 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); } +.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 <%= image_path('ui-bg_flat_10_000000_40x100.png') %> 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; } From 82986b52a0ceb4ed805cbb89e4065ad20fd6e518 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Wed, 7 Aug 2013 15:08:03 +0200 Subject: [PATCH 2020/2024] fix css.erb --- .../stylesheets/jquery-ui-theme.css.erb | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/vendor/assets/stylesheets/jquery-ui-theme.css.erb b/vendor/assets/stylesheets/jquery-ui-theme.css.erb index 2f976167b3..17a38fa1f6 100644 --- a/vendor/assets/stylesheets/jquery-ui-theme.css.erb +++ b/vendor/assets/stylesheets/jquery-ui-theme.css.erb @@ -1,25 +1,25 @@ /* Component containers ----------------------------------*/ -.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee <%= image_path('ui-bg_highlight-soft_100_eeeeee_1x100.png') %> 50% top repeat-x; color: #333333; } +.ui-widget-content { border: 1px solid #dddddd; background: #eeeeee url(<%= image_path('ui-bg_highlight-soft_100_eeeeee_1x100.png') %>) 50% top repeat-x; color: #333333; } .ui-widget-content a { color: #333333; } -.ui-widget-header { border: 1px solid #e78f08; background: #f6a828 <%= image_path('ui-bg_gloss-wave_35_f6a828_500x100.png') %> 50% 50% repeat-x; color: #ffffff; font-weight: bold; } +.ui-widget-header { border: 1px solid #e78f08; background: #f6a828 url(<%= image_path('ui-bg_gloss-wave_35_f6a828_500x100.png') %>) 50% 50% repeat-x; color: #ffffff; font-weight: bold; } .ui-widget-header a { color: #ffffff; } /* Interaction states ----------------------------------*/ -.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 <%= image_path('ui-bg_glass_100_f6f6f6_1x400.png') %> 50% 50% repeat-x; font-weight: bold; color: #1c94c4; } +.ui-state-default, .ui-widget-content .ui-state-default, .ui-widget-header .ui-state-default { border: 1px solid #cccccc; background: #f6f6f6 url(<%= image_path('ui-bg_glass_100_f6f6f6_1x400.png') %>) 50% 50% repeat-x; font-weight: bold; color: #1c94c4; } .ui-state-default a, .ui-state-default a:link, .ui-state-default a:visited { color: #1c94c4; text-decoration: none; } -.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #fbcb09; background: #fdf5ce <%= image_path('ui-bg_glass_100_fdf5ce_1x400.png') %> 50% 50% repeat-x; font-weight: bold; color: #c77405; } +.ui-state-hover, .ui-widget-content .ui-state-hover, .ui-widget-header .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus, .ui-widget-header .ui-state-focus { border: 1px solid #fbcb09; background: #fdf5ce url(<%= image_path('ui-bg_glass_100_fdf5ce_1x400.png') %>) 50% 50% repeat-x; font-weight: bold; color: #c77405; } .ui-state-hover a, .ui-state-hover a:hover { color: #c77405; text-decoration: none; } -.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #fbd850; background: #ffffff <%= image_path('ui-bg_glass_65_ffffff_1x400.png') %> 50% 50% repeat-x; font-weight: bold; color: #eb8f00; } +.ui-state-active, .ui-widget-content .ui-state-active, .ui-widget-header .ui-state-active { border: 1px solid #fbd850; background: #ffffff url(<%= image_path('ui-bg_glass_65_ffffff_1x400.png') %>) 50% 50% repeat-x; font-weight: bold; color: #eb8f00; } .ui-state-active a, .ui-state-active a:link, .ui-state-active a:visited { color: #eb8f00; text-decoration: none; } .ui-widget :active { outline: none; } /* Interaction Cues ----------------------------------*/ -.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fed22f; background: #ffe45c <%= image_path('ui-bg_highlight-soft_75_ffe45c_1x100.png') %> 50% top repeat-x; color: #363636; } +.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {border: 1px solid #fed22f; background: #ffe45c url(<%= image_path('ui-bg_highlight-soft_75_ffe45c_1x100.png') %>) 50% top repeat-x; color: #363636; } .ui-state-highlight a, .ui-widget-content .ui-state-highlight a,.ui-widget-header .ui-state-highlight a { color: #363636; } -.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 <%= image_path('ui-bg_diagonals-thick_18_b81900_40x40.png') %> 50% 50% repeat; color: #ffffff; } +.ui-state-error, .ui-widget-content .ui-state-error, .ui-widget-header .ui-state-error {border: 1px solid #cd0a0a; background: #b81900 url(<%= image_path('ui-bg_diagonals-thick_18_b81900_40x40.png') %>) 50% 50% repeat; color: #ffffff; } .ui-state-error a, .ui-widget-content .ui-state-error a, .ui-widget-header .ui-state-error a { color: #ffffff; } .ui-state-error-text, .ui-widget-content .ui-state-error-text, .ui-widget-header .ui-state-error-text { color: #ffffff; } .ui-priority-primary, .ui-widget-content .ui-priority-primary, .ui-widget-header .ui-priority-primary { font-weight: bold; } @@ -30,18 +30,18 @@ ----------------------------------*/ /* states and images */ -.ui-icon { background-image: <%= image_path('ui-icons_222222_256x240.png') %>; } -.ui-widget-content .ui-icon {background-image: <%= image_path('ui-icons_222222_256x240.png') %>; } -.ui-widget-header .ui-icon {background-image: <%= image_path('ui-icons_ffffff_256x240.png') %>; } -.ui-state-default .ui-icon { background-image: <%= image_path('ui-icons_ef8c08_256x240.png') %>; } -.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: <%= image_path('ui-icons_ef8c08_256x240.png') %>; } -.ui-state-active .ui-icon {background-image: <%= image_path('ui-icons_ef8c08_256x240.png') %>; } -.ui-state-highlight .ui-icon {background-image: <%= image_path('ui-icons_228ef1_256x240.png') %>; } -.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: <%= image_path('ui-icons_ffd27a_256x240.png') %>; } +.ui-icon { background-image: url(<%= image_path('ui-icons_222222_256x240.png') %>); } +.ui-widget-content .ui-icon {background-image: url(<%= image_path('ui-icons_222222_256x240.png') %>); } +.ui-widget-header .ui-icon {background-image: url(<%= image_path('ui-icons_ffffff_256x240.png') %>); } +.ui-state-default .ui-icon { background-image: url(<%= image_path('ui-icons_ef8c08_256x240.png') %>); } +.ui-state-hover .ui-icon, .ui-state-focus .ui-icon {background-image: url(<%= image_path('ui-icons_ef8c08_256x240.png') %>); } +.ui-state-active .ui-icon {background-image: url(<%= image_path('ui-icons_ef8c08_256x240.png') %>); } +.ui-state-highlight .ui-icon {background-image: url(<%= image_path('ui-icons_228ef1_256x240.png') %>); } +.ui-state-error .ui-icon, .ui-state-error-text .ui-icon {background-image: url(<%= image_path('ui-icons_ffd27a_256x240.png') %>); } /* Misc visuals ----------------------------------*/ /* Overlays */ -.ui-widget-overlay { background: #666666 <%= image_path('ui-bg_diagonals-thick_20_666666_40x40.png') %> 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); } -.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 <%= image_path('ui-bg_flat_10_000000_40x100.png') %> 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; } +.ui-widget-overlay { background: #666666 url(<%= image_path('ui-bg_diagonals-thick_20_666666_40x40.png') %>) 50% 50% repeat; opacity: .50;filter:Alpha(Opacity=50); } +.ui-widget-shadow { margin: -5px 0 0 -5px; padding: 5px; background: #000000 url(<%= image_path('ui-bg_flat_10_000000_40x100.png') %>) 50% 50% repeat-x; opacity: .20;filter:Alpha(Opacity=20); -moz-border-radius: 5px; -khtml-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; } From c1609c37b37ac75fbfb605aaf05c596c86879914 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 8 Aug 2013 12:31:46 +0200 Subject: [PATCH 2021/2024] small improvement --- lib/active_scaffold/helpers/view_helpers.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index f1ef427904..512ff280f7 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -235,9 +235,8 @@ def action_link_url(link, record) url_options = action_link_url_options(link, record) if active_scaffold_config.cache_action_link_urls url = url_for(url_options) - model = active_scaffold_config.model - is_sti_record = record && model.columns_hash.include?(model.inheritance_column) && - record[model.inheritance_column].present? + inheritance_column = active_scaffold_config.model.inheritance_column + is_sti_record = record && model.columns_hash.include?(inheritance_column) && record[inheritance_column].present? unless link.dynamic_parameters.is_a?(Proc) || is_sti_record @action_links_urls[link.name_to_cache_link_url] = url end From 630ff1462fcfdc07d9981b5a5d53c8c455a458f7 Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Thu, 8 Aug 2013 14:47:28 +0200 Subject: [PATCH 2022/2024] Revert "small improvement" This reverts commit c1609c37b37ac75fbfb605aaf05c596c86879914. --- lib/active_scaffold/helpers/view_helpers.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/active_scaffold/helpers/view_helpers.rb b/lib/active_scaffold/helpers/view_helpers.rb index 512ff280f7..f1ef427904 100755 --- a/lib/active_scaffold/helpers/view_helpers.rb +++ b/lib/active_scaffold/helpers/view_helpers.rb @@ -235,8 +235,9 @@ def action_link_url(link, record) url_options = action_link_url_options(link, record) if active_scaffold_config.cache_action_link_urls url = url_for(url_options) - inheritance_column = active_scaffold_config.model.inheritance_column - is_sti_record = record && model.columns_hash.include?(inheritance_column) && record[inheritance_column].present? + model = active_scaffold_config.model + is_sti_record = record && model.columns_hash.include?(model.inheritance_column) && + record[model.inheritance_column].present? unless link.dynamic_parameters.is_a?(Proc) || is_sti_record @action_links_urls[link.name_to_cache_link_url] = url end From cfd479ff901db44bd9952edda95a2cb99b52878a Mon Sep 17 00:00:00 2001 From: Sergio Cambra <sergio@programatica.es> Date: Fri, 9 Aug 2013 13:19:05 +0200 Subject: [PATCH 2023/2024] release 3.3.3 --- CHANGELOG | 2 +- lib/active_scaffold/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b82c04e99d..2816afd12e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -= 3.3.3 (not released) += 3.3.3 - Allow to override select options in active_scaffold_search_select - Load effects from jQuery UI when using jquery-rails 3 gem - Fix searching on nested scaffolds (broken on 3.3.2) diff --git a/lib/active_scaffold/version.rb b/lib/active_scaffold/version.rb index 183f6fdc47..2c2dde9a18 100644 --- a/lib/active_scaffold/version.rb +++ b/lib/active_scaffold/version.rb @@ -2,7 +2,7 @@ module ActiveScaffold module Version MAJOR = 3 MINOR = 3 - PATCH = 2 + PATCH = 3 STRING = [MAJOR, MINOR, PATCH].compact.join('.') end From b80c6894c466947517f669ce6cb6f2822a397b4c Mon Sep 17 00:00:00 2001 From: Michael Cowden <michael.cowden@gmail.com> Date: Fri, 9 Aug 2013 10:13:32 -0400 Subject: [PATCH 2024/2024] needed to pass :layout => false to render :action calls in all _respond_to_js methods to avoid Request Failed 500 errors --- lib/active_scaffold/actions/create.rb | 2 +- lib/active_scaffold/actions/delete.rb | 2 +- lib/active_scaffold/actions/list.rb | 4 ++-- lib/active_scaffold/actions/mark.rb | 4 ++-- lib/active_scaffold/actions/nested.rb | 6 +++--- lib/active_scaffold/actions/update.rb | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/active_scaffold/actions/create.rb b/lib/active_scaffold/actions/create.rb index 574896fedf..51a46cefee 100644 --- a/lib/active_scaffold/actions/create.rb +++ b/lib/active_scaffold/actions/create.rb @@ -59,7 +59,7 @@ def create_respond_to_html def create_respond_to_js do_refresh_list if successful? && active_scaffold_config.create.refresh_list && !render_parent? - render :action => 'on_create' + render :action => 'on_create', :content_type => Mime::JS, :layout => false end def create_respond_to_xml diff --git a/lib/active_scaffold/actions/delete.rb b/lib/active_scaffold/actions/delete.rb index 753fe5ae97..5006864209 100644 --- a/lib/active_scaffold/actions/delete.rb +++ b/lib/active_scaffold/actions/delete.rb @@ -24,7 +24,7 @@ def destroy_respond_to_html def destroy_respond_to_js do_refresh_list if successful? && active_scaffold_config.delete.refresh_list && !render_parent? - render(:action => 'destroy') + render(:action => 'destroy', :content_type => Mime::JS, :layout => false) end def destroy_respond_to_xml diff --git a/lib/active_scaffold/actions/list.rb b/lib/active_scaffold/actions/list.rb index 561c6378d9..719b09558c 100644 --- a/lib/active_scaffold/actions/list.rb +++ b/lib/active_scaffold/actions/list.rb @@ -55,7 +55,7 @@ def row_respond_to_html end def row_respond_to_js - render :action => 'row' + render :action => 'row', :content_type => Mime::JS, :layout => false end # The actual algorithm to prepare for the list view @@ -172,7 +172,7 @@ def action_update_respond_to_html def action_update_respond_to_js do_refresh_list unless @record.present? - render(:action => 'on_action_update') + render(:action => 'on_action_update', :content_type => Mime::JS, :layout => false) end def action_update_respond_to_xml diff --git a/lib/active_scaffold/actions/mark.rb b/lib/active_scaffold/actions/mark.rb index 04b4ae8f6f..f65fadf32f 100644 --- a/lib/active_scaffold/actions/mark.rb +++ b/lib/active_scaffold/actions/mark.rb @@ -31,9 +31,9 @@ def mark_respond_to_js do_search if respond_to? :do_search, true set_includes_for_columns if active_scaffold_config.actions.include? :list @page = find_page(:pagination => active_scaffold_config.mark.mark_all_mode != :page) - render :action => 'on_mark' + render :action => 'on_mark', :content_type => Mime::JS, :layout => false else - render :action => 'on_mark', :locals => {:checked => mark?} + render :action => 'on_mark', :content_type => Mime::JS, :layout => false, :locals => {:checked => mark?} end end diff --git a/lib/active_scaffold/actions/nested.rb b/lib/active_scaffold/actions/nested.rb index e49a320e93..abb1805c41 100644 --- a/lib/active_scaffold/actions/nested.rb +++ b/lib/active_scaffold/actions/nested.rb @@ -161,9 +161,9 @@ def add_existing_respond_to_html end def add_existing_respond_to_js if successful? - render :action => 'add_existing' + render :action => 'add_existing', :content_type => Mime::JS, :layout => false else - render :action => 'form_messages' + render :action => 'form_messages', :content_type => Mime::JS, :layout => false end end def add_existing_respond_to_xml @@ -181,7 +181,7 @@ def destroy_existing_respond_to_html end def destroy_existing_respond_to_js - render(:action => 'destroy') + render(:action => 'destroy', :content_type => Mime::JS, :layout => false) end def destroy_existing_respond_to_xml diff --git a/lib/active_scaffold/actions/update.rb b/lib/active_scaffold/actions/update.rb index 1381def1ea..71168c23c2 100644 --- a/lib/active_scaffold/actions/update.rb +++ b/lib/active_scaffold/actions/update.rb @@ -60,7 +60,7 @@ def update_respond_to_js end flash.now[:info] = as_(:updated_model, :model => (@updated_record || @record).to_label) if active_scaffold_config.update.persistent end - render :action => 'on_update' + render :action => 'on_update', :content_type => Mime::JS, :layout => false end def update_respond_to_xml render :xml => response_object.to_xml(:only => active_scaffold_config.update.columns.names), :content_type => Mime::XML, :status => response_status