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

View File

@ -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;
}
}