diff --git a/www/extras/admin/admin.js b/www/extras/admin/admin.js index 8ee10e2c4..f0d6107a4 100644 --- a/www/extras/admin/admin.js +++ b/www/extras/admin/admin.js @@ -1081,14 +1081,17 @@ WebGUI.Admin.LocationBar.prototype.createSearchTab /**************************************************************************** * - * WebGUI.Admin.Tree + * WebGUI.Admin.AssetTable + * Display a table of assets. Extend this to create your own display + * Used by AssetTable and Search */ +WebGUI.Admin.AssetTable += function ( admin, cfg ) { + this.admin = admin; + this.cfg = cfg; -WebGUI.Admin.Tree -= function(admin){ - this.admin = admin; var selectAllCheck = document.createElement( 'input' ); - selectAllCheck.id = 'treeSelectAllCheckbox'; + this.selectAllCheck = selectAllCheck; selectAllCheck.type = "checkbox"; // Add the event handler in onDataTableInitializeRows because innerHTML won't // save event handlers @@ -1102,8 +1105,8 @@ WebGUI.Admin.Tree "dir" : YAHOO.widget.DataTable.CLASS_ASC }; - var assetPaginator = new YAHOO.widget.Paginator({ - containers : ['treePagination'], + this.paginator = new YAHOO.widget.Paginator({ + containers : this.cfg.paginatorIds, pageLinks : 7, rowsPerPage : 100, previousPageLinkLabel : window.admin.i18n.get('WebGUI', '< prev'), @@ -1113,7 +1116,7 @@ WebGUI.Admin.Tree // initialize the data source this.dataSource - = new YAHOO.util.DataSource( '?op=admin;method=getTreeData;', {connTimeout:30000} ); + = new YAHOO.util.DataSource( this.cfg.dataSourceUrl, {connTimeout:30000} ); this.dataSource.responseType = YAHOO.util.DataSource.TYPE_JSON; this.dataSource.responseSchema @@ -1140,122 +1143,93 @@ WebGUI.Admin.Tree } }; + var makeScopedFormatter = function ( scope, func ) { + return function() { func.apply( scope, arguments ) } + }; + this.columnDefs = [ - { key: 'assetId', label: selectAllSpan.innerHTML, formatter: this.formatAssetIdCheckbox }, - { key: 'lineage', label: window.admin.i18n.get('Asset','rank'), sortable: true, formatter: this.formatRank }, - { key: 'helpers', label: "", formatter: this.formatHelpers }, - { key: 'title', label: window.admin.i18n.get('Asset', '99'), formatter: this.formatTitle, sortable: true }, - { key: 'className', label: window.admin.i18n.get('Asset','type'), sortable: true, formatter: this.formatClassName }, - { key: 'revisionDate', label: window.admin.i18n.get('Asset','revision date' ), formatter: this.formatRevisionDate, sortable: true }, - { key: 'assetSize', label: window.admin.i18n.get('Asset','size' ), formatter: this.formatAssetSize, sortable: true }, - { key: 'lockedBy', label: '', formatter: this.formatLockedBy } + { + key: 'assetId', + label: selectAllSpan.innerHTML, + formatter: makeScopedFormatter( this, this.formatAssetIdCheckbox ) + }, + { + key: 'lineage', + label: window.admin.i18n.get('Asset','rank'), + sortable: true, + formatter: makeScopedFormatter( this, this.formatRank ) + }, + { + key: 'helpers', + label: "", + formatter: makeScopedFormatter( this, this.formatHelpers ) + }, + { + key: 'title', + label: window.admin.i18n.get('Asset', '99'), + formatter: makeScopedFormatter( this, this.formatTitle ), + sortable: true + }, + { + key: 'className', + label: window.admin.i18n.get('Asset','type'), + sortable: true, + formatter: makeScopedFormatter( this, this.formatClassName ) + }, + { + key: 'revisionDate', + label: window.admin.i18n.get('Asset','revision date' ), + formatter: makeScopedFormatter( this, this.formatRevisionDate ), + sortable: true + }, + { + key: 'assetSize', + label: window.admin.i18n.get('Asset','size' ), + formatter: makeScopedFormatter( this, this.formatAssetSize ), + sortable: true + }, + { + key: 'lockedBy', + label: '', + formatter: makeScopedFormatter( this, this.formatLockedBy ) + } ]; +}; +/** + * init ( ) + * Initialize the datatable with the columns we have. + * You must call this after all the columnDefs are situated + */ +WebGUI.Admin.AssetTable.prototype.init += function ( ) { // Initialize the data table this.dataTable - = new YAHOO.widget.DataTable( 'treeDataTableContainer', + = new YAHOO.widget.DataTable( this.cfg.dataTableId, this.columnDefs, this.dataSource, { initialLoad : false, dynamicData : true, - paginator : assetPaginator, + paginator : this.paginator, sortedBy : this.defaultSortedBy, generateRequest : this.buildQueryString } ); - // Save the Tree - this.dataTable.tree = this; this.dataTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) { oPayload.totalRecords = oResponse.meta.totalRecords; return oPayload; }; - -}; - -/** - * addHighlightToRow ( child ) - * Highlight the row containing this element by adding to it the "highlight" - * class - */ -WebGUI.Admin.Tree.prototype.addHighlightToRow -= function ( child ) { - var row = this.findRow( child ); - if ( !YAHOO.util.Dom.hasClass( row, "highlight" ) ) { - YAHOO.util.Dom.addClass( row, "highlight" ); - } -}; - -/** - * buildQueryString ( ) - * Build a query string - */ -WebGUI.Admin.Tree.prototype.buildQueryString -= function ( state, dt, newUrl ) { - var assetUrl; - if ( !newUrl ) { - assetUrl = window.admin.currentAssetDef.url; - } - else { - assetUrl = newUrl; - } - - var recordOffset = state.pagination ? state.pagination.recordOffset : 0; - var rowsPerPage = state.pagination ? state.pagination.rowsPerPage : 0; - var orderByColumn = state.sortedBy ? state.sortedBy.key : "lineage"; - var orderByDir = state.sortedBy - ? ( (state.sortedBy.dir === YAHOO.widget.DataTable.CLASS_DESC) ? "DESC" : "ASC" ) - : "ASC" - ; - - var query = "assetUrl=" + assetUrl - + ";recordOffset=" + recordOffset - + ';orderByDirection=' + orderByDir - + ';rowsPerPage=' + rowsPerPage - + ';orderByColumn=' + orderByColumn - ; - - return query; -}; - -/** - * findRow ( child ) - * Find the row that contains this child element. - */ -WebGUI.Admin.Tree.prototype.findRow -= function ( child ) { - var node = child; - while ( node ) { - if ( node.tagName == "TR" ) { - return node; - } - node = node.parentNode; - } -}; - - -/** - * findCheckbox( row ) - * Find the checkbox in the row for the assetId field - */ -WebGUI.Admin.Tree.prototype.findCheckbox -= function ( row ) { - var inputs = row.getElementsByTagName( "input" ); - for ( var i = 0; i < inputs.length; i++ ) { - if ( inputs[i].name == "assetId" ) { - return inputs[i]; - } - } -}; +} /** * formatHelpers ( ) * Format the Edit and More links for the row */ -WebGUI.Admin.Tree.prototype.formatHelpers +WebGUI.Admin.AssetTable.prototype.formatHelpers = function ( elCell, oRecord, oColumn, orderNumber ) { if ( oRecord.getData( 'canEdit' ) ) { var edit = document.createElement("span"); @@ -1275,9 +1249,7 @@ WebGUI.Admin.Tree.prototype.formatHelpers more.href = '#'; // Build onclick handler to show more menu - // These format functions do not have the right context - window.admin.tree.addMenuOpenHandler( more, oRecord.getData( 'assetId' ), oRecord.getData( 'helpers' ) ); - + this.addMenuOpenHandler( more, oRecord.getData( 'assetId' ), oRecord.getData( 'helpers' ) ); }; /** @@ -1285,7 +1257,7 @@ WebGUI.Admin.Tree.prototype.formatHelpers * Add a handler that will open a menu for the given assetId with the given * helpers */ -WebGUI.Admin.Tree.prototype.addMenuOpenHandler +WebGUI.Admin.AssetTable.prototype.addMenuOpenHandler = function ( elem, assetId, helpers ) { var self = this; YAHOO.util.Event.addListener( elem, "click", function(){ @@ -1297,13 +1269,13 @@ WebGUI.Admin.Tree.prototype.addMenuOpenHandler * showHelperMenu( elem, assetId, helpers ) * Show the Helper menu for the given assetId with the given helpers */ -WebGUI.Admin.Tree.prototype.showHelperMenu +WebGUI.Admin.AssetTable.prototype.showHelperMenu = function ( elem, assetId, helpers ) { if ( this.helperMenu ) { // destroy the old helper menu! this.helperMenu.destroy(); } - this.helperMenu = new YAHOO.widget.Menu( "treeHelperMenu", { + this.helperMenu = new YAHOO.widget.Menu( { position : "dynamic", clicktohide : true, constraintoviewport : true, @@ -1335,7 +1307,7 @@ WebGUI.Admin.Tree.prototype.showHelperMenu * clickHelper( type, event, args, menuItem ) * Request the helper. args is an array of [ assetId, helperData ] */ -WebGUI.Admin.Tree.prototype.clickHelper +WebGUI.Admin.AssetTable.prototype.clickHelper = function ( type, e, args, menuItem ) { var assetId = args[0]; var helper = args[1]; @@ -1351,7 +1323,7 @@ WebGUI.Admin.Tree.prototype.clickHelper * formatAssetIdCheckbox ( ) * Format the checkbox for the asset ID. */ -WebGUI.Admin.Tree.prototype.formatAssetIdCheckbox +WebGUI.Admin.AssetTable.prototype.formatAssetIdCheckbox = function ( elCell, oRecord, oColumn, orderNumber ) { elCell.innerHTML = ''; @@ -1362,7 +1334,7 @@ WebGUI.Admin.Tree.prototype.formatAssetIdCheckbox * formatAssetSize ( ) * Format the asset class name */ -WebGUI.Admin.Tree.prototype.formatAssetSize +WebGUI.Admin.AssetTable.prototype.formatAssetSize = function ( elCell, oRecord, oColumn, orderNumber ) { elCell.innerHTML = oRecord.getData( "assetSize" ); }; @@ -1371,7 +1343,7 @@ WebGUI.Admin.Tree.prototype.formatAssetSize * formatClassName ( ) * Format the asset class name */ -WebGUI.Admin.Tree.prototype.formatClassName +WebGUI.Admin.AssetTable.prototype.formatClassName = function ( elCell, oRecord, oColumn, orderNumber ) { elCell.innerHTML = ' ' + oRecord.getData( "className" ); @@ -1381,7 +1353,7 @@ WebGUI.Admin.Tree.prototype.formatClassName * formatLockedBy ( ) * Format the locked icon */ -WebGUI.Admin.Tree.prototype.formatLockedBy +WebGUI.Admin.AssetTable.prototype.formatLockedBy = function ( elCell, oRecord, oColumn, orderNumber ) { var extras = getWebguiProperty('extrasURL'); elCell.innerHTML @@ -1401,7 +1373,7 @@ WebGUI.Admin.Tree.prototype.formatLockedBy * formatRank ( ) * Format the input for the rank box */ -WebGUI.Admin.Tree.prototype.formatRank +WebGUI.Admin.AssetTable.prototype.formatRank = function ( elCell, oRecord, oColumn, orderNumber ) { var rank = oRecord.getData("lineage").match(/[1-9][0-9]{0,5}$/); elCell.innerHTML = '