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