X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/f61fd6fa1d5871782b079ee50fb6bb10777cadc2..84eba72af147a175fb93b7305c1d42b0a4987a8c:/modules/rng/rng.js?ds=inline diff --git a/modules/rng/rng.js b/modules/rng/rng.js index 16a6d25..4189902 100644 --- a/modules/rng/rng.js +++ b/modules/rng/rng.js @@ -35,6 +35,7 @@ return function(sandbox) { if(slug === 'sourceEditor') { doc = sandbox.getModule('sourceEditor').getDocument(); reason = 'source_edit'; + dirty.sourceEditor = false; } if(slug === 'editor') { var doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument(); @@ -42,30 +43,44 @@ return function(sandbox) { doc = sandbox.getModule('metadataEditor').attachMetadata(doc); } reason = 'edit'; + dirty.documentCanvas = dirty.metadataEditor = false; } sandbox.getModule('data').commitDocument(doc, reason); } } var commands = { - highlightDocumentNode: function(wlxmlNode, origin) { + highlightDocumentNode: function(canvasNode, origin) { ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) { if(!origin || moduleName != origin) - sandbox.getModule(moduleName).highlightNode(wlxmlNode) + sandbox.getModule(moduleName).highlightNode(canvasNode) }); }, - dimDocumentNode: function(wlxmlNode, origin) { + dimDocumentNode: function(canvasNode, origin) { ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) { if(!origin || moduleName != origin) - sandbox.getModule(moduleName).dimNode(wlxmlNode) + sandbox.getModule(moduleName).dimNode(canvasNode) }); }, - selectNode: function(wlxmlNode, origin) { - sandbox.getModule('documentCanvas').selectNode(wlxmlNode); - sandbox.getModule('nodePane').setNode(wlxmlNode); - sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode); - sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode); + selectNode: function(canvasNode, origin) { + sandbox.getModule('documentCanvas').selectNode(canvasNode); + sandbox.getModule('nodePane').setNode(canvasNode); + sandbox.getModule('nodeFamilyTree').setNode(canvasNode); + sandbox.getModule('nodeBreadCrumbs').setNode(canvasNode); + }, + resetDocument: function(document, reason) { + var modules = []; + if(reason === 'source_edit') + modules = ['documentCanvas', 'metadataEditor']; + else if (reason === 'edit') + modules = ['sourceEditor']; + else if (reason === 'revert') + modules = ['documentCanvas', 'metadataEditor', 'sourceEditor']; + + modules.forEach(function(moduleName) { + sandbox.getModule(moduleName).setDocument(document); + }); } } @@ -81,7 +96,7 @@ return function(sandbox) { views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView()); addMainTab('Edytor', 'editor', views.visualEditing.getAsView()); - + addMainTab(gettext('Source'), 'sourceEditor', ''); addMainTab('Historia', 'history', views.diffLayout.getAsView()); sandbox.getDOM().append(views.mainLayout.getAsView()); @@ -120,15 +135,7 @@ return function(sandbox) { }); }, documentChanged: function(document, reason) { - var modules = []; - if(reason === 'source_edit') - modules = ['documentCanvas', 'metadataEditor']; - else if (reason === 'edit') - modules = ['sourceEditor']; - - modules.forEach(function(moduleName) { - sandbox.getModule(moduleName).setDocument(document); - }); + commands.resetDocument(document, reason); }, savingStarted: function() { sandbox.getModule('mainBar').setCommandEnabled('save', false); @@ -138,16 +145,27 @@ return function(sandbox) { sandbox.getModule('mainBar').setCommandEnabled('save', true); sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'}); }, + restoringStarted: function(event) { + sandbox.getModule('mainBar').setCommandEnabled('save', false); + sandbox.getModule('indicator').showMessage(gettext('Restoring version ') + event.version + '...'); + }, historyItemAdded: function(item) { sandbox.getModule('documentHistory').addHistory([item], {animate: true}); }, diffFetched: function(diff) { sandbox.getModule('diffViewer').setDiff(diff); + }, + documentReverted: function(event) { + commands.resetDocument(event.document, 'revert'); + sandbox.getModule('mainBar').setCommandEnabled('save', true); + sandbox.getModule('indicator').clearMessage({message:'Wersja ' + event.reverted_version + ' przywrócona'}); + sandbox.getModule('mainBar').setVersion(event.current_version); } } eventHandlers.mainBar = { ready: function() { + sandbox.getModule('mainBar').setVersion(sandbox.getModule('data').getDocumentVersion()); views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView()); }, 'cmd.save': function() { @@ -173,20 +191,20 @@ return function(sandbox) { dirty.documentCanvas = false; }, - nodeSelected: function(wlxmlNode) { - commands.selectNode(wlxmlNode); + nodeSelected: function(canvasNode) { + commands.selectNode(canvasNode); }, contentChanged: function() { dirty.documentCanvas = true; }, - nodeHovered: function(wlxmlNode) { - commands.highlightDocumentNode(wlxmlNode); + nodeHovered: function(canvasNode) { + commands.highlightDocumentNode(canvasNode); }, - nodeBlured: function(wlxmlNode) { - commands.dimDocumentNode(wlxmlNode); + nodeBlured: function(canvasNode) { + commands.dimDocumentNode(canvasNode); } }; @@ -217,14 +235,14 @@ return function(sandbox) { ready: function() { views.currentNodePaneLayout.appendView(sandbox.getModule('nodeFamilyTree').getView()); }, - nodeEntered: function(wlxmlNode) { - commands.highlightDocumentNode(wlxmlNode, 'nodeFamilyTree'); + nodeEntered: function(canvasNode) { + commands.highlightDocumentNode(canvasNode, 'nodeFamilyTree'); }, - nodeLeft: function(wlxmlNode) { - commands.dimDocumentNode(wlxmlNode, 'nodeFamilyTree'); + nodeLeft: function(canvasNode) { + commands.dimDocumentNode(canvasNode, 'nodeFamilyTree'); }, - nodeSelected: function(wlxmlNode) { - commands.selectNode(wlxmlNode); + nodeSelected: function(canvasNode) { + commands.selectNode(canvasNode); } }; @@ -236,11 +254,10 @@ return function(sandbox) { sandbox.getModule('documentCanvas').toggleGrid(toggle); }, newNodeRequested: function(wlxmlTag, wlxmlClass) { - if(window.getSelection().isCollapsed) { sandbox.getModule('documentCanvas').insertNewNode(wlxmlTag, wlxmlClass); - } else { - sandbox.getModule('documentCanvas').wrapSelectionWithNewNode(wlxmlTag, wlxmlClass); - } + }, + command: function(cmd, meta) { + sandbox.getModule('documentCanvas').command(cmd, meta); } }; @@ -248,14 +265,14 @@ return function(sandbox) { ready: function() { views.visualEditing.setView('statusBar', sandbox.getModule('nodeBreadCrumbs').getView()); }, - nodeHighlighted: function(wlxmlNode) { - commands.highlightDocumentNode(wlxmlNode, 'nodeBreadCrumbs'); + nodeHighlighted: function(canvasNode) { + commands.highlightDocumentNode(canvasNode, 'nodeBreadCrumbs'); }, - nodeDimmed: function(wlxmlNode) { - commands.dimDocumentNode(wlxmlNode, 'nodeBreadCrumbs'); + nodeDimmed: function(canvasNode) { + commands.dimDocumentNode(canvasNode, 'nodeBreadCrumbs'); }, - nodeSelected: function(wlxmlNode) { - commands.selectNode(wlxmlNode); + nodeSelected: function(canvasNode) { + commands.selectNode(canvasNode); } } @@ -266,6 +283,12 @@ return function(sandbox) { }, compare: function(ver1, ver2) { sandbox.getModule('data').fetchDiff(ver1, ver2); + }, + restoreVersion: function(event) { + sandbox.getModule('data').restoreVersion(event); + }, + displayVersion: function(event) { + window.open('/' + gettext('editor') + '/' + sandbox.getModule('data').getDocumentId() + '?version=' + event.version, _.uniqueId()); } }