Custom.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. _getItem: function(callback, failure, id, async){
  80. if (callback) callback.apply(id, [{"id":id}]);
  81. },
  82. _newItem: function(data, selector, container, level, category){
  83. return new MWF.xApplication.Template.Selector.Custom.Item(data, selector, container, level, category);
  84. },
  85. createItemsSearchData: function(callback){
  86. if (!this.itemsSearchData){
  87. this.itemsSearchData = [];
  88. MWF.require("MWF.widget.PinYin", function(){
  89. var initIds = [];
  90. this.items.each(function(item){
  91. if (initIds.indexOf(item.data.name)==-1){
  92. var text = item._getShowName().toLowerCase();
  93. var pinyin = text.toPY().toLowerCase();
  94. var firstPY = text.toPYFirst().toLowerCase();
  95. this.itemsSearchData.push({
  96. "text": text,
  97. "pinyin": pinyin,
  98. "firstPY": firstPY,
  99. "data": item.data
  100. });
  101. initIds.push(item.data.name);
  102. }
  103. }.bind(this));
  104. delete initIds;
  105. if (callback) callback();
  106. }.bind(this));
  107. }else{
  108. if (callback) callback();
  109. }
  110. }
  111. });
  112. MWF.xApplication.Template.Selector.Custom.Item = new Class({
  113. Extends: o2.xApplication.Selector.Person.Item,
  114. _getShowName: function(){
  115. return this.data.name;
  116. },
  117. _setIcon: function(){
  118. var style = this.selector.options.style;
  119. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/"+style+"/icon/processicon.png)");
  120. },
  121. _getTtiteText: function(){
  122. return this.data.name;
  123. },
  124. loadSubItem: function(){
  125. return false;
  126. },
  127. checkSelectedSingle: function(){
  128. var selectedItem = this.selector.options.values.filter(function(item, index){
  129. if (typeOf(item)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
  130. if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
  131. return false;
  132. }.bind(this));
  133. if (selectedItem.length){
  134. this.selectedSingle();
  135. }
  136. },
  137. checkSelected: function(){
  138. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  139. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  140. }.bind(this));
  141. if (selectedItem.length){
  142. //selectedItem[0].item = this;
  143. selectedItem[0].addItem(this);
  144. this.selectedItem = selectedItem[0];
  145. this.setSelected();
  146. }
  147. }
  148. });
  149. MWF.xApplication.Template.Selector.Custom.ItemSelected = new Class({
  150. Extends: o2.xApplication.Selector.Person.ItemSelected,
  151. _getShowName: function(){
  152. return this.data.name;
  153. },
  154. _setIcon: function(){
  155. var style = this.selector.options.style;
  156. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/"+style+"/icon/processicon.png)");
  157. },
  158. _getTtiteText: function(){
  159. return this.data.name;
  160. },
  161. check: function(){
  162. if (this.selector.items.length){
  163. var items = this.selector.items.filter(function(item, index){
  164. return (item.data.id === this.data.id) || (item.data.name === this.data.name);
  165. }.bind(this));
  166. this.items = items;
  167. if (items.length){
  168. items.each(function(item){
  169. item.selectedItem = this;
  170. item.setSelected();
  171. }.bind(this));
  172. }
  173. }
  174. }
  175. });
  176. MWF.xApplication.Template.Selector.Custom.ItemCategory = new Class({
  177. Extends: o2.xApplication.Selector.Person.ItemCategory,
  178. _getShowName: function(){
  179. return this.data.name;
  180. },
  181. createNode: function(){
  182. this.node = new Element("div", {
  183. "styles": this.selector.css.selectorItemCategory_department
  184. }).inject(this.container);
  185. this.loaded = true;
  186. },
  187. _setIcon: function(){
  188. var style = this.selector.options.style;
  189. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/"+style+"/icon/applicationicon.png)");
  190. },
  191. _getTtiteText: function(){
  192. return this.data.name;
  193. },
  194. _hasChildItem : function(){
  195. return this._hasChild();
  196. },
  197. _hasChild: function(){
  198. return (this.data.subItemList && this.data.subItemList.length);
  199. },
  200. check: function(){}
  201. });