1jQuery(document).ready(function($) { 2 var dataAuthorisation; 3 var ctxAuthorisation = document.getElementById("form-search-authorisations-result"); 4 5 if (typeof ctxAuthorisation !== 'undefined' && ctxAuthorisation !== null) { 6 callBackSavedToken(AuthorisationDataTable, $); 7 } 8 9 jQuery('.more-columns-button').click(function(event) { 10 jQuery('#form-search-authorisations-result .dt-button.buttons-columnVisibility').click(function() { 11 let authorisationsColumns = { 12 checked_arr : [], 13 unchecked_arr : [] 14 } 15 $.each($('#form-search-authorisations-result .dt-button.buttons-columnVisibility'), function (key, value) { 16 if(value.className.includes('active')) { 17 authorisationsColumns.checked_arr.push(key); 18 } 19 else 20 { 21 authorisationsColumns.unchecked_arr.push(key); 22 } 23 }); 24 setAuthorisationsColumns(authorisationsColumns); 25 }); 26 event.stopPropagation(); 27 }); 28}); 29 30function AuthorisationDataTable($) { 31 // Variable handle firstload 32 GlobalVariable.firstLoadSeachAuthorisation = true; 33 34 var apiUrl = $('#api_url').val(); 35 36 // Disable show alert when error 37 $.fn.dataTable.ext.errMode = 'none'; 38 39 var tableSearchResultAuthorisation = $('#authorisations-table') 40 // Handle draw again datatables 41 .on('draw.dt', function(e, settings, json, xhr) { 42 if (GlobalVariable.firstLoadSeachAuthorisation) { 43 GlobalVariable.firstLoadSeachAuthorisation = false; 44 } 45 }) 46 // Handle switch paging 47 .on('page.dt', function(e, settings, json, xhr) { 48 // code ... 49 }) 50 // Handle loading after call ajax success 51 .on('xhr.dt', function(e, settings, json, xhr) { 52 if (json) { 53 GlobalVariable.totalItem = json.total; 54 } 55 56 if (GlobalVariable.firstLoadSeachAuthorisation || pressSearchAuthorisation) { 57 // Get index of EMAIL 58 var idx = settings.aoColumns 59 .filter(function(x) { 60 return x.data == "email_owner"; 61 }) 62 .map(function(x) { 63 return x.idx 64 })[0]; 65 66 // Set sort desc for column EMAIL 67 // index column 68 settings.aaSorting[0][0] = idx; 69 settings.aaSorting[0][1] = "desc"; 70 settings.aaSorting[0]['_idx'] = idx; 71 72 // Unset press search 73 pressSearchAuthorisation = false; 74 } 75 76 hideLoading(); 77 }) 78 // Handle error here 79 .on('error.dt', function(e, settings, techNote, message) { 80 hideLoading(); 81 }) 82 // Handle sorting 83 .DataTable({ 84 // allow sort column 85 "ordering": true, 86 // p:paging B:button... 87 dom: '<"#top-table.clearfix"<"#left-top"i><"#right-top"lB>><"#content-table"t<"#bottom-table.clearfix"p>>', 88 buttons: [], 89 // call ajax get api 90 "processing": false, 91 "serverSide": true, 92 // Change title when the table is empty of data 93 "language": { 94 "emptyTable": "No result found", 95 "info": "_TOTAL_ results returned", 96 "infoEmpty": "0 result returned", 97 "lengthMenu": "_MENU_", 98 oPaginate: { 99 sNext: '<svg class="svg-inline--fa fa-angle-right fa-w-8" aria-hidden="true" data-prefix="fa" data-icon="angle-right" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512" data-fa-i2svg=""><path fill="currentColor" d="M224.3 273l-136 136c-9.4 9.4-24.6 9.4-33.9 0l-22.6-22.6c-9.4-9.4-9.4-24.6 0-33.9l96.4-96.4-96.4-96.4c-9.4-9.4-9.4-24.6 0-33.9L54.3 103c9.4-9.4 24.6-9.4 33.9 0l136 136c9.5 9.4 9.5 24.6.1 34z"></path></svg>', 100 sPrevious: '<svg class="svg-inline--fa fa-angle-left fa-w-8" aria-hidden="true" data-prefix="fa" data-icon="angle-left" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 512" data-fa-i2svg="">
100<path fill="currentColor" d="M31.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L127.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L201.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34z"></path></svg>' 101 } 102 103 }, 104 pagingType: 'simple_numbers', 105 ajax: { 106 url: apiUrl + "/api/role_delegation/search-results", 107 type: "POST", 108 dataType: "json", 109 contentType: "application/json", 110 beforeSend: async function(jqXHR, settings) { 111 showLoading(); 112 var authorization = getAuthorization(); 113 jqXHR.setRequestHeader('Authorization', authorization); 114 115 if(!GlobalVariable.firstLoadSeachAuthorisation){ 116 await checkpointReloadPage('authorisations'); 117 } 118 }, 119 statusCode: { 120 400: function() { 121 console.log('Bad Request 400'); 122 $('#authorisations-table tbody') 123 .empty() 124 .append('<tr><td colspan="12" class="dataTables_empty">Bad request</td></tr>') 125 }, 126 401: function() { 127 console.log('Access Denied 401'); 128 $('#authorisations-table tbody') 129 .empty() 130 .append('<tr><td colspan="12" class="dataTables_empty">Authorization has been denied for this request.</td></tr>'); 131 processExpireToken(); 132 133 }, 134 500: function() { 135 console.log('Internal server error 500'); 136 $('#authorisations-table tbody') 137 .empty() 138 .append('<tr><td colspan="12" class="dataTables_empty">Internal server error</td></tr>') 139 } 140 }, 141 data: function(data) { 142 //handle press button and checkbox 143 $('#authorisations-table tbody').on('click', 'button[name="btn-remove"]', function() { 144 dataAuthorisation = GlobalVariable.searchAuthorisationResult.row(this.parentElement.parentElement).data(); 145 showModalByID('#confir-remove-author-modal'); 146 }); 147 148 $('#authorisations-table tbody').on('click', 'button[name="btn-confirm"]', function() { 149 dataAuthorisation = GlobalVariable.searchAuthorisationResult.row(this.parentElement.parentElement).data(); 150 if (document.location.href.indexOf("add-author") != -1 || document.location.href.indexOf("req-author") != -1) { 151 document.location.href = String(document.location.href).replace(document.location.href.split('#')[1], ""); 152 } 153 if (!dataAuthorisation.type) { 154 jQuery('#add-author-from').text(dataAuthorisation.email_owner); 155 jQuery('#add-author-herds').text(dataAuthorisation.herd_national_id); 156 showModalByID('#confir-add-author-modal'); 157 } else { 158 jQuery('#req-author-from').text(dataAuthorisation.email_authorised); 159 jQuery('#req-author-herds').text(dataAuthorisation.herd_national_id); 160 showModalByID('#confir-req-author-modal'); 161 } 162 }); 163 164 // Prepare parameters to call API 165 var pageCount = data.length; 166 var pageNumber = (data.start / data.length) + 1; 167 var sortedBy = data.order[0].column != 0 ? data.columns[data.order[0].column].data.toUpperCase() : 'EMAIL_OWNER'; 168 var isDescSorting = data.order[0].dir == 'asc' ? false : true; 169 170 // var roleValue = jQuery('#selectRole').find(":selected").val(); 171 var statusValue = jQuery('#selectStatus').find(":selected").val(); 172 173 // if (roleValue === 'All') { 174 // roleValue = ''; 175 // } 176 177 if (statusValue === 'All') { 178 statusValue = ''; 179 } 180 181 var criterias = { 182 'USER_ID_OWNER_AUTHORISED': JSON.parse(localStorage.getItem('datavat_current_user')).CLAIM_USER_ID, 183 "EMAIL_HERD": $('#searchByText').val().trim(), 184 "ROLE_CODE": '', 185 "STATUS": statusValue 186 }; 187 188 // Handle firstload page, default sort 189 if (GlobalVariable.firstLoadSeachAuthorisation || pressSearchAuthorisation) { 190 sortedBy = 'EMAIL_OWNER'; 191 isDescSorting = true; 192 } 193 194 // Clean criterias 195 return JSON.stringify({ 196 'Criterias': cleanCriterias(criterias), 197 'sortedBy': sortedBy, 198 'isDescSorting': isDescSorting, 199 'pageNumber': pageNumber,
200 'pageCount': pageCount 201 }); 202 } 203 }, 204 // Define column by row 205 columns: [ 206 { data: "email_owner", orderable: true, visible: true }, 207 { data: "email_authorised", orderable: true, visible: true }, 208 { data: "herd_national_id", orderable: true, visible: true }, 209 { data: "role_code", orderable: true, visible: false }, 210 { data: "status", orderable: true, visible: true }, 211 { data: "expiried_date", orderable: true, visible: true }, 212 { data: "created_date", orderable: true, visible: true }, 213 { data: "accepted_date", orderable: true, visible: true }, 214 { data: "modified_date", orderable: true, visible: false }, 215 { 216 'data': 'Action', 217 "width": "150px", 218 orderable: false, 219 'render': function(data, type, row, meta) { 220 if (row.type == 0 && row.user_id_authorised == JSON.parse(localStorage.getItem('datavat_current_user')).CLAIM_USER_ID && row.status == authorisationStatus.PENDING) { 221 return "<button type='button' class='cd-button button-standard' style='padding:5px; margin:0; float:left' name='btn-confirm' value='Confirm'>Confirm</button>" + 222 "<button type='button' class='cd-button button-standard' style='padding:5px; margin:0; float:right' name='btn-remove' value='Remove'>Remove</button>"; 223 } 224 if (row.type == 1 && row.user_id_owner == JSON.parse(localStorage.getItem('datavat_current_user')).CLAIM_USER_ID && row.status == authorisationStatus.PENDING) { 225 return "<button type='button' class='cd-button button-standard' style='padding:5px; margin:0; float:left' name='btn-confirm' value='Confirm'>Confirm</button>" + 226 "<button type='button' class='cd-button button-standard' style='padding:5px; margin:0; float:right' name='btn-remove' value='Remove'>Remove</button>"; 227 } else { 228 if (row.status != authorisationStatus.REMOVED) { 229 return "<button type='button' class='cd-button button-standard' style='padding:5px; margin:0; float:right' name='btn-remove' value='Remove'>Remove</button>"; 230 } 231 return; 232 } 233 } 234 } 235 ], 236 columnDefs: [{ 237 targets: [5, 6, 7, 8], 238 render: function(data) { 239 return data ? moment(data).format('DD/MM/YYYY HH:mm') : ''; 240 } 241 }, ] 242 }); 243 244 // Add button into region top table 245 $(".btn-outter").prependTo("#left-top"); 246 $(".wrap-table > br").remove(); 247 248 // More columns button 249 tableSearchResultAuthorisation.button().add(0, { 250 text: 'Columns', 251 extend: 'colvis', 252 columns: ':not(.noVis)', 253 className: 'cd-button button-sub more-columns-button' 254 }); 255 256 if(getAuthorisationsColumns()) 257 { 258 tableSearchResultAuthorisation.columns(getAuthorisationsColumns().checked_arr).visible(true); 259 tableSearchResultAuthorisation.columns(getAuthorisationsColumns().unchecked_arr).visible(false); 260 } 261 262 // Assign table search bull into Global Variable 263 GlobalVariable.searchAuthorisationResult = tableSearchResultAuthorisation; 264 265 jQuery(".more-columns-button").append('<svg class="svg-inline--fa fa-chevron-down fa-w-14" aria-hidden="true" data-prefix="fa" data-icon="chevron-down" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" data-fa-i2svg=""><path fill="currentColor" d="M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z"></path></svg>'); 266 jQuery(".dataTables_info").addClass("custom-dataTables_info"); 267 jQuery(".dt-buttons").addClass("button-column"); 268 jQuery(".dataTables_length label").append('<svg class="svg-inline--fa fa-chevron-down fa-w-14" style="right: 30px;top: 39px;" aria-hidden="true" data-prefix="fa" data-icon="chevron-down" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" data-fa-i2svg="">
268<path fill="currentColor" d="M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z"></path></svg>'); 269}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.