editor: core plugin - edumed - remove execise button
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Wed, 6 Aug 2014 09:45:39 +0000 (11:45 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 14 Aug 2014 14:26:13 +0000 (16:26 +0200)
src/editor/plugins/core/edumed/choice/choiceBase.js
src/editor/plugins/core/edumed/edumed.less
src/editor/plugins/core/edumed/elementBase.js [new file with mode: 0644]
src/editor/plugins/core/edumed/gaps/element.js
src/editor/plugins/core/edumed/order/element.js
src/editor/plugins/core/edumed/replace/element.js

index dc8fe0a..3bd6ed5 100644 (file)
@@ -4,14 +4,14 @@ define(function(require) {
 
 var $ = require('libs/jquery'),
     _ = require('libs/underscore'),
-    documentElement = require('modules/documentCanvas/canvas/documentElement'),
+    elementBase = require('plugins/core/edumed/elementBase'),
     template = require('libs/text!./element.html');
 
 
-var choiceBase = Object.create(documentElement.DocumentNodeElement.prototype);
+var choiceBase = Object.create(elementBase);
 _.extend(choiceBase, {
     init: function() {
-        documentElement.DocumentNodeElement.prototype.init.call(this);
+        elementBase.init.call(this);
         this.view = $(_.template(template)({type: this.type}));
         this._container().append(this.view);
 
index b503d5a..b78f792 100644 (file)
     .btn {
         line-height: 12px;
     }
+}
+
+.edumed-exercise-remove {
+    position: absolute;
+    top: 20px;
+    right: 5px;
+    padding: 0 3px;
+    line-height: 15px;
 }
\ No newline at end of file
diff --git a/src/editor/plugins/core/edumed/elementBase.js b/src/editor/plugins/core/edumed/elementBase.js
new file mode 100644 (file)
index 0000000..ad7e0b8
--- /dev/null
@@ -0,0 +1,48 @@
+define(function(require) {
+    
+'use strict';
+
+/* globals gettext */
+
+var $ = require('libs/jquery'),
+    _ = require('libs/underscore'),
+    documentElement = require('modules/documentCanvas/canvas/documentElement'),
+    Dialog = require('views/dialog/dialog');
+
+    
+var choiceBase = Object.create(documentElement.DocumentNodeElement.prototype);
+_.extend(choiceBase, {
+    init: function() {
+        var el = this;
+        documentElement.DocumentNodeElement.prototype.init.call(this);
+        this.x = $('<div class="edumed-exercise-remove btn btn-mini btn-danger">x</div>');
+        this.x.on('click', function() {
+            var dialog = Dialog.create({
+                title: 'Removing exercise',
+                text: gettext('Do you really want to remove this exercise?'),
+                executeButtonText: gettext('Yes'),
+                cancelButtonText: gettext('No, don\'t do anything!')
+            });
+            dialog.on('execute', function(event) {
+                el.canvas.wlxmlDocument.transaction(function() {
+                    el.wlxmlNode.detach();
+                }, {
+                    metadata: {
+                        description: gettext('Removing exercise')
+                    },
+                    success: function() {
+                        event.success();
+                    }
+                });
+            });
+            dialog.show();
+
+        });
+
+        this.addWidget(this.x);
+    },
+});
+
+return choiceBase;
+
+});
\ No newline at end of file
index f068de9..294ac0a 100644 (file)
@@ -5,13 +5,13 @@ define(function(require) {
 
 var $ = require('libs/jquery'),
     _ = require('libs/underscore'),
-    documentElement = require('modules/documentCanvas/canvas/documentElement'),
+    elementBase = require('plugins/core/edumed/elementBase'),
     viewTemplate = require('libs/text!./view.html');
 
-var OrderExerciceElement = Object.create(documentElement.DocumentNodeElement.prototype);
+var OrderExerciceElement = Object.create(elementBase);
 _.extend(OrderExerciceElement, {
     init: function() {
-        documentElement.DocumentNodeElement.prototype.init.call(this);
+        elementBase.init.call(this);
         var view  = $(_.template(viewTemplate)());
         this._container().append(view);
 
index 7c5e383..b113199 100644 (file)
@@ -6,13 +6,13 @@ define(function(require) {
 
 var _ = require('libs/underscore');
 
-var documentElement = require('modules/documentCanvas/canvas/documentElement'),
+var elementBase = require('plugins/core/edumed/elementBase'),
     OrderExerciseView = require('./view');
 
-var OrderExerciceElement = Object.create(documentElement.DocumentNodeElement.prototype);
+var OrderExerciceElement = Object.create(elementBase);
 _.extend(OrderExerciceElement, {
     init: function() {
-        documentElement.DocumentNodeElement.prototype.init.call(this);
+        elementBase.init.call(this);
         
         this.view = new OrderExerciseView(this, this.wlxmlNode);
         this._container().append(this.view.dom);
index 3f12f26..128fe50 100644 (file)
@@ -5,7 +5,7 @@ define(function(require) {
 
 var $ = require('libs/jquery'),
     _ = require('libs/underscore'),
-    documentElement = require('modules/documentCanvas/canvas/documentElement'),
+    elementBase = require('plugins/core/edumed/elementBase'),
     genericElement = require('modules/documentCanvas/canvas/genericElement'),
     viewTemplate = require('libs/text!./view.html'),
     tipTemplate = require('libs/text!./tip.html');
@@ -36,10 +36,10 @@ _.extend(AnswerElement, {
     }
 });
 
-var ReplaceExerciseElement = Object.create(documentElement.DocumentNodeElement.prototype);
+var ReplaceExerciseElement = Object.create(elementBase);
 _.extend(ReplaceExerciseElement, {
     init: function() {
-        documentElement.DocumentNodeElement.prototype.init.call(this);
+        elementBase.init.call(this);
         var view  = $(_.template(viewTemplate)());
         this._container().append(view);