PageSourceSearch

https://shabirally.com/Template/Publications/PublicationSubTypeDataController.js

js shabirally.com collected 2026-09-25 01:48:33 UTC 38,080 bytes, 1,046 lines download raw bytes

1AskTheScholarApp.controller("PublicationSubTypeDataController", function ($location, $scope, Constants, $rootScope, PublicationSubTypeDataServices, AskTheScholarAPIStrings, AppConstant) {
2
3    //form load check whether the token is present in cache. if yes, allow the user to 
4    //go to dashboard.
5    var token = data = JSON.parse(window.sessionStorage.getItem('token'));
6    var expiresAt = JSON.parse(window.sessionStorage.getItem('expiresAt'));
7    var userName = JSON.parse(window.sessionStorage.getItem('UserName'));
8
9    if (token === null || token === undefined
10        || expiresAt === null || expiresAt === undefined
11        || userName === null || expiresAt === userName) {
12
13        $rootScope.LoginErrorMessage = Constants.loginTokenEmptyError;
14        $rootScope.MessageType = Constants.Error;
15
16        //redirect to login page.
17        $location.path('/login');
18    }
19    else {
20
21        //we have the token in cache. but check whether its still valid or not
22        //by checking the expiry datetime.
23        if (IsTokenValid(moment(expiresAt))) {
24
25            //store it in scope.
26            $scope.token = token;
27            $scope.expiresAt = expiresAt;
28            $scope.LoggedInUserName = userName;
29        }
30        else {
31            RedirectToLogin(Constants.sessionExpiredError)
32        }
33    }
34
35    $scope.multipleLanguage = false;
36    if (Constants.MultipleLanguageFeature === 'Yes') {
37        $scope.multipleLanguage = true;
38    }
39
40    BindLanguage();
41
42    function BindLanguage() {
43
44        var LanguageDDLData = Constants.AdminLanguageDDLData;
45
46        $("#LanguageDropDownList").kendoDropDownList({
47            dataTextField: "text",
48            dataValueField: "value",
49            dataSource: LanguageDDLData
50        });
51
52        $("#LanguageDropDownListForEdit").kendoDropDownList({
53            dataTextField: "text",
54            dataValueField: "value",
55            dataSource: LanguageDDLData
56        });
57
58        var languageDDL = $("#LanguageDropDownList").data("kendoDropDownList");
59        if (languageDDL !== null && languageDDL !== undefined) {
60            languageDDL.value('en');
61        }
62    }
63
64    //clear the querystring if any.
65    $location.url($location.path());
66
67    $scope.resourceList = [];
68
69    //$scope.LoggedInUserName = 'rashid';
70
71    $scope.subTypeIdForEdit = 0;
72
73    $scope.isSubTypedUpdating = false;
74
75    //variable to store drop down values of sub types.
76    $scope.subTypesDDLList = [];
77
78    //hide error & success messages.
79    HideAlert('#ErrorMessageDiv');
80    HideAlert('#SuccessMessageDiv');
81    HideAlert('#InsertErrorMessageDiv');
82    HideAlert('#EditErrorMessageDiv');
83
84    LoadPrivileges();
85
86    //bind the grid with values();
87    BindSubTypeGrid($scope.token);
88
89    //load the drop down with values
90    //bindDropdown();
91
92    //load kendo upload contorl
93    LoadUploadControl();
94
95    //load calender 
96    LoadCalender();
97
98    calendar();
99
100    BindScheduledDataGrid($scope.token);
101
102    //this method is used to make the kendo calender and set todays data in it
103    function LoadCalender() {
104        var month; var year; var dt;
105
106        var dte = new Date(kendo.toString(new Date(), 'd'));
107
108        //re assign the global date objects.
109        month = dte.getMonth() + 1;
110
111        year = dte.getFullYear();
112
113        dt = dte.getDate();
114
115        $("#datepicker").kendoDatePicker({ format: AppConstant.SimpleDateFormat });
116        $("#datepicker").attr("readonly", true); //user should not type the date
117
118        var datepicker = $("#datepicker").data("kendoDatePicker");
119
120        var fromDate = dt + "/" + month + "/" + year;
121
122        datepicker.value(fromDate);
123    }
124
125    function LoadUploadControl() {
126        $("#specialTypeFile").kendoUpload(
127            {
128                multiple: false,
129                localization: {
130                    select: "Select File",
131                },
132                validation: {
133                    allowedExtensions: [".gif", ".jpg", ".png"],
134                    maxFileSize: 4194304
135                }
136            }
137        );
138
139        $("#specialTypeFileForInsert").kendoUpload(
140            {
141                multiple: false,
142                localization: {
143                    select: "Select File",
144                },
145                validation: {
146                    allowedExtensions: [".gif", ".jpg", ".png"],
147                    maxFileSize: 4194304
148                }
149            }
150        );
151    }
152
153    function getResData(token) {
154
155        var promise = PublicationSubTypeDataServices.getSubTypeData(token); //call service function to call API
156
157        promise.then(
158            function (response) {
159
160                //iterate through the web api result (site data) and store menu data
161                angular.forEach(response.data.ReturnedResult, function (item) {
162
163                    //add items to $scope.RouteDataList
164                    $scope.resourceList.push({ ResourceTitle: item.ResourceTitle, ResourceURL: item.ResourceURL });
165                });
166
167                //now bind the data to grid.
168
169
170            }
171        );
172    }
173
174    function BindSubTypeGrid(token) {
175
176
177        var newOptions = {
178            SubTypeId: 0,
179            SubTypeName: '',
180            ImagePath: '',
181            DefaultImagePath: AskTheScholarAPIStrings.DefaultImagePath
182        };
183
184        var RouteURL = AppConstant.BaseServiceURL;
185
186
187        var deleteAPI = RouteURL + AskTheScholarAPIStrings.DeleteSubTypes + '/' + Constants.WebCustomerId;
188
189        var getSubTypeDataURL = RouteURL + AskTheScholarAPIStrings.GetPublishedDataSubTypes + '/' + Constants.WebCustomerId,
190
191
192            dataSource = new kendo.data.DataSource({
193                transport: {
194                    read: {
195                        url: getSubTypeDataURL,
196                        contentType: "application/json",
197                        type: 'GET',
198                        beforeSend: function (req) {
199                            req.setRequestHeader('Authorization', 'Bearer ' + token);
200                        }
201                    },
202                    destroy: {
203                        url: deleteAPI,
204                        contentType: "application/json",
205                        type: 'GET',
206                        beforeSend: function (req) {
207                            req.setRequestHeader('Authorization', 'Bearer ' + token);
208                        }
209                    },
210                    parameterMap: function (options, operation) {
211
212                        //if the operation is update or insert
213                        //pass created by as well.
214                        if (operation === "update" || operation === "create" && options.models) {
215
216                            //modify the object
217                            if (operation === "update") {
218
219                                newOptions.SubTypeId = options.models[0].SubTypeId;
220                            }
221
222                            newOptions.SubTypeName = options.models[0].SubTypeName;
223                            newOptions.ImagePath = options.models[0].ImagePath;
224
225                            //now pass this to api
226                            return { models: kendo.stringify(newOptions) };
227                        }
228
229                        if (operation !== "read" && options.models) {
230                            return { models: kendo.stringify(options.models) };
231                        }
232                    }
233                },
234                batch: true,
235                pageSize: Constants.GridPageSize,
236
237                requestEnd: function (e) {
238                    
239                    if (e.type === 'destroy') {
240                        //check if there is any error
241                        if (e.response !== null || e.response !== undefined) {
242                            if (e.response.ReturnedResult !== undefined && e.response.ReturnedResult !== null) {
243                                var msg = e.response.ReturnedResult;
244                                if (msg !== undefined) {
245                                    if (msg !== null) {
246                                        if (msg.indexOf('Cannot delete subtype') !== -1) {
247
248                                            //show error message to user.
249                                            HideAlert('#SuccessMessageDiv');
250                                            //set error message
251                                            SetText('#ErrorMessageDiv', 'Sub type cannot be deleted since its used in published data.');
252                                            //show error message.
253                                            ShowAlertMessage('#ErrorMessageDiv');
254                                        }
255                                        else if (msg.indexOf('deleted successfully') != -1) {
256
257                                            HideAlert('#ErrorMessageDiv');
258
259                                            SetText('#SuccessMessageDiv', 'Special category deleted successfully!!');
260                                            ShowAlertMessage('#SuccessMessageDiv');
261                                            bindDropdown();
262                                        }
263                                    }
264                                }
265                            }
266                        }
267                    }
268
269                    if (e.type !== 'read') {
270
271                        var grid = $("#grid").data("kendoGrid");
272                        if (grid !== null) {
273
274                            var currentPage = grid.dataSource.page();
275                            var count = grid.dataSource.view().length;
276                            grid.dataSource.read();
277                            if (count <= 0)
278                                grid.dataSource.page(currentPage - 1);
279                        }
280                        ReloadtheMainGrid();
281                        //this.read();
282                    }
283
284                    window.scrollTo(0, 0);
285                },
286                schema: {
287                    model: {
288                        id: "SubTypeId",
289                        fields: {
290                            SubTypeId: { editable: true, nullable: false },
291                            SubTypeName: { editable: true, nullable: false },
292                            ImagePath: { editable: true, nullable: false }
293                        }
294                    }
295                },
296
297            });
298
299        $("#grid").kendoGrid({
300            dataSource: dataSource,
301            noRecords: {
302                template: "No data available."
303            },
304            toolbar: [
305                { template: "<label><b>List of available Special categories</b></label>" }
306            ],
307            dataBound: function (e) {
308
309                if (e.sender.dataSource.total() <= e.sender.dataSource.pageSize()) {
310                    e.sender.pager.element.hide();
311                } else {
312                    e.sender.pager.element.show();
313                }
314                //get data from datagrid.
315                var sgrid = $("#grid").data("kendoGrid");
316                if (sgrid != null) {
317
318                    var data = sgrid.dataSource.data();
319
320                    //remove before add.
321                    window.localStorage.removeItem('subTypeDataCache');
322
323                    //set the data to local cache
324                    window.localStorage.setItem('subTypeDataCache', JSON.stringify(data));
325
326                    //if ($scope.isSubTypedUpdating === true) {
327
328                    bindDropdown();
329
330                    //    $scope.isSubTypedUpdating = false;
331                    //}
332                }
333            },
334            pageable: true,
335            //height: 250,
336            columns: [
337                {
338                    field: "SubTypeName", title: "Special Category Name", width: "20%",
339                    filterable: {
340                        cell: {
341                            operator: "contains",
342                            template: function (args) {
343                                args.element.css("width", "100%").addClass("k-textbox").keydown(function (e) {
344                                    setTimeout(function () {
345                                        $(e.target).trigger("change");
346                                    });
347                                });
348                            },
349                            showOperators: false
350                        }
351                    }
352                },
353                {
354                    title: "Special category Icon",
355                    width: '20%',
356                    attributes: { style: "text-align:center;" },
357                    template: "<image src=\'#=ImagePath #\' style='width:30px; height:30px;' />"
358                    , filterable: false
359                },
360                {
361                    title: "",
362                    width: '10%',
363                    attributes: { style: "text-align:center;" },
364                    template: "<input type='button' value='Edit' class='btn form-btn' onclick=\"editSubType(\'#=SubTypeId #\')\"></input>"
365                    , filterable: false
366                },
367                { command: [{ className: "form-btn_ForGrid", name: "destroy", text: "Delete" }], width: "10%" }
368
369            ],
370
371            editable: "inline",
372            //editable: {
373
374            //    mode: "inline",
375            //    confirmation: function (e) {
376
377            //        return "Are you sure to delete the sub type " + e.SubTypeName + "?";
378            //    }
379            //},
380            filterable: true,
381            sortable: true
382        });
383
384    }
385
386    $scope.ShowSubTypeForEdit = function (subTypeId) {
387
388        //get the data from scope using subtype id and show it in UI.
389        var data = JSON.parse(localStorage.getItem('subTypeDataCache'));
390        if (data !== null) {
391            //var editedSybTypeData = data.find(x => x.SubTypeId === parseInt(subTypeId, 10));
392
393            var editedSybTypeData = altFind(data, function (e) {
394                return e.SubTypeId == parseInt(subTypeId, 10);
395            });
396
397            $('#subTypeNameTextBox').val(editedSybTypeData.SubTypeName);
398
399            var languageDDL = $("#LanguageDropDownListForEdit").data("kendoDropDownList");
400            if (languageDDL !== null && languageDDL !== undefined) {
401                if (editedSybTypeData.Language !== null && editedSybTypeData.Language !== undefined && editedSybTypeData.Language !== '') {
402                    languageDDL.value(editedSybTypeData.Language);
403                }
404                else {
405                    languageDDL.value('en');
406                }
407            }
408
409            //assign the id to scope.
410            $scope.subTypeIdForEdit = subTypeId;
411            $scope.editedImagePath = editedSybTypeData.ImagePath;
412
413            $scope.$apply();
414            HideAlert('#EditErrorMessageDiv');
415            //at last show the modal for edit.
416            $('#EditDiv').modal(
417                {
418                    show: true,
419                    //backdrop: 'static',
420                    //keyboard: false
421                });
422        }
423        else {
424            //show error message
425        }
426
427    }
428
429    $scope.UpdateSubType = function () {
430
431        var files;
432
433        var subTypeName = $('#subTypeNameTextBox').val();
434
435        var upload = $("#specialTypeFile").data("kendoUpload");
436
437        if (upload != null) {
438
439            var fileList = upload.getFiles();
440
441            files = fileList[0];
442        }
443
444        if (subTypeName != '') {
445
446            //show loading animation
447            //displayLoading(true);
448
449            //get the form object
450            var form = document.getElementById('publishSubTypeForm');
451
452            formData = new FormData(form);
453            if (files != null)
454                var name = files.name;
455
456            var choosenLanguage = 'en';
457            var languageDDL = $("#LanguageDropDownListForEdit").data("kendoDropDownList");
458            if (languageDDL !== null && languageDDL !== undefined) {
459                choosenLanguage = languageDDL.value();
460            }
461
462            //embedd the values
463            var encodedStr = name;
464            var parser = new DOMParser;
465            var dom = parser.parseFromString(
466                '<!doctype html><body>' + encodedStr,
467                'text/html');
468            var decodedString = dom.body.textContent;
469            formData.append("SubTypeId", $scope.subTypeIdForEdit);
470            formData.append("SubTypeName", subTypeName);
471            formData.append("FileName", decodedString);
472            formData.append("Language", choosenLanguage);
473
474            //call the service
475            var promise = PublicationSubTypeDataServices.UpdatePublishedScheduleData(formData, $scope.token);
476
477            promise.then(
478                function (response) {
479
480                    var uploadCtrl = $("#specialTypeFile").data("kendoUpload");
481
482                    if (uploadCtrl != null)
483                        //clear all files from upload
484                        uploadCtrl.removeAllFiles();
485
486                    //hide the loading
487                    //displayLoading(false);
488                    if (response.data.Status == 0) {
489                        HideAlert('#ErrorMessageDiv');
490                        SetText('#SuccessMessageDiv', 'Special category updated successfully!!');
491                        ShowAlertMessage('#SuccessMessageDiv');
492                        $scope.isSubTypedUpdating = true;
493
494                        //reload the grid.
495                        var grid = $("#grid").data("kendoGrid");
496                        if (grid != null) {
497                            grid.dataSource.read();
498                        }
499                        //reload the grid.
500                        var grid1 = $("#scheduledGrid").data("kendoGrid");
501                        if (grid1 != null) {
502                            grid1.dataSource.read();
503                        }
504                    }
505                    else {
506                        var errMsg = response.data.ReturnedResult;
507                        if (errMsg != null) {
508                            if (errMsg.indexOf('Sub Category name is already exists') != -1) {
509
510                                HideAlert('#SuccessMessageDiv');
511                                SetText('#ErrorMessageDiv', errMsg);
512                                ShowAlertMessage('#ErrorMessageDiv');
513                            }
514                        }
515                    }
516
517                    //hide the modal window
518                    $('#EditDiv').modal('toggle');
519
520                    window.scrollTo(0, 0);
521                });
522        }
523        else {
524            SetText('#EditErrorMessageDiv', 'Enter SubType Name');
525            ShowAlertMessage('#EditErrorMessageDiv');
526        }
527    }
528
529    $scope.insertSubType = function () {
530
531        var files;
532
533        var subTypeName = $('#subTypeNameTextBoxForInserting').val();
534
535        var uploadCtrl = $("#specialTypeFileForInsert").data("kendoUpload");
536
537        if (uploadCtrl != null) {
538
539            var fileList = uploadCtrl.getFiles();
540
541            files = fileList[0];
542        }
543
544        if (subTypeName != '') {
545
546
547            //show loading animation
548            //displayLoading(true);
549
550            //get the form object
551            var form = document.getElementById('publishSubTypeInsertForm');
552
553            formData = new FormData(form);
554            if (files != null)
555                var name = files.name;
556
557            var choosenLanguage = 'en';
558            var languageDDL = $("#LanguageDropDownList").data("kendoDropDownList");
559            if (languageDDL !== null && languageDDL !== undefined) {
560                choosenLanguage = languageDDL.value();
561            }
562
563            //embedd the values
564            var encodedStr = name;
565            var parser = new DOMParser;
566            var dom = parser.parseFromString(
567                '<!doctype html><body>' + encodedStr,
568                'text/html');
569            var decodedString = dom.body.textContent;
570
571            formData.append("SubTypeId", 0);
572            formData.append("SubTypeName", subTypeName);
573            formData.append("FileName", decodedString);
574            formData.append("Language", choosenLanguage);
575
576            //call the service
577            var promise = PublicationSubTypeDataServices.InsertPublishedScheduleData(formData, $scope.token);
578
579            promise.then(
580                function (response) {
581
582                    var uploadCtrl = $("#specialTypeFileForInsert").data("kendoUpload");
583
584                    //clear all files from upload
585                    uploadCtrl.removeAllFiles();
586
587                    //hide the loading
588                    //displayLoading(false);
589
590                    if (response.data.Status == 0) {
591                        HideAlert('#ErrorMessageDiv');
592                        SetText('#SuccessMessageDiv', 'Special category inserted successfully!!');
593                        ShowAlertMessage('#SuccessMessageDiv');
594
595                        $scope.isSubTypedUpdating = true;
596
597                        //reload the grid.
598                        var grid = $("#grid").data("kendoGrid");
599                        if (grid != null) {
600                            grid.dataSource.read();
601                        }
602
603
604                    }
605                    else {
606                        var errMsg = response.data.ReturnedResult;
607                        if (errMsg != null) {
608                            if (errMsg.indexOf('Sub Category name is already exists') != -1) {
609
610                                HideAlert('#SuccessMessageDiv');
611                                SetText('#ErrorMessageDiv', errMsg);
612                                ShowAlertMessage('#ErrorMessageDiv');
613                            }
614                        }
615                    }
616
617                    $('#subTypeNameTextBoxForInserting').val('');
618                    //hide the modal window
619                    $('#InsertDiv').modal('toggle');
620
621                    window.scrollTo(0, 0);
622                });
623
624        }
625        else {
626
627            SetText('#InsertErrorMessageDiv', 'Enter SubType Name');
628            ShowAlertMessage('#InsertErrorMessageDiv');
629        }
630    }
631
632    function calendar() {
633
634        angular.module('calendarDemo', ['ngMaterial']).controller('AppCtrl', function () {
635            this.startDate = new Date();
636            this.endDate = new Date();
637            this.endDate.setDate(this.endDate.getDate() + 5);
638        });
639    }
640
641    function bindDropdown() {
642
643        //clear the array
644        $scope.subTypesDDLList = [];
645        var jsonData = {};
646        var finalObj = [];
647        var actualData = {};
648        var s = '';
649        var cachedData = JSON.parse(localStorage.getItem('subTypeDataCache'));
650        if (cachedData != null) {
651
652
653            for (var i = 0; i < cachedData.length; i++) {
654
655                $scope.subTypesDDLList.push(
656                    {
657                        text: cachedData[i].SubTypeName,
658                        value: cachedData[i].SubTypeId
659                    }
660                );
661            }
662
663            // create DropDownList from input HTML element
664            $("#subTypeList").kendoDropDownList({
665                dataTextField: "text",
666                dataValueField: "value",
667                dataSource: $scope.subTypesDDLList,
668                index: 0,
669                //change: onChange
670            });
671
672
673        }
674        else {
675            //Error
676        }
677
678    }
679
680    //this method is used to schedule a special category.
681    $scope.ScheduleSubType = function () {
682
683        var dropdownlist = $("#subTypeList").data("kendoDropDownList");
684        var subTypeName = dropdownlist.text();
685        var subTypeid = subTypeList.value;
686
687        //var datepicker = $("#datepicker").data("kendoDatePicker");
688
689        //var fromDate = dt + "/" + month + "/" + year;
690
691        //datepicker.value(fromDate);
692
693        var selectedDate = datepicker.value;
694        kendo.confirm("Are you sure to create ? You Choose Sub Category as " + subTypeName + " and the date is " + selectedDate).then(function () {
695
696            displayLoading(true);
697
698            var ScheduledData =
699            {
700                SubTypeId: subTypeid,
701                DisplayFrom: selectedDate,
702            };
703
704            //now call the web api and save the question.
705            var promise = PublicationSubTypeDataServices.InsertScheduleData(ScheduledData, $scope.token);
706            promise.then(
707                function (response) {
708                    if (response.data.Status == 0) //success
709                    {
710                        //display the success message
711                        HideAlert('#ErrorMessageDiv');
712                        SetText('#SuccessMessageDiv', 'Schedule for the sub category saved successfully!!!');
713                        ShowAlertMessage('#SuccessMessageDiv');
714
715                        //get the data to display
716                        if (response.data.ReturnedResult != null) {
717                            var subTypeData = response.data.ReturnedResult.SpecialTypeDataToDisplay;
718
719                            //set the value to root scope
720                            $rootScope.specialTypeData = subTypeData;
721
722                            //refresh the roorscope variable by calling homde controller function(refresh the icon in index page)
723                            $rootScope.$emit("SetSpecialCategoryInformationMethod", {});
724
725                            var scholarGrid = $("#scheduledGrid").data("kendoGrid");
726                            if (scholarGrid != null) {
727                                scholarGrid.dataSource.read();
728                            }
729
730                        }
731                    }
732                    else {
733
734                        if (response.data.ReturnedResult != null) { //sub type exists
735
736                            var errMsg = response.data.ReturnedResult.Message;
737
738                            if (errMsg.indexOf('SubType exists for the selected date') != -1) {
739
740                                HideAlert('#SuccessMessageDiv');
741                                SetText('#ErrorMessageDiv', errMsg);
742                                ShowAlertMessage('#ErrorMessageDiv');
743                            }
744                        }
745                        else {//there is a technical error
746
747                            HideAlert('#SuccessMessageDiv');
748                            SetText('#ErrorMessageDiv', 'Oops!!. some thing went wrong. please after some time');
749                            ShowAlertMessage('#ErrorMessageDiv');
750                        }
751
752                    }
753
754                    displayLoading(false);
755
756                    window.scrollTo(0, 0);
757                });
758
759        });
760
761    };
762
763    //this function is used to bind the grid with scheduled special category(subtype) data
764    function BindScheduledDataGrid(token) {
765
766
767        var RouteURL = AppConstant.BaseServiceURL;
768
769        var deleteAPI = RouteURL + AskTheScholarAPIStrings.DeleteScheduledDataById + '/' + Constants.WebCustomerId;
770
771        var getSubTypeDataURL = RouteURL + AskTheScholarAPIStrings.GetScheduledData + '/' + Constants.WebCustomerId,
772
773
774            dataSource = new kendo.data.DataSource({
775                transport: {
776                    read: {
777                        url: getSubTypeDataURL,
778                        contentType: "application/json",
779                        type: 'GET',
780                        beforeSend: function (req) {
781                            req.setRequestHeader('Authorization', 'Bearer ' + token);
782                        }
783                    },
784                    destroy: {
785                        url: deleteAPI,
786                        contentType: "application/json",
787                        type: 'GET',
788                        beforeSend: function (req) {
789                            req.setRequestHeader('Authorization', 'Bearer ' + token);
790                        }
791                    },
792                    parameterMap: function (options, operation) {
793
794                        if (operation !== "read" && options.models) {
795                            return { models: kendo.stringify(options.models) };
796                        }
797                    }
798                },
799                batch: true,
800                pageSize: Constants.GridPageSize,
801                schema: {
802                    //data: "ReturnedResult.ScheduleDataList",
803                    model: {
804                        id: "SpecialDataScheduleId",
805                        fields: {
806                            SpecialDataScheduleId: { editable: false, nullable: false },
807                            SubTypeName: { editable: true, nullable: false },
808                            ImagePath: { editable: true, nullable: false },
809                            DisplayFrom: { type: "date" }
810                        }
811                    }
812                },
813
814            });
815
816        $("#scheduledGrid").kendoGrid({
817            dataSource: dataSource,
818            filterable: true,
819            toolbar: [
820                { template: "<label><b>List of Special categories schedules</b></label>" }
821            ],
822            ////hide the pager control if number of records are less
823            dataBound: function (e) {
824
825                if (e.sender.dataSource.total() <= e.sender.dataSource.pageSize()) {
826                    e.sender.pager.element.hide();
827                } else {
828                    e.sender.pager.element.show();
829                }
830            },
831            noRecords: {
832                template: "No data available."
833            },
834            pageable: true,
835            //height: 250,
836            columns: [
837                {
838                    field: "SubTypeName", title: "Special Category Name", width: "120px",
839                    filterable: {
840                        cell: {
841                            operator: "contains",
842                            template: function (args) {
843                                args.element.css("width", "100%").addClass("k-textbox").keydown(function (e) {
844                                    setTimeout(function () {
845                                        $(e.target).trigger("change");
846                                    });
847                                });
848                            },
849                            showOperators: false
850                        }
851                    }
852                },
853
854                {
855                    title: "Image",
856                    width: 40,
857                    attributes: { style: "text-align:center;" },
858                    template: "<image src=\'#=ImagePath #\' style='width:30px; height:30px;' />"
859                    , filterable: false
860                },
861                //{ field: "DisplayFrom", title: "Display Date", width: "80px" },
862                {
863                    field: "DisplayFrom",
864                    title: "Display From",
865                    width: "8%",
866                    format: "{0:dd/MM/yyyy}",
867                    filterable: {
868                        operators: {
869                            date: {
870                                gte: "From Date",
871                                lte: "To Date"
872                            }
873                        },
874                        ui: function (element) {
875                            element.kendoDatePicker({
876                                format: "{0:dd/MM/yyyy}"
877                            });
878                        }
879                    },
880                    attributes: { style: "text-align:center;" },
881                    parseFormats: "{0:dd/MM/yyyy}"
882                },
883                {
884                    title: "",
885                    width: 50,
886                    attributes: { style: "text-align:center;" },
887                    template: "<input type='button' value='Delete' class='btn form-btn' onclick=\"DeleteScheduledData(\'#=SpecialDataScheduleId #\')\"></input>"
888                    , filterable: false
889                }
890
891                //{ command: ["destroy"], title: "&nbsp;", width: "45px" }
892            ],
893            editable: "inline",
894            sortable: true
895        });
896
897    }
898
899    function ReloadtheMainGrid() {
900        var grid = $("#grid").data("kendoGrid");
901        if (grid != null) {
902
903            var currentPage = grid.dataSource.page();
904            var count = grid.dataSource.view().length;
905            grid.dataSource.read();
906            if (count <= 1)
907                grid.dataSource.page(currentPage - 1);
908        }
909    }
910
911    $scope.deleteScheduledDataById = function (scheduleTypeId) {
912
913        var ScheduleDeleteDTO = {
914            ScheduleId: scheduleTypeId,
915        };
916
917        kendo.confirm("Are you sure, to delete the special category schedule?").then(function () {
918
919            //show loading animation
920            displayLoading(true);
921            var promise = PublicationSubTypeDataServices.DeleteScheduleData(ScheduleDeleteDTO, $scope.token);
922
923            promise.then(
924                function (response) {
925
926                    //hide the loading
927                    //displayLoading(false);
928                    if (response.data.Status == 0) {
929                        HideAlert('#ErrorMessageDiv');
930                        SetText('#SuccessMessageDiv', 'Deleted successfully!!');
931                        ShowAlertMessage('#SuccessMessageDiv');
932
933                        $scope.isSubTypedUpdating = true;
934
935                        if (response.data.ReturnedResult != null) {
936                            scheduledData = response.data.ReturnedResult.SpecialTypeDataToDisplay;
937                            //set the value to root scope
938                            $rootScope.specialTypeData = scheduledData;
939
940                            //refresh the roorscope variable by calling homde controller function(refresh the icon in index page)
941                            $rootScope.$emit("SetSpecialCategoryInformationMethod", {});
942
943                            //reload the grid.
944                            var grid = $("#scheduledGrid").data("kendoGrid");
945                            if (grid != null) {
946
947                                var currentPage = grid.dataSource.page();
948                                var count = grid.dataSource.view().length;
949                                grid.dataSource.read();
950
951                                if (count <= 1)
952                                    grid.dataSource.page(currentPage - 1);
953                            }
954
955                        }
956                    }
957                    else {
958                        var errMsg = response.data.ReturnedResult;
959                        if (errMsg != null) {
960                            if (errMsg.indexOf('Sub Category name is already exists') != -1) {
961
962                                HideAlert('#SuccessMessageDiv');
963                                SetText('#ErrorMessageDiv', errMsg);
964                                ShowAlertMessage('#ErrorMessageDiv');
965                            }
966                        }
967                    }
968
969                    window.scrollTo(0, 0);
970
971                    //hide the animation
972                    displayLoading(false);
973                });
974
975
976        });
977
978
979    };
980
981    $rootScope.$emit("ShowAdmininstartorMenusMethod", {});
982
983    function LoadPrivileges() {
984
985        var userId = JSON.parse(window.sessionStorage.getItem('UserId'));
986
987        if (userId) {
988            $scope.userId = userId;
989        }
990        else
991            RedirectToLogin(Constants.sessionExpiredError);
992
993        if (Constants.UserManagementFeature === 'Yes') {
994
995            var roleName = JSON.parse(window.sessionStorage.getItem('RoleName'));
996
997            if (roleName) {
998                $scope.roleName = roleName;
999            }
1000            else
1001                RedirectToLogin(Constants.NoPrivilegesError);
1002
1003            var privilgeList = JSON.parse(window.sessionStorage.getItem('Privilges'));
1004
1005            if (privilgeList) {
1006                $scope.privilgeList = privilgeList;
1007            }
1008            else
1009                RedirectToLogin(Constants.NoPrivilegesError);
1010        }
1011    }
1012
1013    function ValidatePrivilege() {
1014
1015        var privilegeMatch = [];
1016
1017        //validate the privilege and stope loading the data to the user if no privilege.
1018        if ($scope.privilgeList) {
1019
1020            angular.forEach($scope.adminPrivileges, function (item) {
1021
1022                var privContains = altFind($scope.privilgeList, function (e) {
1023                    return e.includes(item);
1024                });
1025
1026                if (privContains)
1027                    privilegeMatch.push(true);
1028                else
1029                    privilegeMatch.push(false);
1030            });
1031
1032            $scope.hasAccess = privilegeMatch.includes(true);
1033        }
1034    }
1035
1036    function RedirectToLogin(errorMessage) {
1037
1038        $rootScope.LoginErrorMessage = errorMessage;
1039        $rootScope.MessageType = 'Error';
1040        $rootScope.hideAdminMenu = true;
1041
1042        //redirect to login page.
1043        $location.path('/login');
1044    }
1045
1046});

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.