drg_cms 0.6.0.3 → 0.6.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/drg_cms/drg_cms.js +259 -102
  3. data/app/assets/javascripts/drg_cms_cms.js +1 -1
  4. data/app/assets/stylesheets/drg_cms/drg_cms.css +314 -142
  5. data/app/assets/stylesheets/drg_cms/select-multiple.css +11 -2
  6. data/app/controllers/cmsedit_controller.rb +313 -236
  7. data/app/controllers/dc_application_controller.rb +29 -4
  8. data/app/controllers/dc_common_controller.rb +19 -16
  9. data/app/{controllers → controls}/browse_models_control.rb +0 -0
  10. data/app/{controllers → controls}/dc_page_control.rb +24 -8
  11. data/app/controls/dc_poll_result_control.rb +88 -0
  12. data/app/{controllers → controls}/design_element_settings_control.rb +0 -0
  13. data/app/forms/all_options.yml +11 -3
  14. data/app/forms/cms_menu.yml +22 -18
  15. data/app/forms/dc_design.yml +6 -3
  16. data/app/forms/dc_filter.yml +3 -6
  17. data/app/forms/dc_poll_result.yml +74 -0
  18. data/app/forms/dc_poll_result_export.yml +35 -0
  19. data/app/helpers/cmsedit_edit_helper.rb +471 -0
  20. data/app/helpers/cmsedit_helper.rb +151 -821
  21. data/app/helpers/cmsedit_index_helper.rb +567 -0
  22. data/app/helpers/dc_application_helper.rb +48 -31
  23. data/app/models/{dc_dummy.rb → __dc_dummy.rb} +0 -0
  24. data/app/models/dc_filter.rb +12 -5
  25. data/app/models/dc_memory.rb +8 -1
  26. data/app/models/dc_poll.rb +38 -19
  27. data/app/models/dc_poll_result.rb +44 -0
  28. data/app/models/dc_temp.rb +137 -0
  29. data/app/models/drgcms_form_fields/action.rb +61 -0
  30. data/app/models/drgcms_form_fields/comment.rb +8 -4
  31. data/app/models/drgcms_form_fields/date_picker.rb +7 -6
  32. data/app/models/drgcms_form_fields/date_select.rb +1 -1
  33. data/app/models/drgcms_form_fields/datetime_picker.rb +8 -7
  34. data/app/models/drgcms_form_fields/datetime_select.rb +1 -1
  35. data/app/models/drgcms_form_fields/drgcms_field.rb +39 -7
  36. data/app/models/drgcms_form_fields/embedded.rb +7 -2
  37. data/app/models/drgcms_form_fields/file_field.rb +52 -0
  38. data/app/models/drgcms_form_fields/html_field.rb +1 -1
  39. data/app/models/drgcms_form_fields/multitext_autocomplete.rb +7 -4
  40. data/app/models/drgcms_form_fields/number_field.rb +15 -6
  41. data/app/models/drgcms_form_fields/radio.rb +91 -0
  42. data/app/models/drgcms_form_fields/readonly.rb +1 -1
  43. data/app/models/drgcms_form_fields/select.rb +14 -2
  44. data/app/models/drgcms_form_fields/text_area.rb +1 -1
  45. data/app/models/drgcms_form_fields/text_autocomplete.rb +1 -1
  46. data/app/models/drgcms_form_fields/text_field.rb +1 -1
  47. data/app/models/drgcms_form_fields/text_with_select.rb +6 -3
  48. data/app/models/drgcms_form_fields/tree_select.rb +11 -3
  49. data/app/renderers/dc_poll_renderer.rb +29 -11
  50. data/app/views/cmsedit/{remove_edit_stuff.js.erb → __remove_edit_stuff.js.erb} +0 -0
  51. data/app/views/cmsedit/{show.html.erb → __show.html.erb} +0 -0
  52. data/app/views/cmsedit/_edit_stuff.html.erb +2 -4
  53. data/app/views/cmsedit/_form.html.erb +4 -3
  54. data/app/views/cmsedit/_result.html.erb +2 -3
  55. data/app/views/cmsedit/edit.html.erb +2 -1
  56. data/app/views/cmsedit/index.html.erb +6 -1
  57. data/app/views/cmsedit/new.html.erb +1 -1
  58. data/config/locales/drgcms_en.yml +7 -0
  59. data/config/locales/drgcms_sl.yml +8 -1
  60. data/config/locales/models_en.yml +13 -4
  61. data/config/locales/models_sl.yml +13 -2
  62. data/drg_cms.gemspec +1 -1
  63. data/lib/drg_cms.rb +1 -0
  64. data/lib/drg_cms/version.rb +1 -1
  65. data/lib/generators/new_drg_form/new_drg_form_generator.rb +7 -2
  66. metadata +20 -13
  67. data/app/assets/stylesheets/drg_cms/__jquery-ui.css +0 -339
  68. data/test/fixtures/drg_cms_test_data.rb +0 -87
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b6e9f20a0a4ab04d8c5faa736a556f29a9a9709a324fb5438e66f4563c985de
4
- data.tar.gz: e6c20a842d10be10c73a4d3129caafc43445a6552d0f6cbabd981b05981d20f2
3
+ metadata.gz: ce40eeb1428b5e11a14613978b213af29ad3a26c4f68a0addc2987135df60ece
4
+ data.tar.gz: 880a2bca2c8dac8e5e5cb5723e6acca268a9f0f4f439a4befe6a34b7b4a1dbd3
5
5
  SHA512:
6
- metadata.gz: fd974c1b182db06f63cd0f7673b979bbbb4a0c0d2b200e9f6cd9fe428dfabc3d879348046882e97a7400e41961bfe6cbea4c147193bb0de2aca50e2bdbb7b738
7
- data.tar.gz: bd4a6d8897a424ea22b403f70f4b4a12228798564ebe0023f5596e6a987de798ca304ee25c590966e688ba5588243ee566b6d4d897127ef37350b0c0aef55526
6
+ metadata.gz: 389d89408cd1e628ac26b0ec08de34c55851f84094e4258f9e98b7c036f48c992a84dd5c61385bd9ebb0592cb2df3e8dd0cc2c61808820b9e3c43bbb5dc5f7aa
7
+ data.tar.gz: 5c30cabb9b66750e0a6cc9783510dd15cb3ed866f9fca39d06c1037baa8c2c41db5798121f49b4b0e847163396eae77a68d99e8d8c548db55c57ea08f4d17dfd
@@ -43,36 +43,54 @@ dumpAttributes = function(obj) {
43
43
  };
44
44
 
45
45
  /*******************************************************************
46
- * Trying to remove background from iframe element. It is not yet working.
46
+ * Function checks if there are delay loaded embedded elements on
47
+ * selected tab and triggers iframe reload.
47
48
  *******************************************************************/
48
- remove_background_from_iframe = function(obj) {
49
- var head = obj.head;
50
- var css = '<style type="text/css">' +
51
- 'body{background: none; background-picture:none; } ' +
52
- '</style>';
53
- $(head).append(css);
49
+ update_embedded_on_first_display = function(div_name) {
50
+ var iframes = $(div_name).find("iframe");
51
+ $.each(iframes, function(index, iframe) {
52
+ var src_delay = iframe.getAttribute('data-src-delay');
53
+ if (src_delay != null && src_delay != '') {
54
+ iframe.setAttribute('data-src-delay', '');
55
+ iframe.setAttribute('src', src_delay);
56
+ }
57
+ });
58
+ };
59
+
60
+ /*******************************************************************
61
+ * Return false when confirmation is not required
62
+ *******************************************************************/
63
+ confirmation_is_cancled = function(object) {
64
+ var confirmation = object.getAttribute("data-confirm");
65
+ // if confirmation required
66
+ if (confirmation !== null) {
67
+ if (!confirm(confirmation)) {return true;}
68
+ }
69
+ return false;
54
70
  };
55
71
 
56
72
  /*******************************************************************
57
- * Will update select field on the form which select options are dependend on other field
73
+ * Will update select field on the form which select options are dependend
74
+ * on other field value. It calls /dc_common/autocomplete and passes
75
+ * methodname and depend field value to obtain new values for select field.
58
76
  *******************************************************************/
59
77
  update_select_depend = function(select_name, depend_name, method) {
60
78
  var select_field = $('#'+select_name);
61
79
  var depend_field = $('#'+depend_name);
62
- /*
80
+
63
81
  $.ajax({
64
82
  url: "/dc_common/autocomplete",
65
83
  type: "POST",
66
84
  dataType: "json",
67
- data: { input: request.term, table: "#{table}", search: "#{search}" #{(',id: "'+@yaml['id'] + '"') if @yaml['id']} },
85
+ data: { input: depend_field.val(), search: method},
68
86
  success: function(data) {
69
- response( $.map( data, function(key) {
70
- return key;
71
- }));
87
+
88
+ select_field.empty();
89
+ $.each(data, function(index, element) {
90
+ select_field.append( new Option(element['label'], element['id']) );
91
+ });
72
92
  }
73
93
  });
74
- */
75
-
76
94
  };
77
95
 
78
96
  /*******************************************************************
@@ -160,72 +178,107 @@ $(function() {
160
178
  *******************************************************************/
161
179
 
162
180
  process_json_result = function(json) {
163
- var i,operation,what, selector;
164
- $.each(json, function(key, val) {
181
+ var i,w,operation,selector, msg_div, field;
182
+ $.each(json, function(key, value) {
165
183
  i = key.search('_');
166
184
  if (i > 1) {
167
185
  operation = key.substring(0,i);
168
- what = key.substring(i+1,100);
186
+ selector = key.substring(i+1,100);
169
187
  } else {
170
188
  operation = key;
171
- what = '';
189
+ selector = '';
172
190
  }
173
191
  //
174
192
  switch (operation) {
175
- // update field
193
+
194
+ /**** update fields on form ****/
176
195
  case 'record':
177
- $('#'+key).val(val);
196
+ field = $('#'+key);
197
+ // checkbox field
198
+ if (field.is(':checkbox')) {
199
+ field.prop('checked', value);
200
+ // select field
201
+ } else if (field.is('select')) {
202
+ // options for select field
203
+ if (value && value.isArray) {
204
+ field.empty();
205
+ $.each(value, function(index, v) {
206
+ field.append( new Option(v[0], v[1]) );
207
+ });
208
+ // select field value
209
+ } else {
210
+ field.val(value);
211
+ }
212
+ // other input fields
213
+ } else {
214
+ field.val(value);
215
+ }
178
216
  break;
179
- // display message
217
+
218
+ /**** display message ****/
180
219
  case 'msg':
181
- selector = 'dc-form-' + what;
182
- if ( $('.'+selector).length == 0 ) {
183
- val = '<div class="' + selector + '">' + val + '</div>';
184
- $('.dc-title').after(val);
220
+ msg_div = 'dc-form-' + selector;
221
+ if ( $('.'+msg_div).length == 0 ) {
222
+ value = '<div class="' + msg_div + '">' + value + '</div>';
223
+ $('.dc-title').after(value);
185
224
  } else {
186
- $('.'+selector).html(val);
225
+ $('.'+msg_div).html(value);
187
226
  }
188
227
  break;
189
- // display popup message
228
+
229
+ /**** display popup message ****/
190
230
  case 'popup':
191
- $('#popup').html(val);
231
+ $('#popup').html(value);
192
232
  $('#popup').bPopup({ speed: 650, transition: 'slideDown' });
193
233
 
194
- // update div
234
+ /**** update div ****/
195
235
  case '#div+':
196
- $('#'+what).append(val);
236
+ $('#'+selector).append(value);
197
237
  break;
198
238
  case '#+div':
199
- $('#'+what).prepend(val);
239
+ $('#'+selector).prepend(value);
200
240
  break;
201
241
  case '#div':
202
- $('#'+what).html(val);
242
+ $('#'+selector).html(value);
203
243
  break;
204
244
  case '.div+':
205
- $('.'+what).append(val);
245
+ $('.'+selector).append(value);
206
246
  break;
207
247
  case '.+div':
208
- $('.'+what).prepend(val);
248
+ $('.'+selector).prepend(value);
209
249
  break;
210
250
  case '.div':
211
- $('.'+what).html(val);
251
+ $('.'+selector).html(value);
212
252
  break;
213
- // goto url
253
+
254
+ /**** goto url ****/
214
255
  case 'url':
215
- window.location.href = val;
256
+ window.location.href = value;
216
257
  break;
217
258
  case 'alert':
218
- alert(val);
259
+ alert(value);
219
260
  break;
220
261
  case 'window':
221
- w = window.open(val, what);
262
+ if (value == 'close') { window.close();
263
+ } else if (value == 'reload') { location.reload();
264
+ } else {
265
+ w = window.open(value, selector);
266
+ w.focus();
267
+ }
268
+ break;
269
+ case 'newwindow':
270
+ w = window.open(value, selector,"location=no,scrollbars=yes,resizable=yes");
222
271
  w.focus();
223
272
  break;
224
273
  case 'eval':
225
- eval (val);
274
+ eval (value);
226
275
  break;
227
276
  case 'reload':
228
- location.reload();
277
+ if (value == 'parent') {
278
+ parent.location.reload();
279
+ } else {
280
+ location.reload();
281
+ }
229
282
  break;
230
283
  default:
231
284
  console.log("DRGCMS: Invalid ajax result operation: " + operation);
@@ -265,6 +318,21 @@ $.fn.dc_scroll_view = function () {
265
318
  });
266
319
  };
267
320
 
321
+ /*******************************************************************
322
+ * Updates single field on parent iframe form of embedded form.
323
+ *******************************************************************/
324
+ process_parent_form_updates = function(element) {
325
+ var field = element.getAttribute("data-field");
326
+ var value = element.getAttribute("data-value");
327
+ if ( window.parent.$('#'+field).length > 0 ) {
328
+ if (field.substring(0,3) === 'td_') { // readonly field
329
+ window.parent.$('#'+field+' > div').html(value);
330
+ } else { // input field
331
+ window.parent.$('#'+field).val(value);
332
+ }
333
+ }
334
+ };
335
+
268
336
  /*******************************************************************
269
337
  *
270
338
  *******************************************************************/
@@ -285,6 +353,20 @@ $(document).ready( function() {
285
353
  window.scrollTo(0, $.getUrlParam('return_to_ypos'));
286
354
  }
287
355
 
356
+ /*******************************************************************
357
+ * The idea is to update fields on parent iframe form, when embedded document
358
+ * is updated in its iframe. Update fields are listed in .dc-form-updates div
359
+ * and are set by flash[:update] Hash object.
360
+ *
361
+ * eg. flash[:update] = {'td_record_radonly' => 'New value for read_only field',
362
+ * 'record_name' => 'New name'}
363
+ *******************************************************************/
364
+ if ( $('.dc-form-updates').length > 0 ) {
365
+ $('.dc-form-updates').children().each( function( index, element ) {
366
+ process_parent_form_updates(element);
367
+ });
368
+ }
369
+
288
370
  /*******************************************************************
289
371
  * Register ad clicks
290
372
  *******************************************************************/
@@ -337,11 +419,11 @@ $(document).ready( function() {
337
419
  * Tab clicked on form. Hide old and show selected div.
338
420
  *******************************************************************/
339
421
  $('.dc-form-li').on('click', function(e) {
340
- // find li with dc-form-li-selected class. This is our old tab
422
+ // find li with dc-form-li-selected class. This is our old tab
341
423
  var old_tab_id = null;
342
424
  $(e.target).parents('ul').find('li').each( function() {
343
425
  if ($(this).hasClass('dc-form-li-selected')) {
344
- // when not already selected toggle dc-form-li-selected class and save old tab
426
+ // when not already selected toggle dc-form-li-selected class and save old tab
345
427
  if ($(this) !== $(e.target)) {
346
428
  $(this).toggleClass('dc-form-li-selected');
347
429
  $(e.target).toggleClass('dc-form-li-selected');
@@ -354,11 +436,15 @@ $(document).ready( function() {
354
436
  if (old_tab_id !== null) {
355
437
  $('#data_' + old_tab_id).toggleClass('div-hidden');
356
438
  $('#data_' + e.target.getAttribute("data-div")).toggleClass('div-hidden');
357
- // resize parent iframe to fit selected tab size
358
- var div_height = document.getElementById('data_' + e.target.getAttribute("data-div")).clientHeight + 130;
359
- window.frameElement.style.height = div_height.toString() + 'px';
439
+
440
+ // resize parent iframe to fit selected tab size
441
+ // var div_height = document.getElementById('data_' + e.target.getAttribute("data-div")).clientHeight + 130;
442
+ // var div_height = document.getElementById('cmsform').clientHeight + 50;
443
+ var div_height = document.body.scrollHeight;
444
+ window.frameElement.style.height = div_height.toString() + 'px';
360
445
  // it would be too easy $('#cmsform :input:enabled:visible:first').focus();
361
446
  select_first_input_field('#data_' + e.target.getAttribute("data-div"));
447
+ update_embedded_on_first_display('#data_' + e.target.getAttribute("data-div"));
362
448
  }
363
449
  });
364
450
 
@@ -367,7 +453,6 @@ $(document).ready( function() {
367
453
  * unless on initial display.
368
454
  *******************************************************************/
369
455
  $('#iframe_cms').on('load', function() {
370
- // alert('bla 1');
371
456
  new_height = this.contentWindow.document.body.offsetHeight + 50;
372
457
  if (new_height < 500 && new_height > 60) new_height = 500;
373
458
  this.style.height = new_height + 'px';
@@ -392,48 +477,70 @@ $(document).ready( function() {
392
477
  * Process Ajax call on cmsedit form actions
393
478
  *******************************************************************/
394
479
  $('.dc-link-ajax').on('click', function(e) {
395
- // check HTML5 validations
480
+ // confirmation if required
481
+ if (confirmation_is_cancled(this)) {return false;}
482
+
483
+ // check HTML5 validations
396
484
  if ($("form")[0] && !$("form")[0].checkValidity() ) {
397
485
  $("form")[0].reportValidity();
398
486
  return false;
399
487
  }
400
- var target = e.target;
401
- var req = target.getAttribute("data-request");
402
- // Get values from elements on the page:
488
+ var req = this.getAttribute("data-request");
489
+ // Get values from elements on the page:
403
490
  if (req == "script") {
404
- eval (target.getAttribute("data-script"));
491
+ eval (this.getAttribute("data-script"));
405
492
  return false;
406
493
  }
407
494
  else if (req == "post") {
408
495
  data = $('form').serialize();
409
- // alert(data);
410
496
  }
411
497
  else {
412
498
  data = {};
413
499
  req = 'get'; // by default
414
500
  }
415
501
 
416
- $('.dc-spinner').toggleClass('div-hidden');
502
+ $('.dc-spinner').show();
417
503
  $.ajax({
418
- url: target.getAttribute("data-url"),
504
+ url: this.getAttribute("data-url"),
419
505
  type: req,
420
506
  dataType: "json",
421
507
  data: data,
422
- // success: function(files,data,xhr) {
423
- // document.getElementById('if_priponkas').contentDocument.location.reload(true);
424
- // }
425
508
  success: function(data) {
426
509
  process_json_result(data);
427
- $('.dc-spinner').toggleClass('div-hidden');
510
+ $('.dc-spinner').hide();
428
511
  }
429
512
 
430
513
  });
431
- });
514
+ });
515
+
516
+ /*******************************************************************
517
+ * Process action submit button click.
518
+ *******************************************************************/
519
+ $('.dc-action-submit').on('click', function(e) {
520
+ // confirmation if required
521
+ if (confirmation_is_cancled(this)) {return false;}
522
+
523
+ // check HTML5 validations
524
+ var form = $("form")[0];
525
+ if (form && !form.checkValidity() ) {
526
+ form.reportValidity();
527
+ return false;
528
+ }
529
+ var url = this.getAttribute("data-url");
530
+ if (url == null) {return false;}
531
+
532
+ form.setAttribute('action', url);
533
+ form.setAttribute('method', "post");
534
+ form.submit();
535
+ });
432
536
 
433
537
  /*******************************************************************
434
538
  will open a new window with URL specified.
435
539
  ********************************************************************/
436
540
  $('.dc-window-open').on('click', function(e) {
541
+ // confirmation if required
542
+ if (confirmation_is_cancled(this)) {return false;}
543
+
437
544
  var url = this.getAttribute("data-url");
438
545
  var title = this.getAttribute("title");
439
546
  var w = 1000;
@@ -442,7 +549,6 @@ $(document).ready( function() {
442
549
  var top = (screen.height/2)-(h/2);
443
550
  var win = window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
444
551
  win.focus();
445
- // $('#bpopup').bPopup({ loadUrl: url, speed: 650, transition: 'slideDown' });
446
552
  });
447
553
 
448
554
  /*******************************************************************
@@ -494,11 +600,11 @@ $(document).ready( function() {
494
600
  * Display spinner on link with spinner, submit link
495
601
  *******************************************************************/
496
602
  $('.dc-link-spinner').on('click', function(e) {
497
- $('.dc-spinner').toggleClass('div-hidden');
603
+ $('.dc-spinner').show();
498
604
  });
499
605
 
500
606
  $('.dc-link-submit').on('click', function(e) {
501
- $('.dc-spinner').toggleClass('div-hidden');
607
+ $('.dc-spinner').show();
502
608
  });
503
609
 
504
610
  /*******************************************************************
@@ -722,8 +828,9 @@ element = $(this).find(':first').attr('id');
722
828
  });
723
829
 
724
830
  /*******************************************************************
725
- * Resize result table columns
831
+ * Resize result table columns. For now an idea.
726
832
  *******************************************************************/
833
+ /*
727
834
  $( ".dc-result-header .spacer" )
728
835
  .mouseenter(function() {
729
836
  console.log("enter");
@@ -731,7 +838,7 @@ element = $(this).find(':first').attr('id');
731
838
  .mouseleave(function() {
732
839
  console.log("leave");
733
840
  });
734
-
841
+ */
735
842
  /*******************************************************************
736
843
  * number_field type entered
737
844
  *******************************************************************/
@@ -746,44 +853,47 @@ element = $(this).find(':first').attr('id');
746
853
  /*******************************************************************
747
854
  * number_field type leaved
748
855
  *******************************************************************/
749
- $('.dc-number').on('focusout', function(e) {
750
- // format_number_field($(this));
751
-
752
- var decimals = $(this).attr("data-decimal") || 2;
753
- var delimiter = $(this).attr("data-delimiter") || '.';
754
- var separator = $(this).attr("data-separator") || ',';
755
- var currency = $(this).attr("data-currency") || '';
756
- var whole = this.value.split(separator)[0];
757
- var dec = this.value.split(separator)[1];
758
- // save value to hidden field which will be used for return
759
- var field = '#' + $(this).attr("id").slice(0,-1);
760
- var value = this.value.replace(separator,'.');
856
+ $('.dc-number').on('focusout', function(e) {
857
+ var decimals = $(this).attr("data-decimal") || 2;
858
+ var delimiter = $(this).attr("data-delimiter") || '.';
859
+ var separator = $(this).attr("data-separator") || ',';
860
+ var currency = $(this).attr("data-currency") || '';
861
+ var val = this.value;
862
+ // clear delimiters and replace separator with .
863
+ val = val.replace(delimiter,'');
864
+ val = val.replace(separator,'.');
865
+ val = parseFloat(val).toFixed(decimals);
866
+ var whole, dec, sign;
867
+ // [whole,dec] = val.split('.');
868
+ whole = val.split('.')[0];
869
+ dec = val.split('.')[1];
761
870
  // remove negative sign and add at the end
762
- var sign = whole.substr(0,1);
763
- if (sign == '-') {
764
- whole = whole.substr(1,20);
765
- } else {
766
- sign = '';
767
- }
871
+ var sign = whole.substr(0,1);
872
+ if (sign == '-') {
873
+ whole = whole.substr(1,20);
874
+ } else {
875
+ sign = '';
876
+ }
877
+ // save value to hidden field which holds return value
878
+ var field = '#' + $(this).attr("id").slice(0,-1);
879
+ $(field).val(val);
768
880
 
769
- $(field).val( parseFloat(value).toFixed(decimals) );
770
-
771
881
  // decimal part
772
- if (dec == null) dec = '';
773
- dec = dec.substring(0, decimals, dec);
774
- while (dec.length < decimals) dec = dec + '0';
882
+ if (decimals == 0) separator = '';
883
+ if (dec == null) dec = '';
884
+ while (dec.length < decimals) dec = dec + '0';
775
885
  // whole part
776
- if (whole == null || whole == '') whole = '0';
777
- var ar = [];
778
- while (whole.length > 0) {
779
- var pos1 = whole.length - 3
780
- if (pos1 < 0) pos1 = 0;
781
- ar.unshift(whole.substr(pos1,3));
782
- whole = whole.slice(0, -3);
886
+ if (whole == null || whole == '') whole = '0';
887
+ var ar = [];
888
+ while (whole.length > 0) {
889
+ var pos1 = whole.length - 3
890
+ if (pos1 < 0) pos1 = 0;
891
+ ar.unshift(whole.substr(pos1,3));
892
+ whole = whole.slice(0, -3);
783
893
  };
784
894
 
785
- if (delimiter !== '') whole = ar.join(delimiter);
786
- $(this).val(sign + whole + separator + dec + currency);
895
+ if (delimiter !== '') whole = ar.join(delimiter);
896
+ $(this).val(sign + whole + separator + dec + currency);
787
897
  });
788
898
 
789
899
  /*******************************************************************
@@ -809,6 +919,55 @@ element = $(this).find(':first').attr('id');
809
919
  $(field).val( parseFloat(value).toFixed(decimals) );
810
920
  }
811
921
  });
922
+
923
+ /*******************************************************************
924
+ * Result header sort icon is hoverd. Change background icon to filter.
925
+ *******************************************************************/
926
+ $('.dc-result-header .th i').hover( function() {
927
+ old_sort_icon = '';
928
+ // save old sort icon and replace it with filter icon
929
+ $.each( $(this).attr("class").split(/\s+/),
930
+ function(index, item) { if (item.match('sort')) { old_sort_icon = item}; }
931
+ );
932
+ $(this).removeClass(old_sort_icon).addClass('fa-filter');
933
+ // bring back old sort icon
934
+ }, function(){
935
+ $(this).removeClass('fa-filter').addClass(old_sort_icon);
936
+ });
937
+
938
+ /*******************************************************************
939
+ * Result header sort icon is clicked. Display filter menu for the field.
940
+ *******************************************************************/
941
+ $('.dc-result-header .th i').click( function(e) {
942
+ e.preventDefault();
943
+ // additional click will close dialog when visible
944
+ if ($('.filter-popup').is(':visible')) {
945
+ $('.filter-popup').hide();
946
+ return;
947
+ }
948
+ // retrieve name of current field and set it in popup
949
+ var header = $(this).closest('.th');
950
+ var field_name = header.attr("data-name");
951
+ $('.filter-popup').attr('data-name', field_name);
952
+ // change popup position and show
953
+ $('.filter-popup').css({'top':e.pageY+5,'left':e.pageX, 'position':'absolute'});
954
+ $('.filter-popup').show();
955
+ });
956
+
957
+ /*******************************************************************
958
+ * Filter operation is clicked on filter popup. Retrieve data and call
959
+ * filter on action.
960
+ *******************************************************************/
961
+ $('.filter-popup li').click( function(e) {
962
+ var url = $(this).data('url')
963
+ var operator = $(this).data('operator');
964
+ var parent = $(this).closest('.filter-popup')
965
+ var field_name = parent.data("name");
966
+
967
+ url = url + '&filter_field=' + field_name + '&filter_oper=' + operator;
968
+ window.location.href = url;
969
+ });
970
+
812
971
  });
813
972
 
814
973
  /*******************************************************************
@@ -827,9 +986,7 @@ $(document).keydown( function(e) {
827
986
  });
828
987
 
829
988
  /*******************************************************************
830
- * Catch ctrl+s key pressed and fire save form event. I press ctrl+s
831
- * almost every minute. That was a lesson learned years ago when I lost
832
- * few hours of work on computer lockup ;-(
989
+
833
990
  *******************************************************************
834
991
  $(document).onmousedown( function(e) {
835
992
  mouseDown = true;
@@ -841,4 +998,4 @@ $(document).onmouseup( function(e) {
841
998
  console.log("mouse up");
842
999
  });
843
1000
 
844
- **/
1001
+ **/