Guys, i’m using the follow code to block edit and delete button, depending on how many checkbox are checked in the table list:
allowEdit: Ember.computed('model.@each.checked', function() {
let count = 0;
let result;
this.get('model').forEach(item => {
item.get('checked') ? count += 1 : count = count;
});
count === 1 ? result = true : result = false;
return result;
}),
allowDelete: Ember.computed('model.@each.checked', function() {
let count = 0;
let result;
this.get('model').forEach(item => {
item.get('checked') ? count += 1 : count = count;
});
count >= 1 ? result = true : result = false;
return result;
}),
And in my template i have:
{{#link-to "events.edit"}}
<li class="controller__item {{if allowEdit "" "controller__item--disabled"}}">
<i class="icon icon__pencil icon__2x"></i>
<span class="controller__legend">Editar</span>
</li>
{{/link-to}}
<li class="controller__item {{if allowDelete "" "controller__item--disabled"}}" {{action "delete"}}>
<i class="icon icon__trash icon__2x"></i>
<span class="controller__legend">Deletar</span>
</li>
As you can see, i’m doing pretty much the same thing in the two computed properties. I would like to replace the two for one, but i don’t know exactly how i could do that.
edit button will be free if just one checkbox are checked delete button will be free if one or more checkbox are checked.
Thanks!!