MultipleSelector.js 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  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. if(!MWF.O2Selector)MWF.O2Selector = {};
  5. MWF.xApplication.Selector.MultipleSelector = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. "types" : [],
  11. "count": 0,
  12. "title": "",
  13. "groups": [], //选person, group, role 时的范围
  14. "roles": [], //选选person, group, role 时的范围
  15. "units": [], //选 company, department, duty, identity 时的范围
  16. "values" : [],
  17. "zIndex": 1000,
  18. "expand": true,
  19. "contentUrl" : "", //和默认的页面布局不一样的话,可以传入页面布局HTML URL
  20. "injectToBody" : false //当传入HTML URL的时候是否插入到document.body, false的时候插入到this.container
  21. },
  22. initialize: function(container, options){
  23. this.active = true;
  24. if (!options.title) options.title = MWF.xApplication.Selector.LP.multiSelectTitle;
  25. this.setOptions(options);
  26. this.optionsArg = options;
  27. this.path = "../x_component_Selector/$Selector/";
  28. this.cssPath = "../x_component_Selector/$Selector/"+this.options.style+"/css.wcss";
  29. this._loadCss();
  30. this.container = $(container);
  31. if( ["flow"].contains(this.options.style) ){
  32. this.options.contentUrl = this.path + this.options.style + "/"+( this.options.embedded ? "selector_embedded":"selector" )+".html";
  33. this.options.level1Indent = 10;
  34. this.options.indent = 20;
  35. this.options.tabStyle = "blue_flat";
  36. }
  37. this.lp = MWF.xApplication.Selector.LP;
  38. this.lastPeople = "";
  39. this.pageCount = "13";
  40. this.selectedItems = [];
  41. this.selectedItemsObject = {};
  42. this.items = [];
  43. this.selectors = {};
  44. },
  45. load: function(){
  46. if( this.options.contentUrl ){
  47. this.loadWithUrl();
  48. }else {
  49. if (layout.mobile) {
  50. this.loadMobile();
  51. } else {
  52. this.loadPc();
  53. }
  54. this.fireEvent("load");
  55. }
  56. },
  57. loadWithUrl : function(){
  58. if( this.options.style === "flow" ){
  59. var node = new Element("div");
  60. node.loadHtml( this.options.contentUrl, {
  61. "bind": { "lp": MWF.xApplication.Selector.LP, "options": this.options },
  62. "module": this
  63. },function () {
  64. this.node = node.getFirst();
  65. this.node.loadCss("../x_component_Selector/$Selector/flow/style.css");
  66. this.loadContentWithHTML();
  67. this.fireEvent("load");
  68. }.bind(this));
  69. }else{
  70. var request = new Request.HTML({
  71. url: this.options.contentUrl,
  72. method: "GET",
  73. async: false,
  74. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  75. this.node = responseTree[0];
  76. this.loadContentWithHTML();
  77. this.fireEvent("load");
  78. }.bind(this),
  79. onFailure: function(xhr){
  80. alert(xhr);
  81. }
  82. });
  83. request.send();
  84. }
  85. },
  86. loadContentWithHTML : function(){
  87. var container = this.options.injectToBody ? $(document.body) : this.container;
  88. if( !this.options.embedded ){
  89. this.css.maskNode["z-index"] = this.options.zIndex;
  90. this.maskRelativeNode = container;
  91. this.maskRelativeNode.mask({
  92. "destroyOnHide": true,
  93. "style": this.css.maskNode
  94. });
  95. }
  96. if( !this.options.embedded ) {
  97. this.node.setStyles( layout.mobile ? this.css.containerNodeMobile : this.css.containerNode );
  98. this.node.setStyle("z-index", this.options.zIndex.toInt() + 1);
  99. }
  100. if( layout.mobile ){
  101. this.node.setStyle("height", ( container.getSize().y ) + "px");
  102. }
  103. this.titleNode = this.node.getElement(".MWF_selector_titleNode");
  104. this.titleTextNode = this.node.getElement(".MWF_selector_titleTextNode");
  105. this.titleCancelActionNode = this.node.getElement(".MWF_selector_titleCancelActionNode");
  106. this.titleOkActionNode = this.node.getElement(".MWF_selector_titleOkActionNode");
  107. this.titleActionNode = this.node.getElement(".MWF_selector_titleActionNode");
  108. this.tabContainer = this.node.getElement(".MWF_selector_tabContainer");
  109. this.tabContainer.show();
  110. this.contentNode = this.node.getElement(".MWF_selector_contentNode");
  111. this.selectNode = this.node.getElement(".MWF_selector_selectNode");
  112. this.selectTopNode = this.node.getElement(".MWF_selector_selectTopNode");
  113. this.selectTopTextNode = this.node.getElement(".MWF_selector_selectTopTextNode");
  114. this.searchInputDiv = this.node.getElement(".MWF_selector_searchInputDiv");
  115. this.searchInput = this.node.getElement(".MWF_selector_searchInput");
  116. this.searchCancelAction = this.node.getElement(".MWF_selector_searchCancelAction");
  117. this.letterActionNode = this.node.getElement(".MWF_selector_letterActionNode");
  118. this.flatCategoryScrollNode = this.node.getElement(".MWF_selector_flatCategoryScrollNode");
  119. this.flatCategoryNode = this.node.getElement(".MWF_selector_flatCategoryNode");
  120. this.letterAreaNode = this.node.getElement(".MWF_selector_letterAreaNode");
  121. this.itemAreaScrollNode = this.node.getElement(".MWF_selector_itemAreaScrollNode");
  122. this.itemAreaNode = this.node.getElement(".MWF_selector_itemAreaNode");
  123. this.itemSearchAreaScrollNode = this.node.getElement(".MWF_selector_itemSearchAreaScrollNode");
  124. this.itemSearchAreaNode = this.node.getElement(".MWF_selector_itemSearchAreaNode");
  125. this.selectedContainerNode = this.node.getElement(".MWF_selector_selectedContainerNode");
  126. this.selectedTopNode = this.node.getElement(".MWF_selector_selectedTopNode");
  127. this.selectedTopTextNode = this.node.getElement(".MWF_selector_selectedTopTextNode");
  128. this.emptySelectedNode = this.node.getElement(".MWF_selector_emptySelectedNode");
  129. this.selectedScrollNode = this.node.getElement(".MWF_selector_selectedScrollNode");
  130. this.selectedNode = this.node.getElement(".MWF_selector_selectedNode");
  131. this.selectedItemSearchAreaNode = this.node.getElement(".MWF_selector_selectedItemSearchAreaNode");
  132. this.actionNode = this.node.getElement(".MWF_selector_actionNode");
  133. this.okActionNode = this.node.getElement(".MWF_selector_okActionNode");
  134. this.cancelActionNode = this.node.getElement(".MWF_selector_cancelActionNode");
  135. if (this.titleNode) this.titleNode.setStyles( layout.mobile ? this.css.titleNodeMobile : this.css.titleNode );
  136. if (this.titleTextNode){
  137. this.titleTextNode.setStyles(layout.mobile ? this.css.titleTextNodeMobile : this.css.titleTextNode);
  138. if(this.options.title)this.titleTextNode.set("text", this.options.title);
  139. }
  140. if (this.titleActionNode)this.titleActionNode.setStyles(this.css.titleActionNode);
  141. if (this.titleCancelActionNode) this.titleCancelActionNode.setStyles(this.css.titleCancelActionNodeMobile);
  142. if (this.titleOkActionNode) this.titleOkActionNode.setStyles(this.css.titleOkActionNodeMobile);
  143. if (this.tabContainer) this.tabContainer.setStyles(this.css.tabContainer);
  144. if (this.contentNode) this.contentNode.setStyles(this.css.contentNode);
  145. if (this.selectNode) this.selectNode.setStyles( layout.mobile ? this.css.selectNodeMobile : this.css.selectNode);
  146. if (this.selectTopNode)this.selectTopNode.setStyles(this.css.selectTopNode);
  147. if (this.selectTopTextNode)this.selectTopTextNode.setStyles(this.css.selectTopTextNode);
  148. if (this.searchInputDiv) this.searchInputDiv.setStyles(this.css.searchInputDiv);
  149. if (this.searchInput) this.searchInput.setStyles( (this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput );
  150. if (this.searchCancelAction) this.searchCancelAction.setStyles(this.css.searchCancelAction);
  151. if (this.letterActionNode) this.letterActionNode.setStyles(this.css.letterActionNode);
  152. if (this.letterAreaNode) this.letterAreaNode.setStyles(this.css.letterAreaNode);
  153. if (this.itemAreaScrollNode) this.itemAreaScrollNode.setStyles(this.css.itemAreaScrollNode);
  154. if (this.itemAreaNode) this.itemAreaNode.setStyles(this.css.itemAreaNode);
  155. if (this.itemSearchAreaScrollNode) this.itemSearchAreaScrollNode.setStyles(this.css.itemSearchAreaScrollNode);
  156. if (this.itemSearchAreaNode) this.itemSearchAreaNode.setStyles(this.css.itemAreaNode);
  157. if (this.selectedContainerNode)this.selectedContainerNode.setStyles(this.css.selectedContainerNode);
  158. if (this.selectedTopNode)this.selectedTopNode.setStyles(this.css.selectedTopNode);
  159. if (this.selectedTopTextNode)this.selectedTopTextNode.setStyles(this.css.selectedTopTextNode);
  160. if (this.emptySelectedNode)this.emptySelectedNode.setStyles(this.css.selectedTopActionNode);
  161. if (this.selectedScrollNode) this.selectedScrollNode.setStyles(this.css.selectedScrollNode);
  162. if (this.selectedNode) this.selectedNode.setStyles(this.css.selectedNode);
  163. if (this.selectedItemSearchAreaNode) this.selectedItemSearchAreaNode.setStyles(this.css.itemAreaNode);
  164. if (this.actionNode) this.actionNode.setStyles(this.css.actionNode);
  165. if (this.okActionNode) {
  166. this.okActionNode.setStyles(this.css.okActionNode);
  167. this.okActionNode.set("text", MWF.SelectorLP.ok);
  168. }
  169. if (this.cancelActionNode) {
  170. this.cancelActionNode.setStyles(this.css.cancelActionNode);
  171. this.cancelActionNode.set("text", MWF.SelectorLP.cancel);
  172. }
  173. this.node.inject( container );
  174. var size;
  175. if( this.options.injectToBody ){
  176. size = $(document.body).getSize();
  177. }else if( layout.mobile ){
  178. var containerSize = this.container.getSize();
  179. var bodySize = $(document.body).getSize();
  180. if(containerSize.y === 0){
  181. containerSize.y = bodySize.y
  182. }
  183. size = {
  184. "x" : Math.min( containerSize.x, bodySize.x ),
  185. "y" : Math.min( containerSize.y, bodySize.y )
  186. };
  187. var zoom = this.node.getStyle("zoom").toInt();
  188. zoom = zoom ? (zoom * 100) : 0;
  189. if( zoom ){
  190. size.x = size.x * 100 / zoom;
  191. size.y = size.y * 100 / zoom;
  192. }
  193. this.node.setStyles({
  194. "width" : size.x+"px",
  195. "height" : size.y+"px"
  196. });
  197. }else{
  198. debugger;
  199. if( this.options.width || this.options.height ){
  200. this.setSize()
  201. }
  202. this.node.position({
  203. relativeTo: this.container,
  204. position: "center",
  205. edge: "center"
  206. });
  207. size = this.container.getSize();
  208. var nodeSize = this.node.getSize();
  209. this.node.makeDraggable({
  210. "handle": this.titleNode,
  211. "limit": {
  212. "x": [0, size.x - nodeSize.x],
  213. "y": [0, size.y - nodeSize.y]
  214. }
  215. });
  216. }
  217. var isFormWithAction = window.location.href.toLowerCase().indexOf("workmobilewithaction.html") > -1;
  218. var height = this.node.getSize().y-this.getOffsetY( this.contentNode );
  219. if( this.tabContainer ){
  220. height = height - this.getOffsetY( this.tabContainer ) - ( this.tabContainer.getStyle("height").toInt() || 0 )
  221. }
  222. if( this.titleNode ){
  223. height = height - this.getOffsetY( this.titleNode ) - ( this.titleNode.getStyle("height").toInt() || 0 )
  224. }
  225. if( this.actionNode ){
  226. height = height - this.getOffsetY( this.actionNode ) - ( this.actionNode.getStyle("height").toInt() || 0 )
  227. }
  228. this.contentNode.setStyle("height", ""+height+"px");
  229. this.selectNode.setStyle("height", ""+height+"px");
  230. this.contentHeight = height;
  231. this.contentHTML = this.contentNode.get("html");
  232. this.contentNode.empty();
  233. this.loadContent();
  234. if( this.actionNode ){
  235. this.loadAction();
  236. }
  237. if( !this.options.embedded && layout.mobile ){
  238. this.node.setStyles({
  239. "top": "0px",
  240. "left": "0px"
  241. });
  242. }
  243. this.setEvent();
  244. },
  245. loadMobile: function(){
  246. this.maskRelativeNode = $(document.body);
  247. this.maskRelativeNode.mask({
  248. "destroyOnHide": true,
  249. "style": this.css.maskNode
  250. });
  251. this.node = new Element("div", {"styles": this.css.containerNodeMobile});
  252. this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
  253. this.node.setStyle("height", ( $(document.body).getSize().y ) + "px");
  254. this.titleNode = new Element("div", {
  255. "styles": this.css.titleNodeMobile
  256. }).inject(this.node);
  257. this.titleCancelActionNode = new Element("div", {
  258. "styles": this.css.titleCancelActionNodeMobile,
  259. "text": MWF.SelectorLP.back
  260. }).inject(this.titleNode);
  261. this.titleOkActionNode = new Element("div", {
  262. "styles": this.css.titleOkActionNodeMobile,
  263. "text": MWF.SelectorLP.ok
  264. }).inject(this.titleNode);
  265. this.titleTextNode = new Element("div", {
  266. "styles": {
  267. "margin": "0px 50px",
  268. "height": "40px",
  269. "padding": "0px 10px",
  270. "color": "#FFF",
  271. "font-weight": "bold",
  272. "font-size": "14px",
  273. "line-height": "40px"
  274. //"overflow" : "hidden"
  275. }
  276. //"text": this.options.title
  277. }).inject(this.titleNode);
  278. this.contentNode = new Element("div", {
  279. "styles": this.css.contentNode
  280. }).inject(this.node);
  281. this.loadSelectedNodeMobile();
  282. this.loadSelectedCountNode();
  283. this.node.inject($(document.body));
  284. var size = $(document.body).getSize();
  285. //var height = size.y-40;
  286. var height = size.y - this.selectedCountNode.getSize().y - this.getOffsetY(this.selectedCountNode);
  287. height = height - this.titleNode.getSize().y - this.getOffsetY(this.titleNode);
  288. this.contentNode.setStyle("height", ""+height+"px");
  289. this.contentNode.setStyle("margin-top", "2px");
  290. this.loadContent();
  291. this.node.setStyles({
  292. "top": "0px",
  293. "left": "0px"
  294. });
  295. this.setEvent();
  296. },
  297. loadSelectedNodeMobile: function(){
  298. this.css.selectedWrapNodeMobile["z-index"] = this.options.zIndex + 2;
  299. this.selectedWrapNode = new Element("div.selectedWrapNode", {
  300. "styles": this.css.selectedWrapNodeMobile
  301. }).inject(this.contentNode);
  302. this.selectedTitleNode = new Element("div.selectedTitleNodeMobile", {
  303. "styles": this.css.selectedTitleNodeMobile
  304. }).inject(this.selectedWrapNode);
  305. this.selectedTitleLabelNode = new Element("span", {
  306. "style": "font-weight:bold; padding-right:5px;",
  307. "text": MWF.SelectorLP.selected2
  308. }).inject(this.selectedTitleNode);
  309. // this.selectedTitleCountNode = new Element("span", {
  310. // "text": "(0)"
  311. // }).inject(this.selectedTitleNode);
  312. this.selectedScrollNode = new Element("div.selectedScrollNode", {
  313. "styles": this.css.selectedScrollNodeMobile
  314. }).inject(this.selectedWrapNode);
  315. // this.selectedNode = new Element("div.selectedNode", {
  316. // "styles": this.css.selectedNodeMobile
  317. // }).inject(this.selectedScrollNode);
  318. this.selectedWrapNode.setStyle("display", "none");
  319. },
  320. loadSelectedCountNode: function(){
  321. this.selectedCountNode = new Element("div.selectedCountNode", {
  322. "styles": this.css.selectedCountNodeMobile,
  323. "events":{
  324. "click": function () {
  325. this.css.selectedMaskNodeMobile["z-index"] = this.options.zIndex + 2;
  326. this.selectedMaskNode = new Element("div", {
  327. "styles": this.css.selectedMaskNodeMobile,
  328. "events":{
  329. "click": function () {
  330. this.selectedWrapNode.hide();
  331. this.selectedMaskNode.destroy();
  332. }.bind(this)
  333. }
  334. }).inject( this.node );
  335. this.selectedWrapNode.show().inject( this.node );
  336. }.bind(this)
  337. }
  338. }).inject(this.node);
  339. this.selectedCountLabelNode = new Element("div", {
  340. "styles": this.css.selectedCountLabelNodeMobile,
  341. "text": MWF.SelectorLP.selected2
  342. }).inject( this.selectedCountNode );
  343. },
  344. loadPc: function(){
  345. this.css.maskNode["z-index"] = this.options.zIndex;
  346. var position = this.container.getPosition(this.container.getOffsetParent());
  347. this.container.mask({
  348. "destroyOnHide": true,
  349. "style": this.css.maskNode,
  350. "useIframeShim": true,
  351. "iframeShimOptions": {"browsers": true},
  352. "onShow": function(){
  353. this.shim.shim.setStyles({
  354. "opacity": 0,
  355. "top": ""+position.y+"px",
  356. "left": ""+position.x+"px"
  357. });
  358. }
  359. });
  360. // this.container.setStyle("z-index", this.options.zIndex);
  361. this.node = new Element("div", {
  362. "styles": this.css.containerNode_multiple //this.isSingle() ? this.css.containerNodeSingle_multiple : this.css.containerNode_multiple
  363. });
  364. this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
  365. this.titleNode = new Element("div", {
  366. "styles": this.css.titleNode
  367. }).inject(this.node);
  368. this.titleActionNode = new Element("div", {
  369. "styles": this.css.titleActionNode
  370. }).inject(this.titleNode);
  371. this.titleTextNode = new Element("div", {
  372. "styles": this.css.titleTextNode,
  373. "text": this.options.title
  374. }).inject(this.titleNode);
  375. this.contentNode = new Element("div", {
  376. "styles": this.css.contentNode
  377. }).inject(this.node);
  378. this.actionNode = new Element("div", {
  379. "styles": this.css.actionNode
  380. }).inject(this.node);
  381. //if ( this.isSingle() ) this.actionNode.setStyle("text-align", "center");
  382. this.loadAction();
  383. this.node.inject(this.container);
  384. if( this.options.width || this.options.height ){
  385. this.setSize()
  386. }
  387. this.loadContent();
  388. this.node.position({
  389. relativeTo: this.container,
  390. position: "center",
  391. edge: "center"
  392. });
  393. var size = this.container.getSize();
  394. var nodeSize = this.node.getSize();
  395. this.node.makeDraggable({
  396. "handle": this.titleNode,
  397. "limit": {
  398. "x": [0, size.x-nodeSize.x],
  399. "y": [0, size.y-nodeSize.y]
  400. }
  401. });
  402. this.setEvent();
  403. },
  404. isSingle : function(){
  405. var single = true;
  406. var flag = true;
  407. this.options.types.each( function( type, index ){
  408. var opt = this.options[ type + "Options" ];
  409. if( opt ){
  410. if( Number.convert(opt.count) !== 1 )single = false;
  411. flag = false;
  412. }
  413. }.bind(this));
  414. if( flag ){
  415. single = Number.convert( this.options.count ) === 1;
  416. }
  417. return single;
  418. },
  419. setEvent: function(){
  420. if (this.titleActionNode){
  421. this.titleActionNode.addEvent("click", function(){
  422. this.close();
  423. }.bind(this));
  424. }
  425. if (this.titleCancelActionNode){
  426. this.titleCancelActionNode.addEvent("click", function(){
  427. this.close();
  428. }.bind(this));
  429. }
  430. if (this.titleOkActionNode){
  431. this.titleOkActionNode.addEvent("click", function(){
  432. this.fireEvent("complete", [this.getSelectedItems(), this.getSelectedItemsObject() ]);
  433. this.close();
  434. }.bind(this));
  435. }
  436. },
  437. close: function(){
  438. this.fireEvent("close");
  439. this.clearTooltip();
  440. this.node.destroy();
  441. (this.maskRelativeNode || this.container).unmask();
  442. this.active = false;
  443. MWF.release(this);
  444. delete this;
  445. },
  446. clearTooltip: function(){
  447. for( var t in this.selectors ){
  448. var selector = this.selectors[t];
  449. if( selector.tooltips && selector.tooltips.length ){
  450. selector.tooltips.each(function (tooltip) {
  451. if(tooltip.destroy)tooltip.destroy();
  452. })
  453. selector.tooltips = [];
  454. }
  455. }
  456. },
  457. loadAction: function(){
  458. if( !this.okActionNode ) {
  459. this.okActionNode = new Element("button", {
  460. "styles": this.css.okActionNode,
  461. "text": MWF.SelectorLP.ok
  462. }).inject(this.actionNode);
  463. }
  464. if( !this.cancelActionNode ) {
  465. this.cancelActionNode = new Element("button", {
  466. "styles": this.css.cancelActionNode,
  467. "text": MWF.SelectorLP.cancel
  468. }).inject(this.actionNode);
  469. }
  470. this.okActionNode.addEvent("click", function(){
  471. this.fireEvent("complete", [this.getSelectedItems(), this.getSelectedItemsObject() ]);
  472. this.close();
  473. }.bind(this));
  474. this.cancelActionNode.addEvent("click", function(){this.fireEvent("cancel", this); this.close();}.bind(this));
  475. },
  476. loadContent: function(){
  477. if( this.options.contentUrl ){
  478. MWF.require("MWF.widget.Tab", function(){
  479. this.tab = new MWF.widget.Tab( this.tabContainer || this.titleTextNode, {"style": this.options.tabStyle || "default" });
  480. var width;
  481. if( layout.mobile ){
  482. if( this.tabContainer ){
  483. var borderWidth = 0;
  484. if( this.tab.css.tabNode ){
  485. if( this.tab.css.tabNode["border-left"] )borderWidth += this.tab.css.tabNode["border-left"].toInt();
  486. if( this.tab.css.tabNode["border-right"] )borderWidth += this.tab.css.tabNode["border-right"].toInt();
  487. }
  488. var tabWidth = "calc("+( 100 / this.options.types.length ) +"% - " + (borderWidth+"px")+")";
  489. if( this.tab.css.tabNode ){
  490. this.tab.css.tabNode["width"] = tabWidth;
  491. }
  492. if( this.tab.css.tabNodeCurrent ){
  493. this.tab.css.tabNodeCurrent["width"] = tabWidth;
  494. }
  495. }else{
  496. width = this.container.getSize().x - 160; //160是确定和返回按钮的宽度
  497. var w = width / this.options.types.length - 2;
  498. var tabWidth = w < 60 ? w : 60;
  499. if( this.tab.css.tabNode ){
  500. this.tab.css.tabNode["min-width"] = tabWidth+"px";
  501. }
  502. if( this.tab.css.tabNodeCurrent ){
  503. this.tab.css.tabNodeCurrent["min-width"] = tabWidth+"px";
  504. }
  505. }
  506. }else{
  507. this.tab = new MWF.widget.Tab(this.tabContainer, {"style": this.options.tabStyle || "default" });
  508. this.tab.load();
  509. }
  510. this.tab.load();
  511. this.tab.contentNodeContainer.inject(this.contentNode);
  512. }.bind(this), false);
  513. }else if (layout.mobile){
  514. MWF.require("MWF.widget.Tab", function(){
  515. this.tab = new MWF.widget.Tab( this.tabContainer || this.titleTextNode, {"style": "orgMobile" });
  516. var width = this.container.getSize().x - 160; //160是确定和返回按钮的宽度
  517. var w = width / this.options.types.length - 2;
  518. var tabWidth = w < 60 ? w : 60;
  519. if( this.tab.css.tabNode ){
  520. this.tab.css.tabNode["min-width"] = tabWidth+"px";
  521. }
  522. if( this.tab.css.tabNodeCurrent ){
  523. this.tab.css.tabNodeCurrent["min-width"] = tabWidth+"px";
  524. }
  525. this.tab.load();
  526. this.tab.contentNodeContainer.inject(this.contentNode);
  527. }.bind(this), false);
  528. }else{
  529. MWF.require("MWF.widget.Tab", function(){
  530. this.tab = new MWF.widget.Tab(this.contentNode, {"style": this.options.tabStyle || "default" });
  531. this.tab.load();
  532. }.bind(this), false);
  533. }
  534. var isFormWithAction = window.location.href.toLowerCase().indexOf("workmobilewithaction.html") > -1;
  535. if( !MWF.O2Selector.selectedIndex )MWF.O2Selector.selectedIndex = 1;
  536. var selectedIndexMap = {};
  537. var firstType = this.options.types[0];
  538. var values = this.options[firstType+'Options'] ? this.options[firstType+'Options'].values : [];
  539. if(!values)values = [];
  540. values = typeOf(values) === "array" ? values : [values];
  541. values.each(function(e, i){
  542. if( !e )return;
  543. var key = typeOf( e ) === "string" ? e : ( e.distinguishedName || e.unique || e.employee || e.levelName || e.id );
  544. selectedIndexMap[key] = MWF.O2Selector.selectedIndex++;
  545. });
  546. this.options.types.each( function( type, index ){
  547. var options = Object.clone( this.options );
  548. for (var key in this.optionsArg){
  549. if (typeOf(this.optionsArg[key]) === 'function' && (/^on[A-Z]/).test(key)){
  550. options[key] = this.optionsArg[key];
  551. }
  552. }
  553. if( type.toLowerCase()==="identity" ){
  554. options.expand = false;
  555. }
  556. if( this.options[ type + "Options" ] ){
  557. options = Object.merge( options, this.options[ type + "Options" ] );
  558. }
  559. var pageNode = new Element( "div" ).inject( this.contentNode );
  560. var tab = this.tab.addTab( pageNode, this.lp[type], false );
  561. if( index === 0 && this.contentHeight ){
  562. //this.contentHeight = this.contentHeight - this.getOffsetY( tab.tabContainer ) - tab.tabContainer.getStyle("height").toInt();
  563. if( !this.tabContainer ){
  564. this.contentHeight = this.contentHeight - this.getOffsetY( tab.tab.tabNodeContainer ) - tab.tab.tabNodeContainer.getStyle("height").toInt();
  565. }
  566. if( this.selectedCountNode ){
  567. this.contentHeight = this.contentHeight - this.getOffsetY( this.selectedCountNode ) - this.selectedCountNode.getStyle("height").toInt();
  568. }
  569. }
  570. var t = type.capitalize();
  571. if ((type.toLowerCase()==="unit") && ( options.unitType)){
  572. t = "UnitWithType";
  573. }
  574. if ((type.toLowerCase()==="identity") && (( options.dutys) && options.dutys.length)){
  575. if( options.categoryType.toLowerCase()==="duty" ){
  576. t = "IdentityWidthDuty";
  577. }else{
  578. t = "IdentityWidthDutyCategoryByUnit"
  579. }
  580. }
  581. MWF.xDesktop.requireApp("Selector", t, function(){
  582. if( type.toLowerCase()==="identity" && options.resultType && options.resultType === "person" ){
  583. options.values = this.getValueByType( options.values, [ type, "person" ] );
  584. }else{
  585. options.values = this.getValueByType( options.values, type );
  586. }
  587. //options.values = [];
  588. //if( options.multipleValues[type] ){
  589. // options.values = options.multipleValues[type];
  590. //}
  591. //if( options[type+"Values"] && options[type+"Values"].length ){
  592. // options.values = options.values.concat( options[type+"Values"] )
  593. //}
  594. //
  595. //options.names = [];
  596. //if( options.multipleNames[type] ){
  597. // options.names = options.multipleNames[type];
  598. //}
  599. //if( options[type+"Names"] && options[type+"Names"].length ){
  600. // options.names = options.names.concat( options[type+"Names"] )
  601. //}
  602. debugger;
  603. this.selectors[t] = new MWF.xApplication.Selector[t](this.container, options );
  604. var selector = this.selectors[t];
  605. selector.selectedIndexMap = selectedIndexMap;
  606. selector.inMulitple = true;
  607. var itemAreaScrollNode;
  608. if( this.options.contentUrl ){
  609. pageNode.set("html", this.contentHTML);
  610. pageNode.setStyle("height", this.contentHeight);
  611. selector.selectNode = pageNode.getElement(".MWF_selector_selectNode");
  612. selector.selectTopNode = pageNode.getElement(".MWF_selector_selectTopNode");
  613. selector.selectTopTextNode = pageNode.getElement(".MWF_selector_selectTopTextNode");
  614. selector.searchInputDiv = pageNode.getElement(".MWF_selector_searchInputDiv");
  615. selector.searchInput = pageNode.getElement(".MWF_selector_searchInput");
  616. selector.searchCancelAction = pageNode.getElement(".MWF_selector_searchCancelAction");
  617. selector.letterActionNode = pageNode.getElement(".MWF_selector_letterActionNode");
  618. selector.flatCategoryScrollNode = pageNode.getElement(".MWF_selector_flatCategoryScrollNode");
  619. selector.flatCategoryNode = pageNode.getElement(".MWF_selector_flatCategoryNode");
  620. if( this.options.flatCategory && selector.flatCategoryScrollNode ){
  621. selector.isFlatCategory = true;
  622. selector.flatSubCategoryNodeList = [];
  623. }
  624. selector.letterAreaNode = pageNode.getElement(".MWF_selector_letterAreaNode");
  625. selector.itemAreaScrollNode = pageNode.getElement(".MWF_selector_itemAreaScrollNode");
  626. selector.itemAreaNode = pageNode.getElement(".MWF_selector_itemAreaNode");
  627. selector.itemSearchAreaScrollNode = pageNode.getElement(".MWF_selector_itemSearchAreaScrollNode");
  628. selector.itemSearchAreaNode = pageNode.getElement(".MWF_selector_itemSearchAreaNode");
  629. selector.selectedContainerNode = pageNode.getElement(".MWF_selector_selectedContainerNode");
  630. selector.selectedTopNode = pageNode.getElement(".MWF_selector_selectedTopNode");
  631. selector.selectedTopTextNode = pageNode.getElement(".MWF_selector_selectedTopTextNode");
  632. selector.emptySelectedNode = pageNode.getElement(".MWF_selector_emptySelectedNode");
  633. selector.selectedScrollNode = pageNode.getElement(".MWF_selector_selectedScrollNode");
  634. selector.selectedNode = pageNode.getElement(".MWF_selector_selectedNode");
  635. selector.selectedItemSearchAreaNode = pageNode.getElement(".MWF_selector_selectedItemSearchAreaNode");
  636. selector.loadContent( pageNode, true );
  637. if( t.toLowerCase() == "person" || t.toLowerCase() == "group" ){
  638. var startY=0, y=0;
  639. itemAreaScrollNode = selector.itemAreaScrollNode;
  640. itemAreaScrollNode.addEvents({
  641. 'touchstart' : function( ev ){
  642. var touch = ev.touches[0]; //获取第一个触点
  643. startY = Number(touch.pageY); //页面触点Y坐标
  644. }.bind(this),
  645. 'touchmove' : function(ev){
  646. var touch = ev.touches[0]; //获取第一个触点
  647. y = Number(touch.pageY); //页面触点Y坐标
  648. }.bind(this),
  649. 'touchend' : function( ev ){
  650. if (startY - y > 10) { //向上滑动超过10像素
  651. var obj = this.selectors.Person;
  652. if(obj._scrollEvent)obj._scrollEvent( obj.itemAreaScrollNode.scrollTop + 100 );
  653. }
  654. startY = 0;
  655. y = 0;
  656. }.bind(this)
  657. })
  658. }
  659. }else{
  660. // if( this.contentWidth )options.width = this.contentWidth;
  661. // if( this.contentHeight )options.height = this.contentHeight;
  662. if( this.contentWidth )selector.options.width = this.contentWidth;
  663. if( this.contentHeight )selector.options.height = this.contentHeight;
  664. if( layout.mobile ){
  665. selector.overrideSelectedItems();
  666. selector.selectedCountTextNode = new Element("div", {
  667. "styles": this.css.selectedCountTextNodeMobile,
  668. "text": (MWF.SelectorLP.quantifier[ selector.selectType ] || "") + ":0"
  669. }).inject( this.selectedCountNode );
  670. if( index === 0 ){
  671. new Element("span", { "text": "(" }).inject(this.selectedTitleNode);
  672. selector.selectedTitleCountNode = new Element("span", {
  673. "style": "padding-right:5px;",
  674. "text": (MWF.SelectorLP.quantifier[ selector.selectType ] || "") + ":0"
  675. }).inject(this.selectedTitleNode);
  676. }else if( index === this.options.types.length - 1 ){
  677. selector.selectedTitleCountNode = new Element("span", {
  678. "text": (MWF.SelectorLP.quantifier[ selector.selectType ] || "") + ":0"
  679. }).inject(this.selectedTitleNode);
  680. new Element("span", { "text": ")" }).inject(this.selectedTitleNode);
  681. }else{
  682. selector.selectedTitleCountNode = new Element("span", {
  683. "style": "padding-right:5px;",
  684. "text": (MWF.SelectorLP.quantifier[ selector.selectType ] || "") + ":0"
  685. }).inject(this.selectedTitleNode);
  686. }
  687. selector.selectedNode = new Element("div.selectedNode", {
  688. "styles": this.css.selectedNodeMobile
  689. }).inject(this.selectedScrollNode);
  690. }
  691. selector.loadContent( pageNode );
  692. if( !layout.mobile )selector.setSize();
  693. if( layout.mobile ){
  694. tab.addEvent("postShow", function () {
  695. this.setSelectNodeSizeMobile(t, index, tab);
  696. }.bind(this))
  697. itemAreaScrollNode = selector.itemAreaScrollNode;
  698. if( t.toLowerCase() == "person" || t.toLowerCase() == "group" ){
  699. var startY=0, y=0;
  700. itemAreaScrollNode.addEvents({
  701. 'touchstart' : function( ev ){
  702. var touch = ev.touches[0]; //获取第一个触点
  703. startY = Number(touch.pageY); //页面触点Y坐标
  704. }.bind(this),
  705. 'touchmove' : function(ev){
  706. var touch = ev.touches[0]; //获取第一个触点
  707. y = Number(touch.pageY); //页面触点Y坐标
  708. }.bind(this),
  709. 'touchend' : function( ev ){
  710. if (startY - y > 10) { //向上滑动超过10像素
  711. var obj = this.selectors.Person;
  712. if(obj._scrollEvent)obj._scrollEvent( obj.itemAreaScrollNode.scrollTop + 100 );
  713. }
  714. startY = 0;
  715. y = 0;
  716. }.bind(this)
  717. })
  718. }
  719. }else{
  720. //if( !this.isSingle() && Number.convert( options.count ) === 1 ){
  721. // this.selectors[t].selectNode.setStyles({
  722. // "float" : "none",
  723. // "margin-left" : "auto",
  724. // "margin-right" : "auto"
  725. // })
  726. //}
  727. }
  728. }
  729. if( index == 0 )tab.showIm();
  730. }.bind(this));
  731. }.bind(this));
  732. },
  733. setSelectNodeSizeMobile: function(t, index, tab){
  734. if( tab.isSetSize )return;
  735. tab.isSetSize = true;
  736. if( index === 0 ){
  737. var containerSize = this.container.getSize();
  738. var bodySize = $(document.body).getSize();
  739. var size = {
  740. "x" : Math.min( containerSize.x, bodySize.x ),
  741. "y" : Math.min( containerSize.y, bodySize.y )
  742. };
  743. this.contentHeight = size.y;
  744. if( !this.tabContainer ){
  745. this.contentHeight = this.contentHeight - this.getOffsetY( tab.tab.tabNodeContainer ) - tab.tab.tabNodeContainer.getStyle("height").toInt();
  746. }
  747. if( this.selectedCountNode ){
  748. this.contentHeight = this.contentHeight - this.getOffsetY( this.selectedCountNode ) - this.selectedCountNode.getStyle("height").toInt();
  749. }
  750. var formActionY = 0;
  751. // height = height - formActionY - this.titleNode.getSize().y - this.getOffsetY(this.titleNode);
  752. // if(this.selectedCountNode)height = height - this.selectedCountNode.getSize().y - this.getOffsetY(this.selectedCountNode);
  753. // this.contentHeight = height;
  754. var sel = this.selectors[t];
  755. var offsetY = this.getOffsetY(sel.itemAreaScrollNode);
  756. if(sel.searchInputDiv)offsetY = offsetY + sel.searchInputDiv.getSize().y + this.getOffsetY(sel.searchInputDiv);
  757. if(sel.letterAreaNode)offsetY = offsetY + sel.letterAreaNode.getSize().y + this.getOffsetY(sel.letterAreaNode);
  758. this.itemAreaHeight = this.contentHeight - offsetY;
  759. }
  760. // if( isFormWithAction ){
  761. // height = size.y-40-20-6-20;
  762. // }else{
  763. // height = size.y;
  764. // }
  765. if(this.selectors[t].selectNode){
  766. this.selectors[t].selectNode.setStyle("height", ""+this.contentHeight+"px");
  767. }
  768. // if( isFormWithAction ){
  769. // height = size.y-40-20-78 - 20;
  770. // }else{
  771. // height = size.y-42-31-40;
  772. // }
  773. //height = height - 5;
  774. itemAreaScrollNode = this.selectors[t].itemAreaScrollNode;
  775. if( itemAreaScrollNode ){
  776. itemAreaScrollNode.setStyle("height", ""+this.itemAreaHeight+"px");
  777. }
  778. },
  779. getValueByType : function( values, type ){
  780. var result = [];
  781. values = typeOf(values) == "array" ? values : [values];
  782. var types = typeOf(type)== "array" ? type : [type];
  783. values.each( function( data ){
  784. if( !data )return;
  785. if( typeOf( data ) == "string" ){
  786. var dn = data;
  787. }else{
  788. var dn = data.distinguishedName;
  789. }
  790. if (dn && type ){
  791. var flag = dn.substr(dn.length-1, 1);
  792. switch (flag.toLowerCase()){
  793. case "i":
  794. if( type == "identity" || types.contains( "identity" ) )result.push( data );
  795. break;
  796. case "p":
  797. if( type == "person" || types.contains( "person" ) )result.push( data );
  798. break;
  799. case "u":
  800. if( type == "unit" )result.push( data );
  801. break;
  802. case "g":
  803. if( type == "group" )result.push( data );
  804. break;
  805. case "r":
  806. if( type == "role" )result.push( data );
  807. break;
  808. default:
  809. if( type == "person" )result.push( data );
  810. break;
  811. //result.push( data );
  812. }
  813. }else{
  814. //result.push( data );
  815. }
  816. });
  817. return result;
  818. },
  819. emptySelectedItems : function(){
  820. for( var key in this.selectors ){
  821. var selector = this.selectors[key];
  822. if( selector.selectedItems && selector.selectedItems.length > 0 ){
  823. selector.emptySelectedItems();
  824. }
  825. }
  826. },
  827. getSelectedItems : function(){
  828. this.selectedItems = [];
  829. for( var key in this.selectors ){
  830. var selector = this.selectors[key];
  831. if( selector.selectedItems && selector.selectedItems.length > 0 ){
  832. this.selectedItems = this.selectedItems.concat( selector.selectedItems );
  833. }
  834. }
  835. this.selectedItems.sort(function (a, b){
  836. return (a.selectedIndex || 9999999) - (b.selectedIndex || 9999999);
  837. });
  838. return this.selectedItems;
  839. },
  840. getSelectedItemsObject : function(){
  841. this.selectedItemsObject = {};
  842. for( var key in this.selectors ){
  843. var selector = this.selectors[key];
  844. if( selector.selectedItems && selector.selectedItems.length > 0 ){
  845. selector.selectedItems.sort(function (a, b){
  846. return a.selectedIndex - b.selectedIndex;
  847. });
  848. this.selectedItemsObject[key.toLowerCase()] = selector.selectedItems;
  849. }
  850. }
  851. return this.selectedItemsObject;
  852. },
  853. getOffsetX : function(node){
  854. return (node.getStyle("margin-left").toInt() || 0 )+
  855. (node.getStyle("margin-right").toInt() || 0 ) +
  856. (node.getStyle("padding-left").toInt() || 0 ) +
  857. (node.getStyle("padding-right").toInt() || 0 ) +
  858. (node.getStyle("border-left-width").toInt() || 0 ) +
  859. (node.getStyle("border-right-width").toInt() || 0 );
  860. },
  861. getOffsetY : function(node){
  862. return (node.getStyle("margin-top").toInt() || 0 ) +
  863. (node.getStyle("margin-bottom").toInt() || 0 ) +
  864. (node.getStyle("padding-top").toInt() || 0 ) +
  865. (node.getStyle("padding-bottom").toInt() || 0 )+
  866. (node.getStyle("border-top-width").toInt() || 0 ) +
  867. (node.getStyle("border-bottom-width").toInt() || 0 );
  868. },
  869. setSize : function(){
  870. if( !this.options.width && !this.options.height )return;
  871. if( this.options.width && this.options.width === "auto" ){
  872. //if (this.options.count.toInt() !== 1){
  873. this.node.setStyle("width", "auto");
  874. this.contentWidth = "auto";
  875. }else if( this.options.width && typeOf( this.options.width.toInt() ) === "number" ){
  876. var nodeWidth = this.options.width.toInt() - this.getOffsetX(this.node);
  877. this.node.setStyle("width", nodeWidth);
  878. if( this.contentNode ){
  879. nodeWidth = nodeWidth - this.getOffsetX( this.contentNode );
  880. }
  881. this.contentWidth = nodeWidth;
  882. }
  883. if( this.options.height && typeOf( this.options.height.toInt() ) === "number" ){
  884. var nodeHeight = this.options.height.toInt() - this.getOffsetY(this.node);
  885. this.node.setStyle("height", nodeHeight);
  886. if( this.titleNode ){
  887. nodeHeight = nodeHeight - this.getOffsetY( this.titleNode ) - this.titleNode.getStyle("height").toInt();
  888. }
  889. if( this.actionNode ){
  890. nodeHeight = nodeHeight - this.getOffsetY( this.actionNode ) - this.actionNode.getStyle("height").toInt();
  891. }
  892. if( this.contentNode ){
  893. nodeHeight = nodeHeight - this.getOffsetY( this.contentNode );
  894. }
  895. this.contentHeight = nodeHeight;
  896. }
  897. }
  898. });
  899. MWF.xApplication.Selector.MultipleSelector.Filter = new Class({
  900. Implements: [Options, Events],
  901. options: {
  902. "types" : [],
  903. "groups": [], //选person, group, role 时的范围
  904. "roles": [], //选选person, group, role 时的范围
  905. "units": [] //选 company, department, duty, identity 时的范围
  906. },
  907. initialize: function(value, options){
  908. this.setOptions(options);
  909. this.value = value;
  910. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  911. this.selectors = {};
  912. this.options.types.each( function( type, index ){
  913. var opt = Object.clone( this.options );
  914. if( this.options[ type + "Options" ] ){
  915. opt = Object.merge( opt, this.options[ type + "Options" ] );
  916. }
  917. var t = type.capitalize();
  918. if ((type.toLowerCase()==="unit") && ( opt.unitType)){
  919. t = "UnitWithType";
  920. }
  921. if ((type.toLowerCase()==="identity") && ((opt.dutys) && opt.dutys.length)){
  922. t = "IdentityWidthDuty";
  923. }
  924. MWF.xDesktop.requireApp("Selector", t, function(){
  925. this.selectors[t] = new MWF.xApplication.Selector[t].Filter(this.value, opt);
  926. }.bind(this), false);
  927. }.bind(this));
  928. },
  929. filter: function(value, callback){
  930. this.value = value;
  931. var key = this.value;
  932. this.filterData = [];
  933. this.filterCount = 0;
  934. for (i in this.selectors){
  935. this.selectors[i].filter(value, function(data){
  936. this.filterData = this.filterData.concat(data);
  937. this.filterCount++;
  938. this.endFilter(callback);
  939. }.bind(this))
  940. }
  941. //
  942. // this.orgAction.listPersonByKey(function(json){
  943. // data = json.data;
  944. // if (callback) callback(data)
  945. // }.bind(this), failure, key);
  946. },
  947. endFilter: function(callback){
  948. if (this.filterCount>=Object.keys(this.selectors).length){
  949. if (callback) callback(this.filterData);
  950. }
  951. }
  952. });