'wlxml/wlxml',
'wlxml/extensions/list/list',
'fnpjs/logging/logging',
- 'fnpjs/datetime'
-], function($, Dialog, wlxml, listExtension, logging, datetime) {
+ 'fnpjs/datetime',
+ './document'
+], function($, Dialog, wlxml, listExtension, logging, datetime, Document) {
'use strict';
/* global gettext, alert, window */
var loadDocument = function(text, isDraft, draftTimestamp) {
logger.debug('loading document');
try {
- wlxmlDocument = wlxml.WLXMLDocumentFromXML(text);
+ wlxmlDocument = wlxml.WLXMLDocumentFromXML(text, {}, Document);
} catch(e) {
logger.exception(e);
alert(gettext('This document contains errors and can\'t be loaded. :(')); // TODO
- wlxmlDocument = wlxml.WLXMLDocumentFromXML(stubDocument);
+ wlxmlDocument = wlxml.WLXMLDocumentFromXML(stubDocument, {}, Document);
}
wlxmlDocument.registerExtension(listExtension);
--- /dev/null
+define(function(require) {
+
+'use strict';
+
+/* globals gettext */
+
+var _ = require('libs/underscore'),
+ Dialog = require('views/dialog/dialog'),
+ wlxml = require('wlxml/wlxml'),
+ logging = require('fnpjs/logging/logging');
+
+
+var logger = logging.getLogger('document');
+
+var Document = function() {
+ wlxml.WLXMLDocument.apply(this, Array.prototype.slice.call(arguments, 0));
+};
+Document.prototype = Object.create(wlxml.WLXMLDocument.prototype);
+
+_.extend(Document.prototype, {
+ transaction: function(body, params) {
+ params = params || {};
+ var error = params.error;
+ params.error = function(e) {
+ logger.exception(e);
+
+ var dialog = Dialog.create({
+ title: gettext('Error'),
+ text: gettext('Something wrong happend when applying this change so it was undone.'),
+ executeButtonText: gettext('Close')
+ });
+ dialog.show();
+ if(error) {
+ error(e);
+ }
+ dialog.on('execute', function(e) {
+ e.success();
+ });
+ }.bind(this);
+ return wlxml.WLXMLDocument.prototype.transaction.call(this, body, params);
+ }
+});
+
+return Document;
+
+});
\ No newline at end of file
var insertNode = function(insertion, callback) {
var doc = canvas.wlxmlDocument,
- node, metadata, creator, dialog;
+ metadata, creator, dialog;
var execCallback = function(node) {
if(callback) {
if(params.wlxmlTag === 'aside' && params.wlxmlClass === 'comment') {
doc.transaction(function() {
- node = insertion();
+ var node = insertion();
if(user) {
creator = user.name;
if(user.email) {
metadata = node.getMetadata();
metadata.add({key: 'creator', value: creator});
metadata.add({key: 'date', value: datetime.currentStrfmt()});
+ return node;
+ }, {
+ success: execCallback
});
- execCallback(node);
} else if(params.wlxmlClass === 'link') {
dialog = Dialog.create({
title: gettext('Create link'),
});
dialog.on('execute', function(event) {
doc.transaction(function() {
- node = insertion();
+ var node = insertion();
node.setAttr('href', event.formData.href);
event.success();
+ return node;
+ }, {
+ success: execCallback
});
- execCallback(node);
});
dialog.show();
} else {
doc.transaction(function() {
- node = insertion();
- });
- execCallback(node);
+ return insertion();
+ }, {success: execCallback});
}
};