7fee23f2e25547ffd575c89f6c244b39ac7b1c52
[tine20] / tine20 / Setup / js / Setup.js
1 /*
2  * Tine 2.0
3  * 
4  * @package     Setup
5  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
6  * @author      Cornelius Weiss <c.weiss@metaways.de>
7  * @copyright   Copyright (c) 2009 Metaways Infosystems GmbH (http://www.metaways.de)
8  *
9  */
10  
11 Ext.ns('Tine', 'Tine.Setup');
12
13 /**
14  * @namespace   Tine.Setup
15  * @class       Tine.Setup.TreePanel
16  * @extends     Ext.tree.TreePanel
17  * 
18  * <p>Setup TreePanel</p>
19  * 
20  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
21  * @author      Cornelius Weiss <c.weiss@metaways.de>
22  * @copyright   Copyright (c) 2009 Metaways Infosystems GmbH (http://www.metaways.de)
23  * 
24  * @param       {Object} config
25  * @constructor
26  * Create a new Tine.Setup.TreePanel
27  */
28 Tine.Setup.TreePanel = Ext.extend(Ext.tree.TreePanel, {
29     
30     /**
31      * tree panel cfg
32      * 
33      * @private
34      */
35     border: false,
36     rootVisible: false, 
37     
38     /**
39      * @private
40      */
41     initComponent: function() {
42         this.app = Tine.Tinebase.appMgr.get('Setup');
43         
44         var termsFailed   = !Tine.Setup.registry.get('acceptedTermsVersion') || Tine.Setup.registry.get('acceptedTermsVersion') < Tine.Setup.CurrentTermsVersion;
45         var testsFailed   = !Tine.Setup.registry.get('setupChecks').success;
46         var configMissing = !Tine.Setup.registry.get('configExists');
47         var dbMissing     = !Tine.Setup.registry.get('checkDB');
48         var setupRequired = Tine.Setup.registry.get('setupRequired');
49         
50         this.root = {
51             id: '/',
52             children: [{
53                 text: this.app.i18n._('Terms and Conditions'),
54                 iconCls: termsFailed ? 'setup_checks_fail' : 'setup_checks_success',
55                 id: 'TermsPanel',
56                 leaf: true
57             }, {
58                 text: this.app.i18n._('Setup Checks'),
59                 iconCls: testsFailed ? 'setup_checks_fail' : 'setup_checks_success',
60                 disabled: termsFailed,
61                 id: 'EnvCheckGridPanel',
62                 leaf: true
63             }, {
64                 text: this.app.i18n._('Config Manager'),
65                 iconCls: 'setup_config_manager',
66                 disabled: termsFailed || testsFailed,
67                 id: 'ConfigManagerPanel',
68                 leaf: true
69             }, {
70                 text: this.app.i18n._('Authentication/Accounts'),
71                 iconCls: 'setup_authentication_manager',
72                 disabled: termsFailed || testsFailed || configMissing || dbMissing,
73                 id: 'AuthenticationPanel',
74                 leaf: true
75             }, {
76                 text: this.app.i18n._('Email'),
77                 iconCls: 'action_composeEmail',
78                 disabled: termsFailed || testsFailed || configMissing || dbMissing || setupRequired,
79                 id: 'EmailPanel',
80                 leaf: true
81             }, {
82                 text: this.app.i18n._('Application Manager'),
83                 iconCls: 'setup_application_manager',
84                 disabled: termsFailed || testsFailed || configMissing || dbMissing || setupRequired,
85                 id: 'ApplicationGridPanel',
86                 leaf: true
87             }]
88         };
89         
90         Tine.Setup.TreePanel.superclass.initComponent.call(this);
91         
92         this.on('click', this.onNodeClick, this);
93     },
94     
95     /**
96      * @private
97      */
98     onNodeClick: function(node) {
99         if (! node.disabled) {
100             this.app.getMainScreen().activePanel = node.id;
101             this.app.getMainScreen().show();
102         } else {
103             return false;
104         }
105         
106     },
107     
108     /**
109      * @private
110      */
111     afterRender: function() {
112         Tine.Setup.TreePanel.superclass.afterRender.call(this);
113         
114         var activeType = '';
115         var contentTypes = this.getRootNode().childNodes;
116         for (var i=0; i<contentTypes.length; i++) {
117             if(! contentTypes[i].disabled) {
118                 activeType = contentTypes[i];
119             }
120         }
121         
122         activeType.select();
123         this.app.getMainScreen().activePanel = activeType.id;
124         
125         Tine.Setup.registry.on('replace', this.applyRegistryState, this);
126     },
127     
128     /**
129      * apply registry state
130      */
131     applyRegistryState: function() {
132         var termsChecks  = Tine.Setup.registry.get('acceptedTermsVersion') >= Tine.Setup.CurrentTermsVersion;
133         var setupChecks  = Tine.Setup.registry.get('setupChecks').success;
134         var configExists = Tine.Setup.registry.get('configExists');
135         var checkDB      = Tine.Setup.registry.get('checkDB');
136         var setupRequired = Tine.Setup.registry.get('setupRequired');
137         
138         this.setNodeIcon('TermsPanel', termsChecks);
139         this.setNodeIcon('EnvCheckGridPanel', setupChecks);
140         
141         this.getNodeById('EnvCheckGridPanel')[termsChecks ? 'enable': 'disable']();
142         this.getNodeById('ConfigManagerPanel')[termsChecks && setupChecks ? 'enable': 'disable']();
143         this.getNodeById('AuthenticationPanel')[termsChecks && setupChecks && configExists && checkDB ? 'enable': 'disable']();
144         this.getNodeById('ApplicationGridPanel')[termsChecks && setupChecks && configExists && checkDB && !setupRequired ? 'enable': 'disable']();
145         this.getNodeById('EmailPanel')[termsChecks && setupChecks && configExists && checkDB && !setupRequired ? 'enable': 'disable']();
146     },
147     
148     setNodeIcon: function (nodeId, success) {
149         var node = this.getNodeById(nodeId);
150         var iconCls = success ? 'setup_checks_success' : 'setup_checks_fail';
151         if (node.rendered) {
152             var iconEl = Ext.get(node.ui.iconNode);
153             iconEl.removeClass('setup_checks_success');
154             iconEl.removeClass('setup_checks_fail');
155             iconEl.addClass(iconCls);
156         } else {
157             envNode.iconCls = iconCls;
158         }
159     }
160 });
161
162 Ext.ns('Tine', 'Tine.Setup', 'Tine.Setup.Model');
163
164 /**
165  * @namespace   Tine.Setup.Model
166  * @class       Tine.Setup.Model.Application
167  * @extends     Tine.Tinebase.data.Record
168  * 
169  * Application Record Definition
170  */ 
171 Tine.Setup.Model.Application = Tine.Tinebase.data.Record.create([
172     { name: 'id'              },
173     { name: 'name'            },
174     { name: 'status'          },
175     { name: 'order'           },
176     { name: 'version'         },
177     { name: 'current_version' },
178     { name: 'install_status'  },
179     { name: 'depends'         }
180 ], {
181     appName: 'Setup',
182     modelName: 'Application',
183     idProperty: 'name',
184     titleProperty: 'name',
185     // ngettext('Application', 'Applications', n); gettext('Application');
186     recordName: 'Application',
187     recordsName: 'Applications'
188 });
189
190 /**
191  * @namespace   Tine.Setup
192  * @class       Tine.Setup.ApplicationBackend
193  * @extends     Tine.Tinebase.data.RecordProxy
194  * 
195  * default application backend
196  */ 
197 Tine.Setup.ApplicationBackend = new Tine.Tinebase.data.RecordProxy({
198     appName: 'Setup',
199     modelName: 'Application',
200     recordClass: Tine.Setup.Model.Application
201 });
202
203 /**
204  * @namespace   Tine.Setup.Model
205  * @class       Tine.Setup.Model.EnvCheck
206  * @extends     Ext.data.Record
207  * 
208  * env check Record Definition
209  */ 
210 Tine.Setup.Model.EnvCheck = Ext.data.Record.create([
211     {name: 'key'},
212     {name: 'value'},
213     {name: 'message'}
214 ]);