1// (c) Copyright Microsoft Corporation. 2// This source is subject to the Microsoft Permissive License. 3// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. 4// All other rights reserved. 5 6 7/// <reference name="MicrosoftAjax.debug.js" /> 8/// <reference name="MicrosoftAjaxTimer.debug.js" /> 9/// <reference name="MicrosoftAjaxWebForms.debug.js" /> 10/// <reference path="../ExtenderBase/BaseScripts.js" /> 11/// <reference path="../Common/Common.js" /> 12 13 14Type.registerNamespace('AjaxControlToolkit'); 15 16AjaxControlToolkit.DynamicPopulateBehavior = function(element) { 17 /// <summary> 18 /// The DynamicPopulateBehavior replaces the contents of an element with the result of a web service or page method call. The method call returns a string of HTML that is inserted as the children of the target element. 19 /// </summary> 20 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 21 /// DOM Element the behavior is associated with 22 /// </param> 23 AjaxControlToolkit.DynamicPopulateBehavior.initializeBase(this, [element]); 24 25 this._servicePath = null; 26 this._serviceMethod = null; 27 this._contextKey = null; 28 this._cacheDynamicResults = false; 29 this._populateTriggerID = null; 30 this._setUpdatingCssClass = null; 31 this._clearDuringUpdate = true; 32 this._customScript = null; 33 34 this._clickHandler = null; 35 36 this._callID = 0; 37 this._currentCallID = -1; 38 39 // Whether or not we've already populated (used for cacheDynamicResults) 40 this._populated = false; 41} 42AjaxControlToolkit.DynamicPopulateBehavior.prototype = { 43 initialize : function() { 44 /// <summary> 45 /// Initialize the behavior 46 /// </summary> 47 AjaxControlToolkit.DynamicPopulateBehavior.callBaseMethod(this, 'initialize'); 48 $common.prepareHiddenElementForATDeviceUpdate(); 49 50 // hook up the trigger if we have one. 51 if (this._populateTriggerID) { 52 var populateTrigger = $get(this._populateTriggerID); 53 if (populateTrigger) { 54 this._clickHandler = Function.createDelegate(this, this._onPopulateTriggerClick); 55 $addHandler(populateTrigger, "click", this._clickHandler); 56 } 57 } 58 }, 59 60 dispose : function() { 61 /// <summary> 62 /// Dispose the behavior 63 /// </summary> 64 65 // clean up the trigger event. 66 if (this._populateTriggerID && this._clickHandler) { 67 var populateTrigger = $get(this._populateTriggerID); 68 if (populateTrigger) { 69 $removeHandler(populateTrigger, "click", this._clickHandler); 70 } 71 this._populateTriggerID = null; 72 this._clickHandler = null; 73 } 74 75 AjaxControlToolkit.DynamicPopulateBehavior.callBaseMethod(this, 'dispose'); 76 }, 77 78 populate : function(contextKey) { 79 /// <summary> 80 /// Get the dymanic content and use it to populate the target element 81 /// </summary> 82 /// <param name="contextKey" type="String" mayBeNull="true" optional="true"> 83 /// An arbitrary string value to be passed to the web method. For example, if the element to be 84 /// populated is within a data-bound repeater, this could be the ID of the current row. 85 /// </param> 86 87 // Don't populate if we already cached the results 88 if (this._populated && this._cacheDynamicResults) { 89 return; 90 } 91 92 // Initialize the population if this is the very first call 93 if (this._currentCallID == -1) { 94 var eventArgs = new Sys.CancelEventArgs(); 95 this.raisePopulating(eventArgs); 96 if (eventArgs.get_cancel()) { 97 return; 98 } 99 this._setUpdating(true); 100 } 101 102 // Either run the custom population script or invoke the web service 103 if (this._customScript) { 104 // Call custom javascript call to populate control 105 var scriptResult = eval(this._customScript);
106 this.get_element().innerHTML = scriptResult; 107 this._setUpdating(false); 108 } else { 109 this._currentCallID = ++this._callID; 110 if (this._servicePath && this._serviceMethod) { 111 Sys.Net.WebServiceProxy.invoke(this._servicePath, this._serviceMethod, false, 112 { contextKey:(contextKey ? contextKey : this._contextKey) }, 113 Function.createDelegate(this, this._onMethodComplete), Function.createDelegate(this, this._onMethodError), 114 this._currentCallID); 115 $common.updateFormToRefreshATDeviceBuffer(); 116 } 117 } 118 }, 119 120 _onMethodComplete : function (result, userContext, methodName) { 121 /// <summary> 122 /// Callback used when the populating service returns successfully 123 /// </summary> 124 /// <param name="result" type="Object" mayBeNull=""> 125 /// The data returned from the Web service method call 126 /// </param> 127 /// <param name="userContext" type="Object"> 128 /// The context information that was passed when the Web service method was invoked 129 /// </param> 130 /// <param name="methodName" type="String"> 131 /// The Web service method that was invoked 132 /// </param> 133 134 // ignore if it's not the current call. 135 if (userContext != this._currentCallID) return; 136 137 // Time has passed; make sure the element is still accessible 138 var e = this.get_element(); 139 if (e) { 140 e.innerHTML = result; 141 } 142 143 this._setUpdating(false); 144 }, 145 146 _onMethodError : function(webServiceError, userContext, methodName) { 147 /// <summary> 148 /// Callback used when the populating service fails 149 /// </summary> 150 /// <param name="webServiceError" type="Sys.Net.WebServiceError"> 151 /// Web service error 152 /// </param> 153 /// <param name="userContext" type="Object"> 154 /// The context information that was passed when the Web service method was invoked 155 /// </param> 156 /// <param name="methodName" type="String"> 157 /// The Web service method that was invoked 158 /// </param> 159 160 // ignore if it's not the current call. 161 if (userContext != this._currentCallID) return; 162 163 var e = this.get_element(); 164 if (e) { 165 if (webServiceError.get_timedOut()) { 166 e.innerHTML = AjaxControlToolkit.Resources.DynamicPopulate_WebServiceTimeout; 167 } else { 168 e.innerHTML = String.format(AjaxControlToolkit.Resources.DynamicPopulate_WebServiceError, webServiceError.get_statusCode()); 169 } 170 } 171 172 this._setUpdating(false); 173 }, 174 175 _onPopulateTriggerClick : function() { 176 /// <summary> 177 /// Handler for the element described by PopulateTriggerID's click event 178 /// </summary> 179 180 // just call through to the trigger. 181 this.populate(this._contextKey); 182 }, 183 184 _setUpdating : function(updating) { 185 /// <summary> 186 /// Toggle the display elements to indicate if they are being updated or not 187 /// </summary> 188 /// <param name="updating" type="Boolean"> 189 /// Whether or not the display should indicated it is being updated 190 /// </param> 191 192 this.setStyle(updating); 193 194 if (!updating) { 195 this._currentCallID = -1; 196 this._populated = true; 197 this.raisePopulated(this, Sys.EventArgs.Empty); 198 } 199 }, 200 201 setStyle : function(updating) { 202 /// <summary> 203 /// Set the style of the display 204 /// </summary> 205 /// <param name="updating" type="Boolean"> 206 /// Whether or not the display is being updated 207 /// </param> 208 209 var e = this.get_element(); 210 if (this._setUpdatingCssClass) { 211 if (!updating) { 212 e.className = this._oldCss; 213 this._oldCss = null; 214 } else { 215 this._oldCss = e.className; 216 e.className = this._setUpdatingCssClass; 217 } 218 } 219 220 if (updating && this._clearDuringUpdate) { 221 e.innerHTML = ""; 222 } 223 }, 224 225 get_ClearContentsDuringUpdate : function() { 226 /// <value type="Boolean"> 227 /// Whether the contents of the target should be cleared when an update begins 228 /// </value> 229 return this._clearDuringUpdate; 230 }, 231 set_ClearContentsDuringUpdate : function(value) { 232 if (this._clearDuringUpdate != value) { 233 this._clearDuringUpdate = value; 234 this.raisePropertyChanged('ClearContentsDuringUpdate'); 235 } 236 }, 237 238 get_ContextKey : function() { 239 /// <value type="String"> 240 /// An arbitrary string value to be passed to the web method. 241 /// For example, if the element to be populated is within a 242 /// data-bound repeater, this could be the ID of the current row. 243 /// </value> 244 return this._contextKey; 245 }, 246 set_ContextKey : function(value) { 247 if (this._contextKey != value) { 248 this._contextKey = value; 249 this.raisePropertyChanged('ContextKey'); 250 } 251 }, 252 253 get_PopulateTriggerID : function() { 254 /// <value type="String" mayBeNull="true" optional="true"> 255 /// Name of an element that triggers the population of the target when clicked 256 /// </value> 257 return this._populateTriggerID; 258 }, 259 set_PopulateTriggerID : function(value) { 260 if (this._populateTriggerID != value) { 261 this._populateTriggerID = value; 262 this.raisePropertyChanged('PopulateTriggerID'); 263 } 264 }, 265
266 get_ServicePath : function() { 267 /// <value type="String" mayBeNull="true" optional="true"> 268 /// The URL of the web service to call. If the ServicePath is not defined, then we will invoke a PageMethod instead of a web service. 269 /// </value> 270 return this._servicePath; 271 }, 272 set_ServicePath : function(value) { 273 if (this._servicePath != value) { 274 this._servicePath = value; 275 this.raisePropertyChanged('ServicePath'); 276 } 277 }, 278 279 get_ServiceMethod : function() { 280 /// <value type="String"> 281 /// The name of the method to call on the page or web service 282 /// </value> 283 /// <remarks> 284 /// The signature of the method must exactly match the following: 285 /// [WebMethod] 286 /// string DynamicPopulateMethod(string contextKey) 287 /// { 288 /// ... 289 /// } 290 /// </remarks> 291 return this._serviceMethod; 292 }, 293 set_ServiceMethod : function(value) { 294 if (this._serviceMethod != value) { 295 this._serviceMethod = value; 296 this.raisePropertyChanged('ServiceMethod'); 297 } 298 }, 299 300 get_cacheDynamicResults : function() { 301 /// <value type="Boolean" mayBeNull="false"> 302 /// Whether the results of the dynamic population should be cached and 303 /// not fetched again after the first load 304 /// </value> 305 return this._cacheDynamicResults; 306 }, 307 set_cacheDynamicResults : function(value) { 308 if (this._cacheDynamicResults != value) { 309 this._cacheDynamicResults = value; 310 this.raisePropertyChanged('cacheDynamicResults'); 311 } 312 }, 313 314 get_UpdatingCssClass : function() { 315 /// <value type="String"> 316 /// The CSS class to apply to the target during asynchronous calls 317 /// </value> 318 return this._setUpdatingCssClass; 319 }, 320 set_UpdatingCssClass : function(value) { 321 if (this._setUpdatingCssClass != value) { 322 this._setUpdatingCssClass = value; 323 this.raisePropertyChanged('UpdatingCssClass'); 324 } 325 }, 326 327 get_CustomScript : function() { 328 /// <value type="String"> 329 /// The script to invoke instead of calling a Web or Page method. This script must evaluate to a string value. 330 /// </value> 331 return this._customScript; 332 }, 333 set_CustomScript : function(value) { 334 if (this._customScript != value) { 335 this._customScript = value; 336 this.raisePropertyChanged('CustomScript'); 337 } 338 }, 339 340 add_populating : function(handler) { 341 /// <summary> 342 /// Add an event handler for the populating event 343 /// </summary> 344 /// <param name="handler" type="Function" mayBeNull="false"> 345 /// Event handler 346 /// </param> 347 /// <returns /> 348 this.get_events().addHandler('populating', handler); 349 }, 350 remove_populating : function(handler) { 351 /// <summary> 352 /// Remove an event handler from the populating event 353 /// </summary> 354 /// <param name="handler" type="Function" mayBeNull="false"> 355 /// Event handler 356 /// </param> 357 /// <returns /> 358 this.get_events().removeHandler('populating', handler); 359 }, 360 raisePopulating : function(eventArgs) { 361 /// <summary> 362 /// Raise the populating event 363 /// </summary> 364 /// <param name="eventArgs" type="Sys.CancelEventArgs" mayBeNull="false"> 365 /// Event arguments for the populating event 366 /// </param> 367 /// <returns /> 368 369 var handler = this.get_events().getHandler('populating'); 370 if (handler) { 371 handler(this, eventArgs); 372 } 373 }, 374 375 add_populated : function(handler) { 376 /// <summary> 377 /// Add an event handler for the populated event 378 /// </summary> 379 /// <param name="handler" type="Function" mayBeNull="false"> 380 /// Event handler 381 /// </param> 382 /// <returns /> 383 this.get_events().addHandler('populated', handler); 384 }, 385 remove_populated : function(handler) { 386 /// <summary> 387 /// Remove an event handler from the populated event 388 /// </summary> 389 /// <param name="handler" type="Function" mayBeNull="false"> 390 /// Event handler 391 /// </param> 392 /// <returns /> 393 this.get_events().removeHandler('populated', handler); 394 },
395 raisePopulated : function(eventArgs) { 396 /// <summary> 397 /// Raise the populated event 398 /// </summary> 399 /// <param name="eventArgs" type="Sys.EventArgs" mayBeNull="false"> 400 /// Event arguments for the populated event 401 /// </param> 402 /// <returns /> 403 404 var handler = this.get_events().getHandler('populated'); 405 if (handler) { 406 handler(this, eventArgs); 407 } 408 } 409} 410AjaxControlToolkit.DynamicPopulateBehavior.registerClass('AjaxControlToolkit.DynamicPopulateBehavior', AjaxControlToolkit.BehaviorBase); 411 412if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.