[6779] | 1 | scheduler._loaded={};
|
---|
| 2 | scheduler._load=function(url,from){
|
---|
| 3 | url=url||this._load_url;
|
---|
| 4 | url+=(url.indexOf("?")==-1?"?":"&")+"timeshift="+(new Date()).getTimezoneOffset();
|
---|
| 5 | if (this.config.prevent_cache) url+="&uid="+this.uid();
|
---|
| 6 | var to;
|
---|
| 7 | from=from||this._date;
|
---|
| 8 |
|
---|
| 9 | if (this._load_mode){
|
---|
| 10 | var lf = this.templates.load_format;
|
---|
| 11 |
|
---|
| 12 | from = this.date[this._load_mode+"_start"](new Date(from.valueOf()));
|
---|
| 13 | while (from>this._min_date) from=this.date.add(from,-1,this._load_mode);
|
---|
| 14 | to = from;
|
---|
| 15 |
|
---|
| 16 | var cache_line = true;
|
---|
| 17 | while (to<this._max_date){
|
---|
| 18 | to=this.date.add(to,1,this._load_mode);
|
---|
| 19 | if (this._loaded[lf(from)] && cache_line)
|
---|
| 20 | from=this.date.add(from,1,this._load_mode);
|
---|
| 21 | else cache_line = false;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | var temp_to=to;
|
---|
| 25 | do {
|
---|
| 26 | to = temp_to;
|
---|
| 27 | temp_to=this.date.add(to,-1,this._load_mode);
|
---|
| 28 | } while (temp_to>from && this._loaded[lf(temp_to)]);
|
---|
| 29 |
|
---|
| 30 | if (to<=from)
|
---|
| 31 | return false; //already loaded
|
---|
| 32 | dhtmlxAjax.get(url+"&from="+lf(from)+"&to="+lf(to),function(l){scheduler.on_load(l);});
|
---|
| 33 | while(from<to){
|
---|
| 34 | this._loaded[lf(from)]=true;
|
---|
| 35 | from=this.date.add(from,1,this._load_mode);
|
---|
| 36 | }
|
---|
| 37 | } else
|
---|
| 38 | dhtmlxAjax.get(url,function(l){scheduler.on_load(l);});
|
---|
| 39 | this.callEvent("onXLS",[]);
|
---|
| 40 | return true;
|
---|
| 41 | }
|
---|
| 42 | scheduler.on_load=function(loader){
|
---|
| 43 | this._loading=true;
|
---|
| 44 | if (this._process)
|
---|
| 45 | var evs=this[this._process].parse(loader.xmlDoc.responseText);
|
---|
| 46 | else
|
---|
| 47 | var evs=this._magic_parser(loader);
|
---|
| 48 |
|
---|
| 49 | this._not_render=true;
|
---|
| 50 | for (var i=0; i<evs.length; i++){
|
---|
| 51 | if (!this.callEvent("onEventLoading",[evs[i]])) continue;
|
---|
| 52 | this.addEvent(evs[i]);
|
---|
| 53 | }
|
---|
| 54 | this._not_render=false;
|
---|
| 55 | if (this._render_wait) this.render_view_data();
|
---|
| 56 |
|
---|
| 57 | if (this._after_call) this._after_call();
|
---|
| 58 | this._after_call=null;
|
---|
| 59 | this._loading=false;
|
---|
| 60 | this.callEvent("onXLE",[]);
|
---|
| 61 | }
|
---|
| 62 | scheduler.json={};
|
---|
| 63 | scheduler.json.parse = function(data){
|
---|
| 64 | if (typeof data == "string"){
|
---|
| 65 | eval("scheduler._temp = "+data+";");
|
---|
| 66 | data = scheduler._temp;
|
---|
| 67 | }
|
---|
| 68 | var evs = [];
|
---|
| 69 | for (var i=0; i < data.length; i++){
|
---|
| 70 | data[i].start_date = scheduler.templates.xml_date(data[i].start_date);
|
---|
| 71 | data[i].end_date = scheduler.templates.xml_date(data[i].end_date);
|
---|
| 72 | evs.push(data[i]);
|
---|
| 73 | }
|
---|
| 74 | return evs;
|
---|
| 75 | }
|
---|
| 76 | scheduler.parse=function(data,type){
|
---|
| 77 | this._process=type;
|
---|
| 78 | this.on_load({xmlDoc:{responseText:data}});
|
---|
| 79 | }
|
---|
| 80 | scheduler.load=function(url,call){
|
---|
| 81 | if (typeof call == "string"){
|
---|
| 82 | this._process=call;
|
---|
| 83 | call = arguments[2];
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | this._load_url=url;
|
---|
| 87 | this._after_call=call;
|
---|
| 88 | this._load(url,this._date);
|
---|
| 89 | };
|
---|
| 90 | //possible values - day,week,month,year,all
|
---|
| 91 | scheduler.setLoadMode=function(mode){
|
---|
| 92 | if (mode=="all") mode="";
|
---|
| 93 | this._load_mode=mode;
|
---|
| 94 | };
|
---|
| 95 |
|
---|
| 96 | //current view by default, or all data if "true" as parameter provided
|
---|
| 97 | scheduler.refresh=function(refresh_all){
|
---|
| 98 | alert("not implemented");
|
---|
| 99 | /*
|
---|
| 100 | this._loaded={};
|
---|
| 101 | this._load();
|
---|
| 102 | */
|
---|
| 103 | }
|
---|
| 104 | scheduler.serverList=function(name){
|
---|
| 105 | return this.serverList[name] = (this.serverList[name]||[]);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | scheduler._userdata={};
|
---|
| 109 | scheduler._magic_parser=function(loader){
|
---|
| 110 | if (!loader.getXMLTopNode){ //from a string
|
---|
| 111 | var xml_string = loader.xmlDoc.responseText;
|
---|
| 112 | loader = new dtmlXMLLoaderObject(function(){});
|
---|
| 113 | loader.loadXMLString(xml_string);
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | var xml=loader.getXMLTopNode("data");
|
---|
| 117 | if (xml.tagName!="data") return [];//not an xml
|
---|
| 118 |
|
---|
| 119 | var opts = loader.doXPath("//coll_options");
|
---|
| 120 | for (var i=0; i < opts.length; i++) {
|
---|
| 121 | var bind = opts[i].getAttribute("for");
|
---|
| 122 | var arr = this.serverList[bind];
|
---|
| 123 | if (!arr) continue;
|
---|
| 124 | arr.splice(0,arr.length); //clear old options
|
---|
| 125 | var itms = loader.doXPath(".//item",opts[i]);
|
---|
| 126 | for (var j=0; j < itms.length; j++)
|
---|
| 127 | arr.push({ key:itms[j].getAttribute("value"), label:itms[j].getAttribute("label")});
|
---|
| 128 | }
|
---|
| 129 | if (opts.length)
|
---|
| 130 | scheduler.callEvent("onOptionsLoad",[]);
|
---|
| 131 |
|
---|
| 132 | var ud=loader.doXPath("//userdata");
|
---|
| 133 | for (var i=0; i < ud.length; i++) {
|
---|
| 134 | var udx = this.xmlNodeToJSON(ud[i]);
|
---|
| 135 | this._userdata[udx.name]=udx.text;
|
---|
| 136 | };
|
---|
| 137 |
|
---|
| 138 | var evs=[];
|
---|
| 139 | var xml=loader.doXPath("//event");
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | for (var i=0; i < xml.length; i++) {
|
---|
| 143 | evs[i]=this.xmlNodeToJSON(xml[i])
|
---|
| 144 |
|
---|
| 145 | evs[i].text=evs[i].text||evs[i]._tagvalue;
|
---|
| 146 | evs[i].start_date=this.templates.xml_date(evs[i].start_date);
|
---|
| 147 | evs[i].end_date=this.templates.xml_date(evs[i].end_date);
|
---|
| 148 | }
|
---|
| 149 | return evs;
|
---|
| 150 | }
|
---|
| 151 | scheduler.xmlNodeToJSON = function(node){
|
---|
| 152 | var t={};
|
---|
| 153 | for (var i=0; i<node.attributes.length; i++)
|
---|
| 154 | t[node.attributes[i].name]=node.attributes[i].value;
|
---|
| 155 |
|
---|
| 156 | for (var i=0; i<node.childNodes.length; i++){
|
---|
| 157 | var child=node.childNodes[i];
|
---|
| 158 | if (child.nodeType==1)
|
---|
| 159 | t[child.tagName]=child.firstChild?child.firstChild.nodeValue:"";
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | if (!t.text) t.text=node.firstChild?node.firstChild.nodeValue:"";
|
---|
| 163 |
|
---|
| 164 | return t;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | scheduler.attachEvent("onXLS",function(){
|
---|
| 168 | if (this.config.show_loading===true){
|
---|
| 169 | var t;
|
---|
| 170 | t=this.config.show_loading=document.createElement("DIV");
|
---|
| 171 | t.className='dhx_loading';
|
---|
| 172 | t.style.left = Math.round((this._x-128)/2)+"px";
|
---|
| 173 | t.style.top = Math.round((this._y-15)/2)+"px";
|
---|
| 174 | this._obj.appendChild(t);
|
---|
| 175 | }
|
---|
| 176 | });
|
---|
| 177 | scheduler.attachEvent("onXLE",function(){
|
---|
| 178 | var t;
|
---|
| 179 | if (t=this.config.show_loading)
|
---|
| 180 | if (typeof t == "object"){
|
---|
| 181 | this._obj.removeChild(t);
|
---|
| 182 | this.config.show_loading=true;
|
---|
| 183 | }
|
---|
| 184 | });
|
---|