PageSourceSearch

https://askthescholar.com/Template/UnSpamQuestions/unSpamDataController.js

js askthescholar.com collected 2026-10-02 22:01:21 UTC 8,480 bytes, 219 lines download raw bytes

1AskTheScholarApp.controller("unSpamDataController", function ($location, $rootScope, $scope, $http, $window, unSpamDataServices, AppConstant, AskTheScholarAPIStrings, Constants) {
2
3
4    //form load check whether the token is present in cache. if yes, allow the user to 
5    //go to dashboard.
6    var token = data = JSON.parse(window.sessionStorage.getItem('token'));
7    var expiresAt = JSON.parse(window.sessionStorage.getItem('expiresAt'));
8    var userName = JSON.parse(window.sessionStorage.getItem('UserName'));
9
10    if (token == null || token == undefined
11        || expiresAt == null || expiresAt == undefined
12        || userName == null || expiresAt == userName) {
13
14        $rootScope.LoginErrorMessage = Constants.loginTokenEmptyError;
15        $rootScope.MessageType = Constants.Error;
16
17        //redirect to login page.
18        $location.path('/login');
19    }
20    else {
21
22        //we have the token in cache. but check whether its still valid or not
23        //by checking the expiry datetime.
24        if (IsTokenValid(moment(expiresAt))) {
25
26            //store it in scope.
27            $scope.token = token;
28            $scope.expiresAt = expiresAt;
29            $scope.LoggedInUserName = userName;
30        }
31        else {
32            RedirectToLogin(Constants.sessionExpiredError)
33        }
34    }
35
36    //clear the querystring if any.
37    $location.url($location.path());
38
39    //hide error & success messages.
40    HideAlert('#SuccessMessageDiv');
41    HideAlert('#ErrorMessageDiv');
42
43    //bind grid
44    BindSpamGrid();
45
46    function BindSpamGrid() {
47
48        var RouteURL = AppConstant.BaseServiceURL;
49
50        var getSpamDataURL = RouteURL + AskTheScholarAPIStrings.GetSpammedQuestion + '/' + Constants.WebCustomerId,
51
52            dataSource = new kendo.data.DataSource({
53                transport: {
54                    read: {
55                        url: getSpamDataURL,
56                        contentType: "application/json",
57                        type: 'GET',
58                        beforeSend: function (req) {
59                            req.setRequestHeader('Authorization', 'Bearer ' + token);
60                        }
61                    }
62                },
63                batch: true,
64                pageable: true,
65                pageSize: Constants.GridPageSize,
66                schema: {
67
68                    data: "ReturnedResult.SpamedQuestions",
69                    total: "ReturnedResult.itemCount",
70                    model: {
71                        id: "QAId",
72                        fields: {
73                            QAId: { editable: false, nullable: false },
74                            Question: { editable: true, nullable: false },
75                            UserName: { editable: true, nullable: false },
76                            UserEmail: { editable: true, nullable: false }
77                        }
78                    }
79                },
80
81            });
82
83        $("#grid").kendoGrid({
84            dataSource: dataSource,
85            //hide the pager control if number of records are less
86            dataBound: function (e) {
87
88                if (e.sender.dataSource.total() <= e.sender.dataSource.pageSize()) {
89                    e.sender.pager.element.hide();
90                } else {
91                    e.sender.pager.element.show();
92                }
93            },
94            noRecords: {
95                template: "No data available."
96            },
97            toolbar: [
98                { template: "<label><b>&nbsp;Spammed questions list</b></label>" }
99            ],
100            pageable: true,
101            //height: '100%',
102            columns: [
103                //{ field: "ResourceId", title: "Resource Id", width: "30px" },
104                {
105                    field: "UserName", title: "User Name", width: "10%",
106                    filterable: {
107                        cell: {
108                            operator: "contains",
109                            template: function (args) {
110                                args.element.css("width", "100%").addClass("k-textbox").keydown(function (e) {
111                                    setTimeout(function () {
112                                        $(e.target).trigger("change");
113                                    });
114                                });
115                            },
116                            showOperators: false
117                        }
118                    }
119                },
120                {
121                    field: "UserEmail", title: "User Email Id", width: "10%",
122                    filterable: {
123                        cell: {
124                            operator: "contains",
125                            template: function (args) {
126                                args.element.css("width", "100%").addClass("k-textbox").keydown(function (e) {
127                                    setTimeout(function () {
128                                        $(e.target).trigger("change");
129                                    });
130                                });
131                            },
132                            showOperators: false
133                        }
134                    }
135                },
136                {
137                    field: "Question", title: "Question", width: "40%",
138                    filterable: {
139                        cell: {
140                            operator: "contains",
141                            template: function (args) {
142                                args.element.css("width", "100%").addClass("k-textbox").keydown(function (e) {
143                                    setTimeout(function () {
144                                        $(e.target).trigger("change");
145                                    });
146                                });
147                            },
148                            showOperators: false
149                        }
150                    }
151                },
152                {
153                    title: "",
154                    width: '10%',
155                    attributes: { style: "text-align:center;" },
156                    template: "<button type='button' class='form-btn_ForGrid'  onclick=\"UnSpamQuestion(\'#=QAId #\')\">UnSpam</button> "
157                    , filterable: false
158                }
159            ],
160            editable: "popup",
161            filterable: true
162        });
163
164    }
165
166    $scope.UnSpamQuestion = function (questionId) {
167        kendo.confirm("Are you sure, to unSpam the question").then(function () {
168
169            displayLoading(true);
170            var questionData = {
171                questionId: questionId
172            };
173
174            var promise = unSpamDataServices.UnSpamQuestion(questionData, $scope.token);
175
176            promise.then(
177                function (response) {
178                    //hide the loading
179                    displayLoading(false);
180
181                    if (response.data.Status == 0) {
182
183                        //show this success message in base page's success div
184                        //response.data.ReturnedResult //this contains the success message
185
186                        HideAlert('#ErrorMessageDiv');
187
188                        SetText('#SuccessMessageDiv', response.data.ReturnedResult);
189                        ShowAlertMessage('#SuccessMessageDiv');
190
191                        //reload the grid.
192                        var grid = $("#grid").data("kendoGrid");
193                        if (grid != null) {
194                            var currentPage = grid.dataSource.page();
195                            var count = grid.dataSource.view().length;
196                            grid.dataSource.read();
197                            if (count <= 1)
198                                grid.dataSource.page(currentPage - 1);
199                        }
200                    }
201                    else {
202                        SetText('#ErrorMessageDiv', Constants.technicalError);
203                        ShowAlertMessage('#ErrorMessageDiv');
204                    }
205                })
206
207        });
208    }
209
210    function RedirectToLogin(errorMessage) {
211
212        $rootScope.LoginErrorMessage = errorMessage;
213        $rootScope.MessageType = 'Error';
214        $rootScope.hideAdminMenu = true;
215
216        //redirect to login page.
217        $location.path('/login');
218    }
219});

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.