MultipleSelector.js 34 KB

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