diff options
Diffstat (limited to 'ishtar_common/templates/blocks')
5 files changed, 161 insertions, 0 deletions
diff --git a/ishtar_common/templates/blocks/JQueryAdvancedTown.html b/ishtar_common/templates/blocks/JQueryAdvancedTown.html new file mode 100644 index 000000000..78d2d7831 --- /dev/null +++ b/ishtar_common/templates/blocks/JQueryAdvancedTown.html @@ -0,0 +1,99 @@ +{% load i18n %}{% load url from future %}</td></tr> +<tr> + <td>{% trans "State" context "Région" %}</td> + <td> + <select id='current-state'> + <option value=''>--------</option>{% for state in states %} + <option value='{{state.number}}'{% if state.number == selected_state %}selected='selected'{% endif %}>{{state}}</option> + {% endfor %}</select> + </td> +</tr> +<tr> + <td>{% trans "Department" %}</td> + <td> + <select id='current-department'> + </select> + </td> +</tr> +<tr class='required'> + <th><label>{% trans "Town" %}</label></th> + <td><input{{attrs_select}}/> +<input type="hidden"{{attrs_hidden}}/> +<script type="text/javascript"><!--// + selected_department = "{{selected_department}}"; + var empty_select = "<option value=''>--------</option>"; + + function update_department_field(){ + var selected_state = $("#current-state").val(); + if (!selected_state){ + $("#current-department").html("<option value=''>"+"{% trans 'Choose a state first' %}"+"</option>"); + $("#current-department").prop('disabled', true); + $('#id_select_{{field_id}}').prop('disabled', true); + return; + } + $.ajax({ + url: "{% url 'department-by-state' %}" + selected_state, + type: 'get', + dataType: 'json', + success: function(data) { + var html = ""; + for (idx in data){ + dpt = data[idx]; + html += "<option value='" + dpt.number + "'"; + if (String(dpt.number) == String(selected_department)){ + html += " selected='selected'"; + } + html += ">" + dpt.value + "</option>"; + } + $("#current-department").html(html); + $("#current-department").prop('disabled', false); + update_search_town(); + } + }); + } + + function update_search_town(){ + selected_department = $("#current-department").val(); + if (selected_department){ + $("#id_select_{{field_id}}").autocomplete( "option", "source", {{source}}+selected_department); + $('#id_select_{{field_id}}').prop('disabled', false); + } else { + $('#id_select_{{field_id}}').prop('disabled', true); + } + } + + function empty_town(){ + $('#id_{{field_id}}').val(null); + $('#id_select_{{field_id}}').val(null); + } + + $(function() { + update_department_field(); + + $("#current-state").change(function(){ + empty_town(); + update_department_field(); + }); + + $("#current-department").change(function(){ + empty_town(); + update_search_town(); + }); + + $("#id_select_{{field_id}}").autocomplete({ + source: {{source}}, + select: function( event, ui ) { + if(ui.item){ + $('#id_{{field_id}}').val(ui.item.id); + } else { + $('#id_{{field_id}}').val(null); + } + }, + minLength: 2{% if options %}, + {{options}} + {% endif %} + }); + + $('#id_select_{{field_id}}').live('click', empty_town); + +});//--></script> diff --git a/ishtar_common/templates/blocks/JQueryAdvancedTown.js b/ishtar_common/templates/blocks/JQueryAdvancedTown.js new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/ishtar_common/templates/blocks/JQueryAdvancedTown.js @@ -0,0 +1 @@ + diff --git a/ishtar_common/templates/blocks/JQueryPersonOrganization.js b/ishtar_common/templates/blocks/JQueryPersonOrganization.js new file mode 100644 index 000000000..b13a2c28e --- /dev/null +++ b/ishtar_common/templates/blocks/JQueryPersonOrganization.js @@ -0,0 +1,50 @@ + +$("#id_select_{{field_id}}").autocomplete({ + source: {{source}}, + select: function( event, ui ) { + var url = {{edit_source}}; + if(ui.item){ + url = {{edit_source}}+ui.item.id; + $('#id_{{field_id}}').val(ui.item.id); + } else { + $('#id_{{field_id}}').val(null); + } + $.get(url , function( data ) { + $( "#div-{{field_id}}" ).html( data ); + }); + }, + minLength: 2{% if options %}, + {{options}} + {% endif %} +}); + +$.get( {{edit_source}}{% if selected %}+'{{selected}}'{% endif %}, function( data ) { + $( "#div-{{field_id}}" ).html( data ); +}); + +$('#id_select_{{field_id}}').live('click', function(){ + $('#id_{{field_id}}').val(null); + $('#id_select_{{field_id}}').val(null); + $.get( {{edit_source}}, function( data ) { + $( "#div-{{field_id}}" ).html( data ); + }); +}); + +person_save_callback = function(item_id, lbl){ + var url = {{edit_source}}; + $('#id_{{field_id}}').val(null); + $('#id_select_{{field_id}}').val(lbl); + if (item_id){ + url = {{edit_source}}+item_id; + $('#id_{{field_id}}').val(item_id); + } + $("#id_select_{{field_id}}").trigger('autocompletechange'); + $.get(url , function( data ) { + $( "#div-{{field_id}}" ).html( data ); + }); +}; +person_new_callback = function(){ + var url = {{edit_source}}; + $('#id_{{field_id}}').val(null); + $('#id_select_{{field_id}}').val(null); +} diff --git a/ishtar_common/templates/blocks/PersonOrganization.html b/ishtar_common/templates/blocks/PersonOrganization.html new file mode 100644 index 000000000..6e7264c8e --- /dev/null +++ b/ishtar_common/templates/blocks/PersonOrganization.html @@ -0,0 +1,9 @@ +{% load i18n %}<input{{attrs_select}}/> +</table> + +<div id='div-{{name}}'></div> + +<input type="hidden"{{attrs_hidden}}/> +<script type="text/javascript"><!--// +{{js}} +//--></script> diff --git a/ishtar_common/templates/blocks/extra_head.html b/ishtar_common/templates/blocks/extra_head.html new file mode 100644 index 000000000..139597f9c --- /dev/null +++ b/ishtar_common/templates/blocks/extra_head.html @@ -0,0 +1,2 @@ + + |
