2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2018-06-15 23:03:24 +08:00
|
|
|
import {
|
2019-11-08 05:38:28 +08:00
|
|
|
default as discourseComputed,
|
2018-06-15 23:03:24 +08:00
|
|
|
observes
|
2019-11-08 05:38:28 +08:00
|
|
|
} 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,
|
|
|
|
|
2018-06-15 23:03:24 +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) {
|
2018-06-15 23:03:24 +08:00
|
|
|
return !!checked !== !!checkedInternal;
|
2017-04-12 22:52:52 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2018-06-15 23:03:24 +08:00
|
|
|
cancelled() {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.set("checkedInternal", this.checked);
|
2017-04-12 22:52:52 +08:00
|
|
|
},
|
|
|
|
|
2018-06-15 23:03:24 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|