From 5028701711e4a1ee85e88f5ff7f1caf911dad8e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 6 Aug 2014 11:45:39 +0200 Subject: [PATCH] editor: core plugin - edumed - remove execise button --- .../plugins/core/edumed/choice/choiceBase.js | 6 +-- src/editor/plugins/core/edumed/edumed.less | 8 ++++ src/editor/plugins/core/edumed/elementBase.js | 48 +++++++++++++++++++ .../plugins/core/edumed/gaps/element.js | 6 +-- .../plugins/core/edumed/order/element.js | 6 +-- .../plugins/core/edumed/replace/element.js | 6 +-- 6 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 src/editor/plugins/core/edumed/elementBase.js diff --git a/src/editor/plugins/core/edumed/choice/choiceBase.js b/src/editor/plugins/core/edumed/choice/choiceBase.js index dc8fe0a..3bd6ed5 100644 --- a/src/editor/plugins/core/edumed/choice/choiceBase.js +++ b/src/editor/plugins/core/edumed/choice/choiceBase.js @@ -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); diff --git a/src/editor/plugins/core/edumed/edumed.less b/src/editor/plugins/core/edumed/edumed.less index b503d5a..b78f792 100644 --- a/src/editor/plugins/core/edumed/edumed.less +++ b/src/editor/plugins/core/edumed/edumed.less @@ -18,4 +18,12 @@ .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 index 0000000..ad7e0b8 --- /dev/null +++ b/src/editor/plugins/core/edumed/elementBase.js @@ -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 = $('
x
'); + 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 diff --git a/src/editor/plugins/core/edumed/gaps/element.js b/src/editor/plugins/core/edumed/gaps/element.js index f068de9..294ac0a 100644 --- a/src/editor/plugins/core/edumed/gaps/element.js +++ b/src/editor/plugins/core/edumed/gaps/element.js @@ -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); diff --git a/src/editor/plugins/core/edumed/order/element.js b/src/editor/plugins/core/edumed/order/element.js index 7c5e383..b113199 100644 --- a/src/editor/plugins/core/edumed/order/element.js +++ b/src/editor/plugins/core/edumed/order/element.js @@ -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); diff --git a/src/editor/plugins/core/edumed/replace/element.js b/src/editor/plugins/core/edumed/replace/element.js index 3f12f26..128fe50 100644 --- a/src/editor/plugins/core/edumed/replace/element.js +++ b/src/editor/plugins/core/edumed/replace/element.js @@ -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); -- 2.20.1