Custom.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xApplication.Template = MWF.xApplication.Template || {};
  3. MWF.xApplication.Template.Selector = MWF.xApplication.Template.Selector || {};
  4. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  5. MWF.xApplication.Template.Selector.Custom = new Class({
  6. Extends: MWF.xApplication.Selector.Person,
  7. options: {
  8. "style": "default",
  9. "count": 0,
  10. "title": "选择列表",
  11. "values": [],
  12. "selectableItems" : [],
  13. "names": [],
  14. "category" : false,
  15. "expand": false
  16. },
  17. initialize: function(container, options ){
  18. this.setOptions(options);
  19. this.path = "/x_component_Selector/$Selector/";
  20. this.cssPath = "/x_component_Selector/$Selector/"+this.options.style+"/css.wcss";
  21. this._loadCss(true);
  22. this.container = $(container);
  23. this.selectedItems = [];
  24. this.items = [];
  25. debugger;
  26. },
  27. loadSelectItems: function(addToNext){
  28. if(!this.options.category){
  29. this.options.selectableItems.each( function( it ){
  30. var name = typeOf( it ) === "string" ? it : it.name;
  31. var id = typeOf( it ) === "string" ? it : it.id;
  32. var item = this._newItem({ name : name, id : id }, this, this.itemAreaNode );
  33. this.items.push(item);
  34. }.bind(this))
  35. }else{
  36. this.options.selectableItems.each(function (item, index) {
  37. if(item.subItemList && item.subItemList.length>0){
  38. var category = this._newItemCategory(item, this, this.itemAreaNode);
  39. item.subItemList.each(function (subItem, index) {
  40. var item = this._newItem(subItem, this, category.children);
  41. this.items.push(item);
  42. }.bind(this));
  43. }
  44. }.bind(this));
  45. }
  46. },
  47. _scrollEvent: function(y){
  48. return true;
  49. },
  50. _getChildrenItemIds: function(data){
  51. return data.subItemList || [];
  52. },
  53. _newItemCategory: function(data, selector, item, level){
  54. return new MWF.xApplication.Template.Selector.Custom.ItemCategory(data, selector, item, level)
  55. },
  56. _listItemByKey: function(callback, failure, key){
  57. return false;
  58. },
  59. _newItemSelected: function(data, selector, item){
  60. return new MWF.xApplication.Template.Selector.Custom.ItemSelected(data, selector, item)
  61. },
  62. _listItemByPinyin: function(callback, failure, key){
  63. return false;
  64. },
  65. _newItem: function(data, selector, container, level){
  66. return new MWF.xApplication.Template.Selector.Custom.Item(data, selector, container, level);
  67. }
  68. });
  69. MWF.xApplication.Template.Selector.Custom.Item = new Class({
  70. Extends: o2.xApplication.Selector.Person.Item,
  71. _getShowName: function(){
  72. return this.data.name;
  73. },
  74. _setIcon: function(){
  75. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/processicon.png)");
  76. },
  77. _getTtiteText: function(){
  78. return this.data.name;
  79. },
  80. loadSubItem: function(){
  81. return false;
  82. },
  83. checkSelectedSingle: function(){
  84. var selectedItem = this.selector.options.values.filter(function(item, index){
  85. if (typeOf(item)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  86. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  87. return false;
  88. }.bind(this));
  89. if (selectedItem.length){
  90. this.selectedSingle();
  91. }
  92. },
  93. checkSelected: function(){
  94. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  95. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  96. }.bind(this));
  97. if (selectedItem.length){
  98. //selectedItem[0].item = this;
  99. selectedItem[0].addItem(this);
  100. this.selectedItem = selectedItem[0];
  101. this.setSelected();
  102. }
  103. }
  104. });
  105. MWF.xApplication.Template.Selector.Custom.ItemSelected = new Class({
  106. Extends: o2.xApplication.Selector.Person.ItemSelected,
  107. _getShowName: function(){
  108. return this.data.name;
  109. },
  110. _setIcon: function(){
  111. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/processicon.png)");
  112. },
  113. check: function(){
  114. if (this.selector.items.length){
  115. var items = this.selector.items.filter(function(item, index){
  116. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  117. }.bind(this));
  118. this.items = items;
  119. if (items.length){
  120. items.each(function(item){
  121. item.selectedItem = this;
  122. item.setSelected();
  123. }.bind(this));
  124. }
  125. }
  126. }
  127. });
  128. MWF.xApplication.Template.Selector.Custom.ItemCategory = new Class({
  129. Extends: o2.xApplication.Selector.Person.ItemCategory,
  130. _getShowName: function(){
  131. return this.data.name;
  132. },
  133. createNode: function(){
  134. this.node = new Element("div", {
  135. "styles": this.selector.css.selectorItemCategory_department
  136. }).inject(this.container);
  137. },
  138. _setIcon: function(){
  139. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/applicationicon.png)");
  140. },
  141. _hasChild: function(){
  142. return (this.data.subItemList && this.data.subItemList.length);
  143. },
  144. check: function(){}
  145. });