Group.js 7.9 KB

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