Custom.js 7.3 KB

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