discourse/app/assets/javascripts/admin/addon/controllers/admin-email-logs.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.1 KiB
JavaScript
Raw Normal View History

import Controller from "@ember/controller";
import EmailLog from "admin/models/email-log";
import EmberObject, { action } from "@ember/object";
export default class AdminEmailLogsController extends Controller {
loading = false;
filter = EmberObject.create();
2016-03-25 23:37:26 +08:00
loadLogs(sourceModel, loadMore) {
if ((loadMore && this.loading) || this.get("model.allLoaded")) {
return;
}
this.set("loading", true);
sourceModel = sourceModel || EmailLog;
2016-03-25 23:37:26 +08:00
let args = {};
Object.keys(this.filter).forEach((k) => {
if (this.filter[k]) {
args[k] = this.filter[k];
}
});
return sourceModel
.findAll(args, loadMore ? this.get("model.length") : null)
.then((logs) => {
if (this.model && loadMore && logs.length < 50) {
this.model.set("allLoaded", true);
}
if (this.model && loadMore) {
this.model.addObjects(logs);
} else {
this.set("model", logs);
}
})
.finally(() => this.set("loading", false));
}
@action
loadMore() {
this.loadLogs(EmailLog, true);
}
}