You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

380 lines
17 KiB

var users_account = (function ($, window, jQuery) {
var _vars_ = {};
return {
"set_vars": function (options) {
$.extend(_vars_, options || {});
},
"get_vars" : function(){
return _vars_;
},
"_add" : {
"modal" : function(){
//config
$("h4#userAccountModalTitle").text(app.get_vars().system_config.title.add_new_user);
$("button#updateUserAccountBtn").hide();
$("button#addNewUserAccountBtn").show();
app._form._addValidation_by_fields(["email_address", "password", "confirm_password"]);
$("#usersAccountModal").modal({backdrop: 'static',keyboard : false}).on('shown.bs.modal', function() {
app._form._reset(this);
$("#first_name").focus();
//submit form on keypress or enter
app._form._form_submit_on_keypress("userAccountForm", function(){
users_account._validate('add');
});
$('#usersAccountModal').off('shown.bs.modal');
}).on('hidden.bs.modal', function () {
app._form._resetFormValidation("#usersAccountModal");
app._form._reset(this);
$(this).data('bs.modal', null);
$('#usersAccountModal').off('hidden.bs.modal');
});
},
"save" : function(form){
$.ajax({
"url" : app.get_vars().baseurl+"admin/users_account/add_new_user",
"type" : "POST",
"dataType" : "json",
"data" : $(form).serializeArray(),
"success" : function(result){
if(app.isalive(result)) {
app._notify(result.mtype, result.message);
if (result.mtype == "success") {
//reload grid
$("#usersAccountModal").modal("hide");
(users_account.get_vars()._users_account).ajax.reload(null, false);
} else {
var x = 0;
$.map(result.mdetail, function (input, i) {
if (input.field == "password") {
app._form._populate_field_error("password", input.message, x);
app._form._populate_field_error("confirm_password", input.message, x);
} else {
app._form._populate_field_error(input.field, input.message, x);
}
x++;
});
}
}
}
});
}
},
"_edit" : {
"modal" : function(user){
//config
$("h4#userAccountModalTitle").text("").text(app.get_vars().system_config.title.add_new_user);
$("#usersAccountModal").data("user_id", user);
$("button#addNewUserAccountBtn").hide();
$("button#updateUserAccountBtn").show();
app._form._removeValidation_by_fields(["email_address", "password", "confirm_password"]);
$("#usersAccountModal").modal({backdrop: 'static',keyboard : true}).on('shown.bs.modal', function() {
$("#first_name").focus();
var user_info = (users_account.get_vars()._users_account).row(user).data();
app._form._repopulate_values({
data : user_info.action,
fields : ["first_name", "last_name", "email_address", "username"]
});
$('select#user_role').val(user_info.role_id);
//submit form on keypress or enter
app._form._form_submit_on_keypress("userAccountForm", function(){
users_account._validate('edit');
});
$('#usersAccountModal').off('shown.bs.modal');
}).on('hidden.bs.modal', function () {
app._form._resetFormValidation("#userAccountForm");
app._form._reset(this);
$(this).data('bs.modal', null);
$('#usersAccountModal').off('hidden.bs.modal');
});
},
"save" : function(form){
var user = $("#usersAccountModal").data("user_id");
var user_info = (users_account.get_vars()._users_account).row(user).data();
$.ajax({
"url" : app.get_vars().baseurl+"admin/users_account/edit_user_account/"+user_info.action.user_id,
"type" : "POST",
"data": $(form).serializeArray(),
"dataType" : 'json',
"success" : function(result){
//reset validation
//app._form._resetFormValidation("userAccountForm");
if(app.isalive(result)) {
app._notify(result.mtype, result.message);
if (result.mtype == "success") {
//reload grid
$("#usersAccountModal").modal("hide");
(users_account.get_vars()._users_account).ajax.reload(null, false);
} else {
var x = 0;
$.map(result.mdetail, function (input, i) {
if (input.field == "password") {
app._form._populate_field_error("password", input.message, x);
app._form._populate_field_error("confirm_password", input.message, x);
} else {
app._form._populate_field_error(input.field, input.message, x);
}
x++;
});
}
}
}
});
}
},
"_delete" : {
"confirm" : function(user_id, order){
app.modal.confirm_box({
"message" : app.get_vars().system_config.cma_msg.delete_account+" <b>[#"+order+"]</b>?<br/><br><span class='label label-danger' style='font-size: 12px;'>"+app.get_vars()._app.cma_msg.note+"</span>",
"_continue" : function() {
users_account._delete.save(user_id);
},
"id" : "delete_confirm_box",
"className" : "delete_confirm_box"
});
},
"save" : function(user_id){
$.ajax({
url : app.get_vars().baseurl+"admin/users_account/delete_user_account/"+user_id,
type : "POST",
data : {
ask : "xdLe80"
},
dataType : 'json',
success : function(result){
if(app.isalive(result)) {
app._notify(result.mtype, result.message);
if (result.mtype == "success") {
//reload grid
(users_account.get_vars()._users_account).ajax.reload(null, false);
}
}
}
});
}
},
"_deactive_activate" : {
"confirm" : function(user_id, action, order){
app.modal.confirm_box({
"message" : ((action == 1)?app.get_vars().system_config.cma_msg.deactivate_account:app.get_vars().system_config.cma_msg.activate_account) +" <b>[#"+order+"]</b> ?",
"_continue" : function() {
users_account._deactive_activate.save(user_id, action);
},
"id" : "deactivate_confirm_box",
"className" : "deactivate_confirm_box"
});
},
"save" : function(user_id, action){
$.ajax({
url : app.get_vars().baseurl+"admin/users_account/deactivate_activate_user_account/"+user_id+"/"+action,
type : "POST",
data : {
ask : "xdLe80sa"
},
dataType : "json",
success : function(result){
if(app.isalive(result)) {
app._notify(result.mtype, result.message);
if (result.mtype == "success") {
//reload grid
(users_account.get_vars()._users_account).ajax.reload(null, false);
}
}
}
});
}
},
"_validate" : function(action){
var new_pwd = $("#password").val().trim();
var confirm_pass_length = $("#confirm_password").val().trim().length;
var confirm_new_pwd = $("#confirm_password").val().trim();
var msg = (confirm_pass_length === 0 ? "Ce champ est obligatoire." : app.get_vars()._app.account.pwd_did_not_match )
var options = {
"boot_box" : {
"message" : (action == "add")
? app.get_vars().system_config.cma_msg.add_new_user
: app.get_vars()._app.cma_msg.save_changes
,
"_continue" : function() {
(action == "add")
? users_account._add.save($("form#userAccountForm"))
:
users_account._edit.save($("form#userAccountForm"))
},
"id" : action+"_confirm_box",
"className" : action+"_confirm_box"
},
"validation" : {
"form_id" : "form#userAccountForm",
"custom" : {
"rules": {
"check_confirm_pwd": {
"_fnc": function (value, element, options) {
if( confirm_pass_length !== 0 ) {
if(new_pwd === confirm_new_pwd && new_pwd.length > 0){
return true;
} else {
return false;
}
} else if(new_pwd != ""){
return false;
}
return true;
},
msg: msg
},
"check_pwd": {
"_fnc": function (value, element, options) {
if(value.trim() != "") {
return true;
} else{
return true;
}
},
msg: app.get_vars()._app.account.pwd_did_not_match
},
}
},
"rules" : {
"first_name": {
minlength:3,
required: true
},
"email_address" : {
required : false,
email : true
},
"last_name" : {
minlength : 3,
required : true
},
"confirm_password": {
check_confirm_pwd : true
},
"password": {
check_pwd : true
},
"user_role": {
required : true
}
}
}
};
app._form._validate(options);
},
"_load" : function(){
var table = $('#user_account_list').DataTable({
"autoWidth": false,
"responsive": true,
"processing": true, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"order": [0], //Initial no order.
"oLanguage": fr_onload_lang.oLanguage,
// Load data for the table's content from an Ajax source
"ajax": {
"url": app.get_vars().baseurl+"user_account_list",
"type": "POST"
},
"columns": [
{ "data": "employee_order"},
{ "data": "employee"},
{ "data": "email_address"},
{ "data": "username"},
{ "data": "role"},
{ "data": "status", render : function(data, type, full, meta){
return "<a href='#' style='cursor: pointer;' class='custom-popover-tooltip' data-toggle='tooltip'" +
"onclick='users_account._deactive_activate.confirm(" + full.action.user_id +", " +full.action.status+ ", "+full.employee_order+");'"+
"title='" +((full.action.status == 1)? app.get_vars().system_config.action.click_to_deactivate : app.get_vars().system_config.action.click_to_activate) + "'>"+
full.status
+"</a>";
}},
{ "data": "action" , render : function(data, type, full, meta){
var action_btns = "";
if (authorize(PAGE_CODE['sys_settings'], PRIVS[PAGE_CODE['sys_settings']]['user_mgt_edit'])) {
action_btns +=app.grid.create_action_btn(app.get_vars().system_config.action.click_to_edit, "pencil", "success", "users_account._edit.modal("+meta.row+")");
}
if (authorize(PAGE_CODE['sys_settings'], PRIVS[PAGE_CODE['sys_settings']]['user_mgt_delete'])) {
action_btns +=app.grid.create_action_btn(app.get_vars().system_config.action.click_to_delete, "trash", "danger", "users_account._delete.confirm("+full.action.user_id+", "+full.employee_order+")");
}
return '<div class="row-fluid"><div class="span4 offset4 text-center">'+action_btns+'</div></div>';
}}
],
"fnDrawCallback": function() {
app._tooltip._hide();
$('#user_account_list tbody tr td').each( function(x, y) {
var _this = $(this);
if(_this.hasClass('truncate-content-text')){
_this.css('max-width', '180px');
this.setAttribute( 'title', _this.text());
this.setAttribute( 'data-toggle',"tooltip");
}
});
app._tooltip._pop();
},
//Set column definition initialisation properties.
"columnDefs": [
{ "targets": [0], "orderable": false},
{ "targets": [-1], "orderable": false},
{ "targets": [1], className : "truncate-content-text custom-popover-tooltip"}
],
"initComplete": function(settings, json) {
//run tooltip
app._tooltip._hide();
app._tooltip._pop();
//add custom button beside searchbox
$('.dataTables_filter').each(function () {
if (authorize(PAGE_CODE['sys_settings'], PRIVS[PAGE_CODE['sys_settings']]['user_mgt_add'])) {
$(this).append('<button onclick="users_account._add.modal()" ' +
'class="btn btn-primary btn-sm mr-xs subscribe" type="button" style="padding: 7px;">' +
'<span class="glyphicon glyphicon-plus"></span> '+app.get_vars().system_config.btn.add_new_user+'</button>');
}
});
//fire search filter event
app.grid.search_filter("user_account_list", users_account.get_vars()._users_account);
}
});
users_account.set_vars({_users_account : table});
}
};//end of return
// Pass in jQuery.
})(jQuery, this);
$(function() {
//load datatable
users_account._load();
});