Merge branch '2014.11-develop' into 2014.09
[tine20] / tine20 / Felamimail / js / AccountEditDialog.js
1 /*
2  * Tine 2.0
3  * 
4  * @package     Felamimail
5  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
6  * @author      Philipp Schüle <p.schuele@metaways.de>
7  * @copyright   Copyright (c) 2009-2012 Metaways Infosystems GmbH (http://www.metaways.de)
8  *
9  */
10  
11 Ext.namespace('Tine.Felamimail');
12
13 /**
14  * @namespace   Tine.Felamimail
15  * @class       Tine.Felamimail.AccountEditDialog
16  * @extends     Tine.widgets.dialog.EditDialog
17  * 
18  * <p>Account Edit Dialog</p>
19  * <p>
20  * </p>
21  * 
22  * @author      Philipp Schuele <p.schuele@metaways.de>
23  * @copyright   Copyright (c) 2009 Metaways Infosystems GmbH (http://www.metaways.de)
24  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
25  * 
26  * @param       {Object} config
27  * @constructor
28  * Create a new Tine.Felamimail.AccountEditDialog
29  * 
30  */
31 Tine.Felamimail.AccountEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
32     
33     /**
34      * @private
35      */
36     windowNamePrefix: 'AccountEditWindow_',
37     appName: 'Felamimail',
38     recordClass: Tine.Felamimail.Model.Account,
39     recordProxy: Tine.Felamimail.accountBackend,
40     loadRecord: false,
41     tbarItems: [],
42     evalGrants: false,
43
44     /**
45      * overwrite update toolbars function (we don't have record grants yet)
46      * @private
47      */
48     updateToolbars: function() {
49
50     },
51     
52     /**
53      * executed after record got updated from proxy
54      * 
55      * -> only allow to change some of the fields if it is a system account
56      */
57     onRecordLoad: function() {
58         Tine.Felamimail.AccountEditDialog.superclass.onRecordLoad.call(this);
59         
60         // if account type == system disable most of the input fields
61         if (this.record.get('type') == 'system') {
62             this.getForm().items.each(function(item) {
63                 // only enable some fields
64                 switch(item.name) {
65                     case 'signature':
66                     case 'signature_position':
67                     case 'display_format':
68                         break;
69                     default:
70                         item.setDisabled(true);
71                 }
72             }, this);
73         }
74         if (! this.copyRecord && ! this.record.id && this.window) {
75             this.window.setTitle(this.app.i18n._('Add New Account'));
76         }
77     },    
78     
79     /**
80      * returns dialog
81      * 
82      * NOTE: when this method gets called, all initalisation is done.
83      * @private
84      */
85     getFormItems: function() {
86
87         this.signatureEditor = new Ext.form.HtmlEditor({
88             fieldLabel: this.app.i18n._('Signature'),
89             name: 'signature',
90             autoHeight: true,
91             getDocMarkup: function(){
92                 var markup = '<span id="felamimail\-body\-signature">'
93                     + '</span>';
94                 return markup;
95             },
96             plugins: [
97                 new Ext.ux.form.HtmlEditor.RemoveFormat()
98             ]
99         });
100         
101         var commonFormDefaults = {
102             xtype: 'textfield',
103             anchor: '100%',
104             labelSeparator: '',
105             maxLength: 256,
106             columnWidth: 1
107         };
108         
109         return {
110             xtype: 'tabpanel',
111             deferredRender: false,
112             border: false,
113             activeTab: 0,
114             items: [{
115                 title: this.app.i18n._('Account'),
116                 autoScroll: true,
117                 border: false,
118                 frame: true,
119                 xtype: 'columnform',
120                 formDefaults: commonFormDefaults,
121                 items: [[{
122                     fieldLabel: this.app.i18n._('Account Name'),
123                     name: 'name',
124                     allowBlank: false
125                 }, {
126                     fieldLabel: this.app.i18n._('User Email'),
127                     name: 'email',
128                     allowBlank: false,
129                     vtype: 'email'
130                 }, {
131                     fieldLabel: this.app.i18n._('User Name (From)'),
132                     name: 'from'
133                 }, {
134                     fieldLabel: this.app.i18n._('Organization'),
135                     name: 'organization'
136                 }, this.signatureEditor,
137                 {
138                     fieldLabel: this.app.i18n._('Signature position'),
139                     name: 'signature_position',
140                     typeAhead     : false,
141                     triggerAction : 'all',
142                     lazyRender    : true,
143                     editable      : false,
144                     mode          : 'local',
145                     forceSelection: true,
146                     value: 'below',
147                     xtype: 'combo',
148                     store: [
149                         ['above', this.app.i18n._('Above the quote')],
150                         ['below',  this.app.i18n._('Below the quote')]
151                     ]
152                 }
153                 ]]
154             }, {
155                 title: this.app.i18n._('IMAP'),
156                 autoScroll: true,
157                 border: false,
158                 frame: true,
159                 xtype: 'columnform',
160                 formDefaults: commonFormDefaults,
161                 items: [[{
162                     fieldLabel: this.app.i18n._('Host'),
163                     name: 'host',
164                     allowBlank: false
165                 }, {
166                     fieldLabel: this.app.i18n._('Port (Default: 143 / SSL: 993)'),
167                     name: 'port',
168                     allowBlank: false,
169                     maxLength: 5,
170                     xtype: 'numberfield'
171                 }, {
172                     fieldLabel: this.app.i18n._('Secure Connection'),
173                     name: 'ssl',
174                     typeAhead     : false,
175                     triggerAction : 'all',
176                     lazyRender    : true,
177                     editable      : false,
178                     mode          : 'local',
179                     forceSelection: true,
180                     value: 'none',
181                     xtype: 'combo',
182                     store: [
183                         ['none', this.app.i18n._('None')],
184                         ['tls',  this.app.i18n._('TLS')],
185                         ['ssl',  this.app.i18n._('SSL')]
186                     ]
187                 },{
188                     fieldLabel: this.app.i18n._('Username'),
189                     name: 'user',
190                     allowBlank: false
191                 }, {
192                     fieldLabel: this.app.i18n._('Password'),
193                     name: 'password',
194                     emptyText: 'password',
195                     inputType: 'password'
196                 }]]
197             }, {
198                 title: this.app.i18n._('SMTP'),
199                 autoScroll: true,
200                 border: false,
201                 frame: true,
202                 xtype: 'columnform',
203                 formDefaults: commonFormDefaults,
204                 items: [[ {
205                     fieldLabel: this.app.i18n._('Host'),
206                     name: 'smtp_hostname'
207                 }, {
208                     fieldLabel: this.app.i18n._('Port (Default: 25)'),
209                     name: 'smtp_port',
210                     maxLength: 5,
211                     xtype:'numberfield',
212                     allowBlank: false
213                 }, {
214                     fieldLabel: this.app.i18n._('Secure Connection'),
215                     name: 'smtp_ssl',
216                     typeAhead     : false,
217                     triggerAction : 'all',
218                     lazyRender    : true,
219                     editable      : false,
220                     mode          : 'local',
221                     value: 'none',
222                     xtype: 'combo',
223                     store: [
224                         ['none', this.app.i18n._('None')],
225                         ['tls',  this.app.i18n._('TLS')],
226                         ['ssl',  this.app.i18n._('SSL')]
227                     ]
228                 }, {
229                     fieldLabel: this.app.i18n._('Authentication'),
230                     name: 'smtp_auth',
231                     typeAhead     : false,
232                     triggerAction : 'all',
233                     lazyRender    : true,
234                     editable      : false,
235                     mode          : 'local',
236                     xtype: 'combo',
237                     value: 'login',
238                     store: [
239                         ['none',    this.app.i18n._('None')],
240                         ['login',   this.app.i18n._('Login')],
241                         ['plain',   this.app.i18n._('Plain')]
242                     ]
243                 },{
244                     fieldLabel: this.app.i18n._('Username (optional)'),
245                     name: 'smtp_user'
246                 }, {
247                     fieldLabel: this.app.i18n._('Password (optional)'),
248                     name: 'smtp_password',
249                     emptyText: 'password',
250                     inputType: 'password'
251                 }]]
252             }, {
253                 title: this.app.i18n._('Sieve'),
254                 autoScroll: true,
255                 border: false,
256                 frame: true,
257                 xtype: 'columnform',
258                 formDefaults: commonFormDefaults,
259                 items: [[{
260                     fieldLabel: this.app.i18n._('Host'),
261                     name: 'sieve_hostname',
262                     maxLength: 64
263                 }, {
264                     fieldLabel: this.app.i18n._('Port (Default: 2000)'),
265                     name: 'sieve_port',
266                     maxLength: 5,
267                     xtype:'numberfield'
268                 }, {
269                     fieldLabel: this.app.i18n._('Secure Connection'),
270                     name: 'sieve_ssl',
271                     typeAhead     : false,
272                     triggerAction : 'all',
273                     lazyRender    : true,
274                     editable      : false,
275                     mode          : 'local',
276                     value: 'none',
277                     xtype: 'combo',
278                     store: [
279                         ['none', this.app.i18n._('None')],
280                         ['tls',  this.app.i18n._('TLS')]
281                     ]
282                 }]]
283             }, {
284                 title: this.app.i18n._('Other Settings'),
285                 autoScroll: true,
286                 border: false,
287                 frame: true,
288                 xtype: 'columnform',
289                 formDefaults: commonFormDefaults,
290                 items: [[{
291                     fieldLabel: this.app.i18n._('Sent Folder Name'),
292                     name: 'sent_folder',
293                     xtype: 'felamimailfolderselect',
294                     account: this.record,
295                     maxLength: 64
296                 }, {
297                     fieldLabel: this.app.i18n._('Trash Folder Name'),
298                     name: 'trash_folder',
299                     xtype: 'felamimailfolderselect',
300                     account: this.record,
301                     maxLength: 64
302                 }, {
303                     fieldLabel: this.app.i18n._('Drafts Folder Name'),
304                     name: 'drafts_folder',
305                     xtype: 'felamimailfolderselect',
306                     account: this.record,
307                     maxLength: 64
308                 }, {
309                     fieldLabel: this.app.i18n._('Templates Folder Name'),
310                     name: 'templates_folder',
311                     xtype: 'felamimailfolderselect',
312                     account: this.record,
313                     maxLength: 64
314                 }, {
315                     fieldLabel: this.app.i18n._('Display Format'),
316                     name: 'display_format',
317                     typeAhead     : false,
318                     triggerAction : 'all',
319                     lazyRender    : true,
320                     editable      : false,
321                     mode          : 'local',
322                     forceSelection: true,
323                     value: 'html',
324                     xtype: 'combo',
325                     store: [
326                         ['html', this.app.i18n._('HTML')],
327                         ['plain',  this.app.i18n._('Plain Text')],
328                         ['content_type',  this.app.i18n._('Depending on content type (experimental)')]
329                     ]
330                 }]]
331             }]
332         };
333     },
334     
335     /**
336      * generic request exception handler
337      * 
338      * @param {Object} exception
339      */
340     onRequestFailed: function(exception) {
341         this.saving = false;
342         Tine.Felamimail.handleRequestException(exception);
343         this.loadMask.hide();
344     }    
345 });
346
347 /**
348  * Felamimail Account Edit Popup
349  * 
350  * @param   {Object} config
351  * @return  {Ext.ux.Window}
352  */
353  Tine.Felamimail.AccountEditDialog.openWindow = function (config) {
354     var window = Tine.WindowFactory.getWindow({
355         width: 580,
356         height: 500,
357         name: Tine.Felamimail.AccountEditDialog.prototype.windowNamePrefix + Ext.id(),
358         contentPanelConstructor: 'Tine.Felamimail.AccountEditDialog',
359         contentPanelConstructorConfig: config
360     });
361     return window;
362 };