X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/f61fd6fa1d5871782b079ee50fb6bb10777cadc2..3892eb4ed993ba60f53f3daa35110ed1c99f8fe1:/modules/rng/rng.js diff --git a/modules/rng/rng.js b/modules/rng/rng.js index 16a6d25..643b683 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,6 +43,7 @@ return function(sandbox) { doc = sandbox.getModule('metadataEditor').attachMetadata(doc); } reason = 'edit'; + dirty.documentCanvas = dirty.metadataEditor = false; } sandbox.getModule('data').commitDocument(doc, reason); } @@ -66,6 +68,19 @@ return function(sandbox) { sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode); sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode); + }, + 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() { @@ -266,6 +284,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()); } }