1// Name: CascadingDropDown.CascadingDropDownBehavior.debug.js 2// Assembly: AjaxControlToolkit 3// Version: 4.5.7.1005 4// FileVersion: 4.5.7.1005 5// (c) 2010 CodePlex Foundation 6 7 8 9/// <reference name="MicrosoftAjax.debug.js" /> 10/// <reference path="../ExtenderBase/BaseScripts.js" /> 11/// <reference path="../Common/Common.js" /> 12 13(function () { 14 var scriptName = "ExtendedCascadingDropDown"; 15 16 function execute() { 17 18 Type.registerNamespace('Sys.Extended.UI'); 19 20 Sys.Extended.UI.CascadingDropDownSelectionChangedEventArgs = function (oldValue, newValue) { 21 /// <summary> 22 /// Event arguments used when the selectionChanged event is raised 23 /// </summary> 24 /// <param name="oldValue" type="String" mayBeNull="true"> 25 /// Previous selection 26 /// </param> 27 /// <param name="newValue" type="String" mayBeNull="true"> 28 /// New selection 29 /// </param> 30 Sys.Extended.UI.CascadingDropDownSelectionChangedEventArgs.initializeBase(this); 31 32 this._oldValue = oldValue; 33 this._newValue = newValue; 34 } 35 Sys.Extended.UI.CascadingDropDownSelectionChangedEventArgs.prototype = { 36 get_oldValue: function () { 37 /// <value type="String" mayBeNull="true"> 38 /// Previous selection 39 /// </value> 40 return this._oldValue; 41 }, 42 43 get_newValue: function () { 44 /// <value type="String" mayBeNull="true"> 45 /// New selection 46 /// </value> 47 return this._newValue; 48 } 49 } 50 Sys.Extended.UI.CascadingDropDownSelectionChangedEventArgs.registerClass('Sys.Extended.UI.CascadingDropDownSelectionChangedEventArgs', Sys.EventArgs); 51 52 Sys.Extended.UI.CascadingDropDownBehavior = function (e) { 53 /// <summary> 54 /// The CascadingDropDownBehavior is used to populate drop downs with values from a web service 55 /// </summary> 56 /// <param name="e" type="Sys.UI.DomElement" domElement="true"> 57 /// The DOM element the behavior is associated with 58 /// </param> 59 Sys.Extended.UI.CascadingDropDownBehavior.initializeBase(this, [e]); 60 61 this._parentControlID = null; 62 this._category = null; 63 this._promptText = null; 64 this._loadingText = null; 65 this._promptValue = null; 66 this._emptyValue = null; 67 this._emptyText = null; 68 69 this._servicePath = location.pathname; 70 71 this._serviceMethod = null; 72 73 this._contextKey = null; 74 75 this._useContextKey = false; 76 77 this._useHttpGet = false; 78 79 this._enableAtLoading = false; 80 81 this._parentElement = null; 82 this._changeHandler = null; 83 this._parentChangeHandler = null; 84 this._lastParentValues = null; 85 this._selectedValue = null; 86 this._actualDisabledStatus = false; 87 } 88 Sys.Extended.UI.CascadingDropDownBehavior.prototype = { 89 initialize: function () { 90 /// <summary> 91 /// Initialize the behavior 92 /// </summary> 93 /// <returns /> 94 Sys.Extended.UI.CascadingDropDownBehavior.callBaseMethod(this, 'initialize'); 95 $common.prepareHiddenElementForATDeviceUpdate(); 96 97 var e = this.get_element(); 98 this._actualDisabledStatus = e.disabled; 99 this._clearItems(); 100 101 e.CascadingDropDownCategory = this._category; 102 103 this._changeHandler = Function.createDelegate(this, this._onChange); 104 $addHandler(e, "change", this._changeHandler); 105 106 if (this._parentControlID) { 107 this._parentElement = $get(this._parentControlID); 108 109 if (!this._parentElement) { 110 Sys.Debug.fail(String.format(Sys.Extended.UI.Resources.CascadingDropDown_NoParentElement, this._parentControlID)); 111 } 112 113 if (this._parentElement) { 114 e.CascadingDropDownParentControlID = this._parentControlID; 115 this._parentChangeHandler = Function.createDelegate(this, this._onParentChange); 116 117 $addHandler(this._parentElement, "change", this._parentChangeHandler); 118 if (!this._parentElement.childDropDown) { 119 this._parentElement.childDropDown = new Array(); 120 } 121 this._parentElement.childDropDown.push(this); 122 } 123 } 124 125 this._onParentChange(null, true); 126 127 var me = this; 128 setTimeout(function () { 129 if (me._actualDisabledStatus) 130 e.disabled = me._actualDisabledStatus; 131 }, 50); 132 }, 133 134 dispose: function () { 135 /// <summary> 136 /// Dispose the behavior 137 /// </summary> 138 /// <returns /> 139
140 var e = this.get_element(); 141 142 if (this._changeHandler) { 143 $removeHandler(e, "change", this._changeHandler); 144 this._changeHandler = null; 145 } 146 147 if (this._parentChangeHandler) { 148 if (this._parentElement) { 149 $removeHandler(this._parentElement, "change", this._parentChangeHandler); 150 } 151 this._parentChangeHandler = null; 152 } 153 154 Sys.Extended.UI.CascadingDropDownBehavior.callBaseMethod(this, 'dispose'); 155 }, 156 157 _clearItems: function () { 158 /// <summary> 159 /// Clear the items from the drop down 160 /// </summary> 161 /// <returns /> 162 163 var e = this.get_element(); 164 if (e != null && e.options != null) { 165 while (0 < e.options.length) { 166 e.remove(0); 167 } 168 } 169 }, 170 171 _isPopulated: function () { 172 /// <summary> 173 /// Determine whether the drop down has any items 174 /// </summary> 175 /// <returns type="Boolean"> 176 /// Whether the drop down has any items 177 /// </returns> 178 179 var items = this.get_element().options.length; 180 181 if (this._promptText) { 182 return items > 1; 183 } else { 184 return items > 0; 185 } 186 }, 187 188 _setOptions: function (list, inInit, gettingList) { 189 /// <summary> 190 /// Set the contents of the DropDownList to the specified list 191 /// </summary> 192 /// <param name="list" mayBeNull="true" elementType="Object"> 193 /// Array of options (where each option has name and value properties) 194 /// </param> 195 /// <param name="inInit" type="Boolean" optional="true"> 196 /// Whether this is being called from the initialize method 197 /// </param> 198 /// <param name="gettingList" type="Boolean" optional="true"> 199 /// Whether we are fetching the list of options from the web service 200 /// </param> 201 /// <returns /> 202 203 if (!this.get_isInitialized()) { 204 return; 205 } 206 207 var e = this.get_element(); 208 this._clearItems(); 209 210 var headerText; 211 var headerValue = ""; 212 if (gettingList && this._loadingText) { 213 headerText = this._loadingText; 214 if (this._selectedValue) { 215 headerValue = this._selectedValue; 216 } 217 } else if (!gettingList && list && (0 == list.length) && (null != this._emptyText)) { 218 headerText = this._emptyText; 219 if (this._emptyValue) { 220 headerValue = this._emptyValue; 221 } 222 } else if (this._promptText) { 223 headerText = this._promptText; 224 if (this._promptValue) { 225 headerValue = this._promptValue; 226 } 227 } 228 var optionElement; 229 if (headerText) { 230 optionElement = new Option(headerText, headerValue); 231 e.options[e.options.length] = optionElement; 232 } 233 234 var selectedValueOption = null, 235 defaultIndex = -1; 236 237 if (list) { 238 for (var i = 0; i < list.length; i++) { 239 var item = list[i], 240 listItemName = item.name, 241 listItemValue = item.value, 242 listItemOptionTitle = item.optionTitle; 243 244 if (item.isDefaultValue) { 245 this.set_SelectedValue(listItemValue, listItemName, listItemOptionTitle); 246 defaultIndex = i; 247 if (this._promptText) { 248 defaultIndex++; 249 } 250 } 251 252 optionElement = new Option(listItemName, listItemValue); 253 if (listItemValue == this._selectedValue) { 254 selectedValueOption = optionElement; 255 } 256 if (listItemOptionTitle) { 257 optionElement.setAttribute('title', listItemOptionTitle); 258 } 259 260 e.options[e.options.length] = optionElement; 261 } 262 if (selectedValueOption) { 263 selectedValueOption.selected = true; 264 } 265 } 266 267 if (selectedValueOption) { 268 this.set_SelectedValue(e.options[e.selectedIndex].value, e.options[e.selectedIndex].text); 269 } else if (!selectedValueOption && defaultIndex != -1) { 270 e.options[defaultIndex].selected = true; 271 this.set_SelectedValue(e.options[defaultIndex].value, e.options[defaultIndex].text); 272 } else if (!inInit && !selectedValueOption && !gettingList && !this._promptText && (e.options.length > 0)) { 273 this.set_SelectedValue(e.options[0].value, e.options[0].text); 274 } else if (!inInit && !selectedValueOption && !gettingList) { 275 this.set_SelectedValue('', ''); 276 } 277 278 if (e.childDropDown && !gettingList) { 279 for (var i = 0; i < e.childDropDown.length; i++) { 280 e.childDropDown[i]._onParentChange(); 281 } 282 } 283 else { 284 if (list && (Sys.Browser.agent !== Sys.Browser.Safari) && (Sys.Browser.agent !== Sys.Browser.Opera)) { 285 if (document.createEvent) { 286 var onchangeEvent = document.createEvent('HTMLEvents'); 287 onchangeEvent.initEvent('change', true, false);
288 this.get_element().dispatchEvent(onchangeEvent); 289 } else if (document.createEventObject) { 290 this.get_element().fireEvent('onchange'); 291 } 292 } 293 } 294 295 if (!this._enableAtLoading) { 296 if (this._loadingText || this._promptText || this._emptyText) { 297 e.disabled = !list || (0 == list.length); 298 } 299 if (this._actualDisabledStatus) 300 e.disabled = this._actualDisabledStatus; 301 } 302 303 if (gettingList) { 304 this.raisePopulated(Sys.EventArgs.Empty); 305 } 306 }, 307 308 _onChange: function () { 309 /// <summary> 310 /// Handler for the drop down's change event 311 /// </summary> 312 /// <returns /> 313 314 if (!this._isPopulated()) { 315 return; 316 } 317 318 var e = this.get_element(); 319 320 if ((-1 != e.selectedIndex) && !(this._promptText && (0 == e.selectedIndex))) { 321 this.set_SelectedValue(e.options[e.selectedIndex].value, e.options[e.selectedIndex].text, e.options[e.selectedIndex].title); 322 } else { 323 this.set_SelectedValue('', ''); 324 } 325 }, 326 327 _onParentChange: function (evt, inInit) { 328 /// <summary> 329 /// Handler for the parent drop down's change event 330 /// </summary> 331 /// <param name="evt" type="Object"> 332 /// Set by the browser when called as an event handler (unused here) 333 /// </param> 334 /// <param name="inInit" type="Boolean"> 335 /// Whether this is being called from the initialize method 336 /// </param> 337 /// <returns /> 338 339 var e = this.get_element(); 340 341 var knownCategoryValues = ''; 342 var parentControlID = this._parentControlID; 343 while (parentControlID) { 344 var parentElement = $get(parentControlID); 345 if (parentElement && (-1 != parentElement.selectedIndex)) { 346 var selectedValue = parentElement.options[parentElement.selectedIndex].value; 347 348 if (selectedValue && selectedValue != "") { 349 knownCategoryValues = parentElement.CascadingDropDownCategory + ':' + selectedValue + ';' + knownCategoryValues; 350 parentControlID = parentElement.CascadingDropDownParentControlID; 351 continue; 352 } 353 } 354 break; 355 } 356 357 if (knownCategoryValues != '' && this._lastParentValues == knownCategoryValues) { 358 return; 359 } 360 361 this._lastParentValues = knownCategoryValues; 362 363 if (knownCategoryValues == '' && this._parentControlID) { 364 this._setOptions(null, inInit); 365 return; 366 } 367 368 this._setOptions(null, inInit, true); 369 370 if (this._servicePath && this._serviceMethod) { 371 var eventArgs = new Sys.CancelEventArgs(); 372 this.raisePopulating(eventArgs); 373 if (eventArgs.get_cancel()) { 374 return; 375 } 376 377 var params = { knownCategoryValues: knownCategoryValues, category: this._category }; 378 if (this._useContextKey) { 379 params.contextKey = this._contextKey; 380 } 381 382 Sys.Net.WebServiceProxy.invoke(this._servicePath, this._serviceMethod, this._useHttpGet, params, 383 Function.createDelegate(this, this._onMethodComplete), Function.createDelegate(this, this._onMethodError)); 384 $common.updateFormToRefreshATDeviceBuffer(); 385 } 386 }, 387 388 _onMethodComplete: function (result, userContext, methodName) { 389 this._setOptions(result); 390 }, 391 392 _onMethodError: function (webServiceError, userContext, methodName) { 393 if (webServiceError.get_timedOut()) { 394 this._setOptions([this._makeNameValueObject(Sys.Extended.UI.Resources.CascadingDropDown_MethodTimeout)]); 395 } else { 396 this._setOptions([this._makeNameValueObject(String.format(Sys.Extended.UI.Resources.CascadingDropDown_MethodError, webServiceError.get_statusCode()))]); 397 } 398 }, 399 400 _makeNameValueObject: function (message) { 401 /// <summary> 402 /// Create an object with name and value properties set to the provided message 403 /// </summary> 404 /// <param name="message" type="String"> 405 /// Message 406 /// </param> 407 /// <returns type="Object"> 408 /// Object with name and value properties set to the message 409 /// </returns> 410 411 return { 'name': message, 'value': message }; 412 }, 413 414 get_ParentControlID: function () { 415 /// <value type="String"> 416 /// ID of the parent drop down in a hierarchy of drop downs 417 /// </value> 418 return this._parentControlID; 419 }, 420 set_ParentControlID: function (value) { 421 if (this._parentControlID != value) { 422 this._parentControlID = value; 423 this.raisePropertyChanged('ParentControlID'); 424 } 425 }, 426 427 get_Category: function () { 428 /// <value type="String"> 429 /// Category of this drop down 430 /// </value> 431 return this._category; 432 }, 433 set_Category: function (value) { 434 if (this._category != value) { 435 this._category = value; 436 this.raisePropertyChanged('Category'); 437 } 438 }, 439 440 get_PromptText: function () { 441 /// <value type="String"> 442 /// Prompt text displayed as the first entry in the drop down 443 /// </value> 444 return this._promptText; 445 }, 446 set_PromptText: function (value) { 447 if (this._promptText != value) { 448 this._promptText = value; 449 this.raisePropertyChanged('PromptText'); 450 } 451 }, 452 453 get_PromptValue: function () { 454 /// <value type="String"> 455 /// Value for the option displayed by a DropDownList showing the PromptText 456 /// </value> 457 return this._promptValue; 458 }, 459 set_PromptValue: function (value) { 460 if (this._promptValue != value) { 461 this._promptValue = value; 462 this.raisePropertyChanged('PromptValue'); 463 } 464 }, 465 466 get_EmptyText: function () { 467 /// <value type="String"> 468 /// Text for the option displayed when the list is empty 469 /// </value> 470 return this._emptyText; 471 }, 472 set_EmptyText: function (value) { 473 if (this._emptyText != value) { 474 this._emptyText = value; 475 this.raisePropertyChanged('EmptyText'); 476 } 477 }, 478 479 get_EmptyValue: function () { 480 /// <value type="String"> 481 /// Value for the option displayed when the list is empty 482 /// </value> 483 return this._emptyValue; 484 }, 485 set_EmptyValue: function (value) { 486 if (this._emptyValue != value) { 487 this._emptyValue = value; 488 this.raisePropertyChanged('EmptyValue'); 489 } 490 }, 491 492 get_LoadingText: function () { 493 /// <value type="String"> 494 /// Loading text to to be displayed when getting the drop down's values from the web service 495 /// </value> 496 return this._loadingText; 497 }, 498 set_LoadingText: function (value) { 499 if (this._loadingText != value) { 500 this._loadingText = value; 501 this.raisePropertyChanged('LoadingText'); 502 } 503 }, 504 505 get_SelectedValue: function () { 506 /// <value type="String"> 507 /// Selected value of the drop down 508 /// </value> 509 return this._selectedValue; 510 }, 511 set_SelectedValue: function (value, text, title) { 512 if (this._selectedValue != value) { 513 if (!text) { 514 var i = value.indexOf(':::'); 515 if (-1 != i) { 516 text = value.slice(i + 3); 517 value = value.slice(0, i); 518 519 i = text.indexOf(':::'); 520 if (-1 != i) { 521 title = text.slice(i + 3); 522 text = text.slice(0, i); 523 } 524 } 525 } 526 var oldValue = this._selectedValue; 527 this._selectedValue = value; 528 this.raisePropertyChanged('SelectedValue'); 529 this.raiseSelectionChanged(new Sys.Extended.UI.CascadingDropDownSelectionChangedEventArgs(oldValue, value)); 530 } 531 Sys.Extended.UI.CascadingDropDownBehavior.callBaseMethod(this, 'set_ClientState', [this._selectedValue + ':::' + text
531+ ':::' + (title ? (':::' + title) : '')]); 532 }, 533 534 get_ServicePath: function () { 535 /// <value type="String" mayBeNull="true"> 536 /// Path to the web service 537 /// </value> 538 return this._servicePath; 539 }, 540 set_ServicePath: function (value) { 541 if (this._servicePath != value) { 542 this._servicePath = value; 543 this.raisePropertyChanged('ServicePath'); 544 } 545 }, 546 547 get_ServiceMethod: function () { 548 /// <value type="String"> 549 /// Name of the method to invoke on the web service 550 /// </value> 551 return this._serviceMethod; 552 }, 553 set_ServiceMethod: function (value) { 554 if (this._serviceMethod != value) { 555 this._serviceMethod = value; 556 this.raisePropertyChanged('ServiceMethod'); 557 } 558 }, 559 560 get_contextKey: function () { 561 /// <value type="String" mayBeNull="true"> 562 /// User/page specific context provided to an optional overload of the 563 /// web method described by ServiceMethod/ServicePath. If the context 564 /// key is used, it should have the same signature with an additional 565 /// parameter named contextKey of type string. 566 /// </value> 567 return this._contextKey; 568 }, 569 set_contextKey: function (value) { 570 if (this._contextKey != value) { 571 this._contextKey = value; 572 this.set_useContextKey(true); 573 this.raisePropertyChanged('contextKey'); 574 } 575 }, 576 577 get_useContextKey: function () { 578 /// <value type="Boolean"> 579 /// Whether or not the ContextKey property should be used. This will be 580 /// automatically enabled if the ContextKey property is ever set 581 /// (on either the client or the server). If the context key is used, 582 /// it should have the same signature with an additional parameter 583 /// named contextKey of type string. 584 /// </value> 585 return this._useContextKey; 586 }, 587 set_useContextKey: function (value) { 588 if (this._useContextKey != value) { 589 this._useContextKey = value; 590 this.raisePropertyChanged('useContextKey'); 591 } 592 }, 593 594 get_useHttpGet: function () { 595 /// <value type="Boolean"> 596 /// Whether or not the get method should be used instead of post. 597 /// </value> 598 return this._useHttpGet; 599 }, 600 set_useHttpGet: function (value) { 601 if (this._useHttpGet != value) { 602 this._useHttpGet = value; 603 this.raisePropertyChanged('useHttpGet'); 604 } 605 }, 606 607 get_enableAtLoading: function () { 608 /// <value type="Boolean"> 609 /// Whether or not disable the dropdownlist control when this is waiting to 610 /// get data from the service so at the time of loading user can use keyboard 611 /// to navigate to the dropdown control. 612 /// </value> 613 return this._enableAtLoading; 614 }, 615 set_enableAtLoading: function (value) { 616 if (this._enableAtLoading != value) { 617 this._enableAtLoading = value; 618 this.raisePropertyChanged('enableAtLoading'); 619 } 620 }, 621 622 add_selectionChanged: function (handler) { 623 /// <summary> 624 /// Add an event handler for the selectionChanged event 625 /// </summary> 626 /// <param name="handler" type="Function" mayBeNull="false"> 627 /// Event handler 628 /// </param> 629 /// <returns /> 630 this.get_events().addHandler('selectionChanged', handler); 631 }, 632 remove_selectionChanged: function (handler) { 633 /// <summary> 634 /// Remove an event handler from the selectionChanged event 635 /// </summary> 636 /// <param name="handler" type="Function" mayBeNull="false"> 637 /// Event handler 638 /// </param> 639 /// <returns /> 640 this.get_events().removeHandler('selectionChanged', handler); 641 }, 642 raiseSelectionChanged: function (eventArgs) { 643 /// <summary> 644 /// Raise the selectionChanged event 645 /// </summary> 646 /// <param name="eventArgs" type="Sys.Extended.UI.CascadingDropDownSelectionChangedEventArgs" mayBeNull="false"> 647 /// Event arguments for the selectionChanged event 648 /// </param> 649 /// <returns /> 650 651 var handler = this.get_events().getHandler('selectionChanged'); 652 if (handler) { 653 handler(this, eventArgs); 654 } 655 }, 656 657 add_populating: function (handler) { 658 /// <summary> 659 /// Add an event handler for the populating event 660 /// </summary> 661 /// <param name="handler" type="Function" mayBeNull="false"> 662 /// Event handler 663 /// </param> 664 /// <returns /> 665 this.get_events().addHandler('populating', handler); 666 }, 667 remove_populating: function (handler) { 668 /// <summary> 669 /// Remove an event handler from the populating event 670 /// </summary> 671 /// <param name="handler" type="Function" mayBeNull="false"> 672 /// Event handler 673 /// </param> 674 /// <returns /> 675 this.get_events().removeHandler('populating', handler); 676 },
677 raisePopulating: function (eventArgs) { 678 /// <summary> 679 /// Raise the populating event 680 /// </summary> 681 /// <param name="eventArgs" type="Sys.CancelEventArgs" mayBeNull="false"> 682 /// Event arguments for the populating event 683 /// </param> 684 /// <returns /> 685 /// <remarks> 686 /// The populating event can be used to provide custom data to 687 /// CascadingDropDown instead of using a web service. Just cancel the 688 /// event (using the CancelEventArgs) and pass your own data to the 689 /// _setOptions method. 690 /// </remarks> 691 692 var handler = this.get_events().getHandler('populating'); 693 if (handler) { 694 handler(this, eventArgs); 695 } 696 }, 697 698 add_populated: function (handler) { 699 /// <summary> 700 /// Add an event handler for the populated event 701 /// </summary> 702 /// <param name="handler" type="Function" mayBeNull="false"> 703 /// Event handler 704 /// </param> 705 /// <returns /> 706 this.get_events().addHandler('populated', handler); 707 }, 708 remove_populated: function (handler) { 709 /// <summary> 710 /// Remove an event handler from the populated event 711 /// </summary> 712 /// <param name="handler" type="Function" mayBeNull="false"> 713 /// Event handler 714 /// </param> 715 /// <returns /> 716 this.get_events().removeHandler('populated', handler); 717 }, 718 raisePopulated: function (eventArgs) { 719 /// <summary> 720 /// Raise the populated event 721 /// </summary> 722 /// <param name="eventArgs" type="Sys.EventArgs" mayBeNull="false"> 723 /// Event arguments for the populated event 724 /// </param> 725 /// <returns /> 726 727 var handler = this.get_events().getHandler('populated'); 728 if (handler) { 729 handler(this, eventArgs); 730 } 731 } 732 } 733 Sys.Extended.UI.CascadingDropDownBehavior.registerClass('Sys.Extended.UI.CascadingDropDownBehavior', Sys.Extended.UI.BehaviorBase); 734 Sys.registerComponent(Sys.Extended.UI.CascadingDropDownBehavior, { name: "cascadingDropDown" }); 735 736 } // execute 737 738 if (window.Sys && Sys.loader) { 739 Sys.loader.registerScript(scriptName, ["ExtendedBase", "ExtendedCommon", "WebServices"], execute); 740 } 741 else { 742 execute(); 743 } 744 745})();
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.