Group.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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": "",
  8. "groups": [],
  9. "roles": [],
  10. "values": [],
  11. "names": [],
  12. "include" : [],
  13. "selectType" : "group"
  14. },
  15. setInitTitle: function(){
  16. this.setOptions({"title": MWF.xApplication.Selector.LP.selectGroup});
  17. },
  18. _init : function(){
  19. this.selectType = "group";
  20. this.className = "Group";
  21. },
  22. checkLoadSelectItems: function(){
  23. if( this.options.include && this.options.include.length ){
  24. this.loadInclude();
  25. }else if (!this.options.groups.length && !this.options.roles.length){
  26. this.loadSelectItems();
  27. }else{
  28. this.loadSelectItemsByCondition();
  29. }
  30. },
  31. loadInclude: function(){
  32. if( !this.options.include || this.options.include.length === 0 )return;
  33. this.includeGroup = [];
  34. this.options.include.each( function( d ){
  35. var key = typeOf(d)==="object" ? d.distinguishedName : d;
  36. this.orgAction.listGroupByKey(function(json){
  37. if( !json.data )return;
  38. var array = typeOf( json.data ) === "array" ? json.data : [json.data];
  39. array.each(function(data){
  40. if( !this.isExcluded( data ) ) {
  41. this.includeGroup.push( data.distinguishedName );
  42. var item = this._newItem(data, this, this.itemAreaNode, 1);
  43. this.items.push(item);
  44. }
  45. }.bind(this));
  46. }.bind(this), null, key);
  47. }.bind(this))
  48. },
  49. _listItemByKey: function(callback, failure, key){
  50. if (this.options.groups.length || this.options.roles.length) key = this.getLikeKey( key );
  51. this.orgAction.listGroupByKey(function(json){
  52. if( this.includeGroup && this.includeGroup.length > 0 ){
  53. json.data = json.data.filter( function(d){
  54. return this.includeGroup.contains(d.distinguishedName);
  55. }.bind(this))
  56. }
  57. if (callback) callback.apply(this, [json]);
  58. }.bind(this), failure, key);
  59. },
  60. _getItem: function(callback, failure, id, async){
  61. this.orgAction.getGroup(function(json){
  62. if (callback) callback.apply(this, [json]);
  63. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  64. },
  65. _newItemSelected: function(data, selector, item, selectedNode){
  66. return new MWF.xApplication.Selector.Group.ItemSelected(data, selector, item, selectedNode)
  67. },
  68. _listItemByPinyin: function(callback, failure, key){
  69. if (this.options.groups.length || this.options.roles.length) key = this.getLikeKey( key );
  70. this.orgAction.listGroupByPinyin(function(json){
  71. if( this.includeGroup && this.includeGroup.length > 0 ){
  72. json.data = json.data.filter( function(d){
  73. return this.includeGroup.contains(d.distinguishedName);
  74. }.bind(this))
  75. }
  76. if (callback) callback.apply(this, [json]);
  77. }.bind(this), failure, key);
  78. },
  79. _newItem: function(data, selector, container){
  80. return new MWF.xApplication.Selector.Group.Item(data, selector, container);
  81. },
  82. _listItemNext: function(last, count, callback){
  83. this.orgAction.listGroupNext(last, count, function(json){
  84. if (callback) callback.apply(this, [json]);
  85. }.bind(this));
  86. },
  87. _getChildrenItemIds: function(data){
  88. return data.groupList;
  89. },
  90. getLikeKey : function( key ){
  91. var result = key;
  92. if (this.options.groups.length || this.options.roles.length){
  93. var array = [];
  94. this.options.groups.each( function(d){
  95. array.push( typeOf(d)==="object" ? d.distinguishedName : d );
  96. }.bind(this));
  97. var array2 = [];
  98. this.options.roles.each( function(d){
  99. array2.push( typeOf(d)==="object" ? d.distinguishedName : d );
  100. }.bind(this));
  101. result = {"key": key || "", "groupList": array, "roleList": array2};
  102. }
  103. return result;
  104. }
  105. });
  106. MWF.xApplication.Selector.Group.Item = new Class({
  107. Extends: MWF.xApplication.Selector.Person.Item,
  108. _getShowName: function(){
  109. return this.data.name;
  110. },
  111. _getTtiteText: function(){
  112. return this.data.name;
  113. },
  114. _setIcon: function(){
  115. var style = this.selector.options.style;
  116. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
  117. },
  118. loadSubItem: function(){
  119. if( !layout.mobile ){
  120. this.tooltip = new MWF.xApplication.Selector.Group.Tooltip(document.body, this.node, null, {}, {
  121. axis : "y",
  122. hiddenDelay : 0,
  123. displayDelay : 300,
  124. groupId: this.data.id
  125. });
  126. if( this.selector.tooltips ){
  127. this.selector.tooltips.push(this.tooltip);
  128. }
  129. }
  130. }
  131. // loadSubItem: function(){
  132. // this.selector.orgAction.listPersonNested(this.data.id, function(json){
  133. // this.textNode.set("text", this.textNode.get("text")+" ("+json.data.length+")");
  134. // var usersText = "";
  135. // json.data.each(function(item){
  136. // usersText+=item.name+", ";
  137. // }.bind(this));
  138. //
  139. // var node = new Element("div", {"styles": {"max-width": "300px"}, "text": usersText});
  140. //
  141. // if (!Browser.Platform.ios){
  142. // this.tooltip = new mBox.Tooltip({
  143. // content: node,
  144. // setStyles: {content: {padding: 15, lineHeight: 20}},
  145. // attach: this.node,
  146. // transition: 'flyin'
  147. // });
  148. // }
  149. //
  150. // //this.textNode.set("title", usersText);
  151. // }.bind(this));
  152. // }
  153. });
  154. MWF.xApplication.Selector.Group.ItemSelected = new Class({
  155. Extends: MWF.xApplication.Selector.Person.ItemSelected,
  156. _getShowName: function(){
  157. return this.data.name;
  158. },
  159. _getTtiteText: function(){
  160. return this.data.name;
  161. },
  162. _setIcon: function(){
  163. var style = this.selector.options.style;
  164. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
  165. },
  166. loadSubItem: function(){
  167. if( !layout.mobile ){
  168. this.tooltip = new MWF.xApplication.Selector.Group.Tooltip(document.body, this.node, null, {}, {
  169. axis : "y",
  170. hiddenDelay : 0,
  171. displayDelay : 300,
  172. groupId: this.data.id
  173. });
  174. if( this.selector.tooltips ){
  175. this.selector.tooltips.push(this.tooltip);
  176. }
  177. }
  178. }
  179. // loadSubItem: function(){
  180. // this.selector.orgAction.listPersonNested(this.data.id, function(json){
  181. // this.textNode.set("text", this.textNode.get("text")+" ("+json.data.length+")");
  182. // var usersText = "";
  183. // json.data.each(function(item){
  184. // usersText+=item.name+", ";
  185. // }.bind(this));
  186. //
  187. // var node = new Element("div", {"styles": {"max-width": "300px"}, "text": usersText});
  188. //
  189. // if (!Browser.Platform.ios){
  190. // this.tooltip = new mBox.Tooltip({
  191. // content: node,
  192. // setStyles: {content: {padding: 15, lineHeight: 20}},
  193. // attach: this.node,
  194. // transition: 'flyin'
  195. // });
  196. // }
  197. //
  198. // //this.textNode.set("title", usersText);
  199. // }.bind(this));
  200. // }
  201. });
  202. MWF.xDesktop.requireApp("Template", "MTooltips", null, false);
  203. MWF.xApplication.Selector.Group.Tooltip = new Class({
  204. Extends: MTooltips,
  205. options:{
  206. nodeStyles: {
  207. "font-size" : "12px",
  208. "position" : "absolute",
  209. "max-width" : "300px",
  210. "min-width" : "180px",
  211. "z-index" : "1000001",
  212. "background-color" : "#fff",
  213. "padding" : "10px",
  214. "border-radius" : "8px",
  215. "box-shadow": "0 0 18px 0 #999999",
  216. "-webkit-user-select": "text",
  217. "-moz-user-select": "text",
  218. "line-height": "20px"
  219. },
  220. position : { //node 固定的位置
  221. x : "auto", //x轴上left center right, auto 系统自动计算
  222. y : "top" //y 轴上top middle bottom, auto 系统自动计算
  223. },
  224. priorityOfAuto :{
  225. x : [ "center", "right", "left" ], //当position x 为 auto 时候的优先级
  226. y : [ "middle", "top", "bottom" ] //当position y 为 auto 时候的优先级, "middle", "top", "bottom"
  227. },
  228. offset : {
  229. x : 0,
  230. y : 0
  231. },
  232. isFitToContainer : true,
  233. overflow : "scroll"
  234. },
  235. _loadCustom : function( callback ){
  236. o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({
  237. groupList: [this.options.groupId]
  238. }, function(json){
  239. var d = json.data[0];
  240. var text = "";
  241. if( d.personList && d.personList.length ){
  242. text += MWF.xApplication.Selector.LP.person + ": " + d.personList.map(function(item){
  243. return item.split("@")[0]
  244. }.bind(this)).join(",")+ "\n";
  245. }
  246. if( d.identityList && d.identityList.length ){
  247. text += MWF.xApplication.Selector.LP.identity + ": " + d.identityList.map(function(item){
  248. return item.split("@")[0]
  249. }.bind(this)).join(",")+ "\n";
  250. }
  251. if( d.unitList && d.unitList.length ){
  252. text += MWF.xApplication.Selector.LP.unit + ": " + d.unitList.map(function(item){
  253. return item.split("@")[0]
  254. }.bind(this)).join(",")+ "\n";
  255. }
  256. if( d.groupList && d.groupList.length ){
  257. text += MWF.xApplication.Selector.LP.group + ": " + d.groupList.map(function(item){
  258. return item.split("@")[0]
  259. }.bind(this)).join(",")+ "\n";
  260. }
  261. var node = new Element("div", {"styles": {"max-width": "300px", "white-space": "pre-line"}, "text": text});
  262. node.inject( this.contentNode );
  263. if(callback)callback();
  264. }.bind(this))
  265. },
  266. _customNode : function( node, contentNode ){
  267. this.fireEvent("customContent", [contentNode, node]);
  268. }
  269. });
  270. MWF.xApplication.Selector.Group.Filter = new Class({
  271. Implements: [Options, Events],
  272. options: {
  273. "style": "default",
  274. "groups": [],
  275. "roles": []
  276. },
  277. initialize: function(value, options){
  278. this.setOptions(options);
  279. this.value = value;
  280. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  281. },
  282. filter: function(value, callback){
  283. this.value = value;
  284. var key = this.value;
  285. if (this.options.groups.length || this.options.roles.length) key = this.getLikeKey(key);
  286. this.orgAction.listGroupByKey(function(json){
  287. data = json.data;
  288. if (callback) callback(data)
  289. }.bind(this), null, key);
  290. },
  291. getLikeKey : function( key ){
  292. var result = key;
  293. if (this.options.groups.length || this.options.roles.length){
  294. var array = [];
  295. this.options.groups.each( function(d){
  296. array.push( typeOf(d)==="object" ? d.distinguishedName : d );
  297. }.bind(this));
  298. var array2 = [];
  299. this.options.roles.each( function(d){
  300. array2.push( typeOf(d)==="object" ? d.distinguishedName : d );
  301. }.bind(this));
  302. result = {"key": key || "", "groupList": array, "roleList": array2};
  303. }
  304. return result;
  305. }
  306. });