alchemy-custom-model 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/alchemy-custom-model/manifest.js +1 -0
- data/app/assets/javascripts/alchemy-custom-model/sortable.js +30 -0
- data/app/assets/stylesheets/alchemy-custom-model/custom_style.css.scss +50 -0
- data/app/controllers/alchemy/custom/model/admin/base_controller.rb +24 -5
- data/app/controllers/alchemy/custom/model/admin/clones_controller.rb +54 -0
- data/app/controllers/alchemy/custom/model/admin/orders_controller.rb +22 -0
- data/app/helpers/alchemy/custom/model/admin/base_helper.rb +76 -31
- data/app/helpers/alchemy/custom/model/admin/orders_helper.rb +35 -0
- data/app/helpers/alchemy/custom/model/base_helper.rb +5 -0
- data/app/models/alchemy/custom/model/cloner.rb +45 -0
- data/app/views/alchemy/custom/model/admin/base/_buttons_tool.html.erb +10 -1
- data/app/views/alchemy/custom/model/admin/base/index.html.erb +31 -12
- data/app/views/alchemy/custom/model/admin/base/show.html.erb +48 -0
- data/app/views/alchemy/custom/model/admin/clones/new.html.erb +40 -0
- data/app/views/alchemy/custom/model/admin/orders/new.html.erb +32 -0
- data/lib/alchemy/custom/model/engine.rb +1 -0
- data/lib/alchemy/custom/model/errors/error.rb +6 -0
- data/lib/alchemy/custom/model/errors/parent_nil.rb +11 -0
- data/lib/alchemy/custom/model/order.rb +81 -0
- data/lib/alchemy/custom/model/version.rb +1 -1
- metadata +27 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f638f957066f638fc5debf6216b2d487e9d6eee
|
4
|
+
data.tar.gz: fc4d11eab34b963283211d2b6bb775a37cfef60a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee347920f19d72c212cd185de4f0cdd4dc5911213bb3c889e532decf875ba7794aefc23af270dd8729046862fd843c447d24f01ed238ce4165ce4f925aef1d8a
|
7
|
+
data.tar.gz: fc359cca2a93af2afcc32efcad5699cc346f7fe3059b21da82609783b386c995b0a165538e486818a14456f123395be23fdb3f6b0456690f233a2bf018f428e4
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
$(document).on("turbolinks:load",function () {
|
3
|
+
|
4
|
+
$('.sortable_tree').nestedSortable({
|
5
|
+
handle: 'div',
|
6
|
+
items: 'li',
|
7
|
+
cursor: 'pointer',
|
8
|
+
scroll: true,
|
9
|
+
toleranceElement: '> div',
|
10
|
+
maxLevels: 1
|
11
|
+
});
|
12
|
+
|
13
|
+
$("#save_order").click(function(){
|
14
|
+
|
15
|
+
var array_positions = $('#sort_tree').nestedSortable("toHierarchy");
|
16
|
+
var url = $('#save_order').data("url-update");
|
17
|
+
|
18
|
+
$.ajax({
|
19
|
+
url: url,
|
20
|
+
contentType: "application/json;charset=utf-8",
|
21
|
+
data: JSON.stringify({ordered_data: array_positions}),
|
22
|
+
method: "PUT"
|
23
|
+
|
24
|
+
})
|
25
|
+
|
26
|
+
|
27
|
+
});
|
28
|
+
|
29
|
+
|
30
|
+
});
|
@@ -226,3 +226,53 @@
|
|
226
226
|
}
|
227
227
|
}
|
228
228
|
|
229
|
+
.order_tree{
|
230
|
+
|
231
|
+
&.margined {
|
232
|
+
padding-top: 100px;
|
233
|
+
}
|
234
|
+
|
235
|
+
.el_block{
|
236
|
+
|
237
|
+
height: 32px;
|
238
|
+
margin: 12px 0;
|
239
|
+
position: relative;
|
240
|
+
transition: background-color 250ms;
|
241
|
+
|
242
|
+
&:hover {
|
243
|
+
background-color: rgba(251, 251, 216, 0.5);
|
244
|
+
border-radius: 3px;
|
245
|
+
}
|
246
|
+
|
247
|
+
.icon {
|
248
|
+
position: relative;
|
249
|
+
width: 32px;
|
250
|
+
line-height: 32px;
|
251
|
+
float: left;
|
252
|
+
padding: 0 8px;
|
253
|
+
text-align: center;
|
254
|
+
}
|
255
|
+
|
256
|
+
.el_value {
|
257
|
+
border-bottom-left-radius: 3px;
|
258
|
+
border-top-left-radius: 3px;
|
259
|
+
line-height: 28px;
|
260
|
+
overflow: hidden;
|
261
|
+
background-color: rgba(255, 255, 255, 0.75);
|
262
|
+
|
263
|
+
.el_title {
|
264
|
+
display: block;
|
265
|
+
padding: 0 10px;
|
266
|
+
margin: 2px;
|
267
|
+
text-decoration: none;
|
268
|
+
}
|
269
|
+
|
270
|
+
&.disabled {
|
271
|
+
background-color: #efefef;
|
272
|
+
}
|
273
|
+
}
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
}
|
278
|
+
|
@@ -2,6 +2,8 @@ module Alchemy::Custom::Model
|
|
2
2
|
module Admin
|
3
3
|
class BaseController < Alchemy::Custom::Model.admin_controller_class
|
4
4
|
|
5
|
+
class_attribute :method_for_show, instance_accessor: false
|
6
|
+
|
5
7
|
before_action :authorize_resource
|
6
8
|
before_action :clean_slug, only: [:create, :update]
|
7
9
|
before_action :set_language, unless: -> {params[:language_id].nil?}
|
@@ -58,6 +60,20 @@ module Alchemy::Custom::Model
|
|
58
60
|
|
59
61
|
end
|
60
62
|
|
63
|
+
def show
|
64
|
+
if @obj.respond_to? self.class.method_for_show
|
65
|
+
@objects = @obj.send(self.class.method_for_show.to_sym)
|
66
|
+
@objects = @objects.accessible_by(current_ability)
|
67
|
+
@objects = @objects.page(params[:page]).
|
68
|
+
per(params[:per_page] ||
|
69
|
+
(base_class::DEFAULT_PER_PAGE if base_class.const_defined? :DEFAULT_PER_PAGE) ||
|
70
|
+
25)
|
71
|
+
instance_variable_set "@#{self.class.method_for_show.to_s.underscore.downcase.pluralize}", @objects
|
72
|
+
else
|
73
|
+
@objects = base_class.none
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
61
77
|
|
62
78
|
class << self
|
63
79
|
|
@@ -95,7 +111,7 @@ module Alchemy::Custom::Model
|
|
95
111
|
raise '-- Override Method base_class'
|
96
112
|
end
|
97
113
|
|
98
|
-
def url_namespace(obj=base_class)
|
114
|
+
def url_namespace(obj = base_class)
|
99
115
|
[:admin, obj]
|
100
116
|
end
|
101
117
|
|
@@ -170,11 +186,13 @@ module Alchemy::Custom::Model
|
|
170
186
|
|
171
187
|
|
172
188
|
def load_parent
|
173
|
-
|
174
|
-
|
175
|
-
|
189
|
+
if params["#{parent_model_name_demodulized}_id"]
|
190
|
+
unless self.class.parent_model_name.blank?
|
191
|
+
@parent = self.class.parent_klass.
|
192
|
+
find_by("#{self.class.parent_find_method.to_s}": params["#{parent_model_name_demodulized}_id"])
|
176
193
|
|
177
|
-
|
194
|
+
instance_variable_set("@#{parent_model_name_demodulized}", @parent)
|
195
|
+
end
|
178
196
|
end
|
179
197
|
end
|
180
198
|
|
@@ -184,6 +202,7 @@ module Alchemy::Custom::Model
|
|
184
202
|
end
|
185
203
|
|
186
204
|
|
205
|
+
|
187
206
|
end
|
188
207
|
end
|
189
208
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Alchemy
|
2
|
+
module Custom
|
3
|
+
module Model
|
4
|
+
module Admin
|
5
|
+
class ClonesController < BaseController
|
6
|
+
def create
|
7
|
+
@obj.assign_attributes clean_params
|
8
|
+
if @parent.present? and @obj.respond_to?("#{parent_model_name_demodulized}=".to_sym)
|
9
|
+
@obj.send "#{parent_model_name_demodulized}=", @parent
|
10
|
+
end
|
11
|
+
@obj = yield @obj if block_given?
|
12
|
+
if @obj.apply
|
13
|
+
after_successfull_create
|
14
|
+
else
|
15
|
+
after_unsuccessfully_create
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def authorize_resource
|
22
|
+
authorize!(:clone, @parent.class)
|
23
|
+
end
|
24
|
+
|
25
|
+
def base_class
|
26
|
+
"::#{parent_model_name_demodulized.classify}Cloner".constantize
|
27
|
+
end
|
28
|
+
|
29
|
+
def after_successfull_create
|
30
|
+
url = polymorphic_path [:admin, @parent.class]
|
31
|
+
flash[:notice] = t(:record_succesfully_cloned, model: @parent.class.model_name.human)
|
32
|
+
respond_to do |format|
|
33
|
+
format.js {
|
34
|
+
@redirect_url = url
|
35
|
+
render :redirect
|
36
|
+
}
|
37
|
+
format.html {redirect_to url}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def after_unsuccessfully_create
|
42
|
+
render :new
|
43
|
+
end
|
44
|
+
|
45
|
+
def permitted_attributes
|
46
|
+
base_class._virtual_column_names.collect(&:to_sym)
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Alchemy::Custom::Model
|
2
|
+
module Admin
|
3
|
+
class OrdersController < Alchemy::Custom::Model::Admin::BaseController
|
4
|
+
|
5
|
+
|
6
|
+
skip_before_action :load_object
|
7
|
+
skip_before_action :clean_slug
|
8
|
+
|
9
|
+
include Alchemy::Custom::Model::Order
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def url_namespace
|
14
|
+
[:admin,base_class.to_s.underscore.pluralize, :order]
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -61,10 +61,10 @@ module Alchemy::Custom::Model::Admin::BaseHelper
|
|
61
61
|
bf2 << link_to("#", class: 'open_el_finder',
|
62
62
|
title: t("elfinder.edit_image_button"),
|
63
63
|
data: {
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
"elfinder-mode": 'single_selection',
|
65
|
+
"elfinder-target": "##{component_id}",
|
66
|
+
"elfinder-thumb-target": "##{component_id_image}",
|
67
|
+
"elfinder-volumes": 'AlchemyImages'
|
68
68
|
}) do
|
69
69
|
fa_icon("file-image")
|
70
70
|
end
|
@@ -72,9 +72,9 @@ module Alchemy::Custom::Model::Admin::BaseHelper
|
|
72
72
|
bf2 << link_to("#", class: 'clear_selection',
|
73
73
|
title: t("elfinder.clear_image_button"),
|
74
74
|
data: {
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
"clearfield-target": "##{component_id}",
|
76
|
+
"clearfield-thumb-target": "##{component_id_image}",
|
77
|
+
"clearfield-thumb-target-replace": no_image_path
|
78
78
|
}) do
|
79
79
|
fa_icon("times")
|
80
80
|
end
|
@@ -142,10 +142,10 @@ module Alchemy::Custom::Model::Admin::BaseHelper
|
|
142
142
|
bf2 << link_to("#", class: 'open_el_finder',
|
143
143
|
title: t("elfinder.edit_attachment_button"),
|
144
144
|
data: {
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
145
|
+
"elfinder-mode": 'single_selection',
|
146
|
+
"elfinder-target": "##{component_id}",
|
147
|
+
"elfinder-mime_icon_updater": "##{id_icone}",
|
148
|
+
"elfinder-volumes": 'AlchemyFiles'
|
149
149
|
}) do
|
150
150
|
fa_icon("file")
|
151
151
|
end
|
@@ -153,8 +153,8 @@ module Alchemy::Custom::Model::Admin::BaseHelper
|
|
153
153
|
bf2 << link_to("#", class: 'clear_selection',
|
154
154
|
title: t("elfinder.clear_attachment_button"),
|
155
155
|
data: {
|
156
|
-
|
157
|
-
|
156
|
+
"clearfield-target": "##{component_id}",
|
157
|
+
"clearfield-icon": "##{id_icone}"
|
158
158
|
}) do
|
159
159
|
fa_icon("times")
|
160
160
|
end
|
@@ -180,7 +180,6 @@ module Alchemy::Custom::Model::Admin::BaseHelper
|
|
180
180
|
end
|
181
181
|
|
182
182
|
|
183
|
-
|
184
183
|
##
|
185
184
|
# Costruisce il necessario per la generazione della struttura della gallery e per selezione ed upload immagini
|
186
185
|
#
|
@@ -224,19 +223,19 @@ module Alchemy::Custom::Model::Admin::BaseHelper
|
|
224
223
|
|
225
224
|
bf << content_tag(:div, class: 'gallery_item_blk') do
|
226
225
|
link_to("#", class: 'open_el_finder', data: {
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
226
|
+
"elfinder-mode": 'multiple_selection',
|
227
|
+
"elfinder-target_upgrader": partial_url,
|
228
|
+
"elfinder-target": partial_identifier,
|
229
|
+
"elfinder-volumes": 'AlchemyImages,GalleryVolume',
|
230
|
+
"elfinder-volumes_cfgs": Base64.strict_encode64({
|
231
|
+
"GalleryVolume": {
|
232
|
+
volume: 'ComponentAttribute',
|
233
|
+
attribute: field,
|
234
|
+
object: form.object.to_signed_global_id.to_s,
|
235
|
+
file_link_ref: 'picture',
|
236
|
+
tags: tags
|
237
|
+
}
|
238
|
+
}.to_json)
|
240
239
|
}) do
|
241
240
|
fa_icon("images")
|
242
241
|
end
|
@@ -366,14 +365,60 @@ module Alchemy::Custom::Model::Admin::BaseHelper
|
|
366
365
|
end
|
367
366
|
|
368
367
|
|
369
|
-
def check_presence_polymorphic_path(record_or_hash_or_array, options = {})
|
368
|
+
def check_presence_polymorphic_path(record_or_hash_or_array, method = :get, options = {})
|
370
369
|
begin
|
371
|
-
polymorphic_path record_or_hash_or_array, options
|
372
|
-
|
373
|
-
|
370
|
+
url = polymorphic_path record_or_hash_or_array, options
|
371
|
+
route_hash = Rails.application.routes.recognize_path(url, :method => method)
|
372
|
+
if route_hash[:controller] != "alchemy/pages"
|
373
|
+
true
|
374
|
+
else
|
375
|
+
false
|
376
|
+
end
|
377
|
+
rescue NoMethodError, ActionController::RoutingError
|
374
378
|
false
|
375
379
|
end
|
376
380
|
end
|
377
381
|
|
378
382
|
|
383
|
+
def order_path(obj = nil, options = {})
|
384
|
+
if obj.nil?
|
385
|
+
new_polymorphic_path([:admin, base_class.to_s.pluralize.underscore, :order])
|
386
|
+
else
|
387
|
+
new_polymorphic_path([:admin, obj, :order])
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
def exist_order_path?(obj = nil)
|
392
|
+
if obj.nil?
|
393
|
+
order_path
|
394
|
+
else
|
395
|
+
order_path obj
|
396
|
+
end
|
397
|
+
true
|
398
|
+
rescue NoMethodError
|
399
|
+
false
|
400
|
+
end
|
401
|
+
|
402
|
+
def print_order_tree(sort: false)
|
403
|
+
sortable_class = "sortable_tree" if sort
|
404
|
+
content_tag(:ol, class: "order_tree margined #{sortable_class}", id: "sort_tree") do
|
405
|
+
el_buf = ActiveSupport::SafeBuffer.new
|
406
|
+
@elements.each do |el|
|
407
|
+
el_buf << content_tag(:li, id: print_order_identify(el)) do
|
408
|
+
sb = ActiveSupport::SafeBuffer.new
|
409
|
+
sb << content_tag(:div, class: "el_block") do
|
410
|
+
div = ActiveSupport::SafeBuffer.new
|
411
|
+
div << print_sort_icon(el)
|
412
|
+
div << content_tag(:div, class: "el_value") do
|
413
|
+
printelement_to_order el
|
414
|
+
end
|
415
|
+
end
|
416
|
+
sb
|
417
|
+
end
|
418
|
+
end
|
419
|
+
el_buf
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
|
379
424
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Alchemy::Custom::Model::Admin::OrdersHelper
|
2
|
+
def order_path(options = {})
|
3
|
+
new_polymorphic_path([:admin, base_class.to_s.pluralize.underscore, :order], options)
|
4
|
+
end
|
5
|
+
|
6
|
+
def index_ordered_path(obj = nil, options = {})
|
7
|
+
if obj.nil?
|
8
|
+
polymorphic_path([:admin, base_class], options)
|
9
|
+
else
|
10
|
+
polymorphic_path([:admin, obj], options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def update_order_path(options = {})
|
15
|
+
polymorphic_path([:admin, base_class.to_s.pluralize.underscore, :order], options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def print_order_identify(el)
|
19
|
+
"el_#{el.id}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def printelement_to_orderr(el)
|
23
|
+
content_tag(:span, class: "el_title name") do
|
24
|
+
el.name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def print_sort_icon(el)
|
29
|
+
content_tag(:span, class: "icon") do
|
30
|
+
content_tag(:i, nil, {class: "fa fa-arrow-right"})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Alchemy
|
2
|
+
module Custom
|
3
|
+
module Model
|
4
|
+
class Cloner < ActiveType::Object
|
5
|
+
|
6
|
+
attribute :language_id, :integer
|
7
|
+
attribute :site_id, :integer
|
8
|
+
|
9
|
+
validates :language_id, :site_id, presence: true
|
10
|
+
validate :check_lang_in_site, unless: -> {site_id.blank?}
|
11
|
+
|
12
|
+
|
13
|
+
###
|
14
|
+
# ritorna true se il clone è andato a buon fine false altrimenti
|
15
|
+
def apply
|
16
|
+
if valid?
|
17
|
+
cloned = self.category.clone_to_other_lang self.attributes.with_indifferent_access
|
18
|
+
if cloned.valid?
|
19
|
+
true
|
20
|
+
else
|
21
|
+
cloned.errors.full_messages.each do | error|
|
22
|
+
self.errors.add(:base, error)
|
23
|
+
end
|
24
|
+
false
|
25
|
+
end
|
26
|
+
else
|
27
|
+
false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
protected
|
34
|
+
|
35
|
+
def check_lang_in_site
|
36
|
+
site = Alchemy::Site.find self.site_id
|
37
|
+
if !site.languages.pluck(:id).include? self.language_id
|
38
|
+
errors.add(:language_id, :isnt_in_site)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,16 +1,25 @@
|
|
1
|
+
<% obj = local_assigns.fetch(:obj) %>
|
2
|
+
<% if check_presence_polymorphic_path(url_namespace(obj), :get) and can?(:show, base_class) %>
|
3
|
+
<%= link_to fa_icon("eye"), polymorphic_path(url_namespace(obj)),
|
4
|
+
title: t(:show, model: base_class.model_name.human),
|
5
|
+
class: "show" %>
|
6
|
+
<% end %>
|
7
|
+
|
1
8
|
<% if can?(:edit, base_class) %>
|
2
9
|
<%= link_to fa_icon("edit"), edit_polymorphic_path(url_namespace(obj)),
|
3
10
|
title: t(:edit),
|
4
11
|
class: "edit" %>
|
5
12
|
<% end %>
|
6
13
|
|
7
|
-
<% if check_presence_polymorphic_path(url_namespace(obj)+[:clone], action: :new) and can?(:clones, base_class) %>
|
14
|
+
<% if check_presence_polymorphic_path(url_namespace(obj)+[:clone], :get, action: :new) and can?(:clones, base_class) %>
|
8
15
|
<%= link_to_dialog fa_icon("clone"), new_polymorphic_path(url_namespace(obj)+[:clone]),
|
9
16
|
title: t(:clone, model: base_class.model_name.human),
|
10
17
|
class: "clone" %>
|
11
18
|
<% end %>
|
12
19
|
|
13
20
|
|
21
|
+
|
22
|
+
|
14
23
|
<% if can?(:destroy, base_class) %>
|
15
24
|
<%= delete_button polymorphic_path(url_namespace(obj)), icon: "trash" %>
|
16
25
|
<% end %>
|
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
<% content_for(:toolbar) do %>
|
2
3
|
<%= render 'alchemy/admin/partials/site_select' %>
|
3
4
|
<%= render 'language_tree_select' %>
|
@@ -5,19 +6,37 @@
|
|
5
6
|
<%= render partial: 'search_box', locals: {url: polymorphic_path(url_namespace), base_class: base_class} %>
|
6
7
|
<% end %>
|
7
8
|
|
9
|
+
|
10
|
+
<%
|
11
|
+
buttons = []
|
12
|
+
|
13
|
+
buttons << {
|
14
|
+
icon: :plus,
|
15
|
+
label: acm_t(:title_action, action: acm_t(:new, scope: :actions), model: base_class.model_name.human),
|
16
|
+
url: new_polymorphic_path(url_namespace),
|
17
|
+
title: acm_t(:title_action, action: acm_t(:new, scope: :actions), model: base_class.model_name.human),
|
18
|
+
hotkey: 'alt+n',
|
19
|
+
dialog: false,
|
20
|
+
if_permitted_to: [:create, base_class]
|
21
|
+
}
|
22
|
+
|
23
|
+
if exist_order_path?
|
24
|
+
buttons << {
|
25
|
+
icon: :random,
|
26
|
+
label: acm_t(:title_action, action: acm_t(:order, scope: :actions), model: base_class.model_name.human),
|
27
|
+
url: order_path,
|
28
|
+
title: acm_t(:title_action, action: acm_t(:order, scope: :actions), model: base_class.model_name.human),
|
29
|
+
hotkey: 'alt+n',
|
30
|
+
dialog: false,
|
31
|
+
if_permitted_to: [:order, base_class]
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
%>
|
36
|
+
|
8
37
|
<% toolbar(
|
9
|
-
|
10
|
-
|
11
|
-
icon: :plus,
|
12
|
-
label: acm_t(:title_action, action: acm_t(:new, scope: :actions), model: base_class.model_name.human),
|
13
|
-
url: new_polymorphic_path(url_namespace),
|
14
|
-
title: acm_t(:title_action, action: acm_t(:new, scope: :actions), model: base_class.model_name.human),
|
15
|
-
hotkey: 'alt+n',
|
16
|
-
dialog: false,
|
17
|
-
if_permitted_to: [:create, base_class]
|
18
|
-
}
|
19
|
-
],
|
20
|
-
search: false,
|
38
|
+
buttons: buttons,
|
39
|
+
search: false,
|
21
40
|
) %>
|
22
41
|
|
23
42
|
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<%
|
2
|
+
buttons = []
|
3
|
+
|
4
|
+
buttons << {
|
5
|
+
icon: "angle-double-left ",
|
6
|
+
label: acm_t(:title_action, action: t(:index, scope: :actions), model: base_class.model_name.human),
|
7
|
+
url: polymorphic_path(url_namespace),
|
8
|
+
title: acm_t(:title_action, action: t(:index, scope: :actions), model: base_class.model_name.human),
|
9
|
+
hotkey: 'alt+b',
|
10
|
+
dialog: false,
|
11
|
+
if_permitted_to: [:index, @obj.class]
|
12
|
+
}
|
13
|
+
|
14
|
+
if exist_order_path? @obj
|
15
|
+
buttons << {
|
16
|
+
icon: :random,
|
17
|
+
label: acm_t(:title_action, action: acm_t(:order, scope: :actions), model: base_class.model_name.human),
|
18
|
+
url: order_path(@obj),
|
19
|
+
title: acm_t(:title_action, action: acm_t(:order, scope: :actions), model: base_class.model_name.human),
|
20
|
+
hotkey: 'alt+n',
|
21
|
+
dialog: false,
|
22
|
+
if_permitted_to: [:order, base_class]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
%>
|
27
|
+
|
28
|
+
|
29
|
+
<% toolbar(
|
30
|
+
buttons: buttons,
|
31
|
+
search: false
|
32
|
+
) %>
|
33
|
+
|
34
|
+
|
35
|
+
<%= base_container do %>
|
36
|
+
|
37
|
+
<div id="archive_all" class="resources-table-wrapper">
|
38
|
+
|
39
|
+
<%= content_tag :h1, "#{@objects.count} #{base_class.model_name.human(count: @objects.count)}", class: 'resources-header' %>
|
40
|
+
|
41
|
+
|
42
|
+
<%= render partial: "table" %>
|
43
|
+
|
44
|
+
<%= paginate @objects, theme: 'alchemy', hide_per_page_select: true %>
|
45
|
+
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<% end %>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<div class="base-errors">
|
2
|
+
<% @obj.errors[:base].each do |err| %>
|
3
|
+
<%= err %>
|
4
|
+
<br>
|
5
|
+
<% end %>
|
6
|
+
</div>
|
7
|
+
|
8
|
+
<%= simple_form_for @obj, url: polymorphic_path([:admin, @parent, :clone]),
|
9
|
+
method: :post, remote: true, html: {class: "form_cloner"} do |f| %>
|
10
|
+
|
11
|
+
<%= f.input :site_id, as: :select, collection: sites_for_select,
|
12
|
+
input_html: {id: "select_site_clone", class: "alchemy_selectbox"} %>
|
13
|
+
|
14
|
+
<%= f.input :language_id, as: :select,
|
15
|
+
collection: Alchemy::Language.all.
|
16
|
+
map {|l| [l.name, l.id, {data: {site_id: l.site.id}}]},
|
17
|
+
input_html: {id: "select_language_clone", class: "alchemy_selectbox"} %>
|
18
|
+
|
19
|
+
|
20
|
+
<div class="submit">
|
21
|
+
<%= f.submit t(:clone, model: @parent.class.model_name.human) %>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
|
25
|
+
<% end %>
|
26
|
+
|
27
|
+
<script type="text/javascript">
|
28
|
+
|
29
|
+
|
30
|
+
$("#select_site_clone").select2filter({
|
31
|
+
elementToFilter: "#select_language_clone",
|
32
|
+
hideparam: "site-id"
|
33
|
+
});
|
34
|
+
|
35
|
+
$("#select_language_clone").select2filter({
|
36
|
+
elementToFilter: "#select_category_clone",
|
37
|
+
hideparam: "language-id"
|
38
|
+
});
|
39
|
+
|
40
|
+
</script>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<% toolbar(
|
2
|
+
buttons: [
|
3
|
+
{
|
4
|
+
icon: "angle-double-left ",
|
5
|
+
label: t(:show_all),
|
6
|
+
url: index_ordered_path(@obj),
|
7
|
+
title: t(:show_all),
|
8
|
+
hotkey: 'alt+b',
|
9
|
+
dialog: false,
|
10
|
+
if_permitted_to: [:index, parent_klass]
|
11
|
+
}
|
12
|
+
|
13
|
+
],
|
14
|
+
search: false
|
15
|
+
) %>
|
16
|
+
|
17
|
+
|
18
|
+
<%= base_form_container do %>
|
19
|
+
|
20
|
+
<div id="sort_panel">
|
21
|
+
<div class="info message"><i class="icon fa-fw fa-info fas"></i>
|
22
|
+
<%= t(:suggestion) %>
|
23
|
+
</div>
|
24
|
+
<div class="buttons">
|
25
|
+
<button name="button" type="submit" id="save_order" data-url-update=<%= update_order_path %>><%= t(:save_order) %>
|
26
|
+
</button>
|
27
|
+
</div>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<%= print_order_tree sort: true %>
|
31
|
+
|
32
|
+
<% end %>
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Alchemy::Custom::Model
|
2
|
+
module Order
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
|
7
|
+
before_action :check_parent
|
8
|
+
helper_method :parent_klass
|
9
|
+
|
10
|
+
|
11
|
+
def new
|
12
|
+
@obj = @parent
|
13
|
+
if @parent.nil?
|
14
|
+
if self.parent_klass.respond_to? :only_current_language
|
15
|
+
@elements = self.parent_klass.only_current_language
|
16
|
+
else
|
17
|
+
@elements = self.parent_klass.all
|
18
|
+
end
|
19
|
+
else
|
20
|
+
|
21
|
+
if @parent.respond_to? self.class.method_for_show
|
22
|
+
@elements = @parent.send(self.class.method_for_show.to_sym)
|
23
|
+
@elements = @elements.accessible_by(current_ability)
|
24
|
+
|
25
|
+
else
|
26
|
+
@elements = base_class.none
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def update
|
34
|
+
updated_nodes = params[:ordered_data]
|
35
|
+
self.parent_klass.transaction do
|
36
|
+
process_nodes updated_nodes, self.parent_klass
|
37
|
+
end
|
38
|
+
redirect_to polymorphic_path([:admin, self.parent_klass])
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def parent_klass
|
44
|
+
self.class.parent_klass
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def check_parent
|
50
|
+
if self.parent_klass.nil?
|
51
|
+
raise Errors::ParentNil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def base_class
|
56
|
+
parent_klass
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def process_nodes nodes, klass, parent = nil
|
61
|
+
nodes.each_with_index do |node, index|
|
62
|
+
cp = klass.find node[:id]
|
63
|
+
if !parent.nil?
|
64
|
+
cp.update_attributes(parent_id: parent, position: index)
|
65
|
+
else
|
66
|
+
if cp.respond_to? :parent_id
|
67
|
+
cp.update_attributes(position: index, parent_id: nil)
|
68
|
+
else
|
69
|
+
cp.update_attributes(position: index)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
if !node[:children].nil? and !node[:children].empty?
|
73
|
+
process_nodes node[:children], klass, cp.id
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alchemy-custom-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Baccanelli
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: alchemy_cms
|
@@ -79,6 +79,20 @@ dependencies:
|
|
79
79
|
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: 5.2.4
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: active_type
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0.7'
|
89
|
+
type: :runtime
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.7'
|
82
96
|
description: A gem for semplify model implementation with Alchemy CMS
|
83
97
|
email:
|
84
98
|
- alexbaccanelli@gmail.com
|
@@ -101,6 +115,7 @@ files:
|
|
101
115
|
- app/assets/javascripts/alchemy-custom-model/manifest.js
|
102
116
|
- app/assets/javascripts/alchemy-custom-model/nested_attributes_sortable.js.coffee
|
103
117
|
- app/assets/javascripts/alchemy-custom-model/select2filter.js
|
118
|
+
- app/assets/javascripts/alchemy-custom-model/sortable.js
|
104
119
|
- app/assets/javascripts/alchemy-custom-model/subobjects.js
|
105
120
|
- app/assets/javascripts/alchemy-custom-model/total_page_elfinder.js.coffee
|
106
121
|
- app/assets/stylesheets/alchemy-custom-model/custom_elfinder.css.scss
|
@@ -108,13 +123,17 @@ files:
|
|
108
123
|
- app/assets/stylesheets/alchemy-custom-model/custom_tiny_mce.scss
|
109
124
|
- app/assets/stylesheets/alchemy-custom-model/manifest.css
|
110
125
|
- app/controllers/alchemy/custom/model/admin/base_controller.rb
|
126
|
+
- app/controllers/alchemy/custom/model/admin/clones_controller.rb
|
111
127
|
- app/controllers/alchemy/custom/model/admin/files_controller.rb
|
128
|
+
- app/controllers/alchemy/custom/model/admin/orders_controller.rb
|
112
129
|
- app/controllers/alchemy/pages_controller_decorator.rb
|
113
130
|
- app/helpers/alchemy/custom/model/admin/base_helper.rb
|
131
|
+
- app/helpers/alchemy/custom/model/admin/orders_helper.rb
|
114
132
|
- app/helpers/alchemy/custom/model/base_helper.rb
|
115
133
|
- app/helpers/alchemy/custom/model/custom_model_helper.rb
|
116
134
|
- app/helpers/alchemy/pages_helper_decorator.rb
|
117
135
|
- app/models/admin_override_to_param.rb
|
136
|
+
- app/models/alchemy/custom/model/cloner.rb
|
118
137
|
- app/models/application_record.rb
|
119
138
|
- app/views/alchemy/custom/model/admin/base/_buttons_tool.html.erb
|
120
139
|
- app/views/alchemy/custom/model/admin/base/_gallery_item.html.erb
|
@@ -126,8 +145,11 @@ files:
|
|
126
145
|
- app/views/alchemy/custom/model/admin/base/edit.html.erb
|
127
146
|
- app/views/alchemy/custom/model/admin/base/index.html.erb
|
128
147
|
- app/views/alchemy/custom/model/admin/base/new.html.erb
|
148
|
+
- app/views/alchemy/custom/model/admin/base/show.html.erb
|
149
|
+
- app/views/alchemy/custom/model/admin/clones/new.html.erb
|
129
150
|
- app/views/alchemy/custom/model/admin/files/error_notice.json.jbuilder
|
130
151
|
- app/views/alchemy/custom/model/admin/files/ui.html.erb
|
152
|
+
- app/views/alchemy/custom/model/admin/orders/new.html.erb
|
131
153
|
- config/initializers/elfinder_abilities.rb
|
132
154
|
- config/locales/en.yml
|
133
155
|
- config/locales/it.yml
|
@@ -155,8 +177,11 @@ files:
|
|
155
177
|
- lib/alchemy/custom/model/el_finder/volumes/base.rb
|
156
178
|
- lib/alchemy/custom/model/el_finder/volumes/component_attribute.rb
|
157
179
|
- lib/alchemy/custom/model/engine.rb
|
180
|
+
- lib/alchemy/custom/model/errors/error.rb
|
181
|
+
- lib/alchemy/custom/model/errors/parent_nil.rb
|
158
182
|
- lib/alchemy/custom/model/global_id_setter.rb
|
159
183
|
- lib/alchemy/custom/model/model_decoration.rb
|
184
|
+
- lib/alchemy/custom/model/order.rb
|
160
185
|
- lib/alchemy/custom/model/pages_controller_dec.rb
|
161
186
|
- lib/alchemy/custom/model/translation_scope.rb
|
162
187
|
- lib/alchemy/custom/model/version.rb
|