-
Notifications
You must be signed in to change notification settings - Fork 3
/
common.js.php
1257 lines (1090 loc) · 44.3 KB
/
common.js.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if(!defined('datalist_db_encoding')) define('datalist_db_encoding', 'UTF-8');
if(function_exists('date_default_timezone_set')) @date_default_timezone_set('America/New_York');
/* force caching */
$last_modified = filemtime(__FILE__);
$last_modified_gmt = gmdate('D, d M Y H:i:s', $last_modified) . ' GMT';
$headers = (function_exists('getallheaders') ? getallheaders() : $_SERVER);
if(isset($headers['If-Modified-Since']) && (strtotime($headers['If-Modified-Since']) == $last_modified)){
@header("Last-Modified: {$last_modified_gmt}", true, 304);
@header("Cache-Control: public, max-age=240", true);
exit;
}
@header("Last-Modified: {$last_modified_gmt}", true, 200);
@header("Cache-Control: public, max-age=240", true);
@header('Content-Type: text/javascript; charset=' . datalist_db_encoding);
$currDir = dirname(__FILE__);
include("{$currDir}/defaultLang.php");
include("{$currDir}/language.php");
?>
var AppGini = AppGini || {};
AppGini.ajaxCache = function(){
var _tests = [];
/*
An array of functions that receive a parameterless url and a parameters object,
makes a test,
and if test passes, executes something and/or
returns a non-false value if test passes,
or false if test failed (useful to tell if tests should continue or not)
*/
var addCheck = function(check){ /* */
if(typeof(check) == 'function'){
_tests.push(check);
}
};
var _jqAjaxData = function(opt){ /* */
var opt = opt || {};
var url = opt.url || '';
var data = opt.data || {};
var params = url.match(/\?(.*)$/);
var param = (params !== null ? params[1] : '');
var sPageURL = decodeURIComponent(param),
sURLVariables = sPageURL.split('&'),
sParameter,
i;
for(i = 0; i < sURLVariables.length; i++){
sParameter = sURLVariables[i].split('=');
if(sParameter[0] == '') continue;
data[sParameter[0]] = sParameter[1] || '';
}
return data;
};
var start = function(){ /* */
if(!_tests.length) return; // no need to monitor ajax requests since no checks were defined
var reqTests = _tests;
$j.ajaxPrefilter(function(options, originalOptions, jqXHR){
var success = originalOptions.success || $j.noop,
data = _jqAjaxData(originalOptions),
oUrl = originalOptions.url || '',
url = oUrl.match(/\?/) ? oUrl.match(/(.*)\?/)[1] : oUrl;
options.beforeSend = function(){ /* */
var req, cached = false, resp;
for(var i = 0; i < reqTests.length; i++){
resp = reqTests[i](url, data);
if(resp === false) continue;
success(resp);
return false;
}
return true;
}
});
};
return {
addCheck: addCheck,
start: start
};
};
/* initials and fixes */
jQuery(function(){
AppGini.count_ajaxes_blocking_saving = 0;
/* add ":truncated" pseudo-class to detect elements with clipped text */
$j.expr[':'].truncated = function(obj){
var $this = $j(obj);
var $c = $this
.clone()
.css({ display: 'inline', width: 'auto', visibility: 'hidden', 'padding-right': 0 })
.css({ 'font-size': $this.css('font-size') })
.appendTo('body');
var e_width = $this.outerWidth();
var c_width = $c.outerWidth();
$c.remove();
return ( c_width > e_width );
};
var fix_lookup_width = function(field){
var s2 = $j('div.select2-container[id=s2id_' + field + '-container]');
if(!s2.length) return;
var s2new_width = 0, s2view_width = 0, s2parent_width = 0;
var s2new = s2.parent().find('.add_new_parent:visible');
var s2view = s2.parent().find('.view_parent:visible');
if(s2new.length) s2new_width = s2new.outerWidth(true);
if(s2view.length) s2view_width = s2view.outerWidth(true);
s2parent_width = s2.parent().innerWidth();
// console.log({ s2new_width: s2new_width, s2view_width: s2view_width, s2parent_width: s2parent_width });
s2.css({ width: '100%', 'max-width': (s2parent_width - s2new_width - s2view_width - 1) + 'px' });
}
$j(window).resize(function(){
var window_width = $j(window).width();
var max_width = $j('body').width() * 0.5;
$j('.select2-container:not(.option_list)').each(function(){
var field = $j(this).attr('id').replace(/^s2id_/, '').replace(/-container$/, '');
fix_lookup_width(field);
});
//fix_table_responsive_width();
var full_img_factor = 0.9; /* xs */
if(window_width >= 992) full_img_factor = 0.6; /* md, lg */
else if(window_width >= 768) full_img_factor = 0.9; /* sm */
$j('.detail_view .img-responsive').css({'max-width' : parseInt($j('.detail_view').width() * full_img_factor) + 'px'});
/* remove labels from truncated buttons, leaving only glyphicons */
$j('.btn.truncate:truncated').each(function(){
// hide text
var label = $j(this).html();
var mlabel = label.replace(/.*(<i.*?><\/i>).*/, '$1');
$j(this).html(mlabel);
});
});
setTimeout(function(){ /* */ $j(window).resize(); }, 1000);
setTimeout(function(){ /* */ $j(window).resize(); }, 3000);
/* don't allow saving detail view when there's an ajax request to a url that matches the following */
var ajax_blockers = new RegExp(/(ajax_combo\.php|_autofill\.php|ajax_check_unique\.php)/);
$j(document).ajaxSend(function(e, r, s){
if(s.url.match(ajax_blockers)){
AppGini.count_ajaxes_blocking_saving++;
$j('#update, #insert').prop('disabled', true);
}
});
$j(document).ajaxComplete(function(e, r, s){
if(s.url.match(ajax_blockers)){
AppGini.count_ajaxes_blocking_saving = Math.max(AppGini.count_ajaxes_blocking_saving - 1, 0);
if(AppGini.count_ajaxes_blocking_saving <= 0)
$j('#update, #insert').prop('disabled', false);
}
});
/* don't allow responsive images to initially exceed the smaller of their actual dimensions, or .6 container width */
jQuery('.detail_view .img-responsive').each(function(){
var pic_real_width, pic_real_height;
var img = jQuery(this);
jQuery('<img/>') // Make in memory copy of image to avoid css issues
.attr('src', img.attr('src'))
.load(function() {
pic_real_width = this.width;
pic_real_height = this.height;
if(pic_real_width > $j('.detail_view').width() * .6) pic_real_width = $j('.detail_view').width() * .6;
img.css({ "max-width": pic_real_width });
});
});
jQuery('.table-responsive .img-responsive').each(function(){
var pic_real_width, pic_real_height;
var img = jQuery(this);
jQuery('<img/>') // Make in memory copy of image to avoid css issues
.attr('src', img.attr('src'))
.load(function() {
pic_real_width = this.width;
pic_real_height = this.height;
if(pic_real_width > $j('.table-responsive').width() * .6) pic_real_width = $j('.table-responsive').width() * .6;
img.css({ "max-width": pic_real_width });
});
});
/* toggle TV action buttons based on selected records */
jQuery('.record_selector').click(function(){
var id = jQuery(this).val();
var checked = jQuery(this).prop('checked');
update_action_buttons();
});
/* select/deselect all records in TV */
jQuery('#select_all_records').click(function(){
jQuery('.record_selector').prop('checked', jQuery(this).prop('checked'));
update_action_buttons();
});
/* fix behavior of select2 in bootstrap modal. See: https://github.com/ivaynberg/select2/issues/1436 */
jQuery.fn.modal.Constructor.prototype.enforceFocus = function(){ /* */ };
/* remove empty navbar menus */
$j('nav li.dropdown').each(function(){
var num_items = $j(this).children('.dropdown-menu').children('li').length;
if(!num_items) $j(this).remove();
})
update_action_buttons();
/* remove empty images and links from TV, TVP */
$j('.table a[href="<?php echo $Translation['ImageFolder']; ?>"], .table img[src="<?php echo $Translation['ImageFolder']; ?>"]').remove();
/* remove empty email links from TV, TVP */
$j('a[href="mailto:"]').remove();
/* Disable action buttons when form is submitted to avoid user re-submission on slow connections */
$j('form').eq(0).submit(function(){
setTimeout(function(){
$j('#insert, #update, #delete, #deselect').prop('disabled', true);
}, 200); // delay purpose is to allow submitting the button values first then disable them.
});
/* fix links inside alerts */
$j('.alert a:not(.btn)').addClass('alert-link');
});
/* show/hide TV action buttons based on whether records are selected or not */
function update_action_buttons(){
if(jQuery('.record_selector:checked').length){
jQuery('.selected_records').removeClass('hidden');
jQuery('#select_all_records')
.prop('checked', (jQuery('.record_selector:checked').length == jQuery('.record_selector').length));
}else{
jQuery('.selected_records').addClass('hidden');
}
}
/* fix table-responsive behavior on Chrome */
function fix_table_responsive_width(){
var resp_width = jQuery('div.table-responsive').width();
var table_width;
if(resp_width){
jQuery('div.table-responsive table').width('100%');
table_width = jQuery('div.table-responsive table').width();
resp_width = jQuery('div.table-responsive').width();
if(resp_width == table_width){
jQuery('div.table-responsive table').width(resp_width - 1);
}
}
}
function buses_validateData(){
$j('.has-error').removeClass('has-error');
return true;
}
function seats_validateData(){
$j('.has-error').removeClass('has-error');
return true;
}
function availability_validateData(){
$j('.has-error').removeClass('has-error');
return true;
}
function bookings_validateData(){
$j('.has-error').removeClass('has-error');
return true;
}
function routes_validateData(){
$j('.has-error').removeClass('has-error');
return true;
}
function customers_validateData(){
$j('.has-error').removeClass('has-error');
return true;
}
function post(url, params, update, disable, loading, success_callback){
$j.ajax({
url: url,
type: 'POST',
data: params,
beforeSend: function() {
if($j('#' + disable).length) $j('#' + disable).prop('disabled', true);
if($j('#' + loading).length && update != loading) $j('#' + loading).html('<div style="direction: ltr;"><img src="loading.gif"> <?php echo addslashes($Translation['Loading ...']); ?></div>');
},
success: function(resp) {
if($j('#' + update).length) $j('#' + update).html(resp);
if(success_callback != undefined) success_callback();
},
complete: function() {
if($j('#' + disable).length) $j('#' + disable).prop('disabled', false);
if($j('#' + loading).length && loading != update) $j('#' + loading).html('');
}
});
}
function post2(url, params, notify, disable, loading, redirectOnSuccess){
new Ajax.Request(
url, {
method: 'post',
parameters: params,
onCreate: function() {
if($(disable) != undefined) $(disable).disabled=true;
if($(loading) != undefined) $(loading).show();
},
onSuccess: function(resp) {
/* show notification containing returned text */
if($(notify) != undefined) $(notify).removeClassName('Error').appear().update(resp.responseText);
/* in case no errors returned, */
if(!resp.responseText.match(/<?php echo $Translation['error:']; ?>/)){
/* redirect to provided url */
if(redirectOnSuccess != undefined){
window.location=redirectOnSuccess;
/* or hide notification after a few seconds if no url is provided */
}else{
if($(notify) != undefined) window.setTimeout(function(){ /* */ $(notify).fade(); }, 15000);
}
/* in case of error, apply error class */
}else{
$(notify).addClassName('Error');
}
},
onComplete: function() {
if($(disable) != undefined) $(disable).disabled=false;
if($(loading) != undefined) $(loading).hide();
}
}
);
}
function passwordStrength(password, username){
// score calculation (out of 10)
var score = 0;
re = new RegExp(username, 'i');
if(username.length && password.match(re)) score -= 5;
if(password.length < 6) score -= 3;
else if(password.length > 8) score += 5;
else score += 3;
if(password.match(/(.*[0-9].*[0-9].*[0-9])/)) score += 3;
if(password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5;
if(password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) score += 2;
if(score >= 9)
return 'strong';
else if(score >= 5)
return 'good';
else
return 'weak';
}
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
function loadScript(jsUrl, cssUrl, callback){
// adding the script tag to the head
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = jsUrl;
if(cssUrl != ''){
var css = document.createElement('link');
css.href = cssUrl;
css.rel = "stylesheet";
css.type = "text/css";
head.appendChild(css);
}
// then bind the event to the callback function
// there are several events for cross browser compatibility
if(script.onreadystatechange != undefined){ script.onreadystatechange = callback; }
if(script.onload != undefined){ script.onload = callback; }
// fire the loading
head.appendChild(script);
}
/**
* options object. The following members can be provided:
* url: iframe url to load
* message: instead of a url to open, you could pass a message. HTML tags allowed.
* id: id attribute of modal window. auto-generated if not provided
* title: optional modal window title
* size: 'default', 'full'
* close: optional function to execute on closing the modal
* footer: optional array of objects describing the buttons to display in the footer.
* Each button object can have the following members:
* label: string, label of button
* bs_class: string, button bootstrap class. Can be 'primary', 'default', 'success', 'warning' or 'danger'
* click: function to execute on clicking the button. If the button closes the modal, this
* function is executed before the close handler
* causes_closing: boolean, default is true.
*/
function modal_window(options){
return jQuery('body').agModal(options).agModal('show').attr('id');
}
function random_string(string_length){
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for(var i = 0; i < string_length; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
/**
* @return array of IDs (PK values) of selected records in TV (records that the user checked)
*/
function get_selected_records_ids(){
return jQuery('.record_selector:checked').map(function(){ /* */ return jQuery(this).val() }).get();
}
function print_multiple_dv_tvdv(t, ids){
document.myform.NoDV.value=1;
document.myform.PrintDV.value=1;
document.myform.SelectedID.value = '';
document.myform.submit();
return true;
}
function print_multiple_dv_sdv(t, ids){
document.myform.NoDV.value=1;
document.myform.PrintDV.value=1;
document.myform.writeAttribute('novalidate', 'novalidate');
document.myform.submit();
return true;
}
function mass_delete(t, ids){
if(ids == undefined) return;
if(!ids.length) return;
var confirm_message = '<div class="alert alert-danger">' +
'<i class="glyphicon glyphicon-warning-sign"></i> ' +
'<?php echo addslashes($Translation['<n> records will be deleted. Are you sure you want to do this?']); ?>' +
'</div>';
var confirm_title = '<?php echo addslashes($Translation['Confirm deleting multiple records']); ?>';
var label_yes = '<?php echo addslashes($Translation['Yes, delete them!']); ?>';
var label_no = '<?php echo addslashes($Translation['No, keep them.']); ?>';
var progress = '<?php echo addslashes($Translation['Deleting record <i> of <n>']); ?>';
var continue_delete = true;
// request confirmation of mass delete operation
modal_window({
message: confirm_message.replace(/\<n\>/, ids.length),
title: confirm_title,
footer: [ /* shows a 'yes' and a 'no' buttons .. handler for each follows ... */
{
label: '<i class="glyphicon glyphicon-trash"></i> ' + label_yes,
bs_class: 'danger',
// on confirming, start delete operations
click: function(){
// show delete progress, allowing user to abort operations by closing the window or clicking cancel
var progress_window = modal_window({
title: '<?php echo addslashes($Translation['Delete progress']); ?>',
message: '' +
'<div class="progress">' +
'<div class="progress-bar progress-bar-warning" role="progressbar" style="width: 0;"></div>' +
'</div>' +
'<button type="button" class="btn btn-default details_toggle" onclick="' +
'jQuery(this).children(\'.glyphicon\').toggleClass(\'glyphicon-chevron-right glyphicon-chevron-down\'); ' +
'jQuery(\'.well.details_list\').toggleClass(\'hidden\');'
+ '">' +
'<i class="glyphicon glyphicon-chevron-right"></i> ' +
'<?php echo addslashes($Translation['Show/hide details']); ?>' +
'</button>' +
'<div class="well well-sm details_list hidden"><ol></ol></div>',
close: function(){
// stop deleting further records ...
continue_delete = false;
},
footer: [
{
label: '<i class="glyphicon glyphicon-remove"></i> <?php echo addslashes($Translation['Cancel']); ?>',
bs_class: 'warning'
}
]
});
// begin deleting records, one by one
progress = progress.replace(/\<n\>/, ids.length);
var delete_record = function(itrn){
if(!continue_delete) return;
jQuery.ajax(t + '_view.php', {
type: 'POST',
data: { delete_x: 1, SelectedID: ids[itrn] },
success: function(resp){
if(resp == 'OK'){
jQuery(".well.details_list ol").append('<li class="text-success"><?php echo addslashes($Translation['The record has been deleted successfully']); ?></li>');
jQuery('#record_selector_' + ids[itrn]).prop('checked', false).parent().parent().fadeOut(1500);
jQuery('#select_all_records').prop('checked', false);
}else{
jQuery(".well.details_list ol").append('<li class="text-danger">' + resp + '</li>');
}
},
error: function(){
jQuery(".well.details_list ol").append('<li class="text-warning"><?php echo addslashes($Translation['Connection error']); ?></li>');
},
complete: function(){
jQuery('#' + progress_window + ' .progress-bar').attr('style', 'width: ' + (Math.round((itrn + 1) / ids.length * 100)) + '%;').html(progress.replace(/\<i\>/, (itrn + 1)));
if(itrn < (ids.length - 1)){
delete_record(itrn + 1);
}else{
if(jQuery('.well.details_list li.text-danger, .well.details_list li.text-warning').length){
jQuery('button.details_toggle').removeClass('btn-default').addClass('btn-warning').click();
jQuery('.btn-warning[id^=' + progress_window + '_footer_button_]')
.toggleClass('btn-warning btn-default')
.html('<?php echo addslashes($Translation['ok']); ?>');
}else{
setTimeout(function(){ /* */ jQuery('#' + progress_window).agModal('hide'); }, 500);
}
}
}
});
}
delete_record(0);
}
},
{
label: '<i class="glyphicon glyphicon-ok"></i> ' + label_no,
bs_class: 'success'
}
]
});
}
function mass_change_owner(t, ids){
if(ids == undefined) return;
if(!ids.length) return;
var update_form = '<?php echo addslashes($Translation['Change owner of <n> selected records to']); ?> ' +
'<span id="new_owner_for_selected_records"></span><input type="hidden" name="new_owner_for_selected_records" value="">';
var confirm_title = '<?php echo addslashes($Translation['Change owner']); ?>';
var label_yes = '<?php echo addslashes($Translation['Continue']); ?>';
var label_no = '<?php echo addslashes($Translation['Cancel']); ?>';
var progress = '<?php echo addslashes($Translation['Updating record <i> of <n>']); ?>';
var continue_updating = true;
// request confirmation of mass update operation
modal_window({
message: update_form.replace(/\<n\>/, ids.length),
title: confirm_title,
footer: [ /* shows a 'continue' and a 'cancel' buttons .. handler for each follows ... */
{
label: '<i class="glyphicon glyphicon-ok"></i> ' + label_yes,
bs_class: 'success',
// on confirming, start update operations
click: function(){
var memberID = jQuery('input[name=new_owner_for_selected_records]').eq(0).val();
if(!memberID.length) return;
// show update progress, allowing user to abort operations by closing the window or clicking cancel
var progress_window = modal_window({
title: '<?php echo addslashes($Translation['Update progress']); ?>',
message: '' +
'<div class="progress">' +
'<div class="progress-bar progress-bar-success" role="progressbar" style="width: 0;"></div>' +
'</div>' +
'<button type="button" class="btn btn-default details_toggle" onclick="' +
'jQuery(this).children(\'.glyphicon\').toggleClass(\'glyphicon-chevron-right glyphicon-chevron-down\'); ' +
'jQuery(\'.well.details_list\').toggleClass(\'hidden\');'
+ '">' +
'<i class="glyphicon glyphicon-chevron-right"></i> ' +
'<?php echo addslashes($Translation['Show/hide details']); ?>' +
'</button>' +
'<div class="well well-sm details_list hidden"><ol></ol></div>',
close: function(){
// stop updating further records ...
continue_updating = false;
},
footer: [
{
label: '<i class="glyphicon glyphicon-remove"></i> <?php echo addslashes($Translation['Cancel']); ?>',
bs_class: 'warning'
}
]
});
// begin updating records, one by one
progress = progress.replace(/\<n\>/, ids.length);
var update_record = function(itrn){
if(!continue_updating) return;
jQuery.ajax('admin/pageEditOwnership.php', {
type: 'POST',
data: {
pkValue: ids[itrn],
t: t,
memberID: memberID,
saveChanges: 'Save changes'
},
success: function(resp){
if(resp == 'OK'){
jQuery(".well.details_list ol").append('<li class="text-success"><?php echo addslashes($Translation['record updated']); ?></li>');
jQuery('#record_selector_' + ids[itrn]).prop('checked', false);
jQuery('#select_all_records').prop('checked', false);
}else{
jQuery(".well.details_list ol").append('<li class="text-danger">' + resp + '</li>');
}
},
error: function(){
jQuery(".well.details_list ol").append('<li class="text-warning"><?php echo addslashes($Translation['Connection error']); ?></li>');
},
complete: function(){
jQuery('#' + progress_window + ' .progress-bar').attr('style', 'width: ' + (Math.round((itrn + 1) / ids.length * 100)) + '%;').html(progress.replace(/\<i\>/, (itrn + 1)));
if(itrn < (ids.length - 1)){
update_record(itrn + 1);
}else{
if(jQuery('.well.details_list li.text-danger, .well.details_list li.text-warning').length){
jQuery('button.details_toggle').removeClass('btn-default').addClass('btn-warning').click();
jQuery('.btn-warning[id^=' + progress_window + '_footer_button_]')
.toggleClass('btn-warning btn-default')
.html('<?php echo addslashes($Translation['ok']); ?>');
}else{
jQuery('button.btn-warning[id^=' + progress_window + '_footer_button_]')
.toggleClass('btn-warning btn-success')
.html('<i class="glyphicon glyphicon-ok"></i> <?php echo addslashes($Translation['ok']); ?>');
}
}
}
});
}
update_record(0);
}
},
{
label: '<i class="glyphicon glyphicon-remove"></i> ' + label_no,
bs_class: 'warning'
}
]
});
/* show drop down of users */
var populate_new_owner_dropdown = function(){
jQuery('[id=new_owner_for_selected_records]').select2({
width: '100%',
formatNoMatches: function(term){ /* */ return '<?php echo addslashes($Translation['No matches found!']); ?>'; },
minimumResultsForSearch: 10,
loadMorePadding: 200,
escapeMarkup: function(m){ /* */ return m; },
ajax: {
url: 'admin/getUsers.php',
dataType: 'json',
cache: true,
data: function(term, page){ /* */ return { s: term, p: page, t: t }; },
results: function(resp, page){ /* */ return resp; }
}
}).on('change', function(e){
jQuery('[name="new_owner_for_selected_records"]').val(e.added.id);
});
}
populate_new_owner_dropdown();
}
function add_more_actions_link(){
window.open('https://bigprof.com/appgini/help/advanced-topics/hooks/multiple-record-batch-actions?r=appgini-action-menu');
}
/* detect current screen size (xs, sm, md or lg) */
function screen_size(sz){
if(!$j('.device-xs').length){
$j('body').append(
'<div class="device-xs visible-xs"></div>' +
'<div class="device-sm visible-sm"></div>' +
'<div class="device-md visible-md"></div>' +
'<div class="device-lg visible-lg"></div>'
);
}
return $j('.device-' + sz).is(':visible');
}
/* enable floating of action buttons in DV so they are visible on vertical scrolling */
function enable_dvab_floating(){
/* already run? */
if(window.enable_dvab_floating_run != undefined) return;
/* scroll action buttons of DV on scrolling DV */
$j(window).scroll(function(){
if(!screen_size('md') && !screen_size('lg')) return;
if(!$j('.detail_view').length) return;
/* get vscroll amount, DV form height, button toolbar height and position */
var vscroll = $j(window).scrollTop();
var dv_height = $j('[id$="_dv_form"]').eq(0).height();
var bt_height = $j('.detail_view .btn-toolbar').height();
var form_top = $j('.detail_view .form-group').eq(0).offset().top;
var bt_top_max = dv_height - bt_height - 10;
if(vscroll > form_top){
var tm = parseInt(vscroll - form_top) + 60;
if(tm > bt_top_max) tm = bt_top_max;
$j('.detail_view .btn-toolbar').css({ 'margin-top': tm + 'px' });
}else{
$j('.detail_view .btn-toolbar').css({ 'margin-top': 0 });
}
});
window.enable_dvab_floating_run = true;
}
/* check if a given field's value is unique and reflect this in the DV form */
function enforce_uniqueness(table, field){
$j('#' + field).on('change', function(){
/* check uniqueness of field */
var data = {
t: table,
f: field,
value: $j('#' + field).val()
};
if($j('[name=SelectedID]').val().length) data.id = $j('[name=SelectedID]').val();
$j.ajax({
url: 'ajax_check_unique.php',
data: data,
complete: function(resp){
if(resp.responseJSON.result == 'ok'){
$j('#' + field + '-uniqueness-note').hide();
$j('#' + field).parents('.form-group').removeClass('has-error');
}else{
$j('#' + field + '-uniqueness-note').show();
$j('#' + field).parents('.form-group').addClass('has-error');
$j('#' + field).focus();
setTimeout(function(){ /* */ $j('#update, #insert').prop('disabled', true); }, 500);
}
}
})
});
}
/* persist expanded/collapsed chidren in DVP */
function persist_expanded_child(id){
var expand_these = Cookies.getJSON('Bus_Booking_System.dvp_expand');
if(expand_these == undefined) expand_these = [];
if($j('[id=' + id + ']').hasClass('active')){
if(expand_these.indexOf(id) < 0){
// expanded button and not persisting in cookie? save it!
expand_these.push(id);
Cookies.set('Bus_Booking_System.dvp_expand', expand_these, { expires: 30 });
}
}else{
if(expand_these.indexOf(id) >= 0){
// collapsed button and persisting in cookie? remove it!
expand_these.splice(expand_these.indexOf(id), 1);
Cookies.set('Bus_Booking_System.dvp_expand', expand_these, { expires: 30 });
}
}
}
/* apply expanded/collapsed status to children in DVP */
function apply_persisting_children(){
var expand_these = Cookies.getJSON('Bus_Booking_System.dvp_expand');
if(expand_these == undefined) return;
expand_these.each(function(id){
$j('[id=' + id + ']:not(.active)').click();
});
}
function select2_max_width_decrement(){
return ($j('div.container').eq(0).hasClass('theme-compact') ? 99 : 109);
}
/**
* @brief AppGini.TVScroll().more() to scroll one column more.
* AppGini.TVScroll().less() to scroll one column less.
*/
AppGini.TVScroll = function(){
/**
* @brief Calculates the width of the first n columns of the TV table
*
* @param [in] n how many columns to calculate the width for
* @return Return total width of given n columns, or 0 if n < 1 or invalid
*/
var _TVColsWidth = function(n){
if(isNaN(n)) return 0;
if(n < 1) return 0;
var tw = 0, cc;
for(var i = 0; i < n; i++){
cc = $j('.table_view .table th:visible').eq(i);
if(!cc.length) break;
tw += cc.outerWidth();
}
return tw;
};
/**
* @brief show/hide tv-scroll buttons based on whether TV is horizontally scrollable or not
* @details should be called once on document load before hiding TV columns (by calling less())
*/
var toggle_tv_scroll_tools = function(){
var tr = $j('.table_view .table-responsive'),
vpw = tr.width(), // viewport width
tfw = tr.find('.table').width(); // full width of the table
if(vpw >= tfw) $j('.tv-scroll').parents('.btn-group').hide();
else $j('.tv-scroll').parents('.btn-group').show();
}
/**
* @brief Prepares variables for use by less & more
*/
var _TVScrollSetup = function(){
if(AppGini._TVColsScrolled === undefined) AppGini._TVColsScrolled = 0;
AppGini._TVColsCount = $j('.table_view .table th:visible').length;
/* type of scrolling, https://github.com/othree/jquery.rtl-scroll-type */
/*
How to interpret AppGini._ScrollType?
{LTR | RTL}:{scrollLeft val for left position}:{scrollLeft val for right position}:{initial scrollLeft val}
*/
if(AppGini._ScrollType === undefined){
/* all browsers behave the same on LTR */
AppGini._ScrollType = 'LTR:0:100:0';
if($j('.container').hasClass('theme-rtl')){
var definer = $j('<div dir="rtl" style="font-size: 14px; width: 4px; height: 1px; position: absolute; top: -1000px; overflow: scroll">ABCD</div>').appendTo('body')[0];
AppGini._ScrollType = 'RTL:100:0:0'; // IE
if(definer.scrollLeft > 0){
AppGini._ScrollType = 'RTL:0:100:70'; // WebKit
}else{
definer.scrollLeft = 1;
if(definer.scrollLeft === 0) AppGini._ScrollType = 'RTL:-100:0:0'; // Firefox/Opera
}
}
/* show/hide #tv-scroll buttons based on TV scroll state */
$j(window).resize(toggle_tv_scroll_tools);
toggle_tv_scroll_tools();
}
};
/**
* @brief Resets all scrolling and setup values.
* @details Useful after hiding/showing columns to re-setup TV scrolling
*/
var reset = function(){
if(AppGini._ScrollType === undefined) return; // nothing to reset!
AppGini._TVColsScrolled = undefined;
var tr = $j('.table_view .table-responsive');
switch(AppGini._ScrollType){
case 'RTL:100:0:0':
case 'RTL:0:100:0':
case 'RTL:-100:0:0':
tr.scrollLeft(0);
break;
case 'RTL:0:100:70':
var vpw = tr.width(), // viewport width
tfw = tr.find('.table').width(); // full width of the table
tr.scrollLeft(tfw - vpw + 10);
break;
}
_TVScrollSetup();
};
var _TVScroll = function(){
var scroll = 0,
tr = $j('.table_view .table-responsive'),
cw = _TVColsWidth(AppGini._TVColsScrolled); // width of columns to scroll to
switch(AppGini._ScrollType){
case 'RTL:100:0:0':
case 'LTR:0:100:0':
scroll = cw - 1;
break;
case 'RTL:-100:0:0':
scroll = -1 * cw + 1;
break;
case 'RTL:0:100:70':
var vpw = tr.width(), // viewport width
tfw = tr.find('.table').width(); // full width of the table
scroll = tfw - vpw - cw + 1;
break;
}
tr.scrollLeft(scroll);
};
/**
* @brief Scroll the TV table 1 column more
*/
var more = function(){
if(AppGini._TVColsScrolled >= AppGini._TVColsCount) return;
AppGini._TVColsScrolled++;
_TVScroll();
};
/**
* @brief Scroll the TV table 1 column less
*/
var less = function(){
if(AppGini._TVColsScrolled <= 0) return;
AppGini._TVColsScrolled--;
_TVScroll();
};
_TVScrollSetup();
return { more: more, less: less, reset: reset };
};
(function($j){
/*
apply a modal or an in-page modal to an element,
or access modal methods/events if it's already 'modal'ed
Expected usage:
1. $j('any_selector').agModal({ new modal options .. })
2. $j('#modal_id').agModal('command')
3. $j('#modal_id').on('event.bs.modal', event_handler)
case 1: the selector doesn't matter ... the modal will be created and attached
to the body element .. to retrieve the modal id if not specified in options:
var modal_id = $j('any_selector').agModal({ new modal options .. }).attr('id');
case 2: the selector must be the modal element .. if it's a standard BS modal,
command will be passed as is to .modal() and the return value returned.
if it's an in-page modal, command will be emulated and the modal element
returned.
case 3: Bootstrap modal events.
*/
$j.fn.agModal = function(options){
var theModal = this,
open = function(){
return theModal.trigger('show.bs.modal').removeClass('hide').trigger('shown.bs.modal');
},
close = function(){
return theModal.trigger('hide.bs.modal').addClass('hide').trigger('hidden.bs.modal');
};
if(typeof(options) == 'string'){
if(theModal.hasClass('modal')) return theModal.modal(options);
if(!theModal.hasClass('inpage-modal')) return theModal;
/* emulate .modal(command) for the in-page modal */
switch(options){
case 'show':
open();
break;
case 'hide':
close();
break;
}
return theModal;
}
var op = $j.extend({
/* default options */
id: random_string(20),
footer: [],
extras: {},
size: 'default',
forceIPM: false
}, options);
if(op.url == undefined && op.message == undefined){
console.error('Missing message/url in call to AppGini.modal().');
return theModal;
}
var iOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent), /* true for iOS devices */
auto_id = (options.id === undefined), /* true if modal id is auto-generated */
_resize = function(id){