1AskTheScholarApp.controller("BlockedUsersController", function ($rootScope, $location, $scope, $http, BlockedUsersService, AskTheScholarAPIStrings, AppConstant, Constants) { 2 3 HideAlert('#SuccessMessageDiv'); 4 HideAlert('#ErrorMessageDiv'); 5 6 //form load check whether the token is present in cache. if yes, allow the user to 7 //go to dashboard. 8 var token = data = JSON.parse(window.sessionStorage.getItem('token')); 9 var expiresAt = JSON.parse(window.sessionStorage.getItem('expiresAt')); 10 var userName = JSON.parse(window.sessionStorage.getItem('UserName')); 11 12 if (token == null || token == undefined 13 || expiresAt == null || expiresAt == undefined 14 || userName == null || expiresAt == userName) { 15 16 $rootScope.LoginErrorMessage = Constants.loginTokenEmptyError; 17 $rootScope.MessageType = Constants.Error; 18 19 //redirect to login page. 20 $location.path('/login'); 21 } 22 else { 23 24 //we have the token in cache. but check whether its still valid or not 25 //by checking the expiry datetime. 26 if (IsTokenValid(moment(expiresAt))) { 27 28 //store it in scope. 29 $scope.token = token; 30 $scope.expiresAt = expiresAt; 31 $scope.LoggedInUserName = userName; 32 } 33 else { 34 $rootScope.LoginErrorMessage = Constants.sessionExpiredError; 35 $rootScope.MessageType = Constants.Error; 36 //redirect to login page. 37 $location.path('/login'); 38 } 39 } 40 41 //clear the querystring if any. 42 $location.url($location.path()); 43 44 $scope.SpamDictionaryTextList = []; 45 $scope.SpamDictionaryEmailList = []; 46 47 48 BindBlockedUsersGrid($scope.token); 49 50 function getBlockedUsersData() { 51 52 var promise = BlockedUsersService.getSpamDictionaryEmailData($scope.token); //call service function to call API 53 54 promise.then( 55 function (response) { 56 57 //iterate through the web api result (site data) and store menu data 58 angular.forEach(response.data.ReturnedResult, function (item) { 59 60 //add items to $scope.RouteDataList 61 $scope.resourceList.push({ BlockedUserId: item.BlockedUserId, Email: item.EmailAddress }); 62 }); 63 //now bind the data to grid. 64 } 65 ); 66 } 67 68 function BindBlockedUsersGrid(token) { 69 70 var newOptions = { 71 BlockedUserId: 0 72 }; 73 74 var RouteURL = AppConstant.BaseServiceURL; 75 76 var updateApiURL = RouteURL + AskTheScholarAPIStrings.UpdateSpamDictionaryEmail; 77 var deleteAPI = RouteURL + AskTheScholarAPIStrings.DeleteSpamDictionaryEmail + '/' + Constants.WebCustomerId; 78 79 var getSpamDictionaryEmailDataURL = RouteURL + AskTheScholarAPIStrings.GetSpamDictionaryEmailData + '/' + Constants.WebCustomerId; 80 81 82 dataSource = new kendo.data.DataSource({ 83 transport: { 84 read: { 85 url: getSpamDictionaryEmailDataURL, 86 contentType: "application/json", 87 type: 'GET', 88 beforeSend: function (req) { 89 req.setRequestHeader('Authorization', 'Bearer ' + token); 90 } 91 }, 92 destroy: { 93 url: deleteAPI, 94 contentType: "application/json", 95 type: 'GET', 96 beforeSend: function (req) { 97 req.setRequestHeader('Authorization', 'Bearer ' + token); 98 } 99 }, 100 parameterMap: function (options, operation) { 101 102 if (operation !== "read") { 103 104 newOptions.BlockedUserId = options.BlockedUserId; 105 106 return { models: kendo.stringify(newOptions) }; 107 } 108 } 109 }, 110 pageSize: Constants.GridPageSize, 111 requestEnd: function (e) { 112 113 var response = e.response; 114 115 if (response != null || response != undefined) { 116 117 if (response.Status == 0) { 118 if (response.ReturnedResult != null || response.ReturnedResult != undefined) { 119 HideAlert('#ErrorMessageDiv'); 120 SetText('#SuccessMessageDiv', response.ReturnedResult); 121 //show message 122 ShowAlertMessage('#SuccessMessageDiv'); 123 124 } 125 } 126 else { 127 128 if (response.ReturnedResult != null || response.ReturnedResult != undefined) { 129 var msg2 = response.ReturnedResult; 130 if (msg2.indexOf('We could not find the Data !!') != -1) { 131 HideAlert('#SuccessMessageDiv'); 132 SetText('#ErrorMessageDiv', msg2); 133 //show message 134 ShowAlertMessage('#ErrorMessageDiv'); 135 } 136 else { 137 HideAlert('#SuccessMessageDiv'); 138 SetText('#ErrorMessageDiv', Constants.technicalError); 139 ShowAlertMessage('#ErrorMessageDiv'); 140 } 141 } 142 143 } 144 } 145 var type = e.type; 146 147 if (e.type != 'read') {
148 ReloadtheMainGrid(); 149 } 150 }, 151 schema: { 152 model: { 153 id: "BlockedUserId", 154 fields: { 155 BlockedUserId: { editable: false, nullable: false }, 156 EmailAddress: { editable: false, nullable: false }, 157 BlockedDate: { type: "date", editable: false } 158 } 159 } 160 }, 161 162 }); 163 164 $("#gridSpamDictionaryEmail").kendoGrid({ 165 dataSource: dataSource, 166 pageable: true, 167 filterable: true, 168 dataBound: function (e) { 169 170 if (e.sender.dataSource.total() <= e.sender.dataSource.pageSize()) { 171 e.sender.pager.element.hide(); 172 } else { 173 e.sender.pager.element.show(); 174 } 175 }, 176 noRecords: { 177 template: "No data available." 178 }, 179 toolbar: [ 180 { template: "<label><b>Blocked Users</b></label>" } 181 ], 182 columns: [ 183 { 184 field: "EmailAddress", title: "Blocked User's Email Address", width: "40%", 185 filterable: { 186 cell: { 187 operator: "contains", 188 template: function (args) { 189 args.element.css("width", "100%").addClass("k-textbox").keydown(function (e) { 190 setTimeout(function () { 191 $(e.target).trigger("change"); 192 }); 193 }); 194 }, 195 showOperators: false 196 } 197 } 198 }, 199 { 200 field: "BlockedDate", 201 title: "Blocked Date", 202 width: "40%", 203 format: "{0:dd/MM/yyyy}", 204 filterable: { 205 operators: { 206 date: { 207 gte: "From Date", 208 lte: "To Date" 209 } 210 }, 211 ui: function (element) { 212 element.kendoDatePicker({ 213 format: "{0:dd/MM/yyyy}" 214 }); 215 } 216 }, 217 attributes: { style: "text-align:center;" }, 218 parseFormats: "{0:dd/MM/yyyy}" 219 }, 220 221 { command: [{ className: "form-btn_ForGrid", name: "destroy", text: "" }], width: "10%" }], 222 editable: "inline", 223 //editable: { 224 // mode: "inline", 225 // confirmation: function (e) { 226 // return "Are you sure to un block " + e.EmailAddress + "?"; 227 // } 228 //}, 229 sortable: true 230 }); 231 232 } 233 234 function ReloadtheMainGrid() { 235 var grid = $("#gridSpamDictionaryEmail").data("kendoGrid"); 236 if (grid != null) { 237 238 var currentPage = grid.dataSource.page(); 239 var count = grid.dataSource.view().length; 240 grid.dataSource.read(); 241 if (count <= 1) 242 grid.dataSource.page(currentPage - 1); 243 } 244 } 245 246});
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.