-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invocation of callback function after update or replace #17
Comments
Do you mean a |
Maybe it's better to name it "after update finalizers". I mean function that will be executed on client side after update/replace completed, like making tweets draggable again after tweets list got updated. |
Isn't that integrated in rails.js already, the before: and after: stuff which invokes a function after the AJAX request returns?! |
Yes, I can specify callback on ajax success when I add new tweet, then I need to specify another callback on ajax success when I delete tweet. And this callbacks will be the same. What I wanted is to add code to respond from server that will call this function automatically on client side. It's maybe a bad idea and it's maybe violates some OOP separation principles, I'm not sure. I just did't want to specify the same callback in many different places. |
If you're really talking about the |
I'm not sure what the right way to implement that kind of functionality. I kind of asked for your opinion and advise. I just find out about apotomo a couple days ago and I was going through Peter's Guide. But I was doing lessons by lesson in little bit different way. I didn't use For example response on submit or delete is something like this: So main idea is that I don't pass function definition within response, I just append js code necessary to invoke already defined function. |
I was having the same issue...using :callback => params[:callback]. Apotomo's render method is unaware of the :callback param, but including Rack::JSONP does the trick. Apotomo should not care about handling callbacks, it's middlewares job by my opinion. |
Hi Boban, I got |
Hello dre3k |
What about changing wrap_in_javascript_for to:
|
Hey, so I'm a little confused by this. Is there a way to send a JSONP callback and then also execute whatever Apotomo was going to do right out of the box? For example, I have an image uploader that uploads and then re-renders the gallery, and it works fine. Now, I want to call a Javascript function (to display an alert or something) and then have it do the same thing as before. Is this where I should be looking, or is there a better way to do it? |
@jarinudom I guess you want something like the following code to be sent back to the browser, after the upload:
Does that really require JSONP? Or could that be handled using two widget states getting triggered by the same event? |
Oh, I can do that with two widget states? Essentially I just need to call function and pass in a message from the Apotomo controller (something like "Photo uploaded"). Sorry if this is super easy, I'm super new to Apotomo. |
Sure, you can even do that in the same state, just concat what you want it to send back. replace view: :whatever + "alert(..);" |
Oh excellent, thanks! Looks like I will make my deadline after all ;) |
Feel free to bug us on #cells on IRC (especially if there's a deadline)! |
Ok just for anyone reading this, it was actually this: replace(view: :whatever) + "alert('Message!');" |
Hi Nick.
What is our opinion on making possible to specify a callback function(or array of functions) that will be invoked after update or replace.
I'll try to explain. I use coffeescript and I don't embed javascript within haml view. I have application.coffee that bind events to ajax requests. One way to call a function after update is to hook a callback function on ajax complete event. For example in Peter's Guide when new tweet is added tweets list updated and it's necessary to make tweets draggble again. The same is necessary when tweet is dumped and tweet list updated. I think instead of specifying one callback for tweet add and one more the same callback for tweet delete, it's reasonable to let update(and replace) method accept something like :callback option, that can specify function that will be invoked when update is finished. Then it's probably will be useful to specify arguments that passed to this function(s), and maybe make conventional case on :callback => true parameter.
I just started going through Peter's Guide and I have quick&dirty solution, but its will be enough to catch the idea:
# config/initializers/apotomo.rb
The text was updated successfully, but these errors were encountered: