-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathActions.js
More file actions
475 lines (395 loc) · 15.6 KB
/
Actions.js
File metadata and controls
475 lines (395 loc) · 15.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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
151
152
153
154
155
156
157
158
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
/*
* Copyright (c) 2013-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
Ext4.define('File.panel.Action', {
extend: 'Ext.button.Button',
alias: 'widget.iconbtn',
closable: false,
stacked: false,
actionType: null,
hideIcon: false,
hideText: false,
padding: '2px 6px',
stackedCls: undefined,
fontCls: undefined,
statics: {
Type: {
NOMIN: 'NOMIN', // 'No file required',
ATLEASTONE: 'ATLEASTONE', // 'At least one file required',
ONLYONE: 'ONLYONE', // 'Only one file allowed',
ATLEASTTWO: 'ATLEASTTWO', // 'Needs at least two files',
NOFILE: 'NOFILE' // 'Only works with no files'
},
ItemType: {
ONLY_FILE: 'ONLY_FILE', // Only works on files
ONLY_FOLDER: 'ONLY_FOLDER', // Only works on folders
FILE_OR_FOLDER: 'FILE_OR_FOLDER' // Either files or folders (same as having no actionItemType set)
}
},
renderTpl: [
'<span id="{id}-btnEl" class="iconbtn">',
'<tpl if="stacked">',
'<span class="fa-stack fa-1x labkey-fa-stacked-wrapper" aria-hidden="true">',
'<span class="fa {fontCls} fa-stack-2x"></span>',
'<span class="fa fa-stack-1x {stackedCls}"></span>',
'</span>',
'<tpl else>',
'<span class="fa {fontCls}" aria-hidden="true"></span>',
'</tpl>',
'<span id="{id}-btnInnerEl" class="iconbtn-label">',
'<tpl if="text.length > 0 && !hideText">',
' {text:htmlEncode}',
'</tpl>',
'</span>',
'</span>'
],
constructor : function(config) {
if (config.itemId)
config.cls = config.itemId + "Btn";
Ext4.apply(this, {
hardText: config.hardText
});
this.resetProps = {
hideIcon: config.hideIcon === true,
hideText: config.hideText === true
};
// Add aria-label for accessibility (used by screen readers when button text is hidden)
if (config.hardText) {
var hardText = config.hardText;
var existingListeners = config.listeners || {};
var existingAfterRender = existingListeners.afterRender;
existingListeners.afterRender = function(btn) {
btn.getEl().dom.setAttribute('aria-label', hardText);
if (Ext4.isFunction(existingAfterRender)) {
existingAfterRender.call(this, btn);
}
};
config.listeners = existingListeners;
}
this.callParent([config]);
},
getTemplateArgs : function() {
return {
text: this.text || '',
stacked: this.stacked === true,
stackedCls: this.stackedCls,
fontCls: this.fontCls,
hideText: this.hideText === true
};
},
updateEnabled : function (fileSystem, selection) {
var actionType = this.initialConfig.actionType;
var actionItemType = this.initialConfig.actionItemType;
if (!actionType)
return;
var types = File.panel.Action.Type;
var itemTypes = File.panel.Action.ItemType;
if (actionType == types.NOMIN) {
// no nothing
}
else if (selection.length == 0) {
// Set disabled when case is: ATLEASTONE or ONLYONE or ATLEASTTWO
this.setDisabled((actionType == types.ATLEASTONE || actionType == types.ONLYONE || actionType == types.ATLEASTTWO));
}
else if (selection.length == 1) {
// Set disabled when case is: ATLEASTTWO or NOFILE
this.setDisabled((actionType == types.ATLEASTTWO || actionType == types.NOFILE));
// Set disabled if the any of the selected don't match the actionItemType
if (actionItemType) {
if (actionItemType == itemTypes.ONLY_FILE && selection[0].data.collection)
this.disable();
if (actionItemType == itemTypes.ONLY_FOLDER && !selection[0].data.collection)
this.disable();
}
// Let the action instance decide if it should be disabled
if (Ext4.isFunction(this.initialConfig.shouldDisable)) {
if (this.initialConfig.shouldDisable.call(this, fileSystem, selection[0]))
this.disable();
}
}
else if (selection.length >= 2) {
// Set disabled when case is: ONLYONE or NOFILE
this.setDisabled((actionType == types.ONLYONE || actionType == types.NOFILE));
// Set disabled if the any of the selected don't match the actionItemType
for (var i = 0, len = selection.length; i < len; i++) {
if (actionItemType) {
if (actionItemType == itemTypes.ONLY_FILE && selection[i].data.collection) {
this.disable();
break;
}
if (actionItemType == itemTypes.ONLY_FOLDER && !selection[i].data.collection) {
this.disable();
break;
}
}
// Let the action instance decide if it should be disabled
if (Ext4.isFunction(this.initialConfig.shouldDisable)) {
if (this.initialConfig.shouldDisable.call(this, fileSystem, selection[i])) {
this.disable();
break;
}
}
}
}
}
});
Ext4.define('File.panel.Actions', {
extend : 'Ext.panel.Panel',
border: false,
frame: false,
padding: 10,
isPipelineRoot: false,
importDataEnabled: false,
constructor : function(config) {
// Define models
if (!Ext4.ModelManager.isRegistered('File.Model.ActionModel')) {
Ext4.define('File.Model.ActionModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'action' },
{ name: 'actionId' },
{ name: 'enabled', type: 'boolean' },
{ name: 'id' },
{ name: 'showOnToolbar', type: 'boolean' },
{ name: 'type' }
]
});
}
if (Ext4.isEmpty(config.containerPath)) {
throw this.$className + ' requires a containerPath be specified.';
}
this.actionConfig = {};
this.callParent([config]);
},
initComponent : function() {
this.items = [{
xtype: 'box',
tpl: new Ext4.XTemplate('<span class="labkey-strong">Configure Actions</span>'),
data: {},
border: false
}];
this.callParent();
var hasConfig = false,
pipeActions = false;
// onReady will be called on the pipeline config and actions have been received
var onReady = function() {
if (hasConfig && pipeActions) {
if (this.isPipelineRoot) {
this.add({
xtype: 'checkbox',
itemId: 'showImportCheckbox',
id: 'importAction',
checked: this.importDataEnabled,
border: false,
frame: false,
labelSeparator: '',
boxLabel: 'Show "Import Data" toolbar button<br/>(<i>Administrators will always see this button</i>)',
width: 500,
height: 50,
padding: '10 0 0 0'
});
}
else {
var descriptionText = 'File Actions, such as <b>Import Data</b>, are not available for the contents of this File Browser. ' +
'An administrator may have set a pipeline override or configured the display of non-file content. ' +
'<a href="https://www.labkey.org/Documentation/wiki-page.view?name=fileManagementAdmin#actions" target="_blank" rel="noopener noreferrer">(more info...)</a>' +
'<br/><br/>';
if (LABKEY.ActionURL.getController() === 'filecontent') {
descriptionText += LABKEY.Utils.textLink({text: "Go To Pipeline Directory", href: LABKEY.ActionURL.buildURL('pipeline', 'browse')});
}
this.add({
border: false,
height: 300,
padding : '10 0 0 0',
html: descriptionText
});
}
if (Ext4.isObject(pipeActions)) {
this.add(this.getActionGrid(pipeActions));
}
}
};
// request configuration
File.panel.Browser._getPipelineConfiguration(function(json) {
this.parseActionConfiguration(json);
hasConfig = true;
onReady.call(this);
}, this.containerPath, this);
// request actions
if (this.isPipelineRoot) {
Ext4.Ajax.request({
url: LABKEY.ActionURL.buildURL('pipeline', 'actions.api', this.containerPath, { allActions: true }),
method: 'GET',
disableCaching: false,
success: function(response) {
pipeActions = this.getPipelineActions(response);
if (!Ext4.isDefined(pipeActions)) {
pipeActions = true;
}
onReady.call(this);
},
failure: LABKEY.Utils.displayAjaxErrorResponse,
scope: this
});
}
else {
pipeActions = true;
onReady.call(this);
}
},
parseActionConfiguration : function(json) {
var config = json.success ? json.config : {};
// check whether the import data button is enabled
Ext4.apply(this, {
importDataEnabled: config.importDataEnabled === true,
fileConfig: config.fileConfig ? config.fileConfig : 'useDefault',
expandFileUpload: config.expandFileUpload === true,
showFolderTree: config.showFolderTree,
inheritedTbarConfig: config.inheritedTbarConfig
});
if (config.actions) {
for (var i=0; i < config.actions.length; i++) {
var action = config.actions[i];
this.actionConfig[action.id] = action;
}
}
},
getPipelineActions : function(response) {
if (!this.isPipelineRoot) return;
var o = Ext4.decode(response.responseText);
var actions = o.success ? o.actions : [];
// parse the response and create the data object
var data = {actions: []};
if (actions && actions.length)
{
for (var i=0; i < actions.length; i++)
{
var pUtil = actions[i];
var links = pUtil.links.items;
if(!links)
links = [pUtil.links];
if (!links) continue;
var config = this.actionConfig[pUtil.links.id];
for (var j=0; j < links.length; j++)
{
var link = links[j];
if (link.href)
{
var display = 'enabled';
if (config)
{
var linkConfig = config.links[0];
if (linkConfig)
display = linkConfig.display;
}
data.actions.push({
type: pUtil.links.text,
id: link.id,
actionId : pUtil.links.id,
display: display,
action: link.text,
href: link.href,
enabled: (display == 'enabled') || (display == 'toolbar'),
showOnToolbar: display == 'toolbar'
});
}
}
}
}
return data;
},
getActionGrid : function(data) {
if (!this.actionGrid) {
this.actionGrid = Ext4.create('Ext.grid.Panel', {
store: {
storeId: 'actionStore',
model: 'File.Model.ActionModel',
groupField: 'type',
data: data.actions
},
columns: [
{ text: 'Action', dataIndex: 'action', flex: 1 },
{ text: 'Enabled', dataIndex: 'enabled', xtype : 'checkcolumn', width : 100 },
{ text: 'Show on Toolbar', dataIndex: 'showOnToolbar', xtype : 'checkcolumn', width : 150 }
],
features: [{
ftype: 'grouping',
groupHeaderTpl: '{name}', //print the number of items in the group
startCollapsed: false // start all groups collapsed
}],
height: 400
});
}
return this.actionGrid;
},
getActionsForSubmission : function() {
var adminOptions = [];
var grid = this.actionGrid;
//
// 19122 - If pipeline is configured, yet the browser is still configured to point at the files directory
// it can cause a configuration where a grid is not supplied.
//
if (!this.isPipelineRoot || !grid) {
return adminOptions;
}
var records = grid.getStore() ? grid.getStore().getModifiedRecords() : [],
actionConfig = {};
// pipeline action configuration
Ext4.each(records, function(record) {
var actionId,
config,
display;
actionId = record.get('actionId');
if (record.get('showOnToolbar')) {
display = 'toolbar';
}
else if (record.get('enabled')) {
display = 'enabled';
}
else {
display = 'disabled';
}
config = actionConfig[actionId];
if (!config) {
config = {
id: actionId,
display: 'enabled',
label: record.get('type')
};
}
if (!config.links) {
config.links = [];
}
config.links.push({
id: record.get('id'),
display: display,
label: record.get('action')
});
actionConfig[actionId] = config;
});
Ext4.iterate(actionConfig, function(id, config) {
if (Ext4.isObject(config)) {
adminOptions.push({
id: config.id,
display: config.display,
label: config.label,
links: config.links
});
}
});
return adminOptions;
},
getShowImportCheckbox : function() {
return this.down('#showImportCheckbox');
},
isImportDataEnabled : function() {
var cb = this.getShowImportCheckbox(),
value = this.importDataEnabled; // default value
if (cb) {
value = cb.getValue();
}
return value;
}
});