MultipleSelector.js 34 KB

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