This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/controllers/edit-topic-timer.js.es6
Jarek Radosz fe588cc7f8
DEV: Fix function prototype deprecations (#8681)
* DEV: Fix the function prototype observers deprecation

DEPRECATION: Function prototype extensions have been deprecated, please migrate from function(){}.observes('foo') to observer('foo', function() {}). [deprecation id: function-prototype-extensions.observes] See https://deprecations.emberjs.com/v3.x/#toc_function-prototype-extensions-observes for more details.

* DEV: Fix the function prototype event listeners deprecation

DEPRECATION: Function prototype extensions have been deprecated, please migrate from function(){}.on('foo') to on('foo', function() {}). [deprecation id: function-prototype-extensions.on] See https://deprecations.emberjs.com/v3.x/#toc_function-prototype-extensions-on for more details.

* DEV: Simplify `default as` imports

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2020-01-16 18:56:53 +01:00

130 lines
3.4 KiB
JavaScript

import EmberObject from "@ember/object";
import Controller from "@ember/controller";
import discourseComputed from "discourse-common/utils/decorators";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import TopicTimer from "discourse/models/topic-timer";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { setProperties } from "@ember/object";
export const CLOSE_STATUS_TYPE = "close";
export const OPEN_STATUS_TYPE = "open";
export const PUBLISH_TO_CATEGORY_STATUS_TYPE = "publish_to_category";
export const DELETE_STATUS_TYPE = "delete";
export const REMINDER_TYPE = "reminder";
export const BUMP_TYPE = "bump";
export default Controller.extend(ModalFunctionality, {
loading: false,
isPublic: "true",
@discourseComputed("model.closed")
publicTimerTypes(closed) {
let types = [
{
id: CLOSE_STATUS_TYPE,
name: I18n.t(
closed ? "topic.temp_open.title" : "topic.auto_close.title"
)
},
{
id: OPEN_STATUS_TYPE,
name: I18n.t(
closed ? "topic.auto_reopen.title" : "topic.temp_close.title"
)
},
{
id: PUBLISH_TO_CATEGORY_STATUS_TYPE,
name: I18n.t("topic.publish_to_category.title")
},
{
id: BUMP_TYPE,
name: I18n.t("topic.auto_bump.title")
}
];
if (this.currentUser.get("staff")) {
types.push({
id: DELETE_STATUS_TYPE,
name: I18n.t("topic.auto_delete.title")
});
}
return types;
},
@discourseComputed()
privateTimerTypes() {
return [{ id: REMINDER_TYPE, name: I18n.t("topic.reminder.title") }];
},
@discourseComputed("isPublic", "publicTimerTypes", "privateTimerTypes")
selections(isPublic, publicTimerTypes, privateTimerTypes) {
return "true" === isPublic ? publicTimerTypes : privateTimerTypes;
},
@discourseComputed(
"isPublic",
"model.topic_timer",
"model.private_topic_timer"
)
topicTimer(isPublic, publicTopicTimer, privateTopicTimer) {
return "true" === isPublic ? publicTopicTimer : privateTopicTimer;
},
_setTimer(time, statusType) {
this.set("loading", true);
TopicTimer.updateStatus(
this.get("model.id"),
time,
this.get("topicTimer.based_on_last_post"),
statusType,
this.get("topicTimer.category_id")
)
.then(result => {
if (time) {
this.send("closeModal");
setProperties(this.topicTimer, {
execute_at: result.execute_at,
duration: result.duration,
category_id: result.category_id
});
this.set("model.closed", result.closed);
} else {
const topicTimer =
this.isPublic === "true" ? "topic_timer" : "private_topic_timer";
this.set(`model.${topicTimer}`, EmberObject.create({}));
this.setProperties({
selection: null
});
}
})
.catch(error => {
popupAjaxError(error);
})
.finally(() => this.set("loading", false));
},
actions: {
saveTimer() {
if (!this.get("topicTimer.updateTime")) {
this.flash(
I18n.t("topic.topic_status_update.time_frame_required"),
"alert-error"
);
return;
}
this._setTimer(
this.get("topicTimer.updateTime"),
this.get("topicTimer.status_type")
);
},
removeTimer() {
this._setTimer(null, this.get("topicTimer.status_type"));
}
}
});