| 1 |
define(["require", "dojo/_base/lang", "dojo/_base/declare", "dojo/has", "dojo/on", "dojo/Deferred", "dojo/when", |
| 2 |
"dojo/dom-style", "../Controller", "../utils/constraints"], |
| 3 |
function(require, lang, declare, has, on, Deferred, when, domStyle, Controller, constraints){ |
| 4 |
|
| 5 |
var transit; |
| 6 |
var MODULE = "app/controllers/Transition"; |
| 7 |
var LOGKEY = "logTransitions:"; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
return declare("dojox.app.controllers.Transition", Controller, { |
| 14 |
|
| 15 |
proceeding: false, |
| 16 |
|
| 17 |
waitingQueue:[], |
| 18 |
|
| 19 |
constructor: function(app, events){ |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
this.events = { |
| 28 |
"app-transition": this.transition, |
| 29 |
"app-domNode": this.onDomNodeChange |
| 30 |
}; |
| 31 |
require([this.app.transit || "dojox/css3/transit"], function(t){ |
| 32 |
transit = t; |
| 33 |
}); |
| 34 |
if(this.app.domNode){ |
| 35 |
this.onDomNodeChange({oldNode: null, newNode: this.app.domNode}); |
| 36 |
} |
| 37 |
}, |
| 38 |
|
| 39 |
transition: function(event){ |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
var F = MODULE+":transition"; |
| 50 |
this.app.log(LOGKEY,F," "); |
| 51 |
this.app.log(LOGKEY,F,"New Transition event.viewId=["+event.viewId+"]"); |
| 52 |
this.app.log(F,"event.viewId=["+event.viewId+"]","event.opts=",event.opts); |
| 53 |
|
| 54 |
var viewsId = event.viewId || ""; |
| 55 |
this.proceedingSaved = this.proceeding; |
| 56 |
var parts = viewsId.split('+'); |
| 57 |
var removePartsTest = viewsId.split('-'); |
| 58 |
var viewId, newEvent; |
| 59 |
if(parts.length > 0 || removePartsTest.length > 0){ |
| 60 |
while(parts.length > 1){ |
| 61 |
viewId = parts.shift(); |
| 62 |
newEvent = lang.clone(event); |
| 63 |
if(viewId.indexOf("-") >= 0){ |
| 64 |
var removeParts = viewId.split('-'); |
| 65 |
if(removeParts.length > 0){ |
| 66 |
viewId = removeParts.shift(); |
| 67 |
if(viewId){ |
| 68 |
newEvent._removeView = false; |
| 69 |
newEvent.viewId = viewId; |
| 70 |
this.proceeding = true; |
| 71 |
this.proceedTransition(newEvent); |
| 72 |
newEvent = lang.clone(event); |
| 73 |
} |
| 74 |
viewId = removeParts.shift(); |
| 75 |
if(viewId){ |
| 76 |
newEvent._removeView = true; |
| 77 |
newEvent.viewId = viewId; |
| 78 |
this.proceeding = true; |
| 79 |
this.proceedTransition(newEvent); |
| 80 |
} |
| 81 |
} |
| 82 |
}else{ |
| 83 |
newEvent._removeView = false; |
| 84 |
newEvent.viewId = viewId; |
| 85 |
this.proceeding = true; |
| 86 |
this.proceedTransition(newEvent); |
| 87 |
} |
| 88 |
} |
| 89 |
viewId = parts.shift(); |
| 90 |
var removeParts = viewId.split('-'); |
| 91 |
if(removeParts.length > 0){ |
| 92 |
viewId = removeParts.shift(); |
| 93 |
} |
| 94 |
if(viewId.length > 0){ |
| 95 |
this.proceeding = this.proceedingSaved; |
| 96 |
event.viewId = viewId; |
| 97 |
event._doResize = true; |
| 98 |
event._removeView = false; |
| 99 |
this.proceedTransition(event); |
| 100 |
} |
| 101 |
if(removeParts.length > 0){ |
| 102 |
while(removeParts.length > 0){ |
| 103 |
var remViewId = removeParts.shift(); |
| 104 |
newEvent = lang.clone(event); |
| 105 |
newEvent.viewId = remViewId; |
| 106 |
newEvent._removeView = true; |
| 107 |
newEvent._doResize = true; |
| 108 |
this.proceedTransition(newEvent); |
| 109 |
} |
| 110 |
} |
| 111 |
}else{ |
| 112 |
event._doResize = true; |
| 113 |
event._removeView = false; |
| 114 |
this.proceedTransition(event); |
| 115 |
} |
| 116 |
}, |
| 117 |
|
| 118 |
onDomNodeChange: function(evt){ |
| 119 |
if(evt.oldNode != null){ |
| 120 |
this.unbind(evt.oldNode, "startTransition"); |
| 121 |
} |
| 122 |
this.bind(evt.newNode, "startTransition", lang.hitch(this, this.onStartTransition)); |
| 123 |
}, |
| 124 |
|
| 125 |
onStartTransition: function(evt){ |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
if(evt.preventDefault){ |
| 145 |
evt.preventDefault(); |
| 146 |
} |
| 147 |
evt.cancelBubble = true; |
| 148 |
if(evt.stopPropagation){ |
| 149 |
evt.stopPropagation(); |
| 150 |
} |
| 151 |
|
| 152 |
var target = evt.detail.target; |
| 153 |
var regex = /#(.+)/; |
| 154 |
if(!target && regex.test(evt.detail.href)){ |
| 155 |
target = evt.detail.href.match(regex)[1]; |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
this.transition({ "viewId":target, opts: lang.mixin({}, evt.detail), data: evt.detail.data }); |
| 160 |
}, |
| 161 |
|
| 162 |
_addTransitionEventToWaitingQueue: function(transitionEvt){ |
| 163 |
if(transitionEvt.defaultView && this.waitingQueue.length > 0){ |
| 164 |
var addedEvt = false; |
| 165 |
for(var i = 0; i < this.waitingQueue.length; i++){ |
| 166 |
var evt = this.waitingQueue[i]; |
| 167 |
if(!evt.defaultView){ |
| 168 |
this.waitingQueue.splice(i,0,transitionEvt); |
| 169 |
addedEvt = true; |
| 170 |
break; |
| 171 |
} |
| 172 |
} |
| 173 |
if(!addedEvt){ |
| 174 |
this.waitingQueue.push(transitionEvt); |
| 175 |
} |
| 176 |
}else{ |
| 177 |
this.waitingQueue.push(transitionEvt); |
| 178 |
} |
| 179 |
}, |
| 180 |
proceedTransition: function(transitionEvt){ |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
var F = MODULE+":proceedTransition"; |
| 188 |
|
| 189 |
if(this.proceeding){ |
| 190 |
this._addTransitionEventToWaitingQueue(transitionEvt); |
| 191 |
this.app.log(F+" added this event to waitingQueue", transitionEvt); |
| 192 |
this.processingQueue = false; |
| 193 |
return; |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
this.app.log(F+" this.waitingQueue.length ="+ this.waitingQueue.length+ " this.processingQueue="+this.processingQueue); |
| 198 |
if(this.waitingQueue.length > 0 && !this.processingQueue){ |
| 199 |
this.processingQueue = true; |
| 200 |
this._addTransitionEventToWaitingQueue(transitionEvt); |
| 201 |
this.app.log(F+" added this event to waitingQueue passed proceeding", transitionEvt); |
| 202 |
transitionEvt = this.waitingQueue.shift(); |
| 203 |
this.app.log(F+" shifted waitingQueue to process", transitionEvt); |
| 204 |
} |
| 205 |
|
| 206 |
this.proceeding = true; |
| 207 |
|
| 208 |
this.app.log(F+" calling trigger load", transitionEvt); |
| 209 |
if(!transitionEvt.opts){ |
| 210 |
transitionEvt.opts = {}; |
| 211 |
} |
| 212 |
var params = transitionEvt.params || transitionEvt.opts.params; |
| 213 |
this.app.emit("app-load", { |
| 214 |
"viewId": transitionEvt.viewId, |
| 215 |
"params": params, |
| 216 |
"forceTransitionNone": transitionEvt.forceTransitionNone, |
| 217 |
"callback": lang.hitch(this, function(needToHandleDefaultView, defaultHasPlus){ |
| 218 |
if(needToHandleDefaultView){ |
| 219 |
this.proceeding = false; |
| 220 |
this.processingQueue = true; |
| 221 |
|
| 222 |
|
| 223 |
var nextEvt = (defaultHasPlus) ? this.waitingQueue.shift() : this.waitingQueue.pop(); |
| 224 |
if(nextEvt){ |
| 225 |
this.proceedTransition(nextEvt); |
| 226 |
} |
| 227 |
}else{ |
| 228 |
var transitionDef = this._doTransition(transitionEvt.viewId, transitionEvt.opts, params, transitionEvt.opts.data, this.app, transitionEvt._removeView, transitionEvt._doResize, transitionEvt.forceTransitionNone); |
| 229 |
when(transitionDef, lang.hitch(this, function(){ |
| 230 |
this.proceeding = false; |
| 231 |
this.processingQueue = true; |
| 232 |
var nextEvt = this.waitingQueue.shift(); |
| 233 |
if(nextEvt){ |
| 234 |
this.proceedTransition(nextEvt); |
| 235 |
} |
| 236 |
})); |
| 237 |
} |
| 238 |
}) |
| 239 |
}); |
| 240 |
}, |
| 241 |
|
| 242 |
_getTransition: function(nextView, parent, transitionTo, opts, forceTransitionNone){ |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
if(forceTransitionNone){ |
| 260 |
return "none"; |
| 261 |
} |
| 262 |
var parentView = parent; |
| 263 |
var transition = null; |
| 264 |
if(nextView){ |
| 265 |
transition = nextView.transition; |
| 266 |
} |
| 267 |
if(!transition && parentView.views[transitionTo]){ |
| 268 |
transition = parentView.views[transitionTo].transition; |
| 269 |
} |
| 270 |
if(!transition){ |
| 271 |
transition = parentView.transition; |
| 272 |
} |
| 273 |
var defaultTransition = (nextView && nextView.defaultTransition) ? nextView.defaultTransition : parentView.defaultTransition; |
| 274 |
while(!transition && parentView.parent){ |
| 275 |
parentView = parentView.parent; |
| 276 |
transition = parentView.transition; |
| 277 |
if(!defaultTransition){ |
| 278 |
defaultTransition = parentView.defaultTransition; |
| 279 |
} |
| 280 |
} |
| 281 |
return transition || opts.transition || defaultTransition || "none"; |
| 282 |
}, |
| 283 |
|
| 284 |
|
| 285 |
_getParamsForView: function(view, params){ |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
var viewParams = {}; |
| 297 |
for(var item in params){ |
| 298 |
var value = params[item]; |
| 299 |
if(lang.isObject(value)){ |
| 300 |
if(item == view){ |
| 301 |
|
| 302 |
viewParams = lang.mixin(viewParams, value); |
| 303 |
} |
| 304 |
}else{ |
| 305 |
if(item && value != null){ |
| 306 |
viewParams[item] = params[item]; |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
return viewParams; |
| 311 |
}, |
| 312 |
|
| 313 |
_doTransition: function(transitionTo, opts, params, data, parent, removeView, doResize, forceTransitionNone, nested){ |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
var F = MODULE+":_doTransition"; |
| 342 |
|
| 343 |
if(!parent){ |
| 344 |
throw Error("view parent not found in transition."); |
| 345 |
} |
| 346 |
|
| 347 |
this.app.log(F+" transitionTo=[",transitionTo,"], removeView=[",removeView,"] parent.name=[",parent.name,"], opts=",opts); |
| 348 |
|
| 349 |
var parts, toId, subIds, next; |
| 350 |
if(transitionTo){ |
| 351 |
parts = transitionTo.split(","); |
| 352 |
}else{ |
| 353 |
|
| 354 |
|
| 355 |
parts = parent.defaultView.split(","); |
| 356 |
} |
| 357 |
toId = parts.shift(); |
| 358 |
subIds = parts.join(','); |
| 359 |
|
| 360 |
|
| 361 |
next = parent.children[parent.id + '_' + toId]; |
| 362 |
if(!next){ |
| 363 |
if(removeView){ |
| 364 |
this.app.log(F+" called with removeView true, but that view is not available to remove"); |
| 365 |
return; |
| 366 |
} |
| 367 |
throw Error("child view must be loaded before transition."); |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
if(!subIds && next.defaultView){ |
| 372 |
subIds = next.defaultView; |
| 373 |
} |
| 374 |
|
| 375 |
var nextSubViewArray = [next || parent]; |
| 376 |
if(subIds){ |
| 377 |
nextSubViewArray = this._getNextSubViewArray(subIds, next, parent); |
| 378 |
} |
| 379 |
|
| 380 |
var current = constraints.getSelectedChild(parent, next.constraint); |
| 381 |
var currentSubViewArray = this._getCurrentSubViewArray(parent, nextSubViewArray, removeView); |
| 382 |
|
| 383 |
var currentSubNames = this._getNamesFromArray(currentSubViewArray, false); |
| 384 |
var nextSubNames = this._getNamesFromArray(nextSubViewArray, true); |
| 385 |
|
| 386 |
|
| 387 |
next.params = this._getParamsForView(next.name, params); |
| 388 |
|
| 389 |
if(removeView){ |
| 390 |
if(next !== current){ |
| 391 |
this.app.log(F+" called with removeView true, but that view is not available to remove"); |
| 392 |
return; |
| 393 |
} |
| 394 |
this.app.log(LOGKEY,F,"Transition Remove current From=["+currentSubNames+"]"); |
| 395 |
|
| 396 |
next = null; |
| 397 |
} |
| 398 |
|
| 399 |
if(nextSubNames == currentSubNames && next == current){ |
| 400 |
this.app.log(LOGKEY,F,"Transition current and next DO MATCH From=["+currentSubNames+"] TO=["+nextSubNames+"]"); |
| 401 |
this._handleMatchingViews(nextSubViewArray, next, current, parent, data, removeView, doResize, subIds, currentSubNames, toId, forceTransitionNone, opts); |
| 402 |
|
| 403 |
}else{ |
| 404 |
this.app.log(LOGKEY,F,"Transition current and next DO NOT MATCH From=["+currentSubNames+"] TO=["+nextSubNames+"]"); |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
if(!removeView && next){ |
| 420 |
var nextLastSubChild = this.nextLastSubChildMatch || next; |
| 421 |
var startHiding = false; |
| 422 |
for(var i = nextSubViewArray.length-1; i >= 0; i--){ |
| 423 |
var v = nextSubViewArray[i]; |
| 424 |
if(startHiding || v.id == nextLastSubChild.id){ |
| 425 |
startHiding = true; |
| 426 |
if(!v._needsResize && v.domNode){ |
| 427 |
this.app.log(LOGKEY,F," setting domStyle visibility hidden for v.id=["+v.id+"], display=["+v.domNode.style.display+"], visibility=["+v.domNode.style.visibility+"]"); |
| 428 |
this._setViewVisible(v, false); |
| 429 |
} |
| 430 |
} |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
if(current && current._active){ |
| 435 |
this._handleBeforeDeactivateCalls(currentSubViewArray, this.nextLastSubChildMatch || next, current, data, subIds); |
| 436 |
} |
| 437 |
if(next){ |
| 438 |
this.app.log(F+" calling _handleBeforeActivateCalls next name=[",next.name,"], parent.name=[",next.parent.name,"]"); |
| 439 |
this._handleBeforeActivateCalls(nextSubViewArray, this.currentLastSubChildMatch || current, data, subIds); |
| 440 |
} |
| 441 |
if(!removeView){ |
| 442 |
var nextLastSubChild = this.nextLastSubChildMatch || next; |
| 443 |
var trans = this._getTransition(nextLastSubChild, parent, toId, opts, forceTransitionNone) |
| 444 |
this.app.log(F+" calling _handleLayoutAndResizeCalls trans="+trans); |
| 445 |
this._handleLayoutAndResizeCalls(nextSubViewArray, removeView, doResize, subIds, forceTransitionNone, trans); |
| 446 |
}else{ |
| 447 |
|
| 448 |
for(var i = 0; i < nextSubViewArray.length; i++){ |
| 449 |
var v = nextSubViewArray[i]; |
| 450 |
this.app.log(LOGKEY,F,"setting visibility visible for v.id=["+v.id+"]"); |
| 451 |
if(v.domNode){ |
| 452 |
this.app.log(LOGKEY,F," setting domStyle for removeView visibility visible for v.id=["+v.id+"], display=["+v.domNode.style.display+"]"); |
| 453 |
this._setViewVisible(v, true); |
| 454 |
} |
| 455 |
} |
| 456 |
} |
| 457 |
var result = true; |
| 458 |
|
| 459 |
|
| 460 |
if(transit && (!nested || this.currentLastSubChildMatch != null) && this.currentLastSubChildMatch !== next){ |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
result = this._handleTransit(next, parent, this.currentLastSubChildMatch, opts, toId, removeView, forceTransitionNone, doResize); |
| 465 |
} |
| 466 |
when(result, lang.hitch(this, function(){ |
| 467 |
if(next){ |
| 468 |
this.app.log(F+" back from transit for next ="+next.name); |
| 469 |
} |
| 470 |
if(removeView){ |
| 471 |
var nextLastSubChild = this.nextLastSubChildMatch || next; |
| 472 |
var trans = this._getTransition(nextLastSubChild, parent, toId, opts, forceTransitionNone) |
| 473 |
this._handleLayoutAndResizeCalls(nextSubViewArray, removeView, doResize, subIds, forceTransitionNone, trans); |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
this._handleAfterDeactivateCalls(currentSubViewArray, this.nextLastSubChildMatch || next, current, data, subIds); |
| 478 |
this._handleAfterActivateCalls(nextSubViewArray, removeView, this.currentLastSubChildMatch || current, data, subIds); |
| 479 |
})); |
| 480 |
return result; |
| 481 |
} |
| 482 |
}, |
| 483 |
|
| 484 |
_handleMatchingViews: function(subs, next, current, parent, data, removeView, doResize, subIds, currentSubNames, toId, forceTransitionNone, opts){ |
| 485 |
|
| 486 |
|
| 487 |
var F = MODULE+":_handleMatchingViews"; |
| 488 |
|
| 489 |
this._handleBeforeDeactivateCalls(subs, this.nextLastSubChildMatch || next, current, data, subIds); |
| 490 |
|
| 491 |
|
| 492 |
this._handleAfterDeactivateCalls(subs, this.nextLastSubChildMatch || next, current, data, subIds); |
| 493 |
this._handleBeforeActivateCalls(subs, this.currentLastSubChildMatch || current, data, subIds); |
| 494 |
var nextLastSubChild = this.nextLastSubChildMatch || next; |
| 495 |
var trans = this._getTransition(nextLastSubChild, parent, toId, opts, forceTransitionNone) |
| 496 |
this._handleLayoutAndResizeCalls(subs, removeView, doResize, subIds, trans); |
| 497 |
this._handleAfterActivateCalls(subs, removeView, this.currentLastSubChildMatch || current, data, subIds); |
| 498 |
}, |
| 499 |
|
| 500 |
_handleBeforeDeactivateCalls: function(subs, next, current, data, subIds){ |
| 501 |
|
| 502 |
|
| 503 |
var F = MODULE+":_handleBeforeDeactivateCalls"; |
| 504 |
if(current._active){ |
| 505 |
|
| 506 |
for(var i = subs.length-1; i >= 0; i--){ |
| 507 |
var v = subs[i]; |
| 508 |
if(v && v.beforeDeactivate && v._active){ |
| 509 |
this.app.log(LOGKEY,F,"beforeDeactivate for v.id="+v.id); |
| 510 |
v.beforeDeactivate(next, data); |
| 511 |
} |
| 512 |
} |
| 513 |
} |
| 514 |
}, |
| 515 |
|
| 516 |
_handleAfterDeactivateCalls: function(subs, next, current, data, subIds){ |
| 517 |
|
| 518 |
|
| 519 |
var F = MODULE+":_handleAfterDeactivateCalls"; |
| 520 |
if(current && current._active){ |
| 521 |
|
| 522 |
for(var i = 0; i < subs.length; i++){ |
| 523 |
var v = subs[i]; |
| 524 |
if(v && v.beforeDeactivate && v._active){ |
| 525 |
this.app.log(LOGKEY,F,"afterDeactivate for v.id="+v.id); |
| 526 |
v.afterDeactivate(next, data); |
| 527 |
v._active = false; |
| 528 |
} |
| 529 |
} |
| 530 |
|
| 531 |
} |
| 532 |
}, |
| 533 |
|
| 534 |
_handleBeforeActivateCalls: function(subs, current, data, subIds){ |
| 535 |
|
| 536 |
|
| 537 |
var F = MODULE+":_handleBeforeActivateCalls"; |
| 538 |
|
| 539 |
for(var i = subs.length-1; i >= 0; i--){ |
| 540 |
var v = subs[i]; |
| 541 |
this.app.log(LOGKEY,F,"beforeActivate for v.id="+v.id); |
| 542 |
v.beforeActivate(current, data); |
| 543 |
} |
| 544 |
}, |
| 545 |
|
| 546 |
_handleLayoutAndResizeCalls: function(subs, removeView, doResize, subIds, forceTransitionNone, transition){ |
| 547 |
|
| 548 |
|
| 549 |
var F = MODULE+":_handleLayoutAndResizeCalls"; |
| 550 |
var remove = removeView; |
| 551 |
for(var i = 0; i < subs.length; i++){ |
| 552 |
var v = subs[i]; |
| 553 |
this.app.log(LOGKEY,F,"emit layoutView v.id=["+v.id+"] removeView=["+remove+"]"); |
| 554 |
|
| 555 |
this.app.emit("app-layoutView", {"parent": v.parent, "view": v, "removeView": remove, "doResize": false, "transition": transition, "currentLastSubChildMatch": this.currentLastSubChildMatch}); |
| 556 |
remove = false; |
| 557 |
} |
| 558 |
if(doResize){ |
| 559 |
this.app.log(LOGKEY,F,"emit doResize called"); |
| 560 |
this.app.emit("app-resize"); |
| 561 |
if(transition == "none"){ |
| 562 |
this._showSelectedChildren(this.app); |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
}, |
| 567 |
|
| 568 |
_showSelectedChildren: function(w){ |
| 569 |
var F = MODULE+":_showSelectedChildren"; |
| 570 |
this.app.log(LOGKEY,F," setting domStyle visibility visible for w.id=["+w.id+"], display=["+w.domNode.style.display+"], visibility=["+w.domNode.style.visibility+"]"); |
| 571 |
this._setViewVisible(w, true); |
| 572 |
w._needsResize = false; |
| 573 |
for(var hash in w.selectedChildren){ |
| 574 |
if(w.selectedChildren[hash] && w.selectedChildren[hash].domNode){ |
| 575 |
this.app.log(LOGKEY,F," calling _showSelectedChildren for w.selectedChildren[hash].id="+w.selectedChildren[hash].id); |
| 576 |
this._showSelectedChildren(w.selectedChildren[hash]); |
| 577 |
} |
| 578 |
} |
| 579 |
}, |
| 580 |
|
| 581 |
_setViewVisible: function(v, visible){ |
| 582 |
if(visible){ |
| 583 |
domStyle.set(v.domNode, "visibility", "visible"); |
| 584 |
}else{ |
| 585 |
domStyle.set(v.domNode, "visibility", "hidden"); |
| 586 |
} |
| 587 |
}, |
| 588 |
|
| 589 |
|
| 590 |
_handleAfterActivateCalls: function(subs, removeView, current, data, subIds){ |
| 591 |
|
| 592 |
|
| 593 |
var F = MODULE+":_handleAfterActivateCalls"; |
| 594 |
|
| 595 |
var startInt = 0; |
| 596 |
if(removeView && subs.length > 1){ |
| 597 |
startInt = 1; |
| 598 |
} |
| 599 |
for(var i = startInt; i < subs.length; i++){ |
| 600 |
var v = subs[i]; |
| 601 |
if(v.afterActivate){ |
| 602 |
this.app.log(LOGKEY,F,"afterActivate for v.id="+v.id); |
| 603 |
v.afterActivate(current, data); |
| 604 |
v._active = true; |
| 605 |
} |
| 606 |
} |
| 607 |
}, |
| 608 |
|
| 609 |
_getNextSubViewArray: function(subIds, next, parent){ |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
var F = MODULE+":_getNextSubViewArray"; |
| 623 |
var parts = []; |
| 624 |
var p = next || parent; |
| 625 |
if(subIds){ |
| 626 |
parts = subIds.split(","); |
| 627 |
} |
| 628 |
var nextSubViewArray = [p]; |
| 629 |
|
| 630 |
for(var i = 0; i < parts.length; i++){ |
| 631 |
toId = parts[i]; |
| 632 |
var v = p.children[p.id + '_' + toId]; |
| 633 |
if(v){ |
| 634 |
nextSubViewArray.push(v); |
| 635 |
p = v; |
| 636 |
} |
| 637 |
} |
| 638 |
nextSubViewArray.reverse(); |
| 639 |
return nextSubViewArray; |
| 640 |
}, |
| 641 |
|
| 642 |
_getCurrentSubViewArray: function(parent, nextSubViewArray, removeView){ |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
var F = MODULE+":_getCurrentSubViewArray"; |
| 654 |
var currentSubViewArray = []; |
| 655 |
var constraint, type, hash; |
| 656 |
var p = parent; |
| 657 |
this.currentLastSubChildMatch = null; |
| 658 |
this.nextLastSubChildMatch = null; |
| 659 |
|
| 660 |
for(var i = nextSubViewArray.length-1; i >= 0; i--){ |
| 661 |
constraint = nextSubViewArray[i].constraint; |
| 662 |
type = typeof(constraint); |
| 663 |
hash = (type == "string" || type == "number") ? constraint : constraint.__hash; |
| 664 |
|
| 665 |
if(p && p.selectedChildren && p.selectedChildren[hash]){ |
| 666 |
if(p.selectedChildren[hash] == nextSubViewArray[i]){ |
| 667 |
this.currentLastSubChildMatch = p.selectedChildren[hash]; |
| 668 |
this.nextLastSubChildMatch = nextSubViewArray[i]; |
| 669 |
currentSubViewArray.push(this.currentLastSubChildMatch); |
| 670 |
p = this.currentLastSubChildMatch; |
| 671 |
}else{ |
| 672 |
this.currentLastSubChildMatch = p.selectedChildren[hash]; |
| 673 |
currentSubViewArray.push(this.currentLastSubChildMatch); |
| 674 |
this.nextLastSubChildMatch = nextSubViewArray[i]; |
| 675 |
|
| 676 |
if(!removeView){ |
| 677 |
var selChildren = constraints.getAllSelectedChildren(this.currentLastSubChildMatch); |
| 678 |
currentSubViewArray = currentSubViewArray.concat(selChildren); |
| 679 |
} |
| 680 |
break; |
| 681 |
} |
| 682 |
}else{ |
| 683 |
this.currentLastSubChildMatch = null; |
| 684 |
this.nextLastSubChildMatch = nextSubViewArray[i]; |
| 685 |
break; |
| 686 |
} |
| 687 |
|
| 688 |
} |
| 689 |
|
| 690 |
if(removeView){ |
| 691 |
var selChildren = constraints.getAllSelectedChildren(p); |
| 692 |
currentSubViewArray = currentSubViewArray.concat(selChildren); |
| 693 |
} |
| 694 |
|
| 695 |
return currentSubViewArray; |
| 696 |
}, |
| 697 |
|
| 698 |
_getNamesFromArray: function(subViewArray, backward){ |
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
var F = MODULE+":_getNamesFromArray"; |
| 711 |
var subViewNames = ""; |
| 712 |
if(backward){ |
| 713 |
for (var i = subViewArray.length - 1; i >= 0; i--) { |
| 714 |
subViewNames = subViewNames ? subViewNames+","+subViewArray[i].name : subViewArray[i].name; |
| 715 |
} |
| 716 |
}else{ |
| 717 |
for(var i = 0; i < subViewArray.length; i++){ |
| 718 |
subViewNames = subViewNames ? subViewNames+","+subViewArray[i].name : subViewArray[i].name; |
| 719 |
} |
| 720 |
} |
| 721 |
return subViewNames; |
| 722 |
}, |
| 723 |
|
| 724 |
_handleTransit: function(next, parent, currentLastSubChild, opts, toId, removeView, forceTransitionNone, resizeDone){ |
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
var F = MODULE+":_handleTransit"; |
| 748 |
|
| 749 |
var nextLastSubChild = this.nextLastSubChildMatch || next; |
| 750 |
|
| 751 |
var mergedOpts = lang.mixin({}, opts); |
| 752 |
mergedOpts = lang.mixin({}, mergedOpts, { |
| 753 |
reverse: (mergedOpts.reverse || mergedOpts.transitionDir === -1)?true:false, |
| 754 |
|
| 755 |
transition: this._getTransition(nextLastSubChild, parent, toId, mergedOpts, forceTransitionNone) |
| 756 |
}); |
| 757 |
|
| 758 |
if(removeView){ |
| 759 |
nextLastSubChild = null; |
| 760 |
} |
| 761 |
if(currentLastSubChild){ |
| 762 |
this.app.log(LOGKEY,F,"transit FROM currentLastSubChild.id=["+currentLastSubChild.id+"]"); |
| 763 |
} |
| 764 |
if(nextLastSubChild){ |
| 765 |
if(mergedOpts.transition !== "none"){ |
| 766 |
if(!resizeDone && nextLastSubChild._needsResize){ |
| 767 |
this.app.log(LOGKEY,F,"emit doResize called from _handleTransit"); |
| 768 |
this.app.emit("app-resize"); |
| 769 |
} |
| 770 |
this.app.log(LOGKEY,F," calling _showSelectedChildren for w3.id=["+nextLastSubChild.id+"], display=["+nextLastSubChild.domNode.style.display+"], visibility=["+nextLastSubChild.domNode.style.visibility+"]"); |
| 771 |
this._showSelectedChildren(this.app); |
| 772 |
} |
| 773 |
this.app.log(LOGKEY,F,"transit TO nextLastSubChild.id=["+nextLastSubChild.id+"] transition=["+mergedOpts.transition+"]"); |
| 774 |
}else{ |
| 775 |
this._showSelectedChildren(this.app); |
| 776 |
} |
| 777 |
return transit(currentLastSubChild && currentLastSubChild.domNode, nextLastSubChild && nextLastSubChild.domNode, mergedOpts); |
| 778 |
} |
| 779 |
|
| 780 |
}); |
| 781 |
}); |