sunrise-cms 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +49 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +3 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.rdoc +13 -3
- data/Gemfile +11 -22
- data/Gemfile.lock +344 -214
- data/README.md +47 -33
- data/Rakefile +1 -0
- data/app/assets/config/manifest.js +1 -0
- data/app/assets/images/sunrise/icons/export.svg +4 -0
- data/app/assets/images/sunrise/icons/import.svg +5 -0
- data/app/assets/javascripts/sunrise/application.js +2 -5
- data/app/assets/javascripts/sunrise/jquery.dialog.js.coffee +113 -40
- data/app/assets/javascripts/sunrise/jquery.editable.js.coffee +21 -21
- data/app/assets/javascripts/sunrise/manage.js.coffee +29 -28
- data/app/assets/stylesheets/sunrise/application.css +0 -1
- data/app/assets/stylesheets/sunrise/customize.css +7 -4
- data/app/assets/stylesheets/sunrise/main.css +883 -606
- data/app/controllers/sunrise/manager_controller.rb +44 -7
- data/app/controllers/sunrise/settings_controller.rb +2 -3
- data/app/helpers/sunrise/structure_helper.rb +2 -2
- data/app/views/layouts/sunrise/application.html.erb +9 -6
- data/app/views/sunrise/manager/_field.html.erb +5 -5
- data/app/views/sunrise/manager/_form.html.erb +15 -15
- data/app/views/sunrise/manager/_header_edit.html.erb +3 -4
- data/app/views/sunrise/manager/_header_new.html.erb +3 -3
- data/app/views/sunrise/manager/_header_show.html.erb +9 -13
- data/app/views/sunrise/manager/_nested_field.html.erb +6 -6
- data/app/views/sunrise/manager/buttons/_export.html.erb +9 -2
- data/app/views/sunrise/manager/buttons/_import.html.erb +25 -0
- data/app/views/sunrise/manager/buttons/_sort.html.erb +3 -3
- data/app/views/sunrise/manager/edit.html.erb +1 -1
- data/app/views/sunrise/manager/new.html.erb +1 -1
- data/app/views/sunrise/manager/structures/thumbs/_record.html.erb +19 -16
- data/app/views/sunrise/manager/thumbs/_record.html.erb +26 -22
- data/app/views/sunrise/manager/tree/index.html.erb +1 -1
- data/app/views/sunrise/settings/_form.html.erb +5 -5
- data/app/views/sunrise/settings/_header_edit.html.erb +3 -4
- data/config/locales/sunrise/en.yml +35 -35
- data/config/locales/sunrise/ru.yml +35 -35
- data/config/locales/sunrise/uk.yml +35 -35
- data/config/routes.rb +1 -0
- data/db/migrate/20111216144515_create_assets.rb +1 -1
- data/db/migrate/20111216144915_create_structures.rb +1 -1
- data/db/migrate/20111216145015_create_users.rb +1 -1
- data/db/migrate/20120611095315_create_settings.rb +1 -1
- data/lib/generators/sunrise/templates/config/active_record/sunrise.rb +0 -4
- data/lib/generators/sunrise/templates/config/mongoid/sunrise.rb +0 -4
- data/lib/generators/sunrise/templates/models/active_record/attachment_file.rb +0 -2
- data/lib/generators/sunrise/templates/models/active_record/avatar.rb +0 -2
- data/lib/generators/sunrise/templates/models/active_record/picture.rb +0 -2
- data/lib/generators/sunrise/templates/models/active_record/position_type.rb +4 -4
- data/lib/generators/sunrise/templates/models/active_record/role_type.rb +5 -5
- data/lib/generators/sunrise/templates/models/active_record/settings.rb +14 -2
- data/lib/generators/sunrise/templates/models/active_record/structure_type.rb +6 -6
- data/lib/generators/sunrise/templates/models/mongoid/attachment_file.rb +0 -2
- data/lib/generators/sunrise/templates/models/mongoid/avatar.rb +0 -2
- data/lib/generators/sunrise/templates/models/mongoid/picture.rb +0 -2
- data/lib/generators/sunrise/templates/models/mongoid/position_type.rb +4 -4
- data/lib/generators/sunrise/templates/models/mongoid/role_type.rb +5 -5
- data/lib/generators/sunrise/templates/models/mongoid/structure_type.rb +6 -6
- data/lib/generators/sunrise/templates/models/sunrise/sunrise_structure.rb +2 -2
- data/lib/generators/sunrise/templates/spec/controllers/pages_controller_spec.rb +2 -2
- data/lib/generators/sunrise/templates/spec/controllers/welcome_controller_spec.rb +1 -1
- data/lib/generators/sunrise/templates/spec/factories/structure_factory.rb +2 -2
- data/lib/generators/sunrise/templates/spec/factories/user_factory.rb +6 -6
- data/lib/generators/sunrise/templates/spec/spec_helper.rb +1 -1
- data/lib/generators/sunrise/templates/spec/support/helpers/controller_macros.rb +4 -4
- data/lib/generators/sunrise/templates/uploaders/attachment_file_uploader.rb +4 -0
- data/lib/generators/sunrise/templates/uploaders/avatar_uploader.rb +4 -0
- data/lib/generators/sunrise/templates/uploaders/picture_uploader.rb +4 -0
- data/lib/sunrise/abstract_model.rb +13 -3
- data/lib/sunrise/carrierwave/glue.rb +1 -7
- data/lib/sunrise/config/model.rb +4 -0
- data/lib/sunrise/config.rb +0 -5
- data/lib/sunrise/core_ext/string.rb +0 -5
- data/lib/sunrise/engine.rb +7 -1
- data/lib/sunrise/models/ability.rb +8 -8
- data/lib/sunrise/models/position_type.rb +1 -7
- data/lib/sunrise/models/role_type.rb +4 -6
- data/lib/sunrise/models/structure.rb +3 -3
- data/lib/sunrise/models/structure_type.rb +1 -7
- data/lib/sunrise/models/user.rb +4 -4
- data/lib/sunrise/utils.rb +1 -2
- data/lib/sunrise/version.rb +1 -1
- data/lib/sunrise/views/search_wrapper.rb +1 -1
- data/sunrise-cms.gemspec +8 -13
- metadata +24 -65
- data/.rspec +0 -2
- data/lib/sunrise/carrierwave/file_size_validator.rb +0 -75
- data/lib/sunrise/utils/transliteration.rb +0 -73
data/README.md
CHANGED
@@ -1,19 +1,33 @@
|
|
1
1
|
# Sunrise CMS
|
2
2
|
|
3
|
+
[](https://github.com/galetahub/sunrise/actions/workflows/tests.yml)
|
4
|
+
|
3
5
|
Open source mini content management system for programmers.
|
4
6
|
|
5
7
|
## Setup
|
6
8
|
|
9
|
+
For rails 7.x.x:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'sunrise-cms', '~> 2.0', require: 'sunrise'
|
13
|
+
```
|
14
|
+
|
15
|
+
For rails 5.x.x:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'sunrise-cms', '~> 1.1.0', require: 'sunrise'
|
19
|
+
```
|
20
|
+
|
7
21
|
For rails 4.x.x:
|
8
22
|
|
9
23
|
```ruby
|
10
|
-
|
24
|
+
gem "sunrise-cms", require: "sunrise"
|
11
25
|
```
|
12
26
|
|
13
27
|
For rails 3.x.x:
|
14
28
|
|
15
29
|
```ruby
|
16
|
-
|
30
|
+
gem "sunrise-cms", "~> 0.7.x" require: "sunrise"
|
17
31
|
```
|
18
32
|
|
19
33
|
## Instructions
|
@@ -21,23 +35,23 @@ For rails 3.x.x:
|
|
21
35
|
### ActiveRecord
|
22
36
|
|
23
37
|
```bash
|
24
|
-
|
25
|
-
|
38
|
+
rails g devise:install
|
39
|
+
rails g sunrise:install --orm=active_record
|
26
40
|
```
|
27
41
|
|
28
42
|
Copy db migrations files:
|
29
43
|
|
30
44
|
```bash
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
45
|
+
rake sunrise:install:migrations
|
46
|
+
rake page_parts_engine:install:migrations
|
47
|
+
rake meta_manager_engine:install:migrations
|
48
|
+
rails g public_activity:migration
|
35
49
|
```
|
36
50
|
|
37
51
|
### Mongoid
|
38
52
|
|
39
53
|
```bash
|
40
|
-
|
54
|
+
rails g sunrise:install --orm=mongoid
|
41
55
|
```
|
42
56
|
|
43
57
|
## Usage
|
@@ -51,7 +65,7 @@ class SunriseProduct < Sunrise::AbstractModel
|
|
51
65
|
association :structure
|
52
66
|
|
53
67
|
after_sort :clear_cache
|
54
|
-
|
68
|
+
|
55
69
|
index :thumbs do
|
56
70
|
scope { Product.includes(:picture) }
|
57
71
|
preview lambda { |product| product.picture.try(:url, :thumb) }
|
@@ -72,7 +86,7 @@ class SunriseProduct < Sunrise::AbstractModel
|
|
72
86
|
field :unique_accounts_count
|
73
87
|
field :total_points
|
74
88
|
end
|
75
|
-
|
89
|
+
|
76
90
|
show do
|
77
91
|
field :title
|
78
92
|
field :price
|
@@ -80,43 +94,43 @@ class SunriseProduct < Sunrise::AbstractModel
|
|
80
94
|
field :sort_order
|
81
95
|
field :is_visible
|
82
96
|
end
|
83
|
-
|
97
|
+
|
84
98
|
form do
|
85
99
|
field :title
|
86
100
|
field :price
|
87
101
|
field :total_stock
|
88
|
-
|
102
|
+
|
89
103
|
field do |form, record|
|
90
|
-
form.input :notes, :
|
104
|
+
form.input :notes, as: :text, id: record.id
|
91
105
|
end
|
92
106
|
|
93
|
-
group :sidebar, :
|
94
|
-
field :sale_limit_id, :
|
107
|
+
group :sidebar, holder: :sidebar do
|
108
|
+
field :sale_limit_id, collection: lambda { SaleLimit.all }, include_blank: false
|
95
109
|
field :sort_order
|
96
|
-
field :is_visible, :
|
110
|
+
field :is_visible, boolean: true
|
97
111
|
end
|
98
112
|
|
99
|
-
group :bottom, :
|
100
|
-
nested_attributes :variants, :
|
113
|
+
group :bottom, holder: :bottom do
|
114
|
+
nested_attributes :variants, multiply: true do
|
101
115
|
field :size
|
102
|
-
field :total_stock, :
|
103
|
-
field :item_model_id, :
|
116
|
+
field :total_stock, html: { style: 'width:100%;clear:both;' }
|
117
|
+
field :item_model_id, collection: lambda { ItemModel.all }, include_blank: false
|
104
118
|
end
|
105
119
|
|
106
120
|
nested_attributes :project_fields, multiply: true, sort: true do
|
107
121
|
field :name
|
108
122
|
field :value
|
109
123
|
end
|
110
|
-
|
111
|
-
field :picture, :
|
124
|
+
|
125
|
+
field :picture, as: :uploader
|
112
126
|
end
|
113
127
|
end
|
114
128
|
|
115
|
-
|
129
|
+
private
|
116
130
|
|
117
|
-
|
118
|
-
|
119
|
-
|
131
|
+
def clear_cache
|
132
|
+
Rails.cache.clear
|
133
|
+
end
|
120
134
|
end
|
121
135
|
```
|
122
136
|
|
@@ -150,14 +164,14 @@ For more info look at jbuilder https://rubygems.org/gems/jbuilder.
|
|
150
164
|
#### Excel
|
151
165
|
|
152
166
|
```
|
153
|
-
gem "ruby2xlsx"
|
167
|
+
gem "ruby2xlsx"
|
154
168
|
|
155
169
|
GET /manage/users/export.xlsx
|
156
170
|
```
|
157
171
|
|
158
172
|
### Strong parameters
|
159
173
|
|
160
|
-
Now in sunrise file you can perform attributes check.
|
174
|
+
Now in sunrise file you can perform attributes check.
|
161
175
|
By default permited_attributes allow edit all attributes.
|
162
176
|
|
163
177
|
```ruby
|
@@ -165,11 +179,11 @@ class SunrisePost < Sunrise::AbstractModel
|
|
165
179
|
self.resource_name = "Post"
|
166
180
|
edit do
|
167
181
|
# Default value
|
168
|
-
# permited_attributes :all
|
182
|
+
# permited_attributes :all
|
169
183
|
|
170
184
|
# Pre user check
|
171
|
-
permited_attributes lambda { |user|
|
172
|
-
user.admin? ? :all : [:title, :content]
|
185
|
+
permited_attributes lambda { |user|
|
186
|
+
user.admin? ? :all : [:title, :content]
|
173
187
|
}
|
174
188
|
end
|
175
189
|
end
|
@@ -201,4 +215,4 @@ config.to_prepare do
|
|
201
215
|
end
|
202
216
|
```
|
203
217
|
|
204
|
-
Copyright (c)
|
218
|
+
Copyright (c) 2025 Fodojo, released under the MIT license
|
data/Rakefile
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
//= link sunrise/application.css
|
@@ -0,0 +1,4 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
|
+
<svg id="i-export" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" fill="none" stroke="#000000" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
|
3
|
+
<path d="M28 22 L28 30 4 30 4 22 M16 4 L16 24 M8 12 L16 4 24 12" />
|
4
|
+
</svg>
|
@@ -1,11 +1,8 @@
|
|
1
|
-
//= require jquery
|
2
|
-
//= require
|
1
|
+
//= require jquery-ui/widgets/sortable
|
2
|
+
//= require jquery-ui/widgets/datepicker
|
3
3
|
|
4
|
-
//= require jquery-ui/sortable
|
5
|
-
//= require jquery-ui/datepicker
|
6
4
|
//= require datepicker/jquery.ui.datepicker-uk
|
7
5
|
//= require datepicker/jquery.ui.datepicker-ru
|
8
|
-
//= require select2
|
9
6
|
|
10
7
|
//= require sunrise/jquery.tmpl.min
|
11
8
|
//= require sunrise/jquery.cookie
|
@@ -7,130 +7,203 @@ $.fn.extend({
|
|
7
7
|
)
|
8
8
|
})
|
9
9
|
|
10
|
+
$.fn.extend({
|
11
|
+
import_dialog: (options) ->
|
12
|
+
$(this).each((input_field) ->
|
13
|
+
new ImportDialog(this, options) unless ($ this).hasClass "dialog-init"
|
14
|
+
)
|
15
|
+
})
|
16
|
+
|
10
17
|
class Dialog
|
11
|
-
constructor: (@form_field, options = {}) ->
|
18
|
+
constructor: (@form_field, options = {}) ->
|
12
19
|
defaults =
|
13
20
|
shadow_field: "#dark-shadow"
|
14
21
|
dialog_class: "sunrise-dialog"
|
15
|
-
|
22
|
+
|
16
23
|
@options = $.extend defaults, options
|
17
|
-
|
24
|
+
|
18
25
|
this.setup()
|
19
26
|
this.register_observers()
|
20
|
-
|
27
|
+
|
21
28
|
setup: ->
|
22
29
|
dom_id = this.generate_random_id()
|
23
30
|
@element = $ @form_field
|
24
|
-
|
31
|
+
|
25
32
|
@shadow = $ @options.shadow_field
|
26
33
|
@container = $ '<div/>', { id: dom_id, class: @options.dialog_class }
|
27
|
-
@container.hide()
|
34
|
+
@container.hide()
|
28
35
|
@shadow.after @container
|
29
|
-
|
36
|
+
|
30
37
|
@element.addClass "dialog-init"
|
31
|
-
|
38
|
+
|
32
39
|
register_observers: ->
|
33
40
|
@shadow.bind 'click', (evt) => this.hide()
|
34
|
-
@element.bind 'click', (evt) =>
|
41
|
+
@element.bind 'click', (evt) =>
|
35
42
|
this.show()
|
36
43
|
false
|
37
|
-
|
44
|
+
|
38
45
|
show: ->
|
39
46
|
wnd = $(window)
|
40
47
|
body = $('body')
|
41
|
-
|
48
|
+
|
42
49
|
height = if body.innerHeight() > wnd.innerHeight() then body.innerHeight() else wnd.innerHeight()
|
43
50
|
@shadow.css 'height', height + 'px'
|
44
51
|
@container.css 'left', ($(window).innerWidth() - @container.innerWidth()) / 2 + 'px'
|
45
|
-
|
52
|
+
|
46
53
|
@shadow.show()
|
47
54
|
@container.show()
|
48
|
-
|
55
|
+
|
49
56
|
hide: ->
|
50
57
|
@shadow.hide()
|
51
58
|
@container.hide()
|
52
|
-
|
59
|
+
|
53
60
|
generate_random_id: ->
|
54
61
|
string = "dlg_" + this.generate_random_char() + this.generate_random_char() + this.generate_random_char()
|
55
62
|
while $("#" + string).length > 0
|
56
63
|
string += this.generate_random_char()
|
57
64
|
string
|
58
|
-
|
65
|
+
|
59
66
|
generate_random_char: ->
|
60
67
|
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"
|
61
68
|
rand = Math.floor(Math.random() * chars.length)
|
62
69
|
newchar = chars.substring rand, rand+1
|
63
|
-
|
64
|
-
|
70
|
+
|
71
|
+
# SORT
|
65
72
|
class SortDialog extends Dialog
|
66
|
-
|
73
|
+
|
67
74
|
setup: ->
|
68
75
|
super
|
69
|
-
|
76
|
+
|
70
77
|
@container.addClass 'sort-wrapper'
|
71
|
-
|
78
|
+
|
72
79
|
title = $('<div/>', { class: 'sort-title' })
|
73
80
|
title.text(@element.attr 'title')
|
74
|
-
|
81
|
+
|
75
82
|
buttons_holder = $ '<div/>', { class: 'sort-buts-holder' }
|
76
83
|
@save_button = $ '<input/>', { type: 'submit', value: @element.data('save_title'), class: 'button', disabled: 'disabled'}
|
77
84
|
@cancel_button = $ '<input/>', { type: 'submit', value: @element.data('cancel_title'), class: 'button gray'}
|
78
|
-
|
85
|
+
|
79
86
|
buttons_holder.append(@save_button).append(@cancel_button)
|
80
87
|
title_holder = $ '<div/>', { class: 'sort-title-holder' }
|
81
88
|
title_holder.append(title).append(buttons_holder)
|
82
|
-
|
89
|
+
|
83
90
|
items_container = $ '<div/>', { class: 'sort-items-holder', id: 'sort_items' }
|
84
|
-
|
91
|
+
|
85
92
|
@container.append(title_holder).append(items_container)
|
86
|
-
|
93
|
+
|
87
94
|
register_observers: ->
|
88
95
|
super
|
89
|
-
|
96
|
+
|
90
97
|
@cancel_button.bind 'click', (evt) => this.hide()
|
91
98
|
@save_button.bind 'click', (evt) => this.save(evt)
|
92
|
-
|
99
|
+
|
93
100
|
show: ->
|
94
101
|
super
|
95
|
-
this.load_data()
|
96
|
-
|
102
|
+
this.load_data()
|
103
|
+
|
97
104
|
save: ->
|
98
105
|
items = {}
|
99
106
|
klass = this
|
100
|
-
|
107
|
+
|
101
108
|
$('.sort-item').each (index) ->
|
102
109
|
items['ids[' + $(this).data('record-id') + ']'] = index + 1
|
103
|
-
|
110
|
+
|
104
111
|
$.rails.ajax
|
105
112
|
url: @element.data 'url'
|
106
113
|
type: 'POST'
|
107
114
|
data: items
|
108
115
|
success: ->
|
109
116
|
klass.hide()
|
110
|
-
|
117
|
+
|
111
118
|
load_data: ->
|
112
119
|
klass = this
|
113
|
-
|
120
|
+
|
114
121
|
$.ajax
|
115
122
|
url: @element.attr 'href'
|
116
123
|
success: (data, status, xhr) ->
|
117
124
|
$('#sort_items').empty()
|
118
125
|
$("#sort-template" ).tmpl(data).appendTo('#sort_items')
|
119
126
|
# klass.refresh_counters()
|
120
|
-
|
127
|
+
|
121
128
|
$("#sort_items").sortable
|
122
129
|
cursor: 'crosshair'
|
123
130
|
opacity: 0.6
|
124
|
-
update: (event, ui) ->
|
131
|
+
update: (event, ui) ->
|
125
132
|
klass.update_sort_item(event, ui)
|
126
|
-
|
133
|
+
|
127
134
|
refresh_counters: ->
|
128
135
|
$('.sort-item .numb').each (index) ->
|
129
136
|
$(this).text index + 1
|
130
|
-
|
137
|
+
|
131
138
|
update_sort_item: (event, ui) ->
|
132
139
|
@save_button.attr 'disabled', false
|
133
140
|
this.refresh_counters()
|
134
|
-
|
135
|
-
|
136
|
-
|
141
|
+
|
142
|
+
# IMPORT
|
143
|
+
class ImportDialog extends Dialog
|
144
|
+
setup: ->
|
145
|
+
super
|
146
|
+
|
147
|
+
@container.addClass 'import-wrapper'
|
148
|
+
|
149
|
+
title = $('<div/>', { class: 'import-title' })
|
150
|
+
title.text(@element.data('title'))
|
151
|
+
|
152
|
+
@upload_input = $('<input />', { type: 'file', class: 'import-fileupload' })
|
153
|
+
@records_list = $('<ul/>')
|
154
|
+
|
155
|
+
@upload_input.fileupload
|
156
|
+
url: @element.data('url')
|
157
|
+
dataType: 'json'
|
158
|
+
autoUpload: true
|
159
|
+
uploadTemplateId: false
|
160
|
+
downloadTemplateId: false
|
161
|
+
done: (e, data) =>
|
162
|
+
$.each data.result.files, (findex, file) =>
|
163
|
+
$.each file.records, (rindex, record) =>
|
164
|
+
line = $('<li>')
|
165
|
+
|
166
|
+
if record?.html?
|
167
|
+
line.append(record.html)
|
168
|
+
else
|
169
|
+
if record.errors?.length > 0
|
170
|
+
rrr = $.extend({}, record)
|
171
|
+
delete(rrr.row)
|
172
|
+
delete(rrr.errors)
|
173
|
+
line.addClass('import-invalid-error')
|
174
|
+
line.append($("<b>ROW: #{record.row}</b>"))
|
175
|
+
line.append($('<br/>')).append(JSON.stringify(rrr)).append($('<br/>'))
|
176
|
+
line.append(record.errors.join('<br/>'))
|
177
|
+
else
|
178
|
+
line.append($("<b>ROW: #{record.row}</b>"))
|
179
|
+
line.append($('<br/>'))
|
180
|
+
line.append JSON.stringify(record)
|
181
|
+
|
182
|
+
@records_list.append(line)
|
183
|
+
|
184
|
+
@container.addClass('disabled')
|
185
|
+
$("#records").load "#{location.pathname} #records", =>
|
186
|
+
@container.removeClass('disabled')
|
187
|
+
|
188
|
+
buttons_holder = $ '<div/>', { class: 'import-buts-holder' }
|
189
|
+
@close_button = $ '<input/>', { type: 'reset', value: 'Close', class: 'button gray'}
|
190
|
+
|
191
|
+
buttons_holder.append(@save_button).append(@close_button)
|
192
|
+
title_holder = $ '<div/>', { class: 'import-title-holder' }
|
193
|
+
title_holder.append(title).append(@upload_input).append(buttons_holder)
|
194
|
+
|
195
|
+
items_container = $ '<div/>', { class: 'import-items-holder', id: 'import_items' }
|
196
|
+
items_container.append(@records_list)
|
197
|
+
|
198
|
+
@container.append(title_holder).append(items_container)
|
199
|
+
|
200
|
+
register_observers: ->
|
201
|
+
super
|
202
|
+
|
203
|
+
@close_button.bind 'click', (evt) =>
|
204
|
+
# this.hide()
|
205
|
+
# location?.reload?()
|
206
|
+
# @records_list.empty()
|
207
|
+
this.hide()
|
208
|
+
@records_list.empty()
|
209
|
+
|
@@ -9,67 +9,67 @@ class Editable
|
|
9
9
|
constructor: (@fields, options = {}) ->
|
10
10
|
this.setup()
|
11
11
|
this.register_observers()
|
12
|
-
|
12
|
+
|
13
13
|
setup: ->
|
14
14
|
@elements = $ @fields
|
15
15
|
@delete_button = @elements.filter('[data-editable=destroy]').first()
|
16
16
|
@edit_button = @elements.filter('[data-editable=edit]').first()
|
17
|
-
|
18
|
-
register_observers: ->
|
17
|
+
|
18
|
+
register_observers: ->
|
19
19
|
@elements.bind 'click', (evt) =>
|
20
20
|
element = $(evt.target)
|
21
|
-
|
21
|
+
|
22
22
|
unless element.hasClass('disabled')
|
23
23
|
switch element.data('editable')
|
24
24
|
when 'destroy' then this.destroy(element)
|
25
25
|
when 'edit' then this.edit(element)
|
26
26
|
false
|
27
|
-
|
27
|
+
|
28
28
|
$('.check-block input').bind 'change', (evt) =>
|
29
29
|
this.check_buttons()
|
30
|
-
|
30
|
+
|
31
31
|
$('.but-holder .check input').bind 'change', (evt) =>
|
32
32
|
$('.check-block input').prop("checked", $(evt.target).prop("checked"))
|
33
33
|
this.check_buttons()
|
34
|
-
|
34
|
+
|
35
35
|
check_buttons: ->
|
36
|
-
count = $('.check-block input:checked').
|
37
|
-
|
36
|
+
count = $('.check-block input:checked').length
|
37
|
+
|
38
38
|
this.toggle_button count > 0, @delete_button
|
39
39
|
this.toggle_button count == 1, @edit_button
|
40
|
-
|
40
|
+
|
41
41
|
toggle_button: (condition, button) ->
|
42
42
|
if condition then button.removeClass('disabled') else button.addClass('disabled')
|
43
|
-
|
43
|
+
|
44
44
|
destroy: (element) ->
|
45
45
|
if this.allowAction(@delete_button)
|
46
46
|
this.handleMethod(element, 'delete')
|
47
|
-
|
47
|
+
|
48
48
|
edit: (element) ->
|
49
49
|
item = $('.check-block input:checked').first()
|
50
50
|
location = element.attr('href').replace('0', item.val())
|
51
51
|
window.location = location
|
52
|
-
|
52
|
+
|
53
53
|
allowAction: (element) ->
|
54
|
-
message = element.data('confirm-message')
|
54
|
+
message = element.data('confirm-message') || element.data('confirm')
|
55
55
|
answer = false
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
callback = undefined
|
57
|
+
|
58
|
+
return true unless message
|
59
59
|
|
60
|
-
if $.rails.fire(element, 'confirm')
|
60
|
+
if $.rails.fire(element, 'confirm')
|
61
61
|
answer = $.rails.confirm(message)
|
62
62
|
callback = $.rails.fire(element, 'confirm:complete', [answer])
|
63
|
-
|
63
|
+
|
64
64
|
answer && callback
|
65
|
-
|
65
|
+
|
66
66
|
handleMethod: (link, method) ->
|
67
67
|
href = link.attr('href')
|
68
68
|
csrf_token = $('meta[name=csrf-token]').attr('content')
|
69
69
|
csrf_param = $('meta[name=csrf-param]').attr('content')
|
70
70
|
form = $('<form method="post" action="' + href + '"></form>')
|
71
71
|
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />'
|
72
|
-
|
72
|
+
|
73
73
|
$('.check-block input:checked').each (index, element) ->
|
74
74
|
metadata_input += '<input name="ids[]" value="' + $(element).val() + '" type="hidden" />'
|
75
75
|
|