local changes from server
authorJan Szejko <j-sz@o2.pl>
Mon, 7 Mar 2016 13:46:47 +0000 (14:46 +0100)
committerJan Szejko <j-sz@o2.pl>
Mon, 7 Mar 2016 13:46:47 +0000 (14:46 +0100)
20 files changed:
src/editor/entrypoint.js
src/editor/modules/data/data.js
src/editor/modules/documentCanvas/canvas/documentElement.js
src/editor/modules/documentCanvas/nodes.less
src/editor/modules/documentHistory/documentHistory.js
src/editor/modules/documentHistory/documentHistory.less
src/editor/modules/documentHistory/templates/item.html
src/editor/modules/documentHistory/templates/main.html
src/editor/modules/mainBar/mainBar.js
src/editor/modules/mainBar/template.html
src/editor/modules/rng/rng.js
src/editor/plugins/core/canvasElements.js
src/editor/plugins/core/core.js
src/editor/plugins/core/img/box.html [new file with mode: 0644]
src/editor/plugins/core/img/imgElement.js [new file with mode: 0644]
src/editor/plugins/core/links/linkElement.js
src/editor/plugins/core/metadataEditor/view.js
src/editor/plugins/core/switch.js
src/editor/views/attachments/attachments.js [new file with mode: 0644]
src/editor/views/dialog/templates/select.html

index b723517..13ca1ab 100644 (file)
@@ -4,6 +4,8 @@
     /* globals requirejs, editor_init */
 
     requirejs.config({
     /* globals requirejs, editor_init */
 
     requirejs.config({
+        urlArgs: "bust=" + (new Date()).getTime(),
+
         paths: {
             'fnpjs': '../fnpjs',
             'libs': '../../libs',
         paths: {
             'fnpjs': '../fnpjs',
             'libs': '../../libs',
index 0d556a2..67ab801 100644 (file)
@@ -179,6 +179,12 @@ return function(sandbox) {
                     executeButtonText: gettext('Save'),
                     cancelButtonText: gettext('Cancel')
                 });
                     executeButtonText: gettext('Save'),
                     cancelButtonText: gettext('Cancel')
                 });
+            /* Set stage field initial value to current document stage. */
+            for (var i in documentSaveForm.fields) {
+                if (documentSaveForm.fields[i].name == 'textsave-stage') {
+                    documentSaveForm.fields[i].initialValue = data.stage;
+                }
+            }
             
             dialog.on('execute', function(event) {
                 sandbox.publish('savingStarted', 'remote');
             
             dialog.on('execute', function(event) {
                 sandbox.publish('savingStarted', 'remote');
@@ -275,6 +281,42 @@ return function(sandbox) {
             });
             dialog.show();
         },
             });
             dialog.show();
         },
+        publishVersion: function(revision) {
+            var documentPublishForm = $.extend({
+                        fields: [],
+                        revision_field_name: 'revision'
+                    },
+                    sandbox.getConfig().documentPublishForm
+                ),
+                dialog = Dialog.create({
+                    fields: documentPublishForm.fields,
+                    title: gettext('Publish'),
+                    executeButtonText: gettext('Publish'),
+                    cancelButtonText: gettext('Cancel')
+                });
+
+            dialog.on('execute', function(event) {
+                var formData = event.formData;
+                formData[documentPublishForm.revision_field_name] = revision;
+                sandbox.publish('publishingStarted', {version: revision});
+                if(sandbox.getConfig().jsonifySentData) {
+                    formData = JSON.stringify(formData);
+                }
+                $.ajax({
+                    method: 'post',
+                    //dataType: 'json',
+                    dataType: 'text',
+                    url: sandbox.getConfig().documentPublishUrl,
+                    data: formData,
+                    success: function(data) {
+                        reloadHistory();
+                        sandbox.publish('documentPublished');
+                        event.success();
+                    },
+                });
+            });
+            dialog.show();
+        },
         dropDraft: function() {
             logger.debug('Dropping a draft...');
             wlxmlDocument.loadXML(sandbox.getBootstrappedData().document);
         dropDraft: function() {
             logger.debug('Dropping a draft...');
             wlxmlDocument.loadXML(sandbox.getBootstrappedData().document);
@@ -285,4 +327,4 @@ return function(sandbox) {
     };
 };
 
     };
 };
 
-});
\ No newline at end of file
+});
index a1965cd..993064a 100644 (file)
@@ -43,6 +43,7 @@ $.extend(DocumentElement.prototype, {
                     this.state[key] = changes[key] = toUpdate[key];
                 }
             }.bind(this));
                     this.state[key] = changes[key] = toUpdate[key];
                 }
             }.bind(this));
+        console.log(changes);
         if(_.isFunction(this.onStateChange)) {
             this.onStateChange(changes);
             if(_.isBoolean(changes.active)) {
         if(_.isFunction(this.onStateChange)) {
             this.onStateChange(changes);
             if(_.isBoolean(changes.active)) {
index 35ac7a8..d33ea00 100644 (file)
 
 }
 
 
 }
 
+[wlxml-class="img"] {
+    background-repeat: no-repeat;
+    background-size: auto 100%;
+    height: 100px;
+    background-position: 50%;
+}
+
 [wlxml-tag="aside"] {
     margin-top: 10px;
     margin-bottom: 10px;
 [wlxml-tag="aside"] {
     margin-top: 10px;
     margin-bottom: 10px;
index 7bbf32f..8cd4475 100644 (file)
@@ -26,7 +26,11 @@ return function(sandbox) {
     });
     
     dom.find('.btn.display').click(function() {
     });
     
     dom.find('.btn.display').click(function() {
-        sandbox.publish('displayVersion', {version: historyItems.getSelected()[0]});
+        sandbox.publish('displayVersion', historyItems.getSelected()[0]);
+    });
+
+    dom.find('.btn.publish').click(function() {
+        sandbox.publish('publishVersion', historyItems.getSelected()[0]);
     });
         
     var addHistoryItem = function(item, options) {
     });
         
     var addHistoryItem = function(item, options) {
@@ -56,21 +60,21 @@ return function(sandbox) {
         _selected: [],
         select: function(item) {
             if(this._selected.length < 2) {
         _selected: [],
         select: function(item) {
             if(this._selected.length < 2) {
-                this._selected.push(item.version);
+                this._selected.push(item.revision);
                 this._updateUI();
                 return true;
             }
             return false;
         },
         unselect: function(item) {
                 this._updateUI();
                 return true;
             }
             return false;
         },
         unselect: function(item) {
-            this._selected = _.without(this._selected, item.version);
+            this._selected = _.without(this._selected, item.revision);
             this._updateUI();
         },
         add: function(item) {
             this._itemsById[item.version] = item;
         },
         isSelected: function(item) {
             this._updateUI();
         },
         add: function(item) {
             this._itemsById[item.version] = item;
         },
         isSelected: function(item) {
-            return _.contains(this._selected, item.version);
+            return _.contains(this._selected, item.revision);
         },
         getSelected: function() {
             return this._selected;
         },
         getSelected: function() {
             return this._selected;
@@ -81,17 +85,20 @@ return function(sandbox) {
                 toggleButton('compare', false);
                 toggleButton('display', false);
                 toggleButton('restore', false);
                 toggleButton('compare', false);
                 toggleButton('display', false);
                 toggleButton('restore', false);
+                toggleButton('publish', false);
             }
             if(len === 1) {
                 toggleButton('compare', false);
                 toggleButton('display', true);
                 toggleButton('restore', true);
             }
             if(len === 1) {
                 toggleButton('compare', false);
                 toggleButton('display', true);
                 toggleButton('restore', true);
+                toggleButton('publish', true);
             }
             if(len === 2) {
                 toggleItemViews(false);
                 toggleButton('compare', true);
                 toggleButton('display', false);
                 toggleButton('restore', false);
             }
             if(len === 2) {
                 toggleItemViews(false);
                 toggleButton('compare', true);
                 toggleButton('display', false);
                 toggleButton('restore', false);
+                toggleButton('publish', false);
             } else {
                 toggleItemViews(true);
             }
             } else {
                 toggleItemViews(true);
             }
index 608c9df..9cf2e6a 100644 (file)
             font-weight: bold;
         }
         
             font-weight: bold;
         }
         
-        .date, .author, .description {
+        .date, .author, .description, .published {
             margin: 5px 10px 0 40px;
         }
         
             margin: 5px 10px 0 40px;
         }
         
-        .description {
+        .description, .published {
             font-size: .9em;
         }
             font-size: .9em;
         }
+
+        .published {
+            color: #080;
+        }
     }
     
     .item.highlighted {
     }
     
     .item.highlighted {
index 1629226..a69c7d3 100644 (file)
@@ -3,4 +3,5 @@
     <div class="date"><%= date %></div>
     <div class="author"><%= author %></div>
     <div class="description"><%= description %></div>
     <div class="date"><%= date %></div>
     <div class="author"><%= author %></div>
     <div class="description"><%= description %></div>
+    <div class="published"><%= published %></div>
 </div>
\ No newline at end of file
 </div>
\ No newline at end of file
index 83cd627..73a62d7 100644 (file)
@@ -1,9 +1,10 @@
 <div class="rng-module-documentHistory">
     <div class="toolbar">
         <div class="group">
 <div class="rng-module-documentHistory">
     <div class="toolbar">
         <div class="group">
-            <button class="btn btn-mini compare">Porównaj</button>
-            <button class="btn btn-mini restore">Przywróć</button>
-            <button class="btn btn-mini display">Zobacz</button>
+            <button class="btn btn-mini compare">Compare</button>
+            <button class="btn btn-mini restore">Revert</button>
+            <button class="btn btn-mini display">Preview</button>
+            <button class="btn btn-mini publish">Publish</button>
         </div>
     </div>
     <div style="clear:both;"></div>
         </div>
     </div>
     <div style="clear:both;"></div>
index e5cf522..4fdee83 100644 (file)
@@ -12,7 +12,11 @@ return function(sandbox) {
     var config = sandbox.getConfig(),
         userName = config.user && config.user.name,
         view = $(_.template(template)({
     var config = sandbox.getConfig(),
         userName = config.user && config.user.name,
         view = $(_.template(template)({
-            userName: userName || gettext('anonymous')
+            userName: userName || gettext('anonymous'),
+            documentScheduleUrl: config.documentScheduleUrl,
+            documentForkUrl: config.documentForkUrl,
+            documentPreviewUrl: config.documentPreviewMainUrl(data.revision),
+            documentGalleryUrl: config.documentGalleryUrl,
         }));
 
     view.find('[data-cmd]').click(function(e) {
         }));
 
     view.find('[data-cmd]').click(function(e) {
@@ -48,4 +52,4 @@ return function(sandbox) {
 
 };
 
 
 };
 
-});
\ No newline at end of file
+});
index 59f0708..934b3ea 100644 (file)
@@ -1,12 +1,18 @@
 <div class="rng-module-mainBar">
     <div class="top">
 <div class="rng-module-mainBar">
     <div class="top">
+        <a target="_blank" href="/"><span style="color: #dd8000">MIL</span>/<span style="color: #0a0">PEER</span></a> | 
         <%= userName %> (<a href="/"><%= gettext('Exit') %></a>)
     </div>
     <div style="clear:both;"></div>
     <div class="bottom">
         <ul>
         <%= userName %> (<a href="/"><%= gettext('Exit') %></a>)
     </div>
     <div style="clear:both;"></div>
     <div class="bottom">
         <ul>
+            <!--li><a target="_blank" href="<%= documentScheduleUrl %>">Edit schedule</a></li>
+            <li><a target="_blank" href="<%= documentForkUrl %>">Create another version</a></li-->
+           <li><a target="_blank" href="<%= documentPreviewUrl %>">Preview saved version</a></li>
+            <li><a target="_blank" href="<%= documentGalleryUrl %>">Attachments</a></li>
+
             <li><a href="#" data-cmd="drop-draft" data-disabled-text="<%= gettext('no draft exists') %>"><%= gettext('drop a working draft') %></a></li>
             <li><button class="btn btn-mini btn-info" data-cmd="save"><%= gettext('Save') %></button></li>
         </ul>
     </div>
             <li><a href="#" data-cmd="drop-draft" data-disabled-text="<%= gettext('no draft exists') %>"><%= gettext('drop a working draft') %></a></li>
             <li><button class="btn btn-mini btn-info" data-cmd="save"><%= gettext('Save') %></button></li>
         </ul>
     </div>
-</div>
\ No newline at end of file
+</div>
index fc8cd61..e330854 100644 (file)
@@ -132,7 +132,13 @@ return function(sandbox) {
         },
         documentReverted: function(version) {
             documentIsDirty = false;
         },
         documentReverted: function(version) {
             documentIsDirty = false;
-            sandbox.getModule('indicator').clearMessage({message:'Wersja ' + version + ' przywrócona'});
+            sandbox.getModule('indicator').clearMessage({message:'Revision restored'});
+        },
+        publishingStarted: function(version) {
+            sandbox.getModule('indicator').showMessage(gettext('Publishing...'));
+        },
+        documentPublished: function(version) {
+            sandbox.getModule('indicator').clearMessage({message:'Published.'});
         }
     };
     
         }
     };
     
@@ -193,16 +199,13 @@ return function(sandbox) {
         restoreVersion: function(version) {
             sandbox.getModule('data').restoreVersion(version);
         },
         restoreVersion: function(version) {
             sandbox.getModule('data').restoreVersion(version);
         },
-        displayVersion: function(event) {
+        displayVersion: function(revision) {
             /* globals window */
             /* globals window */
-            var config = sandbox.getConfig(),
-                doc = sandbox.getModule('data').getDocument();
-
-            if(config.documentUrl) {
-                window.open(config.documentUrl(doc.properties.document_id, event.version), _.uniqueId());
-            } else {
-                logger.error('Unable to show version ' + event.version + ' of a document - config.documentUrl missing');
-            }
+            //window.open(sandbox.getConfig().documentPreviewUrl(revision), _.uniqueId());
+            window.open(sandbox.getConfig().documentPreviewUrl(revision), 'preview');
+        },
+        publishVersion: function(version) {
+            sandbox.getModule('data').publishVersion(version);
         }
     };
     
         }
     };
     
index 0d7cffa..ab3332e 100644 (file)
@@ -4,7 +4,9 @@ define(function(require) {
 
 var $ = require('libs/jquery'),
     genericElement = require('modules/documentCanvas/canvas/genericElement'), // TODO: This should be accessible via plugin infrastructure
 
 var $ = require('libs/jquery'),
     genericElement = require('modules/documentCanvas/canvas/genericElement'), // TODO: This should be accessible via plugin infrastructure
-    linkElement = require('./links/linkElement');
+    linkElement = require('./links/linkElement'),
+    imgElement = require('./img/imgElement')
+    ;
 
 var widgets = {
     footnoteHandler: function(clickHandler) {
 
 var widgets = {
     footnoteHandler: function(clickHandler) {
@@ -113,7 +115,8 @@ $.extend(footnote, {
 return [
     {tag: 'aside', klass: 'comment', prototype: null},
     {tag: 'aside', klass: 'footnote', prototype: footnote},
 return [
     {tag: 'aside', klass: 'comment', prototype: null},
     {tag: 'aside', klass: 'footnote', prototype: footnote},
-    {tag: 'span', klass: 'link', prototype: linkElement}
+    {tag: 'span', klass: 'link', prototype: linkElement},
+    {tag: 'div', klass: 'img', prototype: imgElement}
 ];
 
 
 ];
 
 
index 31ac09d..bc41e00 100644 (file)
@@ -12,7 +12,10 @@ 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'),
+    attachments = require('views/attachments/attachments');
+
+
 
 
 var exerciseFix = function(newNodes) {
 
 
 var exerciseFix = function(newNodes) {
@@ -520,6 +523,7 @@ var createWrapTextAction = function(createParams) {
 };
 
 
 };
 
 
+
 var createLinkFromSelection = function(callback, params) {
     var doc = params.fragment.document,
         dialog = Dialog.create({
 var createLinkFromSelection = function(callback, params) {
     var doc = params.fragment.document,
         dialog = Dialog.create({
@@ -530,7 +534,8 @@ var createLinkFromSelection = function(callback, params) {
                 {label: gettext('Link'), name: 'href', type: 'input',
                 prePasteHandler: function(text) {
                                     return params.fragment.document.getLinkForUrl(text);
                 {label: gettext('Link'), name: 'href', type: 'input',
                 prePasteHandler: function(text) {
                                     return params.fragment.document.getLinkForUrl(text);
-                                }.bind(this)
+                                }.bind(this),
+                description: '<a href="#-" class="attachment-library">attachment library</a>'
                 }
             ]
         }),
                 }
             ]
         }),
@@ -556,6 +561,9 @@ var createLinkFromSelection = function(callback, params) {
         });
     });
     dialog.show();
         });
     });
     dialog.show();
+    $(".attachment-library", dialog.$el).on('click', function() {
+        attachments.select(function(v) {$("input", dialog.$el).val(v);});
+    });
 };
 
 var editLink = function(callback, params) {
 };
 
 var editLink = function(callback, params) {
@@ -625,6 +633,7 @@ var linkAction = {
     }
 };
 
     }
 };
 
+
 var metadataParams = {};
 
 plugin.actions = [
 var metadataParams = {};
 
 plugin.actions = [
diff --git a/src/editor/plugins/core/img/box.html b/src/editor/plugins/core/img/box.html
new file mode 100644 (file)
index 0000000..e07a7f3
--- /dev/null
@@ -0,0 +1,7 @@
+<div link-box style="white-space: nowrap">
+    <a link target="blank" href="<%= url %>"><%= text %></a> <br/>--
+    <span>
+        <a class="change" href="#"><%= gettext('change') %></a> <!-- |
+        <a class="delete" href="#"><%= gettext('remove') %></a> -->
+    </span>
+</div>
diff --git a/src/editor/plugins/core/img/imgElement.js b/src/editor/plugins/core/img/imgElement.js
new file mode 100644 (file)
index 0000000..a83fb33
--- /dev/null
@@ -0,0 +1,126 @@
+define(function(require) {
+    
+'use strict';
+/* globals gettext */
+
+
+var $ = require('libs/jquery'),
+    _ = require('libs/underscore'),
+    genericElement = require('modules/documentCanvas/canvas/genericElement'),
+    Dialog = require('views/dialog/dialog'),
+    boxTemplate = require('libs/text!./box.html'),
+    attachments = require('views/attachments/attachments'),
+    linkElement = Object.create(genericElement);
+
+
+_.extend(linkElement, {
+    init: function() {
+        genericElement.init.call(this);
+        _.bindAll(this, 'changeLink', 'deleteLink');
+
+        var linkText = this.wlxmlNode.getAttr('src') || '',
+            linkUrl = this.getUrl(linkText);
+        
+        this._container().attr('style', 'background-image: url(\'' + linkUrl + '\');');
+
+        this.box = $(_.template(boxTemplate)({text: linkText, url: linkUrl}));
+        this.box.find('.change').on('click', this.changeLink);
+        this.box.find('.delete').on('click', this.deleteLink);
+        this.box.hide();
+        this.addWidget(this.box);
+    },
+    onStateChange: function(changes) {
+        genericElement.onStateChange.call(this, changes);
+        if(_.isBoolean(changes.active)) {
+            this.box.toggle(changes.active);
+        }
+    },
+    onNodeAttrChange: function(event) {
+        if(event.meta.attr === 'src') {
+            var link = this.box.find('[link]');
+            link.text(event.meta.newVal);
+            var linkUrl = this.getUrl(event.meta.newVal);
+            link.attr('href', linkUrl);
+            this._container().attr('style', 'background-image: url(\'' + linkUrl + '\');');
+        }
+    },
+
+    changeLink: function(e) {
+        var el = this,
+            //doc = this.wlxmlNode.document,
+            //offset = el.canvas.getSelection().toDocumentFragment().offset,
+            dialog = Dialog.create({
+            title: gettext('Edit image'),
+            executeButtonText: gettext('Apply'),
+            cancelButtonText: gettext('Cancel'),
+            fields: [
+                {label: gettext('Image'), name: 'src', type: 'input', initialValue: el.wlxmlNode.getAttr('src'),
+                prePasteHandler: function(text) {
+                                    return this.wlxmlNode.document.getLinkForUrl(text);
+                                }.bind(this),
+                                description: '<a href="#-" class="attachment-library">attachment library</a>'
+            }
+            ]
+        });
+        e.preventDefault();
+        e.stopPropagation();
+
+        dialog.on('execute', function(event) {
+            el.wlxmlNode.document.transaction(function() {
+                el.wlxmlNode.setAttr('src', event.formData.src);
+                event.success();
+            }, {
+                metadata: {
+                    description: gettext('Edit image'),
+                    //fragment: doc.createFragment(doc.CaretFragment, {node: el.wlxmlNode.contents()[0], offset:offset})
+                },
+                success: function() {
+                    //el.canvas.select(doc.createFragment(doc.CaretFragment, {node: el.wlxmlNode.contents()[0], offset:offset}));
+                }
+            });
+        });
+        dialog.show();
+        $(".attachment-library", dialog.$el).on('click', function() {
+            attachments.select(function(v) {$("input", dialog.$el).val(v);});
+        });
+
+    },
+
+    deleteLink: function() {
+        var el = this,
+            doc = this.wlxmlNode.document;
+
+        el.wlxmlNode.document.transaction(function() {
+            var f = el.canvas.getSelection().toDocumentFragment(),
+                prefLen = 0,
+                ret;
+
+            if(el.wlxmlNode.isPrecededByTextNode()) {
+                prefLen = el.wlxmlNode.prev().getText().length;
+            }
+
+            ret = el.wlxmlNode.unwrapContent();
+            return doc.createFragment(doc.CaretFragment, {node: ret.element1, offset: prefLen + f.offset});
+        }, {
+            metadata: {
+                description: gettext('Remove link'),
+                fragment: doc.createFragment(doc.CaretFragment, {node: el.wlxmlNode.contents()[0], offset:0})
+            },
+            success: function(ret) {
+                el.canvas.select(ret);
+            }
+        });
+    },
+
+    getUrl: function(link) {
+        var pattern = /^[a-z]*:\/\//g;
+        if(!pattern.test(link)) {
+            link = 'http://' + link;
+        }
+        return this.wlxmlNode.document.getUrlForLink(link);
+    }
+});
+
+return linkElement;
+
+});
index 61d2abc..36163d1 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'),
+    attachments = require('views/attachments/attachments'),
     linkElement = Object.create(genericElement);
 
 
     linkElement = Object.create(genericElement);
 
 
@@ -52,7 +53,8 @@ _.extend(linkElement, {
                 {label: gettext('Link'), name: 'href', type: 'input', initialValue: el.wlxmlNode.getAttr('href'),
                 prePasteHandler: function(text) {
                                     return this.wlxmlNode.document.getLinkForUrl(text);
                 {label: gettext('Link'), name: 'href', type: 'input', initialValue: el.wlxmlNode.getAttr('href'),
                 prePasteHandler: function(text) {
                                     return this.wlxmlNode.document.getLinkForUrl(text);
-                                }.bind(this)
+                                }.bind(this),
+                                description: '<a href="#-" class="attachment-library">attachment library</a>'
             }
             ]
         });
             }
             ]
         });
@@ -74,6 +76,10 @@ _.extend(linkElement, {
             });
         });
         dialog.show();
             });
         });
         dialog.show();
+        $(".attachment-library", dialog.$el).on('click', function() {
+            attachments.select(function(v) {$("input", dialog.$el).val(v);});
+        });
+
     },
 
     deleteLink: function() {
     },
 
     deleteLink: function() {
index 2857736..432b15d 100644 (file)
@@ -3,8 +3,9 @@ define([
 'libs/underscore',
 'libs/text!./templates/main.html',
 'libs/text!./templates/item.html',
 'libs/underscore',
 'libs/text!./templates/main.html',
 'libs/text!./templates/item.html',
-'views/openSelect/openSelect'
-], function($, _, mainTemplate, itemTemplate, OpenSelectView) {
+'views/openSelect/openSelect',
+'views/attachments/attachments'
+], function($, _, mainTemplate, itemTemplate, OpenSelectView, attachments) {
 
 'use strict';
 /* globals gettext */
 
 'use strict';
 /* globals gettext */
@@ -104,6 +105,16 @@ _.extend(View.prototype, {
         });
         return toret;
     },
         });
         return toret;
     },
+    getIsFileForKey: function(key) {
+        var toret = false;
+        this.metadataConfig.some(function(configRow) {
+            if (configRow.key == key) {
+                toret = configRow.isFile || false;
+                return true
+            }
+        });
+        return toret;
+    },
     setMetadata: function(node) {
         this.dom.find('.rng-module-metadataEditor-addBtn').attr('disabled', !node);
         if(!node) {
     setMetadata: function(node) {
         this.dom.find('.rng-module-metadataEditor-addBtn').attr('disabled', !node);
         if(!node) {
@@ -118,6 +129,7 @@ _.extend(View.prototype, {
         });
     },
     addMetadataRow: function(row) {
         });
     },
     addMetadataRow: function(row) {
+        console.log(row);
         var newRow = $(_.template(itemTemplate)({key: row.getKey() || '', value: row.getValue() || ''}));
         newRow.appendTo(this.metaTable);
         newRow.data('row', row);
         var newRow = $(_.template(itemTemplate)({key: row.getKey() || '', value: row.getValue() || ''}));
         newRow.appendTo(this.metaTable);
         newRow.data('row', row);
@@ -134,6 +146,7 @@ _.extend(View.prototype, {
                 this.getValuesForKey(value).forEach(function(value) {
                     valueSelectView.addItem(value);
                 });
                 this.getValuesForKey(value).forEach(function(value) {
                     valueSelectView.addItem(value);
                 });
+                
             }.bind(this)
         });
         newRow.find('td:first').append(keySelectView.el).data('view', keySelectView);
             }.bind(this)
         });
         newRow.find('td:first').append(keySelectView.el).data('view', keySelectView);
@@ -152,7 +165,18 @@ _.extend(View.prototype, {
             }
         });
         newRow.find('td:nth-child(2)').append(valueSelectView.el).data('view', valueSelectView);
             }
         });
         newRow.find('td:nth-child(2)').append(valueSelectView.el).data('view', valueSelectView);
-        
+
+        if (this.getIsFileForKey(row.getKey())) {
+            var el = $("<a href='#-' class='attachment-library' style='float: right'>attachments</a>");
+            el.on('click', function() {
+                attachments.select(function(v) {
+                    valueSelectView.setInput(v);
+                });
+                return false;
+            });
+            newRow.find('td:nth-child(2)').append(el);
+        }
+
 
         this.metadataConfig.forEach(function(configRow) {
             keySelectView.addItem(configRow.key);
 
         this.metadataConfig.forEach(function(configRow) {
             keySelectView.addItem(configRow.key);
index 645f7ad..88544bf 100644 (file)
@@ -67,12 +67,13 @@ var createSwitchAction = function(createParams) {
 };
 
 var headerAction = createSwitchAction({name: 'switchToHeader', from: {tagName: 'div', klass: 'p'}, to: {tagName: 'header', klass: '', name: gettext('header')}}),
 };
 
 var headerAction = createSwitchAction({name: 'switchToHeader', from: {tagName: 'div', klass: 'p'}, to: {tagName: 'header', klass: '', name: gettext('header')}}),
-    paragraphAction = createSwitchAction({name: 'switchToParagraph', from: {tagName: 'header'}, to: {tagName: 'div', klass: 'p', name: gettext('paragraf')}});
+    paragraphAction = createSwitchAction({name: 'switchToParagraph', from: {tagName: 'header'}, to: {tagName: 'div', klass: 'p', name: gettext('paragraph')}}),
+    imageAction = createSwitchAction({name: 'switchToImage', from: {tagName: 'div'}, to: {tagName: 'div', klass: 'img', name: gettext('image')}});
 
 return {
 
 return {
-    actions: [headerAction, paragraphAction],
+    actions: [headerAction, paragraphAction, imageAction],
     canvasActionHandler: {
     canvasActionHandler: {
-        handles: [headerAction, paragraphAction],
+        handles: [headerAction, paragraphAction, imageAction],
         // handle: function(canvas, action, ret) {
         //     var params = {},
         //         f;
         // handle: function(canvas, action, ret) {
         //     var params = {},
         //         f;
diff --git a/src/editor/views/attachments/attachments.js b/src/editor/views/attachments/attachments.js
new file mode 100644 (file)
index 0000000..258a143
--- /dev/null
@@ -0,0 +1,61 @@
+define(function(require) {
+
+    'use strict';
+
+    var $ = require('libs/jquery'),
+        Dialog = require('views/dialog/dialog');
+
+
+
+// Move it somewhere else.
+var attachmentLibrary = function(callback, params) {
+    var dialog = Dialog.create({
+        title: gettext('Attachment library'),
+        executeButtonText: gettext('Select'),
+        cancelButtonText: gettext('Cancel'),
+    });
+
+    var output = "";
+
+    dialog.on('execute', function(event) {
+        callback($(".active", dialog.$el).attr('data-output'));
+        event.success();
+    });
+
+    dialog.show();
+    var body = $(".modal-body", dialog.$el);
+    $.ajax(config.documentGalleryUrl, {
+        dataType: 'json',
+        success: function(data, status, jqxhr) {
+            for (var i in data) {
+                var img = $("<img style='margin-right: 1em'>")
+                var div = $("<div style='border: 1px solid white'/>");
+                div.append(img);
+                div.append(data[i]['name'])
+                img.attr("src", data[i]['thumbnail_url']);
+                img.attr("title", data[i]['name']);
+                div.attr("data-output", 'file://' + data[i]['name']);
+                div.on('click', function() {
+                    $("div", body).attr('style', 'border: 1px solid white');
+                    $("div", body).removeClass('active');
+                    $(this).attr('style', 'border: 1px solid black');
+                    $(this).addClass('active');
+                });
+                body.append(div);
+            }
+            var editlink = $("<a target='_blank'>Manage attachments</a>");
+            editlink.attr('href', config.documentGalleryUrl);
+            body.append(editlink);
+        },
+    });
+};
+
+
+
+    return {
+        select: function(callback, params) {
+            return new attachmentLibrary(callback, params);
+        }
+    };
+
+});
\ No newline at end of file
index 1e527a6..301fb63 100644 (file)
@@ -2,7 +2,7 @@
     <div style="float: left; width:100px;"><%= label %>:</div>
     <select name="<%= name %>">
     <% options.forEach(function(option) { %>
     <div style="float: left; width:100px;"><%= label %>:</div>
     <select name="<%= name %>">
     <% options.forEach(function(option) { %>
-        <option value="<%= option.value %>"><%= option.text %></option>
+        <option <% if (initialValue == option.value) { %>selected="selected" <% } %>value="<%= option.value %>"><%= option.text %></option>
     <% }); %>
     </select>
     <span class="description"><%= description %></span>
     <% }); %>
     </select>
     <span class="description"><%= description %></span>