Affichage des articles dont le libellé est ViewModel access from ViewController and same ViewModel. Afficher tous les articles
Affichage des articles dont le libellé est ViewModel access from ViewController and same ViewModel. Afficher tous les articles

vendredi 30 janvier 2015

ViewModel access from ViewController and same ViewModel

Hello, im moving to extjs5 and writing an application from scratch.

I have a view that contains (among other things) this



Code:



{
xtype: 'panel',
flex: 1,
margin: '0 10 5 0',
layout: {
type: 'hbox',
pack: 'end'
},
items: {
xtype: 'displayfield',
name: 'statusBanner',
bind: '{astatus}'
}
}

Then i have this inside my viewModel

Code:



Ext.define('cc.view.Agent.AgentModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.agent',
data: {
astatus: 'unknown'
},
formulas: {
agentname: function (a) {
var infoObj = JSON.parse(localStorage.getItem("infoLogin"));
if (infoObj !== undefined)
{
return infoObj.user.usuario;
}
return 'ND';
}
}
,
stores: {
Agents: {
storeID: 'agentsStore',
fields: ['name', 'type', 'status', 'contact', 'maxNoAnswer', 'wrapUpTime', 'rejectDelayTime', 'busyDelayTime'],
proxy: {
type: 'ajax',
url: '/cccore/agents',
reader: {
type: 'json',
rootProperty: 'agents',
successProperty: 'success',
totalProperty: 'total'
}
},
filters: [{
property: 'name',
value: '{agentname}',
operator: '='
}],
listeners : {
load: {
fn: function(){
console.log(); //<<<<---- from here
}
}
},
autoLoad: true
}
}
});

How can i, where says 'from here' set the value of astatus inside data? (meaning with this, i want to astatus be setted with the status field of the first record from the store)

after that, on my viewController i have this



Code:



Ext.define('cc.view.Agent.AgentController', {
extend: 'Ext.app.ViewController',
alias: 'controller.agent',
//aca tengo que escribir los metodos para procesar los eventos
onClickNoDisponible: function () {
this.changeStatus('Logged Out');
},
onClickDisponible: function () {
this.changeStatus('Available');
},
onClickManual: function () {
this.changeStatus('Available (On Demand)');
},
onClickDescanso: function () {
this.changeStatus('On Break');
},
changeStatus: function (status) {
//crear form, submitear, dar load al store de agentes
var form = Ext.create('Ext.form.Panel', {
items: [
{
xtype: 'hiddenfield',
name: 'username',
value: this.getViewModel().get('agentname')
},
{
xtype: 'hiddenfield',
name: 'status',
value: status
}
]
});

// console.log(status+" for "+this.getViewModel().get('agentname'));
// console.log(this.getViewModel().getStore('Agents'));
if (form.isValid()) {
form.submit({
url: '/cccore/agentstatus',
method: 'POST',
success: function (form, action) {
//FROM HERE <----------------------------- FROM HERE
},
failure: function (form, action) {
Ext.Msg.alert('Error en comando', action.result.msg);
}
});
}
}


});

how can i call to load again the Agents store inside my viewModel?

Sorry to ask this, i've been trying and i cannot realize it






ViewModel access from ViewController and same ViewModel