drg_cms 0.6.1.6 → 0.6.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +203 -24
  3. data/app/assets/javascripts/drg_cms/drg_cms.js +183 -95
  4. data/app/assets/stylesheets/drg_cms/drg_cms.css +542 -509
  5. data/app/assets/stylesheets/drg_cms_application.css +1 -1
  6. data/app/assets/stylesheets/drg_cms_cms.css +1 -4
  7. data/app/controllers/cmsedit_controller.rb +25 -103
  8. data/app/controllers/dc_common_controller.rb +6 -5
  9. data/app/controls/browse_models_control.rb +15 -26
  10. data/app/controls/cmsedit_control.rb +125 -0
  11. data/app/controls/dc_help_control.rb +1 -1
  12. data/app/controls/dc_page_control.rb +0 -1
  13. data/app/controls/dc_poll_result_control.rb +1 -1
  14. data/app/controls/dc_report.rb +1 -1
  15. data/app/forms/all_options.yml +1 -1
  16. data/app/forms/cms_menu.yml +24 -24
  17. data/app/forms/dc_browse_fields.yml +13 -9
  18. data/app/forms/dc_poll_result_export.yml +1 -1
  19. data/app/helpers/cms_common_helper.rb +7 -5
  20. data/app/helpers/cms_edit_helper.rb +52 -45
  21. data/app/helpers/cms_helper.rb +76 -40
  22. data/app/helpers/cms_index_helper.rb +180 -139
  23. data/app/helpers/dc_application_helper.rb +37 -43
  24. data/app/models/concerns/dc_page_concern.rb +1 -1
  25. data/app/models/dc_filter.rb +30 -22
  26. data/app/models/dc_json_ld.rb +1 -1
  27. data/app/models/dc_part.rb +19 -9
  28. data/app/models/drgcms_form_fields/drgcms_field.rb +10 -4
  29. data/app/models/drgcms_form_fields/link_to.rb +1 -1
  30. data/app/models/drgcms_form_fields/multitext_autocomplete.rb +5 -5
  31. data/app/models/drgcms_form_fields/readonly.rb +3 -0
  32. data/app/models/drgcms_form_fields/select.rb +8 -7
  33. data/app/models/drgcms_form_fields/text_autocomplete.rb +2 -2
  34. data/app/renderers/dc_part_renderer.rb +1 -1
  35. data/app/renderers/dc_poll_renderer.rb +1 -1
  36. data/app/views/cmsedit/_edit_stuff.html.erb +12 -12
  37. data/app/views/cmsedit/login.html.erb +1 -1
  38. data/app/views/dc_common/paste_clipboard.html.erb +1 -1
  39. data/config/locales/drgcms_en.yml +2 -1
  40. data/config/locales/drgcms_sl.yml +2 -1
  41. data/config/locales/kaminari.yml +1 -1
  42. data/drg_cms.gemspec +1 -1
  43. data/lib/drg_cms/version.rb +1 -1
  44. data/lib/drg_cms.rb +4 -4
  45. metadata +4 -5
  46. data/app/views/cmsedit/__remove_edit_stuff.js.erb +0 -6
  47. data/app/views/cmsedit/__show.html.erb +0 -21
@@ -159,7 +159,7 @@ $(function() {
159
159
  * record_name: will replace value of record[name] field on a form with supplied value
160
160
  *
161
161
  * msg_error: will display error message.
162
- * msg_warn: will display warning message.
162
+ * msg_warning: will display warning message.
163
163
  * msg_info: will display informational message.
164
164
  *
165
165
  * popup: will display popup message
@@ -246,11 +246,17 @@ process_json_result = function(json) {
246
246
  /**** display popup message ****/
247
247
  case 'popup':
248
248
  if (selector == 'url') {
249
- $('#popup').bPopup({ loadUrl: value });
249
+ $('#popup').bPopup({ loadUrl: value,
250
+ transition: 'slideDown', transitionClose: 'slideDown', speed: 300,
251
+ opacity: 0, position: ['auto', 20],
252
+ closeClass: 'dc-link' });
250
253
  }
251
254
  else {
252
255
  $('#popup').html(value);
253
- $('#popup').bPopup({speed: 650, transition: 'slideUp', position: ['auto',1]});
256
+ $('#popup').bPopup( {
257
+ transition: 'slideDown', transitionClose: 'slideDown', speed: 300,
258
+ opacity: 0, position: ['auto', 20],
259
+ closeClass: 'dc-link' });
254
260
  }
255
261
  break;
256
262
 
@@ -395,7 +401,7 @@ process_parent_form_updates = function(element) {
395
401
  /*****************************************************************
396
402
  * Toggle show and hide div
397
403
  ******************************************************************/
398
- dc_toggle_div = function(div) {
404
+ dc_div_toggle = function(div) {
399
405
  if ($(div).is(":visible")) {
400
406
  $(div).slideUp();
401
407
  } else {
@@ -403,17 +409,55 @@ dc_toggle_div = function(div) {
403
409
  }
404
410
  };
405
411
 
412
+ /*****************************************************************
413
+ * Process simple ajax call
414
+ ******************************************************************/
415
+ simple_ajax_call = function(url) {
416
+ $.ajax({
417
+ url: url,
418
+ success: function(data) { process_json_result(data); }
419
+ });
420
+ };
421
+
406
422
  /*****************************************************************
407
423
  * Return value of the input field on a form
408
424
  ******************************************************************/
409
- function dc_get_field_value(field_name) {
425
+ function dc_field_get_value(field_name) {
410
426
  field_name = field_name.replace('record_', '');
411
427
  let field = $('[name="record[' + field_name + ']"]');
412
428
  return field.val();
413
429
  }
414
430
 
431
+ /*****************************************************************
432
+ * Will process data-fields attribute and add field values as parameters to url
433
+ ******************************************************************/
434
+ function dc_url_add_params(form, url) {
435
+ // check if data-fields attribute present
436
+ let fields = form.getAttribute("data-fields");
437
+ if (fields === null) return url;
438
+ // url might already contain ?
439
+ let form_parms = '?';
440
+ if (url.match(/\?/)) form_parms = '';
441
+
442
+ fields.split(',').forEach( function(field) {
443
+ let value = dc_field_get_value(field);
444
+ if (value) form_parms += '&' + field + '=' + value;
445
+ });
446
+ return url + form_parms;
447
+ }
448
+
415
449
  /*******************************************************************
416
- *
450
+ * Copy div text to clipboard
451
+ *******************************************************************/
452
+ function dc_copy_to_clipboard(div) {
453
+ let copyText = document.getElementById(div).innerText;
454
+ console.log(copyText);
455
+ /* Copy the text inside the text field */
456
+ navigator.clipboard.writeText(copyText);
457
+ }
458
+
459
+ /*******************************************************************
460
+ * Events start here
417
461
  *******************************************************************/
418
462
  $(document).ready( function() {
419
463
  /* This could be the way to focus on first input field on document open
@@ -476,7 +520,7 @@ $(document).ready( function() {
476
520
  * Popup CMS edit menu option clicked
477
521
  *******************************************************************/
478
522
  $('.drgcms_popmenu_item').on('click',function(e) {
479
- url = e.target.getAttribute("data-url");
523
+ let url = e.target.getAttribute("data-url");
480
524
  $('#iframe_cms').attr('src', url);
481
525
  // $('#iframe_cms').width(1000).height(1000);
482
526
  // scroll to top of page and hide menu
@@ -487,13 +531,22 @@ $(document).ready( function() {
487
531
  /*******************************************************************
488
532
  * Sort action clicked on cmsedit
489
533
  *******************************************************************/
490
- $('.drgcms_sort').change( function(e) {
534
+ $('.dc-sort-select').change( function(e) {
491
535
  let table = e.target.getAttribute("data-table");
492
536
  let form = e.target.getAttribute("data-form");
493
537
  if (form === null) form = table;
494
538
  let sort = e.target.value;
495
- e.target.value = null;
496
- window.location.href = "/cmsedit?sort=" + sort + "&table=" + table + "&form_name=" + form;
539
+ // e.target.value = null;
540
+ let url = "/cmsedit/run?control=cmsedit.sort&sort=" + sort + "&table=" + table + "&form_name=" + form;
541
+ simple_ajax_call(url);
542
+ });
543
+
544
+ /*******************************************************************
545
+ * Click on field name in result header perform sort action
546
+ *******************************************************************/
547
+ $('.dc-result-header span').on('click',function(e) {
548
+ let url = e.target.getAttribute("data-url");
549
+ simple_ajax_call(url);
497
550
  });
498
551
 
499
552
  /*******************************************************************
@@ -660,6 +713,14 @@ $(document).ready( function() {
660
713
  }
661
714
  });
662
715
  });
716
+
717
+ /*******************************************************************
718
+ * Click on filter off
719
+ *******************************************************************/
720
+ $('.mi-search_off').on('click', function(e) {
721
+ let url = $(this).parents('.dc-filter').attr("data-url");
722
+ if (url.length > 5) simple_ajax_call(url);
723
+ });
663
724
 
664
725
  /*******************************************************************
665
726
  * Process action submit button click.
@@ -682,33 +743,42 @@ $(document).ready( function() {
682
743
  form.submit();
683
744
  });
684
745
 
685
- /*******************************************************************
686
- Will open a new window with URL specified.
687
- ********************************************************************/
688
- $('.dc-window-open').on('click', function(e) {
689
- // confirmation if required
690
- if (confirmation_is_cancled(this)) { return false; }
691
-
692
- let url = this.getAttribute("data-url");
693
- let title = this.getAttribute("title");
694
- let w = this.getAttribute("data-x") || 1000;
695
- let h = this.getAttribute("data-y") || 800;
696
- // add fields values from current formto url
697
- let fields = this.getAttribute("data-fields");
698
- if (fields) {
699
- let form_parms = '?';
700
- // ? separator already in url
701
- if (url.match(/\?/)) { form_parms = ''; }
702
- fields.split(',').forEach( function(field) {
703
- let value = dc_get_field_value(field);
704
- if (value) {form_parms += '&' + field + '=' + value;}
705
- });
706
- url += form_parms;
707
- }
746
+ /*******************************************************************
747
+ Will open a new window with URL specified.
748
+ ********************************************************************/
749
+ $('.dc-window-open').on('click', function(e) {
750
+ // confirmation if required
751
+ if (confirmation_is_cancled(this)) return false;
708
752
 
709
- let win = popup_window(url, title, window, w, h);
710
- win.focus();
711
- });
753
+ let url = this.getAttribute("data-url");
754
+ let title = this.getAttribute("title");
755
+ let w = this.getAttribute("data-x") || 1000;
756
+ let h = this.getAttribute("data-y") || 800;
757
+
758
+ url = dc_url_add_params(this, url)
759
+ let win = popup_window(url, title, window, w, h);
760
+ win.focus();
761
+ });
762
+
763
+ /*******************************************************************
764
+ Will open a new popup with URL specified.
765
+ ********************************************************************/
766
+ $('.dc-popup-open').on('click', function(e) {
767
+ // confirmation if required
768
+ if (confirmation_is_cancled(this)) return false;
769
+
770
+ let url = this.getAttribute("data-url");
771
+ let title = this.getAttribute("title");
772
+ let w = this.getAttribute("data-x") || 1000;
773
+ let h = this.getAttribute("data-y") || 800;
774
+
775
+ url = dc_url_add_params(this, url)
776
+ $('#popup').bPopup({ loadUrl: url,
777
+ transition: 'slideDown', transitionClose: 'slideDown', speed: 300,
778
+ opacity: 0, position: ['auto', 20],
779
+ closeClass: 'dc-link'
780
+ });
781
+ });
712
782
 
713
783
  /*******************************************************************
714
784
  * Animate button on click
@@ -724,20 +794,7 @@ $('.dc-window-open').on('click', function(e) {
724
794
  $(this).toggleClass('dc-animate-button');
725
795
  });
726
796
  */
727
- /*******************************************************************
728
- * Animate button on click
729
- *******************************************************************/
730
- $('.dc-animate').mousedown( function() {
731
- $(this).toggleClass('dc-animate-button');
732
- });
733
-
734
- /*******************************************************************
735
- * Animate button on click
736
- *******************************************************************/
737
- $('.dc-animate').mouseup( function() {
738
- $(this).toggleClass('dc-animate-button');
739
- });
740
-
797
+
741
798
  /*******************************************************************
742
799
  * App menu option clicked
743
800
  *******************************************************************/
@@ -758,7 +815,7 @@ $('.dc-window-open').on('click', function(e) {
758
815
  /*******************************************************************
759
816
  * Display spinner on link with spinner, submit link
760
817
  *******************************************************************/
761
- $('.dc-link-spinner').on('click', function(e) {
818
+ $('.dc-link.spin').on('click', function(e) {
762
819
  $('.dc-spinner').show();
763
820
  });
764
821
 
@@ -791,7 +848,7 @@ $('.dc-window-open').on('click', function(e) {
791
848
 
792
849
  /**********************************************************************
793
850
  * When filter_field (field name) is selected on filter subform this routine finds
794
- * and displays apropriate span with input field.
851
+ * and displays appropriate span with input field.
795
852
  **********************************************************************/
796
853
  $('#filter_field').on('change', function() {
797
854
  if (this.value.length > 0) {
@@ -929,11 +986,10 @@ $('.dc-window-open').on('click', function(e) {
929
986
  *******************************************************************/
930
987
  $('#_record__filter_field').keydown( function(e) {
931
988
  if (e.which == '13' || e.which == '9') {
932
- var url = $(this).parents('span').attr("data-url");
989
+ let url = $(this).parents('span').attr("data-url");
933
990
  url = url + "&filter_value=" + this.value;
934
- location.href = url;
935
- return false;
936
- }
991
+ simple_ajax_call(url);
992
+ };
937
993
  });
938
994
 
939
995
  /*******************************************************************
@@ -951,7 +1007,7 @@ $('.dc-window-open').on('click', function(e) {
951
1007
  value = field.val();
952
1008
  }
953
1009
  url = url + "&filter_value=" + value;
954
- location.href = url;
1010
+ simple_ajax_call(url);
955
1011
  });
956
1012
 
957
1013
  /*******************************************************************
@@ -959,47 +1015,77 @@ $('.dc-window-open').on('click', function(e) {
959
1015
  *******************************************************************/
960
1016
  $('#open_drgcms_filter').on('click', function(e) {
961
1017
  $('#drgcms_filter').bPopup({
962
- speed: 650,
963
- transition: 'slideDown'
964
- });
1018
+ transition: 'slideDown', transitionClose: 'slideDown', speed: 300,
1019
+ opacity: 0, position: ['auto', 20],
1020
+ closeClass: 'dc-link' });
965
1021
  });
966
1022
 
967
1023
  /*******************************************************************
968
1024
  * Click on preview selected image
969
1025
  *******************************************************************/
970
1026
  $('.dc-image-preview').on('click', function(e) {
971
- // var img = $('.img1 img').attr('src');
972
- var img = $(this).children(":first").attr('src');
973
- $('#dc-image-preview').bPopup({
974
- content:'image', //'ajax', 'iframe' or 'image'
975
- contentContainer:'#dc-image-preview',
976
- loadUrl: img
977
- });
1027
+ let img = $(this).children(":first").attr('src');
1028
+ $('#dc-image-preview').bPopup({
1029
+ content: 'image', //'ajax', 'iframe' or 'image'
1030
+ contentContainer: '#dc-image-preview',
1031
+ loadUrl: img,
1032
+ opacity: 0
1033
+ });
978
1034
  });
979
1035
 
980
1036
  /*******************************************************************
981
- *
1037
+ * Set new filter
982
1038
  *******************************************************************/
983
- $('.drgcms_popup_submit').on('click', function(e) {
984
- //e.preventDefault();
985
- url = $(this).attr( 'data-url' );
986
- field = $('select#filter_field1').val();
987
- oper = $('select#filter_oper').val();
988
- location.href = url + '&filter_field=' + field + '&filter_oper=' + oper
989
- // Still opening in new window
990
- // iframe = parent.document.getElementsByTagName("iframe")[0].getAttribute("id");
991
- // loc = url + '&filter_field=' + field + '&filter_oper=' + oper
992
- // $('#'+iframe).attr('src', loc);
993
- // parent.document.getElementById(iframe).src = loc
1039
+ $('.dc-filter-set').on('click', function(e) {
1040
+ let url = $(this).attr( 'data-url' );
1041
+ let field = $('select#filter_field1').val();
1042
+ let operation = $('select#filter_oper').val();
1043
+ url = url + '&filter_field=' + field + '&filter_oper=' + operation
1044
+ simple_ajax_call(url);
994
1045
  });
995
-
996
- /*******************************************************************
997
- * Toggle one cmsedit menu level
998
- *******************************************************************/
999
- $('.cmsedit-top-level-menu').on('click', function(e) {
1000
- $(e.target).find('ul').toggle('fast');
1046
+
1047
+ /*******************************************************************
1048
+ * Toggle one cmsedit menu level
1049
+ *******************************************************************/
1050
+ $('.cmsedit-top-level-menu div').on('click', function(e) {
1051
+ $(e.target).siblings('ul').toggle('fast');
1052
+ $(e.target).toggleClass('expanded');
1053
+ });
1054
+
1055
+ /*******************************************************************
1056
+ * Toggle result set record menu
1057
+ *
1058
+ * This and additional two event hadlers provide expected behavior of submenus popup and close.
1059
+ *******************************************************************/
1060
+ $('.dc-result-submenu .mi-more_vert').on('click', function(e) {
1061
+ let ul = $(e.target).siblings('ul');
1062
+ // hide last selected menu if not the same
1063
+ if (typeof dc_last_menu_selected !== 'undefined') { dc_last_menu_selected.hide(); }
1064
+ // if menu is past the bottom fix it to bottom
1065
+ let menu_bottom = ul.height() + ul.parent().position().top + 20;
1066
+ if (menu_bottom > $(document).height()) ul.css('bottom', 0);
1067
+ ul.show();
1068
+ dc_last_menu_selected = ul;
1001
1069
  });
1002
-
1070
+
1071
+ /*******************************************************************
1072
+ * Result record menu has lost focus. Hide menu.
1073
+ *******************************************************************/
1074
+ $('.dc-result-submenu ul').hover(function(e) {
1075
+ },
1076
+ function(e) {
1077
+ dc_last_menu_selected.hide();
1078
+ dc_last_menu_selected = undefined;
1079
+ });
1080
+
1081
+ /*******************************************************************
1082
+ * Result set record menu is left open if action is canceled. Ex. delete confirm. This will hide menu.
1083
+ *******************************************************************/
1084
+ $('.dc-result-submenu ul li').on('click', function(e) {
1085
+ console.log('ups');
1086
+ if (typeof dc_last_menu_selected !== 'undefined') dc_last_menu_selected.hide();
1087
+ });
1088
+
1003
1089
  /*******************************************************************
1004
1090
  * Resize result table columns. For now an idea.
1005
1091
  *******************************************************************/
@@ -1131,14 +1217,14 @@ $('.dc-window-open').on('click', function(e) {
1131
1217
  *******************************************************************/
1132
1218
  $('.dc-result-header .th i').hover( function() {
1133
1219
  old_sort_icon = '';
1134
- // save old sort icon and replace it with filter icon
1220
+ // save old sort icon and replace it with filter icon
1135
1221
  $.each( $(this).attr("class").split(/\s+/),
1136
1222
  function(index, item) { if (item.match('sort')) { old_sort_icon = item}; }
1137
1223
  );
1138
- $(this).removeClass(old_sort_icon).addClass('fa-filter');
1139
- // bring back old sort icon
1140
- }, function(){
1141
- $(this).removeClass('fa-filter').addClass(old_sort_icon);
1224
+ $(this).removeClass(old_sort_icon).addClass('mi-ads_click');
1225
+ // bring back old sort icon
1226
+ }, function() {
1227
+ $(this).removeClass('mi-ads_click').addClass(old_sort_icon);
1142
1228
  });
1143
1229
 
1144
1230
  /*******************************************************************
@@ -1146,6 +1232,8 @@ $('.dc-window-open').on('click', function(e) {
1146
1232
  *******************************************************************/
1147
1233
  $('.dc-result-header .th i').click( function(e) {
1148
1234
  e.preventDefault();
1235
+ if ($(this).hasClass('no-filter')) return;
1236
+
1149
1237
  // additional click will close dialog when visible
1150
1238
  if ($('.filter-popup').is(':visible')) {
1151
1239
  $('.filter-popup').hide();
@@ -1156,7 +1244,7 @@ $('.dc-window-open').on('click', function(e) {
1156
1244
  let field_name = header.attr("data-name");
1157
1245
  $('.filter-popup').attr('data-name', field_name);
1158
1246
  // change popup position and show
1159
- $('.filter-popup').css({'top':e.pageY+5,'left':e.pageX, 'position':'absolute'});
1247
+ $('.filter-popup').css({'top': e.pageY + 5, 'left': e.pageX, 'position': 'absolute'});
1160
1248
  $('.filter-popup').show();
1161
1249
  });
1162
1250
 
@@ -1171,7 +1259,7 @@ $('.dc-window-open').on('click', function(e) {
1171
1259
  let field_name = parent.data("name");
1172
1260
 
1173
1261
  url = url + '&filter_field=' + field_name + '&filter_oper=' + operator;
1174
- window.location.href = url;
1262
+ simple_ajax_call(url);
1175
1263
  });
1176
1264
 
1177
1265
  /*****************************************************************
@@ -1179,14 +1267,14 @@ $('.dc-window-open').on('click', function(e) {
1179
1267
  ******************************************************************/
1180
1268
  $(".dc-handle").click(function() {
1181
1269
  let div = this.getAttribute("data-div");
1182
- dc_toggle_div(div);
1270
+ dc_div_toggle(div);
1183
1271
  });
1184
1272
 
1185
1273
  /*******************************************************************
1186
1274
  * Show-Hide CMS menu on hamburger click
1187
1275
  *******************************************************************/
1188
1276
  $('#menu-hamburger').on('click', function(e) {
1189
- $('.cmsedit-container #menu').toggleClass('visible');
1277
+ $('.cmsedit-container #cms-menu').toggleClass('visible');
1190
1278
  });
1191
1279
 
1192
1280
  });