ComboBoxMixin.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. require({cache:{
  2. 'url:dijit/form/templates/DropDownBox.html':"<div class=\"dijit dijitReset dijitInline dijitLeft\"\n\tid=\"widget_${id}\"\n\trole=\"combobox\"\n\t><div class='dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer'\n\t\tdata-dojo-attach-point=\"_buttonNode, _popupStateNode\" role=\"presentation\"\n\t\t><input class=\"dijitReset dijitInputField dijitArrowButtonInner\" value=\"&#9660; \" type=\"text\" tabIndex=\"-1\" readonly=\"readonly\" role=\"presentation\"\n\t\t\t${_buttonInputDisabled}\n\t/></div\n\t><div class='dijitReset dijitValidationContainer'\n\t\t><input class=\"dijitReset dijitInputField dijitValidationIcon dijitValidationInner\" value=\"&#935; \" type=\"text\" tabIndex=\"-1\" readonly=\"readonly\" role=\"presentation\"\n\t/></div\n\t><div class=\"dijitReset dijitInputField dijitInputContainer\"\n\t\t><input class='dijitReset dijitInputInner' ${!nameAttrSetting} type=\"text\" autocomplete=\"off\"\n\t\t\tdata-dojo-attach-point=\"textbox,focusNode\" role=\"textbox\" aria-haspopup=\"true\"\n\t/></div\n></div>\n"}});
  3. define("dijit/form/ComboBoxMixin", [
  4. "dojo/_base/declare", // declare
  5. "dojo/_base/Deferred",
  6. "dojo/_base/kernel", // kernel.deprecated
  7. "dojo/_base/lang", // lang.mixin
  8. "dojo/store/util/QueryResults", // dojo.store.util.QueryResults
  9. "./_AutoCompleterMixin",
  10. "./_ComboBoxMenu",
  11. "../_HasDropDown",
  12. "dojo/text!./templates/DropDownBox.html"
  13. ], function(declare, Deferred, kernel, lang, QueryResults, _AutoCompleterMixin, _ComboBoxMenu, _HasDropDown, template){
  14. /*=====
  15. var _AutoCompleterMixin = dijit.form._AutoCompleterMixin;
  16. var _ComboBoxMenu = dijit.form._ComboBoxMenu;
  17. var _HasDropDown = dijit._HasDropDown;
  18. =====*/
  19. // module:
  20. // dijit/form/ComboBoxMixin
  21. // summary:
  22. // Provides main functionality of ComboBox widget
  23. return declare("dijit.form.ComboBoxMixin", [_HasDropDown, _AutoCompleterMixin], {
  24. // summary:
  25. // Provides main functionality of ComboBox widget
  26. // dropDownClass: [protected extension] Function String
  27. // Dropdown widget class used to select a date/time.
  28. // Subclasses should specify this.
  29. dropDownClass: _ComboBoxMenu,
  30. // hasDownArrow: Boolean
  31. // Set this textbox to have a down arrow button, to display the drop down list.
  32. // Defaults to true.
  33. hasDownArrow: true,
  34. templateString: template,
  35. baseClass: "dijitTextBox dijitComboBox",
  36. /*=====
  37. // store: [const] dojo.store.api.Store || dojo.data.api.Read
  38. // Reference to data provider object used by this ComboBox.
  39. //
  40. // Should be dojo.store.api.Store, but dojo.data.api.Read supported
  41. // for backwards compatibility.
  42. store: null,
  43. =====*/
  44. // Set classes like dijitDownArrowButtonHover depending on
  45. // mouse action over button node
  46. cssStateNodes: {
  47. "_buttonNode": "dijitDownArrowButton"
  48. },
  49. _setHasDownArrowAttr: function(/*Boolean*/ val){
  50. this._set("hasDownArrow", val);
  51. this._buttonNode.style.display = val ? "" : "none";
  52. },
  53. _showResultList: function(){
  54. // hide the tooltip
  55. this.displayMessage("");
  56. this.inherited(arguments);
  57. },
  58. _setStoreAttr: function(store){
  59. // For backwards-compatibility, accept dojo.data store in addition to dojo.store.store. Remove in 2.0.
  60. if(!store.get){
  61. lang.mixin(store, {
  62. _oldAPI: true,
  63. get: function(id){
  64. // summary:
  65. // Retrieves an object by it's identity. This will trigger a fetchItemByIdentity.
  66. // Like dojo.store.DataStore.get() except returns native item.
  67. var deferred = new Deferred();
  68. this.fetchItemByIdentity({
  69. identity: id,
  70. onItem: function(object){
  71. deferred.resolve(object);
  72. },
  73. onError: function(error){
  74. deferred.reject(error);
  75. }
  76. });
  77. return deferred.promise;
  78. },
  79. query: function(query, options){
  80. // summary:
  81. // Queries the store for objects. Like dojo.store.DataStore.query()
  82. // except returned Deferred contains array of native items.
  83. var deferred = new Deferred(function(){ fetchHandle.abort && fetchHandle.abort(); });
  84. var fetchHandle = this.fetch(lang.mixin({
  85. query: query,
  86. onBegin: function(count){
  87. deferred.total = count;
  88. },
  89. onComplete: function(results){
  90. deferred.resolve(results);
  91. },
  92. onError: function(error){
  93. deferred.reject(error);
  94. }
  95. }, options));
  96. return QueryResults(deferred);
  97. }
  98. });
  99. }
  100. this._set("store", store);
  101. },
  102. postMixInProperties: function(){
  103. // Since _setValueAttr() depends on this.store, _setStoreAttr() needs to execute first.
  104. // Unfortunately, without special code, it ends up executing second.
  105. if(this.params.store){
  106. this._setStoreAttr(this.params.store);
  107. }
  108. this.inherited(arguments);
  109. // User may try to access this.store.getValue() etc. in a custom labelFunc() function.
  110. // It's not available with the new data store for handling inline <option> tags, so add it.
  111. if(!this.params.store){
  112. var clazz = this.declaredClass;
  113. lang.mixin(this.store, {
  114. getValue: function(item, attr){
  115. kernel.deprecated(clazz + ".store.getValue(item, attr) is deprecated for builtin store. Use item.attr directly", "", "2.0");
  116. return item[attr];
  117. },
  118. getLabel: function(item){
  119. kernel.deprecated(clazz + ".store.getLabel(item) is deprecated for builtin store. Use item.label directly", "", "2.0");
  120. return item.name;
  121. },
  122. fetch: function(args){
  123. kernel.deprecated(clazz + ".store.fetch() is deprecated for builtin store.", "Use store.query()", "2.0");
  124. var shim = ["dojo/data/ObjectStore"]; // indirection so it doesn't get rolled into a build
  125. require(shim, lang.hitch(this, function(ObjectStore){
  126. new ObjectStore({objectStore: this}).fetch(args);
  127. }));
  128. }
  129. });
  130. }
  131. }
  132. });
  133. });