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) {
|
2019-05-27 16:15:39 +08:00
|
|
|
if ((loadMore && this.loading) || this.get("model.allLoaded")) {
|
2019-02-27 00:53:52 +08:00
|
|
|
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
|
2019-05-27 16:15:39 +08:00
|
|
|
.findAll(this.filter, loadMore ? this.get("model.length") : null)
|
2019-02-27 00:53:52 +08:00
|
|
|
.then(logs => {
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.model && loadMore && logs.length < 50) {
|
|
|
|
this.model.set("allLoaded", true);
|
2019-02-27 00:53:52 +08:00
|
|
|
}
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.model && loadMore) {
|
|
|
|
this.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
|
|
|
}
|
|
|
|
});
|