84c1db952e6977e1145029231948a53019ca6dc4
[ptitvelo/web/www.git] / www / plugins / calendrier_mini-2.0 / javascript / calendrier_mini.js.html
1 #HTTP_HEADER{Content-type:text/javascript}
2 if (!jQuery.fn.datepicker){
3 #INCLURE{javascript/ui/jquery.ui.core.js}
4 #INCLURE{javascript/ui/jquery.ui.widget.js}
5 #INCLURE{javascript/ui/jquery.ui.datepicker.js}
6 }
7 if (!jQuery.fn.multiDatesPicker){
8 #INCLURE{javascript/jquery-ui.multidatespicker.js}
9 }
10 [(#REM)<script>]
11 var ajax_image_searching = "<img src='#CHEMIN{images/searching.gif}' width='16' height='16' />";
12 var minical = {
13 options: {
14 buttonText: '<:afficher_calendrier|texte_script:>',
15 buttonImage: '#CHEMIN_IMAGE{calendrier-16.png}',
16 buttonImageOnly: true,
17 prevText: '<:precedent|texte_script:>',
18 nextText: '<:suivant|texte_script:>',
19 currentText: '<:date_aujourdhui|texte_script:>',
20 closeText: '<:bouton_fermer|texte_script:>',
21 monthNames: [
22 '<:date_mois_1|texte_script:>','<:date_mois_2|texte_script:>','<:date_mois_3|texte_script:>','<:date_mois_4|texte_script:>','<:date_mois_5|texte_script:>','<:date_mois_6|texte_script:>',
23 '<:date_mois_7|texte_script:>','<:date_mois_8|texte_script:>','<:date_mois_9|texte_script:>','<:date_mois_10|texte_script:>','<:date_mois_11|texte_script:>','<:date_mois_12|texte_script:>'],
24 monthNamesShort: [
25 '<:date_mois_1_abbr|texte_script:>','<:date_mois_2_abbr|texte_script:>','<:date_mois_3_abbr|texte_script:>','<:date_mois_4_abbr|texte_script:>','<:date_mois_5_abbr|texte_script:>','<:date_mois_6_abbr|texte_script:>',
26 '<:date_mois_7_abbr|texte_script:>','<:date_mois_8_abbr|texte_script:>','<:date_mois_9_abbr|texte_script:>','<:date_mois_10_abbr|texte_script:>','<:date_mois_11_abbr|texte_script:>','<:date_mois_12_abbr|texte_script:>'],
27 dayNames: [
28 '<:date_jour_1|texte_script:>','<:date_jour_2|texte_script:>','<:date_jour_3|texte_script:>','<:date_jour_4:|texte_script:>',
29 '<:date_jour_5|texte_script:>','<:date_jour_6|texte_script:>','<:date_jour_7|texte_script:>'],
30 dayNamesShort: [
31 '<:date_jour_1_abbr|texte_script:>','<:date_jour_2_abbr|texte_script:>','<:date_jour_3_abbr|texte_script:>','<:date_jour_4_abbr|texte_script:>',
32 '<:date_jour_5_abbr|texte_script:>','<:date_jour_6_abbr|texte_script:>','<:date_jour_7_abbr|texte_script:>'],
33 dayNamesMin: [
34 '<:date_jour_1_initiale|texte_script:>','<:date_jour_2_initiale|texte_script:>','<:date_jour_3_initiale|texte_script:>','<:date_jour_4_initiale|texte_script:>',
35 '<:date_jour_5_initiale|texte_script:>','<:date_jour_6_initiale|texte_script:>','<:date_jour_7_initiale|texte_script:>'],
36 dateFormat: 'yy-mm-dd',
37 firstDay: #CONFIG{calendriermini/jour1,1},
38 isRTL: [(#ENV{lang}|lang_dir|=={rtl}|?{true,false})],
39 changeMonth: [(#CONFIG{calendriermini/changement_rapide,1}|?{true,false})],
40 changeYear: [(#CONFIG{calendriermini/changement_rapide,1}|?{true,false})],
41 showOtherMonths: [(#CONFIG{calendriermini/affichage_hors_mois,1}|?{true,false})],
42 selectOtherMonths: [(#CONFIG{calendriermini/affichage_hors_mois,1}|?{true,false})]
43 },
44
45 add_tooltip_and_class: function($this,date,id,tooltip,className){
46 if (!$this.tooltip)
47 $this.tooltip = {};
48 if (!$this.cn)
49 $this.cn = {};
50
51 var d = date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate();
52 if (!$this.tooltip[d])
53 $this.tooltip[d] = {};
54 tooltip = tooltip.replace(/"/g,'&quot;'); // echapper les " pour ne pas casser le html (secu, supprimer le html en amont !)
55 $this.tooltip[d][id] = tooltip;
56
57 if (className && typeof className != "undefined"){
58 if (!$this.cn[d])
59 $this.cn[d] = {};
60 $this.cn[d][id] = className;
61 }
62 },
63
64 set_events: function(me,start,end,data){
65 var dates = [];
66 var $this = me.get(0);
67
68 if (data.length){
69 var d,datebegin,dateend;
70 for(var j=0;j<data.length;j++){
71 d = data[j].start.split(" ");
72 d = d[0].split("-");
73 d = new Date(d[0],d[1]-1,d[2]);
74 dates.push(d);
75 minical.add_tooltip_and_class($this,d,data[j].id,data[j].title,data[j].className);
76
77 if(data[j].end){
78 /* prendre la plus grande date de debut entre debut a afficher et l'interval donne */
79 datebegin = Math.max(start * 1000,d.getTime());
80 d = data[j].end.split(" ");
81 d = d[0].split("-");
82 d = new Date(d[0],d[1]-1,d[2]);
83 /* prendre la plus petite date de fin entre fin a afficher et l'interval donne */
84 dateend = Math.min(end * 1000, d.getTime());
85 if (dateend>datebegin){
86 dates.push(d);
87 minical.add_tooltip_and_class($this,d,data[j].id,data[j].title,data[j].className);
88 datebegin = datebegin+(3600*24*1000);
89 while(datebegin < dateend){
90 d = new Date(datebegin);
91 dates.push(d);
92 minical.add_tooltip_and_class($this,d,data[j].id,data[j].title,data[j].className);
93 datebegin = datebegin+(3600*24*1000);
94 }
95 }
96 }
97 }
98
99 me.multiDatesPicker('addDates', dates);
100 // toujours retirer la classe active qui n'a pas de sens pour l'affichage
101 jQuery('.ui-state-active',me).removeClass('ui-state-active');
102 }
103 },
104
105 before_show_day: function(date) {
106 var d = date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate();
107 var c = [true, ''];
108 if (this.cn && this.cn[d]){
109 for (var i in this.cn[d])
110 c[1] += ' ' + this.cn[d][i];
111 }
112
113 if (this.tooltip && this.tooltip[d]){
114 var glue = '';
115 c[2] = '';
116 for (var i in this.tooltip[d]) {
117 c[2] += glue + this.tooltip[d][i];
118 glue = "\n";
119 }
120 }
121 return c;
122 },
123
124 change_month_year: function(year, month, inst){
125 var me = inst;
126 //console.log("change_month_year:"+year+"/"+month);
127 if (typeof inst.input != "undefined")
128 me = inst.input;
129 //console.log(me);
130 var t = new Date(year,month-1,1);
131 t = parseInt(t.getTime()/1000);
132 var start = t-7*24*3600;
133 var end = t+38*24*3600;
134 // stocker les year/month deja vus pour ne pas les recharger 2 fois quand on va et vient
135 var o = me.get(0);
136 if (typeof o.dateseen == "undefined")
137 o.dateseen = {};
138 if (!o.dateseen[year+"/"+month]){
139 //console.log(o.dateseen);
140 o.dateseen[year+"/"+month] = true;
141 minical.show_loading(me);
142 jQuery.ajax({
143 url:jQuery(me).attr("data-json"),
144 data:{start:start,end:end},
145 success:function(data, textStatus, jqXHR){
146 data = eval(data);
147 minical.set_events(me,start,end,data);
148 minical.hide_loading(me);
149 }
150 });
151 }
152 inst.currentDay=0; // annuler la date active : pas de sens ici
153 },
154 show_loading : function(me){
155 me.animateLoading();
156 },
157 hide_loading : function(me) {
158 me.endLoading(true);
159 },
160
161 scripts_loaded: {widget:false,datepicker:false,multidatepicker:false},
162 init : function(selecteur){
163 //if (!minical.scripts_loaded.widget || !minical.scripts_loaded.datepicker || !minical.scripts_loaded.multidatepicker)
164 // return;
165 [(#CONFIG{calendriermini/format_jour,initiale}|=={abbr}|oui)
166 minical.options.dayNamesMin = minical.options.dayNamesShort;
167 ]
168 jQuery(function(){
169 jQuery(selecteur).not('.loaded')
170 .addClass('loaded')
171 .multiDatesPicker(jQuery.extend(minical.options,
172 {
173 showButtonPanel: true,
174 prevText: '<:minical:mois_precedent|texte_script:>',
175 nextText: '<:minical:mois_suivant|texte_script:>',
176 create: minical.create,
177 beforeShowDay: minical.before_show_day,
178 onChangeMonthYear: minical.change_month_year,
179 onSelect: minical.on_select
180 })
181 )
182 .each(function(){
183 var me=jQuery(this);
184 // se mettre a la date demandee (pour afficher le bon mois)
185 me.datepicker("setDate" , me.attr('data-year')+"-"+me.attr('data-month')+"-1");
186 // et retirer la classe active qui n'a pas de sens pour l'affichage
187 jQuery('.ui-state-active',me).removeClass('ui-state-active');
188 minical.change_month_year(me.attr('data-year'),me.attr('data-month'),me);
189 })
190 .trigger('miniCalendarLoaded')
191 .find(".alt").remove();
192 });
193 },
194 on_select : function(dateText, inst){
195 var me = inst.input;
196 if (dateText) {
197 // annuler la selection !
198 me.multiDatesPicker('toggleDate', dateText);
199 var actif = (me.multiDatesPicker('gotDate', dateText) !==false);
200 if (actif){
201 var url = me.attr('data-url');
202 url = parametre_url(url,me.attr('data-vardate'),dateText);
203 //console.log(url);
204 window.location = url;
205 }
206 }
207 }
208 }