490 lines
15 KiB
JavaScript
490 lines
15 KiB
JavaScript
$(function () {
|
|
$('[data-toggle="tooltip"]').tooltip({
|
|
container: 'body'
|
|
});
|
|
$.fn.modal.Constructor.prototype.enforceFocus = $.noop;
|
|
});
|
|
|
|
/**
|
|
* Các hàm sử dụng chung
|
|
*/
|
|
var common = {};
|
|
common.csrf = $('meta[name="csrf-token"]').attr("content");
|
|
common.csrfParam = $('meta[name="csrf-param"]').attr("content");
|
|
common.modalOpen = function (data, lg, title) {
|
|
$("#myModalContent").html(data);
|
|
$("#myModalContent").attr("style", "");
|
|
if (lg) {
|
|
$(".modal-dialog").addClass("modal-lg");
|
|
} else {
|
|
$(".modal-dialog").removeClass("modal-lg");
|
|
}
|
|
if (!title) {
|
|
$("#modalHeader").addClass("hidden");
|
|
} else {
|
|
$("#modalHeader").removeClass("hidden");
|
|
$("#myModalLabel").html(title);
|
|
}
|
|
$("#myModalFooter").addClass("hidden");
|
|
$("#myModal").modal({
|
|
keyboard: false,
|
|
backdrop: false
|
|
});
|
|
};
|
|
common.modalOpenFullScreen = function (data, title) {
|
|
$("input[name='ReLoadFullScreen']").val("false");
|
|
$("#myModalFullScreenContent").html(data);
|
|
if (title == false) {
|
|
$("#modalFullScreenHeader").addClass("hidden");
|
|
} else {
|
|
$("#modalFullScreenHeader").removeClass("hidden");
|
|
$("#myModalFullScreenLabel").html(title);
|
|
}
|
|
$("#myModalFullScreen").modal();
|
|
};
|
|
common.modalBlock = function (stt) {
|
|
if (stt) {
|
|
$("#blocking").modal({
|
|
keyboard: false,
|
|
backdrop: false
|
|
});
|
|
} else {
|
|
$("#blocking").modal("hide");
|
|
}
|
|
};
|
|
common.uploadBlock = function (stt) {
|
|
if (stt) {
|
|
$("#uploadBlock").modal({
|
|
keyboard: false,
|
|
backdrop: false
|
|
});
|
|
} else {
|
|
$("#uploadBlock").modal("hide");
|
|
}
|
|
};
|
|
common.modalAlert = function (text, cls, link) {
|
|
$("#alertModalContent").html(text);
|
|
$("#alertModalDialog").removeClass("modal-lg");
|
|
$("#alertModal").modal({
|
|
backdrop: 'static',
|
|
keyboard: false
|
|
});
|
|
switch (cls) {
|
|
case "success":
|
|
$("#alertModalHeader").attr("style", "background-color:#5cb85c;color:white;");
|
|
break;
|
|
case "danger":
|
|
$("#alertModalHeader").attr("style", "background-color:#d9534f;color:white;");
|
|
break;
|
|
case "info":
|
|
$("#alertModalHeader").attr("style", "background-color:#5bc0de;color:white;");
|
|
break;
|
|
case "warning":
|
|
$("#alertModalHeader").attr("style", "background-color:#f0ad4e;color:white;");
|
|
break;
|
|
}
|
|
if (link !== "") {
|
|
$('#alertModal').on('hide.bs.modal', function () {
|
|
window.location = link;
|
|
});
|
|
}
|
|
};
|
|
common.ajaxError = function () {
|
|
common.modalAlert("Có lỗi xảy ra, có thể do đường truyền mạng, xin vui lòng thử lại!", "danger", "");
|
|
};
|
|
common.btnUpload = function (mUrl, className, extension, fileSize) {
|
|
var fData = {
|
|
UploadFile: true,
|
|
Name: className
|
|
};
|
|
fData[common.csrfParam] = common.csrf;
|
|
new afuButton({
|
|
uploadURI: mUrl,
|
|
formData: fData,
|
|
wrap: {
|
|
tagName: 'div',
|
|
classes: ''
|
|
},
|
|
fileExtension: extension,
|
|
fileSizeLimit: fileSize,
|
|
classes: 'btn btn-default file-paperclip-' + className,
|
|
fakeInputContent: '<span class=\'fa fa-paperclip\'></span>',
|
|
onUploaded: function (data) {
|
|
common.uploadBlock(false);
|
|
if (data !== 'false') {
|
|
var r = JSON.parse(data);
|
|
if (r['link'] == 2) {
|
|
alert('Định dạng tệp tin không được hỗ trợ!\n Các loại tệp tin được hỗ trợ: ' + extension);
|
|
} else {
|
|
//alert("Tệp tin đã được tải lên thành công");
|
|
$("#fileUpload" + className).attr("href", r['link']);
|
|
$("#fileUpload" + className).html(r['name'] + " ");
|
|
$("input[name='fileUploadLink" + className + "']").val(r['link']);
|
|
}
|
|
} else {
|
|
alert('Có lỗi xảy ra, tải tệp tin không thành công!');
|
|
}
|
|
}
|
|
}).addInstance('file' + className);
|
|
$(".file-paperclip-" + className).closest("div").attr("style", "display:inline-block;");
|
|
};
|
|
common.btnUploadImage = function (mUrl, className, extension, fileSize) {
|
|
var fData = {
|
|
UploadImage: true,
|
|
Name: className
|
|
};
|
|
fData[common.csrfParam] = common.csrf;
|
|
new afuButton({
|
|
uploadURI: mUrl,
|
|
formData: fData,
|
|
wrap: {
|
|
tagName: 'div',
|
|
classes: ''
|
|
},
|
|
fileExtension: extension,
|
|
fileSizeLimit: fileSize,
|
|
classes: 'btn btn-primary btn-xs',
|
|
fakeInputContent: '<span class=\'fa fa-file-image-o\'></span> Chọn hình ảnh',
|
|
onUploaded: function (data) {
|
|
common.uploadBlock(false);
|
|
alert("Hình ảnh đã được tải lên thành công");
|
|
$("#HinhMinhHoa" + className).attr("src", "data/uploads" + data);
|
|
$("input[name='HinhMinhHoaLink" + className + "']").val(data);
|
|
$("input[name='updateStatus']").val("1");
|
|
}
|
|
}).addInstance('image' + className);
|
|
};
|
|
common.dateTimePicker = function (id) {
|
|
$('#' + id).datetimepicker({
|
|
locale: 'vi',
|
|
ignoreReadonly: true,
|
|
format: 'HH:mm DD/MM/YYYY',
|
|
sideBySide: true
|
|
});
|
|
};
|
|
common.dateTimePickerDay = function (id) {
|
|
$('#' + id).datetimepicker({
|
|
locale: 'vi',
|
|
ignoreReadonly: true,
|
|
format: 'DD/MM/YYYY'
|
|
});
|
|
};
|
|
common.dateTimePickerHour = function (id) {
|
|
$('#' + id).datetimepicker({
|
|
locale: 'vi',
|
|
ignoreReadonly: true,
|
|
format: 'HH:mm'
|
|
});
|
|
};
|
|
common.dateTimePickerById = function (id, format) {
|
|
$('#' + id).datetimepicker({
|
|
locale: 'vi',
|
|
ignoreReadonly: true,
|
|
format: format
|
|
});
|
|
};
|
|
common.dateTimePickerByClass = function (cls, format) {
|
|
$('.' + cls).datetimepicker({
|
|
locale: 'vi',
|
|
ignoreReadonly: true,
|
|
sideBySide: true,
|
|
format: format
|
|
});
|
|
};
|
|
common.checkAll = function (id, cls) {
|
|
$('#' + id).on('ifChecked', function (event) {
|
|
$('.' + cls).iCheck('check');
|
|
});
|
|
$('#' + id).on('ifUnchecked', function (event) {
|
|
$('.' + cls).iCheck('uncheck');
|
|
});
|
|
$('#' + id).on('ifChanged', function (event) {
|
|
if (!this.changed) {
|
|
this.changed = true;
|
|
$('#' + id).iCheck('check');
|
|
} else {
|
|
this.changed = false;
|
|
$('#' + id).iCheck('uncheck');
|
|
}
|
|
$('#' + id).iCheck('update');
|
|
});
|
|
};
|
|
common.getUrlParameter = function (sParam) {
|
|
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
|
|
sURLVariables = sPageURL.split('&'),
|
|
sParameterName,
|
|
i;
|
|
for (i = 0; i < sURLVariables.length; i++) {
|
|
sParameterName = sURLVariables[i].split('=');
|
|
if (sParameterName[0] === sParam) {
|
|
return sParameterName[1] === undefined ? true : sParameterName[1];
|
|
}
|
|
}
|
|
};
|
|
common.error = function (id, text) {
|
|
$("#" + id).addClass("has-error").removeClass("has-success").removeClass("has-warning");
|
|
$("#" + id).find(".help-block").html(text).removeClass("hidden");
|
|
};
|
|
common.success = function (id) {
|
|
$("#" + id).addClass("has-success").removeClass("has-error");
|
|
$("#" + id).find(".help-block").addClass("hidden");
|
|
};
|
|
common.warning = function (id, text) {
|
|
$("#" + id).addClass("has-warning").removeClass("has-error").removeClass("has-success");
|
|
$("#" + id).find(".help-block").html(text).removeClass("hidden");
|
|
};
|
|
common.form = function (e, obj, bigSize) {
|
|
var size = bigSize | false;
|
|
common.modalBlock(true);
|
|
$.ajax({
|
|
url: $(e).attr('data-href'),
|
|
type: 'POST',
|
|
success: function (data) {
|
|
common.modalBlock(false);
|
|
common.modalOpen(data.form, size, data.title);
|
|
if (obj === 'department')
|
|
$('#Pid').select2();
|
|
if (obj === 'staff') {
|
|
$('#Department').select2();
|
|
common.dateTimePickerByClass("DatePicker", "DD/MM/YYYY");
|
|
btnImage();
|
|
$("#staff-img").on("click", function () {
|
|
$("#AnhNhanVien").trigger("click");
|
|
});
|
|
}
|
|
if (obj === 'card-register') {
|
|
$('#Staff').select2();
|
|
}
|
|
if (obj === 'device') {
|
|
$('#Area').select2();
|
|
}
|
|
if (obj === 'schedule') {
|
|
common.dateTimePickerByClass("select-picker", "HH:mm");
|
|
}
|
|
if (obj === 'user') {
|
|
$('#role').select2({tags: true, tokenSeparators: [',']});
|
|
}
|
|
if (obj === 'statistics') {
|
|
common.dateTimePickerById("month", "MM/YYYY");
|
|
}
|
|
if (obj === "auth") {
|
|
var roles = JSON.parse($("#roleArray").html());
|
|
for (var k in roles) {
|
|
common.checkboxInit("permission-" + k);
|
|
}
|
|
}
|
|
},
|
|
error: function (jqXHR, textStatus, errorThrown) {
|
|
common.modalBlock(false);
|
|
common.ajaxError();
|
|
}
|
|
});
|
|
};
|
|
common.checkboxInit = function (id) {
|
|
$('.checkbox-' + id).iCheck({
|
|
checkboxClass: 'icheckbox_flat-blue'
|
|
});
|
|
$('#checkall-' + id).on('ifChanged', function (event) {
|
|
if (event.target.checked) {
|
|
$('.checkbox-' + id).iCheck('check');
|
|
} else {
|
|
$('.checkbox-' + id).iCheck('uncheck');
|
|
}
|
|
});
|
|
};
|
|
common.tree = function (e) {
|
|
var stt = $(e).attr("data-stt");
|
|
if (stt === "true") {
|
|
$(e).removeClass("fa-minus-square-o").addClass("fa-plus-square-o").attr("data-stt", "false");
|
|
$("#sub-tree-" + $(e).attr("data")).addClass("hidden");
|
|
} else {
|
|
$(e).removeClass("fa-plus-square-o").addClass("fa-minus-square-o").attr("data-stt", "true");
|
|
$("#sub-tree-" + $(e).attr("data")).removeClass("hidden");
|
|
}
|
|
};
|
|
common.validatePhone = function (PhoneNumber) {
|
|
var pattern = /^[0-9]{10,11}$/;
|
|
if (pattern.test(PhoneNumber)) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
};
|
|
common.validateEmail = function (Email) {
|
|
var pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
|
|
if (pattern.test(Email)) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
};
|
|
common.validateIp = function (Ip) {
|
|
if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(Ip)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
/**
|
|
* =========================
|
|
*/
|
|
|
|
/**
|
|
* Notification
|
|
*/
|
|
var notification = {
|
|
success: function (text, time) {
|
|
$.notify({
|
|
icon: "fa fa-check",
|
|
message: "<strong>" + text + "</strong>"
|
|
}, {
|
|
type: "success",
|
|
allow_dismiss: false,
|
|
showProgressbar: false,
|
|
z_index: 99999999,
|
|
placement: {
|
|
from: "bottom",
|
|
align: "left"
|
|
},
|
|
offset: 70,
|
|
delay: time,
|
|
animate: {
|
|
enter: 'animated fadeInDown',
|
|
exit: 'animated fadeOutUp'
|
|
},
|
|
});
|
|
},
|
|
danger: function (text, time) {
|
|
$.notify({
|
|
icon: "fa fa-remove",
|
|
message: "<strong>" + text + "</strong>"
|
|
}, {
|
|
type: "danger",
|
|
allow_dismiss: false,
|
|
showProgressbar: false,
|
|
z_index: 99999999,
|
|
placement: {
|
|
from: "bottom",
|
|
align: "left"
|
|
},
|
|
offset: 70,
|
|
delay: time,
|
|
animate: {
|
|
enter: 'animated fadeInDown',
|
|
exit: 'animated fadeOutUp'
|
|
},
|
|
});
|
|
},
|
|
warning: function (text, time) {
|
|
$.notify({
|
|
icon: "fa fa-question-circle",
|
|
message: "<strong>" + text + "</strong>"
|
|
}, {
|
|
type: "warning",
|
|
allow_dismiss: false,
|
|
showProgressbar: false,
|
|
z_index: 99999999,
|
|
placement: {
|
|
from: "bottom",
|
|
align: "left"
|
|
},
|
|
offset: 70,
|
|
delay: time,
|
|
animate: {
|
|
enter: 'animated fadeInDown',
|
|
exit: 'animated fadeOutUp'
|
|
},
|
|
});
|
|
},
|
|
info: function (text, time) {
|
|
$.notify({
|
|
icon: "fa fa-info-circle",
|
|
message: "<strong>" + text + "</strong>"
|
|
}, {
|
|
type: "info",
|
|
allow_dismiss: false,
|
|
showProgressbar: false,
|
|
z_index: 99999999,
|
|
placement: {
|
|
from: "bottom",
|
|
align: "right"
|
|
},
|
|
offset: 70,
|
|
delay: time,
|
|
animate: {
|
|
enter: 'animated fadeInDown',
|
|
exit: 'animated fadeOutUp'
|
|
},
|
|
});
|
|
},
|
|
df: function (text, time, type) {
|
|
$.notify({
|
|
icon: "fa fa-info-circle",
|
|
message: text
|
|
}, {
|
|
type: type,
|
|
allow_dismiss: false,
|
|
showProgressbar: false,
|
|
z_index: 99999999,
|
|
placement: {
|
|
from: "bottom",
|
|
align: "right"
|
|
},
|
|
offset: 70,
|
|
delay: time,
|
|
animate: {
|
|
enter: 'animated fadeInDown',
|
|
exit: 'animated fadeOutUp'
|
|
},
|
|
});
|
|
},
|
|
primary: function (text, time) {
|
|
$.notify({
|
|
icon: "fa fa-info-circle",
|
|
message: "<strong>" + text + "</strong>"
|
|
}, {
|
|
type: "primary",
|
|
allow_dismiss: false,
|
|
showProgressbar: false,
|
|
z_index: 99999999,
|
|
placement: {
|
|
from: "bottom",
|
|
align: "left"
|
|
},
|
|
offset: 70,
|
|
delay: time,
|
|
animate: {
|
|
enter: 'animated fadeInDown',
|
|
exit: 'animated fadeOutUp'
|
|
},
|
|
});
|
|
},
|
|
};
|
|
+function ($, document) {
|
|
//Fix scroll with modal multiple show
|
|
var stackModal = 0;
|
|
var orginBodyPad = '';
|
|
$(document).on('show.bs.modal', '.modal', function (event) {
|
|
// var zIndex = 1040 + (10 * $('.modal:visible').length);
|
|
// $(this).css('z-index', zIndex);
|
|
if (stackModal <= 0) {
|
|
orginBodyPad = document.body.style.paddingRight || '';
|
|
}
|
|
stackModal++;
|
|
setTimeout(function () {
|
|
$('.modal-backdrop').not('.modal-stack')
|
|
// .css('z-index', zIndex - 1)
|
|
.addClass('modal-stack');
|
|
}, 0);
|
|
$(this).appendTo(document.body);
|
|
});
|
|
$(document).on('hidden.bs.modal', '.modal', function (event) {
|
|
stackModal--;
|
|
if (stackModal > 0) {
|
|
$('body').addClass("modal-open");
|
|
} else {
|
|
$('body').removeClass("modal-open");
|
|
document.body.style.paddingRight = orginBodyPad;
|
|
orginBodyPad = '';
|
|
}
|
|
});
|
|
}(jQuery, document); |