PageSourceSearch

https://direktno.rs/assets/admin/js/custom/customScript.js

js direktno.rs collected 2026-09-24 23:10:04 UTC 12,628 bytes, 446 lines download raw bytes

1// document ready //
2function findParam(name) {
3    var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
4    if (results == null) {
5        return null;
6    } else {
7        return decodeURI(results[1]) || 0;
8    }
9}
10$(function () {
11    //var urlParams = new URLSearchParams(window.location.search);
12    if (findParam('notification')) {
13        notification(findParam("notification"), "success");
14    }
15});
16
17/**
18 * @param {String} linkTo
19 * @param {JsonObject} parameters
20 * @returns redirect to link with parameters
21 */
22function redirectToUrlWithParameters(linkTo, parameters) {
23    console.log("redirect to " + linkTo);
24    window.location.href = addHtmlExtension(linkTo) + makeParameters(parameters);
25}
26
27function addHtmlExtension(link) {
28    if (new RegExp("\.html$").test(link)) {
29        return link;
30    } else {
31        return link + ".html";
32    }
33}
34/**
35 * @param {type} data - json object containing parameters
36 * @returns string of url parameters 
37 * @example ?param.key=param.value&param.key=param.value...
38 */
39function makeParameters(data) {
40    var dataParameters = "?";
41    for (var key in data) {
42        dataParameters += key + "=" + data[key] + "&";
43    }
44
45    return dataParameters.replace(/[&?]$/g, "");
46}
47/**
48 * @param {String} absoluteUrl - current url
49 * @returns {String} url relative to root
50 */
51function relativeUrl(absoluteUrl) {
52    return absoluteUrl.toString().replace(/^(https?:\/\/[^/]*\/?)/g, "/").replace(/[&?#]$/g, "");
53}
54
55function removeParamsFromUrl(absoluteUrl) {
56    var beforeRemoveParams = relativeUrl(absoluteUrl);
57    return beforeRemoveParams.toString().replace(/\?.*/g, "");
58}
59
60/**
61 * @param {String} pageUrl
62 * @param {JsonObject} params
63 * @param {HtmlAttribute} container
64 * @returns load page into container with selected parameters
65 */
66function loadPageIntoContainer(pageUrl, params, container) {
67    $(container).empty();
68    $(document).find(container).load(pageUrl, params, function () {
69        console.log("content is loaded into " + container);
70        if ($(document).find('#load-event')) {
71            $(document).find('#load-event').trigger('loaded');
72        }
73    });
74}
75
76/**
77 * @param {String} pageUrl
78 * @param {JsonObject} params
79 * @param {HtmlAttribute} container
80 * @param {String} loader - class or id
81 * @returns load page into container with selected parameters
82 */
83function loadPageIntoContainerWithLoader(pageUrl, params, container, loader) {
84    $(document).find(container).load(pageUrl, params, function () {
85        console.log("content is loaded into " + container);
86        $(document).find(loader).hide();
87    });
88}
89/**
90 * @param {String} key
91 * @param {String} value
92 * @returns {String} console log 
93 * @example key: value
94 */
95function sout(key, value) {
96    console.log(key + ": " + value);
97}
98
99/**
100 * @param {JsonArray} array - array of object (JsonObject) elements
101 * @param {String} key - object property key
102 * @param {String} value - object property value
103 * @returns {JsonArray} array without object with value of property key == value
104 */
105function removeElementFromJsonArray(array, key, value) {
106    for (var i = 0; i < array.length; i++) {
107        if (array[i][key] == value) {
108            array.splice(i, 1);
109            break;
110        }
111    }
112}
113
114/**
115 * @param {JsonArray} array - array of object (JsonObject) elements
116 * @param {String} key - object property key
117 * @param {String} value - object property value
118 * @param {String} returnKey - object property key to return its value
119 * @returns {JsonArray} array without object with value of property key == value
120 */
121function removeElementFromJsonArrayReturnValue(array, key, value, returnKey) {
122    var tmp = "";
123    for (var i = 0; i < array.length; i++) {
124        if (array[i][key] == value) {
125            tmp = array[i][returnKey];
126            array.splice(i, 1);
127            break;
128        }
129    }
130    return tmp;
131}
132
133/**
134 * @param {JsonArray} array - array of object (JsonObject) elements
135 * @param {String} key - object property key
136 * @param {String} value - object property value
137 * @returns {boolean} true if contains element key with value, false otherwise
138 */
139function containsElementJsonArray(array, key, value) {
140    for (var i = 0; i < array.length; i++) {
141        if (array[i][key] == value) {
142            return true;
143        }
144    }
145    return false;
146}
147
148/**
149 * @param {JsonObject} jsonObject - JsonObject elements
150 * @returns {console.log()} of all elements key and value
151 */
152function soutJsonObject(jsonObject) {
153    for (var key in jsonObject) {
154        sout(key, jsonObject[key]);
155    }
156}
157
158/**
159 * Calls test servvar and print parameters
160 * 
161 * @param {JsonObject} params - to be passed to test servvar
162 * @returns {}
163 */
164function testServvarParams(params) {
165    $.ajax({
166        url: "/srv/testParams",
167        type: "post",
168        data: params,
169        compvare: function (jqXHR, textStatus) {
170            console.log("compvare");
171        }
172    });
173}
174
175/**
176 * go to back url
177 * 
178 * @returns {undefined}
179 */
180function goBack() {
181    window.history.back();
182}
183
184/**
185 * If redirectUrl exists it will redirect to that url after success
186 * 
187 * @param {String} url (url for test params "/srv/testParams")
188 * @param {JsonObject} params
189 * @returns {console.log("compvare") if compvare}
190 */
191function ajaxRequest(url, params) {
192    $.ajax({
193        url: url,
194        type: "post",
195        data: params,
196        compvare: function (jqXHR, textStatus) {
197            console.log("compvare");
198        },
199        success: function (data, textStatus, jqXHR) {
200            console.log(data);
201            if (!isUndefined(data.redirectUrl)) {
202                if (!isUndefined(data.params)) {
203                    redirectToUrlWithParameters(data.redirectUrl, data.params);
204                } else {
205                    redirectToUrlWithParameters(data.redirectUrl, {});
206                }
207            }
208            if (!isUndefined(data.error)) {
209                notification(data.error, "warning");
210            } else {
211                notification("Успешно", "success");
212            }
213        },
214        error: function (jqXHR, textStatus, errorThrown) {
215
216        },
217        statusCode: {
218            200: function () {
219
220            },
221            404: function () {
222
223            }
224        }
225    });
226}
227
228/**
229 * redirects to redirectUrl from servvar if code 200
230 * stays on page and write error message if code 400
231 * 
232 * @param {String} url (url for test params "/srv/testParams")
233 * @param {JsonObject} params
234 * @returns 
235 */
236function ajaxRequestInTesting(url, params) {
237    $.ajax({
238        url: url,
239        type: "post",
240        data: params,
241        beforeSend: function (xhr) {
242            $(document).find(".loader").show();
243            console.log("before send");
244        },
245        complete: function (jqXHR, textStatus) {
246            $(document).find(".loader").hide();
247            console.log("complete");
248        },
249        success: function (data, textStatus, jqXHR) {
250            console.log("success");
251        },
252        error: function (jqXHR, textStatus, errorThrown) {
253            console.log("error");
254        },
255        statusCode: {
256            // data - json objects
257            // ok
258            200: function (data) {
259                if (isUndefined(data.params)) {
260                    data.params = {};
261                }
262                soutJsonObject(data.params);
263                if (!isUndefined(data.redirectUrl)) { // redirect to url
264                    redirectToUrlWithParameters(data.redirectUrl, data.params);
265                } else if (!isUndefined(params.page) && !isUndefined(params.container)) { // if doesnt contains redirect url, load page
266                    loadPageIntoContainer(params.page, data.params, params.container);
267//                    notification("", "success");
268                }
269                if (!isUndefined(data.params.notification)) { // no redirect just present message
270                    console.log("postoji notif");
271                    notification(data.params.notification, "success");
272                } else {
273                    notification("save", "success");
274                }
275            },
276            // bad request
277            400: function (data) {
278//                $(document).find("#js-error-message").text(data.responseJSON.message);
279                notification(data.responseJSON.params.notification, "danger");
280            },
281            // not found
282            404: function (data) {
283                // #TODO
284            }
285        }
286    });
287}
288
289function isEmptyJson(object) {
290    return object == null || jQuery.isEmptyObject(object) || isUndefined(object);
291}
292
293function isUndefined(object) {
294    return typeof object == "undefined";
295}
296
297/**
298 * Click on activator to open modal
299 * 
300 * @param {type} activator - element to click
301 * @param {type} modal - modal to open
302 * @returns {undefined}
303 */
304function openModal(activator, modal) {
305    openModal(activator, modal, function () {});
306}
307
308/**
309 * 
310 * @param {Identificator} activator
311 * @param {Identificator} modal
312 * @param {function} customFunction
313 * @returns {undefined}
314 */
315function openModal(activator, modal, customFunction) {
316    $(document).find(activator).on("click", function (event) {
317        customFunction;
318        event.preventDefault();
319        $(modal).fadeIn();
320    });
321}
322
323/**
324 * 
325 * @param {String} message (Message in notification modal)
326 * @param {String} type (type of notification) [success / danger / warning / info]
327 */
328function notification(message, type) {
329    switch (message) {
330        case "save":
331            message = "Успешно";
332            break;
333        case "delete":
334            message = "Успешно";
335            break;
336        default :
337            break;
338    }
339    switch (type) {
340        case 'success':
341            icon = 'fas fa-check';
342            break;
343        case 'danger':
344            icon = 'fas fa-exclamation';
345            break;
346        case 'warning':
347            icon = 'fas fa-exclamation-triangle';
348            break;
349        case 'info':
350            icon = 'fas fa-info';
351            break;
352        default:
353            icon = 'fas fa-info';
354            break;
355    }
356    if (!isUndefined($.notify)) {
357        $.notify({
358            // options
359            message: message,
360            icon: icon
361        }, {
362            // settings
363            type: type,
364            newest_on_top: true,
365//        TRAJANJE NOTIFIKACIJE
366//        timer: 100000,
367            placement: {
368                from: "bottom",
369                align: "right"
370            },
371            animate: {
372                enter: 'animated fadeInDown'
373//            ,
374//            exit: 'animated fadeOutUp'
375            }
376        });
377    }
378}
379
380(function ($) {
381    var column = -1;
382    var order = 1;
383    $.fn.exportXLSX = function () {
384        var form = $(this)[0];
385        $(form).attr("action", "/srv/export/xlsx");
386        $(form).attr("method", "get");
387        $(form).submit();
388        return this;
389    };
390
391    $.fn.orderByColumns = function () {
392        var tr = $(this)[0];
393        if (!tr) {
394            throw "Element is not valid!";
395        }
396
397        $(tr).on('click', function (e) {
398            e.preventDefault();
399            if ($(e.target).attr('data-column')) {
400
401                var selectedColumn = $(e.target).attr('data-column');
402
403                if (column == selectedColumn) {
404                    order++;
405
406                    if (order == 3) {
407                        selectedColumn = -1;
408                        order = 1;
409                    }
410                } else {
411                    order = 1;
412                }
413
414                column = selectedColumn;
415                __params.column = selectedColumn;
416                __params.order = order;
417                loadPageIntoContainer("/tabs/employerEmployeeListBrowser.jsp", __params, "#js-employee-list-content");
418            }
419        });
420    };
421
422
423
424    $.fn.addOrderByClazz = function () {
425        if ($(this)[0]) {
426            var headers = $(this[0]).children();
427            headers.each(function () {
428                $(this).removeClass();
429            });
430            var urlParam = findParam('column')
431            if (urlParam != 'undefined') {
432                switch (findParam('order')) {
433                    case '1':
434                        $(headers[parseInt(urlParam) + 1]).addClass('order-asc');
435                        break;
436                    case '2':
437                        $(headers[parseInt(urlParam) + 1]).addClass('order-desc');
438                        break;
439                    default:
440
441                        break;
442                }
443            }
444        }
445    };
446})(jQuery);

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.