/
MetadataMenu.js
413 lines (381 loc) · 15.1 KB
/
MetadataMenu.js
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
/*
* Copyright (C) 2001-2011 Food and Agriculture Organization of the
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
* and United Nations Environment Programme (UNEP)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
* Rome - Italy. email: geonetwork@osgeo.org
*/
Ext.namespace('GeoNetwork');
/**
*
*/
/** api: (define)
* module = GeoNetwork
* class = MetadataMenu
* base_link = `Ext.menu.Menu <http://extjs.com/deploy/dev/docs/?class=Ext.DataView>`_
*/
/** api: constructor
* .. class:: MetadataMenu(config)
*
* Metadata menu allows users to access all metadata managment operations according to their privileges.
*
* Rating widget is available by default if Ext.ux.RatingItem is defined.
*
* Define a GeoNetwork.Settings.editor.editHarvested to allow editing of harvested records
* (TODO : retrieve from catalogue configuration).
*/
GeoNetwork.MetadataMenu = Ext.extend(Ext.menu.Menu, {
/** private: property[record]
* Record used for the current menu.
*/
record: undefined,
/** private: method[setRecord]
* Set current menu record
*
*/
setRecord: function(record) {
this.record = record;
this.updateMenu();
},
resultsView: undefined,
catalogue: undefined,
editAction: undefined,
deleteAction: undefined,
zoomToAction: undefined,
otherActions: undefined,
adminMenuSeparator: undefined,
duplicateAction: undefined,
createChildAction: undefined,
statusAction: undefined,
enableWorkflowAction: undefined,
versioningAction: undefined,
adminAction: undefined,
categoryAction: undefined,
viewAction: undefined,
printAction: undefined,
viewXMLAction: undefined,
getMEFAction: undefined,
ratingWidget: undefined,
statusStore: undefined,
defaultConfig: {},
/** private: method[setRecord]
* Create the menu.
*
*/
create: function() {
this.initAction();
this.composeMenu();
this.addCustomAction();
this.updateMenu();
},
initAction: function(){
this.editAction = new Ext.Action({
text: OpenLayers.i18n('edit'),
iconCls: 'md-mn-edit',
handler: function(){
var id = this.record.get('id');
this.catalogue.metadataEdit(id);
},
scope: this
});
this.deleteAction = new Ext.Action({
text: OpenLayers.i18n('delete'),
iconCls: 'md-mn-del',
handler: function(){
var id = this.record.get('uuid');
this.catalogue.metadataDelete(id);
},
scope: this
});
/* Other actions */
this.duplicateAction = new Ext.Action({
text: OpenLayers.i18n('duplicate'),
iconCls: 'md-mn-copy',
handler: function(){
var id = this.record.get('id');
GeoNetwork.editor.EditorTools.showNewMetadataWindow(this, id, OpenLayers.i18n('duplicate'), false);
},
scope: this
});
this.createChildAction = new Ext.Action({
text: OpenLayers.i18n('createChild'),
iconCls: 'childIcon',
handler: function(){
var id = this.record.get('id');
GeoNetwork.editor.EditorTools.showNewMetadataWindow(this, id, OpenLayers.i18n('createChild'), true);
},
scope: this
});
// FIXME : tooltip for actions does not work
this.adminAction = new Ext.Action({
text: OpenLayers.i18n('privileges'),
tooltip: OpenLayers.i18n('privilegesTT'),
iconCls : 'privIcon',
handler: function(){
var id = this.record.get('id');
this.catalogue.metadataAdmin(id);
},
scope: this
});
this.enableWorkflowAction = new Ext.Action({
text: OpenLayers.i18n('enableWorkflow'),
tooltip: OpenLayers.i18n('enableWorkflowTT'),
iconCls : 'statusIcon',
handler: function(){
var id = this.record.get('id'),
status = GeoNetwork.Settings.DraftStatus || 1;
this.catalogue.metadataSetStatus(id, status, OpenLayers.i18n('enableWorkflow'));
},
scope: this
});
this.statusAction = new Ext.Action({
text: OpenLayers.i18n('status'),
tooltip: OpenLayers.i18n('statusTT'),
iconCls : 'statusIcon',
handler: function(){
var id = this.record.get('id');
this.catalogue.metadataStatus(id);
},
scope: this
});
// TODO : enable only if SVN manager is on.
this.versioningAction = new Ext.Action({
text: OpenLayers.i18n('versioning'),
tooltip: OpenLayers.i18n('versioningTT'),
iconCls : 'versioningIcon',
handler: function(){
var id = this.record.get('id');
this.catalogue.metadataVersioning(id);
},
scope: this
});
this.categoryAction = new Ext.Action({
text: OpenLayers.i18n('categories'),
iconCls : 'categoryIcon',
handler: function(){
var id = this.record.get('id');
this.catalogue.metadataCategory(id);
},
scope: this
});
this.adminMenuSeparator = new Ext.menu.Separator();
/* Public menu */
this.viewAction = new Ext.Action({
text: OpenLayers.i18n('view'),
iconCls: 'md-mn-view',
handler: function(){
var id = this.record.get('uuid');
this.catalogue.metadataShow(id);
},
scope: this
});
this.zoomToAction = new Ext.Action({
text: OpenLayers.i18n('zoomTo'),
iconCls: 'zoomlayer',
handler: function(){
var uuid = this.record.get('uuid');
this.resultsView.zoomTo(uuid);
},
scope: this
});
this.viewXMLAction = new Ext.Action({
text: OpenLayers.i18n('saveXml'),
iconCls: 'xmlIcon',
handler: function(){
var id = this.record.get('uuid');
var schema = this.record.get('schema');
this.catalogue.metadataXMLShow(id, schema);
},
scope: this
});
this.viewRDFAction = new Ext.Action({
text: OpenLayers.i18n('saveRdf'),
//W3C Semantic Web Logo
iconCls: 'rdfIcon',
handler: function(){
var id = this.record.get('uuid');
var schema = this.record.get('schema');
window.open(this.catalogue.services.mdRDFGet + "?uuid=" + id);
},
scope: this
});
this.printAction = new Ext.Action({
text: OpenLayers.i18n('printSel'),
iconCls: 'md-mn-pdf',
handler: function(){
this.catalogue.metadataPrint(this.record.get('uuid'));
},
scope: this
});
this.getMEFAction = new Ext.Action({
text: OpenLayers.i18n('getMEF'),
iconCls: 'md-mn-zip',
handler: function(){
this.catalogue.metadataMEF(this.record.get('uuid'));
},
scope: this
});
/* Rating menu */
if (!this.catalogue.isReadOnly() && Ext.ux.RatingItem) { // Check required widget are loaded before displaying context menu
// If more actions are placed in context menu, this needs improvements.
this.ratingWidget = new Ext.ux.RatingItem(null, {
canReset: false,
name: 'rating',
disabled: true,
nbStars: 5,
cls: 'ux-menu-rating-item',
listeners: {
change: function(e, value, star){
if (value) {
var uuid = this.record.get('uuid');
this.catalogue.metadataRate(uuid, value, this.hide());
this.ratingWidget.reset();
}
// TODO : if nb update current rating
},
scope: this
}
});
}
/* TODO : add categories / privileges / create child */
this.updateMenu();
},
composeMenu: function(){
if(!this.catalogue.isReadOnly()) {
this.add(this.editAction);
this.add(this.deleteAction);
this.otherActions = new Ext.menu.Item({
text: OpenLayers.i18n('otherActions'),
menu: {
items: [this.duplicateAction, this.createChildAction, this.adminAction, this.statusAction, this.enableWorkflowAction, this.versioningAction, this.categoryAction]
}
});
}
else {
this.otherActions = new Ext.menu.Item({
text: OpenLayers.i18n('otherActions'),
menu: {
items: []
}
});
}
this.add(this.otherActions);
this.add(this.adminMenuSeparator);
this.add(this.viewAction);
this.add(this.zoomToAction);
this.add(this.viewXMLAction);
this.add(this.viewRDFAction);
this.add(this.printAction);
this.add(this.getMEFAction);
/* Rating menu */
if (!this.catalogue.isReadOnly() && Ext.ux.RatingItem) { // Check required widget are loaded before displaying context menu
this.add(this.ratingWidget);
}
},
/**
* To override : Add optionnal custom action to the metadataMenu
*/
addCustomAction: function() {
},
/** private: method[updateMenu]
* Update menu privileges according to information defined in current record.
*
*/
updateMenu: function(){
if (!this.record) {
return; // TODO : improve. It happens when ViewWindow is opened without searching first.
}
var isEditable = this.record.get('edit') === 'true' ?
// do not allow edit on harvested records by default
(this.record.get('isharvested') === 'y' ? GeoNetwork.Settings.editor.editHarvested || false : true)
:
false,
status = this.record.get('status'),
disableIfSubmittedForEditor = (status == 4 && this.catalogue.identifiedUser.role === 'Editor' ? true : false),
isHarvested = this.record.get('isharvested') === 'y' ? true : false,
harvesterType = this.record.get('harvestertype'),
identified = this.catalogue.isIdentified() &&
(this.catalogue.identifiedUser && this.catalogue.identifiedUser.role !== 'RegisteredUser'),
isReadOnly = this.catalogue.isReadOnly();
/* Actions and menu visibility for logged in user */
if (!identified || isReadOnly) {
this.editAction.setText(OpenLayers.i18n('edit'));
this.editAction.hide();
this.deleteAction.hide();
} else {
// TODO : if editor and status is submitted - turn off editing
var statusIdx = this.statusStore.find('id', status);
// Set button title with status information if not set to unkonwn (ie. workflow is enabled)
this.editAction.setText(OpenLayers.i18n('edit')
+ (statusIdx !== -1 && status > 0 ?
OpenLayers.String.format(OpenLayers.i18n('currentStatus'), {
status: this.statusStore.getAt(statusIdx).get('label')[catalogue.lang]
}) : '')
);
this.editAction.show();
this.deleteAction.show();
// If status is unkown or undefined
if (status == '' || status == '0') {
this.enableWorkflowAction.show();
this.statusAction.hide();
} else {
this.enableWorkflowAction.hide();
this.statusAction.show();
}
}
if(this.otherActions) this.otherActions.setVisible(identified);
this.adminMenuSeparator.setVisible(identified);
/* Actions status depend on records */
if(GeoNetwork.Settings && GeoNetwork.Settings.editor && GeoNetwork.Settings.editor.disableIfSubmittedForEditor) {
this.editAction.setDisabled(disableIfSubmittedForEditor || !isEditable || isReadOnly);
} else {
this.editAction.setDisabled(!isEditable || isReadOnly);
}
this.adminAction.setDisabled((!isEditable && !isHarvested) || isReadOnly);
this.statusAction.setDisabled((!isEditable && !isHarvested) || isReadOnly);
this.enableWorkflowAction.setDisabled((!isEditable && !isHarvested) || isReadOnly);
this.versioningAction.setDisabled((!isEditable && !isHarvested) || isReadOnly);
this.categoryAction.setDisabled((!isEditable && !isHarvested) || isReadOnly);
this.deleteAction.setDisabled((!isEditable && !isHarvested) || isReadOnly);
this.duplicateAction.setDisabled(isReadOnly);
this.createChildAction.setDisabled(!isEditable || isReadOnly);
if (this.ratingWidget) {
this.ratingWidget.reset();
if ((isHarvested && harvesterType !== 'geonetwork') || isReadOnly) {
/* TODO : add tooltip message to explain why */
this.ratingWidget.disable();
} else {
this.ratingWidget.enable();
}
}
},
/** private: method[initComponent]
* Initializes the metadata menu.
*/
initComponent: function(){
Ext.applyIf(this, this.defaultConfig);
GeoNetwork.MetadataMenu.superclass.initComponent.call(this);
this.statusStore = new GeoNetwork.data.StatusStore(this.catalogue.services.getStatus);
this.statusStore.on('load', function () {
this.create();
}, this);
this.statusStore.load();
}
});
/** api: xtype = gn_MetadataMenu */
Ext.reg('gn_metadatamenu', GeoNetwork.MetadataMenu);