canvas manager wip - setting cursor at the beginning of a new node
[fnpeditor.git] / modules / rng / rng.js
index 16a6d25..643b683 100644 (file)
@@ -35,6 +35,7 @@ return function(sandbox) {
             if(slug === 'sourceEditor') {\r
                 doc = sandbox.getModule('sourceEditor').getDocument();\r
                 reason = 'source_edit';\r
             if(slug === 'sourceEditor') {\r
                 doc = sandbox.getModule('sourceEditor').getDocument();\r
                 reason = 'source_edit';\r
+                dirty.sourceEditor = false;\r
             }\r
             if(slug === 'editor') {\r
                 var doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument();\r
             }\r
             if(slug === 'editor') {\r
                 var doc = dirty.documentCanvas ? sandbox.getModule('documentCanvas').getDocument() : sandbox.getModule('data').getDocument();\r
@@ -42,6 +43,7 @@ return function(sandbox) {
                     doc = sandbox.getModule('metadataEditor').attachMetadata(doc);\r
                 }\r
                 reason = 'edit';\r
                     doc = sandbox.getModule('metadataEditor').attachMetadata(doc);\r
                 }\r
                 reason = 'edit';\r
+                dirty.documentCanvas = dirty.metadataEditor = false;\r
             }\r
             sandbox.getModule('data').commitDocument(doc, reason);\r
         }\r
             }\r
             sandbox.getModule('data').commitDocument(doc, reason);\r
         }\r
@@ -66,6 +68,19 @@ return function(sandbox) {
             sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode);\r
             sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode);\r
             \r
             sandbox.getModule('nodeFamilyTree').setNode(wlxmlNode);\r
             sandbox.getModule('nodeBreadCrumbs').setNode(wlxmlNode);\r
             \r
+        },\r
+        resetDocument: function(document, reason) {\r
+            var modules = [];\r
+            if(reason === 'source_edit')\r
+                modules = ['documentCanvas', 'metadataEditor'];\r
+            else if (reason === 'edit')\r
+                modules = ['sourceEditor'];\r
+            else if (reason === 'revert')\r
+                modules = ['documentCanvas', 'metadataEditor', 'sourceEditor'];\r
+                \r
+            modules.forEach(function(moduleName) {\r
+                sandbox.getModule(moduleName).setDocument(document);\r
+            });\r
         }\r
     }\r
     \r
         }\r
     }\r
     \r
@@ -81,7 +96,7 @@ return function(sandbox) {
     \r
     views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());\r
     addMainTab('Edytor', 'editor', views.visualEditing.getAsView());\r
     \r
     views.visualEditing.setView('rightColumn', views.visualEditingSidebar.getAsView());\r
     addMainTab('Edytor', 'editor', views.visualEditing.getAsView());\r
-    \r
+    addMainTab(gettext('Source'), 'sourceEditor',  '');\r
     addMainTab('Historia', 'history', views.diffLayout.getAsView());\r
     \r
     sandbox.getDOM().append(views.mainLayout.getAsView());\r
     addMainTab('Historia', 'history', views.diffLayout.getAsView());\r
     \r
     sandbox.getDOM().append(views.mainLayout.getAsView());\r
@@ -120,15 +135,7 @@ return function(sandbox) {
             });\r
         },\r
         documentChanged: function(document, reason) {\r
             });\r
         },\r
         documentChanged: function(document, reason) {\r
-            var modules = [];\r
-            if(reason === 'source_edit')\r
-                modules = ['documentCanvas', 'metadataEditor'];\r
-            else if (reason === 'edit')\r
-                modules = ['sourceEditor'];\r
-                \r
-            modules.forEach(function(moduleName) {\r
-                sandbox.getModule(moduleName).setDocument(document);\r
-            });\r
+            commands.resetDocument(document, reason);\r
         },\r
         savingStarted: function() {\r
             sandbox.getModule('mainBar').setCommandEnabled('save', false);\r
         },\r
         savingStarted: function() {\r
             sandbox.getModule('mainBar').setCommandEnabled('save', false);\r
@@ -138,16 +145,27 @@ return function(sandbox) {
             sandbox.getModule('mainBar').setCommandEnabled('save', true);\r
             sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'});\r
         },\r
             sandbox.getModule('mainBar').setCommandEnabled('save', true);\r
             sandbox.getModule('indicator').clearMessage({message:'Dokument zapisany'});\r
         },\r
+        restoringStarted: function(event) {\r
+            sandbox.getModule('mainBar').setCommandEnabled('save', false);\r
+            sandbox.getModule('indicator').showMessage(gettext('Restoring version ') + event.version + '...');\r
+        },\r
         historyItemAdded: function(item) {\r
             sandbox.getModule('documentHistory').addHistory([item], {animate: true});\r
         },\r
         diffFetched: function(diff) {\r
             sandbox.getModule('diffViewer').setDiff(diff);\r
         historyItemAdded: function(item) {\r
             sandbox.getModule('documentHistory').addHistory([item], {animate: true});\r
         },\r
         diffFetched: function(diff) {\r
             sandbox.getModule('diffViewer').setDiff(diff);\r
+        },\r
+        documentReverted: function(event) {\r
+            commands.resetDocument(event.document, 'revert');\r
+            sandbox.getModule('mainBar').setCommandEnabled('save', true);\r
+            sandbox.getModule('indicator').clearMessage({message:'Wersja ' + event.reverted_version + ' przywrócona'});\r
+            sandbox.getModule('mainBar').setVersion(event.current_version);\r
         }\r
     }\r
     \r
     eventHandlers.mainBar = {\r
         ready: function() {\r
         }\r
     }\r
     \r
     eventHandlers.mainBar = {\r
         ready: function() {\r
+            sandbox.getModule('mainBar').setVersion(sandbox.getModule('data').getDocumentVersion());\r
             views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());\r
         },\r
         'cmd.save': function() {\r
             views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());\r
         },\r
         'cmd.save': function() {\r
@@ -266,6 +284,12 @@ return function(sandbox) {
         },\r
         compare: function(ver1, ver2) {\r
             sandbox.getModule('data').fetchDiff(ver1, ver2);\r
         },\r
         compare: function(ver1, ver2) {\r
             sandbox.getModule('data').fetchDiff(ver1, ver2);\r
+        },\r
+        restoreVersion: function(event) {\r
+            sandbox.getModule('data').restoreVersion(event);\r
+        },\r
+        displayVersion: function(event) {\r
+            window.open('/' + gettext('editor') + '/' + sandbox.getModule('data').getDocumentId() + '?version=' + event.version, _.uniqueId());\r
         }\r
     }\r
     \r
         }\r
     }\r
     \r