Blame view

js/app/views/FeedbackUI.js 6.36 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
/**
  * Project      :  AMDA-NG
  * Name         : FeedbackUI.js
  * @plugin 	  amdaUI.FeedbackUI
  * @extends 	  Ext.panel.Panel
  * @brief		 Feedback view
  * @author Benjamin
dcd07176   Elena.Budnik   Feedback manager
8
  * @version $Id: FeedbackUI.js 2031 2014-01-22 11:28:34Z elena $      
16035364   Benjamin Renard   First commit
9
10
11
  */

Ext.define('amdaUI.FeedbackUI', {
dcd07176   Elena.Budnik   Feedback manager
12
13
14
15
	extend: 'Ext.form.Panel',
	alias: 'widget.panelFeedback',

	constructor: function(config) {			
16035364   Benjamin Renard   First commit
16
17
18
19
		this.init(config);
		this.callParent(arguments);
	},
    
dcd07176   Elena.Budnik   Feedback manager
20
21
22
23
24
25
	getInfoMsg : function()
	{
		return '<h3>Welcome,</h3>' +
			'You have problems/comments</br>'+
			'Please select an item[s] from a list below and describe the problem...';
	},
16035364   Benjamin Renard   First commit
26
  	
dcd07176   Elena.Budnik   Feedback manager
27
28
29
30
	getBrowserInfo : function()
	{
		return Ext.browser.name+' - '+Ext.browser.engineName+' - '+Ext.browser.engineVersion;
	},
16035364   Benjamin Renard   First commit
31
    
dcd07176   Elena.Budnik   Feedback manager
32
33
34
35
	getUser : function()
	{
		return sessionID;
	},
16035364   Benjamin Renard   First commit
36
    
dcd07176   Elena.Budnik   Feedback manager
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
	getInterfaceList : function()
	{
		return [
			['General','General'],
			['Plot_Data','Plot Data'],
			['Data_mining','Data mining'],
			['My_Parameters','Parameters'],
			['My_Time_Tables','Time Tables'],
			['My_Catalogs','Catalogs'],
			['Statistics', 'Statistics'],
			['Download_Data','Download Data'],
			['Upload_Data','Upload Data'],
			['Interoperability','Interoperability'],
			['Add_External_Data','External Data']
		];
	},

	onSendFinish : function(result, e){	
		var t = e.getTransaction();
16035364   Benjamin Renard   First commit
56
57
		if (e.status) 
		{	
dcd07176   Elena.Budnik   Feedback manager
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
			if (result && result == 'none')
			{
				// SUCCESS  
				var win = myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.feedback.id);
				Ext.MessageBox.show({
					title: 'Feedback sent',
					msg: 'Thanks for your feedback',
					buttons: Ext.MessageBox.OK,
					icon: Ext.MessageBox.INFO,
					fn: function (btn){
						win.close();
					}
				});
			}
			else
			{
				//ERROR
				var msgErr = 'Unknown error';
				switch (result)
				{
					case 'err_user' :
						msgErr = 'User not defined';
						break;
					case 'err_file' :
						msgErr = 'Feedback file error';
						break;	
				}
				Ext.Msg.show({title:'Error', msg: msgErr, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
			}
16035364   Benjamin Renard   First commit
87
88
89
		}
		else
		{
dcd07176   Elena.Budnik   Feedback manager
90
91
			// FAILURE
			Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
16035364   Benjamin Renard   First commit
92
		}   
dcd07176   Elena.Budnik   Feedback manager
93
	},
16035364   Benjamin Renard   First commit
94
    
dcd07176   Elena.Budnik   Feedback manager
95
96
97
98
99
100
101
102
103
	onSendIssue : function(b,e){
		//get links to components
		var fieldset = this.getComponent('feedback_fieldset');
		var fieldsubject = fieldset.getComponent('subject_checkboxgroup');
		var fielduser = fieldset.getComponent('user_displayfield');
		var fieldbrowser = fieldset.getComponent('browser_displayfield');
		var fieldattach = fieldset.getComponent('attach_filefield');
		var fieldinterface = fieldset.getComponent('interface_combo');
		var fielddes = fieldset.getComponent('desc_textarea');
16035364   Benjamin Renard   First commit
104
      
dcd07176   Elena.Budnik   Feedback manager
105
106
107
108
109
110
		//test if some fields are valid
		if (!fieldsubject.isValid() || !fielddes.isValid())
			{
				Ext.Msg.show({title:'Error', msg: 'Some field are required', icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
				return;
			}
16035364   Benjamin Renard   First commit
111
	  
dcd07176   Elena.Budnik   Feedback manager
112
113
114
115
116
117
118
119
120
		//generate subject message (a list of all checked boxes)
		var subjectMsg = '';
		fieldsubject.items.each(function (item){
			if (!item.checked)
				return;
			if (subjectMsg != '')
				subjectMsg += ' - ';
			subjectMsg += item.boxLabel;
		},this);
16035364   Benjamin Renard   First commit
121
	  
dcd07176   Elena.Budnik   Feedback manager
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
		//make the object to send
		var feed = {user : fielduser.getValue(), 
				interface : fieldinterface.getValue(), 
				subject : subjectMsg, 
				userText : fielddes.getValue(), 
				userAgent : fieldbrowser.getValue(),
				attach : fieldattach.getValue()};
		
		if (feed.attach != '')
		{
			this.submit({
				scope : this,
				url: 'php/uploadFile.php',
				waitMsg: 'Uploading your file...',
				success: function(form, o)
				{
					feed.attach = o.result.file;
					//call action
					AmdaAction.sendFeedback(feed,this.onSendFinish,this);
				},
				failure: function(form, o) 
				{
					Ext.Msg.show( {
						title : 'Feedback - Upload attachment',
						msg : 'Error '+o.result.error,
						modal : true,
						icon : Ext.Msg.ERROR,
						buttons : Ext.Msg.OK
					});
16035364   Benjamin Renard   First commit
151
				}
dcd07176   Elena.Budnik   Feedback manager
152
153
154
155
156
157
			});
		}
		else
			//call action
			AmdaAction.sendFeedback(feed,this.onSendFinish,this);
	},
16035364   Benjamin Renard   First commit
158
    
dcd07176   Elena.Budnik   Feedback manager
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
	
	init : function(config)	
	{
		var myConf = {
			layout: 'fit',
			bodyStyle: { background: '#ddecfe'},
			items : [{
				xtype: 'fieldset',
				itemId: 'feedback_fieldset',
				layout: 'anchor',
				anchor: '100%',
				items : [
					{
						xtype: 'displayfield',
						itemId: 'info_displayfield',
						name: 'information',
						height : 80,
						fieldLabel: '',
						anchor: '100%',
						value: this.getInfoMsg()
					},
					{
						xtype: 'checkboxgroup',
						itemId: 'subject_checkboxgroup',
						fieldLabel: 'Subject',
						anchor: '100%',
						columns : 3,
						vertical: true,
						allowBlank: false,
						items: [
							{boxLabel: 'Bug', inputValue: 'bug', checked: true},
							{boxLabel: 'Question', inputValue: 'question'},
							{boxLabel: 'Data', inputValue: 'data'},
							{boxLabel: 'Comment', inputValue: 'comment'},
							{boxLabel: 'Other', inputValue: 'other'}
						]
					},
					{
						xtype: 'displayfield',
						itemId: 'user_displayfield',
						fieldLabel: 'User',
						anchor: '100%',
						name: 'user',
						value: this.getUser()
					},
					{
						xtype: 'displayfield',
						itemId: 'browser_displayfield',
						fieldLabel: 'Browser',
						anchor: '100%',
						name: 'browser',
						value: this.getBrowserInfo()
					},
					{
						xtype: 'filefield',
						itemId: 'attach_filefield',
						anchor: '100%',
						name: 'attachment',
						fieldLabel: 'Attachment',
						buttonText: 'Select File...',
						emptyText : 'none'
					},
					{
						xtype: 'combo',
						itemId: 'interface_combo',
						fieldLabel: 'Interface',
						name: 'interface',
						store: this.getInterfaceList(),
						value: 'General',
						forceSelection: true,
						anchor: '100%',
						autoSelect: true,
						allowBlanck: false
					},
					{
						xtype : 'textareafield',
						itemId: 'desc_textarea',
						anchor: '100%',
						height : 200,
						name: 'description',
						fieldLabel: 'Description',
						allowBlank: false
					},
					{  
						xtype : 'hiddenfield',
						name: 'MAX_FILE_SIZE',
						value: '3000000' // 3MB				      
					}
				]
			}],
			dockedItems: [{
				xtype: 'toolbar', 
				dock: 'bottom',
				items: [
					'->',
					{
						iconCls: 'icon-feedback',
						text: 'Send',
						scope: this,
						tooltip: 'Send feeback',
						handler: this.onSendIssue
					}					
				]	          
			}]
		}
		Ext.apply (this , Ext.apply (arguments, myConf));
	}
16035364   Benjamin Renard   First commit
266
});