drg_cms 0.7.0.2 → 0.7.1.1

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.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/drg_cms/drg_cms.js +110 -35
  3. data/app/assets/javascripts/drg_cms/jquery.bpopup.js +372 -0
  4. data/app/assets/javascripts/drg_cms_application.js +1 -1
  5. data/app/assets/javascripts/drg_cms_cms.js +1 -1
  6. data/app/assets/stylesheets/drg_cms/drg_cms.css +126 -36
  7. data/app/assets/stylesheets/drg_cms/select-multiple.css +6 -7
  8. data/app/controllers/cmsedit_controller.rb +78 -47
  9. data/app/controllers/dc_application_controller.rb +22 -25
  10. data/app/controllers/dc_common_controller.rb +9 -6
  11. data/app/controllers/dc_main_controller.rb +0 -1
  12. data/app/controls/{dc_category_control.rb → dc_gallery_control.rb} +15 -30
  13. data/app/controls/dc_image_control.rb +180 -0
  14. data/app/controls/dc_page_control.rb +3 -3
  15. data/app/controls/dc_poll_result_control.rb +38 -39
  16. data/app/controls/dc_report.rb +9 -4
  17. data/app/controls/dc_setup_control.rb +53 -0
  18. data/app/controls/design_element_settings_control.rb +88 -37
  19. data/app/forms/all_options.yml +20 -9
  20. data/app/forms/cms_menu.yml +14 -2
  21. data/app/forms/dc_gallery.yml +1 -1
  22. data/app/forms/dc_image.yml +122 -0
  23. data/app/forms/dc_image_search.yml +72 -0
  24. data/app/forms/dc_page.yml +11 -8
  25. data/app/forms/dc_poll.yml +2 -1
  26. data/app/forms/dc_poll_result.yml +10 -7
  27. data/app/forms/dc_setup.yml +45 -0
  28. data/app/forms/dc_steps_template.yml +6 -2
  29. data/app/helpers/cms_common_helper.rb +36 -24
  30. data/app/helpers/cms_edit_helper.rb +26 -33
  31. data/app/helpers/cms_helper.rb +29 -12
  32. data/app/helpers/cms_index_helper.rb +109 -80
  33. data/app/helpers/dc_application_helper.rb +108 -86
  34. data/app/helpers/dc_image_helper.rb +127 -0
  35. data/app/models/concerns/dc_policy_rule_concern.rb +1 -1
  36. data/app/models/concerns/dc_user_concern.rb +13 -5
  37. data/app/models/dc_big_table.rb +1 -1
  38. data/app/models/dc_category.rb +12 -0
  39. data/app/models/dc_design.rb +5 -4
  40. data/app/models/dc_filter.rb +24 -27
  41. data/app/models/dc_image.rb +237 -0
  42. data/app/models/dc_internals.rb +5 -9
  43. data/app/models/dc_memory.rb +2 -2
  44. data/app/models/dc_policy_role.rb +8 -8
  45. data/app/models/dc_setup.rb +111 -0
  46. data/app/models/drgcms_form_fields/datetime_picker.rb +1 -1
  47. data/app/models/drgcms_form_fields/drgcms_field.rb +9 -26
  48. data/app/models/drgcms_form_fields/embedded.rb +28 -17
  49. data/app/models/drgcms_form_fields/journal_diff.rb +2 -2
  50. data/app/models/drgcms_form_fields/multitext_autocomplete.rb +88 -76
  51. data/app/models/drgcms_form_fields/select.rb +41 -19
  52. data/app/models/drgcms_form_fields/text_with_select.rb +5 -9
  53. data/app/renderers/dc_big_menu_renderer.rb +18 -20
  54. data/app/renderers/dc_gallery_renderer.rb +10 -4
  55. data/app/renderers/dc_menu_renderer.rb +21 -58
  56. data/app/renderers/dc_page_renderer.rb +7 -7
  57. data/app/renderers/dc_poll_renderer.rb +13 -12
  58. data/app/renderers/dc_simple_menu_renderer.rb +1 -1
  59. data/app/views/cmsedit/_edit_stuff.html.erb +4 -1
  60. data/app/views/cmsedit/edit.html.erb +1 -1
  61. data/app/views/cmsedit/index.html.erb +1 -1
  62. data/app/views/cmsedit/new.html.erb +1 -0
  63. data/config/locales/drgcms_en.yml +22 -2
  64. data/config/locales/drgcms_sl.yml +25 -6
  65. data/config/locales/models_en.yml +50 -1
  66. data/config/locales/models_sl.yml +60 -1
  67. data/drg_cms.gemspec +1 -1
  68. data/lib/drg_cms/version.rb +1 -1
  69. data/lib/drg_cms.rb +40 -27
  70. data/lib/generators/convert_to_ar/USAGE +8 -0
  71. data/lib/generators/convert_to_ar/convert_to_ar_generator.rb +158 -0
  72. data/lib/generators/new_drg_form/new_drg_form_generator.rb +32 -14
  73. metadata +19 -10
  74. data/app/assets/javascripts/drg_cms/jquery.bpopup.min.js +0 -7
  75. data/app/views/layouts/__cmsedit.html.erb +0 -16
@@ -49,8 +49,8 @@ def render
49
49
  old_value = v.class == Array ? v[0] : v
50
50
  new_value = v.class == Array ? v[1] : v
51
51
  @html << "<div style='background-color: #eee;'>#{@parent.check_box('select', k)} #{k}</div>
52
- <div style='background-color: #fcc;'>-<br>#{old_value}</div>
53
- <div style='background-color: #cfc;'>+<br>#{new_value}</div><br>"
52
+ <div style='background-color: #fcc;'>-<br>#{old_value.to_s.gsub("\n", '<br>')}</div>
53
+ <div style='background-color: #cfc;'>+<br>#{new_value.to_s.gsub("\n", '<br>')}</div><br>"
54
54
  end
55
55
  @html << '</div>'
56
56
  self
@@ -24,12 +24,12 @@ module DrgcmsFormFields
24
24
 
25
25
  ###########################################################################
26
26
  # Implementation of multitext_autocomplete DRG Form field.
27
- #
27
+ #
28
28
  # multitext_autocomplete field is complex data entry field which uses autocomplete
29
29
  # function when selecting multiple values for MongoDB Array field. Array typically holds
30
- # id's of selected documents and control typically displays value of the field name
30
+ # id's of selected documents and control typically displays value of the field name
31
31
  # defined by search options.
32
- #
32
+ #
33
33
  # ===Form options:
34
34
  # * +name:+ field name (required)
35
35
  # * +type:+ multitext_autocomplete (required)
@@ -40,12 +40,12 @@ module DrgcmsFormFields
40
40
  # * collection_name.search_field_name.method_name; When searching is more complex custom search
41
41
  # method may be defined in CollectionName model which will provide result set for search.
42
42
  # * +with_new+ Will add an icon for shortcut to add new document to collection
43
- #
43
+ #
44
44
  # Form example:
45
45
  # 90:
46
46
  # name: kats
47
47
  # type: multitext_autocomplete
48
- # search: dc_category.name
48
+ # search: dc_category.name
49
49
  # with_new: model_name
50
50
  # size: 30
51
51
  ###########################################################################
@@ -55,106 +55,116 @@ class MultitextAutocomplete < DrgcmsField
55
55
  # Returns value for readonly field
56
56
  ###########################################################################
57
57
  def ro_standard(table, search)
58
- result = ''
59
- table = table.classify.constantize
60
- return self if @record[@yaml['name']].nil?
61
- # when field name and method are defined together
62
- search = search.split('.').first if search.match('.')
63
- @record[@yaml['name']].each do |element|
64
- result << table.find(element)[search] + '<br>'
65
- end
66
- super(result)
58
+ current_values = @record.send(@yaml['name'])
59
+ return self if current_values.blank?
60
+
61
+ table = table.classify.constantize
62
+ search = search.split(/\.|\,/).first if search.match(/\.|\,/)
63
+ html = current_values.inject('') { |r, element| r << table.find(element)[search] + '<br>' }
64
+ super(html)
67
65
  end
68
66
 
69
67
  ###########################################################################
70
68
  # Render multitext_autocomplete field html code
71
69
  ###########################################################################
72
- def render
73
- # search field name
70
+ def render
71
+ # get field name
74
72
  if @yaml['search'].class == Hash
75
- table = @yaml['search']['table']
73
+ table = @yaml['search']['table']
76
74
  field_name = @yaml['search']['field']
77
- method = @yaml['search']['method']
78
- search = method.nil? ? field_name : "#{field_name}.#{method}"
79
- elsif @yaml['search'].to_s.match(/\./)
75
+ method = @yaml['search']['method']
76
+ search = method.nil? ? field_name : "#{field_name}.#{method}"
77
+ elsif @yaml['search'].to_s.match(/\.|\,/)
80
78
  table, field_name, method = @yaml['search'].split(/\.|\,/).map(&:strip)
81
79
  search = method.nil? ? field_name : "#{field_name}.#{method}"
82
80
  else # search and table name are separated
83
81
  search = field_name = @yaml['search']
84
82
  end
85
- # determine table name
83
+ # get table name
86
84
  if @yaml['table']
87
85
  table = if @yaml['table'].class == String
88
- @yaml['table']
89
- # eval(how_to_get_my_table_name)
90
- elsif @yaml['table']['eval']
91
- eval @yaml['table']['eval']
92
- else
93
- @parent.logger.error "Field #{@yaml['name']}: Invalid table parameter!"
94
- nil
95
- end
86
+ @yaml['table']
87
+ # eval(how_to_get_my_table_name)
88
+ elsif @yaml['table']['eval']
89
+ eval @yaml['table']['eval']
90
+ else
91
+ Rails.logger.error "Field #{@yaml['name']}: Invalid table parameter!"
92
+ nil
93
+ end
94
+ end
95
+
96
+ if table.blank? || search.blank?
97
+ @html << 'Table or search field not defined!'
98
+ return self
96
99
  end
97
- unless (table and search)
98
- @html << 'Table or search field not defined!'
100
+
101
+ # does collection exists
102
+ collection = table.classify.constantize rescue nil
103
+ if collection.nil?
104
+ @html << "Invalid table name: #{table}"
99
105
  return self
100
106
  end
101
- #
102
- # TODO check if table exists
103
- collection = table.classify.constantize
107
+
108
+ # does field exists
104
109
  unless @record.respond_to?(@yaml['name'])
105
- @html << "Invalid field name: #{@yaml['name']}"
110
+ @html << "Invalid field name: #{@yaml['name']}"
106
111
  return self
107
112
  end
108
- # put field to enter search data on form
113
+
114
+ # search data entry
109
115
  @yaml['html'] ||= {}
110
116
  @yaml['html']['value'] = '' # must be. Otherwise it will look into record and return error
111
117
  @yaml['html']['placeholder'] = t('drgcms.search_placeholder')
112
118
  _name = '_' + @yaml['name']
113
119
  @html << '<div class="ui-autocomplete-border">'
114
- @html << @parent.link_to(@parent.fa_icon('plus-square-o', class: 'dc-green'), '#',onclick: 'return false;') # dummy add. But it is usefull.
120
+ @html << @parent.link_to(@parent.mi_icon('plus-square-o green'), '#', onclick: 'return false;') # dummy add. But it is usefull.
115
121
 
122
+ # text_field for autocomplete
116
123
  record = record_text_for(@yaml['name'])
117
- # text field for autocomplete
118
124
  @html << '<span class="dc-text-autocomplete">' << @parent.text_field(record, _name, @yaml['html']) << '<span></span></span>'
119
- # direct link for adding new documents to collection
120
- if @yaml['with_new'] and !@readonly
121
- @html << ' ' +
122
- @parent.fa_icon('plus-square-o', class: 'in-edit-add', title: t('drgcms.new'),
123
- style: "vertical-align: top;", 'data-table' => @yaml['with_new'] )
125
+
126
+ # link for adding new documents to searched collection
127
+ if @yaml['with_new'] && !@readonly
128
+ @html << ' ' +
129
+ @parent.mi_icon('plus-square-o', class: 'in-edit-add', title: t('drgcms.new'),
130
+ style: "vertical-align: top;", 'data-table' => @yaml['with_new'] )
124
131
  end
132
+
125
133
  # div to list active selections
126
134
  @html << "<div id =\"#{record}#{@yaml['name']}\">"
127
- # find value for each field inside categories
128
- unless @record[@yaml['name']].nil?
129
- @record[@yaml['name']].each do |element|
130
- # this is quick and dirty trick. We have model dc_big_table which can be used for retrive
131
- # more complicated options
135
+ # fill with current values
136
+ current_values = @record.send(@yaml['name'])
137
+ unless current_values.nil?
138
+ current_values.each do |element|
139
+ # this is quick and dirty trick. We have model dc_big_table which can be used for retrive
140
+ # more complicated options
132
141
  # TODO retrieve choices from big_table
133
142
  rec = if table == 'dc_big_table'
134
- collection.find(@yaml['name'], @parent.session)
135
- else
136
- collection.find(element)
137
- end
138
- # Related data is missing. It happends.
143
+ collection.find(@yaml['name'], @parent.session)
144
+ else
145
+ collection.find(element)
146
+ end
147
+
139
148
  @html << if rec
140
- link = @parent.link_to(@parent.fa_icon('remove_circle', class: 'dc-red'), '#',
141
- onclick: "$('##{rec.id}').hide(); var v = $('##{record}_#{@yaml['name']}_#{rec.id}'); v.val(\"-\" + v.val());return false;")
142
- link = @parent.fa_icon('check', class: 'dc-green') if @readonly
149
+ link = @parent.link_to(@parent.mi_icon('remove_circle red'), '#',
150
+ onclick: %($('##{rec.id}').hide(); let v = $('##{record}_#{@yaml['name']}_#{rec.id}'); v.val("-" + v.val());return false;))
151
+ link = @parent.mi_icon('check green') if @readonly
143
152
  field = @parent.hidden_field(record, "#{@yaml['name']}_#{rec.id}", value: element)
144
- "<div id=\"#{rec.id}\" style=\"padding:4px;\">#{link} #{rec.send(field_name)}<br>#{field}</div>"
153
+ %(<div id="#{rec.id}" style="padding:4px;">#{link} #{rec.send(field_name)}<br>#{field}</div>)
145
154
  else
146
- '** error **'
155
+ '** error **' # Related data is missing. It happends.
147
156
  end
148
157
  end
149
158
  end
150
159
  @html << "</div></div>"
151
- # Create text for div to be added when new category is selected
152
- link = @parent.link_to(@parent.fa_icon('remove_circle', class: 'dc-red'), '#',
153
- onclick: "$('#rec_id').hide(); var v = $('##{record}_#{@yaml['name']}_rec_id'); v.val(\"-\" + v.val());return false;")
160
+
161
+ # Create text for div to be added when new category is selected
162
+ link = @parent.link_to(@parent.mi_icon('remove_circle red'), '#',
163
+ onclick: %($('#rec_id').hide(); let v = $('##{record}_#{@yaml['name']}_rec_id'); v.val("-" + v.val());return false;"))
154
164
  field = @parent.hidden_field(record, "#{@yaml['name']}_rec_id", value: 'rec_id')
155
- one_div = "<div id=\"rec_id\" style=\"padding:4px;\">#{link} rec_search<br>#{field}</div>"
156
-
157
- # JS stuff
165
+ one_div = %(<div id="rec_id" style="padding:4px;">#{link} rec_search<br>#{field}</div>)
166
+
167
+ # JS stuff
158
168
  @js << <<EOJS
159
169
  $(document).ready(function() {
160
170
  $("##{record}_#{_name}").autocomplete( {
@@ -172,11 +182,13 @@ $(document).ready(function() {
172
182
  });
173
183
  },
174
184
  change: function (event, ui) {
175
- var div = '#{one_div}';
176
- div = div.replace(/rec_id/g, ui.item.id)
177
- div = div.replace('rec_search', ui.item.value)
178
- $("##{record}#{@yaml['name']}").append(div);
179
- $("##{record}_#{_name}").val('');
185
+ let div = '#{one_div}';
186
+ if (ui.item != null) {
187
+ div = div.replace(/rec_id/g, ui.item.id)
188
+ div = div.replace('rec_search', ui.item.value)
189
+ $("##{record}#{@yaml['name']}").append(div);
190
+ $("##{record}_#{_name}").val('');
191
+ }
180
192
  $("##{record}_#{_name}").focus();
181
193
  },
182
194
  minLength: 2
@@ -184,20 +196,20 @@ $(document).ready(function() {
184
196
  });
185
197
  EOJS
186
198
 
187
- self
199
+ self
188
200
  end
189
201
 
190
202
  ###########################################################################
191
- # Class method for retrieving data from multitext_autocomplete form field.
203
+ # Class method for retrieving data from multitext_autocomplete form field. Values are sabed
204
+ # in parameters as name_id => id
192
205
  ###########################################################################
193
206
  def self.get_data(params, name)
194
207
  r = []
195
- params['record'].each do |k,v|
196
- # if it starts with - then it was removed
197
- r << BSON::ObjectId.from_string(v) if k.match("#{name}_") and v[0,1] != '-'
208
+ params['record'].each do |k, v| # inject does not work on params
209
+ # if it starts with - then it was removed
210
+ r << BSON::ObjectId.from_string(v) if k.starts_with?("#{name}_") && v[0] != '-'
198
211
  end
199
- r.uniq!
200
- r
212
+ r.uniq
201
213
  end
202
214
 
203
215
  end
@@ -47,7 +47,9 @@ module DrgcmsFormFields
47
47
  # * +depend:+ Select options may depend on a value in some other field. If depend option is specified
48
48
  # then chices must be provided by class method and defined in eval option.
49
49
  # * +html:+ html options which apply to select field (optional)
50
- #
50
+ # * +with_new:+ model_name.form_name will invoke view dialog for selected option
51
+ # * +with_edit:+ model_name.form_name will invoke edit dialog for selected option
52
+ #
51
53
  # Form example:
52
54
  # 30:
53
55
  # name: type
@@ -80,9 +82,9 @@ class Select < DrgcmsField
80
82
  def choices_in_helper(helper = nil)
81
83
  helper ||= "helpers.label.#{@form['table']}.choices4_#{@yaml['name']}"
82
84
  c = t(helper)
83
- if c.match( 'translation missing' )
85
+ if c.match(/translation missing/i)
84
86
  helper = "choices_for_#{@form['table']}_#{@yaml['name']}"
85
- return "Error. #{helper} not defined" if c.match( 'translation missing' )
87
+ return "Error. #{helper} not defined" if c.match(/translation missing/i)
86
88
  end
87
89
  c
88
90
  end
@@ -95,21 +97,27 @@ def choices_in_eval(e)
95
97
  e.strip!
96
98
  if @yaml['depend'].nil?
97
99
  method = e.split(/\ |\(/).first
98
- return eval(e) if respond_to?(method) # id method defined here
99
- return eval('@parent.' + e) if @parent.respond_to?(method) # is method defined in helpers
100
+ return eval(e) if respond_to?(method) # is method defined here
101
+ return eval('@parent.' + e) if @parent.respond_to?(method) # is method defined in helper methods
100
102
  # eval whatever it is there
101
103
  eval e
102
104
  else
103
- # add event listener to depend field
104
- @js << %(
105
- $(document).ready(function() {
106
- $('#record_#{@yaml['depend']}').change( function(e) { update_select_depend('record_#{@yaml['name']}', 'record_#{@yaml['depend']}','#{e}');});
107
- $('#_record_#{@yaml['depend']}').change( function(e) { update_select_depend('record_#{@yaml['name']}', '_record_#{@yaml['depend']}','#{e}');});
108
- });
105
+ # add event listener to depend field(s)
106
+ depend_value = ''
107
+ @js << "\n$(document).ready(function() {\n"
108
+ @yaml['depend'].split(',') do |depend|
109
+ depend.strip!
110
+ depend_value << ',' if depend_value.present?
111
+ # depend field might be virtual field. It's value should be set in params
112
+ depend_value << (depend[0] == '_' ? @parent.params["p_#{depend}"] : @record[depend]).to_s
113
+ next if depend == @yaml['name'] # self may be sent, but don't listen to change event
114
+
115
+ @js << %(
116
+ $('#record_#{depend}').change( function(e) { update_select_depend('record_#{@yaml['name']}', '#{@yaml['depend']}', '#{e}');});
117
+ $('#_record_#{depend}').change( function(e) { update_select_depend('record_#{@yaml['name']}', '#{@yaml['depend']}', '#{e}');});
109
118
  )
110
- # depend field might be virtual field. It's value should be set in params
111
- depend_value = @yaml['depend'][0] == '_' ? @parent.params["p_#{@yaml['depend']}"] : @record[@yaml['depend']]
112
-
119
+ end
120
+ @js << + "});\n"
113
121
  e << " '#{depend_value}'"
114
122
  eval e
115
123
  end
@@ -132,7 +140,7 @@ def get_choices
132
140
 
133
141
  choices.chomp.split(',').map { |e| e.match(':') ? e.split(':') : e }
134
142
  rescue Exception => e
135
- Rails.logger.debug "\nError in select eval. #{e.message}\n"
143
+ Rails.logger.error "\nError in select eval. #{e.message}\n"
136
144
  Rails.logger.debug(e.backtrace.join($/)) if Rails.env.development?
137
145
  ['error'] # return empty array when error occures
138
146
  end
@@ -144,9 +152,21 @@ end
144
152
  def add_view_code
145
153
  return '' if (data = @record.send(@yaml['name'])).blank?
146
154
 
147
- table, form_name = @yaml['view'].split(/\ |\,/).delete_if { |e| e.blank? }
155
+ table, form_name = @yaml['with_view'].split(/\ |\,/).delete_if(&:blank)
148
156
  url = @parent.url_for(controller: 'cmsedit', id: data, action: :edit, table: table, form_name: form_name, readonly: true, window_close: 1 )
149
- icon = @parent.mi_icon('eye-o md-18')
157
+ icon = @parent.mi_icon('visibility-o md-18')
158
+ %(<span class="dc-window-open" data-url="#{url}"> #{icon}</span>)
159
+ end
160
+
161
+ ###########################################################################
162
+ # Will add code to view more data about selected option in a window
163
+ ###########################################################################
164
+ def add_edit_code
165
+ return '' if (data = @record.send(@yaml['name'])).blank?
166
+
167
+ table, form_name = @yaml['view'].split(/\ |\,/).delete_if(&:blank)
168
+ url = @parent.url_for(controller: 'cmsedit', id: data, action: :edit, table: table, form_name: form_name, window_close: 1 )
169
+ icon = @parent.mi_icon('edit-o md-18')
150
170
  %(<span class="dc-window-open" data-url="#{url}"> #{icon}</span>)
151
171
  end
152
172
 
@@ -176,7 +196,7 @@ def ro_standard
176
196
  (html = choice; break) if choice.to_s == value.to_s
177
197
  end
178
198
  end
179
- html << add_view_code if @yaml['view']
199
+ html << add_view_code if @yaml['with_view']
180
200
  end
181
201
  super(html)
182
202
  end
@@ -196,12 +216,14 @@ def render
196
216
 
197
217
  record = record_text_for(@yaml['name'])
198
218
  if @yaml['html'][:multiple]
219
+ @yaml['html']['class'] = "#{@yaml['html']['class']} select-multiple"
199
220
  @html << @parent.select(record, @yaml['name'], get_choices, options_part, @yaml['html'])
200
221
  @js << "$('##{record}_#{@yaml['name']}').selectMultiple();"
201
222
  else
202
223
  @html << @parent.select(record, @yaml['name'], get_choices, options_part, @yaml['html'])
203
224
  # add code for view more data
204
- @html << add_view_code() if @yaml['view']
225
+ @html << view_code_add() if @yaml['with_view']
226
+ @html << edit_code_add() if @yaml['with_edit'] && !@readonly
205
227
  end
206
228
  self
207
229
  end
@@ -65,9 +65,7 @@ class TextWithSelect < Select
65
65
  # Render text_with_select field html code
66
66
  ###########################################################################
67
67
  def render
68
- #return ro_standard if @readonly
69
- set_initial_value('html','value')
70
-
68
+ set_initial_value
71
69
  record = record_text_for(@yaml['name'])
72
70
  @html << @parent.text_field( record, @yaml['name'], @yaml['html'])
73
71
  @yaml['html']['class'] ||= ''
@@ -80,13 +78,11 @@ def render
80
78
  # javascript to update text field if new value is selected in select field
81
79
  @js =<<EOJS
82
80
  $(document).ready(function() {
83
- $('##{@yaml['name']}_').change( function() {
84
- if ($(this).val().toString().length > 0) {
85
- $('##{record}_#{@yaml['name']}').val( $(this).val() );
81
+ $('##{@yaml['name']}_').on("click", function() {
82
+ $('##{record}_#{@yaml['name']}').val( $(this).val().toString() );
86
83
  $('##{record}_#{@yaml['name']}').trigger("change");
87
- }
88
- $('##{record}_#{@yaml['name']}').focus();
89
- });
84
+ $('##{record}_#{@yaml['name']}').focus();
85
+ });
90
86
  });
91
87
  EOJS
92
88
  self
@@ -1,4 +1,3 @@
1
- #coding: utf-8
2
1
  #--
3
2
  # Copyright (c) 2013+ Damjan Rems
4
3
  #
@@ -51,9 +50,7 @@ def find_selected #:nodoc:
51
50
  while ret and ret.parent != nil
52
51
  ret = DcBigMenu.find( ret.parent )
53
52
  end
54
- # return first if not found (something is wrong)
55
- # p ret
56
- ret ||= DcBigMenu.where(dc_site_id: @site._id, parent: nil, active: true).limit(1).first
53
+ ret || DcBigMenu.where(dc_site_id: @site._id, parent: nil, active: true).limit(1).first
57
54
  end
58
55
 
59
56
  ########################################################################
@@ -78,7 +75,7 @@ def link_4menu(item) #:nodoc:
78
75
  html = ''
79
76
  link = item.link
80
77
  link = "/#{@site.route_name}/#{item.page_id}" #if link.blank?
81
- #
78
+
82
79
  html << @parent.link_to(item.picture, link) unless item.picture.blank?
83
80
  html << if !item.caption.blank?
84
81
  # TODO Translation
@@ -91,23 +88,23 @@ end
91
88
  ########################################################################
92
89
  def left_menu
93
90
  html = ''
94
- m = DcBigMenu.find( @parent.page.menu_id )
95
- # Show menu on same level if selected has no children
91
+ menu = DcBigMenu.find( @parent.page.menu_id )
92
+ # Show menu on same level if selected has no children
96
93
  if DcBigMenu.where( parent: @parent.page.menu_id ).limit(1).to_a.size == 0
97
- m = DcBigMenu.find( m.parent )
94
+ menu = DcBigMenu.find( m.parent )
98
95
  end
99
- #
100
- html << "<div class='menu-left-item-top'>#{m.caption}</div>"
101
- DcBigMenu.where( parent: m._id ).sort(order: 1).each do |item|
96
+
97
+ html << "<div class='menu-left-item-top'>#{menu.caption}</div>"
98
+ DcBigMenu.where( parent: menu.id ).order(order: 1).each do |item|
102
99
  html << (item._id == @parent.page.menu_id ? '<div class="menu-left-item-selected">' : '<div class="menu-left-item">')
103
100
  html << link_4menu(item)
104
101
  html << '</div>'
105
102
  end
106
- #
103
+
107
104
  html << "<div class='menu-left-item-bottom'>"
108
- if m.parent
109
- p = DcBigMenu.find( m.parent )
110
- html << "&#9650; #{link_4menu(p)}"
105
+ if menu.parent
106
+ parent = DcBigMenu.find( menu.parent )
107
+ html << "&#9650; #{link_4menu(parent)}"
111
108
  end
112
109
  html << '&nbsp;</div>'
113
110
  end
@@ -124,14 +121,14 @@ def path
124
121
  m = DcBigMenu.find( m.parent )
125
122
  a << m
126
123
  end
127
- #
124
+
128
125
  (a.size - 1).downto(0) do |i|
129
126
  html << "<span id=menu-path-#{a.size - 1 - i}>"
130
127
  html << link_4menu(a[i])
131
128
  html << (i > 0 ? ' &raquo; ' : '') #&rsaquo;&#10132;
132
129
  html << '</span>'
133
130
  end
134
- # Save level to parents params object
131
+ # Save level to parents params object
135
132
  @parent.params[:menu_level] = a.size
136
133
  html
137
134
  end
@@ -144,20 +141,21 @@ def default
144
141
  @selected = find_selected
145
142
  level_0 = DcBigMenu.where(dc_site_id: @site._id, parent: nil, active: true).sort(order: 1).to_a
146
143
  level_0.each do |item|
147
- # menu can be hidden from user
144
+ # menu can be hidden from user
148
145
  can_view, msg = dc_user_can_view(@parent, item)
149
146
  next unless can_view
147
+
150
148
  klas = item.id == @selected.id ? "menu0-selected" : "menu0-item"
151
149
  html << "<li class='#{klas}'>#{ link_4menu(item) }</li>\n"
152
150
  end
153
151
  html << "</ul></div>"
154
- # submenu
152
+ # submenu
155
153
  level_1 = DcBigMenu.where(dc_site_id: @site._id, parent: @selected.id, active: true).sort(order: 1).to_a
156
154
  html << "<div class='menu1-div'><ul>\n"
157
155
  level_1.each do |item1|
158
- # menu can be hidden from user
159
156
  can_view, msg = dc_user_can_view(@parent, item1)
160
157
  next unless can_view
158
+
161
159
  html << " <li class='menu1-item'>#{link_4menu(item1)}</li>\n"
162
160
  end
163
161
  html << '</ul></div>'
@@ -52,14 +52,20 @@ end
52
52
  def default
53
53
  can_view, msg = dc_user_can_view(@parent, @page)
54
54
  return msg unless can_view
55
- #
55
+
56
56
  html = '<div class="picture-gallery"><ul>'
57
57
  DcGallery.where(doc_id: @opts[:doc_id], active: true).order_by(order: 1).each do |picture|
58
58
  html << '<li>'
59
- html << edit_menu(picture) if @opts[:edit_mode] > 1
59
+ if @opts[:edit_mode] > 1
60
+ html << edit_menu(picture)
61
+ html << %(
62
+ <span class="dc-inline-link dc-link-ajax" data-url="/cmsedit/run?control=DcGalleryControl.picture_remove;id=#{picture.id};table=DcGallery"
63
+ data-confirm="#{t('drgcms.confirm_delete')}" title="#{t('drgcms.delete')}">
64
+ <i class="mi-o mi-delete"></i>
65
+ </span>)
66
+ end
60
67
  html << "#{@parent.link_to(i@parent.mage_tag(picture.thumbnail, title: picture.title), picture.picture)}<li>"
61
68
  end
62
- #
63
69
  html << '</ul></div>'
64
70
  end
65
71
 
@@ -88,7 +94,7 @@ def edit_menu(picture)
88
94
  opts[:id] = picture.id
89
95
  opts[:table] = 'dc_gallery'
90
96
 
91
- '<li>'+dc_link_for_edit(opts)+'</li>'
97
+ '<li>' + dc_link_for_edit(opts) + '</li>'
92
98
  end
93
99
 
94
100