summaryrefslogtreecommitdiff
path: root/src/web/app/desktop/mixins/widget.ts
blob: 04131cd8f0c994b0add5f07dbd9f096d8376ce30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import * as riot from 'riot';

// ミックスインにオプションを渡せないのアレ
// SEE: https://github.com/riot/riot/issues/2434

(riot as any).mixin('widget', {
	init: function() {
		this.mixin('i');
		this.mixin('api');

		this.id = this.opts.id;
		this.place = this.opts.place;

		if (this.data) {
			Object.keys(this.data).forEach(prop => {
				this.data[prop] = this.opts.data.hasOwnProperty(prop) ? this.opts.data[prop] : this.data[prop];
			});
		}
	},

	save: function() {
		this.update();
		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();
		});
	}
});