348 lines
11 KiB
JavaScript
348 lines
11 KiB
JavaScript
var elements = {
|
|
handle: "users",
|
|
model: "user",
|
|
route: "Stack.Admin.User",
|
|
route_api: "Stack.Admin.API.User",
|
|
table_selector: "#users_datatable",
|
|
exist: "the_user_type_already_exists",
|
|
added: "user_has_been_added",
|
|
modified: "user_has_been_modified",
|
|
deleted: "user_has_been_deleted"
|
|
};
|
|
|
|
var columnsdef = [
|
|
{ orderable: false, targets: [0, 6] },
|
|
{ responsivePriority: 1, targets: [0, 1, 6] }
|
|
];
|
|
|
|
var columns = [
|
|
{
|
|
data: "active",
|
|
searchable: false,
|
|
className: 'text-center',
|
|
render: function ( data, type, row, meta ) {
|
|
var checked = data ? "checked" : "";
|
|
tpl = '<div class="text-center"><input type="checkbox"' + checked + ' data-id="' + row.id + '" class="active-checkbox" data-size="mini" data-width="50" data-height="25" data-onstyle="success" data-offstyle="danger"></div>';
|
|
return tpl;
|
|
}
|
|
},
|
|
{
|
|
data: "name",
|
|
render: function ( data, type, row, meta ) {
|
|
return '<button type="button" class="btn btn-round btn-border btn-info btn-xs avatar-user-btn" title="'+translate.getText.avatar+'"><i class="glyph-icon icon-elusive-camera"></i></button> ' + data;
|
|
}
|
|
},
|
|
{ data: "username" },
|
|
{ data: "email" },
|
|
{ data: "phone" },
|
|
{
|
|
data: "roles",
|
|
searchable: false,
|
|
render: function ( data, type, row, meta ) {
|
|
if (data) {
|
|
tpl = '';
|
|
for (var k in data){
|
|
if (data.hasOwnProperty(k)) {
|
|
tpl += data[k]['name'] + ' ';
|
|
}
|
|
}
|
|
return tpl;
|
|
} else {
|
|
return '';
|
|
}
|
|
}
|
|
},
|
|
{
|
|
data: "id",
|
|
render: function ( data, type, row ) {
|
|
var name = row.name;
|
|
tpl = '<div class="text-center" data-id="' + data + '" data-name="' + name + '">';
|
|
tpl += '<button class="btn btn-border btn-gray btn-xs password-btn margin-right-10" title="'+translate.getText.change_password+'"><i class="glyph-icon fa fa-key"></i></button>';
|
|
if (hasPermission('users_client')) {
|
|
tpl += '<button class="btn btn-border btn-default border-default btn-xs manage-btn margin-right-10" title="'+translate.getText.manage+'"><i class="glyph-icon icon-file-text-o"></i></button>';
|
|
}
|
|
if (hasPermission('users_update')) {
|
|
tpl += '<button class="btn btn-border btn-yellow btn-xs update-btn margin-right-10" title="'+translate.getText.modify+'"><i class="glyph-icon icon-typicons-pencil"></i></button>';
|
|
}
|
|
if (hasPermission('users_delete')) {
|
|
tpl += '<button class="btn btn-border btn-danger btn-xs delete-btn margin-right-10" title="'+translate.getText.delete+'"><i class="glyph-icon fa fa-trash"></i></button>';
|
|
}
|
|
tpl += '</div>';
|
|
return tpl;
|
|
}
|
|
}
|
|
];
|
|
|
|
var users = handleAdmin;
|
|
|
|
var users_addon = {
|
|
avatar: null,
|
|
upload_avatar: false,
|
|
upload_input: null,
|
|
passwordButtonsClick: function() {
|
|
$('.password-btn').off('click').on('click', function() {
|
|
var id = $(this).parent().data('id');
|
|
var name = $(this).parent().data('name');
|
|
users.passwordUser(id, name);
|
|
});
|
|
},
|
|
avatarButtonsClick: function() {
|
|
$('#users_datatable .avatar-user-btn').off('click').on('click', function() {
|
|
var id = $(this).parent().data('id');
|
|
var name = $(this).parent().data('name');
|
|
users.avatarUser(id, name);
|
|
});
|
|
},
|
|
generatePassword: function(elt) {
|
|
$.ajax({
|
|
type: "POST",
|
|
dataType: "json",
|
|
url: laroute.route("Stack.Admin.API.User.generateUserPassword"),
|
|
success: function(response) {
|
|
elt.val(response.pwd);
|
|
},
|
|
error: function() {
|
|
admin_content.alertError();
|
|
}
|
|
});
|
|
},
|
|
initAvatarUploader: function() {
|
|
users.upload_input = $("#avatar_file").filer({
|
|
showThumbs: true,
|
|
addMore: true,
|
|
allowDuplicates: false,
|
|
limit: 1,
|
|
maxSize: 5,
|
|
extensions: [ 'jpg' ],
|
|
uploadFile: {
|
|
url: laroute.route("Stack.Admin.API.User.uploadAvatar"),
|
|
data: { "extension": 'jpg' },
|
|
type: 'POST',
|
|
enctype: 'multipart/form-data',
|
|
synchron: true,
|
|
success: function(data, itemEl, listEl, boxEl, newInputEl, inputEl, id){
|
|
var parent = itemEl.find(".jFiler-jProgressBar").parent(),
|
|
new_file_name = JSON.parse(data),
|
|
filerKit = inputEl.prop("jFiler");
|
|
|
|
filerKit.files_list[id].name = new_file_name;
|
|
|
|
itemEl.find(".jFiler-jProgressBar").fadeOut("slow", function(){
|
|
$("<div class=\"jFiler-item-others text-success\"><i class=\"icon-jfi-check-circle\"></i> Success</div>").hide().appendTo(parent).fadeIn("slow");
|
|
});
|
|
|
|
$("#avatar_file_hidden").val(new_file_name);
|
|
},
|
|
error: function(el){
|
|
var parent = el.find(".jFiler-jProgressBar").parent();
|
|
el.find(".jFiler-jProgressBar").fadeOut("slow", function(){
|
|
$("<div class=\"jFiler-item-others text-error\"><i class=\"icon-jfi-minus-circle\"></i> Error</div>").hide().appendTo(parent).fadeIn("slow");
|
|
});
|
|
},
|
|
statusCode: null,
|
|
onProgress: null,
|
|
onComplete: null
|
|
},
|
|
files: null,
|
|
clipBoardPaste: true,
|
|
excludeName: null,
|
|
beforeRender: null,
|
|
afterRender: null,
|
|
beforeShow: null,
|
|
beforeSelect: null,
|
|
onSelect: null,
|
|
afterShow: null,
|
|
onRemove: function(itemEl, file, id, listEl, boxEl, newInputEl, inputEl){
|
|
var filerKit = inputEl.prop("jFiler"),
|
|
file_name = filerKit.files_list[id].name;
|
|
|
|
$.post(laroute.route('Stack.Admin.API.User.removeAvatar'), {file: file_name});
|
|
},
|
|
onEmpty: null,
|
|
options: null,
|
|
dialogs: {
|
|
alert: function(text) {
|
|
$.alert({
|
|
title: translate.getText.informations,
|
|
type: 'red',
|
|
content: text,
|
|
});
|
|
},
|
|
confirm: function (text, callback) {
|
|
$.confirm({
|
|
title: translate.getText.informations,
|
|
type: 'red',
|
|
content: text,
|
|
buttons: {
|
|
confirm: {
|
|
text: translate.getText.confirm,
|
|
btnClass: 'btn-danger',
|
|
action: function(){
|
|
callback()
|
|
}
|
|
},
|
|
cancel: {
|
|
text: translate.getText.cancel
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
captions: {
|
|
button: translate.getText.choose_file,
|
|
feedback: "",
|
|
feedback2: translate.getText.selected_files,
|
|
removeConfirmation: translate.getText.are_you_sure_you_want_to_remove_this_file,
|
|
errors: {
|
|
filesLimit: translate.getText.file_number_authorized + ": {{fi-limit}}",
|
|
filesType: translate.getText.file_extension_authorized + ": .{{fi-extensions}}",
|
|
filesSize: translate.getText.file_max_size_authorized + ": {{fi-maxSize}} MB."
|
|
}
|
|
}
|
|
});
|
|
},
|
|
avatarUser: function(id, name) {
|
|
$.confirm({
|
|
title: translate.getText.avatar,
|
|
columnClass: 'small',
|
|
content: function () {
|
|
var self = this;
|
|
return $.ajax({
|
|
type: "POST",
|
|
dataType: "json",
|
|
url: laroute.route("Stack.Admin.API.User.getAvatar"),
|
|
data: { 'id': id },
|
|
}).done(function (response) {
|
|
|
|
if (response.error == -1) {
|
|
header.logout();
|
|
} else if (response.avatar == "") {
|
|
self.setContent('<div><i class="glyph-icon fa fa-caret-right margin-left-15 margin-right-5"></i><i class="text-blue">'+name+'</i></div><hr class="margin-top-10 margin-bottom-10"><div class="text-center padding-top-10" id="avatar_upload"><input type="file" name="files[]" id="avatar_file" /><input type="hidden" id="avatar_file_hidden" name="avatar_file" value="NULL" class="form-control" /></div>');
|
|
users.upload_avatar = true;
|
|
} else {
|
|
self.setContent('<div><i class="glyph-icon fa fa-caret-right margin-left-15 margin-right-5"></i><i class="text-blue">'+name+'</i></div><hr class="margin-top-10 margin-bottom-10"><div class="text-center padding-top-10" id="avatar_upload"><img src="'+response.avatar+'" /><br><button type="button" id="delete_avatar" class="btn btn-danger margin-top-10">'+translate.getText.delete+'</button></div>');
|
|
users.upload_avatar = false;
|
|
}
|
|
|
|
}).fail(function(){
|
|
self.setContent(translate.getText.an_error_occured);
|
|
});
|
|
},
|
|
typeAnimated: true,
|
|
onContentReady: function() {
|
|
$("#delete_avatar").off('click').on('click', function(){
|
|
$("#avatar_upload").html('<input type="file" name="files[]" id="avatar_file" /><input type="hidden" id="avatar_file_hidden" name="avatar_file" class="form-control" />');
|
|
users.upload_avatar = true;
|
|
users.initAvatarUploader();
|
|
});
|
|
|
|
if (users.upload_avatar) {
|
|
users.initAvatarUploader();
|
|
}
|
|
},
|
|
type: 'blue',
|
|
buttons: {
|
|
confirm: {
|
|
text: translate.getText.validate,
|
|
btnClass: 'btn-blue',
|
|
action: function(){
|
|
if($('#novation_select').val() == '') {
|
|
admin_content.alertCustomError('please_select_third_party');
|
|
} else {
|
|
var datas = {};
|
|
datas['ujcaid'] = id;
|
|
datas["ujcafile"] = $('#avatar_file_hidden').val();
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
dataType: "json",
|
|
url: laroute.route("Stack.Admin.API.User.updateAvatar"),
|
|
data: datas,
|
|
success: function(response) {
|
|
if (response.error == -1) {
|
|
header.logout();
|
|
} else if(response.error == -6) {
|
|
admin_content.alertNotFound();
|
|
}
|
|
},
|
|
error: function() {
|
|
admin_content.alertError();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
},
|
|
cancel: {
|
|
text: translate.getText.cancel
|
|
}
|
|
}
|
|
});
|
|
},
|
|
passwordUser: function(id, name) {
|
|
|
|
$.confirm({
|
|
title: translate.getText.change_password,
|
|
columnClass: 'small',
|
|
content: '<div class="margin-top-3"><i class="glyph-icon fa-caret-right margin-left-10 margin-right-5"></i><i class="">'+name+'</i><div><div class="input-group"><input type="text" name="password" id="update_password" maxlength="32" class="form-control"><span class="input-group-addon pointer" id="user_password_regenerate"><i class="glyph-icon fa fa-lock"></i></span></div></div></div>',
|
|
typeAnimated: true,
|
|
type: 'dark',
|
|
animation: 'RotateXR',
|
|
onContentReady: function() {
|
|
$("#user_password_regenerate").off('click').on('click', function(){
|
|
event.preventDefault();
|
|
users.generatePassword($("#update_password"));
|
|
});
|
|
},
|
|
buttons: {
|
|
confirm: {
|
|
text: translate.getText.confirm,
|
|
btnClass: 'btn-dark',
|
|
action: function() {
|
|
if ($("#update_password").val() == "") {
|
|
return false;
|
|
} else {
|
|
var datas = {};
|
|
datas['id'] = id;
|
|
datas['password'] = $("#update_password").val();
|
|
|
|
$.ajax({
|
|
type: "POST",
|
|
dataType: "json",
|
|
url: laroute.route("Stack.Admin.API.User.updatePassword"),
|
|
data: datas,
|
|
success: function(response) {
|
|
if (response.error == -1) {
|
|
header.logout();
|
|
} else if(response.error == -6) {
|
|
admin_content.alertNotFound();
|
|
} else if(response.error == -7) {
|
|
admin_content.alertCustomError('the_password_must_have_at_least_six_characters');
|
|
}
|
|
},
|
|
error: function() {
|
|
admin_content.alertError();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
},
|
|
cancel: {
|
|
text: translate.getText.cancel
|
|
}
|
|
}
|
|
});
|
|
},
|
|
};
|
|
|
|
users = {...users, ...users_addon };
|
|
|
|
$(document).ready(function() {
|
|
users.selectAll();
|
|
$(elements.table_selector).on('draw.dt', function () {
|
|
handleTable();
|
|
initIcheck();
|
|
users.passwordButtonsClick();
|
|
users.avatarButtonsClick();
|
|
} );
|
|
} );
|