| 1 | DeveloperGuidelines DeveloperGuidelinesTips |
| 2 | |
| 3 | == ajaxS3 - the real world connectivity tool == |
| 4 | |
| 5 | When there is too much data to download, |
| 6 | or the connection is slow, |
| 7 | or the server is busy |
| 8 | or all of the above, |
| 9 | |
| 10 | 1. the user would prefer to monitor the browser-server dialogue; |
| 11 | 2. the browser would need to re-submit the Ajax request again in the case of timeout. |
| 12 | |
| 13 | The [http://bazaar.launchpad.net/~flavour/sahana/sahanapy-trunk/annotate/head%3A/static/scripts/S3/S3.js ajaxS3] covers these needs. |
| 14 | |
| 15 | |
| 16 | This is a transparent jQuery plugin residing in the S3.js (S3.min.js) which works transparently as a regular ajax handle, |
| 17 | but behind the scenes: |
| 18 | |
| 19 | 1. It shows the flashing message that the download is started |
| 20 | 2. It sets up the timeout and re-tries the request several times if the timeout is triggered |
| 21 | 3. It displays the status and errors in the custom StatusBar |
| 22 | |
| 23 | That way the user always feels and stays in control. |
| 24 | |
| 25 | '''How to use the ajaxS3?''' |
| 26 | [[BR]] |
| 27 | The standard handles have been provided: ''getS3'', ''getJSONS3'', ''postS3'', and the ''ajaxS3'' itself.[[BR]] |
| 28 | |
| 29 | |
| 30 | getJSONS3 |
| 31 | {{{ |
| 32 | $.getJSONS3(url, callback) |
| 33 | $.getJSONS3(url, callback, message) |
| 34 | $.getJSONS3(url, data, callback) |
| 35 | $.getJSONS3(url, data, callback, message) |
| 36 | }}} |
| 37 | These calls will get the JSON from the URL and use the provided callback when successful. |
| 38 | {{{ |
| 39 | #!js |
| 40 | callback(theJSON_you_need, status) |
| 41 | }}} |
| 42 | getS3 |
| 43 | It is the same as '''getJSONS3''', but now the type can be `html` or `json` |
| 44 | {{{ |
| 45 | #!js |
| 46 | $.getS3(url, callback, type) |
| 47 | $.getS3(url, callback, type, message) |
| 48 | $.getS3(url, data, callback, type) |
| 49 | $.getS3(url, data, callback, type, message) |
| 50 | }}} |
| 51 | postS3 |
| 52 | The same as '''getS3''', but now the request goes through the POST tunnel: |
| 53 | {{{ |
| 54 | #!js |
| 55 | $.postS3(url, callback, type) |
| 56 | $.postS3(url, callback, type, message) |
| 57 | $.postS3(url, data, callback, type) |
| 58 | $.postS3(url, data, callback, type, message) |
| 59 | }}} |
| 60 | |
| 61 | Why the ''message'' argument?[[BR]] |
| 62 | The call `$.getJSONS3(url, callback)` will show status something like: |
| 63 | {{{ |
| 64 | "getting form data..." |
| 65 | "getting form data... retry 1" |
| 66 | ... |
| 67 | }}} |
| 68 | And the call `$.getJSONS3(url, callback, 'line items')` will show: |
| 69 | {{{ |
| 70 | "getting line items..." |
| 71 | "getting line items... retry 1" |
| 72 | ... |
| 73 | }}} |
| 74 | DeveloperGuidelines DeveloperGuidelinesTips |