/**
* WebGUI.Admin -- The WebGUI Admin Console
*/
if ( typeof WebGUI == "undefined" ) {
WebGUI = {};
}
WebGUI.Admin = function(cfg){
// Public properties
this.cfg = cfg;
this.currentAssetDef = null;
this.currentTab = "view"; // "view" or "tree" or other ID
this.treeDirty = true;
// Default configuration
if ( !this.cfg.locationBarId ) {
this.cfg.locationBarId = "locationBar";
}
if ( !this.cfg.tabBarId ) {
this.cfg.tabBarId = "tabBar";
}
if ( !this.cfg.adminBarId ) {
this.cfg.adminBarId = "adminBar";
}
// TODO: This should be i18n
this.localeMonths = [
'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'
];
// Custom events
this.afterNavigate = new YAHOO.util.CustomEvent( "afterNavigate", this );
// Private methods
var self = this;
// Initialize these things AFTER the i18n is fetched
var _init = function () {
self.afterNavigate.subscribe( self.requestUpdateCurrentVersionTag, self );
self.requestUpdateCurrentVersionTag();
self.tabBar = new YAHOO.widget.TabView( self.cfg.tabBarId );
// Keep track of View and Tree tabs
self.tabBar.getTab(0).addListener('click',self.afterShowViewTab,self,true);
self.tabBar.getTab(1).addListener('click',self.afterShowTreeTab,self,true);
self.tree = new WebGUI.Admin.Tree(self);
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 ) } );
self.newContentBar = new WebGUI.Admin.AdminBar( "newContentBar", { expandMax : true } );
self.locationBar = new WebGUI.Admin.LocationBar( self.cfg.locationBarId, {
homeUrl : self.cfg.homeUrl
} );
self.afterNavigate.subscribe( self.locationBar.afterNavigate, self.locationBar );
if ( self.currentAssetDef ) {
self.locationBar.navigate( self.currentAssetDef );
}
};
// Get I18N
this.i18n = new WebGUI.i18n( {
namespaces : {
'WebGUI' : [ '< prev', 'next >', 'locked by' ],
'Asset' : [ 'rank', '99', 'type', 'revision date', 'size', 'locked', 'More', 'unlocked', 'edit' ]
},
onpreload : {
fn : _init
}
} );
};
/**
* getRealHeight( elem )
* Get the real height of the given element.
*/
WebGUI.Admin.getRealHeight
= function ( elem ) {
var D = YAHOO.util.Dom;
var _pos = D.getStyle(elem, 'position');
var _vis = D.getStyle(elem, 'visibility');
var clipped = false;
// We don't want 0 height!
if ( parseInt( elem.style.height ) == 0 ) {
elem.style.display = "none";
elem.style.height = ""
}
if (elem.style.display == 'none') {
clipped = true;
D.setStyle(elem, 'position', 'absolute');
D.setStyle(elem, 'visibility', 'hidden');
D.setStyle(elem, 'display', 'block');
}
var height = elem.offsetHeight;
if (height == 'auto') {
//This is IE, let's fool it
D.setStyle(elem, 'zoom', '1');
height = elem.clientHeight;
}
if (clipped) {
D.setStyle(elem, 'display', 'none');
D.setStyle(elem, 'visibility', _vis);
D.setStyle(elem, 'position', _pos);
}
//Strip the px from the style
return parseInt(height);
};
/**
* afterShowTreeTab()
* Fired after the Tree tab is shown. Refreshes if necessary.
*/
WebGUI.Admin.prototype.afterShowTreeTab
= function () {
// Refresh if necessary
if ( this.treeDirty ) {
this.tree.goto( this.currentAssetDef.url );
this.treeDirty = 0;
}
// Update last shown view/tree
this.currentTab = "tree";
};
/**
* afterShowViewTab()
* Fired after the view tab is shown. Refreshes if necessary.
*/
WebGUI.Admin.prototype.afterShowViewTab
= function () {
// Refresh if necessary
if ( this.viewDirty ) {
window.frames[ "view" ].location.href = this.currentAssetDef.url;
this.viewDirty = 0;
}
// Update last shown view/tree
this.currentTab = "view";
};
/**
* appendToUrl( url, params )
* Add URL components to a URL;
*/
appendToUrl
= function ( url, params ) {
var components = [ url ];
if (url.match(/\?/)) {
components.push(";");
}
else {
components.push("?");
}
components.push(params);
return components.join('');
};
/**
* editAsset( url )
* Show the edit form for the asset at the given URL
*/
WebGUI.Admin.prototype.editAsset
= function ( url ) {
this.showView( appendToUrl( url, "func=edit" ) );
};
/**
* gotoAsset( url )
* Open the appropriate tab (View or Tree) and go to the given asset URL
*/
WebGUI.Admin.prototype.gotoAsset
= function ( url ) {
if ( this.currentTab == "view" ) {
window.frames[ "view" ].location.href = url;
this.treeDirty = 1;
}
else if ( this.currentTab == "tree" ) {
// Make tree request
this.tree.goto( url );
this.viewDirty = 1;
}
};
/**
* showView ( [url] )
* Open the view tab, optionally navigating to the given URL
*/
WebGUI.Admin.prototype.showView
= function (url) {
// Show the view tab
this.tabBar.selectTab( 0 );
this.currentTab = "view";
if ( url ) {
// Open the URL
window.frames["view"].location.href = url;
// Mark undirty, as we'll clean it ourselves
this.viewDirty = 0;
}
};
/**
* makeEditAsset( url )
* Create a callback to edit an asset. Use when attaching to event listeners
*/
WebGUI.Admin.prototype.makeEditAsset
= function (url) {
var self = this;
return function() {
self.editAsset( url );
};
};
/**
* makeGotoAsset( url )
* Create a callback to view an asset. Use when attaching to event listeners
*/
WebGUI.Admin.prototype.makeGotoAsset
= function ( url ) {
var self = this;
return function() {
self.gotoAsset( url );
};
};
/**
* navigate( assetDef )
* We've navigated to a new asset. Called by the view iframe when a new
* page is reached
*/
WebGUI.Admin.prototype.navigate
= function ( assetDef ) {
// Don't do the same asset twice
if ( this.currentAssetDef && this.currentAssetDef.assetId == assetDef.assetId ) {
// But still fire the event
this.afterNavigate.fire( assetDef );
return;
}
if ( !this.currentAssetDef || this.currentAssetDef.assetId != assetDef.assetId ) {
this.currentAssetDef = assetDef;
this.treeDirty = 1;
this.updateAssetHelpers( assetDef );
this.updateAssetHistory( assetDef );
}
// Fire event
this.afterNavigate.fire( assetDef );
};
/**
* updateAdminBar( type, args, admin )
* Update the AdminBar. args is an array containing the id of the AdminBar
* pane being shown.
*/
WebGUI.Admin.prototype.updateAdminBar
= function ( type, args, admin ) {
// "this" is the AdminBar
var id = args[0];
if ( id == "assetHelpers" ) {
}
else if ( id == "clipboard" ) {
admin.requestUpdateClipboard.call( admin );
}
else if ( id == "newContent" ) {
}
else if ( id == "versionTags" ) {
admin.requestUpdateVersionTags.call( admin );
}
};
/**
* requestUpdateClipboard( )
* Request the new set of clipboard assets from the server
*/
WebGUI.Admin.prototype.requestUpdateClipboard
= function ( ) {
var callback = {
success : function (o) {
var clipboard = YAHOO.lang.JSON.parse( o.responseText );
this.updateClipboard( clipboard );
},
failure : function (o) {
},
scope: this
};
var showAll = document.getElementById( 'clipboardShowAll' ).checked ? ";all=1" : ";all=0";
var ajax = YAHOO.util.Connect.asyncRequest( 'GET', '?op=admin;method=getClipboard' + showAll, callback );
};
/**
* updateClipboard( assets )
* Update the clipboard list with the given assets
*/
WebGUI.Admin.prototype.updateClipboard
= function ( assets ) {
// Clear out the old clipboard
var div = document.getElementById( 'clipboardItems' );
while ( div.childNodes.length > 0 ) {
div.removeChild( div.childNodes[0] );
}
for ( var i = 0; i < assets.length; i++ ) {
var asset = assets[i];
var a = document.createElement('a');
var icon = document.createElement('img');
icon.src = asset.icon;
a.appendChild( icon );
a.appendChild( document.createTextNode( asset.title ) );
div.appendChild( a );
this.addPasteHandler( a, asset.assetId );
}
};
/**
* addPasteHandler( elem, assetId )
* Add an onclick handler to paste an asset.
*/
WebGUI.Admin.prototype.addPasteHandler
= function ( elem, assetId ) {
var self = this;
YAHOO.util.Event.on( elem, "click", function(){
// Update clipboard after paste in case paste fails
var updateAfterPaste = function(){
this.requestUpdateClipboard();
this.afterNavigate.unsubscribe( updateAfterPaste );
};
self.afterNavigate.subscribe(updateAfterPaste, self );
self.pasteAsset( assetId );
}, self );
};
/**
* pasteAsset( id )
* Paste an asset and update the clipboard
*/
WebGUI.Admin.prototype.pasteAsset
= function ( id ) {
var url = appendToUrl( this.currentAssetDef.url, 'func=paste;assetId=' + id );
this.gotoAsset( url );
};
/**
* requestUpdateVersionTags( )
* Request the new set of version tags from the server
*/
WebGUI.Admin.prototype.requestUpdateVersionTags
= function ( ) {
var callback = {
success : function (o) {
var versionTags = YAHOO.lang.JSON.parse( o.responseText );
this.updateVersionTags( versionTags );
},
failure : function (o) {
},
scope: this
};
var ajax = YAHOO.util.Connect.asyncRequest( 'GET', '?op=admin;method=getVersionTags', callback );
};
/**
* updateVersionTags( tags )
* Update the version tag list with the given tags
*/
WebGUI.Admin.prototype.updateVersionTags
= function ( tags ) {
// Clear out the old tags
var div = document.getElementById( 'versionTagItems' );
while ( div.childNodes.length > 0 ) {
div.removeChild( div.childNodes[0] );
}
for ( var i = 0; i < tags.length; i++ ) {
var tag = tags[i];
var a = document.createElement('a');
var icon = document.createElement('img');
icon.src = tag.icon;
a.appendChild( icon );
a.appendChild( document.createTextNode( tag.name ) );
div.appendChild( a );
this.addJoinTagHandler( a, tag.tagId );
if ( tag.isCurrent ) {
this.updateCurrentVersionTag( tag );
}
}
};
/**
* addJoinTagHandler( elem, tagId )
* Add an onclick handler to join a version tag
*/
WebGUI.Admin.prototype.addJoinTagHandler
= function ( elem, tagId ) {
var self = this;
YAHOO.util.Event.on( elem, "click", function(){
// Update version tags after join in case paste fails
var updateAfterJoin = function(){
this.requestUpdateVersionTags();
this.afterNavigate.unsubscribe( updateAfterJoin );
};
self.afterNavigate.subscribe(updateAfterJoin, self );
self.joinTag( tagId );
}, self );
};
/**
* joinTag( id )
* Join a new version tag
*/
WebGUI.Admin.prototype.joinTag
= function ( id ) {
var url = appendToUrl( this.currentAssetDef.url, 'op=setWorkingVersionTag;tagId=' + id );
this.gotoAsset( url );
};
/**
* updateAssetHelpers( assetDef )
* Update the asset helpers. assetDef must contain:
* helper - An arrayref of hashrefs of helper definitions
* icon - The icon of the current asset
* type - The type of the current asset
*/
WebGUI.Admin.prototype.updateAssetHelpers
= function ( assetDef ) {
var typeEl = document.getElementById( 'helper_asset_name' );
typeEl.style.backgroundImage = 'url(' + assetDef.icon + ')';
typeEl.innerHTML = assetDef.type;
// Clear old helpers
var helperEl = document.getElementById( 'helper_list' );
while ( helperEl.childNodes.length > 0 ) {
helperEl.removeChild( helperEl.childNodes[0] );
}
// Add new ones
for ( var i = 0; i < assetDef.helpers.length; i++ ) {
var helper = assetDef.helpers[i];
var li = document.createElement('li');
li.className = "clickable with_icon";
li.appendChild( document.createTextNode( helper.label ) );
this.addHelperHandler( li, helper );
helperEl.appendChild( li );
}
};
/**
* addHelperHandler( elem, helper )
* Add the click handler to activate the given helper
*/
WebGUI.Admin.prototype.addHelperHandler
= function ( elem, helper ) {
var self = this;
if ( helper.url ) {
YAHOO.util.Event.on( elem, "click", function(){ self.gotoAsset( helper.url ) }, self, true );
}
else if ( helper['class'] ) {
YAHOO.util.Event.on( elem, "click", function(){ self.requestHelper( helper['class'], self.currentAssetDef.assetId ) }, self, true );
}
};
/**
* updateCurrentVersionTag( tag )
* Update the current version tag. tag is an object of data about the tag:
* tagId : the ID of the tag
* name : The name of the tag
* editUrl : A URL to edit the tag
* commitUrl : A URL to commit the tag
* leaveUrl : A URL to leave the tag
*/
WebGUI.Admin.prototype.updateCurrentVersionTag
= function ( tag ) {
if ( !tag.tagId ) {
// hide tag area
document.getElementById( 'versionTag' ).style.display = "none";
return;
}
// Make sure tag is shown now
document.getElementById( 'versionTag' ).style.display = "block";
var editEl = document.getElementById( 'editTag' );
editEl.innerHTML = tag.name;
editEl.href = tag.editUrl;
var publishEl = document.getElementById( 'publishTag' );
publishEl.href = tag.commitUrl;
var leaveEl = document.getElementById( 'leaveTag' );
leaveEl.href = tag.leaveUrl;
};
/**
* requestUpdateCurrentVersionTag( )
* Request an update for the current version tag
*/
WebGUI.Admin.prototype.requestUpdateCurrentVersionTag
= function ( ) {
var callback = {
success : function (o) {
var tag = YAHOO.lang.JSON.parse( o.responseText );
this.updateCurrentVersionTag( tag );
},
failure : function (o) {
},
scope: this
};
var ajax = YAHOO.util.Connect.asyncRequest( 'GET', '?op=admin;method=getCurrentVersionTag', callback );
};
/**
* requestHelper( helperClass, assetId )
* Request the Asset Helper for the given assetId
*/
WebGUI.Admin.prototype.requestHelper
= function ( helperClass, assetId ) {
var callback = {
success : function (o) {
var resp = YAHOO.lang.JSON.parse( o.responseText );
this.processPlugin( resp );
},
failure : function (o) {
},
scope: this
};
var url = '?op=admin;method=processAssetHelper;className=' + helperClass + ';assetId=' + assetId;
var ajax = YAHOO.util.Connect.asyncRequest( 'GET', url, callback );
};
/**
* processPlugin( response )
* Process the plugin response. Possible responses include:
* message : A message to the user
* error : An error message
* openDialog : Open a dialog with the given URL
* openTab : Open a tab with the given URL
* redirect : Redirect the View pane to the given URL
* scriptFile : Load a JS file
* scriptFunc : Run a JS function. Used with scriptFile
* scriptArgs : Arguments to scriptFunc. Used with scriptFile
*/
WebGUI.Admin.prototype.processPlugin
= function ( resp ) {
if ( resp.openTab ) {
this.openTab( resp.openTab );
}
else if ( resp.openDialog ) {
this.openModalDialog( resp.openDialog, resp.width, resp.height );
}
else if ( resp.scriptFile ) {
this.loadAndRun( resp.scriptFile, resp.scriptFunc, resp.scriptArgs );
}
else if ( resp.message ) {
this.showInfoMessage( resp.message );
}
else if ( resp.error ) {
this.showInfoMessage( resp.error );
}
else {
alert( "Unknown plugin response: " + YAHOO.lang.JSON.stringify(resp) );
}
};
/**
* openModalDialog( url, width, height )
* Open a modal dialog with an iframe containing the given URL.
* The page inside the iframe must eventually close the dialog using:
* window.parent.admin.closeModalDialog();
*/
WebGUI.Admin.prototype.openModalDialog
= function ( url, width, height ) {
if ( this.modalDialog ) {
return; // Can't have more than one open
}
if ( !width ) {
width = parseInt( YAHOO.util.Dom.getViewportWidth() * 0.6 ) + "px";
}
if ( !height ) {
height = parseInt( YAHOO.util.Dom.getViewportHeight() * 0.6 ) + "px";
}
var dialog = new YAHOO.widget.Panel( 'adminModalDialog', {
"width" : width,
"height" : height,
fixedcenter : true,
constraintoviewport : true,
underlay : "shadow",
modal : true,
close : false,
visible : true,
draggable : false
} );
dialog.setBody( '' );
dialog.render( document.body );
this.modalDialog = dialog;
};
/**
* closeModalDialog( )
* Close the current modal dialog
*/
WebGUI.Admin.prototype.closeModalDialog
= function ( ) {
if ( !this.modalDialog ) {
return; // Can't close what isn't open
}
this.modalDialog.destroy();
this.modalDialog = null;
};
/**
* showInfoMessage( message )
* Show an informative message that requires no response or interaction from
* the user.
*/
WebGUI.Admin.prototype.showInfoMessage
= function ( message ) {
if ( this.infoMessageTimeout ) {
clearTimeout( this.infoMessageTimeout );
}
var info = document.getElementById( 'infoMessage' );
info.innerHTML = message;
var infoContainer = document.getElementById( 'infoMessageContainer' );
var newHeight = WebGUI.Admin.getRealHeight( infoContainer );
infoContainer.style.height = newHeight + 'px';
infoContainer.style.top = -1 * newHeight + 'px';
infoContainer.style.display = "block";
var anim = new YAHOO.util.Anim( infoContainer );
anim.duration = 0.25;
anim.method = YAHOO.util.Easing.easeOut;
anim.attributes.top = { to: 0 };
anim.animate();
this.infoMessageTimeout = setTimeout( this.hideInfoMessage, 3000 );
};
/**
* hideInfoMessage( )
* Hide the informative message from showInfoMessage()
*/
WebGUI.Admin.prototype.hideInfoMessage
= function ( ) {
var infoContainer = document.getElementById( 'infoMessageContainer' );
infoContainer.style.display = "none";
};
/**
* addNewContent( urlFragment )
* Add new content by visiting the given URL fragment
*/
WebGUI.Admin.prototype.addNewContent
= function ( urlFragment ) {
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');
li.className = "clickable with_icon";
// 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 );
};
/**
* openTab ( url )
* Open a new tab with an iframe and the given URL
*/
WebGUI.Admin.prototype.openTab
= function ( url ) {
// Prepare the iframe first
var iframe = document.createElement( 'iframe' );
iframe.src = url;
YAHOO.util.Event.on( iframe, 'load', function(){ this.updateTabLabel(newTab); }, this, true );
// Prepare the tab
var newTab = new YAHOO.widget.Tab({
label : "Loading...",
content : ''
});
newTab.get('contentEl').appendChild( iframe );
// Fire when ready, Gridley
this.tabBar.addTab( newTab );
};
/**
* updateTabLabel( tab )
* Update the tab's label with the title from the iframe inside
*/
WebGUI.Admin.prototype.updateTabLabel
= function ( tab ) {
// Find the iframe
var iframe = tab.get('contentEl').getElementsByTagName( 'iframe' )[0];
var title = iframe.contentDocument.title;
tab.set( 'label', title );
};
/****************************************************************************
* WebGUI.Admin.LocationBar
*/
WebGUI.Admin.LocationBar
= function (id, cfg) {
// Public properties
this.id = id; // ID of the element containing the location bar
this.cfg = cfg; // Configuration
this.currentAssetDef = null; // Object containing assetId, title, url, icon
this.backAssetDefs = [ ]; // Asset defs to go back to
this.forwardAssetDefs = [ ]; // Asset defs to go forward to
this.filters = [ ]; // search filters
// Private members
var self = this;
var _element = document.getElementById( self.id );
// Create buttons
this.btnBack = new YAHOO.widget.Button( "backButton", {
type : "split",
label : '',
disabled : true,
lazyloadmenu : false,
onclick : { fn: this.goBack, scope: this },
menu : []
} );
this.btnForward = new YAHOO.widget.Button( "forwardButton", {
type : "split",
label : '
',
disabled : true,
lazyloadmenu : false,
onclick : { fn: this.goForward, scope: this },
menu : []
} );
this.btnSearchDialog = new YAHOO.widget.Button( "searchDialogButton", {
label : '
',
onclick : { fn: this.toggleSearchDialog, scope: this }
} );
this.btnHome = new YAHOO.widget.Button( "homeButton", {
type : "button",
label : '
',
onclick : { fn: this.goHome, scope: this }
} );
this.btnSearch = new YAHOO.widget.Button( "searchButton", {
onclick : { fn: this.requestSearch, scope: this }
} );
this.filterSelect = new YAHOO.widget.Button( "searchFilterAdd", {
type : "menu",
menu : 'searchFilterSelect'
} );
var self = this;
YAHOO.util.Event.on( window, "load", function () {
self.filterSelect.getMenu().subscribe( "click", self.addFilter, self, true );
} );
YAHOO.util.Event.on( 'searchKeywords', 'keyup', this.updateLocationBarQuery, this, true );
YAHOO.util.Event.on( 'searchKeywords', 'focus', this.focusKeywords, this, true );
YAHOO.util.Event.on( 'searchKeywords', 'blur', this.blurKeywords, this, true );
// Take control of the location input
this.klInput = new YAHOO.util.KeyListener( "locationInput", { keys: 13 }, {
fn: this.doInputSearch,
scope: this,
correctScope: true
} );
YAHOO.util.Event.addListener( "locationInput", "focus", this.inputFocus, this, true );
YAHOO.util.Event.addListener( "locationInput", "blur", this.inputBlur, this, true );
};
/**
* addBackAsset( assetDef )
* Update the back menu to include a new asset
*/
WebGUI.Admin.LocationBar.prototype.addBackAsset
= function ( assetDef ) {
var b = this.btnBack;
// Button is enabled
b.set("disabled", false);
// Add the menu item
this.backAssetDefs.unshift( assetDef );
b.getMenu().insertItem( {
text : this.getMenuItemLabel( assetDef ),
value : assetDef.url,
onclick : { fn: this.clickBackMenuItem, obj: assetDef, scope: this }
}, 0 );
b.getMenu().render();
// Remove a menu item if necessary
// TODO
};
/**
* clickBackMenuItem( assetDef )
* Click an item in the back menu
*/
WebGUI.Admin.LocationBar.prototype.clickBackMenuItem
= function ( type, e, assetDef ) {
window.admin.gotoAsset( assetDef.url );
this.swapBackToForward( assetDef );
};
/**
* clickForwardMenuItem( assetDef )
* Click an item in the forward menu
*/
WebGUI.Admin.LocationBar.prototype.clickForwardMenuItem
= function ( type, e, assetDef ) {
window.admin.gotoAsset( assetDef.url );
this.swapForwardToBack( assetDef );
};
/**
* doInputSearch()
* Perform the search as described in the location bar
*/
WebGUI.Admin.LocationBar.prototype.doInputSearch
= function ( ) {
var input = document.getElementById("locationInput").value;
// If input starts with a / it's a URL
if ( input.match(/^\//) ) {
// If it doesn't have a ?, just go to the asset
if ( !input.match(/\?/) ) {
window.admin.gotoAsset( input );
}
// If does contain a ?, go to url
else {
window.admin.go( input );
}
}
// Otherwise ask WebGUI what do
else {
this.requestSearch();
}
};
/**
* getMenuItemLabel( assetDef )
* Build a menu item label for the given assetDef
*/
WebGUI.Admin.LocationBar.prototype.getMenuItemLabel
= function ( assetDef ) {
return '
' + assetDef.title;
}
/**
* goBack( e )
* Called when the mouse clicks on the back button
*/
WebGUI.Admin.LocationBar.prototype.goBack
= function ( e ) {
var assetDef = this.backAssetDefs[0];
// First, start the going
window.admin.gotoAsset( assetDef.url );
// Update the back and forward menus
this.swapBackToForward( assetDef );
};
/**
* goForward( e )
* Called when the mouse clicks down on the forward button
*/
WebGUI.Admin.LocationBar.prototype.goForward
= function ( e ) {
var assetDef = this.forwardAssetDefs[0];
// First, start the going
window.admin.gotoAsset( assetDef.url );
// Update the back and forward menus
this.swapForwardToBack( assetDef );
};
/**
* inputBlur( e )
* Called after the URL input field loses focus
*/
WebGUI.Admin.LocationBar.prototype.inputBlur
= function ( e ) {
if ( e.target.value.match(/^\s*$/) ) {
e.target.value = this.currentAssetDef.url;
}
this.klInput.disable();
};
/**
* inputFocus( e )
* Called after the URL input field gains focus.
*/
WebGUI.Admin.LocationBar.prototype.inputFocus
= function ( e ) {
if ( e.target.value == this.currentAssetDef.url ) {
e.target.value = "";
}
this.klInput.enable();
};
/**
* afterNavigate( type, args, me )
* Update our location if necessary
* Context is the WebGUI.Admin object.
* Args is array:
* assetDef - the new current asset
*/
WebGUI.Admin.LocationBar.prototype.afterNavigate
= function ( type, args, me ) {
var assetDef = args[0];
// Always update location bar
me.setTitle( assetDef.title );
me.setUrl( assetDef.url );
// Don't do the same asset twice
if ( me.currentAssetDef && me.currentAssetDef.assetId != assetDef.assetId ) {
me.addBackAsset( me.currentAssetDef );
// We navigated, so destroy the forward queue
//this.forwardAssetDefs = [];
//this.btnForward.getMenu().clearItems();
//this.btnForward.getMenu().render();
//this.btnForward.set( "disabled", true );
}
// Current asset is now...
me.currentAssetDef = assetDef;
return;
};
/**
* setTitle( title )
* Set the title to the new title
*/
WebGUI.Admin.LocationBar.prototype.setTitle
= function ( title ) {
var span = document.getElementById("locationTitle");
while ( span.childNodes.length ) span.removeChild( span.childNodes[0] );
span.appendChild( document.createTextNode( title ) );
};
/**
* setUrl( url )
* Set the URL to the new URL
*/
WebGUI.Admin.LocationBar.prototype.setUrl
= function ( url ) {
var input = document.getElementById( "locationInput" );
input.value = url;
};
/**
* swapBackToForward( assetDef )
* Swap items from the back list to the forward list until assetDef is the
* current asset.
*/
WebGUI.Admin.LocationBar.prototype.swapBackToForward
= function ( assetDef ) {
while ( this.backAssetDefs.length > 0 && this.currentAssetDef.assetId != assetDef.assetId ) {
var workingDef = this.currentAssetDef;
this.forwardAssetDefs.unshift( workingDef );
this.btnForward.getMenu().insertItem( {
text : this.getMenuItemLabel( workingDef ),
value : workingDef.url,
onclick : { fn: this.clickForwardMenuItem, obj: workingDef, scope: this }
}, 0 );
this.currentAssetDef = this.backAssetDefs.shift();
this.btnBack.getMenu().removeItem(0);
}
this.btnForward.getMenu().render();
this.btnForward.set("disabled", false);
this.btnBack.getMenu().render();
if ( this.backAssetDefs.length == 0 ) {
this.btnBack.set( "disabled", true );
}
};
/**
* swapForwardToBack( assetDef )
* Swap items from the forward list to the back list until assetDef is the
* current asset.
*/
WebGUI.Admin.LocationBar.prototype.swapForwardToBack
= function ( assetDef ) {
while ( this.forwardAssetDefs.length > 0 && this.currentAssetDef.assetId != assetDef.assetId ) {
var workingDef = this.currentAssetDef;
this.backAssetDefs.unshift( workingDef );
this.btnBack.getMenu().insertItem( {
text : this.getMenuItemLabel( workingDef ),
value : workingDef.url,
onclick : { fn: this.clickBackMenuItem, obj: workingDef, scope : this }
}, 0 );
this.currentAssetDef = this.forwardAssetDefs.shift();
this.btnForward.getMenu().removeItem(0);
}
this.btnBack.getMenu().render();
this.btnBack.set("disabled", false);
this.btnForward.getMenu().render();
if ( this.forwardAssetDefs.length == 0 ) {
this.btnForward.set( "disabled", true );
}
};
/**
* goHome ( )
* Go to the correct home URL
*/
WebGUI.Admin.LocationBar.prototype.goHome
= function ( ) {
window.admin.gotoAsset( this.cfg.homeUrl );
};
/**
* toggleSearchDialog ( )
* Show or hide the search dialog as necessary
*/
WebGUI.Admin.LocationBar.prototype.toggleSearchDialog
= function ( ) {
var input = document.getElementById( 'locationInput' );
if ( this.searchDialog == true ) {
this.hideSearchDialog();
this.searchDialog = false;
input.value = this.savedLocationInput;
this.savedLocationInput = "";
input.readonly = false;
YAHOO.util.Dom.removeClass( input, 'disabled' );
}
else {
this.showSearchDialog();
this.searchDialog = true;
this.savedLocationInput = input.value;
input.value = "";
this.updateLocationBarQuery();
input.readonly = true;
YAHOO.util.Dom.addClass( input, 'disabled' );
}
};
/**
* showSearchDialog ( )
* Show the search dialog, dimming the content behind it
*/
WebGUI.Admin.LocationBar.prototype.showSearchDialog
= function ( ) {
// Dim the content
//window.admin.dim( 'tab_content_wrapper' );
// Roll out the dialog
var searchDialog = document.getElementById( 'search' );
var height = WebGUI.Admin.getRealHeight( searchDialog );
searchDialog.style.top = -1 * height + 'px';
searchDialog.style.display = "block";
var anim = new YAHOO.util.Anim( searchDialog );
anim.duration = 0.25;
anim.method = YAHOO.util.Easing.easeOut;
anim.attributes.top = { to: 0 };
anim.animate();
};
/**
* hideSearchDialog ( )
* Hide the search dialog, undimming the content behind it
*/
WebGUI.Admin.LocationBar.prototype.hideSearchDialog
= function ( ) {
// Undim the content
//window.admin.undim( 'tab_content_wrapper' );
// Roll up the dialog
var searchDialog = document.getElementById( 'search' );
var height = WebGUI.Admin.getRealHeight( searchDialog );
searchDialog.style.display = "block";
var anim = new YAHOO.util.Anim( searchDialog );
anim.duration = 0.25;
anim.method = YAHOO.util.Easing.easeOut;
anim.attributes.top = { to: -1 * height };
var hideContent = function () {
searchDialog.style.display = "none";
anim.onComplete.unsubscribe( hideContent );
};
anim.onComplete.subscribe( hideContent, this );
anim.animate();
};
/**
* addFilter ( eventType, args )
* Add the selected filter into the filter list
*/
WebGUI.Admin.LocationBar.prototype.addFilter
= function ( eventType, args ) {
var self = this;
var ev = args[0];
var menuitem = args[1];
var keys = {}; // Listen for all keys
// Keep track of our filters
var filter = { };
this.filters.push( filter );
var li = document.createElement( 'li' );
filter.li = li;
var type = menuitem.value;
filter.type = type;
li.className = "filter_" + filter.type;
var ul = document.getElementById( 'searchFilters' );
ul.appendChild( li );
var delIcon = document.createElement('img');
delIcon.className = "clickable";
YAHOO.util.Event.on( delIcon, "click", function(){
self.removeFilter( filter.li );
} );
var name = menuitem.cfg.getProperty('text');
var nameElem = document.createElement('span');
nameElem.className = "name";
nameElem.appendChild( document.createTextNode( name ) );
li.appendChild( nameElem );
if ( filter.type == "title" ) {
var inputElem = document.createElement('input');
filter.inputElem = inputElem;
inputElem.type = "text";
li.appendChild( inputElem );
YAHOO.util.Event.on( inputElem, 'keyup', this.updateLocationBarQuery, this, true );
inputElem.focus();
}
else if ( filter.type == "ownerUserId" ) {
var container = document.createElement( 'div' );
container.className = "autocomplete";
li.appendChild( container );
var inputElem = document.createElement('input');
filter.inputElem = inputElem;
inputElem.type = "text";
container.appendChild( inputElem );
filter.dataSource = new YAHOO.util.XHRDataSource( '?op=admin;method=findUser;' );
filter.dataSource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
filter.dataSource.responseSchema = {
resultsList : "results",
fields : [ 'username', 'name', 'userId', 'avatar', 'email' ]
};
// Auto-complete container
var acDiv = document.createElement('div');
filter.acDiv = acDiv;
container.appendChild( acDiv );
filter.autocomplete = new YAHOO.widget.AutoComplete( inputElem, acDiv, filter.dataSource );
filter.autocomplete.queryQuestionMark = false;
filter.autocomplete.animVert = true;
filter.autocomplete.animSpeed = 0.1;
filter.autocomplete.minQueryLength = 1;
filter.autocomplete.queryDelay = 0.2;
filter.autocomplete.typeAhead = true;
filter.autocomplete.resultTypeList = false;
filter.autocomplete.applyLocalFilter = true;
filter.autocomplete.formatResult = function ( result, query, match ) {
var subtext = ( result.name ? result.name : "" )
+ ( result.email ? " <" + result.email + ">" : "" )
;
return '