Skip to content

Commit

Permalink
Fixed #100 make sure that column view is not crashing if top row is e…
Browse files Browse the repository at this point in the history
…xpanded if no item is displayed in it.
  • Loading branch information
Damien Garbarino committed Jul 28, 2014
1 parent cdb25bb commit 1b5f2c6
Showing 1 changed file with 58 additions and 35 deletions.
93 changes: 58 additions & 35 deletions ColumnViewSecondarySheet.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,65 @@
define(["./MatrixView", "dojo/text!./templates/ColumnViewSecondarySheet.html",
"dojo/_base/html", "dojo/_base/declare", "dojo/_base/event", "dojo/_base/lang",
"dojo/_base/sniff", "dojo/dom", "dojo/dom-class", "dojo/dom-geometry", "dojo/dom-construct",
"dojo/date", "dojo/date/locale", "dojo/query", "dojox/html/metrics", "dojo/_base/fx", "dojo/on",
"dojo/window"],

function(MatrixView, template, html, declare, event, lang, has, dom, domClass, domGeometry, domConstruct,
date, locale, query, metrics, fx, on, win){

define([
"dojo/_base/array",
"dojo/_base/declare",
"dojo/_base/event",
"dojo/_base/lang",
"dojo/dom-geometry",
"dojo/dom-style",
"dojox/calendar/MatrixView",
"dojo/text!./templates/ColumnViewSecondarySheet.html"],

function(arr,
declare,
event,
lang,
domGeometry,
domStyle,
MatrixView,
template){

return declare("dojox.calendar.ColumnViewSecondarySheet", MatrixView, {

// summary:
// This class defines a matrix view designed to be embedded in a column view,
// usually to display long or all day events on one row.
// This class defines a matrix view designed to be embedded in a column view,
// usually to display long or all day events on one row.

templateString: template,

rowCount: 1,

cellPaddingTop: 4,

roundToDay: false,

_defaultHeight: -1,

layoutDuringResize: true,

_defaultItemToRendererKindFunc: function(item){
// tags:
// private
return item.allDay ? "horizontal" : null;
},

_formatGridCellLabel: function(){return null;},

_formatRowHeaderLabel: function(){return null;},


// events redispatch
__fixEvt:function(e){
e.sheet = "secondary";
e.source = this;
return e;
},

_dispatchCalendarEvt: function(e, name){
e = this.inherited(arguments);
if(this.owner.owner){ // the calendar
this.owner.owner[name](e);
}
},

_layoutExpandRenderers: function(index, hasHiddenItems, hiddenItems){
if(!this.expandRenderer){
return;
Expand All @@ -58,13 +68,19 @@ define(["./MatrixView", "dojo/text!./templates/ColumnViewSecondarySheet.html",
if(this._defaultHeight == -1){
this._defaultHeight = h;
}
if(this._defaultHeight != -1 && this._defaultHeight != h && h >= this._getExpandedHeight()){
this._layoutExpandRendererImpl(0, this._expandedRowCol, null, true);

if(this._defaultHeight != -1 && this._defaultHeight != h && h >= this._getExpandedHeight() ||
this._expandedRowCol !== undefined && this._expandedRowCol !== -1){
var col = this._expandedRowCol;
if(col >= this.renderData.columnCount){
col = 0;
}
this._layoutExpandRendererImpl(0, col, null, true);
}else{
this.inherited(arguments);
}
},

expandRendererClickHandler: function(e, renderer){
// summary:
// Default action when an expand renderer is clicked.
Expand All @@ -76,29 +92,36 @@ define(["./MatrixView", "dojo/text!./templates/ColumnViewSecondarySheet.html",
// tags:
// callback


event.stop(e);
var h = domGeometry.getMarginBox(this.domNode).h;
if(this._defaultHeight == h || h < this._getExpandedHeight()){

var h = domGeometry.getMarginBox(this.domNode).h;
var expandedH = this._getExpandedHeight();
if(this._defaultHeight == h || h < expandedH){
this._expandedRowCol = renderer.columnIndex;
this.owner.resizeSecondarySheet(this._getExpandedHeight());
this.owner.resizeSecondarySheet(expandedH);
}else{
delete this._expandedRowCol;
this.owner.resizeSecondarySheet(this._defaultHeight);
}
},

_getExpandedHeight: function(){
// tags:
// private

return this.naturalRowsHeight[0] + this.expandRendererHeight + this.verticalGap + this.verticalGap;
return (this.naturalRowsHeight && this.naturalRowsHeight.length > 0 ? this.naturalRowsHeight[0] : 0) +
this.expandRendererHeight + this.verticalGap + this.verticalGap;
},

_layoutRenderers: function(renderData){
if(!this._domReady){
if(!this._domReady){
return;
}
this.inherited(arguments);
// make sure to show the expand/collapse renderer if no item is displayed but the row was expanded.
if(!renderData.items || renderData.items.length === 0){
this._layoutExpandRenderers(0, false, null);
}
}

});
Expand Down

0 comments on commit 1b5f2c6

Please sign in to comment.