From cb4e9ba9176780ab6b194170826bbfbf84f27295 Mon Sep 17 00:00:00 2001 From: Andrew MacDonald Date: Tue, 31 Mar 2015 11:51:38 -0400 Subject: [PATCH] Can now change schema for current document #252 --- src/js/dialogs/settings.js | 6 +++--- src/js/modules/structureTree.js | 4 ++++ src/js/schema/schemaManager.js | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/js/dialogs/settings.js b/src/js/dialogs/settings.js index 6141fa0..8533d74 100644 --- a/src/js/dialogs/settings.js +++ b/src/js/dialogs/settings.js @@ -242,9 +242,9 @@ return function(writer, config) { } settings.showStructBrackets = $('#showstructbrackets').prop('checked'); - // TODO add handling for schemaChanged - w.schemaManager.schemaId = $('select[name="schema"]', $settingsDialog).val(); - w.event('schemaChanged').publish(w.schemaManager.schemaId); + var schemaId = $('select[name="schema"]', $settingsDialog).val(); + + w.event('schemaChanged').publish(schemaId); var styles = { fontSize: settings.fontSize, diff --git a/src/js/modules/structureTree.js b/src/js/modules/structureTree.js index 768b83a..c17ce2d 100644 --- a/src/js/modules/structureTree.js +++ b/src/js/modules/structureTree.js @@ -189,6 +189,10 @@ return function(config) { }); treeRef.delete_node('#cwrc_tree_root'); var rootNode = $('[_tag="'+w.root+'"]', w.editor.getBody()); + if (rootNode.length === 0) { + // fallback if schema/root has changed + rootNode = $('[_tag]', w.editor.getBody()).first(); + } var rootData = _processNode(rootNode, 0); if (rootData != null) { rootData.li_attr.id = 'cwrc_tree_root'; diff --git a/src/js/schema/schemaManager.js b/src/js/schema/schemaManager.js index bd1c7f2..464e0bd 100644 --- a/src/js/schema/schemaManager.js +++ b/src/js/schema/schemaManager.js @@ -290,6 +290,11 @@ return function(writer, config) { } }; + w.event('schemaChanged').subscribe(function(schemaId) { + w.schemaManager.schemaId = schemaId; + w.schemaManager.loadSchema(schemaId, false, true, function() {}); + }); + return sm; };