'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 */
var wlxmlDocument, text;
- var loadDocument = function(text) {
+ var loadDocument = function(text, isDraft, draftTimestamp) {
logger.debug('loading document');
try {
wlxmlDocument = wlxml.WLXMLDocumentFromXML(text);
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) {
};
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({
});
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() {
wlxmlDocument.loadXML(sandbox.getBootstrappedData().document);
draftDirty = false;
logger.debug('Draft dropped');
+ sandbox.publish('draftDropped');
},
getDocumentId: function() {
return document_id;
--- /dev/null
+<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
--- /dev/null
+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
--- /dev/null
+.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
define([
+'./documentSummary',
'libs/underscore',
'fnpjs/layout',
'fnpjs/vbox',
'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';
};
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();
});
documentIsDirty = true;
});
},
+ draftDropped: function() {
+ documentSummary.setDraftField('-');
+ },
savingStarted: function(what) {
var msg = {
remote: gettext('Saving document'),
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);
@import 'mainLayout.less';
@import 'editingLayout.less';
-@import 'diffLayout.less';
\ No newline at end of file
+@import 'diffLayout.less';
+@import 'documentSummary.less';