From b962b03848a7f58b4c4c7399bc97f241b93a22bd Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Wed, 18 Sep 2013 18:06:01 -0500 Subject: [PATCH] Making the "Copy Branch" menu option work was a treat. requestHelper() invokes an asset helper via AJAX. processPlugin() handles the JSON responses, which in this case is to open a dialog box and show a given URL in it (openDialog key in the JSON hash). that pop-up is open and the page loaded, and that displays a form. that form submits to an asset helper (uh oh) which also returns JSON (actually, it was failing to do even that and was stringifying a hash). even if it returned JSON, it would just get shown to the user in the pop-up. so the form that gets loaded into the pop-up has to, onsubmit, after it has config details from the user, run JS to make the AJAX request to the asset helper to start the actual copy operation, call into the admin's JS to pop up the dialog that polls on a forked process, and then call into the admin to close itself. this is a nasty hack that daisy chains together two possible replies to processPlugin(), one after the other. --- lib/WebGUI/AssetHelper/CopyBranch.pm | 55 +++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/lib/WebGUI/AssetHelper/CopyBranch.pm b/lib/WebGUI/AssetHelper/CopyBranch.pm index 59f398f6a..2257b0c12 100644 --- a/lib/WebGUI/AssetHelper/CopyBranch.pm +++ b/lib/WebGUI/AssetHelper/CopyBranch.pm @@ -4,6 +4,7 @@ use strict; use base qw/WebGUI::AssetHelper/; use Scalar::Util qw{ blessed }; use WebGUI::VersionTag; +use JSON; =head1 LEGAL @@ -61,10 +62,52 @@ sub www_getWith { my $session = $self->session; my $i18n = WebGUI::International->new($session, 'Asset'); - my $f = $self->getForm( 'copy' ); - $f->addField( 'submit', name => 'with', value => 'Children' ); - $f->addField( 'submit', name => 'with', value => 'Descendants' ); - return $f->toHtml; + my $copy_url = $self->getUrl( 'copy' ); # call this URL to start the copy; it returns a forkId + my $url = $self->session->url->page; + + # XXX should probably be in a template + return qq{ + + + + + + + + + + + + + + + +
+
+
+
+ + }; } @@ -91,9 +134,9 @@ sub www_copy { $session, blessed( $self ), 'copyBranch', { childrenOnly => $childrenOnly, assetId => $asset->getId, commit => $commit }, ); - return { + return JSON->new->encode( { forkId => $fork->getId, - }; + } ); } #-------------------------------------------------------------------