1/** 2 * lesson fetcher 3 * js lib 4 */ 5 6 // office 7 function OfficeFetcher(form_selector, office_selector, map_selector){ 8 var $this = this; 9 this.form = jQuery(form_selector); 10 this.office = jQuery(office_selector); 11 this.office_tmpl = jQuery("#office-template").html(); 12 this.map = jQuery(map_selector); 13 this.form_data = {}; 14 this.fetch_data = function(office_id){ 15 16 $this.form_data.office_id = office_id; 17 $this.form_data.action = ajax_object.office_action; 18 19 jQuery.ajax({ 20 'url': ajax_object.ajax_url, 21 'type' : 'post', 22 'dataType' : 'json', 23 'data' : $this.form_data, 24 'success' : $this.parse_results, 25 'error' : $this.error_callback 26 }); 27 28 }; 29 30 31 this.onchange_callback = function(el, event){ 32 event.preventDefault(); 33 var office_id = el.val(); 34 $this.fetch_data(office_id); 35 } 36 37 this.error_callback = function(err){ 38 console.log(err); 39 }; 40 41 this.parse_results = function(d){ 42 if ( !d || !d.success) 43 return; 44 45 var data = d.data; 46 var new_tmpl = jQuery($this.office_tmpl); 47 48 new_tmpl.find("#office-title").html(data.title); 49 new_tmpl.find("#office-phone").html(data.phone); 50 new_tmpl.find("#office-email").html(data.email); 51 new_tmpl.find("#office-address").html(data.address); 52 new_tmpl.find("#office-hours").html(data.hours); 53 if (data.waze.length > 0){ 54 console.log('yes') 55 new_tmpl.find("#office-waze-navigation").attr("href", data.waze); 56 } else { 57 console.log('no') 58 new_tmpl.find("#office-waze-navigation").remove(); 59 } 60 61 new_tmpl.find("#office-link").attr("href", data.link) 62 63 64 65 66 $this.office.html(new_tmpl.html()); 67 68 // map parsinb 69 if (data.google_map){ 70 var p = jQuery(data.google_map); 71 p.css({ 72 "width": "100%", 73 "height": "100%" 74 }); 75 76 $this.map.html(p); 77 } 78 } 79 80 this.init = function(){ 81 if (this.form.find("input").length){ 82 this.form.find("input").on("change", function(event){ 83 $this.onchange_callback(jQuery(this), event) 84 }) 85 } 86 } 87 88 } 89 90 // lesson fetcher 91 function LessonFetcher(grid_element, filters_form){ 92 this.grid = jQuery(grid_element); 93 this.form = jQuery(filters_form); 94 this.form_data = {}; 95 this.form_inputs = {}; 96 this.col_template = null; 97 this.reset_button = jQuery("#reset-filters"); 98 this.mode = this.form.data('mode') == 'lesson' ? 'lesson' : 'home'; 99 var $this = this; 100 101 this.init = function(){ 102 // form inputs 103 this.form_inputs.lesson_id = this.form.find("[name=lesson_id]"); 104 this.form_inputs.lesson_type = this.form.find("[name=lesson_type]"); 105 this.form_inputs.evening = this.form.find("[name=evening]"); 106 this.form_inputs.morning = this.form.find("[name=morning]"); 107 this.form_inputs.baby = this.form.find("[name=baby]"); 108 109 this.col_template = this.grid.find("#col-template").html; 110 111 // fetch on change 112 var $this = this; 113 this.form.find("input, select").change(function(e){ 114 $this.trigger_change(jQuery(this), e); 115 }); 116 117 this.reset_button.click(function(){ 118 $this.reset_form(); 119 }); 120 }; 121 122 this.trigger_change = function(el, event){ 123 event.preventDefault(); 124 if (this.mode == 'lesson'){ 125 if (el.is(":checked")){ 126 127 this.form.find('input').not(el).each(function(){ 128 jQuery(this).prop('checked', false); 129 }); 130 } 131 } 132 133 $this.fetch_data(); 134 } 135 136 this.fetch_data = function(){ 137 $this.grid.removeClass('loaded'); 138 139 $this.form_data.lesson_id = $this.form_inputs.lesson_id.val(); 140 $this.form_data.lesson_type = $this.form_inputs.lesson_type.val(); 141 142 if ($this.mode == 'lesson' ){ 143 $this.form_data.baby = 1; 144 145 if ($this.form_inputs.baby.is(':checked')){ 146 $this.form_data.evening = 1; 147 $this.form_data.morning = 1; 148 } else { 149 $this.form_data.evening = $this.form_inputs.evening.is(':checked') ? 1 : 0; 150 $this.form_data.morning = $this.form_inputs.morning.is(':checked') ? 1 : 0; 151 } 152 } else { 153 $this.form_data.evening = $this.form_inputs.evening.is(':checked') ? 1 : 0; 154 $this.form_data.morning = $this.form_inputs.morning.is(':checked') ? 1 : 0; 155 $this.form_data.baby = $this.form_inputs.baby.is(':checked') ? 1 : 0; 156 } 157 158 $this.form_data.action = ajax_object.lesson_action; 159 160 jQuery.ajax({ 161 'url': ajax_object.ajax_url, 162 'type' : 'post', 163 'dataType' : 'json', 164 'data' : $this.form_data, 165 'success' : $this.parse_results, 166 'error' : $this.error_callback 167 }); 168 169 170 }; 171 172 this.parse_results = function(data){ 173 $this.grid.html(''); 174 175 if (data && data.success == 1){ 176 177 var d = data.data; 178 console.log(d); 179 for (let k in d.events){ 180 var row = d.events[k]; 181 // console.log(row); 182 var time_mark = row.time; 183 var days = row.days; 184 var r = '<div class="lesson-table-row" data-row>'; 185 r += '<div class="lesson-table-col lesson-time"><span>'+time_mark+'</span></div>'; 186 for (let d in days){ 187 var events = days[d]; 188 189 r += '<div class="lesson-table-col">'; 190 for(let ev in events){ 191 let event = events[ev]; 192 let data_time = event.fromtime+';'+event.totime; 193 let lesson_id = $this.form_inputs.lesson_id.val(); 194 r += '<span class="event-item" tabindex="0" data-day="'+d+'" data-hall="'+event.hall+'" data-training="'+event.training_type+'" data-lesson_id="'+lesson_id+'" data-time="'+data_time+'">'; 195 r += '<h4>'+event.training_type+'</h4>'; 196 r += '<span class="event-hall">
196×××× '+event.hall+'</span>'; 197 if (event.registration_exists){ 198 r += '<span class="registration_exists-icon"><img src="'+ajax_object.theme_url+'/assets/images/clock.png" /></span>'; 199 } 200 if (event.instructor){ 201 r += '<span class="event-instructor">'+event.instructor+'</span>'; 202 } 203 204 r += '<br>'; 205 206 r += '</span>'; 207 } 208 r += '</div>'; 209 } 210 r += '</div>'; 211 // $this.grid.append(r); 212 } 213 214 var lesson_types = Object.keys(d.lesson_type).map(function(key) { 215 var o = d.lesson_type[key]; 216 var selected = $this.form_data.lesson_type == o ? 'selected' : ''; 217 return '<option value="'+o+'" '+selected+'>'+o+'</option>'; 218 }); 219 220 lesson_types.unshift('<option value="">×××¨× ×¡×× ×××××</option>'); 221 222 $this.form_inputs.lesson_type.html(lesson_types.join('')); 223 } 224 225 $this.grid.addClass('loaded'); 226 }; 227 228 this.error_callback = function(err){ 229 console.log(err); 230 }; 231 232 this.reset_form = function(){ 233 if (this.mode == 'lesson'){ 234 $this.form.find("input").prop('checked', false); 235 $this.form.find("input").first().prop('checked', true); 236 } else { 237 $this.form.find("input").prop('checked', true); 238 } 239 240 $this.form_inputs.lesson_type.val('').html('<option value="">×ש ××××ר ×¡× ××£</option>') 241 if (this.mode != 'lesson') 242 $this.form_inputs.lesson_id.val(0) 243 244 $this.grid.find(".event-item").fadeIn(function(){ 245 $this.grid.html(''); 246 }); 247 }; 248 249 this.clear_grid = function(){ 250 $this.grid.find(".event-item").fadeIn(); 251 }; 252 253 254 }; 255
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.