From 11ffa88b49ac21b7000746a5a75ec5528461a0ae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 21 Mar 2014 14:09:02 +0100 Subject: [PATCH] editor: documet summary view --- src/editor/modules/data/data.js | 34 ++++++++++++++------- src/editor/modules/rng/documentSummary.html | 14 +++++++++ src/editor/modules/rng/documentSummary.js | 30 ++++++++++++++++++ src/editor/modules/rng/documentSummary.less | 16 ++++++++++ src/editor/modules/rng/rng.js | 22 +++++++++++-- src/editor/modules/rng/rng.less | 3 +- 6 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 src/editor/modules/rng/documentSummary.html create mode 100644 src/editor/modules/rng/documentSummary.js create mode 100644 src/editor/modules/rng/documentSummary.less diff --git a/src/editor/modules/data/data.js b/src/editor/modules/data/data.js index 0bce5dc..42e46f8 100644 --- a/src/editor/modules/data/data.js +++ b/src/editor/modules/data/data.js @@ -4,7 +4,8 @@ define([ '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 */ @@ -32,7 +33,7 @@ return function(sandbox) { var wlxmlDocument, text; - var loadDocument = function(text) { + var loadDocument = function(text, isDraft, draftTimestamp) { logger.debug('loading document'); try { wlxmlDocument = wlxml.WLXMLDocumentFromXML(text); @@ -65,15 +66,17 @@ return function(sandbox) { return; } if(wlxmlDocument && documentDirty && draftDirty) { + var timestamp = datetime.currentStrfmt(); 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); } - sandbox.publish('ready'); + sandbox.publish('ready', isDraft, draftTimestamp); }; function readCookie(name) { @@ -113,15 +116,21 @@ return function(sandbox) { }; 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() { - 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({ @@ -132,22 +141,24 @@ return function(sandbox) { }); 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'); + usingDraft = true; event.success(); }); dialog.show(); dialog.on('close', function() { - loadDocument(text); + loadDocument(text, usingDraft, timestamp); }); } else { - loadDocument(sandbox.getBootstrappedData().document); + loadDocument(sandbox.getBootstrappedData().document, false); } } else { - loadDocument(sandbox.getBootstrappedData().document); + loadDocument(sandbox.getBootstrappedData().document, false); } }, getDocument: function() { @@ -266,6 +277,7 @@ return function(sandbox) { wlxmlDocument.loadXML(sandbox.getBootstrappedData().document); draftDirty = false; logger.debug('Draft dropped'); + sandbox.publish('draftDropped'); }, 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 index 0000000..95c7552 --- /dev/null +++ b/src/editor/modules/rng/documentSummary.html @@ -0,0 +1,14 @@ +
+

<%= title %>

+ + <% properties.forEach(function(propertyDesc) { %> + + + + <% }); %> + + + + +
<%= propertyDesc.label %><%= propertyValues[propertyDesc.name] %>
<%= gettext('Draft Saved') %>
+
\ 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 index 0000000..211037d --- /dev/null +++ b/src/editor/modules/rng/documentSummary.js @@ -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: $('
'), + 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 index 0000000..2c63fa1 --- /dev/null +++ b/src/editor/modules/rng/documentSummary.less @@ -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 diff --git a/src/editor/modules/rng/rng.js b/src/editor/modules/rng/rng.js index 42ab636..a00bf3c 100644 --- a/src/editor/modules/rng/rng.js +++ b/src/editor/modules/rng/rng.js @@ -1,4 +1,5 @@ define([ +'./documentSummary', 'libs/underscore', 'fnpjs/layout', 'fnpjs/vbox', @@ -7,7 +8,7 @@ define([ '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'; @@ -86,9 +87,14 @@ return function(sandbox) { }; eventHandlers.data = { - ready: function() { + ready: function(usingDraft, draftTimestamp) { 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(); }); @@ -102,6 +108,9 @@ return function(sandbox) { documentIsDirty = true; }); }, + draftDropped: function() { + documentSummary.setDraftField('-'); + }, 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]}); - 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); diff --git a/src/editor/modules/rng/rng.less b/src/editor/modules/rng/rng.less index 196be1f..791ab29 100644 --- a/src/editor/modules/rng/rng.less +++ b/src/editor/modules/rng/rng.less @@ -1,3 +1,4 @@ @import 'mainLayout.less'; @import 'editingLayout.less'; -@import 'diffLayout.less'; \ No newline at end of file +@import 'diffLayout.less'; +@import 'documentSummary.less'; -- 2.20.1