REFACTOR: change-timestamp controller (#7498)

This commit is contained in:
Joffrey JAFFEUX 2019-05-08 16:26:51 +02:00 committed by GitHub
parent c4b7fb2754
commit 4aaee7ee35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 22 deletions

View File

@ -17,7 +17,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
@computed("date", "time") @computed("date", "time")
createdAt(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") @computed("createdAt")
@ -26,35 +26,32 @@ export default Ember.Controller.extend(ModalFunctionality, {
}, },
@computed("saving", "date", "validTimestamp") @computed("saving", "date", "validTimestamp")
buttonDisabled() { buttonDisabled(saving, date, validTimestamp) {
if (this.get("saving") || this.get("validTimestamp")) return true; if (saving || validTimestamp) return true;
return Ember.isEmpty(this.get("date")); return Ember.isEmpty(date);
}, },
onShow: function() { onShow() {
this.setProperties({ this.set("date", moment().format("YYYY-MM-DD"));
date: moment().format("YYYY-MM-DD")
});
}, },
actions: { actions: {
changeTimestamp: function() { changeTimestamp() {
this.set("saving", true); this.set("saving", true);
const self = this,
topic = this.get("topicController.model");
Topic.changeTimestamp(topic.get("id"), this.get("createdAt").unix()) const topic = this.topicController.model;
.then(function() {
self.send("closeModal"); Topic.changeTimestamp(topic.id, this.createdAt.unix())
self.setProperties({ date: "", time: "", saving: false }); .then(() => {
Ember.run.next(() => { this.send("closeModal");
DiscourseURL.routeTo(topic.get("url")); this.setProperties({ date: "", time: "", saving: false });
}); Ember.run.next(() => DiscourseURL.routeTo(topic.url));
}) })
.catch(function() { .catch(() =>
self.flash(I18n.t("topic.change_timestamp.error"), "alert-error"); this.flash(I18n.t("topic.change_timestamp.error"), "alert-error")
self.set("saving", false); )
}); .finally(() => this.set("saving", false));
return false; return false;
} }
} }