· 6 years ago · Dec 10, 2019, 12:16 PM
1/**
2 * variable global declaration
3 * @type {[type]}
4 */
5var baseUrl = window.location.protocol + "//" + window.location.host;
6var currentModulUrl = baseUrl + '/' + window.location.pathname.split('/')[2] + '/';
7var baseUrl = (window.location.host == "localhost") ? baseUrl + '/' + window.location.pathname.split('/')[1] + '/' : baseUrl + '/';
8var currentModulUrl = (window.location.host == "localhost") ? currentModulUrl + window.location.pathname.split('/')[3] + '/' : currentModulUrl;
9var adminModulUrl = (window.location.host == "localhost") ? baseUrl + window.location.pathname.split('/')[2] + '/' : baseUrl + window.location.pathname.split('/')[1] + "/";
10var _currentModul = (window.location.host == "localhost") ? adminModulUrl + window.location.pathname.split('/')[3] + '/' : baseUrl + window.location.pathname.split('/')[1] + '/' + window.location.pathname.split('/')[0] + window.location.pathname.split('/')[2] + '/';
11
12var log = console.log.bind(console);
13
14console.log(baseUrl);
15//https://stackoverflow.com/questions/12118202/jquery-twitter-bootstrap-data-loading-text-button-with-delay
16var ajax_progress = '<div class="loading"> </div>';
17var loading_submit = $('button[data-loading-text]');
18var loading = $('.loading');
19loading.hide();
20var loading_button = '<button type="reset" class="btn btn-secondary kt-spinner kt-spinner--v2 kt-spinner--sm kt-spinner--info" disabled id="loading_button">Loading</button>'
21 /*$('button[data-loading-text]').click(function () {
22 $(this).button('loading');
23 });*/
24
25
26$('.select2').select2();
27
28$(document).ready(function($) {
29
30
31 $('.preventDefault').click(function(event) {
32 event.preventDefault();
33 });
34
35 //select2 ajax
36 var select2_autocomplete = $('.select2_autocomplete');
37 select2_autocomplete.select2(
38
39 {
40 minimumInputLength: 2,
41 ajax: {
42 type: 'POST',
43 url: function() {
44 return select2_autocomplete.attr('url');
45 },
46
47 data: function(params) {
48 var query = {
49 search: params.term,
50 additional: function() {
51 return select2_autocomplete.attr('data');
52 },
53 select2: true
54 }
55 return query;
56 },
57 processResults: function(data) {
58 // parse the results into the format expected by Select2.
59 // since we are using custom formatting functions we do not need to
60 // alter the remote JSON data
61 return {
62 results: data
63 };
64 },
65 cache: true
66 }
67 });
68 //end select2ajax
69
70 //generate token dari tombol modal ke input hidden class="generatedToken"
71 $('.generate_token').click(function(event) {
72 let id = $(this).attr('data-target');
73 let random_string = randomstring(20);
74 $('.generatedToken').val('random_string')
75 $(id).find('input.generatedToken').val('random_string');
76 $(id).find('input.fileupload').attr('table_token', random_string);
77 $(id).find('input.multi_uploader').attr('table_token', random_string);
78 $(id).find('.single_uploader').attr('data-token',random_string);
79
80
81
82 });
83
84
85 //buat nomor jadi terbilang / baca fungi terbilangNumber
86
87 if (typeof terbilang === 'function') {
88 terbilangNumber();
89 }
90 if (typeof readmore === 'function') {
91 readmore()
92 };
93 $(document).ajaxComplete(function() {
94 if (typeof readmore === 'function') {
95 readmore()
96 };
97 $('.datatable').dataTable();
98
99 //if($('.get_attachment').length)
100 //getAttachment();
101 });
102
103
104
105 $(document).on("click", ".readmore_toggle", function(e) {
106 $(this).parent('.readmore').parent().next('readmore_detail').slideToggle();
107 });
108
109
110 //convert from number currency and show nilai after input
111 $(".moneyInput, .currency_input, .money_input").on('keyup keypress blur change', function(e) {
112
113 if (typeof terbilang !== 'function')
114 return;
115
116 let val = $(this).val();
117 val = val.split('.').join("");
118
119
120 let bilang = '';
121 if ($.isNumeric(val)) {
122 bilang = terbilang(parseInt(val));
123 }
124
125 $(this).next('._bilangan').remove();
126 $(this).after("<span class='_bilangan' style='color:#A9A700; font-size: 0.87em;'>" + bilang + "</span>");
127
128
129 });
130
131
132 $('.disable_default, .preventDefault, .prevent_default').on('click', function(e) {
133 e.preventDefault();
134
135 });
136
137
138 $('.form_ajax, .ajax_form, .form_ajax_minimal_config, .ajax_form_minimal_config').on('submit', function(e) {
139 e.preventDefault();
140 $(this).ajaxSubmit(ajax_options);
141 });
142
143
144 $('.ajax_test').on('submit', function(e) {
145 e.preventDefault();
146 $(this).ajaxSubmit(ajax_test_options);
147
148 });
149
150
151 $('.summernote').summernote({
152 height: 380,
153 //your other options here...
154 onpaste: function(e) {
155 var thisNote = $(this);
156 var updatePastedText = function(someNote) {
157 var original = someNote.code();
158 var cleaned = CleanPastedHTML(original); //this is where to call whatever clean function you want. I have mine in a different file, called CleanPastedHTML.
159 someNote.code('').html(cleaned); //this sets the displayed content editor to the cleaned pasted code.
160 };
161 setTimeout(function() {
162 //this kinda sucks, but if you don't do a setTimeout,
163 //the function is called before the text is really pasted.
164 updatePastedText(thisNote);
165 }, 10);
166
167
168 }
169 });
170
171 //datatable on tab resize and make it work
172 //https://github.com/almasaeed2010/AdminLTE/issues/1295#issuecomment-269967005
173 $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
174 $.fn.dataTable.tables({
175 visible: true,
176 api: true
177 }).columns.adjust();
178 });
179
180
181
182 //form repeater
183 if ($('.form_repeater').length) {
184 $(".form_repeater").wrap("<div class='form_repeater_parent'></div>");
185 }
186 $(document).on("click", ".form_repeater a.add_new", function(e) {
187 e.preventDefault();
188
189 let form_repeater = $(this).closest('.form_repeater_parent').find('.form_repeater');
190
191 let id = randomstring(4);
192 //let template = $('#rencana_proyek_template').prop('outerHTML');
193
194 let template = $(this).closest('.form_repeater').last();
195 let new_form = form_repeater.prop('outerHTML');
196
197
198 $(new_form).insertAfter(template);
199 let new_inserted = $(this).closest('.form_repeater_parent').find('.form_repeater').last();
200 let current_form_number = $(this).closest('.form_repeater_parent').find('.form_repeater').length;
201
202 // console.log(current_form_number);
203
204 let new_form_number = parseInt(current_form_number);
205
206 //console.log( new_inserted.find('.form_token'));
207
208
209 new_inserted.find('.form_token').val(random_string(30));
210 new_inserted.find('.token').val(random_string(30));
211 new_inserted.prev().find('#form_tool').hide();
212 new_inserted.find('.form_number').text(new_form_number);
213 new_inserted.find('#form_tool').show();
214 new_inserted.find('#remove').show();
215
216
217 $(this).closest('.form_repeater_parent').find('.form_repeater').find('.select2-container').remove();
218 $(this).closest('.form_repeater_parent').find('.form_repeater').find('.select2').select2();
219
220
221
222 //reinitialize select2
223 var selects = $(this).closest('.form_repeater_parent').find('.form_repeater').find('.select2');
224 $.each(selects, function(i, selectElement) {
225 $(selectElement).removeClass('select2-hidden-accessible').next('.select2-container').remove();
226 $(selectElement).removeAttr('data-select2-id tabindex aria-hidden');
227 initSelect2(selectElement);
228 });
229
230 //new_inserted.find('.select2').select2('destroy');
231 // new_inserted.find('.select2').select2();
232
233 init_datepicker_this_year();
234
235 $(new_inserted).scrollTo();
236
237 //$('.select2').select2();
238
239
240 });
241
242 //delete any rencana item
243 $(document).on('click', '.form_repeater .remove', function(e) {
244
245 let current_form = $(this).closest('.form_repeater').last();
246 let prev_form = current_form.prev();
247
248 let url = $(this).attr('url');
249 let id = $(this).attr('data-id');
250
251 deleteConfirm(url, id, current_form, _form_repeater_enable_previous_form_tool);
252
253
254
255 // current_form.find('#form_tool').hide();
256 // prev_form.find('#form_tool').show();
257
258 });
259
260
261 function _form_repeater_enable_previous_form_tool() {
262 let count_form_repeater = $('.form_repeater').length
263 let previous_form = $('.form_repeater').last();
264
265 previous_form.find('#form_tool').removeClass('display_none');
266
267 //klo hanya satu maka jangan tampilkan delete.
268 if (count_form_repeater == 1) {
269 previous_form.find('#form_tool').find('.remove').hide();
270 return;
271 }
272
273 previous_form.find('#form_tool').find('.remove').show();
274
275
276 }
277
278
279 function initSelect2(selectElement) {
280 $(selectElement).select2();
281 }
282
283 // end form repeater
284
285
286
287
288
289
290
291
292
293});
294//end document ready
295
296
297/*You know dont redirect page if ajax is not finish, if you do php script would be stopped to run*/
298var ajax_test_options = {
299 dataType: 'json',
300 beforeSubmit: showPostLoadingTest,
301
302};
303
304//prevent double posting
305function showPostLoadingTest(elem, form) {
306
307 var isValid = checkRequiredInput();
308
309 //to much weight to bear when file input is posted
310 removeElement('input[type="file"]');
311 removeElement('.lampiran_prasyarat');
312 $(form).removeAttr('enctype');
313
314 //console.log(form);
315 //end removing element
316
317 //loading_submit.button('loading');
318 //
319
320 return isValid;
321}
322
323
324
325
326
327
328/*end ajax waiting to response*/
329
330
331/*You know dont redirect page if ajax is not finish, if you do php script would be stopped to run*/
332var ajax_options = {
333 success: ajaxResponse,
334 dataType: 'json',
335 beforeSubmit: showPostLoading,
336
337};
338
339//prevent double posting
340function showPostLoading(elem, form) {
341
342
343 var isFormComplete = checkRequiredInput(form);
344
345 if (!isFormComplete) {
346 swalError('Mohon lengkapi isian form', 'input.is-invalid');
347 return false;
348 }
349
350 //is there any input confirm type, if so make sure it same as confirm input
351 if ($(form).find('.input_confirm').length) {
352 var input = $(form).find('.input');
353 var input_confirm = $(form).find('.input_confirm');
354 if (input.val() != input_confirm.val()) {
355 var msg = (input.attr('msg')) ? input.attr('msg') : 'Pastikan input konfirmasi sesuai';
356 errorNotification(msg, 6000);
357
358 input_confirm.css('border-color', 'red');
359 input_confirm.val('');
360 input_confirm.focus();
361 return false;
362 }
363
364 }
365
366 //loading status
367 let submit_button = $(form).find('button[type="submit"]');
368 submit_button.hide();
369
370 //console.log(form);
371
372
373 //to much weight to bear when file input is posted
374 $(form).find('input[type="file"]').val(null);
375 $(form).find('.lampiran_prasyarat').val(null);
376 $(form).removeAttr('enctype');
377 //end removing element
378
379
380 submit_button.after(loading_button);
381 loading_submit.button('loading');
382}
383
384// function enableSubmit(elem, konfirmasi="Simpan") {
385
386// show_hide_loading_button();
387
388// // $(elem).removeAttr('disabled');
389// // $(elem).removeClass('disabled');
390// // $(elem).text(konfirmasi);
391
392// }
393
394function show_hide_loading_button() {
395 var submit_button = $('button[type="submit"]');
396 var loading_button = $('#loading_button');
397
398 submit_button.toggle();
399 loading_button.toggle();
400}
401
402
403
404function ajaxResponse(responseText, statusText, xhr, form) {
405
406
407
408 let msg = (responseText.msg) ? responseText.msg : 'Error waktu simpan data, Hubungi Developer! ';
409
410 if (responseText.error == 1)
411 swalError(msg);
412
413 if (responseText.error == 0) {
414
415 let msg = (responseText.msg) ? responseText.msg : 'Data Berhasil Diproses';
416
417 if (responseText.redirect === undefined) {
418 successNotification(responseText.msg);
419 } else {
420 swalSuccessResponse(msg, responseText.redirect);
421 }
422
423
424
425
426
427
428 //is called from modal form
429 // if yes then close the modal and catch with this $("#modal_id").on("hidden.bs.modal", function () {
430 let isModalForm = $(form).closest('.modal').length;
431 //console.log($(form).closest('.modal'));
432 if (isModalForm) {
433 let id = $(form).closest('.modal').attr('id');
434 $('#' + id).modal('hide');
435 }
436
437
438 let clearform = $(form).attr('clearform');
439 if (typeof clearform !== 'undefined' && clearform !== false) {
440 $(form).clearForm();
441
442 }
443
444
445 runCallBack();
446
447
448 }
449
450 if (responseText.enableSubmit == 1) {
451
452 //show_hide_loading_button();
453
454 let label_submit = (responseText.submitLabel) ? responseText.submitLabel : 'Simpan';
455
456
457
458 let submit_button = $(form).find('button[type="submit"]');
459 let loading_button = $(form).find('#loading_button');
460
461 loading_button.hide();
462 submit_button.show();
463
464
465
466 }
467
468
469 //run callback
470 function runCallBack() {
471 let callBackExist = $(form).attr('callback');
472 if (typeof callBackExist !== typeof undefined && callBackExist !== false) {
473 let callback = $(form).attr('callback');
474
475 //callback();
476 window[callback]();
477 }
478 }
479
480
481
482
483
484
485
486}
487
488
489
490function checkRequiredInput(form) {
491 var valid_state = true;
492 var in_valid_class = 'is-invalid';
493
494 $(form).find('[data-required="true"]').each(function() {
495 if ((this.value == 0)) {
496 valid_state = false;
497 $(this).closest('div.form-group').addClass('tr_red');
498 $(this).addClass(in_valid_class);
499 isSelect2(this);
500 console.log(this.name);
501
502 } else {
503 isSelect2(this, true);
504 $(this).closest('div.form-group').removeClass('tr_red');
505 $(this).removeClass(in_valid_class);
506
507 }
508
509
510 });
511
512
513 $(form).find('[required]').each(function() {
514 if ((this.value == 0)) {
515 valid_state = false;
516 $(this).closest('div.form-group').addClass('tr_red');
517 $(this).addClass(in_valid_class);
518 isSelect2(this);
519 console.log(this.name);
520 } else {
521 isSelect2(this, true);
522 $(this).closest('div.form-group').removeClass('tr_red');
523 $(this).removeClass(in_valid_class);
524
525 }
526
527 });
528
529
530 function isSelect2(elem, valid = false) {
531 var elem = $(elem);
532 if (elem.hasClass('select2') && !valid) {
533 $(elem).next().find('.select2-selection').addClass(in_valid_class);
534 }
535
536 if (elem.hasClass('select2') && valid) {
537 $(elem).next().find('.select2-selection').removeClass(in_valid_class);
538 }
539 }
540
541
542
543 return valid_state;
544
545 // if (valid) {
546
547 // return true;
548
549
550 // } else {
551 // //swalError('Mohon Lengkapi isian');
552 // return valid;
553 // }
554
555
556}
557
558/*end ajax waiting to response*/
559
560function removeElement(element) {
561
562 $(element).remove();
563
564}
565
566
567//autogrow textarea
568//$('.autogrow').autogrow();
569
570
571
572//general datatable initiation
573
574(function($) {
575 'use strict';
576 var datatableInit = function() {
577 $('#datatable-default').dataTable();
578 $('.datatable').dataTable();
579 $('.datatable-responsive').dataTable({
580 responsive: true
581 });
582
583 $('.datatable_no_top_tool').dataTable({
584 "ordering": false,
585 "info": false
586 });
587 };
588
589
590
591 $(function() {
592 datatableInit();
593 });
594
595}).apply(this, [jQuery]);
596
597
598//end datatable general initiation
599
600$("#moneyInput, #money_input, .currency_input, .moneyInput, .money_input").maskMoney({
601 thousands: '.',
602 decimal: ',',
603 affixesStay: false,
604 precision: 0
605});
606$(".telp, .phone, #phone, #telp, #telephone").mask("9999-?9999-9999");
607$(".nip").mask("9999 9999 9999 9999 ?");
608$(".fax, #fax").mask("9999-?9999-9999-9999");
609$(".number_input").mask("99?");
610
611
612
613
614function terbilangNumber() {
615 $('.terbilang').each(function() {
616 let val = $(this).text();
617 let bilang = terbilang(val);
618
619 $(this).text(bilang);
620 });
621}
622
623
624
625function readmore() {
626
627 let readmore_detail = $('readmore_detail');
628
629 readmore_detail.css({
630 'display': 'block',
631 'padding-left': '10px'
632 });
633 readmore_detail.hide();
634
635 $('.readmore').each(function() {
636 if ($(this).find('.readmore_toggle').length)
637 return;
638
639 $(this).append(' <i class="fa fa-angle-down text-info readmore_toggle"></i>');
640 $(this).find('i.fa').css("border", "1px solid #E2E2E2");
641 $(this).find('i.fa').css("padding", "2px 4px");
642 $(this).find('i.fa').css("margin-left", "8px");
643 $(this).find('i.fa').css("cursor", "pointer");
644
645 });
646}
647
648
649
650
651
652
653
654
655
656function cl(text) {
657 console.log(text);
658}
659
660
661function is_function(func) {
662 return typeof window[func] !== 'undefined' && $.isFunction(window[func]);
663}
664
665
666
667function deleteConfirm(url, id, element_to_remove = false, callback = false) {
668
669 var targetUrl = url;
670 Swal.fire({
671 title: 'Anda yakin ingin menghapus ?',
672 text: "Data yang dihapus tidak bisa dikembalikan lagi",
673 type: 'warning',
674 showCancelButton: true,
675 confirmButtonColor: '#3085d6',
676 cancelButtonColor: '#d33',
677 confirmButtonText: 'Ya, Hapus'
678 }).then(function(result) {
679
680 $.ajax({
681 type: 'post',
682 url: targetUrl,
683 data: {
684 'id': id
685 },
686 success: function(response) {
687
688
689 var json = (isJSON(response)) ? response : $.parseJSON(response);
690
691 //doing msg response here
692 ajaxResponse(json, statusText = false, xhr = false, $form = false);
693
694
695 if (json.error == 1)
696 return;
697
698
699
700 // $(element_to_remove).slideUp(500, function() { $(this).remove(); });
701 if (element_to_remove) {
702 element_to_remove.slideUp(500, function() {
703 $(this).remove();
704 });
705 }
706
707 if (typeof callback !== typeof undefined && callback !== false)
708 window[callback]();
709
710
711
712
713
714
715
716
717 }
718
719 });
720
721
722 });
723}
724
725
726
727
728
729//form konfirmasi
730function formConfirm(formObj) {
731
732 var targetUrl = $(formObj).attr('href');
733 var text = $(formObj).attr('text');
734
735 var ajax_form = $(formObj).closest('form').hasClass('ajax_form') || $(formObj).closest('form').hasClass('form_ajax_minimal_config');
736
737
738 if (text == 0)
739 text = "Apakah anda yakin ingin melanjutkan proses ini ? ";
740
741 Swal.fire({
742 title: 'Yakin ingin melanjutkan ? ',
743 text: text,
744 type: 'warning',
745 showCancelButton: true,
746 confirmButtonColor: '#3085d6',
747 cancelButtonColor: '#d33',
748 confirmButtonText: 'Ya, Lanjutkan'
749 }).then(function(result) {
750
751
752 if (ajax_form) {
753 var form = $(formObj).closest('form');
754 $(form).ajaxSubmit(ajax_options);
755 return;
756 }
757
758 //console.log(adminModulUrl+targetUrl);
759 window.location = adminModulUrl + targetUrl;
760
761 });
762
763
764
765
766
767
768}
769
770
771
772
773
774/*
775Datepicker setting for siujk dan pjtbu
776 */
777// months: ["Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"],
778// monthsShort: ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"],
779
780$.fn.datepicker.dates['id'] = {
781 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
782 daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
783 daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
784
785 today: "Today",
786 clear: "Clear",
787 format: "mm/dd/yyyy",
788 titleFormat: "MM yyyy",
789 /* Leverages same syntax as 'format' */
790 weekStart: 0
791};
792
793
794var _current_year = new Date().getFullYear();
795var _curent_month = new Date().getMonth();
796var _curent_date = new Date().getDate();
797var _next_month = parseInt(_curent_month) + 1;
798var _previous_20_year = parseInt(_current_year) - 20;
799var _today = _curent_date + '-' + _next_month + '-' + _current_year;
800
801init_datepicker_tanggal_lahir();
802init_datepicker_tanggal_terbit();
803init_datepicker_berlaku_sd();
804init_datepicker_this_year();
805
806function init_datepicker_tanggal_lahir() {
807 //date picker
808 $('.datepicker_tanggal_lahir').datepicker({
809 format: 'dd-MM-yyyy',
810
811 todayHighlight: true,
812 startView: 1,
813 endDate: _curent_date + '-' + _next_month + '-' + _previous_20_year,
814 });
815
816}
817
818function init_datepicker_tanggal_terbit() {
819 $('.datepicker_tanggal_terbit').datepicker({
820 format: 'dd-MM-yyyy',
821
822 todayHighlight: true,
823 startView: 1,
824 endDate: _today
825
826 });
827}
828
829function init_datepicker_berlaku_sd() {
830
831 $('.datepicker_berlaku_sd').datepicker({
832 format: 'dd-MM-yyyy',
833
834 startDate: _today,
835 startView: 1,
836 endDate: new Date(_current_year + 5, _curent_month, _curent_date)
837
838 });
839}
840
841
842function init_datepicker_this_year() {
843
844 $('.datepicker_this_year').datepicker({
845 format: 'dd-MM-yyyy',
846 startView: 1,
847
848 });
849}
850
851
852//end datepicker
853
854
855
856
857//
858/**
859 * [add_upload_form tambahkan upload form waktu loading awal untuk halaman penambahan siujk dan pjtbu]
860 * @dom {[Jquery Object]} dom : this in jquery
861 */
862function add_upload_form(dom) {
863 var form = $(dom).closest("tr").first('td').find('.upload_form');
864 var table_reference = $(dom).attr('table_reference');
865 var form_token = $(dom).attr('form-token');
866 var form_name = $(dom).attr('form-name');
867 var is_required = $(dom).attr('is_required');
868
869 if (form.length != 1) {
870
871 $(dom).closest("tr").first('td').find('br').after(upload_form_tmp);
872
873
874 var form_upload = $(dom).closest("tr").first('td').find('.upload_form');
875
876 //change token based on the input
877 form_upload.find('.upload_input').attr({
878 table_reference: table_reference,
879 name: form_name
880 });
881
882 form_upload.find('.lampiran_prasyarat').attr('name', 'lampiran_' + form_name);
883 if (typeof is_required !== typeof undefined && is_required !== false) {
884 form_upload.find('.lampiran_prasyarat').attr('value', '1');
885 }
886
887 form_upload.find('.upload_input').data('token', form_token);
888 //end change token
889
890 form_upload.removeClass('display_none');
891 form_upload.find('.upload_keterangan, .progress-wrp').hide();
892
893
894
895
896
897 } else {
898 $(dom).closest("tr").find('.upload_form').toggle(500);
899 $(dom).closest("tr").first('td').find('.upload_form').removeClass('display_none');
900
901 }
902
903}
904
905/**
906 * [looping_tambah_upload_form description]
907 * @return {[type]} [description]
908 */
909function looping_tambah_upload_form() {
910 $('.upload_form_check_box').each(function() {
911 add_upload_form(this);
912 $(this).attr("checked", "checked");
913 $(this).parent('td').addClass('checkbox');
914 //$(this).css("background-color", "yellow");
915 });
916}
917
918
919/**
920 * Validasi Swal
921 */
922
923//kasih warna
924function lampiran_kurang() {
925 $('input.lampiran_prasyarat[type="hidden"]').each(function() {
926 if ((this.value == 0)) {
927 $(this).parent().parent().parent().css("border", "#FE6565 solid 1px");
928 }
929 });
930}
931
932//require swal 2
933const Toast = Swal.mixin({
934 toast: true,
935 position: 'top-end',
936 showConfirmButton: false,
937 timer: 3000
938});
939
940
941
942// post-submit callback Halaman penambahan PJTBU dan SIUJK
943// url contoh = site_url().'/web/admin/siujk'
944function swalSuccessResponse(msg = false, url = false) {
945
946 msg = (msg) ? msg : 'Data diproses';
947 url = (!url || url === typeof undefined) ? false : url;
948
949 Swal.fire({
950 title: msg,
951 text: 'Terimakasih data anda telah diproses sistem',
952 type: 'success',
953 timer: 2000,
954 onClose: function() {
955 if (url)
956 window.location = url;
957
958
959 }
960 }).then(
961 function() {},
962 // handling the promise rejection
963 function(dismiss) {
964
965 if (dismiss === 'timer' && url) {
966 window.location = url;
967 }
968
969
970 }
971 );
972
973
974}
975
976
977function swalErrorLampiran() {
978 Swal.fire({
979 title: 'Error ',
980 text: 'Ada beberapa berkas yang perlu dilengkapi! ',
981 type: 'warning',
982 confirmButtonColor: '#E23B4F',
983 confirmButtonText: 'Ok',
984 }).then(function() {
985 $(window).scrollTop(0);
986 });
987 return;
988}
989
990
991function swalError(msg, scroll = true) {
992 Swal.fire({
993 title: 'Error ',
994 text: msg,
995 type: 'warning',
996 confirmButtonColor: '#E23B4F',
997 confirmButtonText: 'Ok',
998
999 }).then(function() {
1000 if (scroll === true) {
1001 $("html, body").animate({
1002 scrollTop: 0
1003 }, "slow");
1004 } else {
1005 $(scroll).scrollTo(400);
1006
1007 }
1008
1009
1010 });
1011
1012
1013 return;
1014}
1015
1016$.fn.scrollTo = function(padding, speed) {
1017 if (typeof(speed) === 'undefined')
1018 speed = 1000;
1019
1020 if (typeof(padding) === 'undefined')
1021 padding = 0;
1022
1023 $('html, body').animate({
1024 scrollTop: (parseInt($(this).offset().top) - parseInt(padding))
1025 }, speed);
1026};
1027
1028
1029//end pengecekan pada halaman penambahan baru di siujk dan pjtbu
1030
1031function successNotification(msg = 'Data tersimpan') {
1032 noty({
1033 text: '<i class="glyphicon glyphicon-ok"> </i> ' + msg,
1034 layout: 'topRight',
1035 theme: 'defaultTheme', // or relax
1036 type: 'success',
1037 progressBar: true,
1038 timeout: 2800,
1039 }); // success, error, warning, information, notification});
1040
1041
1042}
1043
1044function errorNotification(msg = 'Data gagal tersimpan', timeout = 15000) {
1045 noty({
1046 text: '<i class="glyphicon glyphicon-remove"> </i> ' + msg,
1047 layout: 'topRight',
1048 theme: 'defaultTheme', // or relax
1049 type: 'error',
1050 progressBar: true,
1051 timeout: timeout,
1052 }); // success, error, warning, information, notification});
1053}
1054
1055function infoNotification(msg = 'Mohon perhatikan Informasi', timeout = 15000) {
1056 noty({
1057 text: '<i class="glyphicon glyphicon-remove"> </i> ' + msg,
1058 layout: 'topRight',
1059 theme: 'defaultTheme', // or relax
1060 type: 'information',
1061 progressBar: true,
1062 timeout: timeout,
1063 }); // success, error, warning, information, notification});
1064}
1065
1066
1067function warningNotification(msg = 'Mohon perhatikan Informasi', timeout = 15000) {
1068 noty({
1069 text: '<i class="glyphicon glyphicon-remove"> </i> ' + msg,
1070 layout: 'topRight',
1071 theme: 'defaultTheme', // or relax
1072 type: 'warning',
1073 progressBar: true,
1074 timeout: timeout,
1075 }); // success, error, warning, information, notification});
1076}
1077
1078function defaultNotification(msg = 'Mohon perhatikan Informasi', timeout = 15000) {
1079 noty({
1080 text: '<i class="glyphicon glyphicon-remove"> </i> ' + msg,
1081 layout: 'topRight',
1082 theme: 'defaultTheme', // or relax
1083 type: 'notification',
1084 progressBar: true,
1085 timeout: timeout,
1086 }); // success, error, warning, information, notification});
1087}
1088
1089
1090
1091
1092/*hidden*/
1093
1094
1095// Semua SUJK
1096function validasiOkSiujk(e) {
1097
1098 var url = adminModulUrl + "siujk/updateStatusAttachment";
1099 $.ajax({
1100 url: url,
1101 type: 'POST',
1102 data: {
1103 id: $('input#tb_id').val(),
1104 reference: $('input#reference').val(),
1105 description: e.id,
1106 status: 1,
1107 komentar: $('textarea#' + e.id).val().trim(),
1108 row_index: $('input#row_index[name="' + e.id + '"]').val().trim()
1109 },
1110 success: function(e) {
1111 successNotification('Status Validasi Tersimpan')
1112 }
1113 });
1114 setTimeout(function() {
1115 //disabled_button_validasi()
1116 }, 1000);
1117}
1118
1119function validasiNoSiujk(e) {
1120 var url = adminModulUrl + "siujk/updateStatusAttachment";
1121 $.ajax({
1122 url: url,
1123 type: 'POST',
1124 data: {
1125 id: $('input#tb_id').val(),
1126 reference: $('input#reference').val(),
1127 description: e.id,
1128 status: 0,
1129 komentar: $('textarea#' + e.id).val().trim()
1130 },
1131 success: function(e) {
1132 successNotification('Status Revisi Tersimpan');
1133 }
1134 });
1135
1136 setTimeout(function() {
1137 // disabled_button_validasi()
1138 }, 1000);
1139}
1140
1141function revisi_pjtbu() {
1142 var url = adminModulUrl + "pjtbu/revisi";
1143 $.ajax({
1144 url: url,
1145 type: 'POST',
1146 data: {
1147 id: $('input#tb_id').val(),
1148 reference: $('input#reference').val(),
1149 komentar_umum: $('textarea#komentar_umum').val().trim(),
1150 validasi_email_check: $('#validasi_email_check').val()
1151 },
1152 success: function(e) {
1153 swal('Berhasil');
1154 window.location = adminModulUrl + 'pjtbu/';
1155 }
1156 });
1157}
1158
1159function revisi_siujk() {
1160 var url = adminModulUrl + "siujk/revisi";
1161 $.ajax({
1162 url: url,
1163 type: 'POST',
1164 data: {
1165 id: $('input#tb_id').val(),
1166 reference: $('input#reference').val(),
1167 komentar_umum: $('textarea#komentar_umum').val().trim(),
1168 validasi_email_check: $('#validasi_email_check').val()
1169 },
1170 success: function(e) {
1171 swal('Berhasil');
1172 window.location = adminModulUrl + 'siujk/';
1173 }
1174 });
1175}
1176
1177function updateValidasiSiujk() {
1178 var url = adminModulUrl + "siujk/updateValidasi";
1179 $.ajax({
1180 url: url,
1181 type: 'POST',
1182 data: {
1183 id: $('input#tb_id').val(),
1184 reference: $('input#reference').val(),
1185 komentar_umum: $('textarea#komentar_umum').val().trim(),
1186 validasi_email_check: $('#validasi_email_check').val()
1187 },
1188 success: function(e) {
1189 swal('Berhasil');
1190 window.location = adminModulUrl + 'pjtbu/';
1191 }
1192 });
1193}
1194
1195function terbitkanSIUJK() {
1196 var url = adminModulUrl + "siujk/terbitkan";
1197 $.ajax({
1198 url: url,
1199 type: 'POST',
1200 data: {
1201 id: $('input#tb_id').val(),
1202 reference: $('input#reference').val(),
1203 komentar_umum: $('textarea#komentar_umum').val().trim(),
1204 validasi_email_check: $('#validasi_email_check').val()
1205 },
1206 success: function(e) {
1207 swal('Berhasil');
1208 }
1209 });
1210}
1211
1212// Semua PJTBU
1213
1214function updateValidasi() {
1215 var url = adminModulUrl + "pjtbu/updateValidasi";
1216 $.ajax({
1217 url: url,
1218 type: 'POST',
1219 data: {
1220 id: $('input#tb_id').val(),
1221 reference: $('input#reference').val(),
1222 komentar_umum: $('textarea#komentar_umum').val().trim(),
1223 validasi_email_check: $('#validasi_email_check').val()
1224 },
1225 success: function(e) {
1226 swal('Berhasil');
1227 window.location = adminModulUrl + 'pjtbu/';
1228 }
1229 });
1230
1231}
1232
1233function terbitkanPJTBU() {
1234 var url = adminModulUrl + "pjtbu/terbitkan";
1235 $.ajax({
1236 url: url,
1237 type: 'POST',
1238 data: {
1239 id: $('input#tb_id').val(),
1240 reference: $('input#reference').val(),
1241 komentar_umum: $('textarea#komentar_umum').val().trim(),
1242 validasi_email_check: $('#validasi_email_check').val()
1243 },
1244 success: function(e) {
1245 swal('Berhasil');
1246 }
1247 });
1248}
1249
1250
1251$(document).ready(function() {
1252
1253
1254
1255 $(".form_konfirm, .form_konfirmasi, .form_confirm").click(function(e) {
1256 e.preventDefault();
1257 formConfirm(this);
1258 });
1259
1260
1261
1262
1263 var date_input = $('input[for="date"]');
1264 var date_options = {
1265 format: 'dd-mm-yyyy',
1266 todayHighlight: true,
1267 autoclose: true,
1268 }
1269 date_input.datepicker(date_options);
1270
1271 $("a.fancybox").fancybox();
1272
1273 /* Using custom settings */
1274
1275 $("a.fancybox").fancybox({
1276 'hideOnContentClick': true
1277 });
1278
1279 /* Apply fancybox to multiple items */
1280
1281 $("a.group").fancybox({
1282 'transitionIn': 'elastic',
1283 'transitionOut': 'elastic',
1284 'speedIn': 600,
1285 'speedOut': 200,
1286 'overlayShow': false
1287 });
1288 /**/
1289
1290 $(document).on('click', 'button#simpanvalidasi', function(e) {
1291
1292 var attachment = {};
1293 var input = {};
1294 // $('span.validasi_oke').each(function() {
1295 // attachment[this.id] = $('span[id="' + this.id + '"]').attr('value');
1296 // });
1297 $('textarea').each(function() {
1298 input[this.id] = $('#' + this.id).val();
1299 });
1300
1301
1302 var url = adminModulUrl + "pjtbu/validasi/" + input.tb_id;
1303 $.ajax({
1304 url: url,
1305 type: 'POST',
1306 data: {
1307 attachment: attachment,
1308 input: input
1309 },
1310 success: function(e) {
1311 swal('Berhasil');
1312 }
1313 });
1314 });
1315 /**/
1316
1317
1318
1319
1320 $('.form_floating_placeholder').floatingPlaceholder();
1321
1322 $(document).on("click", ".upload_check_box", function(e) {
1323
1324
1325 $(this).closest("tr").find('.upload_form').toggle(500);
1326
1327
1328 var attachment_type = $(this).attr('form-name');
1329 var form_token = $(this).attr('form-token');
1330 var table_reference = $(this).attr('table_reference');
1331 var row_index = $(this).attr('row-index');
1332
1333 var object = {
1334 attachment_type: attachment_type,
1335 form_token: form_token,
1336 table_reference: table_reference,
1337 row_index: row_index
1338 };
1339
1340 //if sudah ada jangan load ajax lagi tapi tampilkan yang sudah ada
1341 if ($(this).closest("tr").find('.upload_form').find(".upload_keterangan").find(".file_name").text().length) {
1342 // element exists
1343 $(this).closest("tr").find('.upload_form').find(".upload_keterangan").show();
1344 } else {
1345 create_html_upload_dom(this, object);
1346 }
1347
1348
1349
1350 });
1351
1352
1353
1354 //upload multi handler
1355 function create_html_upload_dom(dom, object) {
1356 var url = adminModulUrl + "attachment/create_upload_html";
1357 $.ajax({
1358 url: url,
1359 type: 'POST',
1360 dataType: 'html',
1361 data: {
1362 object: object
1363 },
1364 })
1365 .done(function(data) {
1366
1367 $(dom).closest("tr").find('.upload_form').html(data);
1368 $(dom).closest("tr").find('.upload_form').find('.progress-wrp').hide();
1369 $(dom).closest("tr").find('.upload_form').find('.upload_keterangan,.icon-status-succes,.icon-status-error').hide();
1370
1371 });
1372
1373
1374 }
1375
1376
1377
1378
1379 //halaman validasi
1380
1381
1382
1383
1384
1385
1386
1387
1388 /*END halaman Validasi*/
1389 $(document).on('click', '.multi_uploader', function(event) {
1390 //event.preventDefault();
1391 /* Act on the event */
1392 multiUploaderInit($(this));
1393 });
1394
1395 // $('.multi_uploader').click(function(event) {
1396 // /* Act on the event */
1397 // // console.log($(this).attr('description'));
1398 // multiUploaderInit($(this));
1399
1400 // });
1401
1402
1403
1404
1405
1406
1407
1408}); //end document ready
1409
1410
1411
1412
1413
1414
1415
1416
1417//tampilkan warna penekanan pada input yang fokus
1418$(document).on('focus', 'input, select', function(e) {
1419 $(this).prev('i').css('color', '#2B3AFC');
1420
1421});
1422
1423$(document).on('blur', 'input, select', function(e) {
1424 $(this).prev('i').css('color', '');
1425
1426});
1427
1428
1429
1430
1431
1432//to remove ugly button browser html
1433$(document).on('click', '.uploadbutton', function() {
1434
1435 $(this).next('input[type=file]').click();
1436});
1437
1438
1439//
1440$(document).on('change', '.upload_input, .single_uploader', function() {
1441
1442
1443 let attachment_type = $(this).attr('name');
1444 let form_token = $(this).attr('data-token');
1445 let table_reference = $(this).attr('table_reference');
1446 let row_index = $(this).attr('row-index');
1447 let table_id = $(this).attr('table_id');
1448 let tmp = $(this).attr('tmp');
1449 let no_preview = (typeof($(this).attr('no_preview')) == 'undefined') ? false : true;
1450 let dom = this;
1451
1452
1453 let object = {
1454 attachment_type: attachment_type,
1455 form_token: form_token,
1456 table_reference: table_reference,
1457 row_index: row_index,
1458 table_id: table_id,
1459 tmp: tmp
1460 };
1461
1462 console.log(object);
1463
1464
1465 $(this).next().show();
1466
1467 let file = $(this)[0].files[0];
1468
1469
1470
1471 let upload = new Upload(file);
1472
1473 //doing upload file
1474 upload.doUpload(object, dom);
1475
1476
1477
1478});
1479
1480
1481
1482
1483
1484
1485//Change id to your id
1486$(document).on('click', '.reupload', function(e) {
1487 e.preventDefault();
1488
1489 $(this).parent().parent().parent().find('.uploadbutton').toggle(500);
1490
1491});
1492
1493
1494var _upload_button = ' <div class="uploadbutton btn btn-label-info btn-elevated btn-sm"><i class="fa fa-paperclip"></i> Pilih file</div>';
1495var _upload_required_input = ' <input class="lampiran_prasyarat" value="0" name="" type="hidden">';
1496var _upload_keterangan = ' <div class="progress-wrp display_none" > <div class="progress-bar"></div> <div class="status">0%</div> </div> <div class="upload_keterangan display_none" > <span class="file_name"></span> <span class="succces_upload pull-right" style="padding-left: 10px"> <i class="fa fa-check icon-status-succes text-success " style="display: none;"> </i> <a href="#" class="reupload pull-right" >Upload ulang ?</a><span class="error_upload pull-right"> <i class="fa fa-exclamation-triangle icon-status-error text-danger "> </i></span> </div>';
1497var _upload_preview = ' <div class="image_preview col-md-2 strict_padding display_none" data-base_url="' + adminModulUrl + '" style="padding: 0px"> </div>'
1498var _preview_link = '<a class="fancybox" href=""><img src="" alt="preview_lampiran"/></a> ';
1499
1500$(_upload_button).insertBefore('.single_uploader');
1501$(_upload_preview).insertAfter('.single_uploader');
1502
1503$(_upload_keterangan).insertAfter('.single_uploader');
1504$(_upload_required_input).insertAfter('.single_uploader');
1505
1506
1507//single retrieve attachment
1508//param token, description
1509if($('.get_attachment').length)
1510 getAttachment();
1511
1512function getAttachment() {
1513$('.get_attachment').each(function(index, el) {
1514
1515 let token = $(this).attr('token');
1516 let description = $(this).attr('description');
1517 let height = (typeof($(this).attr('height')) == 'undefined') ? false : $(this).attr('height');
1518 let width = (typeof($(this).attr('width')) == 'undefined') ? false : $(this).attr('width');
1519 let el_class = (typeof($(this).attr('el_class')) == 'undefined') ? false : $(this).attr('el_class');
1520 let profile = (typeof($(this).attr('profile')) == 'undefined') ? false : true;
1521 let no_preview = (typeof($(this).attr('no_preview')) == 'undefined') ? false : true;
1522
1523 //large, mid, thumb, preview
1524 let size = (typeof($(this).attr('size')) == 'undefined') ? 'thumb' : $(this).attr('size');
1525
1526 if (typeof token !== typeof undefined && token !== false) {
1527 $(this).html('<div class="loading"> </div>');
1528
1529 let dom = $(this);
1530
1531
1532 $.ajax({
1533 url: adminModulUrl + 'attachment/get_preview',
1534 type: 'POST',
1535 dataType: 'json',
1536 data: {
1537 table_token: token,
1538 attachment_type: description,
1539 size: size
1540 },
1541 })
1542 .done(function(json) {
1543 //console.log(json);
1544 if (json.error === 1) {
1545
1546 if (profile) {
1547 dom.append(_upload_preview);
1548 let image_preview = dom.find('.image_preview');
1549 image_preview.removeClass('display_none');
1550 image_preview.html(_preview_link);
1551 image_preview.find('img').attr('src', "https://i.ibb.co/zmcxzvV/no-profile.jpg");
1552 dom.find('.loading').remove();
1553 return;
1554 }
1555
1556
1557 dom.html(json.msg);
1558 return;
1559 } //end error
1560
1561
1562 if (no_preview) {
1563 dom.append(_upload_preview);
1564 let image_preview = dom.find('.image_preview');
1565 image_preview.removeClass('display_none');
1566 image_preview.html(_preview_link);
1567 image_preview.find('a').attr('href', json.base_url + json.preview);
1568 image_preview.find('img').remove();
1569 dom.find('.loading').remove();
1570 return;
1571 }
1572
1573
1574 if (json.is_image === true) {
1575 //dom.html(json.original_name);
1576 dom.append(_upload_preview);
1577 let image_preview = dom.find('.image_preview');
1578 image_preview.removeClass('display_none');
1579 image_preview.html(_preview_link);
1580 image_preview.find("a.fancybox").fancybox();
1581 image_preview.find('a').attr('href', json.base_url + json.preview);
1582 image_preview.find('img').attr('src', json.base_url + json.thumb_preview);
1583
1584 if (height)
1585 image_preview.find('img').attr('height', height);
1586
1587
1588 if (width)
1589 image_preview.find('img').attr('width', width);
1590
1591 if (el_class)
1592 image_preview.find('img').addClass(el_class);
1593
1594
1595
1596
1597 }
1598
1599
1600
1601 if (json.is_image !== true) {
1602 dom.append(_upload_preview);
1603 let image_preview = dom.find('.image_preview');
1604 image_preview.removeClass('col-md-2');
1605 image_preview.addClass('col-md-12');
1606 image_preview.removeClass('display_none');
1607 image_preview.html(json.file_preview);
1608 image_preview.find('a').html(json.file_icon);
1609 image_preview.find('a').append(' ' + json.original_name);
1610
1611 }
1612
1613 dom.find('.loading').remove();
1614
1615
1616
1617
1618 })
1619 }
1620
1621
1622});
1623
1624}
1625
1626
1627function getSingleAttachment(dom, token, description, size='mid')
1628{
1629
1630 let width = '100px';
1631
1632
1633 $.ajax({
1634 url: adminModulUrl + 'attachment/get_preview',
1635 type: 'POST',
1636 dataType: 'json',
1637 data: {
1638 table_token: token,
1639 attachment_type: description,
1640 size: size
1641 },
1642 })
1643 .done(function(json) {
1644 //console.log(json);
1645 if (json.error === 1) {
1646
1647
1648 dom.html(json.msg);
1649 return;
1650 } //end error
1651
1652
1653
1654
1655 if (json.is_image === true) {
1656 //dom.html(json.original_name);
1657 //dom.append(_upload_preview);
1658 let image_preview = dom.find('.image_preview');
1659 image_preview.removeClass('display_none');
1660 image_preview.html(_preview_link);
1661 image_preview.find("a.fancybox").fancybox();
1662 image_preview.find('a').attr('href', json.base_url + json.preview);
1663 image_preview.find('img').attr('src', json.base_url + json.thumb_preview);
1664 image_preview.css('margin-top', '10px');
1665
1666
1667 if (width)
1668 image_preview.find('img').attr('width', width);
1669
1670 }
1671
1672
1673
1674 if (json.is_image !== true) {
1675 dom.append(_upload_preview);
1676 let image_preview = dom.find('.image_preview');
1677 image_preview.removeClass('col-md-2');
1678 image_preview.addClass('col-md-12');
1679 image_preview.removeClass('display_none');
1680 image_preview.html(json.file_preview);
1681 image_preview.find('a').html(json.file_icon);
1682 image_preview.find('a').append(' ' + json.original_name);
1683
1684 }
1685
1686 dom.find('.loading').remove();
1687
1688 let upload_keterangan = dom.find('.upload_keterangan');
1689 upload_keterangan.find('.file_name').text(json.original_name);
1690 upload_keterangan.find('.error_upload').hide();
1691 upload_keterangan.find('.icon-status-succes').removeAttr('style');
1692 upload_keterangan.css('margin-top', '10px');
1693 upload_keterangan.fadeIn();
1694
1695
1696
1697 });
1698}
1699
1700
1701
1702
1703
1704//get single_uploader preview on load --- for editing / reupload purposes
1705$('.single_uploader').each(function(index, el) {
1706 var attr = $(this).attr('edit_mode');
1707 var dom = $(this);
1708
1709
1710
1711 // For some browsers, `attr` is undefined; for others,
1712 // `attr` is false. Check for both.
1713 if (typeof attr !== typeof undefined && attr !== false) {
1714 $.ajax({
1715 url: adminModulUrl + 'attachment/get_preview',
1716 type: 'POST',
1717 dataType: 'json',
1718 data: {
1719 table_token: dom.attr('data-token'),
1720 attachment_type: dom.attr('name')
1721 },
1722 })
1723 .done(function(json) {
1724 //console.log(json);
1725 if (json.error === 1)
1726 return;
1727
1728 dom.hide();
1729 dom.prev('.uploadbutton').hide();
1730 dom.parent().find(".upload_keterangan").show();
1731
1732 dom.parent().parent().parent().css("border", "#AEFFAE solid 0px");
1733
1734 dom.parent().parent().parent().find('.lampiran_prasyarat').val(false);
1735
1736 dom.parent().find(".upload_keterangan").find('.file_name').removeClass('font-color-red font-bold');
1737
1738 dom.parent().find(".upload_keterangan").find('.icon-status-succes').show();
1739 dom.parent().find(".upload_keterangan").find('.icon-status-error ').hide();
1740
1741 dom.parent().css('display', 'inline-block');
1742
1743 console.log(json);
1744
1745 let image_preview = dom.parent().parent().find('.image_preview');
1746 let base_url = image_preview.attr('data-base_url');
1747 base_url = (base_url !== 'undefined') ? base_url : baseUrl;
1748
1749
1750
1751 if (json.is_image === true) {
1752 dom.parent().find(".upload_keterangan").find('.file_name').html(json.original_name);
1753 image_preview.removeClass('display_none');
1754 image_preview.html(_preview_link);
1755 image_preview.find("a.fancybox").fancybox();
1756 image_preview.find('a').attr('href', base_url + json.preview);
1757 image_preview.find('img').attr('src', base_url + json.thumb_preview);
1758
1759 dom.removeAttr('data-required');
1760 }
1761
1762
1763
1764 if (json.is_image !== true) {
1765 image_preview.removeClass('col-md-2');
1766 image_preview.addClass('col-md-6');
1767 image_preview.removeClass('display_none');
1768 image_preview.html(json.file_preview);
1769 image_preview.find('a').html(json.file_icon);
1770 image_preview.find('a').append(' ' + json.original_name);
1771
1772 dom.removeAttr('data-required');
1773 }
1774
1775 //is there any callback ?
1776 var callback_func = $(dom).attr('callback');
1777 if (typeof callback_func !== typeof undefined && callback_func !== false) {
1778 //console.log(callback_func);
1779 window[callback_func]($(dom));
1780 }
1781
1782
1783 })
1784
1785
1786 }
1787});
1788//end showing preview of previously uploaded file
1789
1790$.fn.hasAttr = function(name) {
1791 return this.attr(name) !== undefined;
1792};
1793
1794//multi uploader automatic creation
1795//require bluimp jquery uploader
1796var _multi_uploader_dom = '<div class="upload_form multi_uploader_dom row"> <div class="col-3"><span class="btn btn-default btn-sm fileinput-button"><i class="fa fa-paperclip"></i><span class="title">Narasumber</span><!-- The global progress bar --><input class="fileupload multi_uploader" type="file" name="files[]" multiple table_token ="" description = "file"></span><div class="uploading display_none "><div class=""><img src="https://i.ibb.co/4WtZHMN/loading.gif" /> Uploading</div></div></div><div class="files_count col-9 display_none"><a href="#" data-toggle="modal" data-target="#file_ket" class="show_modal_file_ket" style="float:right; padding-right: 15px;">Ada <span id="count">3</span> file lampiran</a></div><div class="row"><div class="attachment_list col-12 " style="padding: 20px 0px 0px 15px"></div></div></div>';
1797
1798//create multiuploader
1799$('.multi_uploader').each(function(index, el) {
1800
1801 $(this).hide();
1802
1803 let dom = $(this);
1804 let token = $(this).attr('table_token');
1805 let description = $(this).attr('description');
1806 let title = $(this).attr('title');
1807 let edit_mode = $(this).attr('edit_mode');
1808 let image_only = $(this).hasAttr('image_only');
1809 let tmp = ($(this).hasAttr('permanent')) ? false : true;
1810
1811 title = (title === 'undefined') ? 'Lampiran' : title;
1812
1813
1814
1815 let new_dom = _multi_uploader_dom;
1816 $(_multi_uploader_dom).insertAfter(el);
1817
1818
1819 let upload_dom = $(el).next('.multi_uploader_dom');
1820
1821 upload_dom.find('.multi_uploader').attr('table_token', token);
1822 upload_dom.find('.multi_uploader').attr('description', description);
1823 upload_dom.find('.multi_uploader').attr('tmp', tmp);
1824 upload_dom.find('.multi_uploader').attr('image_only', image_only);
1825 upload_dom.find('span.title').text(title);
1826
1827
1828 if (typeof edit_mode !== typeof undefined && edit_mode !== false) {
1829
1830 get_attachment_list(token, description, upload_dom.find('.attachment_list'));
1831
1832 }
1833
1834
1835
1836 $(el).remove();
1837
1838
1839
1840
1841
1842});
1843
1844
1845
1846//UPLOAD CLASS
1847var Upload = function(file) {
1848 this.file = file;
1849};
1850
1851Upload.prototype.getType = function() {
1852 return this.file.type;
1853};
1854Upload.prototype.getSize = function() {
1855 return this.file.size;
1856};
1857Upload.prototype.getName = function() {
1858 return this.file.name;
1859};
1860Upload.prototype.doUpload = function(object, dom) {
1861
1862
1863 let no_preview = (typeof($(dom).attr('no_preview')) == 'undefined') ? false : true;
1864 var that = this;
1865 var formData = new FormData();
1866
1867 // add assoc key values, this will be posts values
1868 formData.append("file", this.file, this.getName());
1869 formData.append("upload_file", true);
1870 formData.append("object", JSON.stringify(object));
1871
1872 //show loading box
1873 $(dom).parent().find(".progress-wrp").show();
1874
1875 $.ajax({
1876 type: "POST",
1877 url: adminModulUrl + "attachment/upload",
1878 xhr: function() {
1879 var myXhr = $.ajaxSettings.xhr();
1880 if (myXhr.upload) {
1881 myXhr.upload.addEventListener('progress', that.progressHandling, false);
1882 }
1883 return myXhr;
1884 },
1885 success: function(data) {
1886 // your callback here
1887 var json = $.parseJSON(data);
1888 $(dom).hide();
1889 $(dom).prev('.uploadbutton').hide();
1890 $(dom).parent().find(".upload_keterangan").show();
1891
1892 $(dom).parent().parent().parent().css("border", "#AEFFAE solid 0px");
1893 $(dom).parent().parent().parent().find('.lampiran_prasyarat').val(json.status);
1894
1895 //upload gagal or file upload bukan gambar
1896 if (json.status === 0) {
1897
1898 $(dom).parent().find(".upload_keterangan").find('.file_name').addClass('font-color-red font-bold');
1899 $(dom).parent().find(".upload_keterangan").find('.icon-status-error').show();
1900 $(dom).parent().find(".upload_keterangan").find('.icon-status-succes').hide();
1901
1902 errorNotification(json.msg);
1903 return;
1904
1905 }
1906
1907
1908
1909
1910
1911 //tandai sudah diupload di input hidden untuk verifikasi sudah berhasil upload dari lampiran tersebut
1912 //ini untuk form tanpa adanya input form disampingnya
1913
1914
1915 //remove pewarnaan border yang gagal divalidasi yang jadi merah sebelumnya
1916 $(dom).parent().find(".upload_keterangan").find('.file_name').removeClass('font-color-red font-bold');
1917 $(dom).parent().find(".upload_keterangan").find('.icon-status-succes').show();
1918 $(dom).parent().find(".upload_keterangan").find('.icon-status-error ').hide();
1919
1920 $(dom).parent().css('display', 'inline-block');
1921
1922
1923
1924 //untuk form upload yang ada inputannya disampingnya seperti halaman pjtbu isian pendidikan terakhir dsb
1925 $(dom).next().val(json.status);
1926
1927 //check dom, jika form horizontal maka seleksi div sesuaikan
1928 var image_preview = $(dom).closest('tr').find('.image_preview');
1929 //var check_dom = $(dom).closest('.horizontal_form');
1930 if (!image_preview.length) {
1931 var image_preview = $(dom).closest('div').find('.image_preview');
1932
1933 }
1934
1935
1936
1937
1938
1939 var base_url = image_preview.attr('data-base_url');
1940
1941 if (no_preview) {
1942 $(dom).parent().find(".upload_keterangan").find('.file_name').html(json.file_name);
1943 image_preview.removeClass('display_none');
1944 image_preview.html(_preview_link);
1945 image_preview.find("a.fancybox").fancybox();
1946 image_preview.find('a').attr('href', base_url + json.preview);
1947 image_preview.find('img').remove();
1948 return;
1949 }
1950
1951
1952
1953
1954 if (json.is_image === true) {
1955 $(dom).parent().find(".upload_keterangan").find('.file_name').html(json.file_name);
1956 image_preview.removeClass('display_none');
1957 image_preview.html(_preview_link);
1958 image_preview.find("a.fancybox").fancybox();
1959 image_preview.find('a').attr('href', base_url + json.preview);
1960 image_preview.find('img').attr('src', base_url + json.thumb_preview);
1961 }
1962
1963
1964
1965 if (json.is_image !== true) {
1966 $(dom).parent().find(".upload_keterangan").find('.file_name').html('');
1967 image_preview.removeClass('col-md-2');
1968 image_preview.addClass('col-md-6');
1969 image_preview.removeClass('display_none');
1970 image_preview.html(json.file_preview);
1971 image_preview.find('a').html(json.file_icon);
1972 image_preview.find('a').append(' ' + json.file_name);
1973 }
1974
1975 // image_preview.removeClass('display_none');
1976 // image_preview.find('a').attr('href', base_url+json.preview);
1977 // image_preview.find('img').attr('src', base_url+json.thumb_preview);
1978
1979 $(dom).closest('div').find('.status_lampiran').html('<span class="label label-warning">Belum diproses</span>');
1980 $(dom).closest('tr').find('.status_lampiran').html('<span class="label label-warning">Belum diproses</span>');
1981
1982 //dont show image preview if not image
1983 // if(json.preview === false)
1984 // image_preview.addClass('display_none');
1985
1986
1987
1988 successNotification('File Berhasil Diupload');
1989
1990
1991
1992 //is there any callback ?
1993 var callback_func = $(dom).attr('callback');
1994 if (typeof callback_func !== typeof undefined && callback_func !== false) {
1995 //console.log(callback_func);
1996 window[callback_func]($(dom));
1997 }
1998
1999
2000
2001 },
2002 error: function(error) {
2003 // handle error
2004 var json = $.parseJSON(data);
2005
2006 $(dom).next().next(".upload_keterangan").show();
2007 $(dom).next().next(".upload_keterangan").find('.icon-status-error').show();
2008 $(dom).next().next(".upload_keterangan").find('.file_name').html(json.file_name);
2009
2010 },
2011 async: true,
2012 data: formData,
2013 cache: false,
2014 contentType: false,
2015 processData: false,
2016 timeout: 60000
2017 });
2018
2019
2020
2021 //masih beta belum diujicoba
2022 // var dataurl = null;
2023
2024
2025 // // Create an image
2026 // var img = document.createElement("img");
2027 // // Create a file reader
2028 // var reader = new FileReader();
2029 // // Set the image once loaded into file reader
2030 // reader.onload = function(e)
2031 // {
2032 // img.src = e.target.result;
2033
2034 // img.onload = function () {
2035 // var canvas = document.createElement("canvas");
2036 // var ctx = canvas.getContext("2d");
2037 // ctx.drawImage(img, 0, 0);
2038
2039 // var MAX_WIDTH = 800;
2040 // var MAX_HEIGHT = 600;
2041 // var width = img.width;
2042 // var height = img.height;
2043
2044 // if (width > height) {
2045 // if (width > MAX_WIDTH) {
2046 // height *= MAX_WIDTH / width;
2047 // width = MAX_WIDTH;
2048 // }
2049 // } else {
2050 // if (height > MAX_HEIGHT) {
2051 // width *= MAX_HEIGHT / height;
2052 // height = MAX_HEIGHT;
2053 // }
2054 // }
2055 // canvas.width = width;
2056 // canvas.height = height;
2057 // var ctx = canvas.getContext("2d");
2058 // ctx.drawImage(img, 0, 0, width, height);
2059
2060 // dataurl = canvas.toDataURL("image/jpeg");
2061 // // Post the data
2062 // var fd = new FormData();
2063
2064 // fd.append("file", dataurl);
2065 // fd.append("object", JSON.stringify(object));
2066 // $.ajax({
2067 // url: adminModulUrl + "attachment/upload",
2068 // xhr: function() {
2069 // var myXhr = $.ajaxSettings.xhr();
2070 // if (myXhr.upload) {
2071 // myXhr.upload.addEventListener('progress', that.progressHandling, false);
2072 // }
2073 // return myXhr;
2074 // },
2075 // data: fd,
2076 // cache: false,
2077 // contentType: false,
2078 // processData: false,
2079 // type: 'POST',
2080 // success: function(data){
2081 // that.successHandling(data, dom);
2082 // location.reload();
2083 // }
2084 // });
2085
2086 // // var upload = new Upload(dataurl);
2087
2088 // //doing upload file
2089 // //upload.doUpload(object, dom);
2090 // }
2091 // }
2092 // // Load files into file reader
2093 // reader.readAsDataURL(this.file);
2094
2095
2096
2097
2098
2099};
2100
2101
2102Upload.prototype.successHandling = function(data, dom) {
2103 var json = $.parseJSON(data);
2104 $(dom).hide();
2105 $(dom).prev('.uploadbutton').hide();
2106 $(dom).parent().find(".upload_keterangan").show();
2107
2108 $(dom).parent().parent().parent().css("border", "#AEFFAE solid 0px");
2109 $(dom).parent().find(".upload_keterangan").find('.file_name').html(json.file_name);
2110 $(dom).parent().parent().parent().find('.lampiran_prasyarat').val(json.status);
2111
2112 //upload gagal or file upload bukan gambar
2113 if (json.status === 0) {
2114
2115 $(dom).parent().find(".upload_keterangan").find('.file_name').addClass('font-color-red font-bold');
2116 $(dom).parent().find(".upload_keterangan").find('.icon-status-error ').show();
2117 $(dom).parent().find(".upload_keterangan").find('.icon-status-success').hide();
2118
2119 errorNotification(json.msg);
2120 return;
2121
2122 }
2123
2124
2125
2126 //tandai sudah diupload di input hidden untuk verifikasi sudah berhasil upload dari lampiran tersebut
2127 //ini untuk form tanpa adanya input form disampingnya
2128
2129
2130 //remove pewarnaan border yang gagal divalidasi yang jadi merah sebelumnya
2131 $(dom).parent().find(".upload_keterangan").find('.file_name').removeClass('font-color-red font-bold');
2132
2133 $(dom).parent().find(".upload_keterangan").find('.icon-status-succes').show();
2134 $(dom).parent().find(".upload_keterangan").find('.icon-status-error ').hide();
2135
2136 $(dom).parent().css('display', 'inline-block');
2137
2138
2139
2140 //untuk form upload yang ada inputannya disampingnya seperti halaman pjtbu isian pendidikan terakhir dsb
2141 $(dom).next().val(json.status);
2142
2143 //check dom, jika form horizontal maka seleksi div sesuaikan
2144 var image_preview = $(dom).closest('tr').find('.image_preview');
2145 //var check_dom = $(dom).closest('.horizontal_form');
2146 if (!image_preview.length) {
2147 var image_preview = $(dom).closest('div').find('.image_preview');
2148
2149 }
2150
2151
2152
2153
2154
2155 var base_url = image_preview.attr('data-base_url');
2156
2157
2158
2159 image_preview.removeClass('display_none');
2160 image_preview.find('a').attr('href', base_url + json.preview);
2161 image_preview.find('img').attr('src', base_url + json.thumb_preview);
2162
2163 $(dom).closest('div').find('.status_lampiran').html('<span class="label label-warning">Belum diproses</span>');
2164 $(dom).closest('tr').find('.status_lampiran').html('<span class="label label-warning">Belum diproses</span>');
2165
2166 //dont show image preview if not image
2167 if (json.preview === false)
2168 image_preview.addClass('display_none');
2169
2170
2171
2172 successNotification('File Berhasil Diupload');
2173
2174
2175
2176 //is there any callback ?
2177 var callback_func = $(dom).attr('callback');
2178 if (typeof callback_func !== typeof undefined && callback_func !== false) {
2179 //console.log(callback_func);
2180 window[callback_func]($(dom));
2181 }
2182
2183
2184};
2185
2186Upload.prototype.progressHandling = function(event) {
2187 var percent = 0;
2188 var position = event.loaded || event.position;
2189 var total = event.total;
2190 var progress_bar_id = ".progress-wrp";
2191 if (event.lengthComputable) {
2192 percent = Math.ceil(position / total * 100);
2193 }
2194 // update progressbars classes so it fits your code
2195
2196 $(progress_bar_id + " .progress-bar").css("width", +percent + "%");
2197 $(progress_bar_id + " .status").text(percent + "%");
2198
2199 if (percent == 100) {
2200 $(progress_bar_id).fadeOut(2000);
2201
2202
2203 }
2204
2205
2206};
2207
2208//Change id to your id
2209$(document).on('click', '.delete_attachment', function(e) {
2210 e.preventDefault();
2211 var url = adminModulUrl + 'attachment/delete/';
2212
2213 deleteConfirm(url, $(this).attr('id'), $(this).closest('li'));
2214
2215 //kurangi jumlah lampiran
2216 var parent = $(this).closest('.upload_form');
2217 var count_div = parent.find('span#count');
2218 var count_div2 = parent.find('span#jumlah_lampiran');
2219
2220 count_div.text(count_div.text() - 1);
2221 count_div2.text(count_div2.text() - 1);
2222
2223 // console.log(count_div);
2224
2225
2226
2227});
2228
2229
2230$(document).on('click', '.delete_confirm', function(e) {
2231
2232 e.preventDefault();
2233
2234 let id = $(this).data('id');
2235 let url = $(this).attr('href');
2236 let callback = $(this).data('callback');
2237 deleteConfirm(url, id, false, callback);
2238});
2239
2240function multiUploaderInit(dom) {
2241
2242 // Change this to the location of your server-side upload handler:
2243 var url = adminModulUrl + 'attachment/multi_uploader';
2244 var table_token = $(dom).attr('table_token');
2245 var description = $(dom).attr('description');
2246 var tmp = $(dom).attr('tmp');
2247 var image_only = $(dom).attr('image_only');
2248
2249
2250 $(dom).fileupload({
2251 url: url,
2252 dataType: 'json',
2253 formData: {
2254 'table_token': table_token,
2255 'description': description,
2256 'tmp': tmp,
2257 'image_only' : image_only
2258 },
2259 done: function(e, file) {
2260 //var json = $.parseJSON(file);
2261 var json = file.result;
2262 var parent_div = $(this).closest('div.upload_form');
2263 if (json.error) {
2264 errorNotification((json.msg) ? json.msg : 'File yang anda upload bukan gambar');
2265 $(this).closest('div.upload_form').find('.uploading').hide();
2266 $(this).closest('div.upload_form').find('.fileinput-button').fadeIn();
2267 return;
2268 }
2269
2270 $(this).closest('div.upload_form').find('.files_count').removeClass('display_none');
2271 $(this).closest('div.upload_form').find('.files_count').find('#count').text(json.jumlah);
2272 $(this).closest('div.upload_form').find('.uploading').hide();
2273 $(this).closest('div.upload_form').find('.fileinput-button').fadeIn();
2274 $(this).closest('div.upload_form').find('.lampiran_prasyarat').val(1);
2275
2276 //making ajax call to show all attachment list
2277 // let url_list = adminModulUrl+'attachment/get_attachment_list/'+table_token+'/'+description;
2278
2279 // fetch(url_list).then(function(response) { return response.text(); }) .then(function(html) {
2280 // //console.log(html);
2281 // parent_div.find('.attachment_list').html(html);
2282 // });
2283
2284 get_attachment_list(table_token, description, parent_div.find('.attachment_list'));
2285
2286 parent_div.find('#count').text(json.jumlah);
2287
2288
2289
2290 },
2291 progressall: function(e, data) {
2292 var progress = parseInt(data.loaded / data.total * 100, 10);
2293 $(this).closest('div.upload_form').find('.fileinput-button').hide();
2294 $(this).closest('div.upload_form').find('.uploading').show();
2295 }
2296 }).prop('disabled', !$.support.fileInput)
2297 .parent().addClass($.support.fileInput ? undefined : 'disabled');
2298
2299}
2300
2301
2302//list with filename and icon along with form tool (delete and edit);
2303function get_attachment_list(table_token, description, attachment_list_div) {
2304 //making ajax call to show all attachment list
2305 let url_list = adminModulUrl + 'attachment/get_attachment_list/' + table_token + '/' + description;
2306
2307 fetch(url_list).then(function(response) {
2308 return response.text();
2309 }).then(function(html) {
2310 //console.log(html);
2311 $(attachment_list_div).html(html);
2312 let files_count = $(attachment_list_div).closest('.multi_uploader_dom').find('.files_count');
2313 files_count.find('#count').text($(attachment_list_div).find('.file_count').text());
2314 files_count.removeClass('display_none');
2315 });
2316}
2317
2318
2319//untuk single uploader hanya satu saja
2320function get_attachment(table_token, description, attachment_list_div) {
2321 //making ajax call to show all attachment list
2322 let url_list = adminModulUrl + 'attachment/get_attachment_list/' + table_token + '/' + description;
2323
2324 fetch(url_list).then(function(response) {
2325 return response.text();
2326 }).then(function(html) {
2327 //console.log(html);
2328 $(attachment_list_div).html(html);
2329 $(attachment_list_div).fadeIn();
2330 $(attachment_list_div).removeClass('display_none');
2331 });
2332}
2333
2334
2335
2336function randomstring(L = 40) {
2337 var s = '';
2338 var randomchar = function() {
2339 var n = Math.floor(Math.random() * 62);
2340 if (n < 10) return n; //1-10
2341 if (n < 36) return String.fromCharCode(n + 55); //A-Z
2342 return String.fromCharCode(n + 61); //a-z
2343 };
2344 while (s.length < L) s += randomchar();
2345 return s;
2346}
2347
2348
2349function random_string($n) {
2350 return randomstring($n);
2351}
2352
2353
2354function isJSON(something) {
2355 if (typeof something != 'string')
2356 something = JSON.stringify(something);
2357
2358 try {
2359 JSON.parse(something);
2360 return true;
2361 } catch (e) {
2362 return false;
2363 }
2364}
2365
2366
2367function CleanPastedHTML(input) {
2368 // 1. remove line breaks / Mso classes
2369 var stringStripper = /(\n|\r| class=(")?Mso[a-zA-Z]+(")?)/g;
2370 var output = input.replace(stringStripper, ' ');
2371 // 2. strip Word generated HTML comments
2372 var commentSripper = new RegExp('<!--(.*?)-->', 'g');
2373 var output = output.replace(commentSripper, '');
2374 var tagStripper = new RegExp('<(/)*(meta|link|span|\\?xml:|st1:|o:|font)(.*?)>', 'gi');
2375 // 3. remove tags leave content if any
2376 output = output.replace(tagStripper, '');
2377 // 4. Remove everything in between and including tags '<style(.)style(.)>'
2378 var badTags = ['style', 'script', 'applet', 'embed', 'noframes', 'noscript'];
2379
2380 for (var i = 0; i < badTags.length; i++) {
2381 tagStripper = new RegExp('<' + badTags[i] + '.*?' + badTags[i] + '(.*?)>', 'gi');
2382 output = output.replace(tagStripper, '');
2383 }
2384 // 5. remove attributes ' style="..."'
2385 var badAttributes = ['style', 'start'];
2386 for (var i = 0; i < badAttributes.length; i++) {
2387 var attributeStripper = new RegExp(' ' + badAttributes[i] + '="(.*?)"', 'gi');
2388 output = output.replace(attributeStripper, '');
2389 }
2390 return output;
2391}
2392
2393
2394function isNumeric(n) {
2395 return !isNaN(parseFloat(n)) && isFinite(n);
2396}
2397
2398
2399function is_numeric(n) {
2400 return isNumeric(n);
2401}
2402
2403
2404if (jQuery().slick) {
2405 //run plugin dependent code
2406 $('.single_slider').slick({
2407 slidesToShow: 1,
2408 slidesToScroll: 1,
2409 arrows: false,
2410 fade: true,
2411 autoplay: true,
2412 });
2413
2414
2415
2416 $('.multiple_slider').slick({
2417 dots: true,
2418 infinite: true,
2419 speed: 300,
2420 slidesToShow: 1,
2421 centerMode: true,
2422 variableWidth: true,
2423 centerMode: true,
2424 centerPadding: '60px',
2425 slidesToShow: 3,
2426 autoplay: true,
2427 autoplaySpeed: 2000,
2428 });
2429}
2430
2431
2432/*disable copas on any input*/
2433$("input[name='konfirmasi_input'], .disable_copas, #disable_copas").bind("cut copy paste", function(e) {
2434 e.preventDefault();
2435});
2436
2437
2438
2439
2440/**
2441 * Add responsive select dropdown from tabs
2442 */
2443
2444$(document).ready(function($) {
2445 tabs_responsive();
2446
2447 $('.select_tabs').change(function(event) {
2448 /* Act on the event */
2449 attr = $(this).val();
2450 tabs = $('.nav-tabs.responsive');
2451 $('.nav-tabs.responsive > li > a[href="' + attr + '"').trigger('click');
2452 //$('.table_ajax[href="'+attr+'"').trigger('click');
2453 console.log(attr);
2454 });
2455});
2456
2457
2458function tabs_responsive() {
2459 select_class = 'select_tabs';
2460 select_tabs = '<select class="form-group ' + select_class + ' d-block d-sm-none" style="color: #a0460d; background: white; margin-bottom: 10px"> </select>';
2461 option = '<option value=""> </option>'
2462 tabs = '.nav-tabs.responsive';
2463
2464 $(tabs).before(select_tabs);
2465 // $(tabs).prev('.select_tabs').html('<option value="afafa"> Hola </option>');
2466
2467
2468
2469 $('' + tabs + ' > li').each(function(i) {
2470
2471 attr = $(this).find('a').attr('href');
2472 text = $(this).find('a').text();
2473 $(tabs).prev('.' + select_class + '').append('<option value="' + attr + '"> ' + text + ' </option>');
2474
2475 });
2476
2477}
2478
2479
2480$('.count').each(function() {
2481 $(this).prop('Counter', 0).animate({
2482 Counter: $(this).text()
2483 }, {
2484 duration: 4000,
2485 easing: 'swing',
2486 step: function(now) {
2487 $(this).text(Math.ceil(now));
2488 }
2489 });
2490});