Custom.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. },
  26. loadSelectItems: function(addToNext){
  27. if(!this.options.category){
  28. this.options.selectableItems.each( function( it ){
  29. var name = typeOf( it ) === "string" ? it : it.name;
  30. var id = typeOf( it ) === "string" ? it : it.id;
  31. var item = this._newItem({ name : name, id : id }, this, this.itemAreaNode );
  32. this.items.push(item);
  33. }.bind(this))
  34. }else{
  35. this.options.selectableItems.each(function (item, index) {
  36. if(item.subItemList && item.subItemList.length>0){
  37. var category = this._newItemCategory(item, this, this.itemAreaNode);
  38. item.subItemList.each(function (subItem, index) {
  39. var item = this._newItem(subItem, this, category.children);
  40. this.items.push(item);
  41. }.bind(this));
  42. }
  43. }.bind(this));
  44. }
  45. },
  46. _scrollEvent: function(y){
  47. return true;
  48. },
  49. _getChildrenItemIds: function(data){
  50. return data.subItemList || [];
  51. },
  52. _newItemCategory: function(data, selector, item, level){
  53. return new MWF.xApplication.Template.Selector.Custom.ItemCategory(data, selector, item, level)
  54. },
  55. _listItemByKey: function(callback, failure, key){
  56. if (key){
  57. this.initSearchArea(true);
  58. this.searchInItems(key);
  59. }else{
  60. this.initSearchArea(false);
  61. }
  62. },
  63. _newItemSelected: function(data, selector, item){
  64. return new MWF.xApplication.Template.Selector.Custom.ItemSelected(data, selector, item)
  65. },
  66. _listItemByPinyin: function(callback, failure, key){
  67. if (key){
  68. this.initSearchArea(true);
  69. this.searchInItems(key);
  70. }else{
  71. this.initSearchArea(false);
  72. }
  73. },
  74. _newItem: function(data, selector, container, level){
  75. return new MWF.xApplication.Template.Selector.Custom.Item(data, selector, container, level);
  76. },
  77. createItemsSearchData: function(callback){
  78. if (!this.itemsSearchData){
  79. this.itemsSearchData = [];
  80. MWF.require("MWF.widget.PinYin", function(){
  81. var initIds = [];
  82. this.items.each(function(item){
  83. if (initIds.indexOf(item.data.name)==-1){
  84. var text = item._getShowName().toLowerCase();
  85. var pinyin = text.toPY().toLowerCase();
  86. var firstPY = text.toPYFirst().toLowerCase();
  87. this.itemsSearchData.push({
  88. "text": text,
  89. "pinyin": pinyin,
  90. "firstPY": firstPY,
  91. "data": item.data
  92. });
  93. initIds.push(item.data.name);
  94. }
  95. }.bind(this));
  96. delete initIds;
  97. if (callback) callback();
  98. }.bind(this));
  99. }else{
  100. if (callback) callback();
  101. }
  102. }
  103. });
  104. MWF.xApplication.Template.Selector.Custom.Item = new Class({
  105. Extends: o2.xApplication.Selector.Person.Item,
  106. _getShowName: function(){
  107. return this.data.name;
  108. },
  109. _setIcon: function(){
  110. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/processicon.png)");
  111. },
  112. _getTtiteText: function(){
  113. return this.data.name;
  114. },
  115. loadSubItem: function(){
  116. return false;
  117. },
  118. checkSelectedSingle: function(){
  119. var selectedItem = this.selector.options.values.filter(function(item, index){
  120. if (typeOf(item)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  121. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  122. return false;
  123. }.bind(this));
  124. if (selectedItem.length){
  125. this.selectedSingle();
  126. }
  127. },
  128. checkSelected: function(){
  129. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  130. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  131. }.bind(this));
  132. if (selectedItem.length){
  133. //selectedItem[0].item = this;
  134. selectedItem[0].addItem(this);
  135. this.selectedItem = selectedItem[0];
  136. this.setSelected();
  137. }
  138. }
  139. });
  140. MWF.xApplication.Template.Selector.Custom.ItemSelected = new Class({
  141. Extends: o2.xApplication.Selector.Person.ItemSelected,
  142. _getShowName: function(){
  143. return this.data.name;
  144. },
  145. _setIcon: function(){
  146. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/processicon.png)");
  147. },
  148. check: function(){
  149. if (this.selector.items.length){
  150. var items = this.selector.items.filter(function(item, index){
  151. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  152. }.bind(this));
  153. this.items = items;
  154. if (items.length){
  155. items.each(function(item){
  156. item.selectedItem = this;
  157. item.setSelected();
  158. }.bind(this));
  159. }
  160. }
  161. }
  162. });
  163. MWF.xApplication.Template.Selector.Custom.ItemCategory = new Class({
  164. Extends: o2.xApplication.Selector.Person.ItemCategory,
  165. _getShowName: function(){
  166. return this.data.name;
  167. },
  168. createNode: function(){
  169. this.node = new Element("div", {
  170. "styles": this.selector.css.selectorItemCategory_department
  171. }).inject(this.container);
  172. },
  173. _setIcon: function(){
  174. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/applicationicon.png)");
  175. },
  176. _hasChild: function(){
  177. return (this.data.subItemList && this.data.subItemList.length);
  178. },
  179. check: function(){}
  180. });