PageSourceSearch

https://telemach.hr/js/binom/angular.contact-forms.js?cb=1.0.0.214…1UxIlmP3Wx46CsqoO2A2q3K63zx6YZvRWgC9hZZbS34

js telemach.hr collected 2026-10-02 05:53:10 UTC 12,283 bytes, 350 lines download raw bytes

1;
2app.controller('contact-forms', function ($scope, $http, $timeout) {
3
4    $scope.model = {
5        request: {
6            reCaptchaResponse: '',
7            leadType: 'SupportContactForm',
8            userType: 'Postpaid',
9            contentCategoryID: 0,
10            genericFields: {},
11            fileUpload: {},
12        },
13        forms: { 
14            documentData: '',
15            documentType: '',
16            documentFilename: '',
17            fileList: [],
18        }
19    };
20
21    $scope.local = {
22        loading: false,
23        showResponse: false,
24        errorMessage: '',
25        validationErrors: [],
26        localizationDict: {},
27        genericFields: {},
28        isFormValid: false,
29        mandatoryFields: [],
30    };
31    $scope.fileUploadLocalization = '';
32    // API
33    $scope.api = {};
34
35    // EVENTS
36    $scope.events = {};
37
38    $scope.events.init = function (leadType, userType, categoryId, mandatoryFields) {
39        $scope.model.request.leadType = leadType;
40        $scope.model.request.userType = userType;
41        $scope.model.request.contentCategoryID = categoryId;
42        $scope.local.mandatoryFields = (mandatoryFields || '').split(',').filter(function (xx) { return xx.length > 0; });
43    };
44
45    $scope.events.onSubmit = function () {
46        $scope.local.loading = true;
47        try {
48            grecaptcha.ready(function () {
49                grecaptcha.execute(window.captchaSiteKey, { action: 'submit' })
50                    .then(function (token) {
51                        $scope.fn.submitOrder(token);
52                    });
53            });
54        }
55        catch (error) {
56            $scope.local.loading = false;
57        }
58    };
59
60    $scope.events.onfileUpload = function (data) {
61        if (data && data.files && data.files.length > 0) {
62            var file = data.files[0];
63            const MAX_FILE_SIZE = 10 * 1024 * 1024;
64
65            if (file.size > MAX_FILE_SIZE) {
66                $("#file-upload").parent().addClass("error-text");
67                $("#file-upload").next().html("File size exceeds the maximum limit.");
68                return;
69            }
70
71            $scope.fn.getBase64(file, function () {
72                $("#file-upload").next().html(file.name); 
73                $("#file-upload").parent().removeClass("error-text");
74            });
75
76            $("#file-upload").next().html(file.name);
77            $("#file-upload").parent().removeClass("error-text");
78
79        } else {
80            $("#file-upload").next().html($scope.local.localizationDict || "No file selected.");
81            $("#file-upload").parent().addClass("error-text");
82        }
83    };
84
85    $scope.events.hideFileChosenMessage = function (element) {
86        element.setAttribute('title', '');
87    };
88
89    // FUNCTIONS
90    $scope.fn = {};
91
92    $scope.fn.handleFileChange = function (event, fieldName) {
93        const file = event.target.files[0];
94        if (file) {
95            $scope.currentFileFieldKey = fieldName;
96            $scope.fn.getBase64(file, function () {
97                $scope.fn.updateFormValidity();
98            });
99        }
100    };
101
102    $scope.fn.getBase64 = function (file, callback) {
103        var reader = new FileReader();
104        reader.readAsDataURL(file);
105        reader.addEventListener("load", function () {
106            let base64Data = reader.result.split('base64,')[1];
107            if ($scope.model.request.genericFields) {
108                const fieldKey = $scope.currentFileFieldKey || "fileUpload";
109                if (!fieldKey) {
110                    //console.error("Field key is missing for file upload.");
111                    return;
112                }
113
114                $scope.model.request.genericFields[fieldKey] = {
115                    value: base64Data,
116                    documentType: file.type,
117                    documentFilename: file.name
118                };
119
120                callback();
121            } else {
122                //console.error("genericFields is undefined in the model.");
123            }
124        }, false);
125    };
126
127
128    $scope.fn.submitOrder = function (token) {
129        $scope.local.loading = true;
130        $scope.local.errorMessage = '';
131
132        let isValid = $scope.fn.validateFields();
133        if (!isValid) {
134            $scope.$apply();
135            $scope.local.loading = false;
136            return;
137        }
138
139        $scope.local.validationErrors = [];
140        let generics = [];
141
142        for (const [key, fieldData] of Object.entries($scope.model.request.genericFields)) {
143            if (fieldData) {
144                let fieldValue = fieldData; 
145
146                if (fieldData.documentFilename) {
147                    generics.push({
148                        label: key,
149                        documentFilename: fieldData.documentFilename,
150                        documentType: fieldData.documentType,
151                        value: fieldData.value
152                    });
153                }
154                else {
155                    generics.push({
156                        label: key,
157                        value: fieldValue
158                    });
159                }
160            }
161        }
162
163        let request = structuredClone($scope.model.request);
164        request.reCaptchaResponse = token;
165        request.genericFields = generics;
166
167        $http({
168            url: '/api/ECommerce/SubmitOrder',
169            method: 'POST',
170            data: request
171        }).then(function (response) {
172            
173            if (response && response.status === 200 && response.data) {
174                if (response.data.success) {
175
176                    $scope.local.loading = false;
177                    $scope.local.showResponse = true;
178                    $scope.model.request = {};
179
180                    if (response.data.redirectUrl) {
181                        $scope.local.loading = true;
182                        window.location.href = response.data.redirectUrl;
183                    }
184                }
185                else {
186                    $scope.local.loading = false;
187                    $scope.local.showResponse = false;
188                    $scope.local.errorMessage = response.data.clientMessage;
189                }
190            }
191        }, function () {
192            $scope.local.isLoading = false;
193            $scope.local.errorMessage = 'Došlo je do pogreške, molimo pokušajte ponovno.';
194        });
195    };
196
197    $scope.fn.validateFields = function () {
198
199        let isValid = true;
200
201        //for (var i = 0; i < $scope.request.length; i++) {
202        //    isValid = $scope.fn.isValidNotEmpty($scope.model.request.phone, $scope.local.localizationDict["Form.General.Label.PhoneNumber"]) && isValid;
203        //}
204
205        //isValid = $scope.fn.isValidNotEmpty($scope.model.request.genericFields[type]) && isValid;
206        //isValid = $scope.fn.isValidEmail($scope.model.request.genericFields[type]) && isValid;
207        //isValid = isValidDocument() && isValid;
208
209        if (!isValid) {
210            $timeout(function () {
211                $scope.$apply();
212            });
213        }
214        
215
216        return isValid;
217    };
218
219    $scope.fn.updateFormValidity = function () {
220        let isValid = true;
221        let mandatory = $scope.local.mandatoryFields || [];
222
223        for (let key in $scope.model.request.genericFields) {
224            let value = $scope.model.request.genericFields[key];
225            let fieldName = key.slice(0, -2).replace('_', ' ');
226
227            if (mandatory.indexOf(key) < 0) {
228                $scope.fn.setError("Polje je obavezno", true, fieldName);
229                continue;
230            }
231
232            if (!value || value.length === 0) {
233                isValid = false;
234                $scope.fn.setError("Polje je obavezno", false, fieldName);
235            } else {
236                $scope.fn.setError("Polje je obavezno", true, fieldName);
237            }
238        }
239
240        $scope.local.isFormValid = isValid;
241
242        if (!$scope.local.isFormValid) {
243            $timeout(function () {
244                $scope.$apply();
245            });
246        }
247        
248    };
249
250    $scope.fn.isValidNotEmpty = function (value, fieldName) {
251        let errorText = "Polje je obavezno"; // $scope.local.localizationDict["Message.ValidationError.InformationRequired"];
252        let isValid = value && value.length > 0;
253
254        $scope.fn.setError(errorText, isValid, fieldName[0]);
255        $scope.fn.updateFormValidity();
256        return isValid;
257    };
258
259    $scope.fn.isValidEmail = function (email, fieldName) {
260        let errorText = "Polje je obavezno"; // $scope.local.localizationDict["Message.ValidationError.InvalidEmailFormat"];
261        let isValid = email && email.isValidMail();
262
263        $scope.fn.setError(errorText, isValid, fieldName[0]);
264        $scope.fn.updateFormValidity();
265        return isValid;
266    };
267
268    $scope.fn.isValidNotEmptyCheckbox = function (value, fieldName) {
269        let errorText = "Polje je obavezno"; // $scope.local.localizationDict["Message.ValidationError.InformationRequired"];
270        let isValid = value && value !== "";
271        
272        $scope.fn.setError(errorText, isValid, fieldName[0]);
273        $scope.fn.updateFormValidity();
274        return isValid;
275    };
276
277    $scope.fn.isValidPhoneNumber = function (value, fieldName) {
278        let errorText = "Polje je obavezno"; // $scope.local.localizationDict["Message.ValidationError.PhoneNotValid"];
279        let isValid = value && value.isValidPhoneFormat();
280
281        $scope.fn.setError(errorText, isValid, fieldName[0]);
282        $scope.fn.updateFormValidity();
283        return isValid;
284    };
285
286    $scope.fn.isValidSubjectDropdown = function (value, fieldName) {
287        let errorText = "Polje je obavezno";
288        let isValid = value && value.length > 0;
289        $scope.fn.setError(errorText, isValid, fieldName[0]);
290        $scope.fn.updateFormValidity();
291        return isValid;
292    };
293
294    $scope.fn.isValidOib = function (value, fieldName) {
295        let errorText = "Polje je obavezno";
296        let isValid = value && value.isValidTaxNr();
297
298        $scope.fn.setError(errorText, isValid, fieldName[0]);
299        $scope.fn.updateFormValidity();
300        return isValid;
301    }
302
303    $scope.fn.isValidDocument = function () {
304        let isValid = true;
305
306        if ($scope.model.forms.documentData.length < 1 || $scope.model.forms.documentType.length < 1 || $scope.model.forms.documentFilename.length < 1) {
307            return isValid;
308        }
309        var supportedTypes = ["application/pdf", "application/msword", "image/png", "image/gif", "image/bmp", "application/zip", "application/x-zip-compressed", "image/jpg", "image/jpeg", "text/plain"];
310
311        if ($scope.model.forms.documentData.length > 0 && isValid) {
312            const fi = document.getElementById('file-upload');
313            const fsize = fi.files.item(0).size;
314            const file = Math.round((fsize / 1024));
315            if (file >= 10240) {
316                isValid = false;
317            }
318        }
319        isValid = supportedTypes.includes($scope.model.forms.documentType) && isValid;
320
321        $scope.fn.setError(isValid, 'file-upload');
322        $scope.fn.updateFormValidity();
323        return isValid;
324    };
325
326    $scope.fn.isValidOrderId = function (value, fieldName) {
327        let errorText = "Broj narudžbe mora sadržavati 10 znamenki";
328        let isValid = !!value && /^\d{10}$/.test(value);
329
330        $scope.fn.setError(errorText, isValid, fieldName[0]);
331        $scope.fn.updateFormValidity();
332        return isValid;
333    };
334
335    $scope.fn.setError = function (errorText, isValid, fieldName) {
336        if (fieldName)
337            errorText = fieldName.toUpperCase() + ': ' + errorText;
338        let index = $scope.local.validationErrors.indexOf(errorText);
339
340        if (!isValid) {
341            if (index < 0) {
342                $scope.local.validationErrors.push(errorText);
343            }
344        } else {
345            if (index >= 0) {
346                $scope.local.validationErrors.splice(index, 1);
347            }
348        }
349    };
350});

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.