/* * Copyright 2007-2011 Charles du Jeu * This file is part of AjaXplorer. * * AjaXplorer 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. * * AjaXplorer 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 AjaXplorer. If not, see . * * The latest code can be found at . */ /** * Independant widget for opening a form with a Tree in it */ Class.create("TreeSelector", { /** * Constructor * @param oElement HTMLElement * @param options Object */ initialize : function(oElement, options){ this.htmlElement = oElement; this.options = Object.extend({ filterSelectorId : 'select[id="external_repository"]', targetField : 'input[name="dest"]', targetNode: 'input[name="dest_node"]', treeContainer : '.treeCopyContainer' }, options || {}); }, /** * Load the tree data * @param rootNode AjxpNode */ load : function(rootNode){ if(webFXTreeHandler && webFXTreeHandler.selected){ this.__initialWebFXSelection = webFXTreeHandler.selected; } this.filterSelector = this.htmlElement.select(this.options.filterSelectorId)[0]; var target = this.targetField = this.htmlElement.select(this.options.targetField)[0]; var targetNode = this.targetNode = this.htmlElement.select(this.options.targetNode)[0]; this.treeContainer = this.htmlElement.select(this.options.treeContainer)[0]; this.filterSelector.hide(); this._nodeActionCallback = function(e){ // Warning, this is the tree object target.value = this.ajxpNode.getPath(); targetNode.value = this.ajxpNode.getPath(); this.select(); }; this._nodeFilter = function(ajxpNode){ return (!ajxpNode.isLeaf()); }; if(!rootNode){ rootNode = new AjxpNode("/", false, MessageHash[373], "folder.png"); } this.treeCopy = new AJXPTree(rootNode, this._nodeActionCallback, this._nodeFilter); this.treeContainer.update(this.treeCopy.toString()); $(this.treeCopy.id).observe("click", function(e){ this.action(); Event.stop(e); }.bind(this.treeCopy)); this.treeCopy.focus(); this.treeCopy.setAjxpRootNode(rootNode); }, /** * Clear the widget */ unload : function(){ if(this.__initialWebFXSelection){ this.__initialWebFXSelection.select(); } this.treeCopy.remove(); }, /** * Retrieve select node * @returns String */ getSelectedNode : function(){ return this.targetNode.getValue(); }, /** * Retrieve selected label * @returns String */ getSelectedLabel : function(){ return this.target.getValue(); }, /** * Whether to show / hide the filter