mardi 24 février 2015

Prevent further action executions

I've got a list of downloads in a blog-posts. Upon clicking on the link I'm incrementing a downloads downloadcount property. In order to prevent further executions I've got this Item-Controller download. For some reasons alreadyIncreased is always false even on consecutive executions of the actions. Why is that?



import Ember from 'ember';

export default Ember.ObjectController.extend({

alreadyIncreased: false,

actions: {
incDownload: function() {

if (this.get('alreadyIncreased') === false){
this.set('alreadyIncreased', true)

this.get('model').incrementProperty('downloadcount')
this.get('model').save()
}
}
}
})


This is the template:



{{#each download in post.downloads itemController="base.download" }}
<p>
<a {{ action "incDownload" }}>
{{ download.name }}
</a> - {{ download.downloadcount }} Hits
</p>
{{/each}}




Aucun commentaire:

Enregistrer un commentaire