/* globals requirejs, editor_init */
requirejs.config({
+ urlArgs: "bust=" + (new Date()).getTime(),
+
paths: {
'fnpjs': '../fnpjs',
'libs': '../../libs',
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.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);
};
};
-});
\ No newline at end of file
+});
this.state[key] = changes[key] = toUpdate[key];
}
}.bind(this));
+ console.log(changes);
if(_.isFunction(this.onStateChange)) {
this.onStateChange(changes);
if(_.isBoolean(changes.active)) {
}
+[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;
});
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) {
_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;
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);
}
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 {
<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 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>
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) {
};
-});
\ No newline at end of file
+});
<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>
+ <!--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>
-</div>
\ No newline at end of file
+</div>
},
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.'});
}
};
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);
}
};
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) {
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}
];
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 createLinkFromSelection = function(callback, params) {
var doc = params.fragment.document,
dialog = Dialog.create({
{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>'
}
]
}),
});
});
dialog.show();
+ $(".attachment-library", dialog.$el).on('click', function() {
+ attachments.select(function(v) {$("input", dialog.$el).val(v);});
+ });
};
var editLink = function(callback, params) {
}
};
+
var metadataParams = {};
plugin.actions = [
--- /dev/null
+<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>
--- /dev/null
+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;
+
+});
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);
{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>'
}
]
});
});
});
dialog.show();
+ $(".attachment-library", dialog.$el).on('click', function() {
+ attachments.select(function(v) {$("input", dialog.$el).val(v);});
+ });
+
},
deleteLink: function() {
'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 */
});
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) {
});
},
addMetadataRow: function(row) {
+ console.log(row);
var newRow = $(_.template(itemTemplate)({key: row.getKey() || '', value: row.getValue() || ''}));
newRow.appendTo(this.metaTable);
newRow.data('row', row);
this.getValuesForKey(value).forEach(function(value) {
valueSelectView.addItem(value);
});
+
}.bind(this)
});
newRow.find('td:first').append(keySelectView.el).data('view', keySelectView);
}
});
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);
};
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;
--- /dev/null
+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
<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>