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


////
//// PagingDijit, 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' */


