2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2016-08-26 01:14:56 +08:00
|
|
|
|
|
|
|
export const States = {
|
|
|
|
UNCHECKED: 0,
|
|
|
|
INVALID: 1,
|
|
|
|
VALID: 2
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
_validState: null,
|
2016-09-01 01:35:49 +08:00
|
|
|
errorDescription: null,
|
2016-08-26 01:14:56 +08:00
|
|
|
|
|
|
|
init() {
|
2019-01-19 17:05:51 +08:00
|
|
|
this._super(...arguments);
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("_validState", States.UNCHECKED);
|
2016-08-26 01:14:56 +08:00
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("_validState")
|
2018-07-30 23:56:48 +08:00
|
|
|
valid: state => state === States.VALID,
|
2016-08-26 01:14:56 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("_validState")
|
2018-07-30 23:56:48 +08:00
|
|
|
invalid: state => state === States.INVALID,
|
2016-08-26 01:14:56 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("_validState")
|
2018-07-30 23:56:48 +08:00
|
|
|
unchecked: state => state === States.UNCHECKED,
|
2016-08-26 01:14:56 +08:00
|
|
|
|
2016-09-01 01:35:49 +08:00
|
|
|
setValid(valid, description) {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("_validState", valid ? States.VALID : States.INVALID);
|
2016-09-01 01:35:49 +08:00
|
|
|
|
|
|
|
if (!valid && description && description.length) {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("errorDescription", description);
|
2016-09-01 01:35:49 +08:00
|
|
|
} else {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.set("errorDescription", null);
|
2016-09-01 01:35:49 +08:00
|
|
|
}
|
2016-08-26 01:14:56 +08:00
|
|
|
}
|
|
|
|
};
|