X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/b7d40f4f02e71505150c8b33ad3ad7d7acde0ae2..e5ddc7a08a1464b59075e435c959cd957238fabd:/modules/rng/rng.js?ds=inline diff --git a/modules/rng/rng.js b/modules/rng/rng.js index 6029e7c..a13cfce 100644 --- a/modules/rng/rng.js +++ b/modules/rng/rng.js @@ -4,10 +4,12 @@ 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'; return function(sandbox) { - 'use strict'; function addMainTab(title, slug, view) { views.mainTabs.addTab(title, slug, view); @@ -19,6 +21,34 @@ return function(sandbox) { metadataEditor: false, }; + var synchronizeTab = function(slug) { + function tabIsDirty(slug) { + if(slug === 'editor' && (dirty.documentCanvas || dirty.metadataEditor)) + return true; + if(slug === 'sourceEditor' && dirty.sourceEditor) + return true; + return false; + } + + if(tabIsDirty(slug)) { + var reason, doc; + 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(); + if(dirty.metadataEditor) { + 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) { ['documentCanvas', 'nodeBreadCrumbs', 'nodeFamilyTree'].forEach(function(moduleName) { @@ -47,29 +77,22 @@ 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()); views.mainTabs.on('tabSelected', function(event) { if(event.prevSlug) { - if(event.prevSlug === 'sourceEditor' && dirty.sourceEditor) { - sandbox.getModule('data').commitDocument(sandbox.getModule('sourceEditor').getDocument(), 'source_edit'); - } - if(event.prevSlug === 'editor' && (dirty.documentCanvas || dirty.metadataEditor)) { - 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'); - } - + synchronizeTab(event.prevSlug); } }); @@ -94,7 +117,7 @@ return function(sandbox) { ready: function() { views.mainLayout.setView('mainView', views.mainTabs.getAsView()); - _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator'], function(moduleName) { + _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer'], function(moduleName) { sandbox.getModule(moduleName).start(); }); }, @@ -115,7 +138,13 @@ return function(sandbox) { }, savingEnded: function(status) { sandbox.getModule('mainBar').setCommandEnabled('save', true); - sandbox.getModule('indicator').clearMessage(); + sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'}); + }, + historyItemAdded: function(item) { + sandbox.getModule('documentHistory').addHistory([item], {animate: true}); + }, + diffFetched: function(diff) { + sandbox.getModule('diffViewer').setDiff(diff); } } @@ -124,7 +153,8 @@ return function(sandbox) { views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView()); }, 'cmd.save': function() { - sandbox.getModule('data').fakeSave(); + synchronizeTab(views.mainTabs.getCurrentSlug()); + sandbox.getModule('data').saveDocument(); } } @@ -231,6 +261,22 @@ return function(sandbox) { } } + eventHandlers.documentHistory = { + ready: function() { + sandbox.getModule('documentHistory').addHistory(sandbox.getModule('data').getHistory()); + views.diffLayout.setView('left', sandbox.getModule('documentHistory').getView()); + }, + compare: function(ver1, ver2) { + sandbox.getModule('data').fetchDiff(ver1, ver2); + } + } + + eventHandlers.diffViewer = { + ready: function() { + views.diffLayout.setView('right', sandbox.getModule('diffViewer').getView()); + } + } + /* api */ return {