2017-02-21 21:28:44 +03:00
|
|
|
import Model from 'ember-data/model';
|
|
|
|
import attr from 'ember-data/attr';
|
|
|
|
|
|
|
|
export default Model.extend({
|
|
|
|
name: attr('string'),
|
2017-03-03 18:31:42 +03:00
|
|
|
package: attr('raw'),
|
|
|
|
active: attr('boolean'),
|
|
|
|
warnings: attr('raw'),
|
2017-06-06 09:09:52 +03:00
|
|
|
errors: attr('raw'),
|
2017-03-03 18:31:42 +03:00
|
|
|
|
|
|
|
activate() {
|
|
|
|
let adapter = this.store.adapterFor(this.constructor.modelName);
|
2017-03-14 16:54:58 +03:00
|
|
|
|
|
|
|
return adapter.activate(this).then(() => {
|
|
|
|
// the server only gives us the newly active theme back so we need
|
|
|
|
// to manually mark other themes as inactive in the store
|
|
|
|
let activeThemes = this.store.peekAll('theme').filterBy('active', true);
|
|
|
|
|
|
|
|
activeThemes.forEach((theme) => {
|
|
|
|
if (theme !== this) {
|
|
|
|
// store.push is necessary to avoid dirty records that cause
|
|
|
|
// problems when we get new data back in subsequent requests
|
|
|
|
this.store.push({data: {
|
|
|
|
id: theme.id,
|
|
|
|
type: 'theme',
|
|
|
|
attributes: {active: false}
|
|
|
|
}});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
|
|
|
});
|
2017-03-03 18:31:42 +03:00
|
|
|
}
|
2017-02-21 21:28:44 +03:00
|
|
|
});
|