setupChecks registry setting might be empty
[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');
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         setupChecks = (setupChecks.success) ? setupChecks.success : false;
139
140         this.setNodeIcon('TermsPanel', termsChecks);
141         this.setNodeIcon('EnvCheckGridPanel', setupChecks);
142         
143         this.getNodeById('EnvCheckGridPanel')[termsChecks ? 'enable': 'disable']();
144         this.getNodeById('ConfigManagerPanel')[termsChecks && setupChecks ? 'enable': 'disable']();
145         this.getNodeById('AuthenticationPanel')[termsChecks && setupChecks && configExists && checkDB ? 'enable': 'disable']();
146         this.getNodeById('ApplicationGridPanel')[termsChecks && setupChecks && configExists && checkDB && !setupRequired ? 'enable': 'disable']();
147         this.getNodeById('EmailPanel')[termsChecks && setupChecks && configExists && checkDB && !setupRequired ? 'enable': 'disable']();
148     },
149     
150     setNodeIcon: function (nodeId, success) {
151         var node = this.getNodeById(nodeId);
152         var iconCls = success ? 'setup_checks_success' : 'setup_checks_fail';
153         if (node.rendered) {
154             var iconEl = Ext.get(node.ui.iconNode);
155             iconEl.removeClass('setup_checks_success');
156             iconEl.removeClass('setup_checks_fail');
157             iconEl.addClass(iconCls);
158         } else {
159             envNode.iconCls = iconCls;
160         }
161     }
162 });
163
164 Ext.ns('Tine', 'Tine.Setup', 'Tine.Setup.Model');
165
166 /**
167  * @namespace   Tine.Setup.Model
168  * @class       Tine.Setup.Model.Application
169  * @extends     Tine.Tinebase.data.Record
170  * 
171  * Application Record Definition
172  */ 
173 Tine.Setup.Model.Application = Tine.Tinebase.data.Record.create([
174     { name: 'id'              },
175     { name: 'name'            },
176     { name: 'status'          },
177     { name: 'order'           },
178     { name: 'version'         },
179     { name: 'current_version' },
180     { name: 'install_status'  },
181     { name: 'depends'         }
182 ], {
183     appName: 'Setup',
184     modelName: 'Application',
185     idProperty: 'name',
186     titleProperty: 'name',
187     // ngettext('Application', 'Applications', n); gettext('Application');
188     recordName: 'Application',
189     recordsName: 'Applications'
190 });
191
192 /**
193  * @namespace   Tine.Setup
194  * @class       Tine.Setup.ApplicationBackend
195  * @extends     Tine.Tinebase.data.RecordProxy
196  * 
197  * default application backend
198  */ 
199 Tine.Setup.ApplicationBackend = new Tine.Tinebase.data.RecordProxy({
200     appName: 'Setup',
201     modelName: 'Application',
202     recordClass: Tine.Setup.Model.Application
203 });
204
205 /**
206  * @namespace   Tine.Setup.Model
207  * @class       Tine.Setup.Model.EnvCheck
208  * @extends     Ext.data.Record
209  * 
210  * env check Record Definition
211  */ 
212 Tine.Setup.Model.EnvCheck = Ext.data.Record.create([
213     {name: 'key'},
214     {name: 'value'},
215     {name: 'message'}
216 ]);