egroupware/phpgwapi/js/dhtmlxGantt/codebase/dhtmlxgantt.js

8 lines
122 KiB
JavaScript
Raw Normal View History

/*
This software is allowed to use under GPL or you need to obtain Commercial or Enterise License
to use it in non-GPL project. Please contact sales@dhtmlx.com for details
*/
function dtmlXMLLoaderObject(t,e,n,i){return this.xmlDoc="",this.async="undefined"!=typeof n?n:!0,this.onloadAction=t||null,this.mainObject=e||null,this.waitCall=null,this.rSeed=i||!1,this}function callerFunction(t,e){return this.handler=function(n){return n||(n=window.event),t(n,e),!0},this.handler}function getAbsoluteLeft(t){return getOffset(t).left}function getAbsoluteTop(t){return getOffset(t).top}function getOffsetSum(t){for(var e=0,n=0;t;)e+=parseInt(t.offsetTop),n+=parseInt(t.offsetLeft),t=t.offsetParent;return{top:e,left:n}}function getOffsetRect(t){var e=t.getBoundingClientRect(),n=document.body,i=document.documentElement,a=window.pageYOffset||i.scrollTop||n.scrollTop,s=window.pageXOffset||i.scrollLeft||n.scrollLeft,r=i.clientTop||n.clientTop||0,o=i.clientLeft||n.clientLeft||0,d=e.top+a-r,l=e.left+s-o;return{top:Math.round(d),left:Math.round(l)}}function getOffset(t){return t.getBoundingClientRect?getOffsetRect(t):getOffsetSum(t)}function convertStringToBoolean(t){switch("string"==typeof t&&(t=t.toLowerCase()),t){case"1":case"true":case"yes":case"y":case 1:case!0:return!0;default:return!1}}function getUrlSymbol(t){return-1!=t.indexOf("?")?"&":"?"}function dhtmlDragAndDropObject(){return window.dhtmlDragAndDrop?window.dhtmlDragAndDrop:(this.lastLanding=0,this.dragNode=0,this.dragStartNode=0,this.dragStartObject=0,this.tempDOMU=null,this.tempDOMM=null,this.waitDrag=0,window.dhtmlDragAndDrop=this,this)}function _dhtmlxError(){return this.catches||(this.catches=new Array),this}function dhtmlXHeir(t,e){for(var n in e)"function"==typeof e[n]&&(t[n]=e[n]);return t}function dhtmlxEvent(t,e,n){t.addEventListener?t.addEventListener(e,n,!1):t.attachEvent&&t.attachEvent("on"+e,n)}function dhtmlxDetachEvent(t,e,n){t.removeEventListener?t.removeEventListener(e,n,!1):t.detachEvent&&t.detachEvent("on"+e,n)}function dhtmlxDnD(t,e){e&&(this._settings=e),dhtmlxEventable(this),dhtmlxEvent(t,"mousedown",dhtmlx.bind(function(e){this.dragStart(t,e)},this))}function dataProcessor(t){return this.serverProcessor=t,this.action_param="!nativeeditor_status",this.object=null,this.updatedRows=[],this.autoUpdate=!0,this.updateMode="cell",this._tMode="GET",this.post_delim="_",this._waitMode=0,this._in_progress={},this._invalid={},this.mandatoryFields=[],this.messages=[],this.styles={updated:"font-weight:bold;",inserted:"font-weight:bold;",deleted:"text-decoration : line-through;",invalid:"background-color:FFE0E0;",invalid_cell:"border-bottom:2px solid red;",error:"color:red;",clear:"font-weight:normal;text-decoration:none;"},this.enableUTFencoding(!0),dhtmlxEventable(this),this}dhtmlx=function(t){for(var e in t)dhtmlx[e]=t[e];return dhtmlx},dhtmlx.extend_api=function(t,e,n){var i=window[t];i&&(window[t]=function(t){if(t&&"object"==typeof t&&!t.tagName){var n=i.apply(this,e._init?e._init(t):arguments);for(var a in dhtmlx)e[a]&&this[e[a]](dhtmlx[a]);for(var a in t)e[a]?this[e[a]](t[a]):0==a.indexOf("on")&&this.attachEvent(a,t[a])}else var n=i.apply(this,arguments);return e._patch&&e._patch(this),n||this},window[t].prototype=i.prototype,n&&dhtmlXHeir(window[t].prototype,n))},dhtmlxAjax={get:function(t,e){var n=new dtmlXMLLoaderObject(!0);return n.async=arguments.length<3,n.waitCall=e,n.loadXML(t),n},post:function(t,e,n){var i=new dtmlXMLLoaderObject(!0);return i.async=arguments.length<4,i.waitCall=n,i.loadXML(t,!0,e),i},getSync:function(t){return this.get(t,null,!0)},postSync:function(t,e){return this.post(t,e,null,!0)}},dtmlXMLLoaderObject.count=0,dtmlXMLLoaderObject.prototype.waitLoadFunction=function(t){var e=!0;return this.check=function(){if(t&&null!=t.onloadAction&&(!t.xmlDoc.readyState||4==t.xmlDoc.readyState)){if(!e)return;e=!1,dtmlXMLLoaderObject.count++,"function"==typeof t.onloadAction&&t.onloadAction(t.mainObject,null,null,null,t),t.waitCall&&(t.waitCall.call(this,t),t.waitCall=null)}},this.check},dtmlXMLLoaderObject.prototype.getXMLTopNode=function(t,e){if(this.xmlDoc.responseXML){var n=this.xmlDoc.responseXML.getElementsByTagName(t);if(0==n.length&&-1!=t.indexOf(":"))var n=this.xmlDoc.responseXML.getElementsByTagName(t.split(":")[1]
},gantt._init_dnd=function(){var t=new dhtmlxDnD(this.$grid_data,{updates_per_second:60});dhtmlx.defined(this.config.dnd_sensitivity)&&(t.config.sensitivity=this.config.dnd_sensitivity),t.attachEvent("onBeforeDragStart",dhtmlx.bind(function(t,e){var n=this._locateHTML(e);return n?(this.hideQuickInfo&&this._hideQuickInfo(),void 0):!1},this)),t.attachEvent("onAfterDragStart",dhtmlx.bind(function(e,n){var i=this._locateHTML(n);t.config.marker.innerHTML=i.outerHTML,t.config.id=this.locate(n);var a=this.getTask(t.config.id);a.$open=!1,a.$transparent=!0,this.refreshData()},this)),t.attachEvent("onDragMove",dhtmlx.bind(function(e,n){var i=t.config,a=this._get_position(this.$grid_data),s=a.x+10,r=n.pos.y-10;r<a.y&&(r=a.y),r>a.y+this.$grid_data.offsetHeight-this.config.row_height&&(r=a.y+this.$grid_data.offsetHeight-this.config.row_height),i.marker.style.left=s+"px",i.marker.style.top=r+"px";var o=document.elementFromPoint(a.x-document.body.scrollLeft+1,r-document.body.scrollTop),d=this.locate(o);if(this.isTaskExists(d)){var l=gantt._get_position(o),h=this.getTask(d),_=this.getTask(t.config.id);if(l.y+o.offsetHeight/2<r){var c=this.getGlobalTaskIndex(h.id),g=this._pull[this._order[c+1+(h.id==_.id?1:0)]];if(g){if(g.id==_.id)return;h=g}else if(g=this._pull[this._order[c+1]],g.$level==_.$level)return this.moveTask(_.id,-1,g.parent),i.target="next:"+g.id,void 0}if(h.$level==_.$level&&_.id!=h.id)this.moveTask(_.id,0,0,h.id),i.target=h.id;else{if(_.id==h.id)return;var c=this.getGlobalTaskIndex(h.id),u=this._pull[this._order[c-1]];u&&u.$level==_.$level&&_.id!=u.id&&(this.moveTask(_.id,-1,u.parent),i.target="next:"+u.id)}}return!0},this)),t.attachEvent("onDragEnd",dhtmlx.bind(function(){this.getTask(t.config.id).$transparent=!1,this.refreshData(),this.callEvent("onRowDragEnd",[t.config.id,t.config.target])},this))},gantt._scale_helpers={getSum:function(t,e,n){void 0===n&&(n=t.length-1),void 0===e&&(e=0);for(var i=0,a=e;n>=a;a++)i+=t[a];return i},setSumWidth:function(t,e,n,i){var a=e.width;void 0===i&&(i=a.length-1),void 0===n&&(n=0);var s=i-n+1;if(!(n>a.length-1||0>=s||i>a.length-1)&&t){var r=this.getSum(a,n,i),o=t-r;this.adjustSize(o,a,n,i),this.adjustSize(-o,a,i+1),e.full_width=this.getSum(a)}},splitSize:function(t,e){for(var n=[],i=0;e>i;i++)n[i]=0;return this.adjustSize(t,n),n},adjustSize:function(t,e,n,i){n||(n=0),void 0===i&&(i=e.length-1);for(var a=i-n+1,s=this.getSum(e,n,i),r=0,o=n;i>=o;o++){var d=Math.floor(t*(s?e[o]/s:1/a));e[o]+=d,r+=d}e[e.length-1]+=t-r},sortScales:function(t){function e(t,e){var n=new Date(1970,0,1);return gantt.date.add(n,e,t)-n}t.sort(function(t,n){return e(t.unit,t.step)<e(n.unit,n.step)?1:-1})},primaryScale:function(){return gantt._init_template("date_scale"),{unit:gantt.config.scale_unit,step:gantt.config.step,template:gantt.templates.date_scale,date:gantt.config.date_scale,css:gantt.templates.scale_cell_class}},prepareConfigs:function(t,e,n,i){for(var a=this.prepareScaleConfig(t[t.length-1],e,n).full_width,s=this.splitSize(i,t.length),r=[],o=0;o<t.length;o++){var d=this.prepareScaleConfig(t[o],e,a,s[o]);this.formatScales(d),r.push(d)}for(var o=0;o<r.length-1;o++)this.alineScaleColumns(r[r.length-1],r[o]);return r},prepareScaleConfig:function(t,e,n,i){var a=dhtmlx.mixin({count:0,col_width:0,full_width:0,height:i,width:[],trace_x:[]},t);this.eachColumn(t.unit,t.step,function(t){a.count++,a.trace_x.push(new Date(t))});var s=n;return a.col_width=Math.floor(s/a.count),e&&a.col_width<e&&(a.col_width=e,s=a.col_width*a.count),a.width=this.splitSize(s,a.count),a.full_width=this.getSum(a.width),a},alineScaleColumns:function(t,e,n,i){for(var a=e.trace_x,s=t.trace_x,r=n||0,o=i||s.length-1,d=0,l=1;l<a.length;l++)for(var h=r;o>=h;h++)if(+s[h]!=+a[l]);else{var _=this.getSum(t.width,r,h-1),c=this.getSum(e.width,d,l-1);c!=_&&this.setSumWidth(_,e,d,l-1),r=h,d=l}},eachColumn:function(t,e,n){var i=new Date(gantt._min_date),a=new Date(gantt._max_date);gantt.date[t+"_start"]&&(i=gantt.date[t+"_start"](i));for(var s=new Date(i);+a>+s;)n.call(this,new Date(s)),s=gantt.date.add(s,e,t)},formatScales:function(t){var e=t.trace_x
a=a||n;var r=e.call(gantt,i);r&&(s[i.id]?this.replace_item(i.id,r):(s[i.id]=r,a.appendChild(r)))},render_items:function(e,i){this.rendered=gantt._task_area_pulls[t]={},i=i||n,i.innerHTML="";for(var a=document.createDocumentFragment(),s=0,r=e.length;r>s;s++)this.render_item(e[s],a);i.appendChild(a)},replace_item:function(t,e){var n=this.rendered[t];n&&n.parentNode&&n.parentNode.replaceChild(e,n),this.rendered[t]=e},remove_item:function(t){var e=this.rendered[t];e&&e.parentNode&&e.parentNode.removeChild(e),delete this.rendered[t]},change_id:function(t,e){this.rendered[e]=this.rendered[t],delete this.rendered[t]},rendered:this._task_area_pulls[t],node:n},this._task_area_renderers[t])},gantt.showTask=function(t){var e=this.getTaskNode(t),n=Math.max(e.offsetLeft-this.config.task_scroll_offset,0),i=e.offsetTop-(this.$task_data.offsetHeight-this.config.row_height)/2;this._scroll_task_area(n,i)},gantt._pull={},gantt._branches={},gantt._order=[],gantt._lpull={},gantt.load=function(t,e,n){dhtmlx.assert(arguments.length,"Invalid load arguments"),this.callEvent("onLoadStart",[]);var i="json",a=null;arguments.length>=3?(i=e,a=n):"string"==typeof arguments[1]?i=arguments[1]:"function"==typeof arguments[1]&&(a=arguments[1]),dhtmlxAjax.get(t,dhtmlx.bind(function(t){this.on_load(t,i),"function"==typeof a&&a.call(this)},this))},gantt.parse=function(t,e){this.on_load({xmlDoc:{responseText:t}},e)},gantt.serialize=function(t){return t=t||"json",this[t].serialize()},gantt.on_load=function(t,e){e||(e="json"),dhtmlx.assert(this[e],"Invalid data type:'"+e+"'");var n=t.xmlDoc.responseText,i=this[e].parse(n,t);this._process_loading(i),this.callEvent("onLoadEnd",[])},gantt._process_loading=function(t){t.collections&&this._load_collections(t.collections);for(var e={},n=t.data,i=0;i<n.length;i++){var a=n[i];this._init_task(a),this.callEvent("onTaskLoading",[a])&&(e[a.id]=a,this._branches[a.parent]||(this._branches[a.parent]=[]),this._branches[a.parent].push(a.id))}dhtmlx.mixin(this._pull,e,!0),this._sync_order();for(var i in this._pull)this._pull[i].$level=this._item_level(this._pull[i]);this._init_links(t.links||(t.collections?t.collections.links:[]))},gantt._init_links=function(t){if(t)for(var e=0;e<t.length;e++){var n=this._init_link(t[e]);this._lpull[n.id]=n}this._sync_links()},gantt._load_collections=function(t){var e=!1;for(var n in t)if(t.hasOwnProperty(n)){e=!0;var i=t[n],a=this.serverList[n];if(!a)continue;a.splice(0,a.length);for(var s=0;s<i.length;s++){var r=i[s],o=dhtmlx.copy(r);o.key=o.value;for(var d in r)if(r.hasOwnProperty(d)){if("value"==d||"label"==d)continue;o[d]=r[d]}a.push(o)}}e&&this.callEvent("onOptionsLoad",[])},gantt._sync_order=function(){this._order=[],this._sync_order_item({parent:0,$open:!0,$ignore:!0,id:0}),this._scroll_resize(),this._set_sizes()},gantt.attachEvent("onBeforeTaskDisplay",function(t,e){return!e.$ignore}),gantt._sync_order_item=function(t){if(t.id&&this.callEvent("onBeforeTaskDisplay",[t.id,t])&&this._order.push(t.id),t.$open){var e=this._branches[t.id];if(e)for(var n=0;n<e.length;n++)this._sync_order_item(this._pull[e[n]])}},gantt._get_visible_order=function(t){dhtmlx.assert(t,"Invalid argument");for(var e=this._order,n=0,i=e.length;i>n;n++)if(e[n]==t)return n;return-1},gantt.eachTask=function(t,e,n){e=e||0,n=n||this;var i=this._branches[e];if(i)for(var a=0;a<i.length;a++){var s=this._pull[i[a]];t.call(n,s),this._branches[s.id]&&this.eachTask(t,s.id,n)}},gantt.json={parse:function(data){return dhtmlx.assert(data,"Invalid data"),"string"==typeof data&&(window.JSON?data=JSON.parse(data):(gantt._temp=eval("("+data+")"),data=gantt._temp||{},gantt._temp=null)),data.dhx_security&&(dhtmlx.security_key=data.dhx_security),data},_copyLink:function(t){var e={};for(var n in t)e[n]=t[n];return e},_copyObject:function(t){var e={};for(var n in t)"$"!=n.charAt(0)&&(e[n]=t[n]);return e.start_date=gantt.templates.xml_format(e.start_date),e.end_date&&(e.end_date=gantt.templates.xml_format(e.end_date)),e},serialize:function(){var t=[],e=[];gantt.eachTask(function(e){t.push(this._copyObject(e))},0,this);for(var n in gantt._lp
},1),void 0)},this),l.onchange=dhtmlx.bind(function(){a()},this),this.form_blocks._fill_lightbox_select(o,0,n.start_date,c,r);var g,u=gantt._tasks.unit;g=n.end_date?(n.end_date.valueOf()-n.start_date.valueOf())/(1e3*this._get_line(u)):n.duration,g=Math.round(g),l.value=g,a()},_get_start_date:function(t,e){var n=t.getElementsByTagName("select"),i=e._time_format_order,a=0,s=0;if(dhtmlx.defined(i[3])){var r=parseInt(n[i[3]].value,10);a=Math.floor(r/60),s=r%60}return new Date(n[i[2]].value,n[i[1]].value,n[i[0]].value,a,s)},_get_duration:function(t){var e=t.getElementsByTagName("input")[1];return e=parseInt(e.value,10),window.isNaN(e)&&(e=1),0>e&&(e*=-1),e},get_value:function(t,e,n){e.start_date=this.form_blocks.duration._get_start_date(t,n);var i=this.form_blocks.duration._get_duration(t,n);return e.end_date=this.date.add(e.start_date,i,this._tasks.unit),e.duration=i,{start_date:new Date(e.start_date),end_date:new Date(e.end_date)}},focus:function(t){gantt._focus(t.getElementsByTagName("select")[0])}}},gantt._is_lightbox_timepicker=function(){for(var t=this.config.lightbox.sections,e=0;e<t.length;e++)if("time"==t[e].name&&"time"==t[e].type)return!0;return!1},gantt._dhtmlx_confirm=function(t,e,n,i){if(!t)return n();var a={text:t};e&&(a.title=e),i&&(a.ok=i),n&&(a.callback=function(t){t&&n()}),dhtmlx.confirm(a)},dataProcessor.prototype={setTransactionMode:function(t,e){this._tMode=t,this._tSend=e},escape:function(t){return this._utf?encodeURIComponent(t):escape(t)},enableUTFencoding:function(t){this._utf=convertStringToBoolean(t)},setDataColumns:function(t){this._columns="string"==typeof t?t.split(","):t},getSyncState:function(){return!this.updatedRows.length},enableDataNames:function(t){this._endnm=convertStringToBoolean(t)},enablePartialDataSend:function(t){this._changed=convertStringToBoolean(t)},setUpdateMode:function(t,e){this.autoUpdate="cell"==t,this.updateMode=t,this.dnd=e},ignore:function(t,e){this._silent_mode=!0,t.call(e||window),this._silent_mode=!1},setUpdated:function(t,e,n){if(!this._silent_mode){var i=this.findRow(t);n=n||"updated";var a=this.obj.getUserData(t,this.action_param);a&&"updated"==n&&(n=a),e?(this.set_invalid(t,!1),this.updatedRows[i]=t,this.obj.setUserData(t,this.action_param,n),this._in_progress[t]&&(this._in_progress[t]="wait")):this.is_invalid(t)||(this.updatedRows.splice(i,1),this.obj.setUserData(t,this.action_param,"")),e||this._clearUpdateFlag(t),this.markRow(t,e,n),e&&this.autoUpdate&&this.sendData(t)}},_clearUpdateFlag:function(){},markRow:function(t,e,n){var i="",a=this.is_invalid(t);if(a&&(i=this.styles[a],e=!0),this.callEvent("onRowMark",[t,e,n,a])&&(i=this.styles[e?n:"clear"]+i,this.obj[this._methods[0]](t,i),a&&a.details)){i+=this.styles[a+"_cell"];for(var s=0;s<a.details.length;s++)a.details[s]&&this.obj[this._methods[1]](t,s,i)}},getState:function(t){return this.obj.getUserData(t,this.action_param)},is_invalid:function(t){return this._invalid[t]},set_invalid:function(t,e,n){n&&(e={value:e,details:n,toString:function(){return this.value.toString()}}),this._invalid[t]=e},checkBeforeUpdate:function(){return!0},sendData:function(t){return!this._waitMode||"tree"!=this.obj.mytype&&!this.obj._h2?(this.obj.editStop&&this.obj.editStop(),"undefined"==typeof t||this._tSend?this.sendAllData():this._in_progress[t]?!1:(this.messages=[],!this.checkBeforeUpdate(t)&&this.callEvent("onValidationError",[t,this.messages])?!1:(this._beforeSendData(this._getRowData(t),t),void 0))):void 0},_beforeSendData:function(t,e){return this.callEvent("onBeforeUpdate",[e,this.getState(e),t])?(this._sendData(t,e),void 0):!1},serialize:function(t,e){if("string"==typeof t)return t;if("undefined"!=typeof e)return this.serialize_one(t,"");var n=[],i=[];for(var a in t)t.hasOwnProperty(a)&&(n.push(this.serialize_one(t[a],a+this.post_delim)),i.push(a));return n.push("ids="+this.escape(i.join(","))),dhtmlx.security_key&&n.push("dhx_security="+dhtmlx.security_key),n.join("&")},serialize_one:function(t,e){if("string"==typeof t)return t;var n=[];for(var i in t)t.hasOwnProperty(i)&&n.push(this.escape((e||"")+i)+"="+this.escape(t[