REFACTOR: change-timestamp controller (#7498)
This commit is contained in:
parent
c4b7fb2754
commit
4aaee7ee35
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue