editor: documet summary view
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 21 Mar 2014 13:09:02 +0000 (14:09 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Fri, 21 Mar 2014 13:09:02 +0000 (14:09 +0100)
src/editor/modules/data/data.js
src/editor/modules/rng/documentSummary.html [new file with mode: 0644]
src/editor/modules/rng/documentSummary.js [new file with mode: 0644]
src/editor/modules/rng/documentSummary.less [new file with mode: 0644]
src/editor/modules/rng/rng.js
src/editor/modules/rng/rng.less

index 0bce5dc..42e46f8 100644 (file)
@@ -4,7 +4,8 @@ define([
     'wlxml/wlxml',
     'wlxml/extensions/list/list',
     'fnpjs/logging/logging',
     'wlxml/wlxml',
     'wlxml/extensions/list/list',
     'fnpjs/logging/logging',
-], function($, Dialog, wlxml, listExtension, logging) {
+    'fnpjs/datetime'
+], function($, Dialog, wlxml, listExtension, logging, datetime) {
 
 'use strict';
 /* global gettext, alert, window */
 
 'use strict';
 /* global gettext, alert, window */
@@ -32,7 +33,7 @@ return function(sandbox) {
 
     var wlxmlDocument, text;
 
 
     var wlxmlDocument, text;
 
-    var loadDocument = function(text) {
+    var loadDocument = function(text, isDraft, draftTimestamp) {
         logger.debug('loading document');
         try {
             wlxmlDocument = wlxml.WLXMLDocumentFromXML(text);
         logger.debug('loading document');
         try {
             wlxmlDocument = wlxml.WLXMLDocumentFromXML(text);
@@ -65,15 +66,17 @@ return function(sandbox) {
                     return;
                 }
                 if(wlxmlDocument && documentDirty && draftDirty) {
                     return;
                 }
                 if(wlxmlDocument && documentDirty && draftDirty) {
+                    var timestamp = datetime.currentStrfmt();
                     logger.debug('Saving draft to local storage.');
                     sandbox.publish('savingStarted', 'local');
                     logger.debug('Saving draft to local storage.');
                     sandbox.publish('savingStarted', 'local');
-                    window.localStorage.setItem(getLocalStorageKey(), wlxmlDocument.toXML());
-                    sandbox.publish('savingEnded', 'success', 'local');
+                    window.localStorage.setItem(getLocalStorageKey().content, wlxmlDocument.toXML());
+                    window.localStorage.setItem(getLocalStorageKey().contentTimestamp, timestamp);
+                    sandbox.publish('savingEnded', 'success', 'local', {timestamp: timestamp});
                     draftDirty = false;
                 }
             }, sandbox.getConfig().autoSaveInterval || 2500);
         }
                     draftDirty = false;
                 }
             }, sandbox.getConfig().autoSaveInterval || 2500);
         }
-        sandbox.publish('ready');
+        sandbox.publish('ready', isDraft, draftTimestamp);
     };
     
     function readCookie(name) {
     };
     
     function readCookie(name) {
@@ -113,15 +116,21 @@ return function(sandbox) {
     };
 
     var getLocalStorageKey = function() {
     };
 
     var getLocalStorageKey = function() {
-        return 'draft-id:' + document_id + '-ver:' + documentProperties.version;
+        var base = 'draft-id:' + document_id + '-ver:' + documentProperties.version;
+        return {
+            content: base,
+            contentTimestamp: base + '-content-timestamp'
+        };
     };
 
    
     return {
         start: function() {
     };
 
    
     return {
         start: function() {
-
             if(window.localStorage) {
             if(window.localStorage) {
-                text = window.localStorage.getItem(getLocalStorageKey());
+                text = window.localStorage.getItem(getLocalStorageKey().content);
+
+                var timestamp = window.localStorage.getItem(getLocalStorageKey().contentTimestamp),
+                    usingDraft;
                 if(text) {
                     logger.debug('Local draft exists');
                     var dialog = Dialog.create({
                 if(text) {
                     logger.debug('Local draft exists');
                     var dialog = Dialog.create({
@@ -132,22 +141,24 @@ return function(sandbox) {
                     });
                     dialog.on('cancel', function() {
                         logger.debug('Bootstrapped version chosen');
                     });
                     dialog.on('cancel', function() {
                         logger.debug('Bootstrapped version chosen');
+                        usingDraft = false;
                         text = sandbox.getBootstrappedData().document;
                         
                     });
                     dialog.on('execute', function(event) {
                         logger.debug('Local draft chosen');
                         text = sandbox.getBootstrappedData().document;
                         
                     });
                     dialog.on('execute', function(event) {
                         logger.debug('Local draft chosen');
+                        usingDraft = true;
                         event.success();
                     });
                     dialog.show();
                     dialog.on('close', function() {
                         event.success();
                     });
                     dialog.show();
                     dialog.on('close', function() {
-                        loadDocument(text);
+                        loadDocument(text, usingDraft, timestamp);
                     });
                 } else {
                     });
                 } else {
-                    loadDocument(sandbox.getBootstrappedData().document);
+                    loadDocument(sandbox.getBootstrappedData().document, false);
                 }
             } else {
                 }
             } else {
-                loadDocument(sandbox.getBootstrappedData().document);
+                loadDocument(sandbox.getBootstrappedData().document, false);
             }
         },
         getDocument: function() {
             }
         },
         getDocument: function() {
@@ -266,6 +277,7 @@ return function(sandbox) {
             wlxmlDocument.loadXML(sandbox.getBootstrappedData().document);
             draftDirty = false;
             logger.debug('Draft dropped');
             wlxmlDocument.loadXML(sandbox.getBootstrappedData().document);
             draftDirty = false;
             logger.debug('Draft dropped');
+            sandbox.publish('draftDropped');
         },
         getDocumentId: function() {
             return document_id;
         },
         getDocumentId: function() {
             return document_id;
diff --git a/src/editor/modules/rng/documentSummary.html b/src/editor/modules/rng/documentSummary.html
new file mode 100644 (file)
index 0000000..95c7552
--- /dev/null
@@ -0,0 +1,14 @@
+<div>
+    <h1 class="title"><%= title %></h1>
+    <table>
+        <% properties.forEach(function(propertyDesc) { %>
+            <tr>
+                <td><%= propertyDesc.label %></td>
+                <td><%= propertyValues[propertyDesc.name] %></td>
+        <% }); %>
+        <tr>
+            <td><%= gettext('Draft Saved') %></td>
+            <td class="draft"></td>
+        </tr>
+    </table>
+</div>
\ No newline at end of file
diff --git a/src/editor/modules/rng/documentSummary.js b/src/editor/modules/rng/documentSummary.js
new file mode 100644 (file)
index 0000000..211037d
--- /dev/null
@@ -0,0 +1,30 @@
+define(function(require) {
+    
+'use strict';
+
+var $ = require('libs/jquery'),
+    _ = require('libs/underscore'),
+    template = require('libs/text!./documentSummary.html');
+
+
+var view = {
+    dom: $('<div class="documentSummary"></div>'),
+    init: function(config) {
+        this.config = config;
+        this.template = _.template(template);
+    },
+    render: function(properties) {
+        this.dom.html(this.template({
+            title: this.config.title,
+            properties: this.config.properties,
+            propertyValues: properties
+        }));
+    },
+    setDraftField: function(value) {
+        this.dom.find('.draft').text(value);
+    }
+};
+
+return view;
+
+});
\ No newline at end of file
diff --git a/src/editor/modules/rng/documentSummary.less b/src/editor/modules/rng/documentSummary.less
new file mode 100644 (file)
index 0000000..2c63fa1
--- /dev/null
@@ -0,0 +1,16 @@
+.documentSummary {
+    .title {
+        font-size: 13px;
+        margin: 0 0 5px 0;
+    }
+    table {
+        width: 100%;
+        tr td:first-child {
+            font-weight: bold;
+            text-align: left;
+        }
+        tr td:nth-child(2) {
+            text-align: right;
+        }
+    }
+}
\ No newline at end of file
index 42ab636..a00bf3c 100644 (file)
@@ -1,4 +1,5 @@
 define([
 define([
+'./documentSummary',
 'libs/underscore',
 'fnpjs/layout',
 'fnpjs/vbox',
 'libs/underscore',
 'fnpjs/layout',
 'fnpjs/vbox',
@@ -7,7 +8,7 @@ define([
 'libs/text!./mainLayout.html',
 'libs/text!./editingLayout.html',
 'libs/text!./diffLayout.html',
 'libs/text!./mainLayout.html',
 'libs/text!./editingLayout.html',
 'libs/text!./diffLayout.html',
-], function(_, layout, vbox, logging, tabs, mainLayoutTemplate, visualEditingLayoutTemplate, diffLayoutTemplate) {
+], function(documentSummary, _, layout, vbox, logging, tabs, mainLayoutTemplate, visualEditingLayoutTemplate, diffLayoutTemplate) {
 
 'use strict';
 
 
 'use strict';
 
@@ -86,9 +87,14 @@ return function(sandbox) {
     };
     
     eventHandlers.data = {
     };
     
     eventHandlers.data = {
-        ready: function() {
+        ready: function(usingDraft, draftTimestamp) {
             views.mainLayout.setView('mainView', views.mainTabs.getAsView());
             
             views.mainLayout.setView('mainView', views.mainTabs.getAsView());
             
+            documentSummary.init(sandbox.getConfig().documentSummaryView);
+            documentSummary.render(sandbox.getModule('data').getDocumentProperties());
+            documentSummary.setDraftField(usingDraft ? (draftTimestamp || '???') : '-');
+            views.currentNodePaneLayout.appendView(documentSummary.dom);
+
             _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer'], function(moduleName) {
                 sandbox.getModule(moduleName).start();
             });
             _.each(['sourceEditor', 'documentCanvas', 'documentToolbar', 'nodePane', 'metadataEditor', 'nodeFamilyTree', 'nodeBreadCrumbs', 'mainBar', 'indicator', 'documentHistory', 'diffViewer'], function(moduleName) {
                 sandbox.getModule(moduleName).start();
             });
@@ -102,6 +108,9 @@ return function(sandbox) {
                 documentIsDirty = true;
             });
         },
                 documentIsDirty = true;
             });
         },
+        draftDropped: function() {
+            documentSummary.setDraftField('-');
+        },
         savingStarted: function(what) {
             var msg = {
                 remote: gettext('Saving document'),
         savingStarted: function(what) {
             var msg = {
                 remote: gettext('Saving document'),
@@ -119,7 +128,14 @@ return function(sandbox) {
             documentIsDirty = false;
             sandbox.getModule('mainBar').setCommandEnabled('save', true);
             sandbox.getModule('indicator').clearMessage({message: msg[what]});
             documentIsDirty = false;
             sandbox.getModule('mainBar').setCommandEnabled('save', true);
             sandbox.getModule('indicator').clearMessage({message: msg[what]});
-            sandbox.getModule('mainBar').setVersion(data.version);
+            if(status === 'success' && what === 'remote') {
+                sandbox.getModule('mainBar').setVersion(data.version);
+                documentSummary.render(data);
+                documentSummary.setDraftField('-');
+            }
+            if(what === 'local') {
+                documentSummary.setDraftField(data.timestamp);
+            }
         },
         restoringStarted: function(event) {
             sandbox.getModule('mainBar').setCommandEnabled('save', false);
         },
         restoringStarted: function(event) {
             sandbox.getModule('mainBar').setCommandEnabled('save', false);
index 196be1f..791ab29 100644 (file)
@@ -1,3 +1,4 @@
 @import 'mainLayout.less';
 @import 'editingLayout.less';
 @import 'mainLayout.less';
 @import 'editingLayout.less';
-@import 'diffLayout.less';
\ No newline at end of file
+@import 'diffLayout.less';
+@import 'documentSummary.less';