Debian Codegraph @

dojox/app/controllers/BorderLayout.js

raw symbols SCIP
1 define(["dojo/_base/declare", "dojo/dom-attr", "dojo/dom-style", "./LayoutBase","dijit/layout/BorderContainer",
2 "dijit/layout/StackContainer", "dijit/layout/ContentPane", "dijit/registry"],
3 function(declare, domAttr, domStyle, LayoutBase, BorderContainer, StackContainer, ContentPane, registry){
4 // module:
5 // dojox/app/controllers/BorderLayout
6 // summary:
7 // Will layout an application with a BorderContainer.
8 // Each view to be shown in a region of the BorderContainer will be wrapped in a StackContainer and a ContentPane.
9 //
10
11 return declare("dojox.app.controllers.BorderLayout", LayoutBase, {
12
13 initLayout: function(event){
14 // summary:
15 // Response to dojox/app "app-initLayout" event which is setup in LayoutBase.
16 // The initLayout event is called once when the View is being created the first time.
17 //
18 // example:
19 // Use emit to trigger "app-initLayout" event, and this function will respond to the event. For example:
20 // | this.app.emit("app-initLayout", view);
21 //
22 // event: Object
23 // | {"view": view, "callback": function(){}};
24 this.app.log("in app/controllers/BorderLayout.initLayout event.view.name=[",event.view.name,"] event.view.parent.name=[",event.view.parent.name,"]");
25
26 var bc;
27 if(!this.borderLayoutCreated){ // If the BorderContainer has not been created yet, create it.
28 this.borderLayoutCreated = true;
29 bc = new BorderContainer({id:this.app.id+"-BC", style: "height:100%;width:100%;border:1px solid black"});
30 event.view.parent.domNode.appendChild(bc.domNode); // put the border container into the parent (app)
31
32 bc.startup(); // startup the BorderContainer
33 }else{
34 bc = registry.byId(this.app.id+"-BC");
35 }
36
37 this.app.log("in app/controllers/BorderLayout.initLayout event.view.constraint=",event.view.constraint);
38 var constraint = event.view.constraint; // constraint holds the region for this view, center, top etc.
39
40 if(event.view.parent.id == this.app.id){ // If the parent of this view is the app we are working with the BorderContainer
41 var reg = registry.byId(event.view.parent.id+"-"+constraint);
42 if(reg){ // already has a stackContainer, just create the contentPane for this view and add it to the stackContainer.
43 var cp1 = registry.byId(event.view.id+"-cp-"+constraint);
44 if(!cp1){
45 cp1 = new ContentPane({id:event.view.id+"-cp-"+constraint});
46 cp1.addChild(event.view); // important to add the widget to the cp before adding cp to BorderContainer for height
47 reg.addChild(cp1);
48 bc.addChild(reg);
49 }else{
50 cp1.domNode.appendChild(event.view.domNode);
51 }
52 }else{ // need a contentPane
53 // this is where the region (constraint) is set for the BorderContainer's StackContainer
54 var noSplitter = this.app.borderLayoutNoSplitter || false;
55 var sc1 = new StackContainer({doLayout: true, splitter:!noSplitter, region:constraint, id:event.view.parent.id+"-"+constraint});
56 var cp1 = new ContentPane({id:event.view.id+"-cp-"+constraint});
57 cp1.addChild(event.view); // should we use addChild or appendChild?
58 sc1.addChild(cp1);
59 bc.addChild(sc1);
60 }
61 }else{ // Not a top level page transition, so not changing a page in the BorderContainer, so handle it like Layout.
62 event.view.parent.domNode.appendChild(event.view.domNode);
63 domAttr.set(event.view.domNode, "data-app-constraint", event.view.constraint);
64 }
65
66 this.inherited(arguments);
67 },
68
69 hideView: function(view){
70 var bc = registry.byId(this.app.id+"-BC");
71 var sc = registry.byId(view.parent.id+"-"+view.constraint);
72 if(bc && sc){
73 sc.removedFromBc = true;
74 bc.removeChild(sc);
75 }
76 },
77
78 showView: function(view){
79 var sc = registry.byId(view.parent.id+"-"+view.constraint);
80 var cp = registry.byId(view.id+"-cp-"+view.constraint);
81 if(sc && cp){
82 if(sc.removedFromBc){
83 sc.removedFromBc = false;
84 registry.byId(this.app.id+"-BC").addChild(sc);
85 domStyle.set(view.domNode, "display", "");
86 }
87 domStyle.set(cp.domNode, "display", "");
88 sc.selectChild(cp);
89 sc.resize();
90 }
91 }
92 });
93 });