SenchaTouch 2 Send values to WebService - BEGINNER - sencha-touch

I am following a senchaTouch tutorial. I have a Web service called HelloWorld.php, located in the URL http://mydomainTest.com/Proj/HelloWorld.php. It takes 3 values, name, email and description.
The web service uses POST method.
My code is as follows; What i want to know is that i haven't specified the Values for Keys (POST value Keys) and how will the web service know, what to save for the Keys (name,email, description)
When creating native iPhone apps, i use to say setPostValue: forKey: (in ASIHttpRequest), what i need to know is how to set the Key for the value passed in Sencha. I have attached my code below, please take a look and help me out.
Ext.define('GS.view.Contacts', {
extend:'Ext.form.Panel',
xtype:'contactform',
config:{
title:'Contact',
iconCls:'user',
url:'http://mydomainTest.com/Proj/HelloWorld.php',
items:[
{
xtype:'fieldset',
title: 'Contact Us',
instructions: '(email is not required)',
items: [
{
xtype:'textfield',
name: 'name',
label:'Name'
},
{
xtype:'emailfield',
name:'email',
label:'Email'
},
{
xtype:'textareafield',
name:'message',
label:'Message'
}
]
},
{
items:[
{
xtype:'button',
text: 'Submit',
ui:'confirm',
handler: function(){
this.up('contactform').submit();
}
}
]
}
]
}
} );

Follow the below steps :-
Get all the form values using var values = Ext.getCmp('contactForm').getValues() where contactForm is an id of this formpanel.
Make an Ext.Ajax request and pass the params property the value of values
Use a success handler to verify the success of request. Print the response text in the console log
Try this
Ext.define('GS.view.Contacts', {
extend:'Ext.form.Panel',
xtype:'contactform',
id:'contactForm',
config:{
title:'Contact',
iconCls:'user',
items:[
{
xtype:'fieldset',
title: 'Contact Us',
instructions: '(email is not required)',
items: [
{
xtype:'textfield',
name: 'name',
label:'Name'
},
{
xtype:'emailfield',
name:'email',
label:'Email'
},
{
xtype:'textareafield',
name:'message',
label:'Message'
}
]
},
{
items:[
{
xtype:'button',
text: 'Submit',
ui:'confirm',
handler: function(){
var values = Ext.getCmp('contactForm').getValues();
// prints the values filled in the form
// text fields of name, email and message.
console.log(values.name+","+values.email+","+values.message);
Ext.Ajax.request({
url: 'http://mydomainTest.com/Proj/HelloWorld.php',
params : values,
success: function(response){
var text = response.responseText;
Ext.Msg.alert('Success', text);
}
});
}
}
]
}
]
}
} );

Related

Sencha Touch proxy send post request with dynamic arguments

I want to send post request in sencha touch and the arguments I want to post are dynamic i.e. I want to take the textField values as a parameters to post. Please help me
proxy: {
type: "ajax",
url:'http://anotherserver.com/query.php',
method:'post',
extraParams: {
val: "TextField1.Text" // **here I want to provide the value of the textField help me plz**
},
reader: {
type: "json",
rootProperty: "notes",
totalProperty: "total"
}
},
Look first for Sencha Touch model concept because your can tag along your model into your Form (Ext.FormPanel) and treat it as one.
var model = Ext.create('Ext.data.Model',{
fields: ['name', 'email', 'password'],
proxy: [] //your proxy settings here,
customFunctionWithAjax: function(){
}
});
var form = Ext.create('Ext.form.Panel', {
fullscreen: true,
items: [
{
xtype: 'textfield',
name: 'name',
label: 'Name'
},
{
xtype: 'emailfield',
name: 'email',
label: 'Email'
},
{
xtype: 'passwordfield',
name: 'password',
label: 'Password'
}
]
});
//after filling up your form you can get all textfields value
//with .getValues() and set it to your model
model.setData(form.getValues);
//then you can do anything you want like SAVE, or update
model.save();
//or call your custom function with your customised ajax request
model.customFunctionWithAjax();
// you can also check if your data are correct before sending it using .validate();
model.validate();
Usually you want to wrap the text field inside a form (formpanel).
Then you can use
var form = Ext.Viewport.down('.formpanel'),
values = form.getValues(),
textfieldValue = values.textfield_name;
...
extraParams: {
val: textfieldValue
},

Linking SSO users to item's detail page

I am displaying snapshot store records in a rallygrid component and would like to make it so the ID field is clickable and brings up the detail page for that work item. Since snapshot records include an "_UnformattedID" rather than "FormattedID", I tried to accomplish this using a column renderer, which adds the text as a link:
renderer: function(val, meta, record) {
return 'US' + record.get('_UnformattedID') + '';
}
This works perfectly for me, as a non-SSO user, but users in our workspace who are using SSO have reported that the link simply brings them to their default start page. Not the detail page they were expecting.
Is there a better way I could be accomplishing this that would allow all users the functionality?
SSO implementation is different across organization, but this trick worked for me.
I detect the host:
this._host = window.location.hostname;
and then I use host when building the return value of the renderer since the resulting URL in SSO and Non-SSO scenarios in my environment only differ in the host portion.
{
text: 'Formatted ID', dataIndex: 'UnformattedID',
renderer: function(val, meta, record) {
return 'US' + record.get('UnformattedID') + '';
}
}
.
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
launch: function() {
this._host = window.location.hostname;
console.log('host', this._host);
var iterationComboBox = Ext.create('Rally.ui.combobox.IterationComboBox',{
listeners:{
ready: function(combobox){
this._iterationOid = combobox.getRecord().get('ObjectID');
this._loadStories(this._iterationOid);
},
select: function(combobox){
this._iterationOid = combobox.getRecord().get('ObjectID');
this._loadStories(this._iterationOid);
},
scope: this
}
});
this.add(iterationComboBox);
},
_loadStories:function(iterationOid){
console.log('loading stories for ', iterationOid);
var myStore = Ext.create('Rally.data.lookback.SnapshotStore', {
autoLoad:true,
fetch : ['Name','_UnformattedID','ScheduleState','_TypeHierarchy'],
filters : [{
property : '__At',
value : 'current'
},
{
property : '_TypeHierarchy',
value : 'HierarchicalRequirement'
},
{
property : 'Iteration',
value : iterationOid
}
],
hydrate: ['_TypeHierarchy'],
listeners: {
load: function(store,records,success){
console.log("loaded %i records", records.length);
this._onDataLoaded(myStore, records);
},
scope:this
}
});
},
_onDataLoaded: function(store,data){
console.log('count',store.getCount());
var that = this;
var records = [];
Ext.Array.each(data, function(record) {
records.push({
Name: record.get('Name'),
ObjectID: record.get('ObjectID'),
UnformattedID: record.get('_UnformattedID')
});
});
var myStore = Ext.create('Rally.data.custom.Store', {
data: records
});
if (!this.down('#grid')) {
this.add({
xtype: 'rallygrid',
id: 'grid',
store: myStore,
columnCfgs: [
{
text: 'Name', dataIndex: 'Name', flex: 1
},
{
text: 'Formatted ID', dataIndex: 'UnformattedID',
renderer: function(val, meta, record) {
return 'US' + record.get('UnformattedID') + '';
}
}
]
});
}
else{
console.log(store);
this.down('#grid').reconfigure(myStore);
}
}
});

How to give parameter to view and retrieve in the view

I saw some example with Ext (cant find it again now) that it should be possible to give parameter to the view like I do below in the push function. If this is also possible in Sencha 2, how can I retrive this value in the view ?
var saveResponse = account.save({
success: function(model, operation) {
console.log('The Account was created, response: '+model);
loginview.push({
xtype: 'adultmenulist',
adult: model
});
},
failure: function(model, operation) {
....
}
});
I usually create a function in my custom object called something like: updateWithRecord. Whenever i push the object i call this method and then proceed to push it like this:
var record = Ext.create('MyApp.model.Adult', { firstName: 'Thomas', lastName: 'Vervik' });
this.getAdultMenuList().updateWithRecord(record);
this.getNav().push(this.getAdultMenuList());
Note how i use MVC ref's for both my detailpage and the NavigationView:
refs: {
nav: {
selector: 'mainnavigation',
xtype: 'mainnavigation',
autoCreate: true
},
adultMenuList: {
selector: 'adultmenulist',
xtype: 'adultmenulist',
autoCreate: true
}
}
And my page would look something like this:
Ext.define('MyApp.view.AdultMenuList, {
extend: 'Ext.Container',
config: {
items: [
{ xtype: 'label', name: 'firstName' }, { xtype: 'label', name: 'lastName' }
]
},
updateWithRecord: function(record) {
this.down('label[name="firstName"]').setHtml(record.get('firstName'));
this.down('label[name="lastName"]').setHtml(record.get('lastName'));
}
});
In your any controller, you just need to create a reference to you view :
refs: {
adultMenuList:'adultmenulist'
}
Then, wherever you want in the controller, you can do :
this.getAdultMenuList().getAdult();
For this to work your adultmenulist need to add an adult parameter defined in its config :
Ext.define('MyApp.view.AdultMenuList, {
extend: 'Ext.Container',
config: {
...
adult:null
}
});
Hope this helped

ExtJS RowExpander - nextBd is null

I have problem configuring RowExpander for my grid. When the grid renders the expander is already opened for each row and with nothing inside. When i click on its icon the following error is generated: nextBd is null. I found very similar problem here http://www.sencha.com/forum/showthread.php?185837-Grid-Panel-PlugIn-Rowexpander-nextBd-is-null but the solution does not work for me and still dont get it why plugin config cannot be passed in initComponent method:
Here is my grid code:
Ext.define('GSIP.view.plans.PlanReqList' ,{
extend: 'Ext.grid.Panel',
alias : 'widget.gsip_devplan_list',
id: 'gsip_plan_list',
plugins: [{
ptype: 'rowexpander',
rowBodyTpl : [
'Nazwa:{name}'
]
}],
//title:i18n.getMsg('gsip.view.PlanReqList.title'),
layout: 'fit',
initComponent: function() {
this.store = 'DevPlan';
// this.plugins = [{
// ptype: 'rowexpander',
// rowBodyTpl : [
// {name}
// ]
// }];
this.features = [{ftype:'filters', encode:false, local:true},{ftype:'grouping'}];
this.tbar = [{
xtype:'commandbutton',
id: 'newReq',
iconCls:'icon-application_add',
text: i18n.getMsg('gsip.view.plans.PlanReqList.addReq'),
command: 'newReq',
}];
this.viewConfig = {
forceFit:true,
getRowClass: function(record, index) {
var c = record.get('elapsedPercent');
if (c >= 0) {
return 'elapsed-normal';
}
}
}
this.columns = [
{header: "Id", dataIndex: "id", width:50, sortable: true, filter:{type:'numeric'}},
{header: i18n.getMsg('gsip.view.plans.PlanReqList.column.name'), dataIndex: "name", flex:1, sortable: true, filter:{type:'string'} },
}
];
this.callParent(arguments);
},
The rowexpander plugin makes use of a feature called rowbody.
In your initComponent() you override this.features (which already includes rowbody) with this line:
this.features = [{ftype:'filters', encode:false, local:true},{ftype:'grouping'}];
Thus the rowbody feature is not included; thus the .x-grid-rowbody-tr class is not injected; thus rowexpander can't find such class for nextBd and returns null.
You should try:
var iNewFeatures = [{ftype:'filters', encode:false, local:true},{ftype:'grouping'}];
this.features = iNewFeatures.concat( this.features );
Lastly, plugins cannot be initiated in InitComponent(), you can either declare them as configs, or within the constructor. See this thread for more info.

how to use href for a column in Ext Grid Panel

I am using a grid panel in which I need to make a column as a link(It should look like link-with no action). I am using listener in the gridpanel and on click of a cell its working fine. Only thing is 1st column should look like a link. But how to put href="#" I am not sure. This is my code:
var addressDetailsStore = Ext.create('Ext.data.Store', {
id:'addressDetailsStore',
autoLoad: true,
fields:
[
'addressType',
'street1',
'street2',
'province',
'city',
'country'
],
proxy: {
type: 'ajax',
url: 'resources/json/addressDetails.json', // url that will load data with respect to start and limit params
reader: {
type: 'json',
root: 'items',
}
}
});
Ext.define('iOMS.view.common.addressView', {
extend: 'Ext.grid.Panel',
alias: 'widget.AddressViewPanel',
layout: 'fit',
collapsible: true,
title:'Address',
store: addressDetailsStore,
listeners:{
cellclick:function (iView, iCellEl, iColIdx, iRecord, iRowEl, iRowIdx, iEvent){
// Getting the event and I am doing logic here..
}
I just want 'addressType' columns appear like a link and I dont know where to put href...
Thanks for your responses.
-Praveen
You could also use a template column:
columns: [
{ text: 'External Link', xtype: 'templatecolumn', tpl: '{title}'}
]
You can specify the columns you want, and for the column with just a link, add a renderer. This example might help you.
var template = new Ext.XTemplate(
' ').compile();
columns:[
{
header: "",
renderer: function () {
return template.applyTemplate();
}
},
You can use renderer function like as follow
columns: [
{
header: 'number',
dataIndex: 'number',
flex: 1,
renderer: function(number) {
return Ext.String.format('{0}', number);
}
},