X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/620a7d196ada7e95c73418e92715076cfed39f76..15f4c3b:/src/editor/plugins/core/core.js?ds=sidebyside diff --git a/src/editor/plugins/core/core.js b/src/editor/plugins/core/core.js index 3921635..d2791d0 100644 --- a/src/editor/plugins/core/core.js +++ b/src/editor/plugins/core/core.js @@ -12,9 +12,33 @@ var _ = require('libs/underscore'), Dialog = require('views/dialog/dialog'), canvasElements = require('plugins/core/canvasElements'), metadataEditor = require('plugins/core/metadataEditor/metadataEditor'), - edumed = require('plugins/core/edumed/edumed'); + edumed = require('plugins/core/edumed/edumed'), + attachments = require('views/attachments/attachments'); + + +var exerciseFix = function(newNodes) { + var list, exercise, max, addedItem, answerValues; + if(newNodes.created.is('item')) { + list = newNodes.created.parent(); + exercise = list.parent(); + if(exercise && exercise.is('exercise')) { + if(exercise.is('exercise.order')) { + answerValues = exercise.object.getItems() + .map(function(item) { + if(!addedItem && item.node.sameNode(newNodes.created)) { + addedItem = item; + } + return item.getAnswer(); + }); + max = Math.max.apply(Math.max, answerValues); + addedItem.setAnswer(max + 1); + } + } + } +}; + plugin.documentExtension.textNode.transformations = { breakContent: { impl: function(args) { @@ -38,6 +62,21 @@ plugin.documentExtension.textNode.transformations = { return true; // break } }); + + /* + /* + This makes sure that adding a new item to the list in some of the edumed exercises + sets an answer attribute that makes sense (and not just copies it which would create + a duplicate value). + + This won't be neccessary when/if we introduce canvas element own key event handlers. + + Alternatively, WLXML elements could implement their own item split methods that we + would delegate to. + */ + exerciseFix(newNodes); + /* */ + parentDescribingNodes.forEach(function(node) { newNodes.first.append(node); }); @@ -83,6 +122,18 @@ plugin.documentExtension.textNode.transformations = { parent.contents().some(function(n) { return move(n, newNode); }); + if(newNodes.second.contents()[0].getText().length === 0) { + var textNode = newNodes.second.contents()[0]; + newNodes.second.detach(); + newNodes.second = parent; + emptyText = newNodes.second.append(textNode); + } + } + + var newNodeText = newNodes.second.contents()[0].getText(); + if(newNodes.second.is({tagName: 'header'}) && newNodeText === '') { + newNodes.second = newNodes.second.setTag('div'); + newNodes.second.setClass('p'); } return _.extend(newNodes, {emptyText: emptyText}); @@ -278,6 +329,13 @@ plugin.documentExtension.documentNode.transformations = { } }); return toret; + }, + insertNewNode: function () { + var node = this; + var newElement = this.document.createDocumentNode({tagName: 'div', attrs: {class: 'p'}}); + node.after(newElement); + newElement.append({text: ''}); + return newElement; } }; @@ -442,7 +500,7 @@ var createWrapTextAction = function(createParams) { }); } - if(params.fragment instanceof params.fragment.TextRangeFragment && params.fragment.hasSiblingBoundries()) { + if(params.fragment instanceof params.fragment.TextRangeFragment && params.fragment.hasSiblingBoundaries()) { parent = params.fragment.startNode.parent(); if(parent && parent.is(createParams.klass) || parent.isInside(createParams.klass)) { return _.extend(state, {allowed: false}); @@ -484,6 +542,7 @@ var createWrapTextAction = function(createParams) { }; + var createLinkFromSelection = function(callback, params) { var doc = params.fragment.document, dialog = Dialog.create({ @@ -494,7 +553,8 @@ var createLinkFromSelection = function(callback, params) { {label: gettext('Link'), name: 'href', type: 'input', prePasteHandler: function(text) { return params.fragment.document.getLinkForUrl(text); - }.bind(this) + }.bind(this), + description: '' + gettext('attachment library') + '' } ] }), @@ -520,6 +580,9 @@ var createLinkFromSelection = function(callback, params) { }); }); dialog.show(); + $(".attachment-library", dialog.$el).on('click', function() { + attachments.select(function(v) {$("input", dialog.$el).val(v);}); + }); }; var editLink = function(callback, params) { @@ -565,7 +628,7 @@ var linkAction = { } if(params.fragment instanceof params.fragment.TextRangeFragment) { - if(!params.fragment.hasSiblingBoundries() || params.fragment.startNode.parent().is('link')) { + if(!params.fragment.hasSiblingBoundaries() || params.fragment.startNode.parent().is('link')) { return {allowed: false}; } return { @@ -589,6 +652,7 @@ var linkAction = { } }; + var metadataParams = {}; plugin.actions = [