2017-10-14 20:24:18 +00:00
|
|
|
/*jslint es6: true, this: true*/
|
2017-10-12 19:00:04 +00:00
|
|
|
/*global window, browser, Vue*/
|
|
|
|
(function () {
|
2017-10-14 20:24:18 +00:00
|
|
|
"use strict";
|
2017-10-12 19:00:04 +00:00
|
|
|
|
2017-10-14 21:16:24 +00:00
|
|
|
const defaultDomain = "(default)";
|
2017-10-15 04:23:40 +00:00
|
|
|
const {packingLib, standards} = window.WEB_API_MANAGER;
|
2017-10-12 19:00:04 +00:00
|
|
|
|
2017-10-14 21:16:24 +00:00
|
|
|
const generateStateObject = function (initialDomain, standards) {
|
2017-10-12 19:00:04 +00:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
selectedDomain: initialDomain,
|
|
|
|
standards: standards,
|
|
|
|
domainRules: {},
|
|
|
|
domainNames: [],
|
2017-10-15 04:23:40 +00:00
|
|
|
shouldLog: false,
|
2017-10-12 19:00:04 +00:00
|
|
|
selectedStandards: [],
|
2017-10-14 20:24:18 +00:00
|
|
|
|
2017-10-15 04:23:40 +00:00
|
|
|
toStorage: function () {
|
|
|
|
return {
|
|
|
|
domainRules: this.domainRules,
|
|
|
|
shouldLog: this.shouldLog
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
populateFromStorage: function (storedValues) {
|
|
|
|
this.setDomainRules(storedValues.domainRules);
|
|
|
|
this.setShouldLog(storedValues.shouldLog);
|
|
|
|
},
|
|
|
|
|
2017-10-12 19:00:04 +00:00
|
|
|
setDomainRules: function (newDomainRules) {
|
|
|
|
this.domainRules = newDomainRules;
|
|
|
|
this.domainNames = Object.keys(newDomainRules);
|
|
|
|
this.selectedStandards = this.domainRules[this.selectedDomain];
|
|
|
|
},
|
2017-10-14 20:24:18 +00:00
|
|
|
|
2017-10-12 19:00:04 +00:00
|
|
|
setSelectedDomain: function (newDomain) {
|
|
|
|
this.selectedDomain = newDomain;
|
|
|
|
this.selectedStandards = this.domainRules[newDomain];
|
|
|
|
},
|
2017-10-14 20:24:18 +00:00
|
|
|
|
2017-10-12 19:00:04 +00:00
|
|
|
setSelectedStandards: function (selectedStandards) {
|
|
|
|
this.selectedStandards = selectedStandards;
|
|
|
|
this.domainRules[this.selectedDomain] = selectedStandards;
|
|
|
|
},
|
2017-10-14 20:24:18 +00:00
|
|
|
|
2017-10-12 19:00:04 +00:00
|
|
|
deleteDomainRule: function (domainToDelete) {
|
2017-10-14 20:24:18 +00:00
|
|
|
|
2017-10-12 19:00:04 +00:00
|
|
|
// If we're deleted the domain thats currently selected, then
|
|
|
|
// select the default domain.
|
|
|
|
if (this.selectedDomain === domainToDelete) {
|
2017-10-14 21:16:24 +00:00
|
|
|
this.setSelectedDomain(defaultDomain);
|
2017-10-12 19:00:04 +00:00
|
|
|
}
|
2017-10-14 21:16:24 +00:00
|
|
|
|
|
|
|
delete this.domainRules[domainToDelete];
|
|
|
|
this.domainNames = Object.keys(this.domainRules);
|
2017-10-12 19:00:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
addDomainRule: function (newDomainRule) {
|
|
|
|
this.domainRules[newDomainRule] = [];
|
|
|
|
this.domainNames = Object.keys(this.domainRules);
|
|
|
|
this.selectedDomain = newDomainRule;
|
2017-10-14 22:26:02 +00:00
|
|
|
this.selectedStandards = this.domainRules[newDomainRule];
|
2017-10-15 04:23:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setShouldLog: function (shouldLog) {
|
|
|
|
this.shouldLog = shouldLog;
|
2017-10-12 19:00:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return state;
|
|
|
|
};
|
2017-10-14 21:16:24 +00:00
|
|
|
|
|
|
|
window.WEB_API_MANAGER.stateLib = {
|
|
|
|
generateStateObject
|
|
|
|
};
|
2017-10-12 19:00:04 +00:00
|
|
|
}());
|