MultipleSelector.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "lp."+MWF.language, null, false);
  3. //MWF.xDesktop.requireApp("Selector", "Actions.RestActions", null, false);
  4. MWF.xApplication.Selector.MultipleSelector = new Class({
  5. Extends: MWF.widget.Common,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "types" : [],
  10. "count": 0,
  11. "title": "Select",
  12. "groups": [], //选person, group, role 时的范围
  13. "roles": [], //选选person, group, role 时的范围
  14. "units": [], //选 company, department, duty, identity 时的范围
  15. "values" : [],
  16. "zIndex": 1000,
  17. "expand": true,
  18. "contentUrl" : "", //和默认的页面布局不一样的话,可以传入页面布局HTML URL
  19. "injectToBody" : false //当传入HTML URL的时候是否插入到document.body, false的时候插入到this.container
  20. },
  21. initialize: function(container, options){
  22. this.setOptions(options);
  23. this.path = "/x_component_Selector/$Selector/";
  24. this.cssPath = "/x_component_Selector/$Selector/"+this.options.style+"/css.wcss";
  25. this._loadCss();
  26. this.container = $(container);
  27. this.lp = MWF.xApplication.Selector.LP;
  28. this.lastPeople = "";
  29. this.pageCount = "13";
  30. this.selectedItems = [];
  31. this.selectedItemsObject = {};
  32. this.items = [];
  33. this.selectors = {};
  34. },
  35. load: function(){
  36. if( this.options.contentUrl ){
  37. this.loadWithUrl()
  38. }else {
  39. if (layout.mobile) {
  40. this.loadMobile();
  41. } else {
  42. this.loadPc();
  43. }
  44. }
  45. this.fireEvent("load");
  46. },
  47. loadWithUrl : function(){
  48. var request = new Request.HTML({
  49. url: this.options.contentUrl,
  50. method: "GET",
  51. async: false,
  52. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  53. this.node = responseTree[0];
  54. this.loadContentWithHTML();
  55. this.fireEvent("load");
  56. }.bind(this),
  57. onFailure: function(xhr){
  58. alert(xhr);
  59. }
  60. });
  61. request.send();
  62. },
  63. loadContentWithHTML : function(){
  64. var container = this.options.injectToBody ? $(document.body) : this.container;
  65. if( !this.options.embedded ){
  66. this.css.maskNode["z-index"] = this.options.zIndex;
  67. this.maskRelativeNode = container;
  68. this.maskRelativeNode.mask({
  69. "destroyOnHide": true,
  70. "style": this.css.maskNode
  71. });
  72. }
  73. if( !this.options.embedded ) {
  74. this.node.setStyles(this.css.containerNodeMobile);
  75. this.node.setStyle("z-index", this.options.zIndex.toInt() + 1);
  76. }
  77. this.node.setStyle("height", ( container.getSize().y ) + "px");
  78. this.titleNode = this.node.getElement(".MWF_selector_titleNode");
  79. this.titleTextNode = this.node.getElement(".MWF_selector_titleTextNode");
  80. this.titleCancelActionNode = this.node.getElement(".MWF_selector_titleCancelActionNode");
  81. this.titleOkActionNode = this.node.getElement(".MWF_selector_titleOkActionNode");
  82. this.tabContainer = this.node.getElement(".MWF_selector_tabContainer");
  83. this.tabContainer.show();
  84. this.contentNode = this.node.getElement(".MWF_selector_contentNode");
  85. this.selectNode = this.node.getElement(".MWF_selector_selectNode");
  86. this.searchInputDiv = this.node.getElement(".MWF_selector_searchInputDiv");
  87. this.searchInput = this.node.getElement(".MWF_selector_searchInput");
  88. this.flatCategoryScrollNode = this.node.getElement(".MWF_selector_flatCategoryScrollNode");
  89. this.flatCategoryNode = this.node.getElement(".MWF_selector_flatCategoryNode");
  90. this.letterAreaNode = this.node.getElement(".MWF_selector_letterAreaNode");
  91. this.itemAreaScrollNode = this.node.getElement(".MWF_selector_itemAreaScrollNode");
  92. this.itemAreaNode = this.node.getElement(".MWF_selector_itemAreaNode");
  93. this.itemSearchAreaScrollNode = this.node.getElement(".MWF_selector_itemSearchAreaScrollNode");
  94. this.itemSearchAreaNode = this.node.getElement(".MWF_selector_itemSearchAreaNode");
  95. this.selectedScrollNode = this.node.getElement(".MWF_selector_selectedScrollNode");
  96. this.selectedNode = this.node.getElement(".MWF_selector_selectedNode");
  97. this.selectedItemSearchAreaNode = this.node.getElement(".MWF_selector_selectedItemSearchAreaNode");
  98. this.actionNode = this.node.getElement(".MWF_selector_actionNode");
  99. this.okActionNode = this.node.getElement(".MWF_selector_okActionNode");
  100. this.cancelActionNode = this.node.getElement(".MWF_selector_cancelActionNode");
  101. if (this.titleNode) this.titleNode.setStyles(this.css.titleNodeMobile);
  102. if (this.titleTextNode){
  103. this.titleTextNode.setStyles(this.css.titleTextNodeMobile);
  104. if(this.options.title)this.titleTextNode.set("text", this.options.title);
  105. }
  106. if (this.titleCancelActionNode) this.titleCancelActionNode.setStyles(this.css.titleCancelActionNodeMobile);
  107. if (this.titleOkActionNode) this.titleOkActionNode.setStyles(this.css.titleOkActionNodeMobile);
  108. if (this.tabContainer) this.tabContainer.setStyles(this.css.tabContainer);
  109. if (this.contentNode) this.contentNode.setStyles(this.css.contentNode);
  110. if (this.selectNode) this.selectNode.setStyles(this.css.selectNodeMobile);
  111. if (this.searchInputDiv) this.searchInputDiv.setStyles(this.css.searchInputDiv);
  112. if (this.searchInput) this.searchInput.setStyles( (this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput );
  113. if (this.letterAreaNode) this.letterAreaNode.setStyles(this.css.letterAreaNode);
  114. if (this.itemAreaScrollNode) this.itemAreaScrollNode.setStyles(this.css.itemAreaScrollNode);
  115. if (this.itemAreaNode) this.itemAreaNode.setStyles(this.css.itemAreaNode);
  116. if (this.itemSearchAreaScrollNode) this.itemSearchAreaScrollNode.setStyles(this.css.itemSearchAreaScrollNode);
  117. if (this.itemSearchAreaNode) this.itemSearchAreaNode.setStyles(this.css.itemAreaNode);
  118. if (this.selectedScrollNode) this.selectedScrollNode.setStyles(this.css.selectedScrollNode);
  119. if (this.selectedNode) this.selectedNode.setStyles(this.css.selectedNode);
  120. if (this.selectedItemSearchAreaNode) this.selectedItemSearchAreaNode.setStyles(this.css.itemAreaNode);
  121. if (this.actionNode) this.actionNode.setStyles(this.css.actionNode);
  122. if (this.okActionNode) {
  123. this.okActionNode.setStyles(this.css.okActionNode);
  124. this.okActionNode.set("text", MWF.SelectorLP.ok);
  125. }
  126. if (this.cancelActionNode) {
  127. this.cancelActionNode.setStyles(this.css.cancelActionNode);
  128. this.cancelActionNode.set("text", MWF.SelectorLP.cancel);
  129. }
  130. var size;
  131. if( this.options.injectToBody ){
  132. size = $(document.body).getSize();
  133. }else{
  134. var containerSize = this.container.getSize();
  135. var bodySize = $(document.body).getSize();
  136. if(containerSize.y === 0){
  137. containerSize.y = bodySize.y
  138. }
  139. size = {
  140. "x" : Math.min( containerSize.x, bodySize.x ),
  141. "y" : Math.min( containerSize.y, bodySize.y )
  142. };
  143. }
  144. var zoom = this.node.getStyle("zoom").toInt() || 0;
  145. if( zoom ){
  146. size.x = size.x * 100 / zoom;
  147. size.y = size.y * 100 / zoom;
  148. }
  149. this.node.setStyles({
  150. "width" : size.x+"px",
  151. "height" : size.y+"px"
  152. });
  153. var isFormWithAction = window.location.href.toLowerCase().indexOf("workmobilewithaction.html") > -1;
  154. var height;
  155. var height = size.y-this.getOffsetY( this.contentNode );
  156. if( this.tabContainer ){
  157. height = height - this.getOffsetY( this.tabContainer ) - ( this.tabContainer.getStyle("height").toInt() || 0 )
  158. }
  159. if( this.titleNode ){
  160. height = height - this.getOffsetY( this.titleNode ) - ( this.titleNode.getStyle("height").toInt() || 0 )
  161. }
  162. if( this.actionNode ){
  163. height = height - this.getOffsetY( this.actionNode ) - ( this.actionNode.getStyle("height").toInt() || 0 )
  164. }
  165. this.contentNode.setStyle("height", ""+height+"px");
  166. this.selectNode.setStyle("height", ""+height+"px");
  167. this.contentHeight = height;
  168. this.contentHTML = this.contentNode.get("html");
  169. this.contentNode.empty();
  170. this.loadContent();
  171. if( this.actionNode ){
  172. this.loadAction();
  173. }
  174. this.node.inject( container );
  175. if( !this.options.embedded ){
  176. this.node.setStyles({
  177. "top": "0px",
  178. "left": "0px"
  179. });
  180. }
  181. this.setEvent();
  182. },
  183. loadMobile: function(){
  184. this.maskRelativeNode = $(document.body);
  185. this.maskRelativeNode.mask({
  186. "destroyOnHide": true,
  187. "style": this.css.maskNode
  188. });
  189. this.node = new Element("div", {"styles": this.css.containerNodeMobile});
  190. this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
  191. this.node.setStyle("height", ( document.body.getSize().y ) + "px");
  192. this.titleNode = new Element("div", {
  193. "styles": this.css.titleNodeMobile
  194. }).inject(this.node);
  195. this.titleCancelActionNode = new Element("div", {
  196. "styles": this.css.titleCancelActionNodeMobile,
  197. "text": MWF.SelectorLP.back
  198. }).inject(this.titleNode);
  199. this.titleOkActionNode = new Element("div", {
  200. "styles": this.css.titleOkActionNodeMobile,
  201. "text": MWF.SelectorLP.ok
  202. }).inject(this.titleNode);
  203. this.titleTextNode = new Element("div", {
  204. "styles": {
  205. "margin": "0px 50px",
  206. "height": "40px",
  207. "padding": "0px 10px",
  208. "color": "#FFF",
  209. "font-weight": "bold",
  210. "font-size": "14px",
  211. "line-height": "40px"
  212. //"overflow" : "hidden"
  213. }
  214. //"text": this.options.title
  215. }).inject(this.titleNode);
  216. this.contentNode = new Element("div", {
  217. "styles": this.css.contentNode
  218. }).inject(this.node);
  219. var size = document.body.getSize();
  220. //var height = size.y-40;
  221. var height = size.y;
  222. this.contentNode.setStyle("height", ""+height+"px");
  223. this.contentNode.setStyle("margin-top", "2px");
  224. this.loadContent();
  225. this.node.inject(document.body);
  226. this.node.setStyles({
  227. "top": "0px",
  228. "left": "0px"
  229. });
  230. this.setEvent();
  231. },
  232. loadPc: function(){
  233. this.css.maskNode["z-index"] = this.options.zIndex;
  234. var position = this.container.getPosition(this.container.getOffsetParent());
  235. this.container.mask({
  236. "destroyOnHide": true,
  237. "style": this.css.maskNode,
  238. "useIframeShim": true,
  239. "iframeShimOptions": {"browsers": true},
  240. "onShow": function(){
  241. this.shim.shim.setStyles({
  242. "opacity": 0,
  243. "top": ""+position.y+"px",
  244. "left": ""+position.x+"px"
  245. });
  246. }
  247. });
  248. // this.container.setStyle("z-index", this.options.zIndex);
  249. this.node = new Element("div", {
  250. "styles": this.css.containerNode_multiple //this.isSingle() ? this.css.containerNodeSingle_multiple : this.css.containerNode_multiple
  251. });
  252. this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
  253. this.titleNode = new Element("div", {
  254. "styles": this.css.titleNode
  255. }).inject(this.node);
  256. this.titleActionNode = new Element("div", {
  257. "styles": this.css.titleActionNode
  258. }).inject(this.titleNode);
  259. this.titleTextNode = new Element("div", {
  260. "styles": this.css.titleTextNode,
  261. "text": this.options.title
  262. }).inject(this.titleNode);
  263. this.contentNode = new Element("div", {
  264. "styles": this.css.contentNode
  265. }).inject(this.node);
  266. this.actionNode = new Element("div", {
  267. "styles": this.css.actionNode
  268. }).inject(this.node);
  269. //if ( this.isSingle() ) this.actionNode.setStyle("text-align", "center");
  270. this.loadAction();
  271. this.node.inject(this.container);
  272. if( this.options.width || this.options.height ){
  273. this.setSize()
  274. }
  275. this.loadContent();
  276. this.node.position({
  277. relativeTo: this.container,
  278. position: "center",
  279. edge: "center"
  280. });
  281. var size = this.container.getSize();
  282. var nodeSize = this.node.getSize();
  283. this.node.makeDraggable({
  284. "handle": this.titleNode,
  285. "limit": {
  286. "x": [0, size.x-nodeSize.x],
  287. "y": [0, size.y-nodeSize.y]
  288. }
  289. });
  290. this.setEvent();
  291. },
  292. isSingle : function(){
  293. var single = true;
  294. var flag = true;
  295. this.options.types.each( function( type, index ){
  296. var opt = this.options[ type + "Options" ];
  297. if( opt ){
  298. if( Number.convert(opt.count) !== 1 )single = false;
  299. flag = false;
  300. }
  301. }.bind(this));
  302. if( flag ){
  303. single = Number.convert( this.options.count ) === 1;
  304. }
  305. return single;
  306. },
  307. setEvent: function(){
  308. if (this.titleActionNode){
  309. this.titleActionNode.addEvent("click", function(){
  310. this.close();
  311. }.bind(this));
  312. }
  313. if (this.titleCancelActionNode){
  314. this.titleCancelActionNode.addEvent("click", function(){
  315. this.close();
  316. }.bind(this));
  317. }
  318. if (this.titleOkActionNode){
  319. this.titleOkActionNode.addEvent("click", function(){
  320. this.fireEvent("complete", [this.getSelectedItems(), this.getSelectedItemsObject() ]);
  321. this.close();
  322. }.bind(this));
  323. }
  324. },
  325. close: function(){
  326. this.fireEvent("close");
  327. this.node.destroy();
  328. (this.maskRelativeNode || this.container).unmask();
  329. MWF.release(this);
  330. delete this;
  331. },
  332. loadAction: function(){
  333. if( !this.okActionNode ) {
  334. this.okActionNode = new Element("button", {
  335. "styles": this.css.okActionNode,
  336. "text": "确定"
  337. }).inject(this.actionNode);
  338. }
  339. if( !this.cancelActionNode ) {
  340. this.cancelActionNode = new Element("button", {
  341. "styles": this.css.cancelActionNode,
  342. "text": "取消"
  343. }).inject(this.actionNode);
  344. }
  345. this.okActionNode.addEvent("click", function(){
  346. this.fireEvent("complete", [this.getSelectedItems(), this.getSelectedItemsObject() ]);
  347. this.close();
  348. }.bind(this));
  349. this.cancelActionNode.addEvent("click", function(){this.fireEvent("cancel"); this.close();}.bind(this));
  350. },
  351. loadContent: function(){
  352. if( this.options.contentUrl ){
  353. MWF.require("MWF.widget.Tab", function(){
  354. this.tab = new MWF.widget.Tab( this.tabContainer || this.titleTextNode, {"style": this.options.tabStyle });
  355. var width;
  356. if( this.tabContainer ){
  357. var borderWidth = 0;
  358. if( this.tab.css.tabNode ){
  359. if( this.tab.css.tabNode["border-left"] )borderWidth += this.tab.css.tabNode["border-left"].toInt();
  360. if( this.tab.css.tabNode["border-right"] )borderWidth += this.tab.css.tabNode["border-right"].toInt();
  361. }
  362. var tabWidth = "calc("+( 100 / this.options.types.length ) +"% - " + (borderWidth+"px")+")";
  363. if( this.tab.css.tabNode ){
  364. this.tab.css.tabNode["width"] = tabWidth;
  365. }
  366. if( this.tab.css.tabNodeCurrent ){
  367. this.tab.css.tabNodeCurrent["width"] = tabWidth;
  368. }
  369. }else{
  370. width = this.container.getSize().x - 160; //160是确定和返回按钮的宽度
  371. var w = width / this.options.types.length - 2;
  372. var tabWidth = w < 60 ? w : 60;
  373. if( this.tab.css.tabNode ){
  374. this.tab.css.tabNode["min-width"] = tabWidth+"px";
  375. }
  376. if( this.tab.css.tabNodeCurrent ){
  377. this.tab.css.tabNodeCurrent["min-width"] = tabWidth+"px";
  378. }
  379. }
  380. this.tab.load();
  381. this.tab.contentNodeContainer.inject(this.contentNode);
  382. }.bind(this), false);
  383. }else if (layout.mobile){
  384. MWF.require("MWF.widget.Tab", function(){
  385. this.tab = new MWF.widget.Tab( this.tabContainer || this.titleTextNode, {"style": "orgMobile" });
  386. var width = this.container.getSize().x - 160; //160是确定和返回按钮的宽度
  387. var w = width / this.options.types.length - 2;
  388. var tabWidth = w < 60 ? w : 60;
  389. if( this.tab.css.tabNode ){
  390. this.tab.css.tabNode["min-width"] = tabWidth+"px";
  391. }
  392. if( this.tab.css.tabNodeCurrent ){
  393. this.tab.css.tabNodeCurrent["min-width"] = tabWidth+"px";
  394. }
  395. this.tab.load();
  396. this.tab.contentNodeContainer.inject(this.contentNode);
  397. }.bind(this), false);
  398. }else{
  399. MWF.require("MWF.widget.Tab", function(){
  400. this.tab = new MWF.widget.Tab(this.contentNode, {"style": this.options.tabStyle || "default" });
  401. this.tab.load();
  402. }.bind(this), false);
  403. }
  404. var isFormWithAction = window.location.href.toLowerCase().indexOf("workmobilewithaction.html") > -1;
  405. this.options.types.each( function( type, index ){
  406. var options = Object.clone( this.options );
  407. if( type.toLowerCase()==="identity" ){
  408. options.expand = false;
  409. }
  410. if( this.options[ type + "Options" ] ){
  411. options = Object.merge( options, this.options[ type + "Options" ] );
  412. }
  413. var pageNode = new Element( "div" ).inject( this.contentNode );
  414. var tab = this.tab.addTab( pageNode, this.lp[type], false );
  415. if( index === 0 && this.contentHeight && !this.tabContainer ){
  416. //this.contentHeight = this.contentHeight - this.getOffsetY( tab.tabContainer ) - tab.tabContainer.getStyle("height").toInt();
  417. this.contentHeight = this.contentHeight - this.getOffsetY( tab.tab.tabNodeContainer ) - tab.tab.tabNodeContainer.getStyle("height").toInt();
  418. }
  419. var t = type.capitalize();
  420. if ((type.toLowerCase()==="unit") && ( options.unitType)){
  421. t = "UnitWithType";
  422. }
  423. if ((type.toLowerCase()==="identity") && (( options.dutys) && options.dutys.length && options.categoryType.toLowerCase()==="duty")){
  424. t = "IdentityWidthDuty";
  425. }
  426. MWF.xDesktop.requireApp("Selector", t, function(){
  427. if( type.toLowerCase()==="identity" && options.resultType && options.resultType === "person" ){
  428. options.values = this.getValueByType( options.values, [ type, "person" ] );
  429. }else{
  430. options.values = this.getValueByType( options.values, type );
  431. }
  432. //options.values = [];
  433. //if( options.multipleValues[type] ){
  434. // options.values = options.multipleValues[type];
  435. //}
  436. //if( options[type+"Values"] && options[type+"Values"].length ){
  437. // options.values = options.values.concat( options[type+"Values"] )
  438. //}
  439. //
  440. //options.names = [];
  441. //if( options.multipleNames[type] ){
  442. // options.names = options.multipleNames[type];
  443. //}
  444. //if( options[type+"Names"] && options[type+"Names"].length ){
  445. // options.names = options.names.concat( options[type+"Names"] )
  446. //}
  447. this.selectors[t] = new MWF.xApplication.Selector[t](this.container, options );
  448. var selector = this.selectors[t];
  449. if( this.options.contentUrl ){
  450. pageNode.set("html", this.contentHTML);
  451. pageNode.setStyle("height", this.contentHeight);
  452. selector.selectNode = pageNode.getElement(".MWF_selector_selectNode");
  453. selector.searchInputDiv = pageNode.getElement(".MWF_selector_searchInputDiv");
  454. selector.searchInput = pageNode.getElement(".MWF_selector_searchInput");
  455. selector.flatCategoryScrollNode = pageNode.getElement(".MWF_selector_flatCategoryScrollNode");
  456. selector.flatCategoryNode = pageNode.getElement(".MWF_selector_flatCategoryNode");
  457. selector.letterAreaNode = pageNode.getElement(".MWF_selector_letterAreaNode");
  458. selector.itemAreaScrollNode = pageNode.getElement(".MWF_selector_itemAreaScrollNode");
  459. selector.itemAreaNode = pageNode.getElement(".MWF_selector_itemAreaNode");
  460. selector.itemSearchAreaScrollNode = pageNode.getElement(".MWF_selector_itemSearchAreaScrollNode");
  461. selector.itemSearchAreaNode = pageNode.getElement(".MWF_selector_itemSearchAreaNode");
  462. selector.selectedScrollNode = pageNode.getElement(".MWF_selector_selectedScrollNode");
  463. selector.selectedNode = pageNode.getElement(".MWF_selector_selectedNode");
  464. selector.selectedItemSearchAreaNode = pageNode.getElement(".MWF_selector_selectedItemSearchAreaNode");
  465. if( this.options.flatCategory && selector.flatCategoryScrollNode ){
  466. selector.isFlatCategory = true;
  467. selector.flatSubCategoryNodeList = [];
  468. }
  469. selector.loadContent( pageNode, true );
  470. if( t.toLowerCase() == "person" || t.toLowerCase() == "group" ){
  471. var startY=0, y=0;
  472. var itemAreaScrollNode = selector.itemAreaScrollNode;
  473. itemAreaScrollNode.addEvents({
  474. 'touchstart' : function( ev ){
  475. var touch = ev.touches[0]; //获取第一个触点
  476. startY = Number(touch.pageY); //页面触点Y坐标
  477. }.bind(this),
  478. 'touchmove' : function(ev){
  479. var touch = ev.touches[0]; //获取第一个触点
  480. y = Number(touch.pageY); //页面触点Y坐标
  481. }.bind(this),
  482. 'touchend' : function( ev ){
  483. if (startY - y > 10) { //向上滑动超过10像素
  484. var obj = this.selectors.Person;
  485. obj._scrollEvent( obj.itemAreaScrollNode.scrollTop + 100 );
  486. }
  487. startY = 0;
  488. y = 0;
  489. }.bind(this)
  490. })
  491. }
  492. }else{
  493. if( this.contentWidth )options.width = this.contentWidth;
  494. if( this.contentHeight )options.height = this.contentHeight;
  495. this.selectors[t].loadContent( pageNode );
  496. this.selectors[t].setSize();
  497. if( layout.mobile ){
  498. var containerSize = this.container.getSize();
  499. var bodySize = $(document.body).getSize();
  500. var size = {
  501. "x" : Math.min( containerSize.x, bodySize.x ),
  502. "y" : Math.min( containerSize.y, bodySize.y )
  503. };
  504. var height;
  505. if( isFormWithAction ){
  506. height = size.y-40-20-6-20;
  507. }else{
  508. height = size.y;
  509. }
  510. if(this.selectors[t].selectNode){
  511. this.selectors[t].selectNode.setStyle("height", ""+height+"px");
  512. }
  513. if( isFormWithAction ){
  514. height = size.y-40-20-78 - 20;
  515. }else{
  516. height = size.y-42-31-40;
  517. }
  518. height = height - 5;
  519. var itemAreaScrollNode = this.selectors[t].itemAreaScrollNode;
  520. if( itemAreaScrollNode ){
  521. itemAreaScrollNode.setStyle("height", ""+height+"px");
  522. }
  523. if( t.toLowerCase() == "person" || t.toLowerCase() == "group" ){
  524. var startY=0, y=0;
  525. itemAreaScrollNode.addEvents({
  526. 'touchstart' : function( ev ){
  527. var touch = ev.touches[0]; //获取第一个触点
  528. startY = Number(touch.pageY); //页面触点Y坐标
  529. }.bind(this),
  530. 'touchmove' : function(ev){
  531. var touch = ev.touches[0]; //获取第一个触点
  532. y = Number(touch.pageY); //页面触点Y坐标
  533. }.bind(this),
  534. 'touchend' : function( ev ){
  535. if (startY - y > 10) { //向上滑动超过10像素
  536. var obj = this.selectors.Person;
  537. obj._scrollEvent( obj.itemAreaScrollNode.scrollTop + 100 );
  538. }
  539. startY = 0;
  540. y = 0;
  541. }.bind(this)
  542. })
  543. }
  544. }else{
  545. //if( !this.isSingle() && Number.convert( options.count ) === 1 ){
  546. // this.selectors[t].selectNode.setStyles({
  547. // "float" : "none",
  548. // "margin-left" : "auto",
  549. // "margin-right" : "auto"
  550. // })
  551. //}
  552. }
  553. }
  554. if( index == 0 )tab.showIm();
  555. }.bind(this));
  556. }.bind(this));
  557. },
  558. getValueByType : function( values, type ){
  559. var result = [];
  560. values = typeOf( values == "array" ) ? values : [values];
  561. var types = typeOf( type == "array" ) ? type : [type];
  562. values.each( function( data ){
  563. if( typeOf( data ) == "string" ){
  564. var dn = data;
  565. }else{
  566. var dn = data.distinguishedName;
  567. }
  568. if (dn && type ){
  569. var flag = dn.substr(dn.length-1, 1);
  570. switch (flag.toLowerCase()){
  571. case "i":
  572. if( type == "identity" || types.contains( "identity" ) )result.push( data );
  573. break;
  574. case "p":
  575. if( type == "person" || types.contains( "person" ) )result.push( data );
  576. break;
  577. case "u":
  578. if( type == "unit" )result.push( data );
  579. break;
  580. case "g":
  581. if( type == "group" )result.push( data );
  582. break;
  583. case "r":
  584. if( type == "role" )result.push( data );
  585. break;
  586. default:
  587. if( type == "person" )result.push( data );
  588. break;
  589. //result.push( data );
  590. }
  591. }else{
  592. //result.push( data );
  593. }
  594. });
  595. return result;
  596. },
  597. emptySelectedItems : function(){
  598. for( var key in this.selectors ){
  599. var selector = this.selectors[key];
  600. if( selector.selectedItems && selector.selectedItems.length > 0 ){
  601. selector.emptySelectedItems();
  602. }
  603. }
  604. },
  605. getSelectedItems : function(){
  606. this.selectedItems = [];
  607. for( var key in this.selectors ){
  608. var selector = this.selectors[key];
  609. if( selector.selectedItems && selector.selectedItems.length > 0 ){
  610. this.selectedItems = this.selectedItems.concat( selector.selectedItems );
  611. }
  612. }
  613. return this.selectedItems;
  614. },
  615. getSelectedItemsObject : function(){
  616. this.selectedItemsObject = {};
  617. for( var key in this.selectors ){
  618. var selector = this.selectors[key];
  619. if( selector.selectedItems && selector.selectedItems.length > 0 ){
  620. this.selectedItemsObject[key.toLowerCase()] = selector.selectedItems;
  621. }
  622. }
  623. return this.selectedItemsObject;
  624. },
  625. getOffsetX : function(node){
  626. return (node.getStyle("margin-left").toInt() || 0 )+
  627. (node.getStyle("margin-right").toInt() || 0 ) +
  628. (node.getStyle("padding-left").toInt() || 0 ) +
  629. (node.getStyle("padding-right").toInt() || 0 ) +
  630. (node.getStyle("border-left-width").toInt() || 0 ) +
  631. (node.getStyle("border-right-width").toInt() || 0 );
  632. },
  633. getOffsetY : function(node){
  634. return (node.getStyle("margin-top").toInt() || 0 ) +
  635. (node.getStyle("margin-bottom").toInt() || 0 ) +
  636. (node.getStyle("padding-top").toInt() || 0 ) +
  637. (node.getStyle("padding-bottom").toInt() || 0 )+
  638. (node.getStyle("border-top-width").toInt() || 0 ) +
  639. (node.getStyle("border-bottom-width").toInt() || 0 );
  640. },
  641. setSize : function(){
  642. if( !this.options.width && !this.options.height )return;
  643. if( this.options.width && this.options.width === "auto" ){
  644. //if (this.options.count.toInt() !== 1){
  645. this.node.setStyle("width", "auto");
  646. this.contentWidth = "auto";
  647. }else if( this.options.width && typeOf( this.options.width.toInt() ) === "number" ){
  648. var nodeWidth = this.options.width.toInt() - this.getOffsetX(this.node);
  649. this.node.setStyle("width", nodeWidth);
  650. if( this.contentNode ){
  651. nodeWidth = nodeWidth - this.getOffsetX( this.contentNode );
  652. }
  653. this.contentWidth = nodeWidth;
  654. }
  655. if( this.options.height && typeOf( this.options.height.toInt() ) === "number" ){
  656. var nodeHeight = this.options.height.toInt() - this.getOffsetY(this.node);
  657. this.node.setStyle("height", nodeHeight);
  658. if( this.titleNode ){
  659. nodeHeight = nodeHeight - this.getOffsetY( this.titleNode ) - this.titleNode.getStyle("height").toInt();
  660. }
  661. if( this.actionNode ){
  662. nodeHeight = nodeHeight - this.getOffsetY( this.actionNode ) - this.actionNode.getStyle("height").toInt();
  663. }
  664. if( this.contentNode ){
  665. nodeHeight = nodeHeight - this.getOffsetY( this.contentNode );
  666. }
  667. this.contentHeight = nodeHeight;
  668. }
  669. }
  670. });
  671. MWF.xApplication.Selector.MultipleSelector.Filter = new Class({
  672. Implements: [Options, Events],
  673. options: {
  674. "types" : [],
  675. "groups": [], //选person, group, role 时的范围
  676. "roles": [], //选选person, group, role 时的范围
  677. "units": [] //选 company, department, duty, identity 时的范围
  678. },
  679. initialize: function(value, options){
  680. this.setOptions(options);
  681. this.value = value;
  682. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  683. this.selectors = {};
  684. this.options.types.each( function( type, index ){
  685. var opt = Object.clone( this.options );
  686. if( this.options[ type + "Options" ] ){
  687. opt = Object.merge( opt, this.options[ type + "Options" ] );
  688. }
  689. var t = type.capitalize();
  690. if ((type.toLowerCase()==="unit") && ( opt.unitType)){
  691. t = "UnitWithType";
  692. }
  693. if ((type.toLowerCase()==="identity") && ((opt.dutys) && opt.dutys.length)){
  694. t = "IdentityWidthDuty";
  695. }
  696. MWF.xDesktop.requireApp("Selector", t, function(){
  697. this.selectors[t] = new MWF.xApplication.Selector[t].Filter(this.value, opt);
  698. }.bind(this), false);
  699. }.bind(this));
  700. },
  701. filter: function(value, callback){
  702. this.value = value;
  703. var key = this.value;
  704. this.filterData = [];
  705. this.filterCount = 0;
  706. for (i in this.selectors){
  707. this.selectors[i].filter(value, function(data){
  708. this.filterData = this.filterData.concat(data);
  709. this.filterCount++;
  710. this.endFilter(callback);
  711. }.bind(this))
  712. }
  713. //
  714. // this.orgAction.listPersonByKey(function(json){
  715. // data = json.data;
  716. // if (callback) callback(data)
  717. // }.bind(this), failure, key);
  718. },
  719. endFilter: function(callback){
  720. if (this.filterCount>=Object.keys(this.selectors).length){
  721. if (callback) callback(this.filterData);
  722. }
  723. }
  724. });