some other minor changes from milpeer
[fnpeditor.git] / src / editor / plugins / core / edumed / elementBase.js
1 define(function(require) {
2     
3 'use strict';
4
5 /* globals gettext */
6
7 var $ = require('libs/jquery'),
8     _ = require('libs/underscore'),
9     documentElement = require('modules/documentCanvas/canvas/documentElement'),
10     Dialog = require('views/dialog/dialog');
11
12     
13 var choiceBase = Object.create(documentElement.DocumentNodeElement.prototype);
14 _.extend(choiceBase, {
15     init: function() {
16         var el = this;
17         documentElement.DocumentNodeElement.prototype.init.call(this);
18         this.x = $('<div class="edumed-exercise-remove btn btn-mini btn-danger">x</div>');
19         this.x.on('click', function() {
20             var dialog = Dialog.create({
21                 title: gettext('Removing exercise'),
22                 text: gettext('Do you really want to remove this exercise?'),
23                 executeButtonText: gettext('Yes'),
24                 cancelButtonText: gettext('No, don\'t do anything!')
25             });
26             dialog.on('execute', function(event) {
27                 el.canvas.wlxmlDocument.transaction(function() {
28                     el.wlxmlNode.detach();
29                 }, {
30                     metadata: {
31                         description: gettext('Removing exercise')
32                     },
33                     success: function() {
34                         event.success();
35                     }
36                 });
37             });
38             dialog.show();
39
40         });
41
42         this.addWidget(this.x);
43     },
44 });
45
46 return choiceBase;
47
48 });