drg_cms 0.4.54 → 0.4.57

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,6 +35,7 @@ class DcMenu
35
35
  field :name, type: String
36
36
  field :description, type: String
37
37
  field :div_name, type: String
38
+ field :link_prepend, type: String
38
39
  field :css, type: String
39
40
  field :active, type: Boolean, default: true
40
41
  field :created_by, type: BSON::ObjectId
@@ -34,6 +34,7 @@ class DcMenuItem
34
34
  field :caption, type: String
35
35
  field :picture, type: String
36
36
  field :link, type: String
37
+ field :link_prepend, type: String
37
38
  field :target, type: String
38
39
  field :page_id, type: BSON::ObjectId
39
40
  field :order, type: Integer
@@ -34,6 +34,7 @@ class DcSimpleMenu
34
34
  field :name, type: String
35
35
  field :description, type: String
36
36
  field :div_name, type: String
37
+ field :link_prepend, type: String
37
38
  field :css, type: String
38
39
  field :active, type: Boolean, default: true
39
40
  field :created_by, type: BSON::ObjectId
@@ -45,6 +45,7 @@ class DcSimpleMenuItem
45
45
  field :caption, type: String
46
46
  field :picture, type: String
47
47
  field :link, type: String
48
+ field :link_prepend, type: String
48
49
  field :target, type: String
49
50
  field :order, type: Integer, default: 10
50
51
  field :submenu, type: String
@@ -27,6 +27,7 @@
27
27
  module DcUserConcern
28
28
  extend ActiveSupport::Concern
29
29
  included do
30
+ @@countries = nil
30
31
 
31
32
  include Mongoid::Document
32
33
  include Mongoid::Timestamps
@@ -89,6 +90,23 @@ def do_before_save
89
90
  self.email = "unknown@#{self.id}" if self.email.to_s.strip.size < 5
90
91
  end
91
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
+
92
110
  end
93
111
  end
94
112
 
@@ -156,6 +156,19 @@ def hash_to_options(hash)
156
156
  options.chomp(',')
157
157
  end
158
158
 
159
+ ####################################################################
160
+ # Checks if field name exists in document and alters record parameters if necesary.
161
+ # Method was added after fields that do not belong to current edited document
162
+ # were added to forms. Valid nonexisting form field names must start with underscore (_) letter.
163
+ #
164
+ # Return:
165
+ # String: 'record' or '_record' when valid nonexisting field is used
166
+ ####################################################################
167
+ def record_text_for(name)
168
+ (!@record.respond_to?(name) and name[0,1] == '_') ? '_record' : 'record'
169
+ end
170
+
171
+
159
172
  ###########################################################################
160
173
  # Default get_data method for retrieving data from parameters. Class method is called
161
174
  # for every entry field defined on form before field value is saved to database.
@@ -213,7 +226,8 @@ class HiddenField < DrgcmsField
213
226
  def render
214
227
  set_initial_value
215
228
  value = @yaml['html']['value'] ? @yaml['html']['value'] : @record[@yaml['name']]
216
- @parent.hidden_field('record', @yaml['name'], value: value)
229
+ record = record_text_for(@yaml['name'])
230
+ @parent.hidden_field(record, @yaml['name'], value: value)
217
231
  end
218
232
  end
219
233
 
@@ -350,8 +364,10 @@ def render
350
364
  _name = '_' + @yaml['name']
351
365
  @html << '<table class="ui-autocomplete-table"><td>'
352
366
  @html << @parent.link_to(@parent.image_tag('drg_cms/add.png', class: 'dc-link-img'), '#',onclick: 'return false;') # dummy add. But it is usefull.
353
- @html << ' ' << @parent.text_field('record', _name, @yaml['html']) # text field for autocomplete
354
- @html << "<div id =\"record#{@yaml['name']}\">" # div to list active records
367
+
368
+ record = record_text_for(@yaml['name'])
369
+ @html << ' ' << @parent.text_field(record, _name, @yaml['html']) # text field for autocomplete
370
+ @html << "<div id =\"#{record}#{@yaml['name']}\">" # div to list active records
355
371
  # find value for each field inside categories
356
372
  unless @record[@yaml['name']].nil?
357
373
  @record[@yaml['name']].each do |element|
@@ -366,8 +382,8 @@ def render
366
382
  # Related data is missing. It happends.
367
383
  @html << if rec
368
384
  link = @parent.link_to(@parent.image_tag('drg_cms/x.png', class: 'dc-link-img'), '#',
369
- onclick: "$('##{rec.id}').hide(); var v = $('#record_#{@yaml['name']}_#{rec.id}'); v.val(\"-\" + v.val());return false;")
370
- field = @parent.hidden_field('record', "#{@yaml['name']}_#{rec.id}", value: element)
385
+ onclick: "$('##{rec.id}').hide(); var v = $('##{record}_#{@yaml['name']}_#{rec.id}'); v.val(\"-\" + v.val());return false;")
386
+ field = @parent.hidden_field(record, "#{@yaml['name']}_#{rec.id}", value: element)
371
387
  "<div id=\"#{rec.id}\">#{link} #{rec[field_name]}<br>#{field}</div>"
372
388
  else
373
389
  '** error **'
@@ -377,14 +393,14 @@ def render
377
393
  @html << "</div></td></table>"
378
394
  # Create text for div to be added when new category is selected
379
395
  link = @parent.link_to(@parent.image_tag('drg_cms/x.png', class: 'dc-link-img'), '#',
380
- onclick: "$('#rec_id').hide(); var v = $('#record_#{@yaml['name']}_rec_id'); v.val(\"-\" + v.val());return false;")
381
- field = @parent.hidden_field('record', "#{@yaml['name']}_rec_id", value: 'rec_id')
396
+ onclick: "$('#rec_id').hide(); var v = $('##{record}_#{@yaml['name']}_rec_id'); v.val(\"-\" + v.val());return false;")
397
+ field = @parent.hidden_field(record, "#{@yaml['name']}_rec_id", value: 'rec_id')
382
398
  one_div = "<div id=\"rec_id\">#{link} rec_search<br>#{field}</div>"
383
399
 
384
400
  # JS stuff
385
401
  @js << <<EOJS
386
402
  $(document).ready(function() {
387
- $("#record_#{_name}").autocomplete( {
403
+ $("##{record}_#{_name}").autocomplete( {
388
404
  source: function(request, response) {
389
405
  $.ajax({
390
406
  url: "#{ @parent.url_for( controller: 'dc_common', action: 'autocomplete' )}",
@@ -392,7 +408,6 @@ $(document).ready(function() {
392
408
  dataType: "json",
393
409
  data: { input: request.term, table: "#{table}", search: "#{search}" #{(',id: "'+@yaml['id'] + '"') if @yaml['id']} },
394
410
  success: function(data) {
395
- /* alert(data); */
396
411
  response( $.map( data, function(key) {
397
412
  return key;
398
413
  }));
@@ -403,8 +418,8 @@ $(document).ready(function() {
403
418
  var div = '#{one_div}';
404
419
  div = div.replace(/rec_id/g, ui.item.id)
405
420
  div = div.replace('rec_search', ui.item.value)
406
- $("#record#{@yaml['name']}").append(div);
407
- $("#record_#{_name}").val('');
421
+ $("##{record}#{@yaml['name']}").append(div);
422
+ $("##{record}_#{_name}").val('');
408
423
  },
409
424
  minLength: 2
410
425
  });
@@ -464,7 +479,7 @@ def do_eval(e)
464
479
  end
465
480
 
466
481
  ###########################################################################
467
- # Crete choices array for select field.
482
+ # Create choices array for select field.
468
483
  ###########################################################################
469
484
  def get_choices
470
485
  begin
@@ -481,8 +496,9 @@ def get_choices
481
496
  choices.class == String ?
482
497
  choices.chomp.split(',').inject([]) {|r,v| r << (v.match(':') ? v.split(':') : v )} :
483
498
  choices
484
- rescue
485
- [] # return empty array when error occures
499
+ rescue Exception => e
500
+ p "Error in select eval. #{e.message}"
501
+ ['error'] # return empty array when error occures
486
502
  end
487
503
  end
488
504
 
@@ -511,7 +527,8 @@ def render
511
527
  set_initial_value('html','selected')
512
528
  #
513
529
  @yaml['html'].symbolize_keys!
514
- @html << @parent.select('record', @yaml['name'], get_choices, @yaml['html'])
530
+ record = record_text_for(@yaml['name'])
531
+ @html << @parent.select(record, @yaml['name'], get_choices, @yaml['html'])
515
532
  self
516
533
  end
517
534
 
@@ -534,10 +551,11 @@ def render
534
551
  # If choices are present split them to set checked and unchecked value
535
552
  @yaml['checked_value'], @yaml['unchecked_value'] = @yaml['choices'].split(',') if @yaml['choices']
536
553
  @yaml['html'].symbolize_keys!
554
+ record = record_text_for(@yaml['name'])
537
555
  @html << if @yaml['checked_value']
538
- @parent.check_box('record', @yaml['name'], @yaml['html'], @yaml['checked_value'], @yaml['unchecked_value'] || '0')
556
+ @parent.check_box(record, @yaml['name'], @yaml['html'], @yaml['checked_value'], @yaml['unchecked_value'] || '0')
539
557
  else
540
- @parent.check_box('record', @yaml['name'], @yaml['html'])
558
+ @parent.check_box(record, @yaml['name'], @yaml['html'])
541
559
  end
542
560
  self
543
561
  end
@@ -558,7 +576,8 @@ end
558
576
  end
559
577
 
560
578
  ###########################################################################
561
- # Implementation of link_to DRG CMS form field.
579
+ # Implementation of link_to DRG CMS form field. link_to form field is mostly used by polls but can
580
+ # be also incorporated in the middle of form.
562
581
  ###########################################################################
563
582
  class LinkTo < DrgcmsField
564
583
 
@@ -582,7 +601,8 @@ end
582
601
  end
583
602
 
584
603
  ###########################################################################
585
- # Create submit_tag form field
604
+ # Create submit_tag form field. submit_tag form field is mostly used by polls but can
605
+ # be also incorporated in the middle of form.
586
606
  ###########################################################################
587
607
  class SubmitTag < DrgcmsField
588
608
 
@@ -612,7 +632,8 @@ class PasswordField < DrgcmsField
612
632
  def render
613
633
  return self if @readonly
614
634
  @yaml['html'] ||= {}
615
- @html << @parent.password_field('record', @yaml['name'], @yaml['html'])
635
+ record = record_text_for(@yaml['name'])
636
+ @html << @parent.password_field(record, @yaml['name'], @yaml['html'])
616
637
  self
617
638
  end
618
639
  end
@@ -634,7 +655,8 @@ def render
634
655
  set_initial_value('options','default')
635
656
  @yaml['options'].symbolize_keys!
636
657
  @yaml['html'].symbolize_keys!
637
- @html << @parent.date_select('record', @yaml['name'], @yaml['options'], @yaml['html'])
658
+ record = record_text_for(@yaml['name'])
659
+ @html << @parent.date_select(record, @yaml['name'], @yaml['options'], @yaml['html'])
638
660
  self
639
661
  end
640
662
 
@@ -674,7 +696,8 @@ def render
674
696
  @yaml['options'].symbolize_keys!
675
697
  @yaml['html'].symbolize_keys!
676
698
  #
677
- @html << @parent.datetime_select('record', @yaml['name'], @yaml['options'], @yaml['html'])
699
+ record = record_text_for(@yaml['name'])
700
+ @html << @parent.datetime_select(record, @yaml['name'], @yaml['options'], @yaml['html'])
678
701
  self
679
702
  end
680
703
 
@@ -708,10 +731,11 @@ def render
708
731
  @yaml['options']['format'] ||= "'#{t('datetimepicker.formats.date')}'"
709
732
  @yaml['options']['timepicker'] = false
710
733
  #
711
- @html << @parent.text_field('record', @yaml['name'], @yaml['html'])
734
+ record = record_text_for(@yaml['name'])
735
+ @html << @parent.text_field(record, @yaml['name'], @yaml['html'])
712
736
  @js << <<EOJS
713
737
  $(document).ready(function() {
714
- $("#record_#{@yaml['name']}").datetimepicker( {
738
+ $("##{record}_#{@yaml['name']}").datetimepicker( {
715
739
  #{hash_to_options(@yaml['options'])}
716
740
  });
717
741
  });
@@ -749,10 +773,11 @@ def render
749
773
  @yaml['options']['lang'] ||= "'#{I18n.locale}'"
750
774
  @yaml['options']['format'] ||= "'#{t('datetimepicker.formats.datetime')}'"
751
775
  #
752
- @html << @parent.text_field('record', @yaml['name'], @yaml['html'])
776
+ record = record_text_for(@yaml['name'])
777
+ @html << @parent.text_field(record, @yaml['name'], @yaml['html'])
753
778
  @js << <<EOJS
754
779
  $(document).ready(function() {
755
- $("#record_#{@yaml['name']}").datetimepicker( {
780
+ $("##{record}_#{@yaml['name']}").datetimepicker( {
756
781
  #{hash_to_options(@yaml['options'])}
757
782
  });
758
783
  });
@@ -784,8 +809,7 @@ def render
784
809
  # search field name
785
810
  if @yaml['search'].class == Hash
786
811
  table = @yaml['search']['table']
787
- ret_name = @yaml['search']['field'] || @yaml['search']['search']
788
- p 'search:search keyword is replaced with field keyword and will be depricated!' if @yaml['search']['search']
812
+ ret_name = @yaml['search']['field']
789
813
  method = @yaml['search']['method']
790
814
  elsif @yaml['search'].match(/\./)
791
815
  table, ret_name, method = @yaml['search'].split('.')
@@ -827,16 +851,17 @@ def render
827
851
  @yaml['html']['value'] = value_displayed
828
852
  #
829
853
  _name = '_' + @yaml['name']
830
- @html << @parent.text_field('record', _name, @yaml['html'])
854
+ record = record_text_for(@yaml['name'])
855
+ @html << @parent.text_field(record, _name, @yaml['html'])
831
856
  if @yaml['with_new']
832
857
  @html << @parent.image_tag('drg_cms/add.png', class: 'in-edit-add', title: t('drgcms.new'),
833
858
  style: "vertical-align: top;", 'data-table' => @yaml['with_new'] )
834
859
  end
835
- @html << @parent.hidden_field('record', @yaml['name'], value: value) # actual value will be in hidden field
860
+ @html << @parent.hidden_field(record, @yaml['name'], value: value) # actual value will be in hidden field
836
861
  # JS stuff
837
862
  @js << <<EOJS
838
863
  $(document).ready(function() {
839
- $("#record_#{_name}").autocomplete( {
864
+ $("##{record}_#{_name}").autocomplete( {
840
865
  source: function(request, response) {
841
866
  $.ajax({
842
867
  url: '/dc_common/autocomplete',
@@ -844,7 +869,6 @@ $(document).ready(function() {
844
869
  dataType: "json",
845
870
  data: { input: request.term, table: "#{table}", search: "#{ret_name}" #{(',id: "'+@yaml['id'] + '"') if @yaml['id']} },
846
871
  success: function(data) {
847
- //alert(data);
848
872
  response( $.map( data, function(key) {
849
873
  return key;
850
874
  }));
@@ -852,7 +876,7 @@ $(document).ready(function() {
852
876
  });
853
877
  },
854
878
  change: function (event, ui) {
855
- $("#record_#{@yaml['name']}").val(ui.item.id);
879
+ $("##{record}_#{@yaml['name']}").val(ui.item.id);
856
880
  },
857
881
  minLength: 2
858
882
  });
@@ -877,7 +901,9 @@ def render
877
901
  @yaml['html'] ||= {}
878
902
  value_send_as = 'p_' + @yaml['name']
879
903
  @yaml['html']['value'] = @parent.params[value_send_as] if @parent.params[value_send_as]
880
- @html << @parent.text_area('record', @yaml['name'], @yaml['html'])
904
+
905
+ record = record_text_for(@yaml['name'])
906
+ @html << @parent.text_area(record, @yaml['name'], @yaml['html'])
881
907
  self
882
908
  end
883
909
  end
@@ -894,7 +920,8 @@ def render
894
920
  return ro_standard if @readonly
895
921
  set_initial_value
896
922
  #
897
- @html << @parent.text_field('record', @yaml['name'], @yaml['html'])
923
+ record = record_text_for(@yaml['name'])
924
+ @html << @parent.text_field( record, @yaml['name'], @yaml['html'])
898
925
  self
899
926
  end
900
927
  end
@@ -913,7 +940,8 @@ def render
913
940
  return ro_standard if @readonly
914
941
  set_initial_value('html','value')
915
942
 
916
- @html << @parent.text_field('record', @yaml['name'], @yaml['html'])
943
+ record = record_text_for(@yaml['name'])
944
+ @html << @parent.text_field( record, @yaml['name'], @yaml['html'])
917
945
  @yaml['html']['class'] = 'text-with-select'
918
946
  @yaml['html'].symbolize_keys!
919
947
  @html << @parent.select( @yaml['name'] + '_', nil, get_choices, { include_blank: true }, { class: 'text-with-select' })
@@ -923,9 +951,9 @@ def render
923
951
  $(document).ready(function() {
924
952
  $('##{@yaml['name']}_').change( function() {
925
953
  if ($(this).val().toString().length > 0) {
926
- $('#record_#{@yaml['name']}').val( $(this).val() );
954
+ $('##{record}_#{@yaml['name']}').val( $(this).val() );
927
955
  }
928
- $('#record_#{@yaml['name']}').focus();
956
+ $('##{record}_#{@yaml['name']}').focus();
929
957
  });
930
958
  });
931
959
  EOJS
@@ -0,0 +1,2 @@
1
+
2
+ <%= iframe_edit1() %>
@@ -24,7 +24,7 @@
24
24
  # English (en) localization for drgCMS
25
25
  en:
26
26
  drgcms:
27
- doc_deleted: Document deleted!
27
+ record_deleted: Document deleted!
28
28
  confirm_delete: Confirm document deletion!
29
29
  confirm_dup: Confirm document duplication!
30
30
  not_authorized: User not authorized for this operation!
@@ -185,6 +185,7 @@ en:
185
185
  description: Description
186
186
  div_name: Menu div
187
187
  css: CSS
188
+ link_prepend: Link prepend
188
189
  active: Active
189
190
  dc_simple_menu_items: Menu items
190
191
  dc_site_id: Site
@@ -195,6 +196,7 @@ en:
195
196
  caption: Caption
196
197
  picture: Picture
197
198
  link: Link
199
+ link_prepend: Link prepend
198
200
  target: Target window
199
201
  order: Order
200
202
  submenu: Submenu
@@ -212,6 +214,7 @@ en:
212
214
  description: Description
213
215
  div_name: Menu div
214
216
  css: CSS
217
+ link_prepend: Link prepend
215
218
  active: Active
216
219
  dc_menu_items: Menu items
217
220
 
@@ -223,6 +226,7 @@ en:
223
226
  caption: Caption
224
227
  picture: Picture
225
228
  link: Link
229
+ link_prepend: Link prepend
226
230
  target: Target window
227
231
  order: Order
228
232
  dc_menu_items: Submenus
@@ -277,6 +281,7 @@ en:
277
281
 
278
282
  name: Name
279
283
  description: Description
284
+ link: Link
280
285
  picture: Picture
281
286
  thumbnail: Thumbnail
282
287
  body: Body
@@ -301,6 +306,7 @@ en:
301
306
 
302
307
  name: Name
303
308
  description: Description
309
+ link: Link
304
310
  picture: Picture
305
311
  thumbnail: Thumbnail
306
312
  body: Body
@@ -591,6 +597,7 @@ en:
591
597
  description: Short description of menu
592
598
  css: CSS for this menu
593
599
  div_name: Div id name around menu area
600
+ link_prepend: Link field usually holds direct link to document. Prepand field holds data, that has to be prepanded to the link.
594
601
  active: Active
595
602
  dc_simple_menu: Menu items
596
603
  dc_site_id: Site this menu belongs to
@@ -599,6 +606,7 @@ en:
599
606
  caption: Caption of menu
600
607
  picture: Picture for the menu
601
608
  link: Link called when menu is chosen
609
+ link_prepend: Link field usually holds direct link to document. Prepand field holds data, that has to be prepanded to the link.
602
610
  target: Target window for the link. Leave empty when same window.
603
611
  order: Order on which menu item is shown. Lower number means prior position.
604
612
  submenu: Submenu captions in form (caption\link).
@@ -611,6 +619,7 @@ en:
611
619
  css: CSS for this menu
612
620
  div_name: Div id name around menu area
613
621
  active: Active
622
+ link_prepend: Link field usually holds direct link to document. Prepand field holds data, that has to be prepanded to the link.
614
623
  dc_menu_items: Menu items
615
624
  dc_site_id: Site this menu belongs to
616
625
 
@@ -618,6 +627,7 @@ en:
618
627
  caption: Caption of menu item
619
628
  picture: Picture for the menu
620
629
  link: Link called when menu is chosen
630
+ link_prepend: Link field usually holds direct link to document. Prepand field holds data, that has to be prepanded to the link.
621
631
  target: Target window for the link. Leave empty when same window.
622
632
  order: Order on which menu item is shown. Lower number means prior position.
623
633
  dc_menu_items: Submenu items
@@ -655,6 +665,7 @@ en:
655
665
  dc_part:
656
666
  name: Parts can be searched by name or by id
657
667
  description: Short description of part
668
+ link: Link when part can be accessed with pretty link
658
669
  picture: Picture contents of part
659
670
  thumbnail: Small version of picture if available
660
671
  body: Content of this part
@@ -675,6 +686,7 @@ en:
675
686
  name: Unique name for piece
676
687
  description: Short description of piece
677
688
  picture: Picture contents of piece
689
+ link: Link when piece can be accessed with pretty link
678
690
  thumbnail: Small version of picture if available
679
691
  body: Content of this piece
680
692
  css: CSS