2019-10-23 12:30:52 -04:00
|
|
|
import Component from "@ember/component";
|
2020-11-24 05:10:28 -05:00
|
|
|
import { action } from "@ember/object";
|
|
|
|
import discourseComputed 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"],
|
|
|
|
|
2020-11-24 05:10:28 -05:00
|
|
|
buffer: null,
|
|
|
|
bufferModelId: null,
|
2019-01-10 05:06:01 -05:00
|
|
|
|
2020-11-24 05:10:28 -05:00
|
|
|
didReceiveAttrs() {
|
2019-01-10 05:06:01 -05:00
|
|
|
this._super(...arguments);
|
|
|
|
|
2020-11-24 05:10:28 -05:00
|
|
|
if (this.modelId !== this.bufferModelId) {
|
|
|
|
// HACK: The condition above ensures this method is called only when its
|
|
|
|
// attributes are changed (i.e. only when `checked` changes).
|
|
|
|
//
|
|
|
|
// Reproduction steps: navigate to theme #1, switch to theme #2 from the
|
|
|
|
// left-side panel, then switch back to theme #1 and click on the <input>
|
|
|
|
// element wrapped by this component. It will call `didReceiveAttrs` even
|
|
|
|
// though none of the attributes have changed (only `buffer` does).
|
|
|
|
this.setProperties({
|
|
|
|
buffer: this.checked,
|
|
|
|
bufferModelId: this.modelId,
|
|
|
|
});
|
|
|
|
}
|
2017-04-12 10:52:52 -04:00
|
|
|
},
|
|
|
|
|
2020-11-24 05:10:28 -05:00
|
|
|
@discourseComputed("checked", "buffer")
|
|
|
|
changed(checked, buffer) {
|
|
|
|
return !!checked !== !!buffer;
|
2017-04-12 10:52:52 -04:00
|
|
|
},
|
|
|
|
|
2020-11-24 05:10:28 -05:00
|
|
|
@action
|
|
|
|
apply() {
|
|
|
|
this.set("checked", this.buffer);
|
|
|
|
this.action();
|
2017-04-12 10:52:52 -04:00
|
|
|
},
|
|
|
|
|
2020-11-24 05:10:28 -05:00
|
|
|
@action
|
|
|
|
cancel() {
|
|
|
|
this.set("buffer", this.checked);
|
2017-04-12 10:52:52 -04:00
|
|
|
},
|
|
|
|
});
|