PageSourceSearch

https://support.rowriter.com/App/Components/Ticket/CreateTicket/cr…?4c1d8c0889036fa46948aefb7a2c4e20

js rowriter.com collected 2026-09-29 02:44:19 UTC 10,427 bytes, 252 lines download raw bytes

1app.controller('createTicketController', ['$scope', '$rootScope', '$window', '$http', '$state', '$timeout', '$location', 'Upload', 'ticketService', 'kbFactory', 'vcRecaptchaService', function ($scope, $rootScope, $window, $http, $state, $timeout, $location, Upload, ticketService, kbFactory, vcRecaptchaService) {
2    $scope.DeflectionResults;
3    $scope.ticket = {};
4    $scope.files = [];
5    $scope.associatedContactAddressList = [];
6    $scope.ticketSubmitting = true;
7    $scope.recaptchaWidgetID = null;
8
9    if ($rootScope.UserInfo.portalViewOnly) {
10        $window.location.href = '/dashboard';
11    }
12
13    ticketService.getOrgTicketInfo(function (data) {
14        $scope.orgTicketInfo = data;
15        $scope.ticket.TicketTypeID = $scope.settings.Features.DefaultTicketTypeID;
16        $scope.ticket.GroupID = $scope.settings.Features.EnableTicketGroupSelection ? $scope.settings.Features.DefaultGroupTypeID : null;
17        if ($scope.orgTicketInfo.DropdownCollection[0].DropdownItems.length == 1) {
18            $scope.ticket.ProductID = $scope.orgTicketInfo.DropdownCollection[0].DropdownItems[0].ID;
19        }
20        SetupWatchers();
21    });
22
23    $scope.submitNewTicket = function (ticket) {
24        ticket.UserInfo = $rootScope.UserInfo;
25        ticket.AssociatedContactAddressList = [];
26        for (var i = 0; i < $scope.associatedContactAddressList.length; i++) {
27            ticket.AssociatedContactAddressList.push($scope.associatedContactAddressList[i].text);
28        }
29
30        $scope.ticketForm.$setSubmitted();
31        if ($scope.ticketForm.$error.recaptcha) {
32            alert('Please complete the captcha verification.');
33        }
34
35        angular.forEach($scope.ticketForm.$error, function (error) {
36            angular.forEach(error, function (errorField) {
37                if (errorField) {
38                    errorField.$touched = true;
39                    errorField.$dirty = true;
40                }
41            });
42        });
43
44        if ($scope.ticketForm.$invalid) return false;
45
46        $scope.ticketSubmitting = true;
47
48        ticketService.createNewTicket(ticket, function (data) {
49            if (data === 'negative' || !data || data.ErrorMessage) {
50                alert(data?.ErrorMessage || 'The ticket could not be created.');
51                $scope.ticketSubmitting = false;
52
53                if ($scope.recaptchaWidgetID !== null)
54                    vcRecaptchaService.reload($scope.recaptchaWidgetID);
55            }
56            else {
57                if ($scope.files.length > 0) {
58                    $scope.uploadFiles($scope.files, data.ActionID, function (e) {
59                        if ($location.$$path == "/createticket" && $scope.settings.UserInfo.isAuthenticated) {
60                            $state.go('standard.ticket', { ticket: data.TicketNumber });
61                        }
62                        else {
63                            $scope.ticketCreatedSuccess = true;
64                            $scope.clearTicket();
65                        }
66                    });
67                }
68                else {
69                    if ($location.$$path == "/createticket" && $scope.settings.UserInfo.isAuthenticated) {
70                        $state.go('standard.ticket', { ticket: data.TicketNumber });
71                    }
72                    else {
73                        $scope.ticketCreatedSuccess = true;
74                        $scope.clearTicket();
75                    }
76                }
77            }
78        });
79    };
80
81    $scope.closeModal = function () {
82        $scope.ticketCreatedSuccess = false;
83        $window.location.href = '/dashboard';
84    };
85
86    $scope.clearTicket = function () {
87        $scope.ticket = {};
88        $scope.ticketForm.$setUntouched();
89        $scope.ticketForm.$setPristine();
90        if ($scope.recaptchaWidgetID !== null)
91            vcRecaptchaService.reload($scope.recaptchaWidgetID);
92        $scope.ticketSubmitting = false;
93    };
94
95    $scope.getCustomFields = function (ticket) {
96        $scope.ticketSubmitting = true;
97        if (ticket !== undefined) {
98            var productID = (ticket.ProductID == undefined || ticket.ProductID == null) ? -1 : ticket.ProductID;
99            var ticketTypeID = (ticket.TicketTypeID == undefined) ? -1 : ticket.TicketTypeID;
100            ticketService.getCustomFields(ticketTypeID, productID, function (data) {
101                $scope.ticket.CustomFields = data;
102                $scope.ticketSubmitting = false;
103            });
104
105        }
106    };
107
108    $scope.loadTemplateByTicketTypeAndProduct = function (ticket, productChanged) {
109        if ($scope.orgTicketInfo.TicketTemplates != null) {
110            for (i = 0; i < $scope.orgTicketInfo.TicketTemplates.length; i++) {
111                let ticketTemplate = $scope.orgTicketInfo.TicketTemplates[i];
112                if (ticketTemplate.TemplateType == 0 && ticketTemplate.TicketTypeID == ticket.TicketTypeID) {
113                    if (ticketTemplate.TriggerFromProducts) {
114                        if (!productChanged) {
115                            continue;
116                        }
117
118                        if (ticketTemplate.Products.length === 0) {
119                            if (ticket.ProductID) {
120                                continue;
121                            }
122                        } else if (ticketTemplate.Products.indexOf(ticket.ProductID) == -1) {
123                            continue;
124                        }
125                    } else {
126                        if (productChanged) {
127                            continue;
128                        }
129                    }
130
131                    ticket.Description += '<br>' + ticketTemplate.TemplateText;
132                }
133            }
134        }
135    };
136
137    $scope.loadTemplateByDropdownValue = function (customValue) {
138        if ($scope.orgTicketInfo.TicketTemplates) {
139            for (i = 0; i < $scope.orgTicketInfo.TicketTemplates.length; i++) {
140                if ($scope.orgTicketInfo.TicketTemplates[i].TriggerText === customValue && $scope.orgTicketInfo.TicketTemplates[i].TemplateType === 1) {
141                    $scope.ticket.Description += '<br>' + $scope.orgTicketInfo.TicketTemplates[i].TemplateText;
142                }
143            }
144        }
145    };
146
147    $scope.ShowKBDeflection = function (Ticket) {
148        $scope.ActiveDeflection = Ticket;
149        $("#deflectionKBModal").modal('show');
150    };
151
152    $scope.validateEmailTag = function (tag) {
153        var emailRegEx = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
154        return emailRegEx.test(tag.text);
155    };
156
157    $scope.LogAnswer = function (WasHelpful) {
158        var deflectionResult = { Helpful: WasHelpful, TicketID: $scope.ActiveDeflection.Article.TicketID };
159        ticketService.logDeflectionResponse(deflectionResult, function (data) {
160            if (WasHelpful) {
161                $('#deflectionKBModal').on('hidden.bs.modal', function (event) {
162                    $state.go('standard.dashboard');
163                });
164            }
165        });
166    };
167
168    $scope.addFiles = function (files) {
169        $scope.files = $scope.files.concat(files);
170    };
171
172    $scope.uploadFiles = function (files, actionID, callback) {
173        if (files && files.length) {
174            Upload.upload({
175                url: '../../api/ticket/UploadFiles',
176                data: { files: files, actionID: actionID }
177            }).then(function (response) {
178                $timeout(function () {
179                    $scope.result = response.data;
180                    callback();
181                });
182            }, function (response) {
183                if (response.status > 0) {
184                    $scope.errorMsg = response.status + ': ' + response.data;
185                }
186            }, function (evt) {
187                $scope.progress =
188                    Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
189            });
190        }
191    };
192
193    $scope.deleteFile = function (idx) {
194        $scope.files.splice(idx, 1);
195    };
196
197    function SetupWatchers() {
198        //Move watch events into funciton to get executed after we setup defaults on page load.
199        $scope.$watch('ticket.ProductID', function () {
200            if ($scope.ticket !== undefined) {
201                $scope.loadTemplateByTicketTypeAndProduct($scope.ticket, true);
202                $scope.getCustomFields($scope.ticket);
203                var productID = $scope.ticket.ProductID;
204                if (productID !== undefined && productID !== null) {
205                    ticketService.getVersions(productID, function (data) {
206                        $scope.versions = data;
207                        if (data != null && data.length == 1) {
208                            $scope.ticket.VersionID = data[0].ProductVersionID;
209                        }
210                        else {
211                            $scope.ticket.VersionID = null;
212                        }
213                    });
214                }
215                else $scope.versions = {};
216            }
217        });
218
219        $scope.$watch('ticket.TicketTypeID', function () {
220            if ($scope.ticket !== undefined) {
221                $scope.loadTemplateByTicketTypeAndProduct($scope.ticket, false);
222                $scope.getCustomFields($scope.ticket);
223            }
224        });
225
226        var inputChangedPromise;
227        $scope.$watch('ticket.Description', function () {
228            if (inputChangedPromise) {
229                $timeout.cancel(inputChangedPromise);
230            }
231            inputChangedPromise = $timeout(function () {
232                var searchText = $scope.ticket.Description.replace(/<\/?[^>]+(>|$)/g, " ").replace("&nbsp;", " ");
233                //var searchText = $(encodedText).text();
234                if (searchText !== "") {
235                    ticketService.getDeflectionResults(searchText, function (data) {
236                        $scope.DeflectionResults = data;
237                    });
238                }
239            }, 1000);
240        });
241
242    }
243
244    $scope.downloadKBAttachment = function (kbID, attachment) {
245        kbFactory.downloadAttachment(kbID, attachment);
246    };
247
248    $scope.SetRecaptchaWidgetID = function (widgetID) {
249        $scope.recaptchaWidgetID = widgetID;
250    };
251
252}]);

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.