drg_cms 0.5.50.2 → 0.5.51.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/History.log +47 -0
  3. data/README.md +2 -1
  4. data/app/assets/images/32px.png +0 -0
  5. data/app/assets/images/drg_cms/32px.png +0 -0
  6. data/app/assets/images/drg_cms/40px.png +0 -0
  7. data/app/assets/images/drg_cms/throbber.gif +0 -0
  8. data/app/assets/images/throbber.gif +0 -0
  9. data/app/assets/javascripts/drg_cms/drg_cms.js +3 -3
  10. data/app/assets/javascripts/drg_cms/jstree.min.js +6 -0
  11. data/app/assets/javascripts/drg_cms_cms.js +2 -1
  12. data/app/assets/stylesheets/drg_cms/drg_cms.css +9 -0
  13. data/app/assets/stylesheets/drg_cms/jstree.css +1108 -0
  14. data/app/assets/stylesheets/drg_cms_cms.css +1 -0
  15. data/app/controllers/cmsedit_controller.rb +14 -12
  16. data/app/controllers/dc_application_controller.rb +2 -2
  17. data/app/controllers/dc_common_controller.rb +15 -20
  18. data/app/controllers/dc_page_control.rb +8 -0
  19. data/app/controllers/design_element_settings_control.rb +135 -0
  20. data/app/forms/all_options.yml +7 -1
  21. data/app/forms/cms_menu.yml +1 -1
  22. data/app/forms/dc_browse_fields.yml +1 -1
  23. data/app/forms/dc_browse_models.yml +2 -2
  24. data/app/forms/dc_category.yml +4 -4
  25. data/app/forms/dc_menu.yml +6 -0
  26. data/app/forms/dc_page.yml +22 -12
  27. data/app/forms/dc_simple_menu.yml +6 -0
  28. data/app/forms/dc_site.yml +6 -0
  29. data/app/helpers/cmsedit_helper.rb +12 -8
  30. data/app/helpers/dc_application_helper.rb +79 -18
  31. data/app/helpers/dc_menu_renderer.rb +6 -1
  32. data/app/helpers/dc_part_renderer.rb +1 -1
  33. data/app/models/concerns/dc_page_concern.rb +133 -0
  34. data/app/models/concerns/dc_piece_concern.rb +57 -0
  35. data/app/models/concerns/dc_policy_rule_concern.rb +78 -0
  36. data/app/models/concerns/dc_site_concern.rb +94 -0
  37. data/app/models/concerns/dc_user_concern.rb +130 -0
  38. data/app/models/dc_ad.rb +1 -1
  39. data/app/models/dc_big_menu.rb +1 -1
  40. data/app/models/dc_category.rb +19 -4
  41. data/app/models/dc_dummy.rb +3 -2
  42. data/app/models/dc_link.rb +1 -1
  43. data/app/models/dc_memory.rb +127 -0
  44. data/app/models/dc_menu.rb +69 -3
  45. data/app/models/dc_menu_item.rb +17 -0
  46. data/app/models/dc_page.rb +0 -106
  47. data/app/models/dc_part.rb +0 -1
  48. data/app/models/dc_piece.rb +0 -35
  49. data/app/models/dc_policy_rule.rb +0 -56
  50. data/app/models/dc_simple_menu.rb +36 -0
  51. data/app/models/dc_simple_menu_item.rb +0 -0
  52. data/app/models/dc_site.rb +1 -71
  53. data/app/models/dc_user.rb +0 -108
  54. data/app/models/drgcms_form_fields.rb +187 -26
  55. data/app/views/cmsedit/_result.html.erb +3 -4
  56. data/config/locales/models_en.yml +11 -3
  57. data/config/locales/models_sl.yml +7 -0
  58. data/lib/drg_cms.rb +1 -0
  59. data/lib/drg_cms/version.rb +1 -1
  60. data/lib/tasks/log_statistics.rb +14 -8
  61. metadata +16 -2
@@ -21,114 +21,6 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- #########################################################################
25
- # ActiveSupport::Concern definition for DcUser class.
26
- #########################################################################
27
- module DcUserConcern
28
- extend ActiveSupport::Concern
29
- included do
30
- @@countries = nil
31
-
32
- include Mongoid::Document
33
- include Mongoid::Timestamps
34
- include ActiveModel::SecurePassword
35
-
36
- field :username, type: String, default: ''
37
- field :title, type: String, default: ''
38
- field :first_name, type: String, default: ''
39
- field :middle_name, type: String, default: ''
40
- field :last_name, type: String, default: ''
41
- field :name, type: String
42
- field :company, type: String, default: ''
43
- field :address, type: String
44
- field :post, type: String
45
- field :country, type: String
46
- field :phone, type: String
47
- field :email, type: String
48
- field :www, type: String
49
- field :picture, type: String
50
- field :birthdate, type: Date
51
- field :about, type: String
52
- field :last_visit, type: Time
53
- field :active, type: Boolean, default: true
54
- field :valid_from, type: Date
55
- field :valid_to, type: Date
56
- field :created_by, type: BSON::ObjectId
57
- field :updated_by, type: BSON::ObjectId
58
-
59
- field :type, type: Integer, default: 0 # 0 => User, 1 => Group
60
- field :members, type: Array
61
-
62
- embeds_many :dc_user_roles
63
-
64
- # for forum
65
- field :signature, type: String
66
- field :interests, type: String
67
- field :job_occup, type: String
68
- field :description, type: String
69
- field :reg_date, type: Date
70
-
71
- field :password_digest, type: String
72
- has_secure_password
73
-
74
- index( { username: 1 }, { unique: true } )
75
- index( { email: 1 }, { unique: true } )
76
- index 'dc_user_roles.dc_policy_role_id' => 1
77
-
78
- index 'members' => 1
79
-
80
- validates_length_of :username, minimum: 4
81
- before_save :do_before_save
82
-
83
- ##########################################################################
84
- # before_save callback takes care of name field and ensures that e-mail is unique
85
- # when entry is left empty.
86
- ##########################################################################
87
- def do_before_save
88
- self.name = "#{self.title} #{self.first_name} #{self.middle_name + ' ' unless self.middle_name.blank?}#{self.last_name}".strip
89
- # to ensure unique e-mail
90
- self.email = "unknown@#{self.id}" if self.email.to_s.strip.size < 5
91
- end
92
-
93
- ##########################################################################
94
- # Will return all possible values for country field ready for input in select field.
95
- # Values are loaded from github when method is first called.
96
- ##########################################################################
97
- def self.choices4_country()
98
- if @@countries.nil?
99
- uri = URI.parse("https://raw.githubusercontent.com/umpirsky/country-list/master/country/cldr/en/country.json")
100
- http = Net::HTTP.new(uri.host, uri.port)
101
- http.use_ssl = true
102
-
103
- request = Net::HTTP::Get.new(uri.request_uri)
104
- response = http.request(request)
105
- @@countries = JSON.parse(response.body).to_a.inject([]) {|result, e| result << [e[1], e[0]] }
106
- end
107
- @@countries
108
- end
109
-
110
- ##########################################################################
111
- # Performs ligically test on passed email parameter.
112
- #
113
- # Parameters:
114
- # [email] String: e-mail address
115
- #
116
- # Returns:
117
- # Boolean: True if parameter is logically valid email address.
118
- #
119
- # Example:
120
- # if !DcUser.is_email?(params[:email])
121
- # flash[:error] = 'e-Mail address is not valid!'
122
- # end
123
- #
124
- ##########################################################################
125
- def self.is_email?(email)
126
- email.to_s =~ /^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
127
- end
128
-
129
- end
130
- end
131
-
132
24
  ########################################################################
133
25
  # == Schema information
134
26
  #
@@ -130,7 +130,7 @@ end
130
130
  # params['p_picture'] = '/path/to_picture'
131
131
  #
132
132
  # When multiple initial values are assigned it is more convinient to assign them
133
- # through flash method.
133
+ # through flash object.
134
134
  # flash[:record] = {}
135
135
  # flash[:record]['picture'] = '/path/to_picture'
136
136
  ####################################################################
@@ -144,6 +144,40 @@ def set_initial_value(opt1='html', opt2='value')
144
144
  end
145
145
  end
146
146
 
147
+ ####################################################################
148
+ # Returns style html code for DRGForm object if style directive is present in field definition.
149
+ # Otherwiese returns empty string.
150
+ #
151
+ # Style may be defined like:
152
+ # style:
153
+ # height: 400px
154
+ # width: 800px
155
+ # padding: 10px 20px
156
+ #
157
+ # or
158
+ #
159
+ # style: "height:400px; width:800px; padding: 10px 20px;"
160
+ #
161
+ # Style directive may also be defined under html directive.
162
+ # html:
163
+ # style:
164
+ # height: 400px
165
+ # width: 800px
166
+ #
167
+ #
168
+ ####################################################################
169
+ def set_style()
170
+ style = @yaml['html']['style'] || @yaml['style']
171
+ case
172
+ when style.nil? then ''
173
+ when style.class == String then "style=\"#{style}\""
174
+ when style.class == Hash then
175
+ value = style.to_a.inject([]) {|r,v| r << "#{v[0]}: #{v[1]}" }.join(';')
176
+ "style=\"#{value}\""
177
+ else ''
178
+ end
179
+ end
180
+
147
181
  ####################################################################
148
182
  # Will return ruby hash formated as javascript string which can be used
149
183
  # for passing parameters in javascript code.
@@ -164,10 +198,7 @@ end
164
198
  #
165
199
  ####################################################################
166
200
  def hash_to_options(hash)
167
- options = hash.to_a.inject('') do |r,v|
168
- r << "#{v[0]}: #{v[1]},"
169
- end
170
- options.chomp(',')
201
+ hash.to_a.inject([]) {|r,v| r << "#{v[0]}: #{v[1]}" }.join(',')
171
202
  end
172
203
 
173
204
  ####################################################################
@@ -585,7 +616,8 @@ end
585
616
  def get_choices
586
617
  begin
587
618
  choices = case
588
- when @yaml['choices'] then @yaml['choices']
619
+ when @yaml['choices'] then
620
+ (@yaml['choices'].match('helpers.') ) ? t(@yaml['choices']) : @yaml['choices']
589
621
  when @yaml['eval'] then
590
622
  do_eval(@yaml['eval'])
591
623
  else
@@ -659,8 +691,10 @@ def self.get_data(params, name)
659
691
  if params['record'][name].class == Array
660
692
  params['record'][name].delete_if {|e| e.blank? }
661
693
  return nil if params['record'][name].size == 0
662
- # convert to BSON objects
663
- return params['record'][name].map{ |e| BSON::ObjectId.from_string(e) }
694
+ # convert to BSON objects
695
+ is_id = BSON::ObjectId.legal?(params['record'][name].first)
696
+ return params['record'][name].map{ |e| BSON::ObjectId.from_string(e) } if is_id
697
+ return params['record'][name]
664
698
  end
665
699
  params['record'][name]
666
700
  end
@@ -885,24 +919,14 @@ def render
885
919
  self
886
920
  end
887
921
 
888
- ####################################################################
889
- # Get data for DateSelect field
890
- # According to https://gist.github.com/315227
891
- ####################################################################
922
+ ###########################################################################
923
+ # DatetimeSelect get_data method.
924
+ ###########################################################################
892
925
  def self.get_data(params, name)
893
- attrs = params['record'].collect do |key, value|
894
- if key =~ /^#{Regexp.escape(name.to_s)}\((\d+)(\w)\)$/
895
- [$1.to_i, value.send("to_#$2")]
896
- end
897
- end.compact.sort_by(&:first).map(&:last)
898
- # Return nil if error
899
- begin
900
- Time.zone.local(*attrs) #unless attrs.empty?
901
- rescue
902
- nil
903
- end
926
+ DatetimeSelect.get_data(params, name).to_date rescue nil
904
927
  end
905
928
 
929
+
906
930
  end
907
931
 
908
932
  ###########################################################################
@@ -939,11 +963,16 @@ def render
939
963
  self
940
964
  end
941
965
 
942
- ###########################################################################
966
+ ####################################################################
943
967
  # DatetimeSelect get_data method.
944
- ###########################################################################
968
+ ####################################################################
945
969
  def self.get_data(params, name)
946
- DateSelect.get_data(params, name)
970
+ begin
971
+ attrs = (1..5).map { |i| params['record']["#{name}(#{i}i)"]}
972
+ Time.zone.local(*attrs)
973
+ rescue
974
+ nil
975
+ end
947
976
  end
948
977
 
949
978
  end
@@ -1346,6 +1375,138 @@ EOJS
1346
1375
  end
1347
1376
  end
1348
1377
 
1378
+ ###########################################################################
1379
+ # Implementation of tree_select DRG CMS form field. Field will provides
1380
+ # multiple select functionality displayed as a tree. Might be used for selecting
1381
+ # multiple categories in a parent-child tree view.#
1382
+ #
1383
+ # ===Form options:
1384
+ # * +name:+ field name (required)
1385
+ # * +type:+ tree_select (required)
1386
+ # * +choices:+ Values for choices separated by comma. Values can also be specified like description:value.
1387
+ # In this case description will be shown to user, but value will be saved to document.
1388
+ # choices: 'OK:0,Ready:1,Error:2'
1389
+ # choices: Ruby,Pyton,PHP
1390
+ # * +eval:+ Choices will be provided by evaluating expression
1391
+ # eval: ModelName.choices4_field; Model class should define method which will provide data for field.
1392
+ # Data returned must be of type Array and have 3 elements.
1393
+ # 1 - description text
1394
+ # 2 - id value
1395
+ # 3 - parent id
1396
+ # * +html:+ html options which apply to select and text_field fields (optional)
1397
+ #
1398
+ # Form example:
1399
+ # 10:
1400
+ # name: categories
1401
+ # type: tree_select
1402
+ # eval: 'Categories.all_categories'
1403
+ # html:
1404
+ # size: 50x10
1405
+ ###########################################################################
1406
+ class TreeSelect < Select
1407
+
1408
+ ###########################################################################
1409
+ # Prepare choices for tree data rendering.
1410
+ ###########################################################################
1411
+ def make_tree(parent)
1412
+ return '' unless @choices[parent.to_s]
1413
+ @html << '<ul>'
1414
+ choices = if @choices[parent.to_s].first.last != 0
1415
+ @choices[parent.to_s].sort_by {|e| e[3] } # sort by order if first is not 0
1416
+ # @choices[parent.to_s].sort_alphabetical_by(&:first) # use UTF-8 sort
1417
+ else
1418
+ @choices[parent.to_s].sort_alphabetical_by(&:first) # use UTF-8 sort
1419
+ end
1420
+ choices.each do |choice|
1421
+ jstree = %Q[{"selected" : #{choice[4] ? 'true' : 'false'} }]
1422
+ # data-jstree must be singe quoted
1423
+ @html << %Q[<li data-id="#{choice[1]}" data-jstree='#{jstree}'>#{choice.first}\n]
1424
+ # call recursively for children
1425
+ make_tree(choice[1]) if @choices[ choice[1].to_s ]
1426
+ @html << "</li>"
1427
+ end
1428
+ @html << '</ul>'
1429
+ end
1430
+
1431
+ ###########################################################################
1432
+ # Prepare choices for tree data rendering.
1433
+ ###########################################################################
1434
+ def _make_tree(parent)
1435
+ @html << '<ul>'
1436
+ choices = @choices[parent.to_s].sort_alphabetical_by(&:first) # use UTF-8 sort
1437
+ choices.each do |choice|
1438
+ jstree = %Q[{"selected" : #{choice[4] ? 'true' : 'false'} }]
1439
+ # data-jstree must be singe quoted
1440
+ @html << %Q[<li data-id="#{choice[1]}" data-jstree='#{jstree}'>#{choice.first}\n]
1441
+ # call recursively for children
1442
+ make_tree(choice[1]) if @choices[ choice[1].to_s ]
1443
+ @html << "</li>"
1444
+ end
1445
+ @html << '</ul>'
1446
+ end
1447
+
1448
+ ###########################################################################
1449
+ # Render tree_select field html code
1450
+ ###########################################################################
1451
+ def render
1452
+ return ro_standard if @readonly
1453
+ set_initial_value('html','value')
1454
+ require 'sort_alphabetical'
1455
+
1456
+ record = record_text_for(@yaml['name'])
1457
+ @html << "<div id=\"#{@yaml['name']}\" class=\"tree-select\" #{set_style()} >"
1458
+ # Fill @choices hash. The key is parent object id
1459
+ @choices = {}
1460
+ do_eval(@yaml['eval']).each {|data| @choices[ data[2].to_s ] ||= []; @choices[ data[2].to_s ] << (data << false)}
1461
+ # put current values hash with. To speed up selection when there is a lot of categories
1462
+ current_values = {}
1463
+ current = @record[@yaml['name']] || []
1464
+ current = [current] unless current.class == Array # non array fields
1465
+ current.each {|e| current_values[e.to_s] = true}
1466
+ # set third element of @choices when selected
1467
+ @choices.keys.each do |key|
1468
+ 0.upto( @choices[key].size - 1 ) do |i|
1469
+ choice = @choices[key][i]
1470
+ choice[4] = true if current_values[ choice[1].to_s ]
1471
+ end
1472
+ end
1473
+ make_tree(nil)
1474
+ @html << '</ul></div>'
1475
+ # add hidden communication field
1476
+ @html << @parent.hidden_field(record, @yaml['name'], value: current.join(','))
1477
+ # javascript to update hidden record field when tree looses focus
1478
+ @js =<<EOJS
1479
+ $(function(){
1480
+ $("##{@yaml['name']}").jstree( {
1481
+ "checkbox" : {"three_state" : false},
1482
+ "core" : { "themes" : { "icons": false } },
1483
+ "plugins" : ["checkbox"]
1484
+ });
1485
+ });
1486
+
1487
+ $(document).ready(function() {
1488
+ $('##{@yaml['name']}').on('focusout', function(e) {
1489
+ var checked_ids = [];
1490
+ var checked = $('##{@yaml['name']}').jstree("get_checked", true);
1491
+ $.each(checked, function() {
1492
+ checked_ids.push( this.data.id );
1493
+ });
1494
+ $('#record_#{@yaml['name']}').val( checked_ids.join(",") );
1495
+ });
1496
+ });
1497
+ EOJS
1498
+ self
1499
+ end
1500
+
1501
+ ###########################################################################
1502
+ # Return value. Return nil if input field is empty
1503
+ ###########################################################################
1504
+ def self.get_data(params, name)
1505
+ params['record'][name].blank? ? nil : params['record'][name].split(',')
1506
+ end
1507
+
1508
+ end
1509
+
1349
1510
  ###########################################################################
1350
1511
  # Implementation of html_field DRG CMS form field.
1351
1512
  #
@@ -4,9 +4,9 @@
4
4
  <%= dc_table_title_for_result @records %>
5
5
 
6
6
  <% unless @records.nil? %>
7
- <%= dc_background_for_result %>
7
+ <%= dc_background_for_result(:start) %>
8
+
8
9
  <tr><%= dc_header_for_result %></tr>
9
-
10
10
  <% for document in @records %>
11
11
  <%= dc_row_for_result(document) %>
12
12
  <%= dc_actions_for_result(document) %>
@@ -14,8 +14,7 @@
14
14
  </tr>
15
15
  <% end %>
16
16
 
17
- </table>
18
- </div>
17
+ <%= dc_background_for_result(:end) %>
19
18
  <% end %>
20
19
 
21
20
  </div>
@@ -61,6 +61,7 @@ en:
61
61
  rails_view: Rails view
62
62
  design: Standard design
63
63
  request_processor: Request processor
64
+ inherit_policy: Policy from site
64
65
 
65
66
  dc_design:
66
67
  tabletitle: Designs
@@ -225,6 +226,7 @@ en:
225
226
  link_prepend: Link prepend
226
227
  active: Active
227
228
  dc_menu_items: Menu items
229
+ dc_site_id: Site
228
230
 
229
231
  dc_menu_item:
230
232
  tabletitle: Menu items
@@ -498,6 +500,11 @@ en:
498
500
  public: Is public
499
501
  sort: Default sort
500
502
 
503
+ dc_memory:
504
+ fields: General
505
+ ztab: Advanced
506
+ dc_element: Element name
507
+
501
508
  # help for forms #####################################################
502
509
 
503
510
  help:
@@ -528,6 +535,7 @@ en:
528
535
  design: Standard design can also be defined at the site level
529
536
  dc_parts: Parts contained in site
530
537
  request_processor: Method which will provide output instead of dc_process_default_request
538
+ inherit_policy: Use policy defined on other site
531
539
 
532
540
  dc_user:
533
541
  username: Username
@@ -633,7 +641,7 @@ en:
633
641
  link_prepend: Link field usually holds direct link to document. Prepand field holds data, that has to be prepanded to the link.
634
642
  active: Active
635
643
  dc_simple_menu: Menu items
636
- dc_site_id: Site this menu belongs to
644
+ dc_site_id: Site to which this menu belongs to
637
645
 
638
646
  dc_simple_menu_item:
639
647
  caption: Caption of menu
@@ -654,7 +662,7 @@ en:
654
662
  active: Active
655
663
  link_prepend: Link field usually holds direct link to document. Prepand field holds data, that has to be prepanded to the link.
656
664
  dc_menu_items: Menu items
657
- dc_site_id: Site this menu belongs to
665
+ dc_site_id: Site to which this menu belongs to
658
666
 
659
667
  dc_menu_item:
660
668
  caption: Caption of menu item
@@ -857,4 +865,4 @@ en:
857
865
  filter: Filter definition in YAML
858
866
  public: Filter is available to all users
859
867
  sort: Default sort when selecting filter
860
-
868
+