File manager - Edit - /home/autoph/public_html/data03252025consolidation/lms/resources/views/common/scripts/role.js
Back
//START ROLES FILE////////////////////////////////////////////////////////////////////////// function init_rolefile_page() { init_header(); if (side_menu_loaded) { init_rolefile(); } else { $.when(init_side_content()).done(function(ajax1Results) { init_rolefile(); }); } } var init_rolefile = function() { return $.ajax({ url: "resources/views/roles.php", data: {}, type: "POST", beforeSend: function() {}, success: function(data) { document.title = 'Roles'; $('#center_content').html(data); add_content_close_listener('center_content'); $('#role_back').on('click', function() { init_config_page(); }); $('#role-search').focusin(function() { $('#role-search-div').removeClass('default-search-size'); $('#role-search-div').addClass('expand-search-size'); }); $('#role-search').focusout(function() { if (isEmpty($(this).val())) { $('#role-search-div').removeClass('expand-search-size'); $('#role-search-div').addClass('default-search-size'); } }); $('#role-search').on('keyup',delay(function(e) { refreshRolefileTableSilent(); }, 500)); $(document).on('click', '.role-list-filter', function(e) { e.stopPropagation(); }); $('#role_add_role').on('click', function() { $.when(init_role_modal(), create_temporary_role()).done(function(ajax1Results, ajax2Results) { // alert(ajax2Results.id) created_role_id = ajax2Results[0].id; $('#role_modal').modal('show'); $('#role_modal').on('hidden.bs.modal', function() { remove_temporary_role(created_role_id); $('#role_modal').remove(); }); $("[role-access]").each(function() { $(this).on('change', function() { if (this.checked) { $(this).val("1"); } else { $(this).val("0"); } }); }); //role dealer tab $('#role-dealer-search').focusin(function() { $('#role-dealer-search-div').removeClass( 'default-search-size'); $('#role-dealer-search-div').addClass( 'expand-search-size'); }); $('#role-dealer-search').focusout(function() { if (isEmpty($(this).val())) { $('#role-dealer-search-div').removeClass( 'expand-search-size'); $('#role-dealer-search-div').addClass( 'default-search-size'); } }); $('#role-dealer-search').on('keyup',delay(function(e) { refreshRoleDealerfileTableSilent(); }, 500)); //end role tab $('#txt_role_name').focus(); $('#btn_role_save').on('click', function() { if (check_if_empty_field($('#txt_role_name'), 'Role name is required.')) { return; } var $element = $("[json-role-modal]"); var json_data = generate_json('json-role-modal', $element); update_role(created_role_id, json_data) // console.log(json_data); }); refreshRoleDealerfileTable(); }); }); refreshRolefileTable(); $('#table_rolefile').on('click-cell.bs.table', function(field, value, row, $el) { if (value != "action") { //update role $.when(init_role_modal()).done(function(ajax1Results) { init_role_modal_elements($el.id,$el.name,$el.menu_access); }); } }); show_hide_preloader(false); }, error: function() { toastr.remove(); toastr.error("Error has occurred. Try again.") } }); } function init_role_modal_elements(role_id,role_name,role_access){ created_role_id = role_id; $('#role_modal').modal('show'); $('#role_modal').on('hidden.bs.modal', function() { $('#role_modal').remove(); }); $("[role-access]").each(function() { $(this).on('change', function() { if (this.checked) { $(this).val("1"); } else { $(this).val("0"); } }); }); //role dealer tab $('#role-dealer-search').focusin(function() { $('#role-dealer-search-div').removeClass( 'default-search-size'); $('#role-dealer-search-div').addClass( 'expand-search-size'); }); $('#role-dealer-search').focusout(function() { if (isEmpty($(this).val())) { $('#role-dealer-search-div').removeClass( 'expand-search-size'); $('#role-dealer-search-div').addClass( 'default-search-size'); } }); $('#role-dealer-search').on('keyup',delay(function(e) { refreshRoleDealerfileTableSilent(); }, 500)); //end role tab $('#txt_role_name').focus(); $('#txt_role_name').val(role_name); $('#btn_role_save').on('click', function() { if (check_if_empty_field($('#txt_role_name'), 'Role name is required.')) { return; } var $element = $("[json-role-modal]"); var json_data = generate_json('json-role-modal', $element); update_role(created_role_id, json_data) // console.log(json_data); }); //set check to menu access const menuobj = JSON.parse(role_access); // console.log(menuobj) $.each(menuobj, function(i, n) { var $current_el = $('#ra_'+n); $current_el.val("1"); $current_el.attr('checked',true); }); refreshRoleDealerfileTable(); } function init_role_modal() { return $.ajax({ url: "resources/views/modals/role_modal.php", data: {}, type: "POST", beforeSend: function() {}, success: function(data) { $('#center_content').append(data); }, error: function() { toastr.remove(); toastr.error("Error has occurred. Try again.") } }); } function update_role(role_id, json_data) { return $.ajax({ url: "app/models/user.php", data: { model: 'update_role', id: role_id, json_data: json_data }, type: "POST", dataType: 'json', beforeSend: function() { $('#btn_role_save').prop( 'disabled', true); toastr.remove(); toastr.info("Saving role."); }, success: function(result) { if (parseInt(result.status) === 1) { refreshRolefileTable(); toastr.remove(); toastr.success(result.message); // refreshRoleDealerfileTable(); $('#role_modal').off('hidden.bs.modal').on('hidden.bs.modal', function() {}); $('#role_modal').modal( 'hide'); $('#role_modal').remove(); } else { $('#btn_role_save').prop( 'disabled', false); toastr.remove(); toastr.error(result.message); } }, error: function() { $('#btn_role_save').prop( 'disabled', false); toastr.remove(); toastr.error("Error has occurred. Try again.") } }); } function create_temporary_role() { return $.ajax({ url: "app/models/user.php", data: { model: 'add_temporary_role' }, type: "POST", dataType: 'json', beforeSend: function() {}, success: function(result) { // console.log(result) return result; }, error: function() { toastr.remove(); toastr.error("Error has occurred. Try again.") } }); } function remove_temporary_role(role_id) { return $.ajax({ url: "app/models/user.php", data: { model: 'remove_temporary_role', id: role_id }, type: "POST", dataType: 'json', beforeSend: function() {}, success: function(result) { }, error: function() { toastr.remove(); toastr.error("Error has occurred. Try again.") } }); } function refreshRolefileTable() { initRolefileList(); var $table = $('#table_rolefile') $(function() { $table.bootstrapTable('refresh', { url: 'app/models/user.php' }); }) } function refreshRolefileTableSilent() { var $table = $('#table_rolefile') $(function() { $table.bootstrapTable('refresh', { url: 'app/models/user.php' }); }) } function initRolefileList() { var $table = $('#table_rolefile'); $table.bootstrapTable('destroy').bootstrapTable({ sidePagination: 'server', formatSearch: function() { return 'Search...' }, onLoadSuccess: function() {}, exportOptions: { fileName: function() { return 'titile' } } }); } function rolefileQueryParams(params) { return { search: $('#role-search').val(), offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, model: 'role_list', }; } function removeRoleFormatter(value, row, index) { return '<i class="fa fa-times text-danger cursor-pointer" aria-hidden="true"></i>'; } window.removeRoleEvent = { 'click i': function(e, value, row, index) { if (parseInt(row.user_count) > 0) { toastr.remove(); toastr.error('Role is currently active in some users.'); return; } Swal.fire({ icon: 'warning', html: 'Are you sure you want to remove this role?', showDenyButton: false, showCancelButton: true, confirmButtonText: `Yes`, cancelButtonText: `No`, denyButtonText: `Don't Confirm`, showClass: { backdrop: 'swal2-noanimation', // disable backdrop animation popup: '', // disable popup animation icon: '' // disable icon animation }, hideClass: { popup: '', // disable popup fade-out animation }, customClass: 'swal-height' }).then((result) => { if (result.isConfirmed) { $.ajax({ url: "app/models/user.php", method: "POST", dataType: 'json', data: { model: 'remove_role', id: row.id }, beforeSend: function() { toastr.remove(); toastr.info('Removing...') }, success: function(result) { if (parseInt(result.status) === 1) { toastr.remove(); toastr.success(result.message); refreshRolefileTable(); } else { toastr.remove(); toastr.error(result.message); } }, error: function() { toastr.remove(); toastr.error( "Error has occurred. Try again." ) } }); } else if (result.isDenied) {} else {} }) } }; ////START ROLE DEALER function refreshRoleDealerfileTable() { initRoleDealerfileList(); var $table = $('#table_role_dealer_file') $(function() { $table.bootstrapTable('refresh', { url: 'app/models/user.php' }); }) } function refreshRoleDealerfileTableSilent() { var $table = $('#table_role_dealer_file') $(function() { $table.bootstrapTable('refresh', { url: 'app/models/user.php' }); }) } function initRoleDealerfileList() { var $table = $('#table_role_dealer_file'); $table.bootstrapTable('destroy').bootstrapTable({ sidePagination: 'server', formatSearch: function() { return 'Search...' }, onLoadSuccess: function() {}, exportOptions: { fileName: function() { return 'titile' } } }); } function roleDealerfileQueryParams(params) { return { search: $('#role-dealer-search').val(), offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, role_id: created_role_id, model: 'role_dealer_list', }; } function roleDealerFormatter(value, row, index) { var html = '<input class="" type="checkbox">'; if (parseInt(row.status) === 1) { html = '<input class="" type="checkbox" checked>'; } return html; } window.roleDealerEvent = { 'click input': function(e, value, row, index) { //get selected id $.ajax({ url: "app/models/user.php", method: "POST", dataType: 'json', data: { model: 'role_change_status', dealer_id: row.d_id, role_id: created_role_id }, beforeSend: function() { // toastr.remove(); // toastr.info('Updating...') }, success: function(result) { if (parseInt(result.status) === 1) { // toastr.remove(); // toastr.success(result.message); refreshRoleDealerfileTableSilent(); } else { toastr.remove(); toastr.error(result.message); } }, error: function() { toastr.remove(); toastr.error( "Error has occurred. Try again." ) } }); } }; ////END ROLE DEALER //END ROLES FILE////////////////////////////////////////////////////////////////////////////////////
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings