/*
	Copyright (c) 2006-2010, ePages GmbH
	All Rights Reserved.

	epages.cartridges.de_epages.mediagallery.widget.StockPhotoTree $Revision: 1.4 $

*/
dojo.provide("epages.cartridges.de_epages.mediagallery.widget.StockPhotoTree");
dojo.require("epages.widget.LocalizedWidget");
dojo.require("dijit.Tree");
dojo.require("epages.io.json");
dojo.require('dojo.data.ItemFileReadStore');
dojo.require('dijit.tree.ForestStoreModel');
dojo.require('dijit.Tree');
dojo.declare(
	"epages.cartridges.de_epages.mediagallery.widget.StockPhotoTree",
	[epages.widget.LocalizedWidget],
	{
		/**
		* public properties
		*/

		/**
		* private properties
		*/
		templatePath       : dojo.moduleUrl('epages.cartridges.de_epages.mediagallery.widget', 'templates/StockPhotoTree.html'),
		translationName    : dojo.moduleUrl('epages.cartridges.de_epages.mediagallery.widget', 'templates/translation'),
		widgetsInTemplate  : true,
		_tree              : undefined,
		_store             : undefined,
		_mode              : undefined,
		/**
		* public methods
		*/
		postCreate  : function() {
			this.inherited("postCreate", arguments);
			//build Store & Model & Tree
			var treeData = {
				identifier: 'id',
				label: 'name',
				items: [
					{ id: 'Buy', name:'Buy Images',type:'link'}
					]
			};
			this._store = new dojo.data.ItemFileReadStore({
				data: treeData
			});

			this._model = new dijit.tree.ForestStoreModel({
				store: this._store,
				query: {
					"type": "link"
				},
				rootId: "StockPhotoDB",
					rootLabel: "StockPhotoDatabase",
					childrenAttrs: ["children"]
				});

				this._tree = new dijit.Tree({
					model: this._model,
					onClick: this._onTreeClick
				},
				this.treeNode);

				//connect to publish events from filebrowser
				dojo.subscribe('Filebrowser/PluginLinkClick',this,'onPluginLinkClicked');
		},

		_onTreeClick:function(/* dojo.data */ item, /*TreeNode*/ node, /*Event*/ evt){
			if(item.root){
				//root node was clicked
				//console.debug('root node clicked');
			}
			else if(item.id == "Buy"){
				//buy was clicked
				//console.debug('buy images clicked');
			}
		},

		onPluginLinkClicked: function(data){
			if(data.id == "stockPhotoPlugin"){
				//console.debug('StockPhotoTree: stockPhotoPlugin link was clicked');
			}
		}
});