Address.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. MWF.require("MWF.widget.PinYin", null, false);
  2. MWF.xDesktop.requireApp("process.Xform", "Combox", null, false);
  3. MWF.xApplication.process.Xform.Address = MWF.APPAddress = new Class({
  4. Implements: [Events],
  5. Extends: MWF.APPCombox,
  6. options: {
  7. "moduleEvents": ["load", "queryLoad", "postLoad", "commitInput", "change"]
  8. },
  9. initialize: function(node, json, form){
  10. this.node = $(node);
  11. this.node.store("module", this);
  12. this.json = json;
  13. this.form = form;
  14. this.field = true;
  15. },
  16. _loadNode: function(){
  17. if (this.readonly){
  18. this._loadNodeRead();
  19. }else{
  20. this._loadNodeEdit();
  21. }
  22. },
  23. _loadNodeRead: function(){
  24. this.node.empty();
  25. //new Element("select").inject(this.node);
  26. },
  27. _loadNodeEdit: function(){
  28. this.node.empty();
  29. MWF.require("MWF.widget.Combox", function(){
  30. this.combox = new MWF.widget.Combox({
  31. "count": 4,
  32. "focusList": true,
  33. "onCommitInput": function(){
  34. this.fireEvent("commitInput");
  35. }.bind(this),
  36. "onChange": function(){
  37. this.fireEvent("change");
  38. }.bind(this),
  39. "optionsMethod": this._searchOptions.bind(this)
  40. });
  41. this.combox.intoEdit = function(e){
  42. if (this.options.count){
  43. if (this.values.length>=this.options.count){
  44. // if (this.input) this.input.noBlur = true;
  45. if (this.input) this.input.node.hide();
  46. // this.getLast().edit();
  47. return false;
  48. }
  49. }
  50. if (!this.input){
  51. this.input = new MWF.widget.Combox.Input(this, this, "");
  52. this.input.node.inject(this.node);
  53. this.input.node.setStyle("width", "1px");
  54. }
  55. this.input.node.show();
  56. this.input.setInputNodeStyles();
  57. //this.input.node.set("value", "111");
  58. this.input.node.focus();
  59. this.input.setInputPosition();
  60. if (this.options.focusList) this.input.searchItems();
  61. }
  62. }.bind(this), false);
  63. this.combox.inject(this.node);
  64. this.node.set({
  65. "id": this.json.id,
  66. "MWFType": this.json.type
  67. });
  68. this.combox.addEvent("change", function(){
  69. this.validationMode();
  70. if (this.validation()) this._setBusinessData(this.getInputData("change"));
  71. }.bind(this));
  72. },
  73. _searchOptions: function(value, callback){
  74. value = value.toLowerCase();
  75. var i = (this.combox.editItem) ? this.combox.editItem.getItemPosition() : this.combox.values.length;
  76. switch (i) {
  77. case 0: //省
  78. MWF.UD.getPublicData("addr_province", function(json){
  79. var list = [];
  80. json.each(function(text){
  81. var keyword = text+MWF.widget.PinYin.toPY(text).toLowerCase()+MWF.widget.PinYin.toPYFirst(text).toLowerCase();
  82. if (value){
  83. if (keyword.indexOf(value)!==-1) list.push({"text": text, "value": text});
  84. }else{
  85. list.push({"text": text, "value": text});
  86. }
  87. }.bind(this));
  88. if (list.length) if (callback) callback(list);
  89. });
  90. break;
  91. case 1: //市
  92. var item = this.combox.getFirst();
  93. MWF.UD.getPublicData("addr_city_"+item.data, function(json){
  94. var list = [];
  95. json.each(function(text){
  96. var keyword = text+MWF.widget.PinYin.toPY(text).toLowerCase()+MWF.widget.PinYin.toPYFirst(text).toLowerCase();
  97. if (value){
  98. if (keyword.indexOf(value)!==-1) list.push({"text": text, "value": text});
  99. }else{
  100. list.push({"text": text, "value": text});
  101. }
  102. }.bind(this));
  103. if (list.length) if (callback) callback(list);
  104. });
  105. break;
  106. case 2: //区
  107. var item = this.combox.getFirst().getNextItem();
  108. MWF.UD.getPublicData("addr_district_"+item.data, function(json){
  109. var list = [];
  110. json.each(function(text){
  111. var keyword = text+MWF.widget.PinYin.toPY(text).toLowerCase()+MWF.widget.PinYin.toPYFirst(text).toLowerCase();
  112. if (value){
  113. if (keyword.indexOf(value)!==-1) list.push({"text": text, "value": text});
  114. }else{
  115. list.push({"text": text, "value": text});
  116. }
  117. }.bind(this));
  118. if (list.length) if (callback) callback(list);
  119. });
  120. break;
  121. default:
  122. if (callback) callback([]);
  123. }
  124. }
  125. });