From: Jan Szejko Date: Mon, 30 Jan 2017 13:50:13 +0000 (+0100) Subject: validate cover extension in metadata dialog X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/765844777c85210d541321bfed7582c07a1b4b00?ds=inline;hp=cff9718672752da4840cb0b5bd62c60e7d9c7a30 validate cover extension in metadata dialog --- diff --git a/src/editor/plugins/core/metadataEditor/action.js b/src/editor/plugins/core/metadataEditor/action.js index cb3d605..96e5b95 100644 --- a/src/editor/plugins/core/metadataEditor/action.js +++ b/src/editor/plugins/core/metadataEditor/action.js @@ -21,12 +21,18 @@ return function(ctx) { var dialog = Dialog.create({ title: gettext('Document Metadata'), executeButtonText: gettext('Close'), - cssClass: 'metadataEditor' + cssClass: 'metadataEditor', + closeButton: false }), view = new View(params.doc.root, ctx.config); dialog.show(); dialog.setContentView(view.dom); dialog.on('execute', function(e) { + var cover_url = view.getMetadataByKey('relation.coverimage.url'); + if (cover_url && !cover_url.match(/\.(png|jpg|jpeg|gif|tif|tiff)$/i)) { + window.alert(gettext('The cover needs to be an image file: jpg, png, gif. Use another URL or clear the cover field.')); + return; + } e.success(); }); } diff --git a/src/editor/plugins/core/metadataEditor/view.js b/src/editor/plugins/core/metadataEditor/view.js index 18434e5..cde4f89 100644 --- a/src/editor/plugins/core/metadataEditor/view.js +++ b/src/editor/plugins/core/metadataEditor/view.js @@ -128,6 +128,16 @@ _.extend(View.prototype, { view.addMetadataRow(row); }); }, + getMetadataByKey: function (key) { + var ret; + this.node.getMetadata().some(function (row) { + if (row.key == 'relation.coverimage.url') { + ret = row.value; + return true; + } + }); + return ret; + }, addMetadataRow: function(row) { console.log(row); var newRow = $(_.template(itemTemplate)({key: row.getKey() || '', value: row.getValue() || ''})); diff --git a/src/editor/views/dialog/dialog.html b/src/editor/views/dialog/dialog.html index 7499cd1..3e1463e 100644 --- a/src/editor/views/dialog/dialog.html +++ b/src/editor/views/dialog/dialog.html @@ -1,6 +1,6 @@