X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/cb800d0ee02280d6e2663cf0524fb74681c8173e..6d45e6495494b30ce0cd662a179faae070e51a6a:/modules/rng/rng.js diff --git a/modules/rng/rng.js b/modules/rng/rng.js index fe666e0..276b0db 100644 --- a/modules/rng/rng.js +++ b/modules/rng/rng.js @@ -4,7 +4,8 @@ define([ 'views/tabs/tabs', 'libs/text!./mainLayout.html', 'libs/text!./editingLayout.html', -], function(layout, vbox, tabs, mainLayoutTemplate, visualEditingLayoutTemplate) { +'libs/text!./diffLayout.html', +], function(layout, vbox, tabs, mainLayoutTemplate, visualEditingLayoutTemplate, diffLayoutTemplate) { 'use strict'; @@ -30,16 +31,21 @@ return function(sandbox) { } if(tabIsDirty(slug)) { + var reason, doc; if(slug === 'sourceEditor') { - sandbox.getModule('data').commitDocument(sandbox.getModule('sourceEditor').getDocument(), 'source_edit'); + 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(); if(dirty.metadataEditor) { doc = sandbox.getModule('metadataEditor').attachMetadata(doc); } - sandbox.getModule('data').commitDocument(doc, 'edit'); + reason = 'edit'; + dirty.documentCanvas = dirty.metadataEditor = false; } + sandbox.getModule('data').commitDocument(doc, reason); } } @@ -62,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); + }); } } @@ -71,12 +90,15 @@ return function(sandbox) { mainTabs: (new tabs.View()).render(), visualEditing: new layout.Layout(visualEditingLayoutTemplate), visualEditingSidebar: (new tabs.View({stacked: true})).render(), - currentNodePaneLayout: new vbox.VBox() + currentNodePaneLayout: new vbox.VBox(), + diffLayout: new layout.Layout(diffLayoutTemplate) } views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView()); addMainTab('Edytor', 'editor', views.visualEditing.getAsView()); + addMainTab('Historia', 'history', views.diffLayout.getAsView()); + sandbox.getDOM().append(views.mainLayout.getAsView()); views.visualEditingSidebar.addTab({icon: 'pencil'}, 'edit', views.currentNodePaneLayout.getAsView()); @@ -108,20 +130,12 @@ return function(sandbox) { ready: function() { views.mainLayout.setView('mainView', views.mainTabs.getAsView()); - _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory'], function(moduleName) { + _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer'], function(moduleName) { sandbox.getModule(moduleName).start(); }); }, 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); @@ -129,15 +143,29 @@ return function(sandbox) { }, savingEnded: function(status) { sandbox.getModule('mainBar').setCommandEnabled('save', true); - sandbox.getModule('indicator').clearMessage(); + 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]); + 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() { @@ -252,7 +280,22 @@ return function(sandbox) { eventHandlers.documentHistory = { ready: function() { sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory()); - addMainTab('Historia', 'history', sandbox.getModule('documentHistory').getView()); + views.diffLayout.setView('left', sandbox.getModule('documentHistory').getView()); + }, + 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()); + } + } + + eventHandlers.diffViewer = { + ready: function() { + views.diffLayout.setView('right', sandbox.getModule('diffViewer').getView()); } }