refactor WebGUI.Admin.prototype.gotoAsset slightly to avoid code duplication
WebGUI.Admin.prototype.addPasteHandler: guessing but fix use of 'this' vs 'self' currentTabName() to avoid code duplication for figuring out which context we're running in (Tree/View) WebGUI.Admin.prototype.pasteAsset: handle pasting in the Tree view by flopping over to the View view first removed WebGUI.Admin.Tree.prototype.runHelperForSelected and relatedly WebGUI.Admin.Tree.prototype.cut, copy, shortcut, duplicate, delete; these are dead code WebGUI.Admin.Tree.prototype.goto: better error handling/debugging added this FIXME to WebGUI.Admin.prototype.gotoAsset: a lot of Tree view operations fail after this point. where the View version just directly goes to the URL, the Tree view tries to modify the URL to pass the extjs-style grid's parameters back. this winds up creating unworkable URLs that try to do two things at once, with two '?'s, two 'op='s, etc. there are two ways to fix this: if we're trying to go to an asset (gotoAsset) and we're in Tree view, flop back to View mode first; or else two distinct requests, one for the remote request (which might generate additional requests to draw in dialog boxes, progress bars, forms, etc) and then when that's all done, refresh the grid view. WebGUI.Admin.prototype.pasteAsset takes the route of flopping to Tree view first.
This commit is contained in:
parent
8be9ed7d59
commit
1ac133d955
1 changed files with 40 additions and 178 deletions
|
|
@ -269,19 +269,18 @@ WebGUI.Admin.prototype.editAsset
|
|||
/**
|
||||
* gotoAsset( url )
|
||||
* Open the appropriate tab (View or Tree) and go to the given asset URL
|
||||
* Cannot go to a URL that has parameters in Tree view
|
||||
*/
|
||||
WebGUI.Admin.prototype.gotoAsset
|
||||
= function ( url ) {
|
||||
if ( this.tabBar.get('activeIndex') > 1 ) {
|
||||
this.tabBar.selectTab( 0 );
|
||||
this.currentTab = "view";
|
||||
}
|
||||
if ( this.currentTab == "view" ) {
|
||||
if ( this.currentTabName() == "view" ) {
|
||||
window.frames[ "view" ].location.href = url;
|
||||
this.treeDirty = 1;
|
||||
}
|
||||
else if ( this.currentTab == "tree" ) {
|
||||
else if ( this.currentTabName() == "tree" ) {
|
||||
// Make tree request
|
||||
// XXX this is currently failing... arg is eg /home?func=pasteList&assetId=x4wzjypIRIaDFISifViMgA which should be okay
|
||||
// XXX FIXME: a lot of Tree view operations fail after this point. where the View version just directly goes to the URL, the Tree view tries to modify the URL to pass the extjs-style grid's parameters back. this winds up creating unworkable URLs that try to do two things at once, with two '?'s, two 'op='s, etc. there are two ways to fix this: if we're trying to go to an asset (gotoAsset) and we're in Tree view, flop back to View mode first; or else two distinct requests, one for the remote request (which might generate additional requests to draw in dialog boxes, progress bars, forms, etc) and then when that's all done, refresh the grid view. WebGUI.Admin.prototype.pasteAsset takes the route of flopping to Tree view first.
|
||||
this.tree.goto( url );
|
||||
this.viewDirty = 1;
|
||||
}
|
||||
|
|
@ -478,27 +477,53 @@ WebGUI.Admin.prototype.updateClipboard
|
|||
*/
|
||||
WebGUI.Admin.prototype.addPasteHandler
|
||||
= function ( elem, assetId ) {
|
||||
var self = this;
|
||||
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.requestUpdateClipboard();
|
||||
self.afterNavigate.unsubscribe( updateAfterPaste );
|
||||
};
|
||||
self.afterNavigate.subscribe(updateAfterPaste, self );
|
||||
|
||||
self.afterNavigate.subscribe(updateAfterPaste, self);
|
||||
self.pasteAsset( assetId );
|
||||
}, self );
|
||||
};
|
||||
|
||||
/**
|
||||
* currentTabName()
|
||||
* Returns the name of the current tab, either "tree" or "view", for callbacks that need to distinguish them
|
||||
*/
|
||||
WebGUI.Admin.prototype.currentTabName
|
||||
= function() {
|
||||
if ( this.tabBar.get('activeIndex') > 1 ) {
|
||||
this.tabBar.selectTab( 0 );
|
||||
this.currentTab = "view";
|
||||
}
|
||||
return this.currentTab;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* pasteAsset( id )
|
||||
* Paste an asset and update the clipboard
|
||||
*/
|
||||
WebGUI.Admin.prototype.pasteAsset
|
||||
= function ( id ) {
|
||||
var url = appendToUrl( this.currentAssetDef.url, 'func=pasteList&assetId=' + id );
|
||||
console.log(url);
|
||||
this.gotoAsset( url );
|
||||
if ( this.currentTabName() == "view" ) {
|
||||
var url = appendToUrl( this.currentAssetDef.url, 'func=pasteList&assetId=' + id );
|
||||
this.gotoAsset( url );
|
||||
}
|
||||
else if ( this.currentTabName() == "tree" ) {
|
||||
this.tabBar.set('activeIndex', 0);
|
||||
// as above...
|
||||
var url = appendToUrl( this.currentAssetDef.url, 'func=pasteList&assetId=' + id );
|
||||
this.treeDirty = true;
|
||||
// this.gotoAsset( url ); // the change notification handler hasn't run yet at this point (and doesn't until we're done here) so this thinks we're still in the Tree view, so we have to do this directly
|
||||
window.frames[ "view" ].location.href = url;
|
||||
this.treeDirty = 1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -1897,170 +1922,6 @@ WebGUI.Admin.Tree
|
|||
};
|
||||
YAHOO.lang.extend( WebGUI.Admin.Tree, WebGUI.Admin.AssetTable );
|
||||
|
||||
/**
|
||||
* runHelperForSelected( helperId )
|
||||
* Run the named asset helper for each selected asset
|
||||
* Show the status of the task in a dialog box
|
||||
*/
|
||||
WebGUI.Admin.Tree.prototype.runHelperForSelected
|
||||
= function ( helperId, title ) {
|
||||
var self = this;
|
||||
var assetIds = this.getSelected();
|
||||
|
||||
// alert("ok");
|
||||
|
||||
// Open the dialog with two progress bars
|
||||
var dialog = new YAHOO.widget.Panel( 'helperForkModalDialog', {
|
||||
"width" : '350px',
|
||||
fixedcenter : true,
|
||||
constraintoviewport : true,
|
||||
underlay : "shadow",
|
||||
close : true,
|
||||
visible : true,
|
||||
draggable : false
|
||||
} );
|
||||
dialog.setHeader( title );
|
||||
dialog.setBody(
|
||||
'<div id="pbQueue"></div><div id="pbQueueStatus">0 / ' + assetIds.length + '</div>'
|
||||
+ '<div id="pbTask"></div><div id="pbTaskStatus"></div>'
|
||||
);
|
||||
dialog.render( document.body );
|
||||
this.treeDialog = dialog;
|
||||
|
||||
var pbQueueBar = new YAHOO.widget.ProgressBar({
|
||||
minValue : 0,
|
||||
value : 0,
|
||||
maxValue : assetIds.length,
|
||||
width: '300px',
|
||||
height: '30px',
|
||||
anim: true
|
||||
});
|
||||
pbQueueBar.render( 'pbQueue' );
|
||||
pbQueueBar.get('anim').duration = 0.5;
|
||||
pbQueueBar.get('anim').method = YAHOO.util.Easing.easeOut;
|
||||
var pbQueueStatus = document.getElementById( 'pbQueueStatus' );
|
||||
|
||||
var pbTaskBar = new YAHOO.widget.ProgressBar({
|
||||
minValue : 0,
|
||||
value : 0,
|
||||
maxValue : 1,
|
||||
width: '300px',
|
||||
height: '30px',
|
||||
anim: true
|
||||
});
|
||||
pbTaskBar.render( 'pbTask' );
|
||||
pbTaskBar.get('anim').duration = 0.5;
|
||||
pbTaskBar.get('anim').method = YAHOO.util.Easing.easeOut;
|
||||
|
||||
// Clean up when we're done
|
||||
var finish = function () {
|
||||
dialog.destroy();
|
||||
dialog = null;
|
||||
self.admin.requestUpdateClipboard();
|
||||
self.admin.requestUpdateCurrentVersionTag();
|
||||
self.goto( self.admin.currentAssetDef.url );
|
||||
};
|
||||
|
||||
// Build a function to call the helper for the next asset
|
||||
var callHelper = function( assetIds ) {
|
||||
var assetId = assetIds.shift();
|
||||
|
||||
var callback = {
|
||||
success : function (o) {
|
||||
var resp = YAHOO.lang.JSON.parse( o.responseText );
|
||||
|
||||
if ( resp.error ) {
|
||||
this.admin.processPlugin( resp );
|
||||
finish();
|
||||
}
|
||||
else if ( resp.forkId ) {
|
||||
// Wait until the helper is done, then call the next
|
||||
YAHOO.WebGUI.Fork.poll({
|
||||
url : '?op=fork;pid=' + resp.forkId,
|
||||
draw : function(data) {
|
||||
pbTaskBar.set( 'maxValue', data.total );
|
||||
pbTaskBar.set( 'value', data.finished );
|
||||
},
|
||||
finish : function(){
|
||||
pbQueueBar.set( 'value', pbQueueBar.get('value') + 1 );
|
||||
pbQueueStatus.innerHTML = pbQueueBar.get('value') + ' / ' + pbQueueBar.get('maxValue');
|
||||
if ( assetIds.length > 0 ) {
|
||||
callHelper( assetIds );
|
||||
}
|
||||
else {
|
||||
// We're all done now!
|
||||
finish();
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Just go to the next one
|
||||
if ( assetIds.length > 0 ) {
|
||||
callHelper( assetIds );
|
||||
}
|
||||
else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
},
|
||||
failure : function (o) {
|
||||
|
||||
},
|
||||
scope: this
|
||||
};
|
||||
|
||||
var url = '?op=admin;method=processAssetHelper;helperId=' + helperId + ';assetId=' + assetId;
|
||||
var ajax = YAHOO.util.Connect.asyncRequest( 'GET', url, callback );
|
||||
};
|
||||
|
||||
// Start the queue
|
||||
callHelper( assetIds );
|
||||
};
|
||||
|
||||
/**
|
||||
* cut( e )
|
||||
* Run the cut assethelper for the selected assets
|
||||
*/
|
||||
WebGUI.Admin.Tree.prototype.cut
|
||||
= function ( e ) {
|
||||
this.runHelperForSelected( "cut", "Cut" );
|
||||
};
|
||||
|
||||
/**
|
||||
* copy( e )
|
||||
* Run the Copy assethelper for the selected assets
|
||||
*/
|
||||
WebGUI.Admin.Tree.prototype.copy
|
||||
= function ( e ) {
|
||||
this.runHelperForSelected( "copy", "Copy" );
|
||||
};
|
||||
|
||||
/**
|
||||
* shortcut( e )
|
||||
* Run the shortcut assethelper for the selected assets
|
||||
*/
|
||||
WebGUI.Admin.Tree.prototype.shortcut
|
||||
= function ( e ) {
|
||||
this.runHelperForSelected( "shortcut", "Create Shortcut" );
|
||||
};
|
||||
|
||||
/**
|
||||
* Run the duplicate assethelper for the selected assets
|
||||
*/
|
||||
WebGUI.Admin.Tree.prototype.duplicate
|
||||
= function ( e ) {
|
||||
this.runHelperForSelected( "duplicate", "Duplicate" );
|
||||
};
|
||||
|
||||
/**
|
||||
* Run the delete assetHelper for the selected assets
|
||||
*/
|
||||
WebGUI.Admin.Tree.prototype.delete
|
||||
= function ( e ) {
|
||||
this.runHelperForSelected( "delete", "Delete" );
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the selected assets' ranks
|
||||
*/
|
||||
|
|
@ -2199,13 +2060,14 @@ WebGUI.Admin.Tree.prototype.buildQueryString
|
|||
/**
|
||||
* Update the tree with a new asset
|
||||
* Do not call this directly, use Admin.gotoAsset(url)
|
||||
* If the assetUrl parameter itself has parameters, this will not generate a correct URL
|
||||
*/
|
||||
WebGUI.Admin.Tree.prototype.goto
|
||||
= function ( assetUrl ) {
|
||||
// TODO: Show loading screen
|
||||
var callback = {
|
||||
success : this.onDataReturnInitializeTable,
|
||||
failure : this.onDataReturnInitializeTable,
|
||||
failure : function() { console.error("Failed to fetch data"); alert("Failed to fetch data of some sort...") }, // XXX see the FIXME in WebGUI.Admin.prototype.gotoAsset. this generally fails for that reason when it fails.
|
||||
scope : this,
|
||||
argument: this.dataTable.getState()
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue