Group.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/groupicon.png)");
  108. },
  109. loadSubItem: function(){
  110. this.selector.orgAction.listPersonNested(this.data.id, function(json){
  111. this.textNode.set("text", this.textNode.get("text")+" ("+json.data.length+")");
  112. var usersText = "";
  113. json.data.each(function(item){
  114. usersText+=item.name+", ";
  115. }.bind(this));
  116. var node = new Element("div", {"styles": {"max-width": "300px"}, "text": usersText});
  117. if (!Browser.Platform.ios){
  118. this.tooltip = new mBox.Tooltip({
  119. content: node,
  120. setStyles: {content: {padding: 15, lineHeight: 20}},
  121. attach: this.node,
  122. transition: 'flyin'
  123. });
  124. }
  125. //this.textNode.set("title", usersText);
  126. }.bind(this));
  127. }
  128. });
  129. MWF.xApplication.Selector.Group.ItemSelected = new Class({
  130. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  131. _getShowName: function(){
  132. return this.data.name;
  133. },
  134. _getTtiteText: function(){
  135. return this.data.name;
  136. },
  137. _setIcon: function(){
  138. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/groupicon.png)");
  139. },
  140. loadSubItem: function(){
  141. this.selector.orgAction.listPersonNested(this.data.id, function(json){
  142. this.textNode.set("text", this.textNode.get("text")+" ("+json.data.length+")");
  143. var usersText = "";
  144. json.data.each(function(item){
  145. usersText+=item.name+", ";
  146. }.bind(this));
  147. var node = new Element("div", {"styles": {"max-width": "300px"}, "text": usersText});
  148. if (!Browser.Platform.ios){
  149. this.tooltip = new mBox.Tooltip({
  150. content: node,
  151. setStyles: {content: {padding: 15, lineHeight: 20}},
  152. attach: this.node,
  153. transition: 'flyin'
  154. });
  155. }
  156. //this.textNode.set("title", usersText);
  157. }.bind(this));
  158. }
  159. });
  160. MWF.xApplication.Selector.Group.Filter = new Class({
  161. Implements: [Options, Events],
  162. options: {
  163. "style": "default",
  164. "groups": [],
  165. "roles": []
  166. },
  167. initialize: function(value, options){
  168. this.setOptions(options);
  169. this.value = value;
  170. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  171. },
  172. filter: function(value, callback){
  173. this.value = value;
  174. var key = this.value;
  175. if (this.options.groups.length || this.options.roles.length) key = this.getLikeKey(key);
  176. this.orgAction.listGroupByKey(function(json){
  177. data = json.data;
  178. if (callback) callback(data)
  179. }.bind(this), null, key);
  180. },
  181. getLikeKey : function( key ){
  182. var result = key;
  183. if (this.options.groups.length || this.options.roles.length){
  184. var array = [];
  185. this.options.groups.each( function(d){
  186. array.push( typeOf(d)==="object" ? d.distinguishedName : d );
  187. }.bind(this));
  188. var array2 = [];
  189. this.options.roles.each( function(d){
  190. array2.push( typeOf(d)==="object" ? d.distinguishedName : d );
  191. }.bind(this));
  192. result = {"key": key || "", "groupList": array, "roleList": array2};
  193. }
  194. return result;
  195. }
  196. });