1 /*!
  2 * This file is part of Aloha Editor Project http://aloha-editor.org
  3 * Copyright (c) 2010-2011 Gentics Software GmbH, aloha@gentics.com
  4 * Contributors http://aloha-editor.org/contribution.php 
  5 * Licensed unter the terms of http://www.aloha-editor.org/license.html
  6 *//*
  7 * Aloha Editor is free software: you can redistribute it and/or modify
  8 * it under the terms of the GNU Affero General Public License as published by
  9 * the Free Software Foundation, either version 3 of the License, or
 10 * (at your option) any later version.*
 11 *
 12 * Aloha Editor is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15 * GNU Affero General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Affero General Public License
 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 19 */
 20 
 21 define(
 22 ['aloha/ext', 'aloha/repositorymanager'],
 23 function(Ext, RepositoryManager) {
 24 	"use strict";
 25 
 26 Ext.tree.AlohaTreeLoader = function(config) {
 27 	Ext.apply(this, config);
 28 	Ext.tree.AlohaTreeLoader.superclass.constructor.call(this);
 29 };
 30 
 31 Ext.extend( Ext.tree.AlohaTreeLoader, Ext.tree.TreeLoader, {
 32 	paramOrder: ['node', 'id'],
 33 	nodeParameter: 'id',
 34 	directFn : function(node, id, callback) {
 35 		var
 36 			params = {
 37 				inFolderId: node.id,
 38 				objectTypeFilter: this.objectTypeFilter,
 39 				repositoryId: node.repositoryId
 40 			};
 41 
 42 		RepositoryManager.getChildren ( params, function( items ) {
 43 			var response = {};
 44 
 45 			response = {
 46 				status: true,
 47 				scope: this,
 48 				argument: {callback: callback, node: node}
 49 			};
 50 
 51 			if(typeof callback === 'function'){
 52 				callback(items, response);
 53 			}
 54 		});
 55 	},
 56 	createNode: function(node) {
 57 		if ( node.name ) {
 58 			node.text = node.name;
 59 		}
 60 		if ( node.hasMoreItems ) {
 61 			node.leaf = !node.hasMoreItems;
 62 		}
 63  64 		if ( node.objectType ) {
 65 			node.cls = node.objectType;
 66 		}
 67         return Ext.tree.TreeLoader.prototype.createNode.call(this, node);
 68     },
 69 	objectTypeFilter : null,
 70 	setObjectTypeFilter : function (otFilter) {
 71 		this.objectTypeFilter = otFilter;
 72 	},
 73 	getObjectTypeFilter : function () {
 74 		return this.objectTypeFilter;
 75 	}
 76 });
 77 
 78 });
 79