fetchTemplates(): Promise<any> {
- // TODO: copy templates should be server settings
+ // First check for local copy templates, since server-side
+ // templates are new w/ this code. Move them to the server.
const tmpls = this.store.getLocalItem('cat.copy.templates');
- if (!tmpls) { return Promise.resolve(); }
- this.templates = tmpls;
- this.templateNames = Object.keys(tmpls)
- .sort((n1, n2) => n1 < n2 ? -1 : 1)
- .map(name => ({id: name, label: name}));
+ const promise = tmpls ?
+ this.serverStore.setItem('cat.copy.templates', tmpls) :
+ Promise.resolve();
- return Promise.resolve();
+ return promise
+ .then(_ =>
+ this.serverStore.getItem('cat.copy.templates'))
+ .then(templates => {
+
+ this.templates = templates;
+
+ this.templateNames = Object.keys(tmpls)
+ .sort((n1, n2) => n1 < n2 ? -1 : 1)
+ .map(name => ({id: name, label: name}));
+
+ this.store.removeLocalItem('cat.copy.templates');
+ });
}
saveTemplates(): Promise<any> {
- // TODO: templates should be stored on the server.
this.store.setLocalItem('cat.copy.templates', this.templates);
// Re-sort, etc.
return this.fetchTemplates();