From 455f850ac01495066a895004e4dd4de208ae57a4 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Fri, 6 Aug 2010 18:41:08 -0500 Subject: [PATCH] history now works. JS needs locale month names --- www/extras/admin/admin.js | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/www/extras/admin/admin.js b/www/extras/admin/admin.js index 8acca6fb9..e06b70187 100644 --- a/www/extras/admin/admin.js +++ b/www/extras/admin/admin.js @@ -32,6 +32,11 @@ WebGUI.Admin = function(cfg){ var self = this; // Initialize these things AFTER the i18n is fetched var _init = function () { + // TODO: This should be i18n + self.localeMonths = [ + 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', + 'September', 'October', 'November', 'December' + ]; self.adminBar = new WebGUI.Admin.AdminBar( self.cfg.adminBarId, { expandMax : true } ); self.adminBar.afterShow.subscribe( self.updateAdminBar, self ); YAHOO.util.Event.on( window, 'load', function(){ self.adminBar.show( self.adminBar.dt[0].id ) } ); @@ -226,6 +231,7 @@ WebGUI.Admin.prototype.navigate this.currentAssetDef = assetDef; this.treeDirty = 1; this.updateAssetHelpers( assetDef ); + this.updateAssetHistory( assetDef ); } // Fire event @@ -650,6 +656,66 @@ WebGUI.Admin.prototype.addNewContent this.gotoAsset( appendToUrl( this.currentAssetDef.url, urlFragment ) ); }; +/** + * updateAssetHistory( assetDef ) + * Update the history list of the current asset + */ +WebGUI.Admin.prototype.updateAssetHistory += function ( assetDef ) { + // Clear old revisions + var historyEl = document.getElementById( 'history_list' ); + while ( historyEl.childNodes.length > 0 ) { + historyEl.removeChild( historyEl.childNodes[0] ); + } + + var now = new Date(); + // Add new ones + for ( var i = 0; i < assetDef.revisions.length; i++ ) { + var revisionDate = assetDef.revisions[i]; + var li = document.createElement('li'); + + // Create a descriptive date string + var rDate = new Date( revisionDate * 1000 ); // JS requires milliseconds + var minutes = rDate.getMinutes(); + minutes = minutes < 10 ? "0" + minutes : minutes; + + var dateString; + // Last year or older + if ( rDate.getFullYear() < now.getFullYear() ) { + dateString = this.localeMonths[rDate.getMonth()] + " " + rDate.getDate() + ", " + + rDate.getFullYear(); + } + // Earlier this year + else if ( rDate.getMonth() < now.getMonth() || rDate.getDate() < now.getDate() - 1 ) { + dateString = this.localeMonths[rDate.getMonth()] + " " + rDate.getDate() + " " + + rDate.getHours() + ":" + minutes; + } + // Yesterday + else if ( rDate.getDate() < now.getDate() ) { + dateString = "Yesterday " + rDate.getHours() + ":" + minutes; + } + // Today + else { + dateString = "Today " + rDate.getHours() + ":" + minutes; + } + + li.appendChild( document.createTextNode( dateString ) ); + this.addHistoryHandler( li, assetDef, revisionDate ); + historyEl.appendChild( li ); + } +}; + +/** + * addHistoryHandler( elem, revisionDate ) + * Add the click handler to view the desired revision + */ +WebGUI.Admin.prototype.addHistoryHandler += function ( elem, assetDef, revisionDate ) { + var self = this; + var url = appendToUrl( assetDef.url, 'func=view;revision=' + revisionDate ); + YAHOO.util.Event.on( elem, "click", function(){ self.gotoAsset( url ) }, self, true ); +}; + /**************************************************************************** * WebGUI.Admin.LocationBar */