Group.js 8.0 KB

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