
/* BEGIN OF INCLUDED FILE '/modules/usability/js/seitbox_dijit_form_SlickCheckBox.js' */


////
//// SlickCheckBox dijit
////
//// A checkbox which supports the parameters 'checkedValue' and 'uncheckedValue' and posts
//// one of this values to the server, depending on it's current state.
////
if (window.dojo) {
    dojo.provide("seitbox.dijit.form.SlickCheckBox");
    dojo.require("dijit.form.CheckBox");
    dojo.declare(
        "seitbox.dijit.form.SlickCheckBox",
        [dijit.form.CheckBox],
        {
            checkedValue: '1',
            uncheckedValue: '0',
            _currentValue: null,
            _uncheckedHiddenField: null,
            postMixInProperties: function(){
                // store current value and set value to checked value
                this._currentValue = this.value;
                this.value = this.checkedValue;
                // set checked state from current value
                if (this._currentValue == this.checkedValue) {
                    this.checked = true;
                } else {
                    this.checked = false;
                    this._createUncheckedHiddenField();
                }
                // call inherited
                this.inherited(arguments);
            },
            postCreate: function(){
                this.inherited(arguments);
                if(!this.checked){
                    this._createUncheckedHiddenField();
                }
            },
            _setCheckedAttr: function(){
                this.inherited(arguments);
                if (!this.checked) {
                    this._createUncheckedHiddenField();
                } else {
                    this._removeUncheckedHiddenField();
                }
            },
            _createUncheckedHiddenField: function() {
                this._uncheckedHiddenField = dojo.doc.createElement("input");
                dojo.attr(this._uncheckedHiddenField, "type", "hidden");
                dojo.attr(this._uncheckedHiddenField, "name", this.name);
                dojo.attr(this._uncheckedHiddenField, "value", this.uncheckedValue);
                dojo.place(this._uncheckedHiddenField, this.domNode, "before");
            },
            _removeUncheckedHiddenField: function() {
                if (this._uncheckedHiddenField != null) {
                    this._uncheckedHiddenField.parentNode.removeChild(this._uncheckedHiddenField);
                    this._uncheckedHiddenField = null;
                }
            }
        }  
    );
}


/* END OF INCLUDED FILE '/modules/usability/js/seitbox_dijit_form_SlickCheckBox.js' */



/* BEGIN OF INCLUDED FILE '/modules/usability/js/seitbox_dijit_Chichiupload.js' */


////
//// Chichiupload dijit
////
if (window.dojo) {
    dojo.provide("seitbox.dijit.Chichiupload");
    dojo.require("dijit.Declaration");
    dojo.require("dojo.parser");
    dojo.require("dijit.form.Button");
    dojo.require("dijit.ProgressBar");
    dojo.require("seitbox.dojox.embed.Flash");
    dojo.declare(
        "seitbox.dijit.Chichiupload",
        [dijit.form.Button],
        {
            statusNode: null,
            flashNode: null,
            flashObject: null,
            flashMovie: null,
            url: '',
            onComplete: '',
            _chichiFiles: null,
            _chichiTotalBytes: null,
            _chichiLoadedBytes: null,
            _chichiLoadedBytesFromCompletedFiles: null,
            _chichiProgressPercent: null,
            _swfUri: '/media/js/fancyupload_2/Swiff.Uploader.swf',
            postCreate: function(){
                // create status node
                this.statusNode = document.createElement("div");
                this.statusNode.id = this.id + "_statusNode";
                this.statusNode.className = "seitboxDijitChichiuploadStatus";
                dojo.style(this.statusNode, "display", "none");
                var html = 'Upload läuft...<br /><div style="width:200px" annotate="true" maximum="100" id="' + this.id + '_progressBar" progress="0" dojoType="dijit.ProgressBar"></div>';
                this.statusNode.innerHTML = html;
                dojo.parser.parse(this.statusNode);
                dojo.place(this.statusNode, this.domNode, 'after');
                // create fallback form (if flash not available)
                //   '<form id="backend_media_imagesSubdirUploadForm_'.$subDir.'" name="backend_media_imagesSubdirUploadForm_'.$subDir.'" method="post" dojoType="dijit.form.Form" enctype="multipart/form-data">'
                //   --> TODO
                // init chichi (Chichi upload)
                this.initChichi();
                // connect click
                dojo.connect(this, 'onClick', function() {
                    this.browse();
                });        
                // call inherited
                this.inherited(arguments);
            },
            initChichi: function() {
                console.log(" ===== Chichi says: Flash version detected:", dojox.embed.Flash.available);
                // create flash node
                this.flashNode = dojo.doc.createElement("div");
                dojo.style(this.flashNode, "position", "absolute");
                dojo.style(this.flashNode, "width", "100px");
                dojo.style(this.flashNode, "height", "22px");
                dojo.place(this.flashNode, this.focusNode, "before");
                // create flash object
                var args = {
                    path:this._swfUri,
                    width:'100%',
                    height:'100%',
                    params:{
                        wMode:'transparent'
                    },
                    vars:{
                        id:this.id,
                        multiple: true,
                        queued: true,
                        typeFilter: null,
                        url: this.url,
                        method: 'post',
                        data: null,
                        fieldName: this.name,
                        target: null,
                        width: '100%',
                        height: '100%',
                        callBacks: null,
                        onSelect: "dijit.byId('"+this.id+"')._onSelect",
                        onAllSelect: "dijit.byId('"+this.id+"')._onAllSelect",
                        onComplete: "dijit.byId('"+this.id+"')._onComplete",
                        onAllComplete: "dijit.byId('"+this.id+"')._onAllComplete",
                        onProgress: "dijit.byId('"+this.id+"')._onProgress",
                        onError: "dijit.byId('"+this.id+"')._onError",
                        onCancel: "dijit.byId('"+this.id+"')._onCancel"
                    }
                };
                this.flashObject = null;
                if (dojo.isFF) {
                    this.flashObject = new seitbox.dojox.embed.Flash(args, this.flashNode);
                } else {
                    this.flashObject = new dojox.embed.Flash(args, this.flashNode);
                }
                this.flashObject.onLoad = dojo.hitch(this, function(mov){
                    console.log(" ===== Chichi says: flashObject.onLoad! Yippieh!!!");
                    this.flashMovie = mov;
                })
            },
            _onSelect: function(file, index, length) {
                console.log(" ===== Chichi says: _onSelect");
            },
            _onAllSelect: function(files, current, overall) {
                console.log(" ===== Chichi says: _onAllSelect");
                console.log(" ===== Chichi says: _onAllSelect files: ", files);
                console.log(" ===== Chichi says: _onAllSelect current: ", current);
                this._chichiFiles = files;
                var totalBytes = 0;
                for(var i=0; i<files.length; i++) {
                    totalBytes += files[i].size;
                }
                this._chichiTotalBytes = totalBytes;
                this._chichiLoadedBytes = 0;
                this._chichiLoadedBytesFromCompletedFiles = 0;
                this._chichiProgressPercent = 0;
                this.upload();
            },
            _onComplete: function(file, response) {
                console.log(" ===== Chichi says: _onComplete");
                console.log(" ===== Chichi says: _onComplete file: ", file);
                this._chichiLoadedBytesFromCompletedFiles += file.size;
                this._updateProgress();
            },
            _onAllComplete: function(current) {
                console.log(" ===== Chichi says: _onAllComplete");
                dojo.style(this.statusNode, "display", "none");
                if (this.onComplete) {
                    eval(this.onComplete);
                }
            },
            _onProgress: function(file, current, overall) {
                console.log(" ===== Chichi says: _onProgress");
                console.log(" ===== Chichi says: _onProgress file: ", file);
                console.log(" ===== Chichi says: _onProgress current: ", current);
                console.log(" ===== Chichi says: _onProgress overall: ", overall);
                var bytesLoaded = parseInt(overall.bytesLoaded);
                if (!bytesLoaded || bytesLoaded == "NaN") {
                    bytesLoaded = 0;
                }
                if (bytesLoaded > this._chichiLoadedBytes) {
                    this._chichiLoadedBytes = bytesLoaded;
                }
                this._updateProgress();
            },
            _onError: function(file, error, info) {
                console.log(" ===== Chichi says: _onError");
                console.log(" ===== Chichi says: _onError file: ", file);
                console.log(" ===== Chichi says: _onError error: ", error);
                console.log(" ===== Chichi says: _onError info: ", info);
            },
            _onCancel: function() {
                console.log(" ===== Chichi says: _onCancel");
            },
            _updateProgress: function() {
                console.log(" ===== Chichi says: _updateProgress");
                dojo.style(this.statusNode, "display", "block");
                var totalBytes = this._chichiTotalBytes;
                var loadedBytes = this._chichiLoadedBytes;
                if (this._chichiLoadedBytesFromCompletedFiles > loadedBytes) {
                    loadedBytes = this._chichiLoadedBytesFromCompletedFiles;
                }
                var progressPercent = Math.floor((loadedBytes / totalBytes) * 100);
                if (progressPercent < 0) {
                    progressPercent = 0;
                }
                if (progressPercent > 100) {
                    progressPercent = 100;
                }
                console.log(" ===== Chichi says: _onProgress progressPercent: ", progressPercent);
                this._chichiProgressPercent = progressPercent;
                dijit.byId(this.id + '_progressBar').update({progress: progressPercent});
            },
            browse: function() {
                console.log(" ===== Chichi says: browse");
                this.flashMovie.browse();
                console.log(" ===== Chichi says: browse has been called ...");
            },
            upload: function() {
                console.log(" ===== Chichi says: upload");
                var options = new Object();
                options.data = null;
                options.fieldName = this.name;
                options.method = 'post';
                options.url = this.url;
                this.flashMovie.upload(options);
                console.log(" ===== Chichi says: upload called ...");
                dojo.style(this.statusNode, "display", "block");
            },
            reposition: function() {
                console.log(" ===== Chichi says: reposition");
            }
        }  
    );
}


/* END OF INCLUDED FILE '/modules/usability/js/seitbox_dijit_Chichiupload.js' */



/* BEGIN OF INCLUDED FILE '/modules/usability/js/seitbox_dijit_Fancyupload.js' */


////
//// Fancyupload dijit
////
if (window.dojo) {
    dojo.provide("seitbox.dijit.Fancyupload");
    dojo.require("dijit.Declaration");
    dojo.require("dojo.parser");
    dojo.require("dijit.form.Button");
    dojo.declare(
        "seitbox.dijit.Fancyupload",
        [dijit.form.Button],
        {
            listNode: null,
            statusNode: null,
            swiffy: null,
            url: '',
            onComplete: '',
            postCreate: function(){
                // create list node
                this.listNode = document.createElement('ul');
                this.listNode.id = this.id + '_listNode';
                this.listNode.className = 'seitboxDijitFancyuploadList';
                this.listNode.style.display = 'none';
                dojo.place(this.listNode, this.domNode, 'after');                
                // create status node
                this.statusNode = document.createElement('div');
                this.statusNode.id = this.id + '_statusNode';
                this.statusNode.className = 'seitboxDijitFancyuploadStatus';
                this.listNode.style.display = 'none';
                var html = '';
                html += '<div>';
                html += '   <strong class="overall-title">Overall progress</strong><br />';
                html += '   <img src="/media/images/common/progress_bar.gif" class="progress overall-progress" />';
                html += '</div>';
                html += '<div>';
                html += '   <strong class="current-title">File Progress</strong><br />';
                html += '   <img src="/media/images/common/progress_bar.gif" class="progress current-progress" />';
                html += '</div>';
                html += '<div class="current-text"></div>';
                this.statusNode.innerHTML = html;
                dojo.place(this.statusNode, this.listNode, 'after');
                // create fallback form (if flash not available)
                //   '<form id="backend_media_imagesSubdirUploadForm_'.$subDir.'" name="backend_media_imagesSubdirUploadForm_'.$subDir.'" method="post" dojoType="dijit.form.Form" enctype="multipart/form-data">'
                //   --> TODO
                // init swiffy (fancy upload)
                this.initSwiffy();
                // connect click
                dojo.connect(this, 'onClick', function() {
                    this.swiffy.browse();
                });        
                // call inherited
                this.inherited(arguments);
            },
            initSwiffy: function() {
                this.swiffy = new FancyUpload2($(this.statusNode.id), $(this.listNode.id), {
                    url: this.url,
                    fieldName: this.name,
                    path: '/media/js/fancyupload_2/Swiff.Uploader.swf',
                    limitSize: 1024 * 1024 * 1024,
                    instantStart: false, // we don't use instantStart, but trigger the upload from onAllSelect event
                    onLoad: function() {
                        // hide fallback form
                        //   --> TODO
                    },
                    onAllSelect: function() {
                        var dijitElemId = this.list.id.replace(/_listNode/,'');
                        var dijitElem = dijit.byId(dijitElemId);
                        dijitElem.statusNode.style.display = 'block';            
                        dijitElem.swiffy.upload.delay(10, dijitElem.swiffy);
                    },
                    onBeforeOpen: function() {
                        var dijitElemId = this.list.id.replace(/_listNode/,'');
                        var dijitElem = dijit.byId(dijitElemId);
                        dijitElem.statusNode.style.display = 'block';            
                    },
                    onOpen: function() {
                        var dijitElemId = this.list.id.replace(/_listNode/,'');
                        var dijitElem = dijit.byId(dijitElemId);
                        dijitElem.statusNode.style.display = 'block';            
                    },
                    onProgress: function() {
                        var dijitElemId = this.list.id.replace(/_listNode/,'');
                        var dijitElem = dijit.byId(dijitElemId);
                        dijitElem.statusNode.style.display = 'block';            
                    },
                    onComplete: function() {
                    },
                    onAllComplete: function() {
                        var dijitElemId = this.list.id.replace(/_listNode/,'');
                        var dijitElem = dijit.byId(dijitElemId);
                        eval(dijitElem.onComplete);
                    },
                    // The changed parts!
                    debug: true,
                    target: this.focusNode.id
                });            
            },
            reposition: function() {
                if (Browser.Plugins.Flash.version >= 10 && this.swiffy && this.swiffy != null && this.swiffy.target) {
                    this.swiffy.reposition();
                }
            }
        }  
    );
}


/* END OF INCLUDED FILE '/modules/usability/js/seitbox_dijit_Fancyupload.js' */



/* BEGIN OF INCLUDED FILE '/modules/usability/js/seitbox_dijit_Paging.js' */


////
//// Paging dijit, used by PagingViewElement
////
if (window.dojo) {
    dojo.provide("seitbox.dijit.Paging");
    dojo.require("dijit.Declaration");
    dojo.require("dojo.parser");
    dojo.require("dijit._Widget");
    dojo.require("dijit._Templated");
    dojo.declare(
	    "seitbox.dijit.Paging",
	    [dijit._Widget, dijit._Templated],
	    {	    
            // summary: A paging dijit
            //
            // description: A simple paging dijit for navigating between
            //       pages from 1 to n. 
            //
			text: '',
			rowsPerPage: 10,
			numPages: 0,
			numRows: 0,
			currentPageI: 0,
			onChangePage: '',
            templateString: '<div class="seitboxDijitPaging">${text}<div class="seitboxDijitPagingSummary">SUM</div><div class="seitboxDijitPagingLinks">LINKS</div></div>',
            templatePath: null,
            setRowsPerPage: function(rowsPerPage) {
                this.rowsPerPage = rowsPerPage;
                this.refreshPagingLinks();
            },
            setNumRows: function(numRows) {
                this.numRows = numRows;
                this.refreshPagingLinks();
            },            
            setCurrentPageI: function(currentPageI) {
                this.currentPageI = currentPageI;
                this.refreshPagingLinks();
                var offset = this.currentPageI * this.rowsPerPage;
                if (this.onChangePage != null && this.onChangePage != '') {
                    var js = this.onChangePage;
                    js = js.replace(/\${offset}/, offset);
                    eval(js);
                } 
            },
            refreshPagingLinks: function() {
                var currentPageN = this.currentPageI + 1;
                var numPages = Math.ceil(this.numRows / this.rowsPerPage);
                this.numPages = numPages;
                // generate paging links
                var pagingLinks = '';
                for(var pageI=0; pageI<numPages; pageI++) {
                    var pageN = pageI + 1;
                    pagingLinks += '<a class="seitboxDijitPagingLink'+(this.currentPageI==pageI ? ' seitboxDijitPagingLinkSelected' : '')+'" href="#page'+pageN+'" onclick="'+this.id+'.setCurrentPageI('+pageI+'); return false;">'+pageN+'</a> ';
                }
                // update paging links
                var pagingLinksContainers = dojo.query('div.seitboxDijitPagingLinks', this.domNode);
                dojo.forEach(pagingLinksContainers, function(elem){
                    elem.innerHTML = pagingLinks;
                });
                // update summary
                var summaryContainers = dojo.query('div.seitboxDijitPagingSummary', this.domNode);
                dojo.forEach(summaryContainers, function(elem){
                    elem.innerHTML = 'Seite ' + currentPageN + '/' + numPages;
                });
            }
	    }  
    );
}

/* END OF INCLUDED FILE '/modules/usability/js/seitbox_dijit_Paging.js' */


