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