coalla-cms 0.5.1.9 → 0.6.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +1 -1
- data/Rakefile +24 -24
- data/app/assets/javascripts/admin/admin.js +236 -33
- data/app/assets/stylesheets/admin/admin.scss +1 -2
- data/app/assets/stylesheets/admin/vendor/bootstrap.min.css +6242 -4
- data/app/assets/stylesheets/admin/vendor/token-input-bootstrap.scss +144 -0
- data/app/controllers/admin/autocomplete_controller.rb +3 -1
- data/app/controllers/admin/base_controller.rb +35 -0
- data/{lib/generators/coalla/cms/templates/controllers/admin/home_controller.rb.erb → app/controllers/admin/home_controller.rb} +0 -0
- data/app/controllers/concerns/admin/editable_columns.rb +55 -0
- data/app/controllers/concerns/admin/sortable_columns.rb +16 -0
- data/app/controllers/{admin/sortable_controller.rb → concerns/admin/sortable_models.rb} +1 -5
- data/app/helpers/admin/alerts_helper.rb +31 -0
- data/app/helpers/admin/content_helper.rb +29 -0
- data/app/helpers/admin/form_helper.rb +50 -0
- data/app/helpers/admin/resource_helpers.rb +102 -0
- data/app/helpers/admin/search_helper.rb +44 -40
- data/app/helpers/admin/table_helper.rb +40 -0
- data/app/helpers/common_helper.rb +2 -2
- data/app/models/file_upload.rb +1 -1
- data/app/models/lookup.rb +1 -1
- data/app/models/site_meta_tags.rb +2 -2
- data/app/views/admin/common/_menu_section.haml +1 -1
- data/app/views/admin/common/_nested_fields_for.html.haml +10 -4
- data/app/views/admin/common/_nested_fields_for_element.html.haml +21 -5
- data/app/views/admin/common/_table_template.html.haml +26 -7
- data/app/views/admin/common/_upload_form.html.haml +2 -1
- data/app/views/admin/editable_columns/edit/_boolean.haml +2 -0
- data/app/views/admin/editable_columns/edit/_date.haml +2 -0
- data/app/views/admin/editable_columns/edit/_datetime.haml +3 -0
- data/app/views/admin/editable_columns/edit/_enumerize.haml +2 -0
- data/app/views/admin/editable_columns/edit/_string.haml +2 -0
- data/app/views/admin/editable_columns/edit/_text.haml +2 -0
- data/app/views/admin/editable_columns/edit/_time.haml +3 -0
- data/app/views/admin/editable_columns/edit_column.haml +8 -0
- data/app/views/admin/editable_columns/result/_boolean.haml +2 -0
- data/app/views/admin/editable_columns/result/_date.haml +1 -0
- data/app/views/admin/editable_columns/result/_datetime.haml +1 -0
- data/app/views/admin/editable_columns/result/_enumerize.haml +1 -0
- data/app/views/admin/editable_columns/result/_string.haml +1 -0
- data/app/views/admin/editable_columns/result/_text.haml +1 -0
- data/app/views/admin/editable_columns/result/_time.haml +1 -0
- data/app/views/admin/site_meta_tags/index.html.haml +2 -2
- data/app/views/layouts/admin.html.haml +12 -0
- data/app/views/structure/_section.haml +2 -9
- data/coalla-cms.gemspec +10 -11
- data/lib/coalla/builders/actions_column_definition.rb +44 -0
- data/lib/coalla/builders/admin_structure.rb +86 -0
- data/lib/coalla/builders/column_definition.rb +9 -0
- data/lib/coalla/builders/form_builder.rb +291 -0
- data/lib/coalla/builders/link_renderer.rb +43 -0
- data/lib/coalla/builders/policy.rb +30 -0
- data/lib/coalla/builders/table_builder.rb +99 -0
- data/lib/coalla/builders/table_formatter.rb +133 -0
- data/lib/coalla/builders/text_formatter.rb +22 -0
- data/lib/coalla/cms/engine.rb +3 -2
- data/lib/coalla/cms/version.rb +2 -2
- data/lib/coalla/ext/mapper.rb +7 -0
- data/lib/coalla/orm/{relation.rb → multi_field.rb} +7 -8
- data/lib/coalla/orm/page_slider.rb +2 -28
- data/lib/coalla/orm/sanitized.rb +1 -5
- data/lib/coalla/orm/sortable_association.rb +30 -0
- data/lib/coalla/uploaders/file_uploader.rb +9 -0
- data/lib/coalla/uploaders/image_uploader.rb +62 -0
- data/lib/coalla/uploaders/meta_image_uploader.rb +7 -0
- data/lib/coalla-cms.rb +10 -0
- data/lib/generators/coalla/cms/create_admin_administrators_generator.rb +5 -7
- data/lib/generators/coalla/cms/create_admin_generator.rb +9 -7
- data/lib/generators/coalla/cms/create_admin_login_view_generator.rb +4 -6
- data/lib/generators/coalla/cms/create_markup_generator.rb +2 -2
- data/lib/generators/coalla/cms/file_uploads/install_generator.rb +0 -17
- data/lib/generators/coalla/cms/file_uploads/mount_generator.rb +4 -7
- data/lib/generators/coalla/cms/image/install_generator.rb +0 -3
- data/lib/generators/coalla/cms/image/mount_generator.rb +0 -3
- data/lib/generators/coalla/cms/image/templates/mount/uploader.rb.erb +1 -1
- data/lib/generators/coalla/cms/image/templates/uploader.rb.erb +1 -1
- data/lib/generators/coalla/cms/init_generator.rb +42 -49
- data/lib/generators/coalla/cms/lookups/install_generator.rb +0 -3
- data/lib/generators/coalla/cms/meta_tags/install_generator.rb +0 -2
- data/lib/generators/coalla/cms/scaffold_generator.rb +7 -7
- data/lib/generators/coalla/cms/setup_admin_generator.rb +9 -9
- data/lib/generators/coalla/cms/setup_routes_generator.rb +3 -3
- data/lib/generators/coalla/cms/slider/init_generator.rb +1 -3
- data/lib/generators/coalla/cms/slider/templates/slider_image.rb.erb +0 -1
- data/lib/generators/coalla/cms/slider/templates/slider_image_uploader.rb.erb +1 -1
- data/lib/generators/coalla/cms/templates/.gitignore +3 -3
- data/lib/generators/coalla/cms/templates/controllers/admin/administrators_controller.rb +2 -40
- data/lib/generators/coalla/cms/templates/controllers/admin/scaffold_controller_template.rb.erb +0 -39
- data/lib/generators/coalla/cms/templates/initializers/carrierwave.rb +0 -90
- data/lib/generators/coalla/cms/templates/locales/activerecord.en.yml +14 -1
- data/lib/generators/coalla/cms/templates/views/admin/administrators/_form.html.haml +1 -1
- data/lib/generators/coalla/cms/templates/views/admin/administrators/edit.html.haml +1 -1
- data/lib/generators/coalla/cms/templates/views/admin/administrators/index.html.haml +5 -5
- data/lib/generators/coalla/cms/templates/views/admin/administrators/new.html.haml +1 -1
- data/lib/generators/coalla/cms/templates/views/admin/scaffold_template/_form.html.haml.erb +1 -1
- data/lib/generators/coalla/cms/templates/views/admin/scaffold_template/edit.html.haml.erb +1 -1
- data/lib/generators/coalla/cms/templates/views/admin/scaffold_template/index.html.haml.erb +5 -5
- data/lib/generators/coalla/cms/templates/views/admin/scaffold_template/new.html.haml.erb +1 -1
- data/lib/generators/coalla/cms/templates/views/administrators/sessions/new.html.haml +1 -1
- data/lib/generators/coalla/cms/utils/orm.rb +29 -0
- data/lib/generators/coalla/cms/utils/scaffold.rb +11 -0
- metadata +60 -145
- data/Gemfile.lock +0 -198
- data/app/assets/stylesheets/admin/vendor/token-input-facebook.patched.css +0 -126
- data/app/assets/stylesheets/admin/vendor/token-input.patched.css +0 -116
- data/app/controllers/admin/notifier_controller.rb +0 -7
- data/app/helpers/admin_helper.rb +0 -29
- data/app/helpers/nested_fields_helper.rb +0 -12
- data/app/helpers/static_text_formatter.rb +0 -25
- data/app/helpers/twitter_builder_helper.rb +0 -253
- data/app/helpers/twitter_form_builder.rb +0 -202
- data/app/uploaders/file_uploader.rb +0 -10
- data/app/uploaders/generic_image_uploader.rb +0 -74
- data/app/uploaders/meta_tags_image_uploader.rb +0 -5
- data/app/utils/admin_structure.rb +0 -82
- data/app/utils/bootstrap_link_renderer.rb +0 -40
- data/app/utils/table_helpers.rb +0 -196
- data/lib/generators/coalla/cms/market/install_generator.rb +0 -71
- data/lib/generators/coalla/cms/market/templates/controllers/categories_controller.rb +0 -47
- data/lib/generators/coalla/cms/market/templates/controllers/products_controller.rb +0 -50
- data/lib/generators/coalla/cms/market/templates/controllers/properties_controller.rb +0 -59
- data/lib/generators/coalla/cms/market/templates/market.rb +0 -5
- data/lib/generators/coalla/cms/market/templates/market.ru.yml +0 -53
- data/lib/generators/coalla/cms/market/templates/migrations/create_categories.rb +0 -15
- data/lib/generators/coalla/cms/market/templates/migrations/create_product_properties.rb +0 -18
- data/lib/generators/coalla/cms/market/templates/migrations/create_products.rb +0 -18
- data/lib/generators/coalla/cms/market/templates/migrations/create_properties.rb +0 -11
- data/lib/generators/coalla/cms/market/templates/models/category.rb +0 -36
- data/lib/generators/coalla/cms/market/templates/models/product.rb +0 -16
- data/lib/generators/coalla/cms/market/templates/models/product_property.rb +0 -14
- data/lib/generators/coalla/cms/market/templates/models/property.rb +0 -7
- data/lib/generators/coalla/cms/market/templates/views/categories/_form.html.haml +0 -10
- data/lib/generators/coalla/cms/market/templates/views/categories/edit.html.haml +0 -5
- data/lib/generators/coalla/cms/market/templates/views/categories/index.html.haml +0 -17
- data/lib/generators/coalla/cms/market/templates/views/categories/new.html.haml +0 -4
- data/lib/generators/coalla/cms/market/templates/views/products/_form.html.haml +0 -17
- data/lib/generators/coalla/cms/market/templates/views/products/_product_property_fields.html.haml +0 -13
- data/lib/generators/coalla/cms/market/templates/views/products/edit.html.haml +0 -5
- data/lib/generators/coalla/cms/market/templates/views/products/index.html.haml +0 -17
- data/lib/generators/coalla/cms/market/templates/views/products/new.html.haml +0 -4
- data/lib/generators/coalla/cms/market/templates/views/properties/_form.html.haml +0 -9
- data/lib/generators/coalla/cms/market/templates/views/properties/edit.html.haml +0 -5
- data/lib/generators/coalla/cms/market/templates/views/properties/index.html.haml +0 -15
- data/lib/generators/coalla/cms/market/templates/views/properties/new.html.haml +0 -4
- data/lib/generators/coalla/cms/news/scaffold_generator.rb +0 -50
- data/lib/generators/coalla/cms/news/templates/entity.rb.erb +0 -10
- data/lib/generators/coalla/cms/news/templates/entity_controller_template.rb.erb +0 -47
- data/lib/generators/coalla/cms/news/templates/entity_image_uploader.rb.erb +0 -7
- data/lib/generators/coalla/cms/news/templates/migration.rb.erb +0 -15
- data/lib/generators/coalla/cms/news/templates/views/_form.haml.erb +0 -16
- data/lib/generators/coalla/cms/news/templates/views/edit.haml.erb +0 -5
- data/lib/generators/coalla/cms/news/templates/views/index.haml.erb +0 -18
- data/lib/generators/coalla/cms/news/templates/views/new.haml.erb +0 -5
- data/lib/generators/coalla/cms/orm_helpers.rb +0 -31
- data/lib/generators/coalla/cms/scaffold_helper.rb +0 -11
- data/lib/generators/coalla/cms/templates/controllers/admin/base_controller.rb.erb +0 -35
@@ -1,253 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
module TwitterBuilderHelper
|
3
|
-
|
4
|
-
ALIGN_CLASSES = {left: 't-left', center: 't-center', right: 't-right'}
|
5
|
-
|
6
|
-
class ColumnDefinition
|
7
|
-
attr_accessor :title, :cols, :col_class, :value_extractor, :align
|
8
|
-
|
9
|
-
def value(item, context = self)
|
10
|
-
self.value_extractor.call(item)
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
class ActionsColumnDefinition < ColumnDefinition
|
16
|
-
|
17
|
-
def initialize
|
18
|
-
self.title = I18n.t('admin.common.actions')
|
19
|
-
@actions = []
|
20
|
-
end
|
21
|
-
|
22
|
-
def cols
|
23
|
-
@cols || @actions.size % 2 + @actions.size / 2
|
24
|
-
end
|
25
|
-
|
26
|
-
def col_class
|
27
|
-
"col-xs-#{cols}"
|
28
|
-
end
|
29
|
-
|
30
|
-
def cols=(value)
|
31
|
-
@cols = value
|
32
|
-
end
|
33
|
-
|
34
|
-
def value(item, context = self)
|
35
|
-
@actions.collect do |action|
|
36
|
-
options = action.second
|
37
|
-
if options[:if]
|
38
|
-
context.instance_exec(item, &action.first) if options[:if].call(item)
|
39
|
-
else
|
40
|
-
context.instance_exec(item, &action.first)
|
41
|
-
end
|
42
|
-
end.compact.join(' ').html_safe
|
43
|
-
end
|
44
|
-
|
45
|
-
def action(method, options = {})
|
46
|
-
@actions << case method
|
47
|
-
when :edit
|
48
|
-
[->(item) { edit_link(send("edit_admin_#{item.class.name.underscore.sub('/', '_')}_path", item)) }, options]
|
49
|
-
when :delete
|
50
|
-
[->(item) { delete_link([:admin, item]) }, options]
|
51
|
-
when Proc
|
52
|
-
[method, options]
|
53
|
-
else
|
54
|
-
raise "unsupported method: #{method.inspect}"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
class TableBuilder
|
61
|
-
|
62
|
-
def initialize(parent, model_class)
|
63
|
-
@parent, @model_class = parent, model_class
|
64
|
-
@columns = []
|
65
|
-
@actions_column = ActionsColumnDefinition.new
|
66
|
-
@action_column_on_left = false
|
67
|
-
@table_helpers = TableHelpers.for(@model_class, @parent)
|
68
|
-
end
|
69
|
-
|
70
|
-
def content collection, &block
|
71
|
-
@collection = collection
|
72
|
-
block.call(self) if block_given?
|
73
|
-
create_content
|
74
|
-
end
|
75
|
-
|
76
|
-
# Метод добавляет столбец к таблице
|
77
|
-
def column(method, options = {})
|
78
|
-
helper = @table_helpers[method]
|
79
|
-
cd = ColumnDefinition.new
|
80
|
-
cd.title = options[:title] || I18n.t("activerecord.attributes.#{@model_class.model_name.singular}.#{method}")
|
81
|
-
cd.cols = options[:cols]
|
82
|
-
cd.col_class = options[:class]
|
83
|
-
cd.value_extractor = ->(item) { helper.format_value(item, options[:format]) }
|
84
|
-
cd.align = options[:align] || helper.respond_to?(:align) && "t-#{helper.align}"
|
85
|
-
@columns << cd
|
86
|
-
end
|
87
|
-
|
88
|
-
# Метод позволяет передать блок, который должен вычислять класс для строки. В этот блок передается объект,
|
89
|
-
# по которому данная строка рендерится. Таким образом, можно управлять, например, цветом строки в зависимости
|
90
|
-
# от состояния объекта (статусы заказов и прочее).
|
91
|
-
def row_class lmb
|
92
|
-
@row_class = lmb
|
93
|
-
end
|
94
|
-
|
95
|
-
# Метод добавляет кнопку в столбец действий
|
96
|
-
def action(value, options = {})
|
97
|
-
add_action(value, options)
|
98
|
-
end
|
99
|
-
|
100
|
-
# Метод добавляет кнопку редактирования сущности в столбец действий
|
101
|
-
def edit(options = {})
|
102
|
-
add_action(:edit, options)
|
103
|
-
end
|
104
|
-
|
105
|
-
# Метод добавляет кнопку удаления сущности в столбец действий
|
106
|
-
def delete(options = {})
|
107
|
-
add_action(:delete, options)
|
108
|
-
end
|
109
|
-
|
110
|
-
# Метод добавляет кнопки добавления и удаления сущностей в столбец действий
|
111
|
-
def edit_and_delete(options = {})
|
112
|
-
self.edit(options)
|
113
|
-
self.delete(options)
|
114
|
-
end
|
115
|
-
|
116
|
-
private
|
117
|
-
|
118
|
-
def add_action(value, options)
|
119
|
-
@action_column_on_left = true if @columns.empty?
|
120
|
-
@actions_column.action(value, options)
|
121
|
-
end
|
122
|
-
|
123
|
-
def all_columns
|
124
|
-
@action_column_on_left ? [@actions_column] + @columns : @columns + [@actions_column]
|
125
|
-
end
|
126
|
-
|
127
|
-
def create_content
|
128
|
-
@parent.render(partial: '/admin/common/table_template', locals: {definitions: all_columns, items: @collection, row_class: @row_class})
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def twitter_form_for(name, *args, &block)
|
133
|
-
options = args.extract_options!
|
134
|
-
form_for(name, *(args << options.deep_merge(builder: TwitterFormBuilder, html: {class: 'form-horizontal'})), &block)
|
135
|
-
end
|
136
|
-
|
137
|
-
def field_set title = nil, &block
|
138
|
-
content = capture(self, &block)
|
139
|
-
content = content_tag(:legend, title) + content if title
|
140
|
-
content_tag :fieldset, content
|
141
|
-
end
|
142
|
-
|
143
|
-
def actions &block
|
144
|
-
content = capture(self, &block)
|
145
|
-
content_tag :div, content, class: 'well'
|
146
|
-
end
|
147
|
-
|
148
|
-
def standard_actions(form)
|
149
|
-
fixed_actions { form.save + form.apply + form.cancel }
|
150
|
-
end
|
151
|
-
|
152
|
-
def fixed_actions &block
|
153
|
-
panel_tag = actions(&block)
|
154
|
-
content_tag :div, panel_tag, class: 'action-bar'
|
155
|
-
end
|
156
|
-
|
157
|
-
def flash_warning_messages
|
158
|
-
r = if flash[:admin_warning]
|
159
|
-
"<div class='row'>
|
160
|
-
<div class='col-md-8 col-md-offset-2'>
|
161
|
-
<div class='alert alert-danger'>
|
162
|
-
<button data-dismiss='alert' class='close' type='button'>×</button>
|
163
|
-
<p>#{h(flash[:admin_warning])}</p>
|
164
|
-
</div>
|
165
|
-
</div>
|
166
|
-
</div>"
|
167
|
-
end
|
168
|
-
r && r.html_safe
|
169
|
-
end
|
170
|
-
|
171
|
-
def flash_alert_messages
|
172
|
-
r = if flash[:alert]
|
173
|
-
"<div class='row'>
|
174
|
-
<div class='col-md-8 col-md-offset-2'>
|
175
|
-
<div class='alert alert-danger'>
|
176
|
-
<button data-dismiss='alert' class='close' type='button'>×</button>
|
177
|
-
<p>#{h(flash[:alert])}</p>
|
178
|
-
</div>
|
179
|
-
</div>
|
180
|
-
</div>"
|
181
|
-
end
|
182
|
-
r && r.html_safe
|
183
|
-
end
|
184
|
-
|
185
|
-
def flash_success_messages
|
186
|
-
r = if flash[:admin_success]
|
187
|
-
"<div class='row'>
|
188
|
-
<div class='col-md-8 col-md-offset-2'>
|
189
|
-
<div class='alert alert-success'>
|
190
|
-
<button data-dismiss='alert' class='close' type='button'>×</button>
|
191
|
-
<p>#{h(flash[:admin_success])}</p>
|
192
|
-
</div>
|
193
|
-
</div>
|
194
|
-
</div>"
|
195
|
-
end
|
196
|
-
r && r.html_safe
|
197
|
-
end
|
198
|
-
|
199
|
-
def flash_messages
|
200
|
-
[flash_warning_messages, flash_success_messages].compact.join.html_safe
|
201
|
-
end
|
202
|
-
|
203
|
-
def create_link path
|
204
|
-
content = "<i class='glyphicon glyphicon-plus'></i> #{I18n.t('admin.common.new')}".html_safe
|
205
|
-
link_to content, path, class: 'btn btn-success'
|
206
|
-
end
|
207
|
-
|
208
|
-
def sort_link path
|
209
|
-
content = "<i class='glyphicon glyphicon-random'></i> #{I18n.t('admin.common.sort')}".html_safe
|
210
|
-
link_to content, path, class: 'btn btn-primary'
|
211
|
-
end
|
212
|
-
|
213
|
-
def edit_link path
|
214
|
-
content = "<i class='glyphicon glyphicon-pencil'></i>".html_safe
|
215
|
-
link_to content, path, class: 'btn btn-default btn-xs', title: I18n.t('admin.common.edit')
|
216
|
-
end
|
217
|
-
|
218
|
-
def delete_link path
|
219
|
-
content = "<i class='glyphicon glyphicon-trash'></i>".html_safe
|
220
|
-
link_to content, path, data: {confirm: I18n.t('admin.common.sure')}, method: :delete, class: 'btn btn-danger btn-xs', title: I18n.t('admin.common.delete')
|
221
|
-
end
|
222
|
-
|
223
|
-
def cancel_action path, name = I18n.t('admin.common.cancel')
|
224
|
-
link_to name, path, class: 'btn btn-default'
|
225
|
-
end
|
226
|
-
|
227
|
-
def back_action name = I18n.t('admin.common.return'), path = back_uri
|
228
|
-
link_to name, path, class: 'btn btn-default'
|
229
|
-
end
|
230
|
-
|
231
|
-
def table_for a_class
|
232
|
-
TableBuilder.new(self, a_class)
|
233
|
-
end
|
234
|
-
|
235
|
-
def th_class(column)
|
236
|
-
klass = []
|
237
|
-
klass << "col-xs-#{column.cols}" if column.cols
|
238
|
-
klass << ALIGN_CLASSES[column.align] if column.align
|
239
|
-
klass.join(' ')
|
240
|
-
end
|
241
|
-
|
242
|
-
def tr_class(row_class, item)
|
243
|
-
row_class && row_class.call(item)
|
244
|
-
end
|
245
|
-
|
246
|
-
def td_class(column)
|
247
|
-
klass = []
|
248
|
-
klass << column.col_class
|
249
|
-
klass << ALIGN_CLASSES[column.align] if column.align
|
250
|
-
klass.join(' ')
|
251
|
-
end
|
252
|
-
|
253
|
-
end
|
@@ -1,202 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
class TwitterFormBuilder < ActionView::Helpers::FormBuilder
|
3
|
-
include ActionView::Helpers::FormTagHelper
|
4
|
-
|
5
|
-
COLS_CLASS = 'col-md-8'
|
6
|
-
|
7
|
-
def errors
|
8
|
-
return nil unless @object.errors.any?
|
9
|
-
|
10
|
-
messages = @object.errors.full_messages.collect do |msg|
|
11
|
-
"<p>#{ERB::Util.h(msg)}</p>".html_safe
|
12
|
-
end
|
13
|
-
|
14
|
-
content_tag(:div,
|
15
|
-
content_tag(:div,
|
16
|
-
content_tag(:div,
|
17
|
-
content_tag(:button, '×'.html_safe, class: 'close', type: 'button', :'data-dismiss' => 'alert') + messages.join('').html_safe,
|
18
|
-
class: 'alert alert-danger'),
|
19
|
-
class: 'col-md-8 col-md-offset-2'),
|
20
|
-
class: 'row')
|
21
|
-
end
|
22
|
-
|
23
|
-
def static_text(method, options = {})
|
24
|
-
row method, content_tag(:p, static_text_formatter.format(method), class: 'form-control-static'), options
|
25
|
-
end
|
26
|
-
|
27
|
-
# Displays multi-line static text in form
|
28
|
-
def static_memo_text(method, options = {})
|
29
|
-
row method, simple_format(@object.send(method), class: 'form-control-static'), options
|
30
|
-
end
|
31
|
-
|
32
|
-
def string method, options = {}
|
33
|
-
row method, text_field(method, with_default_options(options)), options
|
34
|
-
end
|
35
|
-
|
36
|
-
def combobox method, choices, options = {}, html_options = {}
|
37
|
-
row method, select(method, choices, options, with_default_options(html_options)), div_class: options.delete(:div_class) || 'col-md-6'
|
38
|
-
end
|
39
|
-
|
40
|
-
def enum(method, options = {}, html_options = {})
|
41
|
-
combobox method, object.class.send(method.to_s.pluralize).collect { |s| [s[0].humanize, s[0]] }, options, html_options
|
42
|
-
end
|
43
|
-
|
44
|
-
def enumerize(method, options = {}, html_options = {})
|
45
|
-
combobox method, object.class.send(method).values.collect { |s| [s.text, s] }, options, html_options
|
46
|
-
end
|
47
|
-
|
48
|
-
def list_all_combobox(association_name, options = {}, html_options = {})
|
49
|
-
collection_class = object.class.reflect_on_association(association_name).klass
|
50
|
-
combobox("#{association_name}_id", collection_class.all.sort_by(&:name).map { |element| [element.name, element.id] }, {include_blank: true}.merge(options), html_options)
|
51
|
-
end
|
52
|
-
|
53
|
-
def textarea method, options = {}
|
54
|
-
row method, text_area(method, with_default_options(options)), options
|
55
|
-
end
|
56
|
-
|
57
|
-
def checkbox method, options = {}
|
58
|
-
row method, content_tag(:div, check_box(method, options), class: 'checkbox'), options
|
59
|
-
end
|
60
|
-
|
61
|
-
def wysiwyg method, options = {}
|
62
|
-
textarea method, with_default_options(merge_classes(options, 'wymeditor'))
|
63
|
-
end
|
64
|
-
|
65
|
-
def ckeditor(method, options = {})
|
66
|
-
row method, cktext_area(method, with_default_options(options))
|
67
|
-
end
|
68
|
-
|
69
|
-
def password method, options = {}
|
70
|
-
row method, password_field(method, with_default_options(options)), options
|
71
|
-
end
|
72
|
-
|
73
|
-
def date method, options = {}
|
74
|
-
string(method, merge_options({data: {'calendar-date' => true}, div_class: 'col-md-2'}, options))
|
75
|
-
end
|
76
|
-
|
77
|
-
def datetime(method, options = {})
|
78
|
-
value = object.try(method).try(:strftime, '%Y-%m-%d %H:%M')
|
79
|
-
string(method, merge_options({data: {'calendar-datetime' => true}, div_class: 'col-md-3', value: value}, options))
|
80
|
-
end
|
81
|
-
|
82
|
-
def time(method, options = {})
|
83
|
-
value = object.try(method).try(:strftime, '%H:%M')
|
84
|
-
string(method, merge_options({data: {'calendar-time' => true}, div_class: 'col-md-2', value: value}, options))
|
85
|
-
end
|
86
|
-
|
87
|
-
def save text = I18n.t('admin.common.save')
|
88
|
-
submit text, name: :save, class: 'btn btn-success wymupdate'
|
89
|
-
end
|
90
|
-
|
91
|
-
def apply text = I18n.t('admin.common.apply')
|
92
|
-
submit text, name: :apply, class: 'btn btn-default wymupdate'
|
93
|
-
end
|
94
|
-
|
95
|
-
def cancel
|
96
|
-
@template.back_action
|
97
|
-
end
|
98
|
-
|
99
|
-
# Editing has_many collection
|
100
|
-
# parameters: association - name of has_many association
|
101
|
-
# association should be defined as accepts_nested_attributes with allow_destroy = true in model
|
102
|
-
# You should create partial with name #{association)_fields
|
103
|
-
def nested_fields_for(association)
|
104
|
-
@template.render 'admin/common/nested_fields_for', f: self, section_name: @object.class.human_attribute_name(association), collection: association
|
105
|
-
end
|
106
|
-
|
107
|
-
def image_upload method, options = {}
|
108
|
-
version = options[:version]
|
109
|
-
|
110
|
-
uri = if version.present?
|
111
|
-
@object.send("#{method}_url", version)
|
112
|
-
else
|
113
|
-
@object.send("#{method}_url")
|
114
|
-
end
|
115
|
-
|
116
|
-
if options[:size]
|
117
|
-
url = uri || 'placeholder'
|
118
|
-
else
|
119
|
-
url = uri
|
120
|
-
end
|
121
|
-
|
122
|
-
upload_uri = options[:upload_path]
|
123
|
-
unless upload_uri
|
124
|
-
upload_uri = @template.admin_upload_image_path(image_class: @object.class.name.underscore, field: method)
|
125
|
-
end
|
126
|
-
@template.render partial: '/admin/common/image_upload_template', locals: {
|
127
|
-
f: self, url: url, size: options[:size],
|
128
|
-
version: version || '',
|
129
|
-
title: options[:title] || '',
|
130
|
-
text: options[:text],
|
131
|
-
field: method, upload_uri: upload_uri,
|
132
|
-
container: options[:parent_id] || upload_container_id(method),
|
133
|
-
options: options.delete(:options) || {},
|
134
|
-
image_style: options.delete(:image_style) || ''
|
135
|
-
}
|
136
|
-
end
|
137
|
-
|
138
|
-
def file_upload method
|
139
|
-
@template.render partial: '/admin/common/file_upload_template', locals: {
|
140
|
-
f: self,
|
141
|
-
field: method
|
142
|
-
}
|
143
|
-
end
|
144
|
-
|
145
|
-
def multi_field(relation_name, options = {})
|
146
|
-
reflection = self.object.class.reflections[relation_name] || self.object.class.reflections[relation_name.to_s]
|
147
|
-
options = {search_field_name: :name,
|
148
|
-
show_all_on_focus: false,
|
149
|
-
use_cache: true,
|
150
|
-
relation_model_name: reflection.klass.model_name.singular}.merge!(options)
|
151
|
-
options[:source] ||= @template.admin_autocomplete_path(options[:relation_model_name], options[:search_field_name])
|
152
|
-
string "#{relation_name}_tokens", title: self.object.class.human_attribute_name(relation_name),
|
153
|
-
data: {
|
154
|
-
multi_field: true,
|
155
|
-
source: options[:source],
|
156
|
-
pre: self.object.send("#{relation_name}_json", options[:search_field_name]),
|
157
|
-
show_all_on_focus: options[:show_all_on_focus],
|
158
|
-
use_cache: options[:use_cache],
|
159
|
-
object_url_name: options[:object_url_name]}
|
160
|
-
end
|
161
|
-
|
162
|
-
def row(method, controls, options = {})
|
163
|
-
label_class = options[:label_class] || 'control-label col-md-4 col-lg-2'
|
164
|
-
label_tag = label(method, options[:title], class: label_class) unless options[:hide_label]
|
165
|
-
options[:div_class] ||= COLS_CLASS
|
166
|
-
div_tag = content_tag :div, controls.html_safe, class: options[:div_class]
|
167
|
-
content_tag :div, "#{label_tag}#{div_tag}".html_safe, class: 'form-group'
|
168
|
-
end
|
169
|
-
|
170
|
-
private
|
171
|
-
|
172
|
-
def upload_container_id(method)
|
173
|
-
fake_method = "#{method}_upload"
|
174
|
-
ActionView::Helpers::Tags::Base.new(@object_name, fake_method, @template).send(:tag_id)
|
175
|
-
end
|
176
|
-
|
177
|
-
def with_default_options(options)
|
178
|
-
merge_classes(options, 'form-control')
|
179
|
-
options
|
180
|
-
end
|
181
|
-
|
182
|
-
def merge_classes(options, *clazz)
|
183
|
-
classes = [options[:class]].compact
|
184
|
-
classes.push(*clazz)
|
185
|
-
options[:class] = classes.uniq.join(' ')
|
186
|
-
options
|
187
|
-
end
|
188
|
-
|
189
|
-
def merge_options(default_options, options)
|
190
|
-
return default_options if options.blank?
|
191
|
-
new_options = default_options.merge(options)
|
192
|
-
if default_options.has_key?(:data) && options.has_key?(:data)
|
193
|
-
new_options[:data] = default_options[:data].merge(options[:data])
|
194
|
-
end
|
195
|
-
new_options
|
196
|
-
end
|
197
|
-
|
198
|
-
def static_text_formatter
|
199
|
-
@static_text_formatter ||= StaticTextFormatter.new(@object)
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
require 'carrierwave/processing/mime_types'
|
3
|
-
require 'shellwords'
|
4
|
-
|
5
|
-
# TODO Добавить настройку watermark_image, position
|
6
|
-
|
7
|
-
class GenericImageUploader < CarrierWave::Uploader::Base
|
8
|
-
include CarrierWave::RMagick
|
9
|
-
include CarrierWave::MimeTypes
|
10
|
-
|
11
|
-
before :cache, :capture_size_before_cache
|
12
|
-
|
13
|
-
storage :file
|
14
|
-
|
15
|
-
process :set_content_type
|
16
|
-
process :set_image_properties
|
17
|
-
|
18
|
-
def watermark
|
19
|
-
return if !model || !model.respond_to?(getter(:watermarked?)) || !model.send(getter(:watermarked?))
|
20
|
-
|
21
|
-
manipulate! do |img|
|
22
|
-
logo = Magick::Image.read(Rails.root.join("app/assets/images/watermark.png")).first
|
23
|
-
img.composite(logo, Magick::SouthEastGravity, 0, 0, Magick::OverCompositeOp)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def store_dir
|
28
|
-
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
29
|
-
end
|
30
|
-
|
31
|
-
#def default_url
|
32
|
-
# "/assets/fallback/" + [version_name, "default.png"].compact.join('_')
|
33
|
-
#end
|
34
|
-
|
35
|
-
def capture_size_before_cache(new_file)
|
36
|
-
return unless model
|
37
|
-
return unless new_file.path
|
38
|
-
if model.respond_to?(setter(:width)) && model.respond_to?(setter(:height))
|
39
|
-
w, h = `identify -format "%wx %h" #{new_file.path.shellescape}`.split(/x/).map { |dim| dim.to_i }
|
40
|
-
model.send(setter(:width), w)
|
41
|
-
model.send(setter(:height), h)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def set_image_properties
|
46
|
-
return if !model || !file
|
47
|
-
|
48
|
-
model.send(setter(:file_name), file.filename) if model.respond_to?(setter(:file_name))
|
49
|
-
model.send(setter(:size), file.size) if model.respond_to?(setter(:size))
|
50
|
-
model.send(setter(:content_type), file.content_type) if model.respond_to?(setter(:content_type))
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def setter(name)
|
56
|
-
opt = model.class.uploader_options[mounted_as] || {}
|
57
|
-
if opt[:prefixed]
|
58
|
-
"#{mounted_as}_#{name}="
|
59
|
-
else
|
60
|
-
"#{name}="
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
def getter(name)
|
66
|
-
opt = model.class.uploader_options[mounted_as] || {}
|
67
|
-
if opt[:prefixed]
|
68
|
-
"#{mounted_as}_#{name}"
|
69
|
-
else
|
70
|
-
"#{name}"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
#encoding: utf-8
|
2
|
-
class AdminStructure
|
3
|
-
|
4
|
-
include Rails.application.routes.url_helpers
|
5
|
-
|
6
|
-
Section = Struct.new(:name, :path, :icon, :description, :counter, :show_menu_counter, :creation_path) do
|
7
|
-
|
8
|
-
def show_menu_counter?
|
9
|
-
show_menu_counter.present?
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
Separator = Struct.new(:title)
|
15
|
-
|
16
|
-
CONFIG_FILE_NAME = 'structure.rb'
|
17
|
-
|
18
|
-
attr_accessor :sections
|
19
|
-
|
20
|
-
def initialize(controller)
|
21
|
-
@controller = controller
|
22
|
-
@sections = []
|
23
|
-
load_sections_from_config
|
24
|
-
end
|
25
|
-
|
26
|
-
def menu_items
|
27
|
-
dashboard_item = Section.new(I18n.t('admin.common.dashboard'), admin_dashboard_path, 'glyphicon glyphicon-align-left')
|
28
|
-
[dashboard_item] + @sections
|
29
|
-
end
|
30
|
-
|
31
|
-
def sections
|
32
|
-
@sections.find_all { |section| section.is_a?(Section) }
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def load_sections_from_config
|
38
|
-
config_path = Rails.root.join('config', CONFIG_FILE_NAME).to_s
|
39
|
-
if File.exist?(config_path)
|
40
|
-
instance_eval(File.read(config_path), config_path)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# Options:
|
45
|
-
# creation_path - false or path string
|
46
|
-
def section(section_reference, options = {})
|
47
|
-
path = options.delete(:path)
|
48
|
-
icon = options.delete(:icon)
|
49
|
-
description = options.delete(:description)
|
50
|
-
counter = options.delete(:counter)
|
51
|
-
show_menu_counter = options.delete(:show_menu_counter)
|
52
|
-
creation_path = options.delete(:creation_path)
|
53
|
-
if section_reference.is_a?(Class)
|
54
|
-
section_name = section_reference.model_name.human
|
55
|
-
path = send("admin_#{section_reference.model_name.route_key}_path") unless path
|
56
|
-
counter = ->() { section_reference.count } unless counter
|
57
|
-
creation_path = send("new_admin_#{section_reference.model_name.singular}_path") if creation_path.nil?
|
58
|
-
else
|
59
|
-
section_name = section_reference
|
60
|
-
end
|
61
|
-
@sections << Section.new(section_name, path, icon, description, counter, show_menu_counter, creation_path)
|
62
|
-
end
|
63
|
-
|
64
|
-
def lookup_section(section_references = 'Настройки', category = nil, options = {})
|
65
|
-
default_options = options.merge(path: send('admin_lookups_index_path', category: category),
|
66
|
-
icon: 'glyphicon glyphicon-wrench',
|
67
|
-
description: 'Раздел содержит различные настройки и тексты')
|
68
|
-
section(section_references, default_options)
|
69
|
-
end
|
70
|
-
|
71
|
-
def meta_tags_section(section_references = 'Мета-тэги', options = {})
|
72
|
-
default_options = options.merge(path: send('admin_meta_tags_path'),
|
73
|
-
icon: 'glyphicon glyphicon-tag',
|
74
|
-
description: 'Раздел содержит мета-тэги')
|
75
|
-
section(section_references, default_options)
|
76
|
-
end
|
77
|
-
|
78
|
-
def separator(title)
|
79
|
-
@sections << Separator.new(title)
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
class BootstrapLinkRenderer < WillPaginate::ActionView::LinkRenderer
|
2
|
-
|
3
|
-
protected
|
4
|
-
|
5
|
-
def html_container(html)
|
6
|
-
tag(:div, tag(:ul, html, class: 'pagination'), class: 't-center')
|
7
|
-
end
|
8
|
-
|
9
|
-
def page_number(page)
|
10
|
-
if page == current_page
|
11
|
-
tag(:li, tag(:a, page), class: 'active')
|
12
|
-
else
|
13
|
-
tag(:li, link(page, page, rel: rel_value(page)))
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def gap
|
18
|
-
text = @template.will_paginate_translate(:page_gap) { '…' }
|
19
|
-
tag(:li, tag(:a, text), class: 'disabled')
|
20
|
-
end
|
21
|
-
|
22
|
-
def previous_page
|
23
|
-
num = @collection.current_page > 1 && @collection.current_page - 1
|
24
|
-
previous_or_next_page(num, @options[:previous_label])
|
25
|
-
end
|
26
|
-
|
27
|
-
def next_page
|
28
|
-
num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
|
29
|
-
previous_or_next_page(num, @options[:next_label])
|
30
|
-
end
|
31
|
-
|
32
|
-
def previous_or_next_page(page, text)
|
33
|
-
if page
|
34
|
-
tag(:li, link(text, page))
|
35
|
-
else
|
36
|
-
tag(:li, tag(:a, text), class: 'disabled')
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|