aboutsummaryrefslogtreecommitdiffstats
path: root/jm2l/static/js/jm2l.js
blob: a700c4aea0da80956d5db7dc4bbaf1eb27cdfeed (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
function DoPost(TargetURL) {
    var Datas=$('#ModalForm').serialize();
    $.ajax({
        type:'post',
        url:TargetURL,
        data:Datas,
        success:function(result, status, jqXHR){
            var regexp = /(javascript)/gi;
            if (!jqXHR.getResponseHeader('content-type').match(regexp))
                $("#AjaxModal").html(result);
        },
        error:function(result, error){
            alert(error);
        },        
    });
}

function DoPostLieu(TargetURL) {
    var Datas=$('#ModalPlaceForm').serialize();
    $.ajax({
        type:'post',
        url:TargetURL,
        data:Datas,
        success:function(result, status, jqXHR){
            var regexp = /(javascript)/gi;
            if (!jqXHR.getResponseHeader('content-type').match(regexp))
                $("#AjaxPlaceModal").html(result);
        },
        error:function(result, error){
            alert(error);
        },        
    });
}

function DoGet(TargetURL) {
    $.ajax({
        url:TargetURL,
        success:function(result, status, jqXHR){
            var regexp = /(javascript)/gi;
            if (!jqXHR.getResponseHeader('content-type').match(regexp)) {
                $("#AjaxModal").html(result);
                $("#AjaxModal").modal('show');
            }
        },
        error:function(result, error){
            alert(error);
        },        
    });
}

function DoGetLieu(TargetURL) {
    $('#AjaxModal').modal("hide");        
    $.ajax({
        url:TargetURL,
        success:function(result, status, jqXHR){
            var regexp = /(javascript)/gi;
            if (!jqXHR.getResponseHeader('content-type').match(regexp)) {
                $("#AjaxPlaceModal").html(result);
                $("#AjaxPlaceModal").modal('show');
            }
        },
        error:function(result, error){
            alert(error);
        },        
    });
}

$(document).ready(function() { 
    $.fn.modal.Constructor.prototype.enforceFocus = function() {};

    $('[handle="modal"]').click(function(e) {
        e.preventDefault();  
        var url = $(this).attr('Myhref');
        var target = $(this).attr('data-target');
        $(target).html('');
        $(target).addClass("Loading");
        $(target).modal("show");
        $(target).load(url, function() {
            $(target).removeClass("Loading");
        });
        return false;
    });

    $('#AjaxModal').on('hidden', function(bla){
        if (bla.target.id.endsWith('-help'))
            return;
        if (bla.target.id=='AjaxModal') {
            if ($(this).children().length)
                $(this).children()[0].remove();
            if (typeof map === "undefined") 
                return;
            if (map)
                map.remove();
        }
    });

    $('#AjaxPlaceModal').on('hidden', function(bla){
        $("#place_type").select2("destroy");
        if (bla.target.id.endsWith('-help'))
            return;
        if ($(this).children().length)    
            $(this).children()[0].remove();
        $("#place_type");
    });

    $('#AjaxPlaceModal').on('shown', function(bla){
     if (map)
          setTimeout(function() {
            map.invalidateSize();
          }, 10);    
    });

    $('#AjaxModal').on('shown', function(bla){
    if (bla.target.id=="ItinMap")
          setTimeout(function() {
            map.invalidateSize();
            toast.route();
            $('#map_Itineraire').eq(0).html( $('.leaflet-routing-alt').eq(0).html() );
            $('.leaflet-routing-container').eq(0).attr("style","display:none;")
            $('#map_Itineraire > table').eq(0).attr("style","width:100%;");
          }, 10);
    });

    $('[data-toggle="modal"]').click(function(e) {
      e.preventDefault();
      var url = $(this).attr('href');
      //var modal_id = $(this).attr('data-target');
      $.get(url, function(data) {
          $(data).modal();
      });
    });
    
    if (location.hash !== '') {
        var SavHash = location.hash;
        if (Array('#Miam','#Covoiturage','#Hebergement',
            '#Materiel','#ResumeInt').indexOf(location.hash)>=0)
            $('a[href="#Logistique"]').tab('show')
            .on('shown', function(e) {
                $('a[href="' + SavHash + '"]').tab('show');
            });
        else {
            if (Array('#ResumePart','#Conference','#Stand','#Atelier',
                '#TableRonde','#Organisation').indexOf(location.hash)>=0)
                $('a[href="#Interventions"]').tab('show')
                .on('shown', function(e) {
                    $('a[href="' + SavHash + '"]').tab('show');            
                });
            else
                $('a[href="' + SavHash + '"]').tab('show');
        }
    }
        
    jQuery(function() {
        jQuery('.repeat').each(function() {
            jQuery(this).repeatable_fields(
                {
                is_ready: function(container, therow) {
                    var numrow=$(container).attr('data-rf-row-count');
                    $("#tiersship-"+ (numrow-1) +"-tiers_uid").select2(
                        {
                            placeholder: 'Entrez ici votre entité',
                            minimumInputLength: 2, allowClear: true,
                            ajax: {
                                quietMillis: 250, url: "/json-tiers", dataType: 'json',
                                data: function (term, page) {
                                    return { pageSize: 8, pageNum: page, searchTerm: term };
                                },
                                results: function (data, page) {
                                    var more = (page * 8) < data.Total; 
                                    return { results: data.Results, more: more };
                                }
                            }
                        });
                }
            });
        });
    });

    $('a[data-toggle="tab"]')
        .on('shown', function(e) {
            stateObj = { tab: $(e.target).attr('href').substr(1) };
            history.replaceState(stateObj, "", "/MesJM2L" + $(e.target).attr('href') );
        }); 
    
    });