Group.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. MWF.xDesktop.requireApp("Selector", "Person", null, false);
  2. MWF.xApplication.Selector.Group = new Class({
  3. Extends: MWF.xApplication.Selector.Person,
  4. options: {
  5. "style": "default",
  6. "count": 0,
  7. "title": MWF.xApplication.Selector.LP.selectGroup,
  8. "groups": [],
  9. "roles": [],
  10. "values": [],
  11. "names": [],
  12. "include" : [],
  13. "selectType" : "group"
  14. },
  15. _init : function(){
  16. this.selectType = "group";
  17. this.className = "Group";
  18. },
  19. checkLoadSelectItems: function(){
  20. if( this.options.include && this.options.include.length ){
  21. this.loadInclude();
  22. }else if (!this.options.groups.length && !this.options.roles.length){
  23. this.loadSelectItems();
  24. }else{
  25. this.loadSelectItemsByCondition();
  26. }
  27. },
  28. loadInclude: function(){
  29. if( !this.options.include || this.options.include.length === 0 )return;
  30. this.includeGroup = [];
  31. this.options.include.each( function( d ){
  32. var key = typeOf(d)==="object" ? d.distinguishedName : d;
  33. this.orgAction.listGroupByKey(function(json){
  34. if( !json.data )return;
  35. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  36. array.each(function(data){
  37. if( !this.isExcluded( data ) ) {
  38. this.includeGroup.push( data.distinguishedName );
  39. var item = this._newItem(data, this, this.itemAreaNode, 1);
  40. this.items.push(item);
  41. }
  42. }.bind(this));
  43. }.bind(this), null, key);
  44. }.bind(this))
  45. },
  46. _listItemByKey: function(callback, failure, key){
  47. if (this.options.groups.length || this.options.roles.length) key = this.getLikeKey( key );
  48. this.orgAction.listGroupByKey(function(json){
  49. if( this.includeGroup && this.includeGroup.length > 0 ){
  50. json.data = json.data.filter( function(d){
  51. return this.includeGroup.contains(d.distinguishedName);
  52. }.bind(this))
  53. }
  54. if (callback) callback.apply(this, [json]);
  55. }.bind(this), failure, key);
  56. },
  57. _getItem: function(callback, failure, id, async){
  58. this.orgAction.getGroup(function(json){
  59. if (callback) callback.apply(this, [json]);
  60. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  61. },
  62. _newItemSelected: function(data, selector, item, selectedNode){
  63. return new MWF.xApplication.Selector.Group.ItemSelected(data, selector, item, selectedNode)
  64. },
  65. _listItemByPinyin: function(callback, failure, key){
  66. if (this.options.groups.length || this.options.roles.length) key = this.getLikeKey( key );
  67. this.orgAction.listGroupByPinyin(function(json){
  68. if( this.includeGroup && this.includeGroup.length > 0 ){
  69. json.data = json.data.filter( function(d){
  70. return this.includeGroup.contains(d.distinguishedName);
  71. }.bind(this))
  72. }
  73. if (callback) callback.apply(this, [json]);
  74. }.bind(this), failure, key);
  75. },
  76. _newItem: function(data, selector, container){
  77. return new MWF.xApplication.Selector.Group.Item(data, selector, container);
  78. },
  79. _listItemNext: function(last, count, callback){
  80. this.orgAction.listGroupNext(last, count, function(json){
  81. if (callback) callback.apply(this, [json]);
  82. }.bind(this));
  83. },
  84. _getChildrenItemIds: function(data){
  85. return data.groupList;
  86. },
  87. getLikeKey : function( key ){
  88. var result = key;
  89. if (this.options.groups.length || this.options.roles.length){
  90. var array = [];
  91. this.options.groups.each( function(d){
  92. array.push( typeOf(d)==="object" ? d.distinguishedName : d );
  93. }.bind(this));
  94. var array2 = [];
  95. this.options.roles.each( function(d){
  96. array2.push( typeOf(d)==="object" ? d.distinguishedName : d );
  97. }.bind(this));
  98. result = {"key": key || "", "groupList": array, "roleList": array2};
  99. }
  100. return result;
  101. }
  102. });
  103. MWF.xApplication.Selector.Group.Item = new Class({
  104. Extends: MWF.xApplication.Selector.Person.Item,
  105. _getShowName: function(){
  106. return this.data.name;
  107. },
  108. _getTtiteText: function(){
  109. return this.data.name;
  110. },
  111. _setIcon: function(){
  112. var style = this.selector.options.style;
  113. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
  114. },
  115. loadSubItem: function(){
  116. this.selector.orgAction.listPersonNested(this.data.id, function(json){
  117. this.textNode.set("text", this.textNode.get("text")+" ("+json.data.length+")");
  118. var usersText = "";
  119. json.data.each(function(item){
  120. usersText+=item.name+", ";
  121. }.bind(this));
  122. var node = new Element("div", {"styles": {"max-width": "300px"}, "text": usersText});
  123. if (!Browser.Platform.ios){
  124. this.tooltip = new mBox.Tooltip({
  125. content: node,
  126. setStyles: {content: {padding: 15, lineHeight: 20}},
  127. attach: this.node,
  128. transition: 'flyin'
  129. });
  130. }
  131. //this.textNode.set("title", usersText);
  132. }.bind(this));
  133. }
  134. });
  135. MWF.xApplication.Selector.Group.ItemSelected = new Class({
  136. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  137. _getShowName: function(){
  138. return this.data.name;
  139. },
  140. _getTtiteText: function(){
  141. return this.data.name;
  142. },
  143. _setIcon: function(){
  144. var style = this.selector.options.style;
  145. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
  146. },
  147. loadSubItem: function(){
  148. this.selector.orgAction.listPersonNested(this.data.id, function(json){
  149. this.textNode.set("text", this.textNode.get("text")+" ("+json.data.length+")");
  150. var usersText = "";
  151. json.data.each(function(item){
  152. usersText+=item.name+", ";
  153. }.bind(this));
  154. var node = new Element("div", {"styles": {"max-width": "300px"}, "text": usersText});
  155. if (!Browser.Platform.ios){
  156. this.tooltip = new mBox.Tooltip({
  157. content: node,
  158. setStyles: {content: {padding: 15, lineHeight: 20}},
  159. attach: this.node,
  160. transition: 'flyin'
  161. });
  162. }
  163. //this.textNode.set("title", usersText);
  164. }.bind(this));
  165. }
  166. });
  167. MWF.xApplication.Selector.Group.Filter = new Class({
  168. Implements: [Options, Events],
  169. options: {
  170. "style": "default",
  171. "groups": [],
  172. "roles": []
  173. },
  174. initialize: function(value, options){
  175. this.setOptions(options);
  176. this.value = value;
  177. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  178. },
  179. filter: function(value, callback){
  180. this.value = value;
  181. var key = this.value;
  182. if (this.options.groups.length || this.options.roles.length) key = this.getLikeKey(key);
  183. this.orgAction.listGroupByKey(function(json){
  184. data = json.data;
  185. if (callback) callback(data)
  186. }.bind(this), null, key);
  187. },
  188. getLikeKey : function( key ){
  189. var result = key;
  190. if (this.options.groups.length || this.options.roles.length){
  191. var array = [];
  192. this.options.groups.each( function(d){
  193. array.push( typeOf(d)==="object" ? d.distinguishedName : d );
  194. }.bind(this));
  195. var array2 = [];
  196. this.options.roles.each( function(d){
  197. array2.push( typeOf(d)==="object" ? d.distinguishedName : d );
  198. }.bind(this));
  199. result = {"key": key || "", "groupList": array, "roleList": array2};
  200. }
  201. return result;
  202. }
  203. });