2019-04-18 17:52:59 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
import { i18n, propertyNotEqual } from "discourse/lib/computed";
|
2020-09-04 07:24:14 -04:00
|
|
|
import I18n from "I18n";
|
2019-04-18 17:52:59 -04:00
|
|
|
|
|
|
|
export default Ember.Component.extend({
|
|
|
|
classNames: "house-ads-setting",
|
|
|
|
adValue: "",
|
|
|
|
saving: false,
|
|
|
|
savingStatus: "",
|
|
|
|
title: i18n("name", "admin.adplugin.house_ads.%@.title"),
|
|
|
|
help: i18n("name", "admin.adplugin.house_ads.%@.description"),
|
|
|
|
changed: propertyNotEqual("adValue", "value"),
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.set("adValue", this.get("value"));
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
save() {
|
|
|
|
if (!this.get("saving")) {
|
|
|
|
this.setProperties({
|
|
|
|
saving: true,
|
2020-09-04 07:24:14 -04:00
|
|
|
savingStatus: I18n.t("saving"),
|
2019-04-18 17:52:59 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
ajax(
|
2019-10-08 17:41:13 -04:00
|
|
|
`/admin/plugins/pluginad/house_settings/${this.get("name")}.json`,
|
2019-04-18 17:52:59 -04:00
|
|
|
{
|
|
|
|
type: "PUT",
|
2020-09-04 07:24:14 -04:00
|
|
|
data: { value: this.get("adValue") },
|
2019-04-18 17:52:59 -04:00
|
|
|
}
|
|
|
|
)
|
2019-06-14 12:10:11 -04:00
|
|
|
.then(() => {
|
2019-04-18 17:52:59 -04:00
|
|
|
const adSettings = this.get("adSettings");
|
|
|
|
adSettings.set(this.get("name"), this.get("adValue"));
|
|
|
|
this.setProperties({
|
|
|
|
value: this.get("adValue"),
|
2020-09-04 07:24:14 -04:00
|
|
|
savingStatus: I18n.t("saved"),
|
2019-04-18 17:52:59 -04:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError)
|
|
|
|
.finally(() => {
|
|
|
|
this.setProperties({
|
|
|
|
saving: false,
|
2020-09-04 07:24:14 -04:00
|
|
|
savingStatus: "",
|
2019-04-18 17:52:59 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel() {
|
|
|
|
this.set("adValue", this.get("value"));
|
2020-09-04 07:24:14 -04:00
|
|
|
},
|
|
|
|
},
|
2019-04-18 17:52:59 -04:00
|
|
|
});
|