Multiple Stores Loading Issue Sencha Touch - extjs

I have two Stores 'Polls' and 'Choices' with respective models as 'Poll' and 'Choice'
models
Poll
Ext.define('PollsTest.model.Poll', {
extend: 'Ext.data.Model',
xtype : 'poll',
config: {
fields: [
{ name: 'title'},
{ name: 'uri' },
],
hasMany :
[
{
model : 'PollsTest.model.Choices',
name : 'Choices',
primaryKey : 'title',
foreignKey : 'title',
foreignStore : 'Choices'
}
]
}
});
Choice
Ext.define('PollsTest.model.Choice', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'choice', type: 'auto' },
{ name: 'votes', type: 'auto' },
{name : 'title', type: 'auto'},
{name : 'uri', type : 'auto'}
],
belongsTo : {
model : 'PollsTest.model.Choices',
name : 'Choices',
primaryKey : 'title',
foreignKey : 'title',
foreignStore : 'Choices',
getterName: 'getChoices',
setterName: 'setChoices'
}
}
});
Stores
Polls
Ext.define('PollsTest.store.Polls',{
extend : 'Ext.data.Store',
alias : 'store.pollStore',
//xtype:'pollStore',
requires :
[
'PollsTest.model.Poll',
'Ext.data.proxy.JsonP',
'Ext.data.reader.Json'
],
config :
{
autoLoad : true,
model : 'PollsTest.model.Poll',
storeId :'pollStore',
listeners :
{
load : function(store, records)
{
console.log('store loaded',records);
}
},
//storeId : 'pollstore',
proxy :
{
type : 'jsonp',
url : 'http://localhost/polls',
reader :
{
type : 'json',
rootProperty : 'polls'
}
}
},
});
Choices
Ext.define('PollsTest.store.Choices',{
extend : 'Ext.data.Store',
alias : 'store.choiceStore',
requires :
[
'PollsTest.model.Choice'
],
config :
{
autoLoad : false,
model : 'PollsTest.model.Choice',
storeId :'choiceStore',
listeners :
{
load : function(store, records)
{
console.log('choice store loaded',records);
}
},
proxy :
{
type : 'jsonp',
url : '',
reader :
{
type: 'json',
rootProperty : 'choices'
}
}
},
});
So from Polls store I can populate my List and upon clicking the list item the controller pushes the detail panel to the view. The Choices Store will populate based on the tap event occurred on the list. So the problem is I have to push the details panel to the view only after loading the Choices Store
How can I do that?? Suggestions are appreciated.
and My controller will look like this
Ext.define('PollsTest.controller.MainController', {
extend: 'Ext.app.Controller',
requires : ['PollsTest.controller.ChoiceController'],
config: {
refs: {
mainController : 'mainpanel',
controller_list : 'pollslist',
details_controller : 'pollsdetails'
},
control: {
controller_list :
{
itemtap : 'ShowPoll'
},
}
},
ShowPoll : function (list, index, target, record, e, eOpts)
{
var tochoice = record.data.uri;
var main_path = 'http://localhost';
var choices_url = main_path+tochoice;
var choice_store_object = Ext.getStore('choiceStore');
choice_store_object.getProxy().setUrl(choices_url);
choice_store_object.load();
console.log(choice_store_object.getCount());
/* var choices_store_object = Ext.create('PollsTest.store.Choices');
var checking = choices_store_object.on('load',function(){return true;});
if(checking==true) --> didn't work no detail panel pushing is happening but the order of loading the stores works fine here.
{
*/ console.log('before pushing');
this.getMainController().push({xtype : 'pollsdetails',data : record.data });
console.log('after Pushing');
// }
//this.getApplication().getController('ChoiceController').onDetailsShow(this,record,tochoice);
}
});

You can pass a callback function in your choice store load function. The callback function will be executed after the store has loaded.
choice_store_object.load(function(records, operation, success) {
// push the pollsdetails view here
}, this);

This is how I `i have implemented
var choices_store_object = Ext.create('PollsTest.store.Choices');
var checking =choice_store_object.load(function(records, operation, success)
{
console.log('before pushing');
this.getMainController().push({xtype : 'pollsdetails',data : record.data });
console.log('after Pushing');
}, this);
`

Related

How to default select a childnodes in extjs

I am having a breadcrumb toolbar where I have to display childnode default selected. I am using a treestore and root is what i am creating and then making an ajax call to get the childnodes. In my view I am default selecting a selection : pStore.getRoot().childNodes[2], its giving me null.
even pStore.getRoot().firstChild is giving null. Nor sure what i am missing.
Any help is appreciated.
Thanks!
Store
Ext.define('Online.store.Publications',
{
extend : 'Ext.data.TreeStore',
alias : 'store.Publications',
nodeParam : 'id',
autoLoad : true,
root : {
text : 'Pubs ►',
id : 'pub',
expanded : true,
iconCls : 'doc-folder',
leaf : false
},
rootVisible : false,
proxy : {
type : 'ajax',
noCache : false,
url : Online.getBaseURL()+'/nPub/getPublicationsJSON',
reader : {
type : 'json'
},
timeout : 60000,
}
}
});
View
Ext.define('Online.view.Breadcrumb', {
extend : 'Ext.toolbar.Toolbar',
xtype : 'navigation-toolbar',
id : 'navigation-toolbar',
requires : [
'Online.view.BreadcrumbController'
],
controller : 'breadcrumb',
reference : 'navigation-toolbar',
initComponent : function() {
var pStore = Ext.create('store.Publications');
));
Ext.apply(this, {
items : [
{
xtype : 'breadcrumb',
id : 'navigation-breadcrumb',
reference : 'breadcrumb',
useSplitButtons : false,
flex : 0.85,
showIcons : false,
useArrows : true,
bind : {
selection : '{id}'
},
store : pStore,
selection : pStore.getRoot(),
autoLoad : false,
rootVisible : fals
}
]
});
this.callParent();
}
});
Ext.define('Online.view.Breadcrumb', {
extend : 'Ext.toolbar.Toolbar',
xtype : 'navigation-toolbar',
id : 'navigation-toolbar',
requires : [
'Online.view.BreadcrumbController'
],
controller : 'breadcrumb',
reference : 'navigation-toolbar',
initComponent : function() {
var pStore = Ext.create('store.Publications');
var PChilds;
));
Ext.apply(this, {
items : [
{
xtype : 'breadcrumb',
id : 'navigation-breadcrumb',
reference : 'breadcrumb',
useSplitButtons : false,
flex : 0.85,
showIcons : false,
useArrows : true,
bind : {
selection : '{id}'
},
store : pStore,
selection :'',
autoLoad : false,
rootVisible : fals
}
]
});
***pStore.on('load', function(store, records) {
PChilds = pStore.getRootNode().childNodes[0]
var nodeObj = this.items.items[1];
nodeObj.setSelection(PChilds);
},this);***
this.callParent();
}
});

Update Grid Store on Row Editing

I am trying to update the store on RowEditing Update click
Added a Listeners as
listeners: {
'edit': function (editor, e) {
alert('Row Updating');
}
}
Alert is firing on UPdate click so tried to update the store now as below
1.var rec = e.record;
e.store.sync();
2. var timeGrid = this.up('grid');
timeGrid.store.sync();
3. Ext.ComponentQuery.query('#gdItemId')[0].store.sync();
4. this.store.sync();
All the above is failing to update the changed records to store.
It is throwing error as -
Unhandled exception at line 1984, column 17
0x80004005 - JavaScript runtime error: unknown exception
What would be the reason? Please suggest me, how can i update the data here.
Updating :
Adding complete code -
Ext.define('TimeModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'stop_type_id', type: 'int' }
]
});
----------------------
var storeStop = new Ext.data.SimpleStore({
fields: ["value", "text"],
data: [
[1, "Delivery"],
[2, "Pickup"]
]
});
---------------------------
var comboBoxStopRenderer = function (comboStop) {
return function (value) {
var idx = comboStop.store.find(comboStop.valueField, value);
var rec = comboStop.store.getAt(idx);
return (rec === null ? '' : rec.get(comboStop.displayField));
};
}
------------------------
var comboStop = new Ext.form.ComboBox({
store: storeStop,
valueField: "value",
displayField: "text"
});
xtype: 'grid',
itemId: 'gdTimeCommitmentItemId',
store: {
type: 'webapi',
api: {
read: 'api/Report/GetTime'
},
autoLoad: false,
},
columns: [
{
text: 'Stop Type', dataIndex: 'stop_type_id', width: '12%', editor: comboStop, renderer: comboBoxStopRenderer(comboStop)
}
],
plugins: [rowEditingTime],
tbar: [
{
text: 'Add',
handler: function () {
rowEditingTime.cancelEdit();
var timeGrid = this.up('grid');
var r = Ext.create('TimeModel', {
stop_type_id: 1
});
timeGrid.store.insert(0, r);
rowEditingTime.startEdit(0, 0);
}
} ],
listeners: {
'edit': function (editor, e) {
//alert('Updating');
//var rec = e.record;
//e.store.sync();
//var timeGrid = this.up('grid');
//timeGrid.store.sync();
// Ext.ComponentQuery.query('#gdTimeCommitmentItemId')[0].store.sync();
//this.store.sync();
}
}
Include your store proxy class in your question. I think you didn't created your store proxy correctly.
example Store proxy for the Sync
proxy :
{
type : 'ajax',
reader :
{
root : 'data',
type : 'json'
},
api :
{
read : '/ExampleService.svc/students/',
create: '/ExampleService.svc/createstudentbatch/',
update : '/ExampleService.svc/updatestudentbatch/',
destroy : '/ExampleService.svc/deletestudentbatch/'
},
actionMethods :
{
destroy : 'POST',
read : 'GET',
create : 'POST',
update : 'POST'
}}

How to display name/value pairs into a Ext.grid.Panel from a Ext.data.Store

Here is the store :
Ext.define( 'LFinanceCRM.store.Prospect', {
extend : 'Ext.data.Store',
buffered : false,
autoLoad : true,
remoteFilter : true,
storeId : 'prospect-store',
proxy : {
type : 'ajax',
url : 'services/getProspect.php',
filterParam : undefined,
limitParam : undefined,
startParam : undefined,
pageParam : undefined,
idParam : 'id',
reader : {
type : 'json',
root : 'prospect'
}
},
fields : [
{ name : 'id' },
{ name : 'value' }
],
constructor : function(){
this.callParent( arguments );
console.log( 'new ' + this.self.getName());
}
});
Here is the PHP code:
<?php
include_once 'db.php';
header( "Content-type: application/json; charset=utf-8" );
$id = #mysql_real_escape_string($_GET['id']);
$link = db_open();
$query = "SELECT name, value FROM Pairs WHERE id = '$id'";
$result = #mysql_query( $query, $link );
$pairs = array();
if( $result ) {
while( $row = mysql_fetch_assoc( $result )) {
$item = Array();
$item['id' ] = $row['name' ];
$item['value'] = $row['value'];
$pairs[] = $item;
}
}
$response = array( 'prospect' => $pairs );
print json_encode( $response );
#mysql_free_result( $result );
#mysql_close( $link );
?>
Here is the JSON received from PHP:
{prospect:[
{id:'aaa',value:'vvvv'},
{id:'bbb',value:'vvvv'},
...
{id:'yyy',value:'vvvv'},
{id:'zzz',value:'vvvv'},
}]
Here is the view:
Ext.define( 'LFinanceCRM.view.RawDataView', {
extend : 'Ext.grid.Panel',
requires :[],
alias : 'widget.raw-data-view',
autoScroll : true,
title : 'Données brutes',
columnLines : true,
viewConfig : { stripeRows : true },
store : Ext.data.StoreManager.lookup( 'prospect-store' ),
columns : [{
text : 'Nom',
dataIndex : 'name',
sortable : false,
width : '29%'
},{
text : 'Valeur',
dataIndex : 'value',
sortable : true,
width : '70%'
}],
constructor : function() {
this.callParent( arguments );
console.log('new ' + this.self.getName());
}
});
I use the MVC pattern supported by Sencha app build tool, here is the controller:
Ext.define( 'LFinanceCRM.controller.Main', {
extend : 'Ext.app.Controller',
id : 'theController',
onNonLuesSelectionChanged : function( panel, selected, eOpts ) {
console.log('onNonLuesSelectionChanged: ' + selected[0].data.id );
this.getStore('Prospect').load({
id : selected[0].data.id,
callback : function( records, operation, success ) {
var pairs = [];
for( var i = 0; i < records.length; ++i ) {
pairs.push( records[i].data );
}
Ext.ComponentQuery.query('client-view')[0].getForm().setValues( pairs );
Ext.ComponentQuery.query('immo-view' )[0].getForm().setValues( pairs );
}
});
},
onSavePairs : function() {
console.log('onSavePairs');
},
...
onMail : function() {
console.log('onMail');
},
...
stores : ['Prospect'],
constructor : function(){
this.callParent( arguments );
console.log( 'new ' + this.self.getName());
this.control({
'#ProspectsTableNonLues' : { selectionchange : this.onNonLuesSelectionChanged },
...
'#savePairsButton' : { click : this.onSavePairs },
...
'#mail' : { click : this.onMail },
});
}
});
Nothing is displayed yet!
My question is : how can I transform the data from store to feed the view with them?
Your LFinanceCRM.view.RawDataView config is not properly defined.
You should create an instance of Store to assign to the grid panel -
store : Ext.data.StoreManager.lookup( 'prospect-store' ),
should be changed to
store : Ext.create("LFinanceCRM.store.Prospect"),
Also in columns config, dataIndex should be "id" for the first column instead of "name"
{
text : 'Nom',
dataIndex : 'name',
sortable : false,
width : 200
}
should be changed to
{
text : 'Nom',
dataIndex : 'id',
sortable : false,
width : 200
}
Replace your LFinanceCRM.view.RawDataView code with this -
Ext.define( 'LFinanceCRM.view.RawDataView', {
extend : 'Ext.grid.Panel',
alias : 'widget.raw-data-view',
autoScroll : true,
title : 'Données brutes',
columnLines : true,
viewConfig : { stripeRows : true },
store : Ext.create("LFinanceCRM.store.Prospect"),
columns : [{
text : 'Nom',
dataIndex : 'id',
sortable : false,
width : 200
},{
text : 'Valeur',
dataIndex : 'value',
sortable : true,
width : 200
}],
constructor : function() {
this.callParent( arguments );
console.log('new ' + this.self.getName());
}
});
To avoid double request to the server and some other reasons, I prefer share the instance of the store betweens several views.
As pointed out by Prasad K, a mistake between name and id must be corrected.
As pointed in the documentation of Sencha Extjs4.2.2, when a store is instantiated by a controller, its id is the name of its class, even an id is set (bug?).
So the code becomes:
Ext.define( 'LFinanceCRM.view.RawDataView', {
extend : 'Ext.grid.Panel',
alias : 'widget.raw-data-view',
autoScroll : true,
title : 'Données brutes',
columnLines : true,
viewConfig : { stripeRows : true },
store : 'Prospect',
columns : [{
text : 'Nom',
dataIndex : 'id',
sortable : false,
width : '29%'
},{
text : 'Valeur',
dataIndex : 'value',
sortable : true,
width : '70%'
}],
constructor : function() {
this.callParent( arguments );
console.log('new ' + this.self.getName());
}
});
And it works!

How to represent UML Relations with Backbone-Relational?

I have Class Diagram looking like this :
ModelA 1------* ModelB 1------* ModelC 1------* ModelD
Edit :
The Data looks like that
Data :
{ "Titel" : "ModelA",
"ModelA" : [
{
"Titel" : "ModelB1",
"ModelB1" : [
{
"Titel" : "ModelC1",
"ModelC1":[
{ "Titel" : "ModelD1" },
{ "Titel" : "ModelD2" },
{ "Titel" : "ModelD3" }
},
{
"Titel" : "ModelC2",
"ModelC2":[
{ "Titel" : "ModelD21" },
{ "Titel" : "ModelD22" },
{ "Titel" : "ModelD23" }
},
]
},
{
"Titel" : "ModelB2",
"ModelB2" : [
{
"Titel" : "ModelC1",
"ModelC1":[
{ "Titel" : "ModelD1" },
{ "Titel" : "ModelD2" },
{ "Titel" : "ModelD3" }
},
{
"Titel" : "ModelC2",
"ModelC2":[
{ "Titel" : "ModelD21" },
{ "Titel" : "ModelD22" },
{ "Titel" : "ModelD23" }
},
]
}]
}
I create those RelationalModel :
ModelA :
ModelA = Backbone.RelationalModel.extend({
relations:[{
type: Backbone.HasMany,
key: 'modelb',
relatedModel: 'ModelB',
collectionType: 'ModelBCollection',
reverseRelation:{
key: 'belong To',
includeInJSON: 'id'
}
}] });
ModelB :
ModelB = Backbone.RelationalModel.extend({
relations:[{
type: Backbone.HasMany,
key: 'modelc',
relatedModel: 'ModelC',
collectionType: 'ModelCCollection',
reverseRelation:{
key: 'belong To',
includeInJSON: 'id'
}
}] });
ModelC :
ModelC = Backbone.RelationalModel.extend({
relations:[{
type: Backbone.HasMany,
key: 'modeld',
relatedModel: 'ModelD',
collectionType: 'ModelDCollection',
reverseRelation:{
key: 'belong To',
includeInJSON: 'id'
}
}] });
ModelD :
ModelD = Backbone.Model.extend({ });
Collections :
ModelACollection = Backbone.Collection.extend({ model: ModelA });
ModelBCollection = Backbone.Collection.extend({ model: ModelB });
ModelCCollection = Backbone.Collection.extend({ model: ModelC });
ModelDCollection = Backbone.Collection.extend({ model: ModelD });
and i do this in the Router :
Router :
var obja = new ModelACollection(data);
var objb = new ModelBCollection(data.objb);
var objc = new ModelCCollection(data.objc);
var objd = new ModelDCollection(data.objd);
all get fetched but with many warning (firefox, chrome) looks like this :
Warning :
Relation=%o; no model, key or relatedModel (%o, %o, %o) ....
What is the meaning of this Warning?
That's the right to represent this Class Relation with Backbone-relational isn't?
if not?
How can i represent this as a Backbone ModelRelational?
In Model A you are defining
key: 'modelb'
which links to Model B. However, key should be "a string. References an attribute name on relatedModel" (based on the docs). And I cannot see and model field called modelb

TreePanel Error : Uncaught TypeError: Cannot call method 'substring' of undefined

I've a problem while rendering TreePanel. I'm using MVC structure, here's my definition:
(By the way I don't use dynamic loading, included ext-all-debug.)
Menu - Model
Ext.define('RIA4.model.Menu', { extend : 'Ext.data.Model',
idProperty : 'menuId',
fields : [
{ name : 'menuId', type : 'int' },
{ name : 'menuName', type : 'string' },
{ name : 'sourcePath', type : 'string' },
{ name : 'active', type : 'boolean', defaultValue : true },
{ name : 'leaf', type : 'boolean' }
]
});
TreeStore
Ext.define('RIA4.store.Menus', { extend : 'Ext.data.TreeStore',
model : 'RIA4.model.Menu',
proxy : {
type : 'ajax',
api : {
read : 'menu/view.ajax'
},
reader : {
type : 'json',
root : 'data',
successProperty : 'success'
}
},
autoLoad : true
});
TreePanel
Ext.define('RIA4.view.menu.MenuTree', { extend : 'Ext.tree.Panel',
alias : 'widget.menutree',
//requires : [],
title : 'Menu List',
store : 'Menus',
rootVisible : false,
root : {expanded: true, text: "", "data": []}
});
I'll be happy if someone can help me?
Thanks in advance..
Haven't you forgotten to add the following line to controller's config:
views: [ 'menu.MenuTree' ],

Resources