ramblings/oxygen/js-options/options.js

58 lines
1.7 KiB
JavaScript

/*
* Main features
*/
Options = function (authorAccess, namespace) {
this.namespace = namespace;
this.authorAccess = authorAccess;
this.optionsStorage = this.authorAccess.getOptionsStorage();
if (namespace != Options.SYSTEM) {
var systemOptions = new Options(authorAccess, Options.SYSTEM);
var namespaces = JSON.parse(systemOptions.getOption(Options.NAMESPACES, '{}'));
namespaces[this.namespace] = (new Date()).toISOString();
systemOptions.setOption(Options.NAMESPACES, JSON.stringify(namespaces))
}
}
Options.SYSTEM = '__system__';
Options.NAMESPACES = '__namespaces__';
Options.prototype.getOption = function (key, defaultValue) {
this.optionsStorage.setOptionsDoctypePrefix(this.namespace);
return this.optionsStorage.getOption(key, defaultValue);
}
Options.prototype.setOption = function (key, value) {
this.optionsStorage.setOptionsDoctypePrefix(Options.SYSTEM);
var options = JSON.parse(this.optionsStorage.getOption(this.namespace, '{}'));
options[key] = (new Date()).toISOString();
this.optionsStorage.setOption(this.namespace, JSON.stringify(options));
this.optionsStorage.setOptionsDoctypePrefix(this.namespace);
this.optionsStorage.setOption(key, value);
}
Options.prototype.getOptions = function () {
var results = {
};
this.optionsStorage.setOptionsDoctypePrefix(Options.SYSTEM);
var options = JSON.parse(this.optionsStorage.getOption(this.namespace, '{}'));
for (var key in options) {
results[key] = this.getOption(key, '');
}
return results;
}
/*
* Per file extensions
*
*/
Options.prototype.setSystemId = function(systemID) {
if (systemID === undefined) {
this.systemID = this.authorAccess.getDocumentController().getAuthorDocumentNode().getSystemID();
} else {
this.systemID = systemID;
}
}