PageSourceSearch

https://www.esylux.com/_assets/581ae7819742031f221bb47d76589cd6/JavaScripts/esylux_projectlist.js?1750094461

js esylux.com collected 2026-10-04 13:23:21 UTC 17,270 bytes, 530 lines download raw bytes

1(function ($) {
2
3    function registerAutosuggest(projectList, room) {
4        let xhr;
5        room.find('input.sword').autocomplete({
6            search: function (event, ui) {
7                $(event.target).data('productId', '');
8            },
9            source: function (request, response) {
10                xhr && xhr.abort();
11                xhr = $.ajax({
12                    url: ($('#configuration').data('baseuri') || '/')
13                        + '?type=1619162552',
14                    dataType: 'json',
15                    data: {
16                        'term': request.term,
17                        'allowArchived': 0
18                    },
19                    success: function (data) {
20                        response(data.suggestions);
21                    }
22                });
23            },
24            minLength: 2,
25            select: function (event, ui) {
26                if (ui.item.value && ui.item.id) {
27                    $(this)
28                        .closest('.projectlist-room')
29                        .find('.projectlist-addproduct').prop("disabled", false);
30                    $(event.target)
31                        .data('productId', ui.item.id)
32                        .data('productLabel', ui.item.label);
33                }
34            }
35        });
36    }
37
38    function randomRoomId() {
39        return 'R-' + Math.random().toString(36).substr(2, 9);
40    }
41
42    function createRoom(projectList, id, name) {
43        id = id || randomRoomId();
44        let templateRoom = projectList.find('#projectlist-room-template').html();
45        let newRoom = $(templateRoom)
46            .hide()
47            .attr('data-room', id);
48        newRoom.find('.projectlist-room-name').val(name || '');
49        registerAutosuggest(projectList, newRoom);
50        return newRoom;
51    }
52
53    function addRoomAt(projectList, insertAfterElement) {
54        let newRoom = createRoom(projectList);
55        newRoom.insertAfter(
56            insertAfterElement
57        );
58        markDirty(projectList);
59        return newRoom;
60    }
61
62    function addRoom(projectList, id, name) {
63        let newRoom = createRoom(projectList, id, name);
64
65        newRoom.appendTo(
66            projectList.find('.projectlist-rooms')
67        );
68        markDirty(projectList);
69        return newRoom;
70    }
71
72    function removeRoom(projectList, room) {
73        room
74            .slideUp(function () {
75                $(this).remove();
76
77                if (projectList.find('.projectlist-room').length === 0) {
78                    addRoom(projectList).slideDown();
79                }
80            });
81        markDirty(projectList);
82    }
83
84    function addProduct(projectList, room, productId, amount, label, note) {
85        let templateProduct = projectList.find('#projectlist-product-template').html();
86        let newProduct = $(templateProduct)
87            .hide()
88            .appendTo(room.find('.projectlist-room-products'))
89            .attr('data-product', productId)
90            .attr('data-product-label', label);
91        newProduct
92            .find('.projectlist-product-description')
93            .html(label);
94        $.ajax({
95            method: 'POST',
96            url: projectList.data('urlProduct'),
97            data: {
98                'tx_esylux_projectlist[productId]': productId
99            },
100            success: function (response) {
101                newProduct
102                    .find('.projectlist-product-description')
103                    .html(response);
104                newProduct
105                    .find('.projectlist-product-note')
106                    .val(note || '');
107            }
108        });
109        newProduct
110            .find('.projectlist-product-amount')
111            .val(amount || 1);
112
113        newProduct.slideDown(function () {
114            newProduct.find('.projectlist-product-amount').focus()
115        });
116
117        markDirty(projectList);
118        return newProduct;
119    }
120
121    function removeProduct(projectList, product) {
122        product
123            .slideUp(function () {
124                $(this).remove();
125            });
126        markDirty(projectList);
127    }
128    function markDirty(projectList) {
129        $(projectList).find('.projectlist-persist').removeAttr('disabled');
130    }
131
132    function markClean(projectList) {
133        $(projectList).find('.projectlist-persist').attr('disabled', 'disabled');
134        renderCounter();
135
136    }
137
138    function renderCounter(){
139        let key = 'projectList';
140        let projectListData = JSON.parse(window.localStorage.getItem(key));
141
142        if ((projectListData === null || (projectListData.name === "" && projectListData.rooms.length === 1  && projectListData.rooms[0].name === "" && projectListData.rooms[0].products.length === 0 ))) {
143            $('#project-list-counter').hide();
144        } else {
145            $('#project-list-counter').show();
146        }
147
148    }
149
150    window.esyluxGetProjectListProducts = function() {
151        let key = 'projectList';
152        let projectListData = JSON.parse(window.localStorage.getItem(key));
153        let products = [];
154        $(projectListData.rooms).each(function () {
155            let roomData = this;
156            $(roomData.products).each(function () {
157                let productData = this;
158                if (!products[productData.id]) {
159                    products[productData.id] = {
160                        id: productData.id,
161                        amount: 0
162                    };
163                }
164                products[productData.id].amount = (products[productData.id].amount) + parseInt(productData.amount);
165            });
166        });
167        return Object.keys(products).map(function (key) { return products[key]; });
168    }
169
170    function restoreFromStorage(projectList) {
171        let key = 'projectList';
172        let projectListData = JSON.parse(window.localStorage.getItem(key));
173        if (projectListData === null) {
174            return;
175        }
176        projectList.find('.projectlist-name').val(projectListData['name']);
177        $(projectListData.rooms).each(function () {
178            let roomData = this;
179            let room = addRoom(
180                projectList,
181                roomData.id,
182                roomData.name
183            );
184            $(roomData.products).each(function () {
185                let productData = this;
186                addProduct(
187                    projectList,
188                    room,
189                    productData.id,
190                    productData.amount,
191                    productData.label,
192                    productData.note
193                )
194            });
195
196            room.show();
197            $('.projectlist-wanttoremoveall').css({
198                'display' : 'block'
199            });
200        });
201        markClean(projectList);
202    }
203
204    function persist(projectList) {
205        let key = 'projectList';
206        let projectListData = {
207            'name': projectList.find('.projectlist-name').val(),
208            'rooms': []
209        };
210
211        projectList.find('.projectlist-room').each(function () {
212            let room = $(this);
213            let roomKey = room.data('room');
214
215            var productsData = [];
216            room.find('.projectlist-product').each(function () {
217                let product = $(this);
218                productsData.push({
219                    'id': product.data('product'),
220                    'label': product.data('productLabel'),
221                    'amount': product.find('.projectlist-product-amount').val(),
222                    'note': product.find('.projectlist-product-note').val()
223                });
224            });
225
226            let roomData = {
227                'id': roomKey,
228                'name': room.find('.projectlist-room-name').val(),
229                'products': productsData
230            };
231            projectListData.rooms.push(roomData);
232        });
233
234        window.localStorage.setItem(key, JSON.stringify(projectListData));
235
236        markClean(projectList);
237        $('.projectlist-wanttoremoveall').css({
238            'display' : 'block'
239        });
240    }
241
242    function renderAsPdf(projectList) {
243        persist(projectList);
244        let form = projectList.find('.projectlist-submit-renderPdf');
245        form.find('.projectlist-submit').val(window.localStorage.getItem('projectList'));
246        form.submit();
247    }
248
249    function renderAsXls(projectList) {
250        persist(projectList);
251        let form = projectList.find('.projectlist-submit-renderXls');
252        form.find('.projectlist-submit').val(window.localStorage.getItem('projectList'));
253        form.submit();
254    }
255
256    function orderRequest(projectList) {
257        persist(projectList);
258        let form = projectList.find('.projectlist-submit-orderRequest');
259        form.find('.projectlist-submit').val(window.localStorage.getItem('projectList'));
260        form.submit();
261    }
262
263    function registerEvents(projectList) {
264        projectList.on(
265            'change',
266            'input, textarea',
267            function (event) {
268                markDirty(projectList);
269            }
270        );
271
272        // add room
273        projectList.on(
274            'click',
275            '.projectlist-addroom',
276            function (event) {
277                event.preventDefault();
278                let room = addRoomAt(
279                    projectList,
280                    $(this).closest('.projectlist-room')
281                )
282                room.slideDown();
283                return false;
284            }
285        );
286
287        // want to remove room
288        projectList.on(
289            'click',
290            '.projectlist-wanttoremoveroom',
291            function (event) {
292                event.preventDefault();
293                $(this).siblings('.modal').modal('show');
294                return false;
295            }
296        );
297
298        // finally remove room
299        projectList.on(
300            'click',
301            '.projectlist-removeroom',
302            function (event) {
303                event.preventDefault();
304                removeRoom(
305                    projectList,
306                    $(this).parents('.projectlist-room')
307                );
308                $('.remove-modal').modal('hide');
309                return false;
310            }
311        );
312
313        // want to remove project list
314        projectList.on(
315            'click',
316            '.projectlist-wanttoremoveall',
317            function (event) {
318                event.preventDefault();
319                $(this).siblings('.modal').modal('show');
320                return false;
321            }
322        );
323
324        // finally remove project list
325        projectList.on(
326            'click',
327            '.projectlist-removeall',
328            function (event) {
329                event.preventDefault();
330                removeRoom(
331                    projectList,
332                    $('.projectlist-room')
333                );
334                $('.projectlist-name').val('');
335                $('.remove-all-modal').modal('hide');
336                $('.projectlist-wanttoremoveall').hide();
337                $(window).scrollTop(0);
338                return false;
339            }
340        );
341
342        // add product
343        projectList.on(
344            'click',
345            '.projectlist-addproduct',
346            function (event) {
347                event.preventDefault();
348                let input = $(this)
349                    .closest('.projectlist-room')
350                    .find('.projectlist-addproduct-input');
351                let productId = input.data('productId');
352                if (productId !== "" && typeof productId !== 'undefined') {
353                    $(this).prop("disabled", true);
354                    addProduct(
355                        projectList,
356                        $(this).closest('.projectlist-room'),
357                        productId,
358                        1,
359                        input.data('productLabel'),
360                        ''
361                    );
362                    $(input).val('').data('productId', '');
363                }
364                return false;
365            }
366        );
367
368        // add product from watchlist
369        projectList.on(
370            'click',
371            '.projectlist-addfromwatchlist',
372            function (event) {
373                event.preventDefault();
374                let room = $(this).closest('.projectlist-room');
375                let modal = projectList.find('#projectlist-product-watchlist');
376                modal.find('.modal-body').load(
377                    projectList.data('urlWatchlist'),
378                    {
379                        'tx_esylux_projectlist[bookmarkJson]': localStorage.getItem('bookmarks')
380                    },
381                    function () {
382                        modal.modal('show');
383                        modal.find('.modal-body .projectlist-addtoprojectlist')
384                            .off('click')
385                            .on(
386                                'click',
387                                function () {
388                                    let productId, productLabel;
389                                    $('.add-el-to-projectlist').each(function (){
390                                        if($(this).prop("checked")){
391                                            productId = $(this).data('productId');
392                                            productLabel = $(this).data('productLabel');
393                                            if (productId !== "" && typeof productId !== 'undefined') {
394                                                addProduct(
395                                                    projectList,
396                                                    room,
397                                                    productId,
398                                                    1,
399                                                    productLabel,
400                                                    ''
401                                                );
402                                            }
403                                        }
404                                    });
405                                    modal.modal('hide');
406                                    return false;
407                                }
408                            );
409                    }
410                );
411                return false;
412            }
413        );
414
415        // remove product
416        projectList.on(
417            'click',
418            '.projectlist-product-remove',
419            function (event) {
420                event.preventDefault();
421                removeProduct(
422                    projectList,
423                    $(this).closest('.projectlist-product')
424                );
425                return false;
426            }
427        );
428
429        // persist
430        projectList.on(
431            'click',
432            '.projectlist-persist',
433            function (event) {
434                event.preventDefault();
435                persist(projectList);
436                return false;
437            }
438        );
439
440        // download pdf
441        projectList.on(
442            'click',
443            '.projectlist-download',
444            function (event) {
445                event.preventDefault();
446                renderAsPdf(projectList);
447                return false;
448            }
449        );
450
451        // download xls
452        projectList.on(
453            'click',
454            '.projectlist-downloadxls',
455            function (event) {
456                event.preventDefault();
457                renderAsXls(projectList);
458                return false;
459            }
460        );
461
462        // send to orderRequest
463        projectList.on(
464            'click',
465            '.projectlist-request',
466            function (event) {
467                event.preventDefault();
468                orderRequest(projectList);
469                return false;
470            }
471        );
472
473        // request offer
474        projectList.on(
475            'click',
476            '.projectlist-request',
477            function (event) {
478                event.preventDefault();
479                persist(projectList);
480                return false;
481            }
482        );
483
484        projectList.on(
485            'keydown',
486            '.projectlist-product-amount',
487            function (event) {
488                if (event.keyCode === 13) {
489                    event.preventDefault();
490                }
491            }
492        );
493    }
494
495    function initializeProjectlist() {
496        let projectList = $('.projectList');
497        if (projectList.length > 0) {
498            registerEvents(projectList);
499            restoreFromStorage(projectList);
500
501            if (projectList.find('.projectlist-room').length === 0) {
502                addRoom(projectList).show();
503            }
504        }
505    }
506    // checks if functional cookies are allowed
507    function optInSet(){
508        const cookieValue = "functional:1";
509        const cookieString = document.cookie.split(';').toString();
510        const indexOfFirst = cookieString.indexOf(cookieValue);
511        const optInCookie = indexOfFirst + 1;
512
513
514        // opt-in Zustand überprüfen
515        if (optInCookie) {
516            return true; // opt-in gesetzt
517
518        } else {
519            return false; // opt-in nicht gesetzt
520        }
521    }
522
523    $(document).ready(function () {
524        if(optInSet()){
525            renderCounter();
526            initializeProjectlist();
527        }
528
529    });
530})(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.