validate cover extension in metadata dialog
authorJan Szejko <janek37@gmail.com>
Mon, 30 Jan 2017 13:50:13 +0000 (14:50 +0100)
committerJan Szejko <janek37@gmail.com>
Mon, 30 Jan 2017 13:50:13 +0000 (14:50 +0100)
src/editor/plugins/core/metadataEditor/action.js
src/editor/plugins/core/metadataEditor/view.js
src/editor/views/dialog/dialog.html
src/editor/views/dialog/dialog.js

index cb3d605..96e5b95 100644 (file)
@@ -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();
                 });
             }
index 18434e5..cde4f89 100644 (file)
@@ -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() || ''}));
index 7499cd1..3e1463e 100644 (file)
@@ -1,6 +1,6 @@
 <div class="rng-dialog modal hide static <%= cssClass %>">
     <div class="modal-header">
-        <button type="button" class="close">&times;</button>
+        <% if(closeButton) { %><button type="button" class="close">&times;</button><% } %>
         <h1><%= title %></h1>
     </div>
     <div class="modal-body">
index 7d9f775..642342d 100644 (file)
@@ -29,7 +29,8 @@ define(function(require) {
             this.setElement(this.template(_.extend({
                 executeButtonText: null,
                 cancelButtonText: null,
-                cssClass: ''
+                cssClass: '',
+                closeButton: true
             }, this.options)));
 
             var body = this.$('.modal-body');