sharkey/src/web/app/desktop/mixins/widget.ts

32 lines
705 B
TypeScript
Raw Normal View History

2017-11-12 04:39:07 +09:00
import * as riot from 'riot';
// ミックスインにオプションを渡せないのアレ
// SEE: https://github.com/riot/riot/issues/2434
2017-11-13 18:05:35 +09:00
(riot as any).mixin('widget', {
2017-11-12 04:39:07 +09:00
init: function() {
this.mixin('i');
this.mixin('api');
this.id = this.opts.id;
2017-11-12 18:23:33 +09:00
this.place = this.opts.place;
2017-11-12 04:39:07 +09:00
2017-11-12 18:23:33 +09:00
if (this.data) {
Object.keys(this.data).forEach(prop => {
this.data[prop] = this.opts.data.hasOwnProperty(prop) ? this.opts.data[prop] : this.data[prop];
});
}
2017-11-12 04:39:07 +09:00
},
save: function() {
2017-11-12 05:38:48 +09:00
this.update();
2017-11-12 04:39:07 +09:00
this.api('i/update_home', {
id: this.id,
data: this.data
}).then(() => {
this.I.client_settings.home.find(w => w.id == this.id).data = this.data;
this.I.update();
});
}
});