function autoFocus($timeout) {
return {
link: function (scope, element, attrs) {
attrs.$observe("autoFocus", function(newValue){
if (newValue === "true")
$timeout(function(){element.focus()});
});
}
};
};
function autofocusIf($timeout) {
return {
restrict: 'A',
scope: {
autofocusIf: '&'
},
link: function($scope, $element) {
$scope.$watch('autofocusIf', function(shouldFocus) {
if (shouldFocus()) {
$timeout(function() {
$element[0].focus();
});
} else {
$timeout(function() {
$element[0].blur();
});
}
});
}
};
};
function btnClick(users,post) {
return {
restrict: 'A',
scope: {
dataform:'=',
result:'=',
},
link: function (scope, element, attrs) {
element.bind('click', function() {
var user = users.data();
var input = attrs.fid;
var pid = attrs.btnClick;
var grp = attrs.grp;
var file = attrs.file;
var func = attrs.func;
var data = '';
var param = {rt: grp + '.' + file +'.' + func,id:input, user:user, pid:pid, tms:tms(), data: scope.dataform};
busy();
post(param).success(function(e){
rest();
if(e == 0){
toastr.error(e, 'Unsuccessfull',{timeOut: 5000});
console.log(e);
} else {
scope.result = e;
toastr.success('Successfull');
}
});
});
}
};
};
function calendar ($timeout) {
return {
restrict: 'A',
require: 'ngModel',
scope: {
ngModel: "=",
from: "=",
to: "=",
duraday: "=",
},
link: function(scope, el, attr, ngModel) {
$timeout(function(){
// scope.$apply(attr.ngModel + "='test'");
// var dt = new Date();
// scope.$apply(attr.ngModel + "='test'");
var myformat = "yyyy-mm-dd";
$(el).attr('readonly','readonly');
// $(el).attr('placeholder','Enter date...');
var input = $(el);
var attrib = {
// keyboardNavigation: false,
// forceParse: false,
// autoclose: true,
format: myformat,
// startDate: "2019-09-02",
// endDate: endYear,
// minViewMode: "months",
// maxViewMode: "years",
// viewDate: new Date(),
// onSelect: function(dateText) {
// scope.$apply(function() {
// ngModel.$setViewValue(dateText);
// });
// // var expression = attr.ngModel + " = " + "'" + dateText + "'";
// // scope.$apply(expression);
// }
}
if(attr.viewWeek){
attrib.calendarWeeks = attr.viewWeek;
}
if(attr.minViewMode){
attrib.minViewMode = attr.minViewMode;
}
if(attr.startDate){
attrib.startDate = new Date(attr.startDate);
}
if(attr.endDate){
attrib.endDate = new Date(attr.endDate); //new Date(new Date().getFullYear(), 11, 31);
}
if(attr.datepicker == "now"){
// input.datepicker("setDate", new Date());
attrib.setDate = new Date();
}
input.datepicker(attrib);
// $(input[0].firstChild).css('margin','auto');
if(scope.ngModel == '0000-00-00'){
// attrib.defaultDate = new Date();
}
input.on('changeDate',function(e){
var curDate = strtodate(e.date);
var getDate = curDate;
if(attr.format){
getDate = '';
var aDate = curDate.split('-');
// attrib.format = attr.format;
var f = attr.format.toUpperCase();
var fmx = f.length;
var strf = '';
var mtchY = 0;
var mtchM = 0;
var mtchD = 0;
var sparator = '';
for (var i = 0; i < fmx; i++) {
if(f[i] == 'Y'){ mtchY += 1; }
if(f[i] == 'M'){ mtchM += 1; }
if(f[i] == 'D'){ mtchD += 1; }
if(f[i] == '-'){ sparator = f[i]; }
if(f[i] == '/'){ sparator = f[i]; }
}
var obj = {};
if(mtchY == 1){
obj.Y = aDate[0].substr(2);
} else if(mtchY > 1){
obj.Y = aDate[0];
}
if(mtchM > 0) obj.M = aDate[1];
if(mtchD > 0) obj.D = aDate[2];
var match = '';
var str = '';
for (var i = 0; i < f.length; i++) {
if(match == f[i]) continue;
match = f[i];
if(obj[match]) {
str += obj[match];
} else { str += match }
}
getDate = str;
}
scope.$apply(function() {
return ngModel.$setViewValue(getDate);
});
});
// input.on('changeDate',function(e){
// var currMonth = new Date(e.date).getMonth() + 1;
// var currYear = String(e.date).split(" ")[3];
// var currMthYr = currYear+currMonth;
// })
}, 50);
}
};
}
/**
* chatSlimScroll - Directive for slim scroll for small chat
*/
function chatSlimScroll ($timeout) {
return {
restrict: 'A',
link: function(scope, element) {
$timeout(function(){
element.slimscroll({
height: '234px',
railOpacity: 0.4
});
});
}
};
};
function checkClick(users,post) {
return {
restrict: 'A',
scope: {
// dataform:'=',
result: '=',
val: '=ngModel',
},
link: function (scope, element, attrs) {
element.bind('click', function() {
var user = users.data();
var pid = attrs.checkClick;
var grp = attrs.grp;
var file = attrs.file;
var func = attrs.func;
var data = '';
var rt = attrs.rt.split('_').join('.');
var param = {rt:rt, user:user, pid:pid, val: scope.val};
if(attrs.fid) {
input = attrs.fid;
param.id = input;
}
param.tms = 0;
if(scope.val == 1){
param.tms = attrs.temp;
}
busy();
post(param).success(function(e){
rest();
if(e == 0){
toastr.error(e, 'Unsuccessfull',{timeOut: 5000});
console.log(e);
} else {
if(scope.result) scope.result = e;
// toastr.success('Successfull');
}
});
});
}
};
};
function checkVal ($timeout) {
return {
scope: {
checkVal: '=',
value: '@'
},
link: function(scope, elem, attrs ) {
var handler = function(setup) {
if (setup){
// console.log ('value1 = '+ scope.value)
var checked = scope.checkVal&scope.value;
elem.prop('checked', checked);
}else{
// console.log ('value2 = '+ scope.value)
var checked = elem.prop('checked');
if (!scope.checkVal&scope.value)
scope.checkVal |= scope.value
else
scope.checkVal ^= scope.value
}
// console.log ('bit = '+ scope.checkVal)
// console.log ('value = '+ scope.value)
// console.log ('checked ='+ checked)
};
var setupHandler = handler.bind(null, true);
var changeHandler = handler.bind(null, false);
elem.on('change', function() {
scope.$apply(changeHandler);
});
scope.$watch('checkVal', setupHandler, true);
}
};
};
/**
* clockPicker - Directive for clock picker plugin
*/
function clockPicker1 () {
return {
restrict: 'A',
link: function(scope, element) {
element.clockpicker();
}
};
};
function clockpicker ($timeout){
// $('#dtout,#dtin').clockpicker();
return {
restrict: 'A',
link: function(scope, el, attr){
$timeout(function(){
$(el).clockpicker({
placement: 'bottom',
align: 'left',
autoclose: false,
twelvehour:false,
'default': 'now',
donetext: 'Done',
});
},50);
}
};
}
function closeOffCanvas() {
return {
restrict: 'A',
template: '',
controller: function ($scope, $element) {
$scope.closeOffCanvas = function () {
$("body").toggleClass("mini-navbar");
}
}
};
};
function createInput ($compile){
return {
template: '
',
replace: true,
link: function(scope, element) {
var validate = scope.input.validform +'.' + scope.input.name;
var required = scope.input.required;
var el = angular.element('');
switch(scope.input.inputType) {
case 'checkbox':
// el.append('');
el.append('');
break;
case 'text':
// el.append('');
el.append('');
el.append('
Ruangan ini diperlukan.
');
break;
}
$compile(el)(scope);
element.append(el);
}
}
}
/**
* customValid - Directive for custom validation example
*/
function customValid (){
return {
require: 'ngModel',
link: function(scope, ele, attrs, c) {
scope.$watch(attrs.ngModel, function() {
// You can call a $http method here
// Or create custom validation
var validText = "Inspinia";
if(scope.extras == validText) {
c.$setValidity('cvalid', true);
} else {
c.$setValidity('cvalid', false);
}
});
}
}
};
function datepicker ($timeout) {
return {
restrict: 'A',
require: 'ngModel',
scope: {
ngModel: "=",
from: "=",
to: "=",
duraday: "=",
},
link: function(scope, el, attr) {
$timeout(function(){
// scope.$apply(attr.ngModel + "='test'");
// var dt = new Date();
// scope.$apply(attr.ngModel + "='test'");
var len = attr.datepicker.length;
var myformat = "yyyy-mm-dd";
$(el).attr('readonly','readonly');
// $(el).attr('placeholder','Enter date...');
// if(len==10) myformat = attr.datepicker;
var input = $(el);
var attrib = {
keyboardNavigation: false,
forceParse: false,
autoclose: true,
format: myformat,
// startDate: "2019-09-02",
// endDate: endYear,
// minViewMode: "months",
// maxViewMode: "years",
// viewDate: new Date(),
// onSelect: function(dateText) {
// scope.$apply(function() {
// ngModel.$setViewValue(dateText);
// });
// // var expression = attr.ngModel + " = " + "'" + dateText + "'";
// // scope.$apply(expression);
// }
}
if(attr.viewWeek){
attrib.calendarWeeks = attr.viewWeek;
}
if(attr.minViewMode){
attrib.minViewMode = attr.minViewMode;
}
if(attr.format){
attrib.format = attr.format;
}
if(attr.startDate){
attrib.startDate = new Date(attr.startDate);
}
if(attr.endDate){
attrib.endDate = new Date(attr.endDate); //new Date(new Date().getFullYear(), 11, 31);
}
if(attr.datepicker == "now"){
// input.datepicker("setDate", new Date());
attrib.setDate = new Date();
}
input.datepicker(attrib);
if(scope.ngModel == '0000-00-00'){
// attrib.defaultDate = new Date();
}
// input.on('changeDate',function(e){
// var currMonth = new Date(e.date).getMonth() + 1;
// var currYear = String(e.date).split(" ")[3];
// var currMthYr = currYear+currMonth;
// // scope.$apply(function() {
// // ngModel.$setViewValue(currMthYr);
// // });
// })
dura();
}, 50);
function dura(){
var a = scope.from;
var b = scope.to;
var difference;
if(a){
difference = dateDiffInDays(a, scope.ngModel);
} else if(b){
difference = dateDiffInDays(scope.ngModel, b);
}
if(isNumber(difference)){
difference += ' days';
}
// modelSetter(scope, difference);
scope.duraday = difference;
scope.$apply();
}
el.on('change', function (e) {
e.stopPropagation();
e.preventDefault();
dura();
return false;
});
}
};
}
function datepickerButton () {
return {
restrict: 'EA',
require: '?ngModel',
scope: {
name:'@',
},
template: '',
link: function(scope, el, attr, controller) {
// if(!controller) return; // do nothing if no ng-model
var attrib = {
// keyboardNavigation: false,
// forceParse: false,
autoclose: true,
toggleActive: false,
setDate: new Date(),
todayHighlight: true,
// daysOfWeekHighlighted: "0",
}
if(attr.viewWeek){
attrib.calendarWeeks = attr.viewWeek;
}
if(attr.minViewMode){
attrib.minViewMode = attr.minViewMode;
}
if(attr.format){
attrib.format = attr.format;
}
if(attr.startDate){
attrib.startDate = new Date(attr.startDate);
}
if(attr.endDate){
attrib.endDate = new Date(attr.endDate);
}
if(attr.datepickerBtn == "now"){
attrib.setDate = new Date();
}
el.datepicker(attrib).on('changeDate',function(e){
var value = el.find('input').val();
if(attr.callback) {
var callback = attr.callback;
var parent = scope.$parent;
var p = parent[callback];
p(value);
// controller.$formatters.push(function(value) {
// // viewValue = value
// });
}
})
}
};
}
function decimal () {
return {
require: '?ngModel',
link: function(scope, element, attrs, ngModelCtrl) {
if(!ngModelCtrl) {
return;
}
ngModelCtrl.$parsers.push(function(val) {
if (angular.isUndefined(val)) {
var val = '';
}
var clean = val.replace(/[^-0-9\.]/g, '');
var negativeCheck = clean.split('-');
var decimalCheck = clean.split('.');
if(!angular.isUndefined(negativeCheck[1])) {
negativeCheck[1] = negativeCheck[1].slice(0, negativeCheck[1].length);
clean =negativeCheck[0] + '-' + negativeCheck[1];
if(negativeCheck[0].length > 0) {
clean =negativeCheck[0];
}
}
if(!angular.isUndefined(decimalCheck[1])) {
decimalCheck[1] = decimalCheck[1].slice(0,2);
clean =decimalCheck[0] + '.' + decimalCheck[1];
}
if (val !== clean) {
ngModelCtrl.$setViewValue(clean);
ngModelCtrl.$render();
}
return clean;
});
element.bind('keypress', function(event) {
if(event.keyCode === 32) {
event.preventDefault();
}
});
}
};
}
function drawComponent($compile){
return{
restrict: 'EA',
// scope : { type:'@', post:'@', text:'@', func:'@' },
scope: false,
replace: true,
link: function(scope, element, attrs){
var tpl;
var el;
function isEmpty(str) {
return (!str || 0 === str.length);
}
function getType(p) {
if (Array.isArray(p)) return 'array';
// else if (typeof p == 'string') return 'string';
else if (p != null && typeof p == 'object') return 'object';
else return 'string';
}
function oAlign(o){
var m;
switch (o) {
case 'C':
return 'text-center';
break;
case 'L':
return 'text-left';
break;
case 'R':
return 'text-right';
break;
default:
}
return m;
}
function tempObj(e){
var obj = e.element;
var o;
var attr = '';
var target = e;
if(obj == undefined) return e;
if(e.hasOwnProperty('attrib')){
attr += attribute(e);
} else {
for(var key in target){
var value = target[key];
if(key == 'element' || key == 'content') continue;
if(!isEmpty(attr)) attr += ' ';
if(value !== 'null'){
attr += key + '="' + target[key] + '"';
} else {
attr += key;
}
}
}
switch (obj) {
case 'break':
o = '';
break;
case 'a':
case 'b':
case 'button':
case 'div':
case 'form':
case 'fieldset':
case 'h1':
case 'h2':
case 'h3':
case 'h4':
case 'h5':
case 'h6':
case 'i':
case 'iframe':
case 'label':
case 'li':
case 'option':
case 'p':
case 'picture':
case 'span':
case 'strong':
case 'style':
case 'script':
case 'select':
case 'small':
case 'table':
case 'textarea':
case 'thead':
case 'tbody':
case 'tfoot':
case 'tr':
case 'td':
case 'th':
case 'ul':
var c = e.content;
var dtyp = getType(c);
o = '<' + obj + ' ' + attr + '>';
switch (dtyp) {
case 'array':
c.forEach(function(d) {
o += tempObj(d);
});
break;
case 'object':
o += tempObj(c);
break;
default:
if(c !== undefined) o += c;
}
o += '' + obj + '>';
break;
case 'hr':
case 'br':
case 'img':
case 'input':
var c = e.content;
if(c == undefined) c = '';
o = '<' + obj + ' ' + attr + '>' + c;
break;
case 'ibox':
var head = e.header;
var htyp = getType(head);
var body = e.body;
var dtyp = getType(body);
o = '
';
if(head){
o += '
';
switch (htyp) {
case 'array':
head.forEach(function(d) { o += tempObj(d); });
break;
case 'object':
o += tempObj(head);
break;
default:
o += head;
}
o += '
';
}
if(body){
o += '
';
switch (dtyp) {
case 'array':
body.forEach(function(d) { o += tempObj(d); });
break;
case 'object':
o += tempObj(body);
break;
default:
o += body;
}
o += '
';
}
o += '
';
break;
case 'static':
o = '';
break;
case 'tabled':
var atrb = attribute(e);
o = '
';
break;
default:
o = 'NONE';
}
return o;
}
function attribute(a){
var ret = '';
if(a.hasOwnProperty('attrib')){
var atrb = a.attrib;
if(Array.isArray(atrb)){
for(var i = 0; i0) ret += ' ';
ret += atrb[i];
}
} else {
ret = atrb;
}
}
return ret;
}
function elmt(el,data,find,arg){
var o = '' ;
if(data !== undefined){
var obj = data[el];
if(obj === undefined){
obj = data;
}
if(obj.hasOwnProperty(find)){
o += '<'+el+' ' + attribute(obj) + '>';
o += arg(obj[find]);
o += ''+el+'>';
} else {
for(var i=0; i';
o += arg(arr[find]);
o += ''+el+'>';
}
}
} else {
return el;
}
return o;
}
tpl = tempObj(scope.ele);
el = $compile(tpl)(scope);
element.replaceWith(el);
},
controller: function($scope){
$('[data-toggle="tooltip"]').tooltip();
// change date
// $(document).on('focusout','.datetime',function(e){
// var name = $(this).attr('name');
// var date = $(this).val();
// $scope.data[name] = $(this).val();
// })
}
}
};
function drawComponent1($compile){
return{
restrict: 'EA',
// scope : { type:'@', post:'@', text:'@', func:'@' },
scope: false,
replace: true,
link: function(scope, element, attrs){
var tpl;
var el;
function isEmpty(str) {
return (!str || 0 === str.length);
}
function getType(p) {
if (Array.isArray(p)) return 'array';
// else if (typeof p == 'string') return 'string';
else if (p != null && typeof p == 'object') return 'object';
else return 'string';
}
function oAlign(o){
var m;
switch (o) {
case 'C':
return 'text-center';
break;
case 'L':
return 'text-left';
break;
case 'R':
return 'text-right';
break;
default:
}
return m;
}
function tempObj(e){
var obj = e.element;
var o;
var attr = '';
var target = e;
if(obj == undefined) return e;
if(e.hasOwnProperty('attrib')){
attr += attribute(e);
} else {
for(var key in target){
var value = target[key];
if(key == 'element' || key == 'content') continue;
if(!isEmpty(attr)) attr += ' ';
if(value !== 'null'){
attr += key + '="' + target[key] + '"';
} else {
attr += key;
}
}
}
switch (obj) {
case 'break':
o = '';
break;
case 'a':
case 'b':
case 'button':
case 'div':
case 'form':
case 'fieldset':
case 'h1':
case 'h2':
case 'h3':
case 'h4':
case 'h5':
case 'h6':
case 'i':
case 'iframe':
case 'label':
case 'li':
case 'option':
case 'p':
case 'picture':
case 'span':
case 'strong':
case 'style':
case 'script':
case 'select':
case 'small':
case 'table':
case 'textarea':
case 'thead':
case 'tbody':
case 'tfoot':
case 'tr':
case 'td':
case 'th':
case 'ul':
var c = e.content;
var dtyp = getType(c);
o = '<' + obj + ' ' + attr + '>';
switch (dtyp) {
case 'array':
c.forEach(function(d) {
o += tempObj(d);
});
break;
case 'object':
o += tempObj(c);
break;
default:
if(c !== undefined) o += c;
}
o += '' + obj + '>';
break;
case 'hr':
case 'br':
case 'img':
case 'input':
var c = e.content;
if(c == undefined) c = '';
o = '<' + obj + ' ' + attr + '>' + c;
break;
case 'ibox':
var head = e.header;
var htyp = getType(head);
var body = e.body;
var dtyp = getType(body);
o = '
';
if(head){
o += '
';
switch (htyp) {
case 'array':
head.forEach(function(d) { o += tempObj(d); });
break;
case 'object':
o += tempObj(head);
break;
default:
o += head;
}
o += '
';
}
if(body){
o += '
';
switch (dtyp) {
case 'array':
body.forEach(function(d) { o += tempObj(d); });
break;
case 'object':
o += tempObj(body);
break;
default:
o += body;
}
o += '
';
}
o += '
';
break;
case 'static':
o = '';
break;
case 'tabled':
var atrb = attribute(e);
o = '