938 lines
33 KiB
JavaScript
938 lines
33 KiB
JavaScript
var usersTableAdd;
|
|
var usersTableEdit;
|
|
var userGroupsTable;
|
|
var activityTable;
|
|
var usersByUserGroupTable;
|
|
|
|
var datepickerFilter = {};
|
|
var queryParemsFilter = [];
|
|
|
|
$(document).bind('click', function (e) {
|
|
const clicked = $(e.target);
|
|
if (clicked.parents('.toolbox').length != 0) return false;
|
|
if (clicked.parents('.datepicker-grid-view').length != 0) return false;
|
|
if (clicked.parents('.datepicker-navigator').length != 0) return false;
|
|
if (clicked.parents('.datepicker-container').length != 0) return false;
|
|
if (clicked.parents('.select2-selection__choice').length != 0) return false;
|
|
if (clicked.closest('.btn-table-filter').length == 0 && clicked.closest(".parent-filter").length == 0 && $(".parent-filter").css("display") != "none") {
|
|
$(".parent-filter").css("display", "none");
|
|
}
|
|
if (clicked.closest('.btn-table-excel').length == 0 && clicked.closest(".parent-excel").length == 0 && $(".parent-excel").css("display") != "none") {
|
|
$(".parent-excel").css("display", "none");
|
|
}
|
|
if (clicked.closest('.btn-table-word').length == 0 && clicked.closest(".parent-word").length == 0 && $(".parent-word").css("display") != "none") {
|
|
$(".parent-word").css("display", "none");
|
|
}
|
|
});
|
|
|
|
(function () {
|
|
datepickerFilter.from = $("#datapicker-from-table").persianDatepicker({
|
|
format: "YYYY/MM/DD",
|
|
autoClose: true,
|
|
onSelect: function (unix) {
|
|
datepickerFilter.from.touched = true;
|
|
|
|
$("#datapicker-to-table").prop("disabled", "");
|
|
|
|
if (
|
|
datepickerFilter.from.getState().selected.unixDate >=
|
|
datepickerFilter.to.getState().selected.unixDate
|
|
) {
|
|
datepickerFilter.to.setDate(datepickerFilter.from.getState().selected.unixDate);
|
|
}
|
|
|
|
if (datepickerFilter.to && datepickerFilter.to.options && datepickerFilter.to.options.minDate != unix) {
|
|
let cachedValue = datepickerFilter.to.getState().selected.unixDate;
|
|
|
|
datepickerFilter.to.options = { minDate: unix };
|
|
|
|
if (datepickerFilter.from.touched) {
|
|
datepickerFilter.to.setDate(cachedValue);
|
|
}
|
|
}
|
|
},
|
|
});
|
|
|
|
datepickerFilter.to = $("#datapicker-to-table").persianDatepicker({
|
|
format: "YYYY/MM/DD",
|
|
autoClose: true,
|
|
onSelect: function (unix) {
|
|
datepickerFilter.to.touched = true;
|
|
},
|
|
});
|
|
|
|
usersByUserGroupTable = $("#table_users_by_user_group").DataTable({
|
|
dom: "<fB<t>p>",
|
|
pagingType: "simple_numbers",
|
|
paging: true,
|
|
destroy: true,
|
|
responsive: true,
|
|
async: false,
|
|
language: {
|
|
sEmptyTable: "هیچ دادهای در جدول وجود ندارد",
|
|
sInfo: "نمایش _START_ تا _END_ از _TOTAL_ ردیف",
|
|
sInfoEmpty: "نمایش 0 تا 0 از 0 ردیف",
|
|
sInfoFiltered: "(فیلتر شده از _MAX_ ردیف)",
|
|
sInfoPostFix: "",
|
|
sInfoThousands: ",",
|
|
sLengthMenu: "نمایش _MENU_ ردیف",
|
|
sLoadingRecords: "در حال بارگذاری...",
|
|
sProcessing: "در حال پردازش...",
|
|
sSearch: "جستجو: ",
|
|
sZeroRecords: "رکوردی با این مشخصات پیدا نشد",
|
|
oPaginate: {
|
|
sFirst: "برگهی نخست",
|
|
sLast: "برگهی آخر",
|
|
sNext: "بعدی",
|
|
sPrevious: "قبلی",
|
|
},
|
|
oAria: {
|
|
sSortAscending: ": فعال سازی نمایش به صورت صعودی",
|
|
sSortDescending: ": فعال سازی نمایش به صورت نزولی",
|
|
},
|
|
},
|
|
order: [
|
|
[0, "desc"]
|
|
],
|
|
processing: true,
|
|
data: [],
|
|
columns: [{
|
|
className: "text-center",
|
|
data: null,
|
|
render: function (data, type, row, meta) {
|
|
return meta.row + 1;
|
|
},
|
|
},
|
|
{
|
|
data: 'username',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
data: 'first_name',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
data: 'last_name',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
data: 'province_fa',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
],
|
|
buttons: [],
|
|
});
|
|
|
|
userGroupsTable = $("#table_user_groups").DataTable({
|
|
dom: "<fB<t>p>",
|
|
pagingType: "simple_numbers",
|
|
paging: true,
|
|
destroy: true,
|
|
responsive: true,
|
|
async: false,
|
|
language: {
|
|
sEmptyTable: "هیچ دادهای در جدول وجود ندارد",
|
|
sInfo: "نمایش _START_ تا _END_ از _TOTAL_ ردیف",
|
|
sInfoEmpty: "نمایش 0 تا 0 از 0 ردیف",
|
|
sInfoFiltered: "(فیلتر شده از _MAX_ ردیف)",
|
|
sInfoPostFix: "",
|
|
sInfoThousands: ",",
|
|
sLengthMenu: "نمایش _MENU_ ردیف",
|
|
sLoadingRecords: "در حال بارگذاری...",
|
|
sProcessing: "در حال پردازش...",
|
|
sSearch: "جستجو: ",
|
|
sZeroRecords: "رکوردی با این مشخصات پیدا نشد",
|
|
oPaginate: {
|
|
sFirst: "برگهی نخست",
|
|
sLast: "برگهی آخر",
|
|
sNext: "بعدی",
|
|
sPrevious: "قبلی",
|
|
},
|
|
oAria: {
|
|
sSortAscending: ": فعال سازی نمایش به صورت صعودی",
|
|
sSortDescending: ": فعال سازی نمایش به صورت نزولی",
|
|
},
|
|
},
|
|
order: [
|
|
[0, "desc"]
|
|
],
|
|
processing: true,
|
|
ajax: {
|
|
url: `https://rms.rmto.ir/user-activity-report-index`,
|
|
type: "GET",
|
|
beforeSend: function () {
|
|
showLoaderScreen();
|
|
},
|
|
dataSrc: function (json) {
|
|
hideLoaderScreen();
|
|
return json.data;
|
|
},
|
|
error: function () {
|
|
hideLoaderScreen();
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "خطا",
|
|
text: "مشکل در دریافت گروه کاربران",
|
|
confirmButtonText: "بروزرسانی صفحه",
|
|
showLoaderOnConfirm: true,
|
|
preConfirm: () => {
|
|
location.reload(true);
|
|
},
|
|
});
|
|
}
|
|
},
|
|
columns: [{
|
|
className: "text-center",
|
|
data: null,
|
|
render: function (data, type, row, meta) {
|
|
return meta.row + 1;
|
|
},
|
|
},
|
|
{
|
|
data: 'group_name',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
className: "text-center",
|
|
data: null,
|
|
render: function (data) {
|
|
return data.activity_time != null ? `${data.activity_time}` : `0`
|
|
}
|
|
},
|
|
{
|
|
data: 'user_count',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
data: 'average',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
className: "text-center",
|
|
data: null,
|
|
render: function (data) {
|
|
if (data.is_static == 1) {
|
|
let content = `<div class="d-flex justify-content-center">`
|
|
content += `<button title="چاپ" class="btn-dataTable btn-pdf-country-chart"><i class="fa fa-print"></i></button>`
|
|
content += `</div>`
|
|
return content
|
|
} else if(data.is_static == 2){
|
|
let content = `<div class="d-flex justify-content-center">`
|
|
content += `<button title="چاپ" class="btn-dataTable btn-pdf-organization-chart"><i class="fa fa-print"></i></button>`
|
|
content += `</div>`
|
|
return content
|
|
}
|
|
else {
|
|
let content = `<div class="d-flex justify-content-center">`
|
|
content += `<button title="خروجی اکسل" class="btn-dataTable btn-excel-user-group"><i class="fa fa-file-excel"></i></button>`
|
|
content += `<button title="چاپ" class="btn-dataTable btn-pdf-user-group"><i class="fa fa-print"></i></button>`
|
|
content += `<button title="ویرایش" class="btn-dataTable btn-edit-user-group"><i class="fa fa-edit"></i></button>`
|
|
content += `<button title="لیست کاربران" class="btn-dataTable btn-show-user-group"><i class="fa fa-list"></i></button>`
|
|
content += `<button title="حذف" class="btn-dataTable btn-delete-user-group"><i class="fa fa-trash"></i></button>`
|
|
content += `</div>`
|
|
return content
|
|
}
|
|
}
|
|
},
|
|
],
|
|
buttons: [
|
|
{
|
|
text: '<div class="btn-send-activity"><div class="d-flex flex-column"><i class="fa mb-2 fa-user icon-color"></i>مدیریت کاربران</div></div>',
|
|
action: function (e, dt, node, config) {
|
|
window.location = 'https://rms.rmto.ir/karbarlist'
|
|
},
|
|
},
|
|
{
|
|
text: '<div class="btn-table-filter"><div class="d-flex flex-column"><i class="fa mb-2 fa-filter icon-color"></i> فیلترینگ</div></div>',
|
|
action: function (e, dt, node, config) {
|
|
$(".parent-filter").css("display", "block");
|
|
},
|
|
},
|
|
],
|
|
});
|
|
|
|
// userGroupsTable.row.add([48,4,2,2,2,"Sdfsdfsdf"]).draw(false);
|
|
|
|
activityTable = $("#table_activity").DataTable({
|
|
dom: "<fB<t>p>",
|
|
pagingType: "simple_numbers",
|
|
paging: true,
|
|
destroy: true,
|
|
responsive: true,
|
|
async: false,
|
|
language: {
|
|
sEmptyTable: "هیچ دادهای در جدول وجود ندارد",
|
|
sInfo: "نمایش _START_ تا _END_ از _TOTAL_ ردیف",
|
|
sInfoEmpty: "نمایش 0 تا 0 از 0 ردیف",
|
|
sInfoFiltered: "(فیلتر شده از _MAX_ ردیف)",
|
|
sInfoPostFix: "",
|
|
sInfoThousands: ",",
|
|
sLengthMenu: "نمایش _MENU_ ردیف",
|
|
sLoadingRecords: "در حال بارگذاری...",
|
|
sProcessing: "در حال پردازش...",
|
|
sSearch: "جستجو: ",
|
|
sZeroRecords: "رکوردی با این مشخصات پیدا نشد",
|
|
oPaginate: {
|
|
sFirst: "برگهی نخست",
|
|
sLast: "برگهی آخر",
|
|
sNext: "بعدی",
|
|
sPrevious: "قبلی",
|
|
},
|
|
oAria: {
|
|
sSortAscending: ": فعال سازی نمایش به صورت صعودی",
|
|
sSortDescending: ": فعال سازی نمایش به صورت نزولی",
|
|
},
|
|
},
|
|
order: [
|
|
[0, "desc"]
|
|
],
|
|
processing: true,
|
|
ajax: {
|
|
url: "https://rms.rmto.ir/user-activity-report/log-list",
|
|
type: "GET",
|
|
beforeSend: function () {
|
|
showLoaderScreen();
|
|
},
|
|
dataSrc: function (json) {
|
|
hideLoaderScreen();
|
|
return json.data;
|
|
},
|
|
error: function () {
|
|
hideLoaderScreen();
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "خطا",
|
|
text: "مشکل در دریافت گروه کاربران",
|
|
confirmButtonText: "بروزرسانی صفحه",
|
|
showLoaderOnConfirm: true,
|
|
preConfirm: () => {
|
|
location.reload(true);
|
|
},
|
|
});
|
|
}
|
|
},
|
|
columns: [
|
|
{
|
|
data: 'log_unique_code',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
data: 'description',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
],
|
|
buttons: [],
|
|
});
|
|
|
|
usersTableAdd = $("#table_users_add").DataTable({
|
|
dom: "<fB<t>p>",
|
|
pagingType: "simple_numbers",
|
|
paging: true,
|
|
destroy: true,
|
|
responsive: true,
|
|
async: false,
|
|
language: {
|
|
sEmptyTable: "هیچ دادهای در جدول وجود ندارد",
|
|
sInfo: "نمایش _START_ تا _END_ از _TOTAL_ ردیف",
|
|
sInfoEmpty: "نمایش 0 تا 0 از 0 ردیف",
|
|
sInfoFiltered: "(فیلتر شده از _MAX_ ردیف)",
|
|
sInfoPostFix: "",
|
|
sInfoThousands: ",",
|
|
sLengthMenu: "نمایش _MENU_ ردیف",
|
|
sLoadingRecords: "در حال بارگذاری...",
|
|
sProcessing: "در حال پردازش...",
|
|
sSearch: "جستجو: ",
|
|
sZeroRecords: "رکوردی با این مشخصات پیدا نشد",
|
|
oPaginate: {
|
|
sFirst: "برگهی نخست",
|
|
sLast: "برگهی آخر",
|
|
sNext: "بعدی",
|
|
sPrevious: "قبلی",
|
|
},
|
|
oAria: {
|
|
sSortAscending: ": فعال سازی نمایش به صورت صعودی",
|
|
sSortDescending: ": فعال سازی نمایش به صورت نزولی",
|
|
},
|
|
},
|
|
order: [
|
|
[0, "desc"]
|
|
],
|
|
processing: true,
|
|
ajax: {
|
|
url: "https://rms.rmto.ir/webapi/users",
|
|
type: "GET",
|
|
beforeSend: function () {
|
|
showLoaderScreen();
|
|
},
|
|
dataSrc: function (json) {
|
|
hideLoaderScreen();
|
|
return json.data;
|
|
},
|
|
error: function () {
|
|
hideLoaderScreen();
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "خطا",
|
|
text: "مشکل در دریافت کاربران",
|
|
confirmButtonText: "بروزرسانی صفحه",
|
|
showLoaderOnConfirm: true,
|
|
preConfirm: () => {
|
|
location.reload(true);
|
|
},
|
|
});
|
|
}
|
|
},
|
|
columns: [{
|
|
className: "text-center",
|
|
data: null,
|
|
render: function (data, type, row, meta) {
|
|
return meta.row + 1;
|
|
},
|
|
},
|
|
{
|
|
data: 'username',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
data: 'first_name',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
data: 'last_name',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
data: 'province_fa',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
className: "text-center",
|
|
data: null,
|
|
render: function (data) {
|
|
return `<div class="form-check"><input type="checkbox" class="form-check-input check-users" value="${data.id}"></div>`
|
|
}
|
|
},
|
|
],
|
|
buttons: [],
|
|
});
|
|
|
|
usersTableEdit = $("#table_users_edit").DataTable({
|
|
dom: "<fB<t>p>",
|
|
pagingType: "simple_numbers",
|
|
paging: true,
|
|
destroy: true,
|
|
responsive: true,
|
|
async: false,
|
|
language: {
|
|
sEmptyTable: "هیچ دادهای در جدول وجود ندارد",
|
|
sInfo: "نمایش _START_ تا _END_ از _TOTAL_ ردیف",
|
|
sInfoEmpty: "نمایش 0 تا 0 از 0 ردیف",
|
|
sInfoFiltered: "(فیلتر شده از _MAX_ ردیف)",
|
|
sInfoPostFix: "",
|
|
sInfoThousands: ",",
|
|
sLengthMenu: "نمایش _MENU_ ردیف",
|
|
sLoadingRecords: "در حال بارگذاری...",
|
|
sProcessing: "در حال پردازش...",
|
|
sSearch: "جستجو: ",
|
|
sZeroRecords: "رکوردی با این مشخصات پیدا نشد",
|
|
oPaginate: {
|
|
sFirst: "برگهی نخست",
|
|
sLast: "برگهی آخر",
|
|
sNext: "بعدی",
|
|
sPrevious: "قبلی",
|
|
},
|
|
oAria: {
|
|
sSortAscending: ": فعال سازی نمایش به صورت صعودی",
|
|
sSortDescending: ": فعال سازی نمایش به صورت نزولی",
|
|
},
|
|
},
|
|
order: [
|
|
[0, "desc"]
|
|
],
|
|
processing: true,
|
|
ajax: {
|
|
url: "https://rms.rmto.ir/webapi/users",
|
|
type: "GET",
|
|
beforeSend: function () {
|
|
showLoaderScreen();
|
|
},
|
|
dataSrc: function (json) {
|
|
hideLoaderScreen();
|
|
return json.data;
|
|
},
|
|
error: function () {
|
|
hideLoaderScreen();
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "خطا",
|
|
text: "مشکل در دریافت کاربران",
|
|
confirmButtonText: "بروزرسانی صفحه",
|
|
showLoaderOnConfirm: true,
|
|
preConfirm: () => {
|
|
location.reload(true);
|
|
},
|
|
});
|
|
}
|
|
},
|
|
columns: [{
|
|
className: "text-center",
|
|
data: null,
|
|
render: function (data, type, row, meta) {
|
|
return meta.row + 1;
|
|
},
|
|
},
|
|
{
|
|
data: 'username',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
data: 'first_name',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
data: 'last_name',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
data: 'province_fa',
|
|
className: 'text-center text-nowrap'
|
|
},
|
|
{
|
|
className: "text-center",
|
|
data: null,
|
|
render: function (data) {
|
|
return `<div class="form-check"><input type="checkbox" class="form-check-input check-users" value="${data.id}"></div>`
|
|
}
|
|
},
|
|
],
|
|
buttons: [],
|
|
});
|
|
})()
|
|
|
|
function showLoaderScreen() {
|
|
$(".divloader").css("display", "flex").hide().fadeIn();
|
|
}
|
|
|
|
function hideLoaderScreen() {
|
|
$(".divloader").fadeOut();
|
|
}
|
|
|
|
$('#btn_filter').on('click', function () {
|
|
let queryParems = []
|
|
var currentFilterQueryto = ""
|
|
var currentFilterQueryfrom = ""
|
|
var currentDate = {};
|
|
|
|
if (datepickerFilter.from != '' && datepickerFilter.to != '') {
|
|
currentDate.from = moment(
|
|
datepickerFilter.from.getState().selected.year +
|
|
"/" +
|
|
datepickerFilter.from.getState().selected.month +
|
|
"/" +
|
|
datepickerFilter.from.getState().selected.date,
|
|
"jYYYY/jM/jD"
|
|
).format("YYYY-MM-DD");
|
|
|
|
currentDate.to = moment(
|
|
datepickerFilter.to.getState().selected.year +
|
|
"/" +
|
|
datepickerFilter.to.getState().selected.month +
|
|
"/" +
|
|
datepickerFilter.to.getState().selected.date,
|
|
"jYYYY/jM/jD"
|
|
).format("YYYY-MM-DD");
|
|
|
|
queryParems.push(`fromDate=${currentDate.from}`)
|
|
queryParems.push(`toDate=${currentDate.to}`)
|
|
}
|
|
|
|
queryParemsFilter = queryParems
|
|
|
|
reloadTableUserGroups()
|
|
|
|
})
|
|
|
|
function reloadTableUserGroups() {
|
|
const url = `https://rms.rmto.ir/user-activity-report-index${queryParemsFilter.length != 0 ? `?${queryParemsFilter.join('&')}` : ''}`
|
|
|
|
$.ajax({
|
|
url: url,
|
|
type: "GET",
|
|
beforeSend: function () {
|
|
showLoaderScreen()
|
|
},
|
|
success: function (result) {
|
|
if (result.data.length != 0) {
|
|
$("#table_user_groups").dataTable().fnClearTable();
|
|
$("#table_user_groups").dataTable().fnAddData(result.data);
|
|
} else {
|
|
$("#table_user_groups").dataTable().fnClearTable();
|
|
}
|
|
hideLoaderScreen()
|
|
},
|
|
error: function (error) {
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "خطا",
|
|
text: "مشکل در فیلترینگ",
|
|
confirmButtonText: "بستن",
|
|
});
|
|
hideLoaderScreen()
|
|
},
|
|
});
|
|
}
|
|
|
|
$('.add-user-group-btn').on('click', function () {
|
|
const modal = $('#modal_add_user_group');
|
|
|
|
modal.find('#add_group_name').val('')
|
|
modal.find('#add_group_count').val(0)
|
|
modal.find('#btn_add_user_group').prop('disabled', false)
|
|
usersTableAdd.search('').columns().search('').draw()
|
|
$(`.check-users`, usersTableAdd.rows().nodes()).prop('checked', false)
|
|
|
|
modal.modal('show');
|
|
})
|
|
|
|
$(document).on('click', '.btn-edit-user-group', function () {
|
|
const modal = $('#modal_edit_user_group');
|
|
const tr = $(this).closest("tr");
|
|
const row = userGroupsTable.row(tr);
|
|
|
|
modal.find('#edit_group_name').val('')
|
|
modal.find('#edit_group_count').val(0)
|
|
modal.find('#btn_edit_user_group').prop('disabled', false)
|
|
usersTableEdit.search('').columns().search('').draw()
|
|
$(`.check-users`, usersTableEdit.rows().nodes()).prop('checked', false)
|
|
|
|
$.ajax({
|
|
url: "https://rms.rmto.ir/user-activity-report/show-users/" + row.data().group_id,
|
|
type: "GET",
|
|
beforeSend: function () {
|
|
showLoaderScreen()
|
|
},
|
|
success: function (result) {
|
|
hideLoaderScreen();
|
|
modal.find('.modal-title').text(row.data().group_name)
|
|
modal.find('#edit_group_name').val(row.data().group_name)
|
|
modal.find('#edit_group_count').val(row.data().user_count)
|
|
modal.find('#edit_group_id').val(row.data().group_id)
|
|
|
|
result.data.map(user => {
|
|
$(`.check-users[value="${user.id}"]`, usersTableEdit.rows().nodes()).prop('checked', true)
|
|
})
|
|
|
|
modal.modal('show');
|
|
},
|
|
error: function (error) {
|
|
hideLoaderScreen();
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "خطا",
|
|
text: "مشکل در دریافت اطلاعات کاربران گروه",
|
|
confirmButtonText: "بستن",
|
|
});
|
|
console.log(error);
|
|
},
|
|
});
|
|
|
|
})
|
|
|
|
$(document).on('change', '.check-users', function () {
|
|
let table;
|
|
const modal = $(this).parents('.modal')
|
|
if (modal.attr('mode') == 'add') table = usersTableAdd.rows().nodes()
|
|
else if (modal.attr('mode') == 'edit') table = usersTableEdit.rows().nodes()
|
|
modal.find('.users-count').val($(".check-users:checked", table).length)
|
|
})
|
|
|
|
$('#btn_add_user_group').on('click', function () {
|
|
const thisBtn = $(this)
|
|
thisBtn.prop('disabled', true)
|
|
const modal = $('#modal_add_user_group');
|
|
|
|
const name = modal.find('#add_group_name').val()
|
|
let arrUsersId = []
|
|
|
|
$(".check-users:checked", usersTableAdd.rows().nodes()).each(function (i, e) {
|
|
arrUsersId.push($(e).val())
|
|
})
|
|
|
|
if (name == '') {
|
|
Swal.fire({
|
|
icon: "warning",
|
|
title: "خطا",
|
|
text: "نام گروه را وارد نمایید.",
|
|
showConfirmButton: false,
|
|
cancelButtonText: "بستن",
|
|
showCancelButton: true
|
|
});
|
|
|
|
thisBtn.prop('disabled', false)
|
|
return false
|
|
} else if (arrUsersId.length == 0) {
|
|
Swal.fire({
|
|
icon: "warning",
|
|
title: "خطا",
|
|
text: "حداقل یک کاربر را انتخاب نمایید.",
|
|
showConfirmButton: false,
|
|
cancelButtonText: "بستن",
|
|
showCancelButton: true
|
|
});
|
|
|
|
thisBtn.prop('disabled', false)
|
|
return false
|
|
}
|
|
|
|
let formData = new FormData();
|
|
|
|
formData.append("group_name", name);
|
|
formData.append("users", arrUsersId);
|
|
|
|
$.ajax({
|
|
url: "https://rms.rmto.ir/user-activity-report/add",
|
|
type: "POST",
|
|
data: formData,
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false,
|
|
headers: {
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
beforeSend: function () {
|
|
showLoaderScreen();
|
|
},
|
|
success: function (result) {
|
|
thisBtn.prop('disabled', false)
|
|
modal.modal('hide')
|
|
hideLoaderScreen();
|
|
Swal.fire({
|
|
icon: "success",
|
|
title: "ثبت موفق",
|
|
text: "گروه جدید با موفقیت ثبت شد",
|
|
cancelButtonText: "بستن",
|
|
showConfirmButton: false,
|
|
showCancelButton: true,
|
|
}).then(result => {
|
|
reloadTableUserGroups()
|
|
})
|
|
},
|
|
error: function (error) {
|
|
thisBtn.prop('disabled', false)
|
|
hideLoaderScreen();
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "خطا",
|
|
text: "مشکل در ثبت گروه جدید",
|
|
cancelButtonText: "بستن",
|
|
showConfirmButton: false,
|
|
showCancelButton: true,
|
|
});
|
|
},
|
|
});
|
|
})
|
|
|
|
$('#btn_edit_user_group').on('click', function () {
|
|
const thisBtn = $(this)
|
|
thisBtn.prop('disabled', true)
|
|
const modal = $('#modal_edit_user_group');
|
|
|
|
const group_id = modal.find('#edit_group_id').val()
|
|
const name = modal.find('#edit_group_name').val()
|
|
let arrUsersId = []
|
|
|
|
$(".check-users:checked", usersTableEdit.rows().nodes()).each(function (i, e) {
|
|
arrUsersId.push($(e).val())
|
|
})
|
|
|
|
if (name == '') {
|
|
Swal.fire({
|
|
icon: "warning",
|
|
title: "خطا",
|
|
text: "نام گروه را وارد نمایید.",
|
|
showConfirmButton: false,
|
|
cancelButtonText: "بستن",
|
|
showCancelButton: true
|
|
});
|
|
|
|
thisBtn.prop('disabled', false)
|
|
return false
|
|
} else if (arrUsersId.length == 0) {
|
|
Swal.fire({
|
|
icon: "warning",
|
|
title: "خطا",
|
|
text: "حداقل یک کاربر را انتخاب نمایید.",
|
|
showConfirmButton: false,
|
|
cancelButtonText: "بستن",
|
|
showCancelButton: true
|
|
});
|
|
|
|
thisBtn.prop('disabled', false)
|
|
return false
|
|
}
|
|
|
|
let formData = new FormData();
|
|
|
|
formData.append("group_name", name);
|
|
formData.append("users", arrUsersId);
|
|
|
|
$.ajax({
|
|
url: "https://rms.rmto.ir/user-activity-report/edit/" + group_id,
|
|
type: "POST",
|
|
data: formData,
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false,
|
|
headers: {
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
beforeSend: function () {
|
|
showLoaderScreen();
|
|
},
|
|
success: function (result) {
|
|
thisBtn.prop('disabled', false)
|
|
modal.modal('hide')
|
|
hideLoaderScreen();
|
|
Swal.fire({
|
|
icon: "success",
|
|
title: "ثبت موفق",
|
|
text: "گروه با موفقیت ویرایش شد",
|
|
cancelButtonText: "بستن",
|
|
showConfirmButton: false,
|
|
showCancelButton: true,
|
|
}).then(result => {
|
|
reloadTableUserGroups()
|
|
})
|
|
},
|
|
error: function (error) {
|
|
thisBtn.prop('disabled', false)
|
|
hideLoaderScreen();
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "خطا",
|
|
text: "مشکل در ویرایش گروه",
|
|
cancelButtonText: "بستن",
|
|
showConfirmButton: false,
|
|
showCancelButton: true,
|
|
});
|
|
},
|
|
});
|
|
})
|
|
|
|
$(document).on('click', '.btn-excel-user-group', function () {
|
|
const tr = $(this).closest("tr");
|
|
const row = userGroupsTable.row(tr);
|
|
const url = `https://rms.rmto.ir/reports/user-activity-report?group_id=${row.data().group_id}&${queryParemsFilter.join('&')}`
|
|
window.open(url)
|
|
})
|
|
|
|
$(document).on('click', '.btn-pdf-user-group', function () {
|
|
const tr = $(this).closest("tr");
|
|
const row = userGroupsTable.row(tr);
|
|
const url = `https://rms.rmto.ir/user-activity-report/print/${row.data().group_id}${queryParemsFilter.length != 0 ? `?${queryParemsFilter.join('&')}` : ''}`
|
|
window.open(url,'_blank')
|
|
})
|
|
|
|
$(document).on('click', '.btn-pdf-country-chart', function () {
|
|
const url = `https://rms.rmto.ir/user-activity-report/static-print-country-chart${queryParemsFilter.length != 0 ? `?${queryParemsFilter.join('&')}` : ''}`
|
|
window.open(url,'_blank')
|
|
})
|
|
|
|
$(document).on('click', '.btn-pdf-organization-chart', function () {
|
|
const url = `https://rms.rmto.ir/user-activity-report/static-print-organization-chart${queryParemsFilter.length != 0 ? `?${queryParemsFilter.join('&')}` : ''}`
|
|
window.open(url,'_blank')
|
|
})
|
|
|
|
$(document).on('click', '.btn-delete-user-group', function () {
|
|
const tr = $(this).closest("tr");
|
|
const row = userGroupsTable.row(tr);
|
|
|
|
Swal.fire({
|
|
icon: "warning",
|
|
title: "آیا برای حذف مطمئن هستید؟",
|
|
showCancelButton: true,
|
|
confirmButtonColor: "#3085d6",
|
|
cancelButtonColor: "#d33",
|
|
confirmButtonText: "بله، حذف شود",
|
|
cancelButtonText: "منصرف شدم!",
|
|
showLoaderOnConfirm: true,
|
|
preConfirm: () => {
|
|
$.ajax({
|
|
url: "https://rms.rmto.ir/user-activity-report/delete/" + row.data().group_id,
|
|
type: "POST",
|
|
headers: {
|
|
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
|
},
|
|
cache: false,
|
|
contentType: false,
|
|
processData: false,
|
|
beforeSend: function () {
|
|
showLoaderScreen();
|
|
},
|
|
success: function (result) {
|
|
hideLoaderScreen();
|
|
Swal.fire({
|
|
icon: "success",
|
|
title: "ثبت موفق",
|
|
text: "گروه با موفقیت حذف شد",
|
|
cancelButtonText: "بستن",
|
|
showConfirmButton: false,
|
|
showCancelButton: true,
|
|
}).then(result => {
|
|
reloadTableUserGroups()
|
|
})
|
|
},
|
|
error: function (error) {
|
|
hideLoaderScreen();
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "خطا",
|
|
text: "مشکل در حذف گروه",
|
|
cancelButtonText: "بستن",
|
|
showConfirmButton: false,
|
|
showCancelButton: true,
|
|
});
|
|
},
|
|
});
|
|
},
|
|
});
|
|
})
|
|
|
|
$('.show-activity-btn').on('click', function () {
|
|
const modal = $('#modal_show_activity');
|
|
|
|
activityTable.search('').columns().search('').draw()
|
|
|
|
modal.modal('show')
|
|
})
|
|
|
|
$(document).on('click', '.btn-show-user-group', function () {
|
|
const modal = $('#modal_show_user_group');
|
|
const tr = $(this).closest("tr");
|
|
const row = userGroupsTable.row(tr);
|
|
|
|
$.ajax({
|
|
url: "https://rms.rmto.ir/user-activity-report/show-users/" + row.data().group_id,
|
|
type: "GET",
|
|
beforeSend: function () {
|
|
showLoaderScreen()
|
|
},
|
|
success: function (result) {
|
|
hideLoaderScreen();
|
|
$("#table_users_by_user_group").dataTable().fnClearTable();
|
|
$("#table_users_by_user_group").dataTable().fnAddData(result.data);
|
|
|
|
modal.modal('show')
|
|
},
|
|
error: function (error) {
|
|
hideLoaderScreen();
|
|
Swal.fire({
|
|
icon: "error",
|
|
title: "خطا",
|
|
text: "مشکل در دریافت اطلاعات کاربران گروه",
|
|
confirmButtonText: "بستن",
|
|
});
|
|
console.log(error);
|
|
},
|
|
});
|
|
}) |