PageSourceSearch

https://kulturserver-nrw.de/pix/js/pix.js

js kulturserver-nrw.de collected 2026-09-24 22:39:03 UTC 91,186 bytes, 2,149 lines download raw bytes

1/**
2 *
3 * @param {type} PIX
4 * @param {type} $
5 * @requires jquery, CbUi, jStorage, ddslick
6 * @returns {undefined}
7 */
8(function (PIX, $) {
9
10    // default options
11    var config = {
12        'projects': ['cb-pix'],
13        'languages': '/pix/languages',
14        'pictures': '/pix/pictures',
15        'series': '/pix/series',
16        'templates': '/pix/template',
17        'picturesLimit': 36,
18        'picturesLimitZoom': 48,
19        'layerFrame': true,
20        'showShadow': true,
21        'submitClass': '__CbUiSubmitting',
22        'delay': 500,
23        'width': 680,
24        'height': 630,
25        'cntnrDim': 193,
26        'thumbnailDim': 40,
27        'keywordsDelim': ', ',
28        'ml': $.CbWidgetRegistry.brickSource,
29        'checkFields': false,
30        'checkForFields': {'Title': 'notempty', 'Copyright': 'notempty'},
31        'checkFieldsMatches': [],
32        'checkFieldsAllreadyCorrect': [],
33        'checkFieldsMatchesCounter': 0
34    },
35            languages = [],
36            messageWindow;
37
38    // helper functions ---------------------------------------------------------
39
40    /**
41     * Check if this script is run from the app "cb-pix"
42     * @returns {unresolved}
43     */
44    var isPixInCbPix = function () {
45        return document.location.href.match(/\/pix/) || document.location.host.match(/^pix/);
46    };
47
48    var bindMenuButtons = function (win, name) {
49        var el = win.element();
50        el.find('a.pix-manage-pictures').click(function (e) {
51            e.preventDefault();
52            win.close({delay: 0});
53            new PIX.PictureManageWindow({
54                prev: name,
55                zoom: win.zoom,
56                viewState: win.viewState
57            }, win.options, {}).open({
58                delay: 0
59            });
60        });
61        el.find('.pix-cancel').click(function (e) {
62            e.preventDefault();
63            goBack(win);
64        });
65    };
66
67    var togglePicSeriesButtons = function (win) {
68        var
69                hasPrev = typeof win.prev !== 'undefined',
70                hasSeries = parseInt(win.seriesId) > 0;
71        $('.pix-add-series', win.element()).toggle(!hasSeries && !hasPrev);
72        $('.pix-edit-series', win.element()).toggle(hasSeries && !hasPrev);
73    };
74
75    var openWindow = function (win, callbacks, data) {
76        $.CbWidgetRegistry.projects = config.projects;
77        $.CbWidgetRegistry.language = config.language;
78        if (config.createLabels) {
79            $.CbWidgetRegistry.brickSource += '?createNewLabels';
80        }
81        $(document).ready(function () {
82            $.getJSON(config.languages, function (langs) {
83                $.each(langs, function (i, lang) {
84                    languages[lang.Id] = lang;
85                });
86                new win({}, $.extend(config, callbacks), data).open({
87                    delay: config.delay
88                }, //callback of $.CbWidget.window.open for the execution of the dropdown implementation
89                        function () {}
90                );
91            })
92                    .fail(PIX.UX.ajaxError);
93        });
94    };
95
96    var goBack = function (cur) {
97        cur.close({delay: 0});
98        if (cur.prev !== undefined) {
99            new PIX[cur.prev]({
100                zoom: cur.zoom,
101                viewState: cur.viewState
102            }, cur.options, {}).open({
103                delay: 0
104            });
105        }
106    };
107
108    var getThumbnail = function (pic, size) {
109        return pic.Uri.replace(/\.(\w+)$/, '_t' + size + '.$1');
110    };
111
112    // hiding/showing tile/list items depending on toggle button state
113    // (optional parameter determines initial view)
114    var toggleViews = function (initial) {
115        if (initial) {
116            if (initial === 'list') {
117                setToList();
118            } else if (initial === 'tiles') {
119                setToTiles();
120            }
121        }
122
123        function setToList() {
124            $('.pix-image-tile-item').addClass('display-none');
125            $('.pix-image-list-item').removeClass('display-none');
126            $('.view-toggle').attr('src', '/pix/media/png/icon-filter-tile-red.png');
127        }
128        function setToTiles() {
129            $('.pix-image-list-item').addClass('display-none');
130            $('.pix-image-tile-item').removeClass('display-none');
131            $('.view-toggle').attr('src', '/pix/media/png/icon-filter-list-red.png');
132            alignImages('tile');
133        }
134    };
135
136    //vertical centering of the images in their tile containers
137    var alignImages = function () {
138        $(".pix-image-tile-item img").each(function () {
139            var height = $(this).data('height');
140            var width = $(this).data('width');
141            var max_height = 0;
142            var max_width = 0;
143            max_height = $('.pix-image-tile-item:first').height();
144            max_width = $('.pix-image-tile-item:first').width();
145            var top = Math.round((max_height - height) / 2);
146            var left = Math.round((max_width - width) / 2);
147            $(this).css('top', top + 4);
148            $(this).css('left', left + 4);
149        });
150    };
151
152    var ddslickSelectByValue = function (obj, value) {
153        return obj.ddslick('select', {
154            index: $('li:has(input.dd-option-value[value="' + value + '"])', obj).index()
155        });
156    };
157
158    var getPicturesLimit = function (win) {
159        return config.picturesLimit;
160        //return win.zoom ? config.picturesLimitZoom : config.picturesLimit;
161    };
162
163    var notEmpty = function (value) {
164        return (!value || 0 === value.length);
165    };
166
167    var checkPicFieldsValidators = function (pic) {
168        var matchCauses = {};
169        for (var key in config.checkForFields) {
170            var value = config.checkForFields[key];
171            switch (value) {
172                case 'notempty':
173                    if (notEmpty(pic[key])) {
174                        matchCauses[key] = value;
175                    }
176                    break;
177                default:
178                    break;
179            }
180        }
181        if (_.size(matchCauses) > 0) {
182            config.checkFieldsMatches.push({'Picture': pic, 'MatchCauses': matchCauses});
183        } else {
184            config.checkFieldsAllreadyCorrect.push({'Picture': pic, 'MatchCauses': matchCauses});
185        }
186    };
187
188    var checkPicFields = function (pics, obj) {
189        var self = this;
190        // reset matches
191        config.checkFieldsMatches = [];
192        config.checkFieldsAllreadyCorrect = [];
193        config.checkFieldsMatchesCounter = 0;
194        if (_.isArray(pics)) {
195            pics.forEach(function (pic) {
196                checkPicFieldsValidators(pic);
197            });
198        } else {
199            checkPicFieldsValidators(pics);
200        }
201
202        // if matches are not empty after check, open field editor
203        if (config.checkFieldsMatches.length > 0) {
204            new PIX.PictureFieldCheckWindow({
205                prev: 'PictureManageWindow',
206                zoom: obj.zoom,
207                viewState: obj.viewState
208            }, obj.options, config.checkFieldsMatches).open({
209                delay: 0
210            });
211            obj.close();
212        } else {
213            if (typeof obj.options.selectPicture !== 'undefined') {
214                obj.destroy();
215                /**
216                 * @param {object} pic picture object
217                 */
218                obj.options.selectPicture(pics);
219            }
220        }
221
222    };
223
224    // pix functions ------------------------------------------------------------
225
226    PIX.Ml = {
227        translations: {},
228        get: function (label) {
229            return this.translations[label] ? this.translations[label] : 'translation missing: ' + label;
230        },
231        fetch: function (labels, callback) {
232            var self = this;
233            $.ajax({
234                url: config.ml,
235                data: {
236                    labels: labels,
237                    language: config.language,
238                    projects: config.projects
239                },
240                success: function (translations) {
241                    self.translations = translations;
242                    callback();
243                },
244                error: PIX.UX.ajaxError,
245                dataType: 'json'
246            });
247        }
248    };
249    PIX.UX = {
250        ajaxError: function (d, textStatus, error) {
251            var status, responseText;
252            if (d && d.readyState) {
253                status = d.status;
254                responseText = d.responseJSON ? d.responseJSON : d.responseText;
255            }
256            if (textStatus && textStatus.readyState) {
257                status = textStatus.status;
258                responseText = textStatus.responseText;
259            }
260            if (status == 403 && responseText.indexOf('_') > -1) {
261                return PIX.UX.aclMessage(responseText.replace(/^"|"$/g, ''));
262            }
263            PIX.UX.showMessage(responseText);
264        },
265        getMessageDialog: function () {
266            PIX.UX.MessageWindow = PIX.UX.MessageWindow || new jQuery.CbWidget.message_window(
267                    {
268                        template: false,
269                        avoidFrame: true,
270                        responsive: true
271                    }, {
272                language: config.language,
273                id_prefix: '#',
274                projects: config.projects,
275                templateString: '<div class="message-dialog-window">' +
276                        '    <div class="message-dialog-padding message-dialog-heading __CbUiText __CbUiReplaceHtml">message_heading</div>' +
277                        '    <div class="message-dialog-content">' +
278                        '        <div class="message-dialog-message __CbUiText __CbUiReplaceHtml">message_text</div>' +
279                        '        <div class="message-abort-container"><a class="__CbUiCancelButton __CbUiTextButton __CbUiText">_cancel</a> <a class="__CbUiOkButton __CbUiTextButton __CbUiText">_ok</a></div>' +
280                        '    </div>' +
281                        '</div>'
282            },
283                    {}
284            );
285            return PIX.UX.MessageWindow;
286        },
287        showMessage: function (message, caption, onOkCallback) {
288            PIX.UX.getMessageDialog().showMessage(message, caption, onOkCallback);
289        },
290        aclMessage: function (message) {
291            if (message.indexOf('||') == -1) {
292                return PIX.UX.getMessageDialog().showMessage(message, 'acl_restriction_caption');
293            }
294            var messageParts = message.split('||'),
295                    label = messageParts[0],
296                    labels = [
297                        label, label + '_mail_body', label + '_mail_subject',
298                        label + '_restriction_caption', label + '_send_mail_request_button'
299                    ],
300                    ml = Object.create(PIX.Ml);
301            ml.fetch(labels, function () {
302                var translated = ml.get(label);
303                var triggerHome = true;//$('#TopicIndicator').length ? false : true;
304
305                var parts = messageParts[1].split('|');
306                var title = parts[0];
307                var ownerMail = parts[1];
308                var requestMail = parts[2];
309                var firstName = parts[3];
310                var surName = parts[4];
311
312                //Dialog text
313                translated = translated.replace('{EMAIL}', ' ' + ownerMail + ' ');
314                if (requestMail)
315                    translated = translated.replace('{USEREMAIL}', ' ' + requestMail + ' ');
316                //Mail text
317                var body = ml.get(label + '_mail_body').replace('{EMAIL}', ' ' + requestMail + ' ');
318                var subject = ml.get(label + '_mail_subject').replace('{TITLE}', ' ' + title + ' ');
319                body = body.replace(/\{EMAIL\}/g, ' ' + requestMail + ' ');
320                body = body.replace(/\{TITLE\}/g, ' ' + title + ' ');
321                body = body.replace(/\{FIRSTNAME\}/g, ' ' + firstName + ' ');
322                body = body.replace(/\{SURNAME\}/g, ' ' + surName + ' ');
323                PIX.UX.getMessageDialog().showConfirm(
324                        ml.get(label + '_restriction_caption'),
325                        translated,
326                        function () {
327                            document.location.href = 'mailto:' + ownerMail +
328                                    '?body=' + encodeURIComponent(body) +
329                                    '&from=' + requestMail +
330                                    '&subject=' + encodeURIComponent(subject);
331                        },
332                        function () {},
333                        ml.get(label + '_send_mail_request_button')
334                        );
335            });
336        }
337    };
338
339    PIX.configure = function (settings) {
340        if (typeof $.fn.ddslick !== 'function' || $.jStorage === undefined)
341            throw 'Missing dependencies';
342        $.extend(config, settings);
343    };
344
345    PIX.selectPicture = function (callback) {
346        openWindow(PIX.PictureManageWindow, {
347            selectPicture: callback
348        });
349    };
350    PIX.managePictures = function () {
351        openWindow(PIX.PictureManageWindow);
352    };
353
354    PIX.managePicture = function (callback, data) {
355        openWindow(PIX.PictureMetaWindow, {
356            managePicture: callback
357        }, data);
358    };
359
360    PIX.selectSeries = function () {
361        // TODO
362    };
363
364    PIX.manageSeries = function () {
365        // TODO
366    };
367
368    PIX.positionPicture = function (pic, callback) {
369        openWindow(PIX.PicturePositionWindow, {
370            positionPicture: callback
371        }, pic);
372    };
373
374    PIX.transform = function (url, params) {};
375
376    PIX.loadPicture = function (id, callback) {
377        var loader = new $.CbWidget.loader();
378        loader.show();
379        $.getJSON(config.pictures + '/' + id, callback)
380                .fail(PIX.UX.ajaxError)
381                .always(function () {
382                    loader.hide();
383                });
384    };
385
386    PIX.getDescription = function (pic, locale) {
387        if (locale === undefined) {
388            locale = config.locale;
389            if (locale === undefined) {
390                locale = $.CbWidgetRegistry.language;
391                if (locale === undefined)
392                    return '';
393            }
394        }
395        var language = locale.split('_')[0];
396        var partial = [];
397        var found = null;
398        $.each(languages, function (id, lang) {
399            if (lang === undefined)
400                return true;
401            if (lang.Locale === locale) {
402                if (pic.DescriptionsByIdLanguage[id] !== undefined) {
403                    found = id;
404                    return false;
405                }
406            } else if (lang.Locale.split('_')[0] === language) {
407                partial.push(id);
408            }
409            return true;
410        });
411        $.each(partial, function (i, id) {
412            if (pic.DescriptionsByIdLanguage[id] !== undefined) {
413                found = id;
414                return false;
415            } else {
416                return true;
417            }
418        });
419        return found !== null ? pic.DescriptionsByIdLanguage[found] : '';
420    };
421
422    PIX.validateCheckFields = function (pic) {
423        var returnValue = true;
424        for (var key in config.checkForFields) {
425            var value = config.checkForFields[key];
426            switch (value) {
427                case 'notempty':
428                    if (notEmpty(pic[key])) {
429                        returnValue = returnValue && false;
430                    }
431                    break;
432                default:
433                    break;
434            }
435        }
436        return returnValue;
437    };
438
439    // BaseWindow ---------------------------------------------------------------
440
441    PIX.BaseWindow = $.CbWidget.window.extend({
442        labels: [
443            'picture_manage_upload_to',
444            'picture_manage_upload_to_description',
445            'picture_manage_filter_all',
446            'picture_manage_filter_all_description',
447            'picture_manage_filter_marked',
448            'picture_manage_filter_marked_description',
449            'please_choose',
450            '_insert',
451            'show_duplicates',
452            'invert_selection',
453            'add_to_series',
454            'remove_from_series',
455            'tooltip_please_enter_picture_title'
456        ],
457        translations: {},
458
459        ml: function (label) {
460            return this.translations[label] ? this.translations[label] : 'translation missing: ' + label;
461        },
462
463        loadMl: function (callback) {
464            var self = this;
465            $.ajax({
466                url: self.options.ml,
467                data: {
468                    labels: self.labels,
469                    language: self.options.language,
470                    projects: self.options.projects
471                },
472                success: function (translations) {
473                    self.translations = translations;
474                    callback();
475                },
476                error: PIX.UX.ajaxError,
477                dataType: 'json'
478            });
479        }
480    });
481
482    // PicturePositionWindow ----------------------------------------------------
483
484    PIX.PicturePositionWindow = PIX.BaseWindow.extend({
485        constructor: function (loadOptions, options, data) {
486            this.base($.extend({
487                template: config.templates + '/picposition',
488                cls: '__PixWindow'
489            }, loadOptions), options);
490            this.prev = loadOptions.prev;
491            this.autocenter();
492            this.data = data;
493            this.options.supportUrl = 'https://pix.culturebase.org/support';
494        },
495
496        handleReady: function (params) {
497            bindMenuButtons(this, 'PicturePositionWindow');
498            var self = this;
499            var el = this.element();
500
501            el.find(".pix-radio-image, .pix-radio-image-active").click(function () {
502                var button = $(this);
503                var siblings = button.siblings();
504                siblings.removeClass("pix-radio-image-active").addClass("pix-radio-image");
505                siblings.find(":radio").removeAttr("checked");
506                button.removeClass("pix-radio-image").addClass("pix-radio-image-active");
507                button.find(":radio").attr('checked', true);
508            });
509
510            var form = el.find('form');
511            var fields = {};
512            $.each(['CurrentWidth', 'CurrentHeight', 'Title', 'Description'], function (i, field) {
513                fields[field] = $(form.find("[name=" + field + "]"));
514                fields[field].val(self.data[field]);
515            });
516            form.find("[name=Alignment][value=" + self.data.Alignment + "]")
517                    .attr('checked', true).parent()
518                    .removeClass("pix-radio-image")
519                    .addClass("pix-radio-image-active");
520            el.find('.pix-orig-width').text(self.data.Width);
521            el.find('.pix-orig-height').text(self.data.Height);
522
523            var alignRatio = function (primary) {
524                var secondary = primary === 'Width' ? 'Height' : 'Width';
525                if (fields['Current' + primary].val().match(/\d{1,3}%/)) {
526                    new_value = 'auto';
527                } else {
528                    new_value = Math.round(
529                            fields['Current' + primary].val() *
530                            self.data[secondary] / self.data[primary]);
531                }
532                fields['Current' + secondary].val(new_value);
533            };
534
535            var lock = el.find('.pix-text-image-format-ratio-lock'),
536                    locked = false;
537            if (self.data.CurrentWidth.match && self.data.CurrentWidth.match(/\d{1,3}%/)) {
538                locked = self.data.CurrentHeight.match && self.data.CurrentHeight.match(/\s*auto\s*/);
539            } else if (self.data.CurrentHeight.match && self.data.CurrentHeight.match(/\d{1,3}%/)) {
540                locked = self.data.CurrentWidth.match && self.data.CurrentWidth.match(/\s*auto\s*/);
541            } else {
542                locked = (+self.data.CurrentHeight ===
543                        Math.round(self.data.CurrentWidth * self.data.Height / self.data.Width));
544            }
545            if (locked) {
546                lock.addClass('pix-image-ratio-locked');
547            } else {
548                lock.addClass('pix-image-ratio-unlocked');
549            }
550
551            lock.click(function () {
552                if (locked) {
553                    lock.removeClass('pix-image-ratio-locked');
554                    lock.addClass('pix-image-ratio-unlocked');
555                } else {
556                    lock.removeClass('pix-image-ratio-unlocked');
557                    lock.addClass('pix-image-ratio-locked');
558                    alignRatio('Width');
559                }
560                locked = !locked;
561            });
562
563            fields.CurrentWidth.change(function () {
564                if (locked)
565                    alignRatio('Width');
566            });
567
568            fields.CurrentHeight.change(function () {
569                if (locked)
570                    alignRatio('Height');
571            });
572
573            form.submit(function (e) {
574                e.preventDefault();
575                self.options.positionPicture({
576                    Width: self.data.Width,
577                    Height: self.data.Height,
578                    CurrentWidth: fields.CurrentWidth.val(),
579                    CurrentHeight: fields.CurrentHeight.val(),
580                    Title: fields.Title.val(),
581                    Description: fields.Description.val(),
582                    Alignment: form.find("[name=Alignment]:checked").val()
583                });
584                self.close();
585            });
586            this.base(params);
587
588            this.setSupportLink(this.options);
589        }
590    });
591
592    // PictureManageWindow ------------------------------------------------------
593
594    PIX.PictureManageWindow = PIX.BaseWindow.extend({
595        constructor: function (loadOptions, options, data) {
596            this.base($.extend({
597                template: config.templates + '/picmanage',
598                cls: '__PixWindow'
599            }, loadOptions), options);
600            this.prev = loadOptions.prev;
601            this.zoom = loadOptions.zoom;
602            this.viewState = loadOptions.viewState;
603            this.autocenter();
604            this.data = data;
605            this.options.supportUrl = 'https://pix.culturebase.org/support';
606
607            if (config.auth.accountId !== $.jStorage.get('accountId')) {
608                // account switch
609                $.jStorage.set('accountId', config.auth.accountId);
610                this.clearPicStorage();
611                this.clearCollectedPictures();
612            }
613            this.allSeries = [];
614            this.seriesId = $.jStorage.get('seriesId');
615            this.scrollEndReached = false;
616            this.previousSeriesId = -1;
617            this.pixScrollCntnrHeight = 415;
618            this.listItemTemplate = '';
619            this.tileItemTemplate = '';
620            this.allPictures = {};
621            this.cursorIconOffset = 20;
622
623            if ($.jStorage.get('picturesFilter')) {
624                this.filter = $.jStorage.get('picturesFilter');
625            }
626
627            this.scrollPos = $.jStorage.get('scrollPos') || 0;
628        },
629
630        setPicStorage: function () {
631            var self = this;
632            $.jStorage.set('seriesId', self.seriesId);
633            $.jStorage.set('scrollPos', self.scrollPos);
634            $.jStorage.set('picturesLength', self.pictures.length);
635            $.jStorage.set('picturesFilter', self.filter);
636        },
637
638        clearPicStorage: function () {
639            $.jStorage.deleteKey('seriesId');
640            $.jStorage.deleteKey('scrollPos');
641            $.jStorage.deleteKey('picturesLength');
642            $.jStorage.deleteKey('picturesFilter');
643        },
644
645        addPictures: function (pics, prepend) {
646            var self = this;
647            if (pics.Uri) {
648                self.addPicture(pics, prepend);
649                return;
650            }
651            $.each(pics, function (index, pic) {
652                self.addPicture(pic, prepend);
653            });
654        },
655
656        addPicture: function (pic, prepend) {
657            var self = this;
658            var listItem$ = $('.__CbUiHiddenTemplates .pix-image-list-item');
659            var tileItem$ = $('.__CbUiHiddenTemplates .pix-image-tile-item');
660            var container$ = self.element().find('.pix-overview');
661            var title = '', subtitle = '';
662
663            //container item generation: if 2nd parameter is a number -> getThumbnail,
664            //if 2nd parameter is a string -> image transformer request with parameters
665            var insertPic = function (insert$, size) {
666
667                if (typeof pic !== 'object')
668                    return false;
669
670                var remaining = insert$.hasClass('pix-image-list-item') ? 60 : 40;
671                var scale = insert$.hasClass('pix-image-list-item') ? 4 : 2;
672                var params = insert$.hasClass('pix-image-list-item') ? '&do=cropIn&color=ffffff' : '&do=rescaleIn';
673
674                if (pic.CbMdbTmedia2ShareGroups && pic.CbMdbTmedia2ShareGroups.length > 0) {
675                    insert$.addClass("share-group-active");
676                } else {
677                    insert$.addClass("share-group-not-active");
678                }
679
680                //generate trimmed title and subtitle strings
681                if (pic.Title !== null) {
682                    title = (pic.Title.length > remaining) ?
683                            (pic.Title.substr(0, remaining - 3) + '...') : pic.Title;
684                    remaining -= title.length;
685                }
686                if (pic.Subtitle !== null) {
687                    subtitle = (pic.Subtitle.length > remaining) ?
688                            (pic.Subtitle.substr(0, Math.max(0, remaining - 3)) + '...') : pic.Subtitle;
689                }
690
691                if (typeof size === 'number') {
692                    $(insert$.find('img')).attr('src', getThumbnail(pic, size));
693                } else if (typeof size === 'string') {
694                    $(insert$.find('img')).attr('src', 'https://imgtoolkit.culturebase.org?file=' +
695                            getThumbnail(pic, scale) + '&height=' + size + '&width=' + size + '&quality=8' + params);
696                }
697
698                //workaround for image size detection
699                var maxDim = Math.max(pic.Height, pic.Width);
700                var scaleFactor = config.cntnrDim / maxDim;
701                $(insert$.find('img')).data('width', maxDim == pic.Height ? pic.Width * scaleFactor : config.cntnrDim);
702                $(insert$.find('img')).data('height', maxDim == pic.Width ? pic.Height * scaleFactor : config.cntnrDim);
703
704                $(insert$.find('.pix-image-width')).text(pic.Width + 'px');
705                $(insert$.find('.pix-image-height')).text(pic.Height + 'px');
706
707                if (title !== '' && typeof title != 'undefined') {
708                    $(insert$.find('.pix-image-title')).removeClass('title-missing');
709                    $(insert$.find('.pix-image-title')).text(title);
710                } else {
711                    $(insert$.find('.pix-image-title')).addClass('title-missing');
712                }
713
714                if (pic.Keywords.length) {
715                    $(insert$.find('.pix-image-keywords')).addClass('pix-image-text').text(pic.Keywords.join(config.keywordsDelim));
716                }
717
718                var insImg = insert$.find('.pix-edit-form-button.pix-insert-image');
719
720                var copyright = pic.Copyright ? '© ' + pic.Copyright : '';
721                $(insert$.find('.pix-image-copyright')).text(copyright);
722
723                if (isPixInCbPix()) {
724                    insImg.hide();
725                } else {
726                    insImg.click(function (e) {
727                        e.preventDefault();
728
729                        // check for field checks
730                        if (config.checkFields === true) {
731                            // collect pics
732                            checkPicFields(pic, self);
733
734                        } else {
735                            if (typeof self.options.selectPicture !== 'undefined') {
736                                self.destroy();
737                                /**
738                                 * @param {object} pic picture object
739                                 */
740                                self.options.selectPicture(pic);
741                            }
742                        }
743
744                    });
745                }
746
747                if (typeof self.options.selectPicture === 'undefined') {
748                    insert$.addClass('pix-no-insert');
749                }
750
751                insert$.find('.pix-edit-icon.delete').click(function (e) {
752                    var t = $(this);
753                    e.preventDefault();
754                    if (confirm('Löschen?')) {
755                        $.post(config.pictures + '/' + pic.Id, {
756                            method: 'DELETE'
757                        }, function (data) {
758                            if (data === true)
759                                t.closest('.pix-image-tile-item').remove();
760                        }).fail(PIX.UX.ajaxError);
761                    }
762                });
763
764                insert$.find('.pix-image-title, .list-edit-icon, .pix-edit-icon.edit').click(function (e) {
765                    e.preventDefault();
766
767                    // remember previous pic settings
768                    self.setPicStorage();
769
770                    new PIX.PictureMetaWindow({
771                        prev: 'PictureManageWindow',
772                        zoom: self.zoom,
773                        viewState: self.viewState
774                    }, self.options, pic).open({
775                        delay: 0
776                    });
777                    self.close();
778                });
779
780                // picture selection check
781                var tileActions = $('.pix-image-tile-actions', insert$);
782                if (self.isPictureCollected(pic.Id)) {
783                    tileActions.addClass('pic-selected');
784                    $('.select-checkbox', tileActions).prop('checked', true);
785                }
786                $('.select-checkbox', insert$).on('click', function (e) {
787                    var loader = new $.CbWidget.loader();
788                    loader.show();
789                    if ($(this).is(':checked')) {
790                        tileActions.addClass('pic-selected');
791                        self.collectPicture(pic.Id);
792                    } else {
793                        tileActions.removeClass('pic-selected');
794                        self.uncollectPicture(pic.Id);
795                    }
796                    self.toggleSelectBar();
797                    setTimeout(function () {
798                        loader.hide();
799                    }, 0);
800                });
801
802                if (prepend) {
803                    container$.prepend(insert$);
804                } else {
805                    container$.append(insert$);
806                }
807                self.allPictures[pic.Id] = pic;
808                self.togglePlaceholder();
809
810                // Append custom tooltip to image tile.
811                insert$.attr('data-pix-id', pic.Id);
812
813                $('.pix-image-tile-tooltip-anchor', insert$).attr('href', pic.Uri);
814            };
815            if (prepend && pic.Id) {
816                self.pictures.unshift(pic);
817            } else {
818                self.pictures.push(pic);
819            }
820
821            //generate one list- and one tile item for each picture
822            insertPic(self.tileItemTemplate.clone(), config.cntnrDim + 'px');
823            insertPic(self.listItemTemplate.clone(), config.thumbnailDim + 'px');
824        },
825
826        handleLoadedPics: function (pictures) {
827            var self = this;
828            var loader = new $.CbWidget.loader();
829            loader.show();
830            self.scrollEndReached = pictures.length < getPicturesLimit(self) ? true : false;
831            $.each(pictures, function (i, pic) {
832                // TODO: save the pictures' IDs and don't add dupes
833                // we might get dupes by adding/removing and scrolling
834                self.addPicture(pic);
835                //when all pictures have been loaded, align them once
836                if (i == pictures.length - 1) {
837                    alignImages('tile');
838                }
839            });
840            self.loading = false;
841            self.togglePlaceholder();
842            // init the select bar
843            self.toggleSelectBar();
844            // jump to last scroll pos
845            if ($.jStorage.get('picturesLength') && self.scrollPos) {
846                $('.pix-scrollbar-container', self.element()).animate({scrollTop: self.scrollPos}, 'slow');
847            }
848            $.jStorage.deleteKey('picturesLength');
849
850            self.bindHoverListener();
851            loader.hide();
852        },
853
854        loadCollectedPictures: function () {
855            var self = this;
856            //show spinner animation during picture loading
857            var loader = new $.CbWidget.loader(),
858                    collectedPics = self.getCollectedPictures();
859            if (collectedPics.length) {
860                loader.show();
861                $.getJSON(config.pictures + '/by/' + config.auth.accountId, {
862                    ids: collectedPics
863                }, function (pictures) {
864                    self.handleLoadedPics(pictures);
865                })
866                        .fail(PIX.UX.ajaxError)
867                        .always(function () {
868                            loader.hide();
869                        });
870            }
871        },
872
873        loadPictures: function () {
874            var self = this,
875                    picturesLength = $.jStorage.get('picturesLength'),
876                    from = picturesLength ? 0 : self.pictures.length,
877                    limit = picturesLength ? picturesLength : getPicturesLimit(self);
878            if (self.previousSeriesId != -1) {
879                self.scrollEndReached = false;
880            }
881            if (self.loading || self.scrollEndReached)
882                return;
883            self.loading = true;
884            //show spinner animation during picture loading
885            var loader = new $.CbWidget.loader();
886            loader.show();
887            $.getJSON(config.pictures + '/by/' + config.auth.accountId, {
888                from: from,
889                limit: limit,
890                filter: self.filter
891            }, function (pictures) {
892                self.onInitEmpty = !pictures.length && !from && limit == getPicturesLimit(self) && !self.filter;
893                self.handleLoadedPics(pictures);
894            })
895                    .fail(function () {
896                        window.location.reload();
897                    })
898                    .always(function () {
899                        loader.hide();
900                    });
901        },
902
903        loadSeriesPictures: function (id) {
904            var self = this,
905                    picturesLength = $.jStorage.get('picturesLength'),
906                    from = picturesLength ? 0 : self.pictures.length,
907                    limit = picturesLength ? picturesLength : getPicturesLimit(self);
908            if (self.previousSeriesId != self.seriesId) {
909                self.scrollEndReached = false;
910            }
911            if (self.loading || self.scrollEndReached)
912                return;
913            self.loading = true;
914            //show spinner animation during picture loading
915            var loader = new $.CbWidget.loader();
916            loader.show();
917            $.getJSON(config.series + '/' + self.seriesId + '/pictures', {
918                from: from,
919                limit: limit,
920                filter: self.filter
921            }, function (pictures) {
922                self.onInitEmpty = false;
923                self.handleLoadedPics(pictures);
924            })
925                    .fail(PIX.UX.ajaxError)
926                    .always(function () {
927                        loader.hide();
928                    });
929            self.previousSeriesId = self.seriesId;
930            // init the select bar
931            self.toggleSelectBar();
932        },
933
934        /**
935         *
936         * @returns {undefined}
937         */
938        updateCollectedPicturesCounter: function () {
939            var count = this.getCollectedPicturesCount(),
940                    dd = $('#dropdown-select'),
941                    // do not update counter for filtered entries
942                    filter = ':not(:has(input[value="duplicates"],input[value="invert"]))';
943            $('.dd-select', dd).filter(filter).find('.dd-selected-description').text(count);
944            $('.dd-option', dd).filter(filter).find('.dd-desc').text(count);
945        },
946
947        /**
948         *
949         * @returns {Mixed|jQuery.jStorage.get.def|_$.jStorage.get.def|mixed}
950         */
951        getCollectedPictures: function () {
952            var collectedPictures = $.jStorage.get('collectedPictures') || [];
953//         console.log("### getCollectedPictures ###");
954//         console.log(collectedPictures);
955            return collectedPictures;
956        },
957
958        /**
959         *
960         * @param {type} val
961         * @returns {undefined}
962         */
963        setCollectedPictures: function (val) {
964//          var loader = new $.CbWidget.loader();
965//          loader.show();
966//        console.log("### setCollectedPictures ###");
967//         console.log(val);
968            $.jStorage.set('collectedPictures', val);
969            this.updateCollectedPicturesCounter();
970
971        },
972
973        /**
974         *
975         * @param {type} val
976         * @returns {undefined}
977         */
978        clearCollectedPictures: function (val) {
979            this.setCollectedPictures([]);
980        },
981
982        /**
983         *
984         * @returns int
985         */
986        getCollectedPicturesCount: function () {
987            var collectedPictures = this.getCollectedPictures();
988            return collectedPictures ? collectedPictures.length : 0;
989        },
990
991        /**
992         *
993         * @param {type} id
994         * @returns {pix_L1.pixAnonym$24.isPictureCollected@call;getCollectedPictures|Boolean}
995         */
996        isPictureCollected: function (id) {
997            var collectedPictures = this.getCollectedPictures();
998            return collectedPictures && $.inArray(id, collectedPictures) > -1;
999        },
1000
1001        /**
1002         *
1003         * @param {type} id
1004         * @returns {undefined}
1005         */
1006        collectPicture: function (id) {
1007            if (!this.isPictureCollected(id)) {
1008                var collectedPictures = this.getCollectedPictures() || [];
1009                collectedPictures.push(id);
1010                this.setCollectedPictures(collectedPictures);
1011            }
1012        },
1013
1014        /**
1015         *
1016         * @param {type} id
1017         * @returns {undefined}
1018         */
1019        uncollectPicture: function (id) {
1020            console.log("uncollectPicture I    " + id);
1021            if (this.isPictureCollected(id)) {
1022                var collectedPictures = this.getCollectedPictures();
1023
1024                var filteredCollectedPictures = collectedPictures.filter(function (elem) {
1025                    return elem != id;
1026                });
1027                
1028                this.setCollectedPictures(filteredCollectedPictures);
1029            }
1030        },
1031
1032        handleReady: function (params) {
1033            var self = this;
1034            self.loadMl(function () {
1035                self.listItemTemplate = $('.__CbUiHiddenTemplates .pix-image-list-item');
1036                self.tileItemTemplate = $('.__CbUiHiddenTemplates .pix-image-tile-item');
1037                $.CbWidgetRegistry.apply(self.listItemTemplate);
1038                $.CbWidgetRegistry.apply(self.tileItemTemplate);
1039                self.pictures = [];
1040                if (self.seriesId) {
1041                    self.loadSeriesPictures();
1042                } else {
1043                    self.loadPictures();
1044                }
1045
1046                var el = self.element(),
1047                        scroller = el.find('.pix-scrollbar-container'),
1048                        container = el.find('.pix-overview'),
1049                        xmlCodec = new $.CbUtil.xml_codec();
1050
1051                // scroll behaviour
1052                scroller.scroll(function () {
1053                    scroller.scrollTop();
1054                    if (scroller.scrollTop() + scroller.height() >= container.height()) {
1055                        if (self.seriesId) {
1056                            self.loadSeriesPictures();
1057                        } else {
1058                            self.loadPictures();
1059                        }
1060
1061                        if (self.scrollEndReached) {
1062                            $('.end-mark').animate({'height': 20});
1063                            setTimeout(function () {
1064                                $('.end-mark').animate({'height': 0});
1065                            }, 700);
1066                        }
1067                    }
1068                    self.scrollPos = scroller.scrollTop();
1069                    $.jStorage.set('scrollPos', self.scrollPos);
1070                });
1071
1072                // pic upload - dropzone
1073                var loader = new $.CbWidget.loader();
1074                var form = el.find('.pix-image-uploader form');
1075                // the dropzone blockelement
1076                var dropzone = $('.pix-advanced');
1077                // IE > 9 || modern browser
1078                if (window.FileReader && dropzone.length > 0) {
1079                    // upload dropzone
1080                    // switch between button and drag-drop-upload
1081                    $('.pix-standard').hide();
1082                    dropzone.show();
1083                    $('.pix-uploader-switch').on('click', function () {
1084                        $('.pix-uploader-input').show();
1085                        $(this).parents('.pix-uploader-input').hide();
1086                    });
1087                    //configuring the dropzone, loading animation etc.
1088                    var loaderWithProgress = new $.CbWidget.loaderWithProgress();
1089                    var allowedExtensions = '.jpeg, .jpg, .gif, .png';
1090                    var dropzoneObject = new DragDropUpload(
1091                            '.pix-file, .pix-advanced',
1092                            config.pictures + '/by/' + config.auth.accountId + '.json',
1093                            'image_upload[]',
1094                            'pix-upload-form'
1095                            );
1096                    dropzoneObject.setValidation({extensions: allowedExtensions, fileSize: '10MB', postSize: '20MB'});
1097                    $(dropzoneObject).on('uploadStart', function (e, xhr, fileListArray, notValidatedArray) {
1098                        loaderWithProgress.setStart(xhr, fileListArray, notValidatedArray, allowedExtensions);
1099                    });
1100                    $(dropzoneObject).on('validationError', function (e, notValidated, valObject) {
1101                        loaderWithProgress.setEnd(notValidated, valObject);
1102                    });
1103                    $(dropzoneObject).on('uploadProgress', function (e, percentComplete, loaded, total) {
1104                        loaderWithProgress.setProgress(percentComplete, loaded, total);
1105                    });
1106                    $(dropzoneObject).on('uploadSuccess', function (e, data) {
1107                        loaderWithProgress.setEnd();
1108                        self.addPictures(data, true);
1109                        setTimeout(alignImages, 3000);
1110                    });
1111                    $(dropzoneObject).on('uploadError', function (e, data) {
1112                        loaderWithProgress.setEnd();
1113                        PIX.UX.ajaxError({}, 'error', 'dropzone upload error');
1114                    });
1115                } else {
1116                    // upload form submit
1117                    form.attr("action", config.pictures + '/by/' + config.auth.accountId + '.xml');
1118                    form.submit(function () {
1119                        loader.show();
1120                        var uploadForm = $(this);
1121                        var uploadFrameName = 'upload' + Math.floor(Math.random() * 4096);
1122                        var uploadFrame = $('.__CbUiHiddenTemplates .pix-upload-frame')
1123                                .clone()
1124                                .attr('name', uploadFrameName);
1125                        uploadForm.attr('target', uploadFrameName);
1126                        uploadForm.append(uploadFrame);
1127                        uploadFrame.load(function () {
1128                            // upload finished here; silly XML parsing, as we cannot deliver
1129                            // JSON to the iframe.
1130                            self.addPictures(xmlCodec.decode(uploadFrame.contents().children()), true);
1131                            uploadFrame.remove();
1132
1133                            // resets
1134                            uploadForm.attr('target', '');
1135                            uploadForm.find('.pix-file').val('');
1136                            loader.hide();
1137                        });
1138                    });
1139                    el.find('.pix-file').change(function () {
1140                        if ($(this).val() !== '')
1141                            $(this).parents('form').submit();
1142                    });
1143                }
1144
1145                // pix filter
1146                $('.pix-filter-form', el).each(function () {
1147                    var t = $(this),
1148                            input = el.find('.pix-filter-input');
1149                    if (self.filter) {
1150                        input.val(self.filter);
1151                    }
1152                    t.submit(function (e) {
1153                        e.preventDefault();
1154                        self.filter = input.val();
1155
1156                        // make sure to remove empty filter, otherwise empty value is passed
1157                        // to backend
1158                        if (self.filter === '')
1159                            delete self.filter;
1160
1161                        self.resetViewAndQuery();
1162                        if (self.seriesId) {
1163                            self.loadSeriesPictures();
1164                        } else {
1165                            self.loadPictures();
1166                        }
1167                    });
1168                });
1169
1170                bindMenuButtons(self, 'PictureManageWindow');
1171
1172                self.base(params);
1173
1174                // generate all styled selectboxes
1175                self.generateDD();
1176
1177                // view list tiles toggle
1178                $('.view-toggle', el).click(function () {
1179                    $(this).toggleClass('list tiles');
1180                    var revertedViewState = self.viewState === 'tiles' ? 'list' : 'tiles';
1181                    toggleViews(revertedViewState);
1182                    self.viewState = revertedViewState;
1183                });
1184
1185                // if a view state has been passed from the previous window,
1186                // set toggle button and view accordingly
1187                if (self.viewState) {
1188                    var viewToggleClass = self.viewState === 'tiles' ? 'list' : 'tiles';
1189                    $('.view-toggle', el).removeClass('list').addClass(viewToggleClass);
1190                    toggleViews(self.viewState);
1191                } else {
1192                    self.viewState = 'tiles';
1193                    $(this).toggleClass('list tiles');
1194                    toggleViews(self.viewState);
1195                }
1196
1197                self.setSupportLink(self.options);
1198
1199                // pic select bar
1200                $('.select-bar', el).each(function () {
1201                    var t = $(this);
1202                    // pic select "submit" button
1203                    $('.pix-selection-button', t).click(function () {
1204                        var
1205                                action = $('.pix-dropdown-select-box .dd-selected-value', t).val(),
1206                                seriesId = $('.pix-select-bar-dropdown-filter-box .dd-selected-value', t).val(),
1207                                collectedPictures = self.getCollectedPictures(),
1208                                seriesUrl = config.series + '/' + seriesId,
1209                                reloadSeriesPictures = function (series) {
1210                                    self.clearCollectedPictures();
1211                                    $.jStorage.set('seriesId', series.Id);
1212                                    self.seriesId = series.Id;
1213                                   
1213 self.resetViewAndQuery();
1214                                    self.loadSeriesPictures();
1215                                    ddslickSelectByValue($('#dropdown-filter', el), series.Id);
1216                                };
1217
1218                        switch (action) {
1219                            case 'insert':
1220                                // insert into app
1221                                if (typeof self.options.selectPicture !== 'undefined') {
1222                                    self.destroy();
1223                                    var pics = collectedPictures.map(function (id) {
1224                                        return self.allPictures[id];
1225                                    });
1226                                    /**
1227                                     * @param {array} pics array of picture objects
1228                                     */
1229                                    // check for field checks
1230                                    if (config.checkFields === true) {
1231                                        // collect pics
1232                                        checkPicFields(pics, self);
1233
1234                                    } else {
1235                                        self.options.selectPicture(pics);
1236                                    }
1237                                }
1238                                break;
1239                            case 'add':
1240                                // add to series
1241                                $.post(seriesUrl, {
1242                                    pic_ids: collectedPictures,
1243                                    method: 'PUT'
1244                                }, reloadSeriesPictures).fail(PIX.UX.ajaxError);
1245                                break;
1246                            case 'remove':
1247                                // remove from series
1248                                $.post(seriesUrl, {
1249                                    pic_ids: collectedPictures,
1250                                    method: 'DELETE'
1251                                }, reloadSeriesPictures).fail(PIX.UX.ajaxError);
1252                                break;
1253                        }
1254
1255                    });
1256
1257                    // clear collected pics
1258                    $('.deselect-button', t).click(function () {
1259                        $('.pix-scrollbar-container .select-checkbox').prop('checked', false);
1260                        self.clearCollectedPictures();
1261                        self.toggleSelectBar();
1262                    });
1263                });
1264
1265                // pic series manage button
1266                $('.pix-add-series', el).click(function () {
1267                    new PIX.PictureSeriesMetaWindow({
1268                        prev: 'PictureManageWindow',
1269                        zoom: self.zoom,
1270                        viewState: self.viewState
1271                    }, self.options).open({
1272                        delay: 0
1273                    });
1274                    self.close();
1275                });
1276                $('.pix-edit-series', el).click(function () {
1277                    new PIX.PictureSeriesMetaWindow({
1278                        prev: 'PictureManageWindow',
1279                        zoom: self.zoom,
1280                        viewState: self.viewState
1281                    }, self.options, self.allSeries[self.seriesId]).open({
1282                        delay: 0
1283                    });
1284                    self.close();
1285                });
1286                togglePicSeriesButtons(self);
1287
1288                self.bindHoverListener();
1289
1290                if ($('.fullscreen-switch').length) {
1291                    if (self.zoom)
1292                        self.doZoom(self);
1293                    $('.fullscreen-switch').on('click', function () {
1294                        self.setZoom(self);
1295                    });
1296                }
1297
1298                $(document).mousemove(function (event) {
1299                    if ($('.pix-image-tile-tooltip-list').length) {
1300                        $('.pix-image-tile-tooltip-list')
1301                                .css({'left': event.pageX - $('.__CbUiLayerFrame .__CbUiContent')
1302                                            .offset().left + self.cursorIconOffset, 'top': event.pageY - $('.__CbUiLayerFrame .__CbUiContent')
1303                                            .offset().top + self.cursorIconOffset});
1304                    }
1305                });
1306            });
1307        },
1308
1309        undoZoom: function (self) {
1310            this.base(self, config);
1311        },
1312
1313        getWindowFrameOffset: function () {
1314            var self = this;
1315            self.windowXOffset = $('.__CbUiLayerFrame .__CbUiContent').offset().left;
1316            self.windowYOffset = $('.__CbUiLayerFrame .__CbUiContent').offset().top;
1317        },
1318        /**
1319         * Toggle the footer pic selection bar depending on the amount of selected
1320         * pictures.
1321         * @returns {undefined}
1322         */
1323        toggleSelectBar: function () {
1324            if (this.getCollectedPicturesCount()) {
1325                this.updateCollectedPicturesCounter();
1326                $('.select-bar').show();
1327                $('.pix-form-content-container').addClass('select-bar-is-up');
1328            } else {
1329                $('.select-bar').hide();
1330                $('.pix-form-content-container').removeClass('select-bar-is-up');
1331            }
1332        },
1333        showSelectBar: function () {
1334            $('.select-bar').animate({'height': 37});
1335            $('.end-mark').animate({'bottom': 44});
1336            var scrollbarContainerHeight = $('.pix-scrollbar-container').height();
1337            $('.pix-scrollbar-container').animate({'height': scrollbarContainerHeight - 37});
1338            $('.select-bar').addClass('expanded');
1339            $('.pix-scrollbar-container').addClass('squeezed');
1340        },
1341        hideSelectBar: function () {
1342            $('.select-bar').removeClass('expanded');
1343            $('.pix-scrollbar-container').removeClass('squeezed');
1344            $('.select-bar').animate({'height': 0});
1345            $('.end-mark').animate({'bottom': 7});
1346            var scrollbarContainerHeight = $('.pix-scrollbar-container').height();
1347            $('.pix-scrollbar-container').animate({'height': scrollbarContainerHeight + 37});
1348        },
1349        togglePlaceholder: function () {
1350            var self = this;
1351            //if there are no images, hide the corresponding scrollbar and inputs by showing a placeholder instead
1352            // This is not working as expected and is distroying the interface
1353            if (self.pictures.length) {
1354                $('.content-cntnr, #dropdown-uploader').removeClass('not-displayed');
1355                $('.__PixWindow .empty-content-placeholder').addClass('not-displayed');
1356                $('.pix-add-series').show();
1357                self.onInitEmpty = false;
1358            } else if (self.onInitEmpty) {
1359                $('.pix-add-series').hide();
1360                $('.content-cntnr, #dropdown-uploader').addClass('not-displayed');
1361                $('.__PixWindow .empty-content-placeholder').removeClass('not-displayed');
1362            }
1363        },
1364        resetViewAndQuery: function () {
1365            this.pictures = [];
1366            this.scrollEndReached = false;
1367            this.clearPicStorage();
1368            this.element().find('.pix-overview').empty();
1369        },
1370        /**
1371         * generate all styled selectboxes
1372         * @returns {undefined}
1373         */
1374        generateDD: function () {
1375            var self = this,
1376                    initialized = false;
1377            var loader = new $.CbWidget.loader();
1378            loader.show();
1379            $.getJSON(config.series + '/by/' + config.auth.accountId, {
1380                from: 0
1381            }, function (series) {
1382                //two temporary dummy objects for the dropdown's functional demonstration
1383                var dummyUploadddData = [
1384                    {
1385                        text: self.ml('picture_manage_upload_to'),
1386                        value: 1,
1387                        selected: false,
1388                        description: self.ml('picture_manage_upload_to_description'),
1389                        imageSrc: "/pix/media/png/pic-icon-25-green.png"
1390                    }
1391                ],
1392                        dummyFilterddData = [
1393                            {
1394                                text: self.ml('picture_manage_filter_all'),
1395                                value: null,
1396                                selected: false,
1397                                description: self.ml('picture_manage_filter_all_description'),
1398                                imageSrc: "/pix/media/png/pic-icon-20-green.png"
1399                            },
1400                            {
1401                                text: self.ml('picture_manage_filter_marked'),
1402                                value: 0,
1403                                selected: false,
1404                                description: self.ml('picture_manage_filter_marked_description'),
1405                                imageSrc: "/pix/media/png/pic-icon-20-green.png"
1406                            }],
1407                        dummyFilterSelectddData = null,
1408                        dummySelectddData = [
1409                            {
1410                                text: self.ml('please_choose'),
1411                                value: 0,
1412                                selected: false,
1413                                description: " "
1414                            }
1415                        ];
1416
1417                if (!isPixInCbPix()) {
1418                    $.merge(dummySelectddData, [
1419                        {
1420                            text: self.ml('_insert'),
1421                            value: "insert",
1422                            selected: false,
1423                            description: " "
1424                        }
1425                    ]);
1426                }
1427
1428                $.merge(dummySelectddData, [
1429                    {
1430                        text: self.ml('show_duplicates'),
1431                        value: "duplicates",
1432                        selected: false,
1433                        description: " "
1434                    },
1435                    {
1436                        text: self.ml('invert_selection'),
1437                        value: "invert",
1438                        selected: false,
1439                        description: " "
1440                    },
1441                    {
1442                        text: self.ml('add_to_series'),
1443                        value: "add",
1444                        selected: false,
1445                        description: " "
1446                    },
1447                    {
1448                        text: self.ml('remove_from_series'),
1449                        value: "remove",
1450                        selected: false,
1451                        description: " "
1452                    }
1453                ]);
1454
1455
1456                var item;
1457                if (series.length) {
1458                    dummyFilterSelectddData = [];
1459                    jQuery.each(series, function (i, s) {
1460                        self.allSeries[s.Id] = s;
1461                        item = {
1462                            text: s.Title,
1463                            value: s.Id,
1464                            selected: self.seriesId && +self.seriesId === s.Id ? true : false,
1465                            imageSrc: "/pix/media/png/pic-icon-20-green.png"
1466                        };
1467                        dummyFilterddData.push(item);
1468                        dummyFilterSelectddData.push(item);
1469                    });
1470                    $('#select-bar-dropdown-filter').ddslick({
1471                        data: dummyFilterSelectddData,
1472                        width: 275,
1473                        imagePosition: "left",
1474                        onSelected: function (selected) {}
1475                    });
1476                }
1477                $('#dropdown-uploader').ddslick({
1478                    data: dummyUploadddData,
1479                    width: 212,
1480                    imagePosition: "left",
1481                    onSelected: function (selected) {}
1482                });
1483                $('#dropdown-filter').ddslick({
1484                    data: dummyFilterddData,
1485                    width: 275,
1486                    imagePosition: "left",
1487                    onSelected: function (selected) {
1488                        /*
1489                         * This is a workaround to prevent ddslick plugin
1490                         * from firing the 'select' event when the window
1491                         * is open.
1492                         */
1493                        if (initialized) {
1494                            self.seriesId = selected.selectedData.value;
1495                            self.resetViewAndQuery();
1496                            if (self.seriesId > 0) {
1497                                // series
1498                                $.jStorage.set('seriesId', self.seriesId);
1499                                self.loadSeriesPictures();
1500                            } else if (selected.selectedData.value === 0) {
1501                                // collected
1502                                self.scrollEndReached = true;
1503                                $.jStorage.deleteKey('seriesId');
1504                                self.previousSeriesId = -1;
1505                                delete self.seriesId;
1506                                self.loadCollectedPictures();
1507                            } else {
1508                                // all
1509                                $.jStorage.deleteKey('seriesId');
1510                                self.previousSeriesId = -1;
1511                                delete self.seriesId;
1512                                self.loadPictures();
1513                            }
1514                            togglePicSeriesButtons(self);
1515                        } else {
1516                            initialized = true;
1517                        }
1518                    }
1519                });
1520                $('#dropdown-select').ddslick({
1521                    data: dummySelectddData,
1522                    width: 275,
1523                    imagePosition: "left",
1524                    onSelected: function (selected) {
1525                        if (initialized) {
1526
1527                            var selectVal = selected.selectedData.value;
1528
1529                            $('#select-bar-dropdown-filter').show();
1530
1531                            //show the series select box in case series-related actions are selected
1532                            if (selectVal === 'add' || selectVal === 'remove') {
1533                                $('.pix-select-bar-dropdown-filter-box').show('fast');
1534                            } else if (selectVal === 'invert') {
1535                                // invert selection
1536                                $('.pix-overview input.select-checkbox', self.element()).each(function () {
1537                                    $(this)[0].click();
1538                                });
1539                            } else if (selectVal === 'duplicates') {
1540                                // filter duplicates
1541                                var dups = {};
1542                                // collect pic with same hash
1543                                $.each(self.allPictures, function (id, pic) {
1544                                    if (pic.HashValue) {
1545                                        if (typeof dups[pic.HashValue] === 'undefined') {
1546                                            dups[pic.HashValue] = [];
1547                                        }
1548                                        dups[pic.HashValue].push(pic.Id);
1549                                    }
1550                                });
1551                                // filter all dups sorted in overview
1552                                if (!$.isEmptyObject(dups)) {
1553                                    var dupIndex = 0;
1554                                    // jump to top to avoid pic loading when view is resorted
1555                                    $('.pix-scrollbar-container', self.element()).scrollTop(0);
1556                                    $.each(dups, function (dk, picdups) {
1557                                        if (picdups.length > 1) {
1558                                            // dups found
1559                                            $.each(picdups, function (pk, picdupId) {
1560                                                $('.pix-overview > span[data-pix-id="' + picdupId + '"]', self.element())
1561                                                        .attr('data-dup-index', dupIndex);
1562                                                dupIndex++;
1563                                            });
1564                                        }
1565                                    });
1566                                    // resort view
1567                                    var dupItems = $('.pix-overview > span[data-dup-index]');
1568                                    dupItems.sort(function (a, b) {
1569                                        var aInt = parseInt($(a).data('dup-index')),
1570                                                bInt = parseInt($(b).data('dup-index'));
1571                                        return aInt > bInt ? 1 : (aInt < bInt ? -1 : 0);
1572                                    });
1573                                    $('.pix-overview', self.element()).empty().append(dupItems);
1574                                    self.bindHoverListener();
1575                                }
1576                            } else {
1577                                $('.pix-select-bar-dropdown-filter-box').hide('fast');
1578                            }
1579
1580                            //remove prompt pseudo option from selection when an option has been selected
1581                            if (selectVal !== 0) {
1582                                $('#dropdown-select .dd-options li:first-child').hide();
1583                                $('.pix-dropdown-select-box').removeClass('initial-view');
1584                            }
1585
1586                            self.updateCollectedPicturesCounter();
1587
1588                        } else {
1589                            initialized = true;
1590                        }
1591                    }
1592                });
1593
1594            })
1595                    .fail(PIX.UX.ajaxError)
1596                    .always(function () {
1597                        loader.hide();
1598                    });
1599        },
1600
1601        bindHoverListener: function () {
1602            var self = this;
1603            var hoverTargets = $('.pix-overview .pix-image-tile-item .pix-image-tile-tooltip').off();
1604            hoverTargets.hover(
1605                    //enterHandler
1606                            function (event) {
1607                                var id = $(this).closest('.pix-image-tile-item').attr('data-pix-id');
1608                                var $thisList = $('.pix-image-tile-tooltip-list');
1609                                this.toolTipTimeout = setTimeout(function () {
1610                                    self.populateTooltip(self.allPictures[id]);
1611                                    $thisList.show('fast');
1612                                }, 800);
1613                            },
1614                            //leaveHandler
1615                                    function (event) {
1616                                        $('.pix-image-tile-tooltip-list').hide('fast');
1617                                        clearTimeout(this.toolTipTimeout);
1618                                    });
1619                        },
1620
1621                populateTooltip: function (pic) {
1622                    var self = this;
1623                    var toolTipsList = $('.pix-image-tile-tooltip-list'),
1624                            datePlace = 0,
1625                            originatorAgency = 0,
1626                            isDatePlaceTagsEmpty = true,
1627                            isDescWrprEmpty = true;
1628                    var addToTemplate = function (propertyName, contentFromVal) {
1629                        toolTipsList.find('.' + propertyName).html(contentFromVal);
1630                    };
1631                    for (var property in pic) {
1632                        var propertyValue = '';
1633                        if (pic.hasOwnProperty(property)) {
1634                            switch (property) {
1635                                // for the title and link properties set a default value, if not available
1636                                case 'Title':
1637                                    addToTemplate(property, pic[property] ? pic[property] : self.ml('tooltip_please_enter_picture_title'));
1638                                    break;
1639                                case 'Link':
1640                                    addToTemplate(property, pic[property]);
1641                                    break;
1642                                case 'Subtitle':
1643                                    addToTemplate(property, pic[property] ? '// ' + pic[property] : '');
1644                                    break;
1645                                case 'Id':
1646                                    addToTemplate(property, '(' + pic[property] + ')');
1647                                    break;
1648                                case 'Height':
1649                                    addToTemplate(property, 'H: ' + pic[property]);
1650                                    break;
1651                                case 'Width':
1652                                    addToTemplate(property, 'B: ' + pic[property]);
1653                                    break;
1654                                case 'Copyright':
1655                                    addToTemplate(property, pic[property] ? '// © ' + pic[property] : '');
1656                                    break;
1657                                case 'Date':
1658                                    addToTemplate(property, pic[property] ? pic[property] : '');
1659                                    if (pic[property]) {
1660                                        isDatePlaceTagsEmpty = false;
1661                                        datePlace++;
1662                                    }
1663                                    break;
1664                                case 'Place':
1665                                    addToTemplate(property, pic[property] ? pic[property] : '');
1666                                    if (pic[property]) {
1667                                        isDatePlaceTagsEmpty = false;
1668                                        datePlace++;
1669                                    }
1670                                    break;
1671                                case 'Originator':
1672                                    addToTemplate(property, pic[property] ? property + ': ' + pic[property] : '');
1673                                    if (pic[property]) {
1674                                        originatorAgency++;
1675                                    }
1676                                    break;
1677                                case 'Agency':
1678                                    addToTemplate(property, pic[property] ? property + ': ' + pic[property] : '');
1679                                    if (pic[property]) {
1680                                        originatorAgency++;
1681                                    }
1682                                    break;
1683                                case 'Keywords':
1684                                    addToTemplate(property, pic[property].length ? 'Tags: ' + pic[property] : '');
1685                                    if (pic[property].length) {
1686                                        isDatePlaceTagsEmpty = false;
1687                                    }
1688                                    break;
1689                                    // for an object property, iterate trough its direct children
1690                                case 'DescriptionsByIdLanguage':
1691                                    propertyValue = '';
1692                                    for (var subProperty in pic[property]) {
1693                                        var truncText = pic[property][subProperty];
1694                                        if (truncText.length > 150)
1695                                            truncText = truncText.substr(0, 150) + ' ... ';
1696                                        propertyValue += '<div class="sub-desc">' + truncText + '</div>';
1697                                        if (pic[property][subProperty] && pic[property][subProperty].length) {
1698                                            isDescWrprEmpty = false;
1699                                        }
1700                                    }
1701                                    addToTemplate(property, propertyValue);
1702                                    break;
1703                            }
1704                        }
1705                    }
1706                    $('.date-place-tags-cntnr, .originator-agency, .desc-wrpr').removeClass('hidden');
1707                    $('.date-place-tags-cntnr .delim, .originator-agency .delim').addClass('hidden');
1708
1709                    if (isDatePlaceTagsEmpty) {
1710                        $('.date-place-tags-cntnr').addClass('hidden');
1711                    }
1712                    if (datePlace === 2) {
1713                        $('.date-place-tags-cntnr .delim').removeClass('hidden');
1714                    }
1715                    if (!originatorAgency) {
1716                        $('.originator-agency').addClass('hidden');
1717                    }
1718                    if (originatorAgency === 2) {
1719                        $('.originator-agency .delim').removeClass('hidden');
1720                    }
1721                    if (isDescWrprEmpty) {
1722                        $('.desc-wrpr').addClass('hidden');
1723                    }
1724                }
1725            });
1726
1727    // PictureMetaWindow --------------------------------------------------------
1728
1729    PIX.PictureMetaWindow = PIX.BaseWindow.extend({
1730        constructor: function (loadOptions, options, data) {
1731            this.base($.extend({template: config.templates + '/picmeta', cls: '__PixWindow'}, loadOptions), options);
1732            this.prev = loadOptions.prev;
1733            this.zoom = loadOptions.zoom;
1734            this.viewState = loadOptions.viewState;
1735            this.autocenter();
1736            this.data = data;
1737            this.options.supportUrl = 'https://pix.culturebase.org/support';
1738            if (this.data.DescriptionsByIdLanguage instanceof Array) {
1739                // make that an object to avoid the "undefined" 0.
1740                this.data.DescriptionsByIdLanguage = {};
1741            } else if (this.data.DescriptionsByIdLanguage[0]) {
1742                // remove invalid 0 value
1743                delete this.data.DescriptionsByIdLanguage[0];
1744            }
1745        },
1746
1747        handleLoad: function (params) {
1748            var self = this;
1749            var selected = false;
1750            var el = self.element();
1751            this.base(params);
1752
1753            this.setSupportLink(this.options);
1754        },
1755
1756        handleReady: function (params) {
1757            var self = this;
1758            var el = this.element();
1759            var isSubmiting = false;
1760            var descEl = el.find('textarea.pix-image-meta-description');
1761            var delButton = $('.pix-delete', el);
1762            var easyFields = ['Title', 'Subtitle', 'Copyright', 'Agency', 'Date',
1763                'Link', 'Originator', 'Place'];
1764            el.find('.pix-image-meta-image-preview').attr("src", getThumbnail(self.data, 2));
1765            $.each(easyFields, function (i, item) {
1766                el.find('input[name="' + item + '"]').val(self.data[item]);
1767            });
1768            switch (self.data.Rights) {
1769                //case 0: // unspecified: We don't allow this anymore. Change to public
1770                case '1': // public
1771                    el.find('input[name="Rights"][value="1"]').attr('checked', true);
1772                    break;
1773                case '2': // protected/press: by policy this is to be changed to public wherever possible
1774
1775                case '3': // private
1776                    el.find('input[name="Rights"][value="3"]').attr('checked', true);
1777                    break;
1778            }
1779            el.find('input[name="Keywords"]').val(self.data.Keywords.join(config.keywordsDelim));
1780
1781            $.each(self.data.DescriptionsByIdLanguage, function (id, val) {
1782                descEl.filter('[data-id-language="' + id + '"]').val(val);
1783            });
1784
1785            delButton.click(function (e) {
1786                var t = $(this);
1787                e.preventDefault();
1788                if (confirm('Löschen?')) {
1789//               $.post(config.picture + '/' + self.data.Id, {
1790//                     method: 'DELETE'
1791//                  }, function(data){
1792//
1793//                  }).fail(PIX.UX.ajaxError);
1794                }
1795            });
1796
1797            // form submit
1798            el.find('form').attr('action', config.pictures + '/' + self.data.Id).submit(function (e) {
1799                e.preventDefault();
1800                if (isSubmiting === true) {
1801                    return false;
1802                }
1803                isSubmiting = true;
1804
1805                var form = $(this), keywords = [];
1806
1807                descEl.each(function () {
1808                    self.data.DescriptionsByIdLanguage[$(this).data('id-language')] = $(this).val();
1809                });
1810
1811                $.each(form.find('input[name="Keywords"]').val().split(config.keywordsDelim), function (i, keyword) {
1812                    if (keyword !== '')
1813                        keywords.push(keyword);
1814                });
1815
1816                var data = {
1817                    descriptions_by_id_language: self.data.DescriptionsByIdLanguage,
1818                    //uri : self.data.Uri,
1819                    keywords: keywords.length ? keywords : '',
1820                    method: 'PUT',
1821                    rights: el.find('input[name="Rights"]:checked').val(),
1822                    share_group: {}
1823                };
1824
1825                $(".pix-share-groups input.pix-share-group-checkbox").each(function (index, shareGroupCheckbox) {
1826                    data.share_group[$(shareGroupCheckbox).attr("name")] = $(shareGroupCheckbox).prop("checked")
1827                });
1828
1829
1830                $.each(easyFields, function (i, field) {
1831                    data[field.toLowerCase()] = form.find('input[name="' + field + '"]').val();
1832                });
1833
1834                var loader = new $.CbWidget.loader();
1835                loader.show();
1836
1837                // post data
1838                $.post(form.attr('action'), data, function (pic) {
1839                    if (typeof self.options.managePicture === 'function') {
1840                        self.destroy();
1841                        self.options.managePicture(pic);
1842                    } else {
1843                        goBack(self);
1844                    }
1845                })
1846                        .fail(PIX.UX.ajaxError)
1847                        .always(function () {
1848                            loader.hide();
1849                        });
1850            });
1851
1852            //add the image info from self
1853            $('.pix-meta-info-id').text((self.data.MetaTmedia ? self.data.MetaTmedia.Id + ' // ' : '') + self.data.Id);
1854            if (self.data.Datetimecreated) {
1855                $('.pix-meta-info-owner-date').text(self.data.Datetimecreated);
1856            }
1857            if (self.data.CreatedBy) {
1858                $('.pix-meta-info-owner').text(self.data.CreatedBy);
1859            }
1860            if (self.data.LastChange) {
1861                $('.pix-meta-info-updater-date').text(self.data.LastChange);
1862            }
1863
1864            var ml = Object.create(PIX.Ml);
1865            var labels = ['share_group_headline'];
1866            ml.fetch(labels, function () {
1867                $.each(self.data.AvailabeShareGroups, function (index, AvailabeShareGroup) {
1868
1869                    if (index === 0) {
1870                        var headlineMarkup = '<span class="pix-share-group-headline">' + ml.get('share_group_headline') + '</span>';
1871                        $(".pix-share-groups").append(headlineMarkup);
1872                    }
1873
1874                    var checked = AvailabeShareGroup.Active === true ? "checked" : "";
1875                    var inputField = '<div class="pix-share-groups-checkbox-container"><input class="pix-share-group-checkbox" type="checkbox" name="share_group_' + AvailabeShareGroup.Id + '" ' + checked + '/><label>' + AvailabeShareGroup.NameMl + '</label></div>';
1876
1877                    $(".pix-share-groups").append(inputField);
1878                });
1879            });
1880
1881
1882
1883            bindMenuButtons(this, 'PictureMetaWindow');
1884            this.base(params);
1885        }
1886    });
1887
1888    // PictureSeriesMetaWindow --------------------------------------------------
1889
1890    PIX.PictureSeriesMetaWindow = PIX.BaseWindow.extend({
1891        constructor: function (loadOptions, options, data) {
1892            this.base($.extend({template: config.templates + '/picseriesmeta', cls: '__PixWindow'}, loadOptions), options);
1893            this.prev = loadOptions.prev;
1894            this.zoom = loadOptions.zoom;
1895            this.viewState = loadOptions.viewState;
1896            this.autocenter();
1897            this.data = data || {};
1898            this.options.supportUrl = 'https://pix.culturebase.org/support';
1899        },
1900
1901        handleLoad: function (params) {
1902            var self = this;
1903            var selected = false;
1904            var el = self.element();
1905
1906            this.base(params);
1907            this.setSupportLink(this.options);
1908        },
1909
1910        handleReady: function (params) {
1911            var self = this,
1912                    el = self.element(),
1913                    titleEl = $('input[name="Title"]', el),
1914                    methodEl = $('input[name="method"]', el),
1915                    idEl = $('.pix-series-meta-image-id', el),
1916                    helpTexts = $('.edit-series-title, edit-series-header, .add-series-title, .add-series-header', el),
1917                    delButton = $('.pix-delete', el),
1918                    action = config.series;
1919            // default is adding picseries
1920            methodEl.val('POST');
1921
1922            if (self.data.Id) {
1923                // editing picseries
1924                titleEl.val(self.data.Title);
1925                methodEl.val('PUT');
1926                idEl.html(self.data.Id);
1927                helpTexts.toggle();
1928
1929                action = config.series + '/' + self.data.Id;
1930            }
1931
1932            delButton.click(function (e) {
1933                var t = $(this);
1934                e.preventDefault();
1935                if (confirm('Löschen?')) {
1936//               $.post(config.series + '/' + self.data.Id, {
1937//                     method: 'DELETE'
1938//                  }, function(data){
1939//
1940//                  }).fail(PIX.UX.ajaxError);
1941                }
1942                return false;
1943            });
1944
1945            // submit form
1946            $('form', el).attr('action', action).submit(function (e) {
1947                e.preventDefault();
1948                var form = $(this),
1949                        // merge account info into formdata when adding picseries
1950                        formData = self.data.Id ? form.serializeArray() : $.merge(form.serializeArray(), [{
1951                        name: 'account',
1952                        value: self.options.auth.accountId
1953                    }]);
1954
1955                if (titleEl.val() !== '') {
1956                    // post data
1957                    $.post(form.attr('action'), formData, function (picseries) {
1958                        if (typeof self.options.managePictureSeries === 'function') {
1959                            self.destroy();
1960                            self.options.managePictureSeries(picseries);
1961                        } else {
1962                            goBack(self);
1963                        }
1964                    }).fail(PIX.UX.ajaxError);
1965                }
1966            });
1967
1968            bindMenuButtons(self, 'PictureManageWindow');
1969            togglePicSeriesButtons(self);
1970            self.base(params);
1971        }
1972    });
1973
1974    // PictureFieldCheckWindow --------------------------------------------------
1975
1976    PIX.PictureFieldCheckWindow = PIX.BaseWindow.extend({
1977        constructor: function (loadOptions, options, data) {
1978            this.base($.extend({template: config.templates + '/picfieldcheck', cls: '__PixWindow'}, loadOptions), options);
1979            this.prev = loadOptions.prev;
1980            this.zoom = loadOptions.zoom;
1981            this.viewState = loadOptions.viewState;
1982            this.autocenter();
1983            this.data = data;
1984            this.options.supportUrl = 'https://pix.culturebase.org/support';
1985        },
1986
1987        handleLoad: function (params) {
1988            var self = this;
1989            var selected = false;
1990            var el = self.element();
1991
1992            this.base(params);
1993            this.setSupportLink(this.options);
1994        },
1995
1996        handleReady: function (params) {
1997            var self = this;
1998            var el = this.element();
1999            var easyFields = [];
2000            var ml = Object.create(PIX.Ml);
2001            var labels = ['_save_next', '_save_insert', '_back'];
2002            ml.fetch(labels, function () {
2003                //var translated = ml.get(label);
2004                for (var key in config.checkForFields) {
2005                    easyFields.push(key);
2006                }
2007
2008                // load picture
2009                el.find('.pix-check-fields-image-preview').attr("src", getThumbnail(self.data[config.checkFieldsMatchesCounter]['Picture'], 2));
2010
2011                // show/hide counter
2012                if (config.checkFieldsMatches.length > 1) {
2013                    el.find('#pic-check-fields-counter-fields').show();
2014                    el.find('#pic-check-fields-counter').html(config.checkFieldsMatchesCounter + 1);
2015                    el.find('#pic-check-fields-matches').html(config.checkFieldsMatches.length);
2016                    el.find('#pic-check-fields-overall').html(config.checkFieldsMatches.length + config.checkFieldsAllreadyCorrect.length);
2017                    if (config.checkFieldsMatchesCounter < config.checkFieldsMatches.length - 1) {
2018                        el.find('.pix-check-fields-save-next.pix-edit-form-button').html(ml.get('_save_next'));
2019                    } else {
2020                        el.find('.pix-check-fields-save-next.pix-edit-form-button').html(ml.get('_save_insert'));
2021                    }
2022                } else {
2023                    el.find('#pic-check-fields-counter-fields').hide();
2024                    el.find('.pix-check-fields-save-next.pix-edit-form-button').html(ml.get('_save_insert'));
2025                }
2026                el.find('.pix-check-fields-back.pix-edit-form-button').html(ml.get('_back'));
2027
2028                // fill fields
2029                $.each(easyFields, function (i, item) {
2030                    el.find('input[name="' + item + '"]').val(self.data[config.checkFieldsMatchesCounter]['Picture'][item]);
2031                });
2032
2033                // hide back button if not neccessary
2034                var back = el.find('.pix-check-fields-back.pix-edit-form-button');
2035                if (config.checkFieldsMatches.length > 1 && config.checkFieldsMatchesCounter > 0) {
2036                    back.show();
2037                    back.click(function (e) {
2038                        e.preventDefault();
2039                        self.destroy();
2040                        config.checkFieldsMatchesCounter = config.checkFieldsMatchesCounter - 1;
2041                        new PIX.PictureFieldCheckWindow({
2042                            prev: 'PictureManageWindow',
2043                            zoom: self.zoom,
2044                            viewState: self.viewState
2045                        }, self.options, config.checkFieldsMatches).open({
2046                            delay: 0
2047                        });
2048                        self.close();
2049                    });
2050                } else {
2051                    back.hide();
2052                }
2053
2054                // form submit
2055                el.find('form').attr('action', config.pictures + '/' + self.data[config.checkFieldsMatchesCounter]['Picture'].Id).submit(function (e) {
2056                    e.preventDefault();
2057                    var form = $(this), keywords = [];
2058
2059                    var data = {
2060                        method: 'PUT'
2061                    };
2062
2063                    $.each(easyFields, function (i, field) {
2064                        data[field.toLowerCase()] = form.find('input[name="' + field + '"]').val();
2065                    });
2066
2067                    // post data
2068                    $.post(form.attr('action'), data, function (pic) {
2069                        if (config.checkFieldsMatches.length > 1 && config.checkFieldsMatchesCounter < config.checkFieldsMatches.length - 1) {
2070                            config.checkFieldsMatches[config.checkFieldsMatchesCounter]['Picture'] = pic;
2071                            config.checkFieldsMatchesCounter = config.checkFieldsMatchesCounter + 1;
2072                            self.destroy();
2073                            new PIX.PictureFieldCheckWindow({
2074                                prev: 'PictureManageWindow',
2075                                zoom: self.zoom,
2076                                viewState: self.viewState
2077                            }, self.options, config.checkFieldsMatches).open({
2078                                delay: 0
2079                            });
2080                            self.close();
2081                        } else {
2082                            if (typeof self.options.selectPicture !== 'undefined') {
2083                                var pics = [];
2084                                self.data.forEach(function (item) {
2085                                    pics.push(item['Picture']);
2086                                });
2087                                config.checkFieldsAllreadyCorrect.forEach(function (allreadyItem) {
2088                                    pics.push(allreadyItem['Picture']);
2089                                });
2090                                self.destroy();
2091                                /**
2092                                 * @param {object} pic picture object
2093                                 */
2094                                self.options.selectPicture(pics);
2095                            }
2096                        }
2097                    }).fail(PIX.UX.ajaxError);
2098                });
2099
2100
2101                bindMenuButtons(self, 'PictureFieldCheckWindow');
2102                self.base(params);
2103            });
2104        }
2105    });
2106
2107    $(document).ready(function () {
2108        /* we set the handler on the body,
2109         * because the .support element will
2110         * be added after document.ready has been
2111         * called.
2112         *
2113         * see jQuery .on -> delegated events
2114         */
2115        $('body').on('click', '.__PixWindow .support', function () {
2116            var openedWindow = window.open($(this).attr('href'), $(this).attr('target'), 'width=800,height=800,scrollbars=yes');
2117            openedWindow.focus();
2118            return false;
2119        });
2120    });
2121
2122
2123})(window.PIX = {}, jQuery);
2124
2125// Change Copyright Form Input Colors if(value)
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149

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.