/*
 * Tine 2.0 - CoreData 
 * Copyright (c) 2007-2016 Metaways Infosystems GmbH (http://www.metaways.de)
 * http://www.gnu.org/licenses/agpl.html AGPL Version 3
 */
Ext.ns("Tine.CoreData");Tine.CoreData.Manager=function(){var a={},c={},b={};return{getGrid:function(e,d){if(a.hasOwnProperty(e)){constr=a[e].constr;if(!d){d=a[e].options}}else{Tine.log.warn("Id not registered in CoreData manager: "+e)}return Ext.isFunction(constr)?new constr(d):null},getEditDialog:function(e,d){if(c.hasOwnProperty(e)){constr=c[type]}return Ext.isFunction(constr)?new constr(d):null},getToolbar:function(e,d){if(b.hasOwnProperty(e)){constr=b[type];if(!d){d=b[e].options}}else{Tine.log.warn("Id not registered in CoreData manager: "+e)}return Ext.isFunction(constr)?new constr(d):null},registerGrid:function(f,e,d){a[f]={constr:e,options:d}},registerToolbar:function(f,e,d){b[f]={constr:e,options:d}},registerEditDialog:function(e,d){c[e]=d}}}();Ext.ns("Tine","Tine.CoreData");Tine.CoreData.TreePanel=function(a){Ext.apply(this,a);this.id="TreePanel";Tine.CoreData.TreePanel.superclass.constructor.call(this)};Ext.extend(Tine.CoreData.TreePanel,Ext.tree.TreePanel,{autoScroll:true,border:false,initComponent:function(){if(!this.app){this.app=Tine.Tinebase.appMgr.get("CoreData")}var b=this.getCoreDataNodes("/general"),a=this.getCoreDataNodes("/applications");this.root={path:"/",cls:"tinebase-tree-hide-collapsetool",text:this.app.i18n._("Core Data"),expanded:true,children:[{path:"/general",id:"general",expanded:true,text:this.app.i18n._("General Data"),hidden:(b.length==0),children:b},{path:"/applications",id:"applications",expanded:true,text:this.app.i18n._("Application Data"),children:a}]};this.on("click",this.onClick,this);Tine.CoreData.TreePanel.superclass.initComponent.call(this)},getCoreDataNodes:function(c){if(!Tine.CoreData.registry.get("coreData")){return[]}var b=[],a={};Ext.each(Tine.CoreData.registry.get("coreData")["results"],function(d){if((c==="/applications"&&d.application_id.name!=="Tinebase")||(c==="/general"&&d.application_id.name==="Tinebase")){var e=Tine.Tinebase.appMgr.get(d.application_id.name);if(!a[d.application_id.name]){a[d.application_id.name]=[];b.push({path:c+"/"+d.application_id.id,id:d.application_id.id,text:e.i18n._(d.application_id.name),attributes:d.application_id})}a[d.application_id.name].push({path:c+"/"+d.application_id.id+"/"+d.id,id:d.id,text:e.i18n._(d.label),leaf:true,attributes:d})}},this);if(c==="/general"){return(a.Tinebase)?a.Tinebase:[]}else{Ext.each(b,function(d){d.children=a[d.attributes.name]});return b}},onClick:function(a,b){if(a.attributes.attributes&&a.attributes.attributes.id&&a.leaf){Tine.log.debug("Tine.CoreData.TreePanel::onClick");Tine.log.debug(a);var c=this.app.getMainScreen();c.activeContentType=a.attributes.attributes.id;c.activate();c.getCenterPanel().getStore().reload()}else{return false}}});Ext.ns("Tine.CoreData");Tine.CoreData.WestPanel=Ext.extend(Tine.widgets.mainscreen.WestPanel,{getAdditionalItems:function(){return[new Tine.CoreData.TreePanel({height:"auto"})]}});Ext.ns("Tine","Tine.CoreData");Tine.CoreData.Application=Ext.extend(Tine.Tinebase.Application,{});Tine.CoreData.MainScreen=Ext.extend(Tine.widgets.MainScreen,{getNorthPanel:function(a){a=a||this.getActiveContentType();if(!this[a+"ActionToolbar"]){if(a===""){this[a+"ActionToolbar"]=new Ext.Toolbar({items:[]})}else{this[a+"ActionToolbar"]=Ext.isFunction(this[a+this.centerPanelClassNameSuffix].getActionToolbar)?this[a+this.centerPanelClassNameSuffix].getActionToolbar():Tine.CoreData.Manager.getToolbar(a)}}return this[a+"ActionToolbar"]},getCenterPanel:function(a){a=a||this.getActiveContentType();if(!this[a+this.centerPanelClassNameSuffix]){if(a===""){this[a+this.centerPanelClassNameSuffix]=new Ext.Panel({html:this.app.i18n._("Please select core data from tree ...")})}else{this[a+this.centerPanelClassNameSuffix]=Tine.CoreData.Manager.getGrid(a)}}return this[a+this.centerPanelClassNameSuffix]},getWestPanel:function(){var b="WestPanel";if(!this[b]){var a={app:this.app,listeners:{scope:this,selectionchange:function(){var g=this.getCenterPanel();if(g){try{var d=g.getGrid();if(d){var h=d.getSelectionModel();if(h){h.clearSelections();g.actionUpdater.updateActions(h.getSelectionsCollection())}}}catch(f){}}}}};try{if(Tine[this.app.name].hasOwnProperty(b)){this[b]=new Tine[this.app.appName][b](a)}else{this[b]=new Tine.widgets.mainscreen.WestPanel(a)}}catch(c){Tine.log.error("Could not create westPanel");Tine.log.error(c.stack?c.stack:c);this[b]=new Ext.Panel({html:"ERROR"})}}return this[b]},});