[web2py] Re: How capable is the ajax function in web2py.js?
Now I realize that in order to interact with the table, which is managed by pyjamas, for example to select a certain row, I need to define a complex JSONRPCs interface (select row, un-select, paginate to next page, previous page, last page, page number, ...), passing back and forth parameters and results between web2py and pyjamas. This looks quite complex. One thing that can reduce playing ping-pong with the server (and therefore also reduce complexity + enhance performance): think about when you really need to contact the server, and accumulate other changes in the client until you actually contact it. In an application I'm currently prototyping, I allow a user to do lots of manipulations on a table (selecting rows, filtering visible data, sorting columns, ...) purely in the client. When the user selects a row, I dynamically change its css style so it looks differently on screen. No need to contact the server for that. Inside the client (pyjamas) I maintain a data structure in response to the user interactions that encodes updates to the current state of the application (think: a list of currently selected rows). Only when absolutely needed, the new state of the application is sent back to the server (i.e. to web2py using JSONRPC) and processed, or new data is requested from the server. As explained by Anthony (most of the effort will be on the client side), I think using Ajax/JQuery directly won't make things fundamentally easier (on the contrary: unless you find a pre-made component that already does what you want you will now have to write your client side stuff in javascript instead of python, which - depending on your background - may sound scary). --
[web2py] Re: How capable is the ajax function in web2py.js?
Thanks for both your comments, they are good food for thought. My experience with Javascript is very limited and I want to avoid it as much as possible. That is why I have considered - and tried - pyjamas (which has been working very well for me: very easy to use, and up to now very robust). I have some worries: 1. This approach means I must keep coding, and integrating, two technologies: web2py and pyjamas. It is still way better than having to code in javascript. 2. One thing that worries me about implementing all this logic client-side is that a big chunk of my code will be autogenerated javascript. That means, if I run into trouble, I guess it will be very difficult to solve any problems I may have. 3. And this a side issue, but I need to mention it nevertheless: I am having a hard time integrating the CSS from pyjamas and web2py. Since some styles from web2py (table, td, ...) override my styles, suddenly all my pyjamas components are looking very bad. This is a very painful problem, which I do not know how to solve. Do you have any suggestions on how to debug CSS issues? I am limited to Chrome inspector basically. So what I was aiming at now is to use as little client side logic as possible: just perform some AJAX calls to get the data ready for presentation. Actually, I was even planning to do (for example) HTML table rendering on the server (I am considering markup.pyhttp://markup.sourceforge.net/ for that) and send it via AJAX to the client to be displayed. Basically, the server would be in charge of updating the html in the client. The same that web2py does with controllers/views/functions, but for dynamic content, which must be sent via AJAX. I have not yet decided which approach to take. If you have experience in this scenario, your comments are welcome! Thanks, Daniel --
[web2py] Re: How capable is the ajax function in web2py.js?
Daniel, Do your table manipulation in Web2py using view helpers. Example: thead = THEAD(TR(TH(something'), TH('this'), TH('that'), TH('theother'))) tbody = TBODY() for r in rows: tbody.append(TR( r.something, r.this, r.that, r.theother )) return TABLE(thead, tbody) There are other examples with even fewer lines of code in the manual at http://web2py.com/books/default/chapter/29/5#Built-in-helpers. This is just how I like to do it. On Tuesday, June 26, 2012 5:12:49 AM UTC-4, Daniel Gonzalez wrote: Thanks for both your comments, they are good food for thought. My experience with Javascript is very limited and I want to avoid it as much as possible. That is why I have considered - and tried - pyjamas (which has been working very well for me: very easy to use, and up to now very robust). I have some worries: 1. This approach means I must keep coding, and integrating, two technologies: web2py and pyjamas. It is still way better than having to code in javascript. 2. One thing that worries me about implementing all this logic client-side is that a big chunk of my code will be autogenerated javascript. That means, if I run into trouble, I guess it will be very difficult to solve any problems I may have. 3. And this a side issue, but I need to mention it nevertheless: I am having a hard time integrating the CSS from pyjamas and web2py. Since some styles from web2py (table, td, ...) override my styles, suddenly all my pyjamas components are looking very bad. This is a very painful problem, which I do not know how to solve. Do you have any suggestions on how to debug CSS issues? I am limited to Chrome inspector basically. So what I was aiming at now is to use as little client side logic as possible: just perform some AJAX calls to get the data ready for presentation. Actually, I was even planning to do (for example) HTML table rendering on the server (I am considering markup.pyhttp://markup.sourceforge.net/ for that) and send it via AJAX to the client to be displayed. Basically, the server would be in charge of updating the html in the client. The same that web2py does with controllers/views/functions, but for dynamic content, which must be sent via AJAX. I have not yet decided which approach to take. If you have experience in this scenario, your comments are welcome! Thanks, Daniel --
[web2py] Re: How capable is the ajax function in web2py.js?
1. I do not want to reload pages: everything needs to work smoothly as a desktop app. (of course, not all interactions with web2py, just the ones related to this one real-time component). I guess the right tool for this job would be the ajax function in web2py.ps. Is this tool able to handle complex data? The ajax() function is just a basic convenience function. It pulls values from input elements, posts them via Ajax using jQuery, and places the returned HTML in a specified target (or executes some returned Javascript). It relies on jQuery for the actual Ajax calls, so if you need to do anything more sophisticated, you can just use jQuery directly. You should be able to handle whatever Ajax you need. 1. the ajax events must not only be generated by the user, but also autonomously by the web browser. In pyjamas I am doing this with a Timer, which translates to some timer javascript events. Is this possible in web2py? Is there an example of a javascript timer triggering ajax requests in web2py? If you use a web2py Ajax component (which uses the web2py_component() JS function), in trunk there is now a timer option. Otherwise, you should be able to implement your own timer. Note, anything you can do with Ajax is technically possible with web2py -- web2py is a server-side framework and is happy to receive Ajax requests and return responses. Most of the effort will be on the client side -- for that, web2py provides some convenience methods, but you are free to use other third-party libraries or build your own JS/Ajax solution. Anthony --