]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/Application.js
1 /* ************************************************************************
7 Authors: Charles du Jeu
9 ************************************************************************ */
11 /* ************************************************************************
15 ************************************************************************ */
18 * This is the main application class of an Argeo RIA.
20 qx
.Class
.define("org.argeo.ria.Application",
22 extend
: qx
.application
.Standalone
,
30 * Available perspective detected in the current compilation.
37 * Currently layouted perspective label
39 activePerspectiveName
: {
44 * Currently layouted perspective.
50 * Basic command associated to the application, applicable to all perspectives.
52 commandsDefinitions
: {
56 icon
: "resource/slc/process-stop.png",
57 shortcut
: "Control+s",
61 callback : function(e
){},
64 "switchperspective" : {
65 label
: "Switch Perspective",
66 icon
: "resource/slc/view-pane-tree.png",
72 submenuCallback : function(commandId
){
73 // Defer execution to assure that the submenu is closed
74 // before it is rebuilt.
75 qx
.event
.Timer
.once(function(){
76 org
.argeo
.ria
.Application
.INSTANCE
.loadPerspective(commandId
);
79 callback : function(e
){},
83 label
: "Show Console",
84 icon
: "resource/slc/help-contents.png",
90 callback : function(e
){
91 org
.argeo
.ria
.components
.Logger
.getInstance().toggle();
97 icon
: "resource/slc/help-about.png",
98 shortcut
: "Control+h",
102 callback : function(e
){
103 var win
= new org
.argeo
.ria
.components
.Modal("About SLC", null, "SLC is a product from Argeo.");
115 * This method contains the initial application code and gets called
116 * during startup of the application
121 this.base(arguments
);
122 this.self(arguments
).INSTANCE
= this;
125 var viewsManager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
126 viewsManager
.setApplicationRoot(this.getRoot());
130 qx.bom.Event.addNativeListener(window, "unload", function(){
131 // TODO : Close perspective if one is open.
132 if(appli.getActivePerspective()){
133 alert(appli.getActivePerspective());
134 appli.getActivePerspective().remove(org.argeo.ria.components.ViewsManager.getInstance());
138 // Enable logging in debug variant
139 if (qx
.core
.Variant
.isSet("qx.debug", "on"))
141 qx
.log
.appender
.Native
;
142 qx
.log
.appender
.Console
;
144 var winLogger
= org
.argeo
.ria
.components
.Logger
.getInstance();
145 this.getRoot().add(winLogger
);
146 qx
.log
.Logger
.register(winLogger
);
149 var layout
= new qx
.ui
.layout
.VBox();
150 var container
= new qx
.ui
.container
.Composite(layout
);
151 viewsManager
.setViewPanesContainer(container
);
152 // Document is the application root
153 this.getRoot().add(container
, {left
:0,right
:0,top
:0,bottom
:0});
155 // Find available perspectives
156 var allPerspectives
= {};
157 for(var key
in qx
.Bootstrap
.$$registry
){
158 if(qx
.Class
.hasInterface(qx
.Bootstrap
.$$registry
[key
], org
.argeo
.ria
.components
.IPerspective
)){
159 allPerspectives
[key
] = qx
.Bootstrap
.$$registry
[key
];
162 var perspectiveNumber
= qx
.lang
.Object
.getLength(allPerspectives
);
163 if(!perspectiveNumber
){
164 this.error("Cannot find a perspective for startup!");
167 this.setPerspectives(allPerspectives
);
168 // Choose startup perspective, delete switch menu if only one perspective.
169 if(perspectiveNumber
<= 1){
170 delete this.getCommandsDefinitions()["switchperspective"];
171 this.setActivePerspectiveName(qx
.lang
.Object
.getKeys(allPerspectives
)[0]);
176 startupSetting
= qx
.core
.Setting
.get("ria.StartupPerspective");
178 if(startupSetting
&& allPerspectives
[startupSetting
]){
179 this.setActivePerspectiveName(startupSetting
);
181 this.setActivePerspectiveName(qx
.lang
.Object
.getKeys(allPerspectives
)[0]);
183 this.rebuildPerspectiveMenus();
186 var menuBar
= new qx
.ui
.menubar
.MenuBar();
187 var toolbar
= new qx
.ui
.toolbar
.ToolBar();
188 var commandManager
= org
.argeo
.ria
.event
.CommandsManager
.getInstance();
189 commandManager
.init(this.getCommandsDefinitions());
190 commandManager
.createCommands();
191 commandManager
.registerMenuBar(menuBar
);
192 commandManager
.registerToolBar(toolbar
);
193 toolbar
.setShow("both");
194 commandManager
.addToolbarContextMenu(toolbar
);
196 var stopCommand
= commandManager
.getCommandById("stop");
197 var serviceManager
= org
.argeo
.ria
.remote
.RequestManager
.getInstance();
198 serviceManager
.setStopCommand(stopCommand
);
200 container
.add(menuBar
);
201 container
.add(toolbar
);
203 this.loadPerspective();
207 * Load a given perspective by its name.
208 * @param perspectiveName {String} Perspective to load
210 loadPerspective : function(perspectiveName
){
212 this.setActivePerspectiveName(perspectiveName
);
213 this.rebuildPerspectiveMenus();
215 perspectiveName
= this.getActivePerspectiveName();
217 var viewsManager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
218 if(this.getActivePerspective()){
219 this.getActivePerspective().remove(viewsManager
);
221 var allPerspectives
= this.getPerspectives();
222 var perspectiveClass
= allPerspectives
[perspectiveName
];
223 if(!perspectiveClass
){
224 this.error("Cannot find class for startup perspective : "+perspectiveName
);
227 var perspective
= new perspectiveClass
;
228 perspective
.initViewPanes(viewsManager
);
229 perspective
.initViews(viewsManager
);
230 this.setActivePerspective(perspective
);
234 * After switching perspective, call this function to rebuild menu with the right selected.
236 rebuildPerspectiveMenus : function(){
237 var switchCommand
= this.getCommandsDefinitions()["switchperspective"];
238 switchCommand
.submenu
= [];
239 var allPerspectives
= this.getPerspectives();
240 for(var key
in allPerspectives
){
241 switchCommand
.submenu
.push({
242 "label":(allPerspectives
[key
].LABEL
|| key
)+(key
==this.getActivePerspectiveName()?" (current)":""),
243 "icon" :(allPerspectives
[key
].ICON
|| null),
245 "disabled" : (key
==this.getActivePerspectiveName()?true:false)
248 if(switchCommand
.command
){ // Command already created : force reload
249 switchCommand
.command
.clearMenus();
250 switchCommand
.command
.setMenu(switchCommand
.submenu
);
255 * Specific action of calling an external URL without triggering the "close()" method
257 * @param hrefValue {String} A download url that should reply with specific "attachment" header to avoid leaving the application.
259 javascriptDownloadLocation: function(hrefValue
){
260 this.interruptClose
= true;
261 document
.location
.href
= hrefValue
;
262 this.interruptClose
= false;
266 * Called at Application ending (closing the browser).
269 if(this.interruptClose
) return ;
270 if(this.getActivePerspective()){
271 this.getActivePerspective().remove(org
.argeo
.ria
.components
.ViewsManager
.getInstance());
273 this.base(arguments
);