From 7b7f19b8680ed7653359bede5833d2cffc11ef8c Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Mon, 7 Mar 2016 14:46:47 +0100 Subject: [PATCH] local changes from server --- src/editor/entrypoint.js | 2 + src/editor/modules/data/data.js | 44 +++++- .../documentCanvas/canvas/documentElement.js | 1 + src/editor/modules/documentCanvas/nodes.less | 7 + .../documentHistory/documentHistory.js | 15 ++- .../documentHistory/documentHistory.less | 8 +- .../documentHistory/templates/item.html | 1 + .../documentHistory/templates/main.html | 7 +- src/editor/modules/mainBar/mainBar.js | 8 +- src/editor/modules/mainBar/template.html | 8 +- src/editor/modules/rng/rng.js | 23 ++-- src/editor/plugins/core/canvasElements.js | 7 +- src/editor/plugins/core/core.js | 13 +- src/editor/plugins/core/img/box.html | 7 + src/editor/plugins/core/img/imgElement.js | 126 ++++++++++++++++++ src/editor/plugins/core/links/linkElement.js | 8 +- .../plugins/core/metadataEditor/view.js | 30 ++++- src/editor/plugins/core/switch.js | 7 +- src/editor/views/attachments/attachments.js | 61 +++++++++ src/editor/views/dialog/templates/select.html | 2 +- 20 files changed, 350 insertions(+), 35 deletions(-) create mode 100644 src/editor/plugins/core/img/box.html create mode 100644 src/editor/plugins/core/img/imgElement.js create mode 100644 src/editor/views/attachments/attachments.js diff --git a/src/editor/entrypoint.js b/src/editor/entrypoint.js index b723517..13ca1ab 100644 --- a/src/editor/entrypoint.js +++ b/src/editor/entrypoint.js @@ -4,6 +4,8 @@ /* globals requirejs, editor_init */ requirejs.config({ + urlArgs: "bust=" + (new Date()).getTime(), + paths: { 'fnpjs': '../fnpjs', 'libs': '../../libs', diff --git a/src/editor/modules/data/data.js b/src/editor/modules/data/data.js index 0d556a2..67ab801 100644 --- a/src/editor/modules/data/data.js +++ b/src/editor/modules/data/data.js @@ -179,6 +179,12 @@ return function(sandbox) { 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'); @@ -275,6 +281,42 @@ return function(sandbox) { }); 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); @@ -285,4 +327,4 @@ return function(sandbox) { }; }; -}); \ No newline at end of file +}); diff --git a/src/editor/modules/documentCanvas/canvas/documentElement.js b/src/editor/modules/documentCanvas/canvas/documentElement.js index a1965cd..993064a 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -43,6 +43,7 @@ $.extend(DocumentElement.prototype, { this.state[key] = changes[key] = toUpdate[key]; } }.bind(this)); + console.log(changes); if(_.isFunction(this.onStateChange)) { this.onStateChange(changes); if(_.isBoolean(changes.active)) { diff --git a/src/editor/modules/documentCanvas/nodes.less b/src/editor/modules/documentCanvas/nodes.less index 35ac7a8..d33ea00 100644 --- a/src/editor/modules/documentCanvas/nodes.less +++ b/src/editor/modules/documentCanvas/nodes.less @@ -139,6 +139,13 @@ } +[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; diff --git a/src/editor/modules/documentHistory/documentHistory.js b/src/editor/modules/documentHistory/documentHistory.js index 7bbf32f..8cd4475 100644 --- a/src/editor/modules/documentHistory/documentHistory.js +++ b/src/editor/modules/documentHistory/documentHistory.js @@ -26,7 +26,11 @@ return function(sandbox) { }); 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) { @@ -56,21 +60,21 @@ return function(sandbox) { _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._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) { - return _.contains(this._selected, item.version); + return _.contains(this._selected, item.revision); }, getSelected: function() { return this._selected; @@ -81,17 +85,20 @@ return function(sandbox) { toggleButton('compare', false); toggleButton('display', false); toggleButton('restore', false); + toggleButton('publish', false); } 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); + toggleButton('publish', false); } else { toggleItemViews(true); } diff --git a/src/editor/modules/documentHistory/documentHistory.less b/src/editor/modules/documentHistory/documentHistory.less index 608c9df..9cf2e6a 100644 --- a/src/editor/modules/documentHistory/documentHistory.less +++ b/src/editor/modules/documentHistory/documentHistory.less @@ -11,13 +11,17 @@ font-weight: bold; } - .date, .author, .description { + .date, .author, .description, .published { margin: 5px 10px 0 40px; } - .description { + .description, .published { font-size: .9em; } + + .published { + color: #080; + } } .item.highlighted { diff --git a/src/editor/modules/documentHistory/templates/item.html b/src/editor/modules/documentHistory/templates/item.html index 1629226..a69c7d3 100644 --- a/src/editor/modules/documentHistory/templates/item.html +++ b/src/editor/modules/documentHistory/templates/item.html @@ -3,4 +3,5 @@
<%= date %>
<%= author %>
<%= description %>
+
<%= published %>
\ No newline at end of file diff --git a/src/editor/modules/documentHistory/templates/main.html b/src/editor/modules/documentHistory/templates/main.html index 83cd627..73a62d7 100644 --- a/src/editor/modules/documentHistory/templates/main.html +++ b/src/editor/modules/documentHistory/templates/main.html @@ -1,9 +1,10 @@
- - - + + + +
diff --git a/src/editor/modules/mainBar/mainBar.js b/src/editor/modules/mainBar/mainBar.js index e5cf522..4fdee83 100644 --- a/src/editor/modules/mainBar/mainBar.js +++ b/src/editor/modules/mainBar/mainBar.js @@ -12,7 +12,11 @@ return function(sandbox) { 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) { @@ -48,4 +52,4 @@ return function(sandbox) { }; -}); \ No newline at end of file +}); diff --git a/src/editor/modules/mainBar/template.html b/src/editor/modules/mainBar/template.html index 59f0708..934b3ea 100644 --- a/src/editor/modules/mainBar/template.html +++ b/src/editor/modules/mainBar/template.html @@ -1,12 +1,18 @@ \ No newline at end of file +
diff --git a/src/editor/modules/rng/rng.js b/src/editor/modules/rng/rng.js index fc8cd61..e330854 100644 --- a/src/editor/modules/rng/rng.js +++ b/src/editor/modules/rng/rng.js @@ -132,7 +132,13 @@ return function(sandbox) { }, 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); }, - displayVersion: function(event) { + displayVersion: function(revision) { /* 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); } }; diff --git a/src/editor/plugins/core/canvasElements.js b/src/editor/plugins/core/canvasElements.js index 0d7cffa..ab3332e 100644 --- a/src/editor/plugins/core/canvasElements.js +++ b/src/editor/plugins/core/canvasElements.js @@ -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 - linkElement = require('./links/linkElement'); + linkElement = require('./links/linkElement'), + imgElement = require('./img/imgElement') + ; var widgets = { footnoteHandler: function(clickHandler) { @@ -113,7 +115,8 @@ $.extend(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} ]; diff --git a/src/editor/plugins/core/core.js b/src/editor/plugins/core/core.js index 31ac09d..bc41e00 100644 --- a/src/editor/plugins/core/core.js +++ b/src/editor/plugins/core/core.js @@ -12,7 +12,10 @@ var _ = require('libs/underscore'), 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) { @@ -520,6 +523,7 @@ var createWrapTextAction = function(createParams) { }; + 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); - }.bind(this) + }.bind(this), + description: 'attachment library' } ] }), @@ -556,6 +561,9 @@ var createLinkFromSelection = function(callback, params) { }); }); dialog.show(); + $(".attachment-library", dialog.$el).on('click', function() { + attachments.select(function(v) {$("input", dialog.$el).val(v);}); + }); }; var editLink = function(callback, params) { @@ -625,6 +633,7 @@ var linkAction = { } }; + 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 index 0000000..e07a7f3 --- /dev/null +++ b/src/editor/plugins/core/img/box.html @@ -0,0 +1,7 @@ +
+ <%= text %>
-- + + <%= gettext('change') %> + +
diff --git a/src/editor/plugins/core/img/imgElement.js b/src/editor/plugins/core/img/imgElement.js new file mode 100644 index 0000000..a83fb33 --- /dev/null +++ b/src/editor/plugins/core/img/imgElement.js @@ -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: 'attachment library' + } + ] + }); + 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; + +}); diff --git a/src/editor/plugins/core/links/linkElement.js b/src/editor/plugins/core/links/linkElement.js index 61d2abc..36163d1 100644 --- a/src/editor/plugins/core/links/linkElement.js +++ b/src/editor/plugins/core/links/linkElement.js @@ -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'), + attachments = require('views/attachments/attachments'), 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); - }.bind(this) + }.bind(this), + description: 'attachment library' } ] }); @@ -74,6 +76,10 @@ _.extend(linkElement, { }); }); dialog.show(); + $(".attachment-library", dialog.$el).on('click', function() { + attachments.select(function(v) {$("input", dialog.$el).val(v);}); + }); + }, deleteLink: function() { diff --git a/src/editor/plugins/core/metadataEditor/view.js b/src/editor/plugins/core/metadataEditor/view.js index 2857736..432b15d 100644 --- a/src/editor/plugins/core/metadataEditor/view.js +++ b/src/editor/plugins/core/metadataEditor/view.js @@ -3,8 +3,9 @@ define([ '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 */ @@ -104,6 +105,16 @@ _.extend(View.prototype, { }); 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) { @@ -118,6 +129,7 @@ _.extend(View.prototype, { }); }, addMetadataRow: function(row) { + console.log(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); }); + }.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); - + + if (this.getIsFileForKey(row.getKey())) { + var el = $("attachments"); + 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); diff --git a/src/editor/plugins/core/switch.js b/src/editor/plugins/core/switch.js index 645f7ad..88544bf 100644 --- a/src/editor/plugins/core/switch.js +++ b/src/editor/plugins/core/switch.js @@ -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')}}), - 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 { - actions: [headerAction, paragraphAction], + actions: [headerAction, paragraphAction, imageAction], canvasActionHandler: { - handles: [headerAction, paragraphAction], + handles: [headerAction, paragraphAction, imageAction], // 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 index 0000000..258a143 --- /dev/null +++ b/src/editor/views/attachments/attachments.js @@ -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 = $("") + var div = $("
"); + 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 = $("Manage attachments"); + editlink.attr('href', config.documentGalleryUrl); + body.append(editlink); + }, + }); +}; + + + + return { + select: function(callback, params) { + return new attachmentLibrary(callback, params); + } + }; + +}); \ No newline at end of file diff --git a/src/editor/views/dialog/templates/select.html b/src/editor/views/dialog/templates/select.html index 1e527a6..301fb63 100644 --- a/src/editor/views/dialog/templates/select.html +++ b/src/editor/views/dialog/templates/select.html @@ -2,7 +2,7 @@
<%= label %>:
<%= description %> -- 2.20.1