diff --git a/ganttzk/src/main/resources/web/js/common/Common.js b/ganttzk/src/main/resources/web/js/common/Common.js index 1528bd802..052b9a8b2 100644 --- a/ganttzk/src/main/resources/web/js/common/Common.js +++ b/ganttzk/src/main/resources/web/js/common/Common.js @@ -16,5 +16,57 @@ common.Common = zk.$extends(zk.Widget,{},{ cachedResult = functionToExecute.apply(null, arguments); return cachedResult; }; + }, + /** + * It can be called in the constructor of a widget. + * It is required that the widget has the method _divsToRestoreDayInto that returns + * the divs which their scroll must be changed back to the previous day. + */ + +// TODO: Refactoring should be done, not so many methods should be needed to synchronize the day. + mixInDayPositionRestorer: function(widget) { + if (! ('_divsToRestoreDayInto' in widget)) { + throw '_divsToRestoreDayInto function must be present in widget'; + } + var scrollDay = 0; + /** + * Scrolls horizontally the ganttpanel when the zoom has resized the component + * width. + */ + widget.scroll_horizontal = function(daysDisplacement) { + scrollDay = daysDisplacement; + }; + widget.update_day_scroll = function(previousPixelPerDay) { + var divs = this._divsToRestoreDayInto(); + var topScrollDiv = divs[divs.length - 1]; + + var maxHPosition = topScrollDiv.scrollWidth - topScrollDiv.clientWidth; + if (maxHPosition > 0) { + var proportion = topScrollDiv.scrollWidth / maxHPosition; + var positionInScroll = topScrollDiv.scrollLeft; + var positionInPx = positionInScroll * proportion; + if (positionInPx > 0) { + scrollDay = positionInPx / previousPixelPerDay; + } + } + }; + widget.move_scroll = function(diffDays, pixelPerDay) { + var divs = this._divsToRestoreDayInto(); + var topScrollDiv = divs[divs.length - 1]; + + var day = this.scrollDay + parseInt(diffDays); + var newPosInPx = parseInt(day * pixelPerDay); + var maxHPosition = topScrollDiv.scrollWidth - topScrollDiv.clientWidth; + var newProportion = topScrollDiv.scrollWidth / maxHPosition; + if (newProportion > 0) { + var newPosInScroll = newPosInPx / newProportion; + if (newPosInScroll < 0) { + newPosInScroll = 0; + } + for ( var i = 0; i < divs.length; i++) { + divs[i].scrollLeft = newPosInScroll; + } + } + }; } }); \ No newline at end of file diff --git a/ganttzk/src/main/resources/web/js/ganttz/GanttPanel.js b/ganttzk/src/main/resources/web/js/ganttz/GanttPanel.js index d6bb0c956..a36426d91 100644 --- a/ganttzk/src/main/resources/web/js/ganttz/GanttPanel.js +++ b/ganttzk/src/main/resources/web/js/ganttz/GanttPanel.js @@ -9,6 +9,7 @@ ganttz.GanttPanel = zk.$extends(zk.Widget,{ $init : function(){ this.$supers('$init', arguments); this.$class.setInstance(this); + common.Common.mixInDayPositionRestorer(this); }, bind_ : function(evt){ this.$supers('bind_', arguments); @@ -23,6 +24,10 @@ ganttz.GanttPanel = zk.$extends(zk.Widget,{ this.domUnlisten_(this.$n(), 'onMousemove', '_calcXY'); this.$supers('unbind_', arguments); }, + _divsToRestoreDayInto: function() { + var first = jq("#ganttpanel").get(0); + return [first, first.parentNode, first.parentNode.parentNode]; + }, timeplotContainerRescroll : function(){ this._timeplotcontainer.each(jq.proxy(function(index, element){ jq(element).css("left", "-" + this._rightpannellayout.scrollLeft() + "px") @@ -61,60 +66,7 @@ ganttz.GanttPanel = zk.$extends(zk.Widget,{ }, reScrollX : function(px){ jq('#ganttpanel_inner_scroller_x').width(px); - }, - /** - * Scrolls horizontally the ganttpanel when the zoom has resized the component - * width. - */ - scroll_horizontal: function(daysDisplacement) { - scrollDay = daysDisplacement; - }, - - // FIXME: this is quite awful, it should be simple - update_day_scroll: function(previousPixelPerDay) { - this._fromPixelToDay(previousPixelPerDay); - }, - move_scroll: function(diffDays, pixelPerDay) { - this._fromDayToPixel(diffDays,pixelPerDay); - }, - _fromPixelToDay: function(previousPixelPerDay) { - var div1 = document.getElementById ("ganttpanel").parentNode; - var div2 = div1.parentNode; - var div3 = div2.parentNode; - - var maxHPosition = div3.scrollWidth - div3.clientWidth; - if( maxHPosition > 0 ){ - var proportion = div3.scrollWidth / maxHPosition; - var positionInScroll = div3.scrollLeft; - var positionInPx = positionInScroll * proportion; - if(positionInPx > 0){ - var position = positionInPx / previousPixelPerDay; - var day = position; - this.scrollDay = position; - } - } - }, - _fromDayToPixel: function(diffDays,pixelPerDay) { - var div1 = document.getElementById ("ganttpanel").parentNode; - var div2 = div1.parentNode; - var div3 = div2.parentNode; - - var day = this.scrollDay; - day += parseInt(diffDays); - var newPosInPx = parseInt(day * pixelPerDay); - var maxHPosition = div3.scrollWidth - div3.clientWidth; - var newProportion = div3.scrollWidth / maxHPosition; - if( newProportion > 0){ - var newPosInScroll = newPosInPx / newProportion; - if(newPosInScroll < 0){ - newPosInScroll = 0; - } - div1.scrollLeft = newPosInScroll; - div2.scrollLeft = newPosInScroll; - div3.scrollLeft = newPosInScroll; - } } - },{ getInstance : function(){ return this._instance; diff --git a/ganttzk/src/main/resources/web/js/ganttz/resourceload/ResourceLoadList.js b/ganttzk/src/main/resources/web/js/ganttz/resourceload/ResourceLoadList.js index 7c7751e71..fb77b8b0b 100644 --- a/ganttzk/src/main/resources/web/js/ganttz/resourceload/ResourceLoadList.js +++ b/ganttzk/src/main/resources/web/js/ganttz/resourceload/ResourceLoadList.js @@ -4,6 +4,7 @@ ganttz.resourceload.ResourceLoadList = zk.$extends(zk.Widget,{ $init : function(){ this.$supers('$init', arguments); this.$class.setInstance(this); + common.Common.mixInDayPositionRestorer(this); }, bind_ : function(evt){ this.$supers('bind_', arguments); @@ -15,6 +16,10 @@ ganttz.resourceload.ResourceLoadList = zk.$extends(zk.Widget,{ this.domUnlisten_(jq('.rightpanellayout div:first'), 'onScroll', '_listenToScroll'); this.$supers('unbind_', arguments); }, + _divsToRestoreDayInto: function() { + var first = this.$n(); + return [first, first.parentNode, first.parentNode.parentNode]; + }, recalculateTimeTrackerHeight : function(){ var DOMResourceLoadList = jq('.resourceloadlist'); var DOMfirstWatermarkColumn = jq('.rightpanellayout tr#watermark td :first');