PDA

View Full Version : viewModel.linkTo() any way to hook up to events for masking ?



pmarko
2 Jul 2020, 8:03 AM
Hello,

I'm trying to figure out how to mask/unmask view while doing viewModel.linkTo('theModel', {type: 'Model', id: 1 });

theModel is updated only when loading is completed. I would like to apply load mask while model is loading. How can I get the
reference to the model without some hacking around viewModel internals ?


Thank you for any idea.

evant
3 Jul 2020, 3:36 PM
Depending on your version, you can bind to "store.loading" in a viewmodel. I can't remember when it was introduced, IIRC 6.5. The relevant code is in Ext.app.bind.Stub. If you see this in your source, it should be good to go,



loading: 'hasPendingLoad',

pmarko
6 Jul 2020, 12:19 PM
Hi Evan,

Thank you for your answer.

I'm using 7.2.0 modern. I'm aware of "store.loading" binding in a viewModel. The problem I have is with link. I do understand that viewModel is updated only when link is updated. It makes perfect sense. Only if there was a easy way to attach to load event.

At the moment I have to literately do this.

In controller.


load: function(id){
this.getViewModel().set('loading', true);
App.model.Record.load(id, {
scope: this,
callback: function(rec, op, success){
this.getViewModel().set('theRecord', rec);
this.getViewModel().set('loading', false);
}
})
}


I was hoping for...


In a ViewController


load: function(id){
this.getViewModel().linkTo('theRecord', { type: 'Record', id: id });
}


And in a View.

{
bind: {
masked: '{theRecord.loading ? "Loading..." : false }'
}
}

All this just because I'm using routing and can not pass objects between views anymore. Just id's.