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