83880af674e327c53a0fe489021b530b59f2ff36
[Packages/TYPO3.CMS.git] / typo3 / sysext / em / res / js / em_settings.js
1 /**
2 * ExtJS for the extension manager.
3 *
4 *
5 * @author Steffen Kamper <info@sk-typo3.de>
6 * @package TYPO3
7 * @subpackage extension manager
8 * @version $Id: $
9 */
10
11 Ext.ns('TYPO3.EM');
12
13 TYPO3.EM.Settings = Ext.extend(Ext.FormPanel, {
14 border: false,
15 labelWidth: 240,
16 bodyStyle: 'padding:5px 5px 0',
17
18 initComponent: function() {
19
20 this.repositoryStore = new Ext.data.DirectStore({
21 storeId: 'repositoriessettings',
22 directFn: TYPO3.EM.ExtDirect.getRepositories,
23 idProperty: 'uid',
24 root: 'data',
25 totalProperty: 'length',
26 fields : ['title', 'uid', 'updated', 'count', 'selected', 'description', 'wsdl_url', 'mirror_url'],
27 paramsAsHash: true,
28 listeners: {
29 load: function(store) {
30 if (this.isLoaded) {
31 record = store.getById(TYPO3.settings.EM.selectedRepository).data;
32 this.repositoryInfo(record);
33 }
34 },
35 scope: this
36 }
37 });
38
39 this.repSettingsCombo = new Ext.form.ComboBox({
40 id: 'repSettingsCombo',
41 mode: 'local',
42 width: 300,
43 triggerAction: 'all',
44 forceSelection: true,
45 editable: false,
46 name: 'selectedRepository',
47 hiddenName: 'selectedRepository',
48 displayField: 'title',
49 valueField: 'uid',
50 store: this.repositoryStore,
51 fieldLabel: TYPO3.lang.repository_select,
52 listeners: {
53 scope: this,
54 select: function(comboBox, newValue, oldValue) {
55 TYPO3.settings.EM.selectedRepository = newValue.data.uid;
56 this.repositoryInfo(newValue.data);
57 TYPO3.EM.ExtDirect.saveSetting('selectedRepository', newValue.data.uid);
58 }
59 }
60 });
61
62 var mirrorData = TYPO3.settings.EM.extMirrors;
63
64 this.mirrorStore = new Ext.data.DirectStore({
65 storeId: 'em-mirror-store',
66 directFn: TYPO3.EM.ExtDirect.getMirrors,
67 idProperty: 'host',
68 root: 'data',
69 totalProperty: 'length',
70 fields: [
71 {name : 'title'},
72 {name : 'country'},
73 {name : 'host'},
74 {name : 'path'},
75 {name : 'sponsor'},
76 {name : 'link'},
77 {name : 'logo'}
78 ]
79 });
80
81
82
83 var mirrorSm = new Ext.grid.CheckboxSelectionModel({
84 singleSelect: true,
85 header: '',
86 listeners: {
87 'selectionchange': function(selectionModel) {
88 var selectedMirror = '';
89 if (selectionModel.getSelected()) {
90 var sel = selectionModel.getSelected();
91 selectedMirror = sel.data.host;
92 this.getForm().setValues({selectedMirror: selectedMirror});
93 } else {
94 this.getForm().setValues({selectedMirror: ''});
95 }
96 TYPO3.EM.ExtDirect.saveSetting('selectedMirror', selectedMirror);
97 },
98 scope: this
99 }
100 });
101
102 var mirrorCm = new Ext.grid.ColumnModel([
103 mirrorSm,
104 {
105 id: 'mirror-title',
106 header: TYPO3.lang.mirror,
107 width: 200,
108 sortable: false,
109 menuDisabled: true,
110 fixed: true,
111 dataIndex: 'title',
112 hidable: false
113 },{
114 id: 'mirror-country',
115 header: TYPO3.lang.mirror_country,
116 width: 80,
117 sortable: false,
118 menuDisabled: true,
119 fixed: true,
120 dataIndex: 'country',
121 hidable: false
122 },{
123 id: 'mirror-host',
124 header: TYPO3.lang.mirror_url,
125 width: 180,
126 sortable: false,
127 menuDisabled: true,
128 fixed: true,
129 dataIndex: 'host',
130 hidable: false
131 },{
132 id: 'mirror-sponsor',
133 header: TYPO3.lang.mirror_sponsored_by,
134 width: 180,
135 sortable: false,
136 menuDisabled: true,
137 fixed: true,
138 dataIndex: 'sponsor',
139 hidable: false
140
141 },{
142 id: 'mirror-logo',
143 header: TYPO3.lang.mirror_logo_link,
144 width: 180,
145 sortable: false,
146 menuDisabled: true,
147 fixed: true,
148 dataIndex: 'logo',
149 hidable: false,
150 renderer: function(value, metaData, record, rowIndex, colIndex, store) {
151 if (value == '') {
152 return ''
153 } else {
154 return '<a href="' + record.data.link + '" title="' + record.data.sponsor + '" target="_blank"><img src="' + record.data.logo + '" alt="' + record.data.sponsor + '" title="' + record.data.sponsor + '" /></a>';
155 }
156 }
157 }
158 ]);
159
160 Ext.apply(this, {
161 isLoaded: false,
162 items: [{
163 layout: 'hbox',
164 align: 'stretchmax',
165 border: false,
166 id: 'hbox-settings',
167 bodyStyle: 'padding-top: 10px;overflow: auto;',
168 items: [{
169 width: 450,
170 border: false,
171 labelWidth: 100,
172 items: [{
173 xtype:'fieldset',
174 title: TYPO3.lang.repositories,
175 collapsible: false,
176 defaultType: 'textfield',
177 height: 246,
178 items :[
179 this.repSettingsCombo,
180 {
181 title: TYPO3.lang.repository_details,
182 xtype: 'panel',
183 id: 'repDescriptionDisplay',
184 record: null,
185 labelWidth: 0,
186 width: 420,
187 html: '',
188 bodyStyle: 'padding: 10px;',
189 buttons: [{
190 text: TYPO3.lang.cmd_create,
191 iconCls: 'x-btn-new',
192 ref: '../newRep',
193 handler: function() {
194 var win = new TYPO3.EM.EditRepository({
195 isCreate: true,
196 title: TYPO3.lang.repository_create
197 }).show();
198 },
199 scope: this
200 }, ' ', {
201 text: TYPO3.lang.cmd_edit,
202 iconCls: 'x-btn-edit',
203 ref: '../editRep',
204 handler: function() {
205 var record = this.repositoryStore.getById(this.repSettingsCombo.getValue());
206 var win = new TYPO3.EM.EditRepository({
207 title: String.format(TYPO3.lang.repository_edit, record.data.title)
208 });
209 win.getComponent('repForm').getForm().setValues({
210 'title': record.data.title,
211 'description': record.data.description,
212 'wsdl_url': record.data.wsdl_url,
213 'mirror_url': record.data.mirror_url,
214 'rep': record.data.uid
215 });
216 win.show();
217 },
218 scope: this
219 }, ' ', {
220 text: TYPO3.lang.cmd_delete,
221 iconCls: 'x-btn-delete',
222 ref: '../deleteRep',
223 handler: function() {
224 var record = this.repositoryStore.getById(this.repSettingsCombo.getValue());
225 var wait = Ext.MessageBox.wait(TYPO3.lang.repository_deleting, record.data.title);
226 TYPO3.EM.ExtDirect.deleteRepository(record.data.uid, function(response) {
227 if (response.success !== true) {
228 TYPO3.Flashmessage.display(TYPO3.Severity.error, 'Invalid', action.result.error, 5);
229 } else {
230 TYPO3.Flashmessage.display(TYPO3.Severity.ok, TYPO3.lang.repository_delete, String.format(TYPO3.lang.repository_deleted, record.data.title), 5);
231 TYPO3.settings.EM.selectedRepository = 1;
232 this.repSettingsCombo.setValue(1);
233 this.repositoryStore.load({
234 callback: function() {
235 this.repSettingsCombo.fireEvent('select', this.repSettingsCombo, this.repositoryStore.getById(1), 0);
236 },
237 scope: this
238 });
239
240 }
241 wait.hide();
242 }, this);
243 },
244 scope: this
245 }]
246 }]
247 },
248 {
249 xtype:'fieldset',
250 title: TYPO3.lang.user_settings,
251 collapsible: false,
252 defaults: {},
253 defaultType: 'textfield',
254 items :[
255 {
256 fieldLabel: TYPO3.lang.enter_repository_username,
257 name: 'fe_u'
258 }, {
259 fieldLabel: TYPO3.lang.enter_repository_password,
260 inputType: 'password',
261 name: 'fe_p'
262 },
263 new Ext.Container({
264 html: '<b>' + TYPO3.lang.notice + '</b> ' + TYPO3.lang.repository_password_info,
265 xtype: 'displayfield',
266 labelWidth: 1
267 })
268 ],
269 buttons: [
270 {
271 text: TYPO3.lang.cmd_save,
272 iconCls: 'x-btn-save',
273 handler: function() {
274 this.saveFormHandler();
275 },
276 scope: this
277 }
278 ]
279 }]
280 }, {
281 flex: 1,
282 border: false,
283 xtype:'fieldset',
284 title: TYPO3.lang.mirror_selection,
285 collapsible: false,
286 autoHeight:true,
287 items :[{
288 anchor: '100% 100%',
289 xtype: 'grid',
290 id: 'em-mirrorgrid',
291 stripeRows: true,
292 store: this.mirrorStore,
293 cm: mirrorCm,
294 sm: mirrorSm,
295 autoHeight: true
296 },{
297 xtype: 'hidden',
298 name: 'selectedMirror'
299 }]
300 }]
301 }]
302 });
303
304
305 // call parent
306 TYPO3.EM.Settings.superclass.initComponent.apply(this, arguments);
307
308 } ,
309
310 saveFormHandler: function() {
311 this.getForm().submit({
312 waitMsg : TYPO3.lang.action_saving_settings,
313 success: function(form, action) {
314 TYPO3.Flashmessage.display(TYPO3.Severity.information, TYPO3.lang.menu_settings, TYPO3.lang.settingsSaved, 5);
315 TYPO3.settings.EM.hasCredentials = (action.result.data.fe_u !== '' && action.result.data.fe_p !== '');
316 // enable/disable user extension tab
317 if (TYPO3.settings.EM.hasCredentials) {
318 Ext.getCmp('em-main').items.items[4].enable();
319 } else {
320 Ext.getCmp('em-main').items.items[4].disable();
321 }
322 },
323 failure: function(form, action) {
324 if (action.failureType === Ext.form.Action.CONNECT_FAILURE) {
325 TYPO3.Flashmessage.display(TYPO3.Severity.error, 'Error',
326 'Status:'+action.response.status+': '+
327 action.response.statusText, 5);
328 }
329 if (action.failureType === Ext.form.Action.SERVER_INVALID){
330 // server responded with success = false
331 TYPO3.Flashmessage.display(TYPO3.Severity.error, 'Invalid', action.result.errormsg, 5);
332 }
333 }
334
335 });
336 },
337
338 repositoryInfo: function(record) {
339 var panel = Ext.getCmp('repDescriptionDisplay');
340 panel.update([
341 '<h1 class="h1Panel">', record.title, '</h1>',
342 '<p class="panelDescription">', record.description, '</p>',
343 '<p><b>', TYPO3.lang.mirror_url_long, ': ', '</b>', record.mirror_url, '<br />',
344 '<b>', TYPO3.lang.wsdlUrl, ': ', '</b>', record.wsdl_url, '</p>'
345 ].join(''));
346 if (record.uid == 1) {
347 panel.editRep.disable();
348 panel.deleteRep.disable();
349 } else {
350 panel.editRep.enable();
351 panel.deleteRep.enable();
352 }
353 this.mirrorStore.load({
354 params: {
355 repository: this.repSettingsCombo.getValue()
356 },
357 callback: function() {
358 var mirror = this.getForm().getValues().selectedMirror;
359 if (mirror) {
360 var record = this.mirrorStore.getAt(this.mirrorStore.find('host', mirror));
361 Ext.getCmp('em-mirrorgrid').getSelectionModel().selectRecords([record]);
362 } else {
363 Ext.getCmp('em-mirrorgrid').getSelectionModel().selectFirstRow();
364 }
365 },
366 scope: this
367 });
368
369 },
370
371
372 onRender:function() {
373
374 // call parent
375 TYPO3.EM.Settings.superclass.onRender.apply(this, arguments);
376
377 Ext.apply(this.getForm(),{
378 api: {
379 load: TYPO3.EM.ExtDirect.settingsFormLoad,
380 submit: TYPO3.EM.ExtDirect.settingsFormSubmit
381 },
382 paramsAsHash: false
383 });
384
385 this.repositoryStore.load({
386 callback: function() {
387 this.getForm().load({
388 success: function(form, response) {
389 record = this.repositoryStore.getById(TYPO3.settings.EM.selectedRepository);
390 if (record) {
391 this.repSettingsCombo.setValue(TYPO3.settings.EM.selectedRepository);
392 this.repositoryInfo(record.data);
393 this.isLoaded = true;
394 }
395 },
396 scope: this
397 });
398 },
399 scope: this
400 });
401
402 }
403
404
405
406
407 });
408
409 // register xtype
410 Ext.reg('extsettings', TYPO3.EM.Settings);
411
412 // window with repository edit/create form
413 TYPO3.EM.EditRepository = Ext.extend(Ext.Window, {
414 isCreate: false,
415 width: 500,
416 height: 260,
417 layout: 'fit',
418 frame: true,
419 resizable: false,
420 modal: true,
421 caller: null,
422 initComponent : function() {
423 var form = new Ext.form.FormPanel({
424 //baseCls: 'x-plain',
425 border: false,
426 labelWidth: 80,
427 itemId: 'repForm',
428 bodyStyle:'padding:5px 5px 0',
429 width: 350,
430 defaults: {width: 380},
431 defaultType: 'textfield',
432 api: {
433 submit: TYPO3.EM.ExtDirect.repositoryEditFormSubmit
434 },
435 paramsAsHash: false,
436 items: [{
437 itemId: 'title',
438 fieldLabel: TYPO3.lang.extInfoArray_title,
439 name: 'title',
440 allowBlank: false
441 }, {
442 itemId: 'description',
443 fieldLabel: TYPO3.lang.extInfoArray_description,
444 xtype: 'textarea',
445 name: 'description',
446 height: 100
447 }, {
448 itemId: 'mirror_url',
449 fieldLabel: TYPO3.lang.mirror_url_long,
450 name: 'mirror_url'
451 }, {
452 itemId: 'wsdl_url',
453 fieldLabel: TYPO3.lang.wsdlUrl,
454 name: 'wsdl_url',
455 allowBlank: false
456 }, {
457 xtype: 'hidden',
458 name: 'create',
459 value: this.isCreate ? 1 : 0
460 }, {
461 xtype: 'hidden',
462 name: 'rep',
463 value: 0
464 }]
465 });
466
467 Ext.apply(this, {
468 items: form,
469 buttons : [{
470 text: TYPO3.lang.cmd_create,
471 iconCls: 'x-btn-save',
472 handler: function() {
473 this.repositoryUpdate(form, 1);
474 },
475 hidden: !this.isCreate,
476 scope: this
477 }, {
478 text: TYPO3.lang.cmd_update,
479 iconCls: 'x-btn-save',
480 handler: function() {
481 this.repositoryUpdate(form, 0);
482 },
483 hidden: this.isCreate,
484 scope: this
485 }, {
486 text: TYPO3.lang.cmd_cancel,
487 iconCls: 'x-btn-cancel',
488 handler: function() {
489 this.close();
490 },
491 scope: this
492 }]
493 });
494 TYPO3.EM.EditRepository.superclass.initComponent.call(this);
495 },
496
497 repositoryUpdate: function(form, type) {
498 form.getForm().submit({
499 waitMsg : type === 0 ? TYPO3.lang.repository_saving : TYPO3.lang.repository_creating,
500 success: function(form, action) {
501 TYPO3.Flashmessage.display(TYPO3.Severity.information, TYPO3.lang.repository, type == 0
502 ? String.format(TYPO3.lang.repository_saved, action.result.params.title)
503 : String.format(TYPO3.lang.repository_saved, action.result.params.title)
504 , 5);
505 Ext.StoreMgr.get('repositoriessettings').load();
506 this.close();
507 },
508 failure: function(form, action) {
509 if (action.failureType === Ext.form.Action.CONNECT_FAILURE) {
510 TYPO3.Flashmessage.display(TYPO3.Severity.error, TYPO3.lang.msg_error,
511 TYPO3.lang.msg_status + ':' + action.response.status + ': ' +
512 action.response.statusText, 5);
513 }
514 if (action.failureType === Ext.form.Action.SERVER_INVALID){
515 // server responded with success = false
516 TYPO3.Flashmessage.display(TYPO3.Severity.error, TYPO3.lang.msg_invalid, action.result.errormsg, 15);
517 }
518 },
519 scope: this
520 });
521 }
522
523 });