From 4aaee7ee35e4a3291b599b55d6e281a319a96ae3 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 8 May 2019 16:26:51 +0200 Subject: [PATCH] REFACTOR: change-timestamp controller (#7498) --- .../controllers/change-timestamp.js.es6 | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/change-timestamp.js.es6 b/app/assets/javascripts/discourse/controllers/change-timestamp.js.es6 index 87df9f226a9..6d64eb32e81 100644 --- a/app/assets/javascripts/discourse/controllers/change-timestamp.js.es6 +++ b/app/assets/javascripts/discourse/controllers/change-timestamp.js.es6 @@ -17,7 +17,7 @@ export default Ember.Controller.extend(ModalFunctionality, { @computed("date", "time") createdAt(date, time) { - return moment(date + " " + time, "YYYY-MM-DD HH:mm:ss"); + return moment(`${date} ${time}`, "YYYY-MM-DD HH:mm:ss"); }, @computed("createdAt") @@ -26,35 +26,32 @@ export default Ember.Controller.extend(ModalFunctionality, { }, @computed("saving", "date", "validTimestamp") - buttonDisabled() { - if (this.get("saving") || this.get("validTimestamp")) return true; - return Ember.isEmpty(this.get("date")); + buttonDisabled(saving, date, validTimestamp) { + if (saving || validTimestamp) return true; + return Ember.isEmpty(date); }, - onShow: function() { - this.setProperties({ - date: moment().format("YYYY-MM-DD") - }); + onShow() { + this.set("date", moment().format("YYYY-MM-DD")); }, actions: { - changeTimestamp: function() { + changeTimestamp() { this.set("saving", true); - const self = this, - topic = this.get("topicController.model"); - Topic.changeTimestamp(topic.get("id"), this.get("createdAt").unix()) - .then(function() { - self.send("closeModal"); - self.setProperties({ date: "", time: "", saving: false }); - Ember.run.next(() => { - DiscourseURL.routeTo(topic.get("url")); - }); + const topic = this.topicController.model; + + Topic.changeTimestamp(topic.id, this.createdAt.unix()) + .then(() => { + this.send("closeModal"); + this.setProperties({ date: "", time: "", saving: false }); + Ember.run.next(() => DiscourseURL.routeTo(topic.url)); }) - .catch(function() { - self.flash(I18n.t("topic.change_timestamp.error"), "alert-error"); - self.set("saving", false); - }); + .catch(() => + this.flash(I18n.t("topic.change_timestamp.error"), "alert-error") + ) + .finally(() => this.set("saving", false)); + return false; } }