96e5b95466c0ea6876848192d4acd8f8416e4517
[fnpeditor.git] / src / editor / plugins / core / metadataEditor / action.js
1 define(function(require) {
2     
3 'use strict';
4 /* globals gettext */
5
6 var Dialog = require('views/dialog/dialog'),
7     View = require('plugins/core/metadataEditor/view');
8
9
10 return function(ctx) {
11     return {
12         name: 'showMetadataEditor',
13         params: {
14             doc: {type: 'context', name: 'document'}
15         },
16         stateDefaults: {
17             allowed: true,
18             label: gettext('Metadata'),
19             execute: function(callback, params) {
20                 void(callback);
21                 var dialog = Dialog.create({
22                         title: gettext('Document Metadata'),
23                         executeButtonText: gettext('Close'),
24                         cssClass: 'metadataEditor',
25                         closeButton: false
26                     }),
27                     view = new View(params.doc.root, ctx.config);
28                 dialog.show();
29                 dialog.setContentView(view.dom);
30                 dialog.on('execute', function(e) {
31                     var cover_url = view.getMetadataByKey('relation.coverimage.url');
32                     if (cover_url && !cover_url.match(/\.(png|jpg|jpeg|gif|tif|tiff)$/i)) {
33                         window.alert(gettext('The cover needs to be an image file: jpg, png, gif. Use another URL or clear the cover field.'));
34                         return;
35                     }
36                     e.success();
37                 });
38             }
39         },
40         getState: function(params) {
41             return {
42                 allowed: !!params.doc
43             };
44         }
45     };
46 };
47
48 });