2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2020-01-17 01:56:53 +08:00
|
|
|
import discourseComputed, { observes } from "discourse-common/utils/decorators";
|
2017-04-12 22:52:52 +08:00
|
|
|
|
2019-10-24 00:30:52 +08:00
|
|
|
export default Component.extend({
|
2019-01-10 18:06:01 +08:00
|
|
|
classNames: ["inline-edit"],
|
|
|
|
|
|
|
|
checked: null,
|
|
|
|
checkedInternal: null,
|
|
|
|
|
2017-04-12 22:52:52 +08:00
|
|
|
init() {
|
2019-01-10 18:06:01 +08:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
this.set("checkedInternal", this.checked);
|
2017-04-12 22:52:52 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
@observes("checked")
|
|
|
|
checkedChanged() {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.set("checkedInternal", this.checked);
|
2017-04-12 22:52:52 +08:00
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("labelKey")
|
2017-04-12 22:52:52 +08:00
|
|
|
label(key) {
|
|
|
|
return I18n.t(key);
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("checked", "checkedInternal")
|
2017-04-12 22:52:52 +08:00
|
|
|
changed(checked, checkedInternal) {
|
|
|
|
return !!checked !== !!checkedInternal;
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
cancelled() {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.set("checkedInternal", this.checked);
|
2017-04-12 22:52:52 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
finished() {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.set("checked", this.checkedInternal);
|
2019-01-10 18:06:01 +08:00
|
|
|
this.action();
|
2017-04-12 22:52:52 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|