How to catch data send via extjs's store.sync() method - extjs

i am working in extjs+Yii. My client side functionality is desighned in yii and server side functionality is in extjs. In extjs controller i had written code to send dynamically generate store,set its proxy and using sync() method of store.
review:function()
{ var reviewQuestionStore=Ext.create('Balaee.store.qb.QbqnsStore');
proxy=reviewQuestionStore.getProxy();
Ext.apply(proxy.api,{
read:'http://127.0.0.1/s_balaee/Balaee/index.php/QuestionBank/Qbpaper/ReviewQuestionPaper',
create:'http://127.0.0.1/s_balaee/Balaee/index.php/QuestionBank/Qbpaper/ReviewQuestionPaper',
});
Ext.apply(proxy.writer,{
type:'json',
root:'records'
});
Ext.apply(proxy.reader,{
type:'json',
root:'questions'
});
var getdata=this.getLocalvalue();
UserId=getdata.data.userId;
//Using sync method
var check =Ext.create('Balaee.model.qb.QbqnsModel',{
questionPaperNo:Paperno,
userId: UserId,
});
reviewQuestionStore.add(check);
reviewQuestionStore.sync();
}
So its working corectly. And its sending data in json format as-
{"records":{"userId":"5","firstName":"abc","middleName":"","lastName":"","languageId":"","primaryEmail":"sdf#sdf.dfg","birthDate":"","password":"","securityQuestionId":"","securityQuestionAnswer":"","isMale":"","creationTime":"","ipAddress":"","confirmationCode":"","userStatusId":"","question":"","id":null}}
Now i want to catch this data in yii controller function. i had tried as-
$postData = json_decode(file_get_contents("php://input"), true);
$clientData = $postData['records'];
and to access fields i am using $clientData['firstName'].But its not working.So how to catch data in Yii which is send via Extjs's store sync() method.

Use Standard Yii Json decode.It will create array for you
$data= CJSON::decode(file_get_contents("php://input"));

Related

how to retrieve the nodejs session values in a html page using angularjs?

I'am using express-session for creating session in nodejs & using http.post method to send datas to nodejs. How to retrieve the session variable in html using angularjs? Can you please help me?
Here is my code
Inside angularjs controller in the first html page,
$http.post('/form', data)
.then(
function(response){
if (response.data) {
$window.location.href = 'other.html';
}
},
function(response){
console.log("inside failure");
}
);
In nodejs,
app.post('/form', function (req, res) {
console.log("Incoming data" , userData);
req.session.mob = userData.mob;
req.session.provider = userData.provider;
res.send(req.session.mob);
}
     
I have to display the mob value in the 'other.html' which is stored in nodejs session.Can you suggest me how to do it through angularjs?
Not sure If i understand your question correctly - i'll try to help.
First of all, it will be angularJs best practice to use routes or states and pass the data you received from the server (response.data in your example) as a state param or a url param to the new page, and avoid the redirection.
If you do need to redirect to the "other.html" just pass the data from the server as query param in the url (if its a property) or save it in the browser storage (local storage, if the new page is being opened in a new tab) and read the data when your other.html is loaded.
Make sure that you pass a url to $window.location.href.

Angularjs $resource control what is being returned to object

Spring MVC | Angularjs | Hibernate
I have a very simple web app that list all books from database.
Page looks something like this....
-------------------------------------------
Problem
1. My update method returns not only book object but also other information such as error message, error code...etc. This causes a problem in my view when I update.
My angular code looks something like this
$Resource
app.factory("Book" , function($resource){
return $resource("http://localhost:8080/uni-starter/spa/booklist/:id", {id: "#id"}, {
update:{
method:'PUT'
}
});
});
** Loading Data **
Book.get(params, function(data){
angular.forEach(data.results, function(book){
// wrapping each book object with $Resource
self.bookData.push(new Book(book));
});
});
** Update code ** looks like this
book.$update().then(
function success(data){
// UI notification
toaster.pop('success', 'Some Message');
}
).catch( // some error
Angularjs $resource
once the data arrives from the server then the object is populated with the data and the view automatically re-renders itself showing the new data. This means that in most cases one never has to write a callback function for the action methods.
Is it possible to control what is being returned to my book object? In other words, the server returns objects { returnObj, httpStatus, errors, message...etc } but I only want returnObj to = to my book obj? is this possible.
This is a extended question from Spring MVC REST with AngularJS: error handling methods was just wondering if there is a way to solve this on Angularjs rather than on Java side.
Thank you.

Store is loaded twice after data.Model.save()

I have a grid with remote data (php/mysql/json) and use a form to insert records or to edit this data.
I use the api configuration of the proxy/store. I use MVC architecture.
So, all very simple (in pseudo code):
get selected model form grid or create model
frm.loadRecord()
frm.updateRecord()
frm.getRecord().save()
and all works fine, but I noticed in the browser console that after the POST (works fine, calls either the url configured with create or the url configured with update), the store calls (GET) the url configured with retrieve twice. These calls are identical.
So functionally all works fine and I could ignore it, but now I've noticed I want it fixed.
Can anyone help me where to look? Thanks in advance.
Details:
It's all really basic:
In the controller of the gridpanel:
updateRow: function (gridpanel) {
var sm = gridpanel.getSelectionModel();
var record = sm.getLastSelected();
this.showForm(record);
}
and
showForm: function (record) {
...
formpanel.show();
var frm = formpanel.getForm();
frm.loadRecord(record);
}
In the controller of the formpanel:
submit: function(frm) {
frm.updateRecord();
frm.getRecord().save();
}
When I remove the save action the GET requests aren't called, so this seems to trigger them.
In the store:
api: {
create: '../php/api/customers.php?request=create',
read: '../php/api/customers.php?request=retrieve&scope=summary',
update: '../php/api/customers.php?request=update',
destroy: '../php/api/customers.php?request=delete'
}
The screenshot:

How to export grid to XLS in ExtJS4.0

Is there a simple way to export a grid data to XLS in ExtJS.
If not I am trying the following way.
I am trying to read the data store inside a controller. The datastore is already being used by the grid. I want to read the data on a button click and send it to server through AJAX. Later inside server I would retrieve the data and write to XLS. In this case what is the way I can read the data inside the controller?
enter code here
Ext.define("MyApp.controller.GridController", {
extend : 'Ext.app.Controller',
views: ['performance.grid.PerformanceGrid'],
models: ['GridModel'],
stores: ['GridStore'],
refs : [{
ref : 'mainTabPanel',
selector : 'portal > tabpanel'
}],
init : function() {
this.control({
'portal toolbar > button[itemId=xls]' : {
click : this.onAddTab
},
'portal toolbar > button[itemId=pdf]' : {
click : this.onAddPortlet
}
});
},
onAddTab : function(btn, e) {
// I want to read the datastore here and make an AJAX call
},
});
onAddTab: function(btn, e){
var store = // get the store reference probably doing Ext.getStore('the store');
var records = store.data.items.map(function(r){ return r.data });
// send it all to your server as you want to
// Ext.ajax.Request({
// url: 'the url',
// data: records,
// method: 'POST'
// });
});
I didn´t test it but it have to work.
Good luck!
I think that process is not the best because you will have 3 payloads (data round trips that doesn't make any sense)
Your call your server method to get the data that will be populated into the grid.
The JSON object (containing the server data) will then travel again to the server
(THIS DOESN'T MAKE SENSE TO ME... WHY YOU WANT TO SEND DATA TO SERVER WHEN THE SERVER WAS THE SOURCE?? )
The server will process your object from JSON response and then create the document on the fly and send it back to server.
What I think you should do is the following:
Get data from server and bind your grid.
Get your store proxy URL and parse the method and extraParams so you know who served the grid and what you asked to the server.
Create a common method on server that receives a method and an array of parameters. Then inside this method make the logic so depending on the method, you call your data Repository (same repository where your first request got the data), process the document and send the file back to server.
This way you should have something like this:
webmethod(string method, object[] params) {
switch(method){
case "GetTestGridData":
// here you call your Repository in order to get the same data
GeneralRepo repo = new GeneralRepo();
var data = repo.GetTestGridData(object[0],object[1]);
break;
}
byte[] fileStream = Reports.Common.Generate(data, ExportType.PDF);
// response the stream to client...
}

Backbone.js Collection fetch success return

I am trying to get return from Backbone.js Collection fetch using code similar to one below. How do I bypass rest ?
var myData = getCollection();
getCollection(){
this.collection = fetchCollection.fetch({
success: function(collection, data) {
collectionData = fetchCollection.toJSON();
return collectionData;
}
},this);
}
fetch calls the underlying sync methods, Backbone.sync. You can either override the sync method of individual the collections or models, or replace Backbone.sync with your own. One such alternative sync implementation for instance is the Backbone localStorage adaptor which stores to localStorage instead of using REST to talk to a server.

Resources