0011666: Some fixes for Expressodriver
[tine20] / tine20 / Expressodriver / js / CredentialsDialog.js
1 /*
2  * Tine 2.0
3  *
4  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
5  * @author      Marcelo Teixeira <marcelo.teixeira@serpro.gov.br>
6  * @copyright   Copyright (c) 2015 Metaways Infosystems GmbH (http://www.metaways.de)
7  *
8  */
9
10  Ext.ns('Tine.Expressodriver');
11
12  /**
13   * @namespace  Tine.Expressodriver
14   * @class      Tine.Expressodriver.CredentialsDialog
15   * @extends    Ext.Window
16   */
17 Tine.Expressodriver.CredentialsDialog = Ext.extend(Ext.Window, {
18
19     id: 'expressodriverCredentials_window',
20     closeAction: 'close',
21     modal: true,
22     width: 350,
23     height: 230,
24     minWidth: 350,
25     minHeight: 230,
26     layout: 'fit',
27     plain: true,
28     title: null,
29     adapterName: '',
30
31     initComponent: function() {
32         var app = Tine.Tinebase.appMgr.get('Expressodriver');
33         this.title = (this.title !== null) ? this.title : app.i18n._('Credentials for Expressodriver');
34
35         this.items = new Ext.FormPanel({
36             bodyStyle: 'padding:5px;',
37             buttonAlign: 'right',
38             labelAlign: 'top',
39             anchor:'100%',
40             id: 'expressodriverCredentialsPanel',
41             defaults: {
42                 xtype: 'textfield',
43                 inputType: 'password',
44                 anchor: '100%',
45                 allowBlank: false
46             },
47             items: [{
48                 id: 'password',
49                 fieldLabel: _('Password'),
50                 name:'password'
51             },{
52                 id: 'passwordSecondTime',
53                 fieldLabel: _('Repeat Password'),
54                 name:'passwordSecondTime'
55             }],
56             buttons: [{
57                 text: _('Cancel'),
58                 iconCls: 'action_cancel',
59                 handler: function() {
60                     Ext.getCmp('expressodriverCredentials_window').close();
61                 }
62             }, {
63                 text: _('Ok'),
64                 iconCls: 'action_saveAndClose',
65                 handler: function() {
66                     var form = Ext.getCmp('expressodriverCredentialsPanel').getForm();
67                     var values;
68                     if (form.isValid()) {
69                         values = form.getValues();
70                         if (values.password == values.passwordSecondTime) {
71                             Ext.Ajax.request({
72                                 waitTitle: _('Please Wait!'),
73                                 waitMsg: _('changing password...'),
74                                 params: {
75                                     method: 'Expressodriver.setCredentials',
76                                     adapterName: Ext.getCmp('expressodriverCredentials_window').adapterName,
77                                     password: values.password
78                                 },
79                                 success: function(_result, _request){
80                                     var response = Ext.util.JSON.decode(_result.responseText);
81                                     if (response.success) {
82                                         Ext.getCmp('expressodriverCredentials_window').close();
83                                         Ext.MessageBox.show({
84                                             title: _('Success'),
85                                             msg: app.i18n._('Authentication success.'),
86                                             buttons: Ext.MessageBox.OK,
87                                             icon: Ext.MessageBox.INFO
88                                         });
89
90                                         // reload grid and treepanel
91                                         app.getMainScreen().getCenterPanel().grid.getStore().reload();
92
93                                         var treeNode = app.getMainScreen().getWestPanel().getContainerTreePanel();
94                                         var selected = treeNode.getSelectionModel().getSelectedNode();
95                                         if (selected) {
96                                             selected.reload();
97                                         }
98
99                                     } else {
100                                         Ext.MessageBox.show({
101                                             title: app.i18n._('Credentials error'),
102                                             msg: app.i18n._(response.errorMessage),
103                                             buttons: Ext.MessageBox.OK,
104                                             icon: Ext.MessageBox.ERROR
105                                         });
106                                     }
107                                 }
108                             });
109                         } else {
110                             Ext.MessageBox.show({
111                                 title: _('Failure'),
112                                 msg: _('The new passwords mismatch, please correct them.'),
113                                 buttons: Ext.MessageBox.OK,
114                                 icon: Ext.MessageBox.ERROR
115                             });
116                         }
117                     }
118                 }
119             }]
120         });
121
122         Tine.Expressodriver.CredentialsDialog.superclass.initComponent.call(this);
123     }
124 });