Results 1 to 3 of 3

Thread: Updating toolbar on model change

  1. #1
    Sencha User
    Join Date
    Dec 2012
    Location
    Hamburg, Germany
    Posts
    11
    Answers
    2
    Vote Rating
    0
      0  

    Default Answered: Updating toolbar on model change

    Hi!

    I'm searching for a neat way to bind the appearance of a toolbar to a model.

    In particular, I have a bunch of buttons that are visible or not depending on the model's state.
    Let's say the model is an item the user can watch. If he does (the watch property of the item turns true), I want to hide the toolbar's watch button and show an unwatch button.

    The only approach I came up with so far is to add all the buttons (there are 8) to the toolbar, hide them by default and simply call a method that hide()/show() s the respective buttons when the model changes or the view is initialized.

    I'm passing the model as record property to the toolbar during it's creation:
    Code:
    {xtype: 'mytoolbar', record: myModel}
    My next step would be to add a listener to the toolbar's controller that calls an updateButtons() method whenever the model is changed. But the only event I found is updatedata, which is only called if the toolbar's data is changed.

    Do I really need to use the data property of the toolbar instead of the record property? Because that would mean I have to call setData() everytime the model changes...

    But maybe there is a solution I don't know yet, so any help is appreciated :-)

  2. Use the updateRecord method in your toolbar component which will get called anytime the setRecord method is called or when the component is created with the record config.

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    Use the updateRecord method in your toolbar component which will get called anytime the setRecord method is called or when the component is created with the record config.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Dec 2012
    Location
    Hamburg, Germany
    Posts
    11
    Answers
    2
    Vote Rating
    0
      0  

    Default callParent necessary?

    Thanks for your help, it works as I need it.

    I added the updateRecord method like that:

    Code:
    Ext.define('App.view.Toolbar', {
       config: {
          updateRecord: function(newRec, oldRec) {
              this.callParent(newRec, oldRec);
    
               /*** do something ***/
           }
       }
    });

    However, I'm not sure if I need to call callParent or not, as it doesn't seem to change the behaviour I expect.

    Edit: Hm... as it turned out, I don't need to overwrite updateRecord at all... listenting the updatedata event is enough and will be fired upon model manipulation. Seems like I had some other bug when I tried that for the first time... thanks anyway.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •