1 define(function(require) {
7 var _ = require('libs/underscore'),
8 Dialog = require('views/dialog/dialog'),
9 wlxml = require('wlxml/wlxml'),
10 logging = require('fnpjs/logging/logging');
13 var logger = logging.getLogger('document');
15 var Document = function() {
16 wlxml.WLXMLDocument.apply(this, Array.prototype.slice.call(arguments, 0));
19 Document.prototype = Object.create(wlxml.WLXMLDocument.prototype);
21 _.extend(Document.prototype, {
22 transaction: function(body, params) {
23 params = params || {};
24 var error = params.error;
25 params.error = function(e) {
28 var dialog = Dialog.create({
29 title: gettext('Error'),
30 text: gettext('Something wrong happend when applying this change so it was undone.'),
31 executeButtonText: gettext('Close')
37 dialog.on('execute', function(e) {
41 return wlxml.WLXMLDocument.prototype.transaction.call(this, body, params);
43 getUrlForLink: function(link) {
44 var cfg = this.options.editorConfig;
45 if(link.substr(0, 7) === 'file://' && cfg && cfg.documentAttachmentUrl) {
46 link = cfg.documentAttachmentUrl(link.substr(7));
50 getLinkForUrl: function(url) {
52 var baseUrl = function(url) {return url.split('/').slice(0,-1).join('/');};
53 if(baseUrl(url) === baseUrl(window.location.origin + this.getUrlForLink('file://test'))) {
54 return 'file://' + _.last(url.split('/'));
58 setProperty: function(propName, propValue) {
59 if(this.properties[propName] !== propValue) {
60 this.properties[propName] = propValue;
61 this.trigger('propertyChanged', propName, propValue);