Forked from aghuddleston/Ext.ux.data.proxy.JsonAjaxProxy.js
Last active
June 1, 2016 08:59
-
-
Save perryflynn/71624cbf3f86044bc205293e1433cc97 to your computer and use it in GitHub Desktop.
Ext JS 6 Proxy that supports JSON Request Data and preserves GET parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.define('Ext.ux.data.proxy.JsonAjaxProxy', { | |
extend:'Ext.data.proxy.Ajax', | |
alias:'proxy.jsonajax', | |
/** | |
* proxy: { | |
* type:'jsonajax', | |
* api: { | |
* read:'/api' | |
* }, | |
* extraParams: { | |
* extra:'param' | |
* } | |
* } | |
* | |
* call: | |
* store.load({ | |
* params: { | |
* foo: 'bar', | |
* foobar: 'barfoo' | |
* }, | |
* jsonData: { | |
* uids: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ], | |
* action: 'killthemall' | |
* } | |
* }); | |
* | |
* result: | |
* https://cooljsonapi.example/api?foo=bar&foobar=barfoo&extra=param | |
* { uids: [1, 2, 3, 4, 5, 6, 7, 8, 9 ], action: 'killthemall' } | |
*/ | |
actionMethods : { | |
create: "POST", | |
read: "POST", | |
update: "POST", | |
destroy: "POST" | |
}, | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
buildRequest:function (operation) { | |
var request = this.callParent(arguments); | |
// For documentation on jsonData see Ext.Ajax.request | |
request.setJsonData(operation.jsonData); | |
// Do not change params to support GET params | |
// and extra params from proxy | |
// request.setParams(operation.getParams()); | |
return request; | |
}, | |
/* | |
* @override | |
* Inherit docs. We don't apply any encoding here because | |
* all of the direct requests go out as jsonData | |
*/ | |
applyEncoding: function(value){ | |
return value; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment