Person.js 150 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515
  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.Person = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. "count": 0,
  11. "title": "",
  12. "groups": [],
  13. "roles": [],
  14. "values": [],
  15. "exclude" : [],
  16. "zIndex": 1000,
  17. "expand": true,
  18. "embedded" : false, //是否嵌入在其他容器中
  19. "selectAllEnable" : false, //是否允许全选
  20. "selectAllRange" : "direct", //全选直属人员 还是 所有下级人员
  21. "selectAllActiveNestSub": true, //全选时,是否展开子级级以后的层次
  22. "level1Indent" : 10, //第一级的缩进
  23. "indent" : 10, //后续的缩进
  24. "hasLetter" : true, //字母
  25. "hasTop" : false, //可选、已选的标题
  26. "hasShuttle" : false, //穿梭按钮
  27. "searchbarInTopNode" : true, //搜索框在标题上还是另起一行
  28. "hasSelectedSearchbar" : false, //已选是不是有搜索框
  29. "noSelectedContainer" : false, //是否隐藏右侧已选区域
  30. "contentUrl" : "", //和默认的页面布局不一样的话,可以传入页面布局HTML URL
  31. "injectToBody" : false, //当传入HTML URL的时候是否插入到document.body, false的时候插入到this.container
  32. "selectSingleItem" : false, //当只有一个候选项的时候,是否默认选中
  33. "hiddenEmptyCategory" : false,
  34. "flatCategory" : false, //扁平化展现分类,
  35. "selectType" : "person",
  36. "isCheckStatus" : false,
  37. "showSelectedCount" : false,
  38. "itemHeight" : 29,
  39. "identityItemWidth" : 0, //选项宽度,如果不为0,设置为float:left,
  40. "storeRange" : "full", //数据是否保存为精简,可选值:full,simple
  41. "showEmptyText" : true
  42. },
  43. setInitTitle: function(){
  44. this.setOptions({"title": MWF.xApplication.Selector.LP.selectPerson});
  45. },
  46. initialize: function(container, options){
  47. this.active = true;
  48. this.setOptions(options);
  49. if (!this.options.title) this.setInitTitle();
  50. this.path = "../x_component_Selector/$Selector/";
  51. this.cssPath = "../x_component_Selector/$Selector/"+this.options.style+"/css.wcss";
  52. this._loadCss(true);
  53. this.container = $(container);
  54. if( ["flow"].contains(this.options.style) ){
  55. this.options.contentUrl = this.path + this.options.style + "/"+( this.options.embedded ? "selector_embedded":"selector" )+".html";
  56. this.options.level1Indent = 10;
  57. this.options.indent = 20;
  58. }
  59. Object.defineProperties(this, {
  60. "orgAction": {"get": function(){return o2.Actions.get("x_organization_assemble_control");}},
  61. "processAction": {"get": function(){return o2.Actions.get("x_processplatform_assemble_surface");}},
  62. "designerAction": {"get": function(){return o2.Actions.get("x_processplatform_assemble_designer");}},
  63. "portalAction": {"get": function(){return o2.Actions.get("x_portal_assemble_surface");}},
  64. "portalDesignerAction": {"get": function(){return o2.Actions.get("x_portal_assemble_designer");}},
  65. "cmsAction": {"get": function(){return o2.Actions.get("x_cms_assemble_control");}},
  66. "queryAction": {"get": function(){return o2.Actions.get("x_query_assemble_designer");}}
  67. });
  68. // this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  69. // //this.org2Action = MWF.Actions.get("x_organization_assemble_express");
  70. // this.processAction = MWF.Actions.get("x_processplatform_assemble_surface");
  71. // this.designerAction = MWF.Actions.get("x_processplatform_assemble_designer");
  72. // this.portalAction = MWF.Actions.get("x_portal_assemble_surface");
  73. // this.portalDesignerAction = MWF.Actions.get("x_portal_assemble_designer");
  74. // this.cmsAction = MWF.Actions.get("x_cms_assemble_control");
  75. // this.queryAction = MWF.Actions.get("x_query_assemble_designer");
  76. //this.action = new MWF.xApplication.Selector.Actions.RestActions();
  77. this.lastPeople = "";
  78. this.pageCount = "13";
  79. this.selectedItems = []; //所有已选项
  80. this.items = []; //所有选择项
  81. this.subCategorys = []; //直接的分类
  82. this.subItems = []; //直接的选择项
  83. this.subCategoryMap = {};
  84. this.subCategoryMapWithDuty = {};
  85. if( !this.options.values ){
  86. this.options.values = [];
  87. }
  88. this.tooltips = [];
  89. this.availableStatusTypes = ["identity","custom"];
  90. this._init();
  91. },
  92. _init : function(){
  93. this.selectType = "person";
  94. this.className = "Person";
  95. },
  96. load: function(){
  97. this.fireEvent("queryLoad",[this]);
  98. if( this.options.contentUrl ){
  99. this.loadWithUrl()
  100. }else{
  101. if (layout.mobile){
  102. this.loadMobile();
  103. }else{
  104. this.loadPc();
  105. }
  106. this.fireEvent("load");
  107. }
  108. },
  109. loadMobile: function(){
  110. this.overrideSelectedItems();
  111. this.maskRelativeNode = $(document.body);
  112. this.maskRelativeNode.mask({
  113. "destroyOnHide": true,
  114. "style": this.css.maskNode
  115. });
  116. this.node = new Element("div", {"styles": this.css.containerNodeMobile});
  117. this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
  118. this.node.setStyle("height", ( $(document.body).getSize().y ) + "px");
  119. this.titleNode = new Element("div", {
  120. "styles": this.css.titleNodeMobile
  121. }).inject(this.node);
  122. this.titleCancelActionNode = new Element("div", {
  123. "styles": this.css.titleCancelActionNodeMobile,
  124. "text": MWF.SelectorLP.back
  125. }).inject(this.titleNode);
  126. this.titleOkActionNode = new Element("div", {
  127. "styles": this.css.titleOkActionNodeMobile,
  128. "text": MWF.SelectorLP.ok
  129. }).inject(this.titleNode);
  130. this.titleTextNode = new Element("div", {
  131. "styles": this.css.titleTextNodeMobile,
  132. "text": this.options.title
  133. }).inject(this.titleNode);
  134. this.contentNode = new Element("div", {
  135. "styles": this.css.contentNode
  136. }).inject(this.node);
  137. var size = $(document.body).getSize();
  138. var height = size.y-40;
  139. //var height = size.y;
  140. this.contentNode.setStyle("height", ""+height+"px");
  141. this.node.inject($(document.body));
  142. this.node.setStyles({
  143. "top": "0px",
  144. "left": "0px"
  145. });
  146. this.loadContent();
  147. this.setEvent();
  148. },
  149. overrideSelectedItems: function(){
  150. var _self = this;
  151. var oldPush = this.selectedItems.push;
  152. this.selectedItems.push = function(){
  153. oldPush.apply(this, arguments);
  154. _self.setSelectedCount();
  155. };
  156. var oldErase = this.selectedItems.erase;
  157. this.selectedItems.erase = function(){
  158. oldErase.apply(this, arguments);
  159. _self.setSelectedCount();
  160. };
  161. var oldConcat = this.selectedItems.concat;
  162. this.selectedItems.concat = function(){
  163. oldConcat.apply(this, arguments);
  164. _self.setSelectedCount();
  165. };
  166. },
  167. setSelectedCount: function(){
  168. var quantifier = MWF.SelectorLP.quantifier[ this.selectType ] || "";
  169. if(this.selectedCountTextNode)this.selectedCountTextNode.set("text", quantifier + ":"+ this.selectedItems.length );
  170. if(this.selectedTitleCountNode){
  171. if( this.inMulitple ){
  172. this.selectedTitleCountNode.set("text", quantifier + ":" + this.selectedItems.length );
  173. }else{
  174. this.selectedTitleCountNode.set("text", "("+ quantifier + ":" + this.selectedItems.length +")");
  175. }
  176. }
  177. },
  178. loadSelectedCountNode: function(){
  179. if( this.inMulitple )return;
  180. this.selectedCountNode = new Element("div.selectedCountNode", {
  181. "styles": this.css.selectedCountNodeMobile,
  182. "events":{
  183. "click": function () {
  184. this.css.selectedMaskNodeMobile["z-index"] = this.options.zIndex + 2;
  185. this.selectedMaskNode = new Element("div", {
  186. "styles": this.css.selectedMaskNodeMobile,
  187. "events":{
  188. "click": function () {
  189. this.selectedWrapNode.hide();
  190. this.selectedMaskNode.destroy();
  191. }.bind(this)
  192. }
  193. }).inject( this.node );
  194. this.selectedWrapNode.show().inject( this.node );
  195. }.bind(this)
  196. }
  197. }).inject(this.selectNode);
  198. this.selectedCountLabelNode = new Element("div", {
  199. "styles": this.css.selectedCountLabelNodeMobile,
  200. "text": MWF.SelectorLP.selected2
  201. }).inject( this.selectedCountNode );
  202. this.selectedCountTextNode = new Element("div", {
  203. "styles": this.css.selectedCountTextNodeMobile,
  204. "text": (MWF.SelectorLP.quantifier[ this.selectType ] || "") + ":0"
  205. }).inject( this.selectedCountNode );
  206. },
  207. setMaskResize: function(){
  208. var size = this.container.getSize();
  209. this.mask.resize();
  210. this.maskInterval = window.setInterval(function(){
  211. var resize = this.container.getSize();
  212. if ((size.x!==resize.x) || (size.y!==resize.y)){
  213. this.mask.position();
  214. this.mask.resize();
  215. size.x = resize.x;
  216. size.y = resize.y;
  217. }
  218. }.bind(this), 66);
  219. },
  220. loadPc: function(){
  221. if( this.options.embedded ){
  222. this.node = new Element("div", {
  223. "styles": this.css.containerNode_embedded, //(this.options.count.toInt()===1) ? this.css.containerNodeSingle_embedded : this.css.containerNode_embedded,
  224. "events": {
  225. "click": function(e){e.stopPropagation();},
  226. "mousedown": function(e){e.stopPropagation();},
  227. "mouseover": function(e){e.stopPropagation();},
  228. "mouseout": function(e){e.stopPropagation();},
  229. "keydown": function(e){e.stopPropagation();}
  230. }
  231. });
  232. this.contentNode = new Element("div", {
  233. "styles": this.css.contentNode_embedded ? this.css.contentNode_embedded : this.css.contentNode
  234. }).inject(this.node);
  235. this.loadContent();
  236. if( this.options.width || this.options.height ){
  237. this.setSize()
  238. }
  239. this.node.inject(this.container);
  240. } else {
  241. this.css.maskNode["z-index"] = this.options.zIndex;
  242. var position = this.container.getPosition(this.container.getOffsetParent());
  243. this.mask = new Mask(this.container, {
  244. "destroyOnHide": true,
  245. "style": this.css.maskNode,
  246. "useIframeShim": true,
  247. "iframeShimOptions": {"browsers": true},
  248. "inject": {"where":"bottom"},
  249. "onShow": function () {
  250. this.shim.shim.setStyles({
  251. "opacity": 0,
  252. "top": "" + position.y + "px",
  253. "left": "" + position.x + "px"
  254. });
  255. }
  256. //
  257. // "destroyOnHide": true,
  258. // "style": this.css.maskNode,
  259. // "useIframeShim": true,
  260. // "iframeShimOptions": {"browsers": true},
  261. // "onShow": function(){
  262. // this.shim.shim.setStyles({
  263. // "opacity": 0,
  264. // "top": ""+position.y+"px",
  265. // "left": ""+position.x+"px"
  266. // });
  267. // }
  268. });
  269. this.mask.show();
  270. this.setMaskResize();
  271. // this.container.setStyle("z-index", this.options.zIndex);
  272. this.node = new Element("div", {
  273. "styles": this.options.noSelectedContainer ? this.css.containerNodeSingle : this.css.containerNode, //(this.options.count.toInt()===1)
  274. "events": {
  275. "click": function(e){e.stopPropagation();},
  276. "mousedown": function(e){e.stopPropagation();},
  277. "mouseover": function(e){e.stopPropagation();},
  278. "mouseout": function(e){e.stopPropagation();},
  279. "keydown": function(e){e.stopPropagation();}
  280. }
  281. });
  282. this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
  283. this.titleNode = new Element("div.titleNode", {
  284. "styles": this.css.titleNode
  285. }).inject(this.node);
  286. this.titleActionNode = new Element("div", {
  287. "styles": this.css.titleActionNode
  288. }).inject(this.titleNode);
  289. this.titleTextNode = new Element("div", {
  290. "styles": this.css.titleTextNode,
  291. "text": this.options.title
  292. }).inject(this.titleNode);
  293. this.contentNode = new Element("div", {
  294. "styles": this.css.contentNode
  295. }).inject(this.node);
  296. this.loadContent();
  297. this.actionNode = new Element("div", {
  298. "styles": this.css.actionNode
  299. }).inject(this.node);
  300. //if (this.options.count.toInt() === 1) this.actionNode.setStyle("text-align", "center");
  301. this.loadAction();
  302. this.node.inject(this.container);
  303. this.node.position({
  304. relativeTo: this.container,
  305. position: "center",
  306. edge: "center"
  307. });
  308. var size = this.container.getSize();
  309. var nodeSize = this.node.getSize();
  310. this.node.makeDraggable({
  311. "handle": this.titleNode,
  312. "limit": {
  313. "x": [0, size.x - nodeSize.x],
  314. "y": [0, size.y - nodeSize.y]
  315. }
  316. });
  317. if( this.options.width || this.options.height ){
  318. this.setSize()
  319. }
  320. this.setEvent();
  321. }
  322. },
  323. loadWithUrl : function(){
  324. if( this.options.style === "flow" ){
  325. debugger;
  326. var node = new Element("div");
  327. node.loadHtml( this.options.contentUrl, {
  328. "bind": { "lp": MWF.xApplication.Selector.LP, "options": this.options },
  329. "module": this
  330. },function () {
  331. this.node = node.getFirst();
  332. this.node.loadCss("../x_component_Selector/$Selector/flow/style.css");
  333. this.loadContentWithHTML();
  334. this.fireEvent("load");
  335. }.bind(this));
  336. }else{
  337. var request = new Request.HTML({
  338. url: this.options.contentUrl,
  339. method: "GET",
  340. async: false,
  341. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  342. this.node = responseTree[0];
  343. this.loadContentWithHTML();
  344. this.fireEvent("load");
  345. }.bind(this),
  346. onFailure: function(xhr){
  347. alert(xhr);
  348. }
  349. });
  350. request.send();
  351. }
  352. },
  353. loadContentWithHTML : function(){
  354. debugger;
  355. var container = this.options.injectToBody ? $(document.body) : this.container;
  356. if( !this.options.embedded ){
  357. this.maskRelativeNode = container;
  358. this.css.maskNode["z-index"] = this.options.zIndex;
  359. this.maskRelativeNode.mask({
  360. "destroyOnHide": true,
  361. "style": this.css.maskNode
  362. });
  363. }
  364. if( !this.options.embedded ) {
  365. this.node.setStyles( layout.mobile ? this.css.containerNodeMobile : this.css.containerNode );
  366. this.node.setStyle("z-index", this.options.zIndex.toInt() + 1);
  367. }
  368. if( layout.mobile ){
  369. this.node.setStyle("height", ( container.getSize().y ) + "px");
  370. }
  371. this.titleNode = this.node.getElement(".MWF_selector_titleNode");
  372. this.titleTextNode = this.node.getElement(".MWF_selector_titleTextNode");
  373. this.titleCancelActionNode = this.node.getElement(".MWF_selector_titleCancelActionNode");
  374. this.titleOkActionNode = this.node.getElement(".MWF_selector_titleOkActionNode");
  375. this.titleActionNode = this.node.getElement(".MWF_selector_titleActionNode");
  376. this.contentNode = this.node.getElement(".MWF_selector_contentNode");
  377. this.selectNode = this.node.getElement(".MWF_selector_selectNode");
  378. this.selectTopNode = this.node.getElement(".MWF_selector_selectTopNode");
  379. this.selectTopTextNode = this.node.getElement(".MWF_selector_selectTopTextNode");
  380. this.searchInputDiv = this.node.getElement(".MWF_selector_searchInputDiv");
  381. this.searchInput = this.node.getElement(".MWF_selector_searchInput");
  382. this.searchCancelAction = this.node.getElement(".MWF_selector_searchCancelAction");
  383. this.letterActionNode = this.node.getElement(".MWF_selector_letterActionNode");
  384. this.flatCategoryScrollNode = this.node.getElement(".MWF_selector_flatCategoryScrollNode");
  385. this.flatCategoryNode = this.node.getElement(".MWF_selector_flatCategoryNode");
  386. if( this.options.flatCategory && this.flatCategoryScrollNode ){
  387. this.isFlatCategory = true;
  388. this.flatSubCategoryNodeList = [];
  389. }
  390. this.letterAreaNode = this.node.getElement(".MWF_selector_letterAreaNode");
  391. this.itemAreaScrollNode = this.node.getElement(".MWF_selector_itemAreaScrollNode");
  392. this.itemAreaNode = this.node.getElement(".MWF_selector_itemAreaNode");
  393. this.itemSearchAreaScrollNode = this.node.getElement(".MWF_selector_itemSearchAreaScrollNode");
  394. this.itemSearchAreaNode = this.node.getElement(".MWF_selector_itemSearchAreaNode");
  395. this.selectedContainerNode = this.node.getElement(".MWF_selector_selectedContainerNode");
  396. this.selectedTopNode = this.node.getElement(".MWF_selector_selectedTopNode");
  397. this.selectedTopTextNode = this.node.getElement(".MWF_selector_selectedTopTextNode");
  398. this.emptySelectedNode = this.node.getElement(".MWF_selector_emptySelectedNode");
  399. this.selectedScrollNode = this.node.getElement(".MWF_selector_selectedScrollNode");
  400. this.selectedNode = this.node.getElement(".MWF_selector_selectedNode");
  401. this.selectedItemSearchAreaNode = this.node.getElement(".MWF_selector_selectedItemSearchAreaNode");
  402. this.actionNode = this.node.getElement(".MWF_selector_actionNode");
  403. this.okActionNode = this.node.getElement(".MWF_selector_okActionNode");
  404. this.cancelActionNode = this.node.getElement(".MWF_selector_cancelActionNode");
  405. if (this.titleNode) this.titleNode.setStyles( layout.mobile ? this.css.titleNodeMobile : this.css.titleNode );
  406. if (this.titleTextNode){
  407. this.titleTextNode.setStyles(layout.mobile ? this.css.titleTextNodeMobile : this.css.titleTextNode);
  408. if(this.options.title)this.titleTextNode.set("text", this.options.title);
  409. }
  410. if (this.titleActionNode)this.titleActionNode.setStyles(this.css.titleActionNode);
  411. if (this.titleCancelActionNode) this.titleCancelActionNode.setStyles(this.css.titleCancelActionNodeMobile);
  412. if (this.titleOkActionNode) this.titleOkActionNode.setStyles(this.css.titleOkActionNodeMobile);
  413. if (this.contentNode) this.contentNode.setStyles(this.css.contentNode);
  414. if (this.selectNode) this.selectNode.setStyles( layout.mobile ? this.css.selectNodeMobile : this.css.selectNode);
  415. if (this.selectTopNode)this.selectTopNode.setStyles(this.css.selectTopNode);
  416. if (this.selectTopTextNode)this.selectTopTextNode.setStyles(this.css.selectTopTextNode);
  417. if (this.searchInputDiv) this.searchInputDiv.setStyles(this.css.searchInputDiv);
  418. if (this.searchInput) this.searchInput.setStyles( (this.options.count.toInt()===1 || this.options.noSelectedContainer) ? this.css.searchInputSingle : this.css.searchInput );
  419. if (this.searchCancelAction) this.searchCancelAction.setStyles(this.css.searchCancelAction);
  420. if (this.letterActionNode) this.letterActionNode.setStyles(this.css.letterActionNode);
  421. if (this.letterAreaNode) this.letterAreaNode.setStyles(this.css.letterAreaNode);
  422. if (this.itemAreaScrollNode) this.itemAreaScrollNode.setStyles(this.css.itemAreaScrollNode);
  423. if (this.itemAreaNode) this.itemAreaNode.setStyles(this.css.itemAreaNode);
  424. if (this.itemSearchAreaScrollNode) this.itemSearchAreaScrollNode.setStyles(this.css.itemSearchAreaScrollNode);
  425. if (this.itemSearchAreaNode) this.itemSearchAreaNode.setStyles(this.css.itemAreaNode);
  426. if (this.selectedContainerNode)this.selectedContainerNode.setStyles(this.css.selectedContainerNode);
  427. if (this.selectedTopNode)this.selectedTopNode.setStyles(this.css.selectedTopNode);
  428. if (this.selectedTopTextNode)this.selectedTopTextNode.setStyles(this.css.selectedTopTextNode);
  429. if (this.emptySelectedNode)this.emptySelectedNode.setStyles(this.css.selectedTopActionNode);
  430. if (this.selectedScrollNode) this.selectedScrollNode.setStyles(this.css.selectedScrollNode);
  431. if (this.selectedNode) this.selectedNode.setStyles(this.css.selectedNode);
  432. if (this.selectedItemSearchAreaNode) this.selectedItemSearchAreaNode.setStyles(this.css.itemAreaNode);
  433. if (this.actionNode) this.actionNode.setStyles(this.css.actionNode);
  434. if (this.okActionNode) {
  435. this.okActionNode.setStyles(this.css.okActionNode);
  436. this.okActionNode.set("text", MWF.SelectorLP.ok);
  437. }
  438. if (this.cancelActionNode) {
  439. this.cancelActionNode.setStyles(this.css.cancelActionNode);
  440. this.cancelActionNode.set("text", MWF.SelectorLP.cancel);
  441. }
  442. this.node.inject( container );
  443. this.loadContent();
  444. if( this.actionNode ){
  445. this.loadAction();
  446. }
  447. if( !this.options.embedded ){
  448. if( layout.mobile ){
  449. this.node.setStyles({
  450. "top": "0px",
  451. "left": "0px"
  452. });
  453. }else{
  454. if( this.options.width || this.options.height ){
  455. this.setSize()
  456. }
  457. this.node.position({
  458. relativeTo: this.container,
  459. position: "center",
  460. edge: "center"
  461. });
  462. var size = this.container.getSize();
  463. var nodeSize = this.node.getSize();
  464. this.node.makeDraggable({
  465. "handle": this.titleNode,
  466. "limit": {
  467. "x": [0, size.x - nodeSize.x],
  468. "y": [0, size.y - nodeSize.y]
  469. }
  470. });
  471. }
  472. }else{
  473. if( this.options.width || this.options.height ){
  474. this.setSize()
  475. }
  476. }
  477. this.setEvent();
  478. },
  479. switchLetterArea: function(){
  480. var showing = this.letterAreaNode.offsetParent;
  481. this.letterAreaNode.setStyle("display", showing ? "none" : "" );
  482. this.letterActionNode.setStyles( showing ? this.css.letterActionNode : this.css.letterActionNode_active )
  483. if( showing ){
  484. this.letterActionNode.removeClass("MWF_selector_letterActionNode_active");
  485. if( this.options.mainColorEnable )this.letterActionNode.removeClass("mainColor_color");
  486. }else{
  487. this.letterActionNode.addClass("MWF_selector_letterActionNode_active");
  488. if( this.options.mainColorEnable )this.letterActionNode.addClass("mainColor_color");
  489. }
  490. if( this.letterAreaNode.offsetParent )this.loadLetters();
  491. var height = this.selectNode.getSize().y - this.getOffsetY( this.selectNode );
  492. if( this.searchInput ){
  493. height = height - this.getOffsetY( this.searchInputDiv ) - ( this.searchInputDiv.getStyle("height").toInt() || 0 )
  494. }
  495. if( !showing ){
  496. height = height - this.getOffsetY( this.letterAreaNode ) - ( this.letterAreaNode.getStyle("height").toInt() || 0 );
  497. }
  498. this.itemAreaScrollNode.setStyle("height", ""+height+"px");
  499. if( this.itemSearchAreaScrollNode ){
  500. this.itemSearchAreaScrollNode.setStyle("height", ""+height+"px");
  501. }
  502. },
  503. getUnitIdentityCount : function(){
  504. },
  505. getUnitSelecteIndentityCount : function( unitLevelName ){ //根据组织获取已选身份数
  506. var count;
  507. this.selectedItems.each( function (item) {
  508. if( item.data.unitLevelName.indexOf( unitLevelName ) === 0 )count++;
  509. }.bind(this));
  510. return count;
  511. },
  512. getGroupNestCount : function(){
  513. // o2.Actions.load("x_organization_assemble_express").
  514. },
  515. getGroupSelecteIndentityCount : function( groupName ){ //根据组织获取已选身份数
  516. var count;
  517. this.selectedItems.each( function (item) {
  518. if( item.data.unitLevelName.indexOf( unitLevelName ) === 0 )count++;
  519. }.bind(this));
  520. return count;
  521. },
  522. setEvent: function(){
  523. if (this.titleActionNode){
  524. this.titleActionNode.addEvent("click", function(){
  525. this.fireEvent("cancel", this);
  526. this.close();
  527. }.bind(this));
  528. }
  529. if (this.titleCancelActionNode){
  530. this.titleCancelActionNode.addEvent("click", function(){
  531. this.fireEvent("cancel", this);
  532. this.close();
  533. }.bind(this));
  534. }
  535. if (this.titleOkActionNode){
  536. this.titleOkActionNode.addEvent("click", function(){
  537. this.fireEvent("complete", [this.selectedItems]);
  538. if( this.options.closeOnclickOk !== false )this.close();
  539. }.bind(this));
  540. }
  541. },
  542. close: function(){
  543. this.fireEvent("close");
  544. this.clearTooltip();
  545. this.node.destroy();
  546. //if (this.mask) this.mask.hide();
  547. if( !this.options.embedded ){
  548. (this.maskRelativeNode || this.container).unmask();
  549. }
  550. if (this.maskInterval){
  551. window.clearInterval(this.maskInterval);
  552. this.maskInterval = null;
  553. }
  554. this.active = false;
  555. MWF.release(this);
  556. delete this;
  557. },
  558. clearTooltip: function(){
  559. if( this.tooltips && this.tooltips.length ){
  560. this.tooltips.each(function (tooltip) {
  561. if(tooltip.destroy)tooltip.destroy();
  562. }.bind(this));
  563. this.tooltips = [];
  564. }
  565. },
  566. loadAction: function(){
  567. if( !this.okActionNode ){
  568. this.okActionNode = new Element("button", {
  569. "styles": this.css.okActionNode,
  570. "text": MWF.SelectorLP.ok
  571. }).inject(this.actionNode);
  572. }
  573. if( !this.cancelActionNode ){
  574. this.cancelActionNode = new Element("button", {
  575. "styles": this.css.cancelActionNode,
  576. "text": MWF.SelectorLP.cancel
  577. }).inject(this.actionNode);
  578. }
  579. this.okActionNode.addEvent("click", function(){
  580. this.fireEvent("complete", [this.selectedItems]);
  581. if( this.options.closeOnclickOk !== false )this.close();
  582. }.bind(this));
  583. this.cancelActionNode.addEvent("click", function(){this.fireEvent("cancel", this); this.close();}.bind(this));
  584. },
  585. loadContent: function( contentNode, isHTML ){
  586. this.selectedItemsMap = {};
  587. this.fireEvent("queryLoadContent",[this]);
  588. if( contentNode )this.contentNode = contentNode;
  589. if( this.options.contentUrl || isHTML ){
  590. if( layout.mobile ){
  591. this.loadSelectedNodeHTMLMobile();
  592. this.loadSelectNodeHTMLMobile(contentNode);
  593. }else{
  594. this.loadSelectNodeHTML(contentNode);
  595. this.loadSelectedNodeHTML();
  596. }
  597. }else{
  598. if (layout.mobile){
  599. this.loadSelectedNodeMobile();
  600. this.loadSelectNodeMobile();
  601. this.setSelectedItem();
  602. }else{
  603. this.loadSelectNode();
  604. if( this.options.hasShuttle ){
  605. this.loadShuttleNode();
  606. }
  607. //if (this.options.count.toInt()!==1) this.loadSelectedNode();
  608. this.loadSelectedNode();
  609. }
  610. }
  611. this.fireEvent("postLoadContent", [this]);
  612. },
  613. getOffsetX : function(node){
  614. return (node.getStyle("margin-left").toInt() || 0 )+
  615. (node.getStyle("margin-right").toInt() || 0 ) +
  616. (node.getStyle("padding-left").toInt() || 0 ) +
  617. (node.getStyle("padding-right").toInt() || 0 ) +
  618. (node.getStyle("border-left-width").toInt() || 0 ) +
  619. (node.getStyle("border-right-width").toInt() || 0 );
  620. },
  621. getOffsetY : function(node){
  622. return (node.getStyle("margin-top").toInt() || 0 ) +
  623. (node.getStyle("margin-bottom").toInt() || 0 ) +
  624. (node.getStyle("padding-top").toInt() || 0 ) +
  625. (node.getStyle("padding-bottom").toInt() || 0 )+
  626. (node.getStyle("border-top-width").toInt() || 0 ) +
  627. (node.getStyle("border-bottom-width").toInt() || 0 );
  628. },
  629. loadSelectNodeHTML: function(contentNode){
  630. var size;
  631. var height;
  632. debugger;
  633. if( contentNode ){
  634. size = contentNode.getSize();
  635. height = size.y;
  636. if( height === 0 ){
  637. height = contentNode.getStyle("height").toInt();
  638. }
  639. }else{
  640. size = this.node.getSize();
  641. // var zoom = this.node.getStyle("zoom").toInt() || 0;
  642. // if( zoom ){
  643. // size.x = size.x * 100 / zoom;
  644. // size.y = size.y * 100 / zoom;
  645. // }
  646. height = size.y-this.getOffsetY( this.contentNode );
  647. if( this.titleNode ){
  648. height = height - this.getOffsetY( this.titleNode ) - ( this.titleNode.getStyle("height").toInt() || 0 )
  649. }
  650. if( this.actionNode ){
  651. height = height - this.getOffsetY( this.actionNode ) - ( this.actionNode.getStyle("height").toInt() || 0 )
  652. }
  653. this.contentNode.setStyle("height", ""+height+"px");
  654. }
  655. height = height - this.getOffsetY( this.selectNode );
  656. this.selectNode.setStyle("height", ""+height+"px");
  657. this.selectedContainerNode.setStyle("height", ""+height+"px");
  658. var selectedTopHeight = 0;
  659. if( this.selectedTopNode )selectedTopHeight = this.getOffsetY( this.selectedTopNode ) + ( this.selectedTopNode.getStyle("height").toInt() || 0 )
  660. this.selectedScrollNode.setStyle("height", ""+( height - selectedTopHeight )+"px");
  661. if( this.searchInput ){
  662. this.initSearchInput();
  663. height = height - this.getOffsetY( this.searchInputDiv ) - ( this.searchInputDiv.getStyle("height").toInt() || 0 )
  664. }
  665. if( this.options.hasLetter && this.letterAreaNode){
  666. if( this.letterAreaNode.offsetParent ){
  667. this.loadLetters();
  668. height = height - this.getOffsetY( this.letterAreaNode ) - ( this.letterAreaNode.getStyle("height").toInt() || 0 );
  669. }
  670. }
  671. this.itemAreaScrollNode.setStyle("height", ""+height+"px");
  672. this.itemAreaScrollNode.setStyle("overflow", "auto");
  673. if(this.itemSearchAreaScrollNode){
  674. this.itemSearchAreaScrollNode.setStyles({
  675. "display": "none",
  676. "height": ""+height+"px",
  677. "overflow" : "auto"
  678. });
  679. }
  680. this.itemSearchAreaNode.setStyle("display", "none");
  681. this.initLoadSelectItems();
  682. this.checkLoadSelectItems();
  683. },
  684. loadSelectedNodeHTML: function(){
  685. if( this.emptySelectedNode ){
  686. this.emptySelectedNode.addEvent("click", function () {
  687. this.emptySelectedItems()
  688. }.bind(this))
  689. }
  690. this.setSelectedItem();
  691. //if(this.selectedScrollNode)this.selectedScrollNode.setStyle("display", "none");
  692. },
  693. loadSelectNodeHTMLMobile: function(contentNode){
  694. var size;
  695. var height;
  696. if( contentNode ){
  697. size = contentNode.getSize();
  698. height = size.y;
  699. if( height === 0 ){
  700. height = contentNode.getStyle("height").toInt();
  701. }
  702. }else{
  703. var container = this.options.injectToBody ? $(document.body) : this.container;
  704. //var containerSize = this.container.getSize();
  705. //var bodySize = $(document.body).getSize();
  706. size = container.getSize();
  707. if(size.y === 0){
  708. size.y = $(document.body).getSize().y
  709. }
  710. //size = {
  711. // "x" : Math.min( containerSize.x, bodySize.x ),
  712. // "y" : Math.min( containerSize.y, bodySize.y )
  713. //};
  714. if(this.node){
  715. var zoom = this.node.getStyle("zoom").toInt();
  716. zoom = zoom ? (zoom * 100) : 0;
  717. if( zoom ){
  718. size.x = size.x * 100 / zoom;
  719. size.y = size.y * 100 / zoom;
  720. }
  721. this.node.setStyles({
  722. "width" : size.x+"px",
  723. "height" : size.y+"px"
  724. })
  725. }
  726. height = size.y-this.getOffsetY( this.contentNode );
  727. if( this.titleNode ){
  728. height = height - this.getOffsetY( this.titleNode ) - ( this.titleNode.getStyle("height").toInt() || 0 )
  729. }
  730. if( this.actionNode ){
  731. height = height - this.getOffsetY( this.actionNode ) - ( this.actionNode.getStyle("height").toInt() || 0 )
  732. }
  733. this.contentNode.setStyle("height", ""+height+"px");
  734. }
  735. var isFormWithAction = window.location.href.toLowerCase().indexOf("workmobilewithaction.html") > -1;
  736. this.selectNode.setStyle("height", ""+height+"px");
  737. if( this.searchInput ){
  738. this.initSearchInput();
  739. height = height - this.getOffsetY( this.searchInputDiv ) - ( this.searchInputDiv.getStyle("height").toInt() || 0 )
  740. }
  741. if( this.options.hasLetter && this.letterAreaNode ){
  742. var width = size.x - 18;
  743. this.letterAreaNode.setStyle("width", "" + width + "px");
  744. this.loadLetters();
  745. height = height - this.getOffsetY( this.letterAreaNode ) - ( this.letterAreaNode.getStyle("height").toInt() || 0 )
  746. }
  747. this.itemAreaScrollNode.setStyle("height", ""+height+"px");
  748. this.itemAreaScrollNode.setStyle("overflow", "auto");
  749. if(this.itemSearchAreaScrollNode){
  750. this.itemSearchAreaScrollNode.setStyles({
  751. "display": "none",
  752. "height": ""+height+"px",
  753. "overflow" : "auto"
  754. });
  755. }
  756. this.itemSearchAreaNode.setStyle("display", "none");
  757. this.initLoadSelectItems();
  758. this.checkLoadSelectItems();
  759. },
  760. loadSelectNodeMobile: function(){
  761. this.selectNode = new Element("div.selectNode", {
  762. "styles": this.css.selectNodeMobile
  763. }).inject(this.contentNode);
  764. var containerSize = this.container.getSize();
  765. var bodySize = $(document.body).getSize();
  766. var size = {
  767. "x" : Math.min( containerSize.x, bodySize.x ),
  768. "y" : Math.min( containerSize.y, bodySize.y )
  769. };
  770. var height;
  771. if( !this.inMulitple ){
  772. var isFormWithAction = window.location.href.toLowerCase().indexOf("workmobilewithaction.html") > -1;
  773. var formActionY = 0;
  774. if( isFormWithAction ){
  775. // var formActions = document.getElement(".o2_form_mobile_actions");
  776. // if(formActions)formActionY = formActions.getSize().y - this.getOffsetY(formActions);
  777. }
  778. height = size.y - formActionY - this.titleNode.getSize().y - this.getOffsetY(this.titleNode);
  779. this.selectNode.setStyle("height", ""+height+"px");
  780. }
  781. this.searchInputDiv = new Element("div.searchInputDiv", {
  782. "styles": this.css.searchInputDiv
  783. }).inject(this.selectNode);
  784. this.searchInput = new Element("input.searchInput", {
  785. "styles": (this.options.count.toInt()===1 || this.options.noSelectedContainer) ? this.css.searchInputSingle : this.css.searchInput,
  786. "type": "text"
  787. }).inject(this.searchInputDiv);
  788. var width = size.x-20-18;
  789. this.searchInput.setStyle("width", ""+width+"px");
  790. this.searchInput.setStyle("height", "20px");
  791. this.initSearchInput();
  792. if( this.options.hasLetter ) {
  793. this.letterAreaNode = new Element("div", {
  794. "styles": this.css.letterAreaMobileNode
  795. }).inject(this.selectNode);
  796. width = size.x - 18;
  797. this.letterAreaNode.setStyle("width", "" + width + "px");
  798. this.loadLetters();
  799. }
  800. this.itemAreaScrollNode = new Element("div.itemAreaScrollNode", {
  801. "styles": this.css.itemAreaScrollNode
  802. }).inject(this.selectNode);
  803. this.loadSelectedCountNode();
  804. if( !this.inMulitple ) {
  805. var y = this.getOffsetY(this.itemAreaScrollNode);
  806. if (this.searchInputDiv) y = y + this.searchInputDiv.getSize().y + this.getOffsetY(this.searchInputDiv);
  807. if (this.letterAreaNode) y = y + this.letterAreaNode.getSize().y + this.getOffsetY(this.letterAreaNode);
  808. if (this.selectedCountNode) y = y + this.selectedCountNode.getSize().y + this.getOffsetY(this.selectedCountNode);
  809. height = height - y;
  810. this.itemAreaScrollNode.setStyle("height", "" + height + "px");
  811. if( this.itemSearchAreaScrollNode ){
  812. this.itemSearchAreaScrollNode.setStyle("height", "" + height + "px");
  813. }
  814. }
  815. this.itemAreaScrollNode.setStyle("overflow", "auto");
  816. this.itemAreaNode = new Element("div.itemAreaNode", {
  817. "styles": this.css.itemAreaNode
  818. }).inject(this.itemAreaScrollNode);
  819. this.itemSearchAreaNode = new Element("div.itemSearchAreaNode", {
  820. "styles": this.css.itemAreaNode
  821. }).inject(this.itemAreaScrollNode);
  822. this.itemSearchAreaNode.setStyle("display", "none");
  823. this.initLoadSelectItems();
  824. this.checkLoadSelectItems();
  825. },
  826. loadSelectedNodeHTMLMobile: function(){
  827. this.setSelectedItem();
  828. if(this.selectedScrollNode)this.selectedScrollNode.setStyle("display", "none");
  829. },
  830. checkLoadSelectItems: function(){
  831. if (!this.options.groups.length && !this.options.roles.length){
  832. this.loadSelectItems();
  833. }else{
  834. this.loadSelectItemsByCondition();
  835. }
  836. },
  837. loadShuttleNode : function(){
  838. if(this.shuttleNode)return;
  839. this.shuttleNode = new Element("div.shuttleNode", {
  840. "styles": this.css.shuttleNode
  841. }).inject(this.contentNode);
  842. this.shuttleInnerNode = new Element("div.shuttleInnerNode", {
  843. "styles": this.css.shuttleInnerNode
  844. }).inject(this.shuttleNode);
  845. this.goRightNode = new Element("div.goRightNode", {
  846. "styles": this.css.goRightNode
  847. }).inject(this.shuttleInnerNode);
  848. this.goLeftNode = new Element("div.goLeftNode", {
  849. "styles": this.css.goLeftNode
  850. }).inject(this.shuttleInnerNode);
  851. },
  852. loadSelectNode: function(){
  853. this.selectNode = new Element("div.selectNode", {
  854. "styles": this.css.selectNode //(this.options.count.toInt()===1) ? this.css.selectNodeSingle : this.css.selectNode
  855. }).inject(this.contentNode);
  856. if( this.options.hasTop ){ //if( this.options.embedded && this.options.count.toInt()!==1 ){
  857. this.selectTopNode = new Element("div.selectTopNode",{
  858. "styles" : this.css.selectTopNode
  859. }).inject( this.selectNode );
  860. this.selectTopTextNode = new Element("div",{
  861. "text" : MWF.SelectorLP.waitingSelect,
  862. "styles" : this.css.selectTopTextNode
  863. }).inject( this.selectTopNode );
  864. }
  865. if( this.options.searchbarInTopNode ){
  866. this.searchInputDiv = new Element("div", {
  867. "styles": this.css.searchInputDiv
  868. }).inject( this.selectTopNode || this.selectNode);
  869. }else{
  870. this.searchInputDiv = new Element("div.searchInputDiv", {
  871. "styles": this.css.searchInputDiv
  872. }).inject( this.selectNode);
  873. }
  874. this.searchInput = new Element("input", {
  875. "styles": this.css.searchInput, //(this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput,
  876. "placeholder" : MWF.SelectorLP['searchDescription'+this.className] || MWF.SelectorLP.searchDescription,
  877. "type": "text"
  878. }).inject(this.searchInputDiv);
  879. if( this.css.searchCancelAction ){
  880. this.searchCancelAction = new Element("div.searchCancelAction", {
  881. "styles": this.css.searchCancelAction
  882. }).inject( this.searchInputDiv);
  883. }
  884. this.initSearchInput();
  885. if( this.options.hasLetter ){
  886. this.letterAreaNode = new Element("div", {
  887. "styles": this.css.letterAreaNode
  888. }).inject(this.selectNode);
  889. this.loadLetters();
  890. }
  891. this.itemAreaScrollNode = new Element("div", {
  892. "styles": this.css.itemAreaScrollNode
  893. }).inject(this.selectNode);
  894. this.itemAreaNode = new Element("div", {
  895. "styles": this.css.itemAreaNode
  896. }).inject(this.itemAreaScrollNode);
  897. this.itemSearchAreaNode = new Element("div", {
  898. "styles": this.css.itemAreaNode
  899. }).inject(this.itemAreaScrollNode);
  900. this.itemSearchAreaNode.setStyle("display", "none");
  901. this.loadSelectNodeScroll();
  902. this.initLoadSelectItems();
  903. this.checkLoadSelectItems();
  904. },
  905. loadSelectNodeScroll: function(){
  906. var overflowY = this.itemAreaScrollNode.getStyle("overflow-y");
  907. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") )return;
  908. MWF.require("MWF.widget.ScrollBar", function(){
  909. var _self = this;
  910. new MWF.widget.ScrollBar(this.itemAreaScrollNode, {
  911. "style":"xApp_Organization_Explorer",
  912. "where": "before",
  913. "distance": 30,
  914. "friction": 4,
  915. "axis": {"x": false, "y": true},
  916. "onScroll": function(y){
  917. _self._scrollEvent(y);
  918. }
  919. });
  920. }.bind(this));
  921. },
  922. initSearchInput: function(){
  923. this.searchInput.addEvents({
  924. "keyup": function(e){
  925. var iTimerID = this.searchInput.retrieve("searchTimer", null);
  926. if (iTimerID){
  927. window.clearTimeout(iTimerID);
  928. this.searchInput.eliminate("searchTimer");
  929. }
  930. iTimerID = window.setTimeout(function(){
  931. this.search();
  932. }.bind(this), 800);
  933. this.searchInput.store("searchTimer", iTimerID);
  934. if(this.searchCancelAction)this.searchCancelAction.show();
  935. }.bind(this),
  936. "change": function(e){
  937. var key = this.searchInput.get("value");
  938. if (!key) this.initSearchArea(false);
  939. if(this.searchCancelAction)this.searchCancelAction[ key ? "show" : "hide" ]();
  940. }.bind(this),
  941. "blur": function(){
  942. var key = this.searchInput.get("value");
  943. if (!key) this.initSearchArea(false);
  944. if(this.searchCancelAction)this.searchCancelAction[ key ? "show" : "hide" ]();
  945. }.bind(this)
  946. });
  947. if( this.letterActionNode ){
  948. this.letterActionNode.addEvent("click", function () {
  949. this.switchLetterArea()
  950. }.bind(this))
  951. }
  952. if( this.searchCancelAction && this.searchInput ){
  953. this.searchCancelAction.addEvent("click", function () {
  954. this.searchInput.set("value", "");
  955. this.searchInput.focus();
  956. this.initSearchArea(false);
  957. this.searchCancelAction.hide();
  958. }.bind(this))
  959. }
  960. },
  961. initSearchArea: function(flag){
  962. this.searchItems = [];
  963. if (flag){
  964. this.itemSearchAreaNode.empty();
  965. this.itemAreaNode.setStyle("display", "none");
  966. if( this.itemSearchAreaNode.getParent() !== this.itemAreaScrollNode ){
  967. this.itemAreaScrollNode.setStyle("display", "none");
  968. }
  969. if(this.flatCategoryScrollNode){
  970. this.flatCategoryScrollNode.setStyle("display", "none");
  971. }
  972. if( this.itemSearchAreaScrollNode )this.itemSearchAreaScrollNode.setStyle("display", "block");
  973. this.itemSearchAreaNode.setStyle("display", "block");
  974. }else{
  975. this.itemAreaScrollNode.setStyle("display", "block");
  976. this.itemAreaNode.setStyle("display", "block");
  977. if(this.flatCategoryScrollNode && this.flatSubCategoryNodeList && this.flatSubCategoryNodeList.length > 1 ){
  978. this.flatCategoryScrollNode.setStyle("display", "block");
  979. }
  980. if( this.itemSearchAreaScrollNode )this.itemSearchAreaScrollNode.setStyle("display", "none");
  981. this.itemSearchAreaNode.setStyle("display", "none");
  982. }
  983. },
  984. search: function(){
  985. if (!this.options.groups.length && !this.options.roles.length && !this.options.forceSearchInItem ){
  986. var key = this.searchInput.get("value");
  987. if (key){
  988. this._listItemByKey(function(json){
  989. this.initSearchArea(true);
  990. json.data.each(function(data){
  991. if( !this.isExcluded( data ) ) {
  992. var itemSearch = this._newItemSearch(data, this, this.itemSearchAreaNode);
  993. this.searchItems.push( itemSearch );
  994. }
  995. //this._newItem(data, this, this.itemSearchAreaNode);
  996. }.bind(this));
  997. }.bind(this), null, key);
  998. }else{
  999. this.initSearchArea(false);
  1000. }
  1001. }else{
  1002. var key = this.searchInput.get("value");
  1003. if (key){
  1004. this.initSearchArea(true);
  1005. this.searchInItems(key);
  1006. }else{
  1007. this.initSearchArea(false);
  1008. }
  1009. }
  1010. },
  1011. searchInItems: function(key){
  1012. var createdId = [];
  1013. this.createItemsSearchData(function(){
  1014. var word = key.toLowerCase();
  1015. this.itemsSearchData.each(function(obj){
  1016. var text = obj.text+"#"+obj.pinyin+"#"+obj.firstPY;
  1017. var id = obj.data.distinguishedName || obj.data.id || obj.data.name || obj.data.text;
  1018. if (text.indexOf(word)!==-1){
  1019. if (createdId.indexOf( id )===-1){
  1020. this._newItem(obj.data, this, this.itemSearchAreaNode);
  1021. createdId.push( id );
  1022. }
  1023. }
  1024. }.bind(this));
  1025. //delete createdId;
  1026. }.bind(this));
  1027. return createdId;
  1028. },
  1029. createItemsSearchData: function(callback){
  1030. if (!this.itemsSearchData){
  1031. this.itemsSearchData = [];
  1032. MWF.require("MWF.widget.PinYin", function(){
  1033. var initIds = [];
  1034. this.items.each(function(item){
  1035. var id = item.data.distinguishedName || item.data.id || item.data.name || item.data.text;
  1036. if (initIds.indexOf( id )==-1){
  1037. var text = item._getShowName().toLowerCase();
  1038. var pinyin = text.toPY().toLowerCase();
  1039. var firstPY = text.toPYFirst().toLowerCase();
  1040. this.itemsSearchData.push({
  1041. "text": text,
  1042. "pinyin": pinyin,
  1043. "firstPY": firstPY,
  1044. "data": item.data
  1045. });
  1046. initIds.push( id );
  1047. }
  1048. }.bind(this));
  1049. delete initIds;
  1050. if (callback) callback();
  1051. }.bind(this));
  1052. }else{
  1053. if (callback) callback();
  1054. }
  1055. },
  1056. initSelectedSearchInput: function(){
  1057. this.selectedSearchInput.addEvents({
  1058. "keyup": function(e){
  1059. var iTimerID = this.selectedSearchInput.retrieve("searchTimer", null);
  1060. if (iTimerID){
  1061. window.clearTimeout(iTimerID);
  1062. this.selectedSearchInput.eliminate("searchTimer");
  1063. }
  1064. iTimerID = window.setTimeout(function(){
  1065. this.selectedSearch();
  1066. }.bind(this), 800);
  1067. this.selectedSearchInput.store("searchTimer", iTimerID);
  1068. if(this.selectedSearchCancelAction)this.selectedSearchCancelAction.show();
  1069. }.bind(this),
  1070. "change": function(e){
  1071. var key = this.selectedSearchInput.get("value");
  1072. if (!key) this.selectedSearch();
  1073. if(this.selectedSearchCancelAction)this.selectedSearchCancelAction[ key ? "show" : "hide" ]();
  1074. }.bind(this),
  1075. "blur": function(){
  1076. var key = this.selectedSearchInput.get("value");
  1077. if (!key) this.selectedSearch();
  1078. if(this.selectedSearchCancelAction)this.selectedSearchCancelAction[ key ? "show" : "hide" ]();
  1079. }.bind(this)
  1080. });
  1081. if( this.selectedSearchCancelAction && this.selectedSearchInput ){
  1082. this.selectedSearchCancelAction.addEvent("click", function () {
  1083. this.selectedSearchInput.set("value", "");
  1084. this.selectedSearchInput.focus();
  1085. this.selectedSearch();
  1086. this.selectedSearchCancelAction.hide();
  1087. }.bind(this))
  1088. }
  1089. },
  1090. selectedSearch: function(){
  1091. var key = this.selectedSearchInput.get("value");
  1092. if (key){
  1093. this.selectedSearchInItems(key);
  1094. }else{
  1095. this.showAllSelectedItem()
  1096. }
  1097. },
  1098. selectedSearchInItems: function(key){
  1099. var word = key.toLowerCase();
  1100. MWF.require("MWF.widget.PinYin", function() {
  1101. this.selectedItems.each(function (item) {
  1102. if (!item.searchedText) {
  1103. var text = item._getShowName().toLowerCase();
  1104. var pinyin = text.toPY().toLowerCase();
  1105. var firstPY = text.toPYFirst().toLowerCase();
  1106. item.searchedText = text + "#" + pinyin + "#" + firstPY
  1107. }
  1108. if (item.searchedText.indexOf(word) !== -1) {
  1109. item.node.show()
  1110. } else {
  1111. item.node.hide()
  1112. }
  1113. }.bind(this));
  1114. }.bind(this), null, false);
  1115. },
  1116. showAllSelectedItem: function(){
  1117. this.selectedItems.each(function(item){
  1118. item.node.show()
  1119. })
  1120. },
  1121. loadSelectedNode: function( callback ){
  1122. if( this.selectedContainerNode )return;
  1123. this.selectedContainerNode = new Element("div", {
  1124. "styles": this.css.selectedContainerNode
  1125. }).inject(this.contentNode);
  1126. if( this.options.noSelectedContainer ){
  1127. this.selectedContainerNode.hide();
  1128. }
  1129. //if( this.options.embedded && this.options.count.toInt()!==1 ){
  1130. if( this.options.hasTop ){
  1131. this.selectedTopNode = new Element("div",{
  1132. "styles" : this.css.selectedTopNode
  1133. }).inject( this.selectedContainerNode );
  1134. this.selectedTopTextNode = new Element("div",{
  1135. "text" : MWF.SelectorLP.selected,
  1136. "styles" : this.css.selectedTopTextNode
  1137. }).inject( this.selectedTopNode );
  1138. this.emptySelectedNode = new Element("div",{
  1139. "text" : MWF.SelectorLP.empty,
  1140. "styles" : this.css.selectedTopActionNode,
  1141. "events" : {
  1142. "click" : function(){
  1143. this.emptySelectedItems()
  1144. }.bind(this)
  1145. }
  1146. }).inject( this.selectedTopNode );
  1147. }
  1148. if( this.options.hasSelectedSearchbar ){
  1149. if( this.options.searchbarInTopNode ){
  1150. this.selectedSearchInputDiv = new Element("div", {
  1151. "styles": this.css.searchInputDiv
  1152. }).inject( this.selectedTopNode || this.selectedContainerNode);
  1153. }else{
  1154. this.selectedSearchInputDiv = new Element("div.selectedSearchInputDiv", {
  1155. "styles": this.css.searchInputDiv
  1156. }).inject( this.selectedContainerNode);
  1157. }
  1158. this.selectedSearchInput = new Element("input", {
  1159. "styles": this.css.searchInput, //(this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput,
  1160. "placeholder" : MWF.SelectorLP.searchDescription,
  1161. "type": "text"
  1162. }).inject(this.selectedSearchInputDiv);
  1163. if( this.css.searchCancelAction ){
  1164. this.selectedSearchCancelAction = new Element("div.selectedSearchCancelAction", {
  1165. "styles": this.css.searchCancelAction
  1166. }).inject( this.selectedSearchInputDiv);
  1167. }
  1168. this.initSelectedSearchInput();
  1169. }
  1170. this.selectedScrollNode = new Element("div.selectedScrollNode", {
  1171. "styles": this.css.selectedScrollNode
  1172. }).inject(this.selectedContainerNode);
  1173. this.selectedNode = new Element("div.selectedNode", {
  1174. "styles": this.css.selectedNode
  1175. }).inject(this.selectedScrollNode);
  1176. if( this.options.hasSelectedSearchbar ){
  1177. this.selectedItemSearchAreaNode = new Element("div.selectedItemSearchAreaNode", {
  1178. "styles": this.css.itemAreaNode
  1179. }).inject(this.selectedScrollNode);
  1180. this.selectedItemSearchAreaNode.setStyle("display", "none");
  1181. }
  1182. this.setSelectedItem();
  1183. this.loadSelectedNodeScroll();
  1184. if(callback)callback();
  1185. },
  1186. emptySelectedItems : function(){
  1187. while (this.selectedItems.length){
  1188. this.selectedItems[0].clickItem();
  1189. }
  1190. },
  1191. loadSelectedNodeScroll: function(){
  1192. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  1193. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") )return;
  1194. MWF.require("MWF.widget.ScrollBar", function(){
  1195. var _self = this;
  1196. new MWF.widget.ScrollBar(this.selectedScrollNode, {
  1197. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
  1198. });
  1199. }.bind(this));
  1200. },
  1201. loadSelectedNodeMobile: function(){
  1202. if( this.inMulitple )return;
  1203. this.css.selectedWrapNodeMobile["z-index"] = this.options.zIndex + 2;
  1204. this.selectedWrapNode = new Element("div.selectedWrapNode", {
  1205. "styles": this.css.selectedWrapNodeMobile
  1206. }).inject(this.contentNode);
  1207. this.selectedTitleNode = new Element("div.selectedTitleNodeMobile", {
  1208. "styles": this.css.selectedTitleNodeMobile
  1209. }).inject(this.selectedWrapNode);
  1210. this.selectedTitleLabelNode = new Element("span", {
  1211. "style": "font-weight:bold; padding-right:5px;",
  1212. "text": MWF.SelectorLP.selected2
  1213. }).inject(this.selectedTitleNode);
  1214. this.selectedTitleCountNode = new Element("span", {
  1215. "text": "(0)"
  1216. }).inject(this.selectedTitleNode);
  1217. this.selectedScrollNode = new Element("div.selectedScrollNode", {
  1218. "styles": this.css.selectedScrollNodeMobile
  1219. }).inject(this.selectedWrapNode);
  1220. this.selectedNode = new Element("div.selectedNode", {
  1221. "styles": this.css.selectedNodeMobile
  1222. }).inject(this.selectedScrollNode);
  1223. this.selectedWrapNode.setStyle("display", "none");
  1224. },
  1225. setSelectedItem: function(){
  1226. var getSelectedIndex = function (e){
  1227. if( !e )return 9999999;
  1228. var key = typeOf( e ) === "string" ? e : ( e.distinguishedName || e.unique || e.employee || e.levelName || e.id );
  1229. return (this.selectedIndexMap||{})[key] || 9999999;
  1230. }.bind(this);
  1231. if (this.options.values.length){
  1232. this.options.values.each(function(v, i){
  1233. var index = getSelectedIndex(v);
  1234. if (typeOf(v)==="object"){
  1235. v.isFromValues = true;
  1236. var selecteditem = this._newItemSelected(v, this, null);
  1237. selecteditem.selectedIndex = index;
  1238. this.selectedItems.push(selecteditem);
  1239. if(this.addToSelectedItemsMap)this.addToSelectedItemsMap(v, selecteditem);
  1240. }else if( typeOf(v)==="string" ){
  1241. var fun = function(json){
  1242. if( !json || !json.data )return;
  1243. this.options.values[i] = json.data;
  1244. json.data.isFromValues = true;
  1245. var selecteditem = this._newItemSelected(json.data, this, null);
  1246. selecteditem.selectedIndex = index;
  1247. this.selectedItems.push(selecteditem);
  1248. if(this.addToSelectedItemsMap)this.addToSelectedItemsMap(json.data, selecteditem);
  1249. }.bind(this);
  1250. if( this.options.resultType === "person" && this.selectType === "identity" && v.split("@").getLast().toLowerCase() === "p" ){
  1251. this.orgAction.getPerson(function(json){
  1252. fun(json);
  1253. }.bind(this), null, v, false);
  1254. }else{
  1255. this._getItem(fun, null, v, false);
  1256. }
  1257. }
  1258. // this._getItem(function(json){
  1259. // this.selectedItems.push(this._newItemSelected(json.data, this, null));
  1260. // }.bind(this), null, v, false);
  1261. }.bind(this));
  1262. }
  1263. },
  1264. setValues: function( values ){
  1265. this.emptySelectedItems();
  1266. this.options.values = values;
  1267. this.setSelectedItem();
  1268. },
  1269. loadLetters: function(){
  1270. if( this.lettersLoaded )return;
  1271. this.lettersLoaded = true;
  1272. var _self = this;
  1273. var letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
  1274. var letterNodeCss = this.css.letterNode;
  1275. var letterNodeCss_over = this.css.letterNode_over;
  1276. if (layout.mobile){
  1277. letterNodeCss = this.css.letterNode_mobile || letterNodeCss;
  1278. letterNodeCss_over = this.css.letterNode_mobile_over || letterNodeCss_over;
  1279. var size = this.container.getSize();
  1280. // var w = (layout.mobile) ? (size.x-18)/13 : (size.x-20-4-18)/13;
  1281. var w = (layout.mobile) ? (size.x - this.getOffsetX(this.container) - this.getOffsetX(this.letterAreaNode) - 10 )/13 : (size.x-20-4-18)/13;
  1282. //letterNode.setStyle("width", ""+w+"px");
  1283. letterNodeCss.width = ""+w+"px";
  1284. letterNodeCss_over.width = ""+w+"px";
  1285. }else if( this.options.style === "flow" ){
  1286. var width = ( this.letterAreaNode.getSize().x - this.getOffsetX(this.letterAreaNode) - 10 ) / 13;
  1287. letterNodeCss.width = ""+width+"px";
  1288. letterNodeCss_over.width = ""+width+"px";
  1289. }
  1290. letters.each(function(l){
  1291. var letterNode = new Element("div", {
  1292. "styles": letterNodeCss,
  1293. "text": l
  1294. }).inject(this.letterAreaNode);
  1295. if (layout.mobile){
  1296. letterNode.addEvents({
  1297. "click": function(){
  1298. _self.listPersonByPinyin(this);
  1299. if(_self.searchCancelAction)_self.searchCancelAction.show();
  1300. }
  1301. });
  1302. }else{
  1303. letterNode.addEvents({
  1304. "mouseover": function(e){
  1305. e.target.setStyles(letterNodeCss_over);
  1306. var showNode = new Element("div", {
  1307. "styles": this.css.letterShowNode,
  1308. "text": e.target.get("text")
  1309. }).inject(this.selectNode);
  1310. showNode.position({
  1311. relativeTo: this.itemAreaScrollNode,
  1312. position: "center",
  1313. edge: "center"
  1314. });
  1315. e.target.store("showNode", showNode);
  1316. }.bind(this),
  1317. "mouseout": function(e){
  1318. var showNode = e.target.retrieve("showNode");
  1319. showNode.destroy();
  1320. e.target.setStyles(letterNodeCss);
  1321. }.bind(this),
  1322. "click": function(){
  1323. _self.listPersonByPinyin(this);
  1324. if(_self.searchCancelAction)_self.searchCancelAction.show();
  1325. }
  1326. });
  1327. }
  1328. }.bind(this));
  1329. },
  1330. listPersonByPinyin: function(node){
  1331. this.searchInput.focus();
  1332. var pinyin = this.searchInput.get("value");
  1333. pinyin = pinyin+node.get("text");
  1334. this.searchInput.set("value", pinyin);
  1335. if (!this.options.groups.length && !this.options.roles.length){
  1336. if (pinyin){
  1337. this._listItemByPinyin(function(json){
  1338. this.initSearchArea(true);
  1339. json.data.each(function(data){
  1340. // var flag = true;
  1341. // if (this.options.departments){
  1342. // if (this.options.departments.length){
  1343. // if (this.options.departments.indexOf(data.departmentName)==-1) flag = false;
  1344. // }
  1345. // }
  1346. // if (this.options.companys){
  1347. // if (this.options.companys.length){
  1348. // if (this.options.companys.indexOf(data.company)==-1) flag = false;
  1349. // }
  1350. // }
  1351. if( !this.isExcluded( data ) ) {
  1352. this._newItemSearch(data, this, this.itemSearchAreaNode);
  1353. }
  1354. //this._newItem(data, this, this.itemSearchAreaNode);
  1355. //this._newItem(data, this, this.itemSearchAreaNode);
  1356. }.bind(this));
  1357. }.bind(this), null, pinyin.toLowerCase());
  1358. }
  1359. }else{
  1360. if (pinyin){
  1361. this.initSearchArea(true);
  1362. this.searchInItems(pinyin);
  1363. }else{
  1364. this.initSearchArea(false);
  1365. }
  1366. }
  1367. },
  1368. initLoadSelectItems: function(){
  1369. this.loaddingItems = false;
  1370. this.isItemLoaded = false;
  1371. this.loadItemsQueue = 0;
  1372. this.initSearchArea(false);
  1373. },
  1374. //loadSelectItems: function(addToNext){
  1375. // if (!this.isItemLoaded){
  1376. // if (!this.loaddingItems){
  1377. // this.loaddingItems = true;
  1378. // var count = 20;
  1379. // this._listItemNext(this.getLastLoadedItemId(), count, function(json){
  1380. // if (json.data.length){
  1381. // json.data.each(function(data){
  1382. // var item = this._newItem(data, this, this.itemAreaNode);
  1383. // this.items.push(item);
  1384. // }.bind(this));
  1385. // this.loaddingItems = false;
  1386. //
  1387. // if (json.data.length<count){
  1388. // this.isItemLoaded = true;
  1389. // }else{
  1390. // if (this.loadItemsQueue>0){
  1391. // this.loadItemsQueue--;
  1392. // this.loadSelectItems();
  1393. // }
  1394. // }
  1395. // }else{
  1396. // this.isItemLoaded = true;
  1397. // this.loaddingItems = false;
  1398. // }
  1399. // }.bind(this));
  1400. // }else{
  1401. // if (addToNext) this.loadItemsQueue++;
  1402. // }
  1403. // }
  1404. //},
  1405. loadSelectItems: function(addToNext, lastExcludeCount ){
  1406. //lastExcludeCount 参数:表示本次加载是为了补足上次load的时候被排除的数量
  1407. if (!this.isItemLoaded){
  1408. if (!this.loaddingItems){
  1409. this.loaddingItems = true;
  1410. var count = 20;
  1411. this._listItemNext(this.getLastLoadedItemId(), count, function(json){
  1412. if (json.data.length){
  1413. var excludedCount = 0;
  1414. json.data.each(function(data, i){
  1415. if( this.isExcluded( data ) ){
  1416. excludedCount++;
  1417. if( i+1 === count )this.tailExcludeItemId = data.distinguishedName
  1418. }else{
  1419. var item = this._newItem(data, this, this.itemAreaNode);
  1420. this.items.push(item);
  1421. if( i+1 === count )this.tailExcludeItemId = null;
  1422. }
  1423. }.bind(this));
  1424. this.loaddingItems = false;
  1425. if( lastExcludeCount ){ //如果是因为上次load的时候被排除而加载的
  1426. if( count - lastExcludeCount - excludedCount < 0 ){ //如果本次load的数量还不够补足排除的数量,需要再次load
  1427. excludedCount = lastExcludeCount + excludedCount - count; //把不足的数量作为再次load的参数
  1428. this.loadItemsQueue++
  1429. }
  1430. }else if( excludedCount > 0 ){ //把排除的数量作为再次load的参数
  1431. this.loadItemsQueue++
  1432. }
  1433. if (json.data.length<count){
  1434. this.isItemLoaded = true;
  1435. }else{
  1436. if (this.loadItemsQueue>0){
  1437. this.loadItemsQueue--;
  1438. this.loadSelectItems( addToNext, excludedCount );
  1439. }
  1440. }
  1441. }else{
  1442. this.isItemLoaded = true;
  1443. this.loaddingItems = false;
  1444. }
  1445. if( this.afterLoadSelectItem )this.afterLoadSelectItem();
  1446. }.bind(this));
  1447. }else{
  1448. if (addToNext) this.loadItemsQueue++;
  1449. }
  1450. }
  1451. },
  1452. getLastLoadedItemId: function(){
  1453. if( this.tailExcludeItemId )return this.tailExcludeItemId;
  1454. return (this.items.length) ? this.items[this.items.length-1].data.distinguishedName : "(0)";
  1455. },
  1456. //loadSelectItemsByCondition: function(){
  1457. // this.options.groups.each(function(group){
  1458. //
  1459. // this.orgAction.listGroupByKey(function(json){
  1460. // if (json.data.length){
  1461. // var groupData = json.data[0];
  1462. // var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
  1463. // this._getChildrenItemIds(groupData).each(function(id){
  1464. // this._getItem(function(json){
  1465. // var item = this._newItem(json.data, this, category.children);
  1466. // this.items.push(item);
  1467. // }.bind(this), null, id);
  1468. // }.bind(this));
  1469. // }
  1470. // }.bind(this), null, group);
  1471. // }.bind(this));
  1472. //
  1473. // this.options.roles.each(function(role){
  1474. // this.orgAction.listRoleByKey(function(json){
  1475. // if (json.data.length){
  1476. // var roleData = json.data[0];
  1477. // var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
  1478. // this._getChildrenItemIds(roleData).each(function(id){
  1479. // this._getItem(function(json){
  1480. // var item = this._newItem(json.data, this, category.children);
  1481. // this.items.push(item);
  1482. // }.bind(this), null, id)
  1483. // }.bind(this));
  1484. // }
  1485. // }.bind(this), null, role);
  1486. // }.bind(this));
  1487. //},
  1488. loadSelectItemsByCondition: function(){
  1489. this.options.groups.each(function(group){
  1490. this.orgAction.listGroupByKey(function(json){
  1491. if (json.data.length){
  1492. var groupData = json.data[0];
  1493. var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
  1494. this.subCategorys.push(category);
  1495. this._getChildrenItemIds(groupData).each(function(id){
  1496. this._getItem(function(json){
  1497. if( !this.isExcluded( json.data ) ) {
  1498. var item = this._newItem(json.data, this, category.children);
  1499. this.items.push(item);
  1500. }
  1501. }.bind(this), null, id);
  1502. }.bind(this));
  1503. }
  1504. }.bind(this), null, group);
  1505. }.bind(this));
  1506. this.options.roles.each(function(role){
  1507. this.orgAction.listRoleByKey(function(json){
  1508. if (json.data.length){
  1509. var roleData = json.data[0];
  1510. var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
  1511. this.subCategorys.push(category);
  1512. this._getChildrenItemIds(roleData).each(function(id){
  1513. this._getItem(function(json){
  1514. if( !this.isExcluded( json.data ) ) {
  1515. var item = this._newItem(json.data, this, category.children);
  1516. this.items.push(item);
  1517. }
  1518. }.bind(this), null, id)
  1519. }.bind(this));
  1520. }
  1521. }.bind(this), null, role);
  1522. }.bind(this));
  1523. },
  1524. isInValues: function(d){
  1525. if( this.options.values.length === 0 )return false;
  1526. if( !this.valueFlagMap ){
  1527. this.valueFlagMap = {};
  1528. this.options.values.each( function( e ){
  1529. if( !e )return;
  1530. this.valueFlagMap[ typeOf( e ) === "string" ? e : ( e.distinguishedName || e.unique || e.employee || e.levelName || e.id) ] = true;
  1531. }.bind(this));
  1532. }
  1533. var map = this.valueFlagMap;
  1534. return ( d.distinguishedName && map[ d.distinguishedName ] ) ||
  1535. ( d.unique && map[ d.unique ] ) ||
  1536. ( d.employee && map[ d.employee ] ) ||
  1537. ( d.levelName && map[ d.levelName ] ) ||
  1538. ( d.id && map[ d.id ] );
  1539. },
  1540. isExcluded : function( d ){
  1541. if( this.options.exclude.length === 0 )return false;
  1542. if( !this.excludeFlagMap ){
  1543. this.excludeFlagMap = {};
  1544. this.options.exclude.each( function( e ){
  1545. if( !e )return;
  1546. this.excludeFlagMap[ typeOf( e ) === "string" ? e : ( e.distinguishedName || e.unique || e.employee || e.levelName || e.id ) ] = true;
  1547. }.bind(this));
  1548. }
  1549. var map = this.excludeFlagMap;
  1550. return ( d.distinguishedName && map[ d.distinguishedName ] ) ||
  1551. ( d.id && map[ d.id ] ) ||
  1552. ( d.unique && map[ d.unique ] ) ||
  1553. ( d.employee && map[ d.employee ] ) ||
  1554. ( d.levelName && map[ d.levelName ] );
  1555. },
  1556. _getChildrenItemIds: function(data){
  1557. return data.personList;
  1558. },
  1559. _newItemCategory: function(type, data, selector, item){
  1560. return new MWF.xApplication.Selector.Person[type](data, selector, item)
  1561. },
  1562. _listItemByKey: function(callback, failure, key){
  1563. this.orgAction.listPersonByKey(function(json){
  1564. if (callback) callback.apply(this, [json]);
  1565. }.bind(this), failure, key);
  1566. },
  1567. _getItem: function(callback, failure, id, async){
  1568. this.orgAction.getPerson(function(json){
  1569. if (callback) callback.apply(this, [json]);
  1570. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  1571. },
  1572. _newItemSelected: function(data, selector, item, selectedNode){
  1573. return new MWF.xApplication.Selector.Person.ItemSelected(data, selector, item, selectedNode)
  1574. },
  1575. _listItemByPinyin: function(callback, failure, key){
  1576. this.orgAction.listPersonByPinyin(function(json){
  1577. if (callback) callback.apply(this, [json]);
  1578. }.bind(this), failure, key);
  1579. },
  1580. _newItem: function(data, selector, container){
  1581. return new MWF.xApplication.Selector.Person.Item(data, selector, container);
  1582. },
  1583. _newItemSearch: function(data, selector, container){
  1584. return this._newItem(data, selector, container);
  1585. },
  1586. _listItemNext: function(last, count, callback){
  1587. this.orgAction.listPersonNext(last, count, function(json){
  1588. if (callback) callback.apply(this, [json]);
  1589. }.bind(this));
  1590. },
  1591. _scrollEvent: function(y){
  1592. if (!this.options.groups.length && !this.options.roles.length){
  1593. var scrollSize = this.itemAreaScrollNode.getScrollSize();
  1594. var clientSize = this.itemAreaScrollNode.getSize();
  1595. var scrollHeight = scrollSize.y-clientSize.y;
  1596. if (y+30>scrollHeight) {
  1597. if (!this.isItemLoaded) this.loadSelectItems();
  1598. }
  1599. }
  1600. },
  1601. afterLoadSelectItem : function(){
  1602. if( this.items.length === 0 && this.subItems.length === 0 && this.subCategorys.length === 0 ){
  1603. this.noSelectableItemTextDiv = new Element("div", {
  1604. text : MWF.SelectorLP.noSelectableItemText,
  1605. styles : this.css.noSelectableItemText
  1606. }).inject( this.itemAreaNode );
  1607. }
  1608. if( this.options.selectSingleItem ){
  1609. this.selectSingleItem()
  1610. }
  1611. this.fireEvent("afterLoadSelectItem", [this]);
  1612. },
  1613. selectSingleItem: function(){
  1614. if( !this.options.contentUrl && !layout.mobile){
  1615. if( this.options.hasShuttle && !this.shuttleNode ){
  1616. this.loadShuttleNode();
  1617. }
  1618. if( !this.selectedContainerNode ) {
  1619. this.loadSelectedNode(function () {
  1620. this._selectSingleItem();
  1621. }.bind(this));
  1622. }else{
  1623. this._selectSingleItem();
  1624. }
  1625. }else{
  1626. this._selectSingleItem();
  1627. }
  1628. },
  1629. _selectSingleItem : function(){
  1630. var _self = this;
  1631. var checkItem = function () {
  1632. if(this.items.length === 1 || this.subItems.length === 1 ){
  1633. if( this.items.length === 1 && this.subItems.length === 0 ){
  1634. if( !this.items[0].isSelected )this.items[0].clickItem();
  1635. this.fireEvent("afterSelectSingleItem",[this, this.items[0]]);
  1636. }else if( this.items.length === 0 && this.subItems.length === 1 ){
  1637. if( !this.items[0].isSelected )this.subItems[0].clickItem();
  1638. this.fireEvent("afterSelectSingleItem",[this, this.items[0]])
  1639. }else if( this.items.length === 1 && this.subItems.length === 1 ){
  1640. if( this.items[0] === this.subItems[0] ){
  1641. if( !this.items[0].isSelected )this.items[0].clickItem();
  1642. this.fireEvent("afterSelectSingleItem",[this, this.items[0]])
  1643. }else{
  1644. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1645. }
  1646. }else{
  1647. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1648. }
  1649. }else{
  1650. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1651. }
  1652. }.bind(this);
  1653. var checkCategoryItem = function (category) {
  1654. if( !category.subCategorys || category.subCategorys.length === 0 ){
  1655. if( category.subItems && category.subItems.length === 1 ){
  1656. isSingleItem = true;
  1657. if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
  1658. _self.fireEvent("afterSelectSingleItem",[_self, category.subItems[0]])
  1659. }else{
  1660. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1661. }
  1662. }else if(category.subCategorys.length === 1){
  1663. if( category.subItems && category.subItems.length > 0 ){
  1664. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1665. }else if( !category.subCategorys[0]._hasChild || !category.subCategorys[0]._hasChild() ){ //category.subCategorys[0].isItem &&
  1666. isSingleItem = true;
  1667. if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
  1668. _self.fireEvent("afterSelectSingleItem",[_self, category.subItems[0]])
  1669. }else{
  1670. checkCategory( category.subCategorys[0] )
  1671. }
  1672. }else{
  1673. var list = [];
  1674. for( var i=0; i<category.subCategorys.length; i++ ){
  1675. if( category.subCategorys[i]._hasChild && category.subCategorys[i]._hasChild() ){
  1676. list.push( category.subCategorys[i] );
  1677. }
  1678. }
  1679. if( list.length === 1 ){
  1680. if( !category.subItems || category.subItems.length === 0 ){
  1681. checkCategory( list[0] );
  1682. }
  1683. }
  1684. if( list.length === 0 ){
  1685. if( category.subItems && category.subItems.length === 1 ){
  1686. isSingleItem = true;
  1687. if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
  1688. _self.fireEvent("afterSelectSingleItem",[_self, category.subItems[0]])
  1689. }else{
  1690. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1691. }
  1692. }else{
  1693. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1694. }
  1695. }
  1696. };
  1697. var checkCategory = function ( category ) {
  1698. if( category.loaded ){
  1699. checkCategoryItem( category )
  1700. }else if( category.loading ){
  1701. window.setTimeout( function () {
  1702. checkCategory( category )
  1703. }, 100 )
  1704. }
  1705. };
  1706. if( this.subCategorys.length === 1 && this.subItems.length === 0) {
  1707. checkCategory( this.subCategorys[0] );
  1708. }else if( this.subCategorys.length === 0 ){
  1709. checkItem();
  1710. }else{
  1711. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1712. }
  1713. },
  1714. setSize : function(){
  1715. if( !this.options.width && !this.options.height )return;
  1716. var getOffsetX = function(node){
  1717. return (node.getStyle("margin-left").toInt() || 0 )+
  1718. (node.getStyle("margin-right").toInt() || 0 ) +
  1719. (node.getStyle("padding-left").toInt() || 0 ) +
  1720. (node.getStyle("padding-right").toInt() || 0 ) +
  1721. (node.getStyle("border-left-width").toInt() || 0 ) +
  1722. (node.getStyle("border-right-width").toInt() || 0 );
  1723. };
  1724. var getOffsetY = function(node){
  1725. return (node.getStyle("margin-top").toInt() || 0 ) +
  1726. (node.getStyle("margin-bottom").toInt() || 0 ) +
  1727. (node.getStyle("padding-top").toInt() || 0 ) +
  1728. (node.getStyle("padding-bottom").toInt() || 0 )+
  1729. (node.getStyle("border-top-width").toInt() || 0 ) +
  1730. (node.getStyle("border-bottom-width").toInt() || 0 );
  1731. };
  1732. if( this.options.width && this.options.width === "auto" ){
  1733. //if (this.options.count.toInt() !== 1){
  1734. if( this.node )this.node.setStyle("width", "auto");
  1735. this.selectNode.setStyles({
  1736. "width": "50%",
  1737. "float" : "left"
  1738. });
  1739. //this.searchInput.setStyle("width", "99%");
  1740. if(this.letterAreaNode ){
  1741. this.letterAreaNode.setStyle("width", "auto");
  1742. }
  1743. this.selectedContainerNode.setStyle("width", "auto");
  1744. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  1745. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") ){
  1746. this.selectedScrollNode.setStyle("width", "auto");
  1747. }else{
  1748. this.selectedScrollNode.setStyle("margin-right", "8px");
  1749. }
  1750. //}else{
  1751. // this.node.setStyle("width", "auto");
  1752. // this.selectNode.setStyle("width", "auto");
  1753. //}
  1754. }else if( this.options.width && typeOf( this.options.width.toInt() ) === "number" ){
  1755. var nodeWidth;
  1756. if( this.node ){
  1757. nodeWidth = this.options.width.toInt() - getOffsetX(this.node);
  1758. this.node.setStyle("width", nodeWidth);
  1759. }else{
  1760. nodeWidth = this.options.width.toInt();
  1761. }
  1762. nodeWidth = nodeWidth - getOffsetX( this.contentNode );
  1763. if( this.shuttleNode ){
  1764. nodeWidth = nodeWidth - getOffsetX(this.shuttleNode) - this.shuttleNode.getStyle("width").toInt();
  1765. }
  1766. //if (this.options.count.toInt() !== 1){
  1767. var width = nodeWidth - getOffsetX(this.selectNode) - getOffsetX(this.selectedContainerNode);
  1768. var halfWidth = this.options.noSelectedContainer ? width : ( Math.floor(width / 2) - 2);
  1769. this.selectNode.setStyle("width", halfWidth);
  1770. //this.searchInput.setStyle("width", halfWidth - 6);
  1771. if(this.letterAreaNode ){
  1772. this.letterAreaNode.setStyle("width", halfWidth - 19);
  1773. }
  1774. this.selectedContainerNode.setStyle("width", halfWidth);
  1775. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  1776. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") ){
  1777. this.selectedScrollNode.setStyle("width", halfWidth);
  1778. }else{
  1779. this.selectedScrollNode.setStyle("width", halfWidth - 8);
  1780. }
  1781. //}else{
  1782. // var width = nodeWidth - getOffsetX(this.selectNode);
  1783. // this.selectNode.setStyle("width", width);
  1784. //}
  1785. }
  1786. if( this.options.height && typeOf( this.options.height.toInt() ) === "number" ){
  1787. var nodeHeight;
  1788. if( this.node ){
  1789. nodeHeight = this.options.height.toInt() - getOffsetY(this.node);
  1790. this.node.setStyle("height", nodeHeight);
  1791. }else{
  1792. nodeHeight = this.options.height.toInt();
  1793. }
  1794. nodeHeight = nodeHeight - getOffsetY( this.contentNode ) - 1;
  1795. if( this.titleNode ){
  1796. nodeHeight = nodeHeight - getOffsetY( this.titleNode ) - this.titleNode.getStyle("height").toInt();
  1797. }
  1798. if( this.actionNode ){
  1799. nodeHeight = nodeHeight - getOffsetY( this.actionNode ) - this.actionNode.getStyle("height").toInt();
  1800. }
  1801. this.contentNode.setStyle("height", nodeHeight);
  1802. var selectNodeHeight = nodeHeight - getOffsetY(this.selectNode);
  1803. this.selectNode.setStyle("height", selectNodeHeight);
  1804. if( this.shuttleNode ){
  1805. this.shuttleNode.setStyle("height", selectNodeHeight);
  1806. var shuttleInnerHieght = getOffsetY( this.shuttleInnerNode ) + this.shuttleInnerNode.getStyle("height").toInt();
  1807. this.shuttleInnerNode.setStyle("margin-top", (selectNodeHeight-shuttleInnerHieght)/2 +"px" )
  1808. }
  1809. var itemAreaScrollNodeHeight = selectNodeHeight - getOffsetY( this.searchInputDiv ) - this.searchInputDiv.getStyle("height").toInt();
  1810. if( !this.options.searchbarInTopNode && this.selectTopNode ){
  1811. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.selectTopNode ) - this.selectTopNode.getStyle("height").toInt();
  1812. }
  1813. if(this.letterAreaNode && this.letterAreaNode.offsetParent){
  1814. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.letterAreaNode ) - this.letterAreaNode.getStyle("height").toInt();
  1815. }
  1816. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.itemAreaScrollNode );
  1817. this.itemAreaScrollNode.setStyle("height", itemAreaScrollNodeHeight);
  1818. if( this.itemSearchAreaScrollNode ){
  1819. this.itemSearchAreaScrollNode.setStyle("height", itemAreaScrollNodeHeight);
  1820. }
  1821. var selectedContainerNodeHeight = nodeHeight - getOffsetY(this.selectedContainerNode);
  1822. this.selectedContainerNode.setStyle("height", selectedContainerNodeHeight);
  1823. var selectedScrollNodeHeight = selectedContainerNodeHeight;
  1824. if( this.selectedTopNode ) {
  1825. selectedScrollNodeHeight = selectedScrollNodeHeight - getOffsetY(this.selectedTopNode) - this.selectedTopNode.getStyle("height").toInt();
  1826. }
  1827. if( !this.options.searchbarInTopNode && this.selectedSearchInputDiv ){
  1828. selectedScrollNodeHeight = selectedScrollNodeHeight - getOffsetY( this.selectedSearchInputDiv ) - this.selectedSearchInputDiv.getStyle("height").toInt();
  1829. }
  1830. this.selectedScrollNode.setStyle("height", selectedScrollNodeHeight);
  1831. }
  1832. this.fireEvent("setSize",[this])
  1833. },
  1834. addFlatCategoryItem : function( categoryItemNode, hasChildrenItem, itemNodeContainer, isCreateSubCategoryListNode ){
  1835. if(!this.flatSubCategoryNodeList)this.flatSubCategoryNodeList = [];
  1836. if( hasChildrenItem )this.flatSubCategoryNodeList.push( categoryItemNode );
  1837. if( !this.isFlatCategoryLoaded && this.flatSubCategoryNodeList.length > 1 ){
  1838. this.flatCategoryScrollNode.show();
  1839. this.flatCategoryScrollNode.setStyles( this.css.flatCategoryScrollNode );
  1840. var height = this.itemAreaScrollNode.getStyle("height").toInt();
  1841. this.flatCategoryScrollNode.setStyle("height", ""+height+"px");
  1842. this.flatCategoryNode.setStyles( this.css.flatCategoryNode );
  1843. this.isFlatCategoryLoaded = true;
  1844. this.itemAreaScrollNode.setStyles( this.css.itemAreaScrollNode_flatCategory );
  1845. //alert(this.flatSubCategoryNodeList[0].outerHTML)
  1846. }
  1847. if( hasChildrenItem )categoryItemNode.inject( itemNodeContainer || this.flatCategoryNode );
  1848. var subCategoryListNode;
  1849. if( isCreateSubCategoryListNode ){
  1850. subCategoryListNode = new Element("div.subCategoryListNode").inject( itemNodeContainer || this.flatCategoryNode );
  1851. }
  1852. //this.setFlatCategorySequence(categoryItemNode, itemNodeContainer, subCategoryListNode);
  1853. if( hasChildrenItem ){
  1854. //if( this.checkClickFlatCategoryItem(categoryItemNode, itemNodeContainer) ){
  1855. // categoryItemNode.click();
  1856. //}
  1857. if( !this.currentCategoryItemNode ){
  1858. categoryItemNode.click();
  1859. this.currentCategoryItemNode = categoryItemNode
  1860. }else{
  1861. //var date = new Date();
  1862. var first = this.flatCategoryNode.getElement(".flatCategoryItemNode");
  1863. //if(first)console.log(first.get("title"));
  1864. //console.log(new Date() - date );
  1865. //console.log(" " );
  1866. if( first ){
  1867. var dn1 = first.retrieve("dn");
  1868. var dn2 = this.currentCategoryItemNode.retrieve("dn");
  1869. if( dn1 && dn2 ){
  1870. if( dn1 != dn2 ){
  1871. categoryItemNode.click();
  1872. this.currentCategoryItemNode = categoryItemNode
  1873. }
  1874. }else{
  1875. var title1 = first.get("title");
  1876. var title2 = this.currentCategoryItemNode.get("title");
  1877. if( title1 && title1 ){
  1878. if( title1 != title2 ){
  1879. categoryItemNode.click();
  1880. this.currentCategoryItemNode = categoryItemNode
  1881. }
  1882. }else{
  1883. var text1 = first.get("text");
  1884. var text2 = this.currentCategoryItemNode.get("text");
  1885. if( text1 != text2 ){
  1886. categoryItemNode.click();
  1887. this.currentCategoryItemNode = categoryItemNode
  1888. }
  1889. }
  1890. }
  1891. }
  1892. }
  1893. }
  1894. return subCategoryListNode;
  1895. },
  1896. isCheckStatusOrCount: function(){
  1897. if( this.isCheckStatusFlag )return this.isCheckStatusFlag === "y";
  1898. if( this.availableStatusTypes.contains(this.selectType) &&
  1899. ( this.options.count.toInt() !== 1) && (this.options.resultType !== "person") &&
  1900. ( this.options.showSelectedCount || this.options.isCheckStatus ) ){
  1901. if( this.selectType === "unit" ){
  1902. if( this.options.expandSubEnable ){
  1903. this.isCheckStatusFlag = "y";
  1904. return true;
  1905. }else{
  1906. this.isCheckStatusFlag = "n";
  1907. return false;
  1908. }
  1909. }else{
  1910. this.isCheckStatusFlag = "y";
  1911. return true;
  1912. }
  1913. }else{
  1914. this.isCheckStatusFlag = "n";
  1915. return false;
  1916. }
  1917. },
  1918. checkCountAndStatus: function(){
  1919. if( this.subCategorys && this.subCategorys.length ){
  1920. this.subCategorys.each(function (category) {
  1921. if(category.checkCountAndStatus)category.checkCountAndStatus(true);
  1922. })
  1923. }
  1924. },
  1925. addSelectedCount: function( itemOrItemSelected, count ){
  1926. }
  1927. //checkClickFlatCategoryItem : function(categoryItemNode, itemNodeContainer){
  1928. // if( !this.flatCategorySeqObj_current ){
  1929. // this.flatCategorySeqObj_current = categoryItemNode.retrieve("seq");
  1930. // //console.log(this.flatCategorySeqObj_current)
  1931. // return true;
  1932. // }
  1933. // var seq_cur = this.flatCategorySeqObj_current;
  1934. // var seq = categoryItemNode ? categoryItemNode.retrieve("seq") : [];
  1935. // for( var i=0; i<seq.length; i++ ){
  1936. // if( seq_cur[i] && seq[i] < seq_cur[i] ){
  1937. // //console.log(seq)
  1938. // this.flatCategorySeqObj_current = seq;
  1939. // return true;
  1940. // }else if( !seq_cur[i] || seq[i] > seq_cur[i] ){
  1941. // return false;
  1942. // }
  1943. // }
  1944. // return false;
  1945. //},
  1946. //setFlatCategorySequence: function(categoryItemNode, itemNodeContainer, subCategoryListNode){
  1947. // if( !this.flatCategorySeqObj )this.flatCategorySeqObj = {};
  1948. // var parentSeq = itemNodeContainer ? itemNodeContainer.retrieve("seq") : [];
  1949. // var seq = Array.clone( parentSeq );
  1950. // if( this.flatCategorySeqObj[ parentSeq.length ] ){
  1951. // seq.push( this.flatCategorySeqObj[ parentSeq.length ] + 1 );
  1952. // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
  1953. //
  1954. // categoryItemNode.store( "seq", seq );
  1955. // categoryItemNode.set( "seq", seq );
  1956. //
  1957. // if(subCategoryListNode){
  1958. // seq = Array.clone( seq );
  1959. // seq[ seq.length - 1 ] = seq[ seq.length - 1 ]+1;
  1960. // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
  1961. // subCategoryListNode.store("seq", seq );
  1962. // subCategoryListNode.set( "seq", seq );
  1963. // }
  1964. // }else{
  1965. // seq.push( 1 );
  1966. // this.flatCategorySeqObj[ parentSeq.length ] = 1;
  1967. // categoryItemNode.store( "seq", seq );
  1968. // categoryItemNode.set( "seq", seq );
  1969. //
  1970. // if(subCategoryListNode) {
  1971. // seq = Array.clone(seq);
  1972. // seq[seq.length - 1] = seq[seq.length - 1]+1;
  1973. // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
  1974. // subCategoryListNode.store("seq", seq);
  1975. // subCategoryListNode.set("seq", seq);
  1976. // }
  1977. // }
  1978. //}
  1979. });
  1980. MWF.xApplication.Selector.Person.Item = new Class({
  1981. initialize: function(data, selector, container, level, category, delay){
  1982. this.clazz = "Item";
  1983. this.data = data;
  1984. this.selector = selector;
  1985. this.container = container;
  1986. this.isSelected = false;
  1987. this.level = (level) ? level.toInt() : 1;
  1988. this.category = category;
  1989. this.subItems = [];
  1990. this.subCategorys = [];
  1991. this.subCategoryMap = {};
  1992. this.subCategoryMapWithDuty = {};
  1993. // if(!delay)this.load();
  1994. if(delay){
  1995. this.placeholderNode = new Element("div").inject(this.container);
  1996. }else{
  1997. this.load();
  1998. }
  1999. },
  2000. _getShowName: function(){
  2001. return this.data.name + ( this.data.employee ? ("("+this.data.employee+")") : "" );
  2002. },
  2003. _getTtiteText: function(){
  2004. return this.data.name + ( this.data.employee ? ("("+this.data.employee+")") : "" );
  2005. },
  2006. _setIcon: function(){
  2007. var style = this.selector.options.style;
  2008. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/personicon.png)");
  2009. },
  2010. load: function(){
  2011. if( this.clazz === "Item" ){
  2012. this.selector.fireEvent("queryLoadItem",[this]);
  2013. }else if( this.clazz === "ItemSelected" ){
  2014. this.selector.fireEvent("queryLoadItemSelected",[this]);
  2015. }
  2016. if( !this.node ){
  2017. this.node = new Element("div", {
  2018. "styles": this.selector.css.selectorItem
  2019. });
  2020. if(this.placeholderNode){
  2021. this.node.inject( this.placeholderNode, "before");
  2022. this.placeholderNode.destroy();
  2023. this.placeholderNode = null;
  2024. }else{
  2025. this.node.inject(this.container);
  2026. }
  2027. }
  2028. this.levelNode = new Element("div", {
  2029. "styles": this.selector.css.selectorItemLevelNode
  2030. }).inject(this.node);
  2031. if( this.selector.selectType !== "identity" || this.selector.options.identityItemWidth === 0 ) {
  2032. var indent = this.selector.options.level1Indent + (this.level - 1) * this.selector.options.indent;
  2033. this.levelNode.setStyle("width", "" + indent + "px");
  2034. }
  2035. this.iconNode = new Element("div", {
  2036. "styles": this.selector.css.selectorItemIconNode
  2037. }).inject(this.node);
  2038. this._setIcon();
  2039. this.actionNode = new Element("div", {
  2040. "styles": this.selector.css.selectorItemActionNode
  2041. }).inject(this.node);
  2042. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  2043. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  2044. }
  2045. this.textNode = new Element("div", {
  2046. "styles": this.selector.css.selectorItemTextNode,
  2047. "text": this._getShowName(),
  2048. "title": this._getTtiteText()
  2049. }).inject(this.node);
  2050. this.textNode.store("indent", indent);
  2051. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  2052. this.textNode.setStyle("margin-left", ""+m+"px");
  2053. if( this.selector.options.identityItemWidth && this.selector.selectType === "identity"){
  2054. this.node.setStyles({
  2055. "float" : "left",
  2056. "min-width" : this.selector.options.identityItemWidth + "px"
  2057. })
  2058. }
  2059. if(this.postLoad)this.postLoad();
  2060. this.loadSubItem();
  2061. this.setEvent();
  2062. this.check();
  2063. if( this.clazz === "Item" ) {
  2064. this.selector.fireEvent("postLoadItem", [this]);
  2065. }else if( this.clazz === "ItemSelected" ){
  2066. this.selector.fireEvent("postLoadItemSelected",[this]);
  2067. }
  2068. },
  2069. loadSubItem: function(){},
  2070. disable : function(){
  2071. this.node.hide();
  2072. this.disabled = true;
  2073. },
  2074. enable : function(){
  2075. this.node.show();
  2076. this.disabled = false;
  2077. },
  2078. check: function(){
  2079. //if (this.selector.options.count.toInt()===1){
  2080. // this.checkSelectedSingle();
  2081. //}else{
  2082. this.checkSelected();
  2083. //}
  2084. },
  2085. checkSelectedSingle: function(){
  2086. var selectedItem = this.selector.options.values.filter(function(item, index){
  2087. if (typeOf(item)==="object") return this.data.distinguishedName === item.distinguishedName;
  2088. if (typeOf(item)==="string") return this.data.distinguishedName === item;
  2089. return false;
  2090. }.bind(this));
  2091. if (selectedItem.length){
  2092. this.selectedSingle();
  2093. }
  2094. },
  2095. checkSelected: function(){
  2096. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  2097. return item.data.distinguishedName === this.data.distinguishedName;
  2098. }.bind(this));
  2099. if (selectedItem.length){
  2100. selectedItem[0].addItem(this);
  2101. this.selectedItem = selectedItem[0];
  2102. this.setSelected();
  2103. }
  2104. },
  2105. checkTextNodeIndent : function( textNode, styles ){
  2106. var indent = textNode.retrieve("indent");
  2107. if( indent && styles && styles["margin-left"] ){
  2108. var m = styles["margin-left"].toFloat()+indent;
  2109. textNode.setStyle("margin-left", ""+m+"px");
  2110. }
  2111. },
  2112. setSelected: function(){
  2113. this.isSelected = true;
  2114. if(this.node) {
  2115. this.node.setStyles(this.selector.css.selectorItem_selected);
  2116. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  2117. this.checkTextNodeIndent(this.textNode, this.selector.css.selectorItemTextNode_selected);
  2118. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  2119. if( this.selector.options.style === "flow" ){
  2120. this.actionNode.addClass("o2icon-checkbox");
  2121. if( this.selector.options.mainColorEnable )this.actionNode.addClass("mainColor_color");
  2122. }
  2123. if ((this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer) && this.selector.css.selectorItemActionNode_single_selected) {
  2124. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_single_selected);
  2125. }
  2126. }
  2127. // if( this.category ){
  2128. // this.category.checkSelectAll();
  2129. // }
  2130. },
  2131. setEvent: function(){
  2132. this.node.addEvents({
  2133. "mouseover": function(){
  2134. this.overItem();
  2135. }.bind(this),
  2136. "mouseout": function(){
  2137. this.outItem();
  2138. }.bind(this),
  2139. "click": function(){
  2140. this.clickItem( null, true );
  2141. }.bind(this)
  2142. });
  2143. },
  2144. clickItem: function( callback, checkValid ){
  2145. // if ( layout.mobile && this.selector.options.count.toInt()===1){
  2146. // this.selectedSingle( checkValid );
  2147. // }else{
  2148. if (this.isSelected){
  2149. this.unSelected( checkValid);
  2150. }else{
  2151. this.selected( checkValid );
  2152. }
  2153. // }
  2154. },
  2155. overItem: function(){
  2156. if (!this.isSelected ){
  2157. this.node.setStyles(this.selector.css.selectorItem_over);
  2158. }else if( this.selector.css.selectorItem_over_force ){
  2159. this.node.setStyles(this.selector.css.selectorItem_over_force);
  2160. }
  2161. if (!this.isSelected){
  2162. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  2163. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_over ){
  2164. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_over );
  2165. }
  2166. }else if( this.selector.css.selectorItemActionNode_over_force ){
  2167. this.node.setStyles(this.selector.css.selectorItemActionNode_over_force);
  2168. }
  2169. },
  2170. outItem: function(){
  2171. if (!this.isSelected){
  2172. this.node.setStyles(this.selector.css.selectorItem);
  2173. }else if( this.selector.css.selectorItem_over_force ){
  2174. this.node.setStyles(this.selector.css.selectorItem_selected);
  2175. }
  2176. if (!this.isSelected){
  2177. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  2178. if( this.selector.options.style === "flow" ){
  2179. this.actionNode.removeClass("o2icon-checkbox");
  2180. if( this.selector.options.mainColorEnable )this.actionNode.removeClass("mainColor_color");
  2181. }
  2182. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  2183. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  2184. }
  2185. }else if( this.selector.css.selectorItemActionNode_over_force ){
  2186. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  2187. if( this.selector.options.style === "flow" ){
  2188. this.actionNode.addClass("o2icon-checkbox");
  2189. if( this.selector.options.mainColorEnable )this.actionNode.addClass("mainColor_color");
  2190. }
  2191. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  2192. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  2193. }
  2194. }
  2195. },
  2196. selectedSingle: function( checkValid ){
  2197. if (!this.isSelected){
  2198. if (this.selector.currentItem) this.selector.currentItem.unSelectedSingle();
  2199. this.selector.emptySelectedItems();
  2200. this.getData(function(){
  2201. this.selector.currentItem = this;
  2202. this.isSelected = true;
  2203. this.selector.selectedItems.push(this);
  2204. if(this.selector.addToSelectedItemsMap)this.selector.addToSelectedItemsMap(this.data, this);
  2205. this.node.setStyles(this.selector.css.selectorItem_selected);
  2206. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  2207. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
  2208. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  2209. if( this.selector.options.style === "flow" ){
  2210. this.actionNode.addClass("o2icon-checkbox");
  2211. if( this.selector.options.mainColorEnable )this.actionNode.addClass("mainColor_color");
  2212. }
  2213. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  2214. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  2215. }
  2216. this.selector.fireEvent("selectItem",[this]);
  2217. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  2218. }.bind(this));
  2219. }else {
  2220. this.selector.emptySelectedItems();
  2221. this.unSelectedSingle( checkValid );
  2222. }
  2223. },
  2224. getData: function(callback){
  2225. if (callback) callback();
  2226. },
  2227. unSelectedSingle: function(checkValid){
  2228. this.selector.currentItem = null;
  2229. this.isSelected = false;
  2230. this.selector.selectedItems.erase(this);
  2231. if(this.selector.deleteFromSelectedItemsMap)this.selector.deleteFromSelectedItemsMap(this.data);
  2232. this.node.setStyles(this.selector.css.selectorItem);
  2233. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  2234. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode );
  2235. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  2236. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  2237. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  2238. }
  2239. this.selector.fireEvent("unselectItem",[this]);
  2240. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  2241. },
  2242. selected: function( checkValid, callback, selectedNode, bySelectAll ){
  2243. var count = this.selector.options.maxCount || this.selector.options.count;
  2244. count = count.toInt();
  2245. if (!count) count = 0;
  2246. if( count == 1 && this.selector.emptySelectedItems){
  2247. this.selector.emptySelectedItems();
  2248. }
  2249. if ((count===0) || (this.selector.selectedItems.length+1)<=count) {
  2250. this.isSelected = true;
  2251. if( this.node ){
  2252. this.node.setStyles(this.selector.css.selectorItem_selected);
  2253. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  2254. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
  2255. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  2256. if( this.selector.options.style === "flow" ){
  2257. this.actionNode.addClass("o2icon-checkbox");
  2258. if( this.selector.options.mainColorEnable )this.actionNode.addClass("mainColor_color");
  2259. }
  2260. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  2261. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  2262. }
  2263. }
  2264. this.selectedItem = this.selector._newItemSelected(this.data, this.selector, this, selectedNode);
  2265. // this.selectedItem.check();
  2266. this.selector.selectedItems.push(this.selectedItem);
  2267. if(this.selector.addToSelectedItemsMap)this.selector.addToSelectedItemsMap(this.data, this.selectedItem);
  2268. // if( this.category ){
  2269. // this.category.checkSelectAll();
  2270. // }
  2271. this.selector.fireEvent("selectItem",[this]);
  2272. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  2273. if(callback)callback();
  2274. }else{
  2275. MWF.xDesktop.notice("error", {x: "right", y:"top"}, MWF.SelectorLP.selectItemMaxText.replace("{count}", count) , this.node);
  2276. }
  2277. },
  2278. unSelected: function( checkValid, callback ){
  2279. var isSelected = this.isSelected;
  2280. this.isSelected = false;
  2281. if( this.node ){
  2282. this.node.setStyles(this.selector.css.selectorItem);
  2283. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  2284. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode );
  2285. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  2286. if( this.selector.options.style === "flow" ){
  2287. this.actionNode.removeClass("o2icon-checkbox");
  2288. if( this.selector.options.mainColorEnable )this.actionNode.removeClass("mainColor_color");
  2289. }
  2290. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  2291. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  2292. }
  2293. }
  2294. if( this.category && this.selector.options.selectAllRange !== "all" ){
  2295. this.category.checkUnselectAll();
  2296. }
  2297. if( this.selector.searchItems && this.selector.searchItems.length ){
  2298. this.selector.searchItems.each( function(itemSearch){
  2299. var sd = itemSearch.data;
  2300. var d = this.data;
  2301. if(
  2302. ( sd.distinguishedName && (sd.distinguishedName === d.distinguishedName) ) ||
  2303. ( sd.id && (sd.id === d.id) ) ||
  2304. ( sd.unique && (sd.unique === d.unique) ) ||
  2305. ( sd.employee && (sd.employee === d.employee) ) ||
  2306. ( sd.levelName && (sd.levelName === d.levelName) )
  2307. ){
  2308. itemSearch.isSelected = false;
  2309. itemSearch.node.setStyles(this.selector.css.selectorItem);
  2310. itemSearch.textNode.setStyles(this.selector.css.selectorItemTextNode);
  2311. this.checkTextNodeIndent( itemSearch.textNode, this.selector.css.selectorItemTextNode );
  2312. itemSearch.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  2313. if( this.selector.options.style === "flow" ){
  2314. this.actionNode.removeClass("o2icon-checkbox");
  2315. if( this.selector.options.mainColorEnable )this.actionNode.removeClass("mainColor_color");
  2316. }
  2317. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  2318. itemSearch.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  2319. }
  2320. }
  2321. }.bind(this))
  2322. }
  2323. var countItems = [];
  2324. if (this.selectedItem){
  2325. this.selector.selectedItems.erase(this.selectedItem);
  2326. if(this.selector.deleteFromSelectedItemsMap)this.selector.deleteFromSelectedItemsMap(this.selectedItem.data);
  2327. if( this.selector.isCheckStatusOrCount()){
  2328. this.selectedItem.items.each(function(item){
  2329. if( item.isSelected || ( item === this && isSelected ) ){
  2330. countItems.push(item);
  2331. }
  2332. }.bind(this));
  2333. }else if( this.selector.options.selectAllRange === "all" ){
  2334. this.selectedItem.items.each(function(item) {
  2335. if (item.isSelected || (item === this && isSelected)) {
  2336. if (item.category && item.category._addSelectAllSelectedCount) item.category._addSelectAllSelectedCount(-1, true);
  2337. }
  2338. }.bind(this))
  2339. }
  2340. this.selectedItem.items.each(function(item){
  2341. if (item != this){
  2342. item.isSelected = false;
  2343. item.node.setStyles(this.selector.css.selectorItem);
  2344. item.textNode.setStyles(this.selector.css.selectorItemTextNode);
  2345. this.checkTextNodeIndent( item.textNode, this.selector.css.selectorItemTextNode );
  2346. item.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  2347. if( this.selector.options.style === "flow" ){
  2348. this.actionNode.removeClass("o2icon-checkbox");
  2349. if( this.selector.options.mainColorEnable )this.actionNode.removeClass("mainColor_color");
  2350. }
  2351. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  2352. item.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  2353. }
  2354. }
  2355. }.bind(this));
  2356. this.selectedItem.destroy();
  2357. this.selectedItem = null;
  2358. }
  2359. if( this.selector.isCheckStatusOrCount()){
  2360. this.selector.addSelectedCount( this, -1, countItems );
  2361. }
  2362. this.selector.fireEvent("unselectItem",[this]);
  2363. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  2364. if(callback)callback();
  2365. },
  2366. postLoad : function(){},
  2367. getParentCategoryByLevel : function( level ){
  2368. var category = this.category;
  2369. do{
  2370. if( category.level === level ){
  2371. return category;
  2372. }else{
  2373. category = category.category;
  2374. }
  2375. }while( category )
  2376. }
  2377. });
  2378. MWF.xApplication.Selector.Person.ItemSelected = new Class({
  2379. Extends: MWF.xApplication.Selector.Person.Item,
  2380. initialize: function(data, selector, item, selectedNode, delay){
  2381. this.data = data;
  2382. this.selector = selector;
  2383. this.container = selectedNode || this.selector.selectedNode;
  2384. this.isSelected = false;
  2385. this.clazz = "ItemSelected";
  2386. this.items = [];
  2387. if (item) this.items.push(item);
  2388. this.level = this.selector.options.style === "flow" ? 1 : 0;
  2389. this.node = new Element("div", {
  2390. "styles": this.selector.css.selectorItem
  2391. }).inject(this.container);
  2392. this.node.setStyle("display","none");
  2393. if(this.data.isFromValues){
  2394. this.isFromValues = true;
  2395. this.data.isFromValues = false;
  2396. }
  2397. if(!this.selectedIndex && MWF.O2Selector.selectedIndex)this.selectedIndex = MWF.O2Selector.selectedIndex++;
  2398. this.getData(function(){
  2399. this.node.setStyle("display","");
  2400. if(!delay){
  2401. this.load();
  2402. }else{
  2403. this.check();
  2404. }
  2405. }.bind(this));
  2406. },
  2407. postLoad : function(){
  2408. if( this.selector.css.selectorSelectedItemTextNode ){
  2409. this.textNode.setStyles(this.selector.css.selectorSelectedItemTextNode);
  2410. }
  2411. if( layout.mobile && !this.selector.contentUrl ){
  2412. this.actionNode.set("text", MWF.SelectorLP.remove );
  2413. if( this.selector.css.selectedItemActionNodeMobile ){
  2414. this.actionNode.setStyles( this.selector.css.selectedItemActionNodeMobile );
  2415. }
  2416. if( this.selector.css.selectorItemMobile ){
  2417. this.node.setStyles( this.selector.css.selectorItemMobile );
  2418. }
  2419. }else if( this.selector.css.selectorSelectedItemActionNode ){
  2420. this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode );
  2421. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorSelectedItemActionNode_single ){
  2422. this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode_single );
  2423. }
  2424. }
  2425. },
  2426. getData: function(callback){
  2427. if (callback) callback();
  2428. },
  2429. clickItem: function( callback, checkValid ){
  2430. if( this.tooltip ){
  2431. if( this.selector.tooltips )this.selector.tooltips.erase(this.tooltip);
  2432. this.tooltip.destroy();
  2433. this.tooltip = null;
  2434. }
  2435. if (this.items.length){
  2436. var items = [], map = {};
  2437. this.items.each(function(item){
  2438. if( item.data.distinguishedName || item.data.unique ){
  2439. if( (!item.data.distinguishedName || !map[item.data.distinguishedName]) && ( !item.data.unique || !map[item.data.unique])){
  2440. items.push(item);
  2441. map[item.data.distinguishedName] = true;
  2442. map[item.data.unique] = true;
  2443. }
  2444. }else{
  2445. items.push(item);
  2446. }
  2447. });
  2448. items.each(function(item){
  2449. item.unSelected( checkValid );
  2450. });
  2451. if( checkValid )this.selector.fireEvent("valid", [this.selector, this])
  2452. }else{
  2453. //this.item.selectedItem = null;
  2454. //this.item.isSelected = false;
  2455. if( this.selector.isCheckStatusOrCount()){
  2456. this.selector.addSelectedCount( this, -1, [] );
  2457. }
  2458. this.destroy();
  2459. this.selector.selectedItems.erase(this);
  2460. if(this.selector.deleteFromSelectedItemsMap)this.selector.deleteFromSelectedItemsMap(this.data);
  2461. if( checkValid )this.selector.fireEvent("valid", [this.selector, this])
  2462. }
  2463. },
  2464. //overItem: function(){
  2465. // if (!this.isSelected){
  2466. // this.node.setStyles(this.selector.css.selectorItem_over);
  2467. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
  2468. // }
  2469. //},
  2470. overItem: function(){
  2471. if( layout.mobile )return;
  2472. if (!this.isSelected ){
  2473. if( this.selector.css.selectorItem_selected_over ){
  2474. this.node.setStyles(this.selector.css.selectorItem_selected_over);
  2475. }else{
  2476. this.node.setStyles(this.selector.css.selectorItem_over);
  2477. }
  2478. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
  2479. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected_over ){
  2480. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected_over );
  2481. }
  2482. }
  2483. },
  2484. outItem: function(){
  2485. if( layout.mobile )return;
  2486. if (!this.isSelected){
  2487. var styles = this.selector.css.selectorSelectedItem || this.selector.css.selectorItem;
  2488. this.node.setStyles(styles);
  2489. }else if( this.selector.css.selectorItem_over_force ){
  2490. this.node.setStyles(this.selector.css.selectorItem_selected);
  2491. }
  2492. if (!this.isSelected){
  2493. var styles = this.selector.css.selectorSelectedItemActionNode || this.selector.css.selectorItemActionNode;
  2494. this.actionNode.setStyles(styles);
  2495. if( this.selector.options.style === "flow" ){
  2496. this.actionNode.removeClass("o2icon-checkbox");
  2497. if( this.selector.options.mainColorEnable )this.actionNode.removeClass("mainColor_color");
  2498. }
  2499. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) &&
  2500. ( this.selector.css.selectorSelectedItemActionNode_single || this.selector.css.selectorItemActionNode_single ) ){
  2501. this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode_single || this.selector.css.selectorItemActionNode_single );
  2502. }
  2503. }else if( this.selector.css.selectorItemActionNode_over_force ){
  2504. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  2505. if( this.selector.options.style === "flow" ){
  2506. this.actionNode.addClass("o2icon-checkbox");
  2507. if( this.selector.options.mainColorEnable )this.actionNode.addClass("mainColor_color");
  2508. }
  2509. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  2510. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  2511. }
  2512. }
  2513. },
  2514. addItem: function(item){
  2515. if (this.items.indexOf(item)===-1) this.items.push(item);
  2516. },
  2517. check: function(){
  2518. if (this.selector.items.length){
  2519. var items = this.selector.items.filter(function(item, index){
  2520. return item.data.distinguishedName === this.data.distinguishedName;
  2521. }.bind(this));
  2522. this.items = items;
  2523. if (items.length){
  2524. items.each(function(item){
  2525. item.selectedItem = this;
  2526. item.setSelected();
  2527. // if( this.selector.options.showSelectedCount ){
  2528. // if(item.category)item.category._addSelectedCount( 1, true );
  2529. // }
  2530. }.bind(this));
  2531. }
  2532. }
  2533. if( this.afterCheck )this.afterCheck();
  2534. },
  2535. destroy: function(){
  2536. if(this.node){
  2537. // var parent = this.node.getParent(".categorySelectedNode");
  2538. // if( parent && !this.node.getPrevious() && !this.node.getNext() ){ //parent.getChildren().length <= 1
  2539. // parent.destroy();
  2540. // }else{
  2541. this.node.destroy();
  2542. // }
  2543. }
  2544. delete this;
  2545. }
  2546. });
  2547. MWF.xApplication.Selector.Person.ItemCategory = new Class({
  2548. Extends: MWF.xApplication.Selector.Person.Item,
  2549. initialize: function(data, selector, container, level, parentCategory, delay, notActive){
  2550. this.data = data;
  2551. this.selector = selector;
  2552. this.container = container;
  2553. this.isSelected = false;
  2554. this.level = (level) ? level.toInt() : 1;
  2555. this.category = parentCategory;
  2556. this.subItems = [];
  2557. this.subCategorys = [];
  2558. this.subCategoryMap = {};
  2559. this.subCategoryMapWithDuty = {};
  2560. this.notActive = notActive;
  2561. if(!delay)this.load();
  2562. },
  2563. load : function(){
  2564. if( this.selector.isFlatCategory ){
  2565. this.loadForFlat();
  2566. }else if( !this.notActive ){
  2567. this.loadForNormal();
  2568. }else{
  2569. this.createNode();
  2570. // this.node.hide();
  2571. this.children = new Element("div.children", {
  2572. "styles": this.selector.css.selectorItemCategoryChildrenNode
  2573. }).inject(this.node, "after");
  2574. // this.children.hide();
  2575. }
  2576. },
  2577. active: function(){
  2578. this.notActive = false;
  2579. this.node.show();
  2580. this.children.show();
  2581. this.loadForNormal();
  2582. },
  2583. loadForFlat : function(){
  2584. this.selector.fireEvent("queryLoadCategory",[this]);
  2585. //this.createNode();
  2586. this.node = new Element("div.flatCategoryItemNode", {
  2587. "styles": this.selector.css.flatCategoryItemNode,
  2588. "title" : this._getTtiteText()
  2589. });
  2590. this.node.store( "category", this );
  2591. this.node.store( "dn", this.data.distinguishedName );
  2592. this.textNode = new Element("div", {
  2593. "styles": this.selector.css.flatCategoryItemTextNode,
  2594. "text": this._getShowName()
  2595. }).inject(this.node);
  2596. //var level = this.level;
  2597. //var category = this;
  2598. //while( category.category ){
  2599. // level = category.category + "_" + level;
  2600. // category = category.category;
  2601. //}
  2602. this.children = new Element("div", {
  2603. "styles": this.selector.css.selectorItemCategoryChildrenNode
  2604. }).inject(this.selector.itemAreaNode); //this.container
  2605. //if (!this.selector.options.expand)
  2606. this.children.setStyle("display", "none");
  2607. if( this.selector.options.selectAllEnable && this.selector.options.count.toInt()!==1 ){
  2608. var selectAllWrap = new Element("div",{
  2609. styles : this.selector.css.flatCategory_selectAllWrap
  2610. }).inject(this.children);
  2611. this.selectAllNode = new Element("div", {
  2612. "styles": this.selector.css.flatCategory_selectAll,
  2613. "text" : MWF.SelectorLP.selectAll
  2614. }).inject(selectAllWrap);
  2615. this.selectAllNode.addEvent( "click", function(ev){
  2616. if( this.isSelectedAll ){
  2617. this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true ) : this.unselectAll(ev, null, true);
  2618. this.selector.fireEvent("unselectCatgory",[this]);
  2619. this.selector.fireEvent("unselectCatgeory",[this]);
  2620. }else{
  2621. this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev, true) : this.selectAll(ev, true);
  2622. this.selector.fireEvent("selectCatgory",[this]);
  2623. this.selector.fireEvent("selectCatgeory",[this]);
  2624. }
  2625. ev.stopPropagation();
  2626. }.bind(this));
  2627. }
  2628. // var subIdList = this.selector._getChildrenItemIds(this.data);
  2629. // if (subIdList){
  2630. // var count = subIdList.length;
  2631. // this.childrenHeight = count*this.selector.options.itemHeight;
  2632. // this.children.setStyle("height", ""+this.childrenHeight+"px");
  2633. // }
  2634. //if (!this._hasChild()){
  2635. // this.textNode.setStyle("color", "#333");
  2636. //}
  2637. if( this.selectAllNode ){
  2638. if( this.selector.options.selectAllRange === "direct" && !this._hasChildItem() ){
  2639. this.selectAllNode.setStyle("display", "none");
  2640. }
  2641. }
  2642. this.node.addEvents({
  2643. //"mouseover": function(){
  2644. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode_over );
  2645. //}.bind(this),
  2646. //"mouseout": function(){
  2647. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode );
  2648. //}.bind(this),
  2649. "click": function(){
  2650. if( this.selector.currentFlatCategory === this )return;
  2651. if( this.selector.currentFlatCategory ){
  2652. this.selector.currentFlatCategory.clickFlatCategoryItem(null, true); //取消原来选择的
  2653. }
  2654. this.selector.currentFlatCategory = this;
  2655. this.clickFlatCategoryItem();
  2656. }.bind(this)
  2657. });
  2658. //this.setEvent();
  2659. var isCreateSubCategoryListNode = this._hasChildCategory ? this._hasChildCategory() : true;
  2660. var nodeContainer;
  2661. if( this.nodeContainer ){
  2662. nodeContainer = this.nodeContainer;
  2663. }else{
  2664. nodeContainer = (this.category && this.category.subCategoryListNode) ? this.category.subCategoryListNode : null;
  2665. }
  2666. this.subCategoryListNode = this.selector.addFlatCategoryItem( this.node, this._hasChildItem(), nodeContainer, isCreateSubCategoryListNode );
  2667. this.check();
  2668. if( this.loadCategoryChildren )this.loadCategoryChildren();
  2669. //this.afterLoad();
  2670. this.selector.fireEvent("postLoadCategory",[this]);
  2671. },
  2672. loadForNormal : function(){
  2673. this.selector.fireEvent("queryLoadCategory",[this]);
  2674. if(!this.node)this.createNode();
  2675. this.levelNode = new Element("div", {
  2676. "styles": this.selector.css.selectorItemLevelNode
  2677. }).inject(this.node);
  2678. if(this.selector.selectType !== "identity" || this.selector.options.identityItemWidth === 0 ){
  2679. var indent = this.selector.options.level1Indent + (this.level - 1) * this.selector.options.indent;
  2680. this.levelNode.setStyle("width", "" + indent + "px");
  2681. }else{
  2682. this.node.setStyle("clear","both");
  2683. }
  2684. this.iconNode = new Element("div", {
  2685. "styles": this.selector.css.selectorItemCategoryIconNode || this.selector.css.selectorItemIconNode
  2686. }).inject(this.node);
  2687. this._setIcon();
  2688. this.actionNode = new Element("div", {
  2689. "styles": (this.selector.options.expand) ? this.selector.css.selectorItemCategoryActionNode_expand : this.selector.css.selectorItemCategoryActionNode_collapse
  2690. }).inject(this.node);
  2691. if( this.selector.options.style === "flow" )this.actionNode.inject( this.iconNode, "before" );
  2692. if( this.selector.options.selectAllEnable && this.selector.options.count.toInt()!==1 ){
  2693. var selectAllNodeStyles = this.selector.css.selectorItemCategoryActionNode_selectAll;
  2694. if( this.isSelectedAll ){
  2695. if( this.selector.isFlatCategory ){
  2696. selectAllNodeStyles = this.selector.css.flatCategory_selectAll_selected;
  2697. }else if( this.selector.css.selectorItemCategoryActionNode_selectAll_selected ){
  2698. selectAllNodeStyles = this.selector.css.selectorItemCategoryActionNode_selectAll_selected;
  2699. }
  2700. }
  2701. this.selectAllNode = new Element("div", {
  2702. "styles": selectAllNodeStyles,
  2703. "title" : MWF.SelectorLP.selectChildren
  2704. }).inject(this.node);
  2705. this.selectAllNode.addEvent( "click", function(ev){
  2706. if( this.isSelectedAll ){
  2707. // this.unselectAll(ev);
  2708. this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true ) : this.unselectAll(ev, null, true);
  2709. this.selector.fireEvent("unselectCatgory",[this]);
  2710. this.selector.fireEvent("unselectCategory",[this]);
  2711. }else{
  2712. // this.selectAll(ev);
  2713. if( this.selector.options.selectAllRange === "all" ){
  2714. var node = new Element("div.categorySelectedNode").inject( this.selector.selectedNode );
  2715. this.selectAllNested(ev, true, node );
  2716. }else{
  2717. this.selectAll(ev, true)
  2718. }
  2719. this.selector.fireEvent("selectCatgory",[this]);
  2720. this.selector.fireEvent("selectCategory",[this]);
  2721. }
  2722. ev.stopPropagation();
  2723. }.bind(this));
  2724. if( this.selector.css.selectorItemCategoryActionNode_selectAll_over ){
  2725. this.selectAllNode.addEvents( {
  2726. "mouseover" : function(ev){
  2727. if( !this.isSelectedAll && !this.isSelectedSome )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_over );
  2728. //ev.stopPropagation();
  2729. }.bind(this),
  2730. "mouseout" : function(ev){
  2731. if( !this.isSelectedAll && !this.isSelectedSome )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  2732. //ev.stopPropagation();
  2733. }.bind(this)
  2734. })
  2735. }
  2736. }
  2737. this.textNode = new Element("div", {
  2738. "styles": this.selector.css.selectorItemCategoryTextNode,
  2739. "text": this._getShowName()
  2740. }).inject(this.node);
  2741. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  2742. this.textNode.setStyle("margin-left", ""+m+"px");
  2743. if( this.selector.options.showSelectedCount && this.selector.availableStatusTypes.contains(this.selector.selectType) ){
  2744. this.selectedCountNode = new Element("span").inject(this.textNode);
  2745. }
  2746. if(!this.children)this.children = new Element("div.children", {
  2747. "styles": this.selector.css.selectorItemCategoryChildrenNode
  2748. }).inject(this.node, "after");
  2749. if (!this.selector.options.expand) this.children.setStyle("display", "none");
  2750. if( this.selector.options.expandEmptyCategory && !this._hasChildItem() ){ //点击允许展开空分类
  2751. this.children.hide();
  2752. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  2753. this.isExpand = false;
  2754. }else{
  2755. var subIdList = this.selector._getChildrenItemIds(this.data);
  2756. if (subIdList){
  2757. var count = subIdList.length;
  2758. this.childrenHeight = count*this.selector.options.itemHeight;
  2759. this.children.setStyle("height", ""+this.childrenHeight+"px");
  2760. }
  2761. if(this.selector.options.identityItemWidth && this.selector.selectType === "identity"){
  2762. var indent = this.level === 0 ? this.selector.options.level1Indent : this.selector.options.indent;
  2763. this.children.setStyles({
  2764. "padding-left": "" + indent + "px",
  2765. "overflow" : "hidden"
  2766. });
  2767. }
  2768. if ( !this._hasChild()){
  2769. if( this.selector.options.hiddenEmptyCategory ){
  2770. this.node.hide()
  2771. }else{
  2772. if( this.selector.options.style === "flow" ){
  2773. this.node.setStyles({
  2774. "opacity": "0.5",
  2775. "cursor": "default"
  2776. });
  2777. }else{
  2778. this.actionNode.setStyle("background", "transparent");
  2779. this.textNode.setStyle("color", "#777");
  2780. }
  2781. }
  2782. }
  2783. if( this.selectAllNode ){
  2784. if( this.selector.options.selectAllRange === "direct" && !this._hasChildItem() ){
  2785. this.selectAllNode.setStyle("display", "none");
  2786. }
  2787. }
  2788. }
  2789. this.setEvent();
  2790. this.check();
  2791. this.afterLoad();
  2792. this.selector.fireEvent("postLoadCategory",[this]);
  2793. },
  2794. createNode: function(){
  2795. this.node = new Element("div", {
  2796. "styles": this.selector.css.selectorItemCategory,
  2797. "title" : this._getTtiteText()
  2798. }).inject(this.container);
  2799. },
  2800. setEvent: function(){
  2801. this.node.addEvents({
  2802. "mouseover": function(){
  2803. this.overItem();
  2804. }.bind(this),
  2805. "mouseout": function(){
  2806. this.outItem();
  2807. }.bind(this),
  2808. "click": function(){
  2809. this.clickItem();
  2810. }.bind(this)
  2811. });
  2812. },
  2813. unselectAll : function(ev, exclude, checkValid ){
  2814. var fun = function(){
  2815. var excludeList = exclude || [];
  2816. if( exclude && typeOf(exclude) !== "array" )excludeList = [exclude];
  2817. ( this.subItems || [] ).each( function(item){
  2818. if(item.isSelected && !excludeList.contains(item) ){
  2819. item.unSelected( checkValid );
  2820. }
  2821. }.bind(this));
  2822. if( this.selectAllNode ){
  2823. if( this.selector.isFlatCategory ){
  2824. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
  2825. }else if(this.selector.css.selectorItemCategoryActionNode_selectAll){
  2826. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  2827. }
  2828. }
  2829. this.isSelectedAll = false;
  2830. }.bind(this);
  2831. if( this.loaded ){
  2832. fun();
  2833. }else{
  2834. this.clickItem( function(){
  2835. fun();
  2836. }.bind(this))
  2837. }
  2838. },
  2839. unselectAllNested : function( ev, exclude, checkValid ){
  2840. this.unselectAll(ev, exclude, checkValid);
  2841. if( this.subCategorys && this.subCategorys.length ){
  2842. this.subCategorys.each( function( category ){
  2843. category.unselectAllNested( ev, exclude, checkValid )
  2844. })
  2845. }
  2846. },
  2847. selectAllNested : function( ev, checkValid, selectedNode, notActive ){
  2848. var node;
  2849. if(selectedNode)node = new Element("div.categorySelectedNode").inject( selectedNode );
  2850. this.selectAll(ev, checkValid, node, function () {
  2851. if( this.subCategorys && this.subCategorys.length ){
  2852. this.subCategorys.each( function( category ){
  2853. if(selectedNode)var node = new Element("div.categorySelectedNode").inject( selectedNode );
  2854. category.selectAllNested(ev, checkValid, node, notActive)
  2855. })
  2856. }
  2857. }.bind(this), notActive);
  2858. },
  2859. selectAll: function(ev, checkValid, selectedNode, callback, notActive){
  2860. if( this.loaded || this.selector.isFlatCategory ){
  2861. this._selectAll( ev, checkValid, selectedNode, notActive );
  2862. if(callback)callback();
  2863. }else{
  2864. this.clickItem( function(){
  2865. this._selectAll( ev, checkValid, selectedNode, notActive );
  2866. if(callback)callback();
  2867. //this.children.setStyles({
  2868. // "display": "none",
  2869. // "height": "0px"
  2870. //});
  2871. //this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  2872. }.bind(this), notActive);
  2873. }
  2874. },
  2875. _selectAll : function( ev, checkValid, selectedNode, notActive ){
  2876. if( this.selector.options.selectAllRange === "direct" && ( !this.subItems || !this.subItems.length ) )return;
  2877. var count = this.selector.options.maxCount || this.selector.options.count;
  2878. if (!count) count = 0;
  2879. var selectedSubItemCount = 0;
  2880. this.subItems.each( function(item){
  2881. if(item.isSelected)selectedSubItemCount++
  2882. }.bind(this));
  2883. if ((count.toInt()===0) || (this.selector.selectedItems.length+(this.subItems.length-selectedSubItemCount))<=count){
  2884. var checkedCount = 0;
  2885. var doSelectAll = function () {
  2886. this.subItems.each( function(item){
  2887. if(!item.isSelected && !item.disabled )item.selected( false, function () {
  2888. checkedCount++;
  2889. if( this.subItems.length === checkedCount ){
  2890. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  2891. }
  2892. }.bind(this), selectedNode);
  2893. }.bind(this));
  2894. if( this.selectAllNode ){
  2895. if( this.selector.isFlatCategory ){
  2896. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll_selected );
  2897. }else if(this.selector.css.selectorItemCategoryActionNode_selectAll_selected){
  2898. var styles = this.selector.css.selectorItemCategoryActionNode_selectAll_selected;
  2899. if( this.selector.options.isCheckStatus && this.selector.availableStatusTypes.contains(this.selector.selectType) ){
  2900. if( this._getSelectedCount() < this._getTotalCount() ){
  2901. styles = this.selector.css.selectorItemCategoryActionNode_selectsome_selected;
  2902. }
  2903. }
  2904. this.selectAllNode.setStyles( styles );
  2905. }
  2906. }
  2907. this.isSelectedAll = true;
  2908. }.bind(this);
  2909. if( this._beforeSelectAll ){
  2910. this._beforeSelectAll( doSelectAll );
  2911. }else{
  2912. doSelectAll();
  2913. }
  2914. }else{
  2915. MWF.xDesktop.notice("error", {x: "right", y:"top"}, MWF.SelectorLP.selectItemMaxText.replace("{count}", count), this.node);
  2916. }
  2917. },
  2918. checkSelectAll : function(){
  2919. if( this.isSelectedAll )return;
  2920. if( !this.selectAllNode )return;
  2921. if( !this.subItems )return;
  2922. var isAllItemSelected = true;
  2923. for( var i=0; i< this.subItems.length; i++ ){
  2924. if( !this.subItems[i].isSelected ){
  2925. isAllItemSelected = false;
  2926. break;
  2927. }
  2928. }
  2929. if( isAllItemSelected ){
  2930. if( this.selector.isFlatCategory ){
  2931. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll_selected );
  2932. }else if( this.selector.css.selectorItemCategoryActionNode_selectAll_selected ){
  2933. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_selected );
  2934. }
  2935. this.isSelectedAll = true;
  2936. }
  2937. },
  2938. checkUnselectAll : function(){
  2939. if( !this.isSelectedAll )return;
  2940. if( !this.selectAllNode )return;
  2941. if( !this.subItems )return;
  2942. var hasSelectedItem = false;
  2943. for( var i=0; i< this.subItems.length; i++ ){
  2944. if( this.subItems[i].isSelected ){
  2945. hasSelectedItem = true;
  2946. break;
  2947. }
  2948. }
  2949. if( !hasSelectedItem ){
  2950. if( this.selector.isFlatCategory ){
  2951. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
  2952. }else if( this.selector.css.selectorItemCategoryActionNode_selectAll ){
  2953. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  2954. }
  2955. this.isSelectedAll = false;
  2956. }
  2957. },
  2958. afterLoad: function(){
  2959. if (this.level===1) this.clickItem();
  2960. },
  2961. clickFlatCategoryItem : function( callback, hidden ){
  2962. if (this._hasChildItem()){
  2963. var display = this.children.getStyle("display");
  2964. if( hidden ){
  2965. this.children.setStyles({ "display": "none" });
  2966. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  2967. this.isExpand = false;
  2968. }else if (display === "none"){
  2969. this.children.setStyles({
  2970. "display": "block",
  2971. "height": "auto"
  2972. });
  2973. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  2974. this.isExpand = true;
  2975. }else{
  2976. this.children.setStyles({
  2977. "display": "none"
  2978. });
  2979. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  2980. this.isExpand = false;
  2981. }
  2982. if(callback)callback()
  2983. }
  2984. },
  2985. clickItem: function( callback ){
  2986. if (this._hasChild() || this.selector.options.expandEmptyCategory ){
  2987. if (!this.fx){
  2988. this.fx = new Fx.Tween(this.children, {
  2989. "duration": 200
  2990. // "transition": Fx.Transitions.Cubic.easeIn
  2991. });
  2992. }
  2993. if (!this.fx.isRunning()){
  2994. var display = this.children.getStyle("display");
  2995. if (display === "none"){
  2996. this.children.setStyles({
  2997. "display": "block",
  2998. "height": "0px"
  2999. });
  3000. this.fx.start("height", "0px", ""+this.childrenHeight+"px");
  3001. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  3002. this.isExpand = true;
  3003. this.selector.fireEvent("expand", [this] );
  3004. }else{
  3005. if (!this.childrenHeight) this.childrenHeight = this.children.getStyle("height").toFloat();
  3006. this.fx.start("height", ""+this.childrenHeight+"px", "0px").chain(function(){
  3007. this.children.setStyles({
  3008. "display": "none",
  3009. "height": "0px"
  3010. });
  3011. }.bind(this));
  3012. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  3013. this.isExpand = false;
  3014. this.selector.fireEvent("collapse", [this] );
  3015. }
  3016. }
  3017. if(callback)callback()
  3018. }
  3019. },
  3020. activeSub: function(){
  3021. if(this.subItems) {
  3022. this.subItems.each(function (item) {
  3023. item.load()
  3024. });
  3025. }
  3026. if(this.subCategorys)this.subCategorys.each(function(category){
  3027. if(category.notActive)category.active();
  3028. });
  3029. this.subNotActive = false;
  3030. },
  3031. overItem: function(){
  3032. //if (!this.isSelected){
  3033. // this.node.setStyles(this.selector.css.selectorItem_over);
  3034. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  3035. //}
  3036. if( this.selector.css.selectorItemCategory_over ){
  3037. this.node.setStyles(this.selector.css.selectorItemCategory_over);
  3038. }
  3039. var display = this.children.getStyle("display");
  3040. if( display === "none" ){
  3041. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_collapse_over ){
  3042. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_collapse_over )
  3043. }
  3044. }else{
  3045. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_expand_over ){
  3046. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_expand_over )
  3047. }
  3048. }
  3049. },
  3050. outItem: function(){
  3051. //if (!this.isSelected){
  3052. // this.node.setStyles(this.selector.css.selectorItem);
  3053. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  3054. //}
  3055. if( this.selector.css.selectorItemCategory_over ){
  3056. this.node.setStyles(this.selector.css.selectorItemCategory);
  3057. }
  3058. var display = this.children.getStyle("display");
  3059. if( display === "none" ){
  3060. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_collapse_over ){
  3061. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_collapse )
  3062. }
  3063. }else{
  3064. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_expand_over ){
  3065. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_expand )
  3066. }
  3067. }
  3068. },
  3069. _hasChild: function(){
  3070. var subIdList = this.selector._getChildrenItemIds(this.data);
  3071. if (subIdList) if (subIdList.length) return true;
  3072. return false;
  3073. },
  3074. _hasChildCategory: function(){
  3075. return null;
  3076. },
  3077. _hasChildItem: function(){
  3078. return this._hasChild();
  3079. },
  3080. _getTtiteText: function(){
  3081. if( this.data.levelName ){
  3082. return this.data.name+"("+ this.data.levelName +")";
  3083. }else{
  3084. return this.data.name;
  3085. }
  3086. },
  3087. checkCountAndStatus: function( nestedSub ){
  3088. var count = this._getSelectedCount();
  3089. this._checkCountAndStatus(count);
  3090. if( nestedSub && this.subCategorys && this.subCategorys.length){
  3091. this.subCategorys.each(function(category){
  3092. if( category.checkCountAndStatus )category.checkCountAndStatus(nestedSub);
  3093. }.bind(this))
  3094. }
  3095. },
  3096. _checkCountAndStatus: function( count ){
  3097. if( this.selector.isCheckStatusOrCount() ){
  3098. if(this.selectedCountNode){
  3099. if( this.selector.options.showSelectedCount && this.selector.options.showAllCount ){
  3100. var totalCount = this._getTotalCount();
  3101. if(count || totalCount)this.selectedCountNode.set("text", (count||0)+"/"+ (totalCount||0));
  3102. }else if(this.selector.options.showSelectedCount){
  3103. this.selectedCountNode.set("text", count ? "(" + count + ")" : "" );
  3104. }else if(this.selector.options.showAllCount){
  3105. var totalCount = this._getTotalCount();
  3106. this.selectedCountNode.set("text", totalCount ? "(" + totalCount + ")" : "" );
  3107. }
  3108. }
  3109. if( this.selector.options.isCheckStatus && this.selectAllNode ){
  3110. var total = this._getTotalCount();
  3111. if( total ){
  3112. var styles;
  3113. if( count >= total ){
  3114. styles = this.selector.css.selectorItemCategoryActionNode_selectAll_selected;
  3115. this.isSelectedSome = false;
  3116. this.isSelectedAll = true;
  3117. }else if( count > 0 ){
  3118. styles = this.selector.css.selectorItemCategoryActionNode_selectsome_selected;
  3119. this.isSelectedSome = true;
  3120. this.isSelectedAll = false;
  3121. }else{
  3122. styles = this.selector.css.selectorItemCategoryActionNode_selectAll;
  3123. this.isSelectedSome = false;
  3124. this.isSelectedAll = false;
  3125. }
  3126. this.selectAllNode.setStyles( styles );
  3127. }
  3128. }
  3129. }else if( count === 0 && this.selector.options.selectAllRange === "all" && this.selectAllNode ){
  3130. styles = this.selector.css.selectorItemCategoryActionNode_selectAll;
  3131. this.isSelectedSome = false;
  3132. this.isSelectedAll = false;
  3133. this.selectAllNode.setStyles( styles );
  3134. }
  3135. // if( !this.selectedCountNode1 ){
  3136. // this.selectedCountNode1 = new Element("span").inject(this.textNode);
  3137. // }
  3138. // this.selectedCountNode1.set("text",count);
  3139. }
  3140. })
  3141. MWF.xApplication.Selector.Person.ItemGroupCategory = new Class({
  3142. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  3143. _getShowName: function(){
  3144. return this.data.name;
  3145. },
  3146. _setIcon: function(){
  3147. var style = this.selector.options.style;
  3148. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
  3149. }
  3150. });
  3151. MWF.xApplication.Selector.Person.ItemRoleCategory = new Class({
  3152. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  3153. _getShowName: function(){
  3154. return this.data.name;
  3155. },
  3156. _setIcon: function(){
  3157. var style = this.selector.options.style;
  3158. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/roleicon.png)");
  3159. }
  3160. });
  3161. MWF.xApplication.Selector.Person.Filter = new Class({
  3162. Implements: [Options, Events],
  3163. options: {
  3164. "style": "default",
  3165. "groups": [],
  3166. "roles": []
  3167. },
  3168. initialize: function(value, options){
  3169. this.setOptions(options);
  3170. this.value = value;
  3171. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  3172. },
  3173. filter: function(value, callback){
  3174. this.value = value;
  3175. var key = this.value;
  3176. if (this.options.groups.length || this.options.roles.length) key = {"key": key, "groupList": this.options.groupList, "roleList": this.options.roleList};
  3177. this.orgAction.listPersonByKey(function(json){
  3178. data = json.data;
  3179. if (callback) callback(data)
  3180. }.bind(this), null, key);
  3181. }
  3182. });