I'm trying to post an array using a POST request to a specific page, the target page generates a csv and send me back the stream, right now i'm doing using ExtJs Ajax class, but that won't work as i need to make a normal HTTP request not ajax, my current code is as follows:
Ext.extend(Players.panel.Home,MODx.Panel,{
exportSubscribers: function(btn,e) {
MODx.Ajax.request({
url: Players.config.connectorUrl
,params: {
action: 'mgr/player/getSubscribers'
}
});
}
});
The exportSubscribers function is executed from a normal ExtJs button
{ xtype: 'button'
,text: 'Export Subscribers'
,preventRender: true
,handler: this.exportSubscribers
}
What class should i use to turn this into a normal request?
Thanks.
There isn't a class to do a normal request. I known two ways to accomplish a file download:
Use a hidden form in the page, replace the field values and invoke the form's .sumbit method from ExtJS button handler to do the POST request you want.
Replace your button by an HTTP anchor if you can use a GET request to make the server return the file: Download CSV'
You'd be better off making a local request to your server, and then in your server-side code make a cURL request to the CSV source. That way, you can make a non XMLHttpRequest method to get your data.
Related
Popup in Jhipster
I don't know how to edit this popup , I can't find the file where it is modified. I use react for the front-end
Notification content is built by java backend in REST controller and passed to client through HTTP headers (i18n message key and its params)
.headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, result.getId().toString()))
When frontend receives response, the popup is built in notification-middleware.ts, the message key is extracted for translation to retrieve localized message template and then the params are injected to produce final localized text:
toast.success(translate(alert, { param: alertParam }));
You can see the headers when inspecting the response in the browser's console.
So, if you want to change the text for one entity, you must modify the message with "created" key in src/main/webapp/i18n/<Language>/<Entity name>.json for each language that your app supports.
I'm building an API with Symfony 3 following the JSON API specification (Documentation).
When submitting new data, the request has this format :
{
"type": "entity",
"id" : null,
"attributes" : {
"name" : "Test name"
}
}
But the problem is the request does not fit the format expected by symfony's Forms because of the extra object attributes.
So I want to be able to transform the request before the form submit in order to make the form able to populate the underlying Entity.
I have tried to register an FormEvents:PRE_SUBMIT and do the logic in it but it seems I have no access to the Request content.
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
$data = $event->getData();
var_dump($data);
die();
});
The $event->getData() is null.
I have also see there is possibility to register DataTransformer but it is registered per field, and has no access to the Request too.
I don't want to do it manually in the Controller as this will occur on all my forms (or at least the majority), so I search for a more generic way to transform the request, but at this point I can't figure out how to do this.
Thanks for help.
Your EventListener does not have access to your Request, nor does your Form itself.
The best and cleanest way to do this in my opinion would be to define a custom RequestHandler for your Forms, extending the NativeRequestHandler that parses your Request by default.
Then you only need to execute $builder->setRequestHandler() to apply this to your Forms.
So I'm trying to AJAX a single solr doc from my results list to a "doc view" view. I'm trying to use AngularJS to AJAX to my view render method and display the doc that way, but I can't seem to get the angular to work and I'm not sure I'm doing things correctly on the Play side either. Would you at least be willing to tell me if what I'm trying to do will work? The Angular error comes from the docText.text(); call. Here is my code:
Angular controller code:
var docText = $resource("http://localhost:9000/views/full-doc-text.html", {
text: {method: 'PUT'}
});
$scope.handleViewText = function(value) {
docText.text({doc: value});
}
Java code:
public static Result viewText() {
JsonNode json = request().body().asJson();
//do stuff here
return ok(viewtext.render(json));
}
route:
GET /views/full-doc-text.html controllers.Application.viewText()
I see three problems with the code above;
1.The definition of docText resource is not correct. if your read the angularjs manual here you'll see that $resource has 4 parameters. First one is resource url, second is parameter defaults, third one is custom actions and forth one is resource options where last three of them are optional. In your code you pass custom actions as the second parameter, which should be the third. And since you don't have any parameters in your resource url second parameter must be null. So first correction is:
var docText = $resource("http://localhost:9000/views/full-doc-text.html", null, {
text: {method: 'PUT'}
});
2.You define your text action's HTTP method as PUT however in your routes file you are handling GET requests for your desired action. You should change your route definition as:
PUT /views/full-doc-text.html controllers.Application.viewText()
3.PUT method is usually used for update operations when implementing a RESTFULL service. In your case you don't seem to be updating anything. So I suggest to use POST method just for convention.
I have an API powered by Django rest framework and I also use the default pagination option:
{
"count": 40,
"next": "http://127.0.0.1:8000/api/task/?page=2",
"previous": null,
"results": [{},{}...]
}
On angular side, I'm using ngResource to consume my api wiht the following code:
var task_resource = $resource('/api/task/:taskId/', {taskId:'#id'},{
query : {
method : 'GET',
isArray : false
}
});
I just want to be able, when the user click a 'next' button or scroll down to the bottom of the page to query the 'next' page until the end. I know I only have to GET on "next" field but if I do that, I will not use the $resource I defined.
I am wondering what is the solution for such a common pattern with angular and an API.
Since the 'next' url is absolute, you could simply use angular's built-in $http service for those requests. Something like $http.get(data.next).success(function(data){});
Another way would be to create your own custom pagination serializer as described here: http://www.django-rest-framework.org/api-guide/pagination#custom-pagination-serializers
Then you would need to create your own version of the NextPageField, and make it output without the domain part.
The standard implementation for the NextPageField can be found here:
https://github.com/tomchristie/django-rest-framework/blob/560f428e24c7676c660114c2daa6017ff61074ad/rest_framework/pagination.py
I have multiple store on my page to load data in extjs grid. I am using a js function to load these store. Based on the search button click event I attach the respective store to the grid. Its working fine. In the load function I have lots of params that I need to send to the backend to fetch the results and show in the grid. Now with pagination in place. Is there anyway that I can add that js function call inside the paging so I can pass those params. Because right now if I click next button in paging nothing is getting returned. since the required parameters are missing to fetch the results. I tried all the given sample on internet but nothing is working.
It would be great if somebody can actually post an example on paging passing parameters or calling js function on next button event.
Any help will be really appreciated. Thank you.
below is the load store function that I want to call on my next event on pagination.
function loadStore(prodId, productsName, doctype, criteria, filename, titlename) {
store.removeAll();
store.load({
params: {
// specify params for the first page load if using paging
start: 0,
limit: g_perPage,
ajax: "true",
productId: prodId,
ProductsNameArr: productsName,
assetsname: doctype,
criterianame: criteria,
newfilename: filename,
newtitlename: titlename
}
});
}
http://docs.sencha.com/ext-js/3-4/#!/api/Ext.data.Store-property-baseParams
As Nigel said above the beforeload event is what you are after, see below for an example:
store.on('beforeload',function(store,opts) {
store.baseParams = { param1: 'foo', param2: 'bar', ... }
});
baseParams does not seem particularly useful because it sends static values, not the latest search criteria. Getting the dynamic search criteria is tricky too because the grid (i.e. the form fields) may not exist yet.
The Ext JS devs seem to have consistently mistaken docstring fragments for real documentation making for quite a hellish learning curve with their product. A few real examples here would go a long way.