2016-06-30 13:55:44 -04:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
2016-06-07 06:55:01 -04:00
|
|
|
export default Ember.Component.extend({
|
|
|
|
layoutName: "components/poll-voters",
|
|
|
|
tagName: 'ul',
|
|
|
|
classNames: ["poll-voters-list"],
|
|
|
|
isExpanded: false,
|
2016-06-09 09:33:17 -04:00
|
|
|
numOfVotersToShow: 0,
|
|
|
|
offset: 0,
|
|
|
|
loading: false,
|
|
|
|
pollsVoters: null,
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super();
|
|
|
|
this.set("pollsVoters", []);
|
|
|
|
},
|
|
|
|
|
|
|
|
_fetchUsers() {
|
|
|
|
this.set("loading", true);
|
|
|
|
|
2016-06-30 13:55:44 -04:00
|
|
|
ajax("/polls/voters.json", {
|
2016-06-09 09:33:17 -04:00
|
|
|
type: "get",
|
|
|
|
data: { user_ids: this.get("voterIds") }
|
|
|
|
}).then(result => {
|
|
|
|
if (this.isDestroyed) return;
|
|
|
|
this.set("pollsVoters", this.get("pollsVoters").concat(result.users));
|
|
|
|
this.incrementProperty("offset");
|
|
|
|
this.set("loading", false);
|
|
|
|
}).catch((error) => {
|
|
|
|
Ember.logger.log(error);
|
|
|
|
bootbox.alert(I18n.t('poll.error_while_fetching_voters'));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_getIds(ids) {
|
|
|
|
const numOfVotersToShow = this.get("numOfVotersToShow");
|
|
|
|
const offset = this.get("offset");
|
|
|
|
return ids.slice(numOfVotersToShow * offset, numOfVotersToShow * (offset + 1));
|
|
|
|
},
|
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
this._super();
|
|
|
|
|
2016-07-28 11:04:45 -04:00
|
|
|
this.set("numOfVotersToShow", Math.round(this.$().width() / 25) * 2);
|
|
|
|
if (this.get("voterIds").length > 0) this._fetchUsers();
|
2016-06-09 09:33:17 -04:00
|
|
|
},
|
2016-06-07 06:55:01 -04:00
|
|
|
|
|
|
|
actions: {
|
2016-06-09 09:33:17 -04:00
|
|
|
loadMore() {
|
|
|
|
this._fetchUsers();
|
2016-06-07 06:55:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|