Person.js 119 KB

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