jeudi 21 mai 2015

Refreshing model when button is clicked

I was wondering how I could refresh a model with a parameter which comes from a different controller. Basically I want to refresh the list model based on a parameter. The parameter "readstatus" is actually the value of "Filter" in the FilterbuttonController.

When you click on a li, the model should refresh. I know it doesn't seem right but that's how the app works right now and I have to find a way. Any suggestions? Code is below. Thank you.

I have a model :

App.ListRoute = Ember.Route.extend({

    model: function(readStatus){
        return this.store.find('list', { status : readStatus});
}

I have a template :

<script type="text/x-handlebars" data-template-name="filterbutton">      
    <div class="filter-dropdown dd">
        <button class="filter" {{ action 'toggleDd'}}><span id="current_text">{{ filter }}</span> &#xf107;</button> 
        {{#if ddVisible}}        
            <ul class="dropdowns">
                <li {{ action 'filterConversations' 'All'}}></li>
                <li {{ action 'filterConversations' 'Opened'}}><</li>
                <li {{ action 'filterConversations' 'Closed'}}></li>
                <li {{ action 'filterConversations' 'Unread'}}></li>
                <li {{ action 'filterConversations' 'Read'}}></li>
            </ul>
        {{/if}}
    </div>
</script>

This template is associated with the following controller :

App.FilterbuttonController = Ember.Controller.extend({

    ddVisible: false,
    filter: "Filter",

    actions: {

        toggleDd: function(){
            if (this.ddVisible){
                this.set('ddVisible', false);   
            }
            else{
                this.set('ddVisible', true)
            }
        },

        filterConversations: function(chosenFilter){
            this.send('toggleDd');
            this.set('filter', chosenFilter);

            **//This is where the refreshing should be with the value of filter**

        }           
    }
});




Aucun commentaire:

Enregistrer un commentaire