1 /* 2 * Copyright (C) 2008-2009 WaveMaker Software, Inc. 3 * 4 * This file is part of the WaveMaker Client Runtime. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 dojo.provide("wm.base.components.NavigationService"); 19 dojo.require("wm.base.components.Service"); 20 21 /** 22 Service for client side navigation. 23 <br /><br /> 24 Navigation methods on this class are also 25 available as service operations where noted. 26 Service operation inputs match the 27 arguments on the related method, and so they 28 are not documented separately. 29 <br /> 30 @name wm.NavigationService 31 @class 32 @extends wm.Service 33 */ 34 dojo.declare("wm.NavigationService", wm.Service, { 35 /** @lends wm.NavigationService.prototype */ 36 layer: "", 37 layers: "", 38 operation: "", 39 _operations: { 40 gotoLayer: { 41 parameters: { 42 layer: { type: "wm.Layer"} 43 }, 44 returnType: "any", 45 hint: "This operations displays the selected layer." 46 }, 47 nextLayer: { 48 parameters: { 49 layers: { type: "wm.Layers"} 50 }, 51 returnType: "any", 52 hint: "The operation displays the next layer in the selected layers widget." 53 }, 54 previousLayer: { 55 parameters: { 56 layers: { type: "wm.Layers"} 57 }, 58 returnType: "any", 59 hint: "The operation displays the previous layer in the selected layers widget." 60 }, 61 gotoPage: { 62 parameters: { 63 pageName: { type: "string" } 64 }, 65 returnType: "any", 66 hint: "This operation displays a different page and requires a pageName." 67 }, 68 gotoPageContainerPage: { 69 parameters: { 70 pageName: { type: "string" }, 71 pageContainer: { type: "wm.PageContainer" } 72 }, 73 returnType: "any", 74 hint: "This operation displays a page in a pageContainer and requires both a pageContainer and a pageName." 75 }, 76 gotoDialogPage: { 77 parameters: { 78 pageName: {type: "string"}, 79 hideControls: {type: "boolean"}, 80 width: {type: "number"}, 81 height: {type: "number"} 82 }, 83 returnType: "any", 84 hint: "This operation displays a page in a dialog." 85 } 86 }, 87 update: function() { 88 this[this.operation || "gotoLayer"](); 89 }, 90 invoke: function(inMethod, inArgs) { 91 var 92 d = this._deferred = new dojo.Deferred(), 93 m = this[inMethod]; 94 if (m) { 95 m.apply(this, inArgs); 96 } else { 97 this.onError(); 98 d.errback("operation: " + inMethod + " does not exist."); 99 } 100 return d; 101 }, 102 doResult: function() { 103 if (this._resultConnect) { 104 dojo.disconnect(this._resultConnect); 105 this._resultConnect = null; 106 } 107 this.onResult(); 108 if (this._deferred && this._deferred.fired == -1) 109 this._deferred.callback(true); 110 this._deferred = null; 111 }, 112 /** 113 Shows a layer. 114 <br /><br /> 115 This method is available as a configurable operation on this service. 116 @param {wm.Layer} inLayer The layer to show. 117 */ 118 gotoLayer: function(inLayer) { 119 var l = inLayer instanceof wm.Layer ? inLayer : null; 120 if (l) 121 this.showLayer(l); 122 this.doResult(); 123 }, 124 /** 125 Show the next layer in a set of layers. 126 <br /><br /> 127 This method is available as a configurable operation on this service. 128 @param {wm.Layers} inLayers The set of layers to operate on. 129 */ 130 nextLayer: function(inLayers) { 131 var l = inLayers instanceof wm.Layers ? inLayers : null; 132 if (l) 133 l.setNext(); 134 this.doResult(); 135 }, 136 /** 137 Show the previous layer in a set of layers. 138 <br /><br /> 139 This method is available as a configurable operation on this service. 140 @param {wm.Layers} inLayers The set of layers to operate on. 141 */ 142 previousLayer: function(inLayers) { 143 var l = inLayers instanceof wm.Layers ? inLayers : null; 144 if (l) 145 l.setPrevious(); 146 this.doResult(); 147 }, 148 showLayer: function(inLayer) { 149 var l = inLayer; 150 while (l) { 151 wm.fire(l, "activate"); 152 l = l.parent; 153 } 154 }, 155 /** 156 Dynamically load and show a top level page. 157 <br /><br /> 158 This method is available as a configurable operation on this service. 159 @param {String} inPageName The page to load. 160 */ 161 gotoPage: function(inPageName) { 162 this._resultConnect = dojo.connect(app, "onPageChanged", this, "doResult"); 163 app.loadPage(inPageName); 164 }, 165 /** 166 Dynamically load and show a page inside of a page container. 167 <br /><br /> 168 This method is available as a configurable operation on this service. 169 @param {String} inPageName The page to load. 170 @param {wm.PageContainer} inPageContainer The page container that will contain the page. 171 */ 172 gotoPageContainerPage: function(inPageName, inPageContainer) { 173 if (inPageContainer) { 174 // note, pageContainer does not call onPageChanged unless a page actually changed 175 // to avoid confusion, we choose to process the navigation regardless 176 // so call doResult manually if the page will not change. 177 if (inPageName != inPageContainer.pageName) { 178 inPageContainer.setPageName(inPageName); 179 this._resultConnect = dojo.connect(inPageContainer, "onPageChanged", this, "doResult"); 180 } else 181 this.doResult(); 182 } else 183 wm.logging && console.debug("pageContainer not found", inPageContainer); 184 }, 185 /** 186 Dynamically load and show a page inside of dialog box. 187 <br /><br /> 188 This method is available as a configurable operation on this service. 189 @param {String} inPageName The page to load. 190 @param {Boolean} inHideControls Set true to hide the default dialog controls. 191 @param {Number} inWidth The width of the dialog content area in pixels. 192 @param {Number} inHeight The height of the dialog content area in pixels. 193 */ 194 gotoDialogPage: function(inPageName, inHideControls, inWidth, inHeight) { 195 this._resultConnect = dojo.connect(app.pageDialog, "onPageReady", this, "doResult"); 196 app.pageDialog.showPage(inPageName, inHideControls, inWidth, inHeight); 197 } 198 }); 199 200 wm.services.add({name: "navigationService", ctor: "wm.NavigationService", isClientService: true, clientHide: true}); 201