active_scaffold 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +27 -0
- data/CHANGELOG +152 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README +51 -0
- data/Rakefile +24 -0
- data/active_scaffold.gemspec +24 -0
- data/environment.rb +22 -0
- data/frontends/default/images/add.gif +0 -0
- data/frontends/default/images/arrow_down.gif +0 -0
- data/frontends/default/images/arrow_up.gif +0 -0
- data/frontends/default/images/close.gif +0 -0
- data/frontends/default/images/cross.png +0 -0
- data/frontends/default/images/indicator-small.gif +0 -0
- data/frontends/default/images/indicator.gif +0 -0
- data/frontends/default/images/magnifier.png +0 -0
- data/frontends/default/javascripts/jquery/active_scaffold.js +957 -0
- data/frontends/default/javascripts/jquery/jquery.editinplace.js +726 -0
- data/frontends/default/javascripts/prototype/active_scaffold.js +954 -0
- data/frontends/default/javascripts/prototype/dhtml_history.js +867 -0
- data/frontends/default/javascripts/prototype/form_enhancements.js +117 -0
- data/frontends/default/javascripts/prototype/rico_corner.js +370 -0
- data/frontends/default/stylesheets/stylesheet-ie.css +35 -0
- data/frontends/default/stylesheets/stylesheet.css +858 -0
- data/frontends/default/views/_add_existing_form.html.erb +30 -0
- data/frontends/default/views/_base_form.html.erb +41 -0
- data/frontends/default/views/_create_form.html.erb +6 -0
- data/frontends/default/views/_create_form_on_list.html.erb +5 -0
- data/frontends/default/views/_field_search.html.erb +32 -0
- data/frontends/default/views/_form.html.erb +24 -0
- data/frontends/default/views/_form_association.html.erb +14 -0
- data/frontends/default/views/_form_association_footer.html.erb +40 -0
- data/frontends/default/views/_form_attribute.html.erb +15 -0
- data/frontends/default/views/_form_hidden_attribute.html.erb +2 -0
- data/frontends/default/views/_form_messages.html.erb +5 -0
- data/frontends/default/views/_horizontal_subform.html.erb +19 -0
- data/frontends/default/views/_horizontal_subform_header.html.erb +10 -0
- data/frontends/default/views/_horizontal_subform_record.html.erb +37 -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 +16 -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 +12 -0
- data/frontends/default/views/_list_inline_adapter.html.erb +10 -0
- data/frontends/default/views/_list_messages.html.erb +32 -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 +14 -0
- data/frontends/default/views/_list_record_columns.html.erb +8 -0
- data/frontends/default/views/_list_with_header.html.erb +32 -0
- data/frontends/default/views/_messages.html.erb +10 -0
- data/frontends/default/views/_render_field.js.rjs +13 -0
- data/frontends/default/views/_row.html.erb +12 -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 +12 -0
- data/frontends/default/views/_update_actions.html.erb +9 -0
- data/frontends/default/views/_update_form.html.erb +5 -0
- data/frontends/default/views/_vertical_subform.html.erb +12 -0
- data/frontends/default/views/_vertical_subform_record.html.erb +38 -0
- data/frontends/default/views/add_existing.js.rjs +17 -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.rjs +5 -0
- data/frontends/default/views/edit_associated.js.rjs +11 -0
- data/frontends/default/views/field_search.html.erb +5 -0
- data/frontends/default/views/form_messages.js.rjs +1 -0
- data/frontends/default/views/list.html.erb +1 -0
- data/frontends/default/views/list.js.rjs +1 -0
- data/frontends/default/views/on_action_update.js.rjs +8 -0
- data/frontends/default/views/on_create.js.rjs +24 -0
- data/frontends/default/views/on_update.js.rjs +15 -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.rjs +13 -0
- data/frontends/default/views/update_row.js.rjs +1 -0
- data/init.rb +1 -0
- data/install_assets.rb +44 -0
- data/lib/active_record_permissions.rb +134 -0
- data/lib/active_scaffold.rb +279 -0
- data/lib/active_scaffold/actions/common_search.rb +22 -0
- data/lib/active_scaffold/actions/core.rb +150 -0
- data/lib/active_scaffold/actions/create.rb +152 -0
- data/lib/active_scaffold/actions/delete.rb +72 -0
- data/lib/active_scaffold/actions/field_search.rb +82 -0
- data/lib/active_scaffold/actions/list.rb +128 -0
- data/lib/active_scaffold/actions/mark.rb +50 -0
- data/lib/active_scaffold/actions/nested.rb +241 -0
- data/lib/active_scaffold/actions/search.rb +47 -0
- data/lib/active_scaffold/actions/show.rb +54 -0
- data/lib/active_scaffold/actions/subform.rb +17 -0
- data/lib/active_scaffold/actions/update.rb +134 -0
- data/lib/active_scaffold/attribute_params.rb +207 -0
- data/lib/active_scaffold/bridges/ancestry/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/ancestry/lib/ancestry_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/bridge.rb +52 -0
- data/lib/active_scaffold/bridges/calendar_date_select/bridge.rb +16 -0
- data/lib/active_scaffold/bridges/calendar_date_select/lib/as_cds_bridge.rb +79 -0
- data/lib/active_scaffold/bridges/carrierwave/bridge.rb +7 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/carrierwave_bridge_helpers.rb +26 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/form_ui.rb +35 -0
- data/lib/active_scaffold/bridges/carrierwave/lib/list_ui.rb +17 -0
- data/lib/active_scaffold/bridges/date_picker/bridge.rb +22 -0
- data/lib/active_scaffold/bridges/date_picker/lib/datepicker_bridge.rb +225 -0
- data/lib/active_scaffold/bridges/date_picker/public/javascripts/date_picker_bridge.js +22 -0
- data/lib/active_scaffold/bridges/file_column/bridge.rb +11 -0
- data/lib/active_scaffold/bridges/file_column/lib/as_file_column_bridge.rb +46 -0
- data/lib/active_scaffold/bridges/file_column/lib/file_column_helpers.rb +59 -0
- data/lib/active_scaffold/bridges/file_column/lib/form_ui.rb +37 -0
- data/lib/active_scaffold/bridges/file_column/lib/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/paperclip/bridge.rb +12 -0
- data/lib/active_scaffold/bridges/paperclip/lib/form_ui.rb +27 -0
- data/lib/active_scaffold/bridges/paperclip/lib/list_ui.rb +16 -0
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge.rb +38 -0
- data/lib/active_scaffold/bridges/paperclip/lib/paperclip_bridge_helpers.rb +26 -0
- data/lib/active_scaffold/bridges/semantic_attributes/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/semantic_attributes/lib/semantic_attributes_bridge.rb +20 -0
- data/lib/active_scaffold/bridges/shared/date_bridge.rb +187 -0
- data/lib/active_scaffold/bridges/tiny_mce/bridge.rb +5 -0
- data/lib/active_scaffold/bridges/tiny_mce/lib/tiny_mce_bridge.rb +45 -0
- data/lib/active_scaffold/bridges/validation_reflection/bridge.rb +8 -0
- data/lib/active_scaffold/bridges/validation_reflection/lib/validation_reflection_bridge.rb +21 -0
- data/lib/active_scaffold/config/base.rb +54 -0
- data/lib/active_scaffold/config/core.rb +229 -0
- data/lib/active_scaffold/config/create.rb +43 -0
- data/lib/active_scaffold/config/delete.rb +25 -0
- data/lib/active_scaffold/config/field_search.rb +74 -0
- data/lib/active_scaffold/config/form.rb +46 -0
- data/lib/active_scaffold/config/list.rb +174 -0
- data/lib/active_scaffold/config/mark.rb +22 -0
- data/lib/active_scaffold/config/nested.rb +43 -0
- data/lib/active_scaffold/config/search.rb +68 -0
- data/lib/active_scaffold/config/show.rb +34 -0
- data/lib/active_scaffold/config/subform.rb +35 -0
- data/lib/active_scaffold/config/update.rb +38 -0
- data/lib/active_scaffold/configurable.rb +29 -0
- data/lib/active_scaffold/constraints.rb +179 -0
- data/lib/active_scaffold/data_structures/action_columns.rb +133 -0
- data/lib/active_scaffold/data_structures/action_link.rb +162 -0
- data/lib/active_scaffold/data_structures/action_links.rb +59 -0
- data/lib/active_scaffold/data_structures/actions.rb +45 -0
- data/lib/active_scaffold/data_structures/column.rb +348 -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 +108 -0
- data/lib/active_scaffold/data_structures/set.rb +62 -0
- data/lib/active_scaffold/data_structures/sorting.rb +168 -0
- data/lib/active_scaffold/finder.rb +333 -0
- data/lib/active_scaffold/helpers/association_helpers.rb +40 -0
- data/lib/active_scaffold/helpers/controller_helpers.rb +40 -0
- data/lib/active_scaffold/helpers/country_helpers.rb +352 -0
- data/lib/active_scaffold/helpers/form_column_helpers.rb +343 -0
- data/lib/active_scaffold/helpers/human_condition_helpers.rb +59 -0
- data/lib/active_scaffold/helpers/id_helpers.rb +131 -0
- data/lib/active_scaffold/helpers/list_column_helpers.rb +363 -0
- data/lib/active_scaffold/helpers/pagination_helpers.rb +55 -0
- data/lib/active_scaffold/helpers/search_column_helpers.rb +238 -0
- data/lib/active_scaffold/helpers/show_column_helpers.rb +46 -0
- data/lib/active_scaffold/helpers/view_helpers.rb +315 -0
- data/lib/active_scaffold/locale/de.rb +113 -0
- data/lib/active_scaffold/locale/en.rb +118 -0
- data/lib/active_scaffold/locale/es.yml +112 -0
- data/lib/active_scaffold/locale/fr.rb +113 -0
- data/lib/active_scaffold/locale/hu.yml +63 -0
- data/lib/active_scaffold/locale/ja.yml +64 -0
- data/lib/active_scaffold/locale/ru.yml +62 -0
- data/lib/active_scaffold/marked_model.rb +38 -0
- data/lib/dhtml_confirm.rb +54 -0
- data/lib/extensions/action_controller_rendering.rb +20 -0
- data/lib/extensions/action_view_rendering.rb +113 -0
- data/lib/extensions/action_view_resolver.rb +7 -0
- data/lib/extensions/active_record_offset.rb +12 -0
- data/lib/extensions/array.rb +7 -0
- data/lib/extensions/localize.rb +10 -0
- data/lib/extensions/name_option_for_datetime.rb +12 -0
- data/lib/extensions/nil_id_in_url_params.rb +7 -0
- data/lib/extensions/paginator_extensions.rb +26 -0
- data/lib/extensions/reverse_associations.rb +62 -0
- data/lib/extensions/routing_mapper.rb +34 -0
- data/lib/extensions/to_label.rb +8 -0
- data/lib/extensions/unsaved_associated.rb +61 -0
- data/lib/extensions/unsaved_record.rb +20 -0
- data/lib/extensions/usa_state.rb +46 -0
- data/lib/generators/active_scaffold/USAGE +29 -0
- data/lib/generators/active_scaffold/active_scaffold_generator.rb +20 -0
- data/lib/generators/active_scaffold_controller/USAGE +19 -0
- data/lib/generators/active_scaffold_controller/active_scaffold_controller_generator.rb +28 -0
- data/lib/generators/active_scaffold_controller/templates/controller.rb +4 -0
- data/lib/generators/active_scaffold_setup/USAGE +10 -0
- data/lib/generators/active_scaffold_setup/active_scaffold_setup_generator.rb +53 -0
- data/lib/paginator.rb +136 -0
- data/lib/responds_to_parent.rb +70 -0
- data/public/blank.html +33 -0
- data/shoulda_macros/macros.rb +136 -0
- data/test/bridges/bridge_test.rb +47 -0
- data/test/config/base_test.rb +15 -0
- data/test/config/create_test.rb +55 -0
- data/test/config/list_test.rb +74 -0
- data/test/config/show_test.rb +43 -0
- data/test/config/update_test.rb +17 -0
- data/test/const_mocker.rb +36 -0
- data/test/data_structures/action_columns_test.rb +113 -0
- data/test/data_structures/action_link_test.rb +78 -0
- data/test/data_structures/action_links_test.rb +78 -0
- data/test/data_structures/actions_test.rb +25 -0
- data/test/data_structures/association_column_test.rb +42 -0
- data/test/data_structures/column_test.rb +185 -0
- data/test/data_structures/columns_test.rb +69 -0
- data/test/data_structures/error_message_test.rb +28 -0
- data/test/data_structures/set_test.rb +86 -0
- data/test/data_structures/sorting_test.rb +126 -0
- data/test/data_structures/standard_column_test.rb +24 -0
- data/test/data_structures/virtual_column_test.rb +23 -0
- data/test/extensions/active_record_test.rb +45 -0
- data/test/extensions/array_test.rb +12 -0
- data/test/helpers/form_column_helpers_test.rb +31 -0
- data/test/helpers/list_column_helpers_test.rb +31 -0
- data/test/helpers/pagination_helpers_test.rb +55 -0
- data/test/misc/active_record_permissions_test.rb +154 -0
- data/test/misc/attribute_params_test.rb +110 -0
- data/test/misc/configurable_test.rb +96 -0
- data/test/misc/constraints_test.rb +193 -0
- data/test/misc/finder_test.rb +93 -0
- data/test/misc/lang_test.rb +12 -0
- data/test/mock_app/.gitignore +2 -0
- data/test/mock_app/app/controllers/application_controller.rb +10 -0
- data/test/mock_app/app/helpers/application_helper.rb +3 -0
- data/test/mock_app/config/boot.rb +110 -0
- data/test/mock_app/config/database.yml +16 -0
- data/test/mock_app/config/environment.rb +43 -0
- data/test/mock_app/config/environments/development.rb +17 -0
- data/test/mock_app/config/environments/production.rb +28 -0
- data/test/mock_app/config/environments/test.rb +28 -0
- data/test/mock_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/mock_app/config/initializers/inflections.rb +10 -0
- data/test/mock_app/config/initializers/mime_types.rb +5 -0
- data/test/mock_app/config/initializers/new_rails_defaults.rb +19 -0
- data/test/mock_app/config/initializers/session_store.rb +15 -0
- data/test/mock_app/config/locales/en.yml +5 -0
- data/test/mock_app/config/routes.rb +43 -0
- data/test/mock_app/db/test.sqlite3 +1 -0
- data/test/mock_app/public/blank.html +33 -0
- data/test/mock_app/public/images/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/images/active_scaffold/default/add.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/arrow_down.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/arrow_up.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/close.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/cross.png +0 -0
- data/test/mock_app/public/images/active_scaffold/default/indicator-small.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/indicator.gif +0 -0
- data/test/mock_app/public/images/active_scaffold/default/magnifier.png +0 -0
- data/test/mock_app/public/javascripts/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/active_scaffold.js +532 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/dhtml_history.js +867 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/form_enhancements.js +117 -0
- data/test/mock_app/public/javascripts/active_scaffold/default/rico_corner.js +370 -0
- data/test/mock_app/public/stylesheets/active_scaffold/DO_NOT_EDIT +2 -0
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet-ie.css +35 -0
- data/test/mock_app/public/stylesheets/active_scaffold/default/stylesheet.css +839 -0
- data/test/model_stub.rb +55 -0
- data/test/run_all.rb +8 -0
- data/test/test_helper.rb +39 -0
- data/uninstall.rb +13 -0
- metadata +478 -0
data/lib/paginator.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
class Paginator
|
4
|
+
|
5
|
+
VERSION = '1.0.9'
|
6
|
+
|
7
|
+
class ArgumentError < ::ArgumentError; end
|
8
|
+
class MissingCountError < ArgumentError; end
|
9
|
+
class MissingSelectError < ArgumentError; end
|
10
|
+
|
11
|
+
attr_reader :per_page, :count
|
12
|
+
|
13
|
+
# Instantiate a new Paginator object
|
14
|
+
#
|
15
|
+
# Provide:
|
16
|
+
# * A total count of the number of objects to paginate
|
17
|
+
# * The number of objects in each page
|
18
|
+
# * A block that returns the array of items
|
19
|
+
# * The block is passed the item offset
|
20
|
+
# (and the number of items to show per page, for
|
21
|
+
# convenience, if the arity is 2)
|
22
|
+
def initialize(count, per_page, &select)
|
23
|
+
@count, @per_page = count, per_page
|
24
|
+
unless select
|
25
|
+
raise MissingSelectError, "Must provide block to select data for each page"
|
26
|
+
end
|
27
|
+
@select = select
|
28
|
+
end
|
29
|
+
|
30
|
+
# Total number of pages
|
31
|
+
def number_of_pages
|
32
|
+
(@count / @per_page).to_i + (@count % @per_page > 0 ? 1 : 0)
|
33
|
+
end
|
34
|
+
|
35
|
+
# First page object
|
36
|
+
def first
|
37
|
+
page 1
|
38
|
+
end
|
39
|
+
|
40
|
+
# Last page object
|
41
|
+
def last
|
42
|
+
page number_of_pages
|
43
|
+
end
|
44
|
+
|
45
|
+
# Iterate through pages
|
46
|
+
def each
|
47
|
+
each_with_index do |item, index|
|
48
|
+
yield item
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Iterate through pages with indices
|
53
|
+
def each_with_index
|
54
|
+
1.upto(number_of_pages) do |number|
|
55
|
+
yield(page(number), number - 1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Retrieve page object by number
|
60
|
+
def page(number)
|
61
|
+
number = (n = number.to_i) > 0 ? n : 1
|
62
|
+
Page.new(self, number, lambda {
|
63
|
+
offset = (number - 1) * @per_page
|
64
|
+
args = [offset]
|
65
|
+
args << @per_page if @select.arity == 2
|
66
|
+
@select.call(*args)
|
67
|
+
})
|
68
|
+
end
|
69
|
+
|
70
|
+
# Page object
|
71
|
+
#
|
72
|
+
# Retrieves items for a page and provides metadata about the position
|
73
|
+
# of the page in the paginator
|
74
|
+
class Page
|
75
|
+
|
76
|
+
extend Forwardable
|
77
|
+
def_delegator :@pager, :first, :first
|
78
|
+
def_delegator :@pager, :last, :last
|
79
|
+
def_delegator :items, :each
|
80
|
+
def_delegator :items, :each_with_index
|
81
|
+
|
82
|
+
attr_reader :number, :pager
|
83
|
+
|
84
|
+
def initialize(pager, number, select) #:nodoc:
|
85
|
+
@pager, @number = pager, number
|
86
|
+
@offset = (number - 1) * pager.per_page
|
87
|
+
@select = select
|
88
|
+
end
|
89
|
+
|
90
|
+
# Retrieve the items for this page
|
91
|
+
# * Caches
|
92
|
+
def items
|
93
|
+
@items ||= @select.call
|
94
|
+
end
|
95
|
+
|
96
|
+
# Checks to see if there's a page before this one
|
97
|
+
def prev?
|
98
|
+
@number > 1
|
99
|
+
end
|
100
|
+
|
101
|
+
# Get previous page (if possible)
|
102
|
+
def prev
|
103
|
+
@pager.page(@number - 1) if prev?
|
104
|
+
end
|
105
|
+
|
106
|
+
# Checks to see if there's a page after this one
|
107
|
+
def next?
|
108
|
+
@number < @pager.number_of_pages
|
109
|
+
end
|
110
|
+
|
111
|
+
# Get next page (if possible)
|
112
|
+
def next
|
113
|
+
@pager.page(@number + 1) if next?
|
114
|
+
end
|
115
|
+
|
116
|
+
# The "item number" of the first item on this page
|
117
|
+
def first_item_number
|
118
|
+
1 + @offset
|
119
|
+
end
|
120
|
+
|
121
|
+
# The "item number" of the last item on this page
|
122
|
+
def last_item_number
|
123
|
+
if next?
|
124
|
+
@offset + @pager.per_page
|
125
|
+
else
|
126
|
+
@pager.count
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def ==(other) #:nodoc:
|
131
|
+
@pager == other.pager && self.number == other.number
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Copyright (c) 2006 Sean Treadway
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
|
23
|
+
# Module containing the methods useful for child IFRAME to parent window communication
|
24
|
+
module RespondsToParent
|
25
|
+
|
26
|
+
# Executes the response body as JavaScript in the context of the parent window.
|
27
|
+
# Use this method of you are posting a form to a hidden IFRAME or if you would like
|
28
|
+
# to use IFRAME base RPC.
|
29
|
+
def responds_to_parent(&block)
|
30
|
+
yield
|
31
|
+
|
32
|
+
if performed?
|
33
|
+
# We're returning HTML instead of JS or XML now
|
34
|
+
response.headers['Content-Type'] = 'text/html; charset=UTF-8'
|
35
|
+
|
36
|
+
# Either pull out a redirect or the request body
|
37
|
+
script = if response.headers['Location']
|
38
|
+
#TODO: erase_redirect_results is missing in rails 3.0 has to be implemented
|
39
|
+
#erase redirect
|
40
|
+
"document.location.href = #{location.to_s.inspect}"
|
41
|
+
else
|
42
|
+
response.body
|
43
|
+
end
|
44
|
+
|
45
|
+
# Escape quotes, linebreaks and slashes, maintaining previously escaped slashes
|
46
|
+
# Suggestions for improvement?
|
47
|
+
script = (script || '').
|
48
|
+
gsub('\\', '\\\\\\').
|
49
|
+
gsub(/\r\n|\r|\n/, '\\n').
|
50
|
+
gsub(/['"]/, '\\\\\&').
|
51
|
+
gsub('</script>','</scr"+"ipt>')
|
52
|
+
|
53
|
+
# Clear out the previous render to prevent double render
|
54
|
+
response.request.env['action_controller.instance'].instance_variable_set(:@_response_body, nil)
|
55
|
+
|
56
|
+
# Eval in parent scope and replace document location of this frame
|
57
|
+
# so back button doesn't replay action on targeted forms
|
58
|
+
# loc = document.location to be set after parent is updated for IE
|
59
|
+
# with(window.parent) - pull in variables from parent window
|
60
|
+
# setTimeout - scope the execution in the windows parent for safari
|
61
|
+
# window.eval - legal eval for Opera
|
62
|
+
render :text => "<html><body><script type='text/javascript' charset='utf-8'>
|
63
|
+
var loc = document.location;
|
64
|
+
with(window.parent) { setTimeout(function() { window.eval('#{script}'); if (typeof(loc) !== 'undefined') loc.replace('about:blank'); }, 1) };
|
65
|
+
</script></body></html>".html_safe
|
66
|
+
end
|
67
|
+
end
|
68
|
+
alias respond_to_parent responds_to_parent
|
69
|
+
end
|
70
|
+
|
data/public/blank.html
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
<!--
|
2
|
+
Copyright (c) 2005, Brad Neuberg, bkn3@columbia.edu
|
3
|
+
http://codinginparadise.org
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the "Software"),
|
7
|
+
to deal in the Software without restriction, including without limitation
|
8
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
9
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
|
20
|
+
OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
21
|
+
THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
-->
|
23
|
+
|
24
|
+
<html>
|
25
|
+
<script language="JavaScript">
|
26
|
+
function pageLoaded() {
|
27
|
+
window.parent.dhtmlHistory.iframeLoaded(window.location);
|
28
|
+
}
|
29
|
+
</script>
|
30
|
+
<body onload="pageLoaded()">
|
31
|
+
<h1>blank.html - Needed for Internet Explorer's hidden IFrame</h1>
|
32
|
+
</body>
|
33
|
+
</html>
|
@@ -0,0 +1,136 @@
|
|
1
|
+
class ActiveSupport::TestCase
|
2
|
+
def self.should_have_columns_in(action, *columns)
|
3
|
+
should "have #{columns.to_sentence} columns in #{action}" do
|
4
|
+
assert_equal columns, column_names(action)
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.should_include_columns_in(action, *columns)
|
9
|
+
should "include #{columns.to_sentence} columns in #{action}" do
|
10
|
+
action_columns = column_names(action)
|
11
|
+
columns.each do |column|
|
12
|
+
assert action_columns.include?(column.to_sym), "#{column} is not included in #{action}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.should_not_include_columns_in(action, *columns)
|
18
|
+
should "not include #{columns.to_sentence} columns in #{action}" do
|
19
|
+
action_columns = column_names(action)
|
20
|
+
columns.each do |column|
|
21
|
+
assert !action_columns.include?(column.to_sym), "#{column} is included in #{action}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.should_render_as_form_ui(column_name, form_ui)
|
27
|
+
should "render column #{column_name} as #{form_ui} form_ui", :before => lambda{
|
28
|
+
@rendered_columns = []
|
29
|
+
ActionView::Base.any_instance.expects(:"active_scaffold_input_#{form_ui}").at_least_once.with {|column, options|
|
30
|
+
@rendered_columns << column.name
|
31
|
+
true
|
32
|
+
}
|
33
|
+
} do
|
34
|
+
assert_equal form_ui, @controller.active_scaffold_config.columns[column_name].form_ui
|
35
|
+
assert @rendered_columns.include?(column_name)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.should_render_with_options_for_select(column_name, *options)
|
40
|
+
should "render column #{column_name} with options for select" do
|
41
|
+
converting_sort = lambda{|a,b| a.to_s <=> b.to_s}
|
42
|
+
assert_equal options.sort(&converting_sort), @controller.active_scaffold_config.columns[column_name].options[:options].sort(&converting_sort)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.should_render_as_form_override(column_name)
|
47
|
+
should "render column #{column_name} as form override" do
|
48
|
+
column = @controller.active_scaffold_config.columns[column_name]
|
49
|
+
assert @response.template.override_form_field?(column)
|
50
|
+
assert_template :partial => "_#{column_name}_form_column", :count => 0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.should_render_as_form_partial_override(column_name)
|
55
|
+
should "render column #{column_name} as form partial override" do
|
56
|
+
assert_template :partial => "_#{column_name}_form_column"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.should_render_as_form_hidden(column_name)
|
61
|
+
should "render column #{column_name} as form hidden", :before => lambda{
|
62
|
+
@rendered_columns = []
|
63
|
+
ActionView::Base.any_instance.expects(:"hidden_field").at_least_once.with {|object, method, options|
|
64
|
+
@rendered_columns << method
|
65
|
+
true
|
66
|
+
}
|
67
|
+
} do
|
68
|
+
assert_template :partial => "_form_hidden_attribute"
|
69
|
+
assert @rendered_columns.include?(column_name)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.should_render_as_list_ui(column_name, list_ui)
|
74
|
+
should "render column #{column_name} as #{list_ui} list_ui", :before => lambda{
|
75
|
+
@rendered_columns = []
|
76
|
+
ActionView::Base.any_instance.expects(:"active_scaffold_column_#{list_ui}").at_least_once.with {|column, options|
|
77
|
+
@rendered_columns << column.name
|
78
|
+
true
|
79
|
+
}
|
80
|
+
} do
|
81
|
+
assert_equal list_ui, @controller.active_scaffold_config.columns[column_name].list_ui
|
82
|
+
assert @rendered_columns.include?(column_name)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.should_render_as_field_override(column_name)
|
87
|
+
should "render column #{column_name} as field override" do
|
88
|
+
column = @controller.active_scaffold_config.columns[column_name]
|
89
|
+
assert @response.template.override_form_field?(column)
|
90
|
+
assert_template :partial => "_#{column_name}_column", :count => 0
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.should_render_as_field_partial_override(column_name)
|
95
|
+
should "render column #{column_name} as field partial override" do
|
96
|
+
assert_template :partial => "_#{column_name}_column"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.should_render_as_inplace_edit(column_name)
|
101
|
+
should "render column #{column_name} as inplace edit", :before => lambda{
|
102
|
+
@column = @controller.active_scaffold_config.columns[column_name]
|
103
|
+
@rendered_columns = []
|
104
|
+
method = @column.list_ui == :checkbox ? :format_column_checkbox : :active_scaffold_inplace_edit
|
105
|
+
ActionView::Base.any_instance.expects(method).at_least_once.with {|model, column, options|
|
106
|
+
@rendered_columns << column.name
|
107
|
+
true
|
108
|
+
}
|
109
|
+
} do
|
110
|
+
assert @column.inplace_edit
|
111
|
+
assert @rendered_columns.include?(column_name)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.should_respond_to_parent_redirecting_to(description, &block)
|
116
|
+
should_respond_to_parent("redirecting to #{description}") { "document.location.href = \"#{instance_eval(&block)}\"" }
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.should_respond_to_parent(description = nil, &block)
|
120
|
+
should "respond to parent #{description}" do
|
121
|
+
script = block ? instance_eval(&block) : /.*/
|
122
|
+
script = script.is_a?(Regexp) ? script.source : Regexp.quote(script)
|
123
|
+
script = script.gsub('\n', '\\\\\\n').
|
124
|
+
gsub(/['"]/, '\\\\\\\\\&').
|
125
|
+
gsub('</script>','</scr"+"ipt>')
|
126
|
+
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) };") + '.*')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
def column_names(action)
|
132
|
+
columns = []
|
133
|
+
@controller.active_scaffold_config.send(action).columns.each(:flatten => true) {|col| columns << col.name}
|
134
|
+
columns
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
def dbg; require "ruby-debug"; debugger; end;
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
4
|
+
|
5
|
+
|
6
|
+
class Bridges::BridgeTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
@const_store = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
end
|
13
|
+
|
14
|
+
def test__shouldnt_throw_errors
|
15
|
+
ActiveScaffold::Bridge.run_all
|
16
|
+
end
|
17
|
+
|
18
|
+
def test__cds_bridge
|
19
|
+
ConstMocker.mock("CalendarDateSelect") do |cm|
|
20
|
+
cm.remove
|
21
|
+
assert(! bridge_will_be_installed("CalendarDateSelect"))
|
22
|
+
cm.declare
|
23
|
+
assert(bridge_will_be_installed("CalendarDateSelect"))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test__file_column_bridge
|
28
|
+
ConstMocker.mock("FileColumn") do |cm|
|
29
|
+
cm.remove
|
30
|
+
assert(! bridge_will_be_installed("FileColumn"))
|
31
|
+
cm.declare
|
32
|
+
assert(bridge_will_be_installed("FileColumn"))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def find_bridge(name)
|
39
|
+
ActiveScaffold::Bridge.bridges.find{|b| b.name.to_s==name.to_s}
|
40
|
+
end
|
41
|
+
|
42
|
+
def bridge_will_be_installed(name)
|
43
|
+
assert bridge=find_bridge(name), "No bridge found matching #{name}"
|
44
|
+
|
45
|
+
bridge.instance_variable_get("@install_if").call
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class Config::BaseTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@base = ActiveScaffold::Config::Base.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_formats
|
9
|
+
assert_equal [], @base.formats
|
10
|
+
@base.formats << :pdf
|
11
|
+
assert_equal [:pdf], @base.formats
|
12
|
+
@base.formats = [:html]
|
13
|
+
assert_equal [:html], @base.formats
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class Config::CreateTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@config = ActiveScaffold::Config::Core.new :model_stub
|
6
|
+
@default_link = @config.create.link
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
@config.create.link = @default_link
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_default_options
|
14
|
+
assert !@config.create.persistent
|
15
|
+
assert !@config.create.edit_after_create
|
16
|
+
assert_equal 'Create Modelstub', @config.create.label
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_link_defaults
|
20
|
+
link = @config.create.link
|
21
|
+
assert !link.page?
|
22
|
+
assert !link.popup?
|
23
|
+
assert !link.confirm?
|
24
|
+
assert_equal "new", link.action
|
25
|
+
assert_equal "Create New", link.label
|
26
|
+
assert link.inline?
|
27
|
+
blank = {}
|
28
|
+
assert_equal blank, link.html_options
|
29
|
+
assert_equal :get, link.method
|
30
|
+
assert_equal :collection, link.type
|
31
|
+
assert_equal :create, link.crud_type
|
32
|
+
assert_equal :create_authorized?, link.security_method
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_setting_link
|
36
|
+
@config.create.link = ActiveScaffold::DataStructures::ActionLink.new('update', :label => 'Monkeys')
|
37
|
+
assert_not_equal(@default_link, @config.create.link)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_label
|
41
|
+
label = 'create new monkeys'
|
42
|
+
@config.create.label = label
|
43
|
+
assert_equal label, @config.create.label
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_persistent
|
47
|
+
@config.create.persistent = true
|
48
|
+
assert @config.create.persistent
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_edit_after_create
|
52
|
+
@config.create.edit_after_create = true
|
53
|
+
assert @config.create.edit_after_create
|
54
|
+
end
|
55
|
+
end
|