1 model=window.model||{};
5 function load(path,onload,onerror){
6 onerror = onerror||function(){};
7 var xhr = new XMLHttpRequest();
8 xhr.onload = function(){
9 if( this.status != 200 ){
10 onerror( this.responseText, this.status );
12 onload( this.responseText );
15 function errorHandler( e ){
16 onerror( (e||e.error).stack );
18 xhr.onerror = errorHandler;
20 xhr.open("GET",path,true);
25 if( lastxhr && lastxhr.readyState != 4 && lastxhr.abord )
32 var date = new Date();
34 Date.prototype.getDayOfYear = function(){
35 var start = new Date(this.getFullYear(), 0, 0);
36 var diff = this - start;
37 var oneDay = 1000 * 60 * 60 * 24;
38 var day = Math.floor(diff / oneDay);
42 Date.prototype.nextWeek = function(){
43 this.setDate(this.getDate()+7);
46 Date.prototype.lastWeek = function(){
47 this.setDate(this.getDate()-7);
50 function updateDate(){
51 model.week = Math.floor(date.getDayOfYear()/7) + '-' + date.getFullYear();
55 model.nextWeek = function(){
59 model.lastWeek = function(){
64 function loadClasses(){
68 model.displayInfo="none";
69 model.calendar = null;
71 "http://home.gibm.ch/interfaces/133/klassen.php?beruf_id=" + jobId,
74 list: JSON.parse( res ),
75 loadCalendar: loadCalendar
82 function loadCalendar(){
85 if( classId === null || jobId === null )
87 model.calendar = null;
88 model.displayInfo="none";
90 "http://home.gibm.ch/interfaces/133/tafel.php?klasse_id=" + classId + "&woche=" + model.week,
92 var events = JSON.parse( res );
97 model.displayInfo="none";
99 model.displayInfo="block";
108 model.displayInfo="none";
111 load("http://home.gibm.ch/interfaces/133/berufe.php", function( res ){
113 model.displayInfo="none";
115 list: JSON.parse( res ),
116 loadClasses: loadClasses