Navigation Menu

Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Pipe search and download actions by using nodes selections to downloa…
Browse files Browse the repository at this point in the history
…d a whole search result at once.
  • Loading branch information
cdujeu committed Oct 7, 2013
1 parent 7adbae5 commit 4fbcb0b
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 6 deletions.
33 changes: 33 additions & 0 deletions core/src/plugins/action.cart/class.CartManager.js
Expand Up @@ -65,6 +65,38 @@ Class.create("CartManager", FetchedResultPane, {
this.triggerEvent();
},

downloadFetchedPaneContent:function(fetchedResultPane, paneLabel){

if(!$("download_form")) return;
var props = Object.clone(fetchedResultPane.options.nodeProviderProperties);

// Replace "search" by "search-cart-download"
delete props['get_action'];
if(paneLabel) props["archive_name"] = slugString(paneLabel)+".zip";

var form = $('download_form');
form.action = window.ajxpServerAccessPath;
form.secure_token.value = Connexion.SECURE_TOKEN;
var gAction;
form.select("input").each(function(input){
if(input.name!='get_action' && input.name!='secure_token') input.remove();
if(input.name == 'get_action') input.value = 'search-cart-download';
});

$H(props).each(function(pair){
form.insert(new Element('input', {type:'hidden', name:pair.key, value:pair.value}));
});
try{
form.submit();
}catch(e){

}
// Reset download form to initial value
form.down('input[name="get_action"]').setValue('download');

},


downloadContent: function(){
var h = this.getLocalSelectionForPosting();
if(h.size() == 0) return;
Expand All @@ -78,6 +110,7 @@ Class.create("CartManager", FetchedResultPane, {
if(input.name!='get_action' && input.name!='secure_token') input.remove();
});
h.set('dir', '__AJXP_ZIP_FLAT__/');
h.set('archive_name', slugString(this.__label)+".zip");
h.each(function(pair){
form.insert(new Element('input', {type:'hidden', name:pair.key, value:pair.value}));
});
Expand Down
48 changes: 48 additions & 0 deletions core/src/plugins/action.cart/class.CartManager.php
@@ -0,0 +1,48 @@
<?php
/*
* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://pyd.io/>.
*/

class CartManager extends AJXP_Plugin {

public function switchAction ($actionName, $httpVars, $fileVars){

if($actionName == "search-cart-download"){

// Pipe SEARCH + DOWNLOAD actions.

$indexer = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("index");
if($indexer == false) return;
$httpVars["return_selection"] = true;
unset($httpVars["get_action"]);
$res = AJXP_Controller::findActionAndApply("search", $httpVars, $fileVars);
if(isSet($res) && is_array($res)){
$newHttpVars = array(
"selection_nodes" => $res,
"dir" => "__AJXP_ZIP_FLAT__/",
"archive_name" => $httpVars["archive_name"]
);
AJXP_Controller::findActionAndApply("download", $newHttpVars, array());
}

}

}

}
43 changes: 37 additions & 6 deletions core/src/plugins/action.cart/manifest.xml
Expand Up @@ -51,12 +51,18 @@
<processing>
<clientCallback><![CDATA[
var tabulator = $('cart-manager-header').ajxpPaneObject;
var value = $('search_txt').getValue();
var newLabel = "Search '"+value+"'";
newLabel = window.prompt('This will save this search in your Carts. Change the name if you want to:', newLabel);
if(newLabel && tabulator && value){
tabulator.addTab({"id":"new-cart-"+new Date().getTime(),"label":newLabel,"iconClass":"icon-search", closeable:true, dontFocus:false},
{type:"widget", widgetClass:FetchedResultPane, widgetOptions:{label:newLabel,"nodeProviderProperties":{"get_action":"search", "query":value},"reloadOnServerMessage":"tree/reload_bookmarks"}});
var searchEngine;
try{
searchEngine = $$('[ajxpClass="SearchEngine"]')[0].ajxpPaneObject;
}catch(e){};
if(searchEngine){
var value = searchEngine.crtText;
var newLabel = "Search "+value;
newLabel = window.prompt('This will save this search in your Carts. Change the name if you want to:', newLabel);
if(newLabel && tabulator && value){
tabulator.addTab({"id":"new-cart-"+new Date().getTime(),"label":newLabel,"iconClass":"icon-search", closeable:true, dontFocus:false},
{type:"widget", widgetClass:FetchedResultPane, widgetOptions:{label:newLabel,"nodeProviderProperties":searchEngine.buildNodeProviderProperties(),"reloadOnServerMessage":"tree/reload_bookmarks"}});
}
}
]]></clientCallback>
</processing>
Expand Down Expand Up @@ -129,6 +135,30 @@
]]></activeCondition>
</processing>
</action>
<action name="search-cart-download">
<gui src="" iconClass="icon-download-alt" text="action.cart.7" title="action.cart.8">
<context dir="true" recycle="true" selection="false" actionBar="true" actionBarGroup="ajxp-cart-actions"/>
</gui>
<processing>
<clientCallback><![CDATA[
var object = $('cart-manager-header').ajxpPaneObject.getAndSetAjxpObject( $('cart-manager-header').ajxpPaneObject.selectedTabInfo );
if(object && $('download_form')){
var label = $('cart-manager-header').ajxpPaneObject.selectedTabInfo.label;
CartManager.prototype.downloadFetchedPaneContent(object, label);
}
]]></clientCallback>
<serverCallback methodName="switchAction"/>
<activeCondition><![CDATA[
if($('cart-manager-header') && $('cart-manager-header').ajxpPaneObject){
var object = $('cart-manager-header').ajxpPaneObject.getAndSetAjxpObject( $('cart-manager-header').ajxpPaneObject.selectedTabInfo );
if(!object || object.__className!='FetchedResultPane'){
return false;
}
}
return ajaxplorer.actionBar.actions.get('download') != null;
]]></activeCondition>
</processing>
</action>
<action name="current-cart-share">
<gui src="" iconClass="icon-share" text="action.cart.10" title="action.cart.11">
<context dir="true" recycle="true" selection="false" actionBar="true" actionBarGroup="ajxp-cart-actions"/>
Expand Down Expand Up @@ -176,4 +206,5 @@
</actions>
</registry_contributions>

<class_definition classname="CartManager" filename="plugins/action.cart/class.CartManager.php"/>
</ajxp_plugin>

0 comments on commit 4fbcb0b

Please sign in to comment.