I have a fancybox to manage users. Now I defined a function to set a user to primary. Here is the template:
<ul class="user-list">
{{#each inquiry.users as |user|}}
<li>
{{user.email}}
{{#if (isEqual user.id createdBy)}}<span> (primary) </span>
{{else}} <button type="button" class="pretty small btn" {{action 'setPrimary' user}}>Set to Primary</button>
{{/if}}
<div class="pretty small danger btn icon-right entypo icon-cancel" {{action 'removeUser' user}}><a href="#">remove</a></div>
</li>
{{/each}}
</ul>
Here is the controller:
createdBy: function() {
return this.get('inquiry.created_by');
}.property('inquiry'),
actions: {
setPrimary: function(user){
var inquiry = this.get('inquiry');
var userId = user.get('id');
inquiry.set('created_by', userId);
inquiry.save();
$.fancybox.update();
}
}
You see that createdBy in the isEqual helper is a computed property. If the user's id is equal to inquiry's created person's id, the user is the primary user. Or you can set the user as the primary user, which trigger an action to set the created_by
of inquiry to the current user's id. I used the $.fancybox.update()
to re-render the content, but when I click the Set as Primary
button nothing changed. Could someone tell me which part is wrong? Should I use observer instead of computed property for createdBy
property?
Aucun commentaire:
Enregistrer un commentaire