discourse/app/assets/javascripts/wizard/mixins/valid-state.js.es6

37 lines
789 B
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import computed from "ember-addons/ember-computed-decorators";
2016-08-26 01:14:56 +08:00
export const States = {
UNCHECKED: 0,
INVALID: 1,
VALID: 2
};
export default {
_validState: null,
errorDescription: null,
2016-08-26 01:14:56 +08:00
init() {
this._super(...arguments);
2018-06-15 23:03:24 +08:00
this.set("_validState", States.UNCHECKED);
2016-08-26 01:14:56 +08:00
},
2018-07-30 23:56:48 +08:00
@computed("_validState")
valid: state => state === States.VALID,
2016-08-26 01:14:56 +08:00
2018-07-30 23:56:48 +08:00
@computed("_validState")
invalid: state => state === States.INVALID,
2016-08-26 01:14:56 +08:00
2018-07-30 23:56:48 +08:00
@computed("_validState")
unchecked: state => state === States.UNCHECKED,
2016-08-26 01:14:56 +08:00
setValid(valid, description) {
2018-06-15 23:03:24 +08:00
this.set("_validState", valid ? States.VALID : States.INVALID);
if (!valid && description && description.length) {
2018-06-15 23:03:24 +08:00
this.set("errorDescription", description);
} else {
2018-06-15 23:03:24 +08:00
this.set("errorDescription", null);
}
2016-08-26 01:14:56 +08:00
}
};