MPopupSelector.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //提供两种方式,一种是传入selectValue,selectText, 另外一种是 用onLoadData 或 loadData 加载数据,
  2. MWF.xDesktop.requireApp("Template", "MTooltips", null, false);
  3. MWF.xDesktop.requireApp("Template", "MSelector", null, false);
  4. var MPopupSelector = new Class({
  5. Extends: MSelector,
  6. options: {
  7. "style": "default",
  8. "width": "230px",
  9. "height": "30px",
  10. "trigger" : "delay", //immediately
  11. "isChangeOptionStyle" : false,
  12. "emptyOptionEnable" : true,
  13. "textField" : "",
  14. "valueField" : "",
  15. "value" : "",
  16. "text" : "",
  17. "defaultVaue" : "",
  18. "selectValue" : "",
  19. "selectText" : "",
  20. "tooltipsOptions" : {
  21. axis: "y", //箭头在x轴还是y轴上展现
  22. position : { //node 固定的位置
  23. x : "center", //x轴上left center right, auto 系统自动计算
  24. y : "bottom" //y 轴上top middle bottom, auto 系统自动计算
  25. },
  26. event : "click", //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  27. hiddenDelay : 200, //ms , 有target 且 事件类型为 mouseenter 时有效
  28. displayDelay : 0 //ms , 有target 且事件类型为 mouseenter 时有效
  29. }
  30. },
  31. initialize: function ( targetCoordinates, options , app, css, dropdownContainer ) {
  32. this.setOptions(options);
  33. this.path = "/x_component_Template/$MSelector/";
  34. this.cssPath = "/x_component_Template/$MSelector/"+this.options.style+"/css.wcss";
  35. this._loadCss();
  36. if( css ) {
  37. this.css = Object.merge(this.css, css);
  38. }
  39. this.valSeparator = /,|;|\^\^|\|/; //如果是多值对象,作为用户选择的多个值的分隔符
  40. this.targetCoordinates = targetCoordinates;
  41. this.app = app;
  42. this.dropdownContainer = dropdownContainer || $(dropdownContainer);
  43. },
  44. loadEdit:function( callback ){
  45. this.initPara();
  46. if( this.data ){
  47. this.loadContent( this.data );
  48. }else{
  49. this._loadData( function( data ){
  50. this.data = this.parseData( data );
  51. this.loadContent( this.data );
  52. }.bind(this))
  53. }
  54. //this.node.addEvent( "click" , function( ev ){
  55. // this.loadContent();
  56. // ev.stopPropagation();
  57. //}.bind(this));
  58. if(callback)callback();
  59. },
  60. setTargetCoordinates : function( targetCoordinates ){
  61. this.targetCoordinates = targetCoordinates;
  62. this.contentTooltip.targetCoordinates = targetCoordinates;
  63. },
  64. loadContent : function( data ){
  65. if( !this.contentTooltip ){
  66. var width = parseInt(this.options.width)+"px";
  67. this.css.tooltipNode.width = width;
  68. this.css.tooltipNode["max-width"] = width;
  69. var options = Object.merge({
  70. nodeStyles : this.css.tooltipNode,
  71. onPostLoad : function(){
  72. this.selectArrowNode.setStyles( this.css.selectArrowNode_up );
  73. if( this.inputNode ){
  74. this.inputNode.focus();
  75. }
  76. }.bind(this),
  77. onPostInitialize : function(){
  78. if(this.options.trigger == "immediately" ){
  79. this.contentTooltip.load();
  80. }
  81. }.bind(this)
  82. }, this.options.tooltipsOptions );
  83. this.contentTooltip = new MSelector.Tootips( this.dropdownContainer || this.app.content, null, this.app, data, options, this.targetCoordinates );
  84. this.contentTooltip.selector = this;
  85. }
  86. },
  87. setCurrentItem : function( itemNode ){
  88. var data = itemNode.retrieve( "data" );
  89. if( this.currentItemNode ){
  90. this.currentItemNode.setStyles( this.css.listItemNode );
  91. }
  92. this.currentItemNode = itemNode;
  93. this.currentItemData = data;
  94. this.currentItemText = itemNode.get("text");
  95. if( this.options.isChangeOptionStyle )itemNode.setStyles( this.css.listItemNode_current );
  96. },
  97. _selectItem : function( itemNode, itemData ){
  98. },
  99. _loadData : function( callback ){
  100. //if(callback)callback();
  101. this.fireEvent("loadData",callback );
  102. },
  103. _postCreateItem: function(listItemNode, data){
  104. }
  105. });