edgarj 0.01.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +23 -0
- data/Rakefile +40 -0
- data/app/assets/javascripts/edgarj/base.js +49 -0
- data/app/assets/javascripts/edgarj/menu.js +39 -0
- data/app/assets/javascripts/edgarj/operator_selection.js +133 -0
- data/app/assets/stylesheets/edgarj/base.css +304 -0
- data/app/assets/stylesheets/edgarj/menu.css +65 -0
- data/app/controllers/edgarj/authentication_mixin.rb.sample +30 -0
- data/app/controllers/edgarj/controller_mixin_common.rb +80 -0
- data/app/controllers/edgarj/controller_mixin_for_app.rb +71 -0
- data/app/controllers/edgarj/edgarj_controller.rb +535 -0
- data/app/controllers/edgarj/model_permissions_controller.rb +8 -0
- data/app/controllers/edgarj/permission_mixin.rb +84 -0
- data/app/controllers/edgarj/popup_controller.rb +128 -0
- data/app/controllers/edgarj/rescue_mixin.rb +37 -0
- data/app/controllers/edgarj/user_group_users_controller.rb +8 -0
- data/app/controllers/edgarj/user_groups_controller.rb +9 -0
- data/app/controllers/edgarj/user_groups_popup_controller.rb +8 -0
- data/app/helpers/edgarj/assoc_helper.rb +369 -0
- data/app/helpers/edgarj/common_helper.rb +37 -0
- data/app/helpers/edgarj/edgarj_helper.rb +20 -0
- data/app/helpers/edgarj/field_helper.rb +397 -0
- data/app/helpers/edgarj/form_drawer.rb +322 -0
- data/app/helpers/edgarj/list_drawer.rb +169 -0
- data/app/helpers/edgarj/menu_helper.rb +92 -0
- data/app/helpers/edgarj/model_permissions_helper.rb +9 -0
- data/app/helpers/edgarj/popup_helper.rb +40 -0
- data/app/helpers/edgarj/search_helper.rb +14 -0
- data/app/helpers/edgarj/sessions_helper.rb +9 -0
- data/app/helpers/edgarj/user_group_users_helper.rb +9 -0
- data/app/helpers/edgarj/user_groups_helper.rb +9 -0
- data/app/helpers/edgarj/user_groups_popup_helper.rb +9 -0
- data/app/models/edgarj/drawer/base.rb +234 -0
- data/app/models/edgarj/drawer/normal.rb +6 -0
- data/app/models/edgarj/drawer/popup.rb +47 -0
- data/app/models/edgarj/drawer.rb +13 -0
- data/app/models/edgarj/model_permission.rb +41 -0
- data/app/models/edgarj/page_info.rb +47 -0
- data/app/models/edgarj/search.rb +81 -0
- data/app/models/edgarj/search_form.rb +255 -0
- data/app/models/edgarj/search_popup.rb +44 -0
- data/app/models/edgarj/sssn.rb +120 -0
- data/app/models/edgarj/user_group.rb +67 -0
- data/app/models/edgarj/user_group_user.rb +18 -0
- data/app/models/edgarj.rb +5 -0
- data/app/views/edgarj/edgarj/_form.html.erb +25 -0
- data/app/views/edgarj/edgarj/_list.html.erb +52 -0
- data/app/views/edgarj/edgarj/_message_popup.html.erb +15 -0
- data/app/views/edgarj/edgarj/_search_form.html.erb +64 -0
- data/app/views/edgarj/edgarj/_search_operator.html.erb +17 -0
- data/app/views/edgarj/edgarj/_search_operator_selection.html.erb +12 -0
- data/app/views/edgarj/edgarj/clear.js.erb +1 -0
- data/app/views/edgarj/edgarj/create.js.erb +4 -0
- data/app/views/edgarj/edgarj/destroy.js.erb +2 -0
- data/app/views/edgarj/edgarj/index.html.erb +37 -0
- data/app/views/edgarj/edgarj/index.js.erb +1 -0
- data/app/views/edgarj/edgarj/message_popup.js.erb +3 -0
- data/app/views/edgarj/edgarj/page_info_save.js.erb +1 -0
- data/app/views/edgarj/edgarj/search.js.erb +4 -0
- data/app/views/edgarj/edgarj/search_clear.js.erb +1 -0
- data/app/views/edgarj/edgarj/show.js.erb +1 -0
- data/app/views/edgarj/edgarj/top.html.erb +4 -0
- data/app/views/edgarj/edgarj/update.js.erb +4 -0
- data/app/views/edgarj/popup/_index.html.erb +16 -0
- data/app/views/edgarj/popup/_list.html.erb +42 -0
- data/app/views/edgarj/popup/_message_popup.html.erb +15 -0
- data/app/views/edgarj/popup/_search.html.erb +42 -0
- data/app/views/edgarj/popup/_search_save_popup.html.erb +16 -0
- data/app/views/edgarj/popup/index.js.erb +5 -0
- data/app/views/edgarj/popup/message_popup.js.erb +3 -0
- data/app/views/edgarj/popup/page_info_save.js.erb +1 -0
- data/app/views/edgarj/popup/search.js.erb +15 -0
- data/app/views/edgarj/popup/view_status_save.js.erb +1 -0
- data/config/routes.rb +15 -0
- data/config/settings.yml +5 -0
- data/db/migrate/20131118084600_create_edgar_sssns.rb +14 -0
- data/db/migrate/20131123124730_create_edgar_page_infos.rb +15 -0
- data/db/migrate/20140116062252_create_edgar_user_groups.rb +18 -0
- data/db/migrate/20140116062327_create_edgar_user_group_users.rb +10 -0
- data/db/migrate/20140206222308_create_edgar_model_permissions.rb +14 -0
- data/db/migrate/20141209053055_rename_edgar_to_edgarj.rb +17 -0
- data/lib/core_ext/active_record.rb +123 -0
- data/lib/core_ext/resources.rb +71 -0
- data/lib/edgarj/engine.rb +64 -0
- data/lib/edgarj/enum_cache.rb +46 -0
- data/lib/edgarj/templates/rails/helper/helper.rb +10 -0
- data/lib/edgarj/templates/test_unit/scaffold/functional_test.rb +575 -0
- data/lib/edgarj/version.rb +3 -0
- data/lib/edgarj.rb +14 -0
- data/lib/generators/edgarj/popup_scaffold/USAGE +6 -0
- data/lib/generators/edgarj/popup_scaffold/popup_scaffold_generator.rb +35 -0
- data/lib/generators/edgarj/popup_scaffold/templates/controller.rb +13 -0
- data/lib/generators/edgarj/popup_scaffold/templates/functional_test.rb +197 -0
- data/lib/generators/edgarj/popup_scaffold/templates/helper.rb +9 -0
- data/lib/generators/edgarj/scaffold/USAGE +17 -0
- data/lib/generators/edgarj/scaffold/scaffold_generator.rb +40 -0
- data/lib/generators/edgarj/scaffold/templates/controller.rb +13 -0
- data/lib/tasks/edgarj_tasks.rake +32 -0
- data/lib/tasks/pakcage.rake +18 -0
- data/locale/en.yml +94 -0
- data/locale/ja.yml +100 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +21 -0
- data/test/dummy/app/assets/javascripts/authors.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +16 -0
- data/test/dummy/app/assets/stylesheets/authors.css +4 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/controllers/application_controller.rb +15 -0
- data/test/dummy/app/controllers/authors_controller.rb +6 -0
- data/test/dummy/app/controllers/authors_popup_controller.rb +6 -0
- data/test/dummy/app/controllers/books_controller.rb +6 -0
- data/test/dummy/app/controllers/dummy_auth_mixin.rb +36 -0
- data/test/dummy/app/decorators/models/edgarj/user_group_decorator.rb +1 -0
- data/test/dummy/app/helpers/application_helper.rb +3 -0
- data/test/dummy/app/helpers/authors_helper.rb +7 -0
- data/test/dummy/app/helpers/authors_popup_helper.rb +7 -0
- data/test/dummy/app/helpers/books_helper.rb +7 -0
- data/test/dummy/app/models/author.rb +32 -0
- data/test/dummy/app/models/book.rb +5 -0
- data/test/dummy/app/models/user.rb +13 -0
- data/test/dummy/app/views/layouts/application.html.erb +32 -0
- data/test/dummy/app/views/layouts/login.html.erb +20 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +15 -0
- data/test/dummy/config/edgarj/menu_config.rb +28 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +42 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +34 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/strong_parameter.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +26 -0
- data/test/dummy/config/routes.rb +60 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/migrate/20131107120635_create_authors.rb +9 -0
- data/test/dummy/db/migrate/20131218011851_create_books.rb +10 -0
- data/test/dummy/db/migrate/20140201000000_add_user_group_id_to_authors.rb +5 -0
- data/test/dummy/db/migrate/20140807065420_create_users.rb +10 -0
- data/test/dummy/db/schema.rb +93 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/functional/authors_controller_test.rb +631 -0
- data/test/dummy/test/functional/books_controller_test.rb +516 -0
- data/test/dummy/test/helpers/authors_helper_test.rb +4 -0
- data/test/dummy/test/unit/author_test.rb +7 -0
- data/test/dummy/test/unit/book_test.rb +7 -0
- data/test/edgar_test.rb +7 -0
- data/test/fixtures/authors.yml +32 -0
- data/test/fixtures/books.yml +56 -0
- data/test/fixtures/edgarj/model_permissions.yml +97 -0
- data/test/fixtures/edgarj/page_infos.yml +84 -0
- data/test/fixtures/edgarj/sssns.yml +38 -0
- data/test/fixtures/edgarj/user_group_users.yml +114 -0
- data/test/fixtures/edgarj/user_groups.yml +95 -0
- data/test/fixtures/users.yml +49 -0
- data/test/functional/edgarj/edgarj_controller_test.rb +24 -0
- data/test/functional/edgarj/model_permissions_controller_test.rb +554 -0
- data/test/functional/edgarj/user_group_users_controller_test.rb +567 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/support/edgarj/controller_supporter.rb +23 -0
- data/test/test_helper.rb +23 -0
- data/test/unit/edgarj/model_permission_test.rb +27 -0
- data/test/unit/edgarj/page_info_test.rb +7 -0
- data/test/unit/edgarj/sssn_test.rb +10 -0
- data/test/unit/edgarj/user_group_test.rb +32 -0
- data/test/unit/edgarj/user_group_user_test.rb +9 -0
- data/test/unit/helpers/edgarj/model_permissions_helper_test.rb +6 -0
- data/test/unit/helpers/edgarj/user_group_users_helper_test.rb +6 -0
- metadata +456 -0
@@ -0,0 +1,397 @@
|
|
1
|
+
module Edgarj
|
2
|
+
# Edgarj::FieldHelper is independent from Edgarj default form (FormDrawer::Base)
|
3
|
+
# so you can use helper methods here for your customized
|
4
|
+
# form.
|
5
|
+
module FieldHelper
|
6
|
+
# Draw buttons for form.
|
7
|
+
#
|
8
|
+
# When no CREATE/UPDATE permission, save button is disabled.
|
9
|
+
# It can be overwritten by options[:save].
|
10
|
+
#
|
11
|
+
# When no DELETE permission, delete button is disabled.
|
12
|
+
# It can be overwritten by options[:delete].
|
13
|
+
#
|
14
|
+
# options may have:
|
15
|
+
# :save:: html options for 'save' button.
|
16
|
+
# :search_form:: html options for 'search_form' button.
|
17
|
+
# :delete:: html options for 'delete' button.
|
18
|
+
# :namespace:: delete url namespace
|
19
|
+
def draw_form_buttons(options = {})
|
20
|
+
content_tag(:table) do
|
21
|
+
content_tag(:tr) do
|
22
|
+
# save button
|
23
|
+
content_tag(:td) do
|
24
|
+
#cp_bitset = Edgarj::ModelPermission::FlagsBitset
|
25
|
+
#create_or_update = cp_bitset::CREATE + cp_bitset::UPDATE
|
26
|
+
tag(:input, {
|
27
|
+
type: 'button',
|
28
|
+
name: 'save',
|
29
|
+
onClick: '$("#_edgarj_form").submit()',
|
30
|
+
value: t('edgarj.default.save'),
|
31
|
+
class: '_edgarj_form_save',})
|
32
|
+
#disabled: !permitted?(create_or_update)}.merge(options[:save]||{}))
|
33
|
+
end +
|
34
|
+
|
35
|
+
# search button
|
36
|
+
content_tag(:td) do
|
37
|
+
button_for_js(t('edgarj.default.search_form'), <<-JS,
|
38
|
+
$('#edgarj_form').hide();
|
39
|
+
$('#edgarj_search_form').show();
|
40
|
+
JS
|
41
|
+
{class: '_edgarj_form_search'}.merge(options[:search_form] ||{}))
|
42
|
+
end +
|
43
|
+
|
44
|
+
# clear button
|
45
|
+
content_tag(:td) do
|
46
|
+
button_to(t('edgarj.default.clear'),
|
47
|
+
{action: 'clear'},
|
48
|
+
{
|
49
|
+
method: :get,
|
50
|
+
remote: true,
|
51
|
+
})
|
52
|
+
end +
|
53
|
+
|
54
|
+
# delete button
|
55
|
+
content_tag(:td) do
|
56
|
+
button_to(t('edgarj.default.delete'),
|
57
|
+
polymorphic_path([options[:namespace], @record]),
|
58
|
+
{
|
59
|
+
method: :delete,
|
60
|
+
remote: true,
|
61
|
+
data: {confirm: t('edgarj.form.delete_confirm')},
|
62
|
+
disabled: @record.new_record? # || !permitted?(cp_bitset::DELETE),
|
63
|
+
})
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def draw_search_form_buttons
|
70
|
+
content_tag(:table) do
|
71
|
+
content_tag(:tr) do
|
72
|
+
# search button
|
73
|
+
content_tag(:td) do
|
74
|
+
button_for_js(v('search'), '$("#_edgarj_search_form").submit()')
|
75
|
+
end +
|
76
|
+
|
77
|
+
# search_end button
|
78
|
+
content_tag(:td) do
|
79
|
+
button_for_js(v('search_end'), <<-JS)
|
80
|
+
$('#edgarj_form').show();
|
81
|
+
$('#edgarj_search_form').hide();
|
82
|
+
JS
|
83
|
+
end +
|
84
|
+
|
85
|
+
# search_clear button
|
86
|
+
content_tag(:td) do
|
87
|
+
button_to(v('search_clear'),
|
88
|
+
{action: 'search_clear'},
|
89
|
+
{
|
90
|
+
method: :get,
|
91
|
+
remote: true,
|
92
|
+
})
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def draw_search_save_popup
|
99
|
+
render :partial => 'edgarj/search_save_popup'
|
100
|
+
end
|
101
|
+
|
102
|
+
# draw default field for col.type
|
103
|
+
#
|
104
|
+
# options[type] is passed to each rails helper. Following types are
|
105
|
+
# supported:
|
106
|
+
# * :date
|
107
|
+
# * :datetime
|
108
|
+
# * :integer
|
109
|
+
# * :boolean
|
110
|
+
# * :text
|
111
|
+
#
|
112
|
+
# === INPUTS
|
113
|
+
# f:: FormBuilder object
|
114
|
+
# col:: column info returned by AR.columns, or symbol
|
115
|
+
# options:: options hash passed to each helper.
|
116
|
+
def draw_field(f, col, options={})
|
117
|
+
case col.type
|
118
|
+
when :date
|
119
|
+
draw_date(f, col, options[:date] || {})
|
120
|
+
when :datetime
|
121
|
+
draw_datetime(f, col, options[:datetime] || {})
|
122
|
+
when :integer
|
123
|
+
f.text_field(col.name, options[:integer])
|
124
|
+
else
|
125
|
+
f.text_field(col.name, options[:text])
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def draw_boolean(f, col, options={})
|
130
|
+
f.check_box(col.name, options)
|
131
|
+
end
|
132
|
+
|
133
|
+
# draw calendar date select
|
134
|
+
#
|
135
|
+
# === INPUTS
|
136
|
+
# f:: Form builder object.
|
137
|
+
# col_or_sym:: column object returned by rec.class.columns, or symbol
|
138
|
+
# options:: passed to calendar_date_select
|
139
|
+
def draw_date(f, col_or_sym, options={})
|
140
|
+
col_name = get_column_name(col_or_sym)
|
141
|
+
dom_id = sprintf("%s_%s", f.object_name, col_name)
|
142
|
+
f.text_field(col_name, id: dom_id, size: 14) +
|
143
|
+
javascript_tag(<<-EOJS)
|
144
|
+
$(function(){
|
145
|
+
$('##{dom_id}').datepicker({buttonImageOnly: true}).
|
146
|
+
datepicker('option', {
|
147
|
+
dateFormat: 'yy/mm/dd'
|
148
|
+
});
|
149
|
+
});
|
150
|
+
EOJS
|
151
|
+
end
|
152
|
+
|
153
|
+
# draw calendar datetime select
|
154
|
+
#
|
155
|
+
# === INPUTS
|
156
|
+
# f:: Form builder object.
|
157
|
+
# col_or_sym:: column object returned by rec.class.columns, or symbol
|
158
|
+
# options:: passed to calendar_date_select
|
159
|
+
def draw_datetime(f, col_or_sym, options={})
|
160
|
+
col_name = get_column_name(col_or_sym)
|
161
|
+
f.text_field(col_name,
|
162
|
+
value: datetime_fmt(f.object.send(col_name)))
|
163
|
+
end
|
164
|
+
|
165
|
+
# draw 'edgarj_address' field
|
166
|
+
#
|
167
|
+
# The column, which is declared as 'edgarj_address', can be
|
168
|
+
# drawn by this helper.
|
169
|
+
#
|
170
|
+
# === INPUTS
|
171
|
+
# f:: FormBuilder
|
172
|
+
# col_or_sym:: column object returned by rec.class.columns, or symbol
|
173
|
+
def draw_address(f, col_or_sym)
|
174
|
+
address_name = f.object.class.get_belongs_to_name(col_or_sym)
|
175
|
+
render('edgarj/address',
|
176
|
+
f: f,
|
177
|
+
rec: f.object,
|
178
|
+
address_name: address_name
|
179
|
+
)
|
180
|
+
end
|
181
|
+
|
182
|
+
# draw bitset checkboxes.
|
183
|
+
#
|
184
|
+
# When model class has integer field (e.g. 'flags') and
|
185
|
+
# Flags module which defines 'bitflag' constant,
|
186
|
+
# model.flags integer column is drawn as bitset checkboxes.
|
187
|
+
# Constant name will be translated by config/locales/*.yml
|
188
|
+
# See ModelPermission for example.
|
189
|
+
#
|
190
|
+
# 'flags' column value is calculated at client side by JavaScript.
|
191
|
+
#
|
192
|
+
# options is not used now.
|
193
|
+
#
|
194
|
+
# === INPUTS
|
195
|
+
# f:: Form builder object.
|
196
|
+
# col:: column object returned by rec.class.columns, or symbol
|
197
|
+
# bitset:: ruby module contains 'bitflag' integer constants
|
198
|
+
# options:: (not used)
|
199
|
+
def draw_bitset(f, col, bitset=nil, options={})
|
200
|
+
html = ''
|
201
|
+
bitset = model.const_get(col_name.to_s.camelize + 'Bitset') if !bitset
|
202
|
+
i = 0
|
203
|
+
id_array_var = sprintf('%s_%s_var', f.object_name, col.name)
|
204
|
+
ids = []
|
205
|
+
for flag in bitset.constants do
|
206
|
+
checkbox_id = sprintf('%s_%s_%d', f.object_name, col.name, i)
|
207
|
+
html += draw_checkbox(f, checkbox_id, flag, bitset, id_array_var) +
|
208
|
+
label_tag(
|
209
|
+
checkbox_id,
|
210
|
+
f.object.class.human_const_name(bitset, flag)) +
|
211
|
+
' '.html_safe
|
212
|
+
ids << checkbox_id
|
213
|
+
i += 1
|
214
|
+
end
|
215
|
+
# draw hidden field to send sum-up value
|
216
|
+
html += f.hidden_field(col.name)
|
217
|
+
|
218
|
+
# add hidden-field name to ids' last
|
219
|
+
ids << sprintf("%s_%s", f.object_name, col.name)
|
220
|
+
|
221
|
+
# define arrays to calculate flags
|
222
|
+
html += "<script> var #{id_array_var}=[" +
|
223
|
+
ids.map{|id| "'" + id + "'"}.join(',') +
|
224
|
+
"];</script>"
|
225
|
+
html.html_safe
|
226
|
+
end
|
227
|
+
|
228
|
+
# draw enum selection.
|
229
|
+
#
|
230
|
+
# 'Enum' in Edgarj is a module which integer constants are defined.
|
231
|
+
# draw_enum() draws selection rather than simple integer text field.
|
232
|
+
#
|
233
|
+
# Selection-option label is I18 supported by AR human_const_name API.
|
234
|
+
# See lib/edgarj/model.rb rdoc.
|
235
|
+
#
|
236
|
+
# === EXAMPLE
|
237
|
+
# Followings draws Question module's Priority selection
|
238
|
+
# on @question.priority integer column:
|
239
|
+
#
|
240
|
+
# <%= edgarj_form do |f| %>
|
241
|
+
# :
|
242
|
+
# <%= draw_enum(f, :priority) %>
|
243
|
+
# :
|
244
|
+
# <% end %>
|
245
|
+
#
|
246
|
+
# === INPUTS
|
247
|
+
# f:: Form builder object.
|
248
|
+
# col_or_sym:: column object returned by rec.class.columns, or symbol
|
249
|
+
# enum:: enum module. When nil, guess by column name.
|
250
|
+
# options:: draw_enum options and/or passed to select helper.
|
251
|
+
#
|
252
|
+
# ==== Supported options
|
253
|
+
# :choice_1st:: additional 1st choice (mainly used SearchForm enum selection)
|
254
|
+
# :class AR class which will be used for human_const_name()
|
255
|
+
#
|
256
|
+
# === SEE ALSO
|
257
|
+
# get_enum():: get enum definition
|
258
|
+
# draw_column_enum():: draw enum column in list
|
259
|
+
#
|
260
|
+
# FIXME: choices for selection should be cached.
|
261
|
+
def draw_enum(f, col_or_sym, enum=nil, options={})
|
262
|
+
col_name = get_column_name(col_or_sym)
|
263
|
+
enum = model.const_get(col_name.to_s.camelize) if !enum
|
264
|
+
sorted_elements = enum.constants.sort{|a,b|
|
265
|
+
enum.const_get(a) <=> enum.const_get(b)}
|
266
|
+
options_for_select = options.dup
|
267
|
+
choice_1st = options_for_select.delete(:choice_1st)
|
268
|
+
class_4_human_const = options_for_select.delete(:class) || f.object.class
|
269
|
+
f.select(col_name,
|
270
|
+
(choice_1st ? [choice_1st] : []) +
|
271
|
+
sorted_elements.map{|member|
|
272
|
+
[class_4_human_const.human_const_name(enum, member),
|
273
|
+
enum.const_get(member)]},
|
274
|
+
options_for_select)
|
275
|
+
end
|
276
|
+
|
277
|
+
def draw_question_history(question)
|
278
|
+
render :partial => '/questions/history', :locals=>{:question=>question}
|
279
|
+
end
|
280
|
+
|
281
|
+
# Field 'file_NN' in AR is handled as file attachement(upload/download) in Edgarj.
|
282
|
+
# Where, NN is 2-digits from 00 to 99.
|
283
|
+
#
|
284
|
+
# draw_file() helper draws file attachment(upload/download) user-interface
|
285
|
+
# for file_NN field. It supports:
|
286
|
+
#
|
287
|
+
# 1. upload file (Create)
|
288
|
+
# 1. download file (Read)
|
289
|
+
# 1. upload another file (Update)
|
290
|
+
# 1. clear the field (Delete)
|
291
|
+
#
|
292
|
+
# === Model
|
293
|
+
# Integer value of file_NN column in any AR is interpreted a ID value
|
294
|
+
# to point to a FileInfo record.
|
295
|
+
# As NN means, any number of files (max 100) can be attached to any AR.
|
296
|
+
#
|
297
|
+
# belongs_to/has_one relation can be declared between the AR and FileInfo,
|
298
|
+
# but it is not required. Those declarations are just for your
|
299
|
+
# customization level convenience.
|
300
|
+
#
|
301
|
+
# attr_accessible(or attr_protected) to hide file_NN from mass-assignment
|
302
|
+
# *SHOULD BE* applied.
|
303
|
+
#
|
304
|
+
# See Report model unit test for testing.
|
305
|
+
#
|
306
|
+
# === INPUTS
|
307
|
+
# f:: Form builder object.
|
308
|
+
# col_or_sym:: column object returned by rec.class.columns, or symbol
|
309
|
+
# options:: passed to select helper.
|
310
|
+
#
|
311
|
+
# === EXAMPLE
|
312
|
+
# draw_file(f, :file_00) draws:
|
313
|
+
#
|
314
|
+
# <input type=file id='file_info[file_00][uploaded_data]' ...>
|
315
|
+
#
|
316
|
+
# === SEE ALSO
|
317
|
+
# ActiveRecord::Base#upsert_file_NN
|
318
|
+
def draw_file(f, col_or_sym, options={})
|
319
|
+
col_name = get_column_name(col_or_sym)
|
320
|
+
file_info = FileInfo.safe_find(f.object.send(col_name))
|
321
|
+
error_wrapping(
|
322
|
+
if file_info
|
323
|
+
file_field_dom = "file_info_#{col_name}_uploaded_data"
|
324
|
+
file_link_dom = "file_info_#{col_name}_link"
|
325
|
+
|
326
|
+
file_field_sub(col_name, file_info, options.merge(:style=>'display:none')) +
|
327
|
+
' ' +
|
328
|
+
content_tag(:span, :id=>file_link_dom) do
|
329
|
+
link_to(file_info.filename,
|
330
|
+
{:action => 'file_download',
|
331
|
+
:id => f.object.id,
|
332
|
+
:column => col_name}) + ' ' +
|
333
|
+
link_to_function("[#{t('edgarj.default.clear')}]",
|
334
|
+
sprintf("Edgarj.clear_file('%s', '%s', '%s')",
|
335
|
+
file_field_dom,
|
336
|
+
"#{f.object_name}_#{col_name}",
|
337
|
+
file_link_dom))
|
338
|
+
end +
|
339
|
+
f.hidden_field(col_name)
|
340
|
+
else
|
341
|
+
file_field_sub(col_name, FileInfo.new, options)
|
342
|
+
end, f.object.errors.on(col_name)
|
343
|
+
)
|
344
|
+
end
|
345
|
+
|
346
|
+
private
|
347
|
+
# Same as ActionView::Helpers::InstanceTag class instance method
|
348
|
+
def error_wrapping(html_tag, has_error)
|
349
|
+
has_error ? ActionView::Base.field_error_proc.call(html_tag, self) : html_tag
|
350
|
+
end
|
351
|
+
|
352
|
+
# draw Edgarj flags specific checkbox
|
353
|
+
def draw_checkbox(f, id, flag, bitset, id_array_var)
|
354
|
+
val = f.object.send(:flags) || 0
|
355
|
+
flag_val = bitset.const_get(flag)
|
356
|
+
tag(:input,
|
357
|
+
type: 'checkbox',
|
358
|
+
id: id,
|
359
|
+
name: id,
|
360
|
+
value: flag_val,
|
361
|
+
onChange: "Edgarj.sum_bitset(#{id_array_var})",
|
362
|
+
checked: (val & flag_val) != 0 )
|
363
|
+
end
|
364
|
+
|
365
|
+
# find column info from name
|
366
|
+
def find_col(rec, sym)
|
367
|
+
rec.class.columns.detect{|c| c.name == sym.to_s}
|
368
|
+
end
|
369
|
+
|
370
|
+
# get column name from column object or symbol
|
371
|
+
def get_column_name(col_or_sym)
|
372
|
+
if col_or_sym.is_a?(Symbol)
|
373
|
+
col_or_sym
|
374
|
+
else
|
375
|
+
col_or_sym.name
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
# generate following file field:
|
380
|
+
#
|
381
|
+
# <input type='file' name='file_info[file_NN][uploaded_data]' ...>
|
382
|
+
def file_field_sub(col_name, file_info, options)
|
383
|
+
fields_for("file_info[#{col_name}]", file_info) do |f|
|
384
|
+
f.file_field(:uploaded_data, {:size=>20}.merge(options))
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
# replacement of button_to_function to avoid DEPRECATION WARNING.
|
389
|
+
#
|
390
|
+
# When the js is called just once, onClick is simpler than
|
391
|
+
# unobtrusive-javascript approach.
|
392
|
+
def button_for_js(label, js, html_options={})
|
393
|
+
tag(:input, {type: 'button', value: label, onClick: js}.merge(
|
394
|
+
html_options))
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|