2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2020-02-19 17:01:21 +08:00
|
|
|
import { computed } from "@ember/object";
|
2019-10-31 04:13:48 +08:00
|
|
|
import Mixin from "@ember/object/mixin";
|
2020-02-19 17:01:21 +08:00
|
|
|
import { isPresent } from "@ember/utils";
|
2018-03-05 08:04:23 +08:00
|
|
|
|
2019-10-31 03:03:08 +08:00
|
|
|
export default Mixin.create({
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("value", "default")
|
2019-04-26 18:16:21 +08:00
|
|
|
overridden(val, defaultVal) {
|
2018-03-05 08:04:23 +08:00
|
|
|
if (val === null) val = "";
|
|
|
|
if (defaultVal === null) defaultVal = "";
|
|
|
|
|
|
|
|
return val.toString() !== defaultVal.toString();
|
2019-04-26 18:16:21 +08:00
|
|
|
},
|
2018-03-05 08:04:23 +08:00
|
|
|
|
2020-02-19 17:01:21 +08:00
|
|
|
computedValueProperty: computed(
|
|
|
|
"valueProperty",
|
|
|
|
"validValues.[]",
|
|
|
|
function() {
|
|
|
|
if (isPresent(this.valueProperty)) {
|
|
|
|
return this.valueProperty;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isPresent(this.validValues.get("firstObject.value"))) {
|
|
|
|
return "value";
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
),
|
|
|
|
|
|
|
|
computedNameProperty: computed("nameProperty", "validValues.[]", function() {
|
|
|
|
if (isPresent(this.nameProperty)) {
|
|
|
|
return this.nameProperty;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isPresent(this.validValues.get("firstObject.name"))) {
|
|
|
|
return "name";
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("valid_values")
|
2019-04-26 18:16:21 +08:00
|
|
|
validValues(validValues) {
|
2018-03-05 08:04:23 +08:00
|
|
|
const vals = [],
|
2019-05-27 16:15:39 +08:00
|
|
|
translateNames = this.translate_names;
|
2018-03-05 08:04:23 +08:00
|
|
|
|
2019-04-26 18:16:21 +08:00
|
|
|
validValues.forEach(v => {
|
2018-03-05 08:04:23 +08:00
|
|
|
if (v.name && v.name.length > 0 && translateNames) {
|
|
|
|
vals.addObject({ name: I18n.t(v.name), value: v.value });
|
|
|
|
} else {
|
|
|
|
vals.addObject(v);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return vals;
|
2019-04-26 18:16:21 +08:00
|
|
|
},
|
2018-03-05 08:04:23 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("valid_values")
|
2019-04-26 18:16:21 +08:00
|
|
|
allowsNone(validValues) {
|
2018-11-23 00:38:58 +08:00
|
|
|
if (validValues && validValues.indexOf("") >= 0) {
|
2018-03-05 08:04:23 +08:00
|
|
|
return "admin.settings.none";
|
2018-11-23 00:38:58 +08:00
|
|
|
}
|
2019-04-26 18:16:21 +08:00
|
|
|
}
|
2018-03-05 08:04:23 +08:00
|
|
|
});
|