2018-06-15 23:03:24 +08:00
|
|
|
import EmailLog from "admin/models/email-log";
|
2016-01-19 07:57:55 +08:00
|
|
|
|
|
|
|
export default Ember.Controller.extend({
|
2016-03-25 23:37:26 +08:00
|
|
|
loading: false,
|
|
|
|
|
2019-02-27 00:53:52 +08:00
|
|
|
loadLogs(sourceModel, loadMore) {
|
|
|
|
if ((loadMore && this.get("loading")) || this.get("model.allLoaded")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set("loading", true);
|
|
|
|
|
|
|
|
sourceModel = sourceModel || EmailLog;
|
2016-03-25 23:37:26 +08:00
|
|
|
|
2019-02-27 00:53:52 +08:00
|
|
|
return sourceModel
|
|
|
|
.findAll(this.get("filter"), loadMore ? this.get("model.length") : null)
|
|
|
|
.then(logs => {
|
|
|
|
if (this.get("model") && loadMore && logs.length < 50) {
|
|
|
|
this.get("model").set("allLoaded", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.get("model") && loadMore) {
|
2018-06-15 23:03:24 +08:00
|
|
|
this.get("model").addObjects(logs);
|
2019-02-27 00:53:52 +08:00
|
|
|
} else {
|
|
|
|
this.set("model", logs);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.finally(() => this.set("loading", false));
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
loadMore() {
|
|
|
|
this.loadLogs(EmailLog, true);
|
2016-03-25 23:37:26 +08:00
|
|
|
}
|
2016-01-19 07:57:55 +08:00
|
|
|
}
|
|
|
|
});
|