Don't hardcode code button index and remove the for loop and use .some()

This commit is contained in:
OsamaSayegh 2017-05-10 19:52:38 +03:00 committed by Robin Ward
parent 2f8b1e33f4
commit 26209354e3

View File

@ -26,18 +26,12 @@ export default Ember.Controller.extend(ModalFunctionality, {
categoryId: Ember.computed.alias('model.category.id'),
onShow() {
let showRelistButton = false;
const topics = this.get('model.topics');
for (let t = 0; t < topics.length; t++) {
if (!topics[t].visible) {
showRelistButton = true;
break;
}
}
if (showRelistButton && !_buttons[9]) {
const showRelistButton = this.get('model.topics').some(t => !t.visible);
const relistButtonIndex = _buttons.findIndex(b => b.action === 'relistTopics');
if (showRelistButton && relistButtonIndex === -1) {
addBulkButton('relistTopics', 'relist_topics');
} else if (!showRelistButton && _buttons[9]) {
_buttons.splice(9, 1);
} else if (!showRelistButton && relistButtonIndex !== -1) {
_buttons.splice(relistButtonIndex, 1);
}
this.set('modal.modalClass', 'topic-bulk-actions-modal small');