active_scaffold 3.2.18 → 3.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +3 -0
- data/app/assets/images/active_scaffold/add.png +0 -0
- data/app/assets/images/active_scaffold/arrow_down.png +0 -0
- data/app/assets/images/active_scaffold/arrow_up.png +0 -0
- data/app/assets/images/active_scaffold/close.png +0 -0
- data/app/assets/images/active_scaffold/close_touch.png +0 -0
- data/app/assets/images/active_scaffold/config.png +0 -0
- data/app/assets/images/active_scaffold/cross.png +0 -0
- data/app/assets/images/active_scaffold/gears.png +0 -0
- data/app/assets/images/active_scaffold/indicator-small.gif +0 -0
- data/app/assets/images/active_scaffold/indicator.gif +0 -0
- data/app/assets/images/active_scaffold/magnifier.png +0 -0
- data/app/assets/javascripts/active_scaffold.js.erb +19 -0
- data/app/assets/javascripts/jquery/active_scaffold.js +1113 -0
- data/app/assets/javascripts/jquery/date_picker_bridge.js.erb +24 -0
- data/app/assets/javascripts/jquery/draggable_lists.js +27 -0
- data/app/assets/javascripts/jquery/jquery.editinplace.js +743 -0
- data/app/assets/javascripts/jquery/tiny_mce_bridge.js +7 -0
- data/app/assets/javascripts/prototype/active_scaffold.js +1107 -0
- data/app/assets/javascripts/prototype/dhtml_history.js +870 -0
- data/app/assets/javascripts/prototype/form_enhancements.js +117 -0
- data/app/assets/javascripts/prototype/rico_corner.js +370 -0
- data/app/assets/javascripts/prototype/tiny_mce_bridge.js +7 -0
- data/app/assets/stylesheets/active_scaffold-ie.css.scss +54 -0
- data/app/assets/stylesheets/active_scaffold.css.scss +14 -0
- data/app/assets/stylesheets/active_scaffold_colors.css.scss +395 -0
- data/app/assets/stylesheets/active_scaffold_extensions.css.erb +2 -0
- data/app/assets/stylesheets/active_scaffold_images.css.scss +40 -0
- data/app/assets/stylesheets/active_scaffold_layout.css +936 -0
- data/app/assets/stylesheets/blue-theme.css +74 -0
- data/config/locales/de.yml +125 -0
- data/config/locales/en.yml +127 -0
- data/config/locales/es.yml +128 -0
- data/config/locales/fr.yml +131 -0
- data/config/locales/hu.yml +126 -0
- data/config/locales/ja.yml +126 -0
- data/config/locales/ru.yml +135 -0
- data/frontends/default/views/_action_group.html.erb +24 -0
- data/frontends/default/views/_add_existing_form.html.erb +30 -0
- data/frontends/default/views/_base_form.html.erb +53 -0
- data/frontends/default/views/_create_form.html.erb +8 -0
- data/frontends/default/views/_create_form_on_list.html.erb +6 -0
- data/frontends/default/views/_field_search.html.erb +32 -0
- data/frontends/default/views/_form.html.erb +28 -0
- data/frontends/default/views/_form_association.html.erb +17 -0
- data/frontends/default/views/_form_association_footer.html.erb +47 -0
- data/frontends/default/views/_form_attribute.html.erb +23 -0
- data/frontends/default/views/_form_hidden_attribute.html.erb +7 -0
- data/frontends/default/views/_form_messages.html.erb +5 -0
- data/frontends/default/views/_horizontal_subform.html.erb +22 -0
- data/frontends/default/views/_horizontal_subform_footer.html.erb +0 -0
- data/frontends/default/views/_horizontal_subform_header.html.erb +11 -0
- data/frontends/default/views/_horizontal_subform_record.html.erb +43 -0
- data/frontends/default/views/_human_conditions.html.erb +1 -0
- data/frontends/default/views/_list.html.erb +18 -0
- data/frontends/default/views/_list_actions.html.erb +15 -0
- data/frontends/default/views/_list_calculations.html.erb +16 -0
- data/frontends/default/views/_list_column_headings.html.erb +12 -0
- data/frontends/default/views/_list_header.html.erb +10 -0
- data/frontends/default/views/_list_inline_adapter.html.erb +21 -0
- data/frontends/default/views/_list_messages.html.erb +28 -0
- data/frontends/default/views/_list_pagination.html.erb +11 -0
- data/frontends/default/views/_list_pagination_links.html.erb +9 -0
- data/frontends/default/views/_list_record.html.erb +13 -0
- data/frontends/default/views/_list_record_columns.html.erb +8 -0
- data/frontends/default/views/_list_with_header.html.erb +36 -0
- data/frontends/default/views/_messages.html.erb +10 -0
- data/frontends/default/views/_refresh_list.js.erb +1 -0
- data/frontends/default/views/_render_field.js.erb +20 -0
- data/frontends/default/views/_row.html.erb +1 -0
- data/frontends/default/views/_search.html.erb +34 -0
- data/frontends/default/views/_search_attribute.html.erb +10 -0
- data/frontends/default/views/_show.html.erb +8 -0
- data/frontends/default/views/_show_columns.html.erb +15 -0
- data/frontends/default/views/_update_actions.html.erb +9 -0
- data/frontends/default/views/_update_calculations.js.erb +4 -0
- data/frontends/default/views/_update_form.html.erb +6 -0
- data/frontends/default/views/_update_messages.js.erb +2 -0
- data/frontends/default/views/_vertical_subform.html.erb +12 -0
- data/frontends/default/views/_vertical_subform_record.html.erb +43 -0
- data/frontends/default/views/action_confirmation.html.erb +13 -0
- data/frontends/default/views/add_existing.js.erb +14 -0
- data/frontends/default/views/add_existing_form.html.erb +5 -0
- data/frontends/default/views/create.html.erb +5 -0
- data/frontends/default/views/delete.html.erb +13 -0
- data/frontends/default/views/destroy.js.erb +26 -0
- data/frontends/default/views/edit_associated.js.erb +12 -0
- data/frontends/default/views/field_search.html.erb +5 -0
- data/frontends/default/views/form_messages.js.erb +1 -0
- data/frontends/default/views/list.html.erb +1 -0
- data/frontends/default/views/on_action_update.js.erb +22 -0
- data/frontends/default/views/on_create.js.erb +38 -0
- data/frontends/default/views/on_mark.js.erb +6 -0
- data/frontends/default/views/on_update.js.erb +29 -0
- data/frontends/default/views/refresh_list.js.erb +2 -0
- data/frontends/default/views/render_field.js.erb +1 -0
- data/frontends/default/views/row.js.erb +2 -0
- data/frontends/default/views/search.html.erb +5 -0
- data/frontends/default/views/show.html.erb +5 -0
- data/frontends/default/views/update.html.erb +8 -0
- data/frontends/default/views/update_column.js.erb +15 -0
- data/frontends/default/views/update_row.js.erb +1 -0
- data/lib/active_scaffold/actions/common_search.rb +22 -0
- data/lib/active_scaffold/actions/core.rb +203 -0
- data/lib/active_scaffold/actions/create.rb +139 -0
- data/lib/active_scaffold/actions/delete.rb +74 -0
- data/lib/active_scaffold/actions/field_search.rb +78 -0
- data/lib/active_scaffold/actions/list.rb +208 -0
- data/lib/active_scaffold/actions/mark.rb +89 -0
- data/lib/active_scaffold/actions/nested.rb +244 -0
- data/lib/active_scaffold/actions/search.rb +48 -0
- data/lib/active_scaffold/actions/show.rb +61 -0
- data/lib/active_scaffold/actions/subform.rb +23 -0
- data/lib/active_scaffold/actions/update.rb +156 -0
- data/lib/active_scaffold/active_record_permissions.rb +135 -0
- data/lib/active_scaffold/attribute_params.rb +200 -0
- data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +39 -0
- data/lib/active_scaffold/bridges/ancestry.rb +5 -0
- data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +37 -0
- data/lib/active_scaffold/bridges/bitfields.rb +6 -0
- data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +66 -0
- data/lib/active_scaffold/bridges/calendar_date_select.rb +24 -0
- data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +127 -0
- data/lib/active_scaffold/bridges/cancan.rb +15 -0
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge.rb +31 -0
- data/lib/active_scaffold/bridges/carrierwave/carrierwave_bridge_helpers.rb +10 -0
- data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +45 -0
- data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +17 -0
- data/lib/active_scaffold/bridges/carrierwave.rb +12 -0
- data/lib/active_scaffold/bridges/country_helper/country_helper_bridge.rb +358 -0
- data/lib/active_scaffold/bridges/country_helper.rb +9 -0
- data/lib/active_scaffold/bridges/date_picker/ext.rb +63 -0
- data/lib/active_scaffold/bridges/date_picker/helper.rb +180 -0
- data/lib/active_scaffold/bridges/date_picker.rb +23 -0
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +34 -0
- data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge_helpers.rb +10 -0
- data/lib/active_scaffold/bridges/dragonfly/form_ui.rb +27 -0
- data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +16 -0
- data/lib/active_scaffold/bridges/dragonfly.rb +9 -0
- data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +46 -0
- data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +57 -0
- data/lib/active_scaffold/bridges/file_column/form_ui.rb +34 -0
- data/lib/active_scaffold/bridges/file_column/list_ui.rb +26 -0
- data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +43 -0
- data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +9 -0
- data/lib/active_scaffold/bridges/file_column/test/test_helper.rb +15 -0
- data/lib/active_scaffold/bridges/file_column.rb +11 -0
- data/lib/active_scaffold/bridges/paperclip/form_ui.rb +27 -0
- data/lib/active_scaffold/bridges/paperclip/list_ui.rb +16 -0
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +36 -0
- data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +24 -0
- data/lib/active_scaffold/bridges/paperclip.rb +12 -0
- data/lib/active_scaffold/bridges/record_select/helpers.rb +92 -0
- data/lib/active_scaffold/bridges/record_select.rb +11 -0
- data/lib/active_scaffold/bridges/semantic_attributes/column.rb +20 -0
- data/lib/active_scaffold/bridges/semantic_attributes.rb +5 -0
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +209 -0
- data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +46 -0
- data/lib/active_scaffold/bridges/tiny_mce.rb +17 -0
- data/lib/active_scaffold/bridges.rb +61 -0
- data/lib/active_scaffold/config/base.rb +75 -0
- data/lib/active_scaffold/config/core.rb +236 -0
- data/lib/active_scaffold/config/create.rb +32 -0
- data/lib/active_scaffold/config/delete.rb +32 -0
- data/lib/active_scaffold/config/field_search.rb +79 -0
- data/lib/active_scaffold/config/form.rb +64 -0
- data/lib/active_scaffold/config/list.rb +247 -0
- data/lib/active_scaffold/config/mark.rb +30 -0
- data/lib/active_scaffold/config/nested.rb +42 -0
- data/lib/active_scaffold/config/search.rb +73 -0
- data/lib/active_scaffold/config/show.rb +31 -0
- data/lib/active_scaffold/config/subform.rb +35 -0
- data/lib/active_scaffold/config/update.rb +33 -0
- data/lib/active_scaffold/configurable.rb +29 -0
- data/lib/active_scaffold/constraints.rb +171 -0
- data/lib/active_scaffold/data_structures/action_columns.rb +142 -0
- data/lib/active_scaffold/data_structures/action_link.rb +185 -0
- data/lib/active_scaffold/data_structures/action_links.rb +191 -0
- data/lib/active_scaffold/data_structures/actions.rb +45 -0
- data/lib/active_scaffold/data_structures/bridge.rb +22 -0
- data/lib/active_scaffold/data_structures/column.rb +402 -0
- data/lib/active_scaffold/data_structures/columns.rb +75 -0
- data/lib/active_scaffold/data_structures/error_message.rb +24 -0
- data/lib/active_scaffold/data_structures/nested_info.rb +171 -0
- data/lib/active_scaffold/data_structures/set.rb +61 -0
- data/lib/active_scaffold/data_structures/sorting.rb +167 -0
- data/lib/active_scaffold/engine.rb +4 -0
- data/lib/active_scaffold/extensions/action_controller_rendering.rb +20 -0
- data/lib/active_scaffold/extensions/action_controller_rescueing.rb +7 -0
- data/lib/active_scaffold/extensions/action_view_rendering.rb +115 -0
- data/lib/active_scaffold/extensions/active_record_offset.rb +12 -0
- data/lib/active_scaffold/extensions/array.rb +7 -0
- data/lib/active_scaffold/extensions/cache_association.rb +16 -0
- data/lib/active_scaffold/extensions/localize.rb +10 -0
- data/lib/active_scaffold/extensions/name_option_for_datetime.rb +12 -0
- data/lib/active_scaffold/extensions/nil_id_in_url_params.rb +7 -0
- data/lib/active_scaffold/extensions/paginator_extensions.rb +26 -0
- data/lib/active_scaffold/extensions/reverse_associations.rb +64 -0
- data/lib/active_scaffold/extensions/routing_mapper.rb +48 -0
- data/lib/active_scaffold/extensions/to_label.rb +8 -0
- data/lib/active_scaffold/extensions/unsaved_associated.rb +61 -0
- data/lib/active_scaffold/extensions/unsaved_record.rb +20 -0
- data/lib/active_scaffold/extensions/usa_state.rb +46 -0
- data/lib/active_scaffold/finder.rb +399 -0
- data/lib/active_scaffold/helpers/association_helpers.rb +42 -0
- data/lib/active_scaffold/helpers/controller_helpers.rb +94 -0
- data/lib/active_scaffold/helpers/form_column_helpers.rb +322 -0
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +64 -0
- data/lib/active_scaffold/helpers/id_helpers.rb +131 -0
- data/lib/active_scaffold/helpers/list_column_helpers.rb +374 -0
- data/lib/active_scaffold/helpers/pagination_helpers.rb +62 -0
- data/lib/active_scaffold/helpers/search_column_helpers.rb +257 -0
- data/lib/active_scaffold/helpers/show_column_helpers.rb +44 -0
- data/lib/active_scaffold/helpers/view_helpers.rb +398 -0
- data/lib/active_scaffold/marked_model.rb +38 -0
- data/lib/active_scaffold/paginator.rb +136 -0
- data/lib/active_scaffold/responds_to_parent.rb +70 -0
- data/lib/active_scaffold/tableless.rb +83 -0
- data/lib/active_scaffold/version.rb +9 -0
- data/lib/active_scaffold.rb +373 -0
- data/lib/active_scaffold_env.rb +13 -0
- data/lib/generators/active_scaffold/USAGE +29 -0
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +21 -0
- data/lib/generators/active_scaffold_controller/USAGE +19 -0
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +29 -0
- data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
- data/lib/generators/active_scaffold_controller/templates/helper.rb +2 -0
- data/public/blank.html +33 -0
- data/shoulda_macros/macros.rb +136 -0
- data/vendor/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
- data/vendor/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
- data/vendor/assets/images/ui-bg_flat_10_000000_40x100.png +0 -0
- data/vendor/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
- data/vendor/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
- data/vendor/assets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/vendor/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
- data/vendor/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
- data/vendor/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
- data/vendor/assets/images/ui-icons_222222_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_228ef1_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_ef8c08_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_ffd27a_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_ffffff_256x240.png +0 -0
- data/vendor/assets/javascripts/jquery-ui-timepicker-addon.js +1276 -0
- data/vendor/assets/stylesheets/jquery-ui.css +568 -0
- metadata +261 -17
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module ActiveScaffold
|
|
2
|
+
module Helpers
|
|
3
|
+
module FormColumnHelpers
|
|
4
|
+
def active_scaffold_input_dragonfly(column, options)
|
|
5
|
+
options = active_scaffold_input_text_options(options)
|
|
6
|
+
input = file_field(:record, column.name, options)
|
|
7
|
+
dragonfly = @record.send("#{column.name}")
|
|
8
|
+
if dragonfly.present?
|
|
9
|
+
if ActiveScaffold.js_framework == :jquery
|
|
10
|
+
js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;";
|
|
11
|
+
else
|
|
12
|
+
js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;";
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
content = active_scaffold_column_dragonfly(column, @record)
|
|
16
|
+
content_tag(:div,
|
|
17
|
+
content + " | " +
|
|
18
|
+
hidden_field(:record, "remove_#{column.name}", :value => "false") +
|
|
19
|
+
content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code})
|
|
20
|
+
) + content_tag(:div, input, :style => "display: none")
|
|
21
|
+
else
|
|
22
|
+
input
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module ActiveScaffold
|
|
2
|
+
module Helpers
|
|
3
|
+
module ListColumnHelpers
|
|
4
|
+
def active_scaffold_column_dragonfly(column, record)
|
|
5
|
+
attachment = record.send("#{column.name}")
|
|
6
|
+
return nil unless attachment.present?
|
|
7
|
+
content = if attachment.image?
|
|
8
|
+
image_tag(attachment.thumb(column.options[:thumb] || ActiveScaffold::Bridges::Dragonfly::DragonflyBridgeHelpers.thumbnail_style).url, :border => 0)
|
|
9
|
+
else
|
|
10
|
+
attachment.name
|
|
11
|
+
end
|
|
12
|
+
link_to(content, attachment.remote_url, {'data-popup' => true, :target => '_blank'})
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
class ActiveScaffold::Bridges::Dragonfly < ActiveScaffold::DataStructures::Bridge
|
|
2
|
+
def self.install
|
|
3
|
+
require File.join(File.dirname(__FILE__), "dragonfly/form_ui")
|
|
4
|
+
require File.join(File.dirname(__FILE__), "dragonfly/list_ui")
|
|
5
|
+
require File.join(File.dirname(__FILE__), "dragonfly/dragonfly_bridge_helpers")
|
|
6
|
+
require File.join(File.dirname(__FILE__), "dragonfly/dragonfly_bridge")
|
|
7
|
+
ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Dragonfly::DragonflyBridge
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
ActiveScaffold::DataStructures::Column.class_eval do
|
|
2
|
+
attr_accessor :file_column_display
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
module ActiveScaffold::Config
|
|
6
|
+
class Core < Base
|
|
7
|
+
attr_accessor :file_column_fields
|
|
8
|
+
def initialize_with_file_column(model_id)
|
|
9
|
+
initialize_without_file_column(model_id)
|
|
10
|
+
|
|
11
|
+
return unless ActiveScaffold::Bridges::FileColumn::FileColumnHelpers.klass_has_file_column_fields?(self.model)
|
|
12
|
+
|
|
13
|
+
self.model.send :extend, ActiveScaffold::Bridges::FileColumn::FileColumnHelpers
|
|
14
|
+
|
|
15
|
+
# include the "delete" helpers for use with active scaffold, unless they are already included
|
|
16
|
+
self.model.generate_delete_helpers
|
|
17
|
+
|
|
18
|
+
# switch on multipart
|
|
19
|
+
self.update.multipart = true
|
|
20
|
+
self.create.multipart = true
|
|
21
|
+
|
|
22
|
+
self.model.file_column_fields.each{ |field|
|
|
23
|
+
configure_file_column_field(field)
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
alias_method_chain :initialize, :file_column unless self.instance_methods.include?("initialize_without_file_column")
|
|
28
|
+
|
|
29
|
+
def configure_file_column_field(field)
|
|
30
|
+
# set list_ui first because it gets its default value from form_ui
|
|
31
|
+
self.columns[field].list_ui ||= self.model.field_has_image_version?(field, "thumb") ? :thumbnail : :download_link_with_filename
|
|
32
|
+
self.columns[field].form_ui ||= :file_column
|
|
33
|
+
|
|
34
|
+
# these 2 parameters are necessary helper attributes for the file column that must be allowed to be set to the model by active scaffold.
|
|
35
|
+
self.columns[field].params.add "#{field}_temp", "delete_#{field}"
|
|
36
|
+
|
|
37
|
+
# set null to false so active_scaffold wont set it to null
|
|
38
|
+
# delete_file_column will take care of deleting a file or not.
|
|
39
|
+
self.model.columns_hash[field.to_s].instance_variable_set("@null", false)
|
|
40
|
+
|
|
41
|
+
rescue
|
|
42
|
+
false
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module ActiveScaffold
|
|
2
|
+
module Bridges
|
|
3
|
+
class FileColumn
|
|
4
|
+
module FileColumnHelpers
|
|
5
|
+
class << self
|
|
6
|
+
def file_column_fields(klass)
|
|
7
|
+
klass.instance_methods.grep(/_just_uploaded\?$/).collect{|m| m[0..-16].to_sym }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def generate_delete_helpers(klass)
|
|
11
|
+
file_column_fields(klass).each { |field|
|
|
12
|
+
klass.send :class_eval, <<-EOF, __FILE__, __LINE__ + 1 unless klass.methods.include?("#{field}_with_delete=")
|
|
13
|
+
attr_reader :delete_#{field}
|
|
14
|
+
|
|
15
|
+
def delete_#{field}=(value)
|
|
16
|
+
value = (value=="true") if String===value
|
|
17
|
+
return unless value
|
|
18
|
+
|
|
19
|
+
# passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file!
|
|
20
|
+
self.#{field} = nil unless self.#{field}_just_uploaded?
|
|
21
|
+
end
|
|
22
|
+
EOF
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def klass_has_file_column_fields?(klass)
|
|
27
|
+
true unless file_column_fields(klass).empty?
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def file_column_fields
|
|
32
|
+
@file_column_fields||=FileColumnHelpers.file_column_fields(self)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def options_for_file_column_field(field)
|
|
36
|
+
self.allocate.send("#{field}_options")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def field_has_image_version?(field, version="thumb")
|
|
40
|
+
begin
|
|
41
|
+
# the only way to get to the options of a particular field is to use the instance method
|
|
42
|
+
options = options_for_file_column_field(field)
|
|
43
|
+
versions = options[:magick][:versions]
|
|
44
|
+
raise unless versions.stringify_keys[version]
|
|
45
|
+
true
|
|
46
|
+
rescue
|
|
47
|
+
false
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def generate_delete_helpers
|
|
52
|
+
FileColumnHelpers.generate_delete_helpers(self)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module ActiveScaffold
|
|
2
|
+
module Helpers
|
|
3
|
+
# Helpers that assist with the rendering of a Form Column
|
|
4
|
+
module FormColumnHelpers
|
|
5
|
+
def active_scaffold_input_file_column(column, options)
|
|
6
|
+
if @record.send(column.name)
|
|
7
|
+
# we already have a value? display the form for deletion.
|
|
8
|
+
if ActiveScaffold.js_framework == :jquery
|
|
9
|
+
remove_file_js = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;";
|
|
10
|
+
else
|
|
11
|
+
remove_file_js = "$(this).previous().value='true'; p=$(this).up(); p.hide(); p.next().show(); return false;";
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
hidden_options = options.dup
|
|
15
|
+
hidden_options[:id] += '_delete'
|
|
16
|
+
hidden_options[:name].sub!("[#{column.name}]", "[delete_#{column.name}]")
|
|
17
|
+
hidden_options[:value] = 'false'
|
|
18
|
+
custom_hidden_field_tag = hidden_field(:record, column.name, hidden_options)
|
|
19
|
+
|
|
20
|
+
content_tag(:div) do
|
|
21
|
+
content_tag(:div) do
|
|
22
|
+
content = get_column_value(@record, column) + " #{custom_hidden_field_tag} | ".html_safe
|
|
23
|
+
content += content_tag(:a, as_(:remove_file), {:href => '#', :onclick => remove_file_js})
|
|
24
|
+
content += content_tag(:div, file_column_field("record", column.name, options), :style => "display: none")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
file_column_field("record", column.name, options)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module ActiveScaffold
|
|
2
|
+
module Helpers
|
|
3
|
+
# Helpers that assist with the rendering of a List Column
|
|
4
|
+
module ListColumnHelpers
|
|
5
|
+
def active_scaffold_column_download_link_with_filename(column, record)
|
|
6
|
+
return nil if record.send(column.name).nil?
|
|
7
|
+
active_scaffold_column_download_link(column, record, File.basename(record.send(column.name)))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def active_scaffold_column_download_link(column, record, label = nil)
|
|
11
|
+
return nil if record.send(column.name).nil?
|
|
12
|
+
label||=as_(:download)
|
|
13
|
+
link_to( label, url_for_file_column(record, column.name.to_s), :popup => true)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def active_scaffold_column_thumbnail(column, record)
|
|
17
|
+
return nil if record.send(column.name).nil?
|
|
18
|
+
link_to(
|
|
19
|
+
image_tag(url_for_file_column(record, column.name.to_s, "thumb"), :border => 0),
|
|
20
|
+
url_for_file_column(record, column.name.to_s),
|
|
21
|
+
:popup => true)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), "../test_helper.rb")
|
|
2
|
+
|
|
3
|
+
class DeleteFileColumnTest < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
DeleteFileColumn.generate_delete_helpers(MockModel)
|
|
6
|
+
@model = MockModel.new
|
|
7
|
+
@model.band_image = "coolio.jpg"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test__file_column_fields
|
|
11
|
+
assert_equal(1, @model.file_column_fields.length)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test__delete_band_image__boolean__should_delete
|
|
15
|
+
@model.delete_band_image = true
|
|
16
|
+
assert_nil @model.band_image
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test__delete_band_image__string__should_delete
|
|
20
|
+
@model.delete_band_image = "true"
|
|
21
|
+
assert_nil @model.band_image
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test__delete_band_image__boolean_false__shouldnt_delete
|
|
26
|
+
@model.delete_band_image = false
|
|
27
|
+
assert_not_nil @model.band_image
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test__delete_band_image__string_false__shouldnt_delete
|
|
31
|
+
@model.delete_band_image = "false"
|
|
32
|
+
assert_not_nil @model.band_image
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test__just_uploaded__shouldnt_delete
|
|
37
|
+
@model.band_image_just_uploaded = true
|
|
38
|
+
@model.delete_band_image = "true"
|
|
39
|
+
assert_not_nil(@model.band_image)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require "rubygems"
|
|
3
|
+
require 'active_support'
|
|
4
|
+
|
|
5
|
+
for file in ["../lib/delete_file_column.rb", "mock_model.rb"]
|
|
6
|
+
require File.expand_path(File.join(File.dirname(__FILE__), file))
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def dbg
|
|
12
|
+
require 'ruby-debug'
|
|
13
|
+
Debugger.start
|
|
14
|
+
debugger
|
|
15
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class ActiveScaffold::Bridges::FileColumn < ActiveScaffold::DataStructures::Bridge
|
|
2
|
+
def self.install
|
|
3
|
+
if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_file_column")
|
|
4
|
+
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"
|
|
5
|
+
end
|
|
6
|
+
require File.join(File.dirname(__FILE__), "file_column/as_file_column_bridge")
|
|
7
|
+
require File.join(File.dirname(__FILE__), "file_column/form_ui")
|
|
8
|
+
require File.join(File.dirname(__FILE__), "file_column/list_ui")
|
|
9
|
+
require File.join(File.dirname(__FILE__), "file_column/file_column_helpers")
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module ActiveScaffold
|
|
2
|
+
module Helpers
|
|
3
|
+
module FormColumnHelpers
|
|
4
|
+
def active_scaffold_input_paperclip(column, options)
|
|
5
|
+
options = active_scaffold_input_text_options(options)
|
|
6
|
+
input = file_field(:record, column.name, options)
|
|
7
|
+
paperclip = @record.send("#{column.name}")
|
|
8
|
+
if paperclip.file?
|
|
9
|
+
if ActiveScaffold.js_framework == :jquery
|
|
10
|
+
js_remove_file_code = "$(this).prev().val('true'); $(this).parent().hide().next().show(); return false;";
|
|
11
|
+
else
|
|
12
|
+
js_remove_file_code = "$(this).previous().value='true'; $(this).up().hide().next().show(); return false;";
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
content = active_scaffold_column_paperclip(column, @record)
|
|
16
|
+
content_tag(:div,
|
|
17
|
+
content + " | " +
|
|
18
|
+
hidden_field(:record, "delete_#{column.name}", :value => "false") +
|
|
19
|
+
content_tag(:a, as_(:remove_file), {:href => '#', :onclick => js_remove_file_code})
|
|
20
|
+
) + content_tag(:div, input, :style => "display: none")
|
|
21
|
+
else
|
|
22
|
+
input
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module ActiveScaffold
|
|
2
|
+
module Helpers
|
|
3
|
+
module ListColumnHelpers
|
|
4
|
+
def active_scaffold_column_paperclip(column, record)
|
|
5
|
+
paperclip = record.send("#{column.name}")
|
|
6
|
+
return nil unless paperclip.file?
|
|
7
|
+
content = if paperclip.styles.include?(ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.thumbnail_style)
|
|
8
|
+
image_tag(paperclip.url(ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.thumbnail_style), :border => 0)
|
|
9
|
+
else
|
|
10
|
+
paperclip.original_filename
|
|
11
|
+
end
|
|
12
|
+
link_to(content, paperclip.url, {'data-popup' => true, :target => '_blank'})
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module ActiveScaffold
|
|
2
|
+
module Bridges
|
|
3
|
+
class Paperclip
|
|
4
|
+
module PaperclipBridge
|
|
5
|
+
def initialize_with_paperclip(model_id)
|
|
6
|
+
initialize_without_paperclip(model_id)
|
|
7
|
+
return unless self.model.respond_to?(:attachment_definitions) && !self.model.attachment_definitions.nil?
|
|
8
|
+
|
|
9
|
+
self.update.multipart = true
|
|
10
|
+
self.create.multipart = true
|
|
11
|
+
|
|
12
|
+
self.model.attachment_definitions.keys.each do |field|
|
|
13
|
+
configure_paperclip_field(field.to_sym)
|
|
14
|
+
# define the "delete" helper for use with active scaffold, unless it's already defined
|
|
15
|
+
ActiveScaffold::Bridges::Paperclip::PaperclipBridgeHelpers.generate_delete_helper(self.model, field)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.included(base)
|
|
20
|
+
base.alias_method_chain :initialize, :paperclip
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
def configure_paperclip_field(field)
|
|
25
|
+
self.columns << field
|
|
26
|
+
self.columns[field].form_ui ||= :paperclip
|
|
27
|
+
self.columns[field].params.add "delete_#{field}"
|
|
28
|
+
|
|
29
|
+
[:file_name, :content_type, :file_size, :updated_at].each do |f|
|
|
30
|
+
self.columns.exclude("#{field}_#{f}".to_sym)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module ActiveScaffold
|
|
2
|
+
module Bridges
|
|
3
|
+
class Paperclip
|
|
4
|
+
module PaperclipBridgeHelpers
|
|
5
|
+
mattr_accessor :thumbnail_style
|
|
6
|
+
self.thumbnail_style = :thumbnail
|
|
7
|
+
|
|
8
|
+
def self.generate_delete_helper(klass, field)
|
|
9
|
+
klass.class_eval <<-EOF, __FILE__, __LINE__ + 1 unless klass.instance_methods.include?("delete_#{field}=")
|
|
10
|
+
attr_reader :delete_#{field}
|
|
11
|
+
|
|
12
|
+
def delete_#{field}=(value)
|
|
13
|
+
value = (value == "true") if String === value
|
|
14
|
+
return unless value
|
|
15
|
+
|
|
16
|
+
# passing nil to the file column causes the file to be deleted. Don't delete if we just uploaded a file!
|
|
17
|
+
self.#{field} = nil unless self.#{field}.dirty?
|
|
18
|
+
end
|
|
19
|
+
EOF
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class ActiveScaffold::Bridges::Paperclip < ActiveScaffold::DataStructures::Bridge
|
|
2
|
+
def self.install
|
|
3
|
+
if ActiveScaffold::Config::Core.instance_methods.include?("initialize_with_paperclip")
|
|
4
|
+
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"
|
|
5
|
+
end
|
|
6
|
+
require File.join(File.dirname(__FILE__), "paperclip/form_ui")
|
|
7
|
+
require File.join(File.dirname(__FILE__), "paperclip/list_ui")
|
|
8
|
+
require File.join(File.dirname(__FILE__), "paperclip/paperclip_bridge_helpers")
|
|
9
|
+
require File.join(File.dirname(__FILE__), "paperclip/paperclip_bridge")
|
|
10
|
+
ActiveScaffold::Config::Core.send :include, ActiveScaffold::Bridges::Paperclip::PaperclipBridge
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
class ActiveScaffold::Bridges::RecordSelect
|
|
2
|
+
module Helpers
|
|
3
|
+
def self.included(base)
|
|
4
|
+
base.class_eval do
|
|
5
|
+
include FormColumnHelpers
|
|
6
|
+
include SearchColumnHelpers
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
module FormColumnHelpers
|
|
11
|
+
# requires RecordSelect plugin to be installed and configured.
|
|
12
|
+
def active_scaffold_input_record_select(column, options)
|
|
13
|
+
if column.singular_association?
|
|
14
|
+
multiple = false
|
|
15
|
+
multiple = column.options[:html_options][:multiple] if column.options[:html_options] && column.options[:html_options][:multiple]
|
|
16
|
+
active_scaffold_record_select(column, options, @record.send(column.name), multiple)
|
|
17
|
+
elsif column.plural_association?
|
|
18
|
+
active_scaffold_record_select(column, options, @record.send(column.name), true)
|
|
19
|
+
else
|
|
20
|
+
active_scaffold_record_select_autocomplete(column, options)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def active_scaffold_record_select(column, options, value, multiple)
|
|
25
|
+
unless column.association
|
|
26
|
+
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)."
|
|
27
|
+
end
|
|
28
|
+
klass = if column.polymorphic_association?
|
|
29
|
+
@record.send(column.association.foreign_type).constantize rescue nil
|
|
30
|
+
else
|
|
31
|
+
column.association.klass
|
|
32
|
+
end
|
|
33
|
+
return content_tag :span, '', :class => options[:class] unless klass
|
|
34
|
+
|
|
35
|
+
remote_controller = active_scaffold_controller_for(klass).controller_path
|
|
36
|
+
|
|
37
|
+
# if the opposite association is a :belongs_to (in that case association in this class must be has_one or has_many)
|
|
38
|
+
# then only show records that have not been associated yet
|
|
39
|
+
if [:has_one, :has_many].include?(column.association.macro)
|
|
40
|
+
params.merge!({column.association.foreign_key => ''})
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
record_select_options = active_scaffold_input_text_options(options).merge(
|
|
44
|
+
:controller => remote_controller
|
|
45
|
+
)
|
|
46
|
+
record_select_options.merge!(column.options)
|
|
47
|
+
|
|
48
|
+
html = if multiple
|
|
49
|
+
record_multi_select_field(options[:name], value || [], record_select_options)
|
|
50
|
+
else
|
|
51
|
+
record_select_field(options[:name], value || klass.new, record_select_options)
|
|
52
|
+
end
|
|
53
|
+
html = self.class.field_error_proc.call(html, self) if @record.errors[column.name].any?
|
|
54
|
+
html
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def active_scaffold_record_select_autocomplete(column, options)
|
|
58
|
+
record_select_options = active_scaffold_input_text_options(options).merge(
|
|
59
|
+
:controller => active_scaffold_controller_for(@record.class).controller_path
|
|
60
|
+
)
|
|
61
|
+
html = record_select_autocomplete(options[:name], @record, record_select_options)
|
|
62
|
+
html = self.class.field_error_proc.call(html, self) if @record.errors[column.name].any?
|
|
63
|
+
html
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
module SearchColumnHelpers
|
|
68
|
+
def active_scaffold_search_record_select(column, options)
|
|
69
|
+
value = field_search_record_select_value(column)
|
|
70
|
+
active_scaffold_record_select(column, options, value, column.options[:multiple])
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def field_search_record_select_value(column)
|
|
74
|
+
begin
|
|
75
|
+
value = field_search_params[column.name]
|
|
76
|
+
unless value.blank?
|
|
77
|
+
if column.options[:multiple]
|
|
78
|
+
column.association.klass.find value.collect!(&:to_i)
|
|
79
|
+
else
|
|
80
|
+
column.association.klass.find(value.to_i)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
rescue Exception => e
|
|
84
|
+
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}"
|
|
85
|
+
raise e
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
ActionView::Base.class_eval { include ActiveScaffold::Bridges::RecordSelect::Helpers }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class ActiveScaffold::Bridges::RecordSelect < ActiveScaffold::DataStructures::Bridge
|
|
2
|
+
def self.install
|
|
3
|
+
require File.join(File.dirname(__FILE__), "record_select/helpers.rb")
|
|
4
|
+
end
|
|
5
|
+
def self.stylesheets
|
|
6
|
+
'record_select'
|
|
7
|
+
end
|
|
8
|
+
def self.javascripts
|
|
9
|
+
'record_select'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class ActiveScaffold::Bridges::SemanticAttributes
|
|
2
|
+
module Column
|
|
3
|
+
def self.included(base)
|
|
4
|
+
base.class_eval { alias_method_chain :initialize, :semantic_attributes }
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def initialize_with_semantic_attributes(name, active_record_class)
|
|
8
|
+
initialize_without_semantic_attributes(name, active_record_class)
|
|
9
|
+
self.required = !active_record_class.semantic_attributes[self.name].predicates.find {|p| p.allow_empty? == false }.nil?
|
|
10
|
+
active_record_class.semantic_attributes[self.name].predicates.find do |p|
|
|
11
|
+
sem_type = p.class.to_s.split('::')[1].underscore.to_sym
|
|
12
|
+
next if [:required, :association].include?(sem_type)
|
|
13
|
+
@form_ui = sem_type
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
ActiveScaffold::DataStructures::Column.class_eval do
|
|
19
|
+
include ActiveScaffold::Bridges::SemanticAttributes::Column
|
|
20
|
+
end
|