/*! Jamkrida app.js * ================ * Main JS application file for Jamkrida v2. This file * should be included in all pages. It controls some layout * options and implements exclusive Jamkrida plugins. * * @Author Almsaeed Studio * @Support * @Email * @version 2.3.2 * @license MIT */ //Make sure jQuery has been loaded before app.js "use strict"; if (typeof jQuery === "undefined") { throw new Error("This App requires jQuery"); } /* Jamkrida * * @type Object * @description $.Jamkrida is the main object for the template's app. * It's used for implementing functions and options related * to the template. Keeping everything wrapped in an object * prevents conflict with other plugins and is a better * way to organize our code. */ $.Jamkrida = { // selfURI : '/dist/js/app.js.php', appName : "JAMKRIDA SULSEL", appMailAddress : "jamkrida.ss@gmail.com", appVersion : "1.0.0", appOrganization: "PT. JAMKRIDA SULSEL", baseDomain : "api.jamkridasulsel.co.id", restURI : 'http://api.jamkridasulsel.co.id/backend/rest.php', credentials : { email :'', userName:'', sessionId : '', name: '', userId: '', cabang: '', fullData: null }, dayNames : ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu'], monthNames: [ 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember' ], selectPegawaiFilter: { disableIfSppdNotApproved: false, disableIfStatusInactive: false }, browserInfo: function(){ var ua= navigator.userAgent, tem, M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; if(/trident/i.test(M[1])){ tem= /\brv[ :]+(\d+)/g.exec(ua) || []; return 'IE '+(tem[1] || ''); } if(M[1]=== 'Chrome'){ tem= ua.match(/\b(OPR|Edge)\/(\d+)/); if(tem!= null) return tem.slice(1).join(' ').replace('OPR', 'Opera'); } M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?']; if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]); return M.join(' ') + ' {'+ua+'}'; }, inputNumberBox: function(msgTitle, callbackFunc/*(accepted, n)*/, defaultVal, precision){ var _ = this; var _def = defaultVal ||0; var msgText = '
'; _.modalBox(msgTitle, ['OK', 'Batal'], function(dlg){ dlg.setMessage(msgText); _.bindNumericInput('input#currentInputNumberBoxValue',precision); $('input#currentInputNumberBoxValue') .focus() .select() .val(_def); }, function(dlg, index){ if (typeof callbackFunc == 'function') { if (index==0) { var input = $('input#currentInputNumberBoxValue'); callbackFunc(true, _.unmoney(input.val())); } else { callbackFunc(false, 0); } } }, BootstrapDialog.SIZE_SMALL); }, inputBox: function(msgTitle, callbackFunc/*(n)*/, xdef, dlgSize = BootstrapDialog.SIZE_SMALL){ var _ = this; var _def = xdef || ''; var msgText = '
'+ '
'; _.modalBox(msgTitle, ['OK', 'Batal'], function(dlg){ dlg.setMessage(msgText); $('input#currentInputBoxValue').focus().select(); }, function(dlg, index){ if (typeof callbackFunc == 'function') { if (index==0) { var input = $('input#currentInputBoxValue'); callbackFunc(input.val()); } else { callbackFunc(''); } } }, dlgSize); }, msgBox : function(msgText, msgTitle, callbackFunc, dlgSize = BootstrapDialog.SIZE_SMALL) { BootstrapDialog.show({ size: dlgSize, title: ' '+(msgTitle||'Informasi'), message: msgText, type: BootstrapDialog.TYPE_INFO, closable: true, draggable: true, callback: function() { (typeof callbackFunc=='function') ? callbackFunc():function(){return false}; } }); }, warnBox : function(msgText, msgTitle, callbackFunc, dlgSize = BootstrapDialog.SIZE_SMALL) { BootstrapDialog.show({ size: dlgSize, title: ' '+(msgTitle||'Warning'), message: msgText, type: BootstrapDialog.TYPE_WARNING, closable: true, draggable: true, callback: function() { (typeof callbackFunc=='function') ? callbackFunc():function(){return false}; } }); }, errorBox : function(msgText, msgTitle, callbackFunc, dlgSize = BootstrapDialog.SIZE_SMALL) { BootstrapDialog.show({ size: dlgSize, title: ' '+(msgTitle||'Error'), message: msgText, type: BootstrapDialog.TYPE_DANGER, closable: true, draggable: true, callback: function() { (typeof callbackFunc=='function') ? callbackFunc():function(){return false}; } }); }, askBox : function(msgText, msgTitle, callbackFunc/*(jawab)*/, yesButton, noButton, canClose) { BootstrapDialog.confirm({ size: BootstrapDialog.SIZE_SMALL, title: msgTitle, message: msgText, type: BootstrapDialog.TYPE_WARNING, closable: canClose || true, draggable: true, btnCancelLabel: noButton||'Tidak', // btnOKLabel: yesButton||'Ya', // btnOKClass: 'btn-warning', callback: function(result) { (typeof callbackFunc=='function') ? callbackFunc(result):function(){return false}; } }); }, modalBox: function(msgTitle, btnList, onDialogShown/*(dialogInstance)*/, onDialogHidden/*(dialogInstance, btnIndex)*/, dialogSize ) { var btns = []; for (var i=0; i < btnList.length; i++){ btns.push({ id:'bootstrap3-modal-box-btn-'+i, label: btnList[i], action: function(d){ var bId = parseInt(this.prop('id').substr('bootstrap3-modal-box-btn-'.length)); d.btnIndex = bId; d.close(); } }); } BootstrapDialog.show({ size: dialogSize || BootstrapDialog.SIZE_LARGE, title: msgTitle, message: '', buttons: btns, closable: false, tipe: BootstrapDialog.TYPE_DEFAULT, onshown: function(dialogInstance){ dialogInstance.btnIndex = -1; if (typeof onDialogShown == 'function') {onDialogShown(dialogInstance);} }, onhide: function(dialogInstance){ // return false to disable close. if (typeof onDialogHidden == 'function') {return onDialogHidden(dialogInstance, dialogInstance.btnIndex);} } }); }, formBox: function(msgTitle, jsonSchema, onSubmit/*(dlgInstance, errors, jsonData)*/, onCancel/*(dlgInstance)*/, dialogSize ) { /* var btns = []; var btnList = ['OK', 'Cancel']; for (var i=0; i < btnList.length; i++){ btns.push({ id:'bootstrap3-modal-box-btn-'+i, label: btnList[i], action: function(d){ var bId = parseInt(this.prop('id').substr('bootstrap3-modal-box-btn-'.length)); d.btnIndex = bId; d.close(); } }); } */ BootstrapDialog.show({ size: dialogSize || BootstrapDialog.SIZE_LARGE, title: msgTitle, message: $('
').load('form.box.php', {data: encodeURI(JSON.stringify(jsonSchema))}), // buttons: btns, tipe: BootstrapDialog.TYPE_DEFAULT, onshown: function(dialogInstance){ dialogInstance.btnIndex = -1; window.currentUrlDialog = dialogInstance; }, onhide: function(dialogInstance){ // return false to disable close. // return onDialogHidden(dialogInstance, dialogInstance.btnIndex); if (dialogInstance.submitted) { if (typeof onSubmit == 'function') {onSubmit(dialogInstance, dialogInstance.errors, dialogInstance.values);} } else { if (typeof onCancel == 'function') {onCancel(dialogInstance);} } } }); }, urlBox: function(url, title, dialogSize, onDialogHidden/*(dlg)*/, closable) { delete window.currentUrlDialog; // console.log(window.currentUrlDialog); BootstrapDialog.show({ title: title, closable: closable||true, size: dialogSize || BootstrapDialog.SIZE_LARGE, message: $('
').load(url), onshown: function(d){ window.currentUrlDialog = d; // console.log(window.currentUrlDialog); }, onhide: function(dialogInstance){ if (typeof onDialogHidden == 'function') {onDialogHidden(dialogInstance);} // console.log('hide', window.currentUrlDialog); } }); }, selectFromSqlBox: function(caption, sql, displayFields, onSelect/*(selectedData)*/, onCancel, dlgSize) { var df= encodeURIComponent(JSON.stringify(displayFields)); // console.log(df); this.urlBox('util.selectFromSqlBox.php?sql='+encodeURIComponent(sql)+'&fields='+df, caption, dlgSize||BootstrapDialog.SIZE_LARGE, function(d){ if (d.ok) { onSelect(d.selectedData); } else { (onCancel||function(){})(); } }); }, uploadFileBox: function( allowedExtension/*[..,..]*/, showPreview/*true|false*/, onDone/*(jsonFileObject, fileNameOnServer)*/, onError/*(msg)*/ ){ var ext; if (allowedExtension.length<=0){ this.toastWarning('Ekstensi file tidak valid.'); return false; } else { ext = allowedExtension.join('|'); } var prev = (showPreview||false)?'true':'false'; BootstrapDialog.show({ title: 'Pilih File, Klik Upload', size: BootstrapDialog.SIZE_NORMAL, message: $('
').load( 'utils.ui.dialog.fileupload.php?r='+encodeURIComponent(Math.random())+'&e='+encodeURIComponent(ext)+'&p='+encodeURIComponent(prev) ), onshown: function(d){ window.currentUrlDialog = d; window.currentUrlDialog.selectedFileName = ''; window.currentUrlDialog.errorMsg = ''; window.currentUrlDialog.jsonData = {}; }, onhide: function(dialogInstance){ if (dialogInstance.errorMsg!=''){ if (typeof onError == 'function') { onError(dialogInstance.errorMsg); } } else { if (typeof onDone == 'function') { onDone(dialogInstance.jsonData, dialogInstance.selectedFileName); } } } }); /*this.urlBox( 'utils.ui.dialog.fileupload.php?r='+encodeURIComponent(Math.random())+'&e='+encodeURIComponent(ext)+',&p='+encodeURIComponent(prev), 'Pilih file', BootstrapDialog.SIZE_NORMAL, function(dlg){ window.currentUrlDialog.selectedFileName if (typeof onDone == 'function'){ var f = dlg.selectedFileName; onDone(f); } });*/ }, /* array selectedCoa: [{ tingkat, pkode, skode, kode, rekening, tipe, full_kode, vkode }] */ selectCoa: function( title, onDialogHidden/*(dlg, selectedCoas)*/, levelCoa/*1..5*/, tipeCoa/*1digit-kodeCoaLevel1, asterix or empty to show all*/, multiSelect/*Y|N|P*/, fromLevel/*1..5*/, toLevel/*1..5*/ ) { var startLevel = fromLevel || 1; var toLevel = levelCoa || 5; if (startLevel>toLevel) { startLevel = toLevel; } BootstrapDialog.show({ title: title||'Pilih COA', size: BootstrapDialog.SIZE_WIDE, message: $('
').load( 'acc.coa.master.select.php?t='+encodeURIComponent(tipeCoa||'*')+ '&l='+encodeURIComponent(toLevel)+ '&m='+encodeURIComponent(multiSelect||'N')+ '&s='+encodeURIComponent(startLevel) ), onshow: function(d){ d.selectedCoas = []; window.currentSelectCoaDialog = d; window.currentSelectCoaDialog.selectedCoas = []; }, onshown: function(d){ }, onhide: function(dialogInstance){ // console.log(dialogInstance.selectedCoas); dialogInstance.selectedCoas.sort(function(a,b) { return (a.full_kode > b.full_kode) ? 1 : ((b.full_kode > a.full_kode) ? -1 : 0); }); if (typeof onDialogHidden == 'function') {onDialogHidden(dialogInstance, dialogInstance.selectedCoas);} } }); }, dowloadFile: function(remoteName, fileName, removeAfterDOwnload, useDialog, description){ var _ = this; var _useDialog = useDialog || false; var _remove = ((removeAfterDOwnload||false) ? 'true':'false'); var _fileName = fileName||(remoteName.split('/').pop()); var _desc = description||'Klik tombol berikut untuk mengunduh file:'; var url = 'backend/downloadbin.php?f='+encodeURIComponent(remoteName)+'&n='+encodeURIComponent(_fileName)+'&r='+_remove; if (!_useDialog){ var w = window.open(url); setTimeout(function(){ w.close(); }, 3000); } else { _.modalBox('Download File', [' Unduh', ' Batal'], function(dlg){ dlg.setMessage(_desc); }, function(dlg, index){ if (index==0) { var w = window.open(url); setTimeout(function(){ w.close(); }, 3000); } }, BootstrapDialog.SIZE_SMALL); } }, /* Select Pegawai: */ selectPegawai: function( title, onDialogHidden = (a,b)=>{}/*(dlg, selectedPegawai)*/, tipePegawai = '*'/*Digits: D: Direksi, K: Komisaris, S: Staff, asterix or empty to show all*/, sqlFilter = 'select peg.* from peg' ) { let sqlFilterName = $.Jamkrida.credentials.sessionId +'@'+Math.random(); localStorage.setItem(sqlFilterName, sqlFilter); BootstrapDialog.show({ title: title||'Pilih Pegawai', size: BootstrapDialog.SIZE_LARGE, message: $('
').load( // 'sdm.pegawai.select.php?t='+encodeURIComponent(tipePegawai||'*')+'&f='+sqlFilterName 'sdm.pegawai.select.php?t='+encodeURIComponent(tipePegawai||'*')+'&filtername='+encodeURIComponent(sqlFilterName) ), onshow: function(d){ d.selectedPegawai = null; window.currentSelectPegawaiDialog = d; window.currentSelectPegawaiDialog.selectedPegawai = null; }, onshown: function(d){ }, onhide: function(dialogInstance){ /*dialogInstance.selectedPegawai.sort(function(a,b) { return (a.full_kode > b.full_kode) ? 1 : ((b.full_kode > a.full_kode) ? -1 : 0); });*/ if ((typeof onDialogHidden == 'function') && (dialogInstance.selectedPegawai!=null)) { onDialogHidden(dialogInstance, dialogInstance.selectedPegawai); } } }); }, /* Select User: */ selectUser: function( title, onDialogHidden/*(dlg, selectedUser)*/, tipeUser/*Digits: D: Dev, A: Admin, O: Operators, G; Guests, asterix or empty to show all*/ ) { BootstrapDialog.show({ title: title||'Pilih User', size: BootstrapDialog.SIZE_WIDE, message: $('
').load( 'usr.users.select.php?t='+encodeURIComponent(tipeUser||'*') ), onshow: function(d){ d.selectedUser = null; window.currentSelectUserDialog = d; window.currentSelectUserDialog.selectedUser = null; }, onshown: function(d){ }, onhide: function(dialogInstance){ if ((typeof onDialogHidden == 'function') && (dialogInstance.selectedUser!=null)) { onDialogHidden(dialogInstance, dialogInstance.selectedUser); } } }); }, showToast: function(toastText, toastType){ var t = toastType || ''; var color = ''; var icon = ''; switch (t.toLowerCase()) { case 'danger': color = 'error'; icon = 'fa fa-times'; break; case 'warning': color = 'notice'; icon = 'fa fa-warning'; break; case 'success': color = 'success'; icon = 'fa fa-check'; break; case 'info': color = 'info'; icon = 'fa fa-info-circle'; break; default: color = 'simple'; icon = 'fa fa-certificate'; } $.iGrowl({ message: toastText, type: color || 'info', //title: '', icon: icon, delay: 2000, small: true, spacing: 5, animShow: 'fadeInRight', animHide: 'bounceOutUp' }) }, toast : function(toastText){return this.showToast(toastText);}, toastInfo : function(toastText){return this.showToast(toastText, 'info');}, toastDanger : function(toastText){return this.showToast(toastText, 'danger');}, toastWarning: function(toastText){return this.showToast(toastText, 'warning');}, toastSuccess: function(toastText){return this.showToast(toastText, 'success');}, b64toBlob: function(b64Data, contentType, sliceSize) { contentType = contentType || ''; sliceSize = sliceSize || 512; var byteCharacters = atob(b64Data); var byteArrays = []; for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) { var slice = byteCharacters.slice(offset, offset + sliceSize); var byteNumbers = new Array(slice.length); for (var i = 0; i < slice.length; i++) { byteNumbers[i] = slice.charCodeAt(i); } var byteArray = new Uint8Array(byteNumbers); byteArrays.push(byteArray); } var blob = new Blob(byteArrays, {type: contentType}); return blob; }, validateEmail: function(email) { var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; return regex.test(email); }, isValidInteger: function(v) { return data === parseInt(data, 10); }, angkaRum: function(num, format){ var f = format || 'A'; if (!+num) return NaN; var digits = String(+num).split(""), key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM", "","X","XX","XXX","XL","L","LX","LXX","LXXX","XC", "","I","II","III","IV","V","VI","VII","VIII","IX"], roman = "", i = 3; while (i--) roman = (key[+digits.pop() + (i * 10)] || "") + roman; roman = Array(+digits.join("") + 1).join("M") + roman; return f == 'A'? roman.toUpperCase():roman.toLowerCase(); }, isValidDate: function(strDate) { // var v = parseInt(strDate.split('-').join('').split('/').join('')); // return !isNaN(v); let x = strDate.replace(/\D/g,''); return x.length == 8; }, isValidTime: function(strTime /* must be hh:mm */){ // return /^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/ return /^\d{2}:\d{2}?$/ .test(strTime); }, /* This takes "YYYY-MM-DD" format as input: */ parseDate: function(str) { var mdy = str.split('-'); // console.log(mdy); var d = new Date(mdy[0], mdy[1]-1, mdy[2]); // console.log(d); return d; }, dateDiff : function datediff(firstDate, secondDate) { return Math.round((this.parseDate(secondDate)-this.parseDate(firstDate))/(1000*60*60*24)); }, toDay: function(){ var t = new Date(); var d = t.getDate(); var m = t.getMonth()+1; //January is 0! var y = t.getFullYear(); if(d < 10) { d='0'+d; } if(m < 10){ m='0'+m; } return y+'-'+m+'-'+d; }, time: function(){ var t = new Date(); return t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds(); }, dateToStr: function(jsDate){ var d = jsDate.getDate(); var m = jsDate.getMonth()+1; //January is 0! var y = jsDate.getFullYear(); if(d < 10){ d='0'+d; } if(m < 10){ m='0'+m; } return y+'-'+m+'-'+d; }, dateToIndo: function(jsDate,withDayName = false){ if (!withDayName){ return this.dateToStr(jsDate).split('-').reverse().join('/'); } else { return this.dayNames[jsDate.getDay()]+', '+this.dateToStr(jsDate).split('-').reverse().join('/'); } }, lastDate: function(year, month){ var t = new Date(year, month, 0); var d = t.getDate(); var m = t.getMonth()+1; //January is 0! var y = t.getFullYear(); if(d < 10){ d='0'+d; } if(m < 10){ m='0'+m; } return y+'-'+m+'-'+d; }, selesihHari: function(tgl1, tgl2 /* dd/MM/yyyy */){ let d1 = J.parseDate(tgl1.split('/').reverse().join('-')); let d2 = J.parseDate(tgl2.split('/').reverse().join('-')); let jml = 0; if (d1 == d2 ){ jml = 1; } else { let tdiff = d2.getTime() - d1.getTime(); jml = Math.ceil(tdiff / (1000 * 3600 * 24)); } return jml; }, escapeSQL: function(sqlText, quoteString){ var _ = sqlText; _ = (_ + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0'); if ((typeof quoteString != 'undefined') && (quoteString==true)) { return "'"+_+"'"; } else { return _; } }, execSQL : function(sql, onSuccess/*(msg)*/, onFail/*(msg)*/){ var opt = { ajax: 'exec-sql', username: this.credentials.userName, email: this.credentials.email, sessionid: this.credentials.sessionId, sqlcommand: sql, r: Math.random() }; // console.log(opt); this.ajax(this.restURI, opt, function(json){ if (json.error == 'true'){ onFail(json.message); } else { onSuccess(json.message); } }, function(d,s,e){ onFail('Error: '+s); console.log(d); }); }, execQueries : function(sqlArray/*[]*/, onSuccess/*(msg)*/, onFail/*(msg)*/){ var opt = { ajax: 'exec-sqls', username: this.credentials.userName, email: this.credentials.email, sessionid: this.credentials.sessionId, sqlcommands: sqlArray, r: Math.random() }; this.ajax(this.restURI, opt, function(json){ if (json.error == 'true'){ onFail(json.message); } else { onSuccess(json.message); } }, function(d,s,e){ onFail('Error: '+s); console.log(d); }); }, openSQL : function(sql, onSuccess/*(msg, data)*/, onFail/*(msg)*/){ var opt = { ajax: 'fetch-sql', email: this.credentials.email, username: this.credentials.userName, sessionid: this.credentials.sessionId, sqlcommand: sql, r: Math.random() }; this.ajax(this.restURI, opt, function(json){ if (json.error == 'true'){ (onFail||function(m){})(json.message); } else { onSuccess(json.message, json.data); } }, function(d,s,e){ (onFail||function(m){})('Error: '+s); console.log(d); }); }, fetchQuery : function(sql, onSuccess/*(data)*/){ this.openSQL(sql, function(m, d){ onSuccess(d); }, function(m){ onSuccess({}); }); }, isAccessible: function (accessName, accessGroup, accessHandler/* (Accessible)=>{}*/){ var o = this; // console.log(o.credentials); if (o.credentials.fullData.group_kode.toUpperCase()=='DEV'){ (accessHandler||function(b){})(true); } else { o.fetchQuery("select accessible_by("+o.credentials.userId+", '"+accessName+"', '"+accessGroup+"')", function(d){ (accessHandler||function(b){})((d.length>0) && (d[0].accessible_by=='Y')); }); } }, ajax : function(aURL, aData, aOnSuccess, aOnError) { var owner = this; // console.log(aURL); return $.ajax({ type: 'POST', url: aURL, crossDomain: true, data: aData, dataType: 'json', success: aOnSuccess, error: typeof aOnError == 'function' ? aOnError : null/*function(data, status, e){owner.showToast( 'Kesalahan:'+e);}*/ }); }, sendMail: function(to, from, subject, message, attachments, onSuccess/*msg*/, onFail/*msg*/) { var opt = { ajax : 'send-mail', to : to, fr : from, su : subject, ms : message, ats : attachments, r : Math.random() }; this.ajax(this.restURI, opt, function(json){ // console.log(json); if (json.error == 'true'){ onFail(json.message); } else { onSuccess(json.message); } }, function(d,s,e){ onFail('Error: '+s); console.log(d); }); }, // SAMPLE OF USE: requestScanner: function(onSuccess/*(localFileName)*/, onError/*(errMsg)*/){ /*$.ajax({ // type: 'GET', url: 'http://localhost:80/testjson.php', // crossDomain: true, dataType: 'json', jsonpCallback: 'execScanner', success: function(data){ console.log(data); if (typeof onSuccess=='function') { onSuccess(data.localFileName); } }, error: function(a,b,c){ console.log(a); console.log(b); console.log(c); if (typeof aOnError == 'function'){ onError(b); } } });*/ // $.getJSON('http://localhost:8899/datasnap/rest/TServerMethods1/ReverseString/Tes', { var onScanner = function(m){ console.log(m); }; $.getJSON('http://localhost:8899/?jsoncallback=onScanner', { }).done(function(data){ console.log(data); }); // console.log(xhr); /*var flickerAPI = "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?"; $.getJSON( flickerAPI, { tags: "mount rainier", tagmode: "any", format: "json" }) .done(function( data ) { $.each( data.items, function( i, item ) { // $( "" ).attr( "src", item.media.m ).appendTo( "#images" ); console.log(item); if ( i === 3 ) { return false; } }); });*/ }, money : function(n,precision=2) { // return n.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'); return accounting.formatMoney(n, { symbol: "", decimal : ".", thousand: ",", precision : precision }); }, moneyAc: function(n,precision=2){ return accounting.formatMoney(n, { symbol: "", decimal : ".", thousand: ",", precision : precision, format: { pos : "%s %v", neg : "%s (%v)", zero: "%s -" } }); }, unmoney: function(s){ // return parseFloat(s.replace(/\,/g,"")).toFixed(2); // console.log('Asli:', s); var x = accounting.unformat(s); // console.log('Hasil:' ,x); return x; }, getPanjangKodeByLevel: function(levelCoa) { var l = 0; switch(levelCoa.toString()) { case "1": case "2": l = levelCoa; break; case "3": l = 4; break; case "4": l = 6; break; case "5": l = 8; break; } return l; }, getKodeByFullKode: function(fullKode){}, getFullKodeByKode: function(kode){ var r = kode; while (r.length < 8) {r+='0'}; }, formatFullKode: function(fullKode){}, formatKode: function(kode){}, ajaxElement : function(element, aURL, aData, aOnSuccess, aOnError) { var owner = this; var elem = $(element); $.ajax({ type: 'POST', url: aURL, crossDomain: true, data: aData, dataType: 'json', success: aOnSuccess, error: typeof aOnError == 'function' ? aOnError : null, beforeSend: function(xhr) { if (!window.ajxInd) { elem.append('
\
\ \
\
'); window.ajxInd = $('#ajx-ind-div'); } window.ajxInd.show(); }, complete: function(xhr, status){ if (window.ajxInd) { window.ajxInd .hide() .remove(); } } }); }, checkExistingSession: function(userName, sessionId){ this.ajax(this.restURI, {ajax:'is-logged-in', uid:userName, sid: sessionId}, function(json){ if (json.error=='true'){ this.showToast('Anda belum login.'); } else { console.log(json.user_data); } }); }, login: function(userName, password, success/*(json.user_data)*/, fail/*(errorMsg)*/, remember){ var devId = this.browserInfo(); if ((false||remember)!=false){ localStorage.setItem('savedLogin', JSON.stringify({ savedUserName: userName, savedPassword: password, savedRemember: true })); } else { localStorage.setItem('savedLogin', JSON.stringify({ savedUserName: '', savedPassword: '', savedRemember: false })); } var _this = this; _this.ajax(_this.restURI, { ajax:'log-in', hsd56sd76s6d7: userName, hsd67dghdsd67: password, hsd67drhdsd67: devId }, function(json){ // console.log(json); if (json.error=='true'){ if (typeof fail == 'function') { fail(json.message); } } else { if (typeof success == 'function') { // console.log(json.user_data); success(json.user_data); } } }/*, function(a,b,c){console.log(a);} */); }, logOut: function(onSuccess/*(msg)*/) { var _this = this; _this.ajax(_this.restURI, {ajax:'log-out', r: Math.random()}, function(json){ /* _this.credentials.email = ''; _this.credentials.sessionId =''; _this.credentials.name = ''; _this.credentials.fullData = {}; */ if (typeof onSuccess=='function'){ onSuccess(json.message); } }/*, function(a,b,c){console.log(a);}*/); }, bindNumericInput: function(elementSelector, precision=2){ var t = this; var _ = $(elementSelector); if (_ && (_.length>0)){ _ .focus(function(e){ var __ = $(this); __.val(t.unmoney(__.val())) }) .blur(function(e){ var __ = $(this); __.val(t.money(__.val()),precision) }) ; } return _; }, bindNumericInputDOM: function(elementSelector, precision=2){ var t = this; $(document) .on('focus',elementSelector, function(){ var __ = $(this); __.val(t.unmoney(__.val())) }) .on('blur',elementSelector, function(){ var __ = $(this); __.val(t.money(__.val()),precision) }); }, isLoggedIn : function(Email, Sessid, onSuccess, onError){ var loggedIn = false; this.ajax(this.restURI, {ajax:'is-logged-in', email: Email, sessionid:Sessid, r: Math.random()}, function(json){ onSuccess(json); }, function(responseData, textStatus, errorThrown){ onError(textStatus); }); }, /* pasangan dari data_to_attr() di backend/definitions.php */ attrToData: function(attrData){ if (!attrData){ return null; } if (attrData.length <= 5){ return null; } var hexes = attrData.substr(5, attrData.length-5); var bytes = []; for (var i=0; i< hexes.length-1; i+=2){ bytes.push(parseInt(hexes.substr(i,2), 16)); } hexes = String.fromCharCode.apply(String, bytes); // console.log(hexes); hexes = hexes.replace(/[\x00-\x1F\x7F-\x9F]/g, ""); return JSON.parse(hexes); }, dataToAttr: function(jsonData){ if (jsonData == null){ return ''; } var res = ''; var plainData = JSON.stringify(jsonData); if (plainData==''){ return ''; } for (var i=0; i< plainData.length; i++){ res += ('00'+(plainData.charCodeAt(i).toString(16))).slice(-2) } return 'JSON:'+res; } /*, printArea: function(elementId){ var newArea = $('#'+elementId).clone(); var zi = 9999999998; newArea.detach() .html('sosdsjldsd') .css('z-index',zi) .css('width','100%') .css('height','100%') .prepend('
x
') .apendTo('body'); ; console.log(newArea); }*/ }; /* -------------------- * - Jamkrida Options - * -------------------- * Modify these options to suit your implementation */ $.Jamkrida.options = { //Add slimscroll to navbar menus //This requires you to load the slimscroll plugin //in every page before app.js navbarMenuSlimscroll: true, navbarMenuSlimscrollWidth: "3px", //The width of the scroll bar navbarMenuHeight: "200px", //The height of the inner menu //General animation speed for JS animated elements such as box collapse/expand and //sidebar treeview slide up/down. This options accepts an integer as milliseconds, //'fast', 'normal', or 'slow' animationSpeed: 500, //Sidebar push menu toggle button selector sidebarToggleSelector: "[data-toggle='offcanvas']", //Activate sidebar push menu sidebarPushMenu: true, //Activate sidebar slimscroll if the fixed layout is set (requires SlimScroll Plugin) sidebarSlimScroll: true, //Enable sidebar expand on hover effect for sidebar mini //This option is forced to true if both the fixed layout and sidebar mini //are used together sidebarExpandOnHover: false, //BoxRefresh Plugin enableBoxRefresh: true, //Bootstrap.js tooltip enableBSToppltip: true, BSTooltipSelector: "[data-toggle='tooltip']", //Enable Fast Click. Fastclick.js creates a more //native touch experience with touch devices. If you //choose to enable the plugin, make sure you load the script //before Jamkrida's app.js enableFastclick: true, //Control Sidebar Options enableControlSidebar: true, controlSidebarOptions: { //Which button should trigger the open/close event toggleBtnSelector: "[data-toggle='control-sidebar']", //The sidebar selector selector: ".control-sidebar", //Enable slide over content slide: true }, //Box Widget Plugin. Enable this plugin //to allow boxes to be collapsed and/or removed enableBoxWidget: true, //Box Widget plugin options boxWidgetOptions: { boxWidgetIcons: { //Collapse icon collapse: 'fa-minus', //Open icon open: 'fa-plus', //Remove icon remove: 'fa-times' }, boxWidgetSelectors: { //Remove button selector remove: '[data-widget="remove"]', //Collapse button selector collapse: '[data-widget="collapse"]' } }, //Direct Chat plugin options directChat: { //Enable direct chat by default enable: true, //The button to open and close the chat contacts pane contactToggleSelector: '[data-widget="chat-pane-toggle"]' }, //Define the set of colors to use globally around the website colors: { lightBlue: "#3c8dbc", red: "#f56954", green: "#00a65a", aqua: "#00c0ef", yellow: "#f39c12", blue: "#0073b7", navy: "#001F3F", teal: "#39CCCC", olive: "#3D9970", lime: "#01FF70", orange: "#FF851B", fuchsia: "#F012BE", purple: "#8E24AA", maroon: "#D81B60", black: "#222222", gray: "#d2d6de" }, //The standard screen sizes that bootstrap uses. //If you change these in the variables.less file, change //them here too. screenSizes: { xs: 480, sm: 768, md: 992, lg: 1200 } }; /* ------------------ * - Implementation - * ------------------ * The next block of code implements Jamkrida's * functions and plugins as specified by the * options above. */ $(function () { "use strict"; //Fix for IE page transitions $("body").removeClass("hold-transition"); //Extend options if external options exist if (typeof AdminLTEOptions !== "undefined") { $.extend(true, $.Jamkrida.options, AdminLTEOptions); } //Easy access to options var o = $.Jamkrida.options; //Set up the object _init(); //Activate the layout maker $.Jamkrida.layout.activate(); //Enable sidebar tree view controls $.Jamkrida.tree('.sidebar'); //Enable control sidebar if (o.enableControlSidebar) { $.Jamkrida.controlSidebar.activate(); } //Add slimscroll to navbar dropdown if (o.navbarMenuSlimscroll && typeof $.fn.slimscroll != 'undefined') { $(".navbar .menu").slimscroll({ height: o.navbarMenuHeight, alwaysVisible: false, size: o.navbarMenuSlimscrollWidth }).css("width", "100%"); } //Activate sidebar push menu if (o.sidebarPushMenu) { $.Jamkrida.pushMenu.activate(o.sidebarToggleSelector); } //Activate Bootstrap tooltip if (o.enableBSToppltip) { $('body').tooltip({ selector: o.BSTooltipSelector }); } //Activate box widget if (o.enableBoxWidget) { $.Jamkrida.boxWidget.activate(); } //Activate fast click if (o.enableFastclick && typeof FastClick != 'undefined') { FastClick.attach(document.body); } //Activate direct chat widget if (o.directChat.enable) { $(document).on('click', o.directChat.contactToggleSelector, function () { var box = $(this).parents('.direct-chat').first(); box.toggleClass('direct-chat-contacts-open'); }); } /* * INITIALIZE BUTTON TOGGLE * ------------------------ */ $('.btn-group[data-toggle="btn-toggle"]').each(function () { var group = $(this); $(this).find(".btn").on('click', function (e) { group.find(".btn.active").removeClass("active"); $(this).addClass("active"); e.preventDefault(); }); }); }); /* ---------------------------------- * - Initialize the Jamkrida Object - * ---------------------------------- * All Jamkrida functions are implemented below. */ function _init() { 'use strict'; /* Layout * ====== * Fixes the layout height in case min-height fails. * * @type Object * @usage $.Jamkrida.layout.activate() * $.Jamkrida.layout.fix() * $.Jamkrida.layout.fixSidebar() */ $.Jamkrida.layout = { activate: function () { var _this = this; _this.fix(); _this.fixSidebar(); $(window, ".wrapper").resize(function () { _this.fix(); _this.fixSidebar(); }); }, fix: function () { //Get window height and the wrapper height var neg = $('.main-header').outerHeight() + $('.main-footer').outerHeight(); var window_height = $(window).height(); var sidebar_height = $(".sidebar").height(); //Set the min-height of the content and sidebar based on the //the height of the document. if ($("body").hasClass("fixed")) { $(".content-wrapper, .right-side").css('min-height', window_height - $('.main-footer').outerHeight()); } else { var postSetWidth; if (window_height >= sidebar_height) { $(".content-wrapper, .right-side").css('min-height', window_height - neg); postSetWidth = window_height - neg; } else { $(".content-wrapper, .right-side").css('min-height', sidebar_height); postSetWidth = sidebar_height; } //Fix for the control sidebar height var controlSidebar = $($.Jamkrida.options.controlSidebarOptions.selector); if (typeof controlSidebar !== "undefined") { if (controlSidebar.height() > postSetWidth) $(".content-wrapper, .right-side").css('min-height', controlSidebar.height()); } } }, fixSidebar: function () { //Make sure the body tag has the .fixed class if (!$("body").hasClass("fixed")) { if (typeof $.fn.slimScroll != 'undefined') { $(".sidebar").slimScroll({destroy: true}).height("auto"); } return; } else if (typeof $.fn.slimScroll == 'undefined' && window.console) { window.console.error("Error: the fixed layout requires the slimscroll plugin!"); } //Enable slimscroll for fixed layout if ($.Jamkrida.options.sidebarSlimScroll) { if (typeof $.fn.slimScroll != 'undefined') { //Destroy if it exists $(".sidebar").slimScroll({destroy: true}).height("auto"); //Add slimscroll $(".sidebar").slimscroll({ height: ($(window).height() - $(".main-header").height()) + "px", color: "rgba(0,0,0,0.2)", size: "3px" }); } } } }; /* PushMenu() * ========== * Adds the push menu functionality to the sidebar. * * @type Function * @usage: $.Jamkrida.pushMenu("[data-toggle='offcanvas']") */ $.Jamkrida.pushMenu = { activate: function (toggleBtn) { //Get the screen sizes var screenSizes = $.Jamkrida.options.screenSizes; //Enable sidebar toggle $(document).on('click', toggleBtn, function (e) { e.preventDefault(); //Enable sidebar push menu if ($(window).width() > (screenSizes.sm - 1)) { if ($("body").hasClass('sidebar-collapse')) { $("body").removeClass('sidebar-collapse').trigger('expanded.pushMenu'); } else { $("body").addClass('sidebar-collapse').trigger('collapsed.pushMenu'); } } //Handle sidebar push menu for small screens else { if ($("body").hasClass('sidebar-open')) { $("body").removeClass('sidebar-open').removeClass('sidebar-collapse').trigger('collapsed.pushMenu'); } else { $("body").addClass('sidebar-open').trigger('expanded.pushMenu'); } } }); $(".content-wrapper").click(function () { //Enable hide menu when clicking on the content-wrapper on small screens if ($(window).width() <= (screenSizes.sm - 1) && $("body").hasClass("sidebar-open")) { $("body").removeClass('sidebar-open'); } }); //Enable expand on hover for sidebar mini if ($.Jamkrida.options.sidebarExpandOnHover || ($('body').hasClass('fixed') && $('body').hasClass('sidebar-mini'))) { this.expandOnHover(); } }, expandOnHover: function () { var _this = this; var screenWidth = $.Jamkrida.options.screenSizes.sm - 1; //Expand sidebar on hover $('.main-sidebar').hover(function () { if ($('body').hasClass('sidebar-mini') && $("body").hasClass('sidebar-collapse') && $(window).width() > screenWidth) { _this.expand(); } }, function () { if ($('body').hasClass('sidebar-mini') && $('body').hasClass('sidebar-expanded-on-hover') && $(window).width() > screenWidth) { _this.collapse(); } }); }, expand: function () { $("body").removeClass('sidebar-collapse').addClass('sidebar-expanded-on-hover'); }, collapse: function () { if ($('body').hasClass('sidebar-expanded-on-hover')) { $('body').removeClass('sidebar-expanded-on-hover').addClass('sidebar-collapse'); } } }; /* Tree() * ====== * Converts the sidebar into a multilevel * tree view menu. * * @type Function * @Usage: $.Jamkrida.tree('.sidebar') */ $.Jamkrida.tree = function (menu) { var _this = this; var animationSpeed = $.Jamkrida.options.animationSpeed; $(document).on('click', menu + ' li a', function (e) { //Get the clicked link and the next element var $this = $(this); var checkElement = $this.next(); //Check if the next element is a menu and is visible if ((checkElement.is('.treeview-menu')) && (checkElement.is(':visible')) && (!$('body').hasClass('sidebar-collapse'))) { //Close the menu checkElement.slideUp(animationSpeed, function () { checkElement.removeClass('menu-open'); //Fix the layout in case the sidebar stretches over the height of the window //_this.layout.fix(); }); checkElement.parent("li").removeClass("active"); } //If the menu is not visible else if ((checkElement.is('.treeview-menu')) && (!checkElement.is(':visible'))) { //Get the parent menu var parent = $this.parents('ul').first(); //Close all open menus within the parent var ul = parent.find('ul:visible').slideUp(animationSpeed); //Remove the menu-open class from the parent ul.removeClass('menu-open'); //Get the parent li var parent_li = $this.parent("li"); //Open the target menu and add the menu-open class checkElement.slideDown(animationSpeed, function () { //Add the class active to the parent li checkElement.addClass('menu-open'); parent.find('li.active').removeClass('active'); parent_li.addClass('active'); //Fix the layout in case the sidebar stretches over the height of the window _this.layout.fix(); }); } //if this isn't a link, prevent the page from being redirected if (checkElement.is('.treeview-menu')) { e.preventDefault(); } }); }; /* ControlSidebar * ============== * Adds functionality to the right sidebar * * @type Object * @usage $.Jamkrida.controlSidebar.activate(options) */ $.Jamkrida.controlSidebar = { //instantiate the object activate: function () { //Get the object var _this = this; //Update options var o = $.Jamkrida.options.controlSidebarOptions; //Get the sidebar var sidebar = $(o.selector); //The toggle button var btn = $(o.toggleBtnSelector); //Listen to the click event btn.on('click', function (e) { e.preventDefault(); //If the sidebar is not open if (!sidebar.hasClass('control-sidebar-open') && !$('body').hasClass('control-sidebar-open')) { //Open the sidebar _this.open(sidebar, o.slide); } else { _this.close(sidebar, o.slide); } }); //If the body has a boxed layout, fix the sidebar bg position var bg = $(".control-sidebar-bg"); _this._fix(bg); //If the body has a fixed layout, make the control sidebar fixed if ($('body').hasClass('fixed')) { _this._fixForFixed(sidebar); } else { //If the content height is less than the sidebar's height, force max height if ($('.content-wrapper, .right-side').height() < sidebar.height()) { _this._fixForContent(sidebar); } } }, //Open the control sidebar open: function (sidebar, slide) { //Slide over content if (slide) { sidebar.addClass('control-sidebar-open'); } else { //Push the content by adding the open class to the body instead //of the sidebar itself $('body').addClass('control-sidebar-open'); } }, //Close the control sidebar close: function (sidebar, slide) { if (slide) { sidebar.removeClass('control-sidebar-open'); } else { $('body').removeClass('control-sidebar-open'); } }, _fix: function (sidebar) { var _this = this; if ($("body").hasClass('layout-boxed')) { sidebar.css('position', 'absolute'); sidebar.height($(".wrapper").height()); $(window).resize(function () { _this._fix(sidebar); }); } else { sidebar.css({ 'position': 'fixed', 'height': 'auto' }); } }, _fixForFixed: function (sidebar) { sidebar.css({ 'position': 'fixed', 'max-height': '100%', 'overflow': 'auto', 'padding-bottom': '50px' }); }, _fixForContent: function (sidebar) { $(".content-wrapper, .right-side").css('min-height', sidebar.height()); } }; /* BoxWidget * ========= * BoxWidget is a plugin to handle collapsing and * removing boxes from the screen. * * @type Object * @usage $.Jamkrida.boxWidget.activate() * Set all your options in the main $.Jamkrida.options object */ $.Jamkrida.boxWidget = { selectors: $.Jamkrida.options.boxWidgetOptions.boxWidgetSelectors, icons: $.Jamkrida.options.boxWidgetOptions.boxWidgetIcons, animationSpeed: $.Jamkrida.options.animationSpeed, activate: function (_box) { var _this = this; if (!_box) { _box = document; // activate all boxes per default } //Listen for collapse event triggers $(_box).on('click', _this.selectors.collapse, function (e) { e.preventDefault(); _this.collapse($(this)); }); //Listen for remove event triggers $(_box).on('click', _this.selectors.remove, function (e) { e.preventDefault(); _this.remove($(this)); }); }, collapse: function (element) { var _this = this; //Find the box parent var box = element.parents(".box").first(); //Find the body and the footer var box_content = box.find("> .box-body, > .box-footer, > form >.box-body, > form > .box-footer"); if (!box.hasClass("collapsed-box")) { //Convert minus into plus element.children(":first") .removeClass(_this.icons.collapse) .addClass(_this.icons.open); //Hide the content box_content.slideUp(_this.animationSpeed, function () { box.addClass("collapsed-box"); }); } else { //Convert plus into minus element.children(":first") .removeClass(_this.icons.open) .addClass(_this.icons.collapse); //Show the content box_content.slideDown(_this.animationSpeed, function () { box.removeClass("collapsed-box"); }); } }, remove: function (element) { //Find the box parent var box = element.parents(".box").first(); box.slideUp(this.animationSpeed); } }; } /* ------------------ * - Custom Plugins - * ------------------ * All custom plugins are defined below. */ /* * BOX REFRESH BUTTON * ------------------ * This is a custom plugin to use with the component BOX. It allows you to add * a refresh button to the box. It converts the box's state to a loading state. * * @type plugin * @usage $("#box-widget").boxRefresh( options ); */ (function ($) { "use strict"; $.fn.boxRefresh = function (options) { // Render options var settings = $.extend({ //Refresh button selector trigger: ".refresh-btn", //File source to be loaded (e.g: ajax/src.php) source: "", //Callbacks onLoadStart: function (box) { return box; }, //Right after the button has been clicked onLoadDone: function (box) { return box; } //When the source has been loaded }, options); //The overlay var overlay = $('
'); return this.each(function () { //if a source is specified if (settings.source === "") { if (window.console) { window.console.log("Please specify a source first - boxRefresh()"); } return; } //the box var box = $(this); //the button var rBtn = box.find(settings.trigger).first(); //On trigger click rBtn.on('click', function (e) { e.preventDefault(); //Add loading overlay start(box); //Perform ajax call box.find(".box-body").load(settings.source, function () { done(box); }); }); }); function start(box) { //Add overlay and loading img box.append(overlay); settings.onLoadStart.call(box); } function done(box) { //Remove overlay and loading img box.find(overlay).remove(); settings.onLoadDone.call(box); } }; })(jQuery); /* * EXPLICIT BOX CONTROLS * ----------------------- * This is a custom plugin to use with the component BOX. It allows you to activate * a box inserted in the DOM after the app.js was loaded, toggle and remove box. * * @type plugin * @usage $("#box-widget").activateBox(); * @usage $("#box-widget").toggleBox(); * @usage $("#box-widget").removeBox(); */ (function ($) { 'use strict'; $.fn.activateBox = function () { $.Jamkrida.boxWidget.activate(this); }; $.fn.toggleBox = function(){ var button = $($.Jamkrida.boxWidget.selectors.collapse, this); $.Jamkrida.boxWidget.collapse(button); }; $.fn.removeBox = function(){ var button = $($.Jamkrida.boxWidget.selectors.remove, this); $.Jamkrida.boxWidget.remove(button); }; })(jQuery); /* * TODO LIST CUSTOM PLUGIN * ----------------------- * This plugin depends on iCheck plugin for checkbox and radio inputs * * @type plugin * @usage $("#todo-widget").todolist( options ); */ (function ($) { 'use strict'; $.fn.todolist = function (options) { // Render options var settings = $.extend({ //When the user checks the input onCheck: function (ele) { return ele; }, //When the user unchecks the input onUncheck: function (ele) { return ele; } }, options); return this.each(function () { if (typeof $.fn.iCheck != 'undefined') { $('input', this).on('ifChecked', function () { var ele = $(this).parents("li").first(); ele.toggleClass("done"); settings.onCheck.call(ele); }); $('input', this).on('ifUnchecked', function () { var ele = $(this).parents("li").first(); ele.toggleClass("done"); settings.onUncheck.call(ele); }); } else { $('input', this).on('change', function () { var ele = $(this).parents("li").first(); ele.toggleClass("done"); if ($('input', ele).is(":checked")) { settings.onCheck.call(ele); } else { settings.onUncheck.call(ele); } }); } }); }; }(jQuery)); $(document).ready(function(){ /* INitialize Acounting.js*/ accounting.settings = { currency: { symbol : "", // default currency symbol is '$' // format: "%s%v", // controls output: %s = symbol, %v = value/number (can be object: see below) decimal : ".", // decimal point separator thousand: ",", // thousands separator precision : 2 // decimal places }, number: { precision : 2, // default precision on numbers is 0 thousand: ",", decimal : "." } }; if ($.fn.datepicker) { $.fn.datepicker.defaults.format = "dd/mm/yyyy"; } // These can be changed externally to edit the library's defaults: accounting.settings.currency.format = "%s %v"; // Format can be an object, with `pos`, `neg` and `zero`: accounting.settings.currency.format = { pos : "%s %v", // for positive values, eg. "$ 1.00" (required) neg : "%s (%v)", // for negative values, eg. "$ (1.00)" [optional] zero: "%s %v " // for zero values, eg. "$ --" [optional] }; Number.prototype.money = function(){ return $.Jamkrida.money(this); }; String.prototype.unmoney = function(){ return $.Jamkrida.unmoney(this); }; // $.Jamkrida.login('a', 'b', function(user){}, function(msg){}, 'true'); /* ******************************** ** Socket.io initialization ** *******************************/ /* var socket = io('http://localhost:3000/'); socket.on('pushData', function(data){ // console.log(data); var notificationMenu = $('li.notifications-menu a span.label'); if (notificationMenu.length > 0) { notificationMenu.html(data.notifications.length); var ul = $('li.notifications-menu ul.dropdown-menu'); var li = ul.find('li'); $(li[0]).html('Anda memiliki '+data.notifications.length +' notifikasi.'); var notifs = $(li[1]).find('ul.menu'); var list = ''; for (var i = 0; i < data.notifications.length;i++){ list += '
  • \ '+ data.notifications[i].evt_data +'\
  • '; } $(notifs).html(list); } }); */ // change active link element: var currentHref = document.location.pathname.substr(1)+(document.location.search||''); if (currentHref==''){ currentHref = 'index.php'; } /*$('li.treeview a').each(function(i, el) {*/ var el = $('li.treeview a'); var baseUri = 'http://'+$.Jamkrida.baseDomain; for (var i = 0; i< el.length; i++){ var e = $(el[i]); // console.log(currentHref.toLowerCase() + ': ' + e.prop('href').toLowerCase().substr(baseUri.length+1)); if (currentHref.toLowerCase() == e.prop('href').toLowerCase().substr(baseUri.length+1)){ // console.log(e.prop('href').toLowerCase()); e.parent().addClass('currentPage'); e.parents('li').addClass('active')/*.addClass('currentPage')*/; e.parentsUntil('li.treeview').addClass('active')/*.addClass('currentPage')*/; break; } }/*)*/; $(document).ajaxStart(function(){ // console.log('AJAX CALL'); /* if (!window.ajaxIndicator) { $('body').append('
    \
    \ \
    \
    '); window.ajaxIndicator = $('#ajax-indicator-div'); } window.ajaxIndicator.show(); */ }); $(document).ajaxError(function(){ /* if (window.ajaxIndicator) { window.ajaxIndicator .hide() .remove(); } */ $.Jamkrida.toastDanger('Terjadi kesalahan.'); }); $(document).ajaxComplete(function(){ /* if (window.ajaxIndicator) { window.ajaxIndicator .hide() .remove(); } */ }); $(document).on('focus', '.input-uang', function(){ var __ = $(this); __.val($.Jamkrida.unmoney(__.val())); }); $(document).on('blur', '.input-uang', function(){ var __ = $(this); __.val($.Jamkrida.money(__.val())); }); $('ul.treeview-menu li a.divider').click(function(e){ e.preventDefault(); return false; }); // default handler for ... /* var jur = new Jurnal($.Jamkrida); jur.jenis='BTK'; jur.tanggal = '2016/03/29'; jur.userId = 1; jur.keterangan= 'Penarikan dana dari bank Mandiri'; jur.addRekening({kode:'100001001',uraian:'Kas di Bendahara',debet:10000, kredit:0}); jur.addRekening({kode:'100001002',uraian:'Bank Mandiri',debet:0, kredit:10000}); console.log(jur.isBalanced()); console.log(jur.rekening); console.log(jur); jur.saveJurnal(function(json){ console.log(json); }, function(error){ console.log(error); }); */ });