signup.js 0000644 00000013331 15030266611 0006410 0 ustar 00 var init_signup = function() { init_toastr(); return $.ajax({ url: "resources/views/signup.php", data: {}, type: "POST", beforeSend: function() { show_hide_preloader(true); }, success: function(data) { document.title = 'Sign up'; side_menu_loaded = false; $('#header_content').html(''); $('#main_content').html(data); $("#dealer").select2({ // tags:true, // multiple: true, placeholder: "Select dealer", allowClear: true, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'app/models/dealer.php', dataType: 'json', delay: 250, data: function(data) { return { model: 'dealer_list', api: true, search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $("#position").select2({ // tags:true, // multiple: true, placeholder: "Select position", allowClear: true, escapeMarkup: function(markup) { return markup; }, ajax: { url: 'app/models/position.php', dataType: 'json', delay: 250, data: function(data) { return { model: 'position_list', api: true, search: data.term // search term }; }, processResults: function(response) { return { results: response }; }, cache: true } }); $('#id_no').on('keyup',function() { str = $(this).val().trim() str = str.replace(/\s/g, '') $(this).val(str) }); $('#login_account').on('click', function() { init_signin(); }); $('#btn_signup').on('click', function() { if (check_if_empty_field($('#dealer'), 'Dealer is required.')) { return; } if (check_if_empty_field($('#id_no'), 'ID number is required.')) { return; } if (check_if_empty_field($('#firstname'), 'Firstname is required.')) { return; } if (check_if_empty_field($('#lastname'), 'Lastname is required.')) { return; } if (check_if_empty_field($('#email'), 'Email address is required.')) { return; } if (!isValidEmailAddress($('#email').val().trim())) { $('#email').focus(); toastr.remove(); toastr.error('Invalid email address.'); return; } if (check_if_empty_field($('#mobile'), 'Mobile is required.')) { return; } if ($('#mobile').val().trim().length < 10) { $('#mobile').focus(); toastr.remove(); toastr.error('Invalid mobile format.'); return; } if (check_if_empty_field($('#password'), 'Password is required.')) { return; } if ($('#password').val().trim().length < 6) { $('#password').focus(); toastr.remove(); toastr.error('Password must be 6 characters and above.'); return; } var $element = $("[json-signup]"); var json_data = generate_json('json-signup', $element); return $.ajax({ url: "app/models/user.php", data: { model: 'signup', api: true, json_data: json_data }, type: "POST", dataType: 'json', beforeSend: function() { toastr.remove(); toastr.info("Signing up."); }, success: function(result) { if (parseInt(result.status) === 1) { toastr.remove(); toastr.success(result.message); init_signin(); } else { toastr.remove(); toastr.error(result.message); } }, error: function() { toastr.remove(); toastr.error("Error has occurred. Try again.") } }); }); show_hide_preloader(false); }, error: function() { toastr.remove(); toastr.error("Error has occurred. Try again.") } }); }; common.js 0000644 00000017424 15030266611 0006402 0 ustar 00 function defaultFunctions() { initToolTip() } function initToolTip() { $('.tooltip-me').bstooltip(); $('.tooltip-me').on('click', function() { $(this).bstooltip('hide') }) } function show_hide_preloader(show) { if (show) { $(".preloader").css("height", ""); $(".animation__wobble").css("display", ""); } else { $(".preloader").css("height", "0px"); $(".animation__wobble").css("display", "none"); } } function get_user_login_info() { return $.ajax({ url: "app/models/user.php", data: { model: 'user_login_info' }, type: "POST", dataType: 'json', beforeSend: function() {}, success: function(result) { // console.log(result` ) }, error: function(result) { // console.log(result) toastr.remove(); // toastr.error("Error has occurred. Try again."); toastr.error(result.responseText); init_signin(); } }); } function get_user_notification_info() { return $.ajax({ url: "app/models/user.php", data: { model: 'user_notification_info' }, type: "POST", dataType: 'json', beforeSend: function() {}, success: function(result) { // console.log(result) }, error: function() { toastr.remove(); toastr.error("Error has occurred. Try again.") } }); } function delay(callback, ms) { var timer = 0; return function() { var context = this, args = arguments; clearTimeout(timer); timer = setTimeout(function() { callback.apply(context, args); }, ms || 0); }; } function get_user_notifications() {} function get_user_messages() {} function add_content_close_listener(elmnt_id) { var count = 0; $("#" + elmnt_id + " button[data-card-widget]").each(function() { if (this.getAttribute("data-card-widget") == "remove") { $(this).on('click', function() { $("#" + elmnt_id + " > .card").each(function() { if ($(this).css('display').toLowerCase() != 'none') { count++; } }); if (count == 1) { $("#" + elmnt_id).css("display", "none"); if (elmnt_id == 'center_content') { $("#right_content,#left_content").toggleClass('col-md-3') .toggleClass('col-md'); side_menu_loaded = false; } } count = 0; }); } }); } function generate_json(attribute, $element) { var /* Create an object. */ obj = {}, /* Create a variable that references the current object (default → obj). */ ref = obj; /* Iterate over every input. */ $element.each(function() { /* Cache the id of the input. */ var id = this.id; /* Check whether the nodetype attribute is set to 'parent'. */ if (this.getAttribute(attribute) == "parent") { /* Set a new object to the property and set ref to refer to it. */ ref = obj[id] = {}; } else { /* Set the value of the input to the referred object. */ if (this.getAttribute(attribute) == "true") { if (isEmpty($(this).val())) { ref[id] = ''; } else { ref[id] = $(this).val().trim(); } } } }); /* Stringify the object and return it. */ return JSON.stringify(obj); } function isValidEmailAddress(emailAddress) { var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i; return pattern.test(emailAddress); } function isEmpty(string) { var flag = false; try { if (string.trim() == '') { flag = true; } else if (string == null) { flag = true; } else if (typeof string === 'undefined') { flag = true; } } catch (err) { console.log(err); flag = true; } return flag; } function check_if_empty_field($element, msg) { if (isEmpty($element.val())) { $element.focus(); toastr.remove(); toastr.error(msg); return true; } else { return false; } } function customSelectOption($el,id,text){ if(!isEmpty(id)){ var newOption = new Option(text, id, true, true); $el.append(newOption).trigger('change'); } } function init_function(type){ switch(type){ case 0: break; case 'lead_profile': init_leadprofile_page(); break; case 'refresh_lead_table': refreshLeadfileTable(); break; } } function upper_first_letter(data){ return data.toLowerCase() .replace(/\b[a-z]/g, function( letter) { return letter.toUpperCase(); }); } function init_destroy_session() { return $.ajax({ url: "app/models/user.php", data: { model: 'signout', api: 1 }, type: "POST", dataType: 'json', beforeSend: function() {}, success: function(result) {}, error: function() { // toastr.remove(); // toastr.error("Error has occurred. Try again.") } }); } function addSearchTransition($searchEl,$searchElDiv){ //groupfile member tab $searchEl.focusin(function() { $searchElDiv.removeClass( 'default-search-size'); $searchElDiv.addClass( 'expand-search-size'); }); $searchEl.focusout(function() { if (isEmpty($(this).val())) { $searchElDiv.removeClass( 'expand-search-size'); $searchElDiv.addClass( 'default-search-size'); } }); } function resetGroupOwners(){ selected_group = []; selected_group_owner = []; selected_group_owner.push({ owner_id: 0, owner_name: 'My', }); } function accessManagement(code){ if(!global_menu_access.includes(code)){ return false; } switch(parseInt(code)){ case 1 : //settings $('#nav_config').show(); $('#nav_config_divider').show(); break; case 2: //mastefile $('#master_add_company').show(); $('.masterfile_action_remove').show(); break; case 3: //user groups $('#nav_groups').show(); $('#nav_groups_divider').show(); break; } } groupfile.js 0000644 00000041643 15030266611 0007106 0 ustar 00 //START ROLES FILE////////////////////////////////////////////////////////////////////////// function init_groupfile_page() { init_header(); if (side_menu_loaded) { init_groupfile(); } else { $.when(init_side_content()).done(function(ajax1Results) { init_groupfile(); }); } } var init_groupfile = function() { if(!global_menu_access.includes(3)){ return false; } return $.ajax({ url: "resources/views/groupfile.php", data: {}, type: "POST", beforeSend: function() {}, success: function(data) { document.title = 'My Groups'; $('#center_content').html(data); add_content_close_listener('center_content'); defaultFunctions(); if(selected_group_owner.length > 1){ $('#groupfile_back').on('click', function() { selected_group_owner.pop(); // init_masterfile_page(); init_group_member_page(); }); }else{ $('#groupfile_back').hide(); } $('#group_owner_name').text(selected_group_owner.slice(-1)[0].owner_name); addSearchTransition($('#groupfile-search'),$('#groupfile-search-div')); $('#groupfile-search').on('keyup',delay(function(e) { refreshGroupfileTableSilent(); }, 500)); // if(selected_group_owner.length > 1) { // // $('#nav_groupfile_add_groupfile').html(' '); // $('#nav_groupfile_add_groupfile').html('Group List'); // } $(document).on('click', '.groupfile-list-filter', function(e) { e.stopPropagation(); }); $('#groupfile_add_groupfile').on('click', function() { $.when(init_group_modal()/*,create_temporary_group()*/).done(function(ajax1Results/*,ajax2Results*/) { // alert(ajax2Results.id) // created_group_id = ajax2Results[0].id; // alert(created_group_id) $('#group_modal').modal('show'); $('#group_modal').on('hidden.bs.modal', function() { // remove_temporary_group(created_group_id); $('#group_modal').remove(); }); addSearchTransition($('#group-member-search'),$('#group-member-search-div')); //groupfile member tab //*update $('#group-member-search').on('keyup',delay(function(e) { refreshGroupMemberTableSilent(); }, 500)); //end groupfile tab $('#txt_group_name').focus(); $('#btn_group_save').on('click', function() { if (check_if_empty_field($('#txt_group_name'), 'Group name is required.')) { return; } var $element = $("[json-group-modal]"); var json_data = generate_json('json-group-modal', $element); update_group(0, json_data,'') // console.log(json_data); }); refreshGroupMemberTable(); }); }); refreshGroupfileTable(); $('#table_groupfile').on('click-cell.bs.table', function(field, value, row, $el) { if (value != "action" && value != "update") { var selected_group_id = $el.id; var selected_group_name = $el.name; selected_group.push({ group_id: selected_group_id, group_name: selected_group_name, }); // console.log("Groups: "); // console.log(selected_group); init_group_member_page(); } }); show_hide_preloader(false); }, error: function() { toastr.remove(); toastr.error("Error has occurred. Try again.") } }); } function init_group_modal() { return $.ajax({ url: "resources/views/modals/group_modal.php", data: {}, type: "POST", beforeSend: function() { selected_group_member = []; //remove all previous selected in group }, success: function(data) { $('#center_content').append(data); }, error: function() { toastr.remove(); toastr.error("Error has occurred. Try again.") } }); } function update_group(group_id, json_data,type ) { return $.ajax({ url: "app/models/group.php", data: { model: 'update_group', id: group_id, owner_id: selected_group_owner.slice(-1)[0].owner_id, json_data: json_data, group_members : JSON.stringify(selected_group_member), }, type: "POST", dataType: 'json', beforeSend: function() { $('#btn_group_save').prop( 'disabled', true); toastr.remove(); toastr.info("Saving group."); }, success: function(result) { if (parseInt(result.status) === 1) { if(type == 'group_member'){ var json_data_obj = JSON.parse(json_data) var group_name = json_data_obj.txt_group_name.toUpperCase() selected_group_owner.slice(-1)[0].owner_name = group_name $('#selected_group_name').text(group_name); document.title = group_name; refreshGroupMemberTableFile(); }else{ refreshGroupfileTable(); } toastr.remove(); toastr.success(result.message); // refreshGroupfileDealerfileTable(); $('#group_modal').off('hidden.bs.modal').on('hidden.bs.modal', function() {}); $('#group_modal').modal( 'hide'); $('#group_modal').remove(); } else { $('#btn_group_save').prop( 'disabled', false); toastr.remove(); toastr.error(result.message); } }, error: function() { $('#btn_group_save').prop( 'disabled', false); toastr.remove(); toastr.error("Error has occurred. Try again.") } }); } function create_temporary_group() { return $.ajax({ url: "app/models/group.php", data: { model: 'add_temporary_group' }, 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_group(group_id) { return $.ajax({ url: "app/models/group.php", data: { model: 'remove_temporary_group', id: group_id }, type: "POST", dataType: 'json', beforeSend: function() {}, success: function(result) { }, error: function() { toastr.remove(); toastr.error("Error has occurred. Try again.") } }); } function refreshGroupfileTable() { initGroupfileList(); var $table = $('#table_groupfile') $(function() { $table.bootstrapTable('refresh', { url: 'app/models/group.php' }); }) } function refreshGroupfileTableSilent() { var $table = $('#table_groupfile') $(function() { $table.bootstrapTable('refresh', { url: 'app/models/group.php' }); }) } function initGroupfileList() { var $table = $('#table_groupfile'); $table.bootstrapTable('destroy').bootstrapTable({ sidePagination: 'server', formatSearch: function() { return 'Search...' }, onLoadSuccess: function() { if(selected_group_owner.length > 1) { // $('.btn_groupfile_update').hide(); // $('.btn_groupfile_remove').hide(); // alert('') } }, exportOptions: { fileName: function() { return 'titile' } } }); } function groupfileQueryParams(params) { return { search: $('#groupfile-search').val(), offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, added_by: selected_group_owner.slice(-1)[0].owner_id, model: 'group_table', }; } function updateGroupfileFormatter(value, row, index) { if(selected_group_owner.length > 1) { // return ''; } return ''; } function removeGroupfileFormatter(value, row, index) { if(selected_group_owner.length > 1) { // return ''; } return ''; } window.removeGroupfileEvent = { 'click i': function(e, value, row, index) { // if (parseInt(row.user_count) > 0) { // toastr.remove(); // toastr.error('Groupfile is currently active in some users.'); // return; // } if(!global_menu_access.includes(3)){ return false; } Swal.fire({ icon: 'warning', html: 'Are you sure you want to remove this group?', 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/group.php", method: "POST", dataType: 'json', data: { model: 'remove_group', id: row.id }, beforeSend: function() { toastr.remove(); toastr.info('Removing...') }, success: function(result) { if (parseInt(result.status) === 1) { toastr.remove(); toastr.success(result.message); refreshGroupfileTable(); } else { toastr.remove(); toastr.error(result.message); } }, error: function() { toastr.remove(); toastr.error( "Error has occurred. Try again." ) } }); } else if (result.isDenied) {} else {} }) } }; window.updateGroupfileEvent = { 'click i': function(e, value, row, index) { updateGroupfileEventFunc(row.id,row.name,'') } }; function updateGroupfileEventFunc(group_id,group_name,type){ if(!global_menu_access.includes(3)){ return false; } $.when(init_group_modal()).done(function(ajax1Results) { created_group_id = group_id; $('#group_modal').modal('show'); $('#group_modal').on('hidden.bs.modal', function() { $('#group_modal').remove(); }); addSearchTransition($('#group-member-search'),$('#group-member-search-div')); //*update $('#group-member-search').on('keyup',delay(function(e) { refreshGroupMemberTableSilent(); }, 500)); //end groupfile tab $('#txt_group_name').focus(); $('#txt_group_name').val(group_name); $('#btn_group_save').on('click', function() { if (check_if_empty_field($('#txt_group_name'), 'Group name is required.')) { return; } var $element = $("[json-group-modal]"); var json_data = generate_json('json-group-modal', $element); update_group(created_group_id, json_data,type) // console.log(json_data); }); refreshGroupMemberTable(); }); } ////START group member function refreshGroupMemberTable() { initGroupMemberTable(); var $table = $('#table_group_member') $(function() { $table.bootstrapTable('refresh', { url: 'app/models/group.php' }); }) } function refreshGroupMemberTableSilent() { var $table = $('#table_group_member') $(function() { $table.bootstrapTable('refresh', { url: 'app/models/group.php' }); }) } function initGroupMemberTable() { var $table = $('#table_group_member'); $table.bootstrapTable('destroy').bootstrapTable({ sidePagination: 'server', formatSearch: function() { return 'Search...' }, formatNoMatches: function () { return 'User has no group not found.'; }, onLoadSuccess: function() {}, exportOptions: { fileName: function() { return 'titile' } } }); } function groupMemberQueryParams(params) { return { search: $('#group-member-search').val(), offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, group_id : created_group_id, owner_id : selected_group_owner.slice(-1)[0].owner_id, model: 'group_user_table', group_members : JSON.stringify(selected_group_member), }; } function groupMemberFormatter(value, row, index) { var html = ''; if (parseInt(row.status) === 1) { html = ''; } return html; } window.groupMemberEvent = { 'click input': function(e, value, row, index) { if(selected_group_member.includes(row.id) ){ const index = selected_group_member.indexOf(row.id); if (index > -1) { selected_group_member.splice(index, 1); } }else{ selected_group_member.push(row.id) } // alert(JSON.stringify(selected_group_member)); refreshGroupMemberTableSilent(); //get selected id // $.ajax({ // url: "app/models/group.php", // method: "POST", // dataType: 'json', // data: { // model: 'group_member_status', // user_id: row.id, // group_id: created_group_id // }, // beforeSend: function() { // // toastr.remove(); // // toastr.info('Updating...') // }, // success: function(result) { // if (parseInt(result.status) === 1) { // // toastr.remove(); // // toastr.success(result.message); // refreshGroupMemberTableSilent(); // } else { // toastr.remove(); // toastr.error(result.message); // } // }, // error: function() { // toastr.remove(); // toastr.error( // "Error has occurred. Try again." // ) // } // }); } }; ////END ROLE DEALER //END ROLES FILE//////////////////////////////////////////////////////////////////////////////////// notification.js 0000644 00000016117 15030266611 0007576 0 ustar 00 //START CONFIG FILE///////////////////////////////////////////////////////////////////////////////////////////////////// function init_notification_page() { init_header(); if (side_menu_loaded) { init_notification(); // console.log('asd') } else { $.when(init_side_content()).done(function(ajax1Results) { init_notification(); }); } } var init_notification = function() { return $.ajax({ url: "resources/views/notification.php", data: {}, type: "POST", beforeSend: function() {}, success: function(data) { document.title = 'Notifications'; $('#center_content').html(data); add_content_close_listener('center_content'); notification_display_limit = notification_display_limit_const; $.when(user_notification()).done(function(ajax2Results) { // console.log(ajax2Results['data']) //reset notification_display_limit notification_display_limit = notification_display_limit + notification_display_limit_const; //init objects $('#notification_list_div').html(''); $('#notification_view_more').on('click', function() { $.when(user_notification()).done(function(ajax1Results2) { var result_notification2 = ajax1Results2['data']; notification_display_limit = notification_display_limit + notification_display_limit_const; notification_display(result_notification2); }); }); //ajax when area var result_notification = ajax2Results['data']; notification_display(result_notification); mark_as_read_notification(); show_hide_preloader(false); }); show_hide_preloader(false); }, error: function() { toastr.remove(); toastr.error("Error has occurred. Try again.") } }); } function refresh_notification() { $.when(get_user_notification_info()).done(function(ajax2Results) { // console.log(); var notif_count = parseInt(ajax2Results.total); if(notif_count){ $('#notif_count_badge').text(notif_count); if(notif_count > 1){ $('#notif_count').text(notif_count+ ' Notifications'); }else{ $('#notif_count').text(notif_count+ ' Notification'); } $('#notif_div_container').html('') //display notification per category $.each(ajax2Results['data'], function(i, n) { // console.log(n['type']) $('#notif_div_container').append(` `+n['count']+ ' ' +n['type']+` `+n['ago']+ `
`) }); }else{ $('#notif_count').text('0 Notification'); } $("[notification-header]").each(function() { $(this).off('click').on('click', function() { global_in_notif_section = true; selected_notification_category = $(this).attr('notification-header'); // console.log(selected_notification_category) init_notification_page(); }); }); }); } function mark_as_read_notification(){ return $.ajax({ url: "app/models/user.php", data: { model: 'mark_as_read_notification', type_id: selected_notification_category, }, type: "POST", dataType: 'json', beforeSend: function() {}, success: function(result) { // console.log(result) // setTimeout(function(){ refresh_notification(); global_in_notif_section = false; // }, 3000); }, error: function() { toastr.remove(); toastr.error( "Error has occurred. Try again." ) } }); } function user_notification() { return $.ajax({ url: "app/models/user.php", data: { model: 'user_notification', type_id: selected_notification_category, offset: notification_display_limit - notification_display_limit_const, limit: notification_display_limit_const }, type: "POST", dataType: 'json', beforeSend: function() {}, success: function(result) { // console.log(result) }, error: function() { toastr.remove(); toastr.error( "Error has occurred. Try again." ) } }); } function notification_display(ajaxResult) { $.each(ajaxResult, function(i, n) { var data = ajaxResult[i]; // console.log(data); var is_read = parseInt(data['is_read']) === 0? 'border-primary' : '' ; $('#notification_list_div').append(`