| 1 |
define(["dojo/_base/lang","dojo/_base/declare", "dojo/Deferred", "dojo/_base/array", "dojo/dom-construct", "dijit/registry", "dojox/app/Controller"], |
| 2 |
function(lang, declare, Deferred, array, domConstruct, registry, Controller){ |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
return declare("dojox/app/tests/layoutApp2/controllers/UnloadViewController", Controller, { |
| 11 |
|
| 12 |
constructor: function(app){ |
| 13 |
this.app = app; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
this.events = { |
| 22 |
"unload-view": this.unloadView |
| 23 |
}; |
| 24 |
}, |
| 25 |
|
| 26 |
unloadView: function(event){ |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
var parent = event.parent || this.app; |
| 39 |
var view = event.view || ""; |
| 40 |
var viewId = view.id; |
| 41 |
|
| 42 |
if(!parent || !view || !viewId){ |
| 43 |
console.warn("unload-view event for view with no parent or with an invalid view with view = ", view); |
| 44 |
return; |
| 45 |
} |
| 46 |
|
| 47 |
if(parent.selectedChildren[viewId]){ |
| 48 |
console.warn("unload-view event for a view which is still in use so it can not be unloaded for view id = " + viewId + "'."); |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
if(!parent.children[viewId]){ |
| 53 |
console.warn("unload-view event for a view which was not found in parent.children[viewId] for viewId = " + viewId + "'."); |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
this.unloadChild(parent, view); |
| 58 |
|
| 59 |
|
| 60 |
if(event.callback){ |
| 61 |
event.callback(); |
| 62 |
} |
| 63 |
}, |
| 64 |
|
| 65 |
unloadChild: function(parent, viewToUnload){ |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
for(var child in viewToUnload.children){ |
| 77 |
this.unloadChild(viewToUnload, child); |
| 78 |
} |
| 79 |
if(viewToUnload.domNode){ |
| 80 |
|
| 81 |
var widList = registry.findWidgets(viewToUnload.domNode); |
| 82 |
for(var wid in widList){ |
| 83 |
widList[wid].destroyRecursive(); |
| 84 |
} |
| 85 |
domConstruct.destroy(viewToUnload.domNode); |
| 86 |
} |
| 87 |
|
| 88 |
delete parent.children[viewToUnload.id]; |
| 89 |
if(viewToUnload.destroy){ |
| 90 |
viewToUnload.destroy(); |
| 91 |
} |
| 92 |
} |
| 93 |
}); |
| 94 |
}); |