| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/kernel", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/_base/array", |
| 6 |
"dojo/_base/event", |
| 7 |
"dojo/_base/connect", |
| 8 |
"dojo/dom-style", |
| 9 |
"dojo/dom-class", |
| 10 |
"dojo/dom-construct", |
| 11 |
"dojo/fx", |
| 12 |
"dijit/registry", |
| 13 |
"dijit/TitlePane", |
| 14 |
"dijit/_Container", |
| 15 |
"./PortletSettings", |
| 16 |
"./PortletDialogSettings" |
| 17 |
], function(declare, kernel, lang, array, event, connect, domStyle, domClass, domConstruct, fx, registry, |
| 18 |
TitlePane, _Container, PortletSettings, PortletDialogSettings){ |
| 19 |
|
| 20 |
kernel.experimental("dojox.widget.Portlet"); |
| 21 |
|
| 22 |
return declare("dojox.widget.Portlet", [TitlePane, _Container],{ |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
resizeChildren: true, |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
closable: true, |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
_parents: null, |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
_size: null, |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
dragRestriction : false, |
| 59 |
|
| 60 |
buildRendering: function(){ |
| 61 |
this.inherited(arguments); |
| 62 |
|
| 63 |
|
| 64 |
domStyle.set(this.domNode, "visibility", "hidden"); |
| 65 |
}, |
| 66 |
|
| 67 |
postCreate: function(){ |
| 68 |
this.inherited(arguments); |
| 69 |
|
| 70 |
|
| 71 |
domClass.add(this.domNode, "dojoxPortlet"); |
| 72 |
domClass.remove(this.arrowNode, "dijitArrowNode"); |
| 73 |
domClass.add(this.arrowNode, "dojoxPortletIcon dojoxArrowDown"); |
| 74 |
domClass.add(this.titleBarNode, "dojoxPortletTitle"); |
| 75 |
domClass.add(this.hideNode, "dojoxPortletContentOuter"); |
| 76 |
|
| 77 |
|
| 78 |
domClass.add(this.domNode, "dojoxPortlet-" + (!this.dragRestriction ? "movable" : "nonmovable")); |
| 79 |
|
| 80 |
var _this = this; |
| 81 |
if(this.resizeChildren){ |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
this.subscribe("/dnd/drop", function(){_this._updateSize();}); |
| 87 |
|
| 88 |
this.subscribe("/Portlet/sizechange", function(widget){_this.onSizeChange(widget);}); |
| 89 |
this.connect(window, "onresize", function(){_this._updateSize();}); |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
var doSelectSubscribe = lang.hitch(this, function(id, lastId){ |
| 94 |
var widget = registry.byId(id); |
| 95 |
if(widget.selectChild){ |
| 96 |
var s = this.subscribe(id + "-selectChild", function(child){ |
| 97 |
var n = _this.domNode.parentNode; |
| 98 |
|
| 99 |
while(n){ |
| 100 |
if(n == child.domNode){ |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
_this.unsubscribe(s); |
| 105 |
_this._updateSize(); |
| 106 |
break; |
| 107 |
} |
| 108 |
n = n.parentNode; |
| 109 |
} |
| 110 |
}); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
var child = registry.byId(lastId); |
| 116 |
if(widget && child){ |
| 117 |
_this._parents.push({parent: widget, child: child}); |
| 118 |
} |
| 119 |
} |
| 120 |
}); |
| 121 |
var lastId; |
| 122 |
this._parents = []; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
for(var p = this.domNode.parentNode; p != null; p = p.parentNode){ |
| 127 |
var id = p.getAttribute ? p.getAttribute("widgetId") : null; |
| 128 |
if(id){ |
| 129 |
doSelectSubscribe(id, lastId); |
| 130 |
lastId = id; |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
this.connect(this.titleBarNode, "onmousedown", function(evt){ |
| 137 |
if (domClass.contains(evt.target, "dojoxPortletIcon")) { |
| 138 |
event.stop(evt); |
| 139 |
return false; |
| 140 |
} |
| 141 |
return true; |
| 142 |
}); |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
this.connect(this._wipeOut, "onEnd", function(){_this._publish();}); |
| 147 |
this.connect(this._wipeIn, "onEnd", function(){_this._publish();}); |
| 148 |
|
| 149 |
if(this.closable){ |
| 150 |
this.closeIcon = this._createIcon("dojoxCloseNode", "dojoxCloseNodeHover", lang.hitch(this, "onClose")); |
| 151 |
domStyle.set(this.closeIcon, "display", ""); |
| 152 |
} |
| 153 |
}, |
| 154 |
|
| 155 |
startup: function(){ |
| 156 |
if(this._started){return;} |
| 157 |
|
| 158 |
var children = this.getChildren(); |
| 159 |
this._placeSettingsWidgets(); |
| 160 |
|
| 161 |
|
| 162 |
array.forEach(children, function(child){ |
| 163 |
try{ |
| 164 |
if(!child.started && !child._started){ |
| 165 |
child.startup() |
| 166 |
} |
| 167 |
} |
| 168 |
catch(e){ |
| 169 |
console.log(this.id + ":" + this.declaredClass, e); |
| 170 |
} |
| 171 |
}); |
| 172 |
|
| 173 |
this.inherited(arguments); |
| 174 |
|
| 175 |
|
| 176 |
domStyle.set(this.domNode, "visibility", "visible"); |
| 177 |
}, |
| 178 |
|
| 179 |
_placeSettingsWidgets: function(){ |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
array.forEach(this.getChildren(), lang.hitch(this, function(child){ |
| 187 |
if(child.portletIconClass && child.toggle && !child.get("portlet")){ |
| 188 |
this._createIcon(child.portletIconClass, child.portletIconHoverClass, lang.hitch(child, "toggle")); |
| 189 |
domConstruct.place(child.domNode, this.containerNode, "before"); |
| 190 |
child.set("portlet", this); |
| 191 |
this._settingsWidget = child; |
| 192 |
} |
| 193 |
})); |
| 194 |
}, |
| 195 |
|
| 196 |
_createIcon: function(clazz, hoverClazz, fn){ |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
var icon = domConstruct.create("div",{ |
| 201 |
"class": "dojoxPortletIcon " + clazz, |
| 202 |
"waiRole": "presentation" |
| 203 |
}); |
| 204 |
domConstruct.place(icon, this.arrowNode, "before"); |
| 205 |
|
| 206 |
this.connect(icon, "onclick", fn); |
| 207 |
|
| 208 |
if(hoverClazz){ |
| 209 |
this.connect(icon, "onmouseover", function(){ |
| 210 |
domClass.add(icon, hoverClazz); |
| 211 |
}); |
| 212 |
this.connect(icon, "onmouseout", function(){ |
| 213 |
domClass.remove(icon, hoverClazz); |
| 214 |
}); |
| 215 |
} |
| 216 |
return icon; |
| 217 |
}, |
| 218 |
|
| 219 |
onClose: function(evt){ |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
domStyle.set(this.domNode, "display", "none"); |
| 226 |
}, |
| 227 |
|
| 228 |
onSizeChange: function(widget){ |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
if(widget == this){ |
| 233 |
return; |
| 234 |
} |
| 235 |
this._updateSize(); |
| 236 |
}, |
| 237 |
|
| 238 |
_updateSize: function(){ |
| 239 |
|
| 240 |
|
| 241 |
if(!this.open || !this._started || !this.resizeChildren){ |
| 242 |
return; |
| 243 |
} |
| 244 |
|
| 245 |
if(this._timer){ |
| 246 |
clearTimeout(this._timer); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
this._timer = setTimeout(lang.hitch(this, function(){ |
| 251 |
var size ={ |
| 252 |
w: domStyle.get(this.domNode, "width"), |
| 253 |
h: domStyle.get(this.domNode, "height") |
| 254 |
}; |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
for(var i = 0; i < this._parents.length; i++){ |
| 260 |
var p = this._parents[i]; |
| 261 |
var sel = p.parent.selectedChildWidget |
| 262 |
if(sel && sel != p.child){ |
| 263 |
return; |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
if(this._size){ |
| 268 |
|
| 269 |
|
| 270 |
if(this._size.w == size.w && this._size.h == size.h){ |
| 271 |
return; |
| 272 |
} |
| 273 |
} |
| 274 |
this._size = size; |
| 275 |
|
| 276 |
var fns = ["resize", "layout"]; |
| 277 |
this._timer = null; |
| 278 |
var kids = this.getChildren(); |
| 279 |
|
| 280 |
array.forEach(kids, function(child){ |
| 281 |
for(var i = 0; i < fns.length; i++){ |
| 282 |
if(lang.isFunction(child[fns[i]])){ |
| 283 |
try{ |
| 284 |
child[fns[i]](); |
| 285 |
} catch(e){ |
| 286 |
console.log(e); |
| 287 |
} |
| 288 |
break; |
| 289 |
} |
| 290 |
} |
| 291 |
}); |
| 292 |
this.onUpdateSize(); |
| 293 |
}), 100); |
| 294 |
}, |
| 295 |
|
| 296 |
onUpdateSize: function(){ |
| 297 |
|
| 298 |
|
| 299 |
}, |
| 300 |
|
| 301 |
_publish: function(){ |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
connect.publish("/Portlet/sizechange",[this]); |
| 307 |
}, |
| 308 |
|
| 309 |
_onTitleClick: function(evt){ |
| 310 |
if(evt.target == this.arrowNode){ |
| 311 |
this.inherited(arguments); |
| 312 |
} |
| 313 |
}, |
| 314 |
|
| 315 |
addChild: function(child){ |
| 316 |
|
| 317 |
|
| 318 |
this._size = null; |
| 319 |
this.inherited(arguments); |
| 320 |
|
| 321 |
if(this._started){ |
| 322 |
this._placeSettingsWidgets(); |
| 323 |
this._updateSize(); |
| 324 |
} |
| 325 |
if(this._started && !child.started && !child._started){ |
| 326 |
child.startup(); |
| 327 |
} |
| 328 |
}, |
| 329 |
|
| 330 |
destroyDescendants: function( preserveDom){ |
| 331 |
this.inherited(arguments); |
| 332 |
if(this._settingsWidget){ |
| 333 |
this._settingsWidget.destroyRecursive(preserveDom); |
| 334 |
} |
| 335 |
}, |
| 336 |
|
| 337 |
destroy: function(){ |
| 338 |
if(this._timer){ |
| 339 |
clearTimeout(this._timer); |
| 340 |
} |
| 341 |
this.inherited(arguments); |
| 342 |
}, |
| 343 |
|
| 344 |
_setCss: function(){ |
| 345 |
this.inherited(arguments); |
| 346 |
domStyle.set(this.arrowNode, "display", this.toggleable ? "":"none"); |
| 347 |
} |
| 348 |
}); |
| 349 |
}); |