88ab1f1ac1702249edafe69a37a974b1d137c47b
[Packages/TYPO3.CMS.git] / typo3 / sysext / em / res / js / em_repositorylist.js
1 /***************************************************************
2 * Copyright notice
3 *
4 * (c) 2010 Steffen Kamper <info@sk-typo3.de>
5 * All rights reserved
6 *
7 * This script is part of the TYPO3 project. The TYPO3 project is
8 * free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * The GNU General Public License can be found at
14 * http://www.gnu.org/copyleft/gpl.html.
15 *
16 * This script is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * This copyright notice MUST APPEAR in all copies of the script!
22 ***************************************************************/
23
24 /**
25 * ExtJS for the extension manager.
26 *
27 *
28 * @author Steffen Kamper <info@sk-typo3.de>
29 * @package TYPO3
30 * @subpackage extension manager
31 */
32 Ext.ns('TYPO3.EM', 'TYPO3.EM.GridColumns', 'TYPO3.EM.ExtDirect');
33
34 TYPO3.EM.RepositoryList = Ext.extend(Ext.grid.GridPanel, {
35 border:false,
36 stripeRows: true,
37 stateful: true,
38 stateId: 'RepositoryList',
39 stateEvents: ['columnmove', 'columnresize', 'sortchange', 'groupchange'],
40 bodyStyle: 'padding: 10px;',
41 showInstalledOnly: false,
42
43 expander: new Ext.ux.grid.RowPanelExpander({
44 id: 'RepositoryListExpander',
45 createExpandingRowPanelItems: function(record, rowIndex){
46 var panelItems = [
47 new Ext.TabPanel({
48 plain: true,
49 activeTab: 0,
50 defaults: {
51 autoHeight: true,
52 autoWidth: true
53 },
54 record: record,
55 items:[
56 {
57 title: TYPO3.l10n.localize('details_info'),
58 listeners: {
59 activate: function(panel) {
60 panel.update(TYPO3.EM.Layouts.remoteExtensionInfo().applyTemplate(panel.ownerCt.record.data));
61 }
62 }
63 }
64 ]
65 })
66 ];
67 return panelItems;
68 }
69 }),
70
71 initComponent:function() {
72 this.repositoryListStore = new Ext.data.DirectStore({
73 storeId: 'repositoryliststore',
74 directFn: TYPO3.EM.ExtDirect.getRemoteExtensionList,
75 idProperty: 'extkey',
76 root: 'data',
77 totalProperty: 'length',
78 fields:[
79 {name:'install'},
80 {name:'title'},
81 {name:'extkey'},
82 {name:'category', type: 'int'},
83 {name:'version'},
84 {name:'alldownloadcounter', type: 'int'},
85 {name:'downloadcounter', type: 'int'},
86 {name:'statevalue'},
87 {name:'state'},
88 {name:'stateCls'},
89 {name:'icon'},
90 {name:'description'},
91 {name:'lastuploaddate', type: 'date', dateFormat: 'timestamp'},
92 {name:'authorname'},
93 {name:'authoremail'},
94 {name:'versions', type: 'int'},
95 {name:'installed', type: 'int'},
96 {name:'versionislower', type: 'bool'},
97 {name:'existingVersion'},
98 {name:'exists', type: 'int'},
99 {name:'relevance', type: 'int'}
100 ],
101 paramNames: {
102 start : 'start',
103 limit : 'limit',
104 sort : 'sort',
105 dir : 'dir',
106 query: 'query'
107 },
108 baseParams: {
109 query: '',
110 repository: TYPO3.settings.EM.selectedRepository,
111 start: 0,
112 limit: 50
113
114 },
115 remoteSort: true,
116 sortInfo:{
117 field:'title',
118 direction:"ASC"
119 },
120 listeners: {
121 beforeload: function(store, records){
122 var control = Ext.getCmp('rsearchField');
123 if (control.getValue == '') {
124 return false;
125 }
126 store.setBaseParam('rep', Ext.getCmp('repCombo').getValue());
127 store.setBaseParam('installedOnly', this.showInstalledOnly);
128 if (!this.showInstalledOnly) {
129 this.filterMenuButton.removeClass('bold');
130 } else {
131 this.filterMenuButton.addClass('bold');
132 }
133
134 },
135 load: function(store, records){
136 var hasFilters = false;
137 TYPO3.EM.RemoteFilters.filters.each(function (filter) {
138 if (filter.active) {
139 hasFilters = true;
140 }
141 });
142 if (hasFilters) {
143 this.doClearFilters.show();
144 } else {
145 this.doClearFilters.hide();
146 }
147 if (records.length === 0) {
148
149 } else {
150
151 }
152 },
153 scope: this
154 },
155 highlightSearch: function(value) {
156 var control = Ext.getCmp('rsearchField');
157 if (control) {
158 var filtertext = control.getRawValue();
159 if (filtertext) {
160 var re = new RegExp(Ext.escapeRe(filtertext), 'gi');
161 var result = re.exec(value) || [];
162 if (result.length) {
163 return value.replace(result[0], '<span class="filteringList-highlight">' + result[0] + '</span>');
164 }
165 }
166 }
167 return value;
168 }
169
170 });
171
172 this.repositoryStore = new Ext.data.DirectStore({
173 storeId: 'repositories',
174 idProperty: 'uid',
175 directFn: TYPO3.EM.ExtDirect.getRepositories,
176 root: 'data',
177 totalProperty: 'length',
178 fields : ['title', 'uid', 'updated', 'count', 'selected'],
179 paramsAsHash: true
180 });
181
182 var searchField = new Ext.ux.form.SearchField({
183 id: 'rsearchField',
184 store: this.repositoryListStore,
185 width: 260,
186 specialKeyOnly: true,
187 emptyText: TYPO3.l10n.localize('msg_startTyping')
188 });
189
190 var cm = new Ext.grid.ColumnModel({
191 columns: [
192 TYPO3.settings.EM.inlineToWindow == 1 ? TYPO3.EM.GridColumns.DummyColumn : this.expander,
193 TYPO3.EM.GridColumns.ImportExtension,
194 TYPO3.EM.GridColumns.ExtensionTitle,
195 TYPO3.EM.GridColumns.ExtensionKey,
196 TYPO3.EM.GridColumns.ExtensionCategoryRemote,
197 TYPO3.EM.GridColumns.ExtensionRemoteAuthor,
198 TYPO3.EM.GridColumns.ExtensionType,
199 TYPO3.EM.GridColumns.Relevance,
200 TYPO3.EM.GridColumns.ExtensionDownloads,
201 TYPO3.EM.GridColumns.ExtensionStateValue
202 ],
203 defaults: {
204 sortable: true,
205 hideable:false
206 }
207
208 });
209
210 Ext.apply(this, {
211 loadMask: {msg: TYPO3.l10n.localize('action_loadingRepositoryExtlist')},
212 store: this.repositoryListStore,
213 cm: cm,
214 plugins: TYPO3.settings.EM.inlineToWindow == 1 ? [TYPO3.EM.RemoteFilters] : [this.expander, TYPO3.EM.RemoteFilters],
215 viewConfig: {
216 forceFit: true,
217 enableRowBody: true,
218 showPreview: true,
219 getRowClass: this.applyRowClass,
220 iconCls: 'icon-grid'
221 },
222 sm: new Ext.grid.CellSelectionModel({
223 select: Ext.emptyFn
224 }),
225 tbar: [
226 ' ',
227 {
228 text: TYPO3.l10n.localize('cmd_filter'),
229 tooltip: TYPO3.l10n.localize('help_remoteFilter'),
230 scale: 'small',
231 iconAlign: 'right',
232 ref: '../filterMenuButton',
233 menu : {
234 items: [
235 {
236 checked: true,
237 group: 'installFilter',
238 text: TYPO3.l10n.localize('display_all'),
239 handler: function(item, event) {
240 this.showInstalledOnly = 0;
241 this.store.reload();
242 },
243 scope: this
244 }, {
245 checked: false,
246 group: 'installFilter',
247 text: TYPO3.l10n.localize('display_installedOnly'),
248 handler: function(item, event) {
249 this.showInstalledOnly = 1;
250 this.store.reload();
251 },
252 scope: this
253 }
254 ]
255 }
256 },
257 searchField, ' ', {
258 text: TYPO3.l10n.localize('cmd_ClearAllFilters'),
259 ref: '../doClearFilters',
260 handler: function() {
261 TYPO3.EM.RemoteFilters.clearFilters();
262 },
263 scope: this,
264 hidden: true
265 },
266 '->',
267 {
268 xtype: 'tbtext',
269 text: TYPO3.l10n.localize('repository') + ': '
270 },
271 TYPO3.EM.RepositoryCombo,
272 {
273 iconCls: 'x-btn-repupdate',
274 handler: this.repositoryUpdate,
275 tooltip: TYPO3.l10n.localize('cmd_RetrieveUpdate'),
276 scope: this,
277 hidden: !TYPO3.settings.EM.allowRepositoryUpdate
278 },
279 {
280 xtype: 'container',
281 id: 'repListInfo',
282 html: ''
283 },
284 ' '
285
286 ],
287 bbar:[
288 '->', {
289 id: 'rresultPaging',
290 xtype: 'paging',
291 store: this.repositoryListStore,
292 pageSize: 50,
293 displayInfo: true,
294 emptyMsg: TYPO3.l10n.localize('action_searching')
295 }
296 ]
297 });
298
299 TYPO3.EM.RepositoryList.superclass.initComponent.apply(this, arguments);
300 },
301
302 onRender:function() {
303 TYPO3.EM.RepositoryCombo.store = this.repositoryStore;
304 TYPO3.EM.RepositoryCombo.on('select', function(comboBox, newValue, oldValue) {
305 var info = TYPO3.EM.Layouts.repositoryInfo().applyTemplate(newValue.data);
306 Ext.getCmp('repListInfo').update(info);
307 this.repositoryListStore.reload({ params: {repository: newValue.data.uid} });
308 }, this);
309 this.repositoryStore.load({
310 callback: function() {
311 if (this.getCount() == 0) {
312 TYPO3.Flashmessage.display(TYPO3.Severity.error, TYPO3.l10n.localize('msg_error'), TYPO3.l10n.localize('repository_notfound'), 15);
313 } else {
314 var rec = this.getById(TYPO3.settings.EM.selectedRepository);
315 if (!rec) {
316 TYPO3.settings.EM.selectedRepository = 1;
317 rec = this.getById(TYPO3.settings.EM.selectedRepository);
318 }
319 TYPO3.EM.RepositoryCombo.setValue(TYPO3.settings.EM.selectedRepository);
320 Ext.getCmp('repListInfo').update(TYPO3.EM.Layouts.repositoryInfo().applyTemplate(rec.data));
321 }
322 }
323
324 });
325 TYPO3.EM.RepositoryList.superclass.onRender.apply(this, arguments);
326
327 this.on('rowcontextmenu', function(grid, rowIndex, event) {
328 if (event.button === 2) {
329 var record = grid.store.getAt(rowIndex);
330 if (record.data.versions > 1) {
331 var menu = new Ext.menu.Menu({
332 record: record,
333 items: [{
334 text: String.format(TYPO3.l10n.localize('ext_import_versions'), record.data.title)
335 + ' (' + String.format(TYPO3.l10n.localize('ext_import_versions_available'), record.data.versions) + ')',
336 iconCls: 't3-icon t3-icon-actions t3-icon-actions-system t3-icon-system-extension-import',
337 handler: function() {
338 var record = this.ownerCt.record.data;
339 var link = TYPO3.settings.EM.scriptLink
340 + '&nodoc=1&ter_connect=1&ter_search=' + record.extkey +'&CMD[importExtInfo]=' + record.extkey;
341 TYPO3.EM.ImportWindow = new TYPO3.EM.InstallWindow({
342 title: String.format(TYPO3.l10n.localize('ext_import_versions'), record.title) + ' (' + record.extkey + ')',
343 record: record,
344 installAction: 'import',
345 listeners: {
346 close: function() {
347 TYPO3.EM.Tools.refreshMenu(record, 'import');
348 }
349 }
350 }).show(true, function(){
351 Ext.getCmp('emInstallIframeWindow').setUrl(link);
352 });
353 }
354 }]
355 }).showAt(event.getXY());
356 }
357 event.stopEvent();
358 }
359 });
360
361 this.on('rowdblclick',function(grid, rowIndex, event) {
362 if (TYPO3.settings.EM.inlineToWindow == 1) {
363 this.showExtInfoInWindow(rowIndex);
364 }
365 });
366 this.on('cellclick',function(grid, rowIndex, columnIndex, event) {
367 if (TYPO3.settings.EM.inlineToWindow == 1 && columnIndex == 2) {
368 this.showExtInfoInWindow(rowIndex);
369 }
370 });
371 },
372
373 repositoryUpdate: function() {
374 var m = Ext.MessageBox.wait(TYPO3.l10n.localize('msg_longwait'), TYPO3.l10n.localize('repository_update'));
375 var index = TYPO3.EM.RepositoryCombo.getValue();
376 if (!index) {
377 return;
378 }
379 var record = this.repositoryStore.getAt(index - 1);
380 TYPO3.EM.ExtDirect.repositoryUpdate(index, function(response) {
381 if (!response.success) {
382 if (response.rep == 0) {
383 TYPO3.Flashmessage.display(TYPO3.Severity.error, TYPO3.l10n.localize('msg_error'), response.errormsg, 15);
384 } else {
385 TYPO3.Flashmessage.display(TYPO3.Severity.notice, TYPO3.l10n.localize('repository_update_not_needed'), response.errormsg, 5);
386 }
387 } else {
388 TYPO3.Flashmessage.display(TYPO3.Severity.information, TYPO3.l10n.localize('repository_updated'), String.format(TYPO3.l10n.localize('repository_extensions_count'), response.data.count), 10);
389 record.set('count', response.data.count);
390 record.set('updated', response.data.updated);
391 Ext.getCmp('repListInfo').update(TYPO3.EM.Layouts.repositoryInfo().applyTemplate(record.data));
392 }
393 m.hide();
394 }, this);
395 },
396
397 showExtInfoInWindow: function(index) {
398 var record = this.store.getAt(index);
399 var id = 'window-extinfo-' + record.data.extkey;
400 if (Ext.WindowMgr.get(id)) {
401 Ext.WindowMgr.bringToFront(id);
402 } else {
403 new Ext.Window({
404 title: TYPO3.EM.Tools.renderExtensionTitle(record),
405 layout: 'fit',
406 width: 600,
407 height: 350,
408 items : this.expander.createExpandingRowPanelItems(record,index),
409 id: id
410 }).show();
411 }
412 }
413 });
414
415 Ext.reg('remoteextlist', TYPO3.EM.RepositoryList);