PageSourceSearch

https://pipelbiz.com/js/controller/cmpUpdateCtrl.js?ver=1761830182

js pipelbiz.com collected 2026-09-26 11:49:48 UTC 12,553 bytes, 313 lines download raw bytes

1pipelbizControllers.controller('cmpUpdateCtrl', [
2    'campaignService',
3    'campaign',
4    '$scope',
5    '$stateParams',
6    '$filter',
7    '$timeout',
8    'uploadService',
9    '$state',
10    function DashboardCtrl(campaignService, campaign, $scope, $stateParams, $filter, $timeout, uploadService, $state) {
11
12        $scope.campaign = campaign;
13
14        // nfc_type: normal, periodic, value_update, convention_invite, convention_protocol
15        $scope.dash_nfc_type = "normal";
16
17        $scope.dash_nfc_title = "";
18        $scope.dash_nfc_message = "";
19
20        // value_update type
21        $scope.dash_nfc_new_company_value = "";
22        $scope.dash_nfc_new_stock_value = "";
23
24        // convention_invite type
25        $scope.dash_nfc_meeting_date = "";
26        $scope.dash_nfc_meeting_time = "";
27        $scope.dash_nfc_meeting_address_st = "";
28        $scope.dash_nfc_meeting_address_num = "";
29        $scope.dash_nfc_meeting_address_city = "";
30        $scope.dash_nfc_meeting_agenda = "";
31        $scope.dash_nfc_meeting_link = "";
32
33        $scope.dashUpdateAssetsArray = [];
34        $scope.creatingNotification = false;
35
36        $scope.dash_nfc_test_mail = "";
37        $scope.dash_nfc_from_mail = "";
38
39        $scope.doneTestEmail = false;
40        $scope.testMailResponse = "";
41
42        $scope.uniqueEmails = [];
43        $scope.totalEmails = [];
44        $scope.wrongEmails = [];
45        $scope.duplicateEmails = [];
46
47
48        $scope.notificationArraySectionNameDB = "nfc_assets_section_files";
49
50        $scope.dashNewUpdatePreview = function () {
51            $scope.appDetails.previewText = tinymce.get("nfc_message").getContent();
52
53            $("#previewModal").modal();
54        };
55
56        $scope.dashAddNotificationFile = function () {
57            var idx = $scope.dashUpdateAssetsArray.length;
58            var nfcAssetObj = new Object();
59            nfcAssetObj.inputFileName = $scope.notificationArraySectionNameDB + "_" + String(idx);
60            nfcAssetObj.inputFileDescriptionId = $scope.notificationArraySectionNameDB + "_description_" + String(idx);
61
62            $scope.dashUpdateAssetsArray.push(nfcAssetObj);
63        };
64
65        $scope.dashRemoveNotificationFile = function (ngRepeatElementIndex) {
66            var ngElementIndex = Number(ngRepeatElementIndex);
67
68            $scope.dashUpdateAssetsArray.splice(ngElementIndex, 1);
69        };
70
71
72        $scope.createNotification = async function (testMail) {
73
74            var campaign = $scope.campaign;
75            if (!campaign) {
76                return;
77            }
78            if (testMail == "send") {
79                if (!$scope.doneTestEmail) {
80                    $("#testMailModal").modal("show");
81                    return;
82                }
83                $scope.creatingNotification = true;
84                $(".sendingBtn").text("שולח עדכון...");
85                $("#sentModal").modal("show");
86            } else {
87                if ($scope.nfc_test_mail == "") {
88                    $scope.testMailResponse = "אנא הכנס כתובת מייל תקינה";
89                    return;
90                }
91                if (!pipelbiz.helpers.validateEmail($scope.nfc_test_mail)) {
92                    $scope.testMailResponse = "אנא הכנס כתובת מייל תקינה";
93                    return;
94                } else {
95                    $scope.testMailResponse = "";
96                }
97                $scope.doneTestEmail = true;
98            }
99
100            $("#notification_status").text("");
101
102            var fd = new FormData();
103            fd.append("oper", "createNotification");
104
105            var len = $scope.dashUpdateAssetsArray.length;
106            var sectionFilesArrayName = $scope.notificationArraySectionNameDB + "[]";
107
108            let uploadPromiseList = [];
109            let finalResult = []
110            for (i = 0; i < len; i++) {
111                var inputId = $scope.dashUpdateAssetsArray[i].inputFileName;
112
113                $.each(document.getElementById(inputId).files, async function (key, value) {
114
115                    const promise = uploadService.uploadDocumentAsset(value, "cmp_not_" + campaign.cmp_id);
116                    uploadPromiseList.push(promise);
117                    const uploadPath = await promise;
118                    finalResult.push(uploadPath);
119                    //fd.append(sectionFilesArrayName, uploadPath);
120                });
121            }
122
123            //await Promise.all(uploadPromiseList);
124            await Promise.all(uploadPromiseList).then(results => {
125                // log the final results
126                $.each(results, async function (key, value) {
127                    fd.append(sectionFilesArrayName, value);
128                })
129            }).catch(e => {
130                console.log(e);
131            });
132            fd.append("cmp_id", campaign.cmp_id);
133            fd.append("nfc_type", $scope.dash_nfc_type);
134            if ($scope.dash_nfc_type === 'normal' || $scope.dash_nfc_type === 'periodic') {
135                fd.append("nfc_title", $scope.dash_nfc_title);
136            } else if ($scope.dash_nfc_type === 'value_update') {
137                fd.append("nfc_new_company_value", $scope.dash_nfc_new_company_value);
138                fd.append("nfc_new_stock_value", $scope.dash_nfc_new_stock_value);
139            } else if ($scope.dash_nfc_type === 'convention_invite') {
140                fd.append("nfc_meeting_date", $scope.dash_nfc_meeting_date);
141                fd.append("nfc_meeting_time", $scope.dash_nfc_meeting_time);
142                fd.append("nfc_meeting_address_st", $scope.dash_nfc_meeting_address_st);
143                fd.append("nfc_meeting_address_num", $scope.dash_nfc_meeting_address_num);
144                fd.append("nfc_meeting_address_city", $scope.dash_nfc_meeting_address_city);
145                fd.append("nfc_meeting_agenda", $scope.dash_nfc_meeting_agenda);
146                fd.append("nfc_meeting_link", $scope.dash_nfc_meeting_link);
147            }
148            // fd.append("csv", []);
149
150            fd.append("csv", $scope.uniqueEmails);
151            if (testMail == "test") {
152                fd.append("nfc_test_mail", $scope.nfc_test_mail);
153                fd.append("nfc_fname", $scope.userDetails.usr_fname);
154                fd.append("nfc_lname", $scope.userDetails.usr_lname);
155                fd.append("nfc_cmp_name", campaign.cmp_name);
156            }
157
158            try {
159                fd.append("nfc_message", tinymce.get("nfc_message").getContent());
160            } catch (err) {
161                console.log("returning, editor not load yet");
162                $scope.creatingNotification = false;
163                return;
164            }
165            $scope.appDetails.previewText = tinymce.get("nfc_message").getContent();
166
167            //prepare file description array:
168            var assetDescriptionArray = new Array();
169            len = $scope.dashUpdateAssetsArray.length;
170            for (i = 0; i < len; i++) {
171                var desciptionDivId = $scope.dashUpdateAssetsArray[i].inputFileDescriptionId;
172
173                var desc = $(String("#" + desciptionDivId)).val();
174
175                if (desc == undefined || desc == null) {
176                    desc = "";
177                }
178
179                //text is converted in order for the chars to appear correctly
180                desc = pipelbiz.helpers.ConvertToSpecialCharacters(desc);
181
182                assetDescriptionArray.push(desc);
183            }
184
185            fd.append("nfc_description_array", JSON.stringify(assetDescriptionArray));
186            // $.each(finalResult, async function (key, value) {
187            //   fd.append(sectionFilesArrayName, JSON.stringify(value));
188            // })
189
190            if (testMail == "send") {
191                // setTimeout(() => {
192                //   location.href = "thanks/reg";
193                // }, 5000);
194            } else {
195                $scope.testMailResponse = "מייל בדיקה נשלח בהצלחה";
196                $scope.dash_nfc_test_mail = "";
197                setTimeout(function () {
198                    $scope.testMailResponse = "";
199                    $scope.$apply();
200                }, 3000);
201            }
202
203            if (campaign.cmp_group_name != "") {
204                fd.append("cmp_group_name", campaign.cmp_group_name);
205            }
206            // return;
207            $.ajax({
208                url: api_url + "notification.php",
209                data: fd,
210                type: "post",
211                processData: false,
212                contentType: false,
213                success: function (output) {
214                    if (output == "") return;
215
216
217                    if (output.alert_type == "alert-success") {
218                        console.log("ajax call success. output: ");
219                        console.log(output);
220                    } else {
221                        console.log("ajax call failure. output: ");
222                        console.log(output);
223                        $scope.creatingNotification = false;
224                    }
225                    if (testMail == "test") {
226                        $("#notification_status").text(output.msg);
227                    }
228
229                },
230            });
231        };
232
233
234        //var fileInput = document.getElementById("csv")
235        $scope.onlyUnique = function (value, index, self) {
236            return self.indexOf(value) === index;
237        };
238
239        $scope.getDuplicateArrayElements = function (arr) {
240            var sorted_arr = arr.slice().sort();
241            var results = [];
242            for (var i = 0; i < sorted_arr.length - 1; i++) {
243                if (sorted_arr[i + 1] === sorted_arr[i]) {
244                    results.push(sorted_arr[i]);
245                }
246            }
247            return results;
248        };
249
250        $scope.file;
251        $scope.resetFileUpload = function () {
252            $scope.uniqueEmails = [];
253            $scope.totalEmails = [];
254            $scope.wrongEmails = [];
255            $scope.duplicateEmails = [];
256            $("#csv").val("");
257        };
258
259        $scope.gifLoader = false;
260        $scope.notCsv = "";
261        $scope.readFile = function () {
262            var reader = new FileReader();
263            var fileInput = document.getElementById("csv");
264            reader.onload = function () {
265                $scope.allCells = [];
266                $scope.totalEmails = [];
267                $scope.wrongEmails = [];
268                $scope.uniqueEmails = [];
269                $scope.duplicateEmails = [];
270                $scope.gifLoader = true;
271                if (fileInput.files[0].type == "application/vnd.ms-excel" || fileInput.files[0].type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || fileInput.files[0].type == "text/csv") {
272                    $scope.notCsv = "";
273                    const arr = reader.result.split("\r\n");
274
275                    for (i = 0; i < arr.length; i++) {
276                        var y = arr[i].split(",");
277                        for (j = 0; j < y.length; j++) {
278                            const stripSlashesFromCell = y[j].replace(/["]+/g, "");
279                            $scope.allCells.push(stripSlashesFromCell);
280                        }
281                    }
282
283                    for (i = 0; i < $scope.allCells.length; i++) {
284                        if (!pipelbiz.helpers.validateEmail($scope.allCells[i])) {
285                            if ($scope.allCells[i] == "\n" || $scope.allCells[i].trim().length == 0) {
286                                continue;
287                            }
288                            $scope.wrongEmails.push($scope.allCells[i]);
289                        } else {
290                            $scope.totalEmails.push($scope.allCells[i]);
291                        }
292                    }
293                    $scope.uniqueEmails = $scope.totalEmails.filter($scope.onlyUnique);
294                    $scope.duplicateEmails = $scope.getDuplicateArrayElements($scope.totalEmails);
295                    console.log($scope.uniqueEmails);
296                    //console.log($scope.wrongEmails);
297                } else {
298                    $scope.gifLoader = false;
299                    $scope.notCsv = "המסמך אינו קובץ CSV תקין";
300                    $scope.totalEmails = [];
301                    $scope.wrongEmails = [];
302                    $scope.uniqueEmails = [];
303                    $scope.$apply();
304                    return;
305                }
306                $scope.gifLoader = false;
307                $scope.$apply();
308            };
309            reader.readAsText(fileInput.files[0]);
310        };
311
312    },
313]);

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.