attachment list for links + bad links in red
authorJan Szejko <janek37@gmail.com>
Thu, 11 Jan 2018 13:51:16 +0000 (14:51 +0100)
committerJan Szejko <janek37@gmail.com>
Thu, 11 Jan 2018 13:51:16 +0000 (14:51 +0100)
src/editor/plugins/core/core.js
src/editor/plugins/core/links/box.html
src/editor/plugins/core/links/linkElement.js
src/editor/plugins/core/links/links.less
src/editor/styles/main.less
src/editor/views/attachments/add_attachments.js [new file with mode: 0644]
src/editor/views/attachments/attachments.less [new file with mode: 0644]

index 31ac09d..3839a39 100644 (file)
@@ -12,7 +12,8 @@ var _ = require('libs/underscore'),
     Dialog = require('views/dialog/dialog'),
     canvasElements = require('plugins/core/canvasElements'),
     metadataEditor = require('plugins/core/metadataEditor/metadataEditor'),
     Dialog = require('views/dialog/dialog'),
     canvasElements = require('plugins/core/canvasElements'),
     metadataEditor = require('plugins/core/metadataEditor/metadataEditor'),
-    edumed = require('plugins/core/edumed/edumed');
+    edumed = require('plugins/core/edumed/edumed'),
+    add_attachments = require('views/attachments/add_attachments');
 
 
 var exerciseFix = function(newNodes) {
 
 
 var exerciseFix = function(newNodes) {
@@ -556,6 +557,7 @@ var createLinkFromSelection = function(callback, params) {
         });
     });
     dialog.show();
         });
     });
     dialog.show();
+    add_attachments(dialog);
 };
 
 var editLink = function(callback, params) {
 };
 
 var editLink = function(callback, params) {
index db1b2da..4644537 100644 (file)
@@ -1,5 +1,5 @@
 <div link-box style="white-space: nowrap">
 <div link-box style="white-space: nowrap">
-    <a link target="_blank" href="<%= url %>"><%= text %></a> <br/>--
+    <a link target="_blank" href="<%= url %>"<% if(bad) { %> class="bad-link"<% } %>><%= text %></a> <br/>--
     <span>
         <a class="change" href="#"><%= gettext('change') %></a> |
         <a class="delete" href="#"><%= gettext('remove') %></a>
     <span>
         <a class="change" href="#"><%= gettext('change') %></a> |
         <a class="delete" href="#"><%= gettext('remove') %></a>
index 61d2abc..7439804 100644 (file)
@@ -9,6 +9,7 @@ var $ = require('libs/jquery'),
     genericElement = require('modules/documentCanvas/canvas/genericElement'),
     Dialog = require('views/dialog/dialog'),
     boxTemplate = require('libs/text!./box.html'),
     genericElement = require('modules/documentCanvas/canvas/genericElement'),
     Dialog = require('views/dialog/dialog'),
     boxTemplate = require('libs/text!./box.html'),
+    add_attachments = require('views/attachments/add_attachments'),
     linkElement = Object.create(genericElement);
 
 
     linkElement = Object.create(genericElement);
 
 
@@ -18,9 +19,16 @@ _.extend(linkElement, {
         _.bindAll(this, 'changeLink', 'deleteLink');
 
         var linkText = this.wlxmlNode.getAttr('href') || '',
         _.bindAll(this, 'changeLink', 'deleteLink');
 
         var linkText = this.wlxmlNode.getAttr('href') || '',
-            linkUrl = this.getUrl(linkText);
+            linkUrl = this.getUrl(linkText),
+            badLink;
 
 
-        this.box = $(_.template(boxTemplate)({text: linkText, url: linkUrl}));
+        if (linkText.substr(0,7) === 'file://') {
+            var filename = linkText.substr(7);
+            // ugly
+            badLink = (window.materials.indexOf(filename) < 0);
+        }
+
+        this.box = $(_.template(boxTemplate)({text: linkText, url: linkUrl, bad: badLink}));
         this.box.find('.change').on('click', this.changeLink);
         this.box.find('.delete').on('click', this.deleteLink);
         this.box.hide();
         this.box.find('.change').on('click', this.changeLink);
         this.box.find('.delete').on('click', this.deleteLink);
         this.box.hide();
@@ -74,6 +82,7 @@ _.extend(linkElement, {
             });
         });
         dialog.show();
             });
         });
         dialog.show();
+        add_attachments(dialog);
     },
 
     deleteLink: function() {
     },
 
     deleteLink: function() {
index f9ab609..ac9f662 100644 (file)
@@ -11,4 +11,8 @@
     box-shadow:0 10px 5px #888888;
     z-index:9999;
     font-style: normal;
     box-shadow:0 10px 5px #888888;
     z-index:9999;
     font-style: normal;
+
+    .bad-link {
+        color: red;
+    }
 }
\ No newline at end of file
 }
\ No newline at end of file
index 6322459..059789e 100644 (file)
@@ -6,6 +6,7 @@
 @import '../views/openSelect/openSelect.less';
 @import '../views/dialog/dialog.less';
 @import '../views/menu/menu.less';
 @import '../views/openSelect/openSelect.less';
 @import '../views/dialog/dialog.less';
 @import '../views/menu/menu.less';
+@import '../views/attachments/attachments.less';
 @import '../modules/rng/rng.less';
 @import '../modules/documentCanvas/documentCanvas.less';
 @import '../modules/sourceEditor/sourceEditor.less';
 @import '../modules/rng/rng.less';
 @import '../modules/documentCanvas/documentCanvas.less';
 @import '../modules/sourceEditor/sourceEditor.less';
diff --git a/src/editor/views/attachments/add_attachments.js b/src/editor/views/attachments/add_attachments.js
new file mode 100644 (file)
index 0000000..250b2b8
--- /dev/null
@@ -0,0 +1,34 @@
+define(function(require) {
+    'use strict';
+
+    var $ = require('libs/jquery');
+
+    return function (dialog) {
+        var body = $(".modal-body", dialog.$el);
+        var input = $("input[name=href]", body);
+        $.ajax(config.documentGalleryUrl, {
+            dataType: 'json',
+            success: function (data, status, jqxhr) {
+                for (var i in data) {
+                    var img = $("<img style='margin-right: 1em'>");
+                    var button = $("<button/>").attr('type', 'button').addClass('choice');
+                    var div = $("<div style='border: 1px solid white'/>");
+                    button.append(img);
+                    button.append(data[i]['name']);
+                    img.attr("src", data[i]['thumbnail_url']);
+                    img.attr("title", data[i]['name']);
+                    button.attr('for', 'attachment' + i);
+                    div.append(button);
+                    div.attr("data-output", 'file://' + data[i]['name']);
+                    div.on('click', function () {
+                        input.val($(this).attr('data-output'));
+                    });
+                    body.append(div);
+                }
+                var editlink = $("<a target='_blank'>" + gettext("Manage attachments") + "</a>");
+                editlink.attr('href', config.documentGalleryUrl);
+                body.append(editlink);
+            }
+        });
+    };
+});
diff --git a/src/editor/views/attachments/attachments.less b/src/editor/views/attachments/attachments.less
new file mode 100644 (file)
index 0000000..122a9e2
--- /dev/null
@@ -0,0 +1,4 @@
+.modal-body button.choice {
+    min-width: 400px;
+    text-align: left;
+}
\ No newline at end of file