coalla-cms 0.5.2.4 → 0.6.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile +1 -1
- data/app/assets/javascripts/admin/admin.js +233 -34
- 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/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 -5
- 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 +57 -100
- 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 -75
- 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
- /data/{lib/generators/coalla/cms/templates/controllers/admin/home_controller.rb.erb → app/controllers/admin/home_controller.rb} +0 -0
@@ -1,116 +0,0 @@
|
|
1
|
-
/* Example tokeninput style #1: Token vertical list*/
|
2
|
-
ul.token-input-list {
|
3
|
-
overflow: hidden;
|
4
|
-
height: auto !important;
|
5
|
-
height: 1%;
|
6
|
-
width: 400px;
|
7
|
-
border: 1px solid #999;
|
8
|
-
cursor: text;
|
9
|
-
font-size: 12px;
|
10
|
-
font-family: Verdana;
|
11
|
-
z-index: 999;
|
12
|
-
margin: 0;
|
13
|
-
padding: 0;
|
14
|
-
background-color: #fff;
|
15
|
-
list-style-type: none;
|
16
|
-
clear: left;
|
17
|
-
}
|
18
|
-
|
19
|
-
ul.token-input-list li {
|
20
|
-
list-style-type: none;
|
21
|
-
}
|
22
|
-
|
23
|
-
ul.token-input-list li input {
|
24
|
-
border: 0;
|
25
|
-
width: 350px;
|
26
|
-
padding: 3px 8px;
|
27
|
-
background-color: white;
|
28
|
-
-webkit-appearance: caret;
|
29
|
-
}
|
30
|
-
|
31
|
-
li.token-input-token {
|
32
|
-
overflow: hidden;
|
33
|
-
height: auto !important;
|
34
|
-
height: 1%;
|
35
|
-
margin: 3px;
|
36
|
-
padding: 3px 5px;
|
37
|
-
background-color: #d0efa0;
|
38
|
-
color: #000;
|
39
|
-
font-weight: bold;
|
40
|
-
cursor: default;
|
41
|
-
display: block;
|
42
|
-
}
|
43
|
-
|
44
|
-
li.token-input-token p {
|
45
|
-
float: left;
|
46
|
-
padding: 0;
|
47
|
-
margin: 0;
|
48
|
-
}
|
49
|
-
|
50
|
-
li.token-input-token span {
|
51
|
-
float: right;
|
52
|
-
color: #777;
|
53
|
-
cursor: pointer;
|
54
|
-
}
|
55
|
-
|
56
|
-
li.token-input-selected-token {
|
57
|
-
background-color: #08844e;
|
58
|
-
color: #fff;
|
59
|
-
}
|
60
|
-
|
61
|
-
li.token-input-selected-token span {
|
62
|
-
color: #bbb;
|
63
|
-
}
|
64
|
-
|
65
|
-
div.token-input-dropdown {
|
66
|
-
position: absolute;
|
67
|
-
width: 400px;
|
68
|
-
background-color: #fff;
|
69
|
-
overflow: hidden;
|
70
|
-
border-left: 1px solid #ccc;
|
71
|
-
border-right: 1px solid #ccc;
|
72
|
-
border-bottom: 1px solid #ccc;
|
73
|
-
cursor: default;
|
74
|
-
font-size: 12px;
|
75
|
-
font-family: Verdana;
|
76
|
-
z-index: 1;
|
77
|
-
}
|
78
|
-
|
79
|
-
div.token-input-dropdown p {
|
80
|
-
margin: 0;
|
81
|
-
padding: 5px;
|
82
|
-
font-weight: bold;
|
83
|
-
color: #777;
|
84
|
-
}
|
85
|
-
|
86
|
-
div.token-input-dropdown ul {
|
87
|
-
margin: 0;
|
88
|
-
padding: 0;
|
89
|
-
}
|
90
|
-
|
91
|
-
div.token-input-dropdown ul li {
|
92
|
-
background-color: #fff;
|
93
|
-
padding: 3px;
|
94
|
-
list-style-type: none;
|
95
|
-
}
|
96
|
-
|
97
|
-
div.token-input-dropdown ul li.token-input-dropdown-item {
|
98
|
-
background-color: #fafafa;
|
99
|
-
}
|
100
|
-
|
101
|
-
div.token-input-dropdown ul li.token-input-dropdown-item2 {
|
102
|
-
background-color: #fff;
|
103
|
-
}
|
104
|
-
|
105
|
-
div.token-input-dropdown ul li em {
|
106
|
-
font-weight: bold;
|
107
|
-
font-style: normal;
|
108
|
-
}
|
109
|
-
|
110
|
-
div.token-input-dropdown ul li.token-input-selected-dropdown-item {
|
111
|
-
background-color: #d0efa0;
|
112
|
-
}
|
113
|
-
|
114
|
-
/* Coalla patch */
|
115
|
-
.token-input-token a {color: inherit;}
|
116
|
-
.token-input-token a:hover {text-decoration: none;}
|
data/app/helpers/admin_helper.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module AdminHelper
|
2
|
-
|
3
|
-
def admin_paginate(collection, options={})
|
4
|
-
will_paginate collection, {renderer: BootstrapLinkRenderer, inner_window: 2}.merge(options)
|
5
|
-
end
|
6
|
-
|
7
|
-
def render_slides(form, title, collection_name, options = {})
|
8
|
-
slider_class = options.delete(:slider_class_name) || SliderImage
|
9
|
-
multiple = options.has_key?(:multiple) ? options.delete(:multiple) : true
|
10
|
-
edit_allowed = options.has_key?(:edit_allowed) ? options.delete(:edit_allowed) : true
|
11
|
-
render 'admin/common/slides', form: form, title: title, slides: collection_name, slider_class: slider_class, multiple: multiple, edit_allowed: edit_allowed
|
12
|
-
end
|
13
|
-
|
14
|
-
def generate_slider_template(form_builder, options = {})
|
15
|
-
escape_javascript(generate_slider_html(form_builder, options))
|
16
|
-
end
|
17
|
-
|
18
|
-
def generate_slider_html(form_builder, options = {})
|
19
|
-
options[:object] ||= options[:class].new
|
20
|
-
options[:form_builder_local] ||= :lb
|
21
|
-
options[:locals] ||= {}
|
22
|
-
|
23
|
-
collection_name = options[:collection]
|
24
|
-
form_builder.fields_for(collection_name, options[:object], child_index: 'NEW_RECORD') do |f|
|
25
|
-
render(partial: options[:partial], locals: options[:locals].merge({options[:form_builder_local] => f}))
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module NestedFieldsHelper
|
2
|
-
|
3
|
-
def link_to_add_fields(name, builder, association)
|
4
|
-
new_object = builder.object.send(association).klass.new
|
5
|
-
id = new_object.object_id
|
6
|
-
fields = builder.fields_for(association, new_object, child_index: id) do |builder|
|
7
|
-
render 'admin/common/nested_fields_for_element', builder: builder, partial: "#{association.to_s.singularize}_fields"
|
8
|
-
end
|
9
|
-
link_to(name, '#', class: 'add_fields btn btn-success', data: {id: id, fields: fields.gsub("\n", '')})
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
class StaticTextFormatter
|
2
|
-
|
3
|
-
def initialize(object)
|
4
|
-
@object = object
|
5
|
-
@columns = @object.class.columns.index_by(&:name).with_indifferent_access
|
6
|
-
end
|
7
|
-
|
8
|
-
def format(method)
|
9
|
-
method_value = @object.send(method)
|
10
|
-
if method_value
|
11
|
-
if @columns[method]
|
12
|
-
method_type = @columns[method].type
|
13
|
-
if method_type == :datetime
|
14
|
-
method_value = method_value.localtime if method_value.respond_to?(:localtime)
|
15
|
-
Russian.strftime(method_value, '%d.%m.%Y %H:%M')
|
16
|
-
else
|
17
|
-
method_value
|
18
|
-
end
|
19
|
-
else
|
20
|
-
method_value
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
@@ -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
|