﻿<?xml version="1.0" encoding="utf-8" ?> 
<html-fragment>
	<import-style src ="Styles/jsprof.css" id ="jsprof" />
	<import-style src ="Styles/ContentExplorer.css" id ="ContentExplorer" />

	<!-- ___pointer_marker is used to hide controls from the EngineStats modeller -->
	<div style = "width:25%;float:left;">
		 <div class="title" style ="clear:right;">Project Folders</div>
		 <div style ="margin-left:5px;clear:both;">
			<ul class ="treecomp" rid ="tree" component ="tree_decorator" DirectoryOnly ="1" DirectoryId ="DWAC">
				<li>DWAC
					<ul>
						<li>Components</li>		 
						<li>Fragments</li>
						 <li>Modules</li>
						<li>Projects</li>
						<li>Pub</li>
						<li>Tasks</li>
						<li>Templates</li>
            <li>Tests</li>
            <li>Workers</li>
					</ul>
						 
				</li>
			</ul>
		</div>
			<!--
			<div rid ="tree" DirectoryId ="DWAC" style ="clear:both;" component ="tree">
						 
			</div>
			-->
	</div>
	<div style = "width:50%;float:left;">
		 <div class="title" component ="tree_context" style ="clear:right;"></div>
			<div ___pointer_marker = "never" rid ="content-viewer" component = "content_viewer">
			</div>
	</div>
	<p style ="clear:left;"></p>
	<embedded-script><![CDATA[
		embedded_init : function (){
			this.getProperties().dwac_user = escape(this.GetSession().GetParam("UserName"));
			if(!this.getProperties().dwac_user){
					alert("Invalid DWAC user");
					return;
			}
			 
			// Add DWACExplorer to the 'tree' Transaction
			//
			var _t = Hemi.transaction.service;
			var pPacket = _t.getPacketByName("tree");

			if(pPacket) _t.addTransactionParticipant(this,pPacket);

		},
		_handle_newcontent : function(s, v){
			var oViewer = v.data.src;
			var sName = this.GetComponentByRID("tree").GetCurrentNodeName();
			/*
			switch(sName){
				case "Projects":
						this.ShowTab(1);
						this.CreateNewProject();
						break;
				case "Tasks":
						this.ShowTab(2);
						this.CreateNewTaskList();
						break;
				case "Fragments":
						this.ShowTab(3);
						this.CreateNewComponent();
						break;
				case "Components":
						this.ShowTab(4);
						this.CreateNewComponent();
						break;
				case "Templates":
						this.ShowTab(5);
						this.CreateNewTemplate();
						break;
			}
			*/
		},
		_handle_deletecontent : function(s, v){
			var oViewer = v.data.src;
			var sName = this.GetComponentByRID("tree").GetCurrentGroupName();
			var iId = parseInt(oViewer.GetCurrentItem().item_id);
			var oR = Hemi.xml.getXml(g_application_path + "DWAC/" + this.getProperties().dwac_user + "/" + sName + "/ID-" + iId + "/Delete?is-xml=1&ts=" + (new Date()).getTime());
			if(this.IsSuccess(oR)){
				this.RefreshDWACLists();
			}
			

		},		
		_handle_opencontent : function(s, v){
			var oViewer = v.data.src;
			var sName = this.GetComponentByRID("tree").GetCurrentGroupName();
			var iId = parseInt(oViewer.GetCurrentItem().item_id);

			switch(sName){
				case "Projects":
						this.LoadProject(iId);
						this.ShowTab(1);
						break;
				case "Tasks":
						this.LoadTaskList(iId);
						this.ShowTab(2);
						break;
				case "Fragments":
						this.LoadFragment(iId);
						this.ShowTab(3);
						break;
				case "Components":
						this.LoadComponent(iId);
						this.ShowTab(4);
						break;
				case "Templates":
						this.LoadTemplate(iId);
						this.ShowTab(5);
						break;
			}
		},

		RefreshDWACLists : function(){
				this.GetComponentByRID("content-viewer").ClearCache(1);
				this.GetComponentByRID("tree").SelectLeaf(this.GetComponentByRID("tree").GetCurrentGroupName());
				//this.GetComponentByRID("tree").RePopulateTree();
				//Hemi.xml.getXml(g_application_path + "DWAC/" + this.getProperties().dwac_user + "/List?is-xml=1&ts=" + (new Date()).getTime(), this._prehandle_dwaclists_load);
		},
		embedded_destroy : function(){

		},
		OpenFrameworkProfiler : function(fHandler){
			var oW = Hemi.app.createWindow(0, "Templates/FrameworkProfiler.xml", "Templates/FrameworkProfiler.xml", Hemi.app.space.service.getPrimarySpace(),0,0,fHandler);
			if(!oW && fHandler) fHandler(Hemi.app.getWindowManager().GetWindowByName("Templates/FrameworkProfiler.xml"));
		},
		OpenAPIBrowser : function(){
			var oW = Hemi.app.createWindow(0, "Templates/FrameworkProfiler.xml", "Templates/FrameworkProfiler.xml", Hemi.app.space.service.getPrimarySpace(),0,0,this.HandleOpenAPI);
			if(!oW) return this.HandleOpenAPI(Hemi.app.getWindowManager().GetWindowByName("Templates/FrameworkProfiler.xml"));
		},
		HandleOpenAPI : function(oW){
			oW.ShowTab(1);
			oW._handle_show_api();
		}

		

	]]></embedded-script>
</html-fragment>
