summaryrefslogtreecommitdiff
path: root/archaeological_files_pdl/templates/ishtar/blocks/JQueryPersonOrga.js
blob: be1faabfef06867cac16038f2a5f67cadb0f4fca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 );
    });
};

edit_url =  {{edit_source}};
parent_id = "{{field_id}}";

person_new_callback = function(){
    var url =  {{edit_source}};
    $('#id_{{field_id}}').val(null);
    $('#id_select_{{field_id}}').val(null);
}

$(function() {
    var $radios = $('input:radio[name=person_type]');
    if($radios.is(':checked') === false) {
        $radios.filter('[value='+ current_status +']').prop('checked', true);
    }

    $radios.change(function(){
        var loc = window.location;
        window.location = loc.protocol + '//' + loc.host + loc.pathname + "?status=" + $('input:radio[name=person_type]:checked').val();
    });

    $("#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 );
    });

    $(document).on("click", '#id_select_{{field_id}}', function(){
        $('#id_{{field_id}}').val(null);
        $('#id_select_{{field_id}}').val(null);
        $.get( {{edit_source}}, function( data ) {
            $( "#div-{{field_id}}" ).html( data );
        });
    });
});