editor: Setting descriptions for transactions performed in actions
[fnpeditor.git] / src / editor / modules / data / document.js
1 define(function(require) {
2     
3 'use strict';
4
5 /* globals gettext */
6
7 var _ = require('libs/underscore'),
8     Dialog = require('views/dialog/dialog'),
9     wlxml = require('wlxml/wlxml'),
10     logging = require('fnpjs/logging/logging');
11
12
13 var logger = logging.getLogger('document');
14
15 var Document = function() {
16     wlxml.WLXMLDocument.apply(this, Array.prototype.slice.call(arguments, 0));
17 };
18 Document.prototype = Object.create(wlxml.WLXMLDocument.prototype);
19
20 _.extend(Document.prototype, {
21     transaction: function(body, params) {
22         params = params || {};
23         var error = params.error;
24         params.error = function(e) {
25             logger.exception(e);
26
27             var dialog = Dialog.create({
28                 title: gettext('Error'),
29                 text: gettext('Something wrong happend when applying this change so it was undone.'),
30                 executeButtonText: gettext('Close')
31             });
32             dialog.show();
33             if(error) {
34                 error(e);
35             }
36             dialog.on('execute', function(e) {
37                 e.success();
38             });
39         }.bind(this);
40         return wlxml.WLXMLDocument.prototype.transaction.call(this, body, params);
41     }
42 });
43
44 return Document;
45
46 });