| 1 | DeveloperGuidelinesTips |
| 2 | ---- |
| 3 | == PROPOSAL == |
| 4 | |
| 5 | [http://bazaar.launchpad.net/%7Esunneach/sahana/cleanIE/files/628 This branch] has the proven working minimized-coding approach. |
| 6 | It has an additional 'module' [http://bazaar.launchpad.net/~sunneach/sahana/cleanIE/annotate/head%3A/views/auto_input.js views/auto_input.js] which contains all the repeating steps, and the actual views call it. |
| 7 | |
| 8 | === Step 1. The Controller === |
| 9 | |
| 10 | Use [wiki:IS_ONE_OF_EMPTY IS_ONE_OF_EMPTY] to prevent downloading the whole lookup table. |
| 11 | |
| 12 | === Step 2. The View === |
| 13 | |
| 14 | '''Auto_completed edit control''' |
| 15 | This [http://bazaar.launchpad.net/~sunneach/sahana/cleanIE/annotate/628/views/or/office_create.html view] has the auto-completion |
| 16 | enabled __edit control__ which gets its {id, name} pairs from the `/or/organisation`: |
| 17 | {{{ |
| 18 | {{entity_id = "or_office_organisation_id"}} |
| 19 | {{urlpath_c = "or"}} |
| 20 | {{urlpath_f = "organisation"}} |
| 21 | {{urlvar_field = "name"}} |
| 22 | {{include 'auto_input.js'}} |
| 23 | }}} |
| 24 | '''Auto_completed Person edit control''' |
| 25 | The ''person'' needs special treatment, that is why the flag is set: `is_person=True`: |
| 26 | {{{ |
| 27 | {{entity_id = "or_contact_person_id"}} |
| 28 | {{is_person = True}} |
| 29 | {{include 'auto_input.js'}} |
| 30 | }}} |
| 31 | '''Auto_completed edit control with post-processing''' |
| 32 | If you need to update your view after the auto-completed field is changed, use the post_process "callback". |
| 33 | Put into that any JS statement which works. For example, in the [[http://bazaar.launchpad.net/~sunneach/sahana/cleanIE/annotate/head%3A/views/or/contact_create.html views/or/contact_create.html]] it is used to update the office list given the organisation via the `load_offices` call: |
| 34 | {{{ |
| 35 | {{entity_id = "or_contact_organisation_id"}} |
| 36 | {{urlpath_c = "or"}} |
| 37 | {{urlpath_f = "organisation"}} |
| 38 | {{urlvar_field = "name"}} |
| 39 | {{post_process = "load_offices(false);"}} |
| 40 | {{include 'auto_input.js'}} |
| 41 | }}} |
| 42 | '''Dummy selector''' |
| 43 | The offices list is depending on organisation. The flag `dummy_select` makes it the empty dropdown with the single item `default_value`, waiting to be populated by load_offices. Other parameters are not used. |
| 44 | {{{ |
| 45 | {{entity_id = "or_contact_office_id"}} |
| 46 | {{dummy_select = True}} |
| 47 | {{default_value = T('Select an Organisation to see a list of offices')}} |
| 48 | {{include 'auto_input.js'}} |
| 49 | }}} |
| 50 | The `default_value` works for the edit control as well. |
| 51 | |
| 52 | === Appendix: Pop-ups === |
| 53 | |
| 54 | The [http://bazaar.launchpad.net/~sunneach/sahana/cleanIE/annotate/head%3A/views/layout_popup.html TB_Refresh] calls the `set_parent_id` and `clean_up` if they exist in a view. |
| 55 | |
| 56 | |
| 57 | This [http://bazaar.launchpad.net/~sunneach/sahana/cleanIE/annotate/head%3A/views/or/contact_create.html set_parent_id] uses it to pass the 'organisation_id' to the new office creation form. |
| 58 | |
| 59 | |
| 60 | And the `clean-up` in that same view is used to populate the offices dropdown after the new organisation or new office record get created. |
| 61 | |
| 62 | ---- |
| 63 | DeveloperGuidelinesTips |