var documentDirty = false;
var draftDirty = false;
- var documentProperties = {};
var data = sandbox.getBootstrappedData();
- Object.keys(data)
- .filter(function(key) {
- return key !== 'history' && key !== 'document';
- })
- .forEach(function(key) {
- documentProperties[key] = data[key];
- });
+ var document_version = data.version;
+
var wlxmlDocument, text;
wlxmlDocument = wlxml.WLXMLDocumentFromXML(stubDocument, {}, Document);
}
+ Object.keys(data)
+ .filter(function(key) {
+ return key !== 'history' && key !== 'document';
+ })
+ .forEach(function(key) {
+ wlxmlDocument.setProperty(key, data[key]);
+ });
+
wlxmlDocument.registerExtension(listExtension);
sandbox.getPlugins().forEach(function(plugin) {
if(plugin.documentExtension) {
});
};
- var getLocalStorageKey = function() {
- var base = 'draft-id:' + document_id + '-ver:' + documentProperties.version;
+ var getLocalStorageKey = function(forVersion) {
+ var base = 'draft-id:' + document_id + '-ver:' + (forVersion || wlxmlDocument.properties.version);
return {
content: base,
contentTimestamp: base + '-content-timestamp'
return {
start: function() {
if(window.localStorage) {
- text = window.localStorage.getItem(getLocalStorageKey().content);
+ text = window.localStorage.getItem(getLocalStorageKey(document_version).content);
- var timestamp = window.localStorage.getItem(getLocalStorageKey().contentTimestamp),
+ var timestamp = window.localStorage.getItem(getLocalStorageKey(document_version).contentTimestamp),
usingDraft;
if(text) {
logger.debug('Local draft exists');
var formData = event.formData;
formData[documentSaveForm.content_field_name] = wlxmlDocument.toXML();
- formData[documentSaveForm.version_field_name] = documentProperties.version;
+ formData[documentSaveForm.version_field_name] = wlxmlDocument.properties.version;
if(sandbox.getConfig().jsonifySentData) {
formData = JSON.stringify(formData);
}
return key !== 'text';
})
.forEach(function(key) {
- documentProperties[key] = data[key];
+ wlxmlDocument.setProperty(key, data[key]);
});
reloadHistory();
return key !== 'document';
})
.forEach(function(key) {
- documentProperties[key] = data[key];
+ wlxmlDocument.setProperty(key, data[key]);
});
reloadHistory();
wlxmlDocument.loadXML(data.document);
},
getDocumentId: function() {
return document_id;
- },
- getDocumentProperties: function() {
- return documentProperties;
}
};
};
var Document = function() {
wlxml.WLXMLDocument.apply(this, Array.prototype.slice.call(arguments, 0));
+ this.properties = {};
};
Document.prototype = Object.create(wlxml.WLXMLDocument.prototype);
return 'file://' + _.last(url.split('/'));
}
return url;
+ },
+ setProperty: function(propName, propValue) {
+ if(this.properties[propName] !== propValue) {
+ this.properties[propName] = propValue;
+ this.trigger('propertyChanged', propName, propValue);
+ }
}
});
var view = {
dom: $('<div class="documentSummary"></div>'),
- init: function(config) {
+ init: function(config, doc) {
this.config = config;
+ this.doc = doc;
this.template = _.template(template);
+
+ this.doc.on('propertyChanged', this.render, this);
},
- render: function(properties) {
+ render: function() {
this.dom.html(this.template({
title: this.config.title,
properties: this.config.properties,
- propertyValues: properties
+ propertyValues: this.doc.properties
}));
},
setDraftField: function(value) {
eventHandlers.data = {
ready: function(usingDraft, draftTimestamp) {
+ wlxmlDocument = sandbox.getModule('data').getDocument();
+
views.mainLayout.setView('mainView', views.mainTabs.getAsView());
- documentSummary.init(sandbox.getConfig().documentSummaryView);
- documentSummary.render(sandbox.getModule('data').getDocumentProperties());
+ documentSummary.init(sandbox.getConfig().documentSummaryView, wlxmlDocument);
+ documentSummary.render();
documentSummary.setDraftField(usingDraft ? (draftTimestamp || '???') : '-');
views.currentNodePaneLayout.appendView(documentSummary.dom);
sandbox.getModule(moduleName).start();
});
- wlxmlDocument = sandbox.getModule('data').getDocument();
documentIsDirty = false;
wlxmlDocument.on('change', function() {
documentIsDirty = true;
sandbox.getModule('indicator').clearMessage({message: msg[what]});
if(status === 'success' && what === 'remote') {
sandbox.getModule('mainBar').setVersion(data.version);
- documentSummary.render(data);
documentSummary.setDraftField('-');
sandbox.getModule('mainBar').setCommandEnabled('drop-draft', false);
sandbox.getModule('mainBar').setCommandEnabled('save', false);
eventHandlers.mainBar = {
ready: function() {
- sandbox.getModule('mainBar').setVersion(sandbox.getModule('data').getDocumentProperties().version);
+ sandbox.getModule('mainBar').setVersion(sandbox.getModule('data').getDocument().properties.version);
views.mainLayout.setView('topPanel', sandbox.getModule('mainBar').getView());
},
'cmd.save': function() {